Inspiration

Emergency rooms are in crisis, not just from overcrowding, but from inequitable access. Patients who are uninsured, lack transportation, face language barriers, or are experiencing housing instability wait disproportionately longer, even when their clinical urgency is equal to that of more privileged patients. We wanted to build infrastructure that fixes this silently, at the point of triage, before a human even makes a decision.

What it does

MediMatch is a real-time ER patient-to-room matching platform that combines:

  • Equity-aware scoring: Patients are scored on both clinical urgency (ESI triage levels) and Social Determinants of Health (SDOH), insurance, transportation, housing, food security, language, employment, and income. Vulnerable patients with higher barrier scores are systematically prioritized alongside critically ill patients.

  • AI-powered triage: K2-Think (a medical reasoning model) analyzes each patient's symptoms to generate differential diagnoses, immediate action items, clinical summaries, and red-flag warnings—surfaced directly to the ER doctor.

  • Multi-agent care coordination: Once a patient accepts a room, Dedalus (an agentic AI with tool calling) executes a full coordination plan, analyzing SDOH barriers, assessing clinical urgency, allocating ER resources, and building a minute-by-minute care timeline.

  • Real-time cross-browser sync: Doctor logs in on one device, patient sees them automatically on another—using Firestore onSnapshot as a real-time sync channel.

  • Usage-based hospital billing: Hospitals subscribe and are billed per successful ER match via Flowglad, with automatic usage metering on the er-matches meter.

How we built it

The stack is React + Vite on the frontend, Firebase (Auth + Firestore) as the backend, and four external AI APIs:

  1. K2-Think-v2 (MBZUAI-IFM): Used for clinical reasoning. We built a custom JSON extractor to strip the model's internal blocks and reliably parse the final answer.

  2. Dedalus Labs: Used for agentic tool calling. The agent runs up to 6 loop iterations, calling our locally-defined tools (analyze_patient_sdoh, assess_clinical_urgency, allocate_er_resources, build_care_timeline) and accumulating results.

  3. Gemini: Used for urgency score inference when no explicit ESI level is available.

  4. Flowglad: Used for subscription checkout and per-match billing metering.

The Algorithm The matching algorithm weighs urgency, triage levels, and equity barriers using the following formula:

  • score = 4u + 1.5t + w + d + s + e + 0.5i

Where: u = urgency, t = triage level, w = wait days, d = ZIP proximity, s = specialty match, e = equity barriers, i = insurance match.

Challenges we ran into

  • Reasoning model output parsing: K2-Think outputs verbose reasoning chains with nested JSON before the final answer. We had to scan for the last balanced {} block in the entire response.

  • Cross-browser real-time demo: localStorage is profile-scoped; we solved doctor↔patient sync using Firestore demoSessions as the shared coordination layer.

  • Agentic tool call loops: Dedalus sometimes returned partial tool results—we implemented a merge strategy that fills missing fields from a deterministic fallback plan.

  • Billing idempotency: Workflow retries could double-charge hospitals; solved with match-scoped transactionId: match${matchId}_ for Flowglad deduplication.

What we learned

  • Multi-agent architectures with tool calling are powerful but require defensive fallback planning—LLMs don't always call every tool.

  • Real-time sync across browsers is trivial with Firestore onSnapshot once you stop relying on localStorage.

  • Equity-first algorithm design is a policy choice, not just a technical one—we had to explicitly decide which SDOH factors matter and how much.

Built With

Share this project:

Updates