Skip to content

Commit

Permalink
update postgres concepts with latest transpilation
Browse files Browse the repository at this point in the history
  • Loading branch information
alistairewj committed Aug 21, 2024
1 parent beeb69b commit 2be32a0
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 57 deletions.
2 changes: 1 addition & 1 deletion mimic-iv/concepts_postgres/demographics/age.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SELECT
ad.admittime,
pa.anchor_age,
pa.anchor_year, /* calculate the age as anchor_age (60) plus difference between */ /* admit year and the anchor year. */ /* the noqa retains the extra long line so the */ /* convert to postgres bash script works */
pa.anchor_age + EXTRACT(EPOCH FROM ad.admittime - TO_TIMESTAMP(TO_CHAR(pa.anchor_year, '0000') || TO_CHAR(1, '00') || TO_CHAR(1, '00') || TO_CHAR(0, '00') || TO_CHAR(0, '00') || TO_CHAR(0, '00'), 'yyyymmddHH24MISS')) / 31556908.8 AS age /* noqa: L016 */
pa.anchor_age + EXTRACT(EPOCH FROM ad.admittime - MAKE_TIMESTAMP(pa.anchor_year, 1, 1, 0, 0, 0)) / 31556908.8 AS age /* noqa: L016 */
FROM mimiciv_hosp.admissions AS ad
INNER JOIN mimiciv_hosp.patients AS pa
ON ad.subject_id = pa.subject_id
2 changes: 1 addition & 1 deletion mimic-iv/concepts_postgres/demographics/icustay_detail.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SELECT
adm.admittime,
adm.dischtime,
EXTRACT(EPOCH FROM adm.dischtime - adm.admittime) / 86400.0 AS los_hospital, /* calculate the age as anchor_age (60) plus difference between */ /* admit year and the anchor year. */ /* the noqa retains the extra long line so the */ /* convert to postgres bash script works */
pat.anchor_age + EXTRACT(EPOCH FROM adm.admittime - TO_TIMESTAMP(TO_CHAR(pat.anchor_year, '0000') || TO_CHAR(1, '00') || TO_CHAR(1, '00') || TO_CHAR(0, '00') || TO_CHAR(0, '00') || TO_CHAR(0, '00'), 'yyyymmddHH24MISS')) / 31556908.8 AS admission_age, /* noqa: L016 */
pat.anchor_age + EXTRACT(EPOCH FROM adm.admittime - MAKE_TIMESTAMP(pat.anchor_year, 1, 1, 0, 0, 0)) / 31556908.8 AS admission_age, /* noqa: L016 */
adm.race,
adm.hospital_expire_flag,
DENSE_RANK() OVER (PARTITION BY adm.subject_id ORDER BY adm.admittime NULLS FIRST) AS hospstay_seq,
Expand Down
6 changes: 4 additions & 2 deletions mimic-iv/concepts_postgres/demographics/icustay_hourly.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ WITH all_hours AS (
THEN it.intime_hr
ELSE DATE_TRUNC('HOUR', it.intime_hr) + INTERVAL '1 HOUR'
END AS endtime, /* create integers for each charttime in hours from admission */ /* so 0 is admission time, 1 is one hour after admission, etc, */ /* up to ICU disch */ /* we allow 24 hours before ICU admission (to grab labs before admit) */
GENERATE_SERIES(-24, CAST(CEIL(EXTRACT(EPOCH FROM it.outtime_hr - it.intime_hr) / 3600.0) AS INT)) AS hrs /* noqa: L016 */
ARRAY(SELECT
*
FROM GENERATE_SERIES(-24, CAST(CEIL(EXTRACT(EPOCH FROM it.outtime_hr - it.intime_hr) / 3600.0) AS INT))) AS hrs /* noqa: L016 */
FROM mimiciv_derived.icustay_times AS it
)
SELECT
stay_id,
CAST(hr_unnested AS BIGINT) AS hr,
endtime + CAST(hr_unnested AS BIGINT) * INTERVAL '1 HOUR' AS endtime
FROM all_hours
CROSS JOIN UNNEST(all_hours.hrs) AS _t(hr_unnested)
CROSS JOIN UNNEST(all_hours.hrs) AS _t0(hr_unnested)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FROM mimiciv_icu.icustays AS ie
/* Join to the outputevents table to get urine output */
LEFT JOIN mimiciv_derived.urine_output AS uo
ON ie.stay_id = uo.stay_id
AND uo.charttime >= ie.intime
AND /* ensure the data occurs during the first day */ uo.charttime >= ie.intime
AND uo.charttime <= ie.intime + INTERVAL '1 DAY'
GROUP BY
ie.subject_id,
Expand Down
3 changes: 2 additions & 1 deletion mimic-iv/concepts_postgres/firstday/first_day_weight.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ SELECT
FROM mimiciv_icu.icustays AS ie
/* admission weight */
LEFT JOIN mimiciv_derived.weight_durations AS ce
ON ie.stay_id = ce.stay_id AND ce.starttime <= ie.intime + INTERVAL '1 DAY'
ON ie.stay_id = ce.stay_id
AND /* we filter to weights documented during or before the 1st day */ ce.starttime <= ie.intime + INTERVAL '1 DAY'
GROUP BY
ie.subject_id,
ie.stay_id
14 changes: 9 additions & 5 deletions mimic-iv/concepts_postgres/measurement/bg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ DROP TABLE IF EXISTS mimiciv_derived.bg; CREATE TABLE mimiciv_derived.bg AS
/* The aim of this query is to pivot entries related to blood gases */ /* which were found in LABEVENTS */
WITH bg AS (
SELECT
MAX(subject_id) AS subject_id,
MAX(subject_id) AS subject_id, /* specimen_id only ever has 1 measurement for each itemid */ /* so, we may simply collapse rows using MAX() */
MAX(hadm_id) AS hadm_id,
MAX(charttime) AS charttime, /* specimen_id *may* have different storetimes, so this */ /* is taking the latest */
MAX(storetime) AS storetime,
Expand Down Expand Up @@ -57,7 +57,9 @@ WITH bg AS (
AVG(valuenum) AS spo2
FROM mimiciv_icu.chartevents
WHERE
itemid = 220277 /* O2 saturation pulseoxymetry */ AND valuenum > 0 AND valuenum <= 100
itemid = 220277 /* O2 saturation pulseoxymetry */
AND valuenum > 0
AND valuenum <= 100
GROUP BY
subject_id,
charttime
Expand All @@ -78,7 +80,9 @@ WITH bg AS (
) AS fio2_chartevents
FROM mimiciv_icu.chartevents
WHERE
itemid = 223835 /* Inspired O2 Fraction (FiO2) */ AND valuenum > 0 AND valuenum <= 100
itemid = 223835 /* Inspired O2 Fraction (FiO2) */
AND valuenum > 0
AND valuenum <= 100
GROUP BY
subject_id,
charttime
Expand All @@ -90,7 +94,7 @@ WITH bg AS (
FROM bg
LEFT JOIN stg_spo2 AS s1
ON bg.subject_id = s1.subject_id
AND s1.charttime BETWEEN bg.charttime - INTERVAL '2 HOUR' AND bg.charttime
AND /* spo2 occurred at most 2 hours before this blood gas */ s1.charttime BETWEEN bg.charttime - INTERVAL '2 HOUR' AND bg.charttime
WHERE
NOT bg.po2 IS NULL
), stg3 AS (
Expand All @@ -101,7 +105,7 @@ WITH bg AS (
FROM stg2 AS bg
LEFT JOIN stg_fio2 AS s2
ON bg.subject_id = s2.subject_id
AND s2.charttime >= bg.charttime - INTERVAL '4 HOUR'
AND /* fio2 occurred at most 4 hours before this blood gas */ s2.charttime >= bg.charttime - INTERVAL '4 HOUR'
AND s2.charttime <= bg.charttime
AND s2.fio2_chartevents > 0
/* only the row with the most recent SpO2 (if no SpO2 found lastRowSpO2 = 1) */
Expand Down
4 changes: 2 additions & 2 deletions mimic-iv/concepts_postgres/measurement/blood_differential.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ WITH blood_diff AS (
MAX(CASE WHEN itemid = 51257 THEN valuenum ELSE NULL END) AS nrbc, /* utility flags which determine whether imputation is possible */
CASE
WHEN MAX(CASE WHEN itemid IN (51300, 51301, 51755) THEN valuenum ELSE NULL END) > 0
AND SUM(
AND /* and we have at least one percentage from the diff */ /* sometimes the entire diff is 0%, which looks like bad data */ SUM(
CASE
WHEN itemid IN (51146, 51200, 51244, 51245, 51254, 51256)
THEN valuenum
Expand All @@ -70,7 +70,7 @@ WITH blood_diff AS (
WHERE
le.itemid IN (51146 /* basophils */, 52069 /* Absolute basophil count */, 51199 /* Eosinophil Count */, 51200 /* Eosinophils */, 52073 /* Absolute Eosinophil count */, 51244 /* Lymphocytes */, 51245 /* Lymphocytes, Percent */, 51133 /* Absolute Lymphocyte Count */, 52769 /* Absolute Lymphocyte Count */, 51253 /* Monocyte Count */, 51254 /* Monocytes */, 52074 /* Absolute Monocyte Count */, 51256 /* Neutrophils */, 52075 /* Absolute Neutrophil Count */, 51143 /* Atypical lymphocytes */, 51144 /* Bands (%) */, 51218 /* Granulocyte Count */, 52135 /* Immature granulocytes (%) */, 51251 /* Metamyelocytes */, 51257 /* Nucleated Red Cells */ /* wbc totals measured in K/uL */ /* 52220 (wbcp) is percentage */, 51300, 51301, 51755) /* below are point of care tests which are extremely infrequent */ /* and usually low quality */ /* 51697, -- Neutrophils (mmol/L) */ /* below itemid do not have data as of MIMIC-IV v1.0 */ /* 51536, -- Absolute Lymphocyte Count */ /* 51537, -- Absolute Neutrophil */ /* 51690, -- Lymphocytes */ /* 52151, -- NRBC */
AND NOT valuenum IS NULL
AND valuenum >= 0
AND /* differential values cannot be negative */ valuenum >= 0
GROUP BY
le.specimen_id
)
Expand Down
4 changes: 2 additions & 2 deletions mimic-iv/concepts_postgres/measurement/chemistry.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ FROM mimiciv_hosp.labevents AS le
WHERE
le.itemid IN (50862 /* comment is: LABEL | CATEGORY | FLUID | NUMBER OF ROWS IN LABEVENTS */ /* ALBUMIN | CHEMISTRY | BLOOD | 146697 */, 50930 /* Globulin */, 50976 /* Total protein */ /* 52456, -- Anion gap, point of care test */, 50868 /* ANION GAP | CHEMISTRY | BLOOD | 769895 */, 50882 /* BICARBONATE | CHEMISTRY | BLOOD | 780733 */, 50893 /* Calcium */ /* 52502, Creatinine, point of care */, 50912 /* CREATININE | CHEMISTRY | BLOOD | 797476 */, 50902 /* CHLORIDE | CHEMISTRY | BLOOD | 795568 */, 50931 /* GLUCOSE | CHEMISTRY | BLOOD | 748981 */ /* 52525, Glucose, point of care */ /* 52566, -- Potassium, point of care */, 50971 /* POTASSIUM | CHEMISTRY | BLOOD | 845825 */ /* 52579, -- Sodium, point of care */, 50983 /* SODIUM | CHEMISTRY | BLOOD | 808489 */ /* 52603, Urea, point of care */, 51006 /* UREA NITROGEN | CHEMISTRY | BLOOD | 791925 */)
AND NOT valuenum IS NULL
AND (
AND /* lab values cannot be 0 and cannot be negative */ /* .. except anion gap. */ (
valuenum > 0 OR itemid = 50868
) /* lab values cannot be 0 and cannot be negative */ /* .. except anion gap. */
)
GROUP BY
le.specimen_id
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ FROM mimiciv_hosp.labevents AS le
WHERE
le.itemid IN (51221 /* hematocrit */, 51222 /* hemoglobin */, 51248 /* MCH */, 51249 /* MCHC */, 51250 /* MCV */, 51265 /* platelets */, 51279 /* RBC */, 51277 /* RDW */, 52159 /* RDW SD */, 51301 /* WBC */)
AND NOT valuenum IS NULL
AND valuenum > 0
AND /* lab values cannot be 0 and cannot be negative */ valuenum > 0
GROUP BY
le.specimen_id
2 changes: 1 addition & 1 deletion mimic-iv/concepts_postgres/measurement/enzyme.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ FROM mimiciv_hosp.labevents AS le
WHERE
le.itemid IN (50861 /* Alanine transaminase (ALT) */, 50863 /* Alkaline phosphatase (ALP) */, 50878 /* Aspartate transaminase (AST) */, 50867 /* Amylase */, 50885 /* total bili */, 50884 /* indirect bili */, 50883 /* direct bili */, 50910 /* ck_cpk */, 50911 /* CK-MB */, 50927 /* Gamma Glutamyltransferase (GGT) */, 50954 /* ld_ldh */)
AND NOT valuenum IS NULL
AND valuenum > 0
AND /* lab values cannot be 0 and cannot be negative */ valuenum > 0
GROUP BY
le.specimen_id
6 changes: 3 additions & 3 deletions mimic-iv/concepts_postgres/measurement/height.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WITH ht_in AS (
c.valuenum AS height_orig
FROM mimiciv_icu.chartevents AS c
WHERE
NOT c.valuenum IS NULL /* Height (measured in inches) */ AND c.itemid = 226707
NOT c.valuenum IS NULL AND /* Height (measured in inches) */ c.itemid = 226707
), ht_cm AS (
SELECT
c.subject_id,
Expand All @@ -19,7 +19,7 @@ WITH ht_in AS (
ROUND(CAST(c.valuenum AS DECIMAL), 2) AS height
FROM mimiciv_icu.chartevents AS c
WHERE
NOT c.valuenum IS NULL /* Height cm */ AND c.itemid = 226730
NOT c.valuenum IS NULL AND /* Height cm */ c.itemid = 226730
), ht_stg0 AS (
SELECT
COALESCE(h1.subject_id, h1.subject_id) AS subject_id,
Expand All @@ -37,4 +37,4 @@ SELECT
height
FROM ht_stg0
WHERE
NOT height IS NULL /* filter out bad heights */ AND height > 120 AND height < 230
NOT height IS NULL AND /* filter out bad heights */ height > 120 AND height < 230
2 changes: 1 addition & 1 deletion mimic-iv/concepts_postgres/measurement/inflammation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ FROM mimiciv_hosp.labevents AS le
WHERE
le.itemid IN (50889 /* 51652 -- high sensitivity CRP */ /* crp */)
AND NOT valuenum IS NULL
AND valuenum > 0
AND /* lab values cannot be 0 and cannot be negative */ valuenum > 0
GROUP BY
le.specimen_id
13 changes: 8 additions & 5 deletions mimic-iv/concepts_postgres/medication/antibiotic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ WITH abx AS (
FROM mimiciv_hosp.prescriptions
/* excludes vials/syringe/normal saline, etc */
WHERE
NOT drug_type IN ('BASE') /* we exclude routes via the eye, ears, or topically */
AND NOT route IN ('OU', 'OS', 'OD', 'AU', 'AS', 'AD', 'TP')
NOT drug_type IN ('BASE')
AND /* we exclude routes via the eye, ears, or topically */ NOT route IN ('OU', 'OS', 'OD', 'AU', 'AS', 'AD', 'TP')
AND NOT LOWER(route) LIKE '%ear%'
AND NOT LOWER(route) LIKE '%eye%'
AND NOT LOWER(drug) LIKE '%cream%' /* we exclude certain types of antibiotics: topical creams, */ /* gels, desens, etc */
AND /* we exclude certain types of antibiotics: topical creams, */ /* gels, desens, etc */ NOT LOWER(drug) LIKE '%cream%'
AND NOT LOWER(drug) LIKE '%desensitization%'
AND NOT LOWER(drug) LIKE '%ophth oint%'
AND NOT LOWER(drug) LIKE '%gel%'
Expand All @@ -338,9 +338,12 @@ SELECT
FROM mimiciv_hosp.prescriptions AS pr
/* inner join to subselect to only antibiotic prescriptions */
INNER JOIN abx
ON pr.drug = abx.drug AND pr.route = abx.route
ON pr.drug = abx.drug
AND /* route is never NULL for antibiotics */ /* only ~4000 null rows in prescriptions total. */ pr.route = abx.route
/* add in stay_id as we use this table for sepsis-3 */
LEFT JOIN mimiciv_icu.icustays AS ie
ON pr.hadm_id = ie.hadm_id AND pr.starttime >= ie.intime AND pr.starttime < ie.outtime
ON pr.hadm_id = ie.hadm_id
AND pr.starttime >= ie.intime
AND pr.starttime < ie.outtime
WHERE
abx.antibiotic = 1
28 changes: 21 additions & 7 deletions mimic-iv/concepts_postgres/medication/vasoactive_agent.sql
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,33 @@ SELECT
/* isoproterenol is used in CCU/CVICU but not in metavision */ /* other drugs not included here but (rarely) used in the BIDMC: */ /* angiotensin II, methylene blue */
FROM tm_lag AS t
LEFT JOIN mimiciv_derived.dobutamine AS dob
ON t.stay_id = dob.stay_id AND t.starttime >= dob.starttime AND t.endtime <= dob.endtime
ON t.stay_id = dob.stay_id
AND t.starttime >= dob.starttime
AND t.endtime <= dob.endtime
LEFT JOIN mimiciv_derived.dopamine AS dop
ON t.stay_id = dop.stay_id AND t.starttime >= dop.starttime AND t.endtime <= dop.endtime
ON t.stay_id = dop.stay_id
AND t.starttime >= dop.starttime
AND t.endtime <= dop.endtime
LEFT JOIN mimiciv_derived.epinephrine AS epi
ON t.stay_id = epi.stay_id AND t.starttime >= epi.starttime AND t.endtime <= epi.endtime
ON t.stay_id = epi.stay_id
AND t.starttime >= epi.starttime
AND t.endtime <= epi.endtime
LEFT JOIN mimiciv_derived.norepinephrine AS nor
ON t.stay_id = nor.stay_id AND t.starttime >= nor.starttime AND t.endtime <= nor.endtime
ON t.stay_id = nor.stay_id
AND t.starttime >= nor.starttime
AND t.endtime <= nor.endtime
LEFT JOIN mimiciv_derived.phenylephrine AS phe
ON t.stay_id = phe.stay_id AND t.starttime >= phe.starttime AND t.endtime <= phe.endtime
ON t.stay_id = phe.stay_id
AND t.starttime >= phe.starttime
AND t.endtime <= phe.endtime
LEFT JOIN mimiciv_derived.vasopressin AS vas
ON t.stay_id = vas.stay_id AND t.starttime >= vas.starttime AND t.endtime <= vas.endtime
ON t.stay_id = vas.stay_id
AND t.starttime >= vas.starttime
AND t.endtime <= vas.endtime
LEFT JOIN mimiciv_derived.milrinone AS mil
ON t.stay_id = mil.stay_id AND t.starttime >= mil.starttime AND t.endtime <= mil.endtime
ON t.stay_id = mil.stay_id
AND t.starttime >= mil.starttime
AND t.endtime <= mil.endtime
/* remove the final row for each stay_id */ /* it will not have any infusions associated with it */
WHERE
NOT t.endtime IS NULL
2 changes: 1 addition & 1 deletion mimic-iv/concepts_postgres/organfailure/kdigo_stages.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WITH cr_stg AS (
)
THEN 3
WHEN cr.creat >= 4
AND (
AND /* For patients reaching Stage 3 by SCr >4.0 mg/dl */ /* require that the patient first achieve ... */ /* an acute increase >= 0.3 within 48 hr */ /* *or* an increase of >= 1.5 times baseline */ (
cr.creat_low_past_48hr <= 3.7 OR cr.creat >= (
1.5 * cr.creat_low_past_7day
)
Expand Down
4 changes: 3 additions & 1 deletion mimic-iv/concepts_postgres/organfailure/kdigo_uo.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ SELECT
uo_tm_24hr
FROM uo_stg2 AS ur
LEFT JOIN mimiciv_derived.weight_durations AS wd
ON ur.stay_id = wd.stay_id AND ur.charttime >= wd.starttime AND ur.charttime < wd.endtime
ON ur.stay_id = wd.stay_id
AND ur.charttime >= wd.starttime
AND ur.charttime < wd.endtime
21 changes: 15 additions & 6 deletions mimic-iv/concepts_postgres/score/apsiii.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ WITH pa AS (
ROW_NUMBER() OVER (PARTITION BY ie.stay_id ORDER BY bg.po2 DESC NULLS LAST) AS rn
FROM mimiciv_derived.bg AS bg
INNER JOIN mimiciv_icu.icustays AS ie
ON bg.hadm_id = ie.hadm_id AND bg.charttime >= ie.intime AND bg.charttime < ie.outtime
ON bg.hadm_id = ie.hadm_id
AND bg.charttime >= ie.intime
AND bg.charttime < ie.outtime
LEFT JOIN mimiciv_derived.ventilation AS vd
ON ie.stay_id = vd.stay_id
AND bg.charttime >= vd.starttime
AND bg.charttime <= vd.endtime
AND vd.ventilation_status = 'InvasiveVent'
WHERE
vd.stay_id IS NULL /* patient is *not* ventilated */
AND COALESCE(fio2, fio2_chartevents, 21) < 50
AND /* and fio2 < 50, or if no fio2, assume room air */ COALESCE(fio2, fio2_chartevents, 21) < 50
AND NOT bg.po2 IS NULL
AND bg.specimen = 'ART.'
), aa AS (
Expand All @@ -30,7 +32,9 @@ WITH pa AS (
/* row number indicating the highest AaDO2 */
FROM mimiciv_derived.bg AS bg
INNER JOIN mimiciv_icu.icustays AS ie
ON bg.hadm_id = ie.hadm_id AND bg.charttime >= ie.intime AND bg.charttime < ie.outtime
ON bg.hadm_id = ie.hadm_id
AND bg.charttime >= ie.intime
AND bg.charttime < ie.outtime
INNER JOIN mimiciv_derived.ventilation AS vd
ON ie.stay_id = vd.stay_id
AND bg.charttime >= vd.starttime
Expand Down Expand Up @@ -65,7 +69,9 @@ WITH pa AS (
END AS acidbase_score
FROM mimiciv_derived.bg AS bg
INNER JOIN mimiciv_icu.icustays AS ie
ON bg.hadm_id = ie.hadm_id AND bg.charttime >= ie.intime AND bg.charttime < ie.outtime
ON bg.hadm_id = ie.hadm_id
AND bg.charttime >= ie.intime
AND bg.charttime < ie.outtime
WHERE
NOT ph IS NULL AND NOT pco2 IS NULL AND bg.specimen = 'ART.'
), acidbase_max AS (
Expand All @@ -80,7 +86,9 @@ WITH pa AS (
SELECT
ie.stay_id,
CASE
WHEN labs.creatinine_max >= 1.5 AND uo.urineoutput < 410 AND icd.ckd = 0
WHEN labs.creatinine_max >= 1.5
AND uo.urineoutput < 410
AND /* acute renal failure is only coded if the patient */ /* is not on chronic dialysis */ /* we use ICD-9 coding of ESRD as a proxy for chronic dialysis */ icd.ckd = 0
THEN 1
ELSE 0
END AS arf
Expand Down Expand Up @@ -613,7 +621,8 @@ WITH pa AS (
WHEN ABS(heart_rate_max - 75) = ABS(heart_rate_min - 75)
AND smax.hr_score >= smin.hr_score
THEN smax.hr_score
WHEN ABS(heart_rate_max - 75) = ABS(heart_rate_min - 75) AND smax.hr_score < smin.hr_score
WHEN ABS(heart_rate_max - 75) = ABS(heart_rate_min - 75)
AND smax.hr_score < smin.hr_score
THEN smin.hr_score
END AS hr_score,
CASE
Expand Down
8 changes: 6 additions & 2 deletions mimic-iv/concepts_postgres/score/lods.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ WITH cpap AS (
CASE WHEN NOT cp.stay_id IS NULL THEN 1 ELSE 0 END AS cpap
FROM mimiciv_derived.bg AS bg
INNER JOIN mimiciv_icu.icustays AS ie
ON bg.hadm_id = ie.hadm_id AND bg.charttime >= ie.intime AND bg.charttime < ie.outtime
ON bg.hadm_id = ie.hadm_id
AND bg.charttime >= ie.intime
AND bg.charttime < ie.outtime
LEFT JOIN mimiciv_derived.ventilation AS vd
ON ie.stay_id = vd.stay_id
AND bg.charttime >= vd.starttime
AND bg.charttime <= vd.endtime
AND vd.ventilation_status = 'InvasiveVent'
LEFT JOIN cpap AS cp
ON ie.stay_id = cp.stay_id AND bg.charttime >= cp.starttime AND bg.charttime <= cp.endtime
ON ie.stay_id = cp.stay_id
AND bg.charttime >= cp.starttime
AND bg.charttime <= cp.endtime
), pafi2 AS (
/* get the minimum PaO2/FiO2 ratio *only for ventilated/cpap patients* */
SELECT
Expand Down
Loading

0 comments on commit 2be32a0

Please sign in to comment.