Add document downloader and treatment-plan summary combining orders + operation notes

This commit is contained in:
2026-08-06 10:57:53 +08:00
parent 381168a27a
commit 9a041ffb53
3 changed files with 470 additions and 6 deletions
+25 -6
View File
@@ -1,6 +1,6 @@
# medical_orders
批量从住院病历系统(HIS)抓取患者医嘱(长期医嘱 + 临时医嘱),按住院次归档保存。
从住院病历系统(HIS)批量抓取患者医嘱、手术记录/出院记录,并汇总出每位患者的治疗方案(手术/化疗/放疗/免疫/靶向、新辅助 vs 辅助)。
## 用法
@@ -11,19 +11,38 @@
pip install -r requirements.txt
```
3. 运行:
3. 抓医嘱(长期+临时):
```
python download_orders.py --template patient_id.csv --output-dir orders_output
```
4. 抓手术记录/出院记录(用于判断是否真的做了手术、出院诊断、TNM分期):
```
python download_documents.py --template patient_id.csv --output-dir docs_output
```
5. 合并两者,生成治疗方案汇总表:
```
python analyze_treatment.py --orders-dir orders_output --docs-dir docs_output --out orders_output/treatment_summary.csv
```
## 为什么手术判断要单独抓文书
医嘱系统里的"手术"类目记录的大多是介入性/诊断性小操作(输液港置入、局麻收费、内镜检查等),并不等于确诊性的肿瘤根治手术。真正的手术信息只存在于"手术记录"/"出院记录"病历文书里,所以 `download_documents.py` 单独走 `Medical/Index` + `Medical/MedicalRecord` 接口抓这两类文书(注意:`Medical/IndexV5` 接口在这批数据上返回"无病历文书",抓不到东西,要用旧版 `Medical/Index`)。
`analyze_treatment.py` 的"新辅助 vs 辅助"判断是靠比较手术所在住院次(visit_id)和化疗/免疫医嘱所在住院次的先后,是基于结构化记录的启发式判断,不是逐份病历审阅,建议抽查核实后再用于正式分析。
## 输出
写入 `--output-dir`(默认 `orders_output/`,已在 `.gitignore` 中排除):
均写入各自 `--output-dir`(默认 `orders_output/`、`docs_output/`,均已在 `.gitignore` 中排除):
- `<住院号>.json`:该患者每次住院的长期/临时医嘱原始行数据
- `orders_summary.csv`:所有患者、所有住院次的医嘱汇总表
- `orders_output/<住院号>.json` / `orders_summary.csv`:医嘱原始数据
- `docs_output/<住院号>.json` / `documents_summary.csv`:手术记录/出院记录抽取结果
- `orders_output/treatment_summary.csv`:合并后的治疗方案汇总表
## 隐私说明
抓取结果包含患者姓名、住院号等真实隐私信息(PHI),**任何情况下都不要提交到 Git 仓库**。仓库里只保留代码和空模板;真实的患者名单文件和下载结果目录已通过 `.gitignore` 排除。
抓取结果包含患者姓名、住院号、诊断等真实隐私信息(PHI),**任何情况下都不要提交到 Git 仓库**。仓库里只保留代码和空模板;真实的患者名单文件和下载结果目录已通过 `.gitignore` 排除。