MEDS-DEV 0.0.1__py3-none-any.whl

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.
Files changed (62) hide show
  1. MEDS_DEV/__init__.py +13 -0
  2. MEDS_DEV/configs/__init__.py +0 -0
  3. MEDS_DEV/configs/_build_dataset.yaml +24 -0
  4. MEDS_DEV/configs/_evaluate_predictions.yaml +22 -0
  5. MEDS_DEV/configs/_extract_task.yaml +24 -0
  6. MEDS_DEV/configs/_run_model.yaml +63 -0
  7. MEDS_DEV/datasets/AUMCdb/README.md +34 -0
  8. MEDS_DEV/datasets/AUMCdb/predicates.yaml +8 -0
  9. MEDS_DEV/datasets/MIMIC-IV/README.md +10 -0
  10. MEDS_DEV/datasets/MIMIC-IV/__init__.py +0 -0
  11. MEDS_DEV/datasets/MIMIC-IV/commands.yaml +14 -0
  12. MEDS_DEV/datasets/MIMIC-IV/predicates.yaml +167 -0
  13. MEDS_DEV/datasets/MIMIC-IV/requirements.txt +1 -0
  14. MEDS_DEV/datasets/OMOP/README.md +66 -0
  15. MEDS_DEV/datasets/OMOP/predicates.yaml +52 -0
  16. MEDS_DEV/datasets/README.md +19 -0
  17. MEDS_DEV/datasets/UCLA/README.md +33 -0
  18. MEDS_DEV/datasets/UCLA/predicates.yaml +18 -0
  19. MEDS_DEV/datasets/__init__.py +22 -0
  20. MEDS_DEV/datasets/__main__.py +36 -0
  21. MEDS_DEV/evaluation/README.md +4 -0
  22. MEDS_DEV/evaluation/__init__.py +5 -0
  23. MEDS_DEV/evaluation/__main__.py +31 -0
  24. MEDS_DEV/models/__init__.py +16 -0
  25. MEDS_DEV/models/__main__.py +203 -0
  26. MEDS_DEV/models/random_predictor/README.md +5 -0
  27. MEDS_DEV/models/random_predictor/__init__.py +0 -0
  28. MEDS_DEV/models/random_predictor/_config.yaml +14 -0
  29. MEDS_DEV/models/random_predictor/generate_random_predictions.py +81 -0
  30. MEDS_DEV/models/random_predictor/model.yaml +7 -0
  31. MEDS_DEV/tasks/README.md +17 -0
  32. MEDS_DEV/tasks/__init__.py +18 -0
  33. MEDS_DEV/tasks/__main__.py +55 -0
  34. MEDS_DEV/tasks/abnormal_lab/README.md +7 -0
  35. MEDS_DEV/tasks/abnormal_lab/blood_chemistry/elevated_creatinine/first_24h.yaml +64 -0
  36. MEDS_DEV/tasks/abnormal_lab/blood_chemistry/hyponatremia/first_24h.yaml +64 -0
  37. MEDS_DEV/tasks/abnormal_lab/blood_chemistry/metabolic_acidosis/first_24h.yaml +64 -0
  38. MEDS_DEV/tasks/abnormal_lab/cbc/anemia/first_24h.yaml +64 -0
  39. MEDS_DEV/tasks/abnormal_lab/cbc/leukocytosis/first_24h.yaml +64 -0
  40. MEDS_DEV/tasks/abnormal_lab/cbc/thrombocytopenia/first_24h.yaml +64 -0
  41. MEDS_DEV/tasks/abnormal_lab/reduced_echo_derived_LVEF_via_ECG.yaml +45 -0
  42. MEDS_DEV/tasks/abnormal_lab/vital/hypotension/first_24h.yaml +64 -0
  43. MEDS_DEV/tasks/disease_progression/README.md +6 -0
  44. MEDS_DEV/tasks/disease_progression/diabetes/README.md +1 -0
  45. MEDS_DEV/tasks/disease_progression/diabetes/ckd_post_kidney_labs.yaml +85 -0
  46. MEDS_DEV/tasks/mortality/README.md +12 -0
  47. MEDS_DEV/tasks/mortality/in_icu/README.md +7 -0
  48. MEDS_DEV/tasks/mortality/in_icu/first_24h.yaml +44 -0
  49. MEDS_DEV/tasks/phenotyping/README.md +5 -0
  50. MEDS_DEV/tasks/phenotyping/outpatient/MI/1y-5y.yaml +41 -0
  51. MEDS_DEV/tasks/phenotyping/outpatient/MI/README.md +3 -0
  52. MEDS_DEV/tasks/phenotyping/outpatient/README.md +2 -0
  53. MEDS_DEV/tasks/readmission/README.md +20 -0
  54. MEDS_DEV/tasks/readmission/general_hospital/30d.yaml +51 -0
  55. MEDS_DEV/tasks/readmission/general_hospital/README.md +4 -0
  56. MEDS_DEV/utils.py +61 -0
  57. MEDS_DEV-0.0.1.dist-info/LICENSE +21 -0
  58. MEDS_DEV-0.0.1.dist-info/METADATA +301 -0
  59. MEDS_DEV-0.0.1.dist-info/RECORD +62 -0
  60. MEDS_DEV-0.0.1.dist-info/WHEEL +5 -0
  61. MEDS_DEV-0.0.1.dist-info/entry_points.txt +5 -0
  62. MEDS_DEV-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,31 @@
1
+ import logging
2
+ import subprocess
3
+
4
+ import hydra
5
+ from omegaconf import DictConfig
6
+
7
+ from . import CFG_YAML
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ @hydra.main(version_base=None, config_path=str(CFG_YAML.parent), config_name=CFG_YAML.stem)
13
+ def main(cfg: DictConfig):
14
+ cmd_parts = [
15
+ "meds-evaluation-cli",
16
+ f'predictions_path="{cfg.predictions_path}"',
17
+ f'output_dir="{cfg.output_dir}"',
18
+ ]
19
+ cmd = " ".join(cmd_parts)
20
+
21
+ logger.info(f"Running MEDS-Evaluation: {cmd}")
22
+ evaluation_command_out = subprocess.run(cmd, shell=True, capture_output=True)
23
+
24
+ command_errored = evaluation_command_out.returncode != 0
25
+ if command_errored:
26
+ raise RuntimeError(
27
+ f"Evaluation command {cmd} failed with exit code "
28
+ f"{evaluation_command_out.returncode}:\n"
29
+ f"STDERR:\n{evaluation_command_out.stderr.decode()}\n"
30
+ f"STDOUT:\n{evaluation_command_out.stdout.decode()}"
31
+ )
@@ -0,0 +1,16 @@
1
+ from importlib.resources import files
2
+
3
+ from omegaconf import OmegaConf
4
+
5
+ model_files = files("MEDS_DEV.models")
6
+ CFG_YAML = files("MEDS_DEV.configs") / "_run_model.yaml"
7
+
8
+ MODELS = {}
9
+
10
+ for path in model_files.rglob("*/model.yaml"):
11
+ model_name = path.relative_to(model_files).parent.with_suffix("").as_posix()
12
+ MODELS[model_name] = OmegaConf.to_object(OmegaConf.load(path))
13
+ requirements_path = path / "requirements.txt"
14
+ MODELS[model_name]["requirements"] = requirements_path if requirements_path.exists() else None
15
+
16
+ __all__ = ["MODELS", "CFG_YAML"]
@@ -0,0 +1,203 @@
1
+ import itertools
2
+ import logging
3
+ import shutil
4
+ import subprocess
5
+ from collections.abc import Generator
6
+ from pathlib import Path
7
+
8
+ import meds
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+ from enum import StrEnum, auto
13
+
14
+ import hydra
15
+ from omegaconf import DictConfig
16
+
17
+ from ..utils import temp_env
18
+ from . import CFG_YAML, MODELS
19
+
20
+
21
+ class RunMode(StrEnum):
22
+ """The different run modes supported.
23
+
24
+ Args:
25
+ TRAIN: Train a model.
26
+ PREDICT: Predict with a model.
27
+ FULL: Perform all viable stages for a model.
28
+ """
29
+
30
+ TRAIN = auto()
31
+ PREDICT = auto()
32
+ FULL = auto()
33
+
34
+
35
+ ALL_RUN_MODES = [RunMode.TRAIN, RunMode.PREDICT]
36
+
37
+
38
+ class DatasetType(StrEnum):
39
+ """The different dataset types supported.
40
+
41
+ Args:
42
+ UNSUPERVISED: Unsupervised dataset.
43
+ SUPERVISED: Supervised dataset.
44
+ FULL: Run the model across both the unsupervised and supervised datasets.
45
+ """
46
+
47
+ UNSUPERVISED = auto()
48
+ SUPERVISED = auto()
49
+ FULL = auto()
50
+
51
+
52
+ ALL_DATASET_TYPES = [DatasetType.UNSUPERVISED, DatasetType.SUPERVISED]
53
+
54
+ COMMANDS_DICT_T = dict[str, dict[str, str]]
55
+
56
+
57
+ def fmt_command(
58
+ commands: COMMANDS_DICT_T, dataset_type: DatasetType, run_mode: RunMode, **format_kwargs
59
+ ) -> str:
60
+ """Gets the appropriate model command for the given run mode and commands dictionary.
61
+
62
+ Args:
63
+ commands: The dictionary of commands for the model. These are stored in the model folder in
64
+ `model.yaml` in the `commands` key and are loaded for the correct model from the MODELS
65
+ dictionary.
66
+ dataset_type: The dataset type to use.
67
+ run_mode: The run mode to use.
68
+
69
+ Returns:
70
+ The command to run the model.
71
+
72
+ Examples:
73
+ >>> TODO
74
+ """
75
+
76
+ if dataset_type not in commands:
77
+ raise RuntimeError(f"Model does not support dataset type {dataset_type}.")
78
+
79
+ dataset_commands = commands[dataset_type]
80
+ if run_mode not in dataset_commands:
81
+ raise RuntimeError(f"Model does not support run mode {run_mode}.")
82
+
83
+ return commands[dataset_type][run_mode].format(**format_kwargs)
84
+
85
+
86
+ def model_commands(cfg: DictConfig, commands: dict[str, dict[str, str]]) -> Generator[tuple[str, Path]]:
87
+ """Yields the sequence of appropriate dataset, run mode pairs for the given config and commands.
88
+
89
+ Args:
90
+ cfg: TODO
91
+ commands: TODO
92
+
93
+ Yields:
94
+ The sequence of base commands (un-formatted) to run for the given model run.
95
+
96
+ Examples:
97
+ >>> TODO
98
+ """
99
+
100
+ run_modes = ALL_RUN_MODES if cfg.mode == RunMode.FULL else [cfg.mode]
101
+ dataset_types = ALL_DATASET_TYPES if cfg.dataset_type == DatasetType.FULL else [cfg.dataset_type]
102
+
103
+ do_set_split = cfg.mode == RunMode.FULL
104
+
105
+ output_dir = Path(cfg.output_dir)
106
+
107
+ format_kwargs = {"dataset_dir": str(cfg.dataset_dir)}
108
+ if cfg.get("model_initialization_dir", None):
109
+ format_kwargs["model_initialization_dir"] = cfg.model_initialization_dir
110
+ if cfg.get("demo", False):
111
+ format_kwargs["demo"] = True
112
+ if cfg.get("split", None):
113
+ if do_set_split:
114
+ raise ValueError(f"Cannot set split manually when mode is {cfg.mode}.")
115
+ format_kwargs["split"] = cfg.split
116
+
117
+ if len(run_modes) == 1 and len(dataset_types) == 1:
118
+ run_mode = run_modes[0]
119
+ dataset_type = dataset_types[0]
120
+ format_kwargs["output_dir"] = str(output_dir)
121
+
122
+ yield fmt_command(commands, dataset_type, run_mode, **format_kwargs), output_dir
123
+ return
124
+
125
+ all_modes = itertools.product(run_modes, dataset_types)
126
+ for run_mode, dataset_type in all_modes:
127
+ dataset_commands = commands.get(dataset_type, None)
128
+ if dataset_commands is None:
129
+ continue
130
+
131
+ run_command = dataset_commands.get(run_mode, None)
132
+ if not run_command:
133
+ continue
134
+
135
+ run_output_dir = output_dir / cfg.dataset_name
136
+ if dataset_type == DatasetType.SUPERVISED:
137
+ run_output_dir = run_output_dir / cfg.task_name
138
+ format_kwargs["labels_dir"] = str(cfg.labels_dir)
139
+ else:
140
+ run_output_dir = run_output_dir / dataset_type
141
+
142
+ run_output_dir = run_output_dir / run_mode
143
+
144
+ format_kwargs["output_dir"] = str(run_output_dir)
145
+
146
+ if do_set_split:
147
+ if run_mode == RunMode.PREDICT:
148
+ format_kwargs["split"] = meds.held_out_split
149
+ else:
150
+ # We don't set the split in anything but predict mode.
151
+ format_kwargs.pop("split", None)
152
+
153
+ yield (fmt_command(commands, dataset_type, run_mode, **format_kwargs), run_output_dir)
154
+
155
+ if run_mode != RunMode.PREDICT:
156
+ format_kwargs["model_initialization_dir"] = str(run_output_dir)
157
+
158
+
159
+ @hydra.main(version_base=None, config_path=str(CFG_YAML.parent), config_name=CFG_YAML.stem)
160
+ def main(cfg: DictConfig):
161
+ if cfg.model not in MODELS:
162
+ raise ValueError(f"Model {cfg.model} not currently configured")
163
+
164
+ commands = MODELS[cfg.model]["commands"]
165
+ requirements = MODELS[cfg.model]["requirements"]
166
+
167
+ output_dir = Path(cfg.output_dir)
168
+
169
+ if cfg.do_overwrite:
170
+ if output_dir.exists():
171
+ logger.info(f"Removing existing output directory: {output_dir}")
172
+ shutil.rmtree(output_dir)
173
+ else:
174
+ logger.info(f"Output directory {output_dir} does not exist. No need to remove.")
175
+
176
+ output_dir.mkdir(exist_ok=True, parents=True)
177
+
178
+ with temp_env(cfg, requirements) as (temp_dir, env):
179
+ for cmd, out_dir in model_commands(cfg, commands):
180
+ done_file = out_dir / ".done"
181
+ if done_file.exists():
182
+ logger.info(f"Skipping {cmd} because {done_file} exists.")
183
+ continue
184
+
185
+ logger.info(f"Running model command: {cmd}")
186
+ command_out = subprocess.run(cmd, shell=True, env=env, cwd=temp_dir, capture_output=True)
187
+
188
+ command_errored = command_out.returncode != 0
189
+ if command_errored:
190
+ raise RuntimeError(
191
+ f"{cfg.model} command {cmd} failed with exit code "
192
+ f"{command_out.returncode}:\n"
193
+ f"STDERR:\n{command_out.stderr.decode()}\n"
194
+ f"STDOUT:\n{command_out.stdout.decode()}"
195
+ )
196
+ elif not out_dir.is_dir():
197
+ raise RuntimeError(
198
+ f"{cfg.model} command {cmd} failed to create output directory {out_dir}.\n"
199
+ f"STDERR:\n{command_out.stderr.decode()}\n"
200
+ f"STDOUT:\n{command_out.stdout.decode()}"
201
+ )
202
+ else:
203
+ done_file.touch()
@@ -0,0 +1,5 @@
1
+ # Random Predictor
2
+
3
+ This is a random, dummy predictor for use primarily in testing. It literally just spits out random
4
+ predictions. The predictions are not calibrated to the base rate of the task, they are truly just random with
5
+ a chance value of 0.5.
File without changes
@@ -0,0 +1,14 @@
1
+ defaults:
2
+ - _self_
3
+ - override hydra/hydra_logging: disabled
4
+
5
+ dataset_dir: ???
6
+ labels_dir: ???
7
+ output_dir: ???
8
+ predictions_fp: ${output_dir}/predictions.parquet
9
+ split: "held_out"
10
+ seed: 1
11
+
12
+ hydra:
13
+ run:
14
+ dir: ${output_dir}
@@ -0,0 +1,81 @@
1
+ import logging
2
+ from importlib.resources import files
3
+ from pathlib import Path
4
+
5
+ import hydra
6
+ import meds
7
+ import numpy as np
8
+ import polars as pl
9
+ from meds_evaluation.schema import (
10
+ PREDICTED_BOOLEAN_PROBABILITY_FIELD,
11
+ PREDICTED_BOOLEAN_VALUE_FIELD,
12
+ validate_binary_classification_schema,
13
+ )
14
+ from omegaconf import DictConfig
15
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+ CONFIG = files("MEDS_DEV") / "models" / "random_predictor" / "_config.yaml"
19
+
20
+
21
+ @hydra.main(version_base=None, config_path=str(CONFIG.parent.resolve()), config_name=CONFIG.stem)
22
+ def main(cfg: DictConfig) -> None:
23
+ dataset_dir = Path(cfg.dataset_dir)
24
+ labels_dir = Path(cfg.labels_dir)
25
+ predictions_fp = Path(cfg.predictions_fp)
26
+ predictions_fp.parent.mkdir(parents=True, exist_ok=True)
27
+ seed = cfg.seed
28
+
29
+ if cfg.split != meds.held_out_split:
30
+ raise ValueError(
31
+ f"Split {cfg.split} does not match held out split {meds.held_out_split}; this model should "
32
+ "only be used for predictions so this is likely an error!"
33
+ )
34
+
35
+ splits_file = dataset_dir / meds.subject_splits_filepath
36
+ if not splits_file.is_file():
37
+ raise FileNotFoundError(
38
+ f"Could not find splits file {splits_file.relative_to(dataset_dir)} for dataset "
39
+ f"{dataset_dir}."
40
+ )
41
+
42
+ splits = pl.read_parquet(splits_file, use_pyarrow=True)
43
+ subjects = set(splits.filter(pl.col("split") == cfg.split)[meds.subject_id_field])
44
+
45
+ # Labels can live in any parquet file within the labels directory:
46
+ labels_files = list(labels_dir.rglob("*.parquet"))
47
+ if not labels_files:
48
+ logger.warning(f"No labels found in {labels_dir}. Exiting without writing.")
49
+ return
50
+
51
+ def read_split(fp: Path) -> pl.DataFrame:
52
+ return pl.read_parquet(fp, use_pyarrow=True).filter(pl.col(meds.subject_id_field).is_in(subjects))
53
+
54
+ try:
55
+ labels = pl.concat([read_split(f) for f in labels_files], how="vertical_relaxed")
56
+ except Exception as e:
57
+ err_lines = [f"Error reading labels: {e}", "Labels dir contents:"]
58
+ for file in labels_dir.rglob("*.parquet"):
59
+ err_lines.append(f" - {file.relative_to(labels_dir)}")
60
+ err_str = "\n".join(err_lines)
61
+ logger.error(err_str)
62
+ raise ValueError(err_str) from e
63
+
64
+ rng = np.random.default_rng(seed)
65
+ probabilities = rng.uniform(0, 1, len(labels))
66
+
67
+ predictions = labels.with_columns(
68
+ pl.Series(probabilities).alias(PREDICTED_BOOLEAN_PROBABILITY_FIELD),
69
+ )
70
+ predictions = predictions.with_columns(
71
+ (pl.col(PREDICTED_BOOLEAN_PROBABILITY_FIELD) > 0.5).alias(PREDICTED_BOOLEAN_VALUE_FIELD),
72
+ )
73
+
74
+ # Check the schema output:
75
+ validate_binary_classification_schema(predictions)
76
+
77
+ predictions.write_parquet(predictions_fp, use_pyarrow=True)
78
+
79
+
80
+ if __name__ == "__main__":
81
+ main()
@@ -0,0 +1,7 @@
1
+ commands:
2
+ unsupervised: null
3
+ supervised:
4
+ train: null
5
+ predict: >-
6
+ python -m MEDS_DEV.models.random_predictor.generate_random_predictions labels_dir={labels_dir}
7
+ output_dir={output_dir} split={split} dataset_dir={dataset_dir}
@@ -0,0 +1,17 @@
1
+ # Task Criteria Files
2
+
3
+ This folder contains the dataset-agnostic criteria files for a collection of pre-defined tasks. These tasks
4
+ are nested, and the overall "task name" should reflect that nesting -- e.g., the file
5
+ `mortality/in_hospital/first_24h.yaml` is the configuration for the `mortality/in_hospital/first_24h` task.
6
+
7
+ Each directory in this structure should contain a `README.md` file that describes that sub-collection of
8
+ tasks.
9
+
10
+ All task criteria files are [ACES](https://github.com/justin13601/ACES) task-configuration `yaml` files. The
11
+ current version of ACES supported by these files can be seen in the `pyproject.toml` file in the root of this
12
+ repository. Currently, all tasks should be interpreted as _binary classification_ tasks. When run through the
13
+ ACES-CLI tool in `meds` format, the output files will be in the `meds` `label` schema, with the label for the
14
+ task appearing in the `boolean_label` column. For the current version of `meds` supported, see the
15
+ `pyproject.toml` file in the root of this repository.
16
+
17
+ Task criteria files should each contain a free-text `description` key describing the task.
@@ -0,0 +1,18 @@
1
+ from importlib.resources import files
2
+
3
+ from omegaconf import OmegaConf
4
+
5
+ task_files = files("MEDS_DEV.tasks")
6
+ CFG_YAML = files("MEDS_DEV.configs") / "_extract_task.yaml"
7
+ ACES_CFG_YAML = files("MEDS_DEV.configs") / "_ACES_MD.yaml"
8
+
9
+ TASKS = {}
10
+ for path in task_files.glob("**/*.yaml"):
11
+ task = path.relative_to(task_files).with_suffix("").as_posix()
12
+ metadata = OmegaConf.load(path).get("metadata", None)
13
+ TASKS[task] = {
14
+ "criteria_fp": path,
15
+ "metadata": metadata,
16
+ }
17
+
18
+ __all__ = ["TASKS", "CFG_YAML", "ACES_CFG_YAML"]
@@ -0,0 +1,55 @@
1
+ import logging
2
+ import subprocess
3
+
4
+ import hydra
5
+ from omegaconf import DictConfig
6
+
7
+ from .. import DATASETS
8
+ from . import CFG_YAML, TASKS
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+
13
+ @hydra.main(version_base=None, config_path=str(CFG_YAML.parent), config_name=CFG_YAML.stem)
14
+ def main(cfg: DictConfig):
15
+ if cfg.task not in TASKS:
16
+ raise ValueError(f"Task {cfg.task} not currently configured")
17
+ if cfg.dataset not in DATASETS:
18
+ raise ValueError(f"Dataset {cfg.dataset} not currently configured")
19
+
20
+ task_config_path = TASKS[cfg.task]["criteria_fp"]
21
+ dataset_predicates_path = DATASETS[cfg.dataset]["predicates"]
22
+
23
+ if dataset_predicates_path is None:
24
+ raise ValueError(f"Predicates not found for dataset {cfg.dataset}")
25
+
26
+ logger.info(f"Running task {cfg.task} on dataset {cfg.dataset}")
27
+
28
+ # make the ACES command
29
+ cmd = " ".join(
30
+ [
31
+ "aces-cli",
32
+ "--multirun",
33
+ f"cohort_name={cfg.task}",
34
+ "data=sharded",
35
+ "data.standard=meds",
36
+ f"data.root={cfg.dataset_dir}/data",
37
+ f"data.shard=$(expand_shards {cfg.dataset_dir}/data)",
38
+ f"config_path={task_config_path}",
39
+ f"predicates_path={dataset_predicates_path}",
40
+ f"output_filepath={cfg.output_dir}" + r"/\$\{data._prefix\}.parquet",
41
+ f"log_dir={cfg.output_dir}/.logs",
42
+ ]
43
+ )
44
+
45
+ logger.info(f"Running ACES: {cmd}")
46
+ aces_command_out = subprocess.run(cmd, shell=True, capture_output=True)
47
+
48
+ command_errored = aces_command_out.returncode != 0
49
+ if command_errored:
50
+ raise RuntimeError(
51
+ f"Extract {cfg.task} for {cfg.dataset} command {cmd} failed with exit code "
52
+ f"{aces_command_out.returncode}:\n"
53
+ f"STDERR:\n{aces_command_out.stderr.decode()}\n"
54
+ f"STDOUT:\n{aces_command_out.stdout.decode()}"
55
+ )
@@ -0,0 +1,7 @@
1
+ # Abnormal Lab
2
+
3
+ This folder contains tasks for predicting abnormal lab results. Such tasks can be useful for:
4
+
5
+ 1. Identifying patients who are at risk of developing a disease by using lab results as digital biomarkers.
6
+ 2. Eliminating the need to perform costly or invasive tests by using predicted lab results based on less
7
+ expensive or risky tests as a proxy.
@@ -0,0 +1,64 @@
1
+ metadata:
2
+ test_datasets:
3
+ - MIMIC-IV
4
+ description: >-
5
+ This task predicts whether the patient will have elevated _creatinine_ values within the next 24
6
+ hours, given the first 24 hours of their admission to the _hospital_. To be included, 1) patients
7
+ must have at least one measurement for _creatinine_ within the next 24 hours after their
8
+ admission to the hospital, 2) patients must not have shown elevated _creatinine_ values
9
+ previously, and 3) their length of stay in the hospital must be at least 48 hours.
10
+
11
+ predicates:
12
+ hospital_admission: ???
13
+ hospital_discharge: ???
14
+ birth: ???
15
+ death: ???
16
+ discharge_or_death:
17
+ expr: or(death, hospital_discharge)
18
+
19
+ # Plain predicates
20
+ creatinine:
21
+ code: ???
22
+ abnormally_high_creatinine:
23
+ code: ???
24
+ value_min: 1.3 # mg/dL
25
+ value_min_inclusive: False
26
+ value_max: null
27
+
28
+ trigger: hospital_admission
29
+
30
+ windows:
31
+ input:
32
+ start: null
33
+ end: trigger + 24h
34
+ start_inclusive: True
35
+ end_inclusive: True
36
+ index_timestamp: end
37
+ # do not allow to have shown elevated creatinine values previously
38
+ has:
39
+ abnormally_high_creatinine: (None, 0)
40
+ # do not allow hospital discharge to happen within the input + target window
41
+ no_discharge:
42
+ start: trigger
43
+ end: start + 48h
44
+ start_inclusive: False
45
+ end_inclusive: True
46
+ has:
47
+ hospital_admission: (None, 0)
48
+ discharge_or_death: (None, 0)
49
+ # do not allow to include children (age <= 18) patients
50
+ no_children:
51
+ start: end - 6570d # 18 years = 365 * 18 days
52
+ end: trigger
53
+ start_inclusive: True
54
+ end_inclusive: True
55
+ has:
56
+ birth: (None, 0)
57
+ target:
58
+ start: input.end
59
+ end: start + 24h
60
+ start_inclusive: False
61
+ end_inclusive: True
62
+ has:
63
+ creatinine: (1, None)
64
+ label: abnormally_high_creatinine
@@ -0,0 +1,64 @@
1
+ metadata:
2
+ test_datasets:
3
+ - MIMIC-IV
4
+ description: >-
5
+ This task predicts whether the patient will have low _sodium_ values (hyponatremia) within the
6
+ next 24 hours, given the first 24 hours of their admission to the _hospital_. To be included,
7
+ 1) patients must have at least one measurement for _sodium_ within the next 24 hours after their
8
+ admission to the hospital, 2) patients must not have shown low _sodium_ values previously, and
9
+ 3) their length of stay in the hospital must be at least 48 hours.
10
+
11
+ predicates:
12
+ hospital_admission: ???
13
+ hospital_discharge: ???
14
+ birth: ???
15
+ death: ???
16
+ discharge_or_death:
17
+ expr: or(death, hospital_discharge)
18
+
19
+ # Plain predicates
20
+ sodium:
21
+ code: ???
22
+ abnormally_low_sodium:
23
+ code: ???
24
+ value_min: null
25
+ value_max: 135 # mEq/L
26
+ value_max_inclusive: False
27
+
28
+ trigger: hospital_admission
29
+
30
+ windows:
31
+ input:
32
+ start: null
33
+ end: trigger + 24h
34
+ start_inclusive: True
35
+ end_inclusive: True
36
+ index_timestamp: end
37
+ # do not allow to have shown low sodium values previously
38
+ has:
39
+ abnormally_low_sodium: (None, 0)
40
+ # do not allow hospital discharge to happen within the input + target window
41
+ no_discharge:
42
+ start: trigger
43
+ end: start + 48h
44
+ start_inclusive: False
45
+ end_inclusive: True
46
+ has:
47
+ hospital_admission: (None, 0)
48
+ discharge_or_death: (None, 0)
49
+ # do not allow to include children (age <= 18) patients
50
+ no_children:
51
+ start: end - 6570d # 18 years = 365 * 18 days
52
+ end: trigger
53
+ start_inclusive: True
54
+ end_inclusive: True
55
+ has:
56
+ birth: (None, 0)
57
+ target:
58
+ start: input.end
59
+ end: start + 24h
60
+ start_inclusive: False
61
+ end_inclusive: True
62
+ has:
63
+ sodium: (1, None)
64
+ label: abnormally_low_sodium
@@ -0,0 +1,64 @@
1
+ metadata:
2
+ test_datasets:
3
+ - MIMIC-IV
4
+ description: >-
5
+ This task predicts whether the patient will have low _bicarbonate_ values (metabolic acidosis)
6
+ within the next 24 hours, given the first 24 hours of their admission to the hospital. To be
7
+ included, 1) patients must have at least one measurement for _bicarbonate_ within the next 24
8
+ hours after their admission to the hospital, 2) patients must not have shown low _bicarbonate_
9
+ values previously, and 3) their length of stay in the hospital must be at least 48 hours.
10
+
11
+ predicates:
12
+ icu_admission: ???
13
+ icu_discharge: ???
14
+ hospital_discharge: ???
15
+ death: ???
16
+ discharge_or_death:
17
+ expr: or(icu_discharge, death, hospital_discharge)
18
+
19
+ # Plain predicates
20
+ bicarbonate:
21
+ code: ???
22
+ abnormally_low_bicarbonate:
23
+ code: ???
24
+ value_min: null
25
+ value_max: 22 # mEq/L
26
+ value_max_inclusive: False
27
+
28
+ trigger: hospital_admission
29
+
30
+ windows:
31
+ input:
32
+ start: null
33
+ end: trigger + 24h
34
+ start_inclusive: True
35
+ end_inclusive: True
36
+ index_timestamp: end
37
+ # do not allow to have shown low bicarbonate values previously
38
+ has:
39
+ abnormally_low_bicarbonate: (None, 0)
40
+ # do not allow hospital discharge to happen within the input + target window
41
+ no_discharge:
42
+ start: trigger
43
+ end: start + 48h
44
+ start_inclusive: False
45
+ end_inclusive: True
46
+ has:
47
+ hospital_admission: (None, 0)
48
+ discharge_or_death: (None, 0)
49
+ # do not allow to include children (age <= 18) patients
50
+ no_children:
51
+ start: end - 6570d # 18 years = 365 * 18 days
52
+ end: trigger
53
+ start_inclusive: True
54
+ end_inclusive: True
55
+ has:
56
+ birth: (None, 0)
57
+ target:
58
+ start: input.end
59
+ end: start + 24h
60
+ start_inclusive: False
61
+ end_inclusive: True
62
+ has:
63
+ bicarbonate: (1, None)
64
+ label: abnormally_low_bicarbonate