pyhealth.tasks.length_of_stay_prediction#

pyhealth.tasks.length_of_stay_prediction.categorize_los(days)[source]#

Categorizes length of stay into 10 categories.

One for ICU stays shorter than a day, seven day-long categories for each day of the first week, one for stays of over one week but less than two, and one for stays of over two weeks.

Parameters:

days (int) – int, length of stay in days

Returns:

int, category of length of stay

Return type:

category

pyhealth.tasks.length_of_stay_prediction.length_of_stay_prediction_mimic3_fn(patient)[source]#

Processes a single patient for the length-of-stay prediction task.

Length of stay prediction aims at predicting the length of stay (in days) of the current hospital visit based on the clinical information from the visit (e.g., conditions and procedures).

Parameters:

patient (Patient) – a Patient object.

Returns:

a list of samples, each sample is a dict with patient_id, visit_id,

and other task-specific attributes as key.

Return type:

samples

Note that we define the task as a multi-class classification task.

Examples

>>> from pyhealth.datasets import MIMIC3Dataset
>>> mimic3_base = MIMIC3Dataset(
...    root="/srv/local/data/physionet.org/files/mimiciii/1.4",
...    tables=["DIAGNOSES_ICD", "PROCEDURES_ICD", "PRESCRIPTIONS"],
...    code_mapping={"ICD9CM": "CCSCM"},
... )
>>> from pyhealth.tasks import length_of_stay_prediction_mimic3_fn
>>> mimic3_sample = mimic3_base.set_task(length_of_stay_prediction_mimic3_fn)
>>> mimic3_sample.samples[0]
[{'visit_id': '130744', 'patient_id': '103', 'conditions': [['42', '109', '19', '122', '98', '663', '58', '51']], 'procedures': [['1']], 'label': 4}]
pyhealth.tasks.length_of_stay_prediction.length_of_stay_prediction_mimic4_fn(patient)[source]#

Processes a single patient for the length-of-stay prediction task.

Length of stay prediction aims at predicting the length of stay (in days) of the current hospital visit based on the clinical information from the visit (e.g., conditions and procedures).

Parameters:

patient (Patient) – a Patient object.

Returns:

a list of samples, each sample is a dict with patient_id, visit_id,

and other task-specific attributes as key.

Return type:

samples

Note that we define the task as a multi-class classification task.

Examples

>>> from pyhealth.datasets import MIMIC4Dataset
>>> mimic4_base = MIMIC4Dataset(
...     root="/srv/local/data/physionet.org/files/mimiciv/2.0/hosp",
...     tables=["diagnoses_icd", "procedures_icd"],
...     code_mapping={"ICD10PROC": "CCSPROC"},
... )
>>> from pyhealth.tasks import length_of_stay_prediction_mimic4_fn
>>> mimic4_sample = mimic4_base.set_task(length_of_stay_prediction_mimic4_fn)
>>> mimic4_sample.samples[0]
[{'visit_id': '130744', 'patient_id': '103', 'conditions': [['42', '109', '19', '122', '98', '663', '58', '51']], 'procedures': [['1']], 'label': 2}]
pyhealth.tasks.length_of_stay_prediction.length_of_stay_prediction_eicu_fn(patient)[source]#

Processes a single patient for the length-of-stay prediction task.

Length of stay prediction aims at predicting the length of stay (in days) of the current hospital visit based on the clinical information from the visit (e.g., conditions and procedures).

Parameters:

patient (Patient) – a Patient object.

Returns:

a list of samples, each sample is a dict with patient_id, visit_id,

and other task-specific attributes as key.

Return type:

samples

Note that we define the task as a multi-class classification task.

Examples

>>> from pyhealth.datasets import eICUDataset
>>> eicu_base = eICUDataset(
...     root="/srv/local/data/physionet.org/files/eicu-crd/2.0",
...     tables=["diagnosis", "medication"],
...     code_mapping={},
...     dev=True
... )
>>> from pyhealth.tasks import length_of_stay_prediction_eicu_fn
>>> eicu_sample = eicu_base.set_task(length_of_stay_prediction_eicu_fn)
>>> eicu_sample.samples[0]
[{'visit_id': '130744', 'patient_id': '103', 'conditions': [['42', '109', '98', '663', '58', '51']], 'procedures': [['1']], 'label': 5}]
pyhealth.tasks.length_of_stay_prediction.length_of_stay_prediction_omop_fn(patient)[source]#

Processes a single patient for the length-of-stay prediction task.

Length of stay prediction aims at predicting the length of stay (in days) of the current hospital visit based on the clinical information from the visit (e.g., conditions and procedures).

Parameters:

patient (Patient) – a Patient object.

Returns:

a list of samples, each sample is a dict with patient_id, visit_id,

and other task-specific attributes as key.

Return type:

samples

Note that we define the task as a multi-class classification task.

Examples

>>> from pyhealth.datasets import OMOPDataset
>>> omop_base = OMOPDataset(
...     root="https://storage.googleapis.com/pyhealth/synpuf1k_omop_cdm_5.2.2",
...     tables=["condition_occurrence", "procedure_occurrence"],
...     code_mapping={},
... )
>>> from pyhealth.tasks import length_of_stay_prediction_omop_fn
>>> omop_sample = omop_base.set_task(length_of_stay_prediction_eicu_fn)
>>> omop_sample.samples[0]
[{'visit_id': '130744', 'patient_id': '103', 'conditions': [['42', '109', '98', '663', '58', '51']], 'procedures': [['1']], 'label': 7}]