Skip to content

Commit

Permalink
Merge pull request #1210 from MIT-LCP/fix_make
Browse files Browse the repository at this point in the history
syntax fixes
  • Loading branch information
alistairewj authored Dec 15, 2021
2 parents 3e951e1 + e294a8e commit ad293e2
Show file tree
Hide file tree
Showing 20 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
run: |
echo "Generating tables on BigQuery"
cd mimic-iv/concepts
bash make_concepts.sh > /dev/null
bash make_concepts.sh
4 changes: 2 additions & 2 deletions mimic-iv/concepts/make_concepts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
1 change: 0 additions & 1 deletion mimic-iv/concepts/medication/norepinephrine.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions mimic-iv/concepts/postgres/measurement/cardiac_marker.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
;
1 change: 1 addition & 0 deletions mimic-iv/concepts/postgres/medication/dobutamine.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mimic-iv/concepts/postgres/medication/dopamine.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mimic-iv/concepts/postgres/medication/epinephrine.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion mimic-iv/concepts/postgres/medication/norepinephrine.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion mimic-iv/concepts/postgres/medication/phenylephrine.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion mimic-iv/concepts/postgres/medication/vasopressin.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions mimic-iv/concepts/postgres/postgres-make-concepts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions mimic-iv/concepts/postgres/score/apsiii.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand All @@ -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
Expand Down Expand Up @@ -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
(
Expand Down
2 changes: 1 addition & 1 deletion mimic-iv/concepts/postgres/score/sapsii.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mimic-iv/concepts/postgres/score/sofa.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down
1 change: 1 addition & 0 deletions mimic-iv/concepts/postgres/treatment/ventilation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions mimic-iv/concepts/score/apsiii.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand All @@ -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
Expand Down Expand Up @@ -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
(
Expand Down
2 changes: 1 addition & 1 deletion mimic-iv/concepts/score/sapsii.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mimic-iv/concepts/score/sofa.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down
1 change: 1 addition & 0 deletions mimic-iv/concepts/treatment/ventilation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad293e2

Please # to comment.