An experimental clinic inbox assistant inspired by the MedGemma Impact Challenge writeup. The goal of this project is to help clinicians manage patient portal messages by:
- Classifying messages by urgency and type
- Summarizing threads for clinician review
- Drafting safe, patient-friendly replies
- Surfacing red-flag content and escalation needs
This repository focuses on a local/self-hostable backend that can integrate with open medical models such as MedGemma, while keeping a clear human-in-the-loop workflow.
- FastAPI backend exposing an
/analyze_messageendpoint - Pluggable LLM client (start with any OpenAI-compatible model; later plug in MedGemma)
- Message analysis pipeline:
- Urgency classification
- Category tagging (clinical vs admin, refills, questions, etc.)
- Clinician-facing summary
- Draft patient reply
- Safety flags and escalation recommendation
- Python
- FastAPI
- Pydantic
- HTTPX (for calling model APIs)
-
Create and activate a virtual environment.
-
Install dependencies:
pip install -r requirements.txt
-
Set environment variables for your LLM provider (for example, an OpenAI-compatible endpoint).
-
Run the API locally:
uvicorn main:app --reload
-
Open the interactive docs at
http://127.0.0.1:8000/docs.
The backend expects an OpenAI-compatible chat completion endpoint. You can point it to:
- A hosted provider such as OpenAI, or
- Your own deployment of an open model (for example, MedGemma served via an OpenAI-style server).
Environment variables:
LLM_API_KEY(orOPENAI_API_KEY): API key for the model server (required).LLM_BASE_URL(orOPENAI_BASE_URL): Base URL of the API, e.g.https://api.openai.comor your own server.LLM_MODEL(orOPENAI_MODEL): Model name, e.g.gpt-4o-minior your MedGemma deployment name.
Example (PowerShell):
$env:LLM_API_KEY = "your-key-here"
$env:LLM_BASE_URL = "https://api.openai.com"
$env:LLM_MODEL = "gpt-4o-mini"Then open http://127.0.0.1:8000/docs and try POST /analyze_message.
{
"message": {
"message_id": "msg-123",
"patient_id": "patient-42",
"subject": "Chest pain today",
"body": "Hi doctor, I have had chest pain and shortness of breath for 2 hours...",
"previous_thread": null
}
}The response includes:
urgency:"routine" | "soon" | "urgent"categories: list of message categoriesclinician_summary: concise summary for the cliniciandraft_patient_reply: patient-facing draft replysafety_flags: list of safety flagsescalate: whether urgent clinician review is recommended
To use MedGemma, you would:
- Deploy a MedGemma model behind an OpenAI-compatible API (for example, using a gateway or serving framework).
- Point
LLM_BASE_URLto that deployment. - Set
LLM_MODELto the deployed model name.
No code changes in this repository should be needed; the OpenAICompatibleClient will send prompts to the configured endpoint.
This is an early prototype. The focus is on:
- Clear architecture for the inbox analysis pipeline
- Safety-oriented outputs and structured JSON responses
- Making it easy to later swap in MedGemma or other medical models without changing the API surface.