eICU MEDS Extraction ETL
This repository contains the code for downloading the eICU dataset from PhysioNet and transforming it into the Medical Event Data Standard (MEDS) format.
pip install eICU-MEDS
export DATASET_DOWNLOAD_USERNAME=$PHYSIONET_USERNAME
export DATASET_DOWNLOAD_PASSWORD=$PHYSIONET_PASSWORD
meds-extract-run spec=eICU output_dir=data/eicu_meds
The package registers its ETL with MEDS-Extract as the
spec eICU (src/eICU_MEDS/configs/event_configs.yaml),
so meds-extract-run runs all of it. When you run this, it will:
- Download the raw eICU-CRD tables this ETL reads (see
Which eICU tables are extracted) for the currently supported
version into
data/eicu_meds/.meds_extract_run/raw_input(download_dest_dir=puts them elsewhere). Files that already exist and verify against PhysioNet'sSHA256SUMS.txtare skipped, so an interrupted run resumes rather than restarting. - Write the two tables the config reads that the release does not have (the ICD codes of each
diagnosis path and the packaged lab descriptions) into
data/eicu_meds/eicu_pre_meds, with this package'seicu_pre_medsstage. The raw directory is never modified. Like every stage directory, it is deleted once the whole run has succeeded (see below). - Construct the MEDS cohort from the raw tables — every transformation, join, pseudotime derivation
and code description is declared in the spec — and write it to
data/eicu_meds/dataanddata/eicu_meds/metadata. - Run suMEDS's shared
sumeds_link_unit_siblings, which links codes that differ only in their unit (docs): a lab seen in two or more units (LAB//RESULT//{labname}//{unit}, and its…//UNKcode) getsLAB//RESULT//{labname}as parent, with a row of its own. Withlink_single_units: true, a lab seen in one unit gets its stem too, so every code that ends in its unit has one. Thensumeds_normalize_unitswritesunitin UCUM. - Sort each code's ICD parent codes (
eicu_sort_parent_codes). - Enrich
metadata/codes.parquetin place with suMEDS (installed with this package): LOINC parents for lab codes and parents among eICU's own codes (see Enriching code metadata with suMEDS). A failed enrichment (e.g. without internet) does not fail the run, andmetadata/dataset.jsonrecords whether the build was enriched.
The public demo needs no credentials:
meds-extract-run spec=eICU output_dir=data/eicu_demo dataset_key=demo
To build from raw tables you already have, skip the download (add dataset_key=demo for a copy of
the demo, so that metadata/dataset.json records the demo's version):
meds-extract-run spec=eICU output_dir=$MEDS_OUTPUT_DIR do_download=false input_dir=$RAW_INPUT_DIR
Run it with the environment it is installed in activated (or through uv run): MEDS-Transforms
starts each stage as the MEDS_transform-stage command found on PATH, so calling
/path/to/venv/bin/meds-extract-run without activating that environment fails at the first stage
(exit code 127). MEDS_extract-eICU added its own environment to PATH; meds-extract-run does not.
PhysioNet throttles each connection to about 50 KB/s but not the total, so more parallel
connections download faster: download_concurrency=8 (the default is 4) matches what
MEDS_extract-eICU used.
Each stage writes its intermediate output to output_dir/<stage>/, and those directories (the
eicu_pre_meds tables included) are deleted after a successful run, by default: the spec sets
MEDS-Extract's etl.cleanup_intermediates: true, so a finished output holds only data/,
metadata/, .logs/ and .meds_extract_run/. A failed run keeps them, so the same command resumes
where it stopped, and the same command on a finished output still does nothing. To keep them (to look
at a stage's output; output_dir/.logs/pipeline.log keeps the stage logs either way), add
"overrides=['cleanup_intermediates=false']"; the do_cleanup_intermediates= flag of older
MEDS-Extract releases is gone. Cleanup never deletes raw data: a download into the default
output_dir/.meds_extract_run/raw_input stays, and download_dest_dir= elsewhere lets other output
directories reuse it. See the
MEDS-Extract README for
the other options of meds-extract-run.
Migrating from MEDS_extract-eICU
Releases up to 0.2.0 shipped their own runner, MEDS_extract-eICU. It is gone; meds-extract-run
builds the same events and code metadata (the literal codes and lab names outside the lab table now
also carry a code_template). Its options map as follows:
MEDS_extract-eICU |
meds-extract-run spec=eICU |
|---|---|
root_output_dir=ROOT (cohort in ROOT/MEDS_output) |
output_dir=OUT (cohort in OUT/data, OUT/metadata) |
raw_input_dir=RAW (download destination) |
download_dest_dir=RAW |
raw_input_dir=RAW do_download=False |
input_dir=RAW do_download=false |
do_demo=True |
dataset_key=demo |
download_workers=8 |
download_concurrency=8 |
do_enrich=false |
skip_stages=[sumeds_enrich] |
'enrich_args=[--strict]' |
"overrides=['++stage_cfg.strict=true']" (see below) |
N_WORKERS=8 |
stage_runner_fp=runner.yaml (see Parallel runs) |
A note on time in eICU
eICU contains no absolute timestamps. Every table records an integer offset in minutes relative to unit admission, and health-system stays are ordered only at year granularity. This pipeline therefore:
- uses the health system stay (
patienthealthsystemstayid) as the MEDSsubject_id, since events are well ordered only within a stay; and - anchors each stay at a constant, arbitrary pseudo-date (December 31 of the recorded discharge year, at the recorded discharge clock time) and derives every event time by offsetting from it.
Only relative time differences within a subject are meaningful. Absolute dates in the output are not real and must not be interpreted as such: because every stay ends on December 31, the date of an event reveals how long until hospital discharge. See docs/data_leakage.md for this and every other way the output can leak information, table by table.
Stay and site ids
The id columns follow the MIMIC-IV ETL's names, so hadm_id is a hospital stay in both:
| column | eICU source | on which events | metadata/dataset.json |
|---|---|---|---|
subject_id |
patienthealthsystemstayid (hospital stay) |
all | (core column) |
hadm_id |
patienthealthsystemstayid (hospital stay) |
the hospital and unit admissions and discharges, and the unit weights and height | raw_source_id_columns |
icustay_id |
patientunitstayid (unit stay) |
the unit events of the patient table, and the events of admissionDx, intakeOutput, nurseAssessment, nurseCare, nurseCharting, pastHistory, physicalExam and respiratoryCharting | raw_source_id_columns |
hospital_id |
hospitalid (the hospital, one of 208) |
the same events as hadm_id |
site_id_columns |
Every clinical eICU table is keyed by the unit stay (patientunitstayid), and the ETL joins patient
on it to find the subject (patienthealthsystemstayid) and the time anchor. Because the subject is the
hospital stay, hadm_id always equals subject_id; it is there so that queries written for hadm_id
mean the same thing across datasets. One hospital stay can span several unit stays; icustay_id tells
them apart on the events listed above (the other tables, such as lab and the vitals, are keyed by unit
stay too but do not carry it yet). hospital_id is the site of care, not a stay: a site_id_columns
column, as the MEDS dataset metadata schema
defines it.
Death
MEDS_DEATH is emitted at hospital discharge when hospitalDischargeStatus == "Expired", and from
no other field. The
documentation
describes Expired as the patient's condition on leaving the hospital, and on the full release it
agrees with the independently populated hospitalDischargeLocation == "Death" on every one of the
200,859 rows (18,004 deaths).
Hospital rather than unit status is the key because it is the more complete of the two: 7,315 rows
record a unit discharge Alive followed by a hospital death, which unit status would miss.
The converse is deliberately not used. 222 rows (0.1%) have unitDischargeStatus == "Expired"
while hospital status is Alive or blank, and these emit no MEDS_DEATH. They contradict
themselves: in 142 of them the hospital stay continues past the unit discharge at which the
patient supposedly died, some to a discharge home. Rows with a blank hospital status (1,751) are
likewise not treated as deaths. See
#11.
Vital signs: only measurements that happened
vitalPeriodic and vitalAperiodic are wide tables — one row per timestamp, one column per
vital sign — and most cells are empty. A row that recorded a heart rate still carries columns
for intracranial pressure, end-tidal CO2 and the pulmonary-artery pressures, which need
invasive lines that most patients never have.
Each vital's code is therefore guarded so that a missing cell emits no event, rather than an event asserting the measurement was taken with no value attached. Without the guard the full cohort carries 2.60 billion vitals rows of which 69.8% are empty; with it, 785 million, all of them real. Per-vital emptiness in the raw data ranges from 0.5% (heart rate) to 98.2% (intracranial pressure).
The guard is written if $x == $x, which is true for any present value — including 0, inf
and NaN — and null for a missing one, which nulls the code and drops the row. It reads oddly
because dftly has no null test; if $x will not type-check against a float column and a bare
null parses as the string "null". Tracked in
dftly#113; this becomes if is_present($x)
once that lands.
NaN and inf are deliberately preserved rather than dropped — they are recorded values, and
changing that is a data-modelling decision rather than a bug fix.
Numeric-value guards
numeric_value is strict-cast downstream, so a String source column containing a single
non-numeric row aborts the stage. Which columns are String is not inferable from the demo — it
depends on what junk happens to appear — so the guarded set comes from the official eICU DDL
(MIT-LCP/eicu-code, postgres_create_tables.sql): age, medication.dosage,
infusiondrug.{infusionrate, patientweight}, nurseCharting.nursingChartValue,
respiratoryCharting.respChartValue, nurseAssessment.cellAttributeValue,
nurseCare.cellAttributeValue and physicalExam.physicalExamText.
Numeric-typed columns are passed through bare, since the schema forbids junk in them.
Where the non-numeric remainder is worth keeping (charted values, below), the same pattern also
appears negated as a regex match, $x if not (/<guard>/ in $x), to fill text_value, so each
event carries exactly one of the two values.
The guard regex is exactly Rust's f64::from_str grammar, so it is value-for-value identical to
polars' non-strict cast. A narrower hand-rolled pattern silently drops real values such as
1e5, 25. and +5; tests/test_numeric_guard.py pins the equivalence by differential
fuzzing.
Charted observations
Several tables record each observation as one varchar cell under picklist labels or a label path. Each row becomes one event whose code is the table's prefix followed by those labels:
| Table | Code | Time | Full-release rows | Blank (no event) | Entry = chart offset | Entry lag, 90th percentile |
|---|---|---|---|---|---|---|
nurseCharting |
NURSE_CHARTING//<category>//<label>//<name> |
nursingChartEntryOffset |
151,604,232 | 284,600 | 73% | 57 min |
respiratoryCharting |
RESPIRATORY_CHARTING//<category>//<label> |
respChartEntryOffset |
20,168,176 | 3 | 75% | 47 min |
nurseAssessment |
NURSE_ASSESSMENT//<cellAttributePath> |
nurseAssessEntryOffset |
15,602,498 | 0 | 5% | 195 min |
nurseCare |
NURSE_CARE//<cellAttributePath> |
nurseCareEntryOffset |
8,311,132 | 0 | 5% | 206 min |
- A value the numeric guard accepts goes to
numeric_value. Anything else, such as GCS descriptors (4-->(E4) spontaneous),Oral,WDLorNasal cannula, goes totext_value. A value written as a percentage (35%) is text: stripping the%would need a second guard pattern. - A blank cell emits no event.
- The time is the entry offset, not the charted offset, so a value is not visible before it was recorded. The last two columns show how far apart the two are.
- The category is part of the code because the same label can sit under more than one category:
PAunder bothInvasiveandVital SignsinnurseCharting(96 codes from 83 label/name pairs on the full release), and 198 codes from 194 labels inrespiratoryCharting. - In the path-coded tables the path ends in the attribute (
…|Neurologic|Pupils|Right) and determines the label, so the path alone is the code. They cover few stays:nurseAssessmenthas rows for 13,001 andnurseCarefor 13,052 of the 200,859 unit stays on the full release. - Vitals charted here overlap with
vitalPeriodic/vitalAperiodic. They keep their own source-prefixed codes, and nothing is deduplicated across tables. - The two charted tables overlap in one measurement: on the full release, 79% of
respiratoryCharting'sRR (patient)values repeatnurseCharting'sRespiratory Ratefor the same stay at the same minute. Ventilator settings and measurements (PEEP, tidal volume, pressure support, plateau pressure, compliance) appear only inrespiratoryCharting.
Intake and output
intakeOutput is the nursing intake/output flowsheet. Each row becomes one
INTAKE_OUTPUT//<cellPath> event, for example
INTAKE_OUTPUT//flowsheet|Flowsheet Cell Labels|I&O|Output (ml)|Urine, valued by the row's own
cellValueNumeric and timed at intakeOutputEntryOffset, as for the charted tables. The path ends
in the row's label, so the label adds nothing to the code.
intakeTotal,outputTotal,dialysisTotalandnetTotalare not emitted. The documentation describes them as cumulative up to the row's offset and repeated across rows entered at the same time, so emitting them would count the same fluid many times.cellValueTextis not emitted. It is the same number written as text.- Rows are not deduplicated. On the full release 9,619 rows repeat another row in everything but their ID, and the table gives no way to tell a repeated entry from two equal ones.
- The documentation says
cellValueNumericis always positive. 1,476 full-release rows are negative, and they are emitted as recorded.
Physical exam
physicalExam holds the structured physical exam entered in eCareManager. Each row becomes one
PHYSICAL_EXAM//<physicalExamPath> event, for example
PHYSICAL_EXAM//notes/Progress Notes/Physical Exam/Physical Exam/Neurologic/GCS/Motor Score/6,
timed at physicalExamOffset, the table's only offset, which the documentation describes as the
time the item was entered.
- The path ends in the picklist choice (
physicalExamValue), so the choice is already in the code. physicalExamTextis split like the charted values. For 63 vital-sign, weight and I&O items (HR Current,Weight (kg)/Admission, …) it is the measurement and goes tonumeric_value; for the other items it mostly repeats the choice and goes totext_value.- A blank text does not drop the event, because the path is the finding. On the full release 41,327 rows have a blank text, all in items that are not measurements, and their events carry no value.
- The vital signs here are the exam's summaries (current, lowest and highest over 24 hours). Like
the charted vitals, they keep their own codes and are not deduplicated against
vitalPeriodic.
Code metadata: descriptions
metadata/codes.parquet carries code, description, parent_codes and code_template. eICU
ships no code dictionary (nothing like MIMIC-IV's d_labitems): its tables record the names
themselves (labName, drugName, treatmentString, diagnosisString), so the codes are
human-readable on their own and releases up to 0.1.0 wrote no description. That is enough
for a reader, not for tooling that maps codes across datasets or builds features from
descriptions: vital codes are column names (VITALS//PERIODIC//HEARTRATE), lab names are
site picklist abbreviations (Hgb, -polys, WBC x 1000), and vocabulary-based enrichment
(OHDSI Athena) cannot resolve either. So every code now gets the documented meaning of what it
encodes, through three routes, with the source of each description recorded:
| Code family | Route | Source of the text |
|---|---|---|
LAB//RESULT//…, LAB//SPECIMEN_DRAWN//… |
src/eICU_MEDS/metadata/lab_descriptions.csv, which the eicu_pre_meds stage writes as lab_descriptions.parquet; the lab table joins it on the raw labname (one row covers every unit variant), and a _self template reads its description |
per row, in the table's source column: the WeavEHR concept the lab name maps to (aidh-ms/WeavEHR configs/datasets/eicu-crd/2.0/mappings, MIT, commit 210a539), the label of the MIMIC-IV lab item mapped to the same concept (mimic-code d_labitems_to_loinc.csv, MIT), the canonical column in eicu-code pivoted-lab.sql / pivoted-bg.sql (MIT), or, for the long tail, a plain expansion of the picklist name marked expansion |
literal codes: the 26 VITALS//…, ICU_ADMISSION_WEIGHT/_HEIGHT, ICU_DISCHARGE_WEIGHT, SUBJECT_WEIGHT_AT_INFUSION, INFUSION_DRUG, CAREPLAN_EOL, MEDS_BIRTH, MEDS_DEATH |
a constant _self description in configs/event_configs.yaml, with the source of the text in a # Source: comment above it |
per row: the column description in the eICU-CRD table documentation, the WeavEHR concept and unit, and the MIMIC-IV d_items label of the item WeavEHR maps to the same concept (open MIMIC-IV demo, ODbL); expansion where only the abbreviation is documented (ST1–3, SVR/SVRI, PVR/PVRI, cardiac input) |
| every other family (patient events, diagnoses, admission diagnoses, allergies, care plan items, intake/output, medications, nursing assessment, nursing care, nurse charting, past history, physical exam, respiratory charting, treatments) | _metadata: _self: description: templates in configs/event_configs.yaml, evaluated per event |
the code's own components, named after the eICU-CRD column they come from (patient.unitAdmitSource, diagnosis.diagnosisString, …) |
The lab table carries descriptions only. eICU records no LOINC code for its lab names, so the
ETL writes no LOINC parent for them; the lab-name to LOINC crosswalk is part of suMEDS's
versioned ontology data and is applied after extraction (see Enriching code metadata with suMEDS).
Diagnoses keep their ICD parents (below), which come from eICU's own icd9code column.
The lab table lists only lab names that are already public: the 147 in the open eICU-CRD demo
(ODbL) and one more in eicu-code (MIT). It ships nothing
that exists only in the credentialed release. A lab name outside the table (or a blank one) gets a
generic description from the same template, for example Lab result (eICU lab.labName '<labname>').
Every description is written by MEDS-Extract from the spec. Releases up to 0.2.0 filled in the literal codes and the lab names outside the table after the pipeline, because MEDS-Extract could not attach metadata to a code without components before 0.8.1; the text is the same.
On the demo (eICU-CRD demo 2.0.1) every one of the 8,122 codes is described: 294 lab codes, 34 literal codes, and 7,794 component-coded codes. Event data is untouched: per-code event counts are identical to a build without this metadata.
On the full release (eICU-CRD 2.0) every one of the 15,528 codes is described: 316 lab codes
(a RESULT and a SPECIMEN_DRAWN code for each of the 158 lab names; 148 names are in the
table and the other 10 get the generic description), 34 literal codes, and 15,178
component-coded codes. Every code in the data is in codes.parquet, and the file validates
against meds.CodeMetadataSchema.
MEDS 0.4 makes description optional, so consumers must still not rely on it being
non-null for datasets built with older releases.
ICD parent codes for diagnoses are the other piece of code metadata: each DIAGNOSIS//...
code gets ICD9CM//... and/or ICD10CM//... parent codes from the icd9code column of
diagnosis. That column lists several codes in one cell, and the config cannot split a cell into
several metadata rows yet (dftly#87), so the
eicu_pre_meds stage does that one step (the dx_icd_map table) and the config decides each code's
vocabulary. In the demo, 860 of the 1,091 diagnosis codes have one; in the full release, 3,129 of the
3,933. The eicu_sort_parent_codes stage sorts them, so that they read the same way across codes and
releases; the suMEDS enrichment appends its parents after them.
Code metadata: units
metadata/codes.parquet also has a unit column, so downstream tools read each code's unit from
one place. unit is a nullable string: the unit of the code's numeric values, one per code, written
in UCUM by suMEDS's sumeds_normalize_units post-stage (mEq/L becomes meq/L,
mmHg becomes mm[Hg]). The spelling as recorded stays in unit_source_value, and a spelling
suMEDS does not know is kept as it is. Codes are not changed: a unit already in the code string
stays there as recorded (LAB//RESULT//…//mEq/L keeps its name). Every unit is declared in configs/event_configs.yaml, so
MEDS-Extract writes it with the rest of the code metadata, before the post-stages run. Since 0.9.0
MEDS-Extract writes unit as one string per code
(MEDS_extract#336): it strips
each value, drops blank ones and fails the run if a code has more than one unit.
| Code family | Unit source |
|---|---|
LAB//RESULT//… |
lab.labMeasureNameSystem through _self, the code's own last component; a blank cell is no unit (and UNK in the code) |
INTAKE_OUTPUT//… |
the unit label written in intakeOutput.cellPath, through _self: the last parenthesized unit label in the path, of the labels the open demo uses (ml, mL, kg, lb, mcg), so …|Output (ml)|Urine and …|Output (ml)|Gastric (NG) get ml and …|Weight|Bodyweight (kg) gets kg; other parenthesized words ((NG), (volume), brand names) are not units |
NURSE_CHARTING//…, RESPIRATORY_CHARTING//…, PHYSICAL_EXAM//… |
the unit the item's own label states in parentheses, through _self, of the labels the open demo uses: nurse charting C, F, mmHg, secs (Temperature (C), MAP (mmHg), ECG (secs)), respiratory charting %, l/min, L/min, sec (FIO2 (%)), physical exam ml, kg (Weight (kg)/Current); (patient), (set), (systolic) and the like are not units |
VITALS//PERIODIC//TEMPERATURE, ICU_ADMISSION_WEIGHT/_HEIGHT, ICU_DISCHARGE_WEIGHT, SUBJECT_WEIGHT_AT_INFUSION |
the unit the eICU-CRD table documentation states for the column, written as its UCUM code (Cel, kg, cm; the documentation says "celsius", "kilograms", "cm"): a constant _self unit next to the code's constant description, with the documentation's sentence and page in a comment above it |
Every unit is the code's own component, a unit its own label states, or a single documented unit,
so no code has more than one. Everything else has no unit: the documentation states no unit for
the other vital-sign columns, the other charted, physical-exam and nursing items state none, a
numeric medication dosage is a bare number, and the documentation says only that
INFUSION_DRUG's infusionRate is "generally charted as ml/hr" (the rate unit is in each row's
drug name, text_value, so the literal code has none). The documented Celsius (Cel) is kept as stated,
but about 3% of full-release temperatures are above 45 and so likely Fahrenheit: range-check rather
than trust the unit.
The lab codes are the only codes whose last component is their unit, and eICU records each lab
name with one unit, so no two codes differ only in their unit and the ETL adds no parent linking
such codes. The unit in a lab code is stripped of surrounding whitespace; missing or blank is UNK
(LAB//RESULT//{labname}//UNK). MEDS-Extract compares units the same way when it writes unit, so
mg/dL and mg/dL give one code.
On the full release about 7.9% of numeric events have a code with a unit: 95.5% of lab results
(the rest are 24 lab codes whose unit cell is blank, so the code ends in //UNK), all intake/output
values, the temperature, weight and height codes, and the charted and physical-exam items whose
label states a unit. The vital signs without a documented unit are 77.0% of numeric events.
Enriching code metadata with suMEDS
The ETL writes what eICU itself records. Links to external vocabularies that eICU does not
record, and parents among eICU's own codes, are added by
suMEDS. The package ships the rules for it,
src/eICU_MEDS/sumeds_rules.yaml, registered in suMEDS's
sumeds.rules entry-point group under the dataset's name, eICU, so --rules eICU works for any
suMEDS command. The spec runs suMEDS's sumeds_enrich stage with them as the last stage of
meds-extract-run spec=eICU:
etl:
post_stages:
- sumeds_link_unit_siblings: # links lab codes that differ only in their unit
link_single_units: true # and gives a lab seen in one unit its unit-free stem too
- sumeds_normalize_units # `unit` in UCUM; see Code metadata: units
- eicu_sort_parent_codes
- sumeds_enrich:
rules: eICU
It replaces metadata/codes.parquet only once the enriched table is complete, and the file stays
valid MEDS code metadata. The crosswalk tables and ontology packs come from suMEDS's versioned
ontology data (sumeds-ontologies, pinned release), fetched from GitHub on first use and cached under
~/.cache/sumeds, so this repository does not ship them, and no Athena download or LOINC account is
needed.
Was a build enriched?
Enrichment is on by default and soft-fails: if it fails, for example on a server without internet
access, metadata/codes.parquet stays as the ETL wrote it and the run still succeeds. The warning,
with the command that finishes the enrichment, is in OUTPUT_DIR/.logs/pipeline.log, not on the
console. metadata/dataset.json records the outcome under sumeds_enrichment.enriched: true, or
false with the error and the retry command:
python -c 'import json, sys; print(json.load(open(sys.argv[1]))["sumeds_enrichment"]["enriched"])' \
"$OUT/metadata/dataset.json"
Running the same meds-extract-run command again does not retry: the stage counts as done even
when the enrichment soft-failed. Finish the enrichment with suMEDS-enrich, which uses the rules and options recorded
in dataset.json and updates the record to match a successful run:
suMEDS-enrich "$OUT"
# Without internet, from a copy of the sumeds-ontologies packs directory:
suMEDS-enrich "$OUT" --ontology-source /path/to/sumeds-ontologies/ontologies --offline
Leaving it out
meds-extract-run spec=eICU output_dir=$OUT skip_stages=[sumeds_enrich]
writes the ETL output alone, with no sumeds_enrichment record. Running the same command later
without skip_stages runs only the enrichment.
Stage options at run time
The stage takes the suMEDS-enrich options, spelled with underscores (strict, offline,
ontology_source, athena_csv, …; see the
suMEDS usage docs). Set them for one
run with overrides=, which meds-extract-run passes to every stage. The ++ adds the option to the
stage config of the stages that do not have it, which ignore it:
# Fail the run if the enrichment fails:
meds-extract-run spec=eICU output_dir=$OUT "overrides=['++stage_cfg.strict=true']"
# Also look codes up in your own OHDSI Athena download:
meds-extract-run spec=eICU output_dir=$OUT "overrides=['++stage_cfg.athena_csv=/path/to/athena']"
# Use only cached ontology data, without trying the network:
meds-extract-run spec=eICU output_dir=$OUT "overrides=['++stage_cfg.offline=true']"
# Read the ontology packs from a local copy (or set SUMEDS_ONTOLOGY_SOURCE=DIR):
meds-extract-run spec=eICU output_dir=$OUT "overrides=['++stage_cfg.ontology_source=/path/to/packs']"
Without the ++ (overrides=['stage_cfg.strict=true']), the first stage rejects the unknown key
and the run fails.
Clusters without internet access on compute nodes
Fill a cache on shared storage once, from a login node, then build offline on the compute nodes with the same cache:
export XDG_CACHE_HOME=/shared/project/cache
suMEDS-enrich --prefetch --rules eICU # login node: the whole pinned ontology release, a few tens of MB
meds-extract-run spec=eICU output_dir=$OUT do_download=false input_dir=$RAW \
"overrides=['++stage_cfg.offline=true']" # compute node
What the rules add
- LOINC for lab results (
eicu-lab-loinc, a crosswalk):LAB//RESULT//{labname}//{unit}getsLOINC//<code>inparent_codes, plusvocabulary_idandconcept_code, for the 50 lab names in the crosswalk tableeicu/lab_loinc, each validated against the LOINC pack. The links are an inference across two curated mappings (eICU name → WeavEHR concept ← MIMIC-IV item with its LOINC code in mimic-coded_labitems_to_loinc.csv), so the LOINC code inherits the MIMIC item's specimen (serum/plasma versus blood); the table records both ends. - Parents among eICU codes (
eicu-diagnosis-paths,eicu-admission-diagnosis-paths,eicu-treatment-paths, hierarchy rules): a|-separated path gets the nearest shorter path that is itself a code, e.g.TREATMENT//ENTERED//a|b|cgetsTREATMENT//ENTERED//a|b. On the full release that adds 2,929 diagnosis and 2,096 treatment parents; admission diagnosis paths are recorded only as leaves, so that rule adds none today.
suMEDS also looks up every ICD9CM//… and ICD10CM//… parent the ETL writes for a diagnosis code
in its ICD-9-CM and ICD-10-CM packs, and appends that code's ancestors.
The ETL alone emits no LOINC parents for lab codes (builds of main after #27 wrote
LOINC//<code> for the same 50 lab names), and it never emitted parents among eICU codes:
metadata/codes.parquet from the ETL has ICD parents for diagnoses only, and suMEDS supplies
the rest. It never removes or rewrites the ETL's own descriptions or parents: those stay first
in parent_codes, and what suMEDS adds is appended after them. parent_names maps each parent
code to its name (a map<string, string> column; same-table parents have no name, since their
description is in their own row).
Which eICU tables are extracted
eICU-CRD v2.0 ships 31 tables. This pipeline reads 22 of them. The rest are excluded deliberately — the reasoning is recorded here rather than in a code comment, because "this table is missing" is otherwise indistinguishable from an oversight.
Extracted: patient, hospital (joined for site attributes), admissionDx,
allergy, carePlanEOL, carePlanGeneral, carePlanGoal,
carePlanInfectiousDisease, diagnosis, infusionDrug, intakeOutput, lab, medication,
nurseAssessment, nurseCare, nurseCharting, pastHistory, physicalExam, respiratoryCharting, treatment, vitalAperiodic,
vitalPeriodic.
Excluded — deliberate, on the merits:
| Table | Rows | Why not |
|---|---|---|
admissionDrug |
874,920 | Documented as "extremely infrequently used". |
apacheApsVar |
171,177 | Inputs to the APACHE score. We prefer the raw measurements they were computed from. |
apachePatientResult |
297,064 | Pre-computed APACHE scores and predictions — derived values, not observations. |
apachePredVar |
171,177 | Further APACHE inputs; same reasoning. |
carePlanCareProvider |
502,765 | Cannot be linked to the specific care-plan entries it describes, and its offsets record when a provider was entered into the plan rather than any clinical event. |
customLab |
1,082 | Documentation is very sparse, and it holds only the lab measurements that could not be mapped to the standard set in lab. |
microLab |
16,996 | Time leakage: culture-taken time is not culture-result time, so a model would see organism/sensitivity results before they could exist. Also documented as poorly populated. |
note |
2,254,179 | Largely duplicative of the structured tables — narrative notes were mostly removed for PHI reasons. |
Excluded — not yet done, not on the merits. These carry real clinical signal and
were stubbed out but never finished (the original config shipped commented-out blocks
for them marked NOT YET DONE, because their cell-label/value structure needs a code
scheme of its own):
| Table | Rows | Contains |
|---|---|---|
respiratoryCare |
865,381 | Ventilator settings and airway management. |
Parallel runs
meds-extract-run runs every stage in one process by default. To run the data stages with several
workers, give it a runner file with a parallelize block (the joblib launcher is installed with this
package; pip install 'eICU-MEDS[slurm_parallelism]' adds the submitit launcher for Slurm):
printf 'parallelize:\n n_workers: 8\n launcher: joblib\n' > runner.yaml
meds-extract-run spec=eICU output_dir=$OUT stage_runner_fp=runner.yaml
Size n_workers to memory, not cores: each worker is a separate process with its own working
set. On the full release, four workers exhausted a 24 GB laptop, with each of the four
holding 7.5 to 8 GB during split_and_shard_subjects. That is a metadata stage, so every worker
repeats the whole computation rather than taking a share of it. The same build run serially
(polars limited to four threads with POLARS_MAX_THREADS=4) peaked at 4.8 GB and took 20 minutes on
a 10-core machine. This package's own stages and the suMEDS enrichment work in worker 0 only.
The number of subjects per shard is fixed at 1,000 in the spec's etl: block
(n_subjects_per_shard); no command-line option changes it. MEDS-Extract treats shard size as a
property of the dataset, while worker counts belong to the machine running it. To use a different
shard size, edit the spec in a local checkout (see Development).
Summary statistics
tests/regression/full_summary_stats.json is a
meds_summary_stats fingerprint of
the MEDS dataset this ETL builds from the full eICU-CRD 2.0 release with meds-extract-run spec=eICU,
so its code-metadata coverage includes the suMEDS enrichment. It covers subject, event and measurement
counts, digests of the code vocabulary, per-subject, value and time distributions, code-metadata
coverage, the splits and the schema. It names no code and reports no cell of fewer than 20 subjects and
no minimum or maximum, which is what makes it safe to publish. Because it is committed next to the ETL,
its diff shows what an ETL change did to the output, and two ETL versions can be compared without
access to the data.
tests/regression/demo_summary_stats.json is the same
fingerprint of the open eICU-CRD demo. The Tests workflow builds the demo on every pull request and
fails when the result no longer matches it (scripts/summary_stats.sh demo regenerates it; the job
also uploads the new statistics as the eicu-demo-summary-stats artifact).
Regenerate it in every pull request that changes the output, from a build of that branch:
# Build the release with this checkout, then summarize it
scripts/summary_stats.sh full --input-dir $RAW_INPUT_DIR
# Or summarize a build of this checkout you already have
scripts/summary_stats.sh full --meds-dir $MEDS_OUTPUT_DIR
The script builds with strict enrichment and refuses a build whose metadata/dataset.json does not
record a successful enrichment, since the baselines describe enriched builds. Both print how the
statistics changed against the committed baseline before overwriting it. Add
--compare to check a build without writing anything; it exits 1 when
tests/regression/policy.yaml flags an error. Rebuilding the same
commit reproduces the baseline exactly, so any finding is a change in the output. CI cannot rebuild the
credentialed release, so the Summary stats workflow only warns
when a pull request changes src/ (the config or the suMEDS rules) without regenerating the baseline.
A MEDS-Extract, suMEDS or polars upgrade can also move the output, so check it with --compare.
Development
Contributors should use uv to set up a development environment from the
lockfile:
git clone https://github.com/Medical-Event-Data-Standard/eICU_MEDS.git
cd eICU_MEDS
uv sync --group dev
uv run pre-commit install
uv run pytest src/ tests/ --doctest-modules
The end-to-end test (tests/e2e_demo_test.py) downloads the public eICU demo from PhysioNet, so it is
slow on a first run. tests/test_run_with_enrichment.py runs the ETL and the suMEDS enrichment
offline, on a few synthetic rows and a tiny local ontology source. DEVELOPMENT.md covers testing, running the ETL on the full release,
and cutting a release with uv version --bump.
Breaking changes
0.4.0 (2026-11-20)
-
Rebuilt on the full release;
tests/regression/full_summary_stats.jsonregenerated. -
codes.parquetgains unit-free stem rows and stem parents for single-unit codes (#53). suMEDS'ssumeds_link_unit_siblingsnow runs withlink_single_units: true: every code that ends in its unit gets the code without the unit (its stem) as its lastparent_codesentry, and the stem gets a row of its own (no unit, no events), also when the item has a single unit (LAB//RESULT//<labname>//<unit>getsLAB//RESULT//<labname>). Before, only items recorded in two or more units did. Events are unchanged. On a synthetic (MESSY-synth) build, 62LAB//RESULTcodes gain a stem parent and 62 stem rows are added; on the public eICU demo, 128 stem rows are added (8,122 → 8,250 codes). To migrate, nothing is needed unless a tool expects everycodes.parquetrow to have events: drop the stem rows (nocode_template, nounit), or ignore a parent that is the code without its last//component. -
A blank lab unit is
UNK, and a lab code's unit is stripped of surrounding whitespace.LAB//RESULT//{labname}//{unit}andLAB//SPECIMEN_DRAWN//{labname}//{unit}took the unit (lab.labMeasureNameSystem) as recorded, so a lab name whose unit cell is blank (an empty string, not null) got a code ending in//. That code is now…//UNK, as a null unit already was, and a padded unit gives the same code as the stripped one. In the open demo, 37,707 events (18,877 results and 18,830 specimen-drawn events) of 38 codes (19 lab names) change, from…//to…//UNK; no demo unit is padded. On the full release, 24 lab-result codes end in//. Events, times, values and the rest of the code metadata are otherwise unchanged.Old New LAB//RESULT//<labname>//LAB//RESULT//<labname>//UNKLAB//SPECIMEN_DRAWN//<labname>//LAB//SPECIMEN_DRAWN//<labname>//UNKLAB//…//<labname>//<unit padded by ws>LAB//…//<labname>//<unit>To migrate, rewrite old lab codes with the regexes
^(LAB//(?:RESULT|SPECIMEN_DRAWN)//.*//)\s*$→\1UNKand^(LAB//(?:RESULT|SPECIMEN_DRAWN)//.*//)\s+(.*?)\s*$→\1\2. -
Medication orders are
MEDICATION//START//<drug>andMEDICATION//END//<drug>, notMEDICATION//STARTED//<drug>andMEDICATION//STOPPED//<drug>(alignEHR#53). This is the spelling all MEDS ETLs move to for the two ends of an interval,<FAMILY>//START//…and<FAMILY>//END//…, so a start pairs with its end by swappingSTARTforEND. Events, times, values and code metadata are otherwise unchanged.Old New MEDICATION//STARTED//<drug>MEDICATION//START//<drug>MEDICATION//STOPPED//<drug>MEDICATION//END//<drug>To migrate, rewrite old codes with the regexes
^MEDICATION//STARTED//→MEDICATION//START//and^MEDICATION//STOPPED//→MEDICATION//END//. -
Intermediate stage outputs are no longer kept. Up to 0.3.0, a run left each stage's output in
<output_dir>/<stage>/(convert_to_parquet/,convert_to_MEDS_events/,eicu_pre_meds/,eicu_sort_parent_codes/,sumeds_enrich/, …). The spec now sets MEDS-Extract'setl.cleanup_intermediates: true, so a successful run deletes those directories and keeps onlydata/,metadata/,.logs/and.meds_extract_run/. The MEDS data and metadata are unchanged. To migrate, add"overrides=['cleanup_intermediates=false']"tomeds-extract-runwherever you read a stage directory after the run. -
hadm_idis the hospital stay, and the hospital moves tohospital_id. Up to 0.3.0,hadm_idheldhospitalid, the id of the hospital (a site, shared by every stay there). It now holdspatienthealthsystemstayid, the hospital stay, which is also thesubject_id. The hospital is in a new column,hospital_id, listed undersite_id_columnsinmetadata/dataset.json. Both are set on the same events of the patient table as before. Event rows and codes are otherwise unchanged. To migrate, read the hospital fromhospital_idwherever you readhadm_id(pl.col("hadm_id")→pl.col("hospital_id")), and usehadm_id(orsubject_id) for the hospital stay. -
Vocabulary parents are spelled
VOCABULARY//CODE. The ICD parents the ETL writes for diagnoses (ICD9CM,ICD10CM) used one slash,ICD10CM/J18.9; they now use two,ICD10CM//J18.9, the spelling suMEDS already writes for the parents it adds. Codes, events and the sorted order of each code's parents are unchanged. To migrate, respell old parents with the regex^([^/]+)/(?!/)→\1//. suMEDS and alignEHR already read both spellings as the same parent.
Citation
If you use this code in your research, please cite the following:
@article{PhysioNet-eicu-crd-2.0,
author = {Pollard, Tom and Johnson, Alistair and Raffa, Jesse and Celi, Leo Anthony and Badawi, Omar and Mark, Roger},
title = {{eICU Collaborative Research Database}},
journal = {{PhysioNet}},
year = {2019},
month = apr,
note = {Version 2.0},
doi = {10.13026/C2WM1R},
url = {https://doi.org/10.13026/C2WM1R}
}
@article{Pollard2018-ln,
title = "The {eICU} Collaborative Research Database, a freely available
multi-center database for critical care research",
author = "Pollard, Tom J and Johnson, Alistair E W and Raffa, Jesse D and
Celi, Leo A and Mark, Roger G and Badawi, Omar",
journal = "Sci. Data",
publisher = "Springer Science and Business Media LLC",
volume = 5,
number = 1,
pages = "180178",
month = sep,
year = 2018,
copyright = "https://creativecommons.org/licenses/by/4.0",
language = "en"
}
@software{McDermott_eICU_MEDS_eICU_MEDS,
author = {McDermott, Matthew and Zhu, Mingcheng and van de Water, Robin Philippus},
license = {MIT},
title = {{eICU\_MEDS: eICU MEDS Extraction ETL}},
url = {https://github.com/Medical-Event-Data-Standard/eICU_MEDS/}
}
Metadata
Release files for eICU-MEDS 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| eicu_meds-0.4.0.tar.gz | 99.0 kB | With provenance | Details for eicu_meds-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| eicu_meds-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for eicu_meds-0.4.0-py3-none-any.whl |
Total release size: 142.2 kB
Release files / eicu_meds-0.4.0.tar.gz
| Download URL | eicu_meds-0.4.0.tar.gz |
|---|---|
| Size | 99.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a3c6982ce9676ded6cbc72b02e7de79b5c0dd15c6c91254119990ad6518536f
|
|
BLAKE2b-256 checksum How to use checksums |
d4a3e46d1d49ed9c35bb32292d920fbba2f68066a2f6e8b761c28f0120000e16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 21, 2026.
Transparency logRelease files / eicu_meds-0.4.0-py3-none-any.whl
| Download URL | eicu_meds-0.4.0-py3-none-any.whl |
|---|---|
| Size | 43.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
504bf13e20a00855a43ef84d5747a8ffc60c95c7caa1f1aa7cc80a21f8323cc4
|
|
BLAKE2b-256 checksum How to use checksums |
afce08e6b15520a9d66273dbfbb812a94a843fa69c5ddeac2b8cc34943a92cd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 21, 2026.
Transparency logSecurity for eICU-MEDS 0.4.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for eicu_meds-0.4.0.tar.gz
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 Nov 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.