Skip to content

SilverFledgling/MIPD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MIPD – Model-Informed Precision Dosing

Hệ thα»‘ng tα»‘i Ζ°u liều lượng thuα»‘c dα»±a trΓͺn Pharmacokinetics/Pharmacodynamics (PK/PD) cho bệnh viện Việt Nam.

πŸ“Έ Screenshots

Dashboard Results (PK Curve 3 lα»›p)
Dashboard Results
VPC Chart Bland-Altman Plot NPDE Histogram + QQ
VPC Bland-Altman NPDE

🎯 Mα»₯c tiΓͺu

XΓ’y dα»±ng hệ thα»‘ng MIPD hα»— trợ dược sΔ© lΓ’m sΓ ng tα»‘i Ζ°u liều vancomycin:

  • 🧬 MΓ΄ hΓ¬nh PK dΓ’n sα»‘ (Population PK) – 2-compartment IV
  • πŸ“Š Bayesian estimation cΓ‘ thể hΓ³a (MAP, Laplace, ADVI, EP, SMC, MCMC, Adaptive Pipeline)
  • πŸ’Š Tα»‘i Ζ°u liều AUCβ‚‚β‚„/MIC-guided vα»›i Monte Carlo PTA
  • πŸ›‘οΈ Hệ thα»‘ng an toΓ n 5 lα»›p bαΊ£o vệ bệnh nhΓ’n
  • πŸ€– AI/ML: phΓ‘t hiện bαΊ₯t thường TDM, sΓ ng lọc covariate
  • βœ… ThαΊ©m Δ‘α»‹nh mΓ΄ hΓ¬nh (MPE, MAPE, CCC, NPDE, VPC, Bland-Altman)

πŸ—οΈ KiαΊΏn trΓΊc hệ thα»‘ng

Frontend (:5173)  β†’  API Gateway (:5000)  β†’  PK Engine (:8000)
   React/Vite          ASP.NET + YARP          Python/FastAPI
                        JWT Auth
                        RBAC 4 roles
                        Audit Trail

CαΊ₯u trΓΊc thΖ° mα»₯c

MIPD/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ frontend/                    # React SPA (Vite)
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.jsx    # Tα»•ng quan + API health check
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Dosing.jsx       # Dose Calculator β†’ Bayesian API
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Results.jsx      # PK curve 3 lα»›p + SHAP + params
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Validation.jsx   # VPC, Bland-Altman, NPDE + CSV upload
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Patients.jsx     # QuαΊ£n lΓ½ bệnh nhΓ’n
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Settings.jsx     # CΓ i Δ‘αΊ·t hệ thα»‘ng
β”‚   β”‚   β”‚   β”‚   └── Login.jsx        # Đăng nhαΊ­p JWT
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/AuthContext.jsx  # JWT context + protected routes
β”‚   β”‚   β”‚   β”œβ”€β”€ api/client.js        # API client (auto JWT injection)
β”‚   β”‚   β”‚   └── styles.css           # Design system
β”‚   β”‚   β”œβ”€β”€ sample_data/             # CSV mαΊ«u cho Validation
β”‚   β”‚   └── vite.config.js           # Proxy β†’ Gateway
β”‚   β”‚
β”‚   β”œβ”€β”€ backend/MIPD.ApiGateway/     # .NET 8 API Gateway
β”‚   β”‚   β”œβ”€β”€ Program.cs               # YARP + JWT + CORS + Health
β”‚   β”‚   β”œβ”€β”€ appsettings.json         # Route config
β”‚   β”‚   β”œβ”€β”€ Services/
β”‚   β”‚   β”‚   β”œβ”€β”€ AuthService.cs       # User management + login
β”‚   β”‚   β”‚   β”œβ”€β”€ JwtService.cs        # JWT token generation
β”‚   β”‚   β”‚   β”œβ”€β”€ AuditService.cs      # Audit trail logging
β”‚   β”‚   β”‚   └── CacheService.cs      # Redis/InMemory cache
β”‚   β”‚   └── Middleware/
β”‚   β”‚       └── AuditMiddleware.cs    # Request/response auditing
β”‚   β”‚
β”‚   └── pk-engine/                   # Python PK Engine (FastAPI)
β”‚       β”œβ”€β”€ pk/                      # Core PK models
β”‚       β”‚   β”œβ”€β”€ models.py            # PatientData, DoseEvent, PKParams
β”‚       β”‚   β”œβ”€β”€ analytical.py        # Analytical 2-comp solutions
β”‚       β”‚   β”œβ”€β”€ solver.py            # RK45 ODE solver
β”‚       β”‚   β”œβ”€β”€ population.py        # Population PK (Vancomycin VN)
β”‚       β”‚   └── clinical.py          # CrCL, eGFR, IBW, ABW
β”‚       β”œβ”€β”€ bayesian/                # 7 inference methods
β”‚       β”‚   β”œβ”€β”€ map_estimator.py     # MAP
β”‚       β”‚   β”œβ”€β”€ laplace.py           # Laplace approximation
β”‚       β”‚   β”œβ”€β”€ advi.py              # Variational Inference
β”‚       β”‚   β”œβ”€β”€ ep.py                # Expectation Propagation
β”‚       β”‚   β”œβ”€β”€ smc.py               # Sequential Monte Carlo
β”‚       β”‚   β”œβ”€β”€ mcmc.py              # MCMC/NUTS (NumPyro)
β”‚       β”‚   └── engine.py            # Adaptive 3-Layer Pipeline ⭐
β”‚       β”œβ”€β”€ dosing/optimizer.py      # Dose optimization + PTA
β”‚       β”œβ”€β”€ ai/                      # AI/ML features
β”‚       β”‚   β”œβ”€β”€ anomaly_detection.py # Swift Hydra 4-head QC
β”‚       β”‚   β”œβ”€β”€ ml_screening.py      # RF+NN+SVR covariate screening
β”‚       β”‚   └── gp_bnn.py            # GP + BNN models
β”‚       β”œβ”€β”€ validation/metrics.py    # MPE, MAPE, RMSE, CCC, NPDE
β”‚       β”œβ”€β”€ api/                     # FastAPI routes + schemas
β”‚       β”‚   β”œβ”€β”€ main.py              # App entry + CORS
β”‚       β”‚   β”œβ”€β”€ schemas.py           # Pydantic models
β”‚       β”‚   β”œβ”€β”€ safety.py            # 5-layer guardrails
β”‚       β”‚   β”œβ”€β”€ routes_pk.py         # /pk/*
β”‚       β”‚   β”œβ”€β”€ routes_bayesian.py   # /bayesian/*
β”‚       β”‚   β”œβ”€β”€ routes_dosing.py     # /dosing/*
β”‚       β”‚   └── routes_ai.py         # /ai/*
β”‚       └── tests/                   # pytest test suite
β”‚
β”œβ”€β”€ docker/
β”‚   └── init-db.sh                   # Database init script
β”œβ”€β”€ docker-compose.yml               # Multi-service orchestration
β”œβ”€β”€ .github/workflows/ci.yml         # GitHub Actions CI/CD
└── .env.example                     # Environment variables template

πŸš€ Quick Start (Demo cα»₯c bα»™)

YΓͺu cαΊ§u

  • Python 3.11+ (PK Engine)
  • .NET 8 SDK (API Gateway)
  • Node.js 18+ (Frontend)

1. Clone & khởi tẑo

git clone https://github.com/<your-org>/MIPD.git
cd MIPD

2. ChαΊ‘y PK Engine (Terminal 1)

cd src/pk-engine
python -m venv .venv
.venv\Scripts\activate          # Windows
pip install -r requirements.txt
uvicorn api.main:app --port 8000 --reload

β†’ Swagger UI: http://localhost:8000/docs

3. ChαΊ‘y API Gateway (Terminal 2)

cd src/backend/MIPD.ApiGateway
dotnet run --urls "http://localhost:5000"

β†’ Gateway: http://localhost:5000 (JSON info) β†’ Health: http://localhost:5000/health

4. ChαΊ‘y Frontend (Terminal 3)

cd src/frontend
npm install
npm run dev

β†’ App: http://localhost:5173

5. Đăng nhαΊ­p

Email MαΊ­t khαΊ©u Vai trΓ²
admin@mipd.vn admin123 Admin
dr.nguyen@mipd.vn doctor123 Physician
ds.tran@mipd.vn pharma123 Pharmacist
nurse.le@mipd.vn nurse123 Nurse

πŸ“‘ API Endpoints

API Gateway (:5000)

Method Endpoint Chức năng
POST /auth/login Đăng nhαΊ­p β†’ JWT token
POST /auth/register Đăng kΓ½ tΓ i khoαΊ£n
GET /auth/me ThΓ΄ng tin user [Authorized]
GET /health Health check
GET /audit/recent Audit log [Admin]

PK Engine (:8000 qua Gateway /api/*)

Method Endpoint Chức năng
GET / PK Engine health
GET /docs Swagger UI
POST /pk/predict Dα»± Δ‘oΓ‘n nα»“ng Δ‘α»™ + AUC
POST /pk/clinical CrCL, eGFR, IBW, ABW
POST /bayesian/estimate Bayesian estimation (7 methods)
POST /dosing/recommend KhuyαΊΏn nghα»‹ liều + PTA
POST /dosing/cfr Cumulative Fraction of Response
POST /ai/anomaly-check Kiểm tra chαΊ₯t lượng TDM
POST /ai/screen-covariates Sàng lọc covariate
POST /ai/validate-metrics MPE, MAPE, RMSE, CCC

Routing (Vite β†’ Gateway β†’ PK Engine)

Frontend /api/bayesian/estimate
    β†’ Vite proxy    β†’ localhost:5000/api/bayesian/estimate
    β†’ YARP Gateway  β†’ localhost:8000/bayesian/estimate  (strip /api prefix)

πŸ›‘οΈ Hệ thα»‘ng An toΓ n (5 Lα»›p)

Lα»›p BαΊ£o vệ VΓ­ dα»₯
1. Input Validation ChαΊ·n dα»― liệu vΓ΄ lΓ½ Weight < 10 kg, Age > 120
2. PK Plausibility PK params bαΊ₯t thường CL = 0.01 L/h
3. Dose Limits Hard cap liều tα»‘i Δ‘a Max 3000 mg vancomycin
4. Confidence Check Reject CI quΓ‘ rα»™ng CI ratio > 3.0
5. Risk Score Tα»•ng hợp cαΊ£nh bΓ‘o 0.0 (safe) β†’ 1.0 (reject)

πŸ“Š Validation (CSV Upload)

Trang Validation hα»— trợ upload CSV trα»±c tiαΊΏp. File CSV mαΊ«u nαΊ±m trong src/frontend/sample_data/:

File Cα»™t Mα»₯c Δ‘Γ­ch
vpc_sample.csv ID, TIME, DV, PRED, DOSE, WT Visual Predictive Check
bland_altman_sample.csv Patient, Method1, Method2 Bland-Altman plot
npde_sample.csv ID, TIME, DV, PRED, IPRED NPDE histogram + QQ plot

🐳 Docker Deployment

# Copy .env
cp .env.example .env

# Build & run all services
docker compose up --build -d

# Check logs
docker compose logs -f

πŸ§ͺ Testing

# PK Engine tests
cd src/pk-engine
python -m pytest tests/ -v

# Specific test suites
python -m pytest tests/test_bayesian.py -v       # Bayesian methods
python -m pytest tests/test_api_safety.py -v      # Safety guardrails
python -m pytest tests/test_validation_ai.py -v   # AI + validation

πŸ“‹ Tech Stack

Component Technology
Frontend React 18, Vite 5, Recharts
API Gateway .NET 8, YARP, JWT Bearer
PK Engine Python 3.11, FastAPI, NumPy, SciPy
MCMC JAX, NumPyro (Linux/WSL)
AI/ML scikit-learn, BNN
Cache Redis / InMemory fallback
CI/CD GitHub Actions
Container Docker, docker-compose

πŸ‘₯ Vai trΓ² (RBAC)

Vai trò Quyền
Admin Full access + audit log
Physician Xem kαΊΏt quαΊ£ + ra y lệnh
Pharmacist Dose calculator + validation
Nurse Xem phΓ‘c Δ‘α»“ Δ‘iều trα»‹

πŸ“„ License

MIT License

About

Bayesian Model-Informed Precision Dosing (MIPD) platform with Adaptive Algorithms for Vancomycin tailored to the Vietnamese population.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors