Skip to content

Commit 1e0b3ba

Browse files
author
Alistair Johnson
committed
update with compatibility fixes
1 parent edd4769 commit 1e0b3ba

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ WITH cbc AS
4646
(
4747
SELECT
4848
ie.stay_id
49-
, MIN(abs_basophils) AS abs_basophils_min, MAX(abs_basophils) AS abs_basophils_max
50-
, MIN(abs_eosinophils) AS abs_eosinophils_min, MAX(abs_eosinophils) AS abs_eosinophils_max
51-
, MIN(abs_lymphocytes) AS abs_lymphocytes_min, MAX(abs_lymphocytes) AS abs_lymphocytes_max
52-
, MIN(abs_monocytes) AS abs_monocytes_min, MAX(abs_monocytes) AS abs_monocytes_max
53-
, MIN(abs_neutrophils) AS abs_neutrophils_min, MAX(abs_neutrophils) AS abs_neutrophils_max
54-
, MIN(atyps) AS atyps_min, MAX(atyps) AS atyps_max
49+
, MIN(basophils_abs) AS abs_basophils_min, MAX(basophils_abs) AS abs_basophils_max
50+
, MIN(eosinophils_abs) AS abs_eosinophils_min, MAX(eosinophils_abs) AS abs_eosinophils_max
51+
, MIN(lymphocytes_abs) AS abs_lymphocytes_min, MAX(lymphocytes_abs) AS abs_lymphocytes_max
52+
, MIN(monocytes_abs) AS abs_monocytes_min, MAX(monocytes_abs) AS abs_monocytes_max
53+
, MIN(neutrophils_abs) AS abs_neutrophils_min, MAX(neutrophils_abs) AS abs_neutrophils_max
54+
, MIN(atypical_lymphocytes) AS atyps_min, MAX(atypical_lymphocytes) AS atyps_max
5555
, MIN(bands) AS bands_min, MAX(bands) AS bands_max
56-
, MIN(imm_granulocytes) AS imm_granulocytes_min, MAX(imm_granulocytes) AS imm_granulocytes_max
57-
, MIN(metas) AS metas_min, MAX(metas) AS metas_max
56+
, MIN(immature_granulocytes) AS imm_granulocytes_min, MAX(immature_granulocytes) AS imm_granulocytes_max
57+
, MIN(metamyelocytes) AS metas_min, MAX(metamyelocytes) AS metas_max
5858
, MIN(nrbc) AS nrbc_min, MAX(nrbc) AS nrbc_max
5959
FROM mimic_icu.icustays ie
6060
LEFT JOIN mimic_derived.blood_differential le
@@ -84,7 +84,7 @@ WITH cbc AS
8484
(
8585
SELECT
8686
ie.stay_id
87-
87+
8888
, MIN(alt) AS alt_min, MAX(alt) AS alt_max
8989
, MIN(alp) AS alp_min, MAX(alp) AS alp_max
9090
, MIN(ast) AS ast_min, MAX(ast) AS ast_max
@@ -165,4 +165,4 @@ LEFT JOIN coag
165165
ON ie.stay_id = coag.stay_id
166166
LEFT JOIN enz
167167
ON ie.stay_id = enz.stay_id
168-
;
168+
;

mimic-iv/concepts/postgres/measurement/bg.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ DROP TABLE IF EXISTS bg; CREATE TABLE bg AS
44
-- which were found in LABEVENTS
55
WITH bg AS
66
(
7-
select
7+
select
88
-- specimen_id only ever has 1 measurement for each itemid
99
-- so, we may simply collapse rows using MAX()
1010
MAX(subject_id) AS subject_id
@@ -32,7 +32,7 @@ select
3232
-- usually this is a misplaced O2 flow measurement
3333
, MAX(CASE WHEN itemid = 50816 THEN
3434
CASE
35-
WHEN valuenum > 20 AND valuenum <= 100 THEN valuenum
35+
WHEN valuenum > 20 AND valuenum <= 100 THEN valuenum
3636
WHEN valuenum > 0.2 AND valuenum <= 1.0 THEN valuenum*100.0
3737
ELSE NULL END
3838
ELSE NULL END) AS fio2
@@ -159,7 +159,7 @@ select
159159
, stg3.hadm_id
160160
, stg3.charttime
161161
-- raw data indicating sample type
162-
, specimen
162+
, specimen
163163
-- prediction of specimen for obs missing the actual specimen
164164
, case
165165
when specimen is not null then specimen

mimic-iv/concepts/postgres/measurement/gcs.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ DROP TABLE IF EXISTS gcs; CREATE TABLE gcs AS
2323
-- or by reviewing the patient's medical record.
2424
with base as
2525
(
26-
select
26+
select
2727
subject_id
2828
, ce.stay_id, ce.charttime
2929
-- pivot each value into its own column
3030
, max(case when ce.ITEMID = 223901 then ce.valuenum else null end) as GCSMotor
3131
, max(case
3232
when ce.ITEMID = 223900 and ce.VALUE = 'No Response-ETT' then 0
3333
when ce.ITEMID = 223900 then ce.valuenum
34-
else null
34+
else null
3535
end) as GCSVerbal
3636
, max(case when ce.ITEMID = 220739 then ce.valuenum else null end) as GCSEyes
3737
-- convert the data into a number, reserving a value of 0 for ET/Trach
@@ -111,7 +111,7 @@ with base as
111111
-- (i) complete data, (ii) non-sedated GCS, (iii) lowest GCS, (iv) charttime
112112
, gcs_priority as
113113
(
114-
select
114+
select
115115
subject_id
116116
, stay_id
117117
, charttime
@@ -138,4 +138,4 @@ select
138138
, EndoTrachFlag AS gcs_unable
139139
from gcs_priority gs
140140
where rn = 1
141-
;
141+
;

mimic-iv/concepts/postgres/measurement/urine_output_rate.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ WITH tm AS
1313
INNER JOIN mimic_icu.chartevents ce
1414
ON ie.stay_id = ce.stay_id
1515
AND ce.itemid = 220045
16-
AND ce.charttime > DATETIME_SUB(ie.intime, INTERVAL '1' MONTH)
17-
AND ce.charttime < DATETIME_ADD(ie.outtime, INTERVAL '1' MONTH)
16+
AND ce.charttime > DATETIME_SUB(ie.intime, interval '1' MONTH)
17+
AND ce.charttime < DATETIME_ADD(ie.outtime, interval '1' MONTH)
1818
GROUP BY ie.stay_id
1919
)
2020
-- now calculate time since last UO measurement
@@ -92,4 +92,4 @@ LEFT JOIN mimic_derived.weight_durations wd
9292
AND ur.charttime > wd.starttime
9393
AND ur.charttime <= wd.endtime
9494
AND wd.weight > 0
95-
;
95+
;

mimic-iv/concepts/postgres/organfailure/kdigo_uo.sql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ with ur_stg as
2626
, sum(iosum.urineoutput) as UrineOutput_24hr
2727

2828
-- calculate the number of hours over which we've tabulated UO
29-
, ROUND( CAST( CAST(
30-
DATETIME_DIFF(io.charttime as numeric),
29+
, ROUND(CAST(
30+
DATETIME_DIFF(io.charttime,
3131
-- below MIN() gets the earliest time that was used in the summation
3232
MIN(case when iosum.charttime >= DATETIME_SUB(io.charttime, interval '5' hour)
3333
then iosum.charttime
3434
else null end),
3535
'SECOND') AS NUMERIC)/3600.0, 4)
3636
AS uo_tm_6hr
3737
-- repeat extraction for 12 hours and 24 hours
38-
, ROUND( CAST( CAST(
38+
, ROUND(CAST(
3939
DATETIME_DIFF(io.charttime,
40-
MIN(case when iosum.charttime >= DATETIME_SUB(io.charttime as numeric),interval '11' hour)
40+
MIN(case when iosum.charttime >= DATETIME_SUB(io.charttime, interval '11' hour)
4141
then iosum.charttime
4242
else null end),
4343
'SECOND') AS NUMERIC)/3600.0, 4)
4444
AS uo_tm_12hr
45-
, ROUND( CAST( CAST(
45+
, ROUND(CAST(
4646
DATETIME_DIFF(io.charttime,MIN(iosum.charttime),'SECOND')
47-
AS NUMERIC)/3600.0 as numeric),4) AS uo_tm_24hr
47+
AS NUMERIC)/3600.0, 4) AS uo_tm_24hr
4848
from mimic_derived.urine_output io
4949
-- this join gives all UO measurements over the 24 hours preceding this row
5050
left join mimic_derived.urine_output iosum
@@ -61,9 +61,9 @@ select
6161
, ur.urineoutput_12hr
6262
, ur.urineoutput_24hr
6363
-- calculate rates - adding 1 hour as we assume data charted at 10:00 corresponds to previous hour
64-
, ROUND( CAST( CAST((ur.UrineOutput_6hr/wd.weight/(uo_tm_6hr+1)) AS NUMERIC) as numeric),4) AS uo_rt_6hr
65-
, ROUND( CAST( CAST((ur.UrineOutput_12hr/wd.weight/(uo_tm_12hr+1)) AS NUMERIC) as numeric),4) AS uo_rt_12hr
66-
, ROUND( CAST( CAST((ur.UrineOutput_24hr/wd.weight/(uo_tm_24hr+1)) AS NUMERIC) as numeric),4) AS uo_rt_24hr
64+
, ROUND(CAST((ur.UrineOutput_6hr/wd.weight/(uo_tm_6hr+1)) AS NUMERIC), 4) AS uo_rt_6hr
65+
, ROUND(CAST((ur.UrineOutput_12hr/wd.weight/(uo_tm_12hr+1)) AS NUMERIC), 4) AS uo_rt_12hr
66+
, ROUND(CAST((ur.UrineOutput_24hr/wd.weight/(uo_tm_24hr+1)) AS NUMERIC), 4) AS uo_rt_24hr
6767
-- number of hours between current UO time and earliest charted UO within the X hour window
6868
, uo_tm_6hr
6969
, uo_tm_12hr

mimic-iv/concepts/postgres/sepsis/sepsis3.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ WITH sofa AS
2323
)
2424
, s1 as
2525
(
26-
SELECT
26+
SELECT
2727
soi.subject_id
2828
, soi.stay_id
2929
-- suspicion columns
@@ -42,7 +42,7 @@ WITH sofa AS
4242
-- All rows have an associated suspicion of infection event
4343
-- Therefore, Sepsis-3 is defined as SOFA >= 2.
4444
-- Implicitly, the baseline SOFA score is assumed to be zero, as we do not know
45-
-- if the patient has preexisting (acute or chronic) organ dysfunction
45+
-- if the patient has preexisting (acute or chronic) organ dysfunction
4646
-- before the onset of infection.
4747
, sofa_score >= 2 and suspected_infection = 1 as sepsis3
4848
-- subselect to the earliest suspicion/antibiotic/SOFA row
@@ -53,13 +53,13 @@ WITH sofa AS
5353
) AS rn_sus
5454
FROM mimic_derived.suspicion_of_infection as soi
5555
INNER JOIN sofa
56-
ON soi.stay_id = sofa.stay_id
56+
ON soi.stay_id = sofa.stay_id
5757
AND sofa.endtime >= DATETIME_SUB(soi.suspected_infection_time, INTERVAL '48' HOUR)
5858
AND sofa.endtime <= DATETIME_ADD(soi.suspected_infection_time, INTERVAL '24' HOUR)
5959
-- only include in-ICU rows
6060
WHERE soi.stay_id is not null
6161
)
62-
SELECT
62+
SELECT
6363
subject_id, stay_id
6464
-- note: there may be more than one antibiotic given at this time
6565
, antibiotic_time

mimic-iv/concepts/postgres/sepsis/suspicion_of_infection.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ WITH ab_tbl AS
99
, abx.antibiotic
1010
, abx.starttime AS antibiotic_time
1111
-- date is used to match microbiology cultures with only date available
12-
, DATETIME_TRUNC(abx.starttime, DAY) AS antibiotic_date
12+
, DATE_TRUNC('DAY', abx.starttime) AS antibiotic_date
1313
, abx.stoptime AS antibiotic_stoptime
1414
-- create a unique identifier for each patient antibiotic
1515
, ROW_NUMBER() OVER
@@ -43,7 +43,7 @@ WITH ab_tbl AS
4343
, ab_tbl.ab_id
4444

4545
, me72.micro_specimen_id
46-
, coalesce(me72.charttime, CAST(me72.chartdate AS DATETIME)) as last72_charttime
46+
, coalesce(me72.charttime, DATETIME(me72.chartdate)) as last72_charttime
4747
, me72.positiveculture as last72_positiveculture
4848
, me72.spec_type_desc as last72_specimen
4949

@@ -85,7 +85,7 @@ WITH ab_tbl AS
8585
, ab_tbl.ab_id
8686

8787
, me24.micro_specimen_id
88-
, COALESCE(me24.charttime, CAST(me24.chartdate AS DATETIME)) as next24_charttime
88+
, COALESCE(me24.charttime, DATETIME(me24.chartdate)) as next24_charttime
8989
, me24.positiveculture as next24_positiveculture
9090
, me24.spec_type_desc as next24_specimen
9191

0 commit comments

Comments
 (0)