Skip to content
/ CoDeX Public

A hybrid expert system combining deterministic rule-based inference with Bayesian probabilistic reasoning to perform differential diagnosis between COVID-19 and dengue. The system is specifically adapted to the Argentine epidemiological profile and the circulation patterns of dengue-endemic regions in 2025.

Notifications You must be signed in to change notification settings

protos50/CoDeX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🩺 CoDeX(Covid–Dengue eXpert) - Dual Expert System for COVID-19 vs Dengue Differential Diagnosis

A hybrid expert system implementing two complementary classical AI approaches: rule-based reasoning (deterministic) and Bayesian probabilistic inference for differential diagnosis between COVID-19 and Dengue, tailored to the Argentine epidemiological context in dengue-endemic regions (2025).

πŸ€– AI-Assisted Development: This project was designed and developed with the assistance of Generative Artificial Intelligence. It serves as a dual case study: it implements classical AI techniques (rule-based systems + probabilistic reasoning) while demonstrating how modern AI tools can accelerate complex software development in the medical-academic domain.


🌟 Key Features

🧠 Dual Diagnostic Engine

  • Deterministic Agent: Rule-based system with forward chaining and weighted scoring
  • Probabilistic Agent: Bayesian network with 13 nodes and 16 causal dependencies
  • Intelligent Consensus: Complementary results with full reasoning traceability

πŸ’¬ Trimodal User Interface

  • Medical Form: Direct capture of 16 clinical-epidemiological parameters
  • Conversational Chat: Step-by-step guided triage with adaptive logic
  • Advanced Visualization: Interactive decision tree with React Flow + inference traces

βš•οΈ Medical Knowledge Base

  • 2025 protocols from the Argentine Ministry of Health + PAHO
  • 6 differential diagnosis rules with calibrated weights
  • 3 alarm signs with automatic urgent referral
  • Fuzzy fever logic (low-grade/high/hyperpyrexia)

🌍 Argentine Epidemiological Context

  • Endemic areas: Corrientes, Misiones, Formosa, Chaco
  • Seasonality: Higher dengue incidence in summer (Aedes aegypti)
  • Risk factors: travel to Brazil, contact with confirmed cases

πŸ§ͺ AI Fundamentals & Knowledge Representation

πŸ“š Deterministic Approach - Rule-Based System

Architecture: Pure Python implementation of forward chaining inference engine (no expert system libraries).

Knowledge Base (backend/data/reglas_infectologia.json):

  • 6 differential diagnosis rules with calibrated weights:

    • retro_orbital_pain: +5 Dengue, -1 COVID β†’ Classic arbovirus symptom
    • cough: +2 COVID, -2 Dengue β†’ Upper respiratory symptom
    • anosmia: +7 COVID, -2 Dengue β†’ Highly specific for COVID-19
    • myalgia: +4 Dengue, +1 COVID β†’ "Breakbone fever"
    • dengue_contact: +10 Dengue β†’ Strongest predictor in active outbreaks
  • 2 contextual rules:

    • Corrientes + Summer: +5 Dengue (endemic zone + high Aedes aegypti season)
    • Corrientes + Other seasons: +2 Dengue (endemic zone, lower vector activity)
  • 3 alarm signs with urgent referral:

    • Intense abdominal pain β†’ plasma extravasation (severe dengue)
    • Mucosal bleeding β†’ evaluate platelets/hematocrit
    • Dyspnea β†’ COVID pneumonia, Oβ‚‚ saturation check

Inference Algorithm:

  1. Perception: Maps patient data to internal evidence
  2. Weighted Scoring: Accumulates points per activated rule
  3. Fuzzy Fever Logic:
    • 37.0-37.9Β°C: low-grade fever (+0 dengue)
    • 38.0-39.5Β°C: high fever (+2 dengue)
    • β‰₯39.6Β°C: hyperpyrexia (+3 dengue)
  4. Severity Assessment: Detects alarm signs with maximum priority
  5. Differential Classification:
    if score_dengue > score_covid + 3:
        return "SUSPICIOUS OF DENGUE (High Probability)"
    elif score_covid > score_dengue + 3:
        return "COMPATIBLE WITH COVID-19"
    else:
        return "REQUIRES DIFFERENTIAL DIAGNOSIS"
  6. Traceability: Generates human-readable trace of every fired rule

Example Trace:

START: Fever detected (40.2Β°C) β†’ Initial scores
Applying R_RETROOCULAR β†’ Dengue +5, COVID -1
Context: Corrientes + Summer β†’ Dengue +5
Fuzzy Logic: 40.2Β°C β†’ HYPERPYREXIA (Dengue +3)
FINAL SCORES: Dengue 23 vs COVID 3
DIAGNOSIS: SUSPICIOUS OF DENGUE (High Probability)

🎲 Probabilistic Approach - Bayesian Network

Architecture: DAG (Directed Acyclic Graph) with 13 nodes, 16 edges implemented using pgmpy.

Network Structure:

Root Nodes (Context):
  Season β†’ Dengue
  Location β†’ Dengue
  Travel β†’ Dengue
  Contact β†’ Dengue
  
Disease Nodes:
  COVID (independent - global circulation)
  Dengue (depends on 4 contextual factors)

Symptom Nodes (observed evidence):
  Fever ← {Dengue, COVID}
  Cough ← {Dengue, COVID}
  SoreThroat ← {Dengue, COVID}
  RetroOrbitalPain ← {Dengue, COVID}
  Myalgia ← {Dengue, COVID}
  Anosmia ← {Dengue, COVID}
  Dyspnea ← {Dengue, COVID}

Key Conditional Probability Tables (CPDs):

  • Baseline Prevalence: P(COVID) = 5%, P(Dengue | default) = 1%
  • Contextual Dengue: P(Dengue | Contact=Yes) = 85%, P(Dengue | Travel=Yes) = 55%
  • Discriminant Symptoms:
    • P(Anosmia | COVID=Yes, Dengue=No) = 85% (highly specific)
    • P(RetroOrbital | Dengue=Yes, COVID=No) = 80% (classic dengue)
    • P(Cough | COVID=Yes, Dengue=No) = 80% (upper respiratory)

Inference: Variable Elimination algorithm applies Bayes' Theorem recursively, propagating evidence to disease nodes and returning posterior probabilities P(COVID|Evidence) and P(Dengue|Evidence).


πŸ’¬ Conversational Agent - Interactive Triage

16-Question Dynamic Flow:

  1. Base Symptoms (4): Fever, Temperature (conditional), Retro-orbital pain, Cough
  2. Differentiators (5): Sore throat, Myalgia, Anosmia, Alarm signs (3 combined)
  3. Epidemiological Context (6): Location, Season, Brazil travel, Dengue contact, Medical history (asthma, hypertension)

Adaptive Logic: Temperature question only appears if fever=Yes (conditional rendering).

Session Management: RESTful API with UUID-based sessions (/chat/start, /chat/{session_id}/message).

Final Output: After 16 questions, both engines run and return deterministic classification + Bayesian probabilities + full inference trace + interactive decision tree.


πŸš€ Quick Start

Prerequisites

  • Python 3.10+, Node.js 20+, npm

1️⃣ Backend Setup

Create and activate virtual environment:

# Create virtual environment
python -m venv venv

# Activate on Windows
venv\Scripts\activate

# Activate on Linux/Mac
source venv/bin/activate

Install dependencies and run:

pip install -r requirements.txt
python -m uvicorn backend.main:app --reload

βœ… Backend running at http://localhost:8000 (API docs: /docs)

2️⃣ Frontend Setup

cd frontend
npm install
npm run dev

βœ… Frontend running at http://localhost:3000

3️⃣ Usage

  1. Open http://localhost:3000
  2. Choose mode:
    • πŸ“‹ Form: Direct 16-field input
    • πŸ’¬ Chat: Step-by-step conversational triage
  3. View dual results: deterministic classification + Bayesian probabilities + inference trace + decision tree

πŸ“– Example Cases

πŸ§ͺ Case 1: Dengue with Hyperpyrexia

Input: Temp 40.5Β°C, retro-orbital pain, myalgia, Corrientes+Summer, dengue contact
Output:

  • Deterministic: "SUSPICIOUS OF DENGUE" (Score 23 vs -1)
  • Probabilistic: Dengue 99.99%, COVID 0.01%

πŸ§ͺ Case 2: COVID-19 with Anosmia

Input: Temp 38.2Β°C, cough, sore throat, anosmia, CABA+Winter
Output:

  • Deterministic: "COMPATIBLE WITH COVID-19" (Score 9 vs 0)
  • Probabilistic: COVID 99.81%, Dengue 0.19%

🚨 Case 3: Severe Dengue (Alarm Signs)

Input: Temp 39.8Β°C, retro-orbital pain, intense abdominal pain, mucosal bleeding
Output:

  • Deterministic: "SEVERE DENGUE CASE (Alarm Signs)"
  • Action: "⚠️ MEDICAL EMERGENCY - IMMEDIATE REFERRAL"

πŸ“ Project Structure

tp3_prototipo1/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py                      # FastAPI endpoints
β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”œβ”€β”€ deterministic.py         # Rule-based engine with scoring
β”‚   β”‚   β”œβ”€β”€ probabilistic.py         # Bayesian network (pgmpy)
β”‚   β”‚   └── conversational.py        # Chat logic (16 questions)
β”‚   └── data/
β”‚       └── reglas_infectologia.json # Medical knowledge base
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   └── page.tsx                 # Main page (tabs: form/chat)
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ diagnostic-form.tsx      # 16-field medical form
β”‚   β”‚   β”œβ”€β”€ chat-interface.tsx       # Conversational interface
β”‚   β”‚   β”œβ”€β”€ diagnostic-results.tsx   # Results visualization
β”‚   β”‚   └── decision-tree.tsx        # Interactive tree (React Flow)
β”‚   └── lib/
β”‚       └── i18n.ts                  # Internationalization (ES/EN)
β”œβ”€β”€ requirements.txt
└── README.md

πŸ§‘β€βš•οΈ Medical Knowledge Base

Data Sources

  • Argentine Ministry of Health (2025 Protocols)
  • PAHO - Dengue Guidelines
  • Scientific papers: COVIDENGUE Score, arbovirus differential diagnosis

Knowledge Rules Summary

6 Differential Diagnosis Rules:

  • Retro-orbital pain: +5 Dengue (classic arbovirus)
  • Cough: +2 COVID (upper respiratory)
  • Anosmia: +7 COVID (highly specific)
  • Intense myalgia: +4 Dengue ("breakbone fever")
  • Epidemiological link: +10 Dengue (strongest predictor)

2 Contextual Rules:

  • Corrientes + Summer: +5 Dengue (endemic zone + Aedes aegypti season)
  • Corrientes + Other seasons: +2 Dengue (endemic zone, lower vector)

3 Alarm Signs:

  • Intense abdominal pain β†’ URGENT (plasma extravasation)
  • Mucosal bleeding β†’ URGENT (platelets/hematocrit)
  • Dyspnea β†’ RESPIRATORY (COVID pneumonia, Oβ‚‚ saturation)

πŸŽ“ AI Theoretical Foundations

Rule-Based Systems (Deterministic)

  • Knowledge Representation: IF-THEN rules with numeric weights
  • Inference Engine: Forward chaining
  • Search Strategy: Breadth-first in rule space
  • Conflict Resolution: Priority by accumulated weights
  • Explainability: Full trace of fired rules

Probabilistic Reasoning (Bayesian Network)

  • Bayes' Theorem: P(Disease|Symptoms) = P(Symptoms|Disease) Γ— P(Disease) / P(Symptoms)
  • Conditional Independence: Symptoms independent given disease
  • Exact Inference: Variable Elimination algorithm
  • Advantage: Rigorous uncertainty handling + Bayesian updating

Approach Comparison

Aspect Deterministic Probabilistic
Output Categorical classification Probability distribution
Explainability High (full trace) Medium (probabilities)
Maintenance Easy (JSON editable) Complex (CPD calibration)
Uncertainty Not formally handled Mathematical rigor
Speed O(n) rules O(exponential in tree-width)
Clinical Use Quick triage Epidemiological research

🀝 Academic Use

This project is part of a university assignment for the Artificial Intelligence course (Computer Science Degree, UNNE - Argentina).

License: MIT (free educational use)

Citation:

Dual Expert System for COVID-19 vs Dengue Differential Diagnosis
National University of the Northeast, Faculty of Exact Sciences
2025 - Developed with Generative AI Assistance

πŸ™ Acknowledgments

  • Argentine Ministry of Health (public protocols)
  • PAHO/WHO (epidemiological guidelines)
  • pgmpy community (Bayesian network library)
  • shadcn/ui (React components)
  • Claude AI (Anthropic) for development assistance

⚠️ Medical Disclaimer: This system is an educational and research tool. IT DOES NOT REPLACE professional medical judgment and should not be used for real clinical diagnoses. Any medical decision must be made by a licensed healthcare professional.

About

A hybrid expert system combining deterministic rule-based inference with Bayesian probabilistic reasoning to perform differential diagnosis between COVID-19 and dengue. The system is specifically adapted to the Argentine epidemiological profile and the circulation patterns of dengue-endemic regions in 2025.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published