diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2dde47226..b4a866332 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,4 +22,4 @@ jobs: run: | echo "Generating tables on BigQuery" cd mimic-iv/concepts - bash make_concepts.sh > /dev/null \ No newline at end of file + bash make_concepts.sh \ No newline at end of file diff --git a/mimic-iv/concepts/make_concepts.sh b/mimic-iv/concepts/make_concepts.sh index 29d25d771..4f65188df 100644 --- a/mimic-iv/concepts/make_concepts.sh +++ b/mimic-iv/concepts/make_concepts.sh @@ -31,7 +31,7 @@ do # not skipping - so generate the table on bigquery echo "Generating ${TARGET_DATASET}.${tbl}" - bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.${tbl} < ${d}/${fn} + bq query --quiet --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.${tbl} < ${d}/${fn} fi done done @@ -43,5 +43,5 @@ do table=`echo $table_path | rev | cut -d/ -f1 | rev` echo "Generating ${TARGET_DATASET}.${table}" - bq query --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.${table} < ${table_path}.sql + bq query --quiet --use_legacy_sql=False --replace --destination_table=${TARGET_DATASET}.${table} < ${table_path}.sql done \ No newline at end of file diff --git a/mimic-iv/concepts/medication/norepinephrine.sql b/mimic-iv/concepts/medication/norepinephrine.sql index ae889cf9a..900b8f1a5 100644 --- a/mimic-iv/concepts/medication/norepinephrine.sql +++ b/mimic-iv/concepts/medication/norepinephrine.sql @@ -7,7 +7,6 @@ select -- below row is written for completion, but doesn't impact rows WHEN rateuom = 'mg/kg/min' THEN rate * 1000.0 ELSE rate END AS vaso_rate - , rate as vaso_rate , amount as vaso_amount , starttime , endtime diff --git a/mimic-iv/concepts/medication/norepinephrine_equivalent_dose.sql b/mimic-iv/concepts/medication/norepinephrine_equivalent_dose.sql index c06c983d6..7d28ef433 100644 --- a/mimic-iv/concepts/medication/norepinephrine_equivalent_dose.sql +++ b/mimic-iv/concepts/medication/norepinephrine_equivalent_dose.sql @@ -14,7 +14,6 @@ SELECT stay_id, starttime, endtime , 4) AS norepinephrine_equivalent_dose -- angotensin_ii*10 -- angitensin ii rarely used, currently not incorporated -- (it could be included due to norepinephrine sparing effects) - AS norepinephrine_equivalent_dose FROM mimic_derived.vasoactive_agent WHERE norepinephrine IS NOT NULL OR epinephrine IS NOT NULL diff --git a/mimic-iv/concepts/postgres/measurement/cardiac_marker.sql b/mimic-iv/concepts/postgres/measurement/cardiac_marker.sql index 1df8086ab..4cb239526 100644 --- a/mimic-iv/concepts/postgres/measurement/cardiac_marker.sql +++ b/mimic-iv/concepts/postgres/measurement/cardiac_marker.sql @@ -7,16 +7,18 @@ SELECT , MAX(charttime) AS charttime , le.specimen_id -- convert from itemid into a meaningful column - , MAX(CASE WHEN itemid = 51002 THEN value ELSE NULL END) AS troponin_i , MAX(CASE WHEN itemid = 51003 THEN value ELSE NULL END) AS troponin_t , MAX(CASE WHEN itemid = 50911 THEN valuenum ELSE NULL END) AS ck_mb + , MAX(CASE WHEN itemid = 50963 THEN valuenum ELSE NULL END) AS ntprobnp FROM mimic_hosp.labevents le WHERE le.itemid IN ( -- 51002, -- Troponin I (troponin-I is not measured in MIMIC-IV) -- 52598, -- Troponin I, point of care, rare/poor quality 51003, -- Troponin T - 50911 -- Creatinine Kinase, MB isoenzyme + 50911, -- Creatinine Kinase, MB isoenzyme + 50963 -- N-terminal (NT)-pro hormone BNP (NT-proBNP) ) +AND valuenum IS NOT NULL GROUP BY le.specimen_id ; diff --git a/mimic-iv/concepts/postgres/medication/dobutamine.sql b/mimic-iv/concepts/postgres/medication/dobutamine.sql index 8ac6df3f6..061618d77 100644 --- a/mimic-iv/concepts/postgres/medication/dobutamine.sql +++ b/mimic-iv/concepts/postgres/medication/dobutamine.sql @@ -3,6 +3,7 @@ DROP TABLE IF EXISTS dobutamine; CREATE TABLE dobutamine AS -- This query extracts dose+durations of dopamine administration select stay_id, linkorderid +-- all rows in mcg/kg/min , rate as vaso_rate , amount as vaso_amount , starttime diff --git a/mimic-iv/concepts/postgres/medication/dopamine.sql b/mimic-iv/concepts/postgres/medication/dopamine.sql index 91d5bda42..0ba5d232c 100644 --- a/mimic-iv/concepts/postgres/medication/dopamine.sql +++ b/mimic-iv/concepts/postgres/medication/dopamine.sql @@ -3,6 +3,7 @@ DROP TABLE IF EXISTS dopamine; CREATE TABLE dopamine AS -- This query extracts dose+durations of dopamine administration select stay_id, linkorderid +-- all rows in mcg/kg/min , rate as vaso_rate , amount as vaso_amount , starttime diff --git a/mimic-iv/concepts/postgres/medication/epinephrine.sql b/mimic-iv/concepts/postgres/medication/epinephrine.sql index 1a77c6d04..919a94066 100644 --- a/mimic-iv/concepts/postgres/medication/epinephrine.sql +++ b/mimic-iv/concepts/postgres/medication/epinephrine.sql @@ -3,6 +3,7 @@ DROP TABLE IF EXISTS epinephrine; CREATE TABLE epinephrine AS -- This query extracts dose+durations of epinephrine administration select stay_id, linkorderid +-- all rows in mcg/kg/min , rate as vaso_rate , amount as vaso_amount , starttime diff --git a/mimic-iv/concepts/postgres/medication/norepinephrine.sql b/mimic-iv/concepts/postgres/medication/norepinephrine.sql index 2b75bc937..b4bf1fb4a 100644 --- a/mimic-iv/concepts/postgres/medication/norepinephrine.sql +++ b/mimic-iv/concepts/postgres/medication/norepinephrine.sql @@ -3,7 +3,12 @@ DROP TABLE IF EXISTS norepinephrine; CREATE TABLE norepinephrine AS -- This query extracts dose+durations of norepinephrine administration select stay_id, linkorderid - , rate as vaso_rate + -- two rows in mg/kg/min... rest in mcg/kg/min + -- the rows in mg/kg/min are documented incorrectly + , CASE WHEN rateuom = 'mg/kg/min' AND patientweight = 1 THEN rate + -- below row is written for completion, but doesn't impact rows + WHEN rateuom = 'mg/kg/min' THEN rate * 1000.0 + ELSE rate END AS vaso_rate , amount as vaso_amount , starttime , endtime diff --git a/mimic-iv/concepts/postgres/medication/phenylephrine.sql b/mimic-iv/concepts/postgres/medication/phenylephrine.sql index ced71b976..536f9f2bb 100644 --- a/mimic-iv/concepts/postgres/medication/phenylephrine.sql +++ b/mimic-iv/concepts/postgres/medication/phenylephrine.sql @@ -3,7 +3,9 @@ DROP TABLE IF EXISTS phenylephrine; CREATE TABLE phenylephrine AS -- This query extracts dose+durations of phenylephrine administration select stay_id, linkorderid - , rate as vaso_rate + -- one row in mcg/min, the rest in mcg/kg/min + , CASE WHEN rateuom = 'mcg/min' THEN rate / patientweight + ELSE rate END as vaso_rate , amount as vaso_amount , starttime , endtime diff --git a/mimic-iv/concepts/postgres/medication/vasopressin.sql b/mimic-iv/concepts/postgres/medication/vasopressin.sql index d8b0b1f24..65d9ab44e 100644 --- a/mimic-iv/concepts/postgres/medication/vasopressin.sql +++ b/mimic-iv/concepts/postgres/medication/vasopressin.sql @@ -3,7 +3,10 @@ DROP TABLE IF EXISTS vasopressin; CREATE TABLE vasopressin AS -- This query extracts dose+durations of vasopressin administration select stay_id, linkorderid - , rate as vaso_rate + -- three rows in units/min, rest in units/hour + -- the three rows in units/min look reasonable and fit with the patient course + , CASE WHEN rateuom = 'units/min' THEN rate * 60.0 + ELSE rate END AS vaso_rate , amount as vaso_amount , starttime , endtime diff --git a/mimic-iv/concepts/postgres/postgres-make-concepts.sql b/mimic-iv/concepts/postgres/postgres-make-concepts.sql index 6abda8981..f8d547c54 100644 --- a/mimic-iv/concepts/postgres/postgres-make-concepts.sql +++ b/mimic-iv/concepts/postgres/postgres-make-concepts.sql @@ -44,10 +44,13 @@ \i medication/dobutamine.sql \i medication/dopamine.sql \i medication/epinephrine.sql +\i medication/milrinone.sql \i medication/neuroblock.sql \i medication/norepinephrine.sql \i medication/phenylephrine.sql \i medication/vasopressin.sql +\i medication/vasoactive_agent.sql +\i medication/norepinephrine_equivalent_dose.sql -- treatment \i treatment/crrt.sql diff --git a/mimic-iv/concepts/postgres/score/apsiii.sql b/mimic-iv/concepts/postgres/score/apsiii.sql index fd8cb7de9..a2da07136 100644 --- a/mimic-iv/concepts/postgres/score/apsiii.sql +++ b/mimic-iv/concepts/postgres/score/apsiii.sql @@ -52,7 +52,7 @@ with pa as -- and fio2 < 50, or if no fio2, assume room air AND coalesce(fio2, fio2_chartevents, 21) < 50 AND bg.po2 IS NOT NULL - AND bg.specimen_pred = 'ART.' + AND bg.specimen = 'ART.' ) , aa as ( @@ -74,7 +74,7 @@ with pa as WHERE vd.stay_id is not null -- patient is ventilated AND coalesce(fio2, fio2_chartevents) >= 50 AND bg.aado2 IS NOT NULL - AND bg.specimen_pred = 'ART.' + AND bg.specimen = 'ART.' ) -- because ph/pco2 rules are an interaction *within* a blood gas, we calculate them here -- the worse score is then taken for the final calculation @@ -132,7 +132,7 @@ with pa as ON bg.hadm_id = ie.hadm_id AND bg.charttime >= ie.intime AND bg.charttime < ie.outtime where ph is not null and pco2 is not null - AND bg.specimen_pred = 'ART.' + AND bg.specimen = 'ART.' ) , acidbase_max as ( diff --git a/mimic-iv/concepts/postgres/score/sapsii.sql b/mimic-iv/concepts/postgres/score/sapsii.sql index 9ed30b883..24b562bc2 100644 --- a/mimic-iv/concepts/postgres/score/sapsii.sql +++ b/mimic-iv/concepts/postgres/score/sapsii.sql @@ -117,7 +117,7 @@ select hadm_id from co LEFT JOIN mimic_derived.bg bg ON co.subject_id = bg.subject_id - AND bg.specimen_pred = 'ART.' + AND bg.specimen = 'ART.' AND bg.charttime > co.starttime AND bg.charttime <= co.endtime left join mimic_derived.ventilation vd diff --git a/mimic-iv/concepts/postgres/score/sofa.sql b/mimic-iv/concepts/postgres/score/sofa.sql index b8e74ccb2..ae0a6dfa7 100644 --- a/mimic-iv/concepts/postgres/score/sofa.sql +++ b/mimic-iv/concepts/postgres/score/sofa.sql @@ -53,7 +53,7 @@ WITH co AS and bg.charttime >= vd.starttime and bg.charttime <= vd.endtime and vd.ventilation_status = 'InvasiveVent' - WHERE specimen_pred = 'ART.' + WHERE specimen = 'ART.' ) , vs AS ( diff --git a/mimic-iv/concepts/postgres/treatment/ventilation.sql b/mimic-iv/concepts/postgres/treatment/ventilation.sql index 4a2709372..4cee437ce 100644 --- a/mimic-iv/concepts/postgres/treatment/ventilation.sql +++ b/mimic-iv/concepts/postgres/treatment/ventilation.sql @@ -203,6 +203,7 @@ WITH tm AS , vd2 as ( SELECT vd1.stay_id, vd1.charttime + , vd1.charttime_lead, vd1.ventilation_status , ventduration, new_ventilation_event -- create a cumulative sum of the instances of new ventilation -- this results in a monotonically increasing integer assigned diff --git a/mimic-iv/concepts/score/apsiii.sql b/mimic-iv/concepts/score/apsiii.sql index 6dc3c7f9f..cdf03f593 100644 --- a/mimic-iv/concepts/score/apsiii.sql +++ b/mimic-iv/concepts/score/apsiii.sql @@ -50,7 +50,7 @@ with pa as -- and fio2 < 50, or if no fio2, assume room air AND coalesce(fio2, fio2_chartevents, 21) < 50 AND bg.po2 IS NOT NULL - AND bg.specimen_pred = 'ART.' + AND bg.specimen = 'ART.' ) , aa as ( @@ -72,7 +72,7 @@ with pa as WHERE vd.stay_id is not null -- patient is ventilated AND coalesce(fio2, fio2_chartevents) >= 50 AND bg.aado2 IS NOT NULL - AND bg.specimen_pred = 'ART.' + AND bg.specimen = 'ART.' ) -- because ph/pco2 rules are an interaction *within* a blood gas, we calculate them here -- the worse score is then taken for the final calculation @@ -130,7 +130,7 @@ with pa as ON bg.hadm_id = ie.hadm_id AND bg.charttime >= ie.intime AND bg.charttime < ie.outtime where ph is not null and pco2 is not null - AND bg.specimen_pred = 'ART.' + AND bg.specimen = 'ART.' ) , acidbase_max as ( diff --git a/mimic-iv/concepts/score/sapsii.sql b/mimic-iv/concepts/score/sapsii.sql index b33c8ac4a..5e2170c6a 100644 --- a/mimic-iv/concepts/score/sapsii.sql +++ b/mimic-iv/concepts/score/sapsii.sql @@ -115,7 +115,7 @@ select hadm_id from co LEFT JOIN `physionet-data.mimic_derived.bg` bg ON co.subject_id = bg.subject_id - AND bg.specimen_pred = 'ART.' + AND bg.specimen = 'ART.' AND bg.charttime > co.starttime AND bg.charttime <= co.endtime left join `physionet-data.mimic_derived.ventilation` vd diff --git a/mimic-iv/concepts/score/sofa.sql b/mimic-iv/concepts/score/sofa.sql index 960d02ee5..047cff361 100644 --- a/mimic-iv/concepts/score/sofa.sql +++ b/mimic-iv/concepts/score/sofa.sql @@ -51,7 +51,7 @@ WITH co AS and bg.charttime >= vd.starttime and bg.charttime <= vd.endtime and vd.ventilation_status = 'InvasiveVent' - WHERE specimen_pred = 'ART.' + WHERE specimen = 'ART.' ) , vs AS ( diff --git a/mimic-iv/concepts/treatment/ventilation.sql b/mimic-iv/concepts/treatment/ventilation.sql index 0edb57dcc..7133e1c4b 100644 --- a/mimic-iv/concepts/treatment/ventilation.sql +++ b/mimic-iv/concepts/treatment/ventilation.sql @@ -201,6 +201,7 @@ WITH tm AS , vd2 as ( SELECT vd1.stay_id, vd1.charttime + , vd1.charttime_lead, vd1.ventilation_status , ventduration, new_ventilation_event -- create a cumulative sum of the instances of new ventilation -- this results in a monotonically increasing integer assigned