Send webhook events to an EHR as HL7v2 over an IPsec tunnel
Take signed JSON events on a webhook, build an HL7v2 ADT^A08 from each with a JavaScript step, and send it over MLLP to an EHR on a healthcare organization's private network through a site-to-site tunnel.
On this page
- Why a tunnel
- Before you start
- Order of operations
- Steps
- 1. Create the tunnel
- 2. Test the tunnel
- 3. Create the MLLP profile
- 4. Create the workflow
- 5. Build the HL7v2 message
- 6. Test with the sample
- 7. Secure the webhook
- 8. Choose what the source system hears back
- 9. Deploy and send
- 10. Read the EHR's ACK
- Troubleshooting
- Reference
A source system, such as a patient messaging or scheduling platform, can push its events to a URL but can't speak HL7v2. The EHR that needs those events takes HL7v2 over MLLP, and only on the healthcare organization's private network. This guide connects the two: a webhook trigger takes each signed JSON event, a JavaScript step turns it into an HL7v2 ADT^A08 (patient update), and an MLLP send delivers it through a site-to-site IPsec tunnel to the EHR and reads its ACK.
sequenceDiagram
participant Source as Source system (test)
participant Engine as MedHook engine
participant Tunnel as IPsec tunnel
participant EHR as EHR (MLLP, 10.20.0.40)
Source->>Engine: POST event (signed, Idempotency-Key)
Engine-->>Source: 200 accepted
Engine->>Engine: JavaScript: event to ADT^A08
Engine->>Tunnel: HL7v2 over MLLP
Tunnel->>EHR: ADT^A08
EHR-->>Engine: ACK (MSA|AA)Why a tunnel
Healthcare organizations rarely put an HL7 interface on the internet. The EHR's MLLP port stays on a private address, such as 10.20.0.40, and the tunnel gives the engine a private route to it. Nothing on their side opens a public port, and the traffic is encrypted between the two gateways.
The engine allows an MLLP destination on a private address. MLLP and SFTP connections are meant to reach hosts behind a tunnel, so they skip the private-address check that HTTP adapters have. The one thing an MLLP destination can never reach is a link-local or cloud metadata address (169.254.0.0/16, metadata.google.internal), by address or through DNS: the send fails with blocked by SSRF policy before anything is sent. See SSRF protection.
Before you start
- A running engine on the GKE deployment, which tunnels need, and the
adminrole. See Connect a healthcare organization's network with a VPN tunnel. - From the healthcare organization's network team: their firewall's public IP and the private subnet of the EHR's interface engine, for example
10.20.0.0/24. - From their interface team: the host and port of the EHR's MLLP listener inside that subnet, for example
10.20.0.40:6661, and whether to send to a test or a production listener first. - A source system that can POST JSON to a URL and sign the body with HMAC-SHA256. This guide uses this event:
{
"id": "evt-2001",
"type": "contact.updated",
"occurredAt": "2026-11-12T14:02:11Z",
"patient": {
"mrn": "TEST000123",
"family": "TESTPATIENT",
"given": "ALPHA",
"birthDate": "1980-01-01",
"sex": "F",
"phone": "555-0101"
}
}Order of operations
Bring the tunnel up and test it before you build the workflow, and deploy only after a test message gets its ACK. A workflow deployed before the tunnel is up fails every send: the connection can't open, and each event waits on Messages › Needs action until you replay it.
- Create the tunnel and hand off its config.
- Wait for Up, then test TCP and an HL7 round trip.
- Create the MLLP profile and check it connects.
- Build and test the workflow with a sample.
- Deploy, then point the source system at the webhook.
Steps
1. Create the tunnel
Open Tunnels, choose New tunnel and pick Classic VPN. Enter the organization (Demo Health), the peer's public IP and the EHR's subnet (10.20.0.0/24) under Their MLLP subnet, then choose Create tunnel. The full walkthrough, and HA VPN, are in Create the tunnel.
Then give the other side what they need, each in its own message:
- The peer config for their firewall. See Send the peer config.
- A one-time PSK link for the pre-shared key, never the key itself. See Send the pre-shared key.
- The connection packet PDF, which lists the gateway addresses, subnets and ciphers, and never the key. See Send the connection packet.
Their firewall must also let TCP through from MedHook's subnets, which the peer config lists, to the EHR's MLLP port.
2. Test the tunnel
Wait until the tunnel shows Up. Waiting for healthcare org side means your side is ready and theirs is not up yet.
Check that the EHR's port answers through the tunnel with the tunnel's TCP test:
curl -s -X POST "$ENGINE_URL/api/vpn-tunnels/$TUNNEL_ID/test" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"host": "10.20.0.40", "port": 6661}'It opens a TCP connection from the engine and reports whether it connected and how long it took. It sends no data. The host must be an IPv4 address inside the tunnel's subnets, and the tunnel must be ready.
| Result | What it means |
|---|---|
| Connected, with a time | The route, both firewalls and the listener are in place. |
Connection refused (host reachable, nothing listening on that port) | The host answers, but nothing listens on that port. Check it. |
No response within 5s (tunnel down or filtered) | The tunnel is down, or a firewall drops the traffic. |
Then check an HL7 round trip. On the tunnel, choose Send test message, enter 10.20.0.40:6661 and choose Send ADT^A01. The engine sends one synthetic ADT^A01 with MSH-11 = T and shows the ACK and the round-trip time. Agree with their interface team before you send it, because it lands in the EHR's listener. See Test it.
3. Create the MLLP profile
Open Adapters, choose New connection and pick MLLP Outbound. Settings that aren't in the short form are under More settings.
| Field | Value |
|---|---|
| Name | Demo Health EHR |
host | 10.20.0.40 |
port | 6661 |
timeout | 10000 (connect and ACK wait in milliseconds) |
Choose Test connection. It opens a connection to the host, with TLS when tlsEnabled is on, and sends nothing. Then save.
Use the IP address, not a host name. The tunnel's Overview lists, under Used by, the workflows that send to a host inside its subnets, and it only recognizes IPv4 addresses. For TLS, timeouts and the other settings, see Outbound sends.
4. Create the workflow
Open Workflows and choose New workflow. On Start, pick Receive and forward and Blank workflow, then Continue. On Source, pick Webhook. You can skip the API description cards and choose Continue. On Sample, paste the event above. On Draft, name the workflow Contact updates → Demo Health EHR, leave This workflow processes PHI on, and choose Open in builder.
Select the Source step and set Webhook id to contact-updates. Receives at shows the URL the source system posts to, /api/triggers/webhook/contact-updates on your engine.
5. Build the HL7v2 message
Choose + Add destination and set Destination name to Demo Health EHR. Under Output, choose + Add output step. It starts as JavaScript. Replace its code with:
const e = input.data;
const p = e.patient;
// HL7 escapes, so a | or ^ in a value can't break the message
const esc = (v) =>
String(v ?? "")
.replace(/\\/g, "\\E\\")
.replace(/\|/g, "\\F\\")
.replace(/\^/g, "\\S\\")
.replace(/&/g, "\\T\\")
.replace(/~/g, "\\R\\");
const ts = e.occurredAt.replace(/[-:TZ]/g, "").slice(0, 14) + "+0000";
return [
`MSH|^~\\&|MEDHOOK|DEMO|EHR|DEMOHEALTH|${ts}||ADT^A08^ADT_A01|${esc(e.id)}|P|2.5.1`,
`EVN|A08|${ts}`,
`PID|1||${esc(p.mrn)}^^^DEMO^MR||${esc(p.family)}^${esc(p.given)}||${p.birthDate.replace(/-/g, "")}|${esc(p.sex)}|||||${esc(p.phone)}`,
`PV1|1|N`,
].join("\r");A webhook run gives its steps { triggerType: "webhook", triggerId, webhookId, data, headers }, and data is the request body, so the event is input.data. The step returns the message as text, with segments separated by \r. The times carry +0000, because the event's time is in UTC.
The event id becomes MSH-10, the message control ID. The EHR echoes it in MSA-2 of its ACK, and the MLLP step checks that the ACK names the message it sent. Ask the EHR team how long MSH-10 may be: HL7 v2.5.1 allows 20 characters, and some receivers enforce it.
Under Send, set Adapter profile to Demo Health EHR · mllp and Action to send. Choose Save.
6. Test with the sample
Choose Run test. The sample runs as a live delivery would, as input.data, and nothing is delivered. The destination shows WOULD SEND and, under Would send, the HL7v2 message:
MSH|^~\&|MEDHOOK|DEMO|EHR|DEMOHEALTH|20261112140211+0000||ADT^A08^ADT_A01|evt-2001|P|2.5.1
EVN|A08|20261112140211+0000
PID|1||TEST000123^^^DEMO^MR||TESTPATIENT^ALPHA||19800101|F|||||555-0101
PV1|1|NSend the message text to the EHR's interface team to check before go-live. See Test with sample messages.
7. Secure the webhook
A webhook trigger with no signing secret refuses every caller that has no engine credential (401 SIGNATURE_REQUIRED). Give it a secret:
- In the builder, the Source's HMAC signing secret field. The secret is stored encrypted and never shown again.
- Or, on the workflow's Versions tab, the deploy checklist's Callers can authenticate row: choose Generate signing secret. The engine generates one and shows it once with Copy.
Give the secret to the source system's team. They sign the exact bytes of each body with HMAC-SHA256 and send the hex digest as x-hub-signature-256: sha256=<hex>. To stop a captured request being replayed later, they can sign a timestamp too, and Signed timestamp set to required refuses requests that don't. See Signing and Replay window.
The source system should also send an Idempotency-Key header that stays the same on every retry of one event, such as the event id. A retry of an event the engine already accepted gets 200 with "duplicate": true and runs nothing, so the EHR gets one A08 per event. Keep Duplicate deliveries on drop. See Retries and duplicates.
8. Choose what the source system hears back
Answer the sender with sets the answer to an accepted event:
| Option | What the source system gets |
|---|---|
| accepted | 200 with status: "accepted" and the execution id, as soon as the event is recorded. The send to the EHR runs after. This is the default. |
| custom | A status and body you set, as soon as the event is recorded. |
| destination | The output of the step you pick, once the run ends: pick the MLLP send, and the answer holds the EHR's ACK type. A run that fails answers 502. Past Wait up to (seconds, 1-60) it is 202. |
accepted suits most sources: the engine has the event safely, and failures wait on Needs action for you to replay. Choose destination only when the source system must know the EHR took the event, and give its HTTP client a timeout longer than the wait. See Answering the sender.
9. Deploy and send
In Workflows, turn on the workflow's switch and choose Go to Deploy, then choose Deploy v1 to all messages on the Versions tab. Deploy needs a passing test newer than the last save, passing saved test cases (if the workflow has any) and an approval. See Save and deploy.
Send one signed event, the way the source system will:
BODY='{"id":"evt-2001","type":"contact.updated","occurredAt":"2026-11-12T14:02:11Z","patient":{"mrn":"TEST000123","family":"TESTPATIENT","given":"ALPHA","birthDate":"1980-01-01","sex":"F","phone":"555-0101"}}'
SIG=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" -hex | sed 's/^.* //')
curl -X POST "$ENGINE_URL/api/triggers/webhook/contact-updates" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: evt-2001" \
-H "x-hub-signature-256: sha256=$SIG" \
-d "$BODY"The answer is 200 with "status": "accepted". Send the same request again and the answer has "duplicate": true.
10. Read the EHR's ACK
Open Messages. Each event is one row with the workflow name, the source webhook and its outcome. Select it:
- Raw shows the event as the source system sent it.
- Trace lists each step. The Send line ends with the EHR's ACK, for example
ACK MSA|AA|evt-2001.
| ACK | What the send step does |
|---|---|
AA | Succeeds. The EHR has the update. |
AE | Fails, and the step's On failure setting may send it again. |
AR | Fails, and is not retried. The EHR refused the message for good. Read MSA-3 and ERR, fix the cause, and replay. |
🎉 Events from the source system now reach the EHR as HL7v2, over a path that never leaves the private network. The tunnel's Overview lists the workflow under Used by.
Troubleshooting
- The source system gets
401SIGNATURE_REQUIRED. The trigger has no secret, and the request has no engine token. Set a secret as in step 7. - The source system gets
403INVALID_SIGNATURE. The signature doesn't match. The sender must sign the exact bytes it sends, not a re-serialized copy of the JSON, with the same secret. - The send fails with a connect timeout or
EHOSTUNREACH. Nothing reached the EHR, so the step's On failure setting retries it. Check the tunnel's status first. When the tunnel is down, the watcher acts on its own: with a backup tunnel it moves traffic to the backup after 60 seconds, and it re-creates a tunnel that stays down for 5 minutes. A message that used up its retries waits on Needs action: replay it once the tunnel is Up. See Self-healing watcher and Diagnose a down tunnel. - The send fails because no ACK came in time. The EHR may already have the message, so the engine does not resend it on its own. Ask their interface team whether it arrived before you replay it. If their system is slow to answer, raise
ackTimeoutMson the profile. - The send fails with
AEorAR. The EHR refused the message. MSA-3 and ERR say why, for example an unknown MRN or a missing field. Fix the code or the event, then replay. See Outbound sends. - The send fails as "delivery uncertain". The ACK named another message in MSA-2, or it was a commit ACK (
CA,CE,CR). The engine does not resend it. Check with their interface team. - The send fails with
blocked by SSRF policy. The profile's host is, or resolves to, a link-local or metadata address. Use the EHR's address inside the tunnel's subnets. - The TCP test answers that the host is not in this tunnel's subnets. The address is outside Their MLLP subnet. Check the address, or edit the tunnel's subnets with their network team.
- Run test works but live runs fail with
Cannot read properties of undefined. The code reads the event frominputinstead ofinput.data.