Files
HIS-GUI/data/update_dept_ids.py
2026-04-05 20:11:43 +08:00

66 lines
1.8 KiB
Python

import json
# 部门名称到ID的映射
dept_map = {
"心内科": "DEP1",
"外科": "DEP2",
"神经内科": "DEP3",
"儿科": "DEP4",
"肿瘤科": "DEP5",
"消化内科": "DEP6",
"感染科": "DEP7",
"疼痛科": "DEP8",
"内分泌科": "DEP9",
"风湿免疫科": "DEP10",
"内科": "DEP1" # 别名处理
}
# 更新doctors.txt
with open("doctors.txt", 'r', encoding='utf-8') as f:
doctors = json.load(f)
for doc in doctors:
if doc.get("departmentId") in dept_map:
doc["departmentId"] = dept_map[doc["departmentId"]]
with open("doctors.txt", 'w', encoding='utf-8') as f:
json.dump(doctors, f, ensure_ascii=False, indent=2)
# 更新medicines.txt
with open("medicines.txt", 'r', encoding='utf-8') as f:
medicines = json.load(f)
for med in medicines:
if med.get("departmentId") in dept_map:
med["departmentId"] = dept_map[med["departmentId"]]
with open("medicines.txt", 'w', encoding='utf-8') as f:
json.dump(medicines, f, ensure_ascii=False, indent=2)
# 更新checks.txt
with open("checks.txt", 'r', encoding='utf-8') as f:
checks = json.load(f)
for chk in checks:
if chk.get("departmentId") in dept_map:
chk["departmentId"] = dept_map[chk["departmentId"]]
with open("checks.txt", 'w', encoding='utf-8') as f:
json.dump(checks, f, ensure_ascii=False, indent=2)
# 更新wards.txt
with open("wards.txt", 'r', encoding='utf-8') as f:
wards = json.load(f)
for ward in wards:
if ward.get("departmentId") in dept_map:
ward["departmentId"] = dept_map[ward["departmentId"]]
with open("wards.txt", 'w', encoding='utf-8') as f:
json.dump(wards, f, ensure_ascii=False, indent=2)
print("✓ doctors.txt 已更新")
print("✓ medicines.txt 已更新")
print("✓ checks.txt 已更新")
print("✓ wards.txt 已更新")