Skip to content

Commit

Permalink
clean up tasks;
Browse files Browse the repository at this point in the history
need to further explain usage
  • Loading branch information
zzachw committed Nov 10, 2022
1 parent 30e8886 commit d8f0c0b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 101 deletions.
55 changes: 13 additions & 42 deletions pyhealth/tasks/drug_recommendation.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
import sys

from pyhealth.data import Patient, Visit

# TODO: remove this hack later
sys.path.append("/home/chaoqiy2/github/PyHealth-OMOP")


def drug_recommendation_mimic3_fn(patient: Patient):
"""
"""Processes a single patient for the drug recommendation task.
Drug recommendation aims at recommending a set of drugs given the patient health
history (e.g., conditions and procedures).
Process a single patient for the drug recommendation task.
Args:
patient: a Patient object
Returns:
samples: a list of samples, each sample is a dict with patient_id, visit_id,
and other task-specific attributes as key
Note that a patient may be converted to multiple samples, e.g., a patient with
three visits may be converted to three samples ([visit 1], [visit 1, visit 2],
[visit 1, visit 2, visit 3]). Patients can also be excluded from the task
dataset by returning an empty list.
**Example:**
Examples:
>>> from pyhealth.datasets import MIMIC3Dataset
>>> mimic3_ds = MIMIC3Dataset(
... root="/srv/local/data/physionet.org/files/mimiciii/1.4",
Expand Down Expand Up @@ -80,25 +69,19 @@ def drug_recommendation_mimic3_fn(patient: Patient):


def drug_recommendation_mimic4_fn(patient: Patient):
"""
"""Processes a single patient for the drug recommendation task.
Drug recommendation aims at recommending a set of drugs given the patient health
history (e.g., conditions and procedures).
Process a single patient for the drug recommendation task.
Args:
patient: a Patient object
Returns:
samples: a list of samples, each sample is a dict with patient_id, visit_id,
and other task-specific attributes as key
Note that a patient may be converted to multiple samples, e.g., a patient with
three visits may be converted to three samples ([visit 1], [visit 1, visit 2],
[visit 1, visit 2, visit 3]). Patients can also be excluded from the task
dataset by returning an empty list.
**Example:**
Examples:
>>> from pyhealth.datasets import MIMIC4Dataset
>>> mimic4_ds = MIMIC4Dataset(
... root="/srv/local/data/physionet.org/files/mimiciv/2.0/hosp",
Expand Down Expand Up @@ -153,25 +136,19 @@ def drug_recommendation_mimic4_fn(patient: Patient):


def drug_recommendation_eicu_fn(patient: Patient):
"""
"""Processes a single patient for the drug recommendation task.
Drug recommendation aims at recommending a set of drugs given the patient health
history (e.g., conditions and procedures).
Process a single patient for the drug recommendation task.
Args:
patient: a Patient object
Returns:
samples: a list of samples, each sample is a dict with patient_id, visit_id,
and other task-specific attributes as key
Note that a patient may be converted to multiple samples, e.g., a patient with
three visits may be converted to three samples ([visit 1], [visit 1, visit 2],
[visit 1, visit 2, visit 3]). Patients can also be excluded from the task
dataset by returning an empty list.
**Example:**
Examples:
>>> from pyhealth.datasets import eICUDataset
>>> eicu_ds = eICUDataset(
... root="/srv/local/data/physionet.org/files/eicu-crd/2.0",
Expand Down Expand Up @@ -225,25 +202,19 @@ def drug_recommendation_eicu_fn(patient: Patient):


def drug_recommendation_omop_fn(patient: Patient):
"""
"""Processes a single patient for the drug recommendation task.
Drug recommendation aims at recommending a set of drugs given the patient health
history (e.g., conditions and procedures).
Process a single patient for the drug recommendation task.
Args:
patient: a Patient object
Returns:
samples: a list of samples, each sample is a dict with patient_id, visit_id,
and other task-specific attributes as key
Note that a patient may be converted to multiple samples, e.g., a patient with
three visits may be converted to three samples ([visit 1], [visit 1, visit 2],
[visit 1, visit 2, visit 3]). Patients can also be excluded from the task
dataset by returning an empty list.
**Examples:**
Examples:
>>> from pyhealth.datasets import OMOPDataset
>>> omop_ds = OMOPDataset(
... root="https://storage.googleapis.com/pyhealth/synpuf1k_omop_cdm_5.2.2",
Expand All @@ -256,7 +227,7 @@ def drug_recommendation_omop_fn(patient: Patient):
[{'visit_id': '130744', 'patient_id': '103', 'conditions': [['42', '109', '98', '663', '58', '51'], ['98', '663', '58', '51']], 'procedures': [['1'], ['2', '3']], 'label': [['2', '3', '4'], ['0', '1', '4', '5']]}]
"""

samples = []
for i in range(len(patient)):
visit: Visit = patient[i]
Expand Down
30 changes: 13 additions & 17 deletions pyhealth/tasks/length_of_stay_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def categorize_los(days: int):
"""Categorize length of stay into 10 categories.
"""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,
Expand All @@ -29,13 +29,12 @@ def categorize_los(days: int):


def length_of_stay_prediction_mimic3_fn(patient: Patient):
"""
"""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).
Process a single patient for the length-of-stay prediction task.
Args:
patient: a Patient object.
Expand All @@ -45,7 +44,7 @@ def length_of_stay_prediction_mimic3_fn(patient: Patient):
Note that we define the task as a multi-class classification task.
**Example:**
Examples:
>>> from pyhealth.datasets import MIMIC3Dataset
>>> mimic3_ds = MIMIC3Dataset(
... root="/srv/local/data/physionet.org/files/mimiciii/1.4",
Expand Down Expand Up @@ -88,13 +87,12 @@ def length_of_stay_prediction_mimic3_fn(patient: Patient):


def length_of_stay_prediction_mimic4_fn(patient: Patient):
"""
"""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).
Process a single patient for the length-of-stay prediction task.
Args:
patient: a Patient object.
Expand All @@ -104,7 +102,7 @@ def length_of_stay_prediction_mimic4_fn(patient: Patient):
Note that we define the task as a multi-class classification task.
**Example:**
Examples:
>>> from pyhealth.datasets import MIMIC4Dataset
>>> mimic4_ds = MIMIC4Dataset(
... root="/srv/local/data/physionet.org/files/mimiciv/2.0/hosp",
Expand Down Expand Up @@ -148,13 +146,12 @@ def length_of_stay_prediction_mimic4_fn(patient: Patient):


def length_of_stay_prediction_eicu_fn(patient: Patient):
"""
"""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).
Process a single patient for the length-of-stay prediction task.
Args:
patient: a Patient object.
Expand All @@ -164,7 +161,7 @@ def length_of_stay_prediction_eicu_fn(patient: Patient):
Note that we define the task as a multi-class classification task.
**Example:**
Examples:
>>> from pyhealth.datasets import eICUDataset
>>> eicu_ds = eICUDataset(
... root="/srv/local/data/physionet.org/files/eicu-crd/2.0",
Expand Down Expand Up @@ -209,13 +206,12 @@ def length_of_stay_prediction_eicu_fn(patient: Patient):


def length_of_stay_prediction_omop_fn(patient: Patient):
"""
"""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).
Process a single patient for the length-of-stay prediction task.
Args:
patient: a Patient object.
Expand All @@ -225,7 +221,7 @@ def length_of_stay_prediction_omop_fn(patient: Patient):
Note that we define the task as a multi-class classification task.
**Examples:**
Examples:
>>> from pyhealth.datasets import OMOPDataset
>>> omop_ds = OMOPDataset(
... root="https://storage.googleapis.com/pyhealth/synpuf1k_omop_cdm_5.2.2",
Expand Down
33 changes: 12 additions & 21 deletions pyhealth/tasks/mortality_prediction.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import sys

# TODO: remove this hack later
sys.path.append("/home/chaoqiy2/github/PyHealth-OMOP")
from pyhealth.data import Patient, Visit


def mortality_prediction_mimic3_fn(patient: Patient):
"""
"""Processes a single patient for the mortality prediction task.
Mortality prediction aims at predicting whether the patient will decease in the
next hospital visit based on the clinical information from current visit
(e.g., conditions and procedures).
Process a single patient for the mortality prediction task.
Args:
patient: a Patient object
Expand All @@ -22,7 +17,7 @@ def mortality_prediction_mimic3_fn(patient: Patient):
Note that we define the task as a binary classification task.
**Example:**
Examples:
>>> from pyhealth.datasets import MIMIC3Dataset
>>> mimic3_ds = MIMIC3Dataset(
... root="/srv/local/data/physionet.org/files/mimiciii/1.4",
Expand Down Expand Up @@ -69,13 +64,12 @@ def mortality_prediction_mimic3_fn(patient: Patient):


def mortality_prediction_mimic4_fn(patient: Patient):
"""
"""Processes a single patient for the mortality prediction task.
Mortality prediction aims at predicting whether the patient will decease in the
next hospital visit based on the clinical information from current visit
(e.g., conditions and procedures).
Process a single patient for the mortality prediction task.
Args:
patient: a Patient object
Expand All @@ -85,7 +79,7 @@ def mortality_prediction_mimic4_fn(patient: Patient):
Note that we define the task as a binary classification task.
**Example:**
Examples:
>>> from pyhealth.datasets import MIMIC4Dataset
>>> mimic4_ds = MIMIC4Dataset(
... root="/srv/local/data/physionet.org/files/mimiciv/2.0/hosp",
Expand Down Expand Up @@ -132,13 +126,12 @@ def mortality_prediction_mimic4_fn(patient: Patient):


def mortality_prediction_eicu_fn(patient: Patient):
"""
"""Processes a single patient for the mortality prediction task.
Mortality prediction aims at predicting whether the patient will decease in the
next hospital visit based on the clinical information from current visit
(e.g., conditions and procedures).
Process a single patient for the mortality prediction task.
Args:
patient: a Patient object
Expand All @@ -148,7 +141,7 @@ def mortality_prediction_eicu_fn(patient: Patient):
Note that we define the task as a binary classification task.
**Example:**
Examples:
>>> from pyhealth.datasets import eICUDataset
>>> eicu_ds = eICUDataset(
... root="/srv/local/data/physionet.org/files/eicu-crd/2.0",
Expand Down Expand Up @@ -195,13 +188,12 @@ def mortality_prediction_eicu_fn(patient: Patient):


def mortality_prediction_omop_fn(patient: Patient):
"""
"""Processes a single patient for the mortality prediction task.
Mortality prediction aims at predicting whether the patient will decease in the
next hospital visit based on the clinical information from current visit
(e.g., conditions and procedures).
Process a single patient for the mortality prediction task.
Args:
patient: a Patient object
Expand All @@ -211,7 +203,7 @@ def mortality_prediction_omop_fn(patient: Patient):
Note that we define the task as a binary classification task.
**Examples:**
Examples:
>>> from pyhealth.datasets import OMOPDataset
>>> omop_ds = OMOPDataset(
... root="https://storage.googleapis.com/pyhealth/synpuf1k_omop_cdm_5.2.2",
Expand Down Expand Up @@ -304,4 +296,3 @@ def mortality_prediction_omop_fn(patient: Patient):
dataset.set_task(task_fn=mortality_prediction_omop_fn)
dataset.stat()
print(dataset.available_keys)

Loading

0 comments on commit d8f0c0b

Please sign in to comment.