Skip to content
Guides

HL7v2 over MLLP to FHIR R4

Convert ADT, SIU and ORU messages from the MLLP listener to FHIR R4 and POST them to a FHIR server as one transaction.

On this page
HL7v2 over MLLP to FHIR R4. Create a FHIR REST adapter profile, start a workflow from the HL7v2 over MLLP to FHIR R4 template, set the sender's timezone, and test it with a synthetic ADT^A01 message to see the Patient and Encounter it would POST as one transaction Bundle.

This guide builds a channel that listens for HL7v2 messages over MLLP, converts each one to FHIR R4 and POSTs the result to a FHIR server. It uses the built-in HL7v2 over MLLP → FHIR R4 (POST) template. You set the sender's timezone, test with a synthetic ADT^A01 and deploy.

Here is the flow.

sequenceDiagram
    participant Sender as Sending system (test)
    participant Engine as MedHook engine
    participant FHIR as FHIR server (R4)

    Sender->>Engine: ADT^A01 over MLLP
    Engine-->>Sender: ACK (MSA|AA)
    Engine->>Engine: Convert to a FHIR transaction Bundle
    Engine->>FHIR: POST Bundle (Patient + Encounter)
    FHIR-->>Engine: 200 transaction-response

Each message becomes one transaction Bundle. The resources point at each other with urn:uuid references, which only resolve inside a single transaction, so the engine never splits the Bundle into separate requests.

MessageResources in the Bundle
ADT^A01, ADT^A04, ADT^A08Patient and Encounter
SIU^S12Patient and Appointment
ORU^R01Patient, ServiceRequest and Observation

Before you start

  • A running engine and a signed-in user. See the Quick start.
  • A FHIR R4 server the engine can reach, such as https://fhir.example.test/R4. The Medplum server in the Compose stack works too. Its base URL inside the stack is http://medplum-server:8103/fhir/R4.
  • The IANA timezone the sending system writes its times in, for example America/Chicago.

Steps

1. Create a FHIR REST profile

Open Adapters, choose New connection and pick FHIR REST. Fill in the following. Settings that aren't in the short form are under More settings.

FieldValue
NameTest FHIR server
Base URLhttps://fhir.example.test/R4
Auth typenone, basic, bearer, oauth2 (client credentials) or backend-services (SMART)
FHIR versionR4

With FHIR version set to R4, the engine does not read the server's CapabilityStatement to detect the version first. With a reachable server, choose Test connection to check that the engine can reach it. Then choose Save connection, and the connection opens on the Adapters page.

2. Start from the template

Open Workflows and choose Templates. Search for FHIR R4 and choose HL7v2 over MLLP → FHIR R4 (POST). The preview's Steps show the source, a router, the HL7v2 → FHIR R4 step and POST to FHIR server. Under Profiles it uses, Adapter profile for fhir-rest already shows Test FHIR server when it is your only FHIR REST profile. Choose Use this template. The builder opens with the new workflow. It starts Disabled.

The Steps list shows an MLLP listener source that takes ADT, SIU and ORU, and one destination, POST to FHIR server, with the output HL7 → FHIR.

The POST to FHIR server destination with the output HL7 → FHIR, FHIR version R4, an empty sender timezone, Custom mappings merged into the converter's Bundle, the bundle type transaction, and Send with the Test FHIR server profile and the create action

3. Set the sender's timezone

Select the destination. Under Output, the HL7 → FHIR options show FHIR version, Sender timezone, Custom mappings and Bundle type. Enter the timezone, for example America/Chicago.

HL7v2 times usually carry no UTC offset. The engine reads them in the timezone you set. If a message has such a time and Sender timezone is empty, the conversion step fails. The engine does not guess a zone, and it does not send a time it cannot place. The failed message waits on Messages › Needs action, so you can replay it once the timezone is set.

4. Point the destination at the FHIR server

Under Send, set Adapter profile to Test FHIR server · fhir-rest. Leave Action on create. The step POSTs the transaction Bundle to the profile's base URL as application/fhir+json.

If the FHIR server limits how many requests it takes, set Max concurrent calls, all engines or Max calls per second, all engines on its adapter profile. Every engine replica then shares that cap. A call that waits too long for a slot fails without sending, so the step's retry applies. See Create a profile.

5. Understand the conditional create

The template turns on conditionalCreate. Each Patient and Encounter entry carries an ifNoneExist search built from the message:

  • The Patient matches on PID-3, the MR identifier, with its assigning authority as the identifier system.
  • The Encounter matches on PV1-19, the visit number, the same way.

A repeated message about the same patient or visit does not create a duplicate. The first message wins: a later A08 phone change or A03 discharge is not applied to a resource that already exists.

The assigning authority must give a system. An OID in the identifier's assigning authority works, for example TESTFAC&2.16.840.1.113883.19.5.99999&ISO. If the sender uses only a bare namespace such as TESTFAC, map it to a URI in identifierSystems. Without a system the engine cannot match safely, so it creates the resource without ifNoneExist and warns.

The builder shows four options: FHIR version, Sender timezone, Custom mappings and Bundle type. Custom mappings are written on top of the converter's output by default, with targets that name a resource, such as Patient.name[0].family. Choose Replace the converter to keep only your mappings. To change conditionalCreate, conditionalUpdate, identifierSystems, includeSsn or zSegments, edit the transform step's config with Update workflow.

6. Know what is left out

  • SSN. The engine drops PID-19 and any SS identifier in PID-3. Set includeSsn to true only if the destination needs it.
  • Merges. MRG messages and identifier changes (A34, A40, A47 and similar) are not applied. The step warns.
  • Z-segments. The template forwards them on the Patient as an extension that holds the raw segment. They can carry data no other field forwards. Set zSegments to skip unless the destination needs them.

7. Test it

In the sample panel at the bottom, choose Load sample, then Paste a sample (or Replace, if the workflow already has one). Paste this synthetic message and choose Save sample:

text
MSH|^~\&|TESTSENDER|TESTFAC|MEDHOOK|DEMO|20260101120000||ADT^A01|MSG0001|P|2.5
EVN|A01|20260101120000
PID|1||MRN0001^^^TESTFAC&2.16.840.1.113883.19.5.99999&ISO^MR||TESTPATIENT^SYNTHETIC||19800101|F|||1 Test St^^Testville^ST^00000||555-0100|||||||000-00-0000
PV1|1|I|WARD^101^1||||1234^TESTDOCTOR^SYNTHETIC|||MED||||1|||||V0001^^^TESTFAC&2.16.840.1.113883.19.5.99999&ISO^VN|||||||||||||||||||||||||20260101120000

The visit time in PV1-44 has no UTC offset. Choose Run test before you set a timezone. The destination shows FAILED and this message:

text
hl7v2-to-fhir: PV1-44 sent with no UTC offset and the step has no timezone. Set config.timezone to the sender's IANA zone (e.g. America/Chicago), or config.missingTimezone to "warn" to accept times read as UTC or left out.

Now enter America/Chicago in Sender timezone and test again. The destination shows WOULD SEND and Would send with the whole Bundle: the Patient first, then the Encounter. The box scrolls. These parts of it matter:

json
{
  "resourceType": "Bundle",
  "type": "transaction",
  "entry": [
    {
      "resource": { "resourceType": "Patient", "birthDate": "1980-01-01" },
      "request": {
        "method": "POST",
        "url": "Patient",
        "ifNoneExist": "identifier=urn:oid:2.16.840.1.113883.19.5.99999|MRN0001"
      }
    },
    {
      "resource": {
        "resourceType": "Encounter",
        "status": "in-progress",
        "period": { "start": "2026-01-01T12:00:00-06:00" }
      },
      "request": {
        "method": "POST",
        "url": "Encounter",
        "ifNoneExist": "identifier=urn:oid:2.16.840.1.113883.19.5.99999|V0001"
      }
    }
  ]
}

The Patient has no SSN, and the time carries the offset for the zone you set.

8. Save, deploy and send

Choose Save. To deploy, in Workflows, turn on the workflow's switch and choose Go to Deploy, then choose Deploy v1 to all messages on the Versions tab (see Save and deploy). Deploy needs a passing test newer than the last save, passing saved test cases (if the workflow has any) and an approval. Send the same message over MLLP as in the JSON guide. The sender gets AA once the engine has recorded the message. A resend of the same MSH-10 is not posted twice.

🎉 Messages from the listener now land in your FHIR server as Patients and Encounters. To also forward the original message elsewhere, add a second destination in the channel builder.

Troubleshooting

  • The step fails with "sent with no UTC offset". Set Sender timezone as in step 3, then replay the failed message.
  • The FHIR server answers 412 Precondition Failed. It already holds more than one Patient or Encounter with that identifier, often from a feed that posted without ifNoneExist. The whole Bundle fails and is not retried, and later messages about that patient wait on Messages › Needs action. Remove the duplicates, or set conditionalCreate to false.
  • A POST the server rejects with a 4xx is not retried. It fails and waits on Messages › Needs action for replay. Fix the cause, then replay it. A POST whose response was lost is not retried either, because the server may already have it.
  • The warning says PID-3 has no MR identifier with a system. Add an OID to the assigning authority, or map its namespace in identifierSystems.
  • Save is blocked, or the step shows CHOOSE PROFILE or NO PROFILE. Choose an adapter profile on the destination.

Reference