diff --git a/mimic-iv/concepts/postgres/comorbidity/charlson.sql b/mimic-iv/concepts/postgres/comorbidity/charlson.sql index fc5af1118..693581f3d 100644 --- a/mimic-iv/concepts/postgres/comorbidity/charlson.sql +++ b/mimic-iv/concepts/postgres/comorbidity/charlson.sql @@ -21,7 +21,7 @@ WITH diag AS hadm_id , CASE WHEN icd_version = 9 THEN icd_code ELSE NULL END AS icd9_code , CASE WHEN icd_version = 10 THEN icd_code ELSE NULL END AS icd10_code - FROM mimic_hosp.diagnoses_icd diag + FROM mimiciv_hosp.diagnoses_icd diag ) , com AS ( @@ -255,7 +255,7 @@ WITH diag AS SUBSTR(icd10_code, 1, 3) IN ('B20','B21','B22','B24') THEN 1 ELSE 0 END) AS aids - FROM mimic_core.admissions ad + FROM mimiciv_hosp.admissions ad LEFT JOIN diag ON ad.hadm_id = diag.hadm_id GROUP BY ad.hadm_id @@ -270,7 +270,7 @@ WITH diag AS WHEN age <= 60 THEN 2 WHEN age <= 70 THEN 3 ELSE 4 END AS age_score - FROM mimic_derived.age + FROM mimiciv_derived.age ) SELECT ad.subject_id @@ -305,7 +305,7 @@ SELECT + 2*paraplegia + 2*renal_disease + 6*aids AS charlson_comorbidity_index -FROM mimic_core.admissions ad +FROM mimiciv_hosp.admissions ad LEFT JOIN com ON ad.hadm_id = com.hadm_id LEFT JOIN ag diff --git a/mimic-iv/concepts/postgres/demographics/age.sql b/mimic-iv/concepts/postgres/demographics/age.sql index 0f6943172..1c8393ff4 100644 --- a/mimic-iv/concepts/postgres/demographics/age.sql +++ b/mimic-iv/concepts/postgres/demographics/age.sql @@ -23,8 +23,8 @@ SELECT , ad.admittime , pa.anchor_age , pa.anchor_year - , DATETIME_DIFF(ad.admittime, DATETIME(pa.anchor_year, 1, 1, 0, 0,0),'YEAR') + pa.anchor_age AS age -FROM mimic_core.admissions ad -INNER JOIN mimic_core.patients pa + , DATETIME_DIFF(ad.admittime, DATETIME(pa.anchor_year, 1, 1, 0, 0, 0), YEAR) + pa.anchor_age AS age +FROM mimiciv_hosp.admissions ad +INNER JOIN mimiciv_hosp.patients pa ON ad.subject_id = pa.subject_id ; \ No newline at end of file diff --git a/mimic-iv/concepts/postgres/demographics/icustay_detail.sql b/mimic-iv/concepts/postgres/demographics/icustay_detail.sql index 8d4657a6f..adc91f4a1 100644 --- a/mimic-iv/concepts/postgres/demographics/icustay_detail.sql +++ b/mimic-iv/concepts/postgres/demographics/icustay_detail.sql @@ -7,9 +7,9 @@ SELECT ie.subject_id, ie.hadm_id, ie.stay_id -- hospital level factors , adm.admittime, adm.dischtime -, DATETIME_DIFF(adm.dischtime,adm.admittime,'DAY') as los_hospital -, DATETIME_DIFF(adm.admittime, DATETIME(pat.anchor_year, 1, 1, 0, 0,0),'YEAR') + pat.anchor_age as admission_age -, adm.ethnicity +, DATETIME_DIFF(adm.dischtime, adm.admittime, 'DAY') as los_hospital +, DATETIME_DIFF(adm.admittime, DATETIME(pat.anchor_year, 1, 1, 0, 0, 0), YEAR) + pat.anchor_age as admission_age +, adm.race , adm.hospital_expire_flag , DENSE_RANK() OVER (PARTITION BY adm.subject_id ORDER BY adm.admittime) AS hospstay_seq , CASE @@ -18,7 +18,7 @@ SELECT ie.subject_id, ie.hadm_id, ie.stay_id -- icu level factors , ie.intime as icu_intime, ie.outtime as icu_outtime -, ROUND( CAST( DATETIME_DIFF(ie.outtime,ie.intime,'HOUR')/24.0 as numeric),2) as los_icu +, ROUND( CAST( DATETIME_DIFF(ie.outtime as numeric),ie.intime, 'HOUR')/24.0, 2) as los_icu , DENSE_RANK() OVER (PARTITION BY ie.hadm_id ORDER BY ie.intime) AS icustay_seq -- first ICU stay *for the current hospitalization* @@ -26,8 +26,8 @@ SELECT ie.subject_id, ie.hadm_id, ie.stay_id WHEN DENSE_RANK() OVER (PARTITION BY ie.hadm_id ORDER BY ie.intime) = 1 THEN True ELSE False END AS first_icu_stay -FROM mimic_icu.icustays ie -INNER JOIN mimic_core.admissions adm +FROM mimiciv_icu.icustays ie +INNER JOIN mimiciv_hosp.admissions adm ON ie.hadm_id = adm.hadm_id -INNER JOIN mimic_core.patients pat +INNER JOIN mimiciv_hosp.patients pat ON ie.subject_id = pat.subject_id diff --git a/mimic-iv/concepts/postgres/demographics/icustay_hourly.sql b/mimic-iv/concepts/postgres/demographics/icustay_hourly.sql index 4679e6f93..67e2f5c02 100644 --- a/mimic-iv/concepts/postgres/demographics/icustay_hourly.sql +++ b/mimic-iv/concepts/postgres/demographics/icustay_hourly.sql @@ -27,9 +27,9 @@ select -- create integers for each charttime in hours from admission -- so 0 is admission time, 1 is one hour after admission, etc, up to ICU disch -- we allow 24 hours before ICU admission (to grab labs before admit) - , ARRAY(SELECT * FROM generate_series(-24, CEIL(DATETIME_DIFF(it.outtime_hr,it.intime_hr,'HOUR')))) as hrs + , ARRAY(SELECT * FROM generate_series(-24, CEIL(DATETIME_DIFF(it.outtime_hr, it.intime_hr, 'HOUR')))) as hrs - from mimic_derived.icustay_times it + from mimiciv_derived.icustay_times it ) SELECT stay_id , CAST(hr AS bigint) as hr diff --git a/mimic-iv/concepts/postgres/demographics/icustay_times.sql b/mimic-iv/concepts/postgres/demographics/icustay_times.sql index 59da3f692..6339f4e61 100644 --- a/mimic-iv/concepts/postgres/demographics/icustay_times.sql +++ b/mimic-iv/concepts/postgres/demographics/icustay_times.sql @@ -8,7 +8,7 @@ WITH t1 AS select ce.stay_id , min(charttime) as intime_hr , max(charttime) as outtime_hr - FROM mimic_icu.chartevents ce + FROM mimiciv_icu.chartevents ce -- only look at heart rate where ce.itemid = 220045 group by ce.stay_id @@ -18,6 +18,6 @@ select ie.subject_id, ie.hadm_id, ie.stay_id , t1.intime_hr , t1.outtime_hr -FROM mimic_icu.icustays ie +FROM mimiciv_icu.icustays ie left join t1 on ie.stay_id = t1.stay_id; \ No newline at end of file diff --git a/mimic-iv/concepts/postgres/demographics/weight_durations.sql b/mimic-iv/concepts/postgres/demographics/weight_durations.sql index 76ff5fd68..f3375b84a 100644 --- a/mimic-iv/concepts/postgres/demographics/weight_durations.sql +++ b/mimic-iv/concepts/postgres/demographics/weight_durations.sql @@ -11,7 +11,7 @@ WITH wt_stg as else 'daily' end as weight_type -- TODO: eliminate obvious outliers if there is a reasonable weight , c.valuenum as weight - FROM mimic_icu.chartevents c + FROM mimiciv_icu.chartevents c WHERE c.valuenum IS NOT NULL AND c.itemid in ( @@ -44,7 +44,7 @@ WITH wt_stg as else wt_stg1.charttime end as starttime , wt_stg1.weight from wt_stg1 - INNER JOIN mimic_icu.icustays ie + INNER JOIN mimiciv_icu.icustays ie on ie.stay_id = wt_stg1.stay_id ) , wt_stg3 as @@ -89,7 +89,7 @@ WITH wt_stg as , wt.starttime as endtime , wt.weight , wt.weight_type - from mimic_icu.icustays ie + from mimiciv_icu.icustays ie inner join -- the below subquery returns one row for each unique stay_id -- the row contains: the first starttime and the corresponding weight diff --git a/mimic-iv/concepts/postgres/firstday/first_day_bg.sql b/mimic-iv/concepts/postgres/firstday/first_day_bg.sql index 5026425a1..47838ba89 100644 --- a/mimic-iv/concepts/postgres/firstday/first_day_bg.sql +++ b/mimic-iv/concepts/postgres/firstday/first_day_bg.sql @@ -25,8 +25,8 @@ select , MIN(glucose) AS glucose_min, MAX(glucose) AS glucose_max , MIN(potassium) AS potassium_min, MAX(potassium) AS potassium_max , MIN(sodium) AS sodium_min, MAX(sodium) AS sodium_max -FROM mimic_icu.icustays ie -LEFT JOIN mimic_derived.bg bg +FROM mimiciv_icu.icustays ie +LEFT JOIN mimiciv_derived.bg bg ON ie.subject_id = bg.subject_id AND bg.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND bg.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) diff --git a/mimic-iv/concepts/postgres/firstday/first_day_bg_art.sql b/mimic-iv/concepts/postgres/firstday/first_day_bg_art.sql index de4a0aa27..bfbb98de9 100644 --- a/mimic-iv/concepts/postgres/firstday/first_day_bg_art.sql +++ b/mimic-iv/concepts/postgres/firstday/first_day_bg_art.sql @@ -25,8 +25,8 @@ select , MIN(glucose) AS glucose_min, MAX(glucose) AS glucose_max , MIN(potassium) AS potassium_min, MAX(potassium) AS potassium_max , MIN(sodium) AS sodium_min, MAX(sodium) AS sodium_max -FROM mimic_icu.icustays ie -LEFT JOIN mimic_derived.bg bg +FROM mimiciv_icu.icustays ie +LEFT JOIN mimiciv_derived.bg bg ON ie.subject_id = bg.subject_id AND bg.specimen = 'ART.' AND bg.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) diff --git a/mimic-iv/concepts/postgres/firstday/first_day_gcs.sql b/mimic-iv/concepts/postgres/firstday/first_day_gcs.sql index 503424c46..32bc84c3f 100644 --- a/mimic-iv/concepts/postgres/firstday/first_day_gcs.sql +++ b/mimic-iv/concepts/postgres/firstday/first_day_gcs.sql @@ -23,7 +23,7 @@ WITH gcs_final AS PARTITION BY gcs.stay_id ORDER BY gcs.GCS ) as gcs_seq - FROM mimic_derived.gcs gcs + FROM mimiciv_derived.gcs gcs ) SELECT ie.subject_id @@ -35,7 +35,7 @@ SELECT , gcs_verbal , gcs_eyes , gcs_unable -FROM mimic_icu.icustays ie +FROM mimiciv_icu.icustays ie LEFT JOIN gcs_final gs ON ie.stay_id = gs.stay_id AND gs.gcs_seq = 1 diff --git a/mimic-iv/concepts/postgres/firstday/first_day_height.sql b/mimic-iv/concepts/postgres/firstday/first_day_height.sql index 3af458f5c..3b1ce9e71 100644 --- a/mimic-iv/concepts/postgres/firstday/first_day_height.sql +++ b/mimic-iv/concepts/postgres/firstday/first_day_height.sql @@ -11,8 +11,8 @@ WITH ce AS SELECT c.stay_id , AVG(valuenum) as Height_chart - FROM mimic_icu.chartevents c - INNER JOIN mimic_icu.icustays ie ON + FROM mimiciv_icu.chartevents c + INNER JOIN mimiciv_icu.icustays ie ON c.stay_id = ie.stay_id AND c.charttime BETWEEN DATETIME_SUB(ie.intime, INTERVAL '1' DAY) AND DATETIME_ADD(ie.intime, INTERVAL '1' DAY) WHERE c.valuenum IS NOT NULL @@ -24,8 +24,8 @@ SELECT ie.subject_id , ie.stay_id , ROUND( CAST( AVG(height) as numeric),2) AS height -FROM mimic_icu.icustays ie -LEFT JOIN mimic_derived.height ht +FROM mimiciv_icu.icustays ie +LEFT JOIN mimiciv_derived.height ht ON ie.stay_id = ht.stay_id AND ht.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND ht.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) diff --git a/mimic-iv/concepts/postgres/firstday/first_day_lab.sql b/mimic-iv/concepts/postgres/firstday/first_day_lab.sql index 508ec923e..24dbfb291 100644 --- a/mimic-iv/concepts/postgres/firstday/first_day_lab.sql +++ b/mimic-iv/concepts/postgres/firstday/first_day_lab.sql @@ -12,8 +12,8 @@ WITH cbc AS , MAX(platelet) as platelets_max , MIN(wbc) as wbc_min , MAX(wbc) as wbc_max - FROM mimic_icu.icustays ie - LEFT JOIN mimic_derived.complete_blood_count le + FROM mimiciv_icu.icustays ie + LEFT JOIN mimiciv_derived.complete_blood_count le ON le.subject_id = ie.subject_id AND le.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND le.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) @@ -35,8 +35,8 @@ WITH cbc AS , MIN(glucose) AS glucose_min, MAX(glucose) AS glucose_max , MIN(sodium) AS sodium_min, MAX(sodium) AS sodium_max , MIN(potassium) AS potassium_min, MAX(potassium) AS potassium_max - FROM mimic_icu.icustays ie - LEFT JOIN mimic_derived.chemistry le + FROM mimiciv_icu.icustays ie + LEFT JOIN mimiciv_derived.chemistry le ON le.subject_id = ie.subject_id AND le.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND le.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) @@ -56,8 +56,8 @@ WITH cbc AS , MIN(immature_granulocytes) AS imm_granulocytes_min, MAX(immature_granulocytes) AS imm_granulocytes_max , MIN(metamyelocytes) AS metas_min, MAX(metamyelocytes) AS metas_max , MIN(nrbc) AS nrbc_min, MAX(nrbc) AS nrbc_max - FROM mimic_icu.icustays ie - LEFT JOIN mimic_derived.blood_differential le + FROM mimiciv_icu.icustays ie + LEFT JOIN mimiciv_derived.blood_differential le ON le.subject_id = ie.subject_id AND le.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND le.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) @@ -73,8 +73,8 @@ WITH cbc AS , MIN(inr) AS inr_min, MAX(inr) AS inr_max , MIN(pt) AS pt_min, MAX(pt) AS pt_max , MIN(ptt) AS ptt_min, MAX(ptt) AS ptt_max - FROM mimic_icu.icustays ie - LEFT JOIN mimic_derived.coagulation le + FROM mimiciv_icu.icustays ie + LEFT JOIN mimiciv_derived.coagulation le ON le.subject_id = ie.subject_id AND le.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND le.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) @@ -96,8 +96,8 @@ WITH cbc AS , MIN(ck_mb) AS ck_mb_min, MAX(ck_mb) AS ck_mb_max , MIN(ggt) AS ggt_min, MAX(ggt) AS ggt_max , MIN(ld_ldh) AS ld_ldh_min, MAX(ld_ldh) AS ld_ldh_max - FROM mimic_icu.icustays ie - LEFT JOIN mimic_derived.enzyme le + FROM mimiciv_icu.icustays ie + LEFT JOIN mimiciv_derived.enzyme le ON le.subject_id = ie.subject_id AND le.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND le.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) @@ -154,7 +154,7 @@ ie.subject_id , ck_mb_min, ck_mb_max , ggt_min, ggt_max , ld_ldh_min, ld_ldh_max -FROM mimic_icu.icustays ie +FROM mimiciv_icu.icustays ie LEFT JOIN cbc ON ie.stay_id = cbc.stay_id LEFT JOIN chem diff --git a/mimic-iv/concepts/postgres/firstday/first_day_rrt.sql b/mimic-iv/concepts/postgres/firstday/first_day_rrt.sql index 93c5693cc..da87b178a 100644 --- a/mimic-iv/concepts/postgres/firstday/first_day_rrt.sql +++ b/mimic-iv/concepts/postgres/firstday/first_day_rrt.sql @@ -8,8 +8,8 @@ select , MAX(dialysis_present) AS dialysis_present , MAX(dialysis_active) AS dialysis_active , STRING_AGG(DISTINCT dialysis_type, ', ') AS dialysis_type -FROM mimic_icu.icustays ie -LEFT JOIN mimic_derived.rrt rrt +FROM mimiciv_icu.icustays ie +LEFT JOIN mimiciv_derived.rrt rrt ON ie.stay_id = rrt.stay_id AND rrt.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND rrt.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) diff --git a/mimic-iv/concepts/postgres/firstday/first_day_sofa.sql b/mimic-iv/concepts/postgres/firstday/first_day_sofa.sql index e57db8d5d..9af4bb38d 100644 --- a/mimic-iv/concepts/postgres/firstday/first_day_sofa.sql +++ b/mimic-iv/concepts/postgres/firstday/first_day_sofa.sql @@ -31,29 +31,29 @@ DROP TABLE IF EXISTS first_day_sofa; CREATE TABLE first_day_sofa AS with vaso_stg as ( select ie.stay_id, 'norepinephrine' AS treatment, vaso_rate as rate - FROM mimic_icu.icustays ie - INNER JOIN mimic_derived.norepinephrine mv + FROM mimiciv_icu.icustays ie + INNER JOIN mimiciv_derived.norepinephrine mv ON ie.stay_id = mv.stay_id AND mv.starttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND mv.starttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) UNION ALL select ie.stay_id, 'epinephrine' AS treatment, vaso_rate as rate - FROM mimic_icu.icustays ie - INNER JOIN mimic_derived.epinephrine mv + FROM mimiciv_icu.icustays ie + INNER JOIN mimiciv_derived.epinephrine mv ON ie.stay_id = mv.stay_id AND mv.starttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND mv.starttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) UNION ALL select ie.stay_id, 'dobutamine' AS treatment, vaso_rate as rate - FROM mimic_icu.icustays ie - INNER JOIN mimic_derived.dobutamine mv + FROM mimiciv_icu.icustays ie + INNER JOIN mimiciv_derived.dobutamine mv ON ie.stay_id = mv.stay_id AND mv.starttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND mv.starttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) UNION ALL select ie.stay_id, 'dopamine' AS treatment, vaso_rate as rate - FROM mimic_icu.icustays ie - INNER JOIN mimic_derived.dopamine mv + FROM mimiciv_icu.icustays ie + INNER JOIN mimiciv_derived.dopamine mv ON ie.stay_id = mv.stay_id AND mv.starttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND mv.starttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) @@ -66,7 +66,7 @@ with vaso_stg as , max(CASE WHEN treatment = 'epinephrine' THEN rate ELSE NULL END) as rate_epinephrine , max(CASE WHEN treatment = 'dopamine' THEN rate ELSE NULL END) as rate_dopamine , max(CASE WHEN treatment = 'dobutamine' THEN rate ELSE NULL END) as rate_dobutamine - from mimic_icu.icustays ie + from mimiciv_icu.icustays ie LEFT JOIN vaso_stg v ON ie.stay_id = v.stay_id GROUP BY ie.stay_id @@ -77,12 +77,12 @@ with vaso_stg as select ie.stay_id, bg.charttime , bg.pao2fio2ratio , case when vd.stay_id is not null then 1 else 0 end as IsVent - from mimic_icu.icustays ie - LEFT JOIN mimic_derived.bg bg + from mimiciv_icu.icustays ie + LEFT JOIN mimiciv_derived.bg bg ON ie.subject_id = bg.subject_id AND bg.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND bg.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) - LEFT JOIN mimic_derived.ventilation vd + LEFT JOIN mimiciv_derived.ventilation vd ON ie.stay_id = vd.stay_id AND bg.charttime >= vd.starttime AND bg.charttime <= vd.endtime @@ -119,18 +119,18 @@ select ie.stay_id , uo.UrineOutput , gcs.gcs_min -from mimic_icu.icustays ie +from mimiciv_icu.icustays ie left join vaso_mv mv on ie.stay_id = mv.stay_id left join pafi2 pf on ie.stay_id = pf.stay_id -left join mimic_derived.first_day_vitalsign v +left join mimiciv_derived.first_day_vitalsign v on ie.stay_id = v.stay_id -left join mimic_derived.first_day_lab l +left join mimiciv_derived.first_day_lab l on ie.stay_id = l.stay_id -left join mimic_derived.first_day_urine_output uo +left join mimiciv_derived.first_day_urine_output uo on ie.stay_id = uo.stay_id -left join mimic_derived.first_day_gcs gcs +left join mimiciv_derived.first_day_gcs gcs on ie.stay_id = gcs.stay_id ) , scorecalc as @@ -219,7 +219,7 @@ select ie.subject_id, ie.hadm_id, ie.stay_id , cardiovascular , cns , renal -from mimic_icu.icustays ie +from mimiciv_icu.icustays ie left join scorecalc s on ie.stay_id = s.stay_id ; \ No newline at end of file diff --git a/mimic-iv/concepts/postgres/firstday/first_day_urine_output.sql b/mimic-iv/concepts/postgres/firstday/first_day_urine_output.sql index ca44fa903..13ddb3357 100644 --- a/mimic-iv/concepts/postgres/firstday/first_day_urine_output.sql +++ b/mimic-iv/concepts/postgres/firstday/first_day_urine_output.sql @@ -6,9 +6,9 @@ SELECT ie.subject_id , ie.stay_id , SUM(urineoutput) AS urineoutput -FROM mimic_icu.icustays ie +FROM mimiciv_icu.icustays ie -- Join to the outputevents table to get urine output -LEFT JOIN mimic_derived.urine_output uo +LEFT JOIN mimiciv_derived.urine_output uo ON ie.stay_id = uo.stay_id -- ensure the data occurs during the first day AND uo.charttime >= ie.intime diff --git a/mimic-iv/concepts/postgres/firstday/first_day_vitalsign.sql b/mimic-iv/concepts/postgres/firstday/first_day_vitalsign.sql index 5aa9d30f9..edbb6d525 100644 --- a/mimic-iv/concepts/postgres/firstday/first_day_vitalsign.sql +++ b/mimic-iv/concepts/postgres/firstday/first_day_vitalsign.sql @@ -29,8 +29,8 @@ ie.subject_id , MIN(glucose) AS glucose_min , MAX(glucose) AS glucose_max , AVG(glucose) AS glucose_mean -FROM mimic_icu.icustays ie -LEFT JOIN mimic_derived.vitalsign ce +FROM mimiciv_icu.icustays ie +LEFT JOIN mimiciv_derived.vitalsign ce ON ie.stay_id = ce.stay_id AND ce.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR) AND ce.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) diff --git a/mimic-iv/concepts/postgres/firstday/first_day_weight.sql b/mimic-iv/concepts/postgres/firstday/first_day_weight.sql index 2c4aab9e4..1e9f8dda5 100644 --- a/mimic-iv/concepts/postgres/firstday/first_day_weight.sql +++ b/mimic-iv/concepts/postgres/firstday/first_day_weight.sql @@ -11,9 +11,9 @@ SELECT , AVG(ce.weight) AS weight , MIN(ce.weight) AS weight_min , MAX(ce.weight) AS weight_max -FROM mimic_icu.icustays ie +FROM mimiciv_icu.icustays ie -- admission weight -LEFT JOIN mimic_derived.weight_durations ce +LEFT JOIN mimiciv_derived.weight_durations ce ON ie.stay_id = ce.stay_id -- we filter to weights documented during or before the 1st day AND ce.starttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY) diff --git a/mimic-iv/concepts/postgres/measurement/bg.sql b/mimic-iv/concepts/postgres/measurement/bg.sql index 678c433d0..452102511 100644 --- a/mimic-iv/concepts/postgres/measurement/bg.sql +++ b/mimic-iv/concepts/postgres/measurement/bg.sql @@ -46,7 +46,7 @@ select , MAX(CASE WHEN itemid = 50824 THEN valuenum ELSE NULL END) AS sodium , MAX(CASE WHEN itemid = 50825 THEN valuenum ELSE NULL END) AS temperature , MAX(CASE WHEN itemid = 50807 THEN value ELSE NULL END) AS comments -FROM mimic_hosp.labevents le +FROM mimiciv_hosp.labevents le where le.ITEMID in -- blood gases ( @@ -86,7 +86,7 @@ GROUP BY le.specimen_id select subject_id, charttime -- avg here is just used to group SpO2 by charttime , AVG(valuenum) as SpO2 - FROM mimic_icu.chartevents + FROM mimiciv_icu.chartevents where ITEMID = 220277 -- O2 saturation pulseoxymetry and valuenum > 0 and valuenum <= 100 group by subject_id, charttime @@ -106,7 +106,7 @@ GROUP BY le.specimen_id then valuenum else null end ) as fio2_chartevents - FROM mimic_icu.chartevents + FROM mimiciv_icu.chartevents where ITEMID = 223835 -- Inspired O2 Fraction (FiO2) and valuenum > 0 and valuenum <= 100 group by subject_id, charttime diff --git a/mimic-iv/concepts/postgres/measurement/blood_differential.sql b/mimic-iv/concepts/postgres/measurement/blood_differential.sql index 25b2057ae..7c7e7cc2b 100644 --- a/mimic-iv/concepts/postgres/measurement/blood_differential.sql +++ b/mimic-iv/concepts/postgres/measurement/blood_differential.sql @@ -49,7 +49,7 @@ SELECT AND SUM(CASE WHEN itemid IN (51146, 51200, 51244, 51245, 51254, 51256) THEN valuenum ELSE NULL END) > 0 THEN 1 ELSE 0 END AS impute_abs -FROM mimic_hosp.labevents le +FROM mimiciv_hosp.labevents le WHERE le.itemid IN ( 51146, -- basophils @@ -98,27 +98,27 @@ subject_id, hadm_id, charttime, specimen_id -- impute absolute count if percentage & WBC is available , ROUND( CAST( CASE WHEN basophils_abs IS NULL AND basophils IS NOT NULL AND impute_abs = 1 - THEN basophils * wbc + THEN basophils * wbc / 100 ELSE basophils_abs END as numeric),4) AS basophils_abs , ROUND( CAST( CASE WHEN eosinophils_abs IS NULL AND eosinophils IS NOT NULL AND impute_abs = 1 - THEN eosinophils * wbc + THEN eosinophils * wbc / 100 ELSE eosinophils_abs END as numeric),4) AS eosinophils_abs , ROUND( CAST( CASE WHEN lymphocytes_abs IS NULL AND lymphocytes IS NOT NULL AND impute_abs = 1 - THEN lymphocytes * wbc + THEN lymphocytes * wbc / 100 ELSE lymphocytes_abs END as numeric),4) AS lymphocytes_abs , ROUND( CAST( CASE WHEN monocytes_abs IS NULL AND monocytes IS NOT NULL AND impute_abs = 1 - THEN monocytes * wbc + THEN monocytes * wbc / 100 ELSE monocytes_abs END as numeric),4) AS monocytes_abs , ROUND( CAST( CASE WHEN neutrophils_abs IS NULL AND neutrophils IS NOT NULL AND impute_abs = 1 - THEN neutrophils * wbc + THEN neutrophils * wbc / 100 ELSE neutrophils_abs END as numeric),4) AS neutrophils_abs diff --git a/mimic-iv/concepts/postgres/measurement/cardiac_marker.sql b/mimic-iv/concepts/postgres/measurement/cardiac_marker.sql index 4cb239526..026e6f094 100644 --- a/mimic-iv/concepts/postgres/measurement/cardiac_marker.sql +++ b/mimic-iv/concepts/postgres/measurement/cardiac_marker.sql @@ -10,7 +10,7 @@ SELECT , 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 +FROM mimiciv_hosp.labevents le WHERE le.itemid IN ( -- 51002, -- Troponin I (troponin-I is not measured in MIMIC-IV) diff --git a/mimic-iv/concepts/postgres/measurement/chemistry.sql b/mimic-iv/concepts/postgres/measurement/chemistry.sql index 24bd57dca..95ad4c105 100644 --- a/mimic-iv/concepts/postgres/measurement/chemistry.sql +++ b/mimic-iv/concepts/postgres/measurement/chemistry.sql @@ -22,7 +22,7 @@ SELECT , MAX(CASE WHEN itemid = 50931 AND valuenum <= 10000 THEN valuenum ELSE NULL END) AS glucose , MAX(CASE WHEN itemid = 50983 AND valuenum <= 200 THEN valuenum ELSE NULL END) AS sodium , MAX(CASE WHEN itemid = 50971 AND valuenum <= 30 THEN valuenum ELSE NULL END) AS potassium -FROM mimic_hosp.labevents le +FROM mimiciv_hosp.labevents le WHERE le.itemid IN ( -- comment is: LABEL | CATEGORY | FLUID | NUMBER OF ROWS IN LABEVENTS diff --git a/mimic-iv/concepts/postgres/measurement/coagulation.sql b/mimic-iv/concepts/postgres/measurement/coagulation.sql index d4044a57e..9f3377e4d 100644 --- a/mimic-iv/concepts/postgres/measurement/coagulation.sql +++ b/mimic-iv/concepts/postgres/measurement/coagulation.sql @@ -12,7 +12,7 @@ SELECT , MAX(CASE WHEN itemid = 51237 THEN valuenum ELSE NULL END) AS inr , MAX(CASE WHEN itemid = 51274 THEN valuenum ELSE NULL END) AS pt , MAX(CASE WHEN itemid = 51275 THEN valuenum ELSE NULL END) AS ptt -FROM mimic_hosp.labevents le +FROM mimiciv_hosp.labevents le WHERE le.itemid IN ( -- 51149, 52750, 52072, 52073 -- Bleeding Time, no data as of MIMIC-IV v0.4 diff --git a/mimic-iv/concepts/postgres/measurement/complete_blood_count.sql b/mimic-iv/concepts/postgres/measurement/complete_blood_count.sql index 896aa7933..80d350a6c 100644 --- a/mimic-iv/concepts/postgres/measurement/complete_blood_count.sql +++ b/mimic-iv/concepts/postgres/measurement/complete_blood_count.sql @@ -17,7 +17,7 @@ SELECT , MAX(CASE WHEN itemid = 51277 THEN valuenum ELSE NULL END) AS rdw , MAX(CASE WHEN itemid = 52159 THEN valuenum ELSE NULL END) AS rdwsd , MAX(CASE WHEN itemid = 51301 THEN valuenum ELSE NULL END) AS wbc -FROM mimic_hosp.labevents le +FROM mimiciv_hosp.labevents le WHERE le.itemid IN ( 51221, -- hematocrit diff --git a/mimic-iv/concepts/postgres/measurement/creatinine_baseline.sql b/mimic-iv/concepts/postgres/measurement/creatinine_baseline.sql index f97246102..40105b7d8 100644 --- a/mimic-iv/concepts/postgres/measurement/creatinine_baseline.sql +++ b/mimic-iv/concepts/postgres/measurement/creatinine_baseline.sql @@ -20,8 +20,8 @@ WITH p as POWER(75.0 / 186.0 / POWER(ag.age, -0.203), -1/1.154) END AS MDRD_est - FROM mimic_derived.age ag - LEFT JOIN mimic_core.patients p + FROM mimiciv_derived.age ag + LEFT JOIN mimiciv_hosp.patients p ON ag.subject_id = p.subject_id WHERE ag.age >= 18 ) @@ -30,13 +30,13 @@ WITH p as SELECT hadm_id , MIN(creatinine) AS scr_min - FROM mimic_derived.chemistry + FROM mimiciv_derived.chemistry GROUP BY hadm_id ) , ckd as ( SELECT hadm_id, MAX(1) AS CKD_flag - FROM mimic_hosp.diagnoses_icd + FROM mimiciv_hosp.diagnoses_icd WHERE ( SUBSTR(icd_code, 1, 3) = '585' diff --git a/mimic-iv/concepts/postgres/measurement/enzyme.sql b/mimic-iv/concepts/postgres/measurement/enzyme.sql index c9a4b4982..164144c1a 100644 --- a/mimic-iv/concepts/postgres/measurement/enzyme.sql +++ b/mimic-iv/concepts/postgres/measurement/enzyme.sql @@ -18,7 +18,7 @@ SELECT , MAX(CASE WHEN itemid = 50911 THEN valuenum ELSE NULL END) AS ck_mb , MAX(CASE WHEN itemid = 50927 THEN valuenum ELSE NULL END) AS ggt , MAX(CASE WHEN itemid = 50954 THEN valuenum ELSE NULL END) AS ld_ldh -FROM mimic_hosp.labevents le +FROM mimiciv_hosp.labevents le WHERE le.itemid IN ( 50861, -- Alanine transaminase (ALT) diff --git a/mimic-iv/concepts/postgres/measurement/gcs.sql b/mimic-iv/concepts/postgres/measurement/gcs.sql index 57855a788..1625d2618 100644 --- a/mimic-iv/concepts/postgres/measurement/gcs.sql +++ b/mimic-iv/concepts/postgres/measurement/gcs.sql @@ -43,7 +43,7 @@ with base as as endotrachflag , ROW_NUMBER () OVER (PARTITION BY ce.stay_id ORDER BY ce.charttime ASC) as rn - from mimic_icu.chartevents ce + from mimiciv_icu.chartevents ce -- Isolate the desired GCS variables where ce.ITEMID in ( @@ -107,26 +107,6 @@ with base as , EndoTrachFlag from gcs gs ) --- priority is: --- (i) complete data, (ii) non-sedated GCS, (iii) lowest GCS, (iv) charttime -, gcs_priority as -( - select - subject_id - , stay_id - , charttime - , gcs - , gcsmotor - , gcsverbal - , gcseyes - , EndoTrachFlag - , ROW_NUMBER() over - ( - PARTITION BY stay_id, charttime - ORDER BY components_measured DESC, endotrachflag, gcs, charttime DESC - ) as rn - from gcs_stg -) select gs.subject_id , gs.stay_id @@ -136,6 +116,5 @@ select , GCSVerbal AS gcs_verbal , GCSEyes AS gcs_eyes , EndoTrachFlag AS gcs_unable -from gcs_priority gs -where rn = 1 +from gcs_stg gs ; diff --git a/mimic-iv/concepts/postgres/measurement/height.sql b/mimic-iv/concepts/postgres/measurement/height.sql index 79a5726b5..b7967284f 100644 --- a/mimic-iv/concepts/postgres/measurement/height.sql +++ b/mimic-iv/concepts/postgres/measurement/height.sql @@ -8,7 +8,7 @@ WITH ht_in AS -- Ensure that all heights are in centimeters , ROUND( CAST( c.valuenum * 2.54 as numeric),2) AS height , c.valuenum as height_orig - FROM mimic_icu.chartevents c + FROM mimiciv_icu.chartevents c WHERE c.valuenum IS NOT NULL -- Height (measured in inches) AND c.itemid = 226707 @@ -19,7 +19,7 @@ WITH ht_in AS c.subject_id, c.stay_id, c.charttime -- Ensure that all heights are in centimeters , ROUND( CAST( c.valuenum as numeric),2) AS height - FROM mimic_icu.chartevents c + FROM mimiciv_icu.chartevents c WHERE c.valuenum IS NOT NULL -- Height cm AND c.itemid = 226730 diff --git a/mimic-iv/concepts/postgres/measurement/icp.sql b/mimic-iv/concepts/postgres/measurement/icp.sql index b39b8154d..1a34559f3 100644 --- a/mimic-iv/concepts/postgres/measurement/icp.sql +++ b/mimic-iv/concepts/postgres/measurement/icp.sql @@ -8,7 +8,7 @@ with ce as , ce.charttime -- TODO: handle high ICPs when monitoring two ICPs , case when valuenum > 0 and valuenum < 100 then valuenum else null end as icp - FROM mimic_icu.chartevents ce + FROM mimiciv_icu.chartevents ce -- exclude rows marked as error where ce.itemid in ( diff --git a/mimic-iv/concepts/postgres/measurement/inflammation.sql b/mimic-iv/concepts/postgres/measurement/inflammation.sql index c8c97d1c8..97776b1e2 100644 --- a/mimic-iv/concepts/postgres/measurement/inflammation.sql +++ b/mimic-iv/concepts/postgres/measurement/inflammation.sql @@ -9,7 +9,7 @@ SELECT , MAX(CASE WHEN itemid = 50889 THEN valuenum ELSE NULL END) AS crp -- , CAST(NULL AS NUMERIC) AS il6 -- , CAST(NULL AS NUMERIC) AS procalcitonin -FROM mimic_hosp.labevents le +FROM mimiciv_hosp.labevents le WHERE le.itemid IN ( 50889 -- crp diff --git a/mimic-iv/concepts/postgres/measurement/oxygen_delivery.sql b/mimic-iv/concepts/postgres/measurement/oxygen_delivery.sql index 2d31c3657..4e1b818cb 100644 --- a/mimic-iv/concepts/postgres/measurement/oxygen_delivery.sql +++ b/mimic-iv/concepts/postgres/measurement/oxygen_delivery.sql @@ -14,7 +14,7 @@ with ce_stg1 as , valuenum , valueuom , storetime - FROM mimic_icu.chartevents ce + FROM mimiciv_icu.chartevents ce WHERE ce.value IS NOT NULL AND ce.itemid IN ( diff --git a/mimic-iv/concepts/postgres/measurement/rhythm.sql b/mimic-iv/concepts/postgres/measurement/rhythm.sql index 9b125e757..95b3b7fb4 100644 --- a/mimic-iv/concepts/postgres/measurement/rhythm.sql +++ b/mimic-iv/concepts/postgres/measurement/rhythm.sql @@ -9,7 +9,7 @@ select , MAX(case when itemid = 224651 THEN value ELSE NULL END) AS ectopy_frequency , MAX(case when itemid = 226479 THEN value ELSE NULL END) AS ectopy_type_secondary , MAX(case when itemid = 226480 THEN value ELSE NULL END) AS ectopy_frequency_secondary -FROM mimic_icu.chartevents ce +FROM mimiciv_icu.chartevents ce where ce.stay_id IS NOT NULL and ce.itemid in ( diff --git a/mimic-iv/concepts/postgres/measurement/urine_output.sql b/mimic-iv/concepts/postgres/measurement/urine_output.sql index f9a3fde77..88c5ed8d7 100644 --- a/mimic-iv/concepts/postgres/measurement/urine_output.sql +++ b/mimic-iv/concepts/postgres/measurement/urine_output.sql @@ -18,7 +18,7 @@ from when oe.itemid = 227488 and oe.value > 0 then -1*oe.value else oe.value end as urineoutput - from mimic_icu.outputevents oe + from mimiciv_icu.outputevents oe where itemid in ( 226559, -- Foley diff --git a/mimic-iv/concepts/postgres/measurement/urine_output_rate.sql b/mimic-iv/concepts/postgres/measurement/urine_output_rate.sql index 496fbb70c..3968c9f22 100644 --- a/mimic-iv/concepts/postgres/measurement/urine_output_rate.sql +++ b/mimic-iv/concepts/postgres/measurement/urine_output_rate.sql @@ -9,8 +9,8 @@ WITH tm AS SELECT ie.stay_id , min(charttime) AS intime_hr , max(charttime) AS outtime_hr - FROM mimic_icu.icustays ie - INNER JOIN mimic_icu.chartevents ce + FROM mimiciv_icu.icustays ie + INNER JOIN mimiciv_icu.chartevents ce ON ie.stay_id = ce.stay_id AND ce.itemid = 220045 AND ce.charttime > DATETIME_SUB(ie.intime, interval '1' MONTH) @@ -23,13 +23,13 @@ WITH tm AS SELECT tm.stay_id , CASE WHEN LAG(charttime) OVER W IS NULL - THEN DATETIME_DIFF(charttime,intime_hr,'MINUTE') - ELSE DATETIME_DIFF(charttime,LAG(charttime) OVER W,'MINUTE') + THEN DATETIME_DIFF(charttime, intime_hr, 'MINUTE') + ELSE DATETIME_DIFF(charttime, LAG(charttime) OVER W, 'MINUTE') END AS tm_since_last_uo , uo.charttime , uo.urineoutput FROM tm - INNER JOIN mimic_derived.urine_output uo + INNER JOIN mimiciv_derived.urine_output uo ON tm.stay_id = uo.stay_id WINDOW W AS (PARTITION BY tm.stay_id ORDER BY charttime) ) @@ -47,16 +47,16 @@ WITH tm AS -- note that we assume data charted at charttime corresponds to 1 hour of UO -- therefore we use '5' and '11' to restrict the period, rather than 6/12 -- this assumption may overestimate UO rate when documentation is done less than hourly - , sum(case when DATETIME_DIFF(io.charttime,iosum.charttime,'HOUR') <= 5 + , sum(case when DATETIME_DIFF(io.charttime, iosum.charttime, 'HOUR') <= 5 then iosum.urineoutput else null end) as urineoutput_6hr - , SUM(CASE WHEN DATETIME_DIFF(io.charttime,iosum.charttime,'HOUR') <= 5 + , SUM(CASE WHEN DATETIME_DIFF(io.charttime, iosum.charttime, 'HOUR') <= 5 THEN iosum.tm_since_last_uo ELSE NULL END)/60.0 AS uo_tm_6hr - , sum(case when DATETIME_DIFF(io.charttime,iosum.charttime,'HOUR') <= 11 + , sum(case when DATETIME_DIFF(io.charttime, iosum.charttime, 'HOUR') <= 11 then iosum.urineoutput else null end) as urineoutput_12hr - , SUM(CASE WHEN DATETIME_DIFF(io.charttime,iosum.charttime,'HOUR') <= 11 + , SUM(CASE WHEN DATETIME_DIFF(io.charttime, iosum.charttime, 'HOUR') <= 11 THEN iosum.tm_since_last_uo ELSE NULL END)/60.0 AS uo_tm_12hr -- 24 hours @@ -87,7 +87,7 @@ select , ROUND( CAST( uo_tm_12hr as numeric),2) AS uo_tm_12hr , ROUND( CAST( uo_tm_24hr as numeric),2) AS uo_tm_24hr from ur_stg ur -LEFT JOIN mimic_derived.weight_durations wd +LEFT JOIN mimiciv_derived.weight_durations wd ON ur.stay_id = wd.stay_id AND ur.charttime > wd.starttime AND ur.charttime <= wd.endtime diff --git a/mimic-iv/concepts/postgres/measurement/ventilator_setting.sql b/mimic-iv/concepts/postgres/measurement/ventilator_setting.sql index c1c183e49..ff9c35305 100644 --- a/mimic-iv/concepts/postgres/measurement/ventilator_setting.sql +++ b/mimic-iv/concepts/postgres/measurement/ventilator_setting.sql @@ -34,7 +34,7 @@ with ce as ELSE valuenum END AS valuenum , valueuom , storetime - FROM mimic_icu.chartevents ce + FROM mimiciv_icu.chartevents ce where ce.value IS NOT NULL AND ce.stay_id IS NOT NULL AND ce.itemid IN diff --git a/mimic-iv/concepts/postgres/measurement/vitalsign.sql b/mimic-iv/concepts/postgres/measurement/vitalsign.sql index c56bad9d6..8a2a31125 100644 --- a/mimic-iv/concepts/postgres/measurement/vitalsign.sql +++ b/mimic-iv/concepts/postgres/measurement/vitalsign.sql @@ -21,7 +21,7 @@ select , MAX(CASE WHEN itemid = 224642 THEN value ELSE NULL END) AS temperature_site , AVG(case when itemid in (220277) and valuenum > 0 and valuenum <= 100 then valuenum else null end) as spo2 , AVG(case when itemid in (225664,220621,226537) and valuenum > 0 then valuenum else null end) as glucose - FROM mimic_icu.chartevents ce + FROM mimiciv_icu.chartevents ce where ce.stay_id IS NOT NULL and ce.itemid in ( diff --git a/mimic-iv/concepts/postgres/medication/antibiotic.sql b/mimic-iv/concepts/postgres/medication/antibiotic.sql index d8e66d2be..b0fac9376 100644 --- a/mimic-iv/concepts/postgres/medication/antibiotic.sql +++ b/mimic-iv/concepts/postgres/medication/antibiotic.sql @@ -162,7 +162,7 @@ with abx as when lower(drug) like '%zyvox%' then 1 else 0 end as antibiotic - from mimic_hosp.prescriptions + from mimiciv_hosp.prescriptions -- excludes vials/syringe/normal saline, etc where drug_type not in ('BASE') -- we exclude routes via the eye, ears, or topically @@ -188,7 +188,7 @@ pr.subject_id, pr.hadm_id , pr.route , pr.starttime , pr.stoptime -from mimic_hosp.prescriptions pr +from mimiciv_hosp.prescriptions pr -- inner join to subselect to only antibiotic prescriptions inner join abx on pr.drug = abx.drug @@ -196,7 +196,7 @@ inner join abx -- only ~4000 null rows in prescriptions total. AND pr.route = abx.route -- add in stay_id as we use this table for sepsis-3 -LEFT JOIN mimic_icu.icustays ie +LEFT JOIN mimiciv_icu.icustays ie ON pr.hadm_id = ie.hadm_id AND pr.starttime >= ie.intime AND pr.starttime < ie.outtime diff --git a/mimic-iv/concepts/postgres/medication/dobutamine.sql b/mimic-iv/concepts/postgres/medication/dobutamine.sql index 061618d77..41604cead 100644 --- a/mimic-iv/concepts/postgres/medication/dobutamine.sql +++ b/mimic-iv/concepts/postgres/medication/dobutamine.sql @@ -8,5 +8,5 @@ stay_id, linkorderid , amount as vaso_amount , starttime , endtime -from mimic_icu.inputevents +from mimiciv_icu.inputevents where itemid = 221653 -- dobutamine \ No newline at end of file diff --git a/mimic-iv/concepts/postgres/medication/dopamine.sql b/mimic-iv/concepts/postgres/medication/dopamine.sql index 0ba5d232c..e90212bf6 100644 --- a/mimic-iv/concepts/postgres/medication/dopamine.sql +++ b/mimic-iv/concepts/postgres/medication/dopamine.sql @@ -8,5 +8,5 @@ stay_id, linkorderid , amount as vaso_amount , starttime , endtime -from mimic_icu.inputevents +from mimiciv_icu.inputevents where itemid = 221662 -- dopamine \ No newline at end of file diff --git a/mimic-iv/concepts/postgres/medication/epinephrine.sql b/mimic-iv/concepts/postgres/medication/epinephrine.sql index 919a94066..132be5582 100644 --- a/mimic-iv/concepts/postgres/medication/epinephrine.sql +++ b/mimic-iv/concepts/postgres/medication/epinephrine.sql @@ -8,5 +8,5 @@ stay_id, linkorderid , amount as vaso_amount , starttime , endtime -from mimic_icu.inputevents +from mimiciv_icu.inputevents where itemid = 221289 -- epinephrine \ No newline at end of file diff --git a/mimic-iv/concepts/postgres/medication/neuroblock.sql b/mimic-iv/concepts/postgres/medication/neuroblock.sql index 16f367910..c8bec8812 100644 --- a/mimic-iv/concepts/postgres/medication/neuroblock.sql +++ b/mimic-iv/concepts/postgres/medication/neuroblock.sql @@ -7,7 +7,7 @@ select , amount as drug_amount , starttime , endtime -from mimic_icu.inputevents +from mimiciv_icu.inputevents where itemid in ( 222062 -- Vecuronium (664 rows, 154 infusion rows) diff --git a/mimic-iv/concepts/postgres/medication/norepinephrine.sql b/mimic-iv/concepts/postgres/medication/norepinephrine.sql index b4bf1fb4a..8b3f2bd7b 100644 --- a/mimic-iv/concepts/postgres/medication/norepinephrine.sql +++ b/mimic-iv/concepts/postgres/medication/norepinephrine.sql @@ -12,5 +12,5 @@ select , amount as vaso_amount , starttime , endtime -from mimic_icu.inputevents +from mimiciv_icu.inputevents where itemid = 221906 -- norepinephrine \ No newline at end of file diff --git a/mimic-iv/concepts/postgres/medication/phenylephrine.sql b/mimic-iv/concepts/postgres/medication/phenylephrine.sql index 536f9f2bb..8faa3bd73 100644 --- a/mimic-iv/concepts/postgres/medication/phenylephrine.sql +++ b/mimic-iv/concepts/postgres/medication/phenylephrine.sql @@ -9,5 +9,5 @@ select , amount as vaso_amount , starttime , endtime -from mimic_icu.inputevents +from mimiciv_icu.inputevents where itemid = 221749 -- phenylephrine diff --git a/mimic-iv/concepts/postgres/medication/vasopressin.sql b/mimic-iv/concepts/postgres/medication/vasopressin.sql index 65d9ab44e..e2f323d9c 100644 --- a/mimic-iv/concepts/postgres/medication/vasopressin.sql +++ b/mimic-iv/concepts/postgres/medication/vasopressin.sql @@ -10,5 +10,5 @@ select , amount as vaso_amount , starttime , endtime -from mimic_icu.inputevents +from mimiciv_icu.inputevents where itemid = 222315 -- vasopressin \ No newline at end of file diff --git a/mimic-iv/concepts/postgres/organfailure/kdigo_creatinine.sql b/mimic-iv/concepts/postgres/organfailure/kdigo_creatinine.sql index d1389be91..5bddaf5c7 100644 --- a/mimic-iv/concepts/postgres/organfailure/kdigo_creatinine.sql +++ b/mimic-iv/concepts/postgres/organfailure/kdigo_creatinine.sql @@ -8,8 +8,8 @@ WITH cr AS , ie.stay_id , le.charttime , AVG(le.valuenum) AS creat - FROM mimic_icu.icustays ie - LEFT JOIN mimic_hosp.labevents le + FROM mimiciv_icu.icustays ie + LEFT JOIN mimiciv_hosp.labevents le ON ie.subject_id = le.subject_id AND le.ITEMID = 50912 AND le.VALUENUM IS NOT NULL diff --git a/mimic-iv/concepts/postgres/organfailure/kdigo_stages.sql b/mimic-iv/concepts/postgres/organfailure/kdigo_stages.sql index d5bb1a8f9..79b45120f 100644 --- a/mimic-iv/concepts/postgres/organfailure/kdigo_stages.sql +++ b/mimic-iv/concepts/postgres/organfailure/kdigo_stages.sql @@ -28,7 +28,7 @@ with cr_stg AS when cr.creat >= (cr.creat_low_past_48hr+0.3) then 1 when cr.creat >= (cr.creat_low_past_7day*1.5) then 1 else 0 end as aki_stage_creat - FROM mimic_derived.kdigo_creatinine cr + FROM mimiciv_derived.kdigo_creatinine cr ) -- stages for UO / creat , uo_stg as @@ -52,8 +52,8 @@ with cr_stg AS WHEN uo.uo_tm_12hr >= 5 AND uo.uo_rt_12hr < 0.5 THEN 2 WHEN uo.uo_tm_6hr >= 2 AND uo.uo_rt_6hr < 0.5 THEN 1 ELSE 0 END AS aki_stage_uo - from mimic_derived.kdigo_uo uo - INNER JOIN mimic_icu.icustays ie + from mimiciv_derived.kdigo_uo uo + INNER JOIN mimiciv_icu.icustays ie ON uo.stay_id = ie.stay_id ) -- get all charttimes documented @@ -85,7 +85,7 @@ select COALESCE(cr.aki_stage_creat,0), COALESCE(uo.aki_stage_uo,0) ) AS aki_stage -FROM mimic_icu.icustays ie +FROM mimiciv_icu.icustays ie -- get all possible charttimes as listed in tm_stg LEFT JOIN tm_stg tm ON ie.stay_id = tm.stay_id diff --git a/mimic-iv/concepts/postgres/organfailure/kdigo_uo.sql b/mimic-iv/concepts/postgres/organfailure/kdigo_uo.sql index 0308e59b8..eea10d16b 100644 --- a/mimic-iv/concepts/postgres/organfailure/kdigo_uo.sql +++ b/mimic-iv/concepts/postgres/organfailure/kdigo_uo.sql @@ -43,11 +43,11 @@ with ur_stg as 'SECOND') AS NUMERIC)/3600.0, 4) AS uo_tm_12hr , ROUND(CAST( - DATETIME_DIFF(io.charttime,MIN(iosum.charttime),'SECOND') + DATETIME_DIFF(io.charttime, MIN(iosum.charttime), 'SECOND') AS NUMERIC)/3600.0, 4) AS uo_tm_24hr - from mimic_derived.urine_output io + from mimiciv_derived.urine_output io -- this join gives all UO measurements over the 24 hours preceding this row - left join mimic_derived.urine_output iosum + left join mimiciv_derived.urine_output iosum on io.stay_id = iosum.stay_id and iosum.charttime <= io.charttime and iosum.charttime >= DATETIME_SUB(io.charttime, interval '23' hour) @@ -69,7 +69,7 @@ select , uo_tm_12hr , uo_tm_24hr from ur_stg ur -left join mimic_derived.weight_durations wd +left join mimiciv_derived.weight_durations wd on ur.stay_id = wd.stay_id and ur.charttime >= wd.starttime and ur.charttime < wd.endtime diff --git a/mimic-iv/concepts/postgres/organfailure/meld.sql b/mimic-iv/concepts/postgres/organfailure/meld.sql index 2578632d3..226acbed4 100644 --- a/mimic-iv/concepts/postgres/organfailure/meld.sql +++ b/mimic-iv/concepts/postgres/organfailure/meld.sql @@ -58,11 +58,11 @@ SELECT , r.dialysis_present AS rrt -FROM mimic_icu.icustays ie +FROM mimiciv_icu.icustays ie -- join to custom tables to get more data.... -LEFT JOIN mimic_derived.first_day_lab labs +LEFT JOIN mimiciv_derived.first_day_lab labs ON ie.stay_id = labs.stay_id -LEFT JOIN mimic_derived.first_day_rrt r +LEFT JOIN mimiciv_derived.first_day_rrt r ON ie.stay_id = r.stay_id ) , score as diff --git a/mimic-iv/concepts/postgres/postgres-make-concepts.sql b/mimic-iv/concepts/postgres/postgres-make-concepts.sql index f8d547c54..2041cafd0 100644 --- a/mimic-iv/concepts/postgres/postgres-make-concepts.sql +++ b/mimic-iv/concepts/postgres/postgres-make-concepts.sql @@ -47,10 +47,10 @@ \i medication/milrinone.sql \i medication/neuroblock.sql \i medication/norepinephrine.sql +\i medication/norepinephrine_equivalent_dose.sql \i medication/phenylephrine.sql -\i medication/vasopressin.sql \i medication/vasoactive_agent.sql -\i medication/norepinephrine_equivalent_dose.sql +\i medication/vasopressin.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 a2da07136..8a3f3abaa 100644 --- a/mimic-iv/concepts/postgres/score/apsiii.sql +++ b/mimic-iv/concepts/postgres/score/apsiii.sql @@ -39,11 +39,11 @@ with pa as select ie.stay_id, bg.charttime , po2 as PaO2 , ROW_NUMBER() over (partition by ie.stay_id ORDER BY bg.po2 DESC) as rn - from mimic_derived.bg bg - INNER JOIN mimic_icu.icustays ie + from mimiciv_derived.bg bg + INNER JOIN mimiciv_icu.icustays ie ON bg.hadm_id = ie.hadm_id AND bg.charttime >= ie.intime AND bg.charttime < ie.outtime - left join mimic_derived.ventilation vd + left join mimiciv_derived.ventilation vd on ie.stay_id = vd.stay_id and bg.charttime >= vd.starttime and bg.charttime <= vd.endtime @@ -62,11 +62,11 @@ with pa as , bg.aado2 , ROW_NUMBER() over (partition by ie.stay_id ORDER BY bg.aado2 DESC) as rn -- row number indicating the highest AaDO2 - from mimic_derived.bg bg - INNER JOIN mimic_icu.icustays ie + from mimiciv_derived.bg bg + INNER JOIN mimiciv_icu.icustays ie ON bg.hadm_id = ie.hadm_id AND bg.charttime >= ie.intime AND bg.charttime < ie.outtime - INNER JOIN mimic_derived.ventilation vd + INNER JOIN mimiciv_derived.ventilation vd on ie.stay_id = vd.stay_id and bg.charttime >= vd.starttime and bg.charttime <= vd.endtime @@ -127,8 +127,8 @@ with pa as else 12 end end as acidbase_score - from mimic_derived.bg bg - INNER JOIN mimic_icu.icustays ie + from mimiciv_derived.bg bg + INNER JOIN mimiciv_icu.icustays ie 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 @@ -156,10 +156,10 @@ with pa as and icd.ckd = 0 then 1 else 0 end as arf - FROM mimic_icu.icustays ie - left join mimic_derived.first_day_urine_output uo + FROM mimiciv_icu.icustays ie + left join mimiciv_derived.first_day_urine_output uo on ie.stay_id = uo.stay_id - left join mimic_derived.first_day_lab labs + left join mimiciv_derived.first_day_lab labs on ie.stay_id = labs.stay_id left join ( @@ -171,7 +171,7 @@ with pa as -- we do not include 5859 as that is sometimes coded for acute-on-chronic ARF else 0 end) as ckd - from mimic_hosp.diagnoses_icd + from mimiciv_hosp.diagnoses_icd group by hadm_id ) icd on ie.hadm_id = icd.hadm_id @@ -183,8 +183,8 @@ with pa as , MAX( CASE WHEN v.stay_id IS NOT NULL THEN 1 ELSE 0 END ) AS vent - FROM mimic_icu.icustays ie - LEFT JOIN mimic_derived.ventilation v + FROM mimiciv_icu.icustays ie + LEFT JOIN mimiciv_derived.ventilation v ON ie.stay_id = v.stay_id AND ( v.starttime BETWEEN ie.intime AND DATETIME_ADD(ie.intime, INTERVAL '1' DAY) @@ -261,10 +261,10 @@ select ie.subject_id, ie.hadm_id, ie.stay_id -- acute renal failure , arf.arf as arf -FROM mimic_icu.icustays ie -inner join mimic_core.admissions adm +FROM mimiciv_icu.icustays ie +inner join mimiciv_hosp.admissions adm on ie.hadm_id = adm.hadm_id -inner join mimic_core.patients pat +inner join mimiciv_hosp.patients pat on ie.subject_id = pat.subject_id -- join to above views - the row number filters to 1 row per stay_id @@ -283,13 +283,13 @@ left join arf -- join to custom tables to get more data.... left join vent on ie.stay_id = vent.stay_id -left join mimic_derived.first_day_gcs gcs +left join mimiciv_derived.first_day_gcs gcs on ie.stay_id = gcs.stay_id -left join mimic_derived.first_day_vitalsign vital +left join mimiciv_derived.first_day_vitalsign vital on ie.stay_id = vital.stay_id -left join mimic_derived.first_day_urine_output uo +left join mimiciv_derived.first_day_urine_output uo on ie.stay_id = uo.stay_id -left join mimic_derived.first_day_lab labs +left join mimiciv_derived.first_day_lab labs on ie.stay_id = labs.stay_id ) -- First, we calculate the score for the minimum values @@ -856,7 +856,7 @@ select ie.subject_id, ie.hadm_id, ie.stay_id , glucose_score , acidbase_score , gcs_score -FROM mimic_icu.icustays ie +FROM mimiciv_icu.icustays ie left join score s on ie.stay_id = s.stay_id ; \ No newline at end of file diff --git a/mimic-iv/concepts/postgres/score/lods.sql b/mimic-iv/concepts/postgres/score/lods.sql index b2e96a057..4894ea9db 100644 --- a/mimic-iv/concepts/postgres/score/lods.sql +++ b/mimic-iv/concepts/postgres/score/lods.sql @@ -34,8 +34,8 @@ with cpap as WHEN lower(ce.value) LIKE '%cpap%' THEN 1 WHEN lower(ce.value) LIKE '%bipap mask%' THEN 1 else 0 end) as cpap - FROM mimic_icu.icustays ie - inner join mimic_icu.chartevents ce + FROM mimiciv_icu.icustays ie + inner join mimiciv_icu.chartevents ce on ie.stay_id = ce.stay_id and ce.charttime between ie.intime and DATETIME_ADD(ie.intime, INTERVAL '1' DAY) where itemid = 226732 @@ -50,11 +50,11 @@ with cpap as , pao2fio2ratio , case when vd.stay_id is not null then 1 else 0 end as vent , case when cp.stay_id is not null then 1 else 0 end as cpap - from mimic_derived.bg bg - INNER JOIN mimic_icu.icustays ie + from mimiciv_derived.bg bg + INNER JOIN mimiciv_icu.icustays ie ON bg.hadm_id = ie.hadm_id AND bg.charttime >= ie.intime AND bg.charttime < ie.outtime - left join mimic_derived.ventilation vd + left join mimiciv_derived.ventilation vd on ie.stay_id = vd.stay_id and bg.charttime >= vd.starttime and bg.charttime <= vd.endtime @@ -102,10 +102,10 @@ select ie.subject_id , uo.urineoutput -FROM mimic_icu.icustays ie -inner join mimic_core.admissions adm +FROM mimiciv_icu.icustays ie +inner join mimiciv_hosp.admissions adm on ie.hadm_id = adm.hadm_id -inner join mimic_core.patients pat +inner join mimiciv_hosp.patients pat on ie.subject_id = pat.subject_id -- join to above view to get pao2/fio2 ratio @@ -113,13 +113,13 @@ left join pafi2 pf on ie.stay_id = pf.stay_id -- join to custom tables to get more data.... -left join mimic_derived.first_day_gcs gcs +left join mimiciv_derived.first_day_gcs gcs on ie.stay_id = gcs.stay_id -left join mimic_derived.first_day_vitalsign vital +left join mimiciv_derived.first_day_vitalsign vital on ie.stay_id = vital.stay_id -left join mimic_derived.first_day_urine_output uo +left join mimiciv_derived.first_day_urine_output uo on ie.stay_id = uo.stay_id -left join mimic_derived.first_day_lab labs +left join mimiciv_derived.first_day_lab labs on ie.stay_id = labs.stay_id ) , scorecomp as @@ -220,7 +220,7 @@ select ie.subject_id, ie.hadm_id, ie.stay_id , pulmonary , hematologic , hepatic -FROM mimic_icu.icustays ie +FROM mimiciv_icu.icustays ie left join scorecomp s on ie.stay_id = s.stay_id ; \ No newline at end of file diff --git a/mimic-iv/concepts/postgres/score/oasis.sql b/mimic-iv/concepts/postgres/score/oasis.sql index 7b6ae8063..94ea11614 100644 --- a/mimic-iv/concepts/postgres/score/oasis.sql +++ b/mimic-iv/concepts/postgres/score/oasis.sql @@ -13,11 +13,11 @@ DROP TABLE IF EXISTS oasis; CREATE TABLE oasis AS -- Critical care medicine 41, no. 7 (2013): 1711-1718. -- Variables used in OASIS: --- Heart rate, GCS, MAP, Temperature, Respiratory rate, Ventilation status (sourced FROM mimic_icu.chartevents) +-- Heart rate, GCS, MAP, Temperature, Respiratory rate, Ventilation status (sourced FROM mimiciv_icu.chartevents) -- Urine output (sourced from OUTPUTEVENTS) --- Elective surgery (sourced FROM mimic_core.admissions and SERVICES) --- Pre-ICU in-hospital length of stay (sourced FROM mimic_core.admissions and ICUSTAYS) --- Age (sourced FROM mimic_core.patients) +-- Elective surgery (sourced FROM mimiciv_hosp.admissions and SERVICES) +-- Pre-ICU in-hospital length of stay (sourced FROM mimiciv_hosp.admissions and ICUSTAYS) +-- Age (sourced FROM mimiciv_hosp.patients) -- Regarding missing values: -- The ventilation flag is always 0/1. It cannot be missing, since VENT=0 if no data is found for vent settings. @@ -34,8 +34,8 @@ with surgflag as when lower(curr_service) like '%surg%' then 1 when curr_service = 'ORTHO' then 1 else 0 end) as surgical - FROM mimic_icu.icustays ie - left join mimic_hosp.services se + FROM mimiciv_icu.icustays ie + left join mimiciv_hosp.services se on ie.hadm_id = se.hadm_id and se.transfertime < DATETIME_ADD(ie.intime, INTERVAL '1' DAY) group by ie.stay_id @@ -47,8 +47,8 @@ with surgflag as , MAX( CASE WHEN v.stay_id IS NOT NULL THEN 1 ELSE 0 END ) AS vent - FROM mimic_icu.icustays ie - LEFT JOIN mimic_derived.ventilation v + FROM mimiciv_icu.icustays ie + LEFT JOIN mimiciv_derived.ventilation v ON ie.stay_id = v.stay_id AND ( v.starttime BETWEEN ie.intime AND DATETIME_ADD(ie.intime, INTERVAL '1' DAY) @@ -64,7 +64,7 @@ select ie.subject_id, ie.hadm_id, ie.stay_id , ie.intime , ie.outtime , adm.deathtime - , DATETIME_DIFF(ie.intime,adm.admittime,'MINUTE') as preiculos + , DATETIME_DIFF(ie.intime, adm.admittime, 'MINUTE') as preiculos , ag.age , gcs.gcs_min , vital.heart_rate_max @@ -97,21 +97,21 @@ select ie.subject_id, ie.hadm_id, ie.stay_id else 0 end as icustay_expire_flag , adm.hospital_expire_flag -FROM mimic_icu.icustays ie -inner join mimic_core.admissions adm +FROM mimiciv_icu.icustays ie +inner join mimiciv_hosp.admissions adm on ie.hadm_id = adm.hadm_id -inner join mimic_core.patients pat +inner join mimiciv_hosp.patients pat on ie.subject_id = pat.subject_id -LEFT JOIN mimic_derived.age ag +LEFT JOIN mimiciv_derived.age ag ON ie.hadm_id = ag.hadm_id left join surgflag sf on ie.stay_id = sf.stay_id -- join to custom tables to get more data.... -left join mimic_derived.first_day_gcs gcs +left join mimiciv_derived.first_day_gcs gcs on ie.stay_id = gcs.stay_id -left join mimic_derived.first_day_vitalsign vital +left join mimiciv_derived.first_day_vitalsign vital on ie.stay_id = vital.stay_id -left join mimic_derived.first_day_urine_output uo +left join mimiciv_derived.first_day_urine_output uo on ie.stay_id = uo.stay_id left join vent on ie.stay_id = vent.stay_id diff --git a/mimic-iv/concepts/postgres/score/sapsii.sql b/mimic-iv/concepts/postgres/score/sapsii.sql index 24b562bc2..9f3bd83c1 100644 --- a/mimic-iv/concepts/postgres/score/sapsii.sql +++ b/mimic-iv/concepts/postgres/score/sapsii.sql @@ -26,7 +26,7 @@ with co as , stay_id , intime AS starttime , DATETIME_ADD(intime, INTERVAL '24' HOUR) AS endtime - from mimic_icu.icustays ie + from mimiciv_icu.icustays ie ) , cpap as ( @@ -37,7 +37,7 @@ with co as , LEAST(max(DATETIME_ADD(charttime, INTERVAL '4' HOUR)), co.endtime) as endtime , max(case when REGEXP_CONTAINS(lower(ce.value), '(cpap mask|bipap)') then 1 else 0 end) as cpap from co - inner join mimic_icu.chartevents ce + inner join mimiciv_icu.chartevents ce on co.stay_id = ce.stay_id and ce.charttime > co.starttime and ce.charttime <= co.endtime @@ -57,8 +57,8 @@ with co as PARTITION BY adm.HADM_ID ORDER BY TRANSFERTIME ) as serviceOrder - from mimic_core.admissions adm - left join mimic_hosp.services se + from mimiciv_hosp.admissions adm + left join mimiciv_hosp.services se on adm.hadm_id = se.hadm_id ) -- icd-9 diagnostic codes are our best source for comorbidity information @@ -100,7 +100,7 @@ select hadm_id WHEN icd_version = 10 AND SUBSTR(icd_code, 1, 3) BETWEEN 'C77' AND 'C79' THEN 1 WHEN icd_version = 10 AND SUBSTR(icd_code, 1, 4) = 'C800' THEN 1 ELSE 0 END) as mets /* Metastatic cancer */ - from mimic_hosp.diagnoses_icd + from mimiciv_hosp.diagnoses_icd group by hadm_id ) @@ -115,12 +115,12 @@ select hadm_id , case when vd.stay_id is not null then 1 else 0 end as vent , case when cp.subject_id is not null then 1 else 0 end as cpap from co - LEFT JOIN mimic_derived.bg bg + LEFT JOIN mimiciv_derived.bg bg ON co.subject_id = bg.subject_id AND bg.specimen = 'ART.' AND bg.charttime > co.starttime AND bg.charttime <= co.endtime - left join mimic_derived.ventilation vd + left join mimiciv_derived.ventilation vd on co.stay_id = vd.stay_id and bg.charttime > vd.starttime and bg.charttime <= vd.endtime @@ -145,7 +145,7 @@ select hadm_id select co.stay_id , MIN(gcs.gcs) AS mingcs FROM co - left join mimic_derived.gcs gcs + left join mimiciv_derived.gcs gcs ON co.stay_id = gcs.stay_id AND co.starttime < gcs.charttime AND gcs.charttime <= co.endtime @@ -163,7 +163,7 @@ select hadm_id , MIN(vital.temperature) AS tempc_min , MAX(vital.temperature) AS tempc_max FROM co - left join mimic_derived.vitalsign vital + left join mimiciv_derived.vitalsign vital on co.subject_id = vital.subject_id AND co.starttime < vital.charttime AND co.endtime >= vital.charttime @@ -175,7 +175,7 @@ select hadm_id co.stay_id , SUM(uo.urineoutput) as urineoutput FROM co - left join mimic_derived.urine_output uo + left join mimiciv_derived.urine_output uo on co.stay_id = uo.stay_id AND co.starttime < uo.charttime AND co.endtime >= uo.charttime @@ -194,7 +194,7 @@ select hadm_id , MIN(labs.bicarbonate) AS bicarbonate_min , MAX(labs.bicarbonate) AS bicarbonate_max FROM co - left join mimic_derived.chemistry labs + left join mimiciv_derived.chemistry labs on co.subject_id = labs.subject_id AND co.starttime < labs.charttime AND co.endtime >= labs.charttime @@ -207,7 +207,7 @@ select hadm_id , MIN(cbc.wbc) AS wbc_min , MAX(cbc.wbc) AS wbc_max FROM co - LEFT JOIN mimic_derived.complete_blood_count cbc + LEFT JOIN mimiciv_derived.complete_blood_count cbc ON co.subject_id = cbc.subject_id AND co.starttime < cbc.charttime AND co.endtime >= cbc.charttime @@ -220,7 +220,7 @@ select hadm_id , MIN(enz.bilirubin_total) AS bilirubin_min , MAX(enz.bilirubin_total) AS bilirubin_max FROM co - LEFT JOIN mimic_derived.enzyme enz + LEFT JOIN mimiciv_derived.enzyme enz ON co.subject_id = enz.subject_id AND co.starttime < enz.charttime AND co.endtime >= enz.charttime @@ -278,10 +278,10 @@ select end as AdmissionType -from mimic_icu.icustays ie -inner join mimic_core.admissions adm +from mimiciv_icu.icustays ie +inner join mimiciv_hosp.admissions adm on ie.hadm_id = adm.hadm_id -LEFT JOIN mimic_derived.age va +LEFT JOIN mimiciv_derived.age va on ie.hadm_id = va.hadm_id inner join co on ie.stay_id = co.stay_id diff --git a/mimic-iv/concepts/postgres/score/sirs.sql b/mimic-iv/concepts/postgres/score/sirs.sql index 9d94ec570..3a662ccb8 100644 --- a/mimic-iv/concepts/postgres/score/sirs.sql +++ b/mimic-iv/concepts/postgres/score/sirs.sql @@ -37,12 +37,12 @@ select ie.stay_id , l.wbc_min , l.wbc_max , l.bands_max -FROM mimic_icu.icustays ie -left join mimic_derived.first_day_bg_art bg +FROM mimiciv_icu.icustays ie +left join mimiciv_derived.first_day_bg_art bg on ie.stay_id = bg.stay_id -left join mimic_derived.first_day_vitalsign v +left join mimiciv_derived.first_day_vitalsign v on ie.stay_id = v.stay_id -left join mimic_derived.first_day_lab l +left join mimiciv_derived.first_day_lab l on ie.stay_id = l.stay_id ) , scorecalc as @@ -93,7 +93,7 @@ select + coalesce(wbc_score,0) as sirs , temp_score, heart_rate_score, resp_score, wbc_score -FROM mimic_icu.icustays ie +FROM mimiciv_icu.icustays ie left join scorecalc s on ie.stay_id = s.stay_id ; diff --git a/mimic-iv/concepts/postgres/score/sofa.sql b/mimic-iv/concepts/postgres/score/sofa.sql index ae0a6dfa7..910f0d8f9 100644 --- a/mimic-iv/concepts/postgres/score/sofa.sql +++ b/mimic-iv/concepts/postgres/score/sofa.sql @@ -16,9 +16,9 @@ DROP TABLE IF EXISTS sofa; CREATE TABLE sofa AS -- Intensive care medicine 22, no. 7 (1996): 707-710. -- Variables used in SOFA: --- GCS, MAP, FiO2, Ventilation status (sourced FROM mimic_icu.chartevents) --- Creatinine, Bilirubin, FiO2, PaO2, Platelets (sourced FROM mimic_icu.labevents) --- Dopamine, Dobutamine, Epinephrine, Norepinephrine (sourced FROM mimic_icu.inputevents_mv and INPUTEVENTS_CV) +-- GCS, MAP, FiO2, Ventilation status (sourced FROM mimiciv_icu.chartevents) +-- Creatinine, Bilirubin, FiO2, PaO2, Platelets (sourced FROM mimiciv_icu.labevents) +-- Dopamine, Dobutamine, Epinephrine, Norepinephrine (sourced FROM mimiciv_icu.inputevents_mv and INPUTEVENTS_CV) -- Urine output (sourced from OUTPUTEVENTS) -- generate a row for every hour the patient was in the ICU @@ -31,8 +31,8 @@ WITH co AS -- start/endtime can be used to filter to values within this hour , DATETIME_SUB(ih.endtime, INTERVAL '1' HOUR) AS starttime , ih.endtime - from mimic_derived.icustay_hourly ih - INNER JOIN mimic_icu.icustays ie + from mimiciv_derived.icustay_hourly ih + INNER JOIN mimiciv_icu.icustays ie ON ih.stay_id = ie.stay_id ) , pafi as @@ -45,10 +45,10 @@ WITH co AS -- in this case, the SOFA score is 3, *not* 4. , case when vd.stay_id is null then pao2fio2ratio else null end pao2fio2ratio_novent , case when vd.stay_id is not null then pao2fio2ratio else null end pao2fio2ratio_vent - FROM mimic_icu.icustays ie - inner join mimic_derived.bg bg + FROM mimiciv_icu.icustays ie + inner join mimiciv_derived.bg bg on ie.subject_id = bg.subject_id - left join mimic_derived.ventilation vd + left join mimiciv_derived.ventilation vd on ie.stay_id = vd.stay_id and bg.charttime >= vd.starttime and bg.charttime <= vd.endtime @@ -62,7 +62,7 @@ WITH co AS -- vitals , min(vs.mbp) as meanbp_min from co - left join mimic_derived.vitalsign vs + left join mimiciv_derived.vitalsign vs on co.stay_id = vs.stay_id and co.starttime < vs.charttime and co.endtime >= vs.charttime @@ -74,7 +74,7 @@ WITH co AS -- gcs , min(gcs.gcs) as gcs_min from co - left join mimic_derived.gcs gcs + left join mimiciv_derived.gcs gcs on co.stay_id = gcs.stay_id and co.starttime < gcs.charttime and co.endtime >= gcs.charttime @@ -85,7 +85,7 @@ WITH co AS select co.stay_id, co.hr , max(enz.bilirubin_total) as bilirubin_max from co - left join mimic_derived.enzyme enz + left join mimiciv_derived.enzyme enz on co.hadm_id = enz.hadm_id and co.starttime < enz.charttime and co.endtime >= enz.charttime @@ -96,7 +96,7 @@ WITH co AS select co.stay_id, co.hr , max(chem.creatinine) as creatinine_max from co - left join mimic_derived.chemistry chem + left join mimiciv_derived.chemistry chem on co.hadm_id = chem.hadm_id and co.starttime < chem.charttime and co.endtime >= chem.charttime @@ -107,7 +107,7 @@ WITH co AS select co.stay_id, co.hr , min(cbc.platelet) as platelet_min from co - left join mimic_derived.complete_blood_count cbc + left join mimiciv_derived.complete_blood_count cbc on co.hadm_id = cbc.hadm_id and co.starttime < cbc.charttime and co.endtime >= cbc.charttime @@ -136,7 +136,7 @@ WITH co AS THEN uo.urineoutput_24hr / uo.uo_tm_24hr * 24 END) as uo_24hr from co - left join mimic_derived.urine_output_rate uo + left join mimiciv_derived.urine_output_rate uo on co.stay_id = uo.stay_id and co.starttime < uo.charttime and co.endtime >= uo.charttime @@ -154,19 +154,19 @@ WITH co AS , MAX(dop.vaso_rate) as rate_dopamine , MAX(dob.vaso_rate) as rate_dobutamine FROM co - LEFT JOIN mimic_derived.epinephrine epi + LEFT JOIN mimiciv_derived.epinephrine epi on co.stay_id = epi.stay_id and co.endtime > epi.starttime and co.endtime <= epi.endtime - LEFT JOIN mimic_derived.norepinephrine nor + LEFT JOIN mimiciv_derived.norepinephrine nor on co.stay_id = nor.stay_id and co.endtime > nor.starttime and co.endtime <= nor.endtime - LEFT JOIN mimic_derived.dopamine dop + LEFT JOIN mimiciv_derived.dopamine dop on co.stay_id = dop.stay_id and co.endtime > dop.starttime and co.endtime <= dop.endtime - LEFT JOIN mimic_derived.dobutamine dob + LEFT JOIN mimiciv_derived.dobutamine dob on co.stay_id = dob.stay_id and co.endtime > dob.starttime and co.endtime <= dob.endtime diff --git a/mimic-iv/concepts/postgres/sepsis/sepsis3.sql b/mimic-iv/concepts/postgres/sepsis/sepsis3.sql index 5ccafd400..6647e68ae 100644 --- a/mimic-iv/concepts/postgres/sepsis/sepsis3.sql +++ b/mimic-iv/concepts/postgres/sepsis/sepsis3.sql @@ -18,7 +18,7 @@ WITH sofa AS , cns_24hours as cns , renal_24hours as renal , sofa_24hours as sofa_score - FROM mimic_derived.sofa + FROM mimiciv_derived.sofa WHERE sofa_24hours >= 2 ) , s1 as @@ -51,7 +51,7 @@ WITH sofa AS PARTITION BY soi.stay_id ORDER BY suspected_infection_time, antibiotic_time, culture_time, endtime ) AS rn_sus - FROM mimic_derived.suspicion_of_infection as soi + FROM mimiciv_derived.suspicion_of_infection as soi INNER JOIN sofa ON soi.stay_id = sofa.stay_id AND sofa.endtime >= DATETIME_SUB(soi.suspected_infection_time, INTERVAL '48' HOUR) diff --git a/mimic-iv/concepts/postgres/sepsis/suspicion_of_infection.sql b/mimic-iv/concepts/postgres/sepsis/suspicion_of_infection.sql index 3d77ff337..633f90c3a 100644 --- a/mimic-iv/concepts/postgres/sepsis/suspicion_of_infection.sql +++ b/mimic-iv/concepts/postgres/sepsis/suspicion_of_infection.sql @@ -17,7 +17,7 @@ WITH ab_tbl AS PARTITION BY subject_id ORDER BY starttime, stoptime, antibiotic ) AS ab_id - from mimic_derived.antibiotic abx + from mimiciv_derived.antibiotic abx ) , me as ( @@ -30,7 +30,7 @@ WITH ab_tbl AS , MAX(charttime) AS charttime , MAX(spec_type_desc) AS spec_type_desc , max(case when org_name is not null and org_name != '' then 1 else 0 end) as PositiveCulture - from mimic_hosp.microbiologyevents + from mimiciv_hosp.microbiologyevents group by micro_specimen_id ) -- culture followed by an antibiotic diff --git a/mimic-iv/concepts/postgres/treatment/crrt.sql b/mimic-iv/concepts/postgres/treatment/crrt.sql index 09aec2ac3..70be7d00d 100644 --- a/mimic-iv/concepts/postgres/treatment/crrt.sql +++ b/mimic-iv/concepts/postgres/treatment/crrt.sql @@ -51,7 +51,7 @@ with crrt_settings as AND ce.value IN ('Clotted') THEN 1 ELSE NULL END as clotted - from mimic_icu.chartevents ce + from mimiciv_icu.chartevents ce where ce.itemid in ( -- MetaVision ITEMIDs diff --git a/mimic-iv/concepts/postgres/treatment/invasive_line.sql b/mimic-iv/concepts/postgres/treatment/invasive_line.sql index 77d1999ae..b849773d8 100644 --- a/mimic-iv/concepts/postgres/treatment/invasive_line.sql +++ b/mimic-iv/concepts/postgres/treatment/invasive_line.sql @@ -11,8 +11,8 @@ WITH mv AS , di.label AS line_type , mv.location AS line_site , starttime, endtime - FROM mimic_icu.procedureevents mv - INNER JOIN mimic_icu.d_items di + FROM mimiciv_icu.procedureevents mv + INNER JOIN mimiciv_icu.d_items di ON mv.itemid = di.itemid WHERE mv.itemid IN ( diff --git a/mimic-iv/concepts/postgres/treatment/rrt.sql b/mimic-iv/concepts/postgres/treatment/rrt.sql index 0be732a42..b680405d0 100644 --- a/mimic-iv/concepts/postgres/treatment/rrt.sql +++ b/mimic-iv/concepts/postgres/treatment/rrt.sql @@ -135,7 +135,7 @@ with ce as WHEN ce.itemid = 226499 THEN 'IHD' ELSE NULL END as dialysis_type - from mimic_icu.chartevents ce + from mimiciv_icu.chartevents ce WHERE ce.itemid in ( -- === MetaVision itemids === -- @@ -206,7 +206,7 @@ with ce as , 1 AS dialysis_present , 0 AS dialysis_active , NULL AS dialysis_type - from mimic_icu.outputevents + from mimiciv_icu.outputevents where itemid in ( 40386 -- hemodialysis @@ -220,7 +220,7 @@ with ce as , 1 AS dialysis_present , 1 AS dialysis_active , 'CRRT' as dialysis_type - from mimic_icu.inputevents + from mimiciv_icu.inputevents where itemid in ( 227536 -- KCl (CRRT) Medications inputevents_mv Solution @@ -240,7 +240,7 @@ with ce as WHEN itemid = 225809 THEN 'CVVHDF' -- CVVHDF (Continuous venovenous hemodiafiltration) WHEN itemid = 225955 THEN 'SCUF' -- SCUF (Slow continuous ultra filtration) ELSE NULL END as dialysis_type - from mimic_icu.procedureevents + from mimiciv_icu.procedureevents where itemid in ( 225441 -- | Hemodialysis | 4-Procedures | procedureevents_mv | Process diff --git a/mimic-iv/concepts/postgres/treatment/ventilation.sql b/mimic-iv/concepts/postgres/treatment/ventilation.sql index 4cee437ce..c101f86ff 100644 --- a/mimic-iv/concepts/postgres/treatment/ventilation.sql +++ b/mimic-iv/concepts/postgres/treatment/ventilation.sql @@ -24,10 +24,10 @@ DROP TABLE IF EXISTS ventilation; CREATE TABLE ventilation AS WITH tm AS ( SELECT stay_id, charttime - FROM mimic_derived.ventilator_setting + FROM mimiciv_derived.ventilator_setting UNION DISTINCT SELECT stay_id, charttime - FROM mimic_derived.oxygen_delivery + FROM mimiciv_derived.oxygen_delivery ) , vs AS ( @@ -147,10 +147,10 @@ WITH tm AS -- not categorized: other ELSE NULL END AS ventilation_status FROM tm - LEFT JOIN mimic_derived.ventilator_setting vs + LEFT JOIN mimiciv_derived.ventilator_setting vs ON tm.stay_id = vs.stay_id AND tm.charttime = vs.charttime - LEFT JOIN mimic_derived.oxygen_delivery od + LEFT JOIN mimiciv_derived.oxygen_delivery od ON tm.stay_id = od.stay_id AND tm.charttime = od.charttime ) @@ -186,14 +186,14 @@ WITH tm AS -- , vent_mode -- calculate the time since the last event - , DATETIME_DIFF(charttime,charttime_lag,'MINUTE')/60 as ventduration + , DATETIME_DIFF(charttime, charttime_lag, 'MINUTE')/60 as ventduration -- now we determine if the current ventilation status is "new", or continuing the previous , CASE -- if lag is null, this is the first event for the patient WHEN ventilation_status_lag IS NULL THEN 1 -- a 14 hour gap always initiates a new event - WHEN DATETIME_DIFF(charttime,charttime_lag,'HOUR') >= 14 THEN 1 + WHEN DATETIME_DIFF(charttime, charttime_lag, 'HOUR') >= 14 THEN 1 -- not a new event if identical to the last row WHEN ventilation_status_lag != ventilation_status THEN 1 ELSE 0 @@ -224,7 +224,7 @@ SELECT stay_id , MAX( CASE WHEN charttime_lead IS NULL - OR DATETIME_DIFF(charttime_lead,charttime,'HOUR') >= 14 + OR DATETIME_DIFF(charttime_lead, charttime, 'HOUR') >= 14 THEN charttime ELSE charttime_lead END