Skip to content

Commit 43a4245

Browse files
committed
update postgres concepts with mimic-iv v2.0 changes
1 parent aad8ea6 commit 43a4245

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+240
-261
lines changed

mimic-iv/concepts/postgres/comorbidity/charlson.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ WITH diag AS
2121
hadm_id
2222
, CASE WHEN icd_version = 9 THEN icd_code ELSE NULL END AS icd9_code
2323
, CASE WHEN icd_version = 10 THEN icd_code ELSE NULL END AS icd10_code
24-
FROM mimic_hosp.diagnoses_icd diag
24+
FROM mimiciv_hosp.diagnoses_icd diag
2525
)
2626
, com AS
2727
(
@@ -255,7 +255,7 @@ WITH diag AS
255255
SUBSTR(icd10_code, 1, 3) IN ('B20','B21','B22','B24')
256256
THEN 1
257257
ELSE 0 END) AS aids
258-
FROM mimic_core.admissions ad
258+
FROM mimiciv_hosp.admissions ad
259259
LEFT JOIN diag
260260
ON ad.hadm_id = diag.hadm_id
261261
GROUP BY ad.hadm_id
@@ -270,7 +270,7 @@ WITH diag AS
270270
WHEN age <= 60 THEN 2
271271
WHEN age <= 70 THEN 3
272272
ELSE 4 END AS age_score
273-
FROM mimic_derived.age
273+
FROM mimiciv_derived.age
274274
)
275275
SELECT
276276
ad.subject_id
@@ -305,7 +305,7 @@ SELECT
305305
+ 2*paraplegia + 2*renal_disease
306306
+ 6*aids
307307
AS charlson_comorbidity_index
308-
FROM mimic_core.admissions ad
308+
FROM mimiciv_hosp.admissions ad
309309
LEFT JOIN com
310310
ON ad.hadm_id = com.hadm_id
311311
LEFT JOIN ag

mimic-iv/concepts/postgres/demographics/age.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ SELECT
2323
, ad.admittime
2424
, pa.anchor_age
2525
, pa.anchor_year
26-
, DATETIME_DIFF(ad.admittime, DATETIME(pa.anchor_year, 1, 1, 0, 0,0),'YEAR') + pa.anchor_age AS age
27-
FROM mimic_core.admissions ad
28-
INNER JOIN mimic_core.patients pa
26+
, DATETIME_DIFF(ad.admittime, DATETIME(pa.anchor_year, 1, 1, 0, 0, 0), YEAR) + pa.anchor_age AS age
27+
FROM mimiciv_hosp.admissions ad
28+
INNER JOIN mimiciv_hosp.patients pa
2929
ON ad.subject_id = pa.subject_id
3030
;

mimic-iv/concepts/postgres/demographics/icustay_detail.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ SELECT ie.subject_id, ie.hadm_id, ie.stay_id
77

88
-- hospital level factors
99
, adm.admittime, adm.dischtime
10-
, DATETIME_DIFF(adm.dischtime,adm.admittime,'DAY') as los_hospital
11-
, DATETIME_DIFF(adm.admittime, DATETIME(pat.anchor_year, 1, 1, 0, 0,0),'YEAR') + pat.anchor_age as admission_age
12-
, adm.ethnicity
10+
, DATETIME_DIFF(adm.dischtime, adm.admittime, 'DAY') as los_hospital
11+
, DATETIME_DIFF(adm.admittime, DATETIME(pat.anchor_year, 1, 1, 0, 0, 0), YEAR) + pat.anchor_age as admission_age
12+
, adm.race
1313
, adm.hospital_expire_flag
1414
, DENSE_RANK() OVER (PARTITION BY adm.subject_id ORDER BY adm.admittime) AS hospstay_seq
1515
, CASE
@@ -18,16 +18,16 @@ SELECT ie.subject_id, ie.hadm_id, ie.stay_id
1818

1919
-- icu level factors
2020
, ie.intime as icu_intime, ie.outtime as icu_outtime
21-
, ROUND( CAST( DATETIME_DIFF(ie.outtime,ie.intime,'HOUR')/24.0 as numeric),2) as los_icu
21+
, ROUND( CAST( DATETIME_DIFF(ie.outtime as numeric),ie.intime, 'HOUR')/24.0, 2) as los_icu
2222
, DENSE_RANK() OVER (PARTITION BY ie.hadm_id ORDER BY ie.intime) AS icustay_seq
2323

2424
-- first ICU stay *for the current hospitalization*
2525
, CASE
2626
WHEN DENSE_RANK() OVER (PARTITION BY ie.hadm_id ORDER BY ie.intime) = 1 THEN True
2727
ELSE False END AS first_icu_stay
2828

29-
FROM mimic_icu.icustays ie
30-
INNER JOIN mimic_core.admissions adm
29+
FROM mimiciv_icu.icustays ie
30+
INNER JOIN mimiciv_hosp.admissions adm
3131
ON ie.hadm_id = adm.hadm_id
32-
INNER JOIN mimic_core.patients pat
32+
INNER JOIN mimiciv_hosp.patients pat
3333
ON ie.subject_id = pat.subject_id

mimic-iv/concepts/postgres/demographics/icustay_hourly.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ select
2727
-- create integers for each charttime in hours from admission
2828
-- so 0 is admission time, 1 is one hour after admission, etc, up to ICU disch
2929
-- we allow 24 hours before ICU admission (to grab labs before admit)
30-
, ARRAY(SELECT * FROM generate_series(-24, CEIL(DATETIME_DIFF(it.outtime_hr,it.intime_hr,'HOUR')))) as hrs
30+
, ARRAY(SELECT * FROM generate_series(-24, CEIL(DATETIME_DIFF(it.outtime_hr, it.intime_hr, 'HOUR')))) as hrs
3131

32-
from mimic_derived.icustay_times it
32+
from mimiciv_derived.icustay_times it
3333
)
3434
SELECT stay_id
3535
, CAST(hr AS bigint) as hr

mimic-iv/concepts/postgres/demographics/icustay_times.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ WITH t1 AS
88
select ce.stay_id
99
, min(charttime) as intime_hr
1010
, max(charttime) as outtime_hr
11-
FROM mimic_icu.chartevents ce
11+
FROM mimiciv_icu.chartevents ce
1212
-- only look at heart rate
1313
where ce.itemid = 220045
1414
group by ce.stay_id
@@ -18,6 +18,6 @@ select
1818
ie.subject_id, ie.hadm_id, ie.stay_id
1919
, t1.intime_hr
2020
, t1.outtime_hr
21-
FROM mimic_icu.icustays ie
21+
FROM mimiciv_icu.icustays ie
2222
left join t1
2323
on ie.stay_id = t1.stay_id;

mimic-iv/concepts/postgres/demographics/weight_durations.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ WITH wt_stg as
1111
else 'daily' end as weight_type
1212
-- TODO: eliminate obvious outliers if there is a reasonable weight
1313
, c.valuenum as weight
14-
FROM mimic_icu.chartevents c
14+
FROM mimiciv_icu.chartevents c
1515
WHERE c.valuenum IS NOT NULL
1616
AND c.itemid in
1717
(
@@ -44,7 +44,7 @@ WITH wt_stg as
4444
else wt_stg1.charttime end as starttime
4545
, wt_stg1.weight
4646
from wt_stg1
47-
INNER JOIN mimic_icu.icustays ie
47+
INNER JOIN mimiciv_icu.icustays ie
4848
on ie.stay_id = wt_stg1.stay_id
4949
)
5050
, wt_stg3 as
@@ -89,7 +89,7 @@ WITH wt_stg as
8989
, wt.starttime as endtime
9090
, wt.weight
9191
, wt.weight_type
92-
from mimic_icu.icustays ie
92+
from mimiciv_icu.icustays ie
9393
inner join
9494
-- the below subquery returns one row for each unique stay_id
9595
-- the row contains: the first starttime and the corresponding weight

mimic-iv/concepts/postgres/firstday/first_day_bg.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ select
2525
, MIN(glucose) AS glucose_min, MAX(glucose) AS glucose_max
2626
, MIN(potassium) AS potassium_min, MAX(potassium) AS potassium_max
2727
, MIN(sodium) AS sodium_min, MAX(sodium) AS sodium_max
28-
FROM mimic_icu.icustays ie
29-
LEFT JOIN mimic_derived.bg bg
28+
FROM mimiciv_icu.icustays ie
29+
LEFT JOIN mimiciv_derived.bg bg
3030
ON ie.subject_id = bg.subject_id
3131
AND bg.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR)
3232
AND bg.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)

mimic-iv/concepts/postgres/firstday/first_day_bg_art.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ select
2525
, MIN(glucose) AS glucose_min, MAX(glucose) AS glucose_max
2626
, MIN(potassium) AS potassium_min, MAX(potassium) AS potassium_max
2727
, MIN(sodium) AS sodium_min, MAX(sodium) AS sodium_max
28-
FROM mimic_icu.icustays ie
29-
LEFT JOIN mimic_derived.bg bg
28+
FROM mimiciv_icu.icustays ie
29+
LEFT JOIN mimiciv_derived.bg bg
3030
ON ie.subject_id = bg.subject_id
3131
AND bg.specimen = 'ART.'
3232
AND bg.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR)

mimic-iv/concepts/postgres/firstday/first_day_gcs.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ WITH gcs_final AS
2323
PARTITION BY gcs.stay_id
2424
ORDER BY gcs.GCS
2525
) as gcs_seq
26-
FROM mimic_derived.gcs gcs
26+
FROM mimiciv_derived.gcs gcs
2727
)
2828
SELECT
2929
ie.subject_id
@@ -35,7 +35,7 @@ SELECT
3535
, gcs_verbal
3636
, gcs_eyes
3737
, gcs_unable
38-
FROM mimic_icu.icustays ie
38+
FROM mimiciv_icu.icustays ie
3939
LEFT JOIN gcs_final gs
4040
ON ie.stay_id = gs.stay_id
4141
AND gs.gcs_seq = 1

mimic-iv/concepts/postgres/firstday/first_day_height.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ WITH ce AS
1111
SELECT
1212
c.stay_id
1313
, AVG(valuenum) as Height_chart
14-
FROM mimic_icu.chartevents c
15-
INNER JOIN mimic_icu.icustays ie ON
14+
FROM mimiciv_icu.chartevents c
15+
INNER JOIN mimiciv_icu.icustays ie ON
1616
c.stay_id = ie.stay_id
1717
AND c.charttime BETWEEN DATETIME_SUB(ie.intime, INTERVAL '1' DAY) AND DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
1818
WHERE c.valuenum IS NOT NULL
@@ -24,8 +24,8 @@ SELECT
2424
ie.subject_id
2525
, ie.stay_id
2626
, ROUND( CAST( AVG(height) as numeric),2) AS height
27-
FROM mimic_icu.icustays ie
28-
LEFT JOIN mimic_derived.height ht
27+
FROM mimiciv_icu.icustays ie
28+
LEFT JOIN mimiciv_derived.height ht
2929
ON ie.stay_id = ht.stay_id
3030
AND ht.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR)
3131
AND ht.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)

0 commit comments

Comments
 (0)