AMR CDSS: AI-Powered Antimicrobial Resistance Clinical Decision Support System
AI-powered microscopic image analysis and clinical decision support using YOLOv8, FastAPI, PostgreSQL, and edge computing.
SEE β COUNT β CHECK β SUPPORT
An AI-powered Clinical Decision Support System that assists laboratory personnel and physicians in analyzing microscopic blood/pathogen samples, validating proposed treatments, and tracking patient results β deployable on cloud or offline edge hardware.
β οΈ Status: Early Development (MVP stage). Core architecture is defined; implementation is in progress. See Roadmap for current completion state.
- Overview
- Problem & Solution
- Core Concept
- System Architecture
- Key Features
- Technology Stack
- YOLOv8 Vision Engine
- Clinical Decision Support
- Medication Validation
- Patient & Sample Tracking
- Audit Trail & Access Control
- Alerts & Notifications
- Reporting & Export
- Offline-First & Edge Sync
- Multi-language Support
- Feedback Loop & Model Improvement
- Edge Hardware
- Backend Structure
- API Endpoints
- Installation
- Environment Variables
- Running the Backend
- Testing
- Docker
- Security Considerations
- Roadmap
- Clinical Safety
- Contributing
- Author
- License
Clinical AI CDSS combines:
- π¬ Microscopic imaging
- π€ YOLOv8 computer vision
- β‘ FastAPI backend
- ποΈ PostgreSQL database
- π§ Rule-based clinical decision support
- π Medication validation
- π§Ύ Patient/sample history tracking
- π Critical-value alerting (in-app + SMS)
- π₯οΈ Frontend visualization
- βοΈ Offline edge computing
Important: This system is designed to support clinical decision-making β it does not replace qualified healthcare professionals.
Manual microscopic analysis is repetitive, time-consuming, and prone to human counting error. Clinical AI CDSS automates detection and counting, cross-references results against configured clinical rules, and validates proposed treatments β while keeping a full audit trail of every decision.
Microscopic Sample β Digital Camera β YOLOv8 Detection β Object Counting
β Clinical Rule Evaluation β Analysis Result β Frontend Dashboard
β Clinical Decision Support β Medication Validation β Patient Record
ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ
β SEE β --> β COUNT β --> β CHECK β --> β SUPPORT β
β YOLOv8 β β Aggregateβ β Clinical β β Decision β
β detects β β counts β β rules β β + record β
ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ
- SEE β the vision model detects objects in the microscopic image.
- COUNT β detections are aggregated into numerical totals.
- CHECK β the backend evaluates results against configured clinical rules.
- SUPPORT β structured, auditable information is presented to the clinician, linked to the patient record.
Microscopic Slide β Digital Camera β YOLOv8 (best.pt)
β
ββββββββββββββββ΄βββββββββββββββ
βΌ βΌ
Visual Detection Object Counting
(Bounding Boxes) (Quantitative Data)
β β
ββββββββββββββββ¬ββββββββββββββββ
βΌ
FastAPI
β
ββββββββββββββββββββββΌβββββββββββββββββββββ
βΌ βΌ βΌ
PostgreSQL Clinical Rule Engine Notification Service
(patients, samples, (thresholds, warnings) (SMS / in-app alerts)
audit logs, roles)
β β β
ββββββββββββββββββββββΌβββββββββββββββββββββ
βΌ
Analysis Result
β
βΌ
Frontend Dashboard
β
βΌ
Proposed Medication
β
βΌ
POST /api/v1/validate-medication
β
βΌ
Treatment Rule Engine
β β
βββββββ βββββββ
βΌ βΌ
APPROVED WARNING / MISMATCH
β β
βββββββββββ¬ββββββββββ
βΌ
Patient Record + Audit Log + PDF Report
- π¬ Microscopic Image Analysis β analyze samples with a custom-trained YOLOv8 model.
- π€ AI Object Detection β detect configured blood components or microbial classes.
- π Quantitative Analysis β convert detections into numerical counts.
- πΌοΈ Visual Annotations β bounding boxes with class and confidence overlay.
- π§ Clinical Rule Engine β evaluate results against configured thresholds.
- π Medication Validation β validate a proposed drug against the detected pathogen.
- π§Ύ Patient & Sample Tracking β every analysis is linked to a patient/sample ID, enabling historical trend views (e.g., CBC over time).
- π΅οΈ Audit Trail β every analysis, validation, and medication decision is logged with user, timestamp, and outcome.
- π Role-Based Access Control β distinct permissions for Lab Technician, Doctor, and Admin roles.
- β Image Quality Pre-Check β flags blurry, over/under-exposed, or out-of-focus images before running inference.
- π¦ Batch Analysis β process multiple samples in a single session.
- π Critical Value Alerts β automatic flag when a result crosses a dangerous threshold (e.g., abnormally high WBC).
- π² SMS Notifications β optional SMS alert to the attending physician for urgent results (via Africa's Talking or similar gateway), useful in low-connectivity settings.
- π§ In-App & Email Notifications β configurable notification channels.
- π PDF Report Export β generate a printable/shareable report per analysis for the patient file.
- π Offline-First Sync β edge devices queue results locally and sync to the central server/HIMS when connectivity returns.
- π Multi-language UI β Kiswahili and English interface support.
- βοΈ Clinician Feedback Loop β doctors can correct mislabeled detections; corrections are stored for future model retraining.
- β‘ REST API β full analysis and validation workflow exposed via FastAPI.
- ποΈ Persistent Database β stores rules, pathogens, medications, treatment mappings, patients, samples, and audit logs.
- π΄ Edge Computing β deployable on local hardware for offline environments.
{
"detections": [
{ "class": "RBC", "confidence": 0.94, "bbox": [120, 80, 180, 140] },
{ "class": "E_coli", "confidence": 0.87, "bbox": [200, 140, 240, 180] }
],
"image_quality": { "blur_score": 0.12, "status": "acceptable" }
}Confidence reflects the model's detection confidence β not medical or diagnostic certainty.
AI Observation β Quantitative Results β Clinical Rules β Decision Support
β Patient Record β Healthcare Professional
The clinician remains responsible for the final interpretation, alongside confirmatory procedures.
Endpoint: POST /api/v1/validate-medication
Detected Pathogen + Proposed Medication β Treatment Rules β Validation
β APPROVED | WARNING / MISMATCH β Suggested confirmatory tests
The system never invents clinical guidance β treatment rules must be sourced from validated, authoritative references.
- Every sample is linked to a
patient_idandsample_id. - Analysis history per patient is retrievable for trend monitoring (e.g., repeated CBC results).
- Sample metadata: collection date, technician, device/edge-node ID, image reference.
Patient ββ< Sample ββ< Analysis ββ< MedicationValidation
| Role | Upload Sample | Run Analysis | Propose Medication | Validate Medication | View Audit Log |
|---|---|---|---|---|---|
| Lab Technician | β | β | β | β | β |
| Doctor | β | β | β | β | β |
| Admin | β | β | β | β | β |
Every state-changing action is recorded: who, what, when, and result β required for clinical accountability, even at prototype stage.
Analysis Result β Threshold Breach? ββ yes ββ> In-App Alert + SMS to Doctor
β
no
βΌ
Standard Result
SMS delivery is designed around low-connectivity environments common in rural laboratory settings.
- Generate a per-analysis PDF report (annotated image, counts, rule findings, medication validation outcome).
- Reports are stored and linked to the patient/sample record for future retrieval.
Edge Node (offline) β Local Queue (SQLite/local Postgres)
β Connectivity Restored β Sync Worker β Central Server / HIMS
Edge nodes continue operating fully offline; sync is eventually-consistent once network access resumes.
UI strings are externalized for translation β Kiswahili and English supported out of the box, extensible to other languages.
Clinician flags incorrect detection β Correction stored β Dataset growth
β Periodic retraining β Updated best.pt β Redeploy
Digital Microscope Camera (C-Mount) β (USB / CSI video stream) βΌ Edge Processing Unit: Nvidia Jetson Nano (preferred, CUDA) / Raspberry Pi 4 (fallback, ONNX/TFLite) β (Offline FastAPI + YOLOv8 inference) βΌ Touchscreen Interface Panel (Frontend UI)
backend/
βββ core/
β βββ config.py
β βββ database.py
β βββ security.py
βββ models/
β βββ patient.py
β βββ sample.py
β βββ clinical_rule.py
β βββ pathogen.py
β βββ medication.py
β βββ treatment_rule.py
β βββ analysis.py
β βββ audit_log.py
βββ schemas/
β βββ patient.py
β βββ analysis.py
β βββ medication.py
βββ services/
β βββ yolo_service.py
β βββ analysis_service.py
β βββ clinical_rule_service.py
β βββ medication_service.py
β βββ notification_service.py
β βββ report_service.py
β βββ sync_service.py
βββ routers/
β βββ analysis.py
β βββ medication.py
β βββ patients.py
β βββ reports.py
βββ main.py
| Method | Endpoint | Purpose |
|---|---|---|
POST |
/api/v1/analyze |
Upload a microscopic image and run AI analysis |
POST |
/api/v1/validate-medication |
Validate proposed medication against detected pathogen |
GET |
/api/v1/patients/{id}/history |
Retrieve a patient's analysis history |
GET |
/api/v1/reports/{analysis_id} |
Generate/download a PDF report for an analysis |
GET |
/api/v1/audit-logs |
Retrieve audit trail (Admin only) |
POST |
/api/v1/analysis/{id}/feedback |
Submit a correction on a detection |
git clone https://github.com/mtundudev/clinical-ai-cdss.git
cd clinical-ai-cdss
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt| Variable | Description | Example |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgresql://user:pass@localhost:5432/clinical_ai |
SECRET_KEY |
JWT/auth signing secret | change-me |
MODEL_PATH |
Path to trained YOLOv8 weights | ./models/best.pt |
SMS_API_KEY |
SMS gateway API key (e.g. Africa's Talking) | your-api-key |
DEFAULT_LANGUAGE |
Default UI language | sw or en |
Never commit
.envor production secrets to GitHub.
alembic upgrade headuvicorn backend.main:app --reloadInteractive docs: /docs and /redoc
tests/
βββ test_analysis.py
βββ test_yolo_service.py
βββ test_clinical_rules.py
βββ test_medication.py
βββ test_patients.py
βββ test_audit_log.py
βββ test_api.py
pytestDocker Host
βββ FastAPI Application
βββ PostgreSQL
βββ Notification/Sync Worker
- Environment-based secrets management
- JWT authentication + role-based authorization
- Input & file-upload validation
- Safe model loading
- Full audit logging of clinical actions
- Patient-data privacy β access restricted by role, data encrypted at rest where applicable
- Compliance alignment target: relevant national health-data protection requirements (to confirm with local regulatory guidance before any clinical use)
Phase 1 β Foundation
- Define system architecture
- Backend structure, PostgreSQL, SQLAlchemy, Alembic setup
Phase 2 β AI Integration
- Integrate
best.pt, inference, detection extraction, counting
Phase 3 β Analysis API
-
/api/v1/analyze, image validation, rule integration, response schemas
Phase 4 β Clinical Decision Support
- Rule models, evaluation service, warning generation, analysis history
Phase 5 β Medication Validation
- Medication models, treatment rules,
/api/v1/validate-medication
Phase 6 β Patient, Audit & Alerts
- Patient/Sample models, audit log, RBAC, critical-value alerts, SMS integration
Phase 7 β Reporting & Sync
- PDF report generation, offline queue, edge-to-server sync
Phase 8 β Frontend
- Image upload, live feed, annotated display, dashboard, clinical action panel, Kiswahili/English toggle
Phase 9 β Edge Deployment
- Camera integration, Jetson Nano/Pi 4 testing, inference benchmarking, offline deployment
Phase 10 β Integration & Validation
- HIMS integration research, security review, clinical validation planning
This project is a Clinical Decision Support System prototype β not an autonomous diagnostic or prescribing system. AI detections and rule-based outputs may contain errors. Final clinical decisions remain the responsibility of qualified healthcare professionals, following applicable clinical guidelines, laboratory procedures, and regulations. Clinical thresholds and treatment rules must come from authoritative, validated sources β never invented or assumed by the system.
Contributions are welcome. Please open an issue to discuss proposed changes before submitting a pull request. Fork the repo, create a feature branch, and submit a PR with a clear description of the change and its clinical/technical rationale.
Dotto Mtundu Hamis (Mtundu) Backend Developer (FastAPI / Python) β Mbeya, Tanzania GitHub: @mtundudev
This project is licensed under the MIT License β see the LICENSE file for details.