A CDS Hooks blueprint that delivers Bayesian, pharmacokinetic model-driven dosing recommendations into the Epic prescribing workflow, calling a PK/PD engine with patient-specific labs and drug levels to return an individualized dose card at order entry.
Tags: healthcare, epic, smart-on-fhir, fhir, loinc, api-led, process-api, system-api
Bayesian Medication Dosing Decision Support
Objective: Prescribers ordering narrow-therapeutic-index drugs (vancomycin, aminoglycosides, warfarin, tacrolimus) default to weight-based nomograms that ignore renal trajectory, serum drug levels, and prior response, driving subtherapeutic troughs and toxicity. This blueprint wires a Bayesian pharmacokinetic engine into Epic order entry via CDS Hooks: on order open or sign, MuleSoft assembles the patient covariates, calls the PK service, and returns a dose, interval, and predicted trough as an inline card. Done looks like recommendations rendering under two seconds, every card reproducible from a logged input snapshot, and clinicians accepting a dose without leaving Hyperdrive. This accelerator packages the Bayesian Medication Dosing Decision Support Epic Data Sharing Playbook as a MuleSoft-anchored solution plan.
What's Getting Built
- CDS Hooks endpoint (Experience API) — implements the CDS Hooks discovery and per-drug-class dosing service that returns the inline dose card ·
GET /cds-services, POST /cds-services/{drug-class}
- dosing orchestration (Process API) — assembles patient covariates, invokes the PK engine, and builds the dose card with correlation-ID trace ·
POST /dose
- FHIR prefetch labs and meds (System API) — fallback FHIR reads for Patient, lab Observations, and active MedicationRequests when Epic omits a prefetch key ·
GET /Patient/{id}, GET /Observation, GET /MedicationRequest
- Bayesian PK engine (target) — MAP-Bayesian pharmacokinetic service returning dose, interval, and predicted trough for a drug model ·
POST /pk/recommend
- Epic FHIR R4 server (target) — source of Patient, Observation, MedicationRequest, and Condition resources via SMART backend services ·
GET /Patient/{id}, GET /Observation, GET /MedicationRequest, GET /Condition
- dead-letter queue (Anypoint MQ) — holds failed PK calls keyed by correlation ID for later replay and audit ·
PUBLISH failed-pk-call, CONSUME failed-pk-call
Prerequisites
- Epic CDS Hooks configured for medication-prescribe and order-sign hooks with the blueprint registered as an external service
- SMART on FHIR backend-services client (client_credentials) registered in the Epic App Orchard/Vendor Services with fhirUser and system scopes for Patient, Observation, MedicationRequest, and Condition
- Bayesian PK/PD engine (e.g. NONMEM-derived population models or a MAP-Bayesian microservice) reachable from Anypoint with documented drug model IDs
- Anypoint Platform with API Manager, a customer-hosted or CloudHub 2.0 runtime inside the covered-entity VPC, and Anypoint MQ for the dead-letter queue
- LOINC value sets for serum creatinine, drug assay levels, and albumin agreed with the Beaker/lab team
- Epic build for a custom order-adjustment SMART app link or native dose field prepopulation to accept the recommendation
1. Epic interfaces and standards
This accelerator implements the Bayesian Medication Dosing 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.
- CDS Hooks medication-prescribe and order-sign hooks
- SMART on FHIR backend services with FHIR R4 Patient, Observation, MedicationRequest, and Condition
- Hyperdrive/Hyperspace inline CDS cards
- Beaker serum drug-level and creatinine results via Observation
- LOINC-coded lab observations
Architecture
2. Business requirements
- Recommend dose and interval for narrow-therapeutic-index drugs at the moment of ordering, not as a retrospective pharmacy consult.
- Ground every recommendation in the patient's own serum drug levels and renal trajectory, not a fixed nomogram.
- Return the recommendation as an inline card the prescriber can accept without leaving the order.
- Show the predicted trough and the probability of hitting the therapeutic target so the clinician can judge the suggestion.
- Persist the exact model inputs behind each card so any recommendation can be reproduced and defended.
3. Ingestion and CDS Hooks contract
- Expose an Experience API that implements the CDS Hooks discovery endpoint and one service per drug class.
- Read the medication-prescribe context to get the draft MedicationRequest and the drug RxNorm code before any dose is signed.
- Declare a prefetch template for Patient, recent creatinine and drug-level Observations, and active MedicationRequests to avoid round-trips.
- Fall back to a FHIR System API call when Epic omits a prefetch key rather than failing the card.
- Reject hooks for drugs outside the configured model catalog with an empty card set, never an error.
4. Covariate assembly and PK invocation
- Use DataWeave to map FHIR Observations into the engine's covariate schema: weight in kg, SCr in mg/dL with draw timestamps, prior assay concentrations with sample times.
- Derive dosing history from active and recent MedicationRequests so the Bayesian prior is conditioned on actual administered doses.
- Attach the population model ID for the drug and the target (AUC24 for vancomycin, peak/trough for aminoglycosides).
- Pass a correlation ID from the hook through the PK call and into the returned card for end-to-end trace.
- Reject stale covariates: if the newest creatinine is older than the configured window, flag the card as low-confidence.
5. Card rendering and order adjustment
- Return a card with a suggestion action carrying a proposed MedicationRequest so Epic can prepopulate the dose field.
- Include the predicted trough or AUC and the target-attainment probability in the card detail text.
- Offer a SMART app launch link for the clinical pharmacist to inspect the full concentration-time curve.
- Set card indicator to warning when predicted exposure crosses the toxicity threshold, info otherwise.
- Never auto-sign an order; the blueprint proposes and the clinician disposes.
6. Error handling and operations
- Return an empty card set within the CDS Hooks timeout if the PK engine is slow, so ordering is never blocked.
- Route failed PK calls to an Anypoint MQ dead-letter queue keyed by correlation ID for later replay and audit.
- Alert on the absence of expected hook traffic during business hours, which is the failure mode dashboards miss most often.
- Log the full model input snapshot and returned recommendation, not just latency, for every card.
- Circuit-break the PK engine on repeated timeouts and degrade to a no-card response rather than a spinner.
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.
- Restrict CDS Hooks calls to Epic's published source IP ranges and validate the JWT in the Authorization header against Epic's JWKS before processing any hook.
- Treat model input snapshots as PHI at rest: encrypt the dead-letter queue and recommendation logs, and scope retention to the audit window.
- Bind the SMART backend token to system scopes only and rotate the client key on the covered entity's schedule.
- Do not return raw model parameters or other patients' data in card detail text; recommendations are per-patient and per-context.
Sample payload — CDS Hooks medication-prescribe request for vancomycin dosing
{
"hookInstance": "d1e8a2c4-9f3b-4a71-8c2e-7b5f0a1d2e3f",
"hook": "medication-prescribe",
"fhirServer": "https://epic.example.org/api/FHIR/R4",
"context": {
"patientId": "eXbQ2c8sample",
"medications": {
"resourceType": "Bundle",
"entry": [
{
"resource": {
"resourceType": "MedicationRequest",
"status": "draft",
"intent": "order",
"medicationCodeableConcept": {
"coding": [{ "system": "http://www.nlm.nih.gov/research/umls/rxnorm", "code": "11124", "display": "vancomycin" }]
},
"subject": { "reference": "Patient/eXbQ2c8sample" }
}
}
]
}
},
"prefetch": {
"scr": {
"resourceType": "Observation",
"code": { "coding": [{ "system": "http://loinc.org", "code": "2160-0", "display": "Creatinine" }] },
"valueQuantity": { "value": 1.4, "unit": "mg/dL" },
"effectiveDateTime": "2026-08-20T06:15:00Z"
},
"level": {
"resourceType": "Observation",
"code": { "coding": [{ "system": "http://loinc.org", "code": "20578-1", "display": "Vancomycin trough" }] },
"valueQuantity": { "value": 9.2, "unit": "ug/mL" },
"effectiveDateTime": "2026-08-20T05:50:00Z"
}
}
}
Testing and validation
- Unit-test the DataWeave covariate mapping against FHIR Observations with mixed units and missing draw times.
- Replay recorded medication-prescribe hooks against a mock PK engine and assert the card renders within the CDS Hooks timeout.
- Verify the suggestion action produces a MedicationRequest that Epic accepts and prepopulates in the order.
- Test the low-confidence path by feeding a stale creatinine and asserting the card flags reduced reliability.
- Confirm a PK-engine timeout yields an empty card set, a dead-letter entry, and an unblocked order.
- Validate JWT rejection: a hook with an absent or invalid Epic-signed token is refused before any FHIR read.
Phased rollout
Phase 1 — Connect
- Register the CDS Hooks discovery endpoint and SMART backend client in the Epic non-production environment.
- Confirm prefetch templates resolve and the PK engine is reachable from the Anypoint runtime inside the VPC.
Phase 2 — Map and test
- Map FHIR covariates to the engine schema for one drug (vancomycin) and validate against pharmacist-computed doses.
- Run recorded hooks through the full pipeline and reconcile predicted troughs with the reference PK tool.
Phase 3 — Production
- Enable the hook for a single unit and drug behind a feature flag, monitoring card latency and accept rate.
- Expand to additional drug models only after the acceptance and target-attainment metrics stabilize.
Success metrics
- p95 card latency at order-sign under 2 seconds
- Recommendation accept rate by drug and prescriber
- Therapeutic target attainment (AUC24 or trough in range) versus pre-blueprint baseline
- Percentage of cards flagged low-confidence due to stale covariates
- Dead-letter queue depth and PK-engine timeout rate
Troubleshooting
- Cards never appear when clinicians order vancomycin. — Likely cause: Epic prefetch keys did not resolve and the fallback FHIR System API scopes are missing the Observation read. Fix: Grant the backend client system/Observation.read, and add the FHIR fallback path so a missing prefetch key triggers a live query instead of a silent empty response.
- Predicted troughs are consistently off from the pharmacist reference tool. — Likely cause: Serum level draw timestamps are dropped in mapping, so the Bayesian posterior is conditioned on the wrong sample time. Fix: Preserve Observation.effectiveDateTime through the DataWeave transform and pass sample times with each concentration to the engine.
- Order signing occasionally hangs on a spinner. — Likely cause: The PK engine exceeded the CDS Hooks timeout and the service waited on it instead of returning. Fix: Add a hard client timeout below the hook timeout, circuit-break repeated failures, and return an empty card set while dead-lettering the call.
- A recommendation is disputed and cannot be reconstructed. — Likely cause: Only latency and status were logged, not the model inputs behind the card. Fix: Log the full covariate snapshot, model ID, and returned recommendation keyed by correlation ID for every card.
Deliverable: A deployable Anypoint API-led implementation (Experience API for CDS Hooks, Process API for dosing orchestration, System API for FHIR prefetch/fallback) with DataWeave covariate mappings, a Bayesian PK-engine connector, dead-letter and correlation-ID tracing, and Epic CDS Hooks and SMART backend registration artifacts for one reference drug model.