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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mimic-iii/concepts_postgres/code_status.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
DROP TABLE IF EXISTS mimiciii_derived.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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 14 additions & 2 deletions mimic-iii/concepts_postgres/comorbidity/elixhauser_quan.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
8 changes: 7 additions & 1 deletion mimic-iii/concepts_postgres/demographics/heightweight.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
9 changes: 8 additions & 1 deletion mimic-iii/concepts_postgres/demographics/icustay_detail.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 7 additions & 1 deletion mimic-iii/concepts_postgres/demographics/icustay_hours.sql
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion mimic-iii/concepts_postgres/demographics/icustay_times.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 4 additions & 1 deletion mimic-iii/concepts_postgres/diagnosis/ccs_dx.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
DROP TABLE IF EXISTS mimiciii_derived.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" */
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 3 additions & 1 deletion mimic-iii/concepts_postgres/durations/crrt_durations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 4 additions & 2 deletions mimic-iii/concepts_postgres/durations/dobutamine_dose.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
DROP TABLE IF EXISTS mimiciii_derived.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,
Expand Down
6 changes: 4 additions & 2 deletions mimic-iii/concepts_postgres/durations/dopamine_dose.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion mimic-iii/concepts_postgres/durations/dopamine_durations.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
DROP TABLE IF EXISTS mimiciii_derived.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,
Expand Down
7 changes: 5 additions & 2 deletions mimic-iii/concepts_postgres/durations/epinephrine_dose.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
DROP TABLE IF EXISTS mimiciii_derived.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,
Expand Down
5 changes: 4 additions & 1 deletion mimic-iii/concepts_postgres/durations/isuprel_durations.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
DROP TABLE IF EXISTS mimiciii_derived.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,
Expand Down
Loading
Loading