One workflow, many senders
Serve many senders with one workflow using per-sender settings, a connection per sender and sender-keyed code tables, and keep linked copies in step with Update all.
On this page
Many integrations have one shape for many senders: receive HL7v2, map it with a table that differs per customer, post it to an API. You build that shape once. Each sender's differences live in a sender table on the workflow, so a change to the mapping is one change, not one per sender.
When you do need separate workflows, for example because each sender has its own listener or its own approvals, make them linked copies of one template. A change to the template then reaches every copy with Update all.
sequenceDiagram
participant North as Demo Health North
participant South as Demo Health South
participant Engine as MedHook engine
participant API as Customer API
North->>Engine: ADT^A01 (MSH-4 DH-NORTH)
Engine->>Engine: Sender row DH-NORTH, its code table rows
Engine->>API: POST /customers/north-001/adt
South->>Engine: ADT^A01 (MSH-4 DH-SOUTH)
Engine->>Engine: Sender row DH-SOUTH, its code table rows
Engine->>API: POST /customers/south-002/adtPer-sender settings
A workflow's sender table has one row per sender. The engine picks the row for each message from its sending facility (MSH-4) and, if you give one, its sending application (MSH-3). Each row holds the values that differ for that sender, such as the destination customer id or which code table to use.
-
Open the workflow and choose Settings.
-
Under Delivery, in Senders, write one line per sender: its MSH-4, optionally
/and its MSH-3, thenkey=valuepairs separated by;.textDH-NORTH: customerId=north-001; table=north-sex DH-SOUTH/LAB: customerId=south-002 *: customerId=default-000 -
Choose Save senders. The next message uses them. A change to the sender table is not a new version of the workflow and needs no deploy.
The sender table travels with the workflow when you export it or import it. When you promote it to another workspace, the first promotion copies it as a starting point; after that each workspace keeps its own table, so a promotion never changes the values a deployed copy runs with (see Environments and promotion). Mirth export does not carry it.
| Where | How you write it | Example |
|---|---|---|
| Any step's settings | {{sender.key}} | Endpoint /customers/{{sender.customerId}} |
| A JavaScript step or a condition | sender.key | return { customer: sender.customerId }; |
Which row a message gets
| Order | Row |
|---|---|
| 1 | The row with the message's MSH-4 and MSH-3. |
| 2 | The row with the message's MSH-4 and no MSH-3. |
| 3 | The default row, *. |
The default row's values sit under the matched row's, so a sender's row lists only what differs from the default.
JSON senders
A JSON body has no MSH-4. Tell the webhook trigger where the body names its sender with senderFrom, and the sender table works the same way. In the builder it is the trigger's Sender from field.
senderFrom | Builder text | The sender is |
|---|---|---|
{ "path": "organization.id" } | body:organization.id | The value at that path in the body |
{ "header": "x-sender-id" } | header:x-sender-id | The value of that request header |
The value is matched as the sender's MSH-4, so a row dh-north: region=north applies to a body with "organization": { "id": "dh-north" }. Rows with an MSH-3 never match a JSON sender. A body without the value gets the default row, or fails as described below.
Anyone who can call the webhook can name any sender. Give each sender its own credential, such as its own trigger with its own signing secret, when the sender row decides where its data goes.
When a value is missing
A step that reads a key the sender has no value for fails, and so does a message from a sender no row matches when there is no default row. The error names the key or the MSH-4, never a message value, and the failure is not retried: it fails the same way until you add the row or the value.
A workflow with no sender table leaves {{sender. text alone, and a JavaScript step sees no sender.
A different connection per sender
When each customer has its own API, with its own address and credentials, give the destination a connection per sender instead of putting credentials in sender values. The step's own adapter profile is the default; a sender listed in the table sends through its own profile.
- In the builder's Steps view, select the destination.
- Under Send, choose Different connection per sender.
- Choose + Add sender for each sender: its MSH-4, optionally its MSH-3, and its connection. In the Graph view, the send step's node says how many senders have their own connection.
- In Senders not listed, choose use the default connection or fail the message.
- Save and deploy.
sequenceDiagram
participant North as Demo Health North
participant South as Demo Health South
participant Engine as MedHook engine
participant NAPI as North API (north profile)
participant SAPI as South API (south profile)
North->>Engine: ADT^A01 (MSH-4 DH-NORTH)
Engine->>NAPI: POST /adt with the north credentials
South->>Engine: ADT^A01 (MSH-4 DH-SOUTH)
Engine->>SAPI: POST /adt with the south credentialsThe run's Steps tab shows which connection each message used. A sender with no row uses the default connection, or fails before anything is sent, naming its MSH-4. The full rules are on Per-sender connections.
Sender context in workflows a step starts
A Run workflow step hands the sender, and the sender settings it matched, to the workflow it starts. A shared workflow that does the posting for every customer then picks each sender's connection and values, even when the message it receives no longer carries MSH.
A sample set per sender
In Run with sample, the Sender list narrows the sample library and the recent messages to one sender. Save a test case from each customer's message to build that customer's set.
Code tables keyed by sender
A code table row can belong to one sender. Write its source as the sender's MSH-4, a |, and the code. A row with no sender is the default row every other sender reads.
| Source | Target |
|---|---|
M | male |
F | female |
DH-NORTH|M | 1 |
DH-SOUTH|M | MALE |
A message from DH-NORTH maps M to 1, one from DH-SOUTH maps it to MALE, and every other sender gets male. This works in code-table steps, in field mapping lookups and in a JavaScript step's lookup(). HL7v2 never has a | inside a field value, so a sender row never collides with a code. Sender rows apply only in a workflow with a sender table: in any other workflow, a source like A|B is an ordinary row, as before.
Linked templates
Any workflow can be a template. On its Versions tab, Make a linked copy creates a draft linked to it, and Use this template in the templates gallery links the new workflow to the gallery template. A linked workflow records which template it came from and which version it took.
A linked copy keeps its own name, trigger, destination profiles, sender table and test cases. It takes the template's steps, how they connect and the start step. A destination step that is new in the template never takes the template's profile, because that is another workflow's real destination: the linked workflow is held back until you choose a profile for that step (in the API, with bindings).
Update all
When you save a change to the template, its linked workflows show Update available.
- Open the template's Versions tab. Template lists the linked workflows.
- Choose Preview on one to see the steps it will get.
- Choose Update all (N).
For each linked workflow the engine:
- checks that an active workflow has a usable profile on every destination, and that the updated workflow validates;
- runs the workflow's saved test cases against it as dry runs, so nothing is delivered;
- holds the workflow back unchanged if a check fails, if someone saved the workflow while the update ran, or if the update hits an error, and reports why;
- otherwise saves the update as a new draft version.
Update all never deploys. A deployed workflow keeps running its deployed version until you deploy the draft from its Versions tab, through the same checklist as any other change (approval, a fresh passing test). A workflow that was held back keeps showing the update. Fix the cause, then update it again.
Every run writes one workflow.template_update audit event that lists the workflows updated and held back.