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

Diff for: mimic-iv/concepts/demographics/age.sql

+5-3
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

Diff for: mimic-iv/concepts/demographics/icustay_detail.sql

+5-3
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 (

Diff for: mimic-iv/concepts/demographics/icustay_hourly.sql

+1-3
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

Diff for: mimic-iv/concepts/firstday/first_day_height.sql

+4-5
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

Diff for: mimic-iv/concepts/measurement/bg.sql

+5-6
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

Diff for: mimic-iv/concepts/organfailure/kdigo_creatinine.sql

+5-6
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

Diff for: mimic-iv/concepts/organfailure/kdigo_stages.sql

+9-11
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
;

Diff for: mimic-iv/concepts/organfailure/kdigo_uo.sql

+4-10
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
;

Diff for: mimic-iv/concepts/score/apsiii.sql

+10-7
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

Diff for: mimic-iv/concepts/score/lods.sql

+2-3
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%'

Diff for: mimic-iv/concepts/score/oasis.sql

+10-7
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,21 @@ WITH surgflag AS (
4747
FROM `physionet-data.mimiciv_icu.icustays` ie
4848
LEFT JOIN `physionet-data.mimiciv_derived.ventilation` v
4949
ON ie.stay_id = v.stay_id
50+
AND v.ventilation_status = 'InvasiveVent'
5051
AND (
51-
v.starttime BETWEEN ie.intime AND DATETIME_ADD(
52-
ie.intime, INTERVAL '1' DAY
52+
(
53+
v.starttime >= ie.intime
54+
AND v.starttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
5355
)
54-
OR v.endtime BETWEEN ie.intime AND DATETIME_ADD(
55-
ie.intime, INTERVAL '1' DAY
56+
OR (
57+
v.endtime >= ie.intime
58+
AND v.endtime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
5659
)
57-
OR v.starttime <= ie.intime AND v.endtime >= DATETIME_ADD(
58-
ie.intime, INTERVAL '1' DAY
60+
OR (
61+
v.starttime <= ie.intime
62+
AND v.endtime >= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
5963
)
6064
)
61-
AND v.ventilation_status = 'InvasiveVent'
6265
GROUP BY ie.stay_id
6366
)
6467

Diff for: mimic-iv/concepts/score/sapsii.sql

+15-15
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ WITH co AS (
217217
, MAX(vital.temperature) AS tempc_max
218218
FROM co
219219
LEFT JOIN `physionet-data.mimiciv_derived.vitalsign` vital
220-
ON co.subject_id = vital.subject_id
221-
AND co.starttime < vital.charttime
222-
AND co.endtime >= vital.charttime
220+
ON co.subject_id = vital.subject_id
221+
AND co.starttime < vital.charttime
222+
AND co.endtime >= vital.charttime
223223
GROUP BY co.stay_id
224224
)
225225

@@ -229,9 +229,9 @@ WITH co AS (
229229
, SUM(uo.urineoutput) AS urineoutput
230230
FROM co
231231
LEFT JOIN `physionet-data.mimiciv_derived.urine_output` uo
232-
ON co.stay_id = uo.stay_id
233-
AND co.starttime < uo.charttime
234-
AND co.endtime >= uo.charttime
232+
ON co.stay_id = uo.stay_id
233+
AND co.starttime < uo.charttime
234+
AND co.endtime >= uo.charttime
235235
GROUP BY co.stay_id
236236
)
237237

@@ -248,9 +248,9 @@ WITH co AS (
248248
, MAX(labs.bicarbonate) AS bicarbonate_max
249249
FROM co
250250
LEFT JOIN `physionet-data.mimiciv_derived.chemistry` labs
251-
ON co.subject_id = labs.subject_id
252-
AND co.starttime < labs.charttime
253-
AND co.endtime >= labs.charttime
251+
ON co.subject_id = labs.subject_id
252+
AND co.starttime < labs.charttime
253+
AND co.endtime >= labs.charttime
254254
GROUP BY co.stay_id
255255
)
256256

@@ -261,9 +261,9 @@ WITH co AS (
261261
, MAX(cbc.wbc) AS wbc_max
262262
FROM co
263263
LEFT JOIN `physionet-data.mimiciv_derived.complete_blood_count` cbc
264-
ON co.subject_id = cbc.subject_id
265-
AND co.starttime < cbc.charttime
266-
AND co.endtime >= cbc.charttime
264+
ON co.subject_id = cbc.subject_id
265+
AND co.starttime < cbc.charttime
266+
AND co.endtime >= cbc.charttime
267267
GROUP BY co.stay_id
268268
)
269269

@@ -274,9 +274,9 @@ WITH co AS (
274274
, MAX(enz.bilirubin_total) AS bilirubin_max
275275
FROM co
276276
LEFT JOIN `physionet-data.mimiciv_derived.enzyme` enz
277-
ON co.subject_id = enz.subject_id
278-
AND co.starttime < enz.charttime
279-
AND co.endtime >= enz.charttime
277+
ON co.subject_id = enz.subject_id
278+
AND co.starttime < enz.charttime
279+
AND co.endtime >= enz.charttime
280280
GROUP BY co.stay_id
281281
)
282282

Diff for: mimic-iv/concepts/sepsis/suspicion_of_infection.sql

+2-6
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,14 @@ WITH ab_tbl AS (
113113
(
114114
-- if charttime is available, use it
115115
me24.charttime IS NOT NULL
116-
AND ab_tbl.antibiotic_time >= DATETIME_SUB(
117-
me24.charttime, INTERVAL 24 HOUR
118-
)
116+
AND ab_tbl.antibiotic_time >= DATETIME_SUB(me24.charttime, INTERVAL 24 HOUR) -- noqa: L016
119117
AND ab_tbl.antibiotic_time < me24.charttime
120118
)
121119
OR
122120
(
123121
-- if charttime is not available, use chartdate
124122
me24.charttime IS NULL
125-
AND ab_tbl.antibiotic_date >= DATE_SUB(
126-
me24.chartdate, INTERVAL 1 DAY
127-
)
123+
AND ab_tbl.antibiotic_date >= DATE_SUB(me24.chartdate, INTERVAL 1 DAY) -- noqa: L016
128124
AND ab_tbl.antibiotic_date <= me24.chartdate
129125
)
130126
)

0 commit comments

Comments
 (0)