Deploy an externally trained predictive model onto Epic so its scores render inside clinician workflow, using MuleSoft as the inference gateway, feature-assembly layer, and model-monitoring backbone Epic's native predictive tooling does not provide for third-party models.
Tags: healthcare, epic, ai, fhir, smart-on-fhir, analytics, api-led, event-driven
Deploying Predictive Models
Objective: A model trained outside Epic produces a useful score, but that score is worthless until it appears where the clinician decides. The problem is not the model math; it is the plumbing and governance: assembling the exact features the model expects from live Epic data, calling inference with sub-second latency inside a chart-open, writing the result back so it surfaces in Hyperdrive, and proving the deployed model still behaves like the validated one. Done looks like a score that renders at the moment of decision, backed by a monitored pipeline that logs every prediction, detects drift, and can be silenced without an Epic build change. This accelerator packages the Deploying Predictive Models Epic Data Sharing Playbook as a MuleSoft-anchored solution plan.
What's Getting Built
- Scoring Endpoint (Experience API) — implements the CDS Hooks contract and returns the score as a card or triggers writeback on chart open or order-select ·
GET /cds-services, POST /cds-services/{id}
- Feature Assembly (Process API) — assembles the model feature contract, calls the external inference endpoint within the latency budget, and orchestrates writeback ·
POST /score
- FHIR Read (System API) — reads Observation, Condition, MedicationRequest, and Encounter features and writes the score back as an Observation ·
GET /Observation, GET /Condition, GET /MedicationRequest, GET /Encounter, POST /Observation
- External Model Endpoint (target) — versioned inference service that returns the score from the assembled feature vector ·
POST /predict
- prediction-ledger (Object Store) — immutable log of every prediction with inputs, output, model version, and correlation ID for drift monitoring and audit ·
PUT /{correlationId}, GET /{correlationId}
- Drift Monitor (Scheduler) — computes feature and prediction-distribution drift against the validation baseline and alerts on absence of expected scoring events ·
SCHEDULER daily
Prerequisites
- Epic Cognitive Computing / predictive model configuration access, or a Best Practice Advisory build slot for surfacing scores in Hyperdrive
- SMART on FHIR backend OAuth 2.0 client with client_credentials and the FHIR R4 read scopes for every feature the model consumes (Observation, Condition, MedicationRequest, Encounter)
- The trained model exposed as a versioned inference endpoint with a documented feature contract input schema and output schema
- A signed model card and validation report per Epic and organizational AI governance, including the intended population and known contraindicated cohorts
- Anypoint Platform runtime with Object Store v2 or Anypoint MQ for the prediction ledger and dead-letter queue
- CDS Hooks service registration if scores are triggered on patient-view or order-select rather than batch
1. Epic interfaces and standards
This accelerator implements the Deploying Predictive Models Epic Data Sharing Playbook. Register the connecting app on Epic on FHIR and confirm the customer has the relevant Epic modules licensed before building.
- FHIR R4 Observation for writing the score back and Condition/MedicationRequest/Encounter for feature retrieval
- CDS Hooks patient-view and order-select for real-time invocation with a card carrying the score
- Hyperdrive Best Practice Advisory and predictive model score column for clinician-facing display
- Cogito and Caboodle for the retrospective feature warehouse and drift monitoring baselines
- SMART on FHIR backend services OAuth 2.0 for machine-to-machine authorization
- Bulk FHIR Group export for cohort backfill and periodic revalidation pulls
Architecture
2. Business requirements
- Name the decision the score changes: a sepsis score that no one is authorized to act on is a liability, not a feature.
- Fix the invocation trigger up front — patient-view chart open, order-select, or nightly batch — because it dictates the entire latency budget.
- Require a signed model card and intended-use population before writing a line of DataWeave; governance is a prerequisite, not a phase-two nicety.
- Define the silence path first: a documented way to suppress the score in production without an Epic build cycle.
- Set the success bar as clinician action taken on the score, not scores rendered, and instrument for it.
3. Feature assembly and the model contract
- Treat the model feature schema as a hard API contract; assemble every feature in a Process API from System API FHIR reads, never inline in the Experience layer.
- Map each feature to an explicit FHIR source — LOINC-coded Observation, active Condition, MedicationRequest — and pin the lookback window per feature.
- Handle missing features deterministically: impute, default, or refuse to score, and record which path was taken in the prediction ledger.
- Enforce unit and code normalization in DataWeave so a mmol/L versus mg/dL mismatch cannot silently corrupt an input.
- Version the feature-assembly transform alongside the model version; a retrained model with new inputs is a new deployment, not a config tweak.
4. Inference orchestration and writeback
- Call the external model endpoint from the Process API with a strict timeout inside the CDS Hooks latency budget, typically under 500 ms end to end.
- Attach a correlation ID spanning trigger, feature pull, inference call, and writeback so any single score is fully reconstructable.
- Write the score back as a FHIR Observation with the model version in a component or extension, or return it in a CDS Hooks card for patient-view.
- Never block chart open on inference; degrade to no card on timeout and log the miss rather than stalling Hyperdrive.
- Include the model version and feature-set hash on every writeback so a downstream chart review shows exactly which model produced the number.
5. Monitoring, drift, and rollback
- Log every prediction with inputs, output, model version, and timestamp to an immutable ledger; you cannot monitor what you did not persist.
- Compute feature drift and prediction-distribution drift against the validation baseline on a schedule, and alert when either exceeds threshold.
- Alert on the absence of expected scoring events, which is the failure mode dashboards miss most often when an upstream feature source goes quiet.
- Keep a runtime kill switch that suppresses writeback and cards instantly, decoupled from Epic build and from model retraining.
- Reconcile scores against outcomes periodically via Bulk FHIR export to Cogito, so calibration decay is caught before clinicians stop trusting the number.
6. 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.
- Bind the SMART backend client to the minimum FHIR scopes the feature set requires; a scoring pipeline should never hold write access it does not use for the Observation writeback.
- Sign and verify the model endpoint contract so a swapped or tampered model version cannot silently score patients.
- Persist the prediction ledger with PHI-appropriate encryption and retention, since inputs plus output constitute a clinical record subject to disclosure.
- Gate every model-version promotion behind AI governance sign-off and record the approving identity in the deployment ledger.
Sample payload — CDS Hooks patient-view request invoking the deployment
{
"hookInstance": "d1e4c2a0-9f3b-4a11-8b2e-7c6f5a2d1e90",
"hook": "patient-view",
"fhirServer": "https://fhir.epic.example.org/api/FHIR/R4",
"context": {
"userId": "Practitioner/e63bc1",
"patientId": "eXbY8pQ3"
},
"prefetch": {
"observations": {
"resourceType": "Bundle",
"type": "searchset",
"entry": [
{
"resource": {
"resourceType": "Observation",
"status": "final",
"code": { "coding": [ { "system": "http://loinc.org", "code": "6690-2", "display": "WBC" } ] },
"valueQuantity": { "value": 14.2, "unit": "10*3/uL" }
}
}
]
}
}
}
Testing and validation
- Validate the feature-assembly transform against the model's published input schema with contract tests before any live scoring.
- Replay a labeled validation cohort through the full MuleSoft pipeline and confirm scores match the offline model within tolerance to prove no transform drift.
- Load-test the Experience API at peak chart-open concurrency and assert the CDS Hooks latency budget holds at the tail, not just the median.
- Inject missing and malformed features to verify the deterministic missing-data path and that the pipeline never scores on silently defaulted inputs.
- Fire the kill switch in a non-production org and confirm scores stop rendering with no Epic build change and no stuck queue.
- Verify the Observation writeback carries the correct model version and feature-set hash and renders in the intended Hyperdrive column or BPA.
Phased rollout
Phase 1 — Connect
- Register the SMART backend client and confirm read scopes for every feature source in a non-production Epic org.
- Stand up the model endpoint behind the Process API and validate the feature contract with shadow reads, no writeback.
Phase 2 — Map and test
- Build and version the DataWeave feature-assembly transform and replay the validation cohort end to end.
- Run in shadow mode: compute and ledger scores without surfacing them, then reconcile against offline predictions.
Phase 3 — Production
- Enable writeback or CDS Hooks cards for one unit or service line with the kill switch and drift monitors live.
- Expand cohort only after calibration and clinician-action metrics hold, promoting model versions through governance sign-off.
Success metrics
- End-to-end scoring latency at p95 against the CDS Hooks budget
- Scoring coverage: percent of eligible encounters that received a score versus silently skipped
- Feature-drift and prediction-drift alerts raised versus baseline per week
- Clinician action rate on surfaced scores, the real adoption signal
- Calibration decay measured against reconciled outcomes over the monitoring window
Troubleshooting
- Live scores diverge from the offline-validated model on the same inputs. — Likely cause: The DataWeave feature-assembly transform normalizes units, codes, or lookback windows differently than the training pipeline. Fix: Pin the feature contract, add unit and LOINC normalization tests, and replay the validation cohort until live and offline scores match within tolerance.
- Scores stop appearing for a subset of patients with no error raised. — Likely cause: An upstream FHIR feature source went quiet and the pipeline defaulted the missing feature instead of refusing to score. Fix: Alert on absence of expected scoring events, and switch the missing-data path from silent default to explicit no-score with a ledger entry.
- Chart open in Hyperdrive stalls or the CDS card times out intermittently. — Likely cause: Inference is on the synchronous critical path and the model endpoint tail latency exceeds the hook budget. Fix: Enforce a strict Process API timeout, degrade to no card on timeout, and move heavy features to prefetch or a precomputed batch score.
- A retrained model is scoring production patients before governance approved it. — Likely cause: Model version promotion is not gated and the endpoint was updated in place. Fix: Require signed governance sign-off per version, record the approving identity in the deployment ledger, and reject unrecognized model-version hashes.
Deliverable: A MuleSoft inference gateway that assembles the model's feature contract from Epic FHIR R4, calls an external model endpoint within the CDS Hooks latency budget, writes scores back as versioned Observations or cards into Hyperdrive, and runs a prediction ledger with feature and prediction drift monitors plus a runtime kill switch decoupled from Epic build.