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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CliniqAI β Clinical Operations AI for Indian Hospitals
|
| 2 |
+
|
| 3 |
+
> Giving doctors and nurses back the hours they lose to paperwork, so they can spend that time on patients.
|
| 4 |
+
|
| 5 |
+
Built for the **[Hugging Face "Build Small" Hackathon](https://huggingface.co/build-small-hackathon)** β a suite of small, open, β€32B models doing real hospital back-office work, with a human approving every decision that touches a patient.
|
| 6 |
+
|
| 7 |
+
> **Status note:** This README describes **what actually runs today**, verified against the code and test suite. The original planning document (which scoped only 3 agents as "shipping") is preserved as **[`README_OLD.md`](README_OLD.md)** for pitch/historical context. Since then, **all seven agents have been implemented.**
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
## The Problem
|
| 12 |
+
|
| 13 |
+
Indian doctors spend **2β3 hours every day** on documentation. Nurses build duty rosters by hand over half a day. Receptionists book appointments by phone. Patients leave **4β6 hours late** because pharmacy, billing, and family hand-offs all wait on each other.
|
| 14 |
+
|
| 15 |
+
None of this needs medical judgment. It is mechanical, repetitive, and automatable β and that is exactly the layer CliniqAI takes over, while clinicians stay in control of every clinical call.
|
| 16 |
+
|
| 17 |
+
**The design rule:** *Agents prepare. Humans decide.* No agent sends or files anything patient-facing without explicit human approval.
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
## What the App Is
|
| 22 |
+
|
| 23 |
+
A single **Gradio** web app with three role-based consoles, backed by a **FastAPI** service and a **LangGraph** multi-agent orchestrator. Seven agents share one typed state object and return validated **Pydantic** outputs, so everything is parseable, logged, and auditable.
|
| 24 |
+
|
| 25 |
+
```
|
| 26 |
+
Doctor console Patient console Nurse & Admin console
|
| 27 |
+
β β β
|
| 28 |
+
ββββββββββββββββ¬ββββββββ΄βββββββββββββ¬ββββββββββββ
|
| 29 |
+
βΌ βΌ
|
| 30 |
+
FastAPI ββββββββΊ LangGraph Orchestrator
|
| 31 |
+
β
|
| 32 |
+
ββββββββββββ¬ββββββββββββ¬βββββββββββ¬βββββββββββββ¬ββββββββββββ¬βββββββββββ
|
| 33 |
+
Documentation Appointment Roster Handover Discharge Clerical Wiki
|
| 34 |
+
βΌ βΌ βΌ βΌ βΌ βΌ βΌ
|
| 35 |
+
Retrieval (Chroma + BM25) Β· PostgreSQL Β· LLM router (Groq / OpenRouter / Ollama)
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## What Actually Works Today
|
| 41 |
+
|
| 42 |
+
Legend: β
working & demoable Β· π‘ works, needs an API key / external creds to go fully live Β· βοΈ wired, depends on a build/seed step
|
| 43 |
+
|
| 44 |
+
| Capability | Status | Notes |
|
| 45 |
+
|---|---|---|
|
| 46 |
+
| **Doctor console β SOAP documentation** | β
| Paste a transcript (or record audio), get an editable SOAP draft with ICD-10 suggestions + citations, edit, then **Approve** to write it to the patient's wiki page. Falls back to a realistic **mock draft** if no LLM key is set, so it always demos. |
|
| 47 |
+
| **Audio transcription (Whisper)** | π‘ | Groq-hosted `whisper-large-v3-turbo`; needs `GROQ_API_KEY`. Transcript paste works with no key. |
|
| 48 |
+
| **Patient console β appointment chat** | β
| Chat widget routes to the Appointment Agent: parses intent, finds a free slot, books it, and replies with a confirmation + 1/2/0 confirm-reschedule-cancel flow. |
|
| 49 |
+
| **Appointment booking + reminders** | β
| Slot-finding over a calendar; queues T-24h email + chat reminders via Celery. Uses a **local calendar fallback** so it runs offline. |
|
| 50 |
+
| **Nurse β shift handover brief** | β
| Generates a prioritised ward brief (urgent β watch β stable) with per-patient one-liners and pending actions. |
|
| 51 |
+
| **Admin β duty rostering** | β
| Greedy 14-day roster from a staff CSV (or demo data) in well under a second, with a fairness score; plus same-role, lowest-load **sick-call replacement**. |
|
| 52 |
+
| **Nurse β discharge coordination** | β
| Fans out **5 subtasks in parallel** (summary, pharmacy, family notify, follow-up booking, billing) and reports each one's status; failures are isolated. |
|
| 53 |
+
| **Wiki health β lint report** | β
| One click runs `lint_wiki()` over the public corpus: missing frontmatter, stale pages (>180d), broken `[[cross-refs]]`. Currently **0 issues** across the seeded corpus. |
|
| 54 |
+
| **Orchestrator routing** | β
| LangGraph state graph routes each request to the right agent (6 agent nodes + orchestrator). |
|
| 55 |
+
| **Knowledge retrieval (Chroma + BM25)** | βοΈ | Hybrid search is wired behind one `search()` API; populate the index with `scripts/build_indices.py`. |
|
| 56 |
+
| **LLM routing** | β
| LiteLLM picks Groq / OpenRouter / Ollama per task; degrades to mocks when no provider is configured. |
|
| 57 |
+
| **Patient notifications (Telegram / WhatsApp)** | π‘ | Telegram (free Bot API) and WhatsApp (Twilio) send paths exist; both no-op safely to a stub until credentials are set, so nothing crashes in a dry run. |
|
| 58 |
+
| **Observability (Langfuse)** | π‘ | LLM + retrieval calls are traced when Langfuse keys are present. |
|
| 59 |
+
|
| 60 |
+
### Agents β all seven implemented
|
| 61 |
+
|
| 62 |
+
| Agent | Does |
|
| 63 |
+
|---|---|
|
| 64 |
+
| **Documentation** | Transcript β retrieves patient history + guidelines + ICD-10 β drafts a SOAP note with citations β writes to the patient wiki on approval. |
|
| 65 |
+
| **Appointment** | Parses booking/cancel/reschedule intent, checks availability, books, confirms, and schedules reminders. |
|
| 66 |
+
| **Rostering** | Builds a fair 14-day roster from a CSV; resolves sick calls in real time. |
|
| 67 |
+
| **Handover** | Produces a prioritised end-of-shift patient brief. |
|
| 68 |
+
| **Discharge** | Coordinates the 5-stream discharge fan-out in parallel. |
|
| 69 |
+
| **Clerical** | Drafts referral letters and post-visit summaries (human-approved). |
|
| 70 |
+
| **Wiki Maintenance** | Updates patient pages and lints the knowledge corpus for staleness / broken links. |
|
| 71 |
+
|
| 72 |
+
---
|
| 73 |
+
|
| 74 |
+
## How It Works
|
| 75 |
+
|
| 76 |
+
### 1. The knowledge layer β wiki + RAG, not just chunks
|
| 77 |
+
CliniqAI follows the **LLM-Wiki** pattern: structured markdown pages (one per patient, drug, condition, protocol) that the system keeps current and cross-linked, instead of blindly chunking documents. When a guideline changes you update the page and mark the old content superseded β so the next query reads a clean synthesis, not a blend of old and new. Large reference data (ICD-10 codes, formularies) lives in a **Chroma + BM25 hybrid index** for keyword-precise lookup. Structured operational data (appointments, rosters) lives in **PostgreSQL**.
|
| 78 |
+
|
| 79 |
+
### 2. The orchestration layer β typed, auditable agents
|
| 80 |
+
Every request enters the **LangGraph** graph, the orchestrator classifies it, and it flows to the owning agent. Each agent returns a validated Pydantic model (`SOAPNoteDraft`, `BookingResult`, `RosterResult`, `HandoverBrief`, `DischargeCoordination`, `CommunicationDraft`, β¦). State updates follow strict rules β lists append, scalars overwrite, no node mutates shared state directly.
|
| 81 |
+
|
| 82 |
+
### 3. The model layer β small, open, swappable
|
| 83 |
+
Tasks are routed by **LiteLLM**: heavy reasoning (SOAP notes, handover, discharge summaries) β a 32B-class model on **Groq**; high-frequency simple replies β a fast 8B model; offline β **Ollama** locally. Every model in the routing table is free and **β€32B parameters** β the spirit of the Build Small hackathon. If no provider is configured, the app serves realistic mocks so the UI still demos end-to-end.
|
| 84 |
+
|
| 85 |
+
### 4. The safety layer
|
| 86 |
+
Every clinical output is traceable to a source page or guideline, nothing patient-facing is sent without human approval, and all agent actions are traceable via Langfuse.
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## Why It's Beneficial
|
| 91 |
+
|
| 92 |
+
Carried forward from the original product thesis β these are the targets the workflows are built to hit:
|
| 93 |
+
|
| 94 |
+
| Workflow | Today (manual) | With CliniqAI |
|
| 95 |
+
|---|---|---|
|
| 96 |
+
| SOAP note sign-off | 8β10 min/consult | **< 90 sec** review-and-approve |
|
| 97 |
+
| Duty roster generation | 3β5 hours | **< 5 min** (sub-second in practice) |
|
| 98 |
+
| Sick-call replacement | 30β60 min | **< 15 min** |
|
| 99 |
+
| Discharge β patient leaves | 4β6 hours | **< 1.5 hours** (parallel fan-out) |
|
| 100 |
+
| No-show rate | 15β20% | **< 8%** (reminders + waitlist) |
|
| 101 |
+
|
| 102 |
+
The compounding win: a doctor reclaiming ~2 hours/day is the equivalent of adding clinical capacity **without hiring** β the most expensive constraint in Indian healthcare β while the patient experience (faster discharge, fewer missed appointments, clearer summaries) improves at the same time.
|
| 103 |
+
|
| 104 |
+
---
|
| 105 |
+
|
| 106 |
+
## Demo / Run It Locally
|
| 107 |
+
|
| 108 |
+
**Prereqs:** Docker (for Postgres/Redis), and [`uv`](https://docs.astral.sh/uv/). The app runs with **no API keys** thanks to mock fallbacks; add keys to `.env.local` to go fully live.
|
| 109 |
+
|
| 110 |
+
```bash
|
| 111 |
+
# 1. Install deps into the uv-managed venv (Python 3.12)
|
| 112 |
+
uv sync
|
| 113 |
+
|
| 114 |
+
# 2. Bring up Postgres + Redis
|
| 115 |
+
docker compose -f infra/docker-compose.dev.yml up -d
|
| 116 |
+
|
| 117 |
+
# 3. Create the schema and seed demo data
|
| 118 |
+
uv run alembic -c infra/alembic.ini upgrade head
|
| 119 |
+
PYTHONHASHSEED=0 uv run python scripts/seed_demo.py
|
| 120 |
+
|
| 121 |
+
# 4. Launch the Gradio app β http://127.0.0.1:7860
|
| 122 |
+
uv run python deploy/hf_space/app.py
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
Then click through the three consoles:
|
| 126 |
+
|
| 127 |
+
- **Doctor** β paste a consult transcript β **Draft SOAP note** β edit β **Approve**.
|
| 128 |
+
- **Patient** β type *"Book an appointment for tomorrow"* β confirm with **1**.
|
| 129 |
+
- **Nurse & Admin** β **Handover** (Generate brief) Β· **Roster** (Generate roster, then Find replacement) Β· **Discharge queue** (Initiate discharge) Β· **Wiki health** (**Run lint**).
|
| 130 |
+
|
| 131 |
+
Optional live integrations (add to `.env.local`, then restart):
|
| 132 |
+
`GROQ_API_KEY` (LLM + Whisper) Β· `OPENROUTER_API_KEY` (fallback) Β· `TELEGRAM_BOT_TOKEN` + `TELEGRAM_CHAT_ID` (free patient notifications) Β· `LANGFUSE_*` (tracing).
|
| 133 |
+
|
| 134 |
+
To deploy: the same `deploy/hf_space/app.py` runs on **Hugging Face Spaces** β push, set secrets in the Spaces panel, done.
|
| 135 |
+
|
| 136 |
+
---
|
| 137 |
+
|
| 138 |
+
## Testing
|
| 139 |
+
|
| 140 |
+
```bash
|
| 141 |
+
PYTHONHASHSEED=0 uv run pytest -q
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
**64 tests pass** today β documentation, rostering, handover, clerical, orchestrator routing, integrations, and contracts suites are all green. The appointment and discharge happy-path tests currently error/fail due to a **mock-patching harness issue** (they patch names that are imported lazily inside functions, so `mock.patch` can't find them) β the underlying agent code is verified working via direct smoke tests; only the test wiring needs the patch target corrected.
|
| 145 |
+
|
| 146 |
+
---
|
| 147 |
+
|
| 148 |
+
## Tech Stack (as actually wired)
|
| 149 |
+
|
| 150 |
+
**Backend:** Python 3.12 Β· FastAPI Β· LangGraph (orchestration) Β· LiteLLM (model routing) Β· Pydantic v2 (typed outputs) Β· SQLAlchemy + Alembic + PostgreSQL Β· Celery + Redis (reminders).
|
| 151 |
+
**AI & retrieval:** Groq Whisper (`whisper-large-v3-turbo`) Β· ChromaDB + rank-bm25 (hybrid search) Β· Langfuse (tracing).
|
| 152 |
+
**Frontend:** Gradio (three consoles, one-command HF Spaces deploy).
|
| 153 |
+
**Integrations:** Google Calendar (with offline local-calendar fallback) Β· Gmail Β· Telegram Bot API Β· WhatsApp (Twilio).
|
| 154 |
+
|
| 155 |
+
---
|
| 156 |
+
|
| 157 |
+
## Repository Map
|
| 158 |
+
|
| 159 |
+
| Path | What's there |
|
| 160 |
+
|---|---|
|
| 161 |
+
| `app/agents/` | The seven agents (`documentation`, `appointment`, `roster`, `handover`, `discharge`, `clerical`, `wiki`) |
|
| 162 |
+
| `app/orchestrator.py` | LangGraph state graph + routing |
|
| 163 |
+
| `app/ui/` | Gradio consoles: `doctor_tab`, `patient_tab`, `nurse_admin_tab` |
|
| 164 |
+
| `app/retrieval/` | Chroma + BM25 indices behind `index_api.search()` |
|
| 165 |
+
| `app/integrations/` | Calendar, Gmail, Telegram, WhatsApp, Whisper |
|
| 166 |
+
| `app/llm/router.py` | LiteLLM task routing + mock fallback |
|
| 167 |
+
| `wiki/` | The markdown knowledge corpus (10 condition pages seeded) |
|
| 168 |
+
| `deploy/hf_space/app.py` | Gradio entrypoint (local + HF Spaces) |
|
| 169 |
+
| `scripts/` | `seed_demo.py`, `build_indices.py`, `fetch_data.sh` |
|
| 170 |
+
| `plans/`, `README_OLD.md` | Original planning docs and pitch context |
|
| 171 |
+
|
| 172 |
+
---
|
| 173 |
+
|
| 174 |
+
## Clinical Safety
|
| 175 |
+
|
| 176 |
+
- Every clinical recommendation is traceable to a specific wiki page or guideline source.
|
| 177 |
+
- No agent sends a patient-facing communication without human approval.
|
| 178 |
+
- Patient data is handled in line with India's **Digital Personal Data Protection Act (DPDPA)**; synthetic data only in this repo.
|
| 179 |
+
- Full audit trail of agent actions via Langfuse.
|
README_OLD.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# CliniqAI β Clinical Operations AI for Indian Hospitals
|
| 2 |
|
| 3 |
> Giving doctors and nurses back the time they spend on paperwork, so they can focus on patients.
|
|
|
|
| 1 |
+
> β οΈ **DEPRECATED β this is the original planning README (kept for historical / pitch context).**
|
| 2 |
+
> It describes the *intended* 2-week hackathon scope, where only Documentation, Appointment, and
|
| 3 |
+
> Rostering were "shipping" and the rest were "coming soon". The project has since moved past this
|
| 4 |
+
> plan β **all seven agents are now implemented and demoable.** For the current, accurate
|
| 5 |
+
> description of what the app does and how to run it, see **[`README.md`](README.md)**.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
# CliniqAI β Clinical Operations AI for Indian Hospitals
|
| 10 |
|
| 11 |
> Giving doctors and nurses back the time they spend on paperwork, so they can focus on patients.
|