MIMIC-IV
Functions for reading from downloaded MIMIC-IV (v2.2) data.
add_inhospital_mortality_to_stays(stays)
Adds mortality column (binary) to indicate in-hospital mortality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stays |
LazyFrame | DataFrame
|
Stays table. |
required |
Returns:
Type | Description |
---|---|
LazyFrame | DataFrame
|
pl.LazyFrame | pl.DataFrame: Stays table with 'mortality' column. |
Source code in src/utils/mimiciv.py
add_omr_variable_to_stays(stays, omr, variable, tolerance=None)
Adds variables from omr table to stays table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stays |
LazyFrame | DataFrame
|
Stays table. |
required |
omr |
LazyFrame | DataFrame
|
OMR table. |
required |
variable |
str
|
Variable to extract from omr table. |
required |
tolerance |
int
|
Window (days) around admission date to search for data in omr. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
LazyFrame | DataFrame
|
pl.LazyFrame | pl.DataFrame: Stays table with new variable column. |
Source code in src/utils/mimiciv.py
filter_on_nb_stays(stays, min_nb_stays=1, max_nb_stays=1)
Filters stays to ensure certain number of emergency department stays per hospital admission (typically 1).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stays |
LazyFrame | DataFrame
|
Stays table. |
required |
min_nb_stays |
int
|
Minimum number of stays per admission. Defaults to 1. |
1
|
max_nb_stays |
int
|
Maximum number of stays per admission. Defaults to 1. |
1
|
Returns:
Type | Description |
---|---|
LazyFrame | DataFrame
|
pl.LazyFrame | pl.DataFrame: Filtered stays table. |
Source code in src/utils/mimiciv.py
filter_stays_on_age(stays, min_age=18, max_age=np.inf)
Filter stays based on patient age.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stays |
LazyFrame | DataFrame
|
Stays table. |
required |
min_age |
int
|
Minimum patient age. Defaults to 18. |
18
|
max_age |
_type_
|
Maximum patient age. Defaults to np.inf. |
inf
|
Returns:
Type | Description |
---|---|
LazyFrame | DataFrame
|
pl.LazyFrame | pl.DataFrame: Filtered stays table. |
Source code in src/utils/mimiciv.py
get_hadm_id_from_admits(events, admits)
Uses admissions table to extract hadm_id based on events charttime.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
events |
LazyFrame | DataFrame
|
Events table. |
required |
admits |
LazyFrame | DataFrame
|
Admissions table. |
required |
Returns:
Type | Description |
---|---|
LazyFrame | DataFrame
|
pl.LazyFrame | pl.DataFrame: Events table with filled hadm_id values where possible. |
Source code in src/utils/mimiciv.py
read_admissions_table(mimic4_path, use_lazy=False)
Reads in admissions.csv.gz table and formats column types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mimic4_path |
str
|
Path to directory containing downloaded MIMIC-IV hosp module files. |
required |
use_lazy |
bool
|
Whether to return a Polars LazyFrame or DataFrame. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
LazyFrame | DataFrame
|
pl.LazyFrame | pl.DataFrame: Admissions table. |
Source code in src/utils/mimiciv.py
read_events_table(table, mimic4_path, include_items=None)
Reads in ?events.csv.gz tables from MIMIC-IV and formats column types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table |
str
|
Name of the events table. Currently supports 'vitalsign' or 'labevents' |
required |
mimic4_path |
str
|
Path to directory containing events |
required |
include_items |
list
|
List of itemid values to filter. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
LazyFrame
|
pl.LazyFrame : Long-format events table. |
Source code in src/utils/mimiciv.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
read_notes(mimic4_path, use_lazy=False)
Read in discharge summary notes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mimic4_path |
str
|
description |
required |
use_lazy |
bool
|
Whether to return a Polars LazyFrame or DataFrame. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
LazyFrame | DataFrame
|
pl.LazyFrame | pl.DataFrame: description |
Source code in src/utils/mimiciv.py
read_omr_table(mimic4_path, use_lazy=False)
Reads in omr.csv.gz table and formats column types. Adds 'los' column based on hospital stay duration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mimic4_path |
str
|
Path to directory containing downloaded MIMIC-IV hosp module files. |
required |
use_lazy |
bool
|
Whether to return a Polars LazyFrame or DataFrame. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
LazyFrame | DataFrame
|
pl.LazyFrame | pl.DataFrame: Omr table. |
Source code in src/utils/mimiciv.py
read_patients_table(mimic4_path, use_lazy=False)
Reads in patients.csv.gz table and formats column types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mimic4_path |
str
|
Path to directory containing downloaded MIMIC-IV hosp module files. |
required |
use_lazy |
bool
|
Whether to return a Polars LazyFrame or DataFrame. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
LazyFrame | DataFrame
|
pl.LazyFrame | pl.DataFrame: Patients table. |
Source code in src/utils/mimiciv.py
read_stays_table(mimic4_ed_path, use_lazy=False)
Reads in stays.csv.gz table and formats column types. Adds 'los_ed' column based on emergency department stay duration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mimic4_ed_path |
str
|
Path to directory containing downloaded MIMIC-IV hosp module files. |
required |
use_lazy |
bool
|
Whether to return a Polars LazyFrame or DataFrame. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
LazyFrame | DataFrame
|
pl.LazyFrame | pl.DataFrame: Admissions table. |