You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
2
+
DROPTABLE IF EXISTS mimiciv_derived.code_status; CREATE TABLE mimiciv_derived.code_statusAS
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
+
FROMmimiciv_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
0 commit comments