Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions mimic-iii/concepts/durations/neuroblock_dose.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ with drugmv as
, 1 as drug

-- the 'stopped' column indicates if a drug has been disconnected
, max(case when stopped in ('Stopped','D/C\'d') then 1 else 0 end) as drug_stopped
-- match other CareVue duration scripts (avoids apostrophe that breaks sqlglot)
, 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
, max(case
Expand Down Expand Up @@ -68,7 +69,7 @@ with drugmv as
, 1 as drug

-- the 'stopped' column indicates if a drug has been disconnected
, max(case when stopped in ('Stopped','D/C\'d') then 1 else 0 end) as drug_stopped
, max(case when stopped = 'Stopped' OR stopped LIKE 'D/C%' then 1 else 0 end) as drug_stopped
, max(case when valuenum <= 10 then 0 else 1 end) as drug_null

-- educated guess!
Expand Down Expand Up @@ -179,7 +180,12 @@ select
)
= 1 then 1

when (CHARTTIME - (LAG(CHARTTIME, 1) OVER (partition by icustay_id, drug order by charttime))) > (interval '8 hours') then 1
-- BigQuery concepts use DATETIME_DIFF (postgres-style interval math is invalid here)
when DATETIME_DIFF(
CHARTTIME,
LAG(CHARTTIME, 1) OVER (partition by icustay_id, drug order by charttime),
HOUR
) > 8 then 1
else null
end as drug_start

Expand Down
22 changes: 10 additions & 12 deletions mimic-iii/concepts_duckdb/durations/neuroblock_dose.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WITH drugmv AS (
amount AS drug_amount,
starttime,
endtime
FROM mimiciii.inputevents_mv
FROM mimiciii_clinical.inputevents_mv
WHERE
itemid IN (222062, 221555)
AND statusdescription <> 'Rewritten'
Expand All @@ -18,7 +18,7 @@ WITH drugmv AS (
icustay_id,
charttime,
1 AS drug,
MAX(CASE WHEN stopped IN ('Stopped', 'D/C''d') THEN 1 ELSE 0 END) AS drug_stopped,
MAX(CASE WHEN stopped = 'Stopped' OR stopped LIKE 'D/C%' THEN 1 ELSE 0 END) AS drug_stopped,
MAX(
CASE
WHEN itemid >= 40000 AND NOT amount IS NULL
Expand All @@ -30,7 +30,7 @@ WITH drugmv AS (
) AS drug_null,
MAX(CASE WHEN itemid >= 40000 THEN COALESCE(rate, amount) ELSE rate END) AS drug_rate,
MAX(amount) AS drug_amount
FROM mimiciii.inputevents_cv
FROM mimiciii_clinical.inputevents_cv
WHERE
itemid IN (
30114,
Expand All @@ -55,11 +55,11 @@ WITH drugmv AS (
icustay_id,
charttime,
1 AS drug,
MAX(CASE WHEN stopped IN ('Stopped', 'D/C''d') THEN 1 ELSE 0 END) AS drug_stopped,
MAX(CASE WHEN stopped = 'Stopped' OR stopped LIKE 'D/C%' THEN 1 ELSE 0 END) AS drug_stopped,
MAX(CASE WHEN valuenum <= 10 THEN 0 ELSE 1 END) AS drug_null,
MAX(CASE WHEN valuenum <= 10 THEN valuenum ELSE NULL END) AS drug_rate,
MAX(CASE WHEN valuenum > 10 THEN valuenum ELSE NULL END) AS drug_amount
FROM mimiciii.chartevents
FROM mimiciii_clinical.chartevents
WHERE
itemid IN (1856, 2164, 2548, 2285, 2290, 2670, 2546, 1098, 2390, 2511, 1028, 1858)
GROUP BY
Expand Down Expand Up @@ -100,13 +100,11 @@ WITH drugmv AS (
THEN 1
WHEN LAG(drug_stopped, 1) OVER (PARTITION BY icustay_id, drug ORDER BY charttime NULLS FIRST) = 1
THEN 1
WHEN (
CHARTTIME - (
LAG(CHARTTIME, 1) OVER (PARTITION BY icustay_id, drug ORDER BY charttime NULLS FIRST)
)
) > (
INTERVAL '8' HOURS
)
WHEN DATE_DIFF(
'HOUR',
LAG(CHARTTIME, 1) OVER (PARTITION BY icustay_id, drug ORDER BY charttime NULLS FIRST),
CHARTTIME
) > 8
THEN 1
ELSE NULL
END AS drug_start
Expand Down
28 changes: 13 additions & 15 deletions mimic-iii/concepts_postgres/durations/neuroblock_dose.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
DROP TABLE IF EXISTS mimiciii_derived.neuroblock_dose; CREATE TABLE mimiciii_derived.neuroblock_dose AS
/* 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 */
/* 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 */
WITH drugmv AS (
SELECT
icustay_id,
Expand All @@ -9,7 +12,7 @@ WITH drugmv AS (
amount AS drug_amount,
starttime,
endtime
FROM mimiciii.inputevents_mv
FROM mimiciii_clinical.inputevents_mv
WHERE
itemid IN (
222062, /* Vecuronium (664 rows, 154 infusion rows) */
Expand All @@ -21,8 +24,8 @@ WITH drugmv AS (
SELECT
icustay_id,
charttime, /* where clause below ensures all rows are instance of the drug */
1 AS drug, /* the 'stopped' column indicates if a drug has been disconnected */
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 */
1 AS drug, /* the 'stopped' column indicates if a drug has been disconnected */ /* match other CareVue duration scripts (avoids apostrophe that breaks sqlglot) */
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 */
MAX(
CASE
WHEN itemid >= 40000 AND NOT amount IS NULL
Expand All @@ -34,7 +37,7 @@ WITH drugmv AS (
) AS drug_null,
MAX(CASE WHEN itemid >= 40000 THEN COALESCE(rate, amount) ELSE rate END) AS drug_rate,
MAX(amount) AS drug_amount
FROM mimiciii.inputevents_cv
FROM mimiciii_clinical.inputevents_cv
WHERE
itemid IN (
30114, /* Cisatracurium (63994 rows) */
Expand All @@ -60,11 +63,11 @@ WITH drugmv AS (
icustay_id,
charttime, /* where clause below ensures all rows are instance of the drug */
1 AS drug, /* the 'stopped' column indicates if a drug has been disconnected */
MAX(CASE WHEN stopped IN ('Stopped', 'D/C''d') THEN 1 ELSE 0 END) AS drug_stopped,
MAX(CASE WHEN stopped = 'Stopped' OR stopped LIKE 'D/C%' THEN 1 ELSE 0 END) AS drug_stopped,
MAX(CASE WHEN valuenum <= 10 THEN 0 ELSE 1 END) AS drug_null, /* educated guess! */
MAX(CASE WHEN valuenum <= 10 THEN valuenum ELSE NULL END) AS drug_rate,
MAX(CASE WHEN valuenum > 10 THEN valuenum ELSE NULL END) AS drug_amount
FROM mimiciii.chartevents
FROM mimiciii_clinical.chartevents
WHERE
itemid IN (
1856, /* Vecuronium mcg/min (8 rows) */
Expand Down Expand Up @@ -118,13 +121,7 @@ WITH drugmv AS (
THEN 1
WHEN LAG(drug_stopped, 1) OVER (PARTITION BY icustay_id, drug ORDER BY charttime NULLS FIRST) = 1
THEN 1
WHEN (
CHARTTIME - (
LAG(CHARTTIME, 1) OVER (PARTITION BY icustay_id, drug ORDER BY charttime NULLS FIRST)
)
) > (
INTERVAL '8 HOURS'
)
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))) / 3600 AS BIGINT) > 8
THEN 1
ELSE NULL
END AS drug_start
Expand Down Expand Up @@ -227,7 +224,8 @@ WITH drugmv AS (
drug_groups_sum,
drug_rate
)
/* now assign this data to every hour of the patient's stay */ /* drug_amount for carevue is not accurate */
/* now assign this data to every hour of the patient's stay */
/* drug_amount for carevue is not accurate */
SELECT
icustay_id,
starttime,
Expand Down
Loading