Care Transitions Command

A FHIR-native care-transitions control plane that catches hidden note-level contradictions, converts them into evidence-linked blocking Tasks, and holds unsafe discharges until the clinical gate actually clears.

Track Platform Protocol
Full Agent: MCP + A2A Prompt Opinion A2A v1 / JSON-RPC 2.0 / FHIR R4

Inspiration

Discharge failure rarely comes from a missing summary. It comes from a contradiction that arrived too late, lived in the wrong layer, and never became explicit work.

The chart can look perfect: vitals stable, follow-up scheduled, medications reconciled. And discharge can still be unsafe because the real story changed after the structured snapshot:

  • A late nursing note documents orthopnea and weight gain that the morning assessment never captured.
  • A pharmacy note reveals the medication bridge is not actually available tonight.
  • A case-management addendum shows that the caregiver who was supposed to pick up the patient cannot come.

By the time these contradictions surface in normal workflow, the patient may already be in a cab home. The risk was never in the structured fields. It was in the narrative — and nobody converted that narrative into reviewable, trackable coordination work.

We built Care Transitions Command to change the control plane when that happens. Not to describe discharge better. To stop it when the evidence demands, write the blocking work into the EHR, and hold the gate until the EHR says the work is done.


What It Does

Care Transitions Command is a Prompt Opinion-native discharge control plane composed of three components:

  • Discharge Gatekeeper MCP — the deterministic structured discharge spine.
  • Clinical Intelligence MCP — bounded narrative contradiction intelligence.
  • External A2A orchestrator — synchronous prompt-level coordination across both.

Core primitive: Blocking evidence creates FHIR Tasks. Task completion opens the gate. The system holds discharge until the FHIR layer says otherwise.

Structured chart says READY
        |
        v
Clinical notes are checked anyway
        |
        v
Hidden contradiction found in late notes
        |
        v
Blocking FHIR Tasks are written
        |
        v
Discharge gate stays closed until Task.status resolves

The 4-Prompt Demo

Prompt 1 — "Is this patient safe to discharge today?"

The structured chart says ready. The system checks the notes anyway. A hidden contradiction surfaces. The final answer becomes not_ready.

Both postures are visible: the structured baseline that looked safe, and the narrative-grounded final status that changed it.

Prompt 2 — "What hidden risk changed that answer? Show me the contradiction and the evidence."

The system points to the exact nursing note, pharmacy note, and case-management addendum that broke the structured posture.

Citations are live FHIR DocumentReference IDs. Every finding has a source. Nothing is asserted without a note anchor.

Prompt 3 — "What exactly must happen before discharge, and prepare the transition package."

The contradiction becomes work:

  • Prioritized next steps with owners and timing.
  • A clinician handoff brief.
  • Patient-facing hold instructions.
  • Blocking FHIR Task resources.
  • Evidence links through reasonReference.
  • Recorded Provenance.

Prompt 4 — The re-arbitration moment

Some blocking Tasks have resolved. The system re-reads live Task.status.

Non-clinical gates clear. But clinical_stability is still open because orthopnea persists. The answer stays not_ready.

This is not a summarization tool. It is a control system with memory.


The Held-Out Demo Patient: Daniel Brooks

Daniel looks discharge-ready on every structured field: creatinine improved, oral diuretics entered, cardiology follow-up scheduled.

Then three late notes arrive:

  1. Pharmacy note, 18:15 — the medication bridge, sacubitril/valsartan, is not available tonight; prior authorization is pending until Monday; the patient has only two days of old stock at home.
  2. Nursing note, 18:40 — late orthopnea and 1.8 kg weight gain since the morning assessment.
  3. Case-management note, 19:05 — pickup logistics failure; no confirmed caregiver tonight.

The system escalates to not_ready, cites the contradiction, writes blocking FHIR Tasks, records Provenance chains, and refuses to clear discharge until clinical_stability resolves.

FHIR Tasks Written to the Prompt Opinion Workspace

Task ID Category Status
dd4c6f79-... clinical_stability requested
98f80645-... medication_reconciliation completed
3ed46a0f-... patient_education completed

At Prompt 4, medication access and patient education are resolved. Clinical stability is still open. The gate stays closed.


How It Works

Architecture

+------------------------------------------------------------------------+
|                         Prompt Opinion Workspace                       |
|                                                                        |
|   Clinician selects patient                                            |
|       -> BYO operator or A2A consult                                   |
|       -> Patient Scope + FHIR R4 context forwarded                     |
+------------------------------------+-----------------------------------+
                                     |
                                     | Patient Scope + FHIR Bearer token
                                     | Observations, Medications, Orders,
                                     | DocumentReferences, Encounters
                                     v
+------------------------------------------------------------------------+
|              Care Transitions Command: local runtime + ngrok           |
|                                                                        |
|  +-------------------------- A2A Orchestrator -----------------------+  |
|  |  JSON-RPC 2.0       Agent card        Task envelope               |  |
|  |  Prompt routing     12-row matrix     Re-arbitration loop         |  |
|  +------------+----------------+----------------------+--------------+  |
|               |                |                      |                 |
|               v                v                      v                 |
|      +----------------+  +-------------------+  +-------------------+   |
|      | Discharge      |  | Clinical          |  | FHIR Evidence     |   |
|      | Gatekeeper MCP |  | Intelligence MCP  |  | Ledger            |   |
|      +----------------+  +-------------------+  +-------------------+   |
|               |                |                      |                 |
|               v                v                      v                 |
|      Structured        Note contradiction      Task + Provenance        |
|      baseline          detection               write-back               |
|      deterministic     evidence-backed         workspace FHIR           |
+------------------------------------------------------------------------+
                                     ^
                                     |
                                     | FHIR R4 over Bearer token
                                     v
                 Prompt Opinion FHIR server, workspace-scoped

Component Responsibilities

Discharge Gatekeeper MCP

  • Computes the deterministic structured discharge posture from FHIR Observation, MedicationRequest, ServiceRequest, and Encounter resources.
  • Normalizes patient context against a canonical 8-category blocker taxonomy.
  • Emits provisional verdicts: ready, ready_with_caveats, or not_ready.
  • Never reasons over free-text notes; every output is deterministic.

Clinical Intelligence MCP

  • Reads narrative evidence from FHIR DocumentReference resources.
  • Detects contradictions against the structured baseline using bounded LLM reasoning.
  • Returns cited findings with explicit DocumentReference anchors.
  • Never fabricates hidden risk when no contradiction exists.
  • Returns no_hidden_risk for clean patients and insufficient_context when the narrative bundle is empty.

External A2A Orchestrator

  • Receives the Prompt Opinion prompt via synchronous JSON-RPC 2.0.
  • Calls Discharge Gatekeeper MCP first, then Clinical Intelligence MCP when note review is warranted.
  • Fuses deterministic and narrative evidence via a 12-row decision matrix into one user-visible reconciled answer.
  • Writes blocking FHIR Task resources with reasonReference links to the exact source documents.
  • Records Provenance chains from evidence to task.
  • Supports polling re-arbitration by re-reading live Task.status before changing a prior verdict.

The 12-Row Decision Matrix

The final verdict is not produced by the LLM. It is produced by a deterministic decision matrix that fuses the structured baseline and the hidden-risk finding.

Row Structured Baseline Hidden Risk Disposition Impact Final Verdict
1 ready no_hidden_risk none ready
2 ready hidden_risk_present caveat ready_with_caveats
3 ready hidden_risk_present not_ready not_ready
4 ready_with_caveats no_hidden_risk none ready_with_caveats
5 ready_with_caveats hidden_risk_present caveat ready_with_caveats
6 ready_with_caveats hidden_risk_present not_ready not_ready
7 not_ready no_hidden_risk none not_ready
8 not_ready hidden_risk_present caveat not_ready
9 not_ready hidden_risk_present not_ready not_ready
10 ready inconclusive uncertain ready_with_caveats
11 ready_with_caveats inconclusive uncertain ready_with_caveats
12 not_ready inconclusive uncertain not_ready

Row 3 is the canonical demo row: structured baseline ready, hidden risk present, disposition impact not_ready, final verdict not_ready.

Rows 10-12 require manual review because the narrative layer returned inconclusive.

Structured baseline:  ready
Hidden risk:          hidden_risk_present
Disposition impact:   not_ready
------------------------------------------------
Final verdict:        not_ready

Technology Stack

Layer Technology
Agent framework Model Context Protocol (MCP) SDK v1.25.1
Runtime TypeScript 5.8, Express 5.1, tsx 4.19
Schema validation Zod 4.2
FHIR client @smile-cdr/fhirts 2.3.0 + native FHIR R4 REST
Auth / tokens jose 6.0 for JWT and Bearer token handling
Protocol A2A v1 over JSON-RPC 2.0, synchronous, no streaming
Context propagation Prompt Opinion Patient Scope + FHIR R4 Bearer token
LLM, primary Gemma 4 31B-IT via Google AI Studio API
LLM, alternative Gemini 3.1 Flash-Lite, configurable via CLINICAL_INTELLIGENCE_GOOGLE_MODEL
Hosting Local runtimes exposed via ngrok
User-facing surface Prompt Opinion workspace
Evidence layer FHIR R4 Task, Provenance, and DocumentReference

Note on LLM Configuration

The Clinical Intelligence MCP selects its reasoning model via the CLINICAL_INTELLIGENCE_GOOGLE_MODEL environment variable.

The default is gemma-4-31b-it, accessed through the Google AI Studio API. The codebase also supports gemini-3.1-flash-lite and the Gemini 3.x family, with tuned thinkingLevel and thinkingBudget generation configs per model family.

When no API key is present, the system falls back to a deterministic heuristic provider so that smoke checks remain runnable without credentials.

The LLM is only used by the Clinical Intelligence MCP. All structured baseline logic in the Discharge Gatekeeper MCP and all FHIR write-back in the orchestrator are fully deterministic.


What Only Generative AI Can Do Here

A rules engine can check whether SpO2 is below 90%. It cannot read a free-text nursing note and understand that "patient became visibly dyspneic after six stairs" contradicts the structured resting SpO2 of 94%.

It cannot connect that note to the case-management addendum stating "oxygen vendor cannot deliver until tomorrow morning" and produce the insight that discharge home tonight is unsafe for three separate reasons.

It also cannot handle every possible note-writing style, every possible combination of late-arriving documents, and every possible clinical scenario without pre-enumerating every cross-product by hand.

Care Transitions Command's generative AI layer does three things rule-based software cannot:

  1. Unstructured narrative -> structured clinical contradiction. Nursing notes, pharmacy clarifications, and case-management addenda are free-text documents written by humans for humans, in wildly varying styles. The model extracts the specific claim that contradicts the structured baseline and maps it to a canonical blocker category.

  2. Open-ended evidence composition. The Clinical Intelligence MCP decides which notes to read, when a contradiction is strong enough to escalate, when evidence is inconclusive and should return manual_review_required, and how to compose the contradiction summary — all at runtime, given the patient's actual documents.

  3. Cross-layer synthesis at the patient level. The signature insight — "the structured chart said ready, but this nursing note changes the answer" — emerges from joining two independent data sources at inference time: deterministic structured posture and narrative contradiction. Connecting them into a single coherent clinical narrative with evidence citations is reasoning, not lookup.


What Is Deterministic vs. What Is LLM-Based

The deterministic layer exists because generative AI should not invent discharge blockers, fabricate evidence, or hallucinate FHIR resources. It is a safety and credibility choice, not an absence of AI.

Layer Responsibilities
Deterministic Structured patient-context normalization; canonical blocker taxonomy and severity scoring; 12-row verdict fusion matrix; FHIR Task resource drafting with deterministic UUIDv5 generation; Provenance chain construction; re-arbitration polling logic; red-flag rule evaluation against structured observations.
LLM, bounded Free-text note interpretation and contradiction detection; evidence-to-blocker mapping from narrative content; plain-language contradiction summaries; clinician handoff brief composition; patient-facing discharge instruction generation.

Every clinical claim has a DocumentReference anchor. The model's job is to read unstructured input, identify which contradictions matter, reason across the structured outputs, and write the result.

A rules engine cannot do that at the open-ended scope this clinical workflow demands.


How a Request Flows

1. Clinician opens Prompt Opinion and selects a patient
        |
        v
2. Prompt Opinion forwards Patient Scope + FHIR context
        |
        v
3. Orchestrator calls Discharge Gatekeeper MCP
        |
        v
4. Structured baseline is computed
        |
        v
5. If note review is warranted, Clinical Intelligence MCP reads notes
        |
        v
6. Narrative contradictions are mapped to evidence anchors
        |
        v
7. The 12-row matrix fuses structured + narrative posture
        |
        v
8. If not_ready, blocking FHIR Tasks are drafted and written
        |
        v
9. Provenance chains link evidence -> task -> verdict
        |
        v
10. On re-arbitration, live Task.status is re-read before the gate changes

A single discharge assessment completes in under 30 seconds against the live Prompt Opinion FHIR workspace.


Challenges We Ran Into

A2A v1 Dialect Mismatch

The platform's A2A v1 validation expects a rich agent card with a public URL, protocol version, non-empty skills, and text/plain modes.

Our initial sparse card produced a hard 422 during Prompt Opinion external-agent validation.

Fix: a complete agent-card generator that exposes all required fields and keeps the runtime compatible with platform validation. We also confirmed that Prompt Opinion routes external A2A calls to the interface URI advertised on the card, not the card's base URL, so the interface URI must end at the correct message endpoint, such as /message:send.

FHIR Context Alignment Across Three Runtimes

Prompt Opinion Patient Scope, MCP tool bindings, and visible chat transcripts had to stay aligned across Discharge Gatekeeper MCP, Clinical Intelligence MCP, and the external A2A orchestrator.

Any drift produced silent failures where the tool executed but the transcript showed no result.

Fix: explicit request-id correlation logging and smoke checks that verify end-to-end evidence persistence.

Held-Out Demo Patient vs. Regression Trap

The natural instinct is to build the demo around the patient whose notes you hand-curated until the demo works.

We forced a held-out Daniel Brooks lane: his notes were never edited to make the contradiction more dramatic, and his structured baseline was never tweaked to make the flip more obvious.

If the system works on Daniel, it works on any patient with a real contradiction. If it only works on Maria, it is a demo hack.

FHIR Write-Back Honesty

We could have claimed "we integrate with Epic" or "we use FHIR Subscriptions."

We do not.

We write real Task and Provenance resources to Prompt Opinion's workspace FHIR server. We document exactly which resource shapes the platform accepts and which it currently rejects.

AuditEvent write shape is stricter than our current output; local proof remains green, but the live path for AuditEvent is not claimed.

We use polling re-arbitration instead of asserting webhook behavior we cannot demonstrate to a judge in real time.

Stale ngrok and Runtime State

During repeated live proof sessions, tunnel URLs changed, MCP registrations became stale, and smoke checks passed locally while the workspace saw stale tool definitions.

Fix: a full bootstrap-and-registration script that tears down and rebuilds the Prompt Opinion connection before every judged session.


Accomplishments We Are Proud Of

  • A held-out live demo patient, Daniel Brooks, whose contradiction lane writes real Prompt Opinion Task and Provenance artifacts — no demo hacks, no hand-tuned notes.
  • A clean control patient, Olivia Chen, who stays ready, triggers zero blocking Tasks, and proves the system does not force escalation when no contradiction exists.
  • A Prompt 4 re-arbitration path that re-reads live Task.status and still refuses to clear discharge when clinical_stability is unresolved — proving the system has durable state grounded in FHIR, not just in the conversation thread.
  • A scenario-matrix safety case, Eleanor Singh, for mobility, fall risk, and home-support failure — showing the contradiction pattern generalizes beyond cardiac and respiratory presentations.
  • A deterministic + LLM hybrid where every FHIR resource shape is hardcoded and every contradiction finding has a DocumentReference citation. The model advises; the deterministic layer decides and writes.
  • A direct Prompt Opinion BYO lane and an A2A architecture lane that both stay inspectable and honest about which is primary and which is fallback, with wire-level evidence proving the A2A runtime correctly returns a compact completed task to Prompt Opinion.

What We Learned

The most credible healthcare AI moment is not "better summarization." It is contradiction detection with bounded evidence, explicit citations, and a verdict that changes because of what the model found — not because of what the model was told to say.

The product becomes more real when evidence changes the coordination state. A model that explains why discharge should be held is useful. A system that writes a FHIR Task, links it to the evidence, and refuses to clear discharge until that Task completes is a control plane.

Polling re-arbitration is a more honest proof primitive than claiming live webhook or FHIR Subscription behavior we cannot demonstrate to a judge in real time.

Platform constraints are not bugs to hide. Prompt Opinion's workspace FHIR server rejects certain AuditEvent shapes. We document that honestly, keep local AuditEvent proof green, and do not pretend the live path is more complete than it is.

Single coherent system, multiple skills wins. A previous architecture exploration had us considering streaming multi-agent choreography with more components. The winning simplification was: two MCPs with sharp boundaries, one synchronous orchestrator, one patient at a time.


What's Next for Care Transitions Command

  • Native marketplace publication. When Prompt Opinion enables publishing for this subscription tier, publish both MCPs with clear identity boundaries and the A2A orchestrator as the preferred assembled-agent path.

  • Persistent task memory across sessions. Each consult is currently a fresh run. A clinical-grade version should track day-over-day task resolution and surface trend alerts when blockers stall for too long.

  • Expanded procedure and specialty coverage. The current blocker taxonomy covers general medicine. A clinical-grade version would partner with hospital medicine and surgical teams on specialty-specific contradiction patterns.

  • Native FHIR ServiceRequest output. Today the drafter emits Task + Provenance. A production version would also draft ServiceRequest for follow-up imaging, Appointment for re-review, and Communication for patient-facing alerts.

  • Clinical validation. A prospective observational study comparing standard discharge planning against Care Transitions Command-augmented review on patients with late-arriving narrative documentation, targeting readmission rates and time-to-discharge-hold.


Safety, Privacy, and Feasibility

Synthetic data by design for the hackathon; production-ready for real FHIR. Demo patients are hand-built FHIR R4 transaction bundles so the project complies with the no-PHI requirement. The same agent code runs unchanged against a real institutional FHIR server: it speaks FHIR R4 over Bearer token, the protocol modern EHRs expose. Scaling from four synthetic patients to a real hospital service is a deployment configuration change, not an architecture change.

Decision support, not autonomous discharge. Every blocking Task carries status="requested", not completed. Every drafted resource carries review_required: true. A licensed clinician must approve before anything reaches finality.

Defers to the care team. Patient-facing language never says "you cannot leave." It says "contact your care team before discharge."

Boundaries on scope. The system classifies severity and recommends actions. It does not diagnose, it does not order, and it does not auto-message patients. It is a specialist consult invoked by a clinician, scoped to a single workspace and a single patient at a time.

Compliance posture. Prompt Opinion Patient Scope means the agent operates entirely under the workspace's existing FHIR authorization. Credentials are never stored, patient data is never persisted between requests, and the FHIR Bearer token is request-scoped. That posture is HIPAA- and GDPR-compatible by construction.

Feasibility in a real healthcare system. The technical plumbing — FHIR R4, deterministic discharge rules, MCP-based tool composition, and A2A v1 synchronous orchestration — is production-grade and already standard at institutions with active interoperability programs. The agent layer adds the integrative reasoning that does not exist between those primitives today. The path from this submission to a clinical pilot is a validation and procurement conversation, not a re-architecture.


Proof Artifacts

Artifact Location
Endgame audit output/endgame/runs/20260510T101519Z/final-endgame-audit.md
FHIR consolidation proof output/endgame/runs/20260510T160443Z-fhir-consolidation/
Daniel full browser proof, P1-P4 output/playwright/20260510T-final-daniel-p1-p4-autoprep/
Olivia clean control output/playwright/20260510T-final-olivia-p1-longwait/
A2A consult proof output/playwright/20260510T-final-a2a-vc-longwait/

Patient Lanes

  • Daniel Brooks — held-out live demo patient. Structured ready -> note contradiction -> not_ready -> blocking Tasks -> Prompt 4 re-arbitration still holds.
  • Olivia Chen — clean control. ready, no_hidden_risk, zero blocking Tasks written.
  • Eleanor Singh — scenario-matrix safety case. not_ready with mobility, fall, and home-support failure.
  • Maria Alvarez — regression trap. COPD exacerbation; SpO2 94% at rest drops to 82% on exertion; oxygen delivery delayed; daughter unavailable overnight; contradiction remains conservative and avoids Daniel bleed.

Scenario Evidence Matrix

Scenario Baseline Narrative Final What It Proves
Maria trap patient ready hidden_risk_present not_ready Structured ready becomes not_ready when late nursing and case-management notes expose transition blockers.
Maria ablation control ready no_hidden_risk ready Removing contradiction notes prevents escalation.
Clean no-risk control ready no_hidden_risk ready Reassuring narrative does not fabricate hidden risk.
Duplicate-signal control ready_with_caveats no_hidden_risk ready_with_caveats Narrative signals already present in deterministic blockers are suppressed, not double-counted.
Inconclusive or missing narrative ready inconclusive ready_with_caveats Missing evidence triggers manual_review without fabricated escalation.
Alternative home-support risk ready hidden_risk_present not_ready A non-respiratory social support contradiction can still change transition status.
Medication access hidden risk ready hidden_risk_present not_ready Detector is not hardcoded to oxygen or stairs; blocked anticoagulation access can independently stop discharge.

Built With

TypeScript · Model Context Protocol (MCP) · A2A v1 / JSON-RPC 2.0 · FHIR R4 · Zod · Express 5 · Gemma 4 31B-IT · Gemini 3.1 Flash-Lite · Google AI Studio API · Prompt Opinion Patient Scope · ngrok · @smile-cdr/fhirts · jose


Care Transitions Command is decision support, not autonomous discharge authority.

Every finding cites a source. Every gate has an owner. Every verdict is reviewable by a clinician.

Built With

Share this project:

Updates