Skip to content
Guides

Build it once, reuse it everywhere

Six features that keep one piece of integration work in one place, from a reusable step to a whole workflow promoted to production, and when to use each.

On this page

Integration work repeats. Every ADT feed looks up the patient, every scheduling feed shapes the same row, every customer wants the same admission posted to its own API, and every change has to reach staging and production. MedHook gives you six ways to build each of those once and reuse it, instead of copying steps between workflows and fixing them in several places.

This page says what each one is for and links its guide, its recipe and its video. Start with the one that matches the copy you want to stop making.

Which one to use

You want toUseGuideRecipe
Reuse a few steps inside many workflowsA componentReuse steps with componentsSIU to appointment row
Make the same workflow for each new customer from one formA templateMake a template from the workflowNew customer feed in one form
Reuse a whole workflow as a step, and use its answerA callable workflowCall another workflowADT with a patient lookup
Send one event to any number of workflows, each on its ownA topicConnect workflows with topicsOne admission, three destinations
Serve many senders from one workflow, each with its own APIA connection per senderOne workflow, many sendersPost each sender's messages to its own API
Check a step or a few before you reuse or deploy themRun with sampleTest with sample messagesTest the mapping steps of an ADT feed
Move a tested workflow from one environment to the nextPromotionTest, version and deployPromote ADT to FHIR from staging to production

How they fit together

One Demo Health admission can use all six. The diagram shows the ADT workflow of the recipes above, built once and promoted to production.

flowchart LR
    A[ADT^A01 from DH-NORTH] --> B[ADT workflow]
    B -->|Call workflow, wait| C[Look up the patient 1.0.0]
    B --> D[Component: ADT to patient row 1.0.0]
    B -->|connection for DH-NORTH| E[North clinic API]
    B -->|publish| F[Topic adt.admit]
    F --> G[FHIR store workflow]
    F --> H[Notifications workflow]
  • The callable workflow finds the patient once, for every workflow that needs it, and returns only the fields it declares.
  • The component keeps the mapping steps that several workflows share. They run inside the ADT workflow's own run.
  • The connection per sender posts each clinic's messages to that clinic's API, from one destination.
  • The topic hands the admission to every workflow that subscribes, each delivered and retried on its own. Adding a subscriber never changes the ADT workflow.
  • Run with sample tests the mapping steps, the component and each sender's connection on one message, without sending anything, and keeps the run as a test case.
  • Promotion copies the tested workflow, with the topics and workflows it uses, to staging and then production, mapping each connection to that environment's own.

Walk through it end to end

This walk-through builds the Demo Health integration from the diagram in a dev workspace, then promotes it to staging. Each step names what you should see. The same steps run as one browser test on every full test run, so this page and the engine stay in step. You need two admins: promotion lands as a draft, and someone else approves the deploy.

  1. Release the lookup. Build Look up the patient. Under When another workflow calls this one, declare one input, mrn (text, required), and one output, patientId (text, required). Deploy it. On its Versions tab, in Releases, type 1.0.0, add a note, and choose Publish release. The card lists 1.0.0 with your note. Callers pin this release, and nothing you deploy later changes it for them.
  2. Create the topic. Go to Workflows → Topics → New topic. Name it adt.admit, set the ordering key to $.facility and Retries before a dead letter to 0, and give it a schema that requires mrn and facility. Its page opens and says no workflow subscribes yet. Then create three subscribers with a Topic trigger on adt.admit: FHIR store, Bed board and Notifications, which posts to the care team's notifications API. The topic page now lists three subscribers.
  3. Build the ADT intake. Add + Call a workflow to the source steps: Look up the patient, Wait for the result, version 1.0.0, and save the answer as patient. Add two destinations: Admissions, sent to the topic adt.admit, and Customer API, a REST post. On the Customer API send step, choose Different connection per sender. The table starts at No senders yet. Choose + Add sender twice: DH-NORTH with its own connection and DH-SOUTH with its own. The step's own connection stays the default for any sender not listed. Save, then deploy.
  4. Send two admissions. Send one from DH-NORTH and one from DH-SOUTH. Each run shows Waiting while the lookup runs (a waiting run holds no queue slot), then Completed. DH-NORTH's admission reaches the north API and DH-SOUTH's the south one. Each carries patient.patientId and nothing else the lookup made. The parent run's page says it waited for the lookup, with View sub-execution.
  5. Watch the fan-out, then replay. On the topic page, each admission shows three deliveries. FHIR store and Bed board say Delivered. The notifications API is down, so Notifications says Dead letter twice, each with its error (HTTP 422). Once the API is back, choose Replay on each dead letter. Both are delivered and the dead letters list is empty.
  6. Save steps as a component. In Demo Health SIU, the three source steps Parse, Map and Shape row turn a scheduling message into an appointment row. Select the Source, then Save as component in Source transformer. All three steps start picked. Name it SIU → appointment row and choose Save component. It is released as 1.0.0 at once, and the three steps become one Component step. Save. In Demo Health clinic B SIU, select the Source and choose + Use a component: pick SIU → appointment row, and Release shows 1.0.0. Save. Deploy both and run each once. Both post the same row, and the component's Used by lists both workflows.
  7. Test clinic B's steps with a sample. In clinic B, choose Run with sample in Source transformer. The steps before the send (Tag the clinic, then the component) start picked. Paste a sample appointment and choose Run. Each step shows its input, output and changes, including the component's own steps, and the summary ends nothing was sent. Nothing reaches the scheduling API. Name the run and choose Save as test case. It now runs with the other test cases on every deploy.
  8. Publish a new component release. Change Shape row so the row says which scheduling system sent it. On the component's page, choose Publish release…, type 1.1.0, say what changed, and choose Publish 1.1.0. Impact of 1.1.0 lists both workflows on 1.0.0. Choose Run tests. Clinic B is Held back: its tests failed, because the test case you saved in step 7 expects the old row. The SIU workflow's tests pass. Choose Update all (2). The SIU workflow moves to 1.1.0 as a new draft, and its deployed version keeps running until you deploy it. Clinic B stays on 1.0.0 until you update its test case. The update is audited. See Versions, impact and safe updates and the recipe Roll out a shared mapping change.
  9. Promote to staging. On the ADT intake's Versions tab, open ··· and choose Promote to another workspace, then pick the staging workspace. The diff comes first: there is no copy in staging yet. Goes with it lists Look up the patient and the topic adt.admit. Each connection is staging's own, never copied: staging's two sender connections, which have the same names, say Matched by name, and you pick staging's default connection yourself (Picked here). The preview also says This workflow pins release 1.0.0 of Look up the patient, which staging doesn't have yet. Choose Promote. It lands in staging as a turned-off draft, v1, on staging's connections.
  10. Deploy in staging. Releases are never cut by a promotion. In staging, deploy the lookup's copy and cut release 1.0.0 on its Versions tab, then deploy the ADT intake. Each deploy needs a passing dry run (and passing test cases, when it has any), and is refused until a second admin approves it. Approval is never bypassed. Send a DH-SOUTH admission in staging: it reaches staging's south connection.
  11. Make a template and use it twice. Back in dev, open Demo Health SIU and choose Templates › Save as template. Name it Demo Health clinic SIU and choose Save template. Its page opens: Built from lists SIU → appointment row at release 1.1.0, and no workflows are made from it yet. In Edit steps, set the send step's endpoint to /appointments/{{params.clinic}}. Under Parameters it asks for, choose + Add a parameter: clinic, required. Choose Save to draft, then Publish release… and Publish 1.0.0. Choose New from template: name the workflow Demo Health clinic C SIU, fill in clinic with C, pick the scheduling API under Connections (a template never keeps a connection, so each workflow picks its own), and choose Create workflow. Choose Make another and do the same for clinic D. The template page lists both workflows, each with its own clinic and Up to date. Deploy and run each: clinic C's row reaches /appointments/C and clinic D's /appointments/D. Then publish component release 1.2.0. Both workflows now say Update available (SIU → appointment row 1.1.0 → 1.2.0), and Update all (2) tests and updates them together. See Templates made of components.

Components or callable workflows

Both reuse work. They differ in where it runs.

ComponentCallable workflow
RunsInside the workflow that uses it, as its own stepsAs its own run, which the caller waits for or hands off to
Has its own triggerNoYes, so it can also run on its own
Shows in the runAs steps of the caller's runAs a sub-execution, linked both ways
What callers pinA release of the componentA release of the workflow
Good forParse, map and shape steps that many workflows repeatA lookup or a service other workflows ask for an answer

Both declare what they need and what they give back, and only the declared outputs reach the caller. Both change for a caller only when that caller picks a newer release.

Topics or several destinations

A workflow with several destinations sends one message to each, in one run. A topic sends one event to whatever workflows subscribe, each in its own run. Use a topic when the receivers belong to different teams, change on their own schedule, or should never hold each other up. Use destinations when one workflow owns every send.

Watch them

Each feature has a short video, with captions, at the top of its guide when it is published. The Videos page lists every published one.

Reference