Skip to content

Commit 9dc14f3

Browse files
committed
apply sqlfluff fix to concepts using repo config
1 parent 5326128 commit 9dc14f3

Some content is hidden

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

61 files changed

+5742
-5049
lines changed

mimic-iv/concepts/comorbidity/charlson.sql

+217-134
Large diffs are not rendered by default.

mimic-iv/concepts/demographics/age.sql

+11-9
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
-- an admission in 2155 will occur in 2010-2012, and so on.
1616

1717
-- Therefore, the age of a patient = hospital admission time - anchor_year + anchor_age
18-
SELECT
19-
ad.subject_id
20-
, ad.hadm_id
21-
, ad.admittime
22-
, pa.anchor_age
23-
, pa.anchor_year
24-
, DATETIME_DIFF(ad.admittime, DATETIME(pa.anchor_year, 1, 1, 0, 0, 0), YEAR) + pa.anchor_age AS age
18+
SELECT
19+
ad.subject_id
20+
, ad.hadm_id
21+
, ad.admittime
22+
, pa.anchor_age
23+
, 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
2527
FROM `physionet-data.mimiciv_hosp.admissions` ad
2628
INNER JOIN `physionet-data.mimiciv_hosp.patients` pa
27-
ON ad.subject_id = pa.subject_id
28-
;
29+
ON ad.subject_id = pa.subject_id
30+
;

mimic-iv/concepts/demographics/icustay_detail.sql

+34-20
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
11
SELECT ie.subject_id, ie.hadm_id, ie.stay_id
22

3-
-- patient level factors
4-
, pat.gender, pat.dod
3+
-- patient level factors
4+
, pat.gender, pat.dod
55

6-
-- hospital level factors
7-
, adm.admittime, adm.dischtime
8-
, DATETIME_DIFF(adm.dischtime, adm.admittime, DAY) as los_hospital
9-
, DATETIME_DIFF(adm.admittime, DATETIME(pat.anchor_year, 1, 1, 0, 0, 0), YEAR) + pat.anchor_age as admission_age
10-
, adm.race
11-
, adm.hospital_expire_flag
12-
, DENSE_RANK() OVER (PARTITION BY adm.subject_id ORDER BY adm.admittime) AS hospstay_seq
13-
, CASE
14-
WHEN DENSE_RANK() OVER (PARTITION BY adm.subject_id ORDER BY adm.admittime) = 1 THEN True
15-
ELSE False END AS first_hosp_stay
6+
-- hospital level factors
7+
, adm.admittime, adm.dischtime
8+
, 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
12+
, adm.race
13+
, adm.hospital_expire_flag
14+
, DENSE_RANK() OVER (
15+
PARTITION BY adm.subject_id ORDER BY adm.admittime
16+
) AS hospstay_seq
17+
, CASE
18+
WHEN
19+
DENSE_RANK() OVER (
20+
PARTITION BY adm.subject_id ORDER BY adm.admittime
21+
) = 1 THEN True
22+
ELSE False END AS first_hosp_stay
1623

17-
-- icu level factors
18-
, ie.intime as icu_intime, ie.outtime as icu_outtime
19-
, ROUND(CAST(DATETIME_DIFF(ie.outtime, ie.intime, HOUR)/24.0 AS NUMERIC), 2) as los_icu
20-
, DENSE_RANK() OVER (PARTITION BY ie.hadm_id ORDER BY ie.intime) AS icustay_seq
24+
-- icu level factors
25+
, ie.intime AS icu_intime, ie.outtime AS icu_outtime
26+
, ROUND(
27+
CAST(DATETIME_DIFF(ie.outtime, ie.intime, HOUR) / 24.0 AS NUMERIC), 2
28+
) AS los_icu
29+
, DENSE_RANK() OVER (
30+
PARTITION BY ie.hadm_id ORDER BY ie.intime
31+
) AS icustay_seq
2132

22-
-- first ICU stay *for the current hospitalization*
23-
, CASE
24-
WHEN DENSE_RANK() OVER (PARTITION BY ie.hadm_id ORDER BY ie.intime) = 1 THEN True
25-
ELSE False END AS first_icu_stay
33+
-- first ICU stay *for the current hospitalization*
34+
, CASE
35+
WHEN
36+
DENSE_RANK() OVER (
37+
PARTITION BY ie.hadm_id ORDER BY ie.intime
38+
) = 1 THEN True
39+
ELSE False END AS first_icu_stay
2640

2741
FROM `physionet-data.mimiciv_icu.icustays` ie
2842
INNER JOIN `physionet-data.mimiciv_hosp.admissions` adm

mimic-iv/concepts/demographics/icustay_hourly.sql

+23-22
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,31 @@
77
-- this table can be to other tables on ICUSTAY_ID and (ENDTIME - 1 hour,ENDTIME]
88

99
-- get first/last measurement time
10-
with all_hours as
11-
(
12-
select
13-
it.stay_id
10+
WITH all_hours AS (
11+
SELECT
12+
it.stay_id
1413

15-
-- ceiling the intime to the nearest hour by adding 59 minutes then truncating
16-
-- note thart we truncate by parsing as string, rather than using DATETIME_TRUNC
17-
-- this is done to enable compatibility with psql
18-
, PARSE_DATETIME(
19-
'%Y-%m-%d %H:00:00',
20-
FORMAT_DATETIME(
21-
'%Y-%m-%d %H:00:00',
22-
DATETIME_ADD(it.intime_hr, INTERVAL '59' MINUTE)
23-
)) AS endtime
14+
-- ceiling the intime to the nearest hour by adding 59 minutes then truncating
15+
-- note thart we truncate by parsing as string, rather than using DATETIME_TRUNC
16+
-- this is done to enable compatibility with psql
17+
, PARSE_DATETIME(
18+
'%Y-%m-%d %H:00:00'
19+
, FORMAT_DATETIME(
20+
'%Y-%m-%d %H:00:00'
21+
, DATETIME_ADD(it.intime_hr, INTERVAL '59' MINUTE)
22+
)) AS endtime
2423

25-
-- create integers for each charttime in hours from admission
26-
-- so 0 is admission time, 1 is one hour after admission, etc, up to ICU disch
27-
-- we allow 24 hours before ICU admission (to grab labs before admit)
28-
, GENERATE_ARRAY(-24, CEIL(DATETIME_DIFF(it.outtime_hr, it.intime_hr, HOUR))) as hrs
29-
30-
from `physionet-data.mimiciv_derived.icustay_times` it
24+
-- create integers for each charttime in hours from admission
25+
-- so 0 is admission time, 1 is one hour after admission, etc, up to ICU disch
26+
-- 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
30+
FROM `physionet-data.mimiciv_derived.icustay_times` it
3131
)
32+
3233
SELECT stay_id
33-
, CAST(hr AS INT64) as hr
34-
, DATETIME_ADD(endtime, INTERVAL CAST(hr AS INT64) HOUR) as endtime
34+
, CAST(hr AS INT64) AS hr
35+
, DATETIME_ADD(endtime, INTERVAL CAST(hr AS INT64) HOUR) AS endtime
3536
FROM all_hours
36-
CROSS JOIN UNNEST(all_hours.hrs) AS hr;
37+
CROSS JOIN UNNEST(all_hours.hrs) AS hr;
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
-- create a table which has fuzzy boundaries on hospital admission
22
-- involves first creating a lag/lead version of disch/admit time
33
-- get first/last heart rate measurement during hospitalization for each stay_id
4-
WITH t1 AS
5-
(
6-
select ce.stay_id
7-
, min(charttime) as intime_hr
8-
, max(charttime) as outtime_hr
4+
WITH t1 AS (
5+
SELECT ce.stay_id
6+
, MIN(charttime) AS intime_hr
7+
, MAX(charttime) AS outtime_hr
98
FROM `physionet-data.mimiciv_icu.chartevents` ce
109
-- only look at heart rate
11-
where ce.itemid = 220045
12-
group by ce.stay_id
10+
WHERE ce.itemid = 220045
11+
GROUP BY ce.stay_id
1312
)
13+
1414
-- add in subject_id/hadm_id
15-
select
16-
ie.subject_id, ie.hadm_id, ie.stay_id
17-
, t1.intime_hr
18-
, t1.outtime_hr
15+
SELECT
16+
ie.subject_id, ie.hadm_id, ie.stay_id
17+
, t1.intime_hr
18+
, t1.outtime_hr
1919
FROM `physionet-data.mimiciv_icu.icustays` ie
20-
left join t1
21-
on ie.stay_id = t1.stay_id;
20+
LEFT JOIN t1
21+
ON ie.stay_id = t1.stay_id;

0 commit comments

Comments
 (0)