A complete FastAPI backend for the Hospital ICU Digital Twin simulation system, built for a Cyber Security capstone project.
icu_digital_twin/
├── main.py # App entry point + router registration
├── dependencies.py # JWT auth, fake DB, shared helpers
├── requirements.txt
└── routers/
├── auth.py # Login, logout, get me, update role
├── patients.py # Admit, list, get, discharge
├── vitals.py # Push vitals, history, critical, WebSocket
├── resources.py # ICU resources + what-if simulation
├── ai.py # Risk score, length of stay, AI alerts
├── siem.py # Security events, anomalies, audit log, incidents
└── chatbot.py # NLP chatbot interface
pip install -r requirements.txt
uvicorn main:app --reloadThen open: http://localhost:8000/docs
| Username | Password | Role |
|---|---|---|
| dr.ahmad | password123 | clinician |
| admin | admin123 | admin |
POST /auth/login— Get JWT tokenGET /auth/me— Get current user
POST /icu/patients— Admit patientGET /icu/patients— List all patientsGET /icu/patients/{id}— Patient + latest vitalsDELETE /icu/patients/{id}— Discharge patient
POST /icu/vitals/{id}— Push new readingGET /icu/vitals/{id}/history— Historical vitalsGET /icu/vitals/critical— All critical patientsWS /icu/vitals/ws/{id}— Live stream
GET /icu/ai/risk/{id}— Sepsis + deterioration scoreGET /icu/ai/predict/los/{id}— Length of stay predictionGET /icu/ai/alerts— All active AI alerts
GET /icu/resources— Full resource overviewPUT /icu/resources/{id}— Update resource statusPOST /icu/simulation/whatif— What-if scenario
POST /siem/events— Log security eventGET /siem/anomalies— Isolation Forest anomaly detectionGET /siem/alerts— Active security alertsPUT /siem/alerts/{id}/acknowledgeGET /siem/audit-log— Full compliance audit trailPOST /siem/incidents— Create incident report
POST /chatbot/query— Natural language questionDELETE /chatbot/history— Clear session
| Endpoint | Simulated As | Production Model |
|---|---|---|
/icu/ai/risk |
Rule-based scoring | XGBoost / LSTM |
/icu/ai/predict/los |
Heuristic | Gradient Boosting |
/siem/anomalies |
Threshold rules | Isolation Forest |
/chatbot/query |
Keyword matching | LangChain + LLM |