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
fix: BigQuery-safe neuroblock gap check and D/C matching
Replace postgres-style interval subtraction with DATETIME_DIFF, and
match CareVue D/C flags via LIKE so sqlglot can transpile the concept.
Co-authored-by: Cursor <cursoragent@cursor.com>
Copy file name to clipboardExpand all lines: mimic-iii/concepts_postgres/durations/neuroblock_dose.sql
+13-15Lines changed: 13 additions & 15 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 mimiciii_derived.neuroblock_dose; CREATE TABLE mimiciii_derived.neuroblock_doseAS
3
-
/* This query extracts dose+durations of neuromuscular blocking agents *//* Note: we assume that injections will be filtered for carevue as they will have starttime = stopttime. *//* Get drug administration data from CareVue and MetaVision *//* metavision is simple and only requires one temporary table */
3
+
/* This query extracts dose+durations of neuromuscular blocking agents */
4
+
/* Note: we assume that injections will be filtered for carevue as they will have starttime = stopttime. */
5
+
/* Get drug administration data from CareVue and MetaVision */
6
+
/* metavision is simple and only requires one temporary table */
charttime, /* where clause below ensures all rows are instance of the drug */
24
-
1AS drug, /* the 'stopped' column indicates if a drug has been disconnected */
25
-
MAX(CASE WHEN stopped IN ('Stopped', 'D/C''d') THEN 1 ELSE 0 END) AS drug_stopped, /* we only include continuous infusions, therefore expect a rate */
27
+
1AS drug, /* the 'stopped' column indicates if a drug has been disconnected *//* match other CareVue duration scripts (avoids apostrophe that breaks sqlglot) */
28
+
MAX(CASE WHEN stopped ='Stopped'OR stopped LIKE'D/C%' THEN 1 ELSE 0 END) AS drug_stopped, /* we only include continuous infusions, therefore expect a rate */
26
29
MAX(
27
30
CASE
28
31
WHEN itemid >=40000AND NOT amount IS NULL
@@ -34,7 +37,7 @@ WITH drugmv AS (
34
37
) AS drug_null,
35
38
MAX(CASE WHEN itemid >=40000 THEN COALESCE(rate, amount) ELSE rate END) AS drug_rate,
36
39
MAX(amount) AS drug_amount
37
-
FROMmimiciii.inputevents_cv
40
+
FROMmimiciii_clinical.inputevents_cv
38
41
WHERE
39
42
itemid IN (
40
43
30114, /* Cisatracurium (63994 rows) */
@@ -60,11 +63,11 @@ WITH drugmv AS (
60
63
icustay_id,
61
64
charttime, /* where clause below ensures all rows are instance of the drug */
62
65
1AS drug, /* the 'stopped' column indicates if a drug has been disconnected */
63
-
MAX(CASE WHEN stopped IN ('Stopped', 'D/C''d') THEN 1 ELSE 0 END) AS drug_stopped,
66
+
MAX(CASE WHEN stopped ='Stopped'OR stopped LIKE'D/C%' THEN 1 ELSE 0 END) AS drug_stopped,
64
67
MAX(CASE WHEN valuenum <=10 THEN 0 ELSE 1 END) AS drug_null, /* educated guess! */
65
68
MAX(CASE WHEN valuenum <=10 THEN valuenum ELSE NULL END) AS drug_rate,
66
69
MAX(CASE WHEN valuenum >10 THEN valuenum ELSE NULL END) AS drug_amount
67
-
FROMmimiciii.chartevents
70
+
FROMmimiciii_clinical.chartevents
68
71
WHERE
69
72
itemid IN (
70
73
1856, /* Vecuronium mcg/min (8 rows) */
@@ -118,13 +121,7 @@ WITH drugmv AS (
118
121
THEN 1
119
122
WHEN LAG(drug_stopped, 1) OVER (PARTITION BY icustay_id, drug ORDER BY charttime NULLS FIRST) =1
120
123
THEN 1
121
-
WHEN (
122
-
CHARTTIME - (
123
-
LAG(CHARTTIME, 1) OVER (PARTITION BY icustay_id, drug ORDER BY charttime NULLS FIRST)
124
-
)
125
-
) > (
126
-
INTERVAL '8 HOURS'
127
-
)
124
+
WHEN CAST(EXTRACT(EPOCH FROM DATE_TRUNC('hour', CHARTTIME) - DATE_TRUNC('hour', LAG(CHARTTIME, 1) OVER (PARTITION BY icustay_id, drug ORDER BY charttime NULLS FIRST))) /3600ASBIGINT) >8
128
125
THEN 1
129
126
ELSE NULL
130
127
END AS drug_start
@@ -227,7 +224,8 @@ WITH drugmv AS (
227
224
drug_groups_sum,
228
225
drug_rate
229
226
)
230
-
/* now assign this data to every hour of the patient's stay *//* drug_amount for carevue is not accurate */
227
+
/* now assign this data to every hour of the patient's stay */
0 commit comments