Healthcare systems often use different software that doesn't easily share information with each other. For example, hospitals, labs, pharmacies, and insurance systems may all store and manage data in their own way, making communication difficult. To solve this problem, two important standards are used:HL7 v2 → An older messaging standard used to send data between systemsFHIR → A modern standard that uses APIs to share data in a simple and flexible wayIn this guide, we'll learn how to use both HL7 and FHIR together with Node.js to help different healthcare systems exchange data smoothly and work better together.Architecture OverviewA typical integration architecture looks like this:[ HL7 Source Systems ] ↓[ Integration Layer (Node.js) ] ↓[ FHIR Server / API ] ↓[ Web / Mobile Apps ]Our Node.js service acts as:HL7 message receiverParser and transformerFHIR API clientSetting up the projectInitialize a new Node.js project:mkdir hl7-fhir-integration
cd hl7-fhir-integration
npm init -yInstall dependencies:npm install express axios body-parser
npm install hl7-standardReceiving HL7 messagesHL7 messages are often sent over TCP (MLLP protocol), but for simplicity, we'll simulate receiving them via HTTP.// server.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.text({ type: '*/*' }));
app.post('/hl7', (req, res) => {
const hl7Message = req.body;
console.log('Received HL7 Message:\n', hl7Message);
// Process message here
res.send('ACK');
});
app.listen(3000, () => {
console.log('HL7 Receiver running on port 3000');
});
Also, Check |
Patient Portal Development with React.js and FirebaseParsing HL7 messagesWe'll use the "hl7-standard" library to parse HL7 messages.Example HL7 message:MSH|^~\&|HIS|Hospital|LAB|LabSystem|20250401||ADT^A01|12345|P|2.5
PID|1||12345||John^Doe||19900101|MParsing it:const HL7 = require('hl7-standard');
function parseHL7(message) {
const hl7 = new HL7(message);
hl7.transform((err) => {
console.log('Transforming HL7 Message...', err);
if (err) throw err;
});
const pid = hl7.get('PID');
if (!pid) {
throw new Error('PID segment not found');
}
return {
id: pid['PID.3'] || null,
firstName: pid['PID.5']?.['PID.5.1'] || null,
lastName: pid['PID.5']?.['PID.5.2'] || null,
dob: pid['PID.7'] || null,
gender: pid['PID.8'] || null,
};
}Mapping HL7 to FHIRNow we convert parsed HL7 data into a FHIR-compliant resource.function mapToFHIRPatient(data) {
return {
resourceType: 'Patient',
id: data.id,
name: [{ given: [data.firstName], family: data.lastName }],
birthDate: data.dob,
gender: data.gender === 'M' ? 'male' : 'female',
};
}Putting it all togetherUpdate the /hl7 endpointapp.post('/hl7', async (req, res) => {
const hl7Message = req.body;
console.log('Received HL7 Message:\n', hl7Message);
try {
const parsed = parseHL7(hl7Message);
const fhirPatient = mapToFHIRPatient(parsed);
console.log('Mapped FHIR Patient:\n', JSON.stringify(fhirPatient, null, 2));
res.send('MSA|AA|12345'); // ACK
} catch (err) {
console.error(err);
res.status(500).send('MSA|AE|12345'); // Error ACK
}
});You may also like |
FHIR and Blockchain | A New Age of Healthcare Data ManagementHandling different HL7 message typesHL7 is event-driven, which means every message corresponds to a real-world clinical event—such as a patient being admitted, a lab result being generated, or a doctor placing an order.Because of this, each HL7 message type has a different structure and meaning, and therefore requires different transformation logic when converting into FHIR resources.Instead of using a one-size-fits-all approach, our integration layer should:Identify the message type (from the MSH segment)Route the message to the correct handlerApply specific transformation logic for that typeExample: Mapping OBX -> Observationfunction mapToObservation(obx) {
return {
resourceType: 'Observation',
status: 'final',
code: { text: obx[3][0] },
valueString: obx[5][0],
};
}ResultTest with example HL7 message:curl -X POST http://localhost:3000/hl7 -H "Content-Type: text/plain" --data-binary $'MSH|^~\\&|HIS|Hospital|LAB|LabSystem|20250401||ADT^A01|12345|P|2.5\r\nPID|1||12345||John^Doe||19900101|M'In the console you can see the FHIR record:Mapped FHIR Patient:
{
"resourceType": "Patient",
"id": "12345",
"name": [
{
"given": [
"John"
],
"family": "Doe"
}
],
"birthDate": "19900101",
"gender": "male"
}ConclusionIn conclusion, integrating HL7 and FHIR enables healthcare systems to bridge the gap between legacy messaging and modern API-driven architectures. By using Node.js as an integration layer, developers can efficiently parse, transform, and route healthcare data in real time. This approach not only improves interoperability but also enhances data accessibility and system scalability. Ultimately, adopting these standards leads to more connected, efficient, and patient-centric healthcare solutions. For more about healthcare app development, connect with our
healthcare developers.
Technology:ReactJS, Node.js...more
Category:Health & Wellness