- Access to MIMIC-IV. Learn more here.
- Project ID of a Google Project, make sure to have the necessary IAM permissions to run queries on Big Query.
Important Note: The google account enabled to access the MIMIC-IV must the be same as the one associated with the Google Project.
- run
pip install "git+https://github.com/jhn-nt/dpsdc.git"
- to test the installation, run
python3 -m unittest dpsdc.tests
- dry run, completed in a couple of minutes:
python3 -m dpsdc -p <your project-id> --dry
- to run the whole experiment (ca 2 hours), use:
python3 -m dpsdc -p <your project-id>
The above code will run the experiment for a cohort of ventilated patients using weight as a disparity axis and frequency of turnings as a proxy. To test it on a different group run:
python3 -m dpsdc -p <your project-id> -i /path/to/info.json -dp /path/to/proxy.sql -c /path/to/criteria.sql
where:
info.json
is used to charachterize the proxy variable, specifically, it requires 4 keys:proxy_name
: The name of the proxy (Turnings).disparities_axis_name
: the disparity axis under which to measure the proxy (Weight).disparities_axis_uom
: The unit of measurements of the disparity axis (Kg).protocol__hours
: Exact, or when not possible, average frequency of proxy that patients should receive by protocol (for turnings, patients are expected to be turned every 2 hours). See the example below:
{
"proxy_name":"Turnings",
"disparities_axis_name":"Weight",
"disparities_axis_uom":"Kg(s)",
"protocol__hours":2
}
criteria.sql
is a BigQuery query that when run, returns a list of patients ids which respect inclusion and exclusion criteria. In the case of frequency of turnings:
SELECT DISTINCT
FIRST_VALUE(ventilation.stay_id) OVER(PARTITION BY ventilation.stay_id, ventilation.ventilation_status ORDER BY ventilation.starttime) AS stay_id,
FROM `physionet-data.mimiciv_derived.ventilation` ventilation
LEFT JOIN `physionet-data.mimiciv_derived.first_day_weight` weight ON weight.stay_id=ventilation.stay_id
WHERE ventilation.ventilation_status='InvasiveVent'
AND weight.weight IS NOT NULL
AND weight.weight>10
AND weight.weight<250
For the turning example, we want only the first ventialtion instance of all patients whose weight is nor missing nor an outlier, defined as below 10Kgs or above 250Kgs.
3. proxy.sql
is a BigQuery query that when run, returns daily proxy values we wish to invetigate together with its patient id. The patient id is necessary to crossreference the table with criteria defined above.
Returning to the turnings example:
WITH intubation AS (
SELECT DISTINCT
stay_id,
FIRST_VALUE(starttime) OVER(PARTITION BY stay_id ORDER BY starttime) AS intubation_time,
FIRST_VALUE(endtime) OVER(PARTITION BY stay_id ORDER BY starttime) AS extubation_time,
FIRST_VALUE(ventilation_status) OVER(PARTITION BY stay_id ORDER BY starttime) AS ventilation_status
FROM `physionet-data.mimiciv_derived.ventilation`
WHERE ventilation_status IN ('InvasiveVent')
)
SELECT
stay_id,
day,
24/COUNT(day) AS average_item_interval,
COUNT(day) AS item_volume,
COUNT(DISTINCT caregiver_id) AS n_caregivers
FROM (
SELECT
chartevents.stay_id,
chartevents.caregiver_id,
EXTRACT(DATE FROM intubation.intubation_time) AS intubation_date,
EXTRACT(DATE FROM intubation.extubation_time) AS extubation_date,
EXTRACT(DATE FROM chartevents.charttime) AS item_date,
DENSE_RANK() OVER(PARTITION BY chartevents.stay_id ORDER BY EXTRACT(DATE FROM chartevents.charttime)) AS day
FROM `physionet-data.mimiciv_icu.chartevents` chartevents
INNER JOIN intubation ON chartevents.stay_id = intubation.stay_id
WHERE itemid=224082 AND chartevents.charttime BETWEEN intubation.intubation_time AND intubation.extubation_time
AND EXTRACT(DATE FROM intubation.intubation_time)!=EXTRACT(DATE FROM chartevents.charttime)
AND EXTRACT(DATE FROM intubation.extubation_time)!=EXTRACT(DATE FROM chartevents.charttime)
)
GROUP BY stay_id, day
The above query returns a dataset in with the following form:
stay_id | day | average_item_interval |
---|---|---|
pid1 | 01.02 | 2.35 |
pid1 | 02.02 | 1.98 |
pid123 | 12.09 | 2.12 |
pid123 | 13.09 | 2.25 |
pid123 | 14.09 | 1.93 |
pid123 | 15.09 | 3.21 |
You can further append auxialiary features in the query to be adjusted upon.