From 6594921512ace7105836cf753d4f5d94e7377ea3 Mon Sep 17 00:00:00 2001 From: alistairewj <1282676+alistairewj@users.noreply.github.com> Date: Tue, 25 Aug 2026 01:27:06 +0000 Subject: [PATCH] chore: regenerate postgres/duckdb concepts from BigQuery sources --- mimic-iii/concepts_postgres/code_status.sql | 5 ++- .../comorbidity/elixhauser_ahrq_v37.sql | 3 +- .../elixhauser_ahrq_v37_no_drg.sql | 10 ++++- .../comorbidity/elixhauser_quan.sql | 16 ++++++- .../comorbidity/elixhauser_score_ahrq.sql | 3 +- .../comorbidity/elixhauser_score_quan.sql | 3 +- .../demographics/heightweight.sql | 8 +++- .../demographics/icustay_detail.sql | 9 +++- .../demographics/icustay_hours.sql | 8 +++- .../demographics/icustay_times.sql | 3 +- .../concepts_postgres/diagnosis/ccs_dx.sql | 5 ++- .../durations/adenosine_durations.sql | 7 ++- .../durations/crrt_durations.sql | 4 +- .../durations/dobutamine_dose.sql | 6 ++- .../durations/dobutamine_durations.sql | 5 ++- .../durations/dopamine_dose.sql | 6 ++- .../durations/dopamine_durations.sql | 5 ++- .../durations/epinephrine_dose.sql | 7 ++- .../durations/epinephrine_durations.sql | 5 ++- .../durations/isuprel_durations.sql | 5 ++- .../durations/milrinone_durations.sql | 5 ++- .../durations/neuroblock_dose.sql | 8 +++- .../durations/norepinephrine_dose.sql | 7 ++- .../durations/norepinephrine_durations.sql | 5 ++- .../durations/phenylephrine_dose.sql | 6 ++- .../durations/phenylephrine_durations.sql | 5 ++- .../durations/vasopressin_dose.sql | 6 ++- .../durations/vasopressin_durations.sql | 5 ++- .../durations/vasopressor_durations.sql | 14 +++++- .../durations/ventilation_classification.sql | 4 +- .../durations/ventilation_durations.sql | 14 +++++- .../durations/weight_durations.sql | 16 +++++-- mimic-iii/concepts_postgres/echo_data.sql | 4 +- .../firstday/blood_gas_first_day.sql | 5 ++- .../firstday/gcs_first_day.sql | 19 +++++++- .../firstday/height_first_day.sql | 7 ++- .../firstday/labs_first_day.sql | 3 +- .../firstday/rrt_first_day.sql | 35 ++++++++++++++- .../firstday/urine_output_first_day.sql | 4 +- .../firstday/ventilation_first_day.sql | 4 +- .../firstday/vitals_first_day.sql | 3 +- .../firstday/weight_first_day.sql | 5 ++- .../fluid_balance/colloid_bolus.sql | 4 +- .../fluid_balance/ffp_transfusion.sql | 3 +- .../fluid_balance/rbc_transfusion.sql | 3 +- .../organfailure/kdigo_stages.sql | 5 ++- .../organfailure/kdigo_stages_48hr.sql | 5 ++- .../organfailure/kdigo_stages_7day.sql | 5 ++- .../concepts_postgres/organfailure/meld.sql | 29 +++++++++++- .../concepts_postgres/pivot/pivoted_bg.sql | 9 +++- .../pivot/pivoted_bg_art.sql | 4 +- .../concepts_postgres/pivot/pivoted_gcs.sql | 25 ++++++++++- .../pivot/pivoted_height.sql | 12 ++++- .../pivot/pivoted_invasive_lines.sql | 3 +- .../concepts_postgres/pivot/pivoted_lab.sql | 4 +- .../concepts_postgres/pivot/pivoted_sofa.sql | 36 ++++++++++++++- .../concepts_postgres/pivot/pivoted_vital.sql | 3 +- mimic-iii/concepts_postgres/rrt.sql | 35 ++++++++++++++- mimic-iii/concepts_postgres/sepsis/angus.sql | 10 ++++- .../concepts_postgres/sepsis/explicit.sql | 5 ++- mimic-iii/concepts_postgres/sepsis/martin.sql | 5 ++- .../severityscores/apsiii.sql | 38 +++++++++++++++- .../concepts_postgres/severityscores/lods.sql | 32 ++++++++++++- .../severityscores/mlods.sql | 30 ++++++++++++- .../severityscores/oasis.sql | 27 ++++++++++- .../severityscores/qsofa.sql | 22 ++++++++- .../concepts_postgres/severityscores/saps.sql | 28 +++++++++++- .../severityscores/sapsii.sql | 31 ++++++++++++- .../concepts_postgres/severityscores/sirs.sql | 30 ++++++++++++- .../concepts_postgres/severityscores/sofa.sql | 36 +++++++++++++-- .../comorbidity/charlson.sql | 17 ++++++- .../concepts_postgres/demographics/age.sql | 17 ++++++- .../demographics/icustay_hourly.sql | 9 +++- .../demographics/icustay_times.sql | 4 +- .../demographics/weight_durations.sql | 6 ++- .../firstday/first_day_bg.sql | 3 +- .../firstday/first_day_gcs.sql | 11 ++++- .../firstday/first_day_height.sql | 5 ++- .../firstday/first_day_rrt.sql | 3 +- .../firstday/first_day_sofa.sql | 39 ++++++++++++++-- .../firstday/first_day_vitalsign.sql | 3 +- .../firstday/first_day_weight.sql | 5 ++- mimic-iv/concepts_postgres/measurement/bg.sql | 8 +++- .../measurement/blood_differential.sql | 3 +- .../measurement/chemistry.sql | 5 ++- .../measurement/creatinine_baseline.sql | 11 ++++- .../concepts_postgres/measurement/gcs.sql | 20 ++++++++- .../measurement/oxygen_delivery.sql | 13 +++++- .../measurement/urine_output_rate.sql | 5 ++- .../measurement/vitalsign.sql | 4 +- .../medication/dobutamine.sql | 3 +- .../concepts_postgres/medication/dopamine.sql | 3 +- .../medication/epinephrine.sql | 3 +- .../medication/milrinone.sql | 3 +- .../medication/norepinephrine.sql | 3 +- .../norepinephrine_equivalent_dose.sql | 12 ++++- .../medication/phenylephrine.sql | 3 +- .../medication/vasoactive_agent.sql | 15 +++++-- .../medication/vasopressin.sql | 3 +- .../organfailure/kdigo_stages.sql | 5 ++- .../concepts_postgres/organfailure/meld.sql | 45 ++++++++++++++++++- mimic-iv/concepts_postgres/score/apsiii.sql | 32 ++++++++++++- mimic-iv/concepts_postgres/score/lods.sql | 27 ++++++++++- mimic-iv/concepts_postgres/score/oasis.sql | 26 ++++++++++- mimic-iv/concepts_postgres/score/sapsii.sql | 22 ++++++++- mimic-iv/concepts_postgres/score/sirs.sql | 30 ++++++++++++- mimic-iv/concepts_postgres/score/sofa.sql | 32 ++++++++++++- mimic-iv/concepts_postgres/sepsis/sepsis3.sql | 8 +++- .../sepsis/suspicion_of_infection.sql | 6 ++- .../treatment/code_status.sql | 6 ++- mimic-iv/concepts_postgres/treatment/crrt.sql | 3 +- mimic-iv/concepts_postgres/treatment/rrt.sql | 6 ++- .../treatment/ventilation.sql | 20 ++++++++- 113 files changed, 1144 insertions(+), 149 deletions(-) diff --git a/mimic-iii/concepts_postgres/code_status.sql b/mimic-iii/concepts_postgres/code_status.sql index 409952153..bb644271a 100644 --- a/mimic-iii/concepts_postgres/code_status.sql +++ b/mimic-iii/concepts_postgres/code_status.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.code_status; CREATE TABLE mimiciii_derived.code_status AS -/* This query extracts: */ /* i) a patient's first code status */ /* ii) a patient's last code status */ /* iii) the time of the first entry of DNR or CMO */ +/* This query extracts: */ +/* i) a patient's first code status */ +/* ii) a patient's last code status */ +/* iii) the time of the first entry of DNR or CMO */ WITH t1 AS ( SELECT icustay_id, diff --git a/mimic-iii/concepts_postgres/comorbidity/elixhauser_ahrq_v37.sql b/mimic-iii/concepts_postgres/comorbidity/elixhauser_ahrq_v37.sql index d8b4702b4..59301a588 100644 --- a/mimic-iii/concepts_postgres/comorbidity/elixhauser_ahrq_v37.sql +++ b/mimic-iii/concepts_postgres/comorbidity/elixhauser_ahrq_v37.sql @@ -1019,7 +1019,8 @@ WITH eliflg AS ( GROUP BY d.hadm_id ) -/* now merge these flags together to define elixhauser */ /* most are straightforward.. but hypertension flags are a bit more complicated */ +/* now merge these flags together to define elixhauser */ +/* most are straightforward.. but hypertension flags are a bit more complicated */ SELECT adm.subject_id, adm.hadm_id, diff --git a/mimic-iii/concepts_postgres/comorbidity/elixhauser_ahrq_v37_no_drg.sql b/mimic-iii/concepts_postgres/comorbidity/elixhauser_ahrq_v37_no_drg.sql index 5bfd7e3a0..876895aaf 100644 --- a/mimic-iii/concepts_postgres/comorbidity/elixhauser_ahrq_v37_no_drg.sql +++ b/mimic-iii/concepts_postgres/comorbidity/elixhauser_ahrq_v37_no_drg.sql @@ -1,6 +1,11 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.elixhauser_ahrq_v37_no_drg; CREATE TABLE mimiciii_derived.elixhauser_ahrq_v37_no_drg AS -/* This code uses the latest version of Elixhauser provided by AHRQ */ /* However, it does *not* filter based on diagnosis related groups (DRGs) */ /* As such, "comorbidities" identified are more likely to be associated with the primary reason for their hospital stay */ /* The code: */ /* removes "primary" ICD9_CODE (seq_num != 1) */ /* uses AHRQ published rules to define comorbidities */ +/* This code uses the latest version of Elixhauser provided by AHRQ */ +/* However, it does *not* filter based on diagnosis related groups (DRGs) */ +/* As such, "comorbidities" identified are more likely to be associated with the primary reason for their hospital stay */ +/* The code: */ +/* removes "primary" ICD9_CODE (seq_num != 1) */ +/* uses AHRQ published rules to define comorbidities */ WITH eliflg AS ( SELECT hadm_id, @@ -613,7 +618,8 @@ WITH eliflg AS ( GROUP BY hadm_id ) -/* now merge these flags together to define elixhauser */ /* most are straightforward.. but hypertension flags are a bit more complicated */ +/* now merge these flags together to define elixhauser */ +/* most are straightforward.. but hypertension flags are a bit more complicated */ SELECT adm.subject_id, adm.hadm_id, diff --git a/mimic-iii/concepts_postgres/comorbidity/elixhauser_quan.sql b/mimic-iii/concepts_postgres/comorbidity/elixhauser_quan.sql index 28fd2922c..c4edda9e7 100644 --- a/mimic-iii/concepts_postgres/comorbidity/elixhauser_quan.sql +++ b/mimic-iii/concepts_postgres/comorbidity/elixhauser_quan.sql @@ -1,6 +1,17 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.elixhauser_quan; CREATE TABLE mimiciii_derived.elixhauser_quan AS -/* This code calculates the Elixhauser comorbidities as defined in Quan et. al 2009: */ /* Quan, Hude, et al. "Coding algorithms for defining comorbidities in */ /* ICD-9-CM and ICD-10 administrative data." Medical care (2005): 1130-1139. */ /* https://www.ncbi.nlm.nih.gov/pubmed/16224307 */ /* Quan defined an "Enhanced ICD-9" coding scheme for deriving Elixhauser */ /* comorbidities from ICD-9 billing codes. This script implements that calculation. */ /* The logic of the code is roughly that, if the comorbidity lists a length 3 */ /* ICD-9 code (e.g. 585), then we only require a match on the first 3 characters. */ /* This code derives each comorbidity as follows: */ /* 1) ICD9_CODE is directly compared to 5 character codes */ /* 2) The first 4 characters of ICD9_CODE are compared to 4 character codes */ /* 3) The first 3 characters of ICD9_CODE are compared to 3 character codes */ +/* This code calculates the Elixhauser comorbidities as defined in Quan et. al 2009: */ +/* Quan, Hude, et al. "Coding algorithms for defining comorbidities in */ +/* ICD-9-CM and ICD-10 administrative data." Medical care (2005): 1130-1139. */ +/* https://www.ncbi.nlm.nih.gov/pubmed/16224307 */ +/* Quan defined an "Enhanced ICD-9" coding scheme for deriving Elixhauser */ +/* comorbidities from ICD-9 billing codes. This script implements that calculation. */ +/* The logic of the code is roughly that, if the comorbidity lists a length 3 */ +/* ICD-9 code (e.g. 585), then we only require a match on the first 3 characters. */ +/* This code derives each comorbidity as follows: */ +/* 1) ICD9_CODE is directly compared to 5 character codes */ +/* 2) The first 4 characters of ICD9_CODE are compared to 4 character codes */ +/* 3) The first 3 characters of ICD9_CODE are compared to 3 character codes */ WITH eliflg AS ( SELECT hadm_id, @@ -388,7 +399,8 @@ WITH eliflg AS ( GROUP BY hadm_id ) -/* now merge these flags together to define elixhauser */ /* most are straightforward.. but hypertension flags are a bit more complicated */ +/* now merge these flags together to define elixhauser */ +/* most are straightforward.. but hypertension flags are a bit more complicated */ SELECT adm.hadm_id, chf AS congestive_heart_failure, diff --git a/mimic-iii/concepts_postgres/comorbidity/elixhauser_score_ahrq.sql b/mimic-iii/concepts_postgres/comorbidity/elixhauser_score_ahrq.sql index 8336f2ab3..4c31ee120 100644 --- a/mimic-iii/concepts_postgres/comorbidity/elixhauser_score_ahrq.sql +++ b/mimic-iii/concepts_postgres/comorbidity/elixhauser_score_ahrq.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.elixhauser_score_ahrq; CREATE TABLE mimiciii_derived.elixhauser_score_ahrq AS -/* This query provides various methods of combining the Elixhauser components into a single score */ /* The methods are called "vanWalRaven" and "SID30", and "SID29" */ +/* This query provides various methods of combining the Elixhauser components into a single score */ +/* The methods are called "vanWalRaven" and "SID30", and "SID29" */ SELECT subject_id, hadm_id, /* Below is the van Walraven score */ diff --git a/mimic-iii/concepts_postgres/comorbidity/elixhauser_score_quan.sql b/mimic-iii/concepts_postgres/comorbidity/elixhauser_score_quan.sql index 8cce30acb..d94e0a2d4 100644 --- a/mimic-iii/concepts_postgres/comorbidity/elixhauser_score_quan.sql +++ b/mimic-iii/concepts_postgres/comorbidity/elixhauser_score_quan.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.elixhauser_score_quan; CREATE TABLE mimiciii_derived.elixhauser_score_quan AS -/* This query provides various methods of combining the Elixhauser components into a single score */ /* The methods are called "vanWalRaven" and "SID30", and "SID29" */ +/* This query provides various methods of combining the Elixhauser components into a single score */ +/* The methods are called "vanWalRaven" and "SID30", and "SID29" */ SELECT hadm_id, /* Below is the van Walraven score */ 0 * aids + 0 * alcohol_abuse + -2 * blood_loss_anemia + 7 * congestive_heart_failure + 3 /* Cardiac arrhythmias are not included in van Walraven based on Quan 2007 */ * chronic_pulmonary + 3 * coagulopathy + -2 * deficiency_anemias + -3 * depression + 0 * diabetes_complicated + 0 * diabetes_uncomplicated + -7 * drug_abuse + 5 * fluid_electrolyte + 0 * hypertension + 0 * hypothyroidism + 11 * liver_disease + 9 * lymphoma + 12 * metastatic_cancer + 6 * other_neurological + -4 * obesity + 7 * paralysis + 2 * peripheral_vascular + 0 * peptic_ulcer + 0 * psychoses + 4 * pulmonary_circulation + 0 * rheumatoid_arthritis + 5 * renal_failure + 4 * solid_tumor + -1 * valvular_disease + 6 * weight_loss AS elixhauser_vanwalraven, /* Below is the 29 component SID score */ diff --git a/mimic-iii/concepts_postgres/demographics/heightweight.sql b/mimic-iii/concepts_postgres/demographics/heightweight.sql index 10a692f36..8e9a43acc 100644 --- a/mimic-iii/concepts_postgres/demographics/heightweight.sql +++ b/mimic-iii/concepts_postgres/demographics/heightweight.sql @@ -1,6 +1,12 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.heightweight; CREATE TABLE mimiciii_derived.heightweight AS -/* ------------------------------------------------------------------ */ /* Title: Extract height and weight for ICUSTAY_IDs */ /* Description: This query gets the first, minimum, and maximum weight and height */ /* for a single ICUSTAY_ID. It extracts data from the CHARTEVENTS table. */ /* MIMIC version: MIMIC-III v1.4 */ /* ------------------------------------------------------------------ */ /* prep height */ +/* ------------------------------------------------------------------ */ +/* Title: Extract height and weight for ICUSTAY_IDs */ +/* Description: This query gets the first, minimum, and maximum weight and height */ +/* for a single ICUSTAY_ID. It extracts data from the CHARTEVENTS table. */ +/* MIMIC version: MIMIC-III v1.4 */ +/* ------------------------------------------------------------------ */ +/* prep height */ WITH ht_stg AS ( SELECT c.subject_id, diff --git a/mimic-iii/concepts_postgres/demographics/icustay_detail.sql b/mimic-iii/concepts_postgres/demographics/icustay_detail.sql index 0e435ff7e..e8bac8b2a 100644 --- a/mimic-iii/concepts_postgres/demographics/icustay_detail.sql +++ b/mimic-iii/concepts_postgres/demographics/icustay_detail.sql @@ -1,6 +1,13 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.icustay_detail; CREATE TABLE mimiciii_derived.icustay_detail AS -/* ------------------------------------------------------------------ */ /* Title: Detailed information on ICUSTAY_ID */ /* Description: This query provides a useful set of information regarding patient */ /* ICU stays. The information is combined from the admissions, patients, and */ /* icustays tables. It includes age, length of stay, sequence, and expiry flags. */ /* MIMIC version: MIMIC-III v1.3 */ /* ------------------------------------------------------------------ */ /* This query extracts useful demographic/administrative information for patient ICU stays */ +/* ------------------------------------------------------------------ */ +/* Title: Detailed information on ICUSTAY_ID */ +/* Description: This query provides a useful set of information regarding patient */ +/* ICU stays. The information is combined from the admissions, patients, and */ +/* icustays tables. It includes age, length of stay, sequence, and expiry flags. */ +/* MIMIC version: MIMIC-III v1.3 */ +/* ------------------------------------------------------------------ */ +/* This query extracts useful demographic/administrative information for patient ICU stays */ SELECT ie.subject_id, ie.hadm_id, diff --git a/mimic-iii/concepts_postgres/demographics/icustay_hours.sql b/mimic-iii/concepts_postgres/demographics/icustay_hours.sql index cfcabe0d7..62ea1a6a1 100644 --- a/mimic-iii/concepts_postgres/demographics/icustay_hours.sql +++ b/mimic-iii/concepts_postgres/demographics/icustay_hours.sql @@ -1,6 +1,12 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.icustay_hours; CREATE TABLE mimiciii_derived.icustay_hours AS -/* This query generates a row for every hour the patient is in the ICU. */ /* The hours are based on clock-hours (i.e. 02:00, 03:00). */ /* The hour clock starts 24 hours before the first heart rate measurement. */ /* Note that the time of the first heart rate measurement is ceilinged to the hour. */ /* this query extracts the cohort and every possible hour they were in the ICU */ /* this table can be to other tables on ICUSTAY_ID and (ENDTIME - 1 hour,ENDTIME] */ /* get first/last measurement time */ +/* This query generates a row for every hour the patient is in the ICU. */ +/* The hours are based on clock-hours (i.e. 02:00, 03:00). */ +/* The hour clock starts 24 hours before the first heart rate measurement. */ +/* Note that the time of the first heart rate measurement is ceilinged to the hour. */ +/* this query extracts the cohort and every possible hour they were in the ICU */ +/* this table can be to other tables on ICUSTAY_ID and (ENDTIME - 1 hour,ENDTIME] */ +/* get first/last measurement time */ WITH all_hours AS ( SELECT it.icustay_id, /* ceiling the intime to the nearest hour by adding 59 minutes then truncating */ /* note thart we truncate by parsing as string, rather than using DATETIME_TRUNC */ /* this is done to enable compatibility with psql */ diff --git a/mimic-iii/concepts_postgres/demographics/icustay_times.sql b/mimic-iii/concepts_postgres/demographics/icustay_times.sql index 854b7ebf8..bed27f9c2 100644 --- a/mimic-iii/concepts_postgres/demographics/icustay_times.sql +++ b/mimic-iii/concepts_postgres/demographics/icustay_times.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.icustay_times; CREATE TABLE mimiciii_derived.icustay_times AS -/* create a table which has fuzzy boundaries on hospital admission */ /* involves first creating a lag/lead version of disch/admit time */ +/* create a table which has fuzzy boundaries on hospital admission */ +/* involves first creating a lag/lead version of disch/admit time */ WITH h AS ( SELECT subject_id, diff --git a/mimic-iii/concepts_postgres/diagnosis/ccs_dx.sql b/mimic-iii/concepts_postgres/diagnosis/ccs_dx.sql index 19c352b05..a17361aa6 100644 --- a/mimic-iii/concepts_postgres/diagnosis/ccs_dx.sql +++ b/mimic-iii/concepts_postgres/diagnosis/ccs_dx.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.ccs_dx; CREATE TABLE mimiciii_derived.ccs_dx AS -/* add in matched ID, name, and ccs_id */ /* matched id (ccs_mid): the ccs ID with the hierarchy, e.g. 7.1.2.1 */ /* name (ccs_name): the most granular CCS category the diagnosis is in */ /* ID (ccs_id): the CCS identifier for the ICD-9 code (integer) */ +/* add in matched ID, name, and ccs_id */ +/* matched id (ccs_mid): the ccs ID with the hierarchy, e.g. 7.1.2.1 */ +/* name (ccs_name): the most granular CCS category the diagnosis is in */ +/* ID (ccs_id): the CCS identifier for the ICD-9 code (integer) */ SELECT icd9_code, COALESCE(ccs_level4, ccs_level3, ccs_level2, ccs_level1) AS ccs_matched_id, /* remove the trailing ccs_id from name column, i.e. "Burns [240.]" -> "Burns" */ diff --git a/mimic-iii/concepts_postgres/durations/adenosine_durations.sql b/mimic-iii/concepts_postgres/durations/adenosine_durations.sql index 804614433..291978449 100644 --- a/mimic-iii/concepts_postgres/durations/adenosine_durations.sql +++ b/mimic-iii/concepts_postgres/durations/adenosine_durations.sql @@ -1,6 +1,11 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.adenosine_durations; CREATE TABLE mimiciii_derived.adenosine_durations AS -/* This query extracts durations of adenosine administration */ /* Consecutive administrations are numbered 1, 2, ... */ /* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ /* *** COULD NOT FIND ADENOSINE IN THE INPUTEVENTS_MV TABLE *** */ /* This drug is rarely used - it could just be that it was never used in MetaVision. */ /* If using this code, ensure the durations make sense for carevue patients first */ +/* This query extracts durations of adenosine administration */ +/* Consecutive administrations are numbered 1, 2, ... */ +/* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ +/* *** COULD NOT FIND ADENOSINE IN THE INPUTEVENTS_MV TABLE *** */ +/* This drug is rarely used - it could just be that it was never used in MetaVision. */ +/* If using this code, ensure the durations make sense for carevue patients first */ WITH vasocv1 AS ( SELECT icustay_id, diff --git a/mimic-iii/concepts_postgres/durations/crrt_durations.sql b/mimic-iii/concepts_postgres/durations/crrt_durations.sql index 458a5f7be..6072a8961 100644 --- a/mimic-iii/concepts_postgres/durations/crrt_durations.sql +++ b/mimic-iii/concepts_postgres/durations/crrt_durations.sql @@ -152,7 +152,9 @@ WITH crrt_settings AS ( END AS num /* - now we convert CHARTTIME of CRRT settings into durations */ FROM vd1 - /* now we can isolate to just rows with settings */ /* (before we had rows with start/end flags) */ /* this removes any null values for NewCRRT */ + /* now we can isolate to just rows with settings */ + /* (before we had rows with start/end flags) */ + /* this removes any null values for NewCRRT */ WHERE RRT_start = 1 OR RRT = 1 OR RRT_end = 1 ), fin /* create the durations for each CRRT instance */ AS ( diff --git a/mimic-iii/concepts_postgres/durations/dobutamine_dose.sql b/mimic-iii/concepts_postgres/durations/dobutamine_dose.sql index 286c3bbac..8db454250 100644 --- a/mimic-iii/concepts_postgres/durations/dobutamine_dose.sql +++ b/mimic-iii/concepts_postgres/durations/dobutamine_dose.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.dobutamine_dose; CREATE TABLE mimiciii_derived.dobutamine_dose AS -/* This query extracts dose+durations of dopamine administration */ /* Get drug administration data from CareVue first */ +/* This query extracts dose+durations of dopamine administration */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT icustay_id, @@ -172,7 +173,8 @@ WITH vasocv1 AS ( itemid = 221653 /* dobutamine */ AND statusdescription <> 'Rewritten' /* only valid orders */ ) -/* now assign this data to every hour of the patient's stay */ /* vaso_amount for carevue is not accurate */ +/* now assign this data to every hour of the patient's stay */ +/* vaso_amount for carevue is not accurate */ SELECT icustay_id, starttime, diff --git a/mimic-iii/concepts_postgres/durations/dobutamine_durations.sql b/mimic-iii/concepts_postgres/durations/dobutamine_durations.sql index aca824bf0..5464a9cb1 100644 --- a/mimic-iii/concepts_postgres/durations/dobutamine_durations.sql +++ b/mimic-iii/concepts_postgres/durations/dobutamine_durations.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.dobutamine_durations; CREATE TABLE mimiciii_derived.dobutamine_durations AS -/* This query extracts durations of dobutamine administration */ /* Consecutive administrations are numbered 1, 2, ... */ /* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ /* Get drug administration data from CareVue first */ +/* This query extracts durations of dobutamine administration */ +/* Consecutive administrations are numbered 1, 2, ... */ +/* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT icustay_id, diff --git a/mimic-iii/concepts_postgres/durations/dopamine_dose.sql b/mimic-iii/concepts_postgres/durations/dopamine_dose.sql index 2f57f1a0a..c58114582 100644 --- a/mimic-iii/concepts_postgres/durations/dopamine_dose.sql +++ b/mimic-iii/concepts_postgres/durations/dopamine_dose.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.dopamine_dose; CREATE TABLE mimiciii_derived.dopamine_dose AS -/* This query extracts dose+durations of dopamine administration */ /* Get drug administration data from CareVue first */ +/* This query extracts dose+durations of dopamine administration */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT icustay_id, @@ -172,7 +173,8 @@ WITH vasocv1 AS ( itemid = 221662 /* dopamine */ AND statusdescription <> 'Rewritten' /* only valid orders */ ) -/* now assign this data to every hour of the patient's stay */ /* vaso_amount for carevue is not accurate */ +/* now assign this data to every hour of the patient's stay */ +/* vaso_amount for carevue is not accurate */ SELECT icustay_id, starttime, diff --git a/mimic-iii/concepts_postgres/durations/dopamine_durations.sql b/mimic-iii/concepts_postgres/durations/dopamine_durations.sql index e36814988..9ff87a798 100644 --- a/mimic-iii/concepts_postgres/durations/dopamine_durations.sql +++ b/mimic-iii/concepts_postgres/durations/dopamine_durations.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.dopamine_durations; CREATE TABLE mimiciii_derived.dopamine_durations AS -/* This query extracts durations of dopamine administration */ /* Consecutive administrations are numbered 1, 2, ... */ /* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ /* Get drug administration data from CareVue first */ +/* This query extracts durations of dopamine administration */ +/* Consecutive administrations are numbered 1, 2, ... */ +/* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT icustay_id, diff --git a/mimic-iii/concepts_postgres/durations/epinephrine_dose.sql b/mimic-iii/concepts_postgres/durations/epinephrine_dose.sql index 55936a7b9..322c6400f 100644 --- a/mimic-iii/concepts_postgres/durations/epinephrine_dose.sql +++ b/mimic-iii/concepts_postgres/durations/epinephrine_dose.sql @@ -1,6 +1,8 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.epinephrine_dose; CREATE TABLE mimiciii_derived.epinephrine_dose AS -/* This query extracts dose+durations of epinephrine administration */ /* Requires the weightfirstday table */ /* Get drug administration data from CareVue first */ +/* This query extracts dose+durations of epinephrine administration */ +/* Requires the weightfirstday table */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT cv.icustay_id, @@ -186,7 +188,8 @@ WITH vasocv1 AS ( itemid = 221289 /* epinephrine */ AND statusdescription <> 'Rewritten' /* only valid orders */ ) -/* now assign this data to every hour of the patient's stay */ /* vaso_amount for carevue is not accurate */ +/* now assign this data to every hour of the patient's stay */ +/* vaso_amount for carevue is not accurate */ SELECT icustay_id, starttime, diff --git a/mimic-iii/concepts_postgres/durations/epinephrine_durations.sql b/mimic-iii/concepts_postgres/durations/epinephrine_durations.sql index 7020f9094..7a981da4d 100644 --- a/mimic-iii/concepts_postgres/durations/epinephrine_durations.sql +++ b/mimic-iii/concepts_postgres/durations/epinephrine_durations.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.epinephrine_durations; CREATE TABLE mimiciii_derived.epinephrine_durations AS -/* This query extracts durations of epinephrine administration */ /* Consecutive administrations are numbered 1, 2, ... */ /* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ /* Get drug administration data from CareVue first */ +/* This query extracts durations of epinephrine administration */ +/* Consecutive administrations are numbered 1, 2, ... */ +/* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT icustay_id, diff --git a/mimic-iii/concepts_postgres/durations/isuprel_durations.sql b/mimic-iii/concepts_postgres/durations/isuprel_durations.sql index 01e0dd145..bf1450ed6 100644 --- a/mimic-iii/concepts_postgres/durations/isuprel_durations.sql +++ b/mimic-iii/concepts_postgres/durations/isuprel_durations.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.isuprel_durations; CREATE TABLE mimiciii_derived.isuprel_durations AS -/* This query extracts durations of isuprel administration */ /* Consecutive administrations are numbered 1, 2, ... */ /* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ /* Get drug administration data from CareVue first */ +/* This query extracts durations of isuprel administration */ +/* Consecutive administrations are numbered 1, 2, ... */ +/* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT icustay_id, diff --git a/mimic-iii/concepts_postgres/durations/milrinone_durations.sql b/mimic-iii/concepts_postgres/durations/milrinone_durations.sql index ddb7e61a5..8bc13814c 100644 --- a/mimic-iii/concepts_postgres/durations/milrinone_durations.sql +++ b/mimic-iii/concepts_postgres/durations/milrinone_durations.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.milrinone_durations; CREATE TABLE mimiciii_derived.milrinone_durations AS -/* This query extracts durations of milrinone administration */ /* Consecutive administrations are numbered 1, 2, ... */ /* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ /* Get drug administration data from CareVue first */ +/* This query extracts durations of milrinone administration */ +/* Consecutive administrations are numbered 1, 2, ... */ +/* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT icustay_id, diff --git a/mimic-iii/concepts_postgres/durations/neuroblock_dose.sql b/mimic-iii/concepts_postgres/durations/neuroblock_dose.sql index 5da41afa9..2105c6513 100644 --- a/mimic-iii/concepts_postgres/durations/neuroblock_dose.sql +++ b/mimic-iii/concepts_postgres/durations/neuroblock_dose.sql @@ -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, @@ -227,7 +230,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, diff --git a/mimic-iii/concepts_postgres/durations/norepinephrine_dose.sql b/mimic-iii/concepts_postgres/durations/norepinephrine_dose.sql index 21c2c8b8b..d4786f224 100644 --- a/mimic-iii/concepts_postgres/durations/norepinephrine_dose.sql +++ b/mimic-iii/concepts_postgres/durations/norepinephrine_dose.sql @@ -1,6 +1,8 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.norepinephrine_dose; CREATE TABLE mimiciii_derived.norepinephrine_dose AS -/* This query extracts dose+durations of norepinephrine administration */ /* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ /* Get drug administration data from CareVue first */ +/* This query extracts dose+durations of norepinephrine administration */ +/* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT cv.icustay_id, @@ -185,7 +187,8 @@ WITH vasocv1 AS ( itemid = 221906 /* norepinephrine */ AND statusdescription <> 'Rewritten' /* only valid orders */ ) -/* now assign this data to every hour of the patient's stay */ /* vaso_amount for carevue is not accurate */ +/* now assign this data to every hour of the patient's stay */ +/* vaso_amount for carevue is not accurate */ SELECT icustay_id, starttime, diff --git a/mimic-iii/concepts_postgres/durations/norepinephrine_durations.sql b/mimic-iii/concepts_postgres/durations/norepinephrine_durations.sql index a734ed12c..100781d2e 100644 --- a/mimic-iii/concepts_postgres/durations/norepinephrine_durations.sql +++ b/mimic-iii/concepts_postgres/durations/norepinephrine_durations.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.norepinephrine_durations; CREATE TABLE mimiciii_derived.norepinephrine_durations AS -/* This query extracts durations of norepinephrine administration */ /* Consecutive administrations are numbered 1, 2, ... */ /* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ /* Get drug administration data from CareVue first */ +/* This query extracts durations of norepinephrine administration */ +/* Consecutive administrations are numbered 1, 2, ... */ +/* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT icustay_id, diff --git a/mimic-iii/concepts_postgres/durations/phenylephrine_dose.sql b/mimic-iii/concepts_postgres/durations/phenylephrine_dose.sql index 1423c0583..193cf36f2 100644 --- a/mimic-iii/concepts_postgres/durations/phenylephrine_dose.sql +++ b/mimic-iii/concepts_postgres/durations/phenylephrine_dose.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.phenylephrine_dose; CREATE TABLE mimiciii_derived.phenylephrine_dose AS -/* This query extracts dose+durations of phenylephrine administration */ /* Get drug administration data from CareVue first */ +/* This query extracts dose+durations of phenylephrine administration */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT icustay_id, @@ -172,7 +173,8 @@ WITH vasocv1 AS ( itemid = 221749 /* phenylephrine */ AND statusdescription <> 'Rewritten' /* only valid orders */ ) -/* now assign this data to every hour of the patient's stay */ /* vaso_amount for carevue is not accurate */ +/* now assign this data to every hour of the patient's stay */ +/* vaso_amount for carevue is not accurate */ SELECT icustay_id, starttime, diff --git a/mimic-iii/concepts_postgres/durations/phenylephrine_durations.sql b/mimic-iii/concepts_postgres/durations/phenylephrine_durations.sql index 905d65b8a..ddc1ed6e3 100644 --- a/mimic-iii/concepts_postgres/durations/phenylephrine_durations.sql +++ b/mimic-iii/concepts_postgres/durations/phenylephrine_durations.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.phenylephrine_durations; CREATE TABLE mimiciii_derived.phenylephrine_durations AS -/* This query extracts durations of phenylephrine administration */ /* Consecutive administrations are numbered 1, 2, ... */ /* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ /* Get drug administration data from CareVue first */ +/* This query extracts durations of phenylephrine administration */ +/* Consecutive administrations are numbered 1, 2, ... */ +/* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT icustay_id, diff --git a/mimic-iii/concepts_postgres/durations/vasopressin_dose.sql b/mimic-iii/concepts_postgres/durations/vasopressin_dose.sql index 626c78250..bc2b66f75 100644 --- a/mimic-iii/concepts_postgres/durations/vasopressin_dose.sql +++ b/mimic-iii/concepts_postgres/durations/vasopressin_dose.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.vasopressin_dose; CREATE TABLE mimiciii_derived.vasopressin_dose AS -/* This query extracts dose+durations of vasopressin administration */ /* Get drug administration data from CareVue first */ +/* This query extracts dose+durations of vasopressin administration */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT icustay_id, @@ -172,7 +173,8 @@ WITH vasocv1 AS ( itemid = 222315 /* vasopressin */ AND statusdescription <> 'Rewritten' /* only valid orders */ ) -/* now assign this data to every hour of the patient's stay */ /* vaso_amount for carevue is not accurate */ +/* now assign this data to every hour of the patient's stay */ +/* vaso_amount for carevue is not accurate */ SELECT icustay_id, starttime, diff --git a/mimic-iii/concepts_postgres/durations/vasopressin_durations.sql b/mimic-iii/concepts_postgres/durations/vasopressin_durations.sql index a7ecd41ea..a41571ec4 100644 --- a/mimic-iii/concepts_postgres/durations/vasopressin_durations.sql +++ b/mimic-iii/concepts_postgres/durations/vasopressin_durations.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.vasopressin_durations; CREATE TABLE mimiciii_derived.vasopressin_durations AS -/* This query extracts durations of vasopressin administration */ /* Consecutive administrations are numbered 1, 2, ... */ /* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ /* Get drug administration data from CareVue first */ +/* This query extracts durations of vasopressin administration */ +/* Consecutive administrations are numbered 1, 2, ... */ +/* Total time on the drug can be calculated from this table by grouping using ICUSTAY_ID */ +/* Get drug administration data from CareVue first */ WITH vasocv1 AS ( SELECT icustay_id, diff --git a/mimic-iii/concepts_postgres/durations/vasopressor_durations.sql b/mimic-iii/concepts_postgres/durations/vasopressor_durations.sql index 8ff68a0ee..96dbbfc00 100644 --- a/mimic-iii/concepts_postgres/durations/vasopressor_durations.sql +++ b/mimic-iii/concepts_postgres/durations/vasopressor_durations.sql @@ -1,6 +1,18 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.vasopressor_durations; CREATE TABLE mimiciii_derived.vasopressor_durations AS -/* This query extracts durations of vasopressor administration */ /* It groups together any administration of the below list of drugs: */ /* norepinephrine - 30047,30120,221906 */ /* epinephrine - 30044,30119,30309,221289 */ /* phenylephrine - 30127,30128,221749 */ /* vasopressin - 30051,222315 (42273, 42802 also for 2 patients) */ /* dopamine - 30043,30307,221662 */ /* dobutamine - 30042,30306,221653 */ /* milrinone - 30125,221986 */ /* Consecutive administrations are numbered 1, 2, ... */ /* Total time on the drug can be calculated from this table */ /* by grouping using ICUSTAY_ID */ /* select only the ITEMIDs from the inputevents_cv table related to vasopressors */ +/* This query extracts durations of vasopressor administration */ +/* It groups together any administration of the below list of drugs: */ +/* norepinephrine - 30047,30120,221906 */ +/* epinephrine - 30044,30119,30309,221289 */ +/* phenylephrine - 30127,30128,221749 */ +/* vasopressin - 30051,222315 (42273, 42802 also for 2 patients) */ +/* dopamine - 30043,30307,221662 */ +/* dobutamine - 30042,30306,221653 */ +/* milrinone - 30125,221986 */ +/* Consecutive administrations are numbered 1, 2, ... */ +/* Total time on the drug can be calculated from this table */ +/* by grouping using ICUSTAY_ID */ +/* select only the ITEMIDs from the inputevents_cv table related to vasopressors */ WITH io_cv AS ( SELECT icustay_id, diff --git a/mimic-iii/concepts_postgres/durations/ventilation_classification.sql b/mimic-iii/concepts_postgres/durations/ventilation_classification.sql index c726a1056..2276da4ba 100644 --- a/mimic-iii/concepts_postgres/durations/ventilation_classification.sql +++ b/mimic-iii/concepts_postgres/durations/ventilation_classification.sql @@ -234,7 +234,9 @@ GROUP BY icustay_id, charttime UNION -/* add in the extubation flags from procedureevents_mv */ /* note that we only need the start time for the extubation */ /* (extubation is always charted as ending 1 minute after it started) */ +/* add in the extubation flags from procedureevents_mv */ +/* note that we only need the start time for the extubation */ +/* (extubation is always charted as ending 1 minute after it started) */ SELECT icustay_id, starttime AS charttime, diff --git a/mimic-iii/concepts_postgres/durations/ventilation_durations.sql b/mimic-iii/concepts_postgres/durations/ventilation_durations.sql index 2c00b5e6d..840bf5846 100644 --- a/mimic-iii/concepts_postgres/durations/ventilation_durations.sql +++ b/mimic-iii/concepts_postgres/durations/ventilation_durations.sql @@ -1,6 +1,18 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.ventilation_durations; CREATE TABLE mimiciii_derived.ventilation_durations AS -/* This query extracts the duration of mechanical ventilation */ /* The main goal of the query is to aggregate sequential ventilator settings */ /* into single mechanical ventilation "events". The start and end time of these */ /* events can then be used for various purposes: calculating the total duration */ /* of mechanical ventilation, cross-checking values (e.g. PaO2:FiO2 on vent), etc */ /* The query's logic is roughly: */ /* 1) The presence of a mechanical ventilation setting starts a new ventilation event */ /* 2) Any instance of a setting in the next 8 hours continues the event */ /* 3) Certain elements end the current ventilation event */ /* a) documented extubation ends the current ventilation */ /* b) initiation of non-invasive vent and/or oxygen ends the current vent */ /* See the ventilation_classification.sql query for step 1 of the above. */ /* This query has the logic for converting events into durations. */ +/* This query extracts the duration of mechanical ventilation */ +/* The main goal of the query is to aggregate sequential ventilator settings */ +/* into single mechanical ventilation "events". The start and end time of these */ +/* events can then be used for various purposes: calculating the total duration */ +/* of mechanical ventilation, cross-checking values (e.g. PaO2:FiO2 on vent), etc */ +/* The query's logic is roughly: */ +/* 1) The presence of a mechanical ventilation setting starts a new ventilation event */ +/* 2) Any instance of a setting in the next 8 hours continues the event */ +/* 3) Certain elements end the current ventilation event */ +/* a) documented extubation ends the current ventilation */ +/* b) initiation of non-invasive vent and/or oxygen ends the current vent */ +/* See the ventilation_classification.sql query for step 1 of the above. */ +/* This query has the logic for converting events into durations. */ WITH vd0 AS ( SELECT icustay_id, /* this carries over the previous charttime which had a mechanical ventilation event */ diff --git a/mimic-iii/concepts_postgres/durations/weight_durations.sql b/mimic-iii/concepts_postgres/durations/weight_durations.sql index 93a698fed..f12a168a1 100644 --- a/mimic-iii/concepts_postgres/durations/weight_durations.sql +++ b/mimic-iii/concepts_postgres/durations/weight_durations.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.weight_durations; CREATE TABLE mimiciii_derived.weight_durations AS -/* This query extracts weights for adult ICU patients with start/stop times */ /* if an admission weight is given, then this is assigned from intime to outtime */ /* This query extracts weights for adult ICU patients with start/stop times */ /* if an admission weight is given, then this is assigned from intime to outtime */ +/* This query extracts weights for adult ICU patients with start/stop times */ +/* if an admission weight is given, then this is assigned from intime to outtime */ +/* This query extracts weights for adult ICU patients with start/stop times */ +/* if an admission weight is given, then this is assigned from intime to outtime */ WITH wt_neonate AS ( SELECT c.icustay_id, @@ -14,7 +17,9 @@ WITH wt_neonate AS ( AND NOT c.icustay_id IS NULL AND COALESCE(c.error, 0) = 0 AND /* wt_oz/wt_lb/wt_kg are only 0 erroneously, so drop these rows */ c.valuenum > 0 - /* a separate query was run to manually verify only 1 value exists per */ /* icustay_id/charttime/itemid grouping */ /* therefore, we can use max() across itemid to collapse these values to 1 row per group */ + /* a separate query was run to manually verify only 1 value exists per */ + /* icustay_id/charttime/itemid grouping */ + /* therefore, we can use max() across itemid to collapse these values to 1 row per group */ GROUP BY c.icustay_id, c.charttime @@ -42,7 +47,9 @@ WITH wt_neonate AS ( FROM mimiciii.chartevents AS c WHERE c.itemid IN (3723, 4183) AND NOT c.icustay_id IS NULL AND COALESCE(c.error, 0) = 0 - /* a separate query was run to manually verify only 1 value exists per */ /* icustay_id/charttime/itemid grouping */ /* therefore, we can use max() across itemid to collapse these values to 1 row per group */ + /* a separate query was run to manually verify only 1 value exists per */ + /* icustay_id/charttime/itemid grouping */ + /* therefore, we can use max() across itemid to collapse these values to 1 row per group */ GROUP BY c.icustay_id, c.charttime @@ -164,7 +171,8 @@ WITH wt_neonate AS ( wt.weight FROM mimiciii.icustays AS ie INNER JOIN ( - /* the below subquery returns one row for each unique icustay_id */ /* the row contains: the first starttime and the corresponding weight */ + /* the below subquery returns one row for each unique icustay_id */ + /* the row contains: the first starttime and the corresponding weight */ SELECT wt1.icustay_id, wt1.starttime, diff --git a/mimic-iii/concepts_postgres/echo_data.sql b/mimic-iii/concepts_postgres/echo_data.sql index 23ac113ef..b712609ac 100644 --- a/mimic-iii/concepts_postgres/echo_data.sql +++ b/mimic-iii/concepts_postgres/echo_data.sql @@ -1,6 +1,8 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.echo_data; CREATE TABLE mimiciii_derived.echo_data AS -/* This code extracts structured data from echocardiographies */ /* You can join it to the text notes using ROW_ID */ /* Just note that ROW_ID will differ across versions of MIMIC-III. */ +/* This code extracts structured data from echocardiographies */ +/* You can join it to the text notes using ROW_ID */ +/* Just note that ROW_ID will differ across versions of MIMIC-III. */ SELECT ROW_ID, subject_id, diff --git a/mimic-iii/concepts_postgres/firstday/blood_gas_first_day.sql b/mimic-iii/concepts_postgres/firstday/blood_gas_first_day.sql index add2d49d6..c65d04a07 100644 --- a/mimic-iii/concepts_postgres/firstday/blood_gas_first_day.sql +++ b/mimic-iii/concepts_postgres/firstday/blood_gas_first_day.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.blood_gas_first_day; CREATE TABLE mimiciii_derived.blood_gas_first_day AS -/* The aim of this query is to pivot entries related to blood gases and */ /* chemistry values which were found in LABEVENTS */ /* things to check: */ /* when a mixed venous/arterial blood sample are taken at the same time, is the store time different? */ +/* The aim of this query is to pivot entries related to blood gases and */ +/* chemistry values which were found in LABEVENTS */ +/* things to check: */ +/* when a mixed venous/arterial blood sample are taken at the same time, is the store time different? */ WITH pvt AS ( SELECT ie.subject_id, diff --git a/mimic-iii/concepts_postgres/firstday/gcs_first_day.sql b/mimic-iii/concepts_postgres/firstday/gcs_first_day.sql index 656591e94..7baaad979 100644 --- a/mimic-iii/concepts_postgres/firstday/gcs_first_day.sql +++ b/mimic-iii/concepts_postgres/firstday/gcs_first_day.sql @@ -1,6 +1,23 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.gcs_first_day; CREATE TABLE mimiciii_derived.gcs_first_day AS -/* ITEMIDs used: */ /* CAREVUE */ /* 723 as GCSVerbal */ /* 454 as GCSMotor */ /* 184 as GCSEyes */ /* METAVISION */ /* 223900 GCS - Verbal Response */ /* 223901 GCS - Motor Response */ /* 220739 GCS - Eye Opening */ /* The code combines the ITEMIDs into the carevue itemids, then pivots those */ /* So 223900 is changed to 723, then the ITEMID 723 is pivoted to form GCSVerbal */ /* Note: */ /* The GCS for sedated patients is defaulted to 15 in this code. */ /* This is in line with how the data is meant to be collected. */ /* e.g., from the SAPS II publication: */ /* For sedated patients, the Glasgow Coma Score before sedation was used. */ /* This was ascertained either from interviewing the physician who ordered the sedation, */ /* or by reviewing the patient's medical record. */ +/* ITEMIDs used: */ +/* CAREVUE */ +/* 723 as GCSVerbal */ +/* 454 as GCSMotor */ +/* 184 as GCSEyes */ +/* METAVISION */ +/* 223900 GCS - Verbal Response */ +/* 223901 GCS - Motor Response */ +/* 220739 GCS - Eye Opening */ +/* The code combines the ITEMIDs into the carevue itemids, then pivots those */ +/* So 223900 is changed to 723, then the ITEMID 723 is pivoted to form GCSVerbal */ +/* Note: */ +/* The GCS for sedated patients is defaulted to 15 in this code. */ +/* This is in line with how the data is meant to be collected. */ +/* e.g., from the SAPS II publication: */ +/* For sedated patients, the Glasgow Coma Score before sedation was used. */ +/* This was ascertained either from interviewing the physician who ordered the sedation, */ +/* or by reviewing the patient's medical record. */ WITH base AS ( SELECT pvt.ICUSTAY_ID, diff --git a/mimic-iii/concepts_postgres/firstday/height_first_day.sql b/mimic-iii/concepts_postgres/firstday/height_first_day.sql index a873bb5ce..bcf9c3be8 100644 --- a/mimic-iii/concepts_postgres/firstday/height_first_day.sql +++ b/mimic-iii/concepts_postgres/firstday/height_first_day.sql @@ -1,6 +1,11 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.height_first_day; CREATE TABLE mimiciii_derived.height_first_day AS -/* This query extracts heights for adult ICU patients. */ /* It uses all information from the patient's first ICU day. */ /* This is done for consistency with other queries - it's not necessarily needed. */ /* Height is unlikely to change throughout a patient's stay. */ /* ** Requires the echodata view, generated by concepts/echo-data.sql */ /* staging table to ensure all heights are in centimeters */ +/* This query extracts heights for adult ICU patients. */ +/* It uses all information from the patient's first ICU day. */ +/* This is done for consistency with other queries - it's not necessarily needed. */ +/* Height is unlikely to change throughout a patient's stay. */ +/* ** Requires the echodata view, generated by concepts/echo-data.sql */ +/* staging table to ensure all heights are in centimeters */ WITH ce0 AS ( SELECT c.icustay_id, diff --git a/mimic-iii/concepts_postgres/firstday/labs_first_day.sql b/mimic-iii/concepts_postgres/firstday/labs_first_day.sql index c3537b4d7..de02ad5ae 100644 --- a/mimic-iii/concepts_postgres/firstday/labs_first_day.sql +++ b/mimic-iii/concepts_postgres/firstday/labs_first_day.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.labs_first_day; CREATE TABLE mimiciii_derived.labs_first_day AS -/* This query pivots lab values taken in the first 24 hours of a patient's stay */ /* Have already confirmed that the unit of measurement is always the same: null or the correct unit */ +/* This query pivots lab values taken in the first 24 hours of a patient's stay */ +/* Have already confirmed that the unit of measurement is always the same: null or the correct unit */ SELECT pvt.subject_id, pvt.hadm_id, diff --git a/mimic-iii/concepts_postgres/firstday/rrt_first_day.sql b/mimic-iii/concepts_postgres/firstday/rrt_first_day.sql index daafc5b68..c5316bb32 100644 --- a/mimic-iii/concepts_postgres/firstday/rrt_first_day.sql +++ b/mimic-iii/concepts_postgres/firstday/rrt_first_day.sql @@ -1,6 +1,39 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.rrt_first_day; CREATE TABLE mimiciii_derived.rrt_first_day AS -/* determines if patients received any dialysis during their stay */ /* Some example aggregate queries which summarize the data here.. */ /* This query estimates 6.7% of ICU patients received RRT. */ /* select count(rrt.icustay_id) as numobs */ /* , sum(rrt) as numrrt */ /* , sum(case when rrt=1 then 1 else 0 end)*100.0 / count(rrt.icustay_id) */ /* as percent_rrt */ /* from rrt */ /* inner join icustays ie on rrt.icustay_id = ie.icustay_id */ /* inner join patients p */ /* on rrt.subject_id = p.subject_id */ /* and p.dob < ie.intime - interval '1' year */ /* inner join admissions adm */ /* on rrt.hadm_id = adm.hadm_id; */ /* This query estimates that 4.6% of first ICU stays received RRT. */ /* select */ /* count(rrt.icustay_id) as numobs */ /* , sum(rrt) as numrrt */ /* , sum(case when rrt=1 then 1 else 0 end)*100.0 / count(rrt.icustay_id) */ /* as percent_rrt */ /* from */ /* ( */ /* select ie.icustay_id, rrt.rrt */ /* , ROW_NUMBER() over (partition by ie.subject_id order by ie.intime) rn */ /* from rrt */ /* inner join icustays ie */ /* on rrt.icustay_id = ie.icustay_id */ /* inner join patients p */ /* on rrt.subject_id = p.subject_id */ /* and p.dob < ie.intime - interval '1' year */ /* inner join admissions adm */ /* on rrt.hadm_id = adm.hadm_id */ /* ) rrt */ /* where rn = 1; */ +/* determines if patients received any dialysis during their stay */ +/* Some example aggregate queries which summarize the data here.. */ +/* This query estimates 6.7% of ICU patients received RRT. */ +/* select count(rrt.icustay_id) as numobs */ +/* , sum(rrt) as numrrt */ +/* , sum(case when rrt=1 then 1 else 0 end)*100.0 / count(rrt.icustay_id) */ +/* as percent_rrt */ +/* from rrt */ +/* inner join icustays ie on rrt.icustay_id = ie.icustay_id */ +/* inner join patients p */ +/* on rrt.subject_id = p.subject_id */ +/* and p.dob < ie.intime - interval '1' year */ +/* inner join admissions adm */ +/* on rrt.hadm_id = adm.hadm_id; */ +/* This query estimates that 4.6% of first ICU stays received RRT. */ +/* select */ +/* count(rrt.icustay_id) as numobs */ +/* , sum(rrt) as numrrt */ +/* , sum(case when rrt=1 then 1 else 0 end)*100.0 / count(rrt.icustay_id) */ +/* as percent_rrt */ +/* from */ +/* ( */ +/* select ie.icustay_id, rrt.rrt */ +/* , ROW_NUMBER() over (partition by ie.subject_id order by ie.intime) rn */ +/* from rrt */ +/* inner join icustays ie */ +/* on rrt.icustay_id = ie.icustay_id */ +/* inner join patients p */ +/* on rrt.subject_id = p.subject_id */ +/* and p.dob < ie.intime - interval '1' year */ +/* inner join admissions adm */ +/* on rrt.hadm_id = adm.hadm_id */ +/* ) rrt */ +/* where rn = 1; */ WITH cv AS ( SELECT ie.icustay_id, diff --git a/mimic-iii/concepts_postgres/firstday/urine_output_first_day.sql b/mimic-iii/concepts_postgres/firstday/urine_output_first_day.sql index 52516aaac..77578986f 100644 --- a/mimic-iii/concepts_postgres/firstday/urine_output_first_day.sql +++ b/mimic-iii/concepts_postgres/firstday/urine_output_first_day.sql @@ -1,6 +1,8 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.urine_output_first_day; CREATE TABLE mimiciii_derived.urine_output_first_day AS -/* ------------------------------------------------------------------ */ /* Purpose: Create a view of the urine output for each ICUSTAY_ID over the first 24 hours. */ /* ------------------------------------------------------------------ */ +/* ------------------------------------------------------------------ */ +/* Purpose: Create a view of the urine output for each ICUSTAY_ID over the first 24 hours. */ +/* ------------------------------------------------------------------ */ SELECT ie.subject_id, /* patient identifiers */ ie.hadm_id, diff --git a/mimic-iii/concepts_postgres/firstday/ventilation_first_day.sql b/mimic-iii/concepts_postgres/firstday/ventilation_first_day.sql index 236ec02a6..ee88b37fd 100644 --- a/mimic-iii/concepts_postgres/firstday/ventilation_first_day.sql +++ b/mimic-iii/concepts_postgres/firstday/ventilation_first_day.sql @@ -1,6 +1,8 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.ventilation_first_day; CREATE TABLE mimiciii_derived.ventilation_first_day AS -/* Determines if a patient is ventilated on the first day of their ICU stay. */ /* Creates a table with the result. */ /* Requires the `ventilation_durations` table, generated by ../ventilation-durations.sql */ +/* Determines if a patient is ventilated on the first day of their ICU stay. */ +/* Creates a table with the result. */ +/* Requires the `ventilation_durations` table, generated by ../ventilation-durations.sql */ SELECT ie.subject_id, ie.hadm_id, diff --git a/mimic-iii/concepts_postgres/firstday/vitals_first_day.sql b/mimic-iii/concepts_postgres/firstday/vitals_first_day.sql index fe4feca49..d4b2cef6e 100644 --- a/mimic-iii/concepts_postgres/firstday/vitals_first_day.sql +++ b/mimic-iii/concepts_postgres/firstday/vitals_first_day.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.vitals_first_day; CREATE TABLE mimiciii_derived.vitals_first_day AS -/* This query pivots the vital signs for the first 24 hours of a patient's stay */ /* Vital signs include heart rate, blood pressure, respiration rate, and temperature */ +/* This query pivots the vital signs for the first 24 hours of a patient's stay */ +/* Vital signs include heart rate, blood pressure, respiration rate, and temperature */ SELECT pvt.subject_id, pvt.hadm_id, diff --git a/mimic-iii/concepts_postgres/firstday/weight_first_day.sql b/mimic-iii/concepts_postgres/firstday/weight_first_day.sql index adebae2b5..89978e01d 100644 --- a/mimic-iii/concepts_postgres/firstday/weight_first_day.sql +++ b/mimic-iii/concepts_postgres/firstday/weight_first_day.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.weight_first_day; CREATE TABLE mimiciii_derived.weight_first_day AS -/* This query extracts weights for adult ICU patients on their first ICU day. */ /* It does *not* use any information after the first ICU day, as weight is */ /* sometimes used to monitor fluid balance. */ /* ** Requires the echodata view, generated by concepts/echo-data.sql */ +/* This query extracts weights for adult ICU patients on their first ICU day. */ +/* It does *not* use any information after the first ICU day, as weight is */ +/* sometimes used to monitor fluid balance. */ +/* ** Requires the echodata view, generated by concepts/echo-data.sql */ WITH ce AS ( SELECT c.icustay_id, /* we take the avg value from roughly first day */ /* TODO: eliminate obvious outliers if there is a reasonable weight */ /* (e.g. weight of 180kg and 90kg would remove 180kg instead of taking the median) */ diff --git a/mimic-iii/concepts_postgres/fluid_balance/colloid_bolus.sql b/mimic-iii/concepts_postgres/fluid_balance/colloid_bolus.sql index ecf70289b..c61c79060 100644 --- a/mimic-iii/concepts_postgres/fluid_balance/colloid_bolus.sql +++ b/mimic-iii/concepts_postgres/fluid_balance/colloid_bolus.sql @@ -1,6 +1,8 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.colloid_bolus; CREATE TABLE mimiciii_derived.colloid_bolus AS -/* received colloid before admission */ /* 226365 -- OR Colloid Intake */ /* 226376 -- PACU Colloid Intake */ +/* received colloid before admission */ +/* 226365 -- OR Colloid Intake */ +/* 226376 -- PACU Colloid Intake */ WITH t1 AS ( SELECT mv.icustay_id, diff --git a/mimic-iii/concepts_postgres/fluid_balance/ffp_transfusion.sql b/mimic-iii/concepts_postgres/fluid_balance/ffp_transfusion.sql index f35e5dd02..9dbaef664 100644 --- a/mimic-iii/concepts_postgres/fluid_balance/ffp_transfusion.sql +++ b/mimic-iii/concepts_postgres/fluid_balance/ffp_transfusion.sql @@ -64,7 +64,8 @@ WITH raw_ffp AS ( CAST(EXTRACT(EPOCH FROM DATE_TRUNC('hour', LAG(charttime) OVER (PARTITION BY icustay_id ORDER BY charttime ASC NULLS FIRST)) - DATE_TRUNC('hour', charttime)) / 3600 AS BIGINT) AS delta FROM raw_ffp ) -/* We consider any transfusions started within 1 hr of the last one */ /* to be part of the same event */ +/* We consider any transfusions started within 1 hr of the last one */ +/* to be part of the same event */ SELECT cm.icustay_id, cm.charttime, diff --git a/mimic-iii/concepts_postgres/fluid_balance/rbc_transfusion.sql b/mimic-iii/concepts_postgres/fluid_balance/rbc_transfusion.sql index 9e854e884..3501e5fb2 100644 --- a/mimic-iii/concepts_postgres/fluid_balance/rbc_transfusion.sql +++ b/mimic-iii/concepts_postgres/fluid_balance/rbc_transfusion.sql @@ -61,7 +61,8 @@ WITH raw_rbc AS ( CAST(EXTRACT(EPOCH FROM DATE_TRUNC('hour', LAG(charttime) OVER (PARTITION BY icustay_id ORDER BY charttime ASC NULLS FIRST)) - DATE_TRUNC('hour', charttime)) / 3600 AS BIGINT) AS delta FROM raw_rbc ) -/* We consider any transfusions started within 1 hr of the last one */ /* to be part of the same event */ +/* We consider any transfusions started within 1 hr of the last one */ +/* to be part of the same event */ SELECT cm.icustay_id, cm.charttime, diff --git a/mimic-iii/concepts_postgres/organfailure/kdigo_stages.sql b/mimic-iii/concepts_postgres/organfailure/kdigo_stages.sql index bbdbd5495..f28dab833 100644 --- a/mimic-iii/concepts_postgres/organfailure/kdigo_stages.sql +++ b/mimic-iii/concepts_postgres/organfailure/kdigo_stages.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.kdigo_stages; CREATE TABLE mimiciii_derived.kdigo_stages AS -/* This query checks if the patient had AKI according to KDIGO. */ /* AKI is calculated every time a creatinine or urine output measurement occurs. */ /* Baseline creatinine is defined as the lowest creatinine in the past 7 days. */ /* get creatinine stages */ +/* This query checks if the patient had AKI according to KDIGO. */ +/* AKI is calculated every time a creatinine or urine output measurement occurs. */ +/* Baseline creatinine is defined as the lowest creatinine in the past 7 days. */ +/* get creatinine stages */ WITH cr_stg AS ( SELECT cr.icustay_id, diff --git a/mimic-iii/concepts_postgres/organfailure/kdigo_stages_48hr.sql b/mimic-iii/concepts_postgres/organfailure/kdigo_stages_48hr.sql index 466625476..095dfb045 100644 --- a/mimic-iii/concepts_postgres/organfailure/kdigo_stages_48hr.sql +++ b/mimic-iii/concepts_postgres/organfailure/kdigo_stages_48hr.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.kdigo_stages_48hr; CREATE TABLE mimiciii_derived.kdigo_stages_48hr AS -/* This query checks if the patient had AKI during the first 48 hours of their ICU */ /* stay according to the KDIGO guideline. */ /* https://kdigo.org/wp-content/uploads/2016/10/KDIGO-2012-AKI-Guideline-English.pdf */ /* get the worst staging of creatinine in the first 48 hours */ +/* This query checks if the patient had AKI during the first 48 hours of their ICU */ +/* stay according to the KDIGO guideline. */ +/* https://kdigo.org/wp-content/uploads/2016/10/KDIGO-2012-AKI-Guideline-English.pdf */ +/* get the worst staging of creatinine in the first 48 hours */ WITH cr_aki AS ( SELECT k.icustay_id, diff --git a/mimic-iii/concepts_postgres/organfailure/kdigo_stages_7day.sql b/mimic-iii/concepts_postgres/organfailure/kdigo_stages_7day.sql index 105804a1c..466461da2 100644 --- a/mimic-iii/concepts_postgres/organfailure/kdigo_stages_7day.sql +++ b/mimic-iii/concepts_postgres/organfailure/kdigo_stages_7day.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.kdigo_stages_7day; CREATE TABLE mimiciii_derived.kdigo_stages_7day AS -/* This query checks if the patient had AKI during the first 7 days of their ICU */ /* stay according to the KDIGO guideline. */ /* https://kdigo.org/wp-content/uploads/2016/10/KDIGO-2012-AKI-Guideline-English.pdf */ /* get the worst staging of creatinine in the first 48 hours */ +/* This query checks if the patient had AKI during the first 7 days of their ICU */ +/* stay according to the KDIGO guideline. */ +/* https://kdigo.org/wp-content/uploads/2016/10/KDIGO-2012-AKI-Guideline-English.pdf */ +/* get the worst staging of creatinine in the first 48 hours */ WITH cr_aki AS ( SELECT k.icustay_id, diff --git a/mimic-iii/concepts_postgres/organfailure/meld.sql b/mimic-iii/concepts_postgres/organfailure/meld.sql index 77ca50ca0..a228457e9 100644 --- a/mimic-iii/concepts_postgres/organfailure/meld.sql +++ b/mimic-iii/concepts_postgres/organfailure/meld.sql @@ -1,6 +1,33 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.meld; CREATE TABLE mimiciii_derived.meld AS -/* Model for end-stage liver disease (MELD) */ /* This model is used to determine prognosis and receipt of liver transplantation. */ /* Reference: */ /* Kamath PS, Wiesner RH, Malinchoc M, Kremers W, Therneau TM, */ /* Kosberg CL, D'Amico G, Dickson ER, Kim WR. */ /* A model to predict survival in patients with end-stage liver disease. */ /* Hepatology. 2001 Feb;33(2):464-70. */ /* Updated January 2016 to include serum sodium, see: */ /* https://optn.transplant.hrsa.gov/news/meld-serum-sodium-policy-changes/ */ /* Here is the relevant portion of the policy note: */ /* 9.1.D MELD Score */ /* Candidates who are at least 12 years old receive an initial MELD(i) score equal to: */ /* 0.957 x ln(creatinine mg/dL) + 0.378 x ln(bilirubin mg/dL) + 1.120 x ln(INR) + 0.643 */ /* Laboratory values less than 1.0 will be set to 1.0 when calculating a candidate’s MELD */ /* score. */ /* The following candidates will receive a creatinine value of 4.0 mg/dL: */ /* - Candidates with a creatinine value greater than 4.0 mg/dL */ /* - Candidates who received two or more dialysis treatments within the prior week */ /* - Candidates who received 24 hours of continuous veno-venous hemodialysis (CVVHD) within the prior week */ /* The maximum MELD score is 40. The MELD score derived from this calculation will be rounded to the tenth decimal place and then multiplied by 10. */ /* For candidates with an initial MELD score greater than 11, The MELD score is then recalculated as follows: */ /* MELD = MELD(i) + 1.32*(137-Na) – [0.033*MELD(i)*(137-Na)] */ /* Sodium values less than 125 mmol/L will be set to 125, and values greater than 137 mmol/L will be set to 137. */ /* TODO needed in this code: */ /* 1. identify 2x dialysis in the past week, or 24 hours of CVVH */ /* at the moment it just checks for any dialysis on the day */ /* 2. adjust the serum sodium using the corresponding glucose measurement */ /* Measured sodium + 0.024 * (Serum glucose - 100) (Hiller, 1999) */ +/* Model for end-stage liver disease (MELD) */ +/* This model is used to determine prognosis and receipt of liver transplantation. */ +/* Reference: */ +/* Kamath PS, Wiesner RH, Malinchoc M, Kremers W, Therneau TM, */ +/* Kosberg CL, D'Amico G, Dickson ER, Kim WR. */ +/* A model to predict survival in patients with end-stage liver disease. */ +/* Hepatology. 2001 Feb;33(2):464-70. */ +/* Updated January 2016 to include serum sodium, see: */ +/* https://optn.transplant.hrsa.gov/news/meld-serum-sodium-policy-changes/ */ +/* Here is the relevant portion of the policy note: */ +/* 9.1.D MELD Score */ +/* Candidates who are at least 12 years old receive an initial MELD(i) score equal to: */ +/* 0.957 x ln(creatinine mg/dL) + 0.378 x ln(bilirubin mg/dL) + 1.120 x ln(INR) + 0.643 */ +/* Laboratory values less than 1.0 will be set to 1.0 when calculating a candidate’s MELD */ +/* score. */ +/* The following candidates will receive a creatinine value of 4.0 mg/dL: */ +/* - Candidates with a creatinine value greater than 4.0 mg/dL */ +/* - Candidates who received two or more dialysis treatments within the prior week */ +/* - Candidates who received 24 hours of continuous veno-venous hemodialysis (CVVHD) within the prior week */ +/* The maximum MELD score is 40. The MELD score derived from this calculation will be rounded to the tenth decimal place and then multiplied by 10. */ +/* For candidates with an initial MELD score greater than 11, The MELD score is then recalculated as follows: */ +/* MELD = MELD(i) + 1.32*(137-Na) – [0.033*MELD(i)*(137-Na)] */ +/* Sodium values less than 125 mmol/L will be set to 125, and values greater than 137 mmol/L will be set to 137. */ +/* TODO needed in this code: */ +/* 1. identify 2x dialysis in the past week, or 24 hours of CVVH */ +/* at the moment it just checks for any dialysis on the day */ +/* 2. adjust the serum sodium using the corresponding glucose measurement */ +/* Measured sodium + 0.024 * (Serum glucose - 100) (Hiller, 1999) */ WITH cohort AS ( SELECT ie.subject_id, diff --git a/mimic-iii/concepts_postgres/pivot/pivoted_bg.sql b/mimic-iii/concepts_postgres/pivot/pivoted_bg.sql index 8c00b7882..2d2e92940 100644 --- a/mimic-iii/concepts_postgres/pivot/pivoted_bg.sql +++ b/mimic-iii/concepts_postgres/pivot/pivoted_bg.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.pivoted_bg; CREATE TABLE mimiciii_derived.pivoted_bg AS -/* The aim of this query is to pivot entries related to blood gases and */ /* chemistry values which were found in LABEVENTS */ /* create a table which has fuzzy boundaries on ICU admission */ /* involves first creating a lag/lead version of intime/outtime */ +/* The aim of this query is to pivot entries related to blood gases and */ +/* chemistry values which were found in LABEVENTS */ +/* create a table which has fuzzy boundaries on ICU admission */ +/* involves first creating a lag/lead version of intime/outtime */ WITH i AS ( SELECT subject_id, @@ -191,7 +194,9 @@ WITH i AS ( GROUP BY pvt.hadm_id, pvt.charttime - /* remove observations if there is more than one specimen listed */ /* we do not know whether these are arterial or mixed venous, etc... */ /* happily this is a small fraction of the total number of observations */ + /* remove observations if there is more than one specimen listed */ + /* we do not know whether these are arterial or mixed venous, etc... */ + /* happily this is a small fraction of the total number of observations */ HAVING SUM(CASE WHEN label = 'SPECIMEN' THEN 1 ELSE 0 END) < 2 ) diff --git a/mimic-iii/concepts_postgres/pivot/pivoted_bg_art.sql b/mimic-iii/concepts_postgres/pivot/pivoted_bg_art.sql index ba07210c0..ced45eaef 100644 --- a/mimic-iii/concepts_postgres/pivot/pivoted_bg_art.sql +++ b/mimic-iii/concepts_postgres/pivot/pivoted_bg_art.sql @@ -1,6 +1,8 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.pivoted_bg_art; CREATE TABLE mimiciii_derived.pivoted_bg_art AS -/* This query requires the pivoted_bg table to be generated. */ /* It extracts only arterial blood gas samples - either explicitly stated or */ /* inferred by a hard-coded logistic regression model. */ +/* This query requires the pivoted_bg table to be generated. */ +/* It extracts only arterial blood gas samples - either explicitly stated or */ +/* inferred by a hard-coded logistic regression model. */ WITH stg_spo2 AS ( SELECT hadm_id, diff --git a/mimic-iii/concepts_postgres/pivot/pivoted_gcs.sql b/mimic-iii/concepts_postgres/pivot/pivoted_gcs.sql index b74dc766d..d3500e517 100644 --- a/mimic-iii/concepts_postgres/pivot/pivoted_gcs.sql +++ b/mimic-iii/concepts_postgres/pivot/pivoted_gcs.sql @@ -1,6 +1,29 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.pivoted_gcs; CREATE TABLE mimiciii_derived.pivoted_gcs AS -/* This query extracts the Glasgow Coma Scale, a measure of neurological function. */ /* The query has a few special rules: */ /* (1) The verbal component can be set to 0 if the patient is ventilated. */ /* This is corrected to 5 - the overall GCS is set to 15 in these cases. */ /* (2) Often only one of three components is documented. The other components */ /* are carried forward. */ /* ITEMIDs used: */ /* CAREVUE */ /* 723 as gcsverbal */ /* 454 as gcsmotor */ /* 184 as gcseyes */ /* METAVISION */ /* 223900 GCS - Verbal Response */ /* 223901 GCS - Motor Response */ /* 220739 GCS - Eye Opening */ /* The code combines the ITEMIDs into the carevue itemids, then pivots those */ /* So 223900 is changed to 723, then the ITEMID 723 is pivoted to form gcsverbal */ /* Note: */ /* The GCS for sedated patients is defaulted to 15 in this code. */ /* This is in line with how the data is meant to be collected. */ /* e.g., from the SAPS II publication: */ /* For sedated patients, the Glasgow Coma Score before sedation was used. */ /* This was ascertained either from interviewing the physician who ordered the sedation, */ /* or by reviewing the patient's medical record. */ +/* This query extracts the Glasgow Coma Scale, a measure of neurological function. */ +/* The query has a few special rules: */ +/* (1) The verbal component can be set to 0 if the patient is ventilated. */ +/* This is corrected to 5 - the overall GCS is set to 15 in these cases. */ +/* (2) Often only one of three components is documented. The other components */ +/* are carried forward. */ +/* ITEMIDs used: */ +/* CAREVUE */ +/* 723 as gcsverbal */ +/* 454 as gcsmotor */ +/* 184 as gcseyes */ +/* METAVISION */ +/* 223900 GCS - Verbal Response */ +/* 223901 GCS - Motor Response */ +/* 220739 GCS - Eye Opening */ +/* The code combines the ITEMIDs into the carevue itemids, then pivots those */ +/* So 223900 is changed to 723, then the ITEMID 723 is pivoted to form gcsverbal */ +/* Note: */ +/* The GCS for sedated patients is defaulted to 15 in this code. */ +/* This is in line with how the data is meant to be collected. */ +/* e.g., from the SAPS II publication: */ +/* For sedated patients, the Glasgow Coma Score before sedation was used. */ +/* This was ascertained either from interviewing the physician who ordered the sedation, */ +/* or by reviewing the patient's medical record. */ WITH base AS ( SELECT ce.icustay_id, diff --git a/mimic-iii/concepts_postgres/pivot/pivoted_height.sql b/mimic-iii/concepts_postgres/pivot/pivoted_height.sql index 17ce12742..ed8131f09 100644 --- a/mimic-iii/concepts_postgres/pivot/pivoted_height.sql +++ b/mimic-iii/concepts_postgres/pivot/pivoted_height.sql @@ -83,7 +83,13 @@ WITH ht_in AS ( WHERE text LIKE '%Ideal body weight:%' AND ne.category <> 'Echo' ), ht_from_ibw AS ( - /* IBW formulas */ /* inches */ /* F: IBW = 45.5 kg + 2.3 kg * (height in inches - 60) */ /* M: IBW = 50 kg + 2.3 kg * (height in inches - 60) */ /* cm */ /* F: 45.5 + (0.91 × [height in centimeters − 152.4]) */ /* M: 50 + (0.91 × [height in centimeters − 152.4]) */ + /* IBW formulas */ + /* inches */ + /* F: IBW = 45.5 kg + 2.3 kg * (height in inches - 60) */ + /* M: IBW = 50 kg + 2.3 kg * (height in inches - 60) */ + /* cm */ + /* F: 45.5 + (0.91 × [height in centimeters − 152.4]) */ + /* M: 50 + (0.91 × [height in centimeters − 152.4]) */ SELECT ne.subject_id, charttime, @@ -102,7 +108,9 @@ WITH ht_in AS ( WHERE NOT ibw IS NULL AND ibw <> 0 ), ht_nutrition AS ( - /* nutrition notes usually only document height */ /* but the original note formatting has been lost, so we can't do a clever regex */ /* instead, we just look for the unit of measure (cm) */ + /* nutrition notes usually only document height */ + /* but the original note formatting has been lost, so we can't do a clever regex */ + /* instead, we just look for the unit of measure (cm) */ SELECT subject_id, charttime, diff --git a/mimic-iii/concepts_postgres/pivot/pivoted_invasive_lines.sql b/mimic-iii/concepts_postgres/pivot/pivoted_invasive_lines.sql index 3f853bfe6..c8a9d6589 100644 --- a/mimic-iii/concepts_postgres/pivot/pivoted_invasive_lines.sql +++ b/mimic-iii/concepts_postgres/pivot/pivoted_invasive_lines.sql @@ -184,7 +184,8 @@ WITH stg0 AS ( endtime FROM mv ) -/* as a final step, combine any similar terms together */ /* this was comprehensive as of MIMIC-III v1.4 */ +/* as a final step, combine any similar terms together */ +/* this was comprehensive as of MIMIC-III v1.4 */ SELECT icustay_id, CASE diff --git a/mimic-iii/concepts_postgres/pivot/pivoted_lab.sql b/mimic-iii/concepts_postgres/pivot/pivoted_lab.sql index 929f98a93..415f9f2d6 100644 --- a/mimic-iii/concepts_postgres/pivot/pivoted_lab.sql +++ b/mimic-iii/concepts_postgres/pivot/pivoted_lab.sql @@ -1,6 +1,8 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.pivoted_lab; CREATE TABLE mimiciii_derived.pivoted_lab AS -/* create a table which has fuzzy boundaries on ICU admission (+- 12 hours from documented time) */ /* this is used to assign icustay_id to lab data, which can be collected outside ICU */ /* involves first creating a lag/lead version of intime/outtime */ +/* create a table which has fuzzy boundaries on ICU admission (+- 12 hours from documented time) */ +/* this is used to assign icustay_id to lab data, which can be collected outside ICU */ +/* involves first creating a lag/lead version of intime/outtime */ WITH i AS ( SELECT subject_id, diff --git a/mimic-iii/concepts_postgres/pivot/pivoted_sofa.sql b/mimic-iii/concepts_postgres/pivot/pivoted_sofa.sql index 3aa38e214..cad59827e 100644 --- a/mimic-iii/concepts_postgres/pivot/pivoted_sofa.sql +++ b/mimic-iii/concepts_postgres/pivot/pivoted_sofa.sql @@ -1,6 +1,36 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.pivoted_sofa; CREATE TABLE mimiciii_derived.pivoted_sofa AS -/* ------------------------------------------------------------------ */ /* Title: Sequential Organ Failure Assessment (SOFA) */ /* This query extracts the sequential organ failure assessment (formally: sepsis-related organ failure assessment). */ /* This score is a measure of organ failure for patients in the ICU. */ /* The score is calculated for every hour of the patient's ICU stay. */ /* However, as the calculation window is 24 hours, care should be taken when */ /* using the score before the end of the first day. */ /* ------------------------------------------------------------------ */ /* Reference for SOFA: */ /* Jean-Louis Vincent, Rui Moreno, Jukka Takala, Sheila Willatts, Arnaldo De Mendonça, */ /* Hajo Bruining, C. K. Reinhart, Peter M Suter, and L. G. Thijs. */ /* "The SOFA (Sepsis-related Organ Failure Assessment) score to describe organ dysfunction/failure." */ /* Intensive care medicine 22, no. 7 (1996): 707-710. */ /* Variables used in SOFA: */ /* GCS, MAP, FiO2, Ventilation status (sourced FROM `physionet-data.mimiciii_clinical.chartevents`) */ /* Creatinine, Bilirubin, FiO2, PaO2, Platelets (sourced FROM `physionet-data.mimiciii_clinical.labevents`) */ /* Dopamine, Dobutamine, Epinephrine, Norepinephrine (sourced FROM `physionet-data.mimiciii_clinical.inputevents_mv` and INPUTEVENTS_CV) */ /* Urine output (sourced from OUTPUTEVENTS) */ /* The following views required to run this query: */ /* 1) pivoted_bg_art - generated by pivoted-bg.sql */ /* 2) pivoted_uo - generated by pivoted-uo.sql */ /* 3) pivoted_lab - generated by pivoted-lab.sql */ /* 4) pivoted_gcs - generated by pivoted-gcs.sql */ /* 5) ventilation_durations - generated by ../durations/ventilation_durations.sql */ /* 6) norepinephrine_dose - generated by ../durations/norepinephrine-dose.sql */ /* 7) epinephrine_dose - generated by ../durations/epinephrine-dose.sql */ /* 8) dopamine_dose - generated by ../durations/dopamine-dose.sql */ /* 9) dobutamine_dose - generated by ../durations/dobutamine-dose.sql */ /* Note: */ /* The score is calculated for only adult ICU patients, */ /* generate a row for every hour the patient was in the ICU */ +/* ------------------------------------------------------------------ */ +/* Title: Sequential Organ Failure Assessment (SOFA) */ +/* This query extracts the sequential organ failure assessment (formally: sepsis-related organ failure assessment). */ +/* This score is a measure of organ failure for patients in the ICU. */ +/* The score is calculated for every hour of the patient's ICU stay. */ +/* However, as the calculation window is 24 hours, care should be taken when */ +/* using the score before the end of the first day. */ +/* ------------------------------------------------------------------ */ +/* Reference for SOFA: */ +/* Jean-Louis Vincent, Rui Moreno, Jukka Takala, Sheila Willatts, Arnaldo De Mendonça, */ +/* Hajo Bruining, C. K. Reinhart, Peter M Suter, and L. G. Thijs. */ +/* "The SOFA (Sepsis-related Organ Failure Assessment) score to describe organ dysfunction/failure." */ +/* Intensive care medicine 22, no. 7 (1996): 707-710. */ +/* Variables used in SOFA: */ +/* GCS, MAP, FiO2, Ventilation status (sourced FROM `physionet-data.mimiciii_clinical.chartevents`) */ +/* Creatinine, Bilirubin, FiO2, PaO2, Platelets (sourced FROM `physionet-data.mimiciii_clinical.labevents`) */ +/* Dopamine, Dobutamine, Epinephrine, Norepinephrine (sourced FROM `physionet-data.mimiciii_clinical.inputevents_mv` and INPUTEVENTS_CV) */ +/* Urine output (sourced from OUTPUTEVENTS) */ +/* The following views required to run this query: */ +/* 1) pivoted_bg_art - generated by pivoted-bg.sql */ +/* 2) pivoted_uo - generated by pivoted-uo.sql */ +/* 3) pivoted_lab - generated by pivoted-lab.sql */ +/* 4) pivoted_gcs - generated by pivoted-gcs.sql */ +/* 5) ventilation_durations - generated by ../durations/ventilation_durations.sql */ +/* 6) norepinephrine_dose - generated by ../durations/norepinephrine-dose.sql */ +/* 7) epinephrine_dose - generated by ../durations/epinephrine-dose.sql */ +/* 8) dopamine_dose - generated by ../durations/dopamine-dose.sql */ +/* 9) dobutamine_dose - generated by ../durations/dobutamine-dose.sql */ +/* Note: */ +/* The score is calculated for only adult ICU patients, */ +/* generate a row for every hour the patient was in the ICU */ WITH co AS ( SELECT ih.icustay_id, @@ -144,7 +174,9 @@ WITH co AS ( AND co.endtime > dob.starttime AND co.endtime <= dob.endtime ), scorecalc AS ( - /* Calculate the final score */ /* note that if the underlying data is missing, the component is null */ /* eventually these are treated as 0 (normal), but knowing when data is missing is useful for debugging */ + /* Calculate the final score */ + /* note that if the underlying data is missing, the component is null */ + /* eventually these are treated as 0 (normal), but knowing when data is missing is useful for debugging */ SELECT scorecomp.*, /* Respiration */ CAST(CASE diff --git a/mimic-iii/concepts_postgres/pivot/pivoted_vital.sql b/mimic-iii/concepts_postgres/pivot/pivoted_vital.sql index 22b568c03..6f4d0ac03 100644 --- a/mimic-iii/concepts_postgres/pivot/pivoted_vital.sql +++ b/mimic-iii/concepts_postgres/pivot/pivoted_vital.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.pivoted_vital; CREATE TABLE mimiciii_derived.pivoted_vital AS -/* This query pivots the vital signs for the first 24 hours of a patient's stay */ /* Vital signs include heart rate, blood pressure, respiration rate, and temperature */ +/* This query pivots the vital signs for the first 24 hours of a patient's stay */ +/* Vital signs include heart rate, blood pressure, respiration rate, and temperature */ WITH ce AS ( SELECT ce.icustay_id, diff --git a/mimic-iii/concepts_postgres/rrt.sql b/mimic-iii/concepts_postgres/rrt.sql index 7daa137f8..d498cf452 100644 --- a/mimic-iii/concepts_postgres/rrt.sql +++ b/mimic-iii/concepts_postgres/rrt.sql @@ -1,6 +1,39 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.rrt; CREATE TABLE mimiciii_derived.rrt AS -/* determines if patients received any dialysis during their stay */ /* Some example aggregate queries which summarize the data here.. */ /* This query estimates 6.7% of ICU patients received RRT. */ /* select count(rrt.icustay_id) as numobs */ /* , sum(rrt) as numrrt */ /* , sum(case when rrt=1 then 1 else 0 end)*100.0 / count(rrt.icustay_id) */ /* as percent_rrt */ /* from rrt */ /* inner join icustays ie on rrt.icustay_id = ie.icustay_id */ /* inner join patients p */ /* on rrt.subject_id = p.subject_id */ /* and p.dob < ie.intime - interval '1' year */ /* inner join `physionet-data.mimiciii_clinical.admissions` adm */ /* on rrt.hadm_id = adm.hadm_id; */ /* This query estimates that 4.6% of first ICU stays received RRT. */ /* select */ /* count(rrt.icustay_id) as numobs */ /* , sum(rrt) as numrrt */ /* , sum(case when rrt=1 then 1 else 0 end)*100.0 / count(rrt.icustay_id) */ /* as percent_rrt */ /* from */ /* ( */ /* select ie.icustay_id, rrt.rrt */ /* , ROW_NUMBER() over (partition by ie.subject_id order by ie.intime) rn */ /* from rrt */ /* inner join `physionet-data.mimiciii_clinical.icustays` ie */ /* on rrt.icustay_id = ie.icustay_id */ /* inner join `physionet-data.mimiciii_clinical.patients` p */ /* on rrt.subject_id = p.subject_id */ /* and p.dob < ie.intime - interval '1' year */ /* inner join `physionet-data.mimiciii_clinical.admissions` adm */ /* on rrt.hadm_id = adm.hadm_id */ /* ) rrt */ /* where rn = 1; */ +/* determines if patients received any dialysis during their stay */ +/* Some example aggregate queries which summarize the data here.. */ +/* This query estimates 6.7% of ICU patients received RRT. */ +/* select count(rrt.icustay_id) as numobs */ +/* , sum(rrt) as numrrt */ +/* , sum(case when rrt=1 then 1 else 0 end)*100.0 / count(rrt.icustay_id) */ +/* as percent_rrt */ +/* from rrt */ +/* inner join icustays ie on rrt.icustay_id = ie.icustay_id */ +/* inner join patients p */ +/* on rrt.subject_id = p.subject_id */ +/* and p.dob < ie.intime - interval '1' year */ +/* inner join `physionet-data.mimiciii_clinical.admissions` adm */ +/* on rrt.hadm_id = adm.hadm_id; */ +/* This query estimates that 4.6% of first ICU stays received RRT. */ +/* select */ +/* count(rrt.icustay_id) as numobs */ +/* , sum(rrt) as numrrt */ +/* , sum(case when rrt=1 then 1 else 0 end)*100.0 / count(rrt.icustay_id) */ +/* as percent_rrt */ +/* from */ +/* ( */ +/* select ie.icustay_id, rrt.rrt */ +/* , ROW_NUMBER() over (partition by ie.subject_id order by ie.intime) rn */ +/* from rrt */ +/* inner join `physionet-data.mimiciii_clinical.icustays` ie */ +/* on rrt.icustay_id = ie.icustay_id */ +/* inner join `physionet-data.mimiciii_clinical.patients` p */ +/* on rrt.subject_id = p.subject_id */ +/* and p.dob < ie.intime - interval '1' year */ +/* inner join `physionet-data.mimiciii_clinical.admissions` adm */ +/* on rrt.hadm_id = adm.hadm_id */ +/* ) rrt */ +/* where rn = 1; */ WITH cv_ce AS ( SELECT ie.icustay_id, diff --git a/mimic-iii/concepts_postgres/sepsis/angus.sql b/mimic-iii/concepts_postgres/sepsis/angus.sql index da0dfc112..4202398b4 100644 --- a/mimic-iii/concepts_postgres/sepsis/angus.sql +++ b/mimic-iii/concepts_postgres/sepsis/angus.sql @@ -1,6 +1,14 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.angus; CREATE TABLE mimiciii_derived.angus AS -/* ICD-9 codes for Angus criteria of sepsis */ /* Angus et al, 2001. Epidemiology of severe sepsis in the United States */ /* http://www.ncbi.nlm.nih.gov/pubmed/11445675 */ /* Case selection and definitions */ /* To identify cases with severe sepsis, we selected all acute care */ /* hospitalizations with ICD-9-CM codes for both: */ /* (a) a bacterial or fungal infectious process AND */ /* (b) a diagnosis of acute organ dysfunction (Appendix 2). */ /* ICD-9 codes for infection - as sourced from Appendix 1 of above paper */ +/* ICD-9 codes for Angus criteria of sepsis */ +/* Angus et al, 2001. Epidemiology of severe sepsis in the United States */ +/* http://www.ncbi.nlm.nih.gov/pubmed/11445675 */ +/* Case selection and definitions */ +/* To identify cases with severe sepsis, we selected all acute care */ +/* hospitalizations with ICD-9-CM codes for both: */ +/* (a) a bacterial or fungal infectious process AND */ +/* (b) a diagnosis of acute organ dysfunction (Appendix 2). */ +/* ICD-9 codes for infection - as sourced from Appendix 1 of above paper */ WITH infection_group AS ( SELECT subject_id, diff --git a/mimic-iii/concepts_postgres/sepsis/explicit.sql b/mimic-iii/concepts_postgres/sepsis/explicit.sql index 6bb9feec7..f54e09924 100644 --- a/mimic-iii/concepts_postgres/sepsis/explicit.sql +++ b/mimic-iii/concepts_postgres/sepsis/explicit.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.explicit; CREATE TABLE mimiciii_derived.explicit AS -/* This code extracts explicit sepsis using ICD-9 diagnosis codes */ /* That is, the two codes 995.92 (severe sepsis) or 785.52 (septic shock) */ /* These codes are extremely specific to sepsis, but have very low sensitivity */ /* From Iwashyna et al. (vs. chart reviews): 100% PPV, 9.3% sens, 100% specificity */ +/* This code extracts explicit sepsis using ICD-9 diagnosis codes */ +/* That is, the two codes 995.92 (severe sepsis) or 785.52 (septic shock) */ +/* These codes are extremely specific to sepsis, but have very low sensitivity */ +/* From Iwashyna et al. (vs. chart reviews): 100% PPV, 9.3% sens, 100% specificity */ WITH co_dx AS ( SELECT hadm_id, /* sepsis codes */ diff --git a/mimic-iii/concepts_postgres/sepsis/martin.sql b/mimic-iii/concepts_postgres/sepsis/martin.sql index 682b39ed5..21ba9c455 100644 --- a/mimic-iii/concepts_postgres/sepsis/martin.sql +++ b/mimic-iii/concepts_postgres/sepsis/martin.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.martin; CREATE TABLE mimiciii_derived.martin AS -/* ICD-9 codes for sepsis as validated by Martin et al. */ /* Greg S. Martin, David M. Mannino, Stephanie Eaton, and Marc Moss. The epidemiology of */ /* sepsis in the united states from 1979 through 2000. N Engl J Med, 348(16):1546–1554, Apr */ /* 2003. doi: 10.1056/NEJMoa022139. URL http://dx.doi.org/10.1056/NEJMoa022139. */ +/* ICD-9 codes for sepsis as validated by Martin et al. */ +/* Greg S. Martin, David M. Mannino, Stephanie Eaton, and Marc Moss. The epidemiology of */ +/* sepsis in the united states from 1979 through 2000. N Engl J Med, 348(16):1546–1554, Apr */ +/* 2003. doi: 10.1056/NEJMoa022139. URL http://dx.doi.org/10.1056/NEJMoa022139. */ WITH co_dx AS ( SELECT subject_id, diff --git a/mimic-iii/concepts_postgres/severityscores/apsiii.sql b/mimic-iii/concepts_postgres/severityscores/apsiii.sql index 38632cb8b..48d16a4b6 100644 --- a/mimic-iii/concepts_postgres/severityscores/apsiii.sql +++ b/mimic-iii/concepts_postgres/severityscores/apsiii.sql @@ -1,6 +1,39 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.apsiii; CREATE TABLE mimiciii_derived.apsiii AS -/* ------------------------------------------------------------------ */ /* Title: Acute Physiology Score III (APS III) */ /* This query extracts the acute physiology score III. */ /* This score is a measure of patient severity of illness. */ /* The score is calculated on the first day of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for APS III: */ /* Knaus WA, Wagner DP, Draper EA, Zimmerman JE, Bergner M, Bastos PG, Sirio CA, Murphy DJ, Lotring T, Damiano A. */ /* The APACHE III prognostic system. Risk prediction of hospital mortality for critically ill hospitalized adults. */ /* Chest Journal. 1991 Dec 1;100(6):1619-36. */ /* Reference for the equation for calibrating APS III to hospital mortality: */ /* Johnson, A. E. W. (2015). Mortality prediction and acuity assessment in critical care. */ /* University of Oxford, Oxford, UK. */ /* Variables used in APS III: */ /* GCS */ /* VITALS: Heart rate, mean blood pressure, temperature, respiration rate */ /* FLAGS: ventilation/cpap, chronic dialysis */ /* IO: urine output */ /* LABS: pao2, A-aDO2, hematocrit, WBC, creatinine */ /* , blood urea nitrogen, sodium, albumin, bilirubin, glucose, pH, pCO2 */ /* The following views are required to run this query: */ /* 1) urine_output_first_day - generated by urine-output-first-day.sql */ /* 2) ventilation_first_day - generated by ventilated-first-day.sql */ /* 3) vitals_first_day - generated by vitals-first-day.sql */ /* 4) gcs_first_day - generated by gcs-first-day.sql */ /* 5) labs_first_day - generated by labs-first-day.sql */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate icustay_ids. */ /* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ /* List of TODO: */ /* The site of temperature is not incorporated. Axillary measurements should be increased by 1 degree. */ /* Unfortunately the data for metavision is not available at the moment. */ /* 674 | Temp. Site */ /* 224642 | Temperature Site */ +/* ------------------------------------------------------------------ */ +/* Title: Acute Physiology Score III (APS III) */ +/* This query extracts the acute physiology score III. */ +/* This score is a measure of patient severity of illness. */ +/* The score is calculated on the first day of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for APS III: */ +/* Knaus WA, Wagner DP, Draper EA, Zimmerman JE, Bergner M, Bastos PG, Sirio CA, Murphy DJ, Lotring T, Damiano A. */ +/* The APACHE III prognostic system. Risk prediction of hospital mortality for critically ill hospitalized adults. */ +/* Chest Journal. 1991 Dec 1;100(6):1619-36. */ +/* Reference for the equation for calibrating APS III to hospital mortality: */ +/* Johnson, A. E. W. (2015). Mortality prediction and acuity assessment in critical care. */ +/* University of Oxford, Oxford, UK. */ +/* Variables used in APS III: */ +/* GCS */ +/* VITALS: Heart rate, mean blood pressure, temperature, respiration rate */ +/* FLAGS: ventilation/cpap, chronic dialysis */ +/* IO: urine output */ +/* LABS: pao2, A-aDO2, hematocrit, WBC, creatinine */ +/* , blood urea nitrogen, sodium, albumin, bilirubin, glucose, pH, pCO2 */ +/* The following views are required to run this query: */ +/* 1) urine_output_first_day - generated by urine-output-first-day.sql */ +/* 2) ventilation_first_day - generated by ventilated-first-day.sql */ +/* 3) vitals_first_day - generated by vitals-first-day.sql */ +/* 4) gcs_first_day - generated by gcs-first-day.sql */ +/* 5) labs_first_day - generated by labs-first-day.sql */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate icustay_ids. */ +/* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ +/* List of TODO: */ +/* The site of temperature is not incorporated. Axillary measurements should be increased by 1 degree. */ +/* Unfortunately the data for metavision is not available at the moment. */ +/* 674 | Temp. Site */ +/* 224642 | Temperature Site */ WITH pa AS ( SELECT bg.icustay_id, @@ -17,7 +50,8 @@ WITH pa AS ( AND /* and fio2 < 50, or if no fio2, assume room air */ COALESCE(fio2, fio2_chartevents, 21) < 50 AND NOT bg.po2 IS NULL ), aa AS ( - /* join blood gas to ventilation durations to determine if patient was vent */ /* also join to cpap table for the same purpose */ + /* join blood gas to ventilation durations to determine if patient was vent */ + /* also join to cpap table for the same purpose */ SELECT bg.icustay_id, bg.charttime, diff --git a/mimic-iii/concepts_postgres/severityscores/lods.sql b/mimic-iii/concepts_postgres/severityscores/lods.sql index a879dfdb0..d2bd596b7 100644 --- a/mimic-iii/concepts_postgres/severityscores/lods.sql +++ b/mimic-iii/concepts_postgres/severityscores/lods.sql @@ -1,6 +1,33 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.lods; CREATE TABLE mimiciii_derived.lods AS -/* ------------------------------------------------------------------ */ /* Title: Logistic Organ Dysfunction Score (LODS) */ /* This query extracts the logistic organ dysfunction system. */ /* This score is a measure of organ failure in a patient. */ /* The score is calculated on the first day of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for LODS: */ /* Le Gall, J. R., Klar, J., Lemeshow, S., Saulnier, F., Alberti, C., Artigas, A., & Teres, D. */ /* The Logistic Organ Dysfunction system: a new way to assess organ dysfunction in the intensive care unit. */ /* JAMA 276.10 (1996): 802-810. */ /* Variables used in LODS: */ /* GCS */ /* VITALS: Heart rate, systolic blood pressure */ /* FLAGS: ventilation/cpap */ /* IO: urine output */ /* LABS: blood urea nitrogen, WBC, bilirubin, creatinine, prothrombin time (PT), platelets */ /* ABG: PaO2 with associated FiO2 */ /* The following views are required to run this query: */ /* 1) urine_output_first_day - generated by urine-output-first-day.sql */ /* 2) ventilation_durations - generated by ventilation_durations.sql */ /* 3) vitals_first_day - generated by vitals-first-day.sql */ /* 4) gcs_first_day - generated by gcs-first-day.sql */ /* 5) labs_first_day - generated by labs-first-day.sql */ /* 5) blood_gas_first_day_arterial - generated by blood-gas-first-day-arterial.sql */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ /* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ /* extract CPAP from the "Oxygen Delivery Device" fields */ +/* ------------------------------------------------------------------ */ +/* Title: Logistic Organ Dysfunction Score (LODS) */ +/* This query extracts the logistic organ dysfunction system. */ +/* This score is a measure of organ failure in a patient. */ +/* The score is calculated on the first day of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for LODS: */ +/* Le Gall, J. R., Klar, J., Lemeshow, S., Saulnier, F., Alberti, C., Artigas, A., & Teres, D. */ +/* The Logistic Organ Dysfunction system: a new way to assess organ dysfunction in the intensive care unit. */ +/* JAMA 276.10 (1996): 802-810. */ +/* Variables used in LODS: */ +/* GCS */ +/* VITALS: Heart rate, systolic blood pressure */ +/* FLAGS: ventilation/cpap */ +/* IO: urine output */ +/* LABS: blood urea nitrogen, WBC, bilirubin, creatinine, prothrombin time (PT), platelets */ +/* ABG: PaO2 with associated FiO2 */ +/* The following views are required to run this query: */ +/* 1) urine_output_first_day - generated by urine-output-first-day.sql */ +/* 2) ventilation_durations - generated by ventilation_durations.sql */ +/* 3) vitals_first_day - generated by vitals-first-day.sql */ +/* 4) gcs_first_day - generated by gcs-first-day.sql */ +/* 5) labs_first_day - generated by labs-first-day.sql */ +/* 5) blood_gas_first_day_arterial - generated by blood-gas-first-day-arterial.sql */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ +/* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ +/* extract CPAP from the "Oxygen Delivery Device" fields */ WITH cpap AS ( SELECT ie.icustay_id, @@ -34,7 +61,8 @@ WITH cpap AS ( GROUP BY ie.icustay_id ), pafi1 AS ( - /* join blood gas to ventilation durations to determine if patient was vent */ /* also join to cpap table for the same purpose */ + /* join blood gas to ventilation durations to determine if patient was vent */ + /* also join to cpap table for the same purpose */ SELECT bg.icustay_id, bg.charttime, diff --git a/mimic-iii/concepts_postgres/severityscores/mlods.sql b/mimic-iii/concepts_postgres/severityscores/mlods.sql index 8fd192ef3..9ad9bac6f 100644 --- a/mimic-iii/concepts_postgres/severityscores/mlods.sql +++ b/mimic-iii/concepts_postgres/severityscores/mlods.sql @@ -1,6 +1,31 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.mlods; CREATE TABLE mimiciii_derived.mlods AS -/* ------------------------------------------------------------------ */ /* Title: Modified Logistic organ dysfunction system (mLODS) */ /* This query extracts a modified version of the logistic organ dysfunction system. */ /* This score was used in the third international definition of sepsis: Sepsis-3. */ /* This score is a measure of organ failure in a patient. */ /* ------------------------------------------------------------------ */ /* Reference for LODS: */ /* Le Gall, J. R., Klar, J., Lemeshow, S., Saulnier, F., Alberti, C., Artigas, A., & Teres, D. */ /* The Logistic Organ Dysfunction system: a new way to assess organ dysfunction in the intensive care unit. */ /* JAMA 276.10 (1996): 802-810. */ /* Reference for modified LODS: */ /* Le Gall, J. R., Klar, J., Lemeshow, S., Saulnier, F., Alberti, C., Artigas, A., & Teres, D. */ /* The Logistic Organ Dysfunction system: a new way to assess organ dysfunction in the intensive care unit. */ /* JAMA 276.10 (1996): 802-810. */ /* Variables used in mLODS: */ /* GCS */ /* VITALS: Heart rate, systolic blood pressure */ /* FLAGS: ventilation/cpap */ /* LABS: WBC, bilirubin, creatinine, platelets */ /* ABG: PaO2 with associated FiO2 */ /* Variables *excluded*, that are used in the original LODS: */ /* prothrombin time (PT), blood urea nitrogen, urine output */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ /* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ /* extract CPAP from the "Oxygen Delivery Device" fields */ +/* ------------------------------------------------------------------ */ +/* Title: Modified Logistic organ dysfunction system (mLODS) */ +/* This query extracts a modified version of the logistic organ dysfunction system. */ +/* This score was used in the third international definition of sepsis: Sepsis-3. */ +/* This score is a measure of organ failure in a patient. */ +/* ------------------------------------------------------------------ */ +/* Reference for LODS: */ +/* Le Gall, J. R., Klar, J., Lemeshow, S., Saulnier, F., Alberti, C., Artigas, A., & Teres, D. */ +/* The Logistic Organ Dysfunction system: a new way to assess organ dysfunction in the intensive care unit. */ +/* JAMA 276.10 (1996): 802-810. */ +/* Reference for modified LODS: */ +/* Le Gall, J. R., Klar, J., Lemeshow, S., Saulnier, F., Alberti, C., Artigas, A., & Teres, D. */ +/* The Logistic Organ Dysfunction system: a new way to assess organ dysfunction in the intensive care unit. */ +/* JAMA 276.10 (1996): 802-810. */ +/* Variables used in mLODS: */ +/* GCS */ +/* VITALS: Heart rate, systolic blood pressure */ +/* FLAGS: ventilation/cpap */ +/* LABS: WBC, bilirubin, creatinine, platelets */ +/* ABG: PaO2 with associated FiO2 */ +/* Variables *excluded*, that are used in the original LODS: */ +/* prothrombin time (PT), blood urea nitrogen, urine output */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ +/* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ +/* extract CPAP from the "Oxygen Delivery Device" fields */ WITH cpap AS ( SELECT ie.icustay_id, @@ -33,7 +58,8 @@ WITH cpap AS ( GROUP BY ie.icustay_id ), pafi1 AS ( - /* join blood gas to ventilation durations to determine if patient was vent */ /* also join to cpap table for the same purpose */ + /* join blood gas to ventilation durations to determine if patient was vent */ + /* also join to cpap table for the same purpose */ SELECT bg.icustay_id, bg.charttime, diff --git a/mimic-iii/concepts_postgres/severityscores/oasis.sql b/mimic-iii/concepts_postgres/severityscores/oasis.sql index 86e39816b..a96435cc3 100644 --- a/mimic-iii/concepts_postgres/severityscores/oasis.sql +++ b/mimic-iii/concepts_postgres/severityscores/oasis.sql @@ -1,6 +1,31 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.oasis; CREATE TABLE mimiciii_derived.oasis AS -/* ------------------------------------------------------------------ */ /* Title: Oxford Acute Severity of Illness Score (oasis) */ /* This query extracts the Oxford acute severity of illness score. */ /* This score is a measure of severity of illness for patients in the ICU. */ /* The score is calculated on the first day of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for OASIS: */ /* Johnson, Alistair EW, Andrew A. Kramer, and Gari D. Clifford. */ /* "A new severity of illness scale using a subset of acute physiology and chronic health evaluation data elements shows comparable predictive accuracy*." */ /* Critical care medicine 41, no. 7 (2013): 1711-1718. */ /* Variables used in OASIS: */ /* Heart rate, GCS, MAP, Temperature, Respiratory rate, Ventilation status (sourced FROM `physionet-data.mimiciii_clinical.chartevents`) */ /* Urine output (sourced from OUTPUTEVENTS) */ /* Elective surgery (sourced FROM `physionet-data.mimiciii_clinical.admissions` and SERVICES) */ /* Pre-ICU in-hospital length of stay (sourced FROM `physionet-data.mimiciii_clinical.admissions` and ICUSTAYS) */ /* Age (sourced FROM `physionet-data.mimiciii_clinical.patients`) */ /* The following views are required to run this query: */ /* 1) urine_output_first_day - generated by urine-output-first-day.sql */ /* 2) vent_first_day - generated by ventilated-first-day.sql */ /* 3) vitals_first_day - generated by vitals-first-day.sql */ /* 4) gcs_first_day - generated by gcs-first-day.sql */ /* Regarding missing values: */ /* The ventilation flag is always 0/1. It cannot be missing, since VENT=0 if no data is found for vent settings. */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ /* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ +/* ------------------------------------------------------------------ */ +/* Title: Oxford Acute Severity of Illness Score (oasis) */ +/* This query extracts the Oxford acute severity of illness score. */ +/* This score is a measure of severity of illness for patients in the ICU. */ +/* The score is calculated on the first day of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for OASIS: */ +/* Johnson, Alistair EW, Andrew A. Kramer, and Gari D. Clifford. */ +/* "A new severity of illness scale using a subset of acute physiology and chronic health evaluation data elements shows comparable predictive accuracy*." */ +/* Critical care medicine 41, no. 7 (2013): 1711-1718. */ +/* Variables used in OASIS: */ +/* Heart rate, GCS, MAP, Temperature, Respiratory rate, Ventilation status (sourced FROM `physionet-data.mimiciii_clinical.chartevents`) */ +/* Urine output (sourced from OUTPUTEVENTS) */ +/* Elective surgery (sourced FROM `physionet-data.mimiciii_clinical.admissions` and SERVICES) */ +/* Pre-ICU in-hospital length of stay (sourced FROM `physionet-data.mimiciii_clinical.admissions` and ICUSTAYS) */ +/* Age (sourced FROM `physionet-data.mimiciii_clinical.patients`) */ +/* The following views are required to run this query: */ +/* 1) urine_output_first_day - generated by urine-output-first-day.sql */ +/* 2) vent_first_day - generated by ventilated-first-day.sql */ +/* 3) vitals_first_day - generated by vitals-first-day.sql */ +/* 4) gcs_first_day - generated by gcs-first-day.sql */ +/* Regarding missing values: */ +/* The ventilation flag is always 0/1. It cannot be missing, since VENT=0 if no data is found for vent settings. */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ +/* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ WITH surgflag AS ( SELECT ie.icustay_id, diff --git a/mimic-iii/concepts_postgres/severityscores/qsofa.sql b/mimic-iii/concepts_postgres/severityscores/qsofa.sql index b55137381..a90c870b0 100644 --- a/mimic-iii/concepts_postgres/severityscores/qsofa.sql +++ b/mimic-iii/concepts_postgres/severityscores/qsofa.sql @@ -1,6 +1,22 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.qsofa; CREATE TABLE mimiciii_derived.qsofa AS -/* ------------------------------------------------------------------ */ /* Title: Quick Sequential Organ Failure Assessment (qSOFA) */ /* This query extracts the quick sequential organ failure assessment. */ /* This score was a recent revision of SOFA, aiming to detect patients at risk of sepsis. */ /* The score is calculated on the first day of each ICU patients' stay - though needn't be. */ /* ------------------------------------------------------------------ */ /* Reference for qSOFA: */ /* Singer M, et al. The Third International Consensus Definitions for Sepsis and Septic Shock (Sepsis-3) */ /* Seymour CW, et al. Assessment of Clinical Criteria for Sepsis: For the Third International Consensus Definitions for Sepsis and Septic Shock (Sepsis-3) */ /* Variables used in qSOFA: */ /* GCS, respiratory rate, systolic blood pressure */ /* The following views required to run this query: */ /* 1) gcsfirstday - generated by gcs-first-day.sql */ /* 2) vitalsfirstday - generated by vitals-first-day.sql */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ /* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ +/* ------------------------------------------------------------------ */ +/* Title: Quick Sequential Organ Failure Assessment (qSOFA) */ +/* This query extracts the quick sequential organ failure assessment. */ +/* This score was a recent revision of SOFA, aiming to detect patients at risk of sepsis. */ +/* The score is calculated on the first day of each ICU patients' stay - though needn't be. */ +/* ------------------------------------------------------------------ */ +/* Reference for qSOFA: */ +/* Singer M, et al. The Third International Consensus Definitions for Sepsis and Septic Shock (Sepsis-3) */ +/* Seymour CW, et al. Assessment of Clinical Criteria for Sepsis: For the Third International Consensus Definitions for Sepsis and Septic Shock (Sepsis-3) */ +/* Variables used in qSOFA: */ +/* GCS, respiratory rate, systolic blood pressure */ +/* The following views required to run this query: */ +/* 1) gcsfirstday - generated by gcs-first-day.sql */ +/* 2) vitalsfirstday - generated by vitals-first-day.sql */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ +/* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ WITH scorecomp AS ( SELECT ie.icustay_id, @@ -13,7 +29,9 @@ WITH scorecomp AS ( LEFT JOIN mimiciii_derived.gcs_first_day AS gcs ON ie.icustay_id = gcs.icustay_id ), scorecalc AS ( - /* Calculate the final score */ /* note that if the underlying data is missing, the component is null */ /* eventually these are treated as 0 (normal), but knowing when data is missing is useful for debugging */ + /* Calculate the final score */ + /* note that if the underlying data is missing, the component is null */ + /* eventually these are treated as 0 (normal), but knowing when data is missing is useful for debugging */ SELECT icustay_id, CASE WHEN sysbp_min IS NULL THEN NULL WHEN sysbp_min <= 100 THEN 1 ELSE 0 END AS sysbp_score, diff --git a/mimic-iii/concepts_postgres/severityscores/saps.sql b/mimic-iii/concepts_postgres/severityscores/saps.sql index 72a817bdb..37a61a929 100644 --- a/mimic-iii/concepts_postgres/severityscores/saps.sql +++ b/mimic-iii/concepts_postgres/severityscores/saps.sql @@ -1,6 +1,32 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.saps; CREATE TABLE mimiciii_derived.saps AS -/* ------------------------------------------------------------------ */ /* Title: Simplified Acute Physiology Score (SAPS) */ /* This query extracts the simplified acute physiology score. */ /* This score is a measure of patient severity of illness. */ /* The score is calculated on the first day of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for SAPS: */ /* Jean-Roger Le Gall, Philippe Loirat, Annick Alperovitch, Paul Glaser, Claude Granthil, */ /* Daniel Mathieu, Philippe Mercier, Remi Thomas, and Daniel Villers. */ /* "A simplified acute physiology score for ICU patients." */ /* Critical care medicine 12, no. 11 (1984): 975-977. */ /* Variables used in SAPS: */ /* Age, GCS */ /* VITALS: Heart rate, systolic blood pressure, temperature, respiration rate */ /* FLAGS: ventilation/cpap */ /* IO: urine output */ /* LABS: blood urea nitrogen, hematocrit, WBC, glucose, potassium, sodium, HCO3 */ /* The following views are required to run this query: */ /* 1) urine_output_first_day - generated by urine-output-first-day.sql */ /* 2) vent_first_day - generated by ventilated-first-day.sql */ /* 3) vitals_first_day - generated by vitals-first-day.sql */ /* 4) gcs_first_day - generated by gcs-first-day.sql */ /* 5) labs_first_day - generated by labs-first-day.sql */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ /* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ /* extract CPAP from the "Oxygen Delivery Device" fields */ +/* ------------------------------------------------------------------ */ +/* Title: Simplified Acute Physiology Score (SAPS) */ +/* This query extracts the simplified acute physiology score. */ +/* This score is a measure of patient severity of illness. */ +/* The score is calculated on the first day of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for SAPS: */ +/* Jean-Roger Le Gall, Philippe Loirat, Annick Alperovitch, Paul Glaser, Claude Granthil, */ +/* Daniel Mathieu, Philippe Mercier, Remi Thomas, and Daniel Villers. */ +/* "A simplified acute physiology score for ICU patients." */ +/* Critical care medicine 12, no. 11 (1984): 975-977. */ +/* Variables used in SAPS: */ +/* Age, GCS */ +/* VITALS: Heart rate, systolic blood pressure, temperature, respiration rate */ +/* FLAGS: ventilation/cpap */ +/* IO: urine output */ +/* LABS: blood urea nitrogen, hematocrit, WBC, glucose, potassium, sodium, HCO3 */ +/* The following views are required to run this query: */ +/* 1) urine_output_first_day - generated by urine-output-first-day.sql */ +/* 2) vent_first_day - generated by ventilated-first-day.sql */ +/* 3) vitals_first_day - generated by vitals-first-day.sql */ +/* 4) gcs_first_day - generated by gcs-first-day.sql */ +/* 5) labs_first_day - generated by labs-first-day.sql */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ +/* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ +/* extract CPAP from the "Oxygen Delivery Device" fields */ WITH cpap AS ( SELECT ie.icustay_id, diff --git a/mimic-iii/concepts_postgres/severityscores/sapsii.sql b/mimic-iii/concepts_postgres/severityscores/sapsii.sql index 96e116ab2..77d357a85 100644 --- a/mimic-iii/concepts_postgres/severityscores/sapsii.sql +++ b/mimic-iii/concepts_postgres/severityscores/sapsii.sql @@ -1,6 +1,32 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.sapsii; CREATE TABLE mimiciii_derived.sapsii AS -/* ------------------------------------------------------------------ */ /* Title: Simplified Acute Physiology Score II (SAPS II) */ /* This query extracts the simplified acute physiology score II. */ /* This score is a measure of patient severity of illness. */ /* The score is calculated on the first day of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for SAPS II: */ /* Le Gall, Jean-Roger, Stanley Lemeshow, and Fabienne Saulnier. */ /* "A new simplified acute physiology score (SAPS II) based on a European/North American multicenter study." */ /* JAMA 270, no. 24 (1993): 2957-2963. */ /* Variables used in SAPS II: */ /* Age, GCS */ /* VITALS: Heart rate, systolic blood pressure, temperature */ /* FLAGS: ventilation/cpap */ /* IO: urine output */ /* LABS: PaO2/FiO2 ratio, blood urea nitrogen, WBC, potassium, sodium, HCO3 */ /* The following views are required to run this query: */ /* 1) urine_output_first_day - generated by urine-output-first-day.sql */ /* 2) ventilation_durations - generated by ventilation_durations.sql */ /* 3) vitals_first_day - generated by vitals-first-day.sql */ /* 4) gcs_first_day - generated by gcs-first-day.sql */ /* 5) labs_first_day - generated by labs-first-day.sql */ /* 6) blood_gas_arterial_first_day - generated by blood-gas-first-day-arterial.sql */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ /* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ /* extract CPAP from the "Oxygen Delivery Device" fields */ +/* ------------------------------------------------------------------ */ +/* Title: Simplified Acute Physiology Score II (SAPS II) */ +/* This query extracts the simplified acute physiology score II. */ +/* This score is a measure of patient severity of illness. */ +/* The score is calculated on the first day of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for SAPS II: */ +/* Le Gall, Jean-Roger, Stanley Lemeshow, and Fabienne Saulnier. */ +/* "A new simplified acute physiology score (SAPS II) based on a European/North American multicenter study." */ +/* JAMA 270, no. 24 (1993): 2957-2963. */ +/* Variables used in SAPS II: */ +/* Age, GCS */ +/* VITALS: Heart rate, systolic blood pressure, temperature */ +/* FLAGS: ventilation/cpap */ +/* IO: urine output */ +/* LABS: PaO2/FiO2 ratio, blood urea nitrogen, WBC, potassium, sodium, HCO3 */ +/* The following views are required to run this query: */ +/* 1) urine_output_first_day - generated by urine-output-first-day.sql */ +/* 2) ventilation_durations - generated by ventilation_durations.sql */ +/* 3) vitals_first_day - generated by vitals-first-day.sql */ +/* 4) gcs_first_day - generated by gcs-first-day.sql */ +/* 5) labs_first_day - generated by labs-first-day.sql */ +/* 6) blood_gas_arterial_first_day - generated by blood-gas-first-day-arterial.sql */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ +/* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ +/* extract CPAP from the "Oxygen Delivery Device" fields */ WITH cpap AS ( SELECT ie.icustay_id, @@ -85,7 +111,8 @@ WITH cpap AS ( GROUP BY hadm_id ), pafi1 AS ( - /* join blood gas to ventilation durations to determine if patient was vent */ /* also join to cpap table for the same purpose */ + /* join blood gas to ventilation durations to determine if patient was vent */ + /* also join to cpap table for the same purpose */ SELECT bg.icustay_id, bg.charttime, diff --git a/mimic-iii/concepts_postgres/severityscores/sirs.sql b/mimic-iii/concepts_postgres/severityscores/sirs.sql index 5a3f3fed0..35eeef709 100644 --- a/mimic-iii/concepts_postgres/severityscores/sirs.sql +++ b/mimic-iii/concepts_postgres/severityscores/sirs.sql @@ -1,6 +1,30 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.sirs; CREATE TABLE mimiciii_derived.sirs AS -/* ------------------------------------------------------------------ */ /* Title: Systemic inflammatory response syndrome (SIRS) criteria */ /* This query extracts the Systemic inflammatory response syndrome (SIRS) criteria */ /* The criteria quantify the level of inflammatory response of the body */ /* The score is calculated on the first day of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for SIRS: */ /* American College of Chest Physicians/Society of Critical Care Medicine Consensus Conference: */ /* definitions for sepsis and organ failure and guidelines for the use of innovative therapies in sepsis" */ /* Crit. Care Med. 20 (6): 864–74. 1992. */ /* doi:10.1097/00003246-199206000-00025. PMID 1597042. */ /* Variables used in SIRS: */ /* Body temperature (min and max) */ /* Heart rate (max) */ /* Respiratory rate (max) */ /* PaCO2 (min) */ /* White blood cell count (min and max) */ /* the presence of greater than 10% immature neutrophils (band forms) */ /* The following views required to run this query: */ /* 1) vitals_first_day - generated by vitals-first-day.sql */ /* 2) labs_first_day - generated by labs-first-day.sql */ /* 3) blood_gas_first_day_arterial - generated by blood-gas-first-day-arterial.sql */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ /* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ +/* ------------------------------------------------------------------ */ +/* Title: Systemic inflammatory response syndrome (SIRS) criteria */ +/* This query extracts the Systemic inflammatory response syndrome (SIRS) criteria */ +/* The criteria quantify the level of inflammatory response of the body */ +/* The score is calculated on the first day of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for SIRS: */ +/* American College of Chest Physicians/Society of Critical Care Medicine Consensus Conference: */ +/* definitions for sepsis and organ failure and guidelines for the use of innovative therapies in sepsis" */ +/* Crit. Care Med. 20 (6): 864–74. 1992. */ +/* doi:10.1097/00003246-199206000-00025. PMID 1597042. */ +/* Variables used in SIRS: */ +/* Body temperature (min and max) */ +/* Heart rate (max) */ +/* Respiratory rate (max) */ +/* PaCO2 (min) */ +/* White blood cell count (min and max) */ +/* the presence of greater than 10% immature neutrophils (band forms) */ +/* The following views required to run this query: */ +/* 1) vitals_first_day - generated by vitals-first-day.sql */ +/* 2) labs_first_day - generated by labs-first-day.sql */ +/* 3) blood_gas_first_day_arterial - generated by blood-gas-first-day-arterial.sql */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ +/* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ WITH bg AS ( /* join blood gas to ventilation durations to determine if patient was vent */ SELECT @@ -30,7 +54,9 @@ WITH bg AS ( LEFT JOIN mimiciii_derived.labs_first_day AS l ON ie.icustay_id = l.icustay_id ), scorecalc AS ( - /* Calculate the final score */ /* note that if the underlying data is missing, the component is null */ /* eventually these are treated as 0 (normal), but knowing when data is missing is useful for debugging */ + /* Calculate the final score */ + /* note that if the underlying data is missing, the component is null */ + /* eventually these are treated as 0 (normal), but knowing when data is missing is useful for debugging */ SELECT icustay_id, CASE diff --git a/mimic-iii/concepts_postgres/severityscores/sofa.sql b/mimic-iii/concepts_postgres/severityscores/sofa.sql index ebd63ea44..fba459d8c 100644 --- a/mimic-iii/concepts_postgres/severityscores/sofa.sql +++ b/mimic-iii/concepts_postgres/severityscores/sofa.sql @@ -1,6 +1,32 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciii_derived.sofa; CREATE TABLE mimiciii_derived.sofa AS -/* ------------------------------------------------------------------ */ /* Title: Sequential Organ Failure Assessment (SOFA) */ /* This query extracts the sequential organ failure assessment (formally: sepsis-related organ failure assessment). */ /* This score is a measure of organ failure for patients in the ICU. */ /* The score is calculated on the first day of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for SOFA: */ /* Jean-Louis Vincent, Rui Moreno, Jukka Takala, Sheila Willatts, Arnaldo De Mendonça, */ /* Hajo Bruining, C. K. Reinhart, Peter M Suter, and L. G. Thijs. */ /* "The SOFA (Sepsis-related Organ Failure Assessment) score to describe organ dysfunction/failure." */ /* Intensive care medicine 22, no. 7 (1996): 707-710. */ /* Variables used in SOFA: */ /* GCS, MAP, FiO2, Ventilation status (sourced FROM `physionet-data.mimiciii_clinical.chartevents`) */ /* Creatinine, Bilirubin, FiO2, PaO2, Platelets (sourced FROM `physionet-data.mimiciii_clinical.labevents`) */ /* Dobutamine, Epinephrine, Norepinephrine (sourced FROM `physionet-data.mimiciii_clinical.inputevents_mv` and INPUTEVENTS_CV) */ /* Urine output (sourced from OUTPUTEVENTS) */ /* The following views required to run this query: */ /* 1) urine_output_first_day - generated by urine-output-first-day.sql */ /* 2) vitals_first_day - generated by vitals-first-day.sql */ /* 3) gcs_first_day - generated by gcs-first-day.sql */ /* 4) labs_first_day - generated by labs-first-day.sql */ /* 5) blood_gas_first_day_arterial - generated by blood-gas-first-day-arterial.sql */ /* 6) echodata - generated by echo-data.sql */ /* 7) ventilation_durations - generated by ventilation_durations.sql */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ /* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ +/* ------------------------------------------------------------------ */ +/* Title: Sequential Organ Failure Assessment (SOFA) */ +/* This query extracts the sequential organ failure assessment (formally: sepsis-related organ failure assessment). */ +/* This score is a measure of organ failure for patients in the ICU. */ +/* The score is calculated on the first day of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for SOFA: */ +/* Jean-Louis Vincent, Rui Moreno, Jukka Takala, Sheila Willatts, Arnaldo De Mendonça, */ +/* Hajo Bruining, C. K. Reinhart, Peter M Suter, and L. G. Thijs. */ +/* "The SOFA (Sepsis-related Organ Failure Assessment) score to describe organ dysfunction/failure." */ +/* Intensive care medicine 22, no. 7 (1996): 707-710. */ +/* Variables used in SOFA: */ +/* GCS, MAP, FiO2, Ventilation status (sourced FROM `physionet-data.mimiciii_clinical.chartevents`) */ +/* Creatinine, Bilirubin, FiO2, PaO2, Platelets (sourced FROM `physionet-data.mimiciii_clinical.labevents`) */ +/* Dobutamine, Epinephrine, Norepinephrine (sourced FROM `physionet-data.mimiciii_clinical.inputevents_mv` and INPUTEVENTS_CV) */ +/* Urine output (sourced from OUTPUTEVENTS) */ +/* The following views required to run this query: */ +/* 1) urine_output_first_day - generated by urine-output-first-day.sql */ +/* 2) vitals_first_day - generated by vitals-first-day.sql */ +/* 3) gcs_first_day - generated by gcs-first-day.sql */ +/* 4) labs_first_day - generated by labs-first-day.sql */ +/* 5) blood_gas_first_day_arterial - generated by blood-gas-first-day-arterial.sql */ +/* 6) echodata - generated by echo-data.sql */ +/* 7) ventilation_durations - generated by ventilation_durations.sql */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption that the user will subselect appropriate ICUSTAY_IDs. */ +/* For example, the score is calculated for neonates, but it is likely inappropriate to actually use the score values for these patients. */ WITH wt AS ( SELECT ie.icustay_id, /* ensure weight is measured in kg */ @@ -115,7 +141,9 @@ WITH wt AS ( bg.icustay_id NULLS FIRST, bg.charttime NULLS FIRST ), pafi2 AS ( - /* because pafi has an interaction between vent/PaO2:FiO2, we need two columns for the score */ /* it can happen that the lowest unventilated PaO2/FiO2 is 68, but the lowest ventilated PaO2/FiO2 is 120 */ /* in this case, the SOFA score is 3, *not* 4. */ + /* because pafi has an interaction between vent/PaO2:FiO2, we need two columns for the score */ + /* it can happen that the lowest unventilated PaO2/FiO2 is 68, but the lowest ventilated PaO2/FiO2 is 120 */ + /* in this case, the SOFA score is 3, *not* 4. */ SELECT icustay_id, MIN(CASE WHEN isvent = 0 THEN pao2fio2 ELSE NULL END) AS pao2fio2_novent_min, @@ -154,7 +182,9 @@ WITH wt AS ( LEFT JOIN mimiciii_derived.gcs_first_day AS gcs ON ie.icustay_id = gcs.icustay_id ), scorecalc AS ( - /* Calculate the final score */ /* note that if the underlying data is missing, the component is null */ /* eventually these are treated as 0 (normal), but knowing when data is missing is useful for debugging */ + /* Calculate the final score */ + /* note that if the underlying data is missing, the component is null */ + /* eventually these are treated as 0 (normal), but knowing when data is missing is useful for debugging */ SELECT icustay_id, /* Respiration */ CASE diff --git a/mimic-iv/concepts_postgres/comorbidity/charlson.sql b/mimic-iv/concepts_postgres/comorbidity/charlson.sql index 45920cede..0de07c36d 100644 --- a/mimic-iv/concepts_postgres/comorbidity/charlson.sql +++ b/mimic-iv/concepts_postgres/comorbidity/charlson.sql @@ -1,6 +1,21 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.charlson; CREATE TABLE mimiciv_derived.charlson AS -/* ------------------------------------------------------------------ */ /* This query extracts Charlson Comorbidity Index (CCI) based on the */ /* recorded ICD-9 and ICD-10 codes. */ /* Reference for CCI: */ /* (1) Charlson ME, Pompei P, Ales KL, MacKenzie CR. (1987) A new method */ /* of classifying prognostic comorbidity in longitudinal studies: */ /* development and validation.J Chronic Dis; 40(5):373-83. */ /* (2) Charlson M, Szatrowski TP, Peterson J, Gold J. (1994) Validation */ /* of a combined comorbidity index. J Clin Epidemiol; 47(11):1245-51. */ /* */ /* Reference for ICD-9-CM and ICD-10 Coding Algorithms for Charlson */ /* Comorbidities: */ /* (3) Quan H, Sundararajan V, Halfon P, et al. Coding algorithms for */ /* defining Comorbidities in ICD-9-CM and ICD-10 administrative data. */ /* Med Care. 2005 Nov; 43(11): 1130-9. */ /* ------------------------------------------------------------------ */ +/* ------------------------------------------------------------------ */ +/* This query extracts Charlson Comorbidity Index (CCI) based on the */ +/* recorded ICD-9 and ICD-10 codes. */ +/* Reference for CCI: */ +/* (1) Charlson ME, Pompei P, Ales KL, MacKenzie CR. (1987) A new method */ +/* of classifying prognostic comorbidity in longitudinal studies: */ +/* development and validation.J Chronic Dis; 40(5):373-83. */ +/* (2) Charlson M, Szatrowski TP, Peterson J, Gold J. (1994) Validation */ +/* of a combined comorbidity index. J Clin Epidemiol; 47(11):1245-51. */ +/* */ +/* Reference for ICD-9-CM and ICD-10 Coding Algorithms for Charlson */ +/* Comorbidities: */ +/* (3) Quan H, Sundararajan V, Halfon P, et al. Coding algorithms for */ +/* defining Comorbidities in ICD-9-CM and ICD-10 administrative data. */ +/* Med Care. 2005 Nov; 43(11): 1130-9. */ +/* ------------------------------------------------------------------ */ WITH diag AS ( SELECT hadm_id, diff --git a/mimic-iv/concepts_postgres/demographics/age.sql b/mimic-iv/concepts_postgres/demographics/age.sql index 8e2b13134..6c50c4782 100644 --- a/mimic-iv/concepts_postgres/demographics/age.sql +++ b/mimic-iv/concepts_postgres/demographics/age.sql @@ -1,6 +1,21 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.age; CREATE TABLE mimiciv_derived.age AS -/* This query calculates the age of a patient on admission to the hospital. */ /* The columns of the table patients: anchor_age, anchor_year, anchor_year_group */ /* provide information regarding the actual patient year for the patient */ /* admission, and the patient's age at that time. */ /* anchor_year is a shifted year for the patient. */ /* anchor_year_group is a range of years - the patient's anchor_year occurred */ /* during this range. */ /* anchor_age is the patient's age in the anchor_year. */ /* Example: a patient has an anchor_year of 2153, */ /* anchor_year_group of 2008 - 2010, and an anchor_age of 60. */ /* The year 2153 for the patient corresponds to 2008, 2009, or 2010. */ /* The patient was 60 in the shifted year of 2153, */ /* i.e. they were 60 in 2008, 2009, or 2010. */ /* A patient admission in 2154 will occur in 2009-2011, */ /* an admission in 2155 will occur in 2010-2012, and so on. */ /* Therefore, the age of a patient = admission time - anchor_year + anchor_age */ +/* This query calculates the age of a patient on admission to the hospital. */ +/* The columns of the table patients: anchor_age, anchor_year, anchor_year_group */ +/* provide information regarding the actual patient year for the patient */ +/* admission, and the patient's age at that time. */ +/* anchor_year is a shifted year for the patient. */ +/* anchor_year_group is a range of years - the patient's anchor_year occurred */ +/* during this range. */ +/* anchor_age is the patient's age in the anchor_year. */ +/* Example: a patient has an anchor_year of 2153, */ +/* anchor_year_group of 2008 - 2010, and an anchor_age of 60. */ +/* The year 2153 for the patient corresponds to 2008, 2009, or 2010. */ +/* The patient was 60 in the shifted year of 2153, */ +/* i.e. they were 60 in 2008, 2009, or 2010. */ +/* A patient admission in 2154 will occur in 2009-2011, */ +/* an admission in 2155 will occur in 2010-2012, and so on. */ +/* Therefore, the age of a patient = admission time - anchor_year + anchor_age */ SELECT ad.subject_id, ad.hadm_id, diff --git a/mimic-iv/concepts_postgres/demographics/icustay_hourly.sql b/mimic-iv/concepts_postgres/demographics/icustay_hourly.sql index af09eddcb..794e5381c 100644 --- a/mimic-iv/concepts_postgres/demographics/icustay_hourly.sql +++ b/mimic-iv/concepts_postgres/demographics/icustay_hourly.sql @@ -1,6 +1,13 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.icustay_hourly; CREATE TABLE mimiciv_derived.icustay_hourly AS -/* This query generates a row for every hour the patient is in the ICU. */ /* The hours are based on clock-hours (i.e. 02:00, 03:00). */ /* The hour clock starts 24 hours before the first heart rate measurement. */ /* Note that the time of the first heart rate measurement is ceilinged to */ /* the hour. */ /* this query extracts the cohort and every possible hour they were in the ICU */ /* this table can be to other tables on stay_id and (ENDTIME - 1 hour,ENDTIME] */ /* get first/last measurement time */ +/* This query generates a row for every hour the patient is in the ICU. */ +/* The hours are based on clock-hours (i.e. 02:00, 03:00). */ +/* The hour clock starts 24 hours before the first heart rate measurement. */ +/* Note that the time of the first heart rate measurement is ceilinged to */ +/* the hour. */ +/* this query extracts the cohort and every possible hour they were in the ICU */ +/* this table can be to other tables on stay_id and (ENDTIME - 1 hour,ENDTIME] */ +/* get first/last measurement time */ WITH all_hours AS ( SELECT it.stay_id, /* round the intime up to the nearest hour */ diff --git a/mimic-iv/concepts_postgres/demographics/icustay_times.sql b/mimic-iv/concepts_postgres/demographics/icustay_times.sql index 05ec78974..052384d0c 100644 --- a/mimic-iv/concepts_postgres/demographics/icustay_times.sql +++ b/mimic-iv/concepts_postgres/demographics/icustay_times.sql @@ -1,6 +1,8 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.icustay_times; CREATE TABLE mimiciv_derived.icustay_times AS -/* create a table which has fuzzy boundaries on hospital admission */ /* involves first creating a lag/lead version of disch/admit time */ /* get first/last heart rate measurement during hospitalization for each stay_id */ +/* create a table which has fuzzy boundaries on hospital admission */ +/* involves first creating a lag/lead version of disch/admit time */ +/* get first/last heart rate measurement during hospitalization for each stay_id */ WITH t1 AS ( SELECT ce.stay_id, diff --git a/mimic-iv/concepts_postgres/demographics/weight_durations.sql b/mimic-iv/concepts_postgres/demographics/weight_durations.sql index 4edf740b7..71e81fc83 100644 --- a/mimic-iv/concepts_postgres/demographics/weight_durations.sql +++ b/mimic-iv/concepts_postgres/demographics/weight_durations.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.weight_durations; CREATE TABLE mimiciv_derived.weight_durations AS -/* This query extracts weights for adult ICU patients with start/stop times */ /* if an admission weight is given, then this is assigned from intime to outtime */ +/* This query extracts weights for adult ICU patients with start/stop times */ +/* if an admission weight is given, then this is assigned from intime to outtime */ WITH wt_stg AS ( SELECT c.stay_id, @@ -72,7 +73,8 @@ WITH wt_stg AS ( wt.weight_type FROM mimiciv_icu.icustays AS ie INNER JOIN ( - /* the below subquery returns one row for each unique stay_id */ /* the row contains: the first starttime and the corresponding weight */ + /* the below subquery returns one row for each unique stay_id */ + /* the row contains: the first starttime and the corresponding weight */ SELECT wt1.stay_id, wt1.starttime, diff --git a/mimic-iv/concepts_postgres/firstday/first_day_bg.sql b/mimic-iv/concepts_postgres/firstday/first_day_bg.sql index 8c28ae8c6..98bbe0577 100644 --- a/mimic-iv/concepts_postgres/firstday/first_day_bg.sql +++ b/mimic-iv/concepts_postgres/firstday/first_day_bg.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.first_day_bg; CREATE TABLE mimiciv_derived.first_day_bg AS -/* Highest/lowest blood gas values for all blood specimens, */ /* including venous/arterial/mixed */ +/* Highest/lowest blood gas values for all blood specimens, */ +/* including venous/arterial/mixed */ SELECT ie.subject_id, ie.stay_id, diff --git a/mimic-iv/concepts_postgres/firstday/first_day_gcs.sql b/mimic-iv/concepts_postgres/firstday/first_day_gcs.sql index 4f42e0260..6f7124320 100644 --- a/mimic-iv/concepts_postgres/firstday/first_day_gcs.sql +++ b/mimic-iv/concepts_postgres/firstday/first_day_gcs.sql @@ -1,6 +1,15 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.first_day_gcs; CREATE TABLE mimiciv_derived.first_day_gcs AS -/* Glasgow Coma Scale, a measure of neurological function. */ /* Ranges from 3 (worst, comatose) to 15 (best, normal function). */ /* Note: */ /* The GCS for sedated patients is defaulted to 15 in this code. */ /* This follows common practice for scoring patients with severity */ /* of illness scores. */ /* e.g., from the SAPS II publication: */ /* For sedated patients, the Glasgow Coma Score before sedation was used. */ /* This was ascertained either from interviewing the physician who ordered */ /* the sedation, or by reviewing the patient's medical record. */ +/* Glasgow Coma Scale, a measure of neurological function. */ +/* Ranges from 3 (worst, comatose) to 15 (best, normal function). */ +/* Note: */ +/* The GCS for sedated patients is defaulted to 15 in this code. */ +/* This follows common practice for scoring patients with severity */ +/* of illness scores. */ +/* e.g., from the SAPS II publication: */ +/* For sedated patients, the Glasgow Coma Score before sedation was used. */ +/* This was ascertained either from interviewing the physician who ordered */ +/* the sedation, or by reviewing the patient's medical record. */ WITH gcs_final AS ( SELECT ie.subject_id, diff --git a/mimic-iv/concepts_postgres/firstday/first_day_height.sql b/mimic-iv/concepts_postgres/firstday/first_day_height.sql index 92da9a24b..37636fbee 100644 --- a/mimic-iv/concepts_postgres/firstday/first_day_height.sql +++ b/mimic-iv/concepts_postgres/firstday/first_day_height.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.first_day_height; CREATE TABLE mimiciv_derived.first_day_height AS -/* This query extracts heights for adult ICU patients. */ /* It uses all information from the patient's first ICU day. */ /* This is done for consistency with other queries. */ /* Height is unlikely to change throughout a patient's stay. */ +/* This query extracts heights for adult ICU patients. */ +/* It uses all information from the patient's first ICU day. */ +/* This is done for consistency with other queries. */ +/* Height is unlikely to change throughout a patient's stay. */ SELECT ie.subject_id, ie.stay_id, diff --git a/mimic-iv/concepts_postgres/firstday/first_day_rrt.sql b/mimic-iv/concepts_postgres/firstday/first_day_rrt.sql index 904bcf2a4..a761a6eed 100644 --- a/mimic-iv/concepts_postgres/firstday/first_day_rrt.sql +++ b/mimic-iv/concepts_postgres/firstday/first_day_rrt.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.first_day_rrt; CREATE TABLE mimiciv_derived.first_day_rrt AS -/* flag indicating if patients received dialysis during */ /* the first day of their ICU stay */ +/* flag indicating if patients received dialysis during */ +/* the first day of their ICU stay */ SELECT ie.subject_id, ie.stay_id, diff --git a/mimic-iv/concepts_postgres/firstday/first_day_sofa.sql b/mimic-iv/concepts_postgres/firstday/first_day_sofa.sql index e21b7ac26..7c3e4d205 100644 --- a/mimic-iv/concepts_postgres/firstday/first_day_sofa.sql +++ b/mimic-iv/concepts_postgres/firstday/first_day_sofa.sql @@ -1,6 +1,32 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.first_day_sofa; CREATE TABLE mimiciv_derived.first_day_sofa AS -/* ------------------------------------------------------------------ */ /* Title: Sequential Organ Failure Assessment (SOFA) */ /* This query extracts the sequential organ failure assessment */ /* (formerly: sepsis-related organ failure assessment). */ /* This score is a measure of organ failure for patients in the ICU. */ /* The score is calculated on the first day of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for SOFA: */ /* Jean-Louis Vincent, Rui Moreno, Jukka Takala, Sheila Willatts, */ /* Arnaldo De Mendonça, Hajo Bruining, C. K. Reinhart, Peter M Suter, */ /* and L. G. Thijs. */ /* "The SOFA (Sepsis-related Organ Failure Assessment) score to describe */ /* organ dysfunction/failure." */ /* Intensive care medicine 22, no. 7 (1996): 707-710. */ /* Variables used in SOFA: */ /* GCS, MAP, FiO2, Ventilation status (sourced from CHARTEVENTS) */ /* Creatinine, Bilirubin, FiO2, PaO2, Platelets (sourced from LABEVENTS) */ /* Dopamine, Dobutamine, Epinephrine, Norepinephrine (sourced from INPUTEVENTS) */ /* Urine output (sourced from OUTPUTEVENTS) */ /* The following views required to run this query: */ /* 1) first_day_urine_output */ /* 2) first_day_vitalsign */ /* 3) first_day_gcs */ /* 4) first_day_lab */ /* 5) first_day_bg_art */ /* 6) ventdurations */ /* extract drug rates from derived vasopressor tables */ +/* ------------------------------------------------------------------ */ +/* Title: Sequential Organ Failure Assessment (SOFA) */ +/* This query extracts the sequential organ failure assessment */ +/* (formerly: sepsis-related organ failure assessment). */ +/* This score is a measure of organ failure for patients in the ICU. */ +/* The score is calculated on the first day of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for SOFA: */ +/* Jean-Louis Vincent, Rui Moreno, Jukka Takala, Sheila Willatts, */ +/* Arnaldo De Mendonça, Hajo Bruining, C. K. Reinhart, Peter M Suter, */ +/* and L. G. Thijs. */ +/* "The SOFA (Sepsis-related Organ Failure Assessment) score to describe */ +/* organ dysfunction/failure." */ +/* Intensive care medicine 22, no. 7 (1996): 707-710. */ +/* Variables used in SOFA: */ +/* GCS, MAP, FiO2, Ventilation status (sourced from CHARTEVENTS) */ +/* Creatinine, Bilirubin, FiO2, PaO2, Platelets (sourced from LABEVENTS) */ +/* Dopamine, Dobutamine, Epinephrine, Norepinephrine (sourced from INPUTEVENTS) */ +/* Urine output (sourced from OUTPUTEVENTS) */ +/* The following views required to run this query: */ +/* 1) first_day_urine_output */ +/* 2) first_day_vitalsign */ +/* 3) first_day_gcs */ +/* 4) first_day_lab */ +/* 5) first_day_bg_art */ +/* 6) ventdurations */ +/* extract drug rates from derived vasopressor tables */ WITH vaso_stg AS ( SELECT ie.stay_id, @@ -72,7 +98,11 @@ WITH vaso_stg AS ( AND bg.charttime <= vd.endtime AND vd.ventilation_status = 'InvasiveVent' ), pafi2 AS ( - /* because pafi has an interaction between vent/PaO2:FiO2, */ /* we need two columns for the score */ /* it can happen that the lowest unventilated PaO2/FiO2 is 68, */ /* but the lowest ventilated PaO2/FiO2 is 120 */ /* in this case, the SOFA score is 3, *not* 4. */ + /* because pafi has an interaction between vent/PaO2:FiO2, */ + /* we need two columns for the score */ + /* it can happen that the lowest unventilated PaO2/FiO2 is 68, */ + /* but the lowest ventilated PaO2/FiO2 is 120 */ + /* in this case, the SOFA score is 3, *not* 4. */ SELECT stay_id, MIN(CASE WHEN isvent = 0 THEN pao2fio2ratio ELSE NULL END) AS pao2fio2_novent_min, @@ -109,7 +139,10 @@ WITH vaso_stg AS ( LEFT JOIN mimiciv_derived.first_day_gcs AS gcs ON ie.stay_id = gcs.stay_id ), scorecalc AS ( - /* Calculate the final score */ /* note that if the underlying data is missing, the component is null */ /* eventually these are treated as 0 (normal), but knowing when data */ /* is missing is useful for debugging */ + /* Calculate the final score */ + /* note that if the underlying data is missing, the component is null */ + /* eventually these are treated as 0 (normal), but knowing when data */ + /* is missing is useful for debugging */ SELECT stay_id, /* Respiration */ CASE diff --git a/mimic-iv/concepts_postgres/firstday/first_day_vitalsign.sql b/mimic-iv/concepts_postgres/firstday/first_day_vitalsign.sql index a90a8dbf3..b512dfe15 100644 --- a/mimic-iv/concepts_postgres/firstday/first_day_vitalsign.sql +++ b/mimic-iv/concepts_postgres/firstday/first_day_vitalsign.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.first_day_vitalsign; CREATE TABLE mimiciv_derived.first_day_vitalsign AS -/* This query pivots vital signs and aggregates them */ /* for the first 24 hours of a patient's stay. */ +/* This query pivots vital signs and aggregates them */ +/* for the first 24 hours of a patient's stay. */ SELECT ie.subject_id, ie.stay_id, diff --git a/mimic-iv/concepts_postgres/firstday/first_day_weight.sql b/mimic-iv/concepts_postgres/firstday/first_day_weight.sql index 48dcddf21..9d1a984b1 100644 --- a/mimic-iv/concepts_postgres/firstday/first_day_weight.sql +++ b/mimic-iv/concepts_postgres/firstday/first_day_weight.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.first_day_weight; CREATE TABLE mimiciv_derived.first_day_weight AS -/* This query extracts weights for adult ICU patients on their first ICU day. */ /* It does *not* use any information after the first ICU day, as weight is */ /* sometimes used to monitor fluid balance. */ /* The MIMIC-III version used echodata but this isn't available in MIMIC-IV. */ +/* This query extracts weights for adult ICU patients on their first ICU day. */ +/* It does *not* use any information after the first ICU day, as weight is */ +/* sometimes used to monitor fluid balance. */ +/* The MIMIC-III version used echodata but this isn't available in MIMIC-IV. */ SELECT ie.subject_id, ie.stay_id, diff --git a/mimic-iv/concepts_postgres/measurement/bg.sql b/mimic-iv/concepts_postgres/measurement/bg.sql index dca59ee3a..60b9de13d 100644 --- a/mimic-iv/concepts_postgres/measurement/bg.sql +++ b/mimic-iv/concepts_postgres/measurement/bg.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. 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 */ +/* 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, /* specimen_id only ever has 1 measurement for each itemid */ /* so, we may simply collapse rows using MAX() */ @@ -197,7 +198,10 @@ SELECT sodium, lactate, glucose -/* ventilation stuff that's sometimes input */ /* , intubated, tidalvolume, ventilationrate, ventilator */ /* , peep, o2flow */ /* , requiredo2 */ +/* ventilation stuff that's sometimes input */ +/* , intubated, tidalvolume, ventilationrate, ventilator */ +/* , peep, o2flow */ +/* , requiredo2 */ FROM stg3 WHERE lastrowfio2 = 1 /* only the most recent FiO2 */ \ No newline at end of file diff --git a/mimic-iv/concepts_postgres/measurement/blood_differential.sql b/mimic-iv/concepts_postgres/measurement/blood_differential.sql index 73f906e1d..3833a1f52 100644 --- a/mimic-iv/concepts_postgres/measurement/blood_differential.sql +++ b/mimic-iv/concepts_postgres/measurement/blood_differential.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.blood_differential; CREATE TABLE mimiciv_derived.blood_differential AS -/* For reference, some common unit conversions: */ /* 10^9/L == K/uL == 10^3/uL */ +/* For reference, some common unit conversions: */ +/* 10^9/L == K/uL == 10^3/uL */ WITH blood_diff AS ( SELECT MAX(subject_id) AS subject_id, diff --git a/mimic-iv/concepts_postgres/measurement/chemistry.sql b/mimic-iv/concepts_postgres/measurement/chemistry.sql index e16414217..9d99041b5 100644 --- a/mimic-iv/concepts_postgres/measurement/chemistry.sql +++ b/mimic-iv/concepts_postgres/measurement/chemistry.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.chemistry; CREATE TABLE mimiciv_derived.chemistry AS -/* extract chemistry labs */ /* excludes point of care tests (very rare) */ /* blood gas measurements are *not* included in this query */ /* instead they are in bg.sql */ +/* extract chemistry labs */ +/* excludes point of care tests (very rare) */ +/* blood gas measurements are *not* included in this query */ +/* instead they are in bg.sql */ SELECT MAX(subject_id) AS subject_id, MAX(hadm_id) AS hadm_id, diff --git a/mimic-iv/concepts_postgres/measurement/creatinine_baseline.sql b/mimic-iv/concepts_postgres/measurement/creatinine_baseline.sql index 3f6dfe86f..8e6011b5a 100644 --- a/mimic-iv/concepts_postgres/measurement/creatinine_baseline.sql +++ b/mimic-iv/concepts_postgres/measurement/creatinine_baseline.sql @@ -1,6 +1,15 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.creatinine_baseline; CREATE TABLE mimiciv_derived.creatinine_baseline AS -/* This query extracts the serum creatinine baselines of adult patients */ /* on each hospital admission. */ /* The baseline is determined by the following rules: */ /* i. if the lowest creatinine value during this admission is normal (<1.1), */ /* then use the value */ /* ii. if the patient is diagnosed with chronic kidney disease (CKD), */ /* then use the lowest creatinine value during the admission, */ /* although it may be rather large. */ /* iii. Otherwise, we estimate the baseline using Simplified MDRD: */ /* eGFR = 186 × Scr^(-1.154) × Age^(-0.203) × 0.742Female */ +/* This query extracts the serum creatinine baselines of adult patients */ +/* on each hospital admission. */ +/* The baseline is determined by the following rules: */ +/* i. if the lowest creatinine value during this admission is normal (<1.1), */ +/* then use the value */ +/* ii. if the patient is diagnosed with chronic kidney disease (CKD), */ +/* then use the lowest creatinine value during the admission, */ +/* although it may be rather large. */ +/* iii. Otherwise, we estimate the baseline using Simplified MDRD: */ +/* eGFR = 186 × Scr^(-1.154) × Age^(-0.203) × 0.742Female */ WITH p AS ( SELECT ag.subject_id, diff --git a/mimic-iv/concepts_postgres/measurement/gcs.sql b/mimic-iv/concepts_postgres/measurement/gcs.sql index 5465a4929..ea9f5d1da 100644 --- a/mimic-iv/concepts_postgres/measurement/gcs.sql +++ b/mimic-iv/concepts_postgres/measurement/gcs.sql @@ -1,6 +1,24 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.gcs; CREATE TABLE mimiciv_derived.gcs AS -/* This query extracts the Glasgow Coma Scale, a measure of neurological */ /* function. */ /* The query has a few special rules: */ /* (1) The verbal component can be set to 0 if the patient is ventilated. */ /* This is corrected to 5 - the overall GCS is set to 15 in these cases. */ /* (2) Often only one of three components is documented. The other components */ /* are carried forward. */ /* ITEMIDs used: */ /* METAVISION */ /* 223900 GCS - Verbal Response */ /* 223901 GCS - Motor Response */ /* 220739 GCS - Eye Opening */ /* Note: */ /* The GCS for sedated patients is defaulted to 15 in this code. */ /* This is in line with how the data is meant to be collected. */ /* e.g., from the SAPS II publication: */ /* For sedated patients, the Glasgow Coma Score before sedation was used. */ /* This was ascertained either from interviewing the physician who ordered */ /* the sedation, or by reviewing the patient's medical record. */ +/* This query extracts the Glasgow Coma Scale, a measure of neurological */ +/* function. */ +/* The query has a few special rules: */ +/* (1) The verbal component can be set to 0 if the patient is ventilated. */ +/* This is corrected to 5 - the overall GCS is set to 15 in these cases. */ +/* (2) Often only one of three components is documented. The other components */ +/* are carried forward. */ +/* ITEMIDs used: */ +/* METAVISION */ +/* 223900 GCS - Verbal Response */ +/* 223901 GCS - Motor Response */ +/* 220739 GCS - Eye Opening */ +/* Note: */ +/* The GCS for sedated patients is defaulted to 15 in this code. */ +/* This is in line with how the data is meant to be collected. */ +/* e.g., from the SAPS II publication: */ +/* For sedated patients, the Glasgow Coma Score before sedation was used. */ +/* This was ascertained either from interviewing the physician who ordered */ +/* the sedation, or by reviewing the patient's medical record. */ WITH base AS ( SELECT subject_id, diff --git a/mimic-iv/concepts_postgres/measurement/oxygen_delivery.sql b/mimic-iv/concepts_postgres/measurement/oxygen_delivery.sql index d35942373..735455e71 100644 --- a/mimic-iv/concepts_postgres/measurement/oxygen_delivery.sql +++ b/mimic-iv/concepts_postgres/measurement/oxygen_delivery.sql @@ -33,7 +33,18 @@ WITH ce_stg1 AS ( ) AS rn FROM ce_stg1 AS ce ), o2 AS ( - /* The below ITEMID can have multiple entries for charttime/storetime */ /* These are valid entries, and should be retained in derived tables. */ /* 224181 -- Small Volume Neb Drug #1 | Respiratory | Text */ /* , 227570 -- Small Volume Neb Drug/Dose #1 | Respiratory | Text */ /* , 224833 -- SBT Deferred | Respiratory | Text */ /* , 224716 -- SBT Stopped | Respiratory | Text */ /* , 224740 -- RSBI Deferred | Respiratory | Text */ /* , 224829 -- Trach Tube Type | Respiratory | Text */ /* , 226732 -- O2 Delivery Device(s) | Respiratory | Text */ /* , 226873 -- Inspiratory Ratio | Respiratory | Numeric */ /* , 226871 -- Expiratory Ratio | Respiratory | Numeric */ /* maximum of 4 o2 devices on at once */ + /* The below ITEMID can have multiple entries for charttime/storetime */ + /* These are valid entries, and should be retained in derived tables. */ + /* 224181 -- Small Volume Neb Drug #1 | Respiratory | Text */ + /* , 227570 -- Small Volume Neb Drug/Dose #1 | Respiratory | Text */ + /* , 224833 -- SBT Deferred | Respiratory | Text */ + /* , 224716 -- SBT Stopped | Respiratory | Text */ + /* , 224740 -- RSBI Deferred | Respiratory | Text */ + /* , 224829 -- Trach Tube Type | Respiratory | Text */ + /* , 226732 -- O2 Delivery Device(s) | Respiratory | Text */ + /* , 226873 -- Inspiratory Ratio | Respiratory | Numeric */ + /* , 226871 -- Expiratory Ratio | Respiratory | Numeric */ + /* maximum of 4 o2 devices on at once */ SELECT subject_id, stay_id, diff --git a/mimic-iv/concepts_postgres/measurement/urine_output_rate.sql b/mimic-iv/concepts_postgres/measurement/urine_output_rate.sql index 4cdc9ef7e..dd5796a0c 100644 --- a/mimic-iv/concepts_postgres/measurement/urine_output_rate.sql +++ b/mimic-iv/concepts_postgres/measurement/urine_output_rate.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.urine_output_rate; CREATE TABLE mimiciv_derived.urine_output_rate AS -/* 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 */ +/* 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 */ WITH tm AS ( SELECT ie.stay_id, diff --git a/mimic-iv/concepts_postgres/measurement/vitalsign.sql b/mimic-iv/concepts_postgres/measurement/vitalsign.sql index 4646ccb0c..581327a1c 100644 --- a/mimic-iv/concepts_postgres/measurement/vitalsign.sql +++ b/mimic-iv/concepts_postgres/measurement/vitalsign.sql @@ -1,6 +1,8 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.vitalsign; CREATE TABLE mimiciv_derived.vitalsign AS -/* This query pivots the vital signs for the entire patient stay. */ /* The result is a tabler with stay_id, charttime, and various */ /* vital signs, with one row per charted time. */ +/* This query pivots the vital signs for the entire patient stay. */ +/* The result is a tabler with stay_id, charttime, and various */ +/* vital signs, with one row per charted time. */ SELECT ce.subject_id, ce.stay_id, diff --git a/mimic-iv/concepts_postgres/medication/dobutamine.sql b/mimic-iv/concepts_postgres/medication/dobutamine.sql index 67a891589..50431c199 100644 --- a/mimic-iv/concepts_postgres/medication/dobutamine.sql +++ b/mimic-iv/concepts_postgres/medication/dobutamine.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.dobutamine; CREATE TABLE mimiciv_derived.dobutamine AS -/* This query extracts dose+durations of dobutamine administration */ /* Local hospital dosage guidance: 2 mcg/kg/min (low) - 40 mcg/kg/min (max) */ +/* This query extracts dose+durations of dobutamine administration */ +/* Local hospital dosage guidance: 2 mcg/kg/min (low) - 40 mcg/kg/min (max) */ SELECT stay_id, linkorderid, /* all rows in mcg/kg/min */ diff --git a/mimic-iv/concepts_postgres/medication/dopamine.sql b/mimic-iv/concepts_postgres/medication/dopamine.sql index 63ef1c941..166f2e2d2 100644 --- a/mimic-iv/concepts_postgres/medication/dopamine.sql +++ b/mimic-iv/concepts_postgres/medication/dopamine.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.dopamine; CREATE TABLE mimiciv_derived.dopamine AS -/* This query extracts dose+durations of dopamine administration */ /* Local hospital dosage guidance: 2 mcg/kg/min (low) - 10 mcg/kg/min (high) */ +/* This query extracts dose+durations of dopamine administration */ +/* Local hospital dosage guidance: 2 mcg/kg/min (low) - 10 mcg/kg/min (high) */ SELECT stay_id, linkorderid, /* all rows in mcg/kg/min */ diff --git a/mimic-iv/concepts_postgres/medication/epinephrine.sql b/mimic-iv/concepts_postgres/medication/epinephrine.sql index 91d02facc..209d34bda 100644 --- a/mimic-iv/concepts_postgres/medication/epinephrine.sql +++ b/mimic-iv/concepts_postgres/medication/epinephrine.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.epinephrine; CREATE TABLE mimiciv_derived.epinephrine AS -/* This query extracts dose+durations of epinephrine administration */ /* Local hospital dosage guidance: 0.2 mcg/kg/min (low) - 2 mcg/kg/min (high) */ +/* This query extracts dose+durations of epinephrine administration */ +/* Local hospital dosage guidance: 0.2 mcg/kg/min (low) - 2 mcg/kg/min (high) */ SELECT stay_id, linkorderid, /* all rows in mcg/kg/min */ diff --git a/mimic-iv/concepts_postgres/medication/milrinone.sql b/mimic-iv/concepts_postgres/medication/milrinone.sql index bdb21b562..6804406bb 100644 --- a/mimic-iv/concepts_postgres/medication/milrinone.sql +++ b/mimic-iv/concepts_postgres/medication/milrinone.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.milrinone; CREATE TABLE mimiciv_derived.milrinone AS -/* This query extracts dose+durations of milrinone administration */ /* Local hospital dosage guidance: 0.5 mcg/kg/min (usual) */ +/* This query extracts dose+durations of milrinone administration */ +/* Local hospital dosage guidance: 0.5 mcg/kg/min (usual) */ SELECT stay_id, linkorderid, /* all rows in mcg/kg/min */ diff --git a/mimic-iv/concepts_postgres/medication/norepinephrine.sql b/mimic-iv/concepts_postgres/medication/norepinephrine.sql index 623b6d952..797b863f1 100644 --- a/mimic-iv/concepts_postgres/medication/norepinephrine.sql +++ b/mimic-iv/concepts_postgres/medication/norepinephrine.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.norepinephrine; CREATE TABLE mimiciv_derived.norepinephrine AS -/* This query extracts dose+durations of norepinephrine administration */ /* Local hospital dosage guidance: 0.03 mcg/kg/min (low), 0.5 mcg/kg/min (high) */ +/* This query extracts dose+durations of norepinephrine administration */ +/* Local hospital dosage guidance: 0.03 mcg/kg/min (low), 0.5 mcg/kg/min (high) */ SELECT stay_id, linkorderid, /* two rows in mg/kg/min... rest in mcg/kg/min */ /* the rows in mg/kg/min are documented incorrectly */ /* all rows converted into mcg/kg/min (equiv to ug/kg/min) */ diff --git a/mimic-iv/concepts_postgres/medication/norepinephrine_equivalent_dose.sql b/mimic-iv/concepts_postgres/medication/norepinephrine_equivalent_dose.sql index 883e6d881..b073f8785 100644 --- a/mimic-iv/concepts_postgres/medication/norepinephrine_equivalent_dose.sql +++ b/mimic-iv/concepts_postgres/medication/norepinephrine_equivalent_dose.sql @@ -1,6 +1,16 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.norepinephrine_equivalent_dose; CREATE TABLE mimiciv_derived.norepinephrine_equivalent_dose AS -/* This query calculates norepinephrine equivalent dose for vasopressors. */ /* Based on "Vasopressor dose equivalence: A scoping review and */ /* suggested formula" by Goradia et al. 2020. */ /* The relevant table makes the following equivalences: */ /* Norepinephrine - 1:1 - comparison dose of 0.1 ug/kg/min */ /* Epinephrine - 1:1 [0.7, 1.4] - 0.1 ug/kg/min */ /* Dopamine - 1:100 [75.2, 144.4] - 10 ug/kg/min */ /* Metaraminol - 1:8 [8.3] - 0.8 ug/kg/min */ /* Phenylephrine - 1:10 [1.1, 16.3] - 1 ug/kg/min */ /* Vasopressin - 1:0.4 [0.3, 0.4] - 0.04 units/min */ /* Angiotensin II - 1:0.1 [0.07, 0.13] - 0.01 ug/kg/min */ +/* This query calculates norepinephrine equivalent dose for vasopressors. */ +/* Based on "Vasopressor dose equivalence: A scoping review and */ +/* suggested formula" by Goradia et al. 2020. */ +/* The relevant table makes the following equivalences: */ +/* Norepinephrine - 1:1 - comparison dose of 0.1 ug/kg/min */ +/* Epinephrine - 1:1 [0.7, 1.4] - 0.1 ug/kg/min */ +/* Dopamine - 1:100 [75.2, 144.4] - 10 ug/kg/min */ +/* Metaraminol - 1:8 [8.3] - 0.8 ug/kg/min */ +/* Phenylephrine - 1:10 [1.1, 16.3] - 1 ug/kg/min */ +/* Vasopressin - 1:0.4 [0.3, 0.4] - 0.04 units/min */ +/* Angiotensin II - 1:0.1 [0.07, 0.13] - 0.01 ug/kg/min */ SELECT stay_id, starttime, diff --git a/mimic-iv/concepts_postgres/medication/phenylephrine.sql b/mimic-iv/concepts_postgres/medication/phenylephrine.sql index bd2666520..57e2836ba 100644 --- a/mimic-iv/concepts_postgres/medication/phenylephrine.sql +++ b/mimic-iv/concepts_postgres/medication/phenylephrine.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.phenylephrine; CREATE TABLE mimiciv_derived.phenylephrine AS -/* This query extracts dose+durations of phenylephrine administration */ /* Local hospital dosage guidance: 0.5 mcg/kg/min (low) - 5 mcg/kg/min (high) */ +/* This query extracts dose+durations of phenylephrine administration */ +/* Local hospital dosage guidance: 0.5 mcg/kg/min (low) - 5 mcg/kg/min (high) */ SELECT stay_id, linkorderid, /* one row in mcg/min, the rest in mcg/kg/min */ diff --git a/mimic-iv/concepts_postgres/medication/vasoactive_agent.sql b/mimic-iv/concepts_postgres/medication/vasoactive_agent.sql index a60780efb..9b472a2d8 100644 --- a/mimic-iv/concepts_postgres/medication/vasoactive_agent.sql +++ b/mimic-iv/concepts_postgres/medication/vasoactive_agent.sql @@ -1,6 +1,12 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.vasoactive_agent; CREATE TABLE mimiciv_derived.vasoactive_agent AS -/* This query creates a single table with ongoing doses of vasoactive agents. */ /* TBD: rarely angiotensin II, methylene blue, and */ /* isoprenaline/isoproterenol are used. These are not in the query currently */ /* as they are not documented in MetaVision. However, they could */ /* be documented in other hospital wide systems. */ /* collect all vasopressor administration times */ /* create a single table with these as start/stop times */ +/* This query creates a single table with ongoing doses of vasoactive agents. */ +/* TBD: rarely angiotensin II, methylene blue, and */ +/* isoprenaline/isoproterenol are used. These are not in the query currently */ +/* as they are not documented in MetaVision. However, they could */ +/* be documented in other hospital wide systems. */ +/* collect all vasopressor administration times */ +/* create a single table with these as start/stop times */ WITH tm AS ( SELECT stay_id, @@ -91,7 +97,9 @@ SELECT vas.vaso_rate AS vasopressin, /* units/hour */ /* inodialators */ dob.vaso_rate AS dobutamine, /* mcg/kg/min */ mil.vaso_rate AS milrinone /* mcg/kg/min */ -/* 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 */ +/* 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 @@ -121,6 +129,7 @@ LEFT JOIN mimiciv_derived.milrinone AS mil 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 */ +/* remove the final row for each stay_id */ +/* it will not have any infusions associated with it */ WHERE NOT t.endtime IS NULL \ No newline at end of file diff --git a/mimic-iv/concepts_postgres/medication/vasopressin.sql b/mimic-iv/concepts_postgres/medication/vasopressin.sql index a0a1d13f8..089e32093 100644 --- a/mimic-iv/concepts_postgres/medication/vasopressin.sql +++ b/mimic-iv/concepts_postgres/medication/vasopressin.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.vasopressin; CREATE TABLE mimiciv_derived.vasopressin AS -/* This query extracts dose+durations of vasopressin administration */ /* Local hospital dosage guidance: 1.2 units/hour (low) - 2.4 units/hour (high) */ +/* This query extracts dose+durations of vasopressin administration */ +/* Local hospital dosage guidance: 1.2 units/hour (low) - 2.4 units/hour (high) */ SELECT stay_id, linkorderid, /* three rows in units/min, rest in units/hour */ /* the three rows in units/min look reasonable and */ /* fit with the patient course */ /* convert all rows to units/hour */ diff --git a/mimic-iv/concepts_postgres/organfailure/kdigo_stages.sql b/mimic-iv/concepts_postgres/organfailure/kdigo_stages.sql index 3946bccfb..42415cea9 100644 --- a/mimic-iv/concepts_postgres/organfailure/kdigo_stages.sql +++ b/mimic-iv/concepts_postgres/organfailure/kdigo_stages.sql @@ -1,6 +1,9 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.kdigo_stages; CREATE TABLE mimiciv_derived.kdigo_stages AS -/* This query checks if the patient had AKI according to KDIGO. */ /* AKI is calculated every time a creatinine or urine output measurement occurs. */ /* Baseline creatinine is defined as the lowest creatinine in the past 7 days. */ /* get creatinine stages */ +/* This query checks if the patient had AKI according to KDIGO. */ +/* AKI is calculated every time a creatinine or urine output measurement occurs. */ +/* Baseline creatinine is defined as the lowest creatinine in the past 7 days. */ +/* get creatinine stages */ WITH cr_stg AS ( SELECT cr.stay_id, diff --git a/mimic-iv/concepts_postgres/organfailure/meld.sql b/mimic-iv/concepts_postgres/organfailure/meld.sql index f6c28ebba..ca81a616f 100644 --- a/mimic-iv/concepts_postgres/organfailure/meld.sql +++ b/mimic-iv/concepts_postgres/organfailure/meld.sql @@ -1,6 +1,49 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.meld; CREATE TABLE mimiciv_derived.meld AS -/* Model for end-stage liver disease (MELD) */ /* This model is used to determine prognosis and receipt of */ /* liver transplantation. */ /* Reference: */ /* Kamath PS, Wiesner RH, Malinchoc M, Kremers W, Therneau TM, */ /* Kosberg CL, D'Amico G, Dickson ER, Kim WR. */ /* A model to predict survival in patients with end-stage liver disease. */ /* Hepatology. 2001 Feb;33(2):464-70. */ /* Updated January 2016 to include serum sodium, see: */ /* https://optn.transplant.hrsa.gov/news/meld-serum-sodium-policy-changes/ */ /* Here is the relevant portion of the policy note: */ /* 9.1.D MELD Score */ /* Candidates who are at least 12 years old receive an initial MELD(i) score */ /* equal to: */ /* 0.957 x ln(creatinine mg/dL) */ /* + 0.378 x ln(bilirubin mg/dL) */ /* + 1.120 x ln(INR) */ /* + 0.643 */ /* Laboratory values less than 1.0 will be set to 1.0 when calculating a */ /* candidate’s MELD score. */ /* The following candidates will receive a creatinine value of 4.0 mg/dL: */ /* - Candidates with a creatinine value greater than 4.0 mg/dL */ /* - Candidates who received two or more dialysis treatments within */ /* the prior week */ /* - Candidates who received 24 hours of continuous veno-venous hemodialysis */ /* (CVVHD) within the prior week */ /* The maximum MELD score is 40. The MELD score derived from this calculation */ /* will be rounded to the tenth decimal place and then multiplied by 10. */ /* For candidates with an initial MELD score greater than 11, The MELD score */ /* is then recalculated as follows: */ /* MELD = MELD(i) + 1.32*(137-Na) – [0.033*MELD(i)*(137-Na)] */ /* Sodium values less than 125 mmol/L will be set to 125, and values greater */ /* than 137 mmol/L will be set to 137. */ /* TODO needed in this code: */ /* 1. identify 2x dialysis in the past week, or 24 hours of CVVH */ /* at the moment it just checks for any dialysis on the first day */ /* 2. identify cholestatic or alcoholic liver disease */ /* 0.957 x ln(creatinine mg/dL) */ /* + 0.378 x ln(bilirubin mg/dL) */ /* + 1.120 x ln(INR) */ /* + 0.643 x etiology */ /* (0 if cholestatic or alcoholic, 1 otherwise) */ /* 3. adjust the serum sodium using the corresponding glucose measurement */ /* Measured sodium + 0.024 * (Serum glucose - 100) (Hiller, 1999) */ +/* Model for end-stage liver disease (MELD) */ +/* This model is used to determine prognosis and receipt of */ +/* liver transplantation. */ +/* Reference: */ +/* Kamath PS, Wiesner RH, Malinchoc M, Kremers W, Therneau TM, */ +/* Kosberg CL, D'Amico G, Dickson ER, Kim WR. */ +/* A model to predict survival in patients with end-stage liver disease. */ +/* Hepatology. 2001 Feb;33(2):464-70. */ +/* Updated January 2016 to include serum sodium, see: */ +/* https://optn.transplant.hrsa.gov/news/meld-serum-sodium-policy-changes/ */ +/* Here is the relevant portion of the policy note: */ +/* 9.1.D MELD Score */ +/* Candidates who are at least 12 years old receive an initial MELD(i) score */ +/* equal to: */ +/* 0.957 x ln(creatinine mg/dL) */ +/* + 0.378 x ln(bilirubin mg/dL) */ +/* + 1.120 x ln(INR) */ +/* + 0.643 */ +/* Laboratory values less than 1.0 will be set to 1.0 when calculating a */ +/* candidate’s MELD score. */ +/* The following candidates will receive a creatinine value of 4.0 mg/dL: */ +/* - Candidates with a creatinine value greater than 4.0 mg/dL */ +/* - Candidates who received two or more dialysis treatments within */ +/* the prior week */ +/* - Candidates who received 24 hours of continuous veno-venous hemodialysis */ +/* (CVVHD) within the prior week */ +/* The maximum MELD score is 40. The MELD score derived from this calculation */ +/* will be rounded to the tenth decimal place and then multiplied by 10. */ +/* For candidates with an initial MELD score greater than 11, The MELD score */ +/* is then recalculated as follows: */ +/* MELD = MELD(i) + 1.32*(137-Na) – [0.033*MELD(i)*(137-Na)] */ +/* Sodium values less than 125 mmol/L will be set to 125, and values greater */ +/* than 137 mmol/L will be set to 137. */ +/* TODO needed in this code: */ +/* 1. identify 2x dialysis in the past week, or 24 hours of CVVH */ +/* at the moment it just checks for any dialysis on the first day */ +/* 2. identify cholestatic or alcoholic liver disease */ +/* 0.957 x ln(creatinine mg/dL) */ +/* + 0.378 x ln(bilirubin mg/dL) */ +/* + 1.120 x ln(INR) */ +/* + 0.643 x etiology */ +/* (0 if cholestatic or alcoholic, 1 otherwise) */ +/* 3. adjust the serum sodium using the corresponding glucose measurement */ +/* Measured sodium + 0.024 * (Serum glucose - 100) (Hiller, 1999) */ WITH cohort AS ( SELECT ie.subject_id, diff --git a/mimic-iv/concepts_postgres/score/apsiii.sql b/mimic-iv/concepts_postgres/score/apsiii.sql index 1cb11ade4..3637ce319 100644 --- a/mimic-iv/concepts_postgres/score/apsiii.sql +++ b/mimic-iv/concepts_postgres/score/apsiii.sql @@ -1,6 +1,33 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.apsiii; CREATE TABLE mimiciv_derived.apsiii AS -/* ------------------------------------------------------------------ */ /* Title: Acute Physiology Score III (APS III) */ /* This query extracts the acute physiology score III. */ /* This score is a measure of patient severity of illness. */ /* The score is calculated on the first day of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for APS III: */ /* Knaus WA, Wagner DP, Draper EA, Zimmerman JE, Bergner M, */ /* Bastos PG, Sirio CA, Murphy DJ, Lotring T, Damiano A. */ /* The APACHE III prognostic system. Risk prediction of hospital */ /* mortality for critically ill hospitalized adults. Chest Journal. */ /* 1991 Dec 1;100(6):1619-36. */ /* Reference for the equation for calibrating APS III: */ /* Johnson, A. E. W. (2015). Mortality prediction and acuity assessment */ /* in critical care. University of Oxford, Oxford, UK. */ /* Variables used in APS III: */ /* GCS */ /* VITALS: Heart rate, mean blood pressure, temperature, respiration rate */ /* FLAGS: ventilation/cpap, chronic dialysis */ /* IO: urine output */ /* LABS: pao2, A-aDO2, hematocrit, WBC, creatinine */ /* , blood urea nitrogen, sodium, albumin, bilirubin, glucose, pH, pCO2 */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption that */ /* the user will subselect appropriate stay_ids. */ /* List of TODO: */ /* The site of temperature is not incorporated. Axillary measurements */ /* should be increased by 1 degree. */ +/* ------------------------------------------------------------------ */ +/* Title: Acute Physiology Score III (APS III) */ +/* This query extracts the acute physiology score III. */ +/* This score is a measure of patient severity of illness. */ +/* The score is calculated on the first day of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for APS III: */ +/* Knaus WA, Wagner DP, Draper EA, Zimmerman JE, Bergner M, */ +/* Bastos PG, Sirio CA, Murphy DJ, Lotring T, Damiano A. */ +/* The APACHE III prognostic system. Risk prediction of hospital */ +/* mortality for critically ill hospitalized adults. Chest Journal. */ +/* 1991 Dec 1;100(6):1619-36. */ +/* Reference for the equation for calibrating APS III: */ +/* Johnson, A. E. W. (2015). Mortality prediction and acuity assessment */ +/* in critical care. University of Oxford, Oxford, UK. */ +/* Variables used in APS III: */ +/* GCS */ +/* VITALS: Heart rate, mean blood pressure, temperature, respiration rate */ +/* FLAGS: ventilation/cpap, chronic dialysis */ +/* IO: urine output */ +/* LABS: pao2, A-aDO2, hematocrit, WBC, creatinine */ +/* , blood urea nitrogen, sodium, albumin, bilirubin, glucose, pH, pCO2 */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption that */ +/* the user will subselect appropriate stay_ids. */ +/* List of TODO: */ +/* The site of temperature is not incorporated. Axillary measurements */ +/* should be increased by 1 degree. */ WITH pa AS ( SELECT ie.stay_id, @@ -23,7 +50,8 @@ WITH pa AS ( AND NOT bg.po2 IS NULL AND bg.specimen = 'ART.' ), aa AS ( - /* join blood gas to ventilation durations to determine if patient was vent */ /* also join to cpap table for the same purpose */ + /* join blood gas to ventilation durations to determine if patient was vent */ + /* also join to cpap table for the same purpose */ SELECT ie.stay_id, bg.charttime, diff --git a/mimic-iv/concepts_postgres/score/lods.sql b/mimic-iv/concepts_postgres/score/lods.sql index edaa0c740..7713b4e29 100644 --- a/mimic-iv/concepts_postgres/score/lods.sql +++ b/mimic-iv/concepts_postgres/score/lods.sql @@ -1,6 +1,28 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.lods; CREATE TABLE mimiciv_derived.lods AS -/* ------------------------------------------------------------------ */ /* Title: Logistic Organ Dysfunction Score (LODS) */ /* This query extracts the logistic organ dysfunction system. */ /* This score is a measure of organ failure in a patient. */ /* The score is calculated on the first day of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for LODS: */ /* Le Gall, J. R., Klar, J., Lemeshow, S., Saulnier, F., Alberti, C., */ /* Artigas, A., & Teres, D. */ /* The Logistic Organ Dysfunction system: a new way to assess organ */ /* dysfunction in the intensive care unit. JAMA 276.10 (1996): 802-810. */ /* Variables used in LODS: */ /* GCS */ /* VITALS: Heart rate, systolic blood pressure */ /* FLAGS: ventilation/cpap */ /* IO: urine output */ /* LABS: blood urea nitrogen, WBC, bilirubin, creatinine, */ /* prothrombin time (PT), platelets */ /* ABG: PaO2 with associated FiO2 */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption */ /* that the user will subselect appropriate stay_ids. */ /* extract CPAP from the "Oxygen Delivery Device" fields */ +/* ------------------------------------------------------------------ */ +/* Title: Logistic Organ Dysfunction Score (LODS) */ +/* This query extracts the logistic organ dysfunction system. */ +/* This score is a measure of organ failure in a patient. */ +/* The score is calculated on the first day of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for LODS: */ +/* Le Gall, J. R., Klar, J., Lemeshow, S., Saulnier, F., Alberti, C., */ +/* Artigas, A., & Teres, D. */ +/* The Logistic Organ Dysfunction system: a new way to assess organ */ +/* dysfunction in the intensive care unit. JAMA 276.10 (1996): 802-810. */ +/* Variables used in LODS: */ +/* GCS */ +/* VITALS: Heart rate, systolic blood pressure */ +/* FLAGS: ventilation/cpap */ +/* IO: urine output */ +/* LABS: blood urea nitrogen, WBC, bilirubin, creatinine, */ +/* prothrombin time (PT), platelets */ +/* ABG: PaO2 with associated FiO2 */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption */ +/* that the user will subselect appropriate stay_ids. */ +/* extract CPAP from the "Oxygen Delivery Device" fields */ WITH cpap AS ( SELECT ie.stay_id, @@ -28,7 +50,8 @@ WITH cpap AS ( GROUP BY ie.stay_id ), pafi1 AS ( - /* join blood gas to ventilation durations to determine if patient was vent */ /* also join to cpap table for the same purpose */ + /* join blood gas to ventilation durations to determine if patient was vent */ + /* also join to cpap table for the same purpose */ SELECT ie.stay_id, bg.charttime, diff --git a/mimic-iv/concepts_postgres/score/oasis.sql b/mimic-iv/concepts_postgres/score/oasis.sql index e1e680f62..741d2db81 100644 --- a/mimic-iv/concepts_postgres/score/oasis.sql +++ b/mimic-iv/concepts_postgres/score/oasis.sql @@ -1,6 +1,30 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.oasis; CREATE TABLE mimiciv_derived.oasis AS -/* ------------------------------------------------------------------ */ /* Title: Oxford Acute Severity of Illness Score (oasis) */ /* This query extracts the Oxford acute severity of illness score. */ /* This score is a measure of severity of illness for patients in the ICU. */ /* The score is calculated on the first day of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for OASIS: */ /* Johnson, Alistair EW, Andrew A. Kramer, and Gari D. Clifford. */ /* A new severity of illness scale using a subset of acute physiology */ /* and chronic health evaluation data elements shows comparable */ /* predictive accuracy*. */ /* Critical care medicine 41, no. 7 (2013): 1711-1718. */ /* Variables used in OASIS: */ /* Heart rate, GCS, MAP, Temperature, Respiratory rate, Ventilation status */ /* (from chartevents) */ /* Urine output (from outputevents) */ /* Elective surgery (from admissions and services) */ /* Pre-ICU in-hospital length of stay (from admissions and icustays) */ /* Age (from patients) */ /* Regarding missing values: */ /* The ventilation flag is always 0/1. It cannot be missing, */ /* since VENT=0 if no data is found for vent settings. */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption */ /* that the user will subselect appropriate stay_ids. */ +/* ------------------------------------------------------------------ */ +/* Title: Oxford Acute Severity of Illness Score (oasis) */ +/* This query extracts the Oxford acute severity of illness score. */ +/* This score is a measure of severity of illness for patients in the ICU. */ +/* The score is calculated on the first day of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for OASIS: */ +/* Johnson, Alistair EW, Andrew A. Kramer, and Gari D. Clifford. */ +/* A new severity of illness scale using a subset of acute physiology */ +/* and chronic health evaluation data elements shows comparable */ +/* predictive accuracy*. */ +/* Critical care medicine 41, no. 7 (2013): 1711-1718. */ +/* Variables used in OASIS: */ +/* Heart rate, GCS, MAP, Temperature, Respiratory rate, Ventilation status */ +/* (from chartevents) */ +/* Urine output (from outputevents) */ +/* Elective surgery (from admissions and services) */ +/* Pre-ICU in-hospital length of stay (from admissions and icustays) */ +/* Age (from patients) */ +/* Regarding missing values: */ +/* The ventilation flag is always 0/1. It cannot be missing, */ +/* since VENT=0 if no data is found for vent settings. */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption */ +/* that the user will subselect appropriate stay_ids. */ WITH surgflag AS ( SELECT ie.stay_id, diff --git a/mimic-iv/concepts_postgres/score/sapsii.sql b/mimic-iv/concepts_postgres/score/sapsii.sql index 3daf37946..ea43474d1 100644 --- a/mimic-iv/concepts_postgres/score/sapsii.sql +++ b/mimic-iv/concepts_postgres/score/sapsii.sql @@ -1,6 +1,23 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.sapsii; CREATE TABLE mimiciv_derived.sapsii AS -/* ------------------------------------------------------------------ */ /* Title: Simplified Acute Physiology Score II (SAPS II) */ /* This query extracts the simplified acute physiology score II. */ /* This score is a measure of patient severity of illness. */ /* The score is calculated on the first day of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for SAPS II: */ /* Le Gall, Jean-Roger, Stanley Lemeshow, and Fabienne Saulnier. */ /* "A new simplified acute physiology score (SAPS II) based on */ /* a European/North American multicenter study." */ /* JAMA 270, no. 24 (1993): 2957-2963. */ /* Variables used in SAPS II: */ /* Age, GCS */ /* VITALS: Heart rate, systolic blood pressure, temperature */ /* FLAGS: ventilation/cpap */ /* IO: urine output */ /* LABS: PaO2/FiO2 ratio, blood urea nitrogen, WBC, */ /* potassium, sodium, HCO3 */ +/* ------------------------------------------------------------------ */ +/* Title: Simplified Acute Physiology Score II (SAPS II) */ +/* This query extracts the simplified acute physiology score II. */ +/* This score is a measure of patient severity of illness. */ +/* The score is calculated on the first day of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for SAPS II: */ +/* Le Gall, Jean-Roger, Stanley Lemeshow, and Fabienne Saulnier. */ +/* "A new simplified acute physiology score (SAPS II) based on */ +/* a European/North American multicenter study." */ +/* JAMA 270, no. 24 (1993): 2957-2963. */ +/* Variables used in SAPS II: */ +/* Age, GCS */ +/* VITALS: Heart rate, systolic blood pressure, temperature */ +/* FLAGS: ventilation/cpap */ +/* IO: urine output */ +/* LABS: PaO2/FiO2 ratio, blood urea nitrogen, WBC, */ +/* potassium, sodium, HCO3 */ WITH co AS ( SELECT subject_id, @@ -102,7 +119,8 @@ WITH co AS ( GROUP BY hadm_id ), pafi1 AS ( - /* join blood gas to ventilation durations to determine if patient was vent */ /* also join to cpap table for the same purpose */ + /* join blood gas to ventilation durations to determine if patient was vent */ + /* also join to cpap table for the same purpose */ SELECT co.stay_id, bg.charttime, diff --git a/mimic-iv/concepts_postgres/score/sirs.sql b/mimic-iv/concepts_postgres/score/sirs.sql index af10c4913..6b8faa434 100644 --- a/mimic-iv/concepts_postgres/score/sirs.sql +++ b/mimic-iv/concepts_postgres/score/sirs.sql @@ -1,6 +1,29 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.sirs; CREATE TABLE mimiciv_derived.sirs AS -/* ------------------------------------------------------------------ */ /* Title: Systemic inflammatory response syndrome (SIRS) criteria */ /* This query extracts the Systemic inflammatory response syndrome */ /* (SIRS) criteria. The criteria quantify the level of inflammatory */ /* response of the body. The score is calculated on the first day */ /* of each ICU patients' stay. */ /* ------------------------------------------------------------------ */ /* Reference for SIRS: */ /* American College of Chest Physicians/Society of Critical Care */ /* Medicine Consensus Conference: definitions for sepsis and organ */ /* failure and guidelines for the use of innovative therapies in */ /* sepsis". Crit. Care Med. 20 (6): 864–74. 1992. */ /* doi:10.1097/00003246-199206000-00025. PMID 1597042. */ /* Variables used in SIRS: */ /* Body temperature (min and max) */ /* Heart rate (max) */ /* Respiratory rate (max) */ /* PaCO2 (min) */ /* White blood cell count (min and max) */ /* the presence of greater than 10% immature neutrophils (band forms) */ /* Note: */ /* The score is calculated for *all* ICU patients, with the assumption */ /* that the user will subselect appropriate stay_ids. */ /* Aggregate the components for the score */ +/* ------------------------------------------------------------------ */ +/* Title: Systemic inflammatory response syndrome (SIRS) criteria */ +/* This query extracts the Systemic inflammatory response syndrome */ +/* (SIRS) criteria. The criteria quantify the level of inflammatory */ +/* response of the body. The score is calculated on the first day */ +/* of each ICU patients' stay. */ +/* ------------------------------------------------------------------ */ +/* Reference for SIRS: */ +/* American College of Chest Physicians/Society of Critical Care */ +/* Medicine Consensus Conference: definitions for sepsis and organ */ +/* failure and guidelines for the use of innovative therapies in */ +/* sepsis". Crit. Care Med. 20 (6): 864–74. 1992. */ +/* doi:10.1097/00003246-199206000-00025. PMID 1597042. */ +/* Variables used in SIRS: */ +/* Body temperature (min and max) */ +/* Heart rate (max) */ +/* Respiratory rate (max) */ +/* PaCO2 (min) */ +/* White blood cell count (min and max) */ +/* the presence of greater than 10% immature neutrophils (band forms) */ +/* Note: */ +/* The score is calculated for *all* ICU patients, with the assumption */ +/* that the user will subselect appropriate stay_ids. */ +/* Aggregate the components for the score */ WITH scorecomp AS ( SELECT ie.stay_id, @@ -20,7 +43,10 @@ WITH scorecomp AS ( LEFT JOIN mimiciv_derived.first_day_lab AS l ON ie.stay_id = l.stay_id ), scorecalc AS ( - /* Calculate the final score */ /* note that if the underlying data is missing, the component is null */ /* eventually these are treated as 0 (normal), but knowing when */ /* data is missing is useful for debugging */ + /* Calculate the final score */ + /* note that if the underlying data is missing, the component is null */ + /* eventually these are treated as 0 (normal), but knowing when */ + /* data is missing is useful for debugging */ SELECT stay_id, CASE diff --git a/mimic-iv/concepts_postgres/score/sofa.sql b/mimic-iv/concepts_postgres/score/sofa.sql index d59a51739..6d6a2c69a 100644 --- a/mimic-iv/concepts_postgres/score/sofa.sql +++ b/mimic-iv/concepts_postgres/score/sofa.sql @@ -1,6 +1,30 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.sofa; CREATE TABLE mimiciv_derived.sofa AS -/* ------------------------------------------------------------------ */ /* Title: Sequential Organ Failure Assessment (SOFA) */ /* This query extracts the sequential organ failure assessment */ /* (formally: sepsis-related organ failure assessment). */ /* This score is a measure of organ failure for patients in the ICU. */ /* The score is calculated for **every hour** of the patient's ICU stay. */ /* However, as the calculation window is 24 hours, care should be */ /* taken when using the score before the end of the first day, */ /* as the data window is limited. */ /* ------------------------------------------------------------------ */ /* Reference for SOFA: */ /* Jean-Louis Vincent, Rui Moreno, Jukka Takala, Sheila Willatts, */ /* Arnaldo De Mendonça, Hajo Bruining, C. K. Reinhart, */ /* Peter M Suter, and L. G. Thijs. */ /* "The SOFA (Sepsis-related Organ Failure Assessment) score to */ /* describe organ dysfunction/failure." */ /* Intensive care medicine 22, no. 7 (1996): 707-710. */ /* Variables used in SOFA: */ /* GCS, MAP, FiO2, Ventilation status (chartevents) */ /* Creatinine, Bilirubin, FiO2, PaO2, Platelets (labevents) */ /* Dopamine, Dobutamine, Epinephrine, Norepinephrine (inputevents) */ /* Urine output (outputevents) */ /* use icustay_hourly to get a row for every hour the patient was in the ICU */ /* all of our joins to data will use these times */ /* to extract data pertinent to only that hour */ +/* ------------------------------------------------------------------ */ +/* Title: Sequential Organ Failure Assessment (SOFA) */ +/* This query extracts the sequential organ failure assessment */ +/* (formally: sepsis-related organ failure assessment). */ +/* This score is a measure of organ failure for patients in the ICU. */ +/* The score is calculated for **every hour** of the patient's ICU stay. */ +/* However, as the calculation window is 24 hours, care should be */ +/* taken when using the score before the end of the first day, */ +/* as the data window is limited. */ +/* ------------------------------------------------------------------ */ +/* Reference for SOFA: */ +/* Jean-Louis Vincent, Rui Moreno, Jukka Takala, Sheila Willatts, */ +/* Arnaldo De Mendonça, Hajo Bruining, C. K. Reinhart, */ +/* Peter M Suter, and L. G. Thijs. */ +/* "The SOFA (Sepsis-related Organ Failure Assessment) score to */ +/* describe organ dysfunction/failure." */ +/* Intensive care medicine 22, no. 7 (1996): 707-710. */ +/* Variables used in SOFA: */ +/* GCS, MAP, FiO2, Ventilation status (chartevents) */ +/* Creatinine, Bilirubin, FiO2, PaO2, Platelets (labevents) */ +/* Dopamine, Dobutamine, Epinephrine, Norepinephrine (inputevents) */ +/* Urine output (outputevents) */ +/* use icustay_hourly to get a row for every hour the patient was in the ICU */ +/* all of our joins to data will use these times */ +/* to extract data pertinent to only that hour */ WITH co AS ( SELECT ih.stay_id, @@ -195,7 +219,11 @@ WITH co AS ( LEFT JOIN vaso ON co.stay_id = vaso.stay_id AND co.hr = vaso.hr ), scorecalc AS ( - /* Calculate the final score */ /* note that if the underlying data is missing, */ /* the component is null */ /* eventually these are treated as 0 (normal), */ /* but knowing when data is missing is useful for debugging */ + /* Calculate the final score */ + /* note that if the underlying data is missing, */ + /* the component is null */ + /* eventually these are treated as 0 (normal), */ + /* but knowing when data is missing is useful for debugging */ SELECT scorecomp.*, /* Respiration */ CASE diff --git a/mimic-iv/concepts_postgres/sepsis/sepsis3.sql b/mimic-iv/concepts_postgres/sepsis/sepsis3.sql index 6d2a25634..a4705acf2 100644 --- a/mimic-iv/concepts_postgres/sepsis/sepsis3.sql +++ b/mimic-iv/concepts_postgres/sepsis/sepsis3.sql @@ -1,6 +1,12 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.sepsis3; CREATE TABLE mimiciv_derived.sepsis3 AS -/* Creates a table with "onset" time of Sepsis-3 in the ICU. */ /* That is, the earliest time at which a patient had SOFA >= 2 */ /* and suspicion of infection. */ /* As many variables used in SOFA are only collected in the ICU, */ /* this query can only define sepsis-3 onset within the ICU. */ /* extract rows with SOFA >= 2 */ /* implicitly this assumes baseline SOFA was 0 before ICU admission. */ +/* Creates a table with "onset" time of Sepsis-3 in the ICU. */ +/* That is, the earliest time at which a patient had SOFA >= 2 */ +/* and suspicion of infection. */ +/* As many variables used in SOFA are only collected in the ICU, */ +/* this query can only define sepsis-3 onset within the ICU. */ +/* extract rows with SOFA >= 2 */ +/* implicitly this assumes baseline SOFA was 0 before ICU admission. */ WITH sofa AS ( SELECT stay_id, diff --git a/mimic-iv/concepts_postgres/sepsis/suspicion_of_infection.sql b/mimic-iv/concepts_postgres/sepsis/suspicion_of_infection.sql index d60e1f6d8..ae95ba81d 100644 --- a/mimic-iv/concepts_postgres/sepsis/suspicion_of_infection.sql +++ b/mimic-iv/concepts_postgres/sepsis/suspicion_of_infection.sql @@ -1,6 +1,8 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.suspicion_of_infection; CREATE TABLE mimiciv_derived.suspicion_of_infection AS -/* note this duplicates prescriptions */ /* each ICU stay in the same hospitalization will get a copy of */ /* all prescriptions for that hospitalization */ +/* note this duplicates prescriptions */ +/* each ICU stay in the same hospitalization will get a copy of */ +/* all prescriptions for that hospitalization */ WITH ab_tbl AS ( SELECT abx.subject_id, @@ -22,7 +24,7 @@ WITH ab_tbl AS ( MAX(hadm_id) AS hadm_id, CAST(MAX(chartdate) AS DATE) AS chartdate, MAX(charttime) AS charttime, - MAX(spec_type_desc) AS spec_type_desc, /* non-positive: NULL/empty, NEGATIVE (90856), CANCELLED (90760) */ + MAX(spec_type_desc) AS spec_type_desc, /* non-positive: NULL/empty organism, NEGATIVE (90856), */ /* or CANCELLED culture (90760) — cancelled is not growth */ MAX( CASE WHEN NOT org_name IS NULL diff --git a/mimic-iv/concepts_postgres/treatment/code_status.sql b/mimic-iv/concepts_postgres/treatment/code_status.sql index 70c08448c..ef8f68e9c 100644 --- a/mimic-iv/concepts_postgres/treatment/code_status.sql +++ b/mimic-iv/concepts_postgres/treatment/code_status.sql @@ -1,6 +1,7 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.code_status; CREATE TABLE mimiciv_derived.code_status AS -/* This query extracts code status with the time at which the */ /* code status was documented. */ +/* This query extracts code status with the time at which the */ +/* code status was documented. */ WITH t1 AS ( /* There are five distinct values for the code status order in the ICU data: @@ -51,7 +52,8 @@ There are five distinct values for the code status order in the ICU data: WHERE p.order_type = 'General Care' AND order_subtype = 'Code status' ) -/* Merge together code status from ICU data */ /* with code status from provider order entry */ +/* Merge together code status from ICU data */ +/* with code status from provider order entry */ SELECT t1.subject_id, t1.hadm_id, diff --git a/mimic-iv/concepts_postgres/treatment/crrt.sql b/mimic-iv/concepts_postgres/treatment/crrt.sql index 3743df14f..2f04da025 100644 --- a/mimic-iv/concepts_postgres/treatment/crrt.sql +++ b/mimic-iv/concepts_postgres/treatment/crrt.sql @@ -68,7 +68,8 @@ WITH crrt_settings AS ( ) AND NOT ce.value IS NULL ) -/* use MAX() to collapse to a single row */ /* there is only ever 1 row for unique combinations of stay_id/charttime/itemid */ +/* use MAX() to collapse to a single row */ +/* there is only ever 1 row for unique combinations of stay_id/charttime/itemid */ SELECT stay_id, charttime, diff --git a/mimic-iv/concepts_postgres/treatment/rrt.sql b/mimic-iv/concepts_postgres/treatment/rrt.sql index 9993ea980..83e8bf420 100644 --- a/mimic-iv/concepts_postgres/treatment/rrt.sql +++ b/mimic-iv/concepts_postgres/treatment/rrt.sql @@ -225,7 +225,11 @@ WITH ce AS ( WHERE dialysis_present = 1 UNION - /* SELECT */ /* stay_id, charttime, dialysis_present, dialysis_active, dialysis_type */ /* FROM oe */ /* WHERE dialysis_present = 1 */ /* UNION DISTINCT */ + /* SELECT */ + /* stay_id, charttime, dialysis_present, dialysis_active, dialysis_type */ + /* FROM oe */ + /* WHERE dialysis_present = 1 */ + /* UNION DISTINCT */ SELECT stay_id, starttime AS charttime, diff --git a/mimic-iv/concepts_postgres/treatment/ventilation.sql b/mimic-iv/concepts_postgres/treatment/ventilation.sql index e8034fa6a..fd4e4c8c2 100644 --- a/mimic-iv/concepts_postgres/treatment/ventilation.sql +++ b/mimic-iv/concepts_postgres/treatment/ventilation.sql @@ -1,6 +1,24 @@ -- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY. DROP TABLE IF EXISTS mimiciv_derived.ventilation; CREATE TABLE mimiciv_derived.ventilation AS -/* Classify oxygen devices and ventilator modes into six clinical categories. */ /* Categories include.. */ /* Invasive oxygen delivery types: */ /* Tracheostomy (with or without positive pressure ventilation) */ /* InvasiveVent (positive pressure ventilation via endotracheal tube, */ /* could be oro/nasotracheal or tracheostomy) */ /* Non invasive oxygen delivery types (ref doi:10.1001/jama.2020.9524): */ /* NonInvasiveVent (non-invasive positive pressure ventilation) */ /* HFNC (high flow nasal oxygen / cannula) */ /* SupplementalOxygen (all other non-rebreather, */ /* facemask, face tent, nasal prongs...) */ /* No oxygen device: */ /* None */ /* When conflicting settings occur (rare), the priority is: */ /* trach > mech vent > NIV > high flow > o2 */ /* Some useful cases for debugging: */ /* stay_id = 30019660 has a tracheostomy placed in the ICU */ /* stay_id = 30000117 has explicit documentation of extubation */ /* first we collect all times which have relevant documentation */ +/* Classify oxygen devices and ventilator modes into six clinical categories. */ +/* Categories include.. */ +/* Invasive oxygen delivery types: */ +/* Tracheostomy (with or without positive pressure ventilation) */ +/* InvasiveVent (positive pressure ventilation via endotracheal tube, */ +/* could be oro/nasotracheal or tracheostomy) */ +/* Non invasive oxygen delivery types (ref doi:10.1001/jama.2020.9524): */ +/* NonInvasiveVent (non-invasive positive pressure ventilation) */ +/* HFNC (high flow nasal oxygen / cannula) */ +/* SupplementalOxygen (all other non-rebreather, */ +/* facemask, face tent, nasal prongs...) */ +/* No oxygen device: */ +/* None */ +/* When conflicting settings occur (rare), the priority is: */ +/* trach > mech vent > NIV > high flow > o2 */ +/* Some useful cases for debugging: */ +/* stay_id = 30019660 has a tracheostomy placed in the ICU */ +/* stay_id = 30000117 has explicit documentation of extubation */ +/* first we collect all times which have relevant documentation */ WITH tm AS ( SELECT stay_id,