-
Notifications
You must be signed in to change notification settings - Fork 0
/
08_Vasopressors_dose.sql
38 lines (36 loc) · 1.06 KB
/
08_Vasopressors_dose.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
DROP TABLE IF EXISTS `mvte-318912.mv.pressors`;
CREATE TABLE `mvte-318912.mv.pressors` AS
WITH vaso_duration AS (
SELECT
stay_id
,norepinephrine_equivalent_dose
,starttime
,endtime
,extract (MINUTE from endtime-starttime) as duration #sometimes duration is 0
,norepinephrine_equivalent_dose / (extract (MINUTE from endtime-starttime) + 1) as dose
FROM `physionet-data.mimiciv_derived.norepinephrine_equivalent_dose`
#where stay_id = 31326208
#rder by starttime limit 1
)
, hourly AS (
SELECT
main.starttime
,main.endtime
,main.hr
,main.stay_id
,CASE WHEN vaso.dose IS NOT NULL THEN vaso.dose
ELSE 0 END AS dose
FROM `mvte-318912.mv.icu_720h` main
LEFT JOIN vaso_duration vaso
ON main.stay_id = vaso.stay_id
WHERE vaso.starttime > main.starttime
AND vaso.starttime < main.endtime
OR vaso.endtime > main.starttime
AND vaso.endtime < main.endtime
)
,hourly_avg AS (
SELECT hr,stay_id,avg(dose) as vaso_dose_per_min
FROM hourly
GROUP BY hr,stay_id
)
SELECT * FROM hourly_avg