Case 02 · 2026 · Deployed
SwasthyaSetu
An offline-first referral network for India's public health system, designed so no patient is lost between facilities.
01 / The brief
An offline-first referral network for India's public health system, built so no patient is lost between facilities.
Why it existed
Paper referral chits, inconsistent identities and disconnected EHRs cause patients to disappear between Sub-Centres, PHCs and district hospitals.
What shipped
Zero data loss on reconnect, a nine-state referral lifecycle, and an OCR confidence gate that never auto-saves an extraction below 90%. Clinicians never wait on the network.
02 / Context
The constraint came first.
India's public health system moves patients through Sub-Centres, PHCs, CHCs and district hospitals. Paper referral chits, inconsistent identities and offline EHRs cause patients to disappear between facilities.
- Frontline devices are often offline for hours.
- Patient identity is inconsistent across facilities; silent merges are unacceptable.
- Handwritten OCR errors must never become clinical record without review.
03 / What I owned
My hands were on these.
- Monorepo architecture spanning web, API, shared types and the AI service
- IndexedDB-first write path and the idempotent EVT- sync queue
- Multi-vector patient identity matching with human confirmation
- Confidence-gated OCR and the nine-state referral state machine
- Docker Compose deployment across frontend, API and AI services
04 / Decisions
Four choices that mattered.
- Local-first writesIntake is written to IndexedDB first, then pushed through an idempotent EVT- queue when connectivity returns. The clinician never waits on the network.
- Match, do not mergeMulti-vector scoring across phone, RapidFuzz name similarity, village and age/gender surfaces identity candidates for a human to confirm.
- Confidence-gated OCRGemini Flash and TrOCR extract diagnosis, medication and follow-up dates. Anything below 90% confidence is flagged NEEDS_REVIEW and never auto-saved.
- An explicit referral state machineNine states from DRAFT to FOLLOW_UP_COMPLETED, with an immutable audit event on every transition. Clinical accountability is part of the data model.
05 / Architecture
How the pieces fit.
06 / Evidence
What can be measured.
Metrics state their source on the receipts ledger.
07 / Reflection
What broke, and what I would change.
Last-write-wins is not good enough for clinical data. I would add a sync simulator that injects partitions and reordered events into CI, then resolve conflicts with domain rules rather than timestamps.
08 / Stack and fit