#!/usr/bin/env python # -*- coding: utf-8 -*- """把 患者报告\<病历号>\病理报告\病理报告.json 全部汇总成一个json文件""" import json import os OUTPUT_ROOT = r"C:\Users\senqu\Desktop\尚安迪\2026.8.25\患者报告" MERGED_PATH = r"C:\Users\senqu\Desktop\尚安迪\2026.8.25\病理报告汇总.json" def main(): merged = {} patient_count = 0 report_count = 0 for cn in sorted(os.listdir(OUTPUT_ROOT)): json_path = os.path.join(OUTPUT_ROOT, cn, "病理报告", "病理报告.json") if not os.path.isfile(json_path): continue with open(json_path, 'r', encoding='utf-8') as f: reports = json.load(f) if not reports: continue merged[cn] = reports patient_count += 1 report_count += len(reports) with open(MERGED_PATH, 'w', encoding='utf-8') as f: json.dump(merged, f, ensure_ascii=False, indent=2) print(f"汇总完成: {patient_count} 个患者, {report_count} 份报告") print(f"输出文件: {MERGED_PATH}") if __name__ == '__main__': main()