Skip to main content

HL7 v2 to FHIR Demo

This project shows how to build an HL7 v2 to FHIR integration in Linkiir Grid, using schemas and the Data Map node for graphical mapping. A simulator generates an HL7 v2 admit message. You map it to a FHIR Patient, validate the Patient against a FHIR server, and send it on. The project also includes a ready-to-run workflow that reads FHIR from a server and maps it back to HL7 v2 in Lua.

Import it to learn, hands-on:

  • How to import a Linkiir Grid project from a zip bundle and run its workflows.
  • How Linkiir Grid converts HL7 v2 to FHIR with the graphical Data Map node, and FHIR back to HL7 v2 with a custom scripting node.
  • How the FHIR Validator checks a resource against a server before it is sent.
  • How to follow a message through the workflow in the logs.

Download FHIR_Demo.linkiir.zip (1.1 MB)

This is one of two Demo Projects. For a tour of the core nodes, see the Feature Demo.

This demo uses a public FHIR test server

So that it runs as soon as you import it, the demo points at https://hapi.fhir.org/baseR4, a free public FHIR sandbox, with authentication set to None. It is for learning only, so never send real patient data to it. To use your own FHIR server, see Point it at your own server.


What's inside​

The project FHIR Demo contains two independent workflows.

WorkflowFlowWhat it shows
HL7v2 to FHIRData Simulator (HL7 ADT) → ADT to FHIR (Data Map) → FHIR Validator → HAPI FHIR DestinationMap an HL7 v2 admit to a FHIR Patient, validate it, and send it to a FHIR server. You build the map yourself in Steps 2 and 3
FHIR to HL7v2HAPI FHIR Source → FHIR to HL7v2 Mapper (Transform Custom) → Print HL7v2 DestinationRead a Patient from a FHIR server and map it back to an HL7 v2 message in Lua. Ready to run as shipped

Both source nodes ship with Live Mode on and a 60-second interval. Once a workflow is started, it handles a new message every minute without further action.


Step 1 — Import the project​

  1. Open the Linkiir Grid in your browser.
  2. Go to Projects.
  3. Click the chevron on Add Project and choose From zip.
  4. Drop FHIR_Demo.linkiir.zip on Choose a project bundle, or click to browse for it.
  5. Click Import.

The project appears as FHIR Demo with two workflows. No other setup is needed. For name collisions and refused imports, see Import and Export Projects.

Outbound HTTPS

Both workflows call the public HAPI FHIR server over the network. On an air-gapped grid, both workflows report connection errors.


Step 2 — Open the Map view​

  1. Open the FHIR Demo project. On the Workflows tab, find the HL7v2 to FHIR workflow and select the hammer icon to open it in the Workflow Builder.
  2. Select the ADT to FHIR node. Right-click it and choose Edit map, or select Edit Map at the bottom of the node's settings.

This opens the Map view, the board where you build the message transformation. The node is already set up to take an HL7 v2.5.1 ADT^A01 and build a FHIR R4 resource. A sample admit message, ADT_A01.txt, is loaded, so the source column on the left shows real values beside each field. The destination column on the right is empty until you fill it in the next step.


Step 3 — Build the map​

In this step you build a FHIR R4 Patient resource from the admit message.

  1. In the destination column (right), open the Add resource… dropdown and select Patient.
  2. Select Auto-map at the top right of the destination column. It links the PID fields to the Patient: identifier, name, gender, birth date, address and phone. It also adds a narrative.
  3. Select Run Test on the toolbar to run the map on the sample and see the FHIR Patient it builds. See Testing a Data Map.
  4. Select Commit to save your changes. Type a commit message, or select Use the summary to fill one in from the changes you made. See Saving and committing.
Commit before you run the workflow

The runtime runs only committed code. Until you commit the map, the running workflow does not use it. The ADT to FHIR node then skips each message as rejected (its On Error setting is Skip the message) and nothing reaches the validator.

Now select a few of the links between the columns to see how each field is mapped. The Rule tab shows each rule's settings, the functions and normalizing steps you can add, and what the rule read and wrote on the last run. For more on what a Data Map converts between, see Data Map Formats.


Step 4 — Run the HL7v2 to FHIR workflow​

With the map built and committed, run the workflow end to end.

  1. Open the Monitor page.
  2. Find the HL7v2 to FHIR workflow under the FHIR Demo project and select Start.
  3. Right-click the HL7v2 to FHIR workflow and select Open in logs. The first message appears within a minute.
  4. In the FHIR Validator node's INFO entry, confirm that it reports no blocking issues.

A message leaves log lines like these:

Data Simulator: simulated 1 x HL7 v2.5.1 ADT^A01 (Admit)
FHIR Validator: valid, forwarded. no blocking issues (1 informational note)
HAPI FHIR Destination: Live Mode is off, nothing sent. Turn Live Mode on to POST to https://hapi.fhir.org/baseR4.

To see the message's whole journey, open one of its log entries and select Related messages. It shows each stop in order: the simulator generates the ADT^A01, ADT to FHIR maps it to a FHIR Patient, the validator checks it, and the destination receives it.

The destination is safe by default

The HAPI FHIR Destination ships with Live Mode off. It prepares the write but does not POST to the shared public server. The full chain still runs and the Patient reaches the destination. To write for real, turn Live Mode on in the node's settings, and point it at your own server rather than the public sandbox.


Step 5 — Run the FHIR to HL7v2 workflow​

The second workflow converts in the opposite direction. It uses a traditional custom scripting node, rather than a Data Map node, so you can compare the two approaches.

The HAPI FHIR Source polls the server for two Patients each interval and pushes each one downstream. The FHIR to HL7v2 Mapper turns each Patient into an HL7 v2 ADT^A08 (update). The Print HL7v2 Destination logs each segment so you can read the result.

  1. On the Monitor page, start the FHIR to HL7v2 workflow.
  2. Right-click it and select Open in logs.

The log shows the printed messages:

HAPI FHIR Source: pushed 2 Patient resource(s).
Print HL7v2: received a transformed HL7 v2 message (154 bytes):
MSH|^~\&|LINKIIR|LINKIIR GRID|RECEIVER|FACILITY|...|ADT^A08^ADT_A01|...|P|2.5.1
EVN|A08|...
PID|1||MRN100001^^^LINKIIR^MR||SMITH^JAMES||19800115|M|||123 OAK AVENUE^^CHICAGO^IL^60601^USA||(312)555-0142
Print HL7v2: printed 3 segment(s).
Public data is sparse

Patients on the public HAPI server often have no name or birth date, so some printed PID segments have empty fields. That comes from the real upstream data and is not a mapping error. The HL7v2 to FHIR workflow, fed by the simulator, always produces fully populated messages.


Where the mapping lives​

Open a node with Open in scripting, or from the Workflow Builder, to see its files. Testing and Debugging covers running the scripts on their samples and setting breakpoints.

FileRole
ADT to FHIR → mapping/maps/adt_a01_fhir.map.luaThe map you built in Step 3, as a Lua table. The Map view reads and rewrites it.
ADT to FHIR → mapping/maps/adt_a01_fhir.luaThe readable Lua code generated from the map. See The generated code.
ADT to FHIR → custom.lua, premap.lua, postmap.luaPlaces for your own Lua that the map calls, or that runs before and after it. See The node's files.
FHIR to HL7v2 Mapper → fhir_to_hl7v2_map.luaThe hand-written reverse mapping (mapToHL7): FHIR Patient → HL7 v2 MSH, EVN and PID, built with linkiir.data.create and filled by position.
FHIR to HL7v2 Mapper → main.luaNode glue: parses the FHIR JSON, calls the mapper, and forwards the HL7.
Print HL7v2 Destination → main.luaSplits the message on segment boundaries and logs each segment.

Techniques to reuse​

TechniqueWhere to see it
Graphical HL7 v2 → FHIR mapping, with Auto-mapADT to FHIR Map view
Validating FHIR against a server before sendingFHIR Validator
Sending a resource to a FHIR server (POST)HAPI FHIR Destination
Reading from a FHIR server on an intervalHAPI FHIR Source
Keeping hand-written mapping in its own module beside a thin main.luaFHIR to HL7v2 Mapper
Building HL7 v2 by position with linkiir.data.createFHIR to HL7v2 Mapper → fhir_to_hl7v2_map.lua

Point it at your own server​

The same nodes work against any FHIR R4 or R5 server. Change these settings on the three FHIR nodes: HAPI FHIR Source, FHIR Validator and HAPI FHIR Destination.

SettingPublic demoYour server
FHIR Base URL (FHIR Server URL on the FHIR Validator)https://hapi.fhir.org/baseR4Your server's FHIR base URL
Authentication (HAPI FHIR Source and Destination)None (public test endpoint)OAuth2 Backend Services (or Bearer or Basic), then fill in the credential fields

The nodes ship with empty credential fields, so enter your own after import. To write to your server, also turn Live Mode on on the HAPI FHIR Destination. See the HAPI FHIR Adapter and FHIR Validator references for every field.


Troubleshooting​

SymptomCauseFix
Connection or timeout errors in the logThe grid can't reach hapi.fhir.org, or the server is busyCheck outbound HTTPS. The public server is sometimes slow, and the next interval retries
Nothing appears in the logsThe workflow is stopped, or a source node's Live Mode is offStart the workflow, and check that Data Simulator (HL7 ADT) and HAPI FHIR Source show Live Mode on
ADT to FHIR logs Message rejected and nothing reaches the validatorThe map isn't built, or isn't committed yetFinish Step 3 and Commit
Map changes don't show up in the running workflowThe changes are saved but not committedCommit the node's files. The runtime runs only committed code
FHIR Validator stops the messageThe server reported a real error on the resourceRead the node's log entry, which lists the issues by severity. Check the map's output with Run Test
HAPI FHIR Destination logs "nothing sent"Live Mode is off (the safe default)Expected. Turn Live Mode on only to write to a server you own
FHIR to HL7v2 prints PID segments with empty fieldsThe public Patient had no name or birth dateExpected with public test data. HL7v2 to FHIR produces fully populated messages

For general problems, see Troubleshooting.


Where to go next​

GoalRead
Building your own Data Map nodesData Map Nodes and Building a Map
Sending different messages to different mapsConditions
Changing or adding schemasSchema Editor
Writing mappings in Lua insteadCustom Scripting Nodes
The FHIR adapters this demo builds onLinkiir FHIR Adapters
Building FHIR resource templatesFHIR Profiling Tools
Starting, stopping and watching workflowsMonitoring Workflows
Searching logs and message historyLog Search and Message History
The core-nodes tourFeature Demo