Wires Epic Hyperdrive to an external CDS Hooks decision service through a MuleSoft Process API, returning real-time Cards on order-select, order-sign, and patient-view without blocking the clinician. Covers discovery, prefetch, SMART launch, and card-to-order-mapping.
Tags: healthcare, epic, fhir, smart-on-fhir, us-core, api-led, process-api, interoperability
Clinical Decision Support
Objective: Epic clinicians ordering meds and studies need advice at the moment of decision, not a report read later. Hyperdrive fires CDS Hooks (order-select, order-sign, patient-view) to an external service that must respond in well under a second or the alert never renders. The work is stitching Epic's hook calls, prefetch, and SMART on FHIR context to rule engines and normalizing output into valid Cards fast enough that no one waits. Done looks like: discovery advertises the right hooks, every invoke returns valid Cards within budget, suggestions map to Epic orderables, and dead engines degrade to an empty card set, not a spinner. This accelerator packages the Clinical Decision Support Epic Data Sharing Playbook as a MuleSoft-anchored solution plan.
What's Getting Built
- CDS Hooks (Experience API) — serves discovery and invoke for order-select, order-sign, and patient-view and returns Cards ·
GET /cds-services, POST /cds-services/{id}
- Orchestration (Process API) — validates the invoke, resolves prefetch, fans out to rule engines, and assembles Cards within the latency budget ·
POST /orchestrate, ASSEMBLE cards
- Epic FHIR R4 (System API) — resolves prefetch-gap resources against the Epic FHIR endpoint in parallel ·
GET /MedicationRequest, GET /ServiceRequest, GET /Patient/{id}, GET /Condition
- Rule Engine Connectors (target) — external CDS rule and drug-interaction engines fanned out to concurrently for advice ·
POST /evaluate
- SMART token cache (Object Store) — caches the SMART backend-services access token keyed by scope until expiry minus a safety margin ·
GET /{scope}, PUT /{scope}
- Dead Letter (target) — captures failed or timed-out rule evaluations with full context for offline replay ·
PUBLISH dlq
Prerequisites
- Epic CDS Hooks configured in Hyperdrive with the MuleSoft discovery endpoint registered and the desired hooks enabled per department
- SMART on FHIR backend/confidential client registered in Epic with an app orchestration record and scopes for the FHIR resources the rules read
- Epic FHIR R4 endpoint reachable for prefetch fallback resolution of Patient, MedicationRequest, ServiceRequest, and Condition
- One or more CDS rule engines or drug-interaction services with documented request and response contracts
- Anypoint Platform environment with Anypoint MQ for the dead-letter queue and Object Store v2 for JWKS and token caching
- Signed public JWKS published for the SMART client and a synchronized clock source across Mule workers
1. Epic interfaces and standards
This accelerator implements the Clinical Decision Support Epic Data Sharing Playbook. Register the connecting app on Epic on FHIR and confirm the customer has the relevant Epic modules licensed before building.
- Hyperdrive and Hyperspace CDS Hooks client firing order-select, order-sign, and patient-view
- HL7 CDS Hooks 2.0 discovery and invoke endpoints with Cards, suggestions, and system actions
- SMART on FHIR backend-services token exchange for the fhirAuthorization block
- FHIR R4 MedicationRequest, ServiceRequest, Patient, and Condition for prefetch and lookup
- Infobutton style context for reference links surfaced in Card source and links
Architecture
2. Business requirements
- Advise at the point of order entry, not after signing, so the clinician can act on the Card before the order is committed.
- Advertise only the hooks each department actually consumes; a discovery response listing hooks Epic never fires is dead surface area.
- Guarantee a hard latency budget per invoke and treat a breach as a functional failure, because a late Card is a Card the clinician never sees.
- Map every suggestion back to a resolvable Epic orderable so accepting a suggestion writes a real order, not an orphan reference.
- Keep the decision logic in the rule engine and keep MuleSoft as the contract broker, so clinical content changes without redeploying the API.
3. Discovery and hook contract
- Serve the discovery document from the Experience API listing each hook, its id, the prefetch template, and a stable version.
- Declare prefetch queries for the resources rules need so Epic sends context inline and avoids a round trip.
- Validate the incoming invoke against the CDS Hooks schema for hook, hookInstance, context, and fhirServer before any rule call.
- Reject unknown hook ids at the edge with a 400 rather than passing garbage to the rule engine.
- Stamp a correlation id from hookInstance onto every downstream call so a single clinician action is traceable end to end.
4. Prefetch resolution and SMART context
- Use Epic-supplied prefetch when present and fall back to the System API against the FHIR R4 endpoint only for the resources actually missing.
- Exchange the SMART backend-services JWT for an access token and cache it in Object Store keyed by scope until expiry minus a safety margin.
- Resolve fhirServer and fhirAuthorization from the invoke body rather than a hardcoded endpoint, since context can span connected orgs.
- Fetch prefetch fallbacks in parallel with a short per-resource timeout so one slow resource does not blow the whole budget.
- Never fail the whole invoke because one optional prefetch resource is unavailable; evaluate rules on what you have.
5. Rule evaluation and Card assembly
- Fan out to rule engines concurrently and collect results within the remaining latency budget, dropping laggards.
- Transform each engine result in DataWeave into a valid Card with summary, indicator, source, and detail markdown.
- Emit suggestions with actions that create, update, or delete FHIR resources so Epic can apply them to the order.
- Set indicator honestly: reserve hard-stop styling for true contraindications, not routine reminders, or clinicians tune it all out.
- Return an empty cards array on total rule-engine failure so Hyperdrive renders nothing rather than an error state.
6. Error handling and operations
- Route failed or timed-out rule evaluations to an Anypoint MQ dead-letter queue with the full context for offline replay and tuning.
- Alert on the absence of expected invokes for an enabled hook, which is the failure mode dashboards miss most often.
- Track card-return rate and suggestion-accept rate per hook so silently useless rules get pruned.
- Log the correlation id, hook id, latency, and card count on every invoke and never log PHI from context or prefetch.
- Version the discovery contract and roll new hooks behind a flag so Epic build validation runs before clinicians see them.
7. Security and compliance
- Encrypt PHI in transit and at rest.
- Audit-log every access to and modification of patient data, and carry a correlation ID end to end.
- Enforce minimum-necessary access for integration operators and support users.
- Validate the SMART backend-services JWT signature against Epic's published JWKS and reject tokens with a wrong audience or expired exp.
- Scope the outbound FHIR access token to the minimum resources the rules read and never request write scopes the decision service does not use.
- Treat prefetch and context as PHI in transit; enforce TLS to the rule engines and strip identifiers from any card detail sent to third-party content.
- Rate-limit and IP-allowlist the invoke endpoint to Epic's egress so the decision service cannot be probed for patient context externally.
Sample payload — CDS Hooks order-select invoke from Hyperdrive
{
"hook": "order-select",
"hookInstance": "d1577c69-dfbe-44ad-ba6d-3e05e953b2ea",
"fhirServer": "https://epic.example.org/api/FHIR/R4",
"fhirAuthorization": {
"access_token": "eyJhbGciOiJSUzI1NiIs...",
"token_type": "Bearer",
"expires_in": 300,
"scope": "patient/MedicationRequest.read patient/Condition.read",
"subject": "cds-service4"
},
"context": {
"userId": "Practitioner/EPIC-PROV-8891",
"patientId": "eXYZ-patient-4402",
"encounterId": "eABC-enc-7761",
"selections": ["MedicationRequest/med-rx-1001"],
"draftOrders": {
"resourceType": "Bundle",
"entry": [
{
"resource": {
"resourceType": "MedicationRequest",
"id": "med-rx-1001",
"status": "draft",
"intent": "order",
"medicationCodeableConcept": {
"coding": [{"system": "http://www.nlm.nih.gov/research/umls/rxnorm", "code": "855332", "display": "warfarin sodium 5 MG"}]
},
"subject": {"reference": "Patient/eXYZ-patient-4402"}
}
}
]
}
},
"prefetch": {
"patient": {"resourceType": "Patient", "id": "eXYZ-patient-4402"}
}
}
Testing and validation
- Post the CDS Hooks conformance test suite against discovery and assert every advertised hook has a valid prefetch template and version.
- Send a fully-prefetched order-select invoke and assert no System API FHIR call fires, confirming prefetch short-circuits lookup.
- Send an invoke with prefetch gaps and assert only the missing resources are fetched, in parallel, within the per-resource timeout.
- Inject a rule-engine timeout and assert the response is an empty cards array with a dead-letter message enqueued, not a 500.
- Validate a returned suggestion action against the FHIR R4 profile so Epic can apply it to a real orderable.
- Load-test at expected concurrent order entries and assert p95 invoke latency stays under the declared budget.
Phased rollout
Phase 1 — Connect
- Register the MuleSoft discovery endpoint in Epic and confirm Hyperdrive retrieves the hook list in a non-production environment.
- Establish SMART backend-services token exchange and verify a scoped FHIR read succeeds against the test endpoint.
Phase 2 — Map and test
- Build DataWeave transforms for each rule engine and validate Cards and suggestions against the CDS Hooks and FHIR schemas.
- Run the conformance suite plus synthetic order-select and order-sign flows with Epic build and clinician informatics review.
Phase 3 — Production
- Enable one hook for one department behind a flag and monitor card-return and accept rates before widening.
- Expand hooks and departments incrementally, pruning rules whose Cards are never acted on.
Success metrics
- p95 and p99 invoke latency per hook against the declared budget
- Card-return rate and suggestion-accept rate per hook and per rule
- Rule-engine timeout and dead-letter rate
- SMART token cache hit ratio and token-exchange failure count
- Count of enabled hooks receiving zero invokes over a rolling window
Troubleshooting
- Hyperdrive shows no Cards even though the rule engine returns advice. — Likely cause: The invoke exceeded Epic's latency ceiling and the client discarded the late response. Fix: Measure per-stage latency by correlation id, parallelize prefetch and rule calls, and drop laggard engines so the response returns within budget.
- Accepting a suggestion in Epic produces no order or an error. — Likely cause: The suggestion action referenced a code or resource Epic could not resolve to an orderable. Fix: Map suggestion actions to Epic-recognized RxNorm or procedure codes and validate each action against the FHIR R4 profile before returning it.
- Intermittent 401s from the FHIR endpoint during prefetch fallback. — Likely cause: A cached SMART access token was reused past its effective expiry. Fix: Cache tokens keyed by scope with an expiry safety margin and refresh on a 401 rather than failing the invoke.
- Discovery works but a specific hook never fires from Epic. — Likely cause: The hook is not enabled for that department or the prefetch template does not match Epic configuration. Fix: Confirm the hook is enabled per department in Epic and reconcile the discovery prefetch template with Epic build; alert on enabled hooks with zero invokes.
Deliverable: A deployable MuleSoft CDS Hooks blueprint: a Process API implementing the discovery and invoke endpoints for order-select, order-sign, and patient-view hooks, with DataWeave transforms that build FHIR-shaped Cards, prefetch handling, SMART on FHIR token exchange, and an Anypoint MQ dead-letter path for failed rule evaluations.