Skip to content

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

DashboardResults (PK Curve 3 lớp)
DashboardResults
VPC ChartBland-Altman PlotNPDE Histogram + QQ
VPCBland-AltmanNPDE

🎯 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

EmailMật khẩuVai trò
admin@mipd.vnadmin123Admin
dr.nguyen@mipd.vndoctor123Physician
ds.tran@mipd.vnpharma123Pharmacist
nurse.le@mipd.vnnurse123Nurse

📡 API Endpoints

API Gateway (:5000)

MethodEndpointChức năng
POST/auth/loginĐăng nhập → JWT token
POST/auth/registerĐăng ký tài khoản
GET/auth/meThông tin user [Authorized]
GET/healthHealth check
GET/audit/recentAudit log [Admin]

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

MethodEndpointChức năng
GET/PK Engine health
GET/docsSwagger UI
POST/pk/predictDự đoán nồng độ + AUC
POST/pk/clinicalCrCL, eGFR, IBW, ABW
POST/bayesian/estimateBayesian estimation (7 methods)
POST/dosing/recommendKhuyến nghị liều + PTA
POST/dosing/cfrCumulative Fraction of Response
POST/ai/anomaly-checkKiểm tra chất lượng TDM
POST/ai/screen-covariatesSàng lọc covariate
POST/ai/validate-metricsMPE, 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ớpBảo vệVí dụ
1. Input ValidationChặn dữ liệu vô lýWeight < 10 kg, Age > 120
2. PK PlausibilityPK params bất thườngCL = 0.01 L/h
3. Dose LimitsHard cap liều tối đaMax 3000 mg vancomycin
4. Confidence CheckReject CI quá rộngCI ratio > 3.0
5. Risk ScoreTổng hợp cảnh báo0.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/:

FileCộtMục đích
vpc_sample.csvID, TIME, DV, PRED, DOSE, WTVisual Predictive Check
bland_altman_sample.csvPatient, Method1, Method2Bland-Altman plot
npde_sample.csvID, TIME, DV, PRED, IPREDNPDE 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 testscd 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

ComponentTechnology
FrontendReact 18, Vite 5, Recharts
API Gateway.NET 8, YARP, JWT Bearer
PK EnginePython 3.11, FastAPI, NumPy, SciPy
MCMCJAX, NumPyro (Linux/WSL)
AI/MLscikit-learn, BNN
CacheRedis / InMemory fallback
CI/CDGitHub Actions
ContainerDocker, docker-compose

👥 Vai trò (RBAC)

Vai tròQuyền
AdminFull access + audit log
PhysicianXem kết quả + ra y lệnh
PharmacistDose calculator + validation
NurseXem 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

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages