Skip to main content

OneEHR

Python 3.12+ PyPI License: MIT Docs

OneEHR is a Python package for longitudinal EHR experiments. It uses standardized EHR tables and a TOML experiment config to run preprocessing, model training, testing, analysis, and figures across conventional ML/DL models and LLM or agent systems.

What OneEHR Provides

  • Three-table EHR input contract: dynamic.csv, optional static.csv, and optional label.csv
  • 42 built-in model architectures: tabular ML, recurrent and non-recurrent DL, irregular-time, multimodal, KG-enhanced, EHR-specialized, and survival models
  • One run directory per experiment: preprocessing artifacts, checkpoints, predictions, metrics, analysis JSON, and figures
  • Dataset converters: MIMIC-III, MIMIC-IV, and eICU converters for common clinical prediction tasks
  • Medical code utilities: ICD-9/10 parsing, CCS grouping, ATC hierarchy, and code mapping helpers
  • Analysis modules: comparison metrics, bootstrap confidence intervals, feature importance, fairness, calibration, statistical tests, and missing-data summaries
  • Plot commands: ROC, PR, calibration, confusion, forest, fairness, missing-data, decision-curve, significance, cohort-flow, and training-curve figures

Install

OneEHR requires Python 3.12+.

pip install oneehr
oneehr --help

Install from a source checkout:

git clone https://github.com/MedX-PKU/OneEHR.git
cd OneEHR
uv venv .venv --python 3.12
source .venv/bin/activate
uv pip install -e ".[test]"
uv run oneehr --help

Optional extras:

pip install "oneehr[survival]"  # lifelines support for survival analysis
pip install lime                # optional LIME interpretability support

Quickstart

Run the bundled TJH COVID-19 ICU example from a source checkout:

uv run python examples/tjh/convert.py

CONFIG=examples/tjh/mortality_patient.toml
uv run oneehr preprocess --config "$CONFIG"
uv run oneehr train      --config "$CONFIG"
uv run oneehr test       --config "$CONFIG"
uv run oneehr analyze    --config "$CONFIG"
uv run oneehr plot       --config "$CONFIG" --style nature

The run is written to runs/tjh/:

runs/tjh/
    manifest.json
    preprocess/
    train/
    test/
    analyze/
    figures/

Use the Python API with the config path:

import oneehr

config_path = "examples/tjh/mortality_patient.toml"

preprocess_result = oneehr.preprocess(config_path)
train_result = oneehr.train(config_path)
test_result = oneehr.test(config_path)
analysis_result = oneehr.analyze(config_path)

print(preprocess_result.run_dir)
print(test_result.metrics_path)
print(analysis_result.modules_run)

Input Data

OneEHR expects plain CSV files:

dynamic.csv: patient_id, event_time, code, value
static.csv:  patient_id, <patient-level covariates...>
label.csv:   patient_id, label_time, label_code, label_value

Example TOML:

[dataset]
dynamic = "data/dynamic.csv"
static = "data/static.csv"
label = "data/label.csv"

[task]
kind = "binary"
prediction_mode = "patient"

[[models]]
name = "xgboost"

[[models]]
name = "gru"

[output]
root = "runs"
run_name = "my_experiment"

See Data Model and Configuration for the full contract.

CLI Workflow

oneehr preprocess --config experiment.toml
oneehr train      --config experiment.toml
oneehr test       --config experiment.toml
oneehr analyze    --config experiment.toml
oneehr plot       --config experiment.toml

Dataset conversion:

oneehr convert --dataset mimic3 --raw-dir /path/to/mimic3 --output-dir data/mimic3 --task mortality
oneehr convert --dataset mimic4 --raw-dir /path/to/mimic4 --output-dir data/mimic4 --task mortality
oneehr convert --dataset eicu   --raw-dir /path/to/eicu   --output-dir data/eicu   --task mortality

Models

Category Config names
Tabular ML xgboost, catboost, rf, dt, gbdt, lr
Recurrent gru, lstm, rnn, grud, dipole, hitanet, m3care, pai
Non-recurrent cnn, tcn, transformer, sand, mlp, deepr, mamba, jamba, lsan
Irregular-time mtand, raindrop, contiformer, teco
EHR-specialized adacare, stagenet, retain, concare, grasp, mcgru, dragent, prism, safari
Multimodal emerge
KG-enhanced graphcare, kerprint, protoehr
Survival deepsurv, deephit

Models with static branches use patient-level static features when static.csv is provided. KG-enhanced models use the built-in lightweight_auto KG preset unless kg_source = "external" and external_kg_path are provided.

Documentation

Full documentation: medx-pku.github.io/OneEHR

Run the documentation site locally:

uv run --group docs mkdocs serve

Build the static site:

uv run --group docs mkdocs build

Development

uv venv .venv --python 3.12
source .venv/bin/activate
uv pip install -e ".[test]"
pytest tests/ -v
ruff check oneehr tests

See CONTRIBUTING.md for contribution guidelines.

Metadata

Release files for oneehr 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oneehr 0.1.2
File Size Uploaded
oneehr-0.1.2.tar.gz 167.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for oneehr 0.1.2
File Interpreter ABI Platform
oneehr-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 374.4 kB

Release files / oneehr-0.1.2.tar.gz

Download URL oneehr-0.1.2.tar.gz
Size 167.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4ab3a5fe99c482b94b31e3884c7451311e520a0767c842d3cd976676b2061b76
BLAKE2b-256 checksum
How to use checksums
b49706ebcaa5f0a4fb700180baa2397d25bf7fd7023feb4d5c69bd266d958666
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 25, 2026.

Transparency log

Release files / oneehr-0.1.2-py3-none-any.whl

Download URL oneehr-0.1.2-py3-none-any.whl
Size 206.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2eca32cf22f7b8d738a2494074cf54fd792260715c24863141183c4d3a930176
BLAKE2b-256 checksum
How to use checksums
83ca863cec5aeeef8c3b903783de39c804ba39b15e319e3b27d3d3115738b56c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page