Skip to content

Repository files navigation

AMR-CDSS

AMR CDSS: AI-Powered Antimicrobial Resistance Clinical Decision Support System

Clinical-Decision-Support-System

AI-powered microscopic image analysis and clinical decision support using YOLOv8, FastAPI, PostgreSQL, and edge computing.

🧬 Clinical AI β€” Clinical Decision Support System backend

Python FastAPI YOLOv8 PostgreSQL SQLAlchemy Docker License

Typing Animation

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 Β  Build

⚠️ Status: Early Development (MVP stage). Core architecture is defined; implementation is in progress. See Roadmap for current completion state.


πŸ“Œ Table of Contents


πŸ”¬ Overview

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.


🎯 Problem & Solution

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

🧠 Core Concept

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   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.

πŸ—οΈ System Architecture

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

✨ Key Features

Core Analysis

  • πŸ”¬ 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 & Workflow Management

  • 🧾 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.

Alerts & Communication

  • πŸ”” 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.

Reporting & Data

  • πŸ“„ 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.

AI & Continuous Improvement

  • ✏️ 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.

πŸ€– YOLOv8 Vision Engine

{
  "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.


🧠 Clinical Decision Support

AI Observation β†’ Quantitative Results β†’ Clinical Rules β†’ Decision Support
      β†’ Patient Record β†’ Healthcare Professional

The clinician remains responsible for the final interpretation, alongside confirmatory procedures.


πŸ’Š Medication Validation

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.


🧾 Patient & Sample Tracking

  • Every sample is linked to a patient_id and sample_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

πŸ•΅οΈ Audit Trail & Access Control

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.


πŸ”” Alerts & Notifications

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.


πŸ“„ Reporting & Export

  • 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.

πŸ”„ Offline-First & Edge Sync

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.


🌍 Multi-language Support

UI strings are externalized for translation β€” Kiswahili and English supported out of the box, extensible to other languages.


✏️ Feedback Loop & Model Improvement

Clinician flags incorrect detection β†’ Correction stored β†’ Dataset growth
        β†’ Periodic retraining β†’ Updated best.pt β†’ Redeploy

βš™οΈ Edge Hardware

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

πŸ”Œ API Endpoints

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

πŸš€ Installation

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

πŸ”§ Environment Variables

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 .env or production secrets to GitHub.

πŸ—ƒοΈ Database Setup

alembic upgrade head

▢️ Running the Backend

uvicorn backend.main:app --reload

Interactive docs: /docs and /redoc

πŸ§ͺ Testing

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
pytest

🐳 Docker

Docker Host
 β”œβ”€β”€ FastAPI Application
 β”œβ”€β”€ PostgreSQL
 └── Notification/Sync Worker

πŸ” Security Considerations

  • 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)

πŸ›£οΈ Roadmap

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

⚠️ Clinical Safety

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.


🀝 Contributing

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.


πŸ‘€ Author

Dotto Mtundu Hamis (Mtundu) Backend Developer (FastAPI / Python) β€” Mbeya, Tanzania GitHub: @mtundudev


πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.

About

AMR CDSS: AI-Powered Antimicrobial Resistance Clinical Decision Support System

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages