Skip to content

Commit 76289ce

Browse files
committed
reformat and add noqa comments where needed
This is primarily to ensure the convert to PostgreSQL shell script continues to work by allowing long file lines.
1 parent 9dc14f3 commit 76289ce

File tree

13 files changed

+77
-85
lines changed

13 files changed

+77
-85
lines changed

mimic-iv/concepts/demographics/age.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ SELECT
2121
, ad.admittime
2222
, pa.anchor_age
2323
, pa.anchor_year
24-
, DATETIME_DIFF(
25-
ad.admittime, DATETIME(pa.anchor_year, 1, 1, 0, 0, 0), YEAR
26-
) + pa.anchor_age AS age
24+
-- calculate the age as anchor_age (60) plus difference between
25+
-- admit year and the anchor year.
26+
-- the noqa retains the extra long line so the
27+
-- convert to postgres bash script works
28+
, pa.anchor_age + DATETIME_DIFF(ad.admittime, DATETIME(pa.anchor_year, 1, 1, 0, 0, 0), YEAR) AS age -- noqa: L016
2729
FROM `physionet-data.mimiciv_hosp.admissions` ad
2830
INNER JOIN `physionet-data.mimiciv_hosp.patients` pa
2931
ON ad.subject_id = pa.subject_id

mimic-iv/concepts/demographics/icustay_detail.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ SELECT ie.subject_id, ie.hadm_id, ie.stay_id
66
-- hospital level factors
77
, adm.admittime, adm.dischtime
88
, DATETIME_DIFF(adm.dischtime, adm.admittime, DAY) AS los_hospital
9-
, DATETIME_DIFF(
10-
adm.admittime, DATETIME(pat.anchor_year, 1, 1, 0, 0, 0), YEAR
11-
) + pat.anchor_age AS admission_age
9+
-- calculate the age as anchor_age (60) plus difference between
10+
-- admit year and the anchor year.
11+
-- the noqa retains the extra long line so the
12+
-- convert to postgres bash script works
13+
, pat.anchor_age + DATETIME_DIFF(adm.admittime, DATETIME(pat.anchor_year, 1, 1, 0, 0, 0), YEAR) AS admission_age -- noqa: L016
1214
, adm.race
1315
, adm.hospital_expire_flag
1416
, DENSE_RANK() OVER (

mimic-iv/concepts/demographics/icustay_hourly.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ WITH all_hours AS (
2424
-- create integers for each charttime in hours from admission
2525
-- so 0 is admission time, 1 is one hour after admission, etc, up to ICU disch
2626
-- we allow 24 hours before ICU admission (to grab labs before admit)
27-
, GENERATE_ARRAY(
28-
-24, CEIL(DATETIME_DIFF(it.outtime_hr, it.intime_hr, HOUR))
29-
) AS hrs
27+
, GENERATE_ARRAY(-24, CEIL(DATETIME_DIFF(it.outtime_hr, it.intime_hr, HOUR))) AS hrs -- noqa: L016
3028
FROM `physionet-data.mimiciv_derived.icustay_times` it
3129
)
3230

mimic-iv/concepts/firstday/first_day_height.sql

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ WITH ce AS (
99
c.stay_id
1010
, AVG(valuenum) AS height_chart
1111
FROM `physionet-data.mimiciv_icu.chartevents` c
12-
INNER JOIN `physionet-data.mimiciv_icu.icustays` ie ON
13-
c.stay_id = ie.stay_id
14-
AND c.charttime BETWEEN DATETIME_SUB(
15-
ie.intime, INTERVAL '1' DAY
16-
) AND DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
12+
INNER JOIN `physionet-data.mimiciv_icu.icustays` ie
13+
ON c.stay_id = ie.stay_id
14+
AND c.charttime >= DATETIME_SUB(ie.intime, INTERVAL '1' DAY)
15+
AND c.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
1716
WHERE c.valuenum IS NOT NULL
1817
AND c.itemid IN (226730) -- height
1918
AND c.valuenum != 0

mimic-iv/concepts/measurement/bg.sql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ WITH bg AS (
155155
-- same hospitalization
156156
ON bg.subject_id = s1.subject_id
157157
-- spo2 occurred at most 2 hours before this blood gas
158-
AND s1.charttime BETWEEN DATETIME_SUB(
159-
bg.charttime, INTERVAL '2' HOUR
160-
) AND bg.charttime
158+
AND s1.charttime
159+
BETWEEN DATETIME_SUB(bg.charttime, INTERVAL '2' HOUR)
160+
AND bg.charttime
161161
WHERE bg.po2 IS NOT NULL
162162
)
163163

@@ -172,9 +172,8 @@ WITH bg AS (
172172
-- same patient
173173
ON bg.subject_id = s2.subject_id
174174
-- fio2 occurred at most 4 hours before this blood gas
175-
AND s2.charttime BETWEEN DATETIME_SUB(
176-
bg.charttime, INTERVAL '4' HOUR
177-
) AND bg.charttime
175+
AND s2.charttime >= DATETIME_SUB(bg.charttime, INTERVAL '4' HOUR)
176+
AND s2.charttime <= bg.charttime
178177
AND s2.fio2_chartevents > 0
179178
-- only the row with the most recent SpO2 (if no SpO2 found lastRowSpO2 = 1)
180179
WHERE bg.lastrowspo2 = 1

mimic-iv/concepts/organfailure/kdigo_creatinine.sql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ WITH cr AS (
1111
AND le.itemid = 50912
1212
AND le.valuenum IS NOT NULL
1313
AND le.valuenum <= 150
14-
AND le.charttime BETWEEN DATETIME_SUB(
15-
ie.intime, INTERVAL '7' DAY
16-
) AND ie.outtime
14+
AND le.charttime >= DATETIME_SUB(ie.intime, INTERVAL '7' DAY)
15+
AND le.charttime <= ie.outtime
1716
GROUP BY ie.hadm_id, ie.stay_id, le.charttime
1817
)
1918

@@ -41,9 +40,9 @@ WITH cr AS (
4140
FROM cr
4241
-- add in all creatinine values in the last 7 days
4342
LEFT JOIN cr cr7
44-
ON cr.stay_id = cr7.stay_id
45-
AND cr7.charttime < cr.charttime
46-
AND cr7.charttime >= DATETIME_SUB(cr.charttime, INTERVAL '7' DAY)
43+
ON cr.stay_id = cr7.stay_id
44+
AND cr7.charttime < cr.charttime
45+
AND cr7.charttime >= DATETIME_SUB(cr.charttime, INTERVAL '7' DAY)
4746
GROUP BY cr.stay_id, cr.charttime
4847
)
4948

mimic-iv/concepts/organfailure/kdigo_stages.sql

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ WITH cr_stg AS (
4545
, CASE
4646
WHEN uo.uo_rt_6hr IS NULL THEN NULL
4747
-- require patient to be in ICU for at least 6 hours to stage UO
48-
WHEN
49-
uo.charttime <= DATETIME_ADD(
50-
ie.intime, INTERVAL '6' HOUR
51-
) THEN 0
48+
WHEN uo.charttime <= DATETIME_ADD(ie.intime, INTERVAL '6' HOUR)
49+
THEN 0
5250
-- require the UO rate to be calculated over duration specified in KDIGO
5351
-- Stage 3: <0.3 ml/kg/h for >=24 hours
5452
WHEN uo.uo_tm_24hr >= 24 AND uo.uo_rt_24hr < 0.3 THEN 3
@@ -141,14 +139,14 @@ SELECT
141139
FROM `physionet-data.mimiciv_icu.icustays` ie
142140
-- get all possible charttimes as listed in tm_stg
143141
LEFT JOIN tm_stg tm
144-
ON ie.stay_id = tm.stay_id
142+
ON ie.stay_id = tm.stay_id
145143
LEFT JOIN cr_stg cr
146-
ON ie.stay_id = cr.stay_id
147-
AND tm.charttime = cr.charttime
144+
ON ie.stay_id = cr.stay_id
145+
AND tm.charttime = cr.charttime
148146
LEFT JOIN uo_stg uo
149-
ON ie.stay_id = uo.stay_id
150-
AND tm.charttime = uo.charttime
147+
ON ie.stay_id = uo.stay_id
148+
AND tm.charttime = uo.charttime
151149
LEFT JOIN crrt_stg crrt
152-
ON ie.stay_id = crrt.stay_id
153-
AND tm.charttime = crrt.charttime
150+
ON ie.stay_id = crrt.stay_id
151+
AND tm.charttime = crrt.charttime
154152
;

mimic-iv/concepts/organfailure/kdigo_uo.sql

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ WITH uo_stg1 AS (
22
SELECT ie.stay_id, uo.charttime
33
, DATETIME_DIFF(charttime, intime, SECOND) AS seconds_since_admit
44
, COALESCE(
5-
DATETIME_DIFF(
6-
charttime
7-
, LAG(
8-
charttime
9-
) OVER (PARTITION BY ie.stay_id ORDER BY charttime)
10-
, SECOND
11-
) / 3600.0
5+
DATETIME_DIFF(charttime, LAG(charttime) OVER (PARTITION BY ie.stay_id ORDER BY charttime), SECOND) / 3600.0 -- noqa: L016
126
, 1
137
) AS hours_since_previous_row
148
, urineoutput
@@ -108,7 +102,7 @@ SELECT
108102
, uo_tm_24hr
109103
FROM uo_stg2 ur
110104
LEFT JOIN `physionet-data.mimiciv_derived.weight_durations` wd
111-
ON ur.stay_id = wd.stay_id
112-
AND ur.charttime >= wd.starttime
113-
AND ur.charttime < wd.endtime
105+
ON ur.stay_id = wd.stay_id
106+
AND ur.charttime >= wd.starttime
107+
AND ur.charttime < wd.endtime
114108
;

mimic-iv/concepts/score/apsiii.sql

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,21 @@ WITH pa AS (
193193
FROM `physionet-data.mimiciv_icu.icustays` ie
194194
LEFT JOIN `physionet-data.mimiciv_derived.ventilation` v
195195
ON ie.stay_id = v.stay_id
196+
AND v.ventilation_status = 'InvasiveVent'
196197
AND (
197-
v.starttime BETWEEN ie.intime AND DATETIME_ADD(
198-
ie.intime, INTERVAL '1' DAY
198+
(
199+
v.starttime >= ie.intime
200+
AND v.starttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
199201
)
200-
OR v.endtime BETWEEN ie.intime AND DATETIME_ADD(
201-
ie.intime, INTERVAL '1' DAY
202+
OR (
203+
v.endtime >= ie.intime
204+
AND v.endtime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
202205
)
203-
OR v.starttime <= ie.intime AND v.endtime >= DATETIME_ADD(
204-
ie.intime, INTERVAL '1' DAY
206+
OR (
207+
v.starttime <= ie.intime
208+
AND v.endtime >= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
205209
)
206210
)
207-
AND v.ventilation_status = 'InvasiveVent'
208211
GROUP BY ie.stay_id
209212
)
210213

mimic-iv/concepts/score/lods.sql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ WITH cpap AS (
3434
FROM `physionet-data.mimiciv_icu.icustays` ie
3535
INNER JOIN `physionet-data.mimiciv_icu.chartevents` ce
3636
ON ie.stay_id = ce.stay_id
37-
AND ce.charttime BETWEEN ie.intime AND DATETIME_ADD(
38-
ie.intime, INTERVAL '1' DAY
39-
)
37+
AND ce.charttime >= ie.intime
38+
AND ce.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
4039
WHERE itemid = 226732
4140
AND (
4241
LOWER(ce.value) LIKE '%cpap%' OR LOWER(ce.value) LIKE '%bipap mask%'

0 commit comments

Comments
 (0)