MIMIC-III-MEDS 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mimic_iii_meds-0.0.1/LICENSE +21 -0
- mimic_iii_meds-0.0.1/PKG-INFO +407 -0
- mimic_iii_meds-0.0.1/README.md +362 -0
- mimic_iii_meds-0.0.1/pyproject.toml +81 -0
- mimic_iii_meds-0.0.1/setup.cfg +4 -0
- mimic_iii_meds-0.0.1/src/MIMIC_III_MEDS/__init__.py +49 -0
- mimic_iii_meds-0.0.1/src/MIMIC_III_MEDS/messy.yaml +635 -0
- mimic_iii_meds-0.0.1/src/MIMIC_III_MEDS/sumeds_rules.yaml +54 -0
- mimic_iii_meds-0.0.1/src/MIMIC_III_MEDS/text_columns_stage.py +140 -0
- mimic_iii_meds-0.0.1/src/MIMIC_III_MEDS.egg-info/PKG-INFO +407 -0
- mimic_iii_meds-0.0.1/src/MIMIC_III_MEDS.egg-info/SOURCES.txt +20 -0
- mimic_iii_meds-0.0.1/src/MIMIC_III_MEDS.egg-info/dependency_links.txt +1 -0
- mimic_iii_meds-0.0.1/src/MIMIC_III_MEDS.egg-info/entry_points.txt +8 -0
- mimic_iii_meds-0.0.1/src/MIMIC_III_MEDS.egg-info/requires.txt +25 -0
- mimic_iii_meds-0.0.1/src/MIMIC_III_MEDS.egg-info/top_level.txt +1 -0
- mimic_iii_meds-0.0.1/tests/test_code_metadata.py +230 -0
- mimic_iii_meds-0.0.1/tests/test_deaths.py +18 -0
- mimic_iii_meds-0.0.1/tests/test_messy_config.py +168 -0
- mimic_iii_meds-0.0.1/tests/test_mimic3_releases.py +166 -0
- mimic_iii_meds-0.0.1/tests/test_run_with_enrichment.py +389 -0
- mimic_iii_meds-0.0.1/tests/test_sumeds_rules.py +144 -0
- mimic_iii_meds-0.0.1/tests/test_unit_component.py +27 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robin van de Water
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: MIMIC-III-MEDS
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A MEDS-Extract ETL for MIMIC-III v1.4: the full release, its CareVue subset and the open demo.
|
|
5
|
+
Author-email: Robin van de Water <robin.vandewater@hpi.de>
|
|
6
|
+
Project-URL: Homepage, https://github.com/rvandewater/MIMIC_III_MEDS
|
|
7
|
+
Project-URL: Repository, https://github.com/rvandewater/MIMIC_III_MEDS
|
|
8
|
+
Project-URL: Issues, https://github.com/rvandewater/MIMIC_III_MEDS/issues
|
|
9
|
+
Project-URL: Source data, https://physionet.org/content/mimiciii/1.4/
|
|
10
|
+
Project-URL: MEDS, https://medical-event-data-standard.github.io/
|
|
11
|
+
Keywords: MEDS,MIMIC-III,MIMIC,EHR,ETL,MEDS-Extract,PhysioNet,critical care
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Requires-Python: <3.14,>=3.11.4
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: MEDS-extract[download]<0.10,>=0.9.2
|
|
25
|
+
Requires-Dist: sumeds<0.7,>=0.6.11
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pre-commit<4; extra == "dev"
|
|
28
|
+
Provides-Extra: tests
|
|
29
|
+
Requires-Dist: pytest; extra == "tests"
|
|
30
|
+
Requires-Dist: sumeds[testing]<0.7,>=0.6.11; extra == "tests"
|
|
31
|
+
Provides-Extra: local-parallelism
|
|
32
|
+
Requires-Dist: hydra-joblib-launcher; extra == "local-parallelism"
|
|
33
|
+
Provides-Extra: slurm-parallelism
|
|
34
|
+
Requires-Dist: hydra-submitit-launcher; extra == "slurm-parallelism"
|
|
35
|
+
Provides-Extra: docs
|
|
36
|
+
Requires-Dist: mkdocs==1.6.0; extra == "docs"
|
|
37
|
+
Requires-Dist: mkdocs-material==9.5.31; extra == "docs"
|
|
38
|
+
Requires-Dist: mkdocstrings[python,shell]==0.25.2; extra == "docs"
|
|
39
|
+
Requires-Dist: mkdocs-gen-files==0.5.0; extra == "docs"
|
|
40
|
+
Requires-Dist: mkdocs-literate-nav==0.6.1; extra == "docs"
|
|
41
|
+
Requires-Dist: mkdocs-section-index==0.3.9; extra == "docs"
|
|
42
|
+
Requires-Dist: mkdocs-git-authors-plugin==0.9.0; extra == "docs"
|
|
43
|
+
Requires-Dist: mkdocs-git-revision-date-localized-plugin==1.2.6; extra == "docs"
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
# MIMIC-III MEDS Extraction ETL
|
|
47
|
+
|
|
48
|
+
[](https://github.com/rvandewater/MIMIC_III_MEDS/actions/workflows/tests.yaml)
|
|
49
|
+
[](https://github.com/rvandewater/MIMIC_III_MEDS/actions/workflows/code-quality-main.yaml)
|
|
50
|
+

|
|
51
|
+
[](https://github.com/rvandewater/MIMIC_III_MEDS#license)
|
|
52
|
+

|
|
53
|
+
|
|
54
|
+
A [MEDS-Extract](https://github.com/mmcdermott/MEDS_extract) ETL that converts
|
|
55
|
+
[MIMIC-III](https://physionet.org/content/mimiciii/1.4/) v1.4 (critical care data from the Beth
|
|
56
|
+
Israel Deaconess Medical Center, 2001–2012) to the [MEDS](https://medical-event-data-standard.github.io/)
|
|
57
|
+
format. One spec builds three releases of the same layout:
|
|
58
|
+
|
|
59
|
+
| Release | `dataset_key` | Dataset name in `dataset.json` | Access and licence |
|
|
60
|
+
| ------------------------------------------------------------------------------- | ------------------- | ------------------------------ | ----------------------------------------------------------------------- |
|
|
61
|
+
| [MIMIC-III Clinical Database v1.4](https://physionet.org/content/mimiciii/1.4/) | `dataset` (default) | `MIMIC-III` | credentialed; PhysioNet Credentialed Health Data License 1.5.0 |
|
|
62
|
+
| [CareVue subset v1.4](https://physionet.org/content/mimic3-carevue/1.4/) | `carevue` | `MIMIC-III-CareVue` | credentialed; PhysioNet Credentialed Health Data License 1.5.0 |
|
|
63
|
+
| [Demo v1.4](https://physionet.org/content/mimiciii-demo/1.4/) | `demo` | `MIMIC-III-Demo` | open (100 patients); Open Data Commons Open Database License (ODbL) 1.0 |
|
|
64
|
+
|
|
65
|
+
**The CareVue subset** is the release meant for benchmarking next to MIMIC-IV, and the one
|
|
66
|
+
registered in [MEDS-DEV](https://github.com/Medical-Event-Data-Standard/MEDS-DEV). Full MIMIC-III
|
|
67
|
+
repeats MIMIC-IV's 2008–2012 admissions under different identifiers and date shifts, which cannot be
|
|
68
|
+
linked or removed. The CareVue subset keeps only MIMIC-III patients with an ICU stay charted in
|
|
69
|
+
Philips CareVue (2001–2008) and removes every patient with a hospitalization in MIMIC-IV v2.0
|
|
70
|
+
(6,636 subjects), so it adds patients that MIMIC-IV does not have. That makes it an out-of-time and
|
|
71
|
+
charting-system shift test set for models trained on MIMIC-IV. See [Cohort](#cohort-carevue-subset)
|
|
72
|
+
for its biases.
|
|
73
|
+
|
|
74
|
+
## Usage
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install MIMIC-III-MEDS
|
|
78
|
+
export DATASET_DOWNLOAD_USERNAME=... # your PhysioNet username
|
|
79
|
+
export DATASET_DOWNLOAD_PASSWORD=... # and password
|
|
80
|
+
|
|
81
|
+
# The CareVue subset, as MEDS-DEV builds it
|
|
82
|
+
meds-extract-run spec=MIMIC-III dataset_key=carevue output_dir=$OUTPUT_DIR \
|
|
83
|
+
"overrides=['etl_metadata.dataset_name=MIMIC-III-CareVue']"
|
|
84
|
+
|
|
85
|
+
# Full MIMIC-III v1.4
|
|
86
|
+
meds-extract-run spec=MIMIC-III output_dir=$OUTPUT_DIR
|
|
87
|
+
|
|
88
|
+
# The open demo (no credentials)
|
|
89
|
+
meds-extract-run spec=MIMIC-III dataset_key=demo output_dir=$OUTPUT_DIR \
|
|
90
|
+
"overrides=['etl_metadata.dataset_name=MIMIC-III-Demo']"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
With the data already on disk, add `do_download=false input_dir=$RAW_DIR` (keep `dataset_key`, which
|
|
94
|
+
stamps the release's version into `dataset.json`). The `overrides=` sets the dataset name that
|
|
95
|
+
`metadata/dataset.json` records; without it every build is called `MIMIC-III`. The download fetches
|
|
96
|
+
every table except `NOTEEVENTS` (free text, not read) and the MD5 lists, checks each file against the
|
|
97
|
+
release's `SHA256SUMS.txt`, resumes after an interruption and skips files that already verify. Point
|
|
98
|
+
`download_dest_dir=` at durable storage to reuse a download across output directories.
|
|
99
|
+
[`scripts/get_mimic3.sh`](https://github.com/rvandewater/MIMIC_III_MEDS/blob/main/scripts/get_mimic3.sh) runs only the download (`--full`,
|
|
100
|
+
`--demo`, `--list`; meant for an HPC login or transfer node).
|
|
101
|
+
|
|
102
|
+
This one command runs the ETL and then enriches its code metadata with
|
|
103
|
+
[suMEDS](https://github.com/rvandewater/suMEDS) (installed with this package): ICD-9 ancestors, OMOP
|
|
104
|
+
Gender codes and parents among the dataset's own ICD codes. If it cannot (no internet, say), the ETL
|
|
105
|
+
still succeeds, unenriched, and `suMEDS-enrich $OUTPUT_DIR` finishes it later. Add
|
|
106
|
+
`skip_stages=[sumeds_enrich]` for the plain ETL. See
|
|
107
|
+
[Enriching code metadata with suMEDS](#enriching-code-metadata-with-sumeds).
|
|
108
|
+
|
|
109
|
+
The output directory holds the MEDS dataset (`data/` and `metadata/`), with the dataset name and
|
|
110
|
+
version (`1.4:<ETL version>`) in `metadata/dataset.json`. `dataset.json` lists `hadm_id`,
|
|
111
|
+
`icustay_id`, `order_id` and `link_order_id`, the keys back to the raw tables, under
|
|
112
|
+
`raw_source_id_columns`, and every other extension column under `other_extension_columns`. It records
|
|
113
|
+
no `license` or `description_uri`: they differ between the releases (see the table above), and
|
|
114
|
+
MEDS-Extract cannot set them per release.
|
|
115
|
+
|
|
116
|
+
Intermediate stage outputs are deleted after a successful run (`etl.cleanup_intermediates: true`), so
|
|
117
|
+
a finished `$OUTPUT_DIR` holds only `data/`, `metadata/`, `.logs/` and `.meds_extract_run/`. A failed
|
|
118
|
+
run keeps them, so the same command resumes where it stopped. Add
|
|
119
|
+
`"overrides=['cleanup_intermediates=false']"` to keep them.
|
|
120
|
+
|
|
121
|
+
## Configuration
|
|
122
|
+
|
|
123
|
+
The pipeline is one file, [`src/MIMIC_III_MEDS/messy.yaml`](https://github.com/rvandewater/MIMIC_III_MEDS/blob/main/src/MIMIC_III_MEDS/messy.yaml),
|
|
124
|
+
registered under the `MEDS_extract.pipelines` entry-point group as `MIMIC-III`. The package's only
|
|
125
|
+
code is one small pre-stage, `mimic3_text_columns`
|
|
126
|
+
([`text_columns_stage.py`](https://github.com/rvandewater/MIMIC_III_MEDS/blob/main/src/MIMIC_III_MEDS/text_columns_stage.py)); see
|
|
127
|
+
[ICD-9 procedure codes](#icd-9-procedure-codes).
|
|
128
|
+
|
|
129
|
+
### Raw data layout
|
|
130
|
+
|
|
131
|
+
All three releases are MIMIC-III v1.4 exported from PostgreSQL: one file per table at the top of the
|
|
132
|
+
release, upper-case file names (`ADMISSIONS.csv.gz`; `.csv` in the demo) and lower-case column names.
|
|
133
|
+
The table keys in `messy.yaml` are the file names without extension, and MEDS-Extract matches them
|
|
134
|
+
exactly (case included). Point `input_dir` at the directory holding the files, which is what
|
|
135
|
+
`meds-extract-download` writes.
|
|
136
|
+
|
|
137
|
+
The CareVue subset is "formatted identically to MIMIC-III", with every table present.
|
|
138
|
+
`INPUTEVENTS_MV` and `PROCEDUREEVENTS_MV` hold no rows ("no patients were admitted using the
|
|
139
|
+
MetaVision system"); they are still downloaded, because MEDS-Extract fails on a table the spec reads
|
|
140
|
+
and cannot find, and an empty table gives no events.
|
|
141
|
+
|
|
142
|
+
Tables not read: `NOTEEVENTS` (free text), `CALLOUT` (ICU discharge requests), `DATETIMEEVENTS`
|
|
143
|
+
(charted dates, such as a line's insertion date), `MICROBIOLOGYEVENTS`, and the dictionaries
|
|
144
|
+
`CAREGIVERS` and `D_CPT` (whose rows are CPT ranges, not codes). MIMIC-IV-MEDS does not read the
|
|
145
|
+
MIMIC-IV counterparts of notes, `DATETIMEEVENTS` or `MICROBIOLOGYEVENTS` either.
|
|
146
|
+
|
|
147
|
+
### Code families
|
|
148
|
+
|
|
149
|
+
Every code in `metadata/codes.parquet` gets a `description`. Codes for which MIMIC-III records a
|
|
150
|
+
standard-vocabulary code get `parent_codes`, named after the OMOP `vocabulary_id` where there is one.
|
|
151
|
+
Where MIMIC-III and MIMIC-IV record the same thing, the codes are spelled as
|
|
152
|
+
[MIMIC-IV-MEDS](https://github.com/Medical-Event-Data-Standard/MIMIC_IV_MEDS) spells them, so that a
|
|
153
|
+
model or task definition carries over.
|
|
154
|
+
|
|
155
|
+
| Code family | Source (MIMIC-III table) | Time | Metadata |
|
|
156
|
+
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ----------------------- | ------------------------------------------------------------------------------ |
|
|
157
|
+
| `GENDER//{gender}` | `PATIENTS` | static | `_self` |
|
|
158
|
+
| `MEDS_BIRTH` | `PATIENTS.dob` | `dob` | `_self`; see [Birth](#birth) |
|
|
159
|
+
| `MEDS_DEATH` | `ADMISSIONS.deathtime`, `PATIENTS.dod` | see [Deaths](#deaths) | `_self` |
|
|
160
|
+
| `HOSPITAL_ADMISSION//{admission_type}//{admission_location}` | `ADMISSIONS`; `text_value`: the free-text admitting `diagnosis` | `admittime` | `_self` |
|
|
161
|
+
| `HOSPITAL_DISCHARGE//{discharge_location}` | `ADMISSIONS` | `dischtime` | `_self` |
|
|
162
|
+
| `ED_REGISTRATION`, `ED_OUT` | `ADMISSIONS.edregtime`, `edouttime` | themselves | `_self` |
|
|
163
|
+
| `INSURANCE//…`, `LANGUAGE//…`, `MARITAL_STATUS//…`, `RELIGION//…`, `RACE//…` | `ADMISSIONS` (`RACE` from `ethnicity`) | `admittime` | `_self`; see [Demographics](#demographics) |
|
|
164
|
+
| `DIAGNOSIS//ICD//9CM//{icd9_code}` | `DIAGNOSES_ICD` | admission's `dischtime` | `D_ICD_DIAGNOSES.long_title`; parent `ICD9CM//<dotted code>` |
|
|
165
|
+
| `PROCEDURE//ICD//9CM//{icd9_code}` | `PROCEDURES_ICD` | admission's `dischtime` | `D_ICD_PROCEDURES.long_title`; parent `ICD9Proc//<dotted code>` |
|
|
166
|
+
| `DRG//{drg_type}//{drg_code}` | `DRGCODES`; `text_value`: the DRG title; `drg_severity`, `drg_mortality` | admission's `dischtime` | `_self`; parent `MS-DRG//…`, `APR-DRG//…` or `CMS-DRG//…` (see [DRG](#drg)) |
|
|
167
|
+
| `CPT//{cpt_cd}` | `CPTEVENTS` | admission's `dischtime` | `_self` (CPT section headers; MIMIC-III ships no CPT titles); parent `CPT4//…` |
|
|
168
|
+
| `SERVICE//{curr_service}` | `SERVICES` | `transfertime` | `_self` |
|
|
169
|
+
| `TRANSFER_TO//{eventtype}//{curr_careunit}` | `TRANSFERS` | `intime` | `_self`; see [Transfers](#transfers) |
|
|
170
|
+
| `ICU_ADMISSION//{first_careunit}`, `ICU_DISCHARGE//{last_careunit}` | `ICUSTAYS` | `intime`, `outtime` | `_self` |
|
|
171
|
+
| `LAB//RESULT//{itemid}//{valueuom}` | `LABEVENTS`; `valuenum`, `value` | `charttime` | `D_LABITEMS.label`; parent `LOINC//{loinc_code}` where `D_LABITEMS` has one |
|
|
172
|
+
| `ICU_CHART//{itemid}//{valueuom}` | `CHARTEVENTS`; `valuenum`, `value`; rows with `error` = 1 dropped | `charttime` | `D_ITEMS.label` |
|
|
173
|
+
| `SUBJECT_FLUID_OUTPUT//{itemid}//{valueuom}` | `OUTPUTEVENTS`; `value`; rows with `iserror` = 1 dropped | `charttime` | `D_ITEMS.label` |
|
|
174
|
+
| `INFUSION//AMOUNT//{itemid}//{amountuom}`, `INFUSION//RATE//{itemid}//{rateuom}` | `INPUTEVENTS_CV` (CareVue); `amount`, `rate` | `charttime` | `D_ITEMS.label`; see [Inputs](#inputs) |
|
|
175
|
+
| `INFUSION//START//{itemid}//{rateuom}`, `INFUSION//END//{itemid}//{amountuom}`, `SUBJECT_WEIGHT_AT_INFUSION` | `INPUTEVENTS_MV` (MetaVision; full release and demo) | `starttime`, `endtime` | `D_ITEMS.label` |
|
|
176
|
+
| `PROCEDURE//START//{itemid}`, `PROCEDURE//END//{itemid}` | `PROCEDUREEVENTS_MV` (MetaVision; full release and demo) | `starttime`, `endtime` | `D_ITEMS.label` |
|
|
177
|
+
| `MEDICATION//START//{drug}//{route}//{dose_unit_rx}`, `MEDICATION//END//{drug}//{route}` | `PRESCRIPTIONS`; start value `dose_val_rx` | `startdate`, `enddate` | `_self`; parent `NDC//{ndc}` (11 digits; `0` means none) |
|
|
178
|
+
|
|
179
|
+
A null code component is `UNK` (`HOSPITAL_DISCHARGE//UNK`), except for the demographics, where a null
|
|
180
|
+
gives no event.
|
|
181
|
+
|
|
182
|
+
**Item ids.** CareVue item ids are below 220000 and MetaVision ones from 220000, the same ids MIMIC-IV
|
|
183
|
+
uses for MetaVision. The hospital lab's item ids (`D_LABITEMS`, 50xxx) are shared with MIMIC-IV, so
|
|
184
|
+
`LAB//RESULT//50912//mg/dL` means the same in both datasets; the CareVue chart ids
|
|
185
|
+
(`ICU_CHART//211//bpm`, heart rate) have no MIMIC-IV counterpart, which is the charting-system shift.
|
|
186
|
+
|
|
187
|
+
**Units.** Every code that carries a `numeric_value` from a unit column ends in that unit: stripped
|
|
188
|
+
of surrounding whitespace, `UNK` where missing or blank. So each code has one unit, which `unit` in
|
|
189
|
+
`codes.parquet` holds, written in [UCUM](https://ucum.org/) by suMEDS's `sumeds_normalize_units`
|
|
190
|
+
(`mEq/L` becomes `meq/L`, `bpm` becomes `{beats}/min`); the unit as recorded stays in
|
|
191
|
+
`unit_source_value`. suMEDS's
|
|
192
|
+
[`sumeds_link_unit_siblings`](https://github.com/rvandewater/suMEDS/blob/main/docs/unit_siblings.md)
|
|
193
|
+
gives codes that differ only in their unit the code without the unit as a parent, and adds a row for
|
|
194
|
+
it, so `LAB//RESULT//50912//mg/dL` and a `…//UNK` sibling share the parent `LAB//RESULT//50912`. With
|
|
195
|
+
`link_single_units`, every code ending in a unit gets that stem, so a prescription or MetaVision
|
|
196
|
+
infusion start pairs with its end by stem (alignEHR#53); `unknown_unit_prefixes` does the same for the
|
|
197
|
+
`MEDICATION` and `INFUSION` codes without a recorded unit (a MetaVision bolus has no rate).
|
|
198
|
+
|
|
199
|
+
### Birth
|
|
200
|
+
|
|
201
|
+
`MEDS_BIRTH` is at `PATIENTS.dob`, a real (date-shifted) date of birth. MIMIC-III shifts the date of
|
|
202
|
+
birth of patients older than 89 at their first admission a further 300 years back, so their age at
|
|
203
|
+
any event computes as about 300 (the median of the hidden ages is 91.4). It is kept as recorded,
|
|
204
|
+
rather than replaced by a made-up date: an age above 200 means "over 89". MIMIC-IV-MEDS, whose source
|
|
205
|
+
gives only an age, records 91 for them; to match it, cap ages at 91 when computing them.
|
|
206
|
+
|
|
207
|
+
### Deaths
|
|
208
|
+
|
|
209
|
+
Each subject gets at most one `MEDS_DEATH`: at the earliest `ADMISSIONS.deathtime` (an in-hospital
|
|
210
|
+
death; `PATIENTS` joins it with `cols: {deathtime: min}`), else at `PATIENTS.dod`, the date of death
|
|
211
|
+
(midnight), the MIMIC-IV rule. `PATIENTS.dod` merges the hospital record (`dod_hosp`) and the Social
|
|
212
|
+
Security death index (`dod_ssn`), so it includes deaths after discharge. `hospital_expire_flag` and
|
|
213
|
+
`expire_flag` are not used.
|
|
214
|
+
|
|
215
|
+
### Demographics
|
|
216
|
+
|
|
217
|
+
`insurance`, `language`, `marital_status`, `religion` and `ethnicity` are recorded per admission, so
|
|
218
|
+
each is its own event, timed at the admission. MIMIC-III's `ethnicity` holds the same categories that
|
|
219
|
+
MIMIC-IV (from v2.0) calls `race`, so it is written `RACE//…`, as in MIMIC-IV-MEDS. Nulls are not
|
|
220
|
+
coalesced: a missing demographic gives no event rather than a `RACE//UNK` code that would read as an
|
|
221
|
+
observed category.
|
|
222
|
+
|
|
223
|
+
### Event timing
|
|
224
|
+
|
|
225
|
+
- **Billing codes** (`DIAGNOSIS`, `PROCEDURE//ICD`, `DRG`, `CPT`) have no time of their own and are
|
|
226
|
+
timed at the admission's `dischtime`, when they are known, as in MIMIC-IV-MEDS.
|
|
227
|
+
- **Lab results** are at `charttime`, when the specimen was drawn. MIMIC-III has no result time
|
|
228
|
+
(MIMIC-IV-MEDS times `LAB//RESULT` at `storetime`), so a result appears before it was available;
|
|
229
|
+
allow for that in prediction windows.
|
|
230
|
+
- **Prescriptions** have dates only: `startdate` and `enddate` parse to midnight, so a start can
|
|
231
|
+
come before the admission it belongs to on the same day.
|
|
232
|
+
- `PATIENTS.dod`, for deaths outside the hospital, is a date (midnight).
|
|
233
|
+
- Times are shifted per patient into 2100–2200, preserving intervals, day of the week and season.
|
|
234
|
+
|
|
235
|
+
### ICD-9 procedure codes
|
|
236
|
+
|
|
237
|
+
MEDS-Extract types every CSV column from all of its values, and it has no way yet to declare a type
|
|
238
|
+
([MEDS_extract#143](https://github.com/mmcdermott/MEDS_extract/issues/143)). The ICD-9 procedure
|
|
239
|
+
codes are digits only, so `PROCEDURES_ICD.icd9_code` and `D_ICD_PROCEDURES.icd9_code` would be read
|
|
240
|
+
as integers and lose their leading zeros. They cannot be padded back: an ICD-9 procedure code has 3
|
|
241
|
+
or 4 digits, so `0331` (insertion of a totally implantable vascular access device) and `331`
|
|
242
|
+
(thoracoscopic lung biopsy) would both become `331`. In `D_ICD_PROCEDURES`, 3,882 codes collapse to
|
|
243
|
+
3,809. The spec's pre-stage `mimic3_text_columns` therefore re-reads those two tables with
|
|
244
|
+
`icd9_code` as text (every other column typed as MEDS-Extract would type it) and hands them to the ETL
|
|
245
|
+
as parquet, which keeps the types. Diagnosis codes need nothing: their columns hold V and E codes, so
|
|
246
|
+
they are read as text anyway.
|
|
247
|
+
|
|
248
|
+
NDCs (always 11 digits), CPT codes (always 5 characters) and DRG codes (3 digits) are read as integers
|
|
249
|
+
too, but their length is fixed, so the spec pads them back (`00006494300`, `00100`, `003`).
|
|
250
|
+
|
|
251
|
+
### DRG
|
|
252
|
+
|
|
253
|
+
`DRGCODES.drg_type` is one of three groupers: `MS` (MS-DRG, from October 2007, parent `MS-DRG//…`),
|
|
254
|
+
`HCFA` (the CMS DRG grouper that MS-DRG replaced, parent `CMS-DRG//…`) and `APR` (APR-DRG, parent
|
|
255
|
+
`APR-DRG//…`). The code keeps `drg_type` as recorded (`DRG//HCFA//003`). The DRG title varies in
|
|
256
|
+
spelling across rows of one code, so it is in `text_value`, not the description.
|
|
257
|
+
|
|
258
|
+
### Inputs
|
|
259
|
+
|
|
260
|
+
CareVue charts an input at one time, `charttime`, with the amount given since the last charting
|
|
261
|
+
(`amount`) and the rate running then (`rate`); it records no start or end. Each row gives up to two
|
|
262
|
+
point events, `INFUSION//AMOUNT//{itemid}//{amountuom}` and `INFUSION//RATE//{itemid}//{rateuom}`, and
|
|
263
|
+
no event for a missing amount or rate. MetaVision (`INPUTEVENTS_MV`, full release only) records
|
|
264
|
+
intervals, which become `INFUSION//START//…` (value: rate) and `INFUSION//END//…` (value: amount) as in
|
|
265
|
+
MIMIC-IV-MEDS. All carry `order_id` and `link_order_id`.
|
|
266
|
+
|
|
267
|
+
### Transfers
|
|
268
|
+
|
|
269
|
+
MIMIC-III's `TRANSFERS.curr_careunit` names a care unit only for ICU locations (`MICU`, `SICU`, `CCU`,
|
|
270
|
+
`CSRU`, `TSICU`, `NICU`, `NWARD`); a ward and the discharge rows have none, so they are
|
|
271
|
+
`TRANSFER_TO//transfer//UNK` and `TRANSFER_TO//discharge//UNK`.
|
|
272
|
+
|
|
273
|
+
### Cohort (CareVue subset)
|
|
274
|
+
|
|
275
|
+
- **Mortality-biased.** The removed subjects are those with a hospitalization in MIMIC-IV (2008–2019),
|
|
276
|
+
that is, patients who survived to come back. Survivors are therefore under-represented, and death
|
|
277
|
+
and readmission rates are higher than in MIMIC-III as a whole. Compare rates with that in mind.
|
|
278
|
+
- **ICD-9 only, CareVue charting only** (no MetaVision tables, no ICD-10).
|
|
279
|
+
- **Neonates.** MIMIC-III includes neonatal ICU stays (`NICU`), and so does the subset. Restrict tasks
|
|
280
|
+
to adults by age at admission or by care unit where needed.
|
|
281
|
+
- `LABEVENTS` keeps only rows before the discharge of the subject's last CareVue hospitalization.
|
|
282
|
+
- No overlap with MIMIC-IV, so it is safe as an out-of-time test set for models trained on MIMIC-IV.
|
|
283
|
+
|
|
284
|
+
## Enriching code metadata with suMEDS
|
|
285
|
+
|
|
286
|
+
The ETL writes what MIMIC-III itself records. Links that MIMIC-III does not record, and parents among
|
|
287
|
+
its own codes, are added afterwards by [suMEDS](https://github.com/rvandewater/suMEDS). The package
|
|
288
|
+
ships the rules, [`src/MIMIC_III_MEDS/sumeds_rules.yaml`](https://github.com/rvandewater/MIMIC_III_MEDS/blob/main/src/MIMIC_III_MEDS/sumeds_rules.yaml),
|
|
289
|
+
registered in suMEDS's `sumeds.rules` entry-point group as `MIMIC-III`, so `--rules MIMIC-III` works
|
|
290
|
+
for any suMEDS command. The spec runs them as its last stage. The ontology packs come from suMEDS's
|
|
291
|
+
versioned ontology data (sumeds-ontologies), fetched from GitHub on first use and cached.
|
|
292
|
+
|
|
293
|
+
The rules (MIMIC-IV-MEDS's ICD-9 rules) add:
|
|
294
|
+
|
|
295
|
+
- **ICD-9 diagnoses and procedures**: the dotted code is validated against the ICD-9-CM or ICD9Proc
|
|
296
|
+
pack and gives `vocabulary_id`, `concept_code` and every pack ancestor, after the ETL's own parent
|
|
297
|
+
(`DIAGNOSIS//ICD//9CM//4280` gets `ICD9CM//428.0`, `ICD9CM//428`).
|
|
298
|
+
- **Gender**: `GENDER//F` and `GENDER//M` get the OMOP Gender codes `Gender//F` and `Gender//M`.
|
|
299
|
+
- **Parents among the dataset's ICD codes**: an ICD code of the dataset becomes the parent of another
|
|
300
|
+
when it is its nearest pack ancestor present (`DIAGNOSIS//ICD//9CM//4280` gets
|
|
301
|
+
`DIAGNOSIS//ICD//9CM//428` when both occur).
|
|
302
|
+
|
|
303
|
+
suMEDS names every parent a pack knows in `parent_names` (including the ETL's `LOINC//…` parents) and
|
|
304
|
+
never removes or rewrites the ETL's parents or descriptions.
|
|
305
|
+
|
|
306
|
+
`metadata/dataset.json` says whether a build is enriched: `sumeds_enrichment.enriched` is `true` (with
|
|
307
|
+
the rules and coverage) or `false` (with the error and the `retry` command). Enrichment soft-fails:
|
|
308
|
+
without internet the ETL still succeeds with `codes.parquet` as MEDS-Extract writes it. The warning is
|
|
309
|
+
in `$OUTPUT_DIR/.logs/pipeline.log`. Finish it later:
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
suMEDS-enrich $OUTPUT_DIR
|
|
313
|
+
# Air-gapped: from a copy of the sumeds-ontologies packs directory
|
|
314
|
+
suMEDS-enrich $OUTPUT_DIR --ontology-source /path/to/sumeds-ontologies/ontologies --offline
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
On a cluster whose compute nodes have no internet, fill a shared cache from a login node first:
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
export XDG_CACHE_HOME=/shared/project/cache
|
|
321
|
+
suMEDS-enrich --prefetch --rules MIMIC-III # on the login node
|
|
322
|
+
meds-extract-run spec=MIMIC-III dataset_key=carevue output_dir=$OUTPUT_DIR "overrides=['++stage_cfg.offline=true']"
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
The stage takes the `suMEDS-enrich` options as `"overrides=['++stage_cfg.<option>=...']"` (for
|
|
326
|
+
example `strict=true` to make a failed enrichment fail the run).
|
|
327
|
+
|
|
328
|
+
## Summary statistics
|
|
329
|
+
|
|
330
|
+
`tests/regression/<kind>_summary_stats.json` are
|
|
331
|
+
[meds_summary_stats](https://github.com/Medical-Event-Data-Standard/meds_summary_stats) fingerprints of
|
|
332
|
+
the MEDS datasets this ETL builds: counts, digests of the code vocabulary, value and time
|
|
333
|
+
distributions, code-metadata coverage, splits and schema. They name no code and report no cell of fewer
|
|
334
|
+
than 20 subjects and no minimum or maximum, which is what makes them safe to publish. Kinds: `demo`
|
|
335
|
+
(rebuilt and compared in CI), `carevue` and `full` (credentialed; regenerated by whoever changes the
|
|
336
|
+
ETL). The `demo` and `carevue` baselines are committed (`carevue` from a 0.0.1 build of the CareVue
|
|
337
|
+
subset); there is no `full` baseline yet. The
|
|
338
|
+
[Datasets page](https://medical-event-data-standard.github.io/datasets) of the MEDS website charts the
|
|
339
|
+
committed baselines.
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
scripts/summary_stats.sh carevue --input-dir $CAREVUE_RAW_DIR # build with this checkout, then update
|
|
343
|
+
scripts/summary_stats.sh carevue --meds-dir $MEDS_OUTPUT_DIR # or summarize an existing build
|
|
344
|
+
scripts/summary_stats.sh demo # downloads the demo
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Each prints how the statistics changed against the committed baseline before overwriting it. Add
|
|
348
|
+
`--compare` to check a build without writing; it exits 1 when
|
|
349
|
+
[`tests/regression/policy.yaml`](https://github.com/rvandewater/MIMIC_III_MEDS/blob/main/tests/regression/policy.yaml) flags an error. The
|
|
350
|
+
[Summary stats workflow](https://github.com/rvandewater/MIMIC_III_MEDS/blob/main/.github/workflows/summary-stats.yaml) warns when a pull request changes
|
|
351
|
+
`src/` without regenerating the credentialed baselines.
|
|
352
|
+
|
|
353
|
+
## Citation
|
|
354
|
+
|
|
355
|
+
If you use this package, cite it through this repository, and cite the dataset you built through
|
|
356
|
+
PhysioNet:
|
|
357
|
+
|
|
358
|
+
```bibtex
|
|
359
|
+
@misc{PhysioNet-mimic3-carevue-1.4,
|
|
360
|
+
author = {Johnson, Alistair and Pollard, Tom and Mark, Roger},
|
|
361
|
+
title = {{MIMIC-III Clinical Database CareVue subset}},
|
|
362
|
+
publisher = {PhysioNet},
|
|
363
|
+
year = {2022},
|
|
364
|
+
note = {Version 1.4},
|
|
365
|
+
doi = {10.13026/8a4q-w170},
|
|
366
|
+
url = {https://doi.org/10.13026/8a4q-w170}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
@misc{PhysioNet-mimiciii-1.4,
|
|
370
|
+
author = {Johnson, Alistair and Pollard, Tom and Mark, Roger},
|
|
371
|
+
title = {{MIMIC-III Clinical Database}},
|
|
372
|
+
publisher = {PhysioNet},
|
|
373
|
+
year = {2016},
|
|
374
|
+
note = {Version 1.4},
|
|
375
|
+
doi = {10.13026/C2XW26},
|
|
376
|
+
url = {https://doi.org/10.13026/C2XW26}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
@article{johnson2016mimic,
|
|
380
|
+
title = {{MIMIC-III}, a freely accessible critical care database},
|
|
381
|
+
author = {Johnson, Alistair E. W. and Pollard, Tom J. and Shen, Lu and Lehman, Li-wei H. and Feng, Mengling and Ghassemi, Mohammad and Moody, Benjamin and Szolovits, Peter and Celi, Leo Anthony and Mark, Roger G.},
|
|
382
|
+
journal = {Scientific Data},
|
|
383
|
+
volume = {3},
|
|
384
|
+
pages = {160035},
|
|
385
|
+
year = {2016},
|
|
386
|
+
doi = {10.1038/sdata.2016.35}
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
For citing MEDS in general:
|
|
391
|
+
|
|
392
|
+
```bibtex
|
|
393
|
+
@article{mcdermott2026meds,
|
|
394
|
+
title={MEDS—An Emerging Data Standard and Ecosystem for Health AI Research},
|
|
395
|
+
author={McDermott, Matthew BA and Steinberg, Ethan and Fries, Jason A and van de Water, Robin P and Pang, Chao and Rockenschaub, Patrick and Renc, Pawel and Oh, Jungwoo and Stankevi{\v{c}}i{\=u}t{\.e}, Kamil{\.e} and Xu, Justin and others},
|
|
396
|
+
journal={NEJM AI},
|
|
397
|
+
volume={3},
|
|
398
|
+
number={6},
|
|
399
|
+
pages={AIra2501253},
|
|
400
|
+
year={2026},
|
|
401
|
+
publisher={Massachusetts Medical Society}
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## License
|
|
406
|
+
|
|
407
|
+
MIT for this code. The data keep the licence of their PhysioNet release (see the table above).
|