Skip to content
Guides

Connect to an EHR over FHIR

Create an Epic FHIR adapter profile with backend-services settings, test the connection, then search for a patient and read it with a manual workflow.

On this page
Connect to an EHR over FHIR. Create an Epic FHIR adapter profile with backend-services settings, test the connection, then build a manual workflow that searches for a synthetic patient and reads it by ID, deploy it and run it. Everything talks to a local Epic-shaped test server.

This guide connects the engine to an EHR's FHIR R4 API. You create an Epic FHIR adapter profile that signs in with backend services, test it, then build a manual workflow that searches for a patient and reads that patient by ID. Other EHR adapters follow the same steps with their own settings.

Here is the flow.

sequenceDiagram
    participant You
    participant Engine as MedHook engine
    participant Epic as Epic (test system)

    You->>Engine: Test connection
    Engine->>Epic: POST token URL (client assertion signed with the engine key)
    Epic-->>Engine: Access token
    Engine->>Epic: GET metadata
    Epic-->>Engine: CapabilityStatement
    You->>Engine: Run now
    Engine->>Epic: GET Patient?family=TESTPATIENT
    Engine->>Epic: GET Patient/{id}
    Epic-->>Engine: Bundle and Patient

With backend services, the engine signs a short-lived request with its private key and the EHR returns an access token. Epic reads the matching public key from the engine's JWKS URL. No password is stored. The engine asks for a new token when the old one expires.

Before you start

  • A running engine and a signed-in operator or admin. See the Quick start.
  • Access to register an app for backend services with the healthcare organization's Epic. Registering gives you the client ID. The engine's own key signs the token requests, so you need no key pair of your own.
  • The organization's token URL and FHIR base URL. They look like https://fhir.example.test/oauth2/token and https://fhir.example.test/api/FHIR/R4.
  • The engine can reach those URLs over HTTPS.

Steps

1. Create the connection

Open Adapters and choose New connection. Pick Epic FHIR from the catalog, or paste the FHIR base URL and choose Continue with Epic FHIR. Then fill in:

FieldValue
Production | SandboxSandbox while you test; add Production later for the organization's live Epic
NameEpic FHIR · Demo Health
Base URLhttps://fhir.example.test/api/FHIR/R4, the FHIR R4 base, ending in /R4
Client IDThe client ID from the app registration. You can leave it empty and add it in EHR setup.
Token URLhttps://fhir.example.test/oauth2/token, under More settings

Leave Private key PEM and Key ID empty: the engine signs token requests with its own key, which you give Epic in EHR setup. To use a key pair of your own instead, paste the whole private key, including the BEGIN and END lines, and its key ID. Leave SMART enabled on false. You only need it for a SMART on FHIR app launch.

Choose Test connection. Without a client ID the engine reads only the server's public CapabilityStatement, and the test reads passed with a note: "Auth is tested in EHR setup once you have a client ID." Choose Save and open EHR setup. Secrets are encrypted at rest and never shown again.

2. Finish EHR setup and test

The connection opens on EHR setup, whose badge counts the steps left:

  1. Register MedHook as a backend app in Epic on FHIR: Build Apps, Backend Systems, FHIR R4.
  2. Copy the JWKS URL and kid into the registration.
  3. Choose the scopes your workflows use, such as system/Patient.read.
  4. Paste the client ID Epic gave you and choose Save client ID.
  5. Run check compares the server's CapabilityStatement with the steps that deliver here.
  6. Run test reads Epic's public sandbox patient. It runs only against Epic's own sandbox, so a test server like the one in this guide is refused before anything is sent.

Then open Overview and choose Test connection. The engine gets a token from the token URL and reads the CapabilityStatement. The Connection test console shows > POST token, then GET /metadata, < ok with the time it took, and "auth, reachability and permissions look good". See EHR setup.

3. Build a workflow that searches and reads

Open Workflows and choose New workflow. On Start, pick Receive and forward and Blank workflow, then choose Continue through Source and Sample. On Draft, enter a Name, such as Read TESTPATIENT from Epic, and choose Open in builder. In the builder, select Source and set Trigger type to manual · run on demand, so you can run it yourself from the builder.

A new workflow has no destination yet. The Steps list shows Add a destination as the next step, and Save waits until there is one.

Choose + Add destination and set up the search:

FieldValue
Destination nameSearch TESTPATIENT
LabelSearch patients
Adapter profileEpic FHIR · Demo Health · epic-fhir
Actionsearch-patients
Config (JSON){ "family": "TESTPATIENT" }

search-patients takes family, given and birthDate, or an identifier, or a FHIR id as fhirId. It returns a searchset Bundle.

Choose + Add destination again and set up the read:

FieldValue
Destination nameRead the Patient
LabelRead Patient
Adapter profileEpic FHIR · Demo Health · epic-fhir
Actionread
Config (JSON){ "resourceType": "Patient", "id": "eTESTPATIENT0001" }

Choose Save.

4. Deploy it

A manual workflow runs its deployed version, so deploy it first:

  1. Open Workflows and turn on the workflow's switch. Because it has never been deployed, the engine asks you to deploy it first. Choose Go to Deploy.
  2. On the Versions tab, the deploy panel lists what the deploy needs. Choose Request approval and have a different admin approve it, then choose Deploy v1 to all messages.
  3. On a test engine with one admin, choose Override and deploy while checks are still open, then Deploy anyway. The audit log records the override.

When the deploy succeeds, the version shows Live and the workflow is Active. See HL7v2 over MLLP to a JSON webhook for the deploy checks in detail.

5. Run it

Choose the Build tab. A manual workflow has Run now in the builder toolbar. It runs the active version once; unsaved edits are not included. Until the workflow is deployed, the button is off.

The run opens in the Runs tab, in its panel. The Trace shows both destinations running at the same time. To read what each step returned, open the run's message in Messages and choose Steps: Search patients shows the Bundle with one match, TESTPATIENT, and Read Patient shows the Patient resource with the same id. To come back to this run later, open the workflow's Runs tab, or pick it under Recent runs on Overview.

🎉 The engine now reads from the EHR. To run on a timer or an event, change the trigger to a schedule, and map the resources onto what your downstream system expects. See Triggers and Transforms.

Troubleshooting

  • Test connection fails on auth. Check the client ID, and that the registration has the engine's JWKS URL (or, with a key of your own, that the private key matches the public key on the registration). A newly registered key can take time to reach the organization's Epic.
  • Test connection cannot reach the server. Check the token URL and the FHIR base URL, and that the engine's network can reach them. A private address must be listed in the engine's SSRF_ALLOWLIST.
  • Run now is off. The workflow has not been deployed yet. Deploy it, then come back to the builder.
  • The search returns no entries. The criteria matched nobody. Check the spelling, or search by an identifier.

Reference