Integrating HL7 and FHIR in Healthcare App for Data Exchange
Posted By : Mohd Yasar | 07-Apr-2026
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 systems
- FHIR ? A modern standard that uses APIs to share data in a simple and flexible way
In 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 Overview
A 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 receiver
- Parser and transformer
- FHIR API client
Setting up the project
Initialize 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-standard
Receiving HL7 messages
HL7 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 Firebase
Parsing HL7 messages
We'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 FHIR
Now 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 together
Update the /hl7 endpoint
app.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 Management
Handling different HL7 message types
HL7 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 handler
- Apply specific transformation logic for that type
Example: Mapping OBX -> Observation
function mapToObservation(obx) {
return {
resourceType: 'Observation',
status: 'final',
code: { text: obx[3][0] },
valueString: obx[5][0],
};
}Result
Test 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"
}
Conclusion
In 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.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Mohd Yasar
Mohd Yasar is a skilled Backend Developer, with proficiency in NodeJs, MongoDB, MySql, Docker, Solidity, NFT's, and microservices architecture. He has extensive experience in developing secure and scalable solutions for complex applications, and has delivered successful projects such as Scaffold, Cryptomining, Mintlab, WalletPort, Data Management in Distributed Systems, and Bluechain, meeting the clients' requirements. Overall, he seems to have a diverse skill set and a strong foundation in developing scalable and reliable projects using a variety of technologies.