forked from MIT-LCP/mimic-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aline_vaso_flag.sql
59 lines (57 loc) · 1.6 KB
/
aline_vaso_flag.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- Create a table which indicates if a patient was ever on a vasopressor during their ICU stay
-- List of vasopressors used:
-- norepinephrine - 30047,30120,221906
-- epinephrine - 30044,30119,30309,221289
-- phenylephrine - 30127,30128,221749
-- vasopressin - 30051,222315
-- dopamine - 30043,30307,221662
-- Isuprel - 30046,227692
DROP MATERIALIZED VIEW IF EXISTS ALINE_VASO_FLAG CASCADE;
CREATE MATERIALIZED VIEW ALINE_VASO_FLAG as
with io_cv as
(
select
icustay_id, charttime, itemid, stopped, rate, amount
from inputevents_cv
where itemid in
(
30047,30120 -- norepinephrine
,30044,30119,30309 -- epinephrine
,30127,30128 -- phenylephrine
,30051 -- vasopressin
,30043,30307,30125 -- dopamine
,30046 -- isuprel
)
and rate is not null
and rate > 0
)
-- select only the ITEMIDs from the inputevents_mv table related to vasopressors
, io_mv as
(
select
icustay_id, linkorderid, starttime, endtime
from inputevents_mv io
-- Subselect the vasopressor ITEMIDs
where itemid in
(
221906 -- norepinephrine
,221289 -- epinephrine
,221749 -- phenylephrine
,222315 -- vasopressin
,221662 -- dopamine
,227692 -- isuprel
)
and rate is not null
and rate > 0
and statusdescription != 'Rewritten' -- only valid orders
)
select
co.subject_id, co.hadm_id, co.icustay_id
, max(case when coalesce(io_mv.icustay_id, io_cv.icustay_id) is not null then 1 else 0 end) as vaso_flag
from icustays co
left join io_mv
on co.icustay_id = io_mv.icustay_id
left join io_cv
on co.icustay_id = io_cv.icustay_id
group by co.subject_id, co.hadm_id, co.icustay_id
order by icustay_id;