| title | Clinical Decision Support Agent β Powered by MedGemma | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| emoji | π₯ | ||||||||
| colorFrom | blue | ||||||||
| colorTo | green | ||||||||
| sdk | docker | ||||||||
| app_port | 7860 | ||||||||
| fullWidth | true | ||||||||
| tags |
|
An agentic clinical decision support system powered by MedGemma 27B that parses patient cases, generates differential diagnoses, checks drug interactions via FDA APIs, retrieves clinical guidelines, and detects care gaps β all in real time.
App demo: Available upon request
Video demo: Watch on YouTube
Origin: Built for the MedGemma Impact Challenge (Kaggle / Google Research).
A clinician pastes a patient case. The system automatically:
- Parses the free-text into structured patient data (demographics, vitals, labs, medications, history)
- Reasons about the case to generate a ranked differential diagnosis with chain-of-thought transparency
- Checks drug interactions against OpenFDA and RxNorm databases
- Retrieves clinical guidelines from a 62-guideline RAG corpus spanning 14 medical specialties
- Detects conflicts between guideline recommendations and the patient's actual data β surfacing omissions, contradictions, dosage concerns, and monitoring gaps
- Synthesizes everything into a structured CDS report with recommendations, warnings, conflicts, and citations
All six steps stream to the frontend in real time via WebSocket β the clinician sees each step execute live.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FRONTEND (Next.js 14 + React) β
β Patient Case Input β Agent Activity Feed β CDS Report View β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββ
β REST API + WebSocket
ββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββ β
β BACKEND (FastAPI + Python 3.10) β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β ORCHESTRATOR (6-Step Pipeline) β β
β ββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ¬ββββββ β
β ββββΌββββ βββββΌβββββ ββββΌββββ βββββΌβββββ βββββΌββββββ ββββΌβββββ β
β βParse β βReason β β Drug β β RAG β βConflict β βSynth- β β
β βPati- β β(LLM) β βCheck β βGuide- β βDetect- β βesize β β
β βent β βDiffer- β βOpenFDAββlines β βion β β(LLM) β β
β βData β βential β βRxNorm ββChromaDBβ β(LLM) β βReport β β
β ββββββββ ββββββββββ ββββββββ ββββββββββ βββββββββββ βββββββββ β
β β
β External: OpenFDA API β RxNorm/NLM API β ChromaDB (local) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
See docs/architecture.md for the full design document.
All 6 pipeline steps completed successfully:
| Step | Duration | Result |
|---|---|---|
| Parse Patient Data | 7.8 s | Structured profile extracted |
| Clinical Reasoning | 21.2 s | ACS correctly identified as top differential |
| Drug Interaction Check | 11.3 s | Interactions queried against OpenFDA / RxNorm |
| Guideline Retrieval (RAG) | 9.6 s | Relevant cardiology guidelines retrieved |
| Conflict Detection | ~5 s | Guideline vs patient data comparison for omissions, contradictions, monitoring gaps |
| Synthesis | 25.3 s | Comprehensive CDS report generated |
30 / 30 queries passed (100%) across all 14 specialties:
| Metric | Value |
|---|---|
| Queries tested | 30 |
| Pass rate | 100% (30/30) |
| Avg relevance score | 0.639 |
| Min relevance score | 0.519 |
| Max relevance score | 0.765 |
| Top-1 accuracy | 100% (correct guideline ranked #1 for every query) |
Full results: docs/test_results.md
22 comprehensive clinical scenarios covering: ACS, AFib, heart failure, stroke, sepsis, anaphylaxis, polytrauma, DKA, thyroid storm, adrenal crisis, massive PE, status asthmaticus, GI bleeding, pancreatitis, status epilepticus, meningitis, suicidal ideation, neonatal fever, pediatric dehydration, hyperkalemia, acetaminophen overdose, and elderly polypharmacy with falls.
A validation framework tests the pipeline against real-world clinical datasets:
| Dataset | Source | Cases Available | What It Tests |
|---|---|---|---|
| MedQA (USMLE) | HuggingFace | 1,273 | Diagnostic accuracy β does the top differential match the correct answer? |
| MTSamples | GitHub | ~5,000 | Parse quality & field completeness on real transcription notes |
| PMC Case Reports | PubMed E-utilities | Dynamic | Diagnostic accuracy on published case reports with known diagnoses |
Initial smoke test (3 MedQA cases): 100% parse success, 66.7% top-1 diagnostic accuracy.
50-case MedQA validation (MedGemma 27B via HF Endpoint):
| Metric | Value |
|---|---|
| Cases run | 50 |
| Pipeline success | 94% (47/50) |
| Top-1 diagnostic accuracy | 36% |
| Top-3 diagnostic accuracy | 38% |
| Differential accuracy | 10% |
| Mentioned in report | 38% |
| Avg pipeline time | 204 s/case |
Of the 50 cases, 36 were diagnostic questions β on those, 39% mentioned the correct diagnosis and 14% placed it in the differential.
See docs/test_results.md for full details and reproduction steps.
62 clinical guidelines across 14 medical specialties, stored in ChromaDB with sentence-transformer embeddings (all-MiniLM-L6-v2):
| Specialty | Count | Key Topics |
|---|---|---|
| Cardiology | 8 | HTN, chest pain / ACS, HF, AFib, lipids, NSTEMI, PE, valvular disease |
| Emergency Medicine | 10 | Stroke, sepsis, trauma, anaphylaxis, burns, ACLS, seizures, toxicology, hyperkalemia, acute abdomen |
| Endocrinology | 7 | DM management, DKA, thyroid, adrenal insufficiency, osteoporosis, hypoglycemia, hypercalcemia |
| Pulmonology | 4 | COPD, asthma, CAP, pleural effusion |
| Neurology | 4 | Epilepsy, migraine, MS, meningitis |
| Gastroenterology | 5 | Upper GI bleed, pancreatitis, cirrhosis, IBD, CRC screening |
| Infectious Disease | 5 | STIs, UTI, HIV, SSTIs, COVID-19 |
| Psychiatry | 4 | MDD, suicide risk, GAD, substance use |
| Pediatrics | 4 | Fever without source, asthma, dehydration, neonatal jaundice |
| Nephrology | 2 | CKD, AKI |
| Hematology | 2 | VTE, sickle cell |
| Rheumatology | 2 | RA, gout |
| OB/GYN | 2 | Hypertensive disorders of pregnancy, postpartum hemorrhage |
| Other | 3+ | Preventive medicine (USPSTF), perioperative cardiac risk, dermatology (melanoma) |
Sources include ACC/AHA, ADA, GOLD, GINA, IDSA, ACOG, AAN, APA, AAP, ACR, ASH, KDIGO, WHO, and other major guideline organizations.
medgemma_impact_challenge/
βββ README.md
βββ CLAUDE.md # AI assistant context
βββ DEVELOPMENT_LOG.md # Build history & decisions
βββ docs/
β βββ architecture.md # System architecture & design
β βββ test_results.md # Test results & benchmarks
β βββ deploy_medgemma_hf.md # HF Endpoint deployment guide
βββ src/
β βββ backend/
β β βββ requirements.txt
β β βββ test_e2e.py # End-to-end pipeline test
β β βββ test_clinical_cases.py # 22 clinical scenario test suite
β β βββ test_rag_quality.py # RAG retrieval quality tests
β β βββ validation/ # External dataset validation
β β β βββ harness_medqa.py # MedQA (USMLE) accuracy
β β β βββ harness_mtsamples.py # MTSamples parse quality
β β β βββ harness_pmc.py # PMC Case Reports accuracy
β β βββ tracks/ # Experimental pipeline variants
β β βββ app/
β β βββ main.py # FastAPI entry point
β β βββ config.py # Settings
β β βββ agent/orchestrator.py # 6-step pipeline orchestrator
β β βββ services/medgemma.py # LLM service (OpenAI-compatible)
β β βββ models/schemas.py # Pydantic data models
β β βββ tools/
β β β βββ patient_parser.py # Step 1: Free-text β structured data
β β β βββ clinical_reasoning.py # Step 2: Differential diagnosis
β β β βββ drug_interactions.py # Step 3: OpenFDA + RxNorm
β β β βββ guideline_retrieval.py # Step 4: RAG over ChromaDB
β β β βββ conflict_detection.py # Step 5: Guideline vs patient gaps
β β β βββ synthesis.py # Step 6: CDS report generation
β β βββ data/clinical_guidelines.json # 62 guidelines, 14 specialties
β β βββ api/ # REST + WebSocket endpoints
β βββ frontend/ # Next.js 14 + React 18 + TypeScript
β βββ src/
β βββ components/ # PatientInput, AgentPipeline, CDSReport
β βββ hooks/ # WebSocket state management
βββ Dockerfile # HuggingFace Spaces deployment
- Python 3.10+ (tested with Python 3.10)
- Node.js 18+ (tested with Node.js 18)
- API Key: HuggingFace API token (for MedGemma endpoint) or Google AI Studio API key
cd src/backend
# Create and activate virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # macOS/Linux
# Install dependencies
pip install -r requirements.txt
# Configure environment
copy .env.template .env # Windows (or: cp .env.template .env)
# Edit .env β set MEDGEMMA_API_KEY and MEDGEMMA_BASE_URL
# For HF Endpoints: see docs/deploy_medgemma_hf.md
# For Google AI Studio: set MEDGEMMA_API_KEY to your Google AI Studio key
# Start the backend
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000cd src/frontend
npm install
npm run dev
# Open http://localhost:3000Note: The frontend proxies API requests to the backend. If using a non-default port, update
next.config.jsandsrc/hooks/useAgentWebSocket.tsaccordingly.
cd src/backend
# RAG retrieval quality test (no backend needed)
python test_rag_quality.py --rebuild --verbose
# Full pipeline E2E test (requires running backend)
python test_e2e.py
# Comprehensive clinical test suite (requires running backend)
python test_clinical_cases.py --list # See all 22 cases
python test_clinical_cases.py --case em_sepsis # Run one case
python test_clinical_cases.py --specialty Cardio # Run by specialty
python test_clinical_cases.py # Run all cases
python test_clinical_cases.py --report results.json # Save results
# External dataset validation (no backend needed β calls orchestrator directly)
python -m validation.run_validation --fetch-only # Download datasets only
python -m validation.run_validation --medqa --max-cases 5 # 5 MedQA cases
python -m validation.run_validation --mtsamples --max-cases 5
python -m validation.run_validation --pmc --max-cases 5
python -m validation.run_validation --all --max-cases 10 # All 3 datasets- Open
http://localhost:3000 - Paste a patient case description (or click a sample case)
- Click "Analyze Patient Case"
- Watch the 6-step agent pipeline execute in real time
- Review the CDS report: differential diagnosis, drug warnings, conflicts & gaps, guideline recommendations, next steps
| Layer | Technology | Purpose |
|---|---|---|
| Frontend | Next.js 14, React 18, TypeScript, Tailwind CSS | Patient input, pipeline visualization, report display |
| API | FastAPI, WebSocket, Pydantic v2 | REST endpoints + real-time streaming |
| LLM | MedGemma 27B Text IT (via HuggingFace Dedicated Endpoint) | Clinical reasoning + synthesis |
| RAG | ChromaDB, sentence-transformers (all-MiniLM-L6-v2) | Clinical guideline retrieval |
| Drug Data | OpenFDA API, RxNorm / NLM API | Drug interactions, medication normalization |
| Validation | Pydantic | Structured output validation across all pipeline steps |
| External Validation | MedQA, MTSamples, PMC Case Reports | Diagnostic accuracy & parse quality benchmarking |
| Endpoint | Method | Description |
|---|---|---|
/api/health |
GET | Health check |
/api/cases/submit |
POST | Submit a patient case for analysis |
/api/cases/{case_id} |
GET | Get case results (poll for completion) |
/api/cases |
GET | List all cases |
/ws/agent |
WebSocket | Real-time pipeline step streaming |
curl -X POST http://localhost:8000/api/cases/submit \
-H "Content-Type: application/json" \
-d '{
"patient_text": "62yo male with crushing chest pain radiating to left arm...",
"include_drug_check": true,
"include_guidelines": true
}'| Document | Description |
|---|---|
| docs/architecture.md | System architecture, pipeline design, design decisions |
| docs/test_results.md | Detailed test results, RAG benchmarks, pipeline timing |
| docs/deploy_medgemma_hf.md | MedGemma HuggingFace Endpoint deployment guide |
| DEVELOPMENT_LOG.md | Chronological build history, problems solved, decisions made |
| CONTRIBUTING.md | How to contribute |
| SECURITY.md | Security policy and responsible disclosure |
Licensed under the Apache License 2.0.
This project uses MedGemma and other models from Google's Health AI Developer Foundations (HAI-DEF), subject to the HAI-DEF Terms of Use.
Disclaimer: This is a research / demonstration system. It is NOT a substitute for professional medical judgment. All clinical decisions must be made by qualified healthcare professionals.