Project Story: Care Coordination Discharge Planner

Inspiration

I've spent the past 10 years working in healthcare analytics — across large academic medical centers and startups applying AI to clinical workflows. The same pattern keeps appearing: complex regulatory requirements force clinicians to manually abstract the same information over and over, moving data from the health record to forms just to get a patient the care they've already been prescribed.

Discharge coordination is where that gap is widest. One in five Medicare patients is readmitted within 30 days — not because their clinical care was poor, but because the transition out of the hospital failed them [1]. These readmissions cost $26 billion annually, and CMS penalizes hospitals over $500 million per year for preventable returns [3]. Structured discharge planning can reduce readmission rates by 30%,[2] but it requires staffing most hospitals can't sustain.

The gap is absurdly concrete: a physician writes a detailed discharge summary — "patient is homebound, physical therapy 3x/week, refer to home health agency" — and that note sits unread while a case manager manually fills out the same information in a separate form, often getting it wrong or missing it entirely.

I built this because the last mile of healthcare deserves real engineering.


What It Does

The Care Coordination Discharge Planner automates the clinical and regulatory validation required to transition a patient from hospital to post-acute care and generates the Standard Written Orders to make it happen. One natural-language message in, a CMS-compliant order out. Six discharge use cases, each backed by a deterministic rules engine:

Use Case Regulatory Standard What It Catches
Home Oxygen Therapy CMS LCD E0424/E0431 O2 sat not ≤88%; missing qualifying diagnosis; test older than 91 days; invalid NPI
Medication Reconciliation ISMP High-Risk Drug Guidelines Allergy conflicts; dose changes; high-risk drugs without patient education
SNF Placement Medicare 3-Day Qualifying Stay Observation days miscounted; missing skilled need classification
Home Health Agency Referral 42 CFR § 409.42–409.44 Homebound status not established; no skilled need documented; face-to-face encounter missing
OPAT (IV Antibiotics at Home) CMS OPAT Guidelines Antibiotic not OPAT-eligible; no IV access confirmed; monitoring plan absent
Cardiac Rehabilitation CMS 42 CFR § 410.49 Qualifying event outside eligible timeframe; contraindications; incorrect session count

A clinical note scanner reads free-text physician notes and extracts structured clinical indicators using pattern matching — no LLM in the loop, no hallucination risk. When a physician writes "patient is homebound, PT 3x/week for 6 months," the system finds it and feeds it directly into the validation pipeline. This is what makes the Patricia Nguyen demo work: her structured FHIR record has no service requests at all, but the note scanner reads her discharge summary and finds the evidence that saves the referral.

Every order is produced in four formats simultaneously: machine-readable JSON, a FHIR R4 DocumentReference (importable into any EHR), a human-readable markdown summary for clinician review, and — for HHA referrals — a filled CMS-485 PDF (Home Health Certification and Plan of Care) populated with diagnoses from FHIR and discipline orders extracted directly from the discharge summary, ready for physician signature. The clinician's job goes from "fill out this form" to "verify this form."


How We Built It

The core principle: AI handles natural language and routing; deterministic code handles compliance.

Clinician / Discharge Coordinator
        ↓
Lead Orchestrator Agent  (Prompt Opinion A2A)
        ↓
Discharge Specialist Agent
        ↓
┌──────────────────────────────┐
│    MCP Server (FastMCP)      │
│  scan_clinical_notes         │  ← reads physician notes
│  list_discharge_use_cases    │
│  get_patient_context         │  ← FHIR R4 (HAPI sandbox + fixtures)
│  validate_discharge_order    │  ← deterministic CMS rules
│  generate_swo                │  ← JSON + FHIR DocumentReference
│                              │     + markdown + filled CMS-485 PDF
└──────────────────────────────┘
        ↓
Self-Registering Plugin Registry
(6 use cases, ~1,700 lines of clinical rules)

Tech stack: FastMCP 2.0 · Prompt Opinion A2A · Pydantic 2 · HAPI FHIR R4 · Python 3.11

Where GenAI earns its keep: The Lead Orchestrator and Discharge Specialist are A2A agents on Prompt Opinion. They do what rule-based software can't — parse a clinician's free-text request, resolve the patient, match the situation to a use case, decide which MCP tools to invoke and in what order, and explain the result in plain language. The rules engine and the form generator never make a clinical judgment; that's the agents' job. The agents never make a coverage determination; that's the rules engine's job. Each does what it's safe to do.

The plugin architecture is the decision we're most proud of: each discharge use case is a fully self-contained, auto-registering module. Adding a seventh use case requires zero changes to the MCP server or orchestration layer. Every validation finding maps directly to a CMS regulation, includes a rule ID, severity, and specific remediation steps.


Challenges We Ran Into

1. Structured data doesn't tell the whole story. The most clinically important discharge information — physician reasoning, explicit care plans, homebound determinations — lives in free-text notes, not structured FHIR resources. We built the note scanner to be precise and auditable: every pattern match is a deterministic regex grounded in a specific CMS rule citation, never an LLM inference.

2. The HAPI FHIR sandbox is shared and noisy. Synthetic-patient data gets wiped, observation dates are unreliable, and clinical notes are missing entirely. We built a fixture-fallback FHIR client that keeps the demo deterministic without giving up real R4 semantics — production deployments swap in a real EHR endpoint with no other code changes.

3. Regulatory rules are genuinely complex. The Medicare 3-day qualifying stay rule sounds simple until you discover that the admission day counts and the discharge day does not — a subtlety that determines SNF coverage eligibility. Getting these rules right meant reading the actual CMS Benefit Policy Manual, not summaries of it.

4. LLM hallucination in the tool-calling layer. The most surprising challenge had nothing to do with clinical logic: the model invented tools that don't exist. During live testing, the agent repeatedly called generate_discharge_order with complete confidence — fabricating the tool name, fabricating plausible arguments, failing silently. This is a real risk in multi-agent systems where the model's training creates strong priors about what tool names should sound like. We fixed it by explicitly enumerating every valid tool name in the server's system instructions, giving the agent a whitelist it must check against. In healthcare, an invented tool call isn't just a bug — it's a missed referral or a compliance gap that nobody notices until a patient is readmitted.


Accomplishments That We're Proud Of

  • 200 passing tests across all six use cases, including edge cases for every CMS rule.
  • The clinical note scanner surfaces physician reasoning from free-text notes and feeds it directly into the validation pipeline — making the system feel like it understands discharge medicine, not just form-filling.
  • Zero-hallucination compliance validation. Every finding is deterministic and traceable to a regulation. No LLM makes a coverage determination.
  • Four simultaneous output formats. One call produces machine-readable JSON, a valid FHIR R4 DocumentReference, a human-readable markdown summary, and — for HHA referrals — a filled CMS Form 485 PDF with Block 21 (Orders for Discipline and Treatments) pre-populated from the discharge-summary note. The clinician's job goes from "fill out this form" to "verify this form."
  • A plugin architecture that scales. Adding any new discharge use case is a new directory and one interface implementation — the core system never changes.
  • Deployed and reachable today. The MCP server runs as a containerized FastMCP app on Fly.io at https://discharge-coordinator-mcp.fly.dev/mcp. Every git push triggers a GitHub Actions build that redeploys in ~3 minutes. The filled CMS-485 PDFs are served through the same domain as a clickable download in the chat.

How to Test It

The system is live. Three paths, in increasing depth:

1. Watch the demo video (linked in the submission) for a 3-minute end-to-end walkthrough of the headline patient, Patricia Nguyen.

2. Invoke it on Prompt Opinion via our Marketplace listing: https://app.promptopinion.ai/marketplace/mcp/019cedd9-1276-7647-8e49-01cf723116d5

Send any of these messages to the Lead Orchestrator agent:

  • "Patricia Nguyen needs a home health referral" — the marquee demo: empty structured FHIR, note scanner extracts the evidence, system generates an approved referral and a clickable filled CMS Form 485 PDF.
  • "Carlos Martinez is going home on oxygen" — clean CMS LCD E0424 pass (O₂ sat 85%, qualifying COPD diagnosis, NPI on file).
  • "Robert Chen needs skilled nursing facility placement after hip surgery" — 4-day inpatient stay clears the Medicare 3-day qualifying rule.

3. Verify the MCP server directly:

curl -I https://discharge-coordinator-mcp.fly.dev/mcp
# HTTP/1.1 405 Method Not Allowed — FastMCP rejecting GET; route is alive.

What We Learned

The hardest part of healthcare AI is not the AI — it's drawing the boundary. Getting a model to understand a clinical scenario is tractable; getting it to produce output that's compliant, traceable, and safe enough to act on requires deterministic engineering. The rules engine is the most valuable thing we built. And the discharge summary turned out to be the dark matter of healthcare data — everywhere, rich, almost entirely unread by automated systems — which is what the note scanner is for.


What's Next

  • More use cases. Hospice election, palliative care, pediatric home care, wound VAC therapy — each is a new plugin, not a new system.
  • Real EHR integration. Epic, Cerner, and CommonWell all expose FHIR R4. The client is already built for this.
  • Close the readmission loop. Track 30-day follow-up (did home health start? was the SNF bed placed?) to turn this into a care-transition management system with measurable ROI.
  • Payer integration. Connect the validation output to payer APIs via Da Vinci Prior Auth — the clinical evidence we generate is already the evidence payers need.

Getting discharge right isn't niche. It's one of the most consequential unsolved problems in American healthcare, and it touches every hospital and every Medicare beneficiary who leaves one.


References

[1]: Jencks, S.F., Williams, M.V., & Coleman, E.A. (2009). Rehospitalizations among patients in the Medicare fee-for-service program. New England Journal of Medicine, 360(14), 1418–1428.

[2]: Hines, A.L., Barrett, M.L., Jiang, H.J., & Steiner, C.A. (2014). Conditions with the largest number of adult hospital readmissions by payer, 2011. AHRQ Statistical Brief #172.

[3]: U.S. Centers for Medicare & Medicaid Services. (2023). FY2024 Hospital Readmissions Reduction Program Supplemental Data File. CMS.gov.

Built With

Share this project:

Updates