Inspiration

Patient history is fragmented across hospitals, PDFs, discharge summaries, labs,
handwritten notes, and incompatible EHRs. Clinicians waste critical time just answering
one question: *"What actually happened to this patient over time?"* We built CareTrace
to answer that question automatically — turning a stack of disconnected documents into a
 coherent clinical story.

## What it does
CareTrace ingests multiple fragmented clinical documents (discharge summaries, lab
reports, referral notes, medication lists, radiology reports) and reconstructs a
complete longitudinal patient history. It produces a chronological clinical timeline, a
valid FHIR R4 Bundle with structured resources (Patient, Condition, MedicationStatement,
 Observation, Encounter, AllergyIntolerance), risk flags (medication gaps, missing
follow-ups, conflicting diagnoses, deteriorating trends), and a physician-ready
narrative summary — all propagated through SHARP context for multi-agent
interoperability.

## How we built it
- **MCP Server (FastMCP)** — 3 SHARP-enabled tools: `extract_medical_entities`, 
`build_fhir_bundle`, and `reconstruct_patient_timeline`, published to the Prompt Opinion
 Marketplace
- **LangGraph orchestration** — a 4-node graph (extract → FHIR build → timeline → post
to FHIR) running as a FastAPI backend
- **AI layer** — GitHub Models (`gpt-4o-mini`) for cloud deployments, with Ollama
(`llama3.2:3b`) as a local fallback for air-gapped/HIPAA environments
- **HAPI FHIR R4** — live FHIR resource storage and retrieval
- **Next.js frontend** — file upload, interactive timeline visualization, risk alerts
panel, and FHIR bundle viewer
- **Deployed** on HuggingFace Spaces (MCP + backend) and Vercel (frontend)

## Challenges we ran into
- Getting FHIR R4 validation right — dates from AI models come back as "July 22, 2024"
instead of ISO 8601, causing HAPI FHIR to reject the bundle. We built a date normalizer
that handles natural language dates, year-only values, and already-formatted strings.
- Avoiding double extraction — our LangGraph pipeline was calling the entity extractor
twice per document (once in the extract node, once inside
`reconstruct_patient_timeline`), multiplying inference time. We refactored to pass
already-extracted entities directly to the timeline node.
- MCP SSE transport behind proxies — the FastMCP SSE server rejected requests where the
Host header didn't match, which broke ngrok and HuggingFace Spaces routing. Fixed by
configuring uvicorn to serve the Starlette SSE app directly with proper host handling.
- SHARP extension compliance — Prompt Opinion's platform flags servers that don't declare FHIR extension support. We built SHARP context propagation (`patient_id`,
`fhir_base_url`) into all three MCP tool signatures.

## Accomplishments that we're proud of
- A single `reconstruct_patient_timeline` call takes 5 fragmented documents and returns
59 FHIR R4 resources, an 8-event chronological timeline, and a HIGH-severity renal
deterioration risk flag — all in under 60 seconds
- Full privacy toggle: one env variable (`AI_PROVIDER=ollama`) switches the entire stack
 to local inference with zero patient data leaving the machine — making it viable for
real HIPAA environments
- All 3 MCP tools discovered automatically by the Prompt Opinion platform on first
connection, with SHARP context flowing through every tool call
- End-to-end from raw clinical text to live FHIR server POST, with valid FHIR R4
transaction bundles

## What we learned
- LangGraph is well-suited for clinical workflows because state transitions map
naturally to clinical reasoning steps — extract, structure, analyze, store
- FHIR compliance is harder than it looks: value sets, date formats, and resource
references all have strict requirements that generic AI output routinely violates
- The MCP protocol makes healthcare tool composition genuinely practical — our tools can
 be picked up by any agent in the Prompt Opinion ecosystem without custom integration
work
- For healthcare AI demos, the "before and after" moment (5 disconnected documents → 1
coherent patient journey) is worth more than any technical detail

## What's next for CareTrace 
- **SHARP full compliance** — complete the Prompt Opinion FHIR extension spec so patient
 context flows automatically from EHR sessions
- **Streaming output** — pipe timeline events to the frontend token-by-token as they're
extracted, so clinicians see the story build in real time
- **Clinical Memory Graph** — evolve the timeline into a relationship graph (symptom
progression, medication evolution, encounter linkage) — essentially GitHub Copilot for
patient history
- **Missing context detection** — flag gaps like "insulin initiated but no diabetes
diagnosis documented" or "radiology finding with no follow-up order"
- **Multi-patient analytics** — aggregate anonymized timelines across a patient
population to surface cohort-level risk patterns 

Built With

Share this project:

Updates