Skip to content
Guides

HL7v2 over MLLP to a JSON webhook

Receive HL7v2 messages on the MLLP listener and POST each one as JSON to an HTTPS endpoint.

On this page
HL7v2 over MLLP to a JSON webhook. Create a Generic REST adapter profile for a test endpoint, start a workflow from the HL7v2 over MLLP to JSON webhook template, point its destination at the profile, test it with a synthetic ADT^A01 message and deploy it.

This guide builds a channel that listens for HL7v2 messages over MLLP and POSTs each message as JSON to a URL you control. You start from the built-in template, point it at your endpoint, test it with a synthetic ADT^A01 and deploy it.

Here is the flow.

sequenceDiagram
    participant Sender as Sending system (test)
    participant Engine as MedHook engine
    participant Hook as Webhook endpoint

    Sender->>Engine: ADT^A01 over MLLP (port 2575)
    Engine-->>Sender: ACK (MSA|AA)
    Engine->>Hook: POST JSON {rawMessage, parsedMessage, messageType, ...}
    Hook-->>Engine: 2xx

The engine answers with the ACK once it has recorded the message. The POST to your endpoint runs right after. If the POST fails, the step retries before the execution fails.

Before you start

  • A running engine and a signed-in user. See the Quick start.
  • An HTTPS endpoint the engine can reach, for example https://webhook.example.test/hl7.
  • The sending system can open a TCP connection to the engine's MLLP port. The default is 2575.

Steps

1. Create an adapter profile for the endpoint

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

FieldValue
NameTest webhook
Base URLhttps://webhook.example.test/hl7
Auth typenone, or bearer with a token if your endpoint needs it

With a reachable endpoint, choose Test connection to check that the engine can reach it. Then choose Save connection, and the connection opens on the Adapters page. See Create a profile for the same step through the API.

2. Start from the template

Open Workflows and choose Templates. Find HL7v2 over MLLP → JSON webhook and choose its card. The preview opens on the right. Under Profiles it uses, it asks for a profile for each adapter the template needs: here, Adapter profile for generic-rest. With one Generic REST profile, Test webhook is already selected. With several, pick one. With none, choose Create one, or leave Choose later and pick it in the builder. Then choose Use this template. The builder opens with a new workflow. It starts Disabled, so no message reaches it until you deploy.

The Steps list on the left shows two things:

  1. Source, an MLLP listener that takes every message type.
  2. Destination, named POST JSON to webhook, with the output Original message.

The builder for the MLLP to JSON template: the Steps list with the MLLP listener source on port 2575 and the POST JSON to webhook destination, and the source's trigger, message type, sending facility and application, ACK, failed-message and duplicate fields

3. Choose which messages come in

Select the Source step. Under Message types you can narrow the listener, for example ADT^A01, ADT^A04. Leave it empty to take every type.

For finer control, add rules under Inbound filter. A rule has a field such as PV1-2, an operator and a value. Choose all of (AND) or any of (OR) to combine rules. A message that fails the filter gets an AR ACK and does not run.

The Listening on card at the bottom of the Steps list shows the address your sender connects to. Choose Copy to copy it.

The Source has more options. The defaults suit this guide:

FieldWhat it does
ListenerShown when your operator declared named listeners in Helm. Picks the port, and TLS, the message arrives on.
ACK the senderaccept (default) answers AA once the message is recorded. destination answers AA, AE or AR from the destinations' outcome, waiting up to Wait for destinations (ms).
On a failed messagecontinue (default) runs the next message from the same facility. hold stops that facility's messages until the failed one succeeds or is discarded.
Duplicate deliveriesdrop (default) answers a resend with the same MSH-10 without running it again. run every delivery is for senders that reuse control IDs.
Source transformerOutput steps that run once on the message before any destination filter.

Messages from one sending facility always run one at a time, in arrival order. See MLLP and ACKs and Triggers: MLLP.

4. Point the destination at your endpoint

Select the POST JSON to webhook destination. Under Send, Adapter profile shows Test webhook · generic-rest if you chose it in the dialog. If you chose later, the step shows Choose an adapter profile for this destination: set Adapter profile to Test webhook · generic-rest. Leave Action on post.

Leave Endpoint and Body empty. The step then POSTs the whole message to the profile's base URL as JSON. Set Content type on the step, or defaultContentType on the profile, to send another type. On failure is retry with 3 retries.

5. Test it

Choose Send sample ADT^A01 in the Test run panel, or Run test in the toolbar. The builder runs a bundled synthetic message through every step. It delivers nothing.

Under Test results, the destination shows WOULD SEND and Would send with the body it would POST. The body has this shape:

json
{
  "rawMessage": "MSH|^~\\&|SENDING_APP|SENDING_FACILITY|...",
  "messageType": "ADT^A01",
  "messageControlId": "MSG00001",
  "sendingApp": "SENDING_APP",
  "sendingFacility": "SENDING_FACILITY",
  "receivingApp": "RECEIVING_APP",
  "receivingFacility": "RECEIVING_FACILITY",
  "parsedMessage": {
    "MSH": [["MSH", "|", "^~\\&", "SENDING_APP", "..."]],
    "PID": [["PID", "1", "", "PATID1234^^^MRN", "", "Doe^John^A", "..."]]
  }
}

parsedMessage holds the segments by name. Each segment is a list of fields, and repeating segments such as OBX give more than one entry.

To use your own message, choose Replace on the sample panel, paste a synthetic message and choose Save sample. Samples are stored encrypted.

6. Save and deploy

Choose Save. A workflow that has never been deployed is deployed from its Versions tab:

  1. Open Workflows. The new workflow shows as Draft.
  2. Turn on its switch. Because it has never been deployed, the engine asks you to deploy it first. Choose Go to Deploy.
  3. The workflow's Versions tab opens. The deploy panel, Deploy v1, lists what the deploy needs: passing saved test cases (if the workflow has any, see Save test cases), a passing test newer than your last save, validation, a dry run against the last 50 messages (it shows No stored messages to run yet on a new workflow) and an approval.
  4. Choose Request approval. A different admin, signed in to the engine UI as a person, then chooses Approve, and you choose Deploy v1 to all messages (the number is the version you saved). An admin cannot approve their own request, and an API client cannot approve at all.

If you are the only admin, or you need to deploy before an approval, choose Override and deploy while checks are still open. The engine asks you to confirm, and Deploy anyway deploys without them. This is an admin override: the audit log records the deploy with what was skipped, so use it for test engines and urgent fixes rather than as the normal path.

To deploy a later version of a workflow that is already live, open the same Versions tab (or choose the version number in the Build toolbar). A later deploy can also run as a canary or on a schedule. See Test, version and deploy safely.

When the deploy succeeds, the version shows Live, the panel reads v1 is live and the workflow is Active. Deploying enables it, so there is no separate switch to turn on. The listener now accepts messages for it.

7. Send a real message

From a machine that can reach the engine, send a synthetic message over MLLP. MLLP wraps the message in the bytes 0x0B and 0x1C 0x0D:

bash
MSG='MSH|^~\&|TESTSENDER|TESTFAC|MEDHOOK|DEMO|20260101120000||ADT^A01|MSG0001|P|2.5\rEVN|A01|20260101120000\rPID|1||MRN0001^^^TESTFAC^MR||TESTPATIENT^SYNTHETIC||19800101|F\rPV1|1|I|WARD^101^1'
(printf '\013%b\034\015' "$MSG"; sleep 5) | nc engine.example.test 2575 | tr '\r' '\n'

The sleep 5 keeps the connection open until the ACK arrives: many nc builds, including the one in macOS, close it as soon as their input ends. On the machine that runs the Compose stack from the Quick start, the host is localhost: nc localhost 2575.

The reply is an ACK whose MSA segment reads MSA|AA|MSG0001. Your endpoint receives the JSON body shortly after. Open Messages to see the message and its run. To send a batch file, use TLS or check the ACK in a script, see Send test messages over MLLP.

🎉 Every message that reaches the listener now arrives at your endpoint as JSON. To fan one message out to several systems, see Build a channel with several destinations.

Troubleshooting

  • The step shows CHOOSE PROFILE, or Save is blocked. The destination has no adapter profile yet. Choose one under Send. Until it has one, the workflow can't be deployed.
  • The step shows NO PROFILE. Its adapter profile was deleted or belongs to another workspace. Choose another under Send.
  • The sender gets an AR ACK. No deployed workflow matched the message. Check that the workflow is Active, and that Message types and the Inbound filter accept the message. The sample panel shows whether each rule passes.
  • The sender gets an AE ACK. The engine could not record the message, for example while the database is down or the engine is shutting down. The sender should retry.
  • The test shows FAILED with a connection or blocked-address error. The engine cannot reach the endpoint. Check the base URL and the engine's network. Private addresses need the allowlist described above.
  • The endpoint receives the same message twice. A resend with the same MSH-10 is not run again. Two copies mean two different control IDs, or a retry after your endpoint answered with an error.

Reference