Skip to content

Commit 2711b63

Browse files
committed
append union statement for crrt
1 parent 86a3515 commit 2711b63

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

mimic-iv/concepts/organfailure/kdigo_stages.sql

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33
-- Baseline creatinine is defined as the lowest creatinine in the past 7 days.
44

55
-- get creatinine stages
6-
with cr_stg AS
6+
WITH cr_stg AS
77
(
88
SELECT
99
cr.stay_id
1010
, cr.charttime
1111
, cr.creat_low_past_7day
1212
, cr.creat_low_past_48hr
1313
, cr.creat
14-
, case
14+
, CASE
1515
-- 3x baseline
16-
when cr.creat >= (cr.creat_low_past_7day*3.0) then 3
16+
WHEN cr.creat >= (cr.creat_low_past_7day*3.0) THEN 3
1717
-- *OR* cr >= 4.0 with associated increase
18-
when cr.creat >= 4
18+
WHEN cr.creat >= 4
1919
-- For patients reaching Stage 3 by SCr >4.0 mg/dl
2020
-- require that the patient first achieve ... acute increase >= 0.3 within 48 hr
2121
-- *or* an increase of >= 1.5 times baseline
22-
and (cr.creat_low_past_48hr <= 3.7 OR cr.creat >= (1.5*cr.creat_low_past_7day))
23-
then 3
22+
AND (cr.creat_low_past_48hr <= 3.7 OR cr.creat >= (1.5*cr.creat_low_past_7day))
23+
THEN 3
2424
-- TODO: initiation of RRT
25-
when cr.creat >= (cr.creat_low_past_7day*2.0) then 2
26-
when cr.creat >= (cr.creat_low_past_48hr+0.3) then 1
27-
when cr.creat >= (cr.creat_low_past_7day*1.5) then 1
28-
else 0 end as aki_stage_creat
25+
WHEN cr.creat >= (cr.creat_low_past_7day*2.0) THEN 2
26+
WHEN cr.creat >= (cr.creat_low_past_48hr+0.3) THEN 1
27+
WHEN cr.creat >= (cr.creat_low_past_7day*1.5) THEN 1
28+
ELSE 0 END AS aki_stage_creat
2929
FROM `physionet-data.mimiciv_derived.kdigo_creatinine`
3030
)
3131
-- stages for UO / creat
32-
, uo_stg as
32+
, uo_stg AS
3333
(
34-
select
34+
SELECT
3535
uo.stay_id
3636
, uo.charttime
3737
, uo.weight
@@ -53,6 +53,16 @@ with cr_stg AS
5353
FROM `physionet-data.mimiciv_derived.kdigo_uo` uo
5454
INNER JOIN `physionet-data.mimiciv_icu.icustays` ie
5555
ON uo.stay_id = ie.stay_id
56+
),
57+
-- get CRRT data
58+
crrt_stg AS (
59+
SELECT
60+
stay_id,
61+
charttime,
62+
CASE
63+
WHEN charttime IS NOT NULL THEN 3
64+
ELSE NULL END AS aki_stage_crrt
65+
FROM `physionet-data.mimic_derived.crrt`
5666
)
5767
-- get all charttimes documented
5868
, tm_stg AS
@@ -64,18 +74,13 @@ with cr_stg AS
6474
SELECT
6575
stay_id, charttime
6676
FROM uo_stg
67-
),
68-
-- get CRRT data
69-
crrt_stg AS (
70-
SELECT
71-
stay_id,
72-
charttime,
73-
CASE
74-
WHEN charttime IS NOT NULL THEN 3
75-
ELSE NULL END AS aki_stage_crrt
76-
FROM `physionet-data.mimic_derived.crrt`
77+
UNION DISTINCT
78+
SELECT
79+
stay_id, charttime
80+
FROM crrt_stg
81+
7782
)
78-
select
83+
SELECT
7984
ie.subject_id
8085
, ie.hadm_id
8186
, ie.stay_id

0 commit comments

Comments
 (0)