Building CDS Hooks services on Medplum

Medplum exposes CDS Hooks through a discovery endpoint and an invocation endpoint that runs a configured Bot. This page explains how the pieces fit, what to configure, and where teams usually get stuck.

On this page

How CDS Hooks services on Medplum work and when to build one

A team builds a CDS Hooks service when its EHR or clinical workflow needs decision support at a defined point, such as when a clinician opens a patient chart (patient-view) or signs an order (order-sign). Medplum exposes this with a discovery endpoint at GET /cds-services, which tells the calling system what services exist, and an invocation endpoint at POST /cds-services/{botId}, which runs the Bot you configured for that service. Authentication is required for both calls, so the calling system must hold valid credentials before any of this works.

In plain terms, the EHR is the client. It first discovers which services are available, then at the chosen hook it sends a request containing context about the current patient, encounter or draft order, along with any prefetched data. The Medplum Bot receives that payload, applies your logic, and returns cards: short advisory messages, suggested actions, or links the clinician sees inside the EHR. The Bot does the clinical logic, so the same discipline you apply to other Medplum Bots (testing, versioning, secrets handling and review) applies here. Confirm with your EHR vendor which hooks and card features its CDS Hooks client supports, since the hook a clinician sees depends on that support, not on Medplum alone.

Build a CDS Hooks service when a decision support rule must fire inside a clinical workflow and a clinician needs to act on the result in that same moment. If the need is a nightly report or a batch alert, a Subscription or scheduled job is usually a better fit. This page walks through the discovery and invocation endpoints, configuring Bots as CDS services, the hooks you can use, and the authentication setup each caller needs. Before you start, check whether your EHR's CDS Hooks client sends the context your Bot requires, and confirm the authentication method your calling system can support.

What a team needs before building CDS Hooks services on Medplum

A CDS Hooks service on Medplum depends on four things lining up: a running Medplum deployment, a Bot that holds the decision logic, a calling EHR that supports the hooks you need, and an authenticated path between the two. Each card below is a decision or check to settle before the build starts, and most of them need an answer from the calling system's team as well as your own.

Medplum deployment and version

Decide whether the service runs on Medplum Cloud or on a self-hosted deployment you operate. Self-hosting puts the CDS Hooks endpoints, the Bot runtime and the database inside your network, so the team owns patching, backups and availability. Confirm the version you will target against the latest release on the GitHub releases page, since patch and minor versions ship on different cadences and upgrades must run in sequence. Ask the calling system's team which endpoint addresses they can reach and whether they need a stable public hostname.

Latest release at research
5.2.5
Medplum releases

Bot runtime for the decision logic

The CDS Hooks service is a Medplum Bot, so the team needs a working Bot deployment that can read the patient context and return cards. Plan the execution environment, how the Bot is deployed and versioned, and how its logic is tested before a clinical team sees it. Clinical rules change more often than server code, so decide who approves changes and how a rollback is recorded. Confirm with your Bot owner that the runtime and any outbound calls to terminology or rules services are allowed by your network policy.

Clinical content and rule sources

Before writing code, agree the clinical content the service will use: the guideline, order set, drug interaction source or local protocol behind each recommendation, and who owns its wording and review cycle. Identify which codes the logic depends on, such as LOINC, SNOMED CT or RxNorm, and confirm which code system versions your organization licenses and maintains. Ask your clinical informatics or pharmacy team to sign off on the trigger conditions and the advice text, because a CDS card that fires in the wrong context creates clinical risk, not just a bug.

Calling EHR support and hook choices

CDS Hooks is only useful where the calling EHR implements the standard and fires the hooks you plan to use, such as patient-view or order-sign. Ask the calling system's team which hooks they send, which context fields they populate, whether they support prefetch and how they display returned cards, including any suggestion or action types. Confirm their CDS Hooks version and whether they register your service's endpoint through their own administration tools. Note any hook they do not send, because the service cannot compensate for it.

Client credentials and identity setup

The discovery and invocation endpoints both require authentication, so the calling system needs a credential it can present to Medplum. Medplum supports client credentials for server-to-server access, and you can choose between Medplum's own identity provider and an external one. Decide which client identity the EHR will use, what access policy that identity holds, and how the secret is issued, rotated and stored. Confirm with the calling team which token type and lifetime their platform supports before you commit to a design.

Medplum authentication docs

Network, certificate and hosting constraints

The calling EHR must reach your Medplum endpoints over HTTPS, so ask about outbound and inbound rules on both sides, including any firewall, proxy or private connectivity the calling system requires. Confirm the certificate chain and hostname that the calling system will trust, and who renews it. If your Medplum server sits in a private network, decide whether the calling system can reach it directly or whether the call must pass through a gateway you control. Record these answers in writing, since they determine whether the service can run in production at all.

How an EHR call reaches a Bot through Medplum

The flow starts when the EHR or CDS client calls discovery on GET /cds-services to learn which services exist. For an invocation, the client sends an authenticated request to POST /cds-services/{botId}, and the Medplum server runs the configured Bot. The Bot's result returns to the EHR as cards. The trust boundary sits between the EHR network and the Medplum deployment, so confirm that every call crossing it carries a valid token and that the network path is allowed by your firewall rules.

Discovery and hook invocation crossing from the EHR network into Medplum.

Configuring a Bot as a CDS service in sequence

This sequence takes a Medplum Bot from clinical logic to a working CDS Hooks service that an EHR can discover and call. Each step ends with a check so the team knows the service is reachable and returning cards before the EHR connection is tested.

  1. Build and deploy the evaluation Bot

    Your developers write the Bot that holds the clinical logic, such as a rule that checks medication orders against allergy or renal data. They deploy it to the Medplum project that will serve the CDS Hooks requests and record its Bot ID. The step is done when the Bot deploys without errors and a manual test run against a sample Patient returns the expected output. Clinical informatics should review the rule logic and its inputs before anything else is connected.

  2. Identify the Bot as a CDS service

    Confirm the Bot is set up to act as a CDS service in your Medplum project, and record the Bot ID, since it becomes the path segment in the invocation endpoint. Decide which hook the service answers, such as patient-view or order-sign, and note the service's ID, title and description as they should appear to the EHR. Check the setup against the current Medplum CDS Hooks documentation, because the exact configuration fields can change between releases. The step is done when the team has a written record of the Bot ID, hook and service metadata.

  3. Check the discovery response

    Call GET /cds-services on your Medplum server with an authenticated request and confirm the response lists the service you configured. Check that the service ID, title, description and hook match your record from the previous step. If the service is missing, the Bot configuration or the project is wrong and the team should fix that before moving on. The step is done when the discovery response lists the expected service with the expected hook.

  4. Create the authenticated client for the EHR

    Create a client identity in Medplum for the EHR or CDS consumer to use, and grant it access only to the Bot and project it needs. Use client credentials for server-to-server access and confirm the token request succeeds. Agree with the EHR team which authentication method their system supports, since both discovery and invocation require authentication. The step is done when the client can obtain a token and use it to call GET /cds-services successfully, while an unauthenticated call is rejected.

  5. Invoke the service with a sample hook payload

    Send a POST request to /cds-services/{botId} with the authenticated token and a sample hook payload that follows the CDS Hooks request format for the chosen hook. Use a synthetic Patient and context that your test project holds, and label the test data clearly so no real records are involved. Confirm the Bot runs and the response contains the cards you expect, including summary, indicator and source fields. The step is done when the test invocation returns cards that match the expected output from the first step.

  6. Verify the end-to-end result in the EHR test environment

    Connect the EHR's test environment to the Medplum discovery and invocation endpoints and trigger the hook through a test workflow. Confirm the EHR shows the cards at the expected point in the workflow and that the actions and links behave as designed. Record any differences in payload handling, timeouts or authentication errors and resolve them before go-live. The step is done when the EHR test run shows the expected cards in the expected workflow, with the results documented for the clinical and security reviewers.

Choosing hooks such as patient-view and order-sign

The hook you choose decides two things: when the Bot runs and what clinical data reaches it. In CDS Hooks, a hook is the point in the EHR workflow where the calling system asks a service for decision support. A patient-view hook fires when a clinician opens a patient chart, so the service sees the patient in context but has little information about any pending action. An order-sign hook fires when a clinician signs orders, so the service can evaluate the specific medications, tests or procedures being placed. These suit different decisions. Patient-view fits background advice such as care gaps, chart summaries or reminders. Order-sign fits interventions that need the proposed order, such as dose checks or duplicate testing warnings, where a response can still change what the clinician does before signing.

Before you write the Bot logic, confirm with the EHR team which hooks the calling system fires for your workflow and which prefetch data it sends with each call. CDS Hooks lets the calling system send prefetched FHIR resources in the request, and Medplum's invocation endpoint at POST /cds-services/{botId} runs the configured Bot against that request. The Bot can only use what the call provides. If the EHR sends no MedicationRequest for an order-sign event, or sends only the patient reference for patient-view, the Bot must either fetch that data through an authorized FHIR call or return advice that does not depend on it. Ask whether prefetch is enabled, whether templates are customized per site, and whether the EHR supports the hook you planned. Record the answers in the service design, because they set the test cases you will need. The Medplum CDS Hooks documentation describes the hook and request mechanics in detail.

Mapping hook context and FHIR resources to Bot inputs

This table maps each element a calling EHR sends in a CDS Hooks request to the Bot input it becomes and the FHIR resources the Bot reads, with the owner of each decision. Use it as a checklist before the build starts, and treat the confirm column as the list of questions for the EHR team.

Hook elementBot input and FHIR readsDecision ownerConfirm with the EHR team
Hook name (for example patient-view or order-sign)Selects which Bot logic runs and which context fields are expected. Decide one Bot per hook or branch on the hook value.Medplum solution architect with clinical informaticsWhich hooks the EHR fires and at which workflow step
Hook context (patientId, encounterId, orders)Passed as the request body context. The Bot reads Patient, Encounter and ServiceRequest resources referenced by these IDs.Integration engineerWhether encounterId is sent on every hook and which order identifiers appear in draft orders
Prefetch resourcesSupplied by the EHR in the request. The Bot should use these first and fall back to a FHIR read only when a resource is missing.Integration engineer with EHR teamWhich prefetch templates are supported and whether they reflect the current record
Patient identifiers (MRN, FHIR logical ID)Map the EHR patient identifier to the Medplum Patient ID through an agreed identifier system before any read.Data governance lead with the EHR teamIdentifier system URIs, and how merged or duplicate patients are reported
User identity (practitioner, role)Read Practitioner or PractitionerRole from the request token or context. Use it for authorization logic, not for patient lookup.Security engineer with identity teamWhich claim or user reference identifies the clinician, and how service accounts are flagged
Clinical data needed for the decisionBot queries Observation, Condition, MedicationRequest or AllergyIntolerance through the FHIR API with the Bot's own access.Clinical owner who approves the rule logicWhich code systems the EHR uses, such as LOINC or SNOMED CT, and any local codes
Access scope of the BotThe Bot reads only the resource types its project policy allows. Confirm the access policy before the first call.Medplum project administratorWhether the EHR sends a patient-scoped token or the Bot uses client credentials

Securing CDS Hooks endpoints and the Bots behind them

A CDS Hooks service on Medplum exposes clinical data to an EHR on every hook call, so both the endpoints and the Bots behind them need controls. The cards below cover authentication, credentials, least-privilege reads, card and log content, network paths and the compliance evidence your team must own.

Authentication on both endpoints

Medplum requires authentication for the discovery endpoint at GET /cds-services and the invocation endpoint at POST /cds-services/{botId}. Confirm that your EHR's CDS client can obtain and present a valid token for both calls, and test that unauthenticated requests are rejected on each path. Do not assume discovery is public because it returns only service metadata.

CDS Hooks docs

Client credential scope

Give the EHR a dedicated client with the narrowest access it needs to invoke the CDS services. Medplum supports client credentials for server-to-server access, so the EHR can authenticate without a user session. Record which project and identity the client acts under, because the Bot's effective permissions depend on that identity. Ask your team to document who approved the client and what it can call.

Medplum auth docs

Credential rotation

Plan rotation for client secrets and any signing material before the EHR integration goes live, and store the values in your secrets manager rather than in Bot source code or configuration files in version control. Test that rotation does not interrupt in-flight hook calls, and confirm the process with the EHR team, since both sides must update their settings. Revoke credentials promptly when a person or system leaves the integration.

Least-privilege access policies for Bot reads

A CDS Bot usually needs to read a small set of resources for the patient in context, such as Patient, Condition, MedicationRequest or AllergyIntolerance. Create an access policy scoped to those resource types and, where possible, to the patient reference in the hook context. Avoid granting the Bot's identity broad search or admin rights. Test the policy with a Bot request for a patient outside the expected scope and confirm it is denied.

Patient data in cards and logs

Card summaries and detail text can carry diagnoses, medications and identifiers into the EHR screen, so keep them to what the clinician needs at that moment. Check what your Bot writes to logs, including request bodies, hook context and errors, and redact identifiers before they reach log storage. Confirm with your privacy and compliance leads how long card and log data is retained in each system.

Medplum compliance docs

Network paths between the EHR and Medplum

Decide which networks can reach the CDS endpoints and restrict the path to the EHR's known egress addresses or a gateway where your architecture allows it. Use TLS for all hook traffic and keep the Medplum server out of public access where your design permits. Test timeouts and failure behavior, because a slow CDS response can delay the EHR workflow. Document the design for your security reviewers.

Shared responsibility for compliance

Medplum's compliance documentation states that compliance is a shared responsibility between Medplum and its customers, so the controls above are your team's to implement and evidence. Map each control to your own policies, then have your assessors review the design and test results. DeployOpen prepares systems and evidence for assessment, but independent auditors and certification bodies issue any audit report or attestation.

Compliance docs

Testing CDS Hooks services before the EHR goes live

Test the service in layers before any clinician sees it, and start with discovery. Confirm that a GET request to /cds-services returns the service you configured with the expected id, title, description and hook list, and that an unauthenticated request is rejected, since the Medplum CDS Hooks docs state that authentication is required for both the discovery and invocation endpoints. Next, invoke the POST /cds-services/{botId} endpoint directly with a request built from a non-production Medplum project that holds synthetic patients, practitioners and orders. Use the same hook name, context and prefetch shape your EHR will send, and compare what comes back with what you expect the Bot to return for that patient. Confirm the exact request and prefetch fields with the EHR vendor's CDS Hooks implementation, because a mismatch there will not show up in a Medplum-only test.

Next, check the card content and failure behavior. For each scenario, verify the card's summary, detail, indicator and any suggested actions or links, and confirm that the text renders correctly in the EHR's CDS display. Include negative cases: missing prefetch data, a patient with no relevant history, an expired or invalid token, a Bot that throws an error, and a slow response. Decide in advance what the EHR should show when the service fails or times out, and confirm that the workflow still lets the clinician proceed. Then review the audit trail for each test call. Confirm that the Bot execution and the request are logged with enough detail to reconstruct what the service saw and returned, and that the logs contain no real patient identifiers. Synthetic test data should be used for all of this work. Clinical content, including the recommendation logic, alert thresholds and card wording, should go through the organization's clinical governance process and be signed off before go-live.

Common CDS Hooks failures on Medplum and how to fix them

This table lists the failures teams most often hit when exposing CDS Hooks services on Medplum, with the likely cause and first fix for each. Work through the rows in order, since authentication and Bot ID problems block most of the others, and escalate only after the first fix has been tested.

FailureLikely causeFirst fix
Discovery call fails or is rejectedThe GET /cds-services request has no valid credentials, or the token belongs to a client without access to the projectSend a valid bearer token from a client that can read the project, then retry the GET request and confirm a 200 response
Invocation call is rejectedThe POST /cds-services/{botId} request lacks authentication, or the caller's token is expiredRequest a fresh token, confirm the request includes it, and test invocation with a single known patient context
Bot ID in the path does not matchThe URL uses a Bot name, an old ID, or an ID from another project instead of the deployed Bot's IDCopy the ID of the deployed Bot from the Bot resource and update the service path used by the EHR or test client
Service does not appear in discoveryThe Bot is not configured as a CDS service, its service entry is missing the expected fields, or the Bot is in a different projectCheck the Bot's CDS service configuration and project membership, then rerun discovery and compare the returned service list
Hook fires but prefetch data is missingThe discovery definition does not request the prefetch templates the Bot reads, or the calling EHR omits themCompare the prefetch keys in the service definition with the keys the Bot reads, and log the incoming request to confirm what arrived
Prefetch data is unexpected or staleThe template resolves to a different resource than intended, or the caller supplies older dataTest each prefetch query directly against the FHIR API with the same patient and context, and align the query with the data the Bot needs
Bot execution times outThe Bot performs slow searches, calls external services without limits, or processes more data than the hook requiresNarrow searches, cache reference data where appropriate, and review Bot logs to find the slowest step before changing timeouts on the caller
Cards return with errors after a successful callThe Bot response does not match the CDS Hooks card structure expected by the callerValidate the response body against the CDS Hooks card fields and test with the caller's exact hook name and context
Failure persists after these checksPossible platform-side issue or a configuration fault that cannot be isolated from the customer environmentCollect the request IDs, Bot logs, the discovery response, and the exact timestamps, then contact Medplum support with a reproducible example

Questions teams ask before building CDS Hooks on Medplum

How much does it cost to build CDS Hooks services on Medplum?

Cost depends on the written scope, so no figure is given here. The main components are discovery and invocation endpoints, one Bot per CDS service, clinical logic, EHR-side configuration and validation, and the hosting you run Medplum on. Build work is one-time, while the Medplum subscription or self-hosting infrastructure, Bot maintenance, and rule updates recur. Ask for a quote that separates these items and names who pays for EHR vendor configuration. Medplum's own pricing page lists hosted plans and a self-hosted Community option, but those prices cover the platform, not the CDS services built on it.

What drives the cost and effort of a CDS Hooks build?

The biggest drivers are the number of hooks, such as patient-view or order-sign, and how many distinct CDS services you expose. Clinical logic complexity matters most: a rule that reads a few FHIR resources differs greatly from one that combines medications, labs and guidelines. EHR-side configuration and validation add effort because each consuming system must register and test your services. Authentication setup, logging for clinical review, and change control for rules that clinicians rely on also add work. Ask any partner to itemize effort by hook, by rule and by EHR integration.

How long does a CDS Hooks implementation take?

No duration is supplied for this work, so timing should come from a written scope. Timing depends on how many hooks are needed, how complex the clinical rules are, whether clinical governance must approve each rule, and how long the EHR team needs to register and test the services in their environment. Plan for validation in a non-production environment before any clinician sees a card. Ask for milestones tied to hooks and environments, and check which dependencies, such as an EHR vendor's change windows, sit outside your control.

What does our internal team need to provide?

Your team needs to supply clinical owners who define what each hook should say and when it should fire, plus engineers who can operate the Medplum project and its Bots. You will also need access to a test environment in the consuming EHR, sample patient data that is cleared for testing, and a named approver for clinical content. Security and compliance staff should review the authentication design and logging. A partner will ask for these people early, because most delays come from waiting on clinical sign-off or EHR access rather than from coding.

Can our own team build CDS Hooks services on Medplum without a partner?

Yes, a capable engineering team can build CDS Hooks services on Medplum if it has FHIR experience, can write and deploy Bots, and has clinical and EHR integration staff available. The harder parts are usually clinical validation, coordinating with the EHR vendor's configuration team, and keeping authentication and audit settings correct across environments. Teams that lack these skills often use a partner for the first service and then take over ongoing rule maintenance. Compare the internal effort against the written scope to see which parts you cover and which you do not.

Which Medplum deployment choices affect a CDS Hooks build?

The main choices are where Medplum runs and who operates it. Medplum Cloud plans and self-hosted deployments differ in what you control, so confirm with Medplum which features and Bot execution options your plan includes. Self-hosting on AWS, Kubernetes, Ubuntu, Docker or other supported options changes how you handle networking, secrets and upgrades. Authentication choices, including Medplum's own identity provider or an external one, determine how the EHR authenticates to your discovery and invocation endpoints. Medplum's self-hosting documentation and its compliance documents both describe shared responsibility, so settle these boundaries before design starts.

What should we ask a partner to confirm before signing?

Ask for a written scope that lists every hook, every CDS service, the consuming EHR environments and the validation steps. Confirm how authentication is set up for the discovery and invocation endpoints, since both require it, and who owns the credentials. Ask who handles clinical rule review, how changes are versioned and tested, and what happens after go-live, including support and upgrades. Request the deliverables in writing, such as Bot source, configuration records and test evidence, and confirm which items are excluded, including EHR vendor work and clinical content authoring.

How DeployOpen scopes and delivers CDS Hooks services on Medplum

DeployOpen plans, builds, documents and supports CDS Hooks services on Medplum inside the client's own infrastructure, with the scope agreed in writing before work starts. The engagement covers the discovery and invocation endpoints, the Bots behind each service, authentication and the handover to the team that will run it.

How we scope

  • Agree in writing which hooks, such as patient-view or order-sign, each CDS service will answer.
  • Confirm which clinical content, rules or data sources the Bots will use and who owns them.
  • Define how authentication, access policies and the clinical sign-off process apply before any build starts.

How we build

  • Build the discovery endpoint and the invocation endpoint so each configured Bot runs as a CDS service.
  • Test each hook end to end with authenticated requests, including responses sent for a patient with missing data.
  • Review each Bot for logging, error handling and secrets so no clinical data leaks into logs or responses.

How we hand over

  • Deliver written documentation of each CDS service, its hooks, its Bot, its inputs and its configuration.
  • Walk your clinical informatics, security and platform teams through the test results and open risks.
  • Provide a runbook covering service configuration changes, credential rotation and how to disable a service.

How we support

  • Offer ongoing support, upgrades and continuous testing for CDS services as a retainer after handover.
  • Retest affected CDS services when Medplum versions change and when the scope of a hook changes.
  • Keep documentation current so your team can review, change or retire each service with confidence.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.