Skip to main content

Role-tagged, causally-ordered clinical event streams from MIMIC-IV and EHRSHOT.

Project description

mimic-event-stream

Turn per-table clinical records into one causally-ordered, role-tagged event stream per patient — every event tagged condition (a measurement), action (an intervention), or label (a clinician inference) — with an admission-scoped leakage guard. MIMIC-IV and EHRSHOT (OMOP) share one Event model and ordering.

The package contains code only — no patient data. MIMIC-IV and EHRSHOT are separately licensed (PhysioNet credentialed access / EHRSHOT DUA); point the loader at your own licensed copy.

Install

pip install mimic-event-stream

Quick start

from mimic_event_stream import DemoLoader, build_stream, render_timeline

loader = DemoLoader(root="/path/to/mimic-iv-clinical-database-demo")
stream = build_stream(loader, subject_id=loader.subject_ids[0])
for ev in stream[:20]:
    print(ev.event_time, ev.role.name, ev.value)

print(render_timeline(loader, loader.subject_ids[0], max_events=40))

EHRSHOT (OMOP flat timeline):

from mimic_event_stream import build_ehrshot_stream, load_ehrshot_patient

rows = load_ehrshot_patient("EHRSHOT_ASSETS/data/ehrshot.csv", patient_id=123)
stream = build_ehrshot_stream(rows, patient_id=123)

Point the loader with the WMB_MIMIC4_DEMO_DIR env var, or pass root= directly. For full MIMIC-IV (18 GB labevents, 40 GB chartevents), use the size-agnostic DuckDBLoader (subject-filtered scans, Parquet-cached):

from mimic_event_stream.duckdb_loader import DuckDBLoader, sample_icu_subjects

subjects = sample_icu_subjects("/path/to/mimic-iv", n=200)
loader = DuckDBLoader("/path/to/mimic-iv", subjects, cache_dir="/scratch/cache")

The Event model

Each Event carries subject_id, visit_id, event_time, an honest time_resolution, a role (condition < action < label on ties), the source table, and a pre-rendered value. Events sort by (event_time, resolution, role, source, seq) for a deterministic causal order; admission-level labels are re-anchored after the last real event of their admission so a discharge diagnosis can never precede a same-admission measurement (the leakage guard).

Development

git clone https://github.com/josh-freeman/mimic-event-stream
cd mimic-event-stream
uv sync --extra dev
WMB_MIMIC4_DEMO_DIR=/path/to/demo pytest tests/ -q

The repository also contains research code under tte/ (bulk QA benchmarks, RL) and recommendation_qa/ — these are not part of the published package.

License

MIT (code only — see LICENSE). Not affiliated with or endorsed by PhysioNet or MIT-LCP.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mimic_event_stream-0.1.0.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mimic_event_stream-0.1.0-py3-none-any.whl (40.5 kB view details)

Uploaded Python 3

File details

Details for the file mimic_event_stream-0.1.0.tar.gz.

File metadata

  • Download URL: mimic_event_stream-0.1.0.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Rocky Linux","version":"8.10","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mimic_event_stream-0.1.0.tar.gz
Algorithm Hash digest
SHA256 95a6c84e0dc5138cf82471aef553bb772d5fdd25cc918ddac5b2e431b0f88743
MD5 802c95b4e5069a394fcd86fb0b63a42d
BLAKE2b-256 64227f7c53c15fd2858467377b6012d155c43d2244fa342f724611b6a300318b

See more details on using hashes here.

File details

Details for the file mimic_event_stream-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mimic_event_stream-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 40.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Rocky Linux","version":"8.10","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mimic_event_stream-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d9ba6f9993c043e79e6ba96540e59d02e398ea3c47017c1b8175b3b3341b316
MD5 a34755f91911e625145bb7080ac7a39b
BLAKE2b-256 cfad4b8be3155c354dbc69caabe4232bc4f8037f500f638e3720fba735ad9912

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page