Skip to content

[Feature] Add custom CSV EHR dataset adapter for lightweight onboarding - #1298

Open
burual wants to merge 2 commits into
sunlabuiuc:masterfrom
burual:feature/custom-csv-adapter
Open

burual wants to merge 2 commits into
sunlabuiuc:masterfrom
burual:feature/custom-csv-adapter

Conversation

@burual

@burual burual commented Oct 15, 2026

Copy link
Copy Markdown

Summary

为 PyHealth 添加一个轻量级自定义 CSV 病历数据 adapter,方便新手在不了解 PyHealth 完整架构的情况下快速上手并理解 Patient→Visit→Event 三层数据模型。

Changes

  • pyhealth/datasets/synthetic_ehr.py — 新的 SyntheticEHRDataset 类

    • 继承 BaseDataset(2.x 架构),同时保留 1.x 风格的直观结构作为教学桥梁
    • 从自定义 CSV 文件加载电子健康记录数据
    • 自动解析患者人口学信息、诊断、手术、药物和实验室检查
    • 就诊按时间戳排序
  • tests/core/test_synthetic_ehr.py — 7 个 pytest 单元测试

    • test_load_normal_csv — 3 患者 × 2 就诊
    • test_patient_metadata — 性别/年龄解析
    • test_visit_timestamp_sorting — 就诊时间排序
    • test_event_types_present — 四种事件类型
    • test_lab_values — 实验室检查值
    • test_empty_csv — 空 CSV 边界情况
    • test_multiple_visits_same_patient — 同患者多次就诊
  • examples/synthetic_ehr/generate_synthetic_ehr.py — 合成数据生成脚本

    • 生成 10 患者、23 条就诊记录的示例 CSV

Testing

所有 7 个测试在本机通过(Python 3.12.7)。

Notes

  • CSV 文件不提交仓库,仅提交生成脚本
  • 设计为教学用途,降低新贡献者的入门门槛

- pyhealth/datasets/synthetic_ehr.py: parse custom CSV into Patient-Visit-Event structure, compatible with 1.x-style API

- tests/core/test_synthetic_ehr.py: 7 pytest unit tests

- examples/synthetic_ehr/: example data generator + synthetic_ehr.csv
@jhnwu3 jhnwu3 added the status: manual Pending maintainer's review label Oct 19, 2026
@jhnwu3

jhnwu3 commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

/review

@github-actions

Copy link
Copy Markdown

Test Coverage

Warning

Tests failure; coverage may be incomplete.

Total: 67.92% (16837 / 24791 lines)

Modified file Coverage Lines
pyhealth/datasets/synthetic_ehr.py 70.56% 139 / 197

Workflow run · c108871

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: manual Pending maintainer's review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants