Skip to content

Commit 3572b0c

Browse files
committed
add missing transpiled concept
1 parent 36d89ee commit 3572b0c

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
2+
DROP TABLE IF EXISTS mimiciv_derived.code_status; CREATE TABLE mimiciv_derived.code_status AS
3+
/* This query extracts code status with the time at which the */ /* code status was documented. */
4+
WITH t1 AS (
5+
/*
6+
There are five distinct values for the code status order in the ICU data:
7+
1 DNR / DNI
8+
2 DNI (do not intubate)
9+
3 Comfort measures only
10+
4 Full code
11+
5 DNR (do not resuscitate)
12+
*/
13+
SELECT
14+
subject_id,
15+
hadm_id,
16+
stay_id,
17+
charttime, /* coalesce the values */
18+
CASE WHEN value IN ('Full code') THEN 1 ELSE 0 END AS fullcode,
19+
CASE WHEN value IN ('Comfort measures only') THEN 1 ELSE 0 END AS cmo,
20+
CASE WHEN value IN ('DNI (do not intubate)', 'DNR / DNI') THEN 1 ELSE 0 END AS dni,
21+
CASE WHEN value IN ('DNR (do not resuscitate)', 'DNR / DNI') THEN 1 ELSE 0 END AS dnr
22+
FROM mimiciv_icu.chartevents
23+
WHERE
24+
itemid IN (223758)
25+
), poe /* Provider order entry contains hospital wide orders for code status changes */ /* Interestingly, it does not contain comfort measures only orders */ AS (
26+
SELECT
27+
p.subject_id,
28+
p.hadm_id,
29+
ie.stay_id,
30+
p.ordertime,
31+
CASE
32+
WHEN pd.field_value = 'Resuscitate (Full code)'
33+
THEN 1
34+
WHEN pd.field_value = 'Full code (attempt resuscitation)'
35+
THEN 1
36+
ELSE 0
37+
END AS fullcode,
38+
CASE
39+
WHEN pd.field_value = 'DNAR (DO NOT attempt resuscitation for cardiac arrest) '
40+
THEN 1 /* noqa */
41+
WHEN pd.field_value = 'Do not resuscitate (DNR/DNI)'
42+
THEN 1
43+
ELSE 0
44+
END AS dnr,
45+
CASE WHEN pd.field_value = 'Do not resuscitate (DNR/DNI)' THEN 1 ELSE 0 END AS dni
46+
FROM mimiciv_hosp.poe AS p
47+
INNER JOIN mimiciv_hosp.poe_detail AS pd
48+
ON p.poe_id = pd.poe_id
49+
LEFT JOIN mimiciv_icu.icustays AS ie
50+
ON p.hadm_id = ie.hadm_id AND p.ordertime >= ie.intime AND p.ordertime <= ie.outtime
51+
WHERE
52+
p.order_type = 'General Care' AND order_subtype = 'Code status'
53+
)
54+
/* Merge together code status from ICU data */ /* with code status from provider order entry */
55+
SELECT
56+
t1.subject_id,
57+
t1.hadm_id,
58+
t1.stay_id,
59+
t1.charttime,
60+
t1.fullcode,
61+
t1.cmo,
62+
t1.dni,
63+
t1.dnr
64+
FROM t1
65+
UNION ALL
66+
SELECT
67+
poe.subject_id,
68+
poe.hadm_id,
69+
poe.stay_id,
70+
poe.ordertime AS charttime,
71+
poe.fullcode,
72+
0 AS cmo,
73+
poe.dni,
74+
poe.dnr
75+
FROM poe

0 commit comments

Comments
 (0)