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
{{ message }}
Repository navigation
Commit 70998b9
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: mimic-iv/concepts_postgres/measurement/urine_output_rate.sql
+11-8Lines changed: 11 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,9 @@
1
1
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
2
2
DROPTABLE IF EXISTS mimiciv_derived.urine_output_rate; CREATE TABLE mimiciv_derived.urine_output_rateAS
3
-
/* attempt to calculate urine output per hour *//* rate/hour is the interpretable measure of kidney function *//* though it is difficult to estimate from aperiodic point measures *//* first we get the earliest heart rate documented for the stay */
3
+
/* attempt to calculate urine output per hour */
4
+
/* rate/hour is the interpretable measure of kidney function */
5
+
/* though it is difficult to estimate from aperiodic point measures */
6
+
/* first we get the earliest heart rate documented for the stay */
4
7
WITH tm AS (
5
8
SELECT
6
9
ie.stay_id,
@@ -14,13 +17,13 @@ WITH tm AS (
14
17
ANDce.charttime<ie.outtime+ INTERVAL '1' MONTH
15
18
GROUP BY
16
19
ie.stay_id
17
-
), uo_tm /* now calculate time since last UO measurement */AS (
20
+
), uo_tm /* now calculate time since last UO measurement *//* Use SECOND then convert so BigQuery (truncating) and Postgres (fractional) *//* DATETIME_DIFF agree; same approach as kdigo_uo.sql. */AS (
18
21
SELECT
19
22
tm.stay_id,
20
23
CASE
21
24
WHEN LAG(charttime) OVER w IS NULL
22
-
THEN CAST(EXTRACT(EPOCH FROM DATE_TRUNC('minute', charttime) - DATE_TRUNC('minute', intime_hr)) /60ASBIGINT)
23
-
ELSE CAST(EXTRACT(EPOCH FROM DATE_TRUNC('minute', charttime) - DATE_TRUNC('minute', LAG(charttime) OVER w)) /60ASBIGINT)
25
+
THEN CAST(CAST(EXTRACT(EPOCH FROM DATE_TRUNC('second', charttime) - DATE_TRUNC('second', intime_hr)) /1ASBIGINT)ASDOUBLE PRECISION) /60.0
26
+
ELSE CAST(CAST(EXTRACT(EPOCH FROM DATE_TRUNC('second', charttime) - DATE_TRUNC('second', LAG(charttime) OVER w)) /1ASBIGINT)ASDOUBLE PRECISION) /60.0
24
27
END AS tm_since_last_uo,
25
28
uo.charttime,
26
29
uo.urineoutput
@@ -35,15 +38,15 @@ WITH tm AS (
35
38
SUM(DISTINCT io.urineoutput) AS uo, /* note that we assume data charted at charttime corresponds *//* to 1 hour of UO, therefore we use '5' and '11' to restrict the *//* period, rather than 6/12 this assumption may overestimate UO rate *//* when documentation is done less than hourly */
36
39
SUM(
37
40
CASE
38
-
WHEN CAST(EXTRACT(EPOCH FROM DATE_TRUNC('hour', io.charttime) - DATE_TRUNC('hour', iosum.charttime)) /3600ASBIGINT) <=5
41
+
WHEN CAST(CAST(EXTRACT(EPOCH FROM DATE_TRUNC('second', io.charttime) - DATE_TRUNC('second', iosum.charttime)) /1ASBIGINT)ASDOUBLE PRECISION) /3600.0<=5
39
42
THEN iosum.urineoutput
40
43
ELSE NULL
41
44
END
42
45
) AS urineoutput_6hr,
43
46
ROUND(
44
47
CAST(CAST(SUM(
45
48
CASE
46
-
WHEN CAST(EXTRACT(EPOCH FROM DATE_TRUNC('hour', io.charttime) - DATE_TRUNC('hour', iosum.charttime)) /3600ASBIGINT) <=5
49
+
WHEN CAST(CAST(EXTRACT(EPOCH FROM DATE_TRUNC('second', io.charttime) - DATE_TRUNC('second', iosum.charttime)) /1ASBIGINT)ASDOUBLE PRECISION) /3600.0<=5
47
50
THEN iosum.tm_since_last_uo
48
51
ELSE NULL
49
52
END
@@ -52,15 +55,15 @@ WITH tm AS (
52
55
) AS uo_tm_6hr,
53
56
SUM(
54
57
CASE
55
-
WHEN CAST(EXTRACT(EPOCH FROM DATE_TRUNC('hour', io.charttime) - DATE_TRUNC('hour', iosum.charttime)) /3600ASBIGINT) <=11
58
+
WHEN CAST(CAST(EXTRACT(EPOCH FROM DATE_TRUNC('second', io.charttime) - DATE_TRUNC('second', iosum.charttime)) /1ASBIGINT)ASDOUBLE PRECISION) /3600.0<=11
56
59
THEN iosum.urineoutput
57
60
ELSE NULL
58
61
END
59
62
) AS urineoutput_12hr,
60
63
ROUND(
61
64
CAST(CAST(SUM(
62
65
CASE
63
-
WHEN CAST(EXTRACT(EPOCH FROM DATE_TRUNC('hour', io.charttime) - DATE_TRUNC('hour', iosum.charttime)) /3600ASBIGINT) <=11
66
+
WHEN CAST(CAST(EXTRACT(EPOCH FROM DATE_TRUNC('second', io.charttime) - DATE_TRUNC('second', iosum.charttime)) /1ASBIGINT)ASDOUBLE PRECISION) /3600.0<=11
0 commit comments