使用说明
POC MCP-患者和DPI管理系统
该项目是一个基于模型上下文协议(MCP)的概念验证(POC),使用Docker通过Streamlit web界面管理两个数据库(患者和DPI)。
🏗️ 建筑
该系统由6个Docker服务组成:
- db_patient :患者和普通人的PostgreSQL数据库
- db_dpi :用于患者记录(住院和服务)的PostgreSQL数据库
- 急诊病人 :用于患者和社区管理的REST API(FastAPI)
- api_dpi :用于管理住宿和服务的REST API(FastAPI)
- mcp服务器 :REST MCP服务器公开8个AI工具(端口8003)
- 网络 :带AI聊天机器人的Streamlit web界面(Ollama+LangChain)
MCP数据流
Utilisateur → Streamlit (web:8501)
↓
MCP Client (mcp_client.py)
↓
Ollama LLM (qwen3:8b) ←→ MCP Server (mcp_server:8003)
↓
API Patient + API DPI
↓
Bases de données
📊 数据模型
患者数据库
公社
id:UUID(主键)nom:字符串(唯一)
患者
id:UUID(主键)nom:字符串(indexé)prenom:字符串(indexé)date_naissance:日期(索引)commune_id:UUID(外键→公钥)
DPI数据库
服务
id:UUID(主键)nom:字符串(唯一)
住宿
id:UUID(主键)patient_id:UUID(外部参考)service_id:UUID(外键→服务)date_debut:日期date_fin:日期(可选)
🚀 快速启动
先决条件
- 码头工人
- Docker Compose
启动系统
# copier le fichie exemple.env
cp exemple.env .env
# modifier le fichier .env
vim .env
# Démarrer tous les services
docker-compose up -d
# initailiser les données
python after_init_data/seed_sejours.py ./.env
# Vérifier les logs
docker-compose logs -f
# Arrêter les services
docker-compose down
# Arrêter et supprimer les volumes (reset complet)
docker-compose down -v
🌐 获得服务
- 界面Web流式传输 : http://localhost:8501
- API患者 : http://localhost:8001
- 文档:http://localhost:8001/docs
- API DPI : http://localhost:8002
- 文档:http://localhost:8002/docs
- MCP服务器 : http://localhost:8003
- 工具列表:http://localhost:8003/tools
- 文档:http://localhost:8003/docs
- 患者数据库 :本地主机:5432
- DPI数据库 :本地主机:5433
📝 使用
通过界面网络(Streamlit)
- 打开http://localhost:8501
- 使用侧边栏在部分之间导航:
- 概述 :统计和图表
- 聊天 :与IA聊天(Ollama+MCP-SERVER)
- 患者 :患者名单
- 群体 :城市列表
- 住宿 :住宿清单
- 服务 :服务列表
通过les API
API患者(端口8001)
# Créer une commune
curl -X POST http://localhost:8001/communes \
-H "Content-Type: application/json" \
-d '{"nom": "Bordeaux"}'
# Lister les communes
curl http://localhost:8001/communes
# Créer un patient
curl -X POST http://localhost:8001/patients \
-H "Content-Type: application/json" \
-d '{
"nom": "Dupont",
"prenom": "Jean",
"date_naissance": "1980-05-15",
"commune_id": "<COMMUNE_ID>"
}'
# Lister les patients
curl http://localhost:8001/patients
API DPI(端口8002)
# Créer un service
curl -X POST http://localhost:8002/services \
-H "Content-Type: application/json" \
-d '{"nom": "Radiologie"}'
# Lister les services
curl http://localhost:8002/services
# Créer un séjour
curl -X POST http://localhost:8002/sejours \
-H "Content-Type: application/json" \
-d '{
"patient_id": "<PATIENT_ID>",
"service_id": "<SERVICE_ID>",
"date_debut": "2024-01-15",
"date_fin": "2024-01-20"
}'
# Lister les séjours
curl http://localhost:8002/sejours
# Récupérer les séjours d'un patient
curl http://localhost:8002/sejours/patient/<PATIENT_ID>
MCP服务器(端口8003)
MCP服务器为AI助手公开了8个工具:
# Lister tous les outils disponibles
curl http://localhost:8003/tools
# Appeler un outil (exemple : get_patients)
curl -X POST http://localhost:8003/tools/call \
-H "Content-Type: application/json" \
-d '{
"name": "get_patients",
"arguments": {}
}'
# Rechercher un patient
curl -X POST http://localhost:8003/tools/call \
-H "Content-Type: application/json" \
-d '{
"name": "search_patient",
"arguments": {
"nom": "Dupont",
"prenom": "Jean"
}
}'
# Obtenir des statistiques
curl -X POST http://localhost:8003/tools/call \
-H "Content-Type: application/json" \
-d '{
"name": "get_statistics",
"arguments": {}
}'
可用的MCP工具:
get_patients-列出所有患者search_patient-按姓名搜索患者get_patient_sejours-病人的住宿get_communes-市镇名单get_services-服务列表get_sejours-所有住宿列表get_service_sejours-服务住宿get_statistics-全球统计
🗂️ 项目结构
McpTest/
├── compose.yml # Configuration Docker Compose
├── .env # Variables d'environnement
├── .gitignore # Fichiers à ignorer par Git
├── README.md # Cette documentation
├── start.sh # Script de démarrage
├── stop.sh # Script d'arrêt
├── db/ # Bases de données PostgreSQL
│ ├── patient/ # Base Patient
│ │ ├── init/
│ │ │ └── 01_init.sql # Initialisation tables + données
│ │ └── data/ # Données PostgreSQL (volume)
│ └── dpi/ # Base DPI
│ ├── init/
│ │ └── 01_init.sql # Initialisation tables + données
│ └── data/ # Données PostgreSQL (volume)
├── api_patient/ # API REST Patient (FastAPI)
│ ├── Dockerfile
│ ├── requirements.txt
│ └── server.py
├── api_dpi/ # API REST DPI (FastAPI)
│ ├── Dockerfile
│ ├── requirements.txt
│ └── server.py
├── mcp_server/ # Serveur MCP REST (FastAPI)
│ ├── Dockerfile
│ ├── requirements.txt
│ └── server.py # 8 outils MCP exposés via HTTP
├── web/ # Interface Streamlit
│ ├── Dockerfile
│ ├── requirements.txt
│ ├── app.py # Dashboard principal
│ └── mcp_client.py # Client MCP + LangChain + Ollama
├── memory_bank/ # Documentation du projet
│ ├── project_overview.md
│ ├── api_endpoints.md
│ ├── technical_decisions.md
│ ├── configuration.md
│ └── troubleshooting.md
└── after_init_data/ # Scripts post-initialisation
└── seed_sejours.py # Génération de données de test
🔧 配置
环境变量在文件中定义 .env :
# Database Patient
API_PATIENT_DB=patient_db
API_PATIENT_USER=patient_user
API_PATIENT_PASSWORD=patient_pass
# Database DPI
API_DPI_DB=dpi_db
API_DPI_USER=dpi_user
API_DPI_PASSWORD=dpi_pass
# APIs
API_PATIENT_URL=http://localhost:8001
API_DPI_URL=http://localhost:8002
# MCP Server
MCP_SERVER_URL=http://localhost:8003
# Ollama (pour le chatbot IA)
OLLAMA_HOST=http://host.docker.internal:11434
🛠️ 发展
AI聊天机器人的先决条件
# Installer Ollama (macOS)
brew install ollama
# Démarrer Ollama
ollama serve
# Télécharger le modèle qwen3:8b (dans un autre terminal)
ollama pull qwen3:8b
发射
# Démarrer tous les services
docker-compose up -d
# Ou utiliser le script
./start.sh
访问日志
# Tous les services
docker-compose logs -f
# Service spécifique
docker-compose logs -f api_patient
docker-compose logs -f api_dpi
docker-compose logs -f mcp_server
docker-compose logs -f web
访问数据库
docker exec -it <db_container> psql -U <user> <db_name>
📈 演示数据
数据库使用演示数据初始化:
群体 :普纳乌亚、法阿、帕皮提、皮雷、阿鲁、马希纳
服务 :心脏病学、神经学、急诊、外科、儿科
患者 :启动时生成
住宿 :通过after-init-data/seed-sejours.py随机生成
🐛 故障排除
服务无法启动
# Vérifier l'état des services
docker-compose ps
# Vérifier les logs pour les erreurs
docker-compose logs
数据库连接问题
# Vérifier que les bases sont prêtes
docker-compose logs db_patient
docker-compose logs db_dpi
重置完成
# Arrêter et supprimer tout (conteneurs, volumes, réseaux)
docker-compose down -v
# Redémarrer
docker-compose up -d
📄 许可证
本项目是用于演示目的的POC。