Healthcare systems generate and exchange a massive amount of data every day, from patient admissions to lab results and discharge summaries. But exchanging this information between different software systems is not straightforward because each system may store and process data differently.
That’s where HL7 message processing and FHIR come into play. In this blog, we’ll walk through the basics of HL7, its segments, what FHIR is, and how we can process HL7 messages using AWS SQS and Node.js.
HL7 (Health Level Seven) is a set of international standards that define how healthcare information is exchanged between systems. It was created to ensure hospitals, labs, pharmacies, and other healthcare providers can talk to each other, regardless of the software they use.
For example, when a patient is admitted to a hospital, the hospital system can send an ADT (Admit, Discharge, Transfer) HL7 message to notify other systems like billing or lab management.
Effective HL7 message processing ensures that all these updates flow seamlessly between systems without data loss or duplication.
HL7 messages are structured text files. They are made up of segments, which are lines of data separated by carriage returns. Each segment begins with a three-letter code and contains fields separated by a pipe symbol (|).
Here are some common segments:
Example HL7 snippet:
MSH|^~\&|HOSPITAL|123|LAB|456|202509201200||ADT^A01|MSG0001|P|2.5
PID|1||12345^^^HOSP^MR||DOE^JOHN||19800101|M
PV1|1|I|2000^2012^01||||1234^SMITH^ADAM
These structures are the foundation of HL7 message processing workflows in healthcare integrations.
FHIR (Fast Healthcare Interoperability Resources) is a modern standard developed by HL7. While HL7 v2 messages are plain text and can be complex to parse, FHIR uses JSON or XML formats, making it easier to work with in modern applications.
For instance, the same patient admission message above could be represented as a structured FHIR Patient and Encounter resource in JSON, making it simpler for developers to consume and validate.
In many modern architectures, HL7 message processing pipelines convert HL7 v2 to FHIR formats to ensure interoperability across new systems.
In a hospital ecosystem, thousands of HL7 messages may be generated per hour. If systems directly talk to each other, they can get overloaded.
AWS SQS (Simple Queue Service) acts as a middle layer to handle this load. It works like a message buffer:
This architecture ensures reliable HL7 message processing at scale, keeping systems decoupled and fault-tolerant.
Let’s see how we can wire this up.
npm install @aws-sdk/client-sqs @medplum/fhirtypes uuid
import { Consumer } from "sqs-consumer";
import { SQSClient } from "@aws-sdk/client-sqs";
import dotenv from "dotenv";
import { extractPatient } from "../hl7Converter/extractPatient";
import { Patient } from "@medplum/fhirtypes";
dotenv.config();
// Create the SQS client
const sqsClient = new SQSClient({
region: process.env.AWS_REGION,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
},
});
// Setup queue URLs
const mainQueueUrl = process.env.QUEUE_URL!;
// Main message processor
async function processHL7Message(message: any) {
const body = message.Body;
console.log("Received message:", body);
const patient: Patient = extractPatient(body);
console.log("Extracted Patient:", JSON.stringify(patient, null, 2));
}
// Create the SQS consumer
export const app = Consumer.create({
queueUrl: mainQueueUrl,
handleMessage: async (message) => {
await processHL7Message(message);
},
sqs: sqsClient,
batchSize: 10,
pollingWaitTimeMs: 10000, // Long polling
});
This function extracts patient data from an HL7 message and converts it into a FHIR R4 Patient resource a key part of automated hl7 message processing pipelines.
import { Patient } from "@medplum/fhirtypes";
import { v4 as uuidv4 } from "uuid";
const patientId = `pat-${uuidv4()}`;
// --- Utilities ---
function formatHL7Date(hl7Date: string): string | undefined {
if (!hl7Date || hl7Date.length < 8) return undefined;
return `${hl7Date.slice(0, 4)}-${hl7Date.slice(4, 6)}-${hl7Date.slice(6, 8)}`;
}
export const extractPatient = (hl7: string) => {
const segments = hl7.trim().split(/\r?\n/);
const pid = segments.find((s) => s.startsWith("PID|"))?.split("|");
const patient: Patient = {
resourceType: "Patient",
id: patientId,
text: {
status: "generated",
div: `<div xmlns="http://www.w3.org/1999/xhtml">Patient Record</div>`,
},
identifier: pid?.[3]
? [{ system: "http://hospital.org/mrn", value: pid[3].split("^")[0] }]
: undefined,
name: pid?.[5]
? [{ family: pid[5].split("^")[0], given: [pid[5].split("^")[1] || ""] }]
: undefined,
gender: pid?.[8] === "M" ? "male" : pid?.[8] === "F" ? "female" : "unknown",
birthDate: pid?.[7] ? formatHL7Date(pid[7]) : undefined,
telecom: pid?.[13] ? [{ system: "phone", value: pid[13] }] : undefined,
address: pid?.[11]
? [
{
line: [pid[11].split("^")[0] || ""],
city: pid[11].split("^")[2] || "",
state: pid[11].split("^")[3] || "",
postalCode: pid[11].split("^")[4] || "",
country: pid[11].split("^")[5] || "",
},
]
: undefined,
};
return patient;
};
import { app as sqsListener } from "./common/utils/sqsListener";
sqsListener.start();
Sample HL7 message:
MSH|^~\&|REG_SYS|HOSPITAL|EHR_SYS|HOSPITAL|20250728T093000||ADT^A04|MSG0004|P|2.4
EVN|A04|20250728T093000
PID|1||123456^^^HOSP^MR||DOE^JOHN^A||19850615|M|||123 MAIN ST^^MUMBAI^MH^400001^IN||+91-9876543210
PV1|1|O|OPD^201^1^HOSP^^ROOM12||||5678^SHARMA^PRIYA^S|||OPD|||||||V123456^HOSP^ADM|||||||||||||||||||||||||20250728
Your SQS listener should be able to poll this message, process it, and output the structured FHIR patient record. This end-to-end flow demonstrates reliable hl7 message processing using AWS SQS and Node.js.
{
"resourceType": "Patient",
"id": "pat-c7db5919-052f-4b8c-9811-27648a9da41e",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Patient Record</div>"
},
"identifier": [
{
"system": "http://hospital.org/mrn",
"value": "123456"
}
],
"name": [
{
"family": "DOE",
"given": [
"JOHN"
]
}
],
"gender": "male",
"birthDate": "1985-06-15",
"telecom": [
{
"system": "phone",
"value": "+91-9876543210"
}
],
"address": [
{
"line": [
"123 MAIN ST"
],
"city": "MUMBAI",
"state": "MH",
"postalCode": "400001",
"country": "IN"
}
HL7 and FHIR are the backbone of healthcare interoperability. HL7 messages provide a long-established way to exchange data, while FHIR offers a modern, developer-friendly format.
By combining AWS SQS with Node.js, you can create a reliable pipeline to handle hl7 message processing, convert data into FHIR resources, and integrate them with downstream applications.
This architecture not only ensures scalability and fault tolerance but also prepares healthcare systems to adopt FHIR for modern interoperability needs.
We worked with Mindbowser on a design sprint, and their team did an awesome job. They really helped us shape the look and feel of our web app and gave us a clean, thoughtful design that our build team could...
The team at Mindbowser was highly professional, patient, and collaborative throughout our engagement. They struck the right balance between offering guidance and taking direction, which made the development process smooth. Although our project wasn’t related to healthcare, we clearly benefited...
Founder, Texas Ranch Security
Mindbowser played a crucial role in helping us bring everything together into a unified, cohesive product. Their commitment to industry-standard coding practices made an enormous difference, allowing developers to seamlessly transition in and out of the project without any confusion....
CEO, MarketsAI
I'm thrilled to be partnering with Mindbowser on our journey with TravelRite. The collaboration has been exceptional, and I’m truly grateful for the dedication and expertise the team has brought to the development process. Their commitment to our mission is...
Founder & CEO, TravelRite
The Mindbowser team's professionalism consistently impressed me. Their commitment to quality shone through in every aspect of the project. They truly went the extra mile, ensuring they understood our needs perfectly and were always willing to invest the time to...
CTO, New Day Therapeutics
I collaborated with Mindbowser for several years on a complex SaaS platform project. They took over a partially completed project and successfully transformed it into a fully functional and robust platform. Throughout the entire process, the quality of their work...
President, E.B. Carlson
Mindbowser and team are professional, talented and very responsive. They got us through a challenging situation with our IOT product successfully. They will be our go to dev team going forward.
Founder, Cascada
Amazing team to work with. Very responsive and very skilled in both front and backend engineering. Looking forward to our next project together.
Co-Founder, Emerge
The team is great to work with. Very professional, on task, and efficient.
Founder, PeriopMD
I can not express enough how pleased we are with the whole team. From the first call and meeting, they took our vision and ran with it. Communication was easy and everyone was flexible to our schedule. I’m excited to...
Founder, Seeke
We had very close go live timeline and Mindbowser team got us live a month before.
CEO, BuyNow WorldWide
Mindbowser brought in a team of skilled developers who were easy to work with and deeply committed to the project. If you're looking for reliable, high-quality development support, I’d absolutely recommend them.
Founder, Teach Reach
Mindbowser built both iOS and Android apps for Mindworks, that have stood the test of time. 5 years later they still function quite beautifully. Their team always met their objectives and I'm very happy with the end result. Thank you!
Founder, Mindworks
Mindbowser has delivered a much better quality product than our previous tech vendors. Our product is stable and passed Well Architected Framework Review from AWS.
CEO, PurpleAnt
I am happy to share that we got USD 10k in cloud credits courtesy of our friends at Mindbowser. Thank you Pravin and Ayush, this means a lot to us.
CTO, Shortlist
Mindbowser is one of the reasons that our app is successful. These guys have been a great team.
Founder & CEO, MangoMirror
Kudos for all your hard work and diligence on the Telehealth platform project. You made it possible.
CEO, ThriveHealth
Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.
CEO, SMILINGMIND
They were a very responsive team! Extremely easy to communicate and work with!
Founder & CEO, TotTech
We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.
Co-Founder, TEAM8s
Mindbowser was very helpful with explaining the development process and started quickly on the project.
Executive Director of Product Development, Innovation Lab
The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.
Co-Founder, Vesica
Mindbowser is professional, efficient and thorough.
Consultant, XPRIZE
Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.
Founder, S.T.A.R.S of Wellness
Mindbowser was great; they listened to us a lot and helped us hone in on the actual idea of the app. They had put together fantastic wireframes for us.
Co-Founder, Flat Earth
Mindbowser was incredibly responsive and understood exactly what I needed. They matched me with the perfect team member who not only grasped my vision but executed it flawlessly. The entire experience felt collaborative, efficient, and truly aligned with my goals.
Founder, Child Life On Call
The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!
CEO, SDOH2Health LLC
Mindbowser was easy to work with and hit the ground running, immediately feeling like part of our team.
CEO, Stealth Startup
Mindbowser was an excellent partner in developing my fitness app. They were patient, attentive, & understood my business needs. The end product exceeded my expectations. Thrilled to share it globally.
Owner, Phalanx
Mindbowser's expertise in tech, process & mobile development made them our choice for our app. The team was dedicated to the process & delivered high-quality features on time. They also gave valuable industry advice. Highly recommend them for app development...
Co-Founder, Fox&Fork