How mauriceos/ubora-health works
Purpose and entry points
Ubora is a human-governed primary-healthcare stock reconciliation and redistribution demo for Kenyan facilities. It converts bilingual nurse shift reports into structured inventory observations, deterministically audits stock movement, proposes surplus-to-stockout transfers, and produces an approval-gated MoH Form S11.
The Next.js App Router UI starts at src/app/page.tsx, with voucher detail/print workflow at src/app/voucher/[id]/page.tsx. Server operations are exposed through route handlers under src/app/api/.
Client application and role workflows
src/components/UboraApp.tsx is the principal client shell, coordinating nurse, DHO, and pharmacist experiences. Authentication is demo-local through src/components/LoginScreen.tsx; onboarding and language presentation are client concerns in src/components/Onboarding.tsx and src/lib/i18n.ts.
Nurses submit/review reports and send verified findings onward. DHO users assess ranked redistribution candidates and initiate voucher drafts. Pharmacists complete authorization and print approved paperwork.
Extraction boundary: model produces fields only
src/app/api/extract/route.ts accepts report text and delegates language extraction to the Gemma integration in src/lib/gemma/index.ts. Provider selection, cloud/Ollama connectivity, normalization, and rule fallback policy are isolated in:
• src/lib/gemma/providers.ts
• src/lib/gemma/config.ts
• src/lib/gemma/normalize.ts
The extraction contract is defined by src/lib/domain/extractionSchema.ts. This is the critical trust boundary: model output is structured input for deterministic logic, never authorization or transfer arithmetic.
Deterministic stock audit
src/app/api/audit/route.ts invokes src/lib/auditor.ts to reconcile reported shelf counts, bin-card expectations, case mix, and drawdown reasons. Domain catalogs and dispensing baselines live in:
• src/lib/domain/commodities.ts
• src/lib/domain/caseMix.ts
• src/lib/domain/extractionSchema.ts
Audit results distinguish reconciling stock, plausible wastage, missing mandatory lot details, register gaps, and unexplained drawdown. Only verified surplus can cross into redistribution; contradictions are held for recount.
Redistribution matching
src/app/api/match/route.ts fronts src/lib/matcher.ts, which matches eligible surplus lots to facility deficits and ranks candidates using expiry loss avoided minus transport cost. Facility/corridor reference data is in src/lib/data/facilities.ts.
This stage consumes audited, eligible lots rather than raw model output, preserving the audit gate before any logistics proposal.
Voucher lifecycle and governance
Voucher creation, retrieval, approval, and printing are served by:
• src/app/api/vouchers/route.ts
• src/app/api/vouchers/[id]/approve/route.ts
• src/app/api/vouchers/[id]/print/route.ts
State and authorization sequencing are maintained in src/lib/store.ts; S11 fields and rendering templates are separated into src/lib/s11-fields.ts and src/lib/s11-template.ts. The enforced lifecycle is draft, issuer confirmation, receiver confirmation, then pharmacist authorization; no model or single actor can finalize a transfer.
Runtime, persistence, and external services
The runtime is Next.js 16/React 19/TypeScript, with API routes running server-side. Google AI Studio/Gemini is the primary Gemma 4 provider; local Ollama is the offline HTTP alternative. GOOGLE_API_KEY remains server-only. Persistence appears application-local via src/lib/store.ts, appropriate for the demo rather than durable multi-user production storage.
Audit reporting is available through src/app/api/audit/route.ts; demo/corridor setup endpoints are src/app/api/demo/route.ts and src/app/api/bootstrap/route.ts.
Main entry points: UboraApp.tsx Ubora client shell · vouchers/route.ts Voucher lifecycle API · audit/route.ts Audit endpoint · index.ts Gemma extraction gateway
Components 18
Client workflows
- Ubora client shell · Coordinates nurse, DHO, and pharmacist workflows.
src/components/UboraApp.tsx - Demo login
src/components/LoginScreen.tsx - Application entry
src/app/page.tsx - Voucher detail & print
src/app/voucher/[id]/page.tsx
Server API
- Extraction endpoint
src/app/api/extract/route.ts - Audit endpoint
src/app/api/audit/route.ts - Matching endpoint
src/app/api/match/route.ts - Voucher lifecycle API · Creates, approves, and prints vouchers.
src/app/api/vouchers/route.ts - Demo setup · Bootstraps demo and corridor data.
src/app/api/bootstrap/route.ts
Deterministic domain
- Extraction contract · Model output is structured input, never transfer authority.
src/lib/domain/extractionSchema.ts - Stock auditor · Verifies surplus and holds contradictions for recount.
src/lib/auditor.ts - Clinical baselines · Commodity and case-mix dispensing references.
src/lib/domain/commodities.ts - Redistribution matcher · Ranks eligible-lot transfers by expiry loss avoided less transport cost.
src/lib/matcher.ts - Facility corridors
src/lib/data/facilities.ts - Application state · Maintains voucher state and authorization sequence.
src/lib/store.ts - MoH Form S11 · Renders approval-gated transfer paperwork.
src/lib/s11-template.ts
Model providers
- Gemma extraction gateway · Selects provider and normalizes extracted fields.
src/lib/gemma/index.ts - Gemini / Ollama · Cloud primary with offline local alternative.
src/lib/gemma/providers.ts
Connections 20
- Application entry → Ubora client shell: renders
- Demo login → Ubora client shell: starts demo session
- Ubora client shell → Extraction endpoint: submits shift report
- Extraction endpoint → Gemma extraction gateway: delegates extraction
- Gemma extraction gateway → Gemini / Ollama: selects provider
- Gemma extraction gateway → Extraction contract: returns validated fields
- Ubora client shell → Audit endpoint: sends reported observations
- Audit endpoint → Stock auditor: reconciles stock
- Extraction contract → Stock auditor: structured observations
- Clinical baselines → Stock auditor: expected dispensing inputs
- Ubora client shell → Matching endpoint: requests redistribution candidates
- Audit endpoint → Matching endpoint: verified eligible surplus only
- Matching endpoint → Redistribution matcher: ranks transfers
- Facility corridors → Redistribution matcher: deficits and transport corridors
- Ubora client shell → Voucher lifecycle API: drafts and confirms transfer
- Redistribution matcher → Voucher lifecycle API: proposed transfer
- Voucher lifecycle API → Application state: enforces staged approvals
- Voucher lifecycle API → MoH Form S11: generates approved form
- Voucher detail & print → Voucher lifecycle API: retrieves, authorizes, prints
- Demo setup → Application state: seeds demo state