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
6 changes: 5 additions & 1 deletion .github/workflows/lint_sqlfluff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ jobs:
shell: bash
run: sqlfluff lint --format github-annotation --annotation-level failure --nofail ${{ steps.get_files_to_lint.outputs.lintees }} > annotations.json
- name: Annotate
# Fork PRs cannot create check runs with GITHUB_TOKEN; lint already ran.
continue-on-error: true
if: steps.get_files_to_lint.outputs.lintees != ''
uses: yuzutech/annotations-action@v0.6.0
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
title: "SQLFluff Lint"
input: "./annotations.json"
input: "./annotations.json"
ignore-missing-file: true
12 changes: 9 additions & 3 deletions mimic-iii/concepts/comorbidity/elixhauser_ahrq_v37_no_drg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
-- The code:
-- removes "primary" ICD9_CODE (seq_num != 1)
-- uses AHRQ published rules to define comorbidities
-- RTRIM icd9_code so space-padded values still match BETWEEN/equality
with
eliflg as
icd as
(
select hadm_id, seq_num, RTRIM(icd9_code) as icd9_code
from `physionet-data.mimiciii_clinical.diagnoses_icd`
where seq_num != 1
)
, eliflg as
(
select hadm_id, seq_num, icd9_code
-- note that these codes will seem incomplete at first
Expand Down Expand Up @@ -390,8 +397,7 @@ select hadm_id, seq_num, icd9_code
when icd9_code = '3091' then 1
when icd9_code = '311' then 1
end as depress /* Depression */
from `physionet-data.mimiciii_clinical.diagnoses_icd` icd
WHERE seq_num = 1
from icd
)
-- collapse the icd9_code specific flags into hadm_id specific flags
-- this groups comorbidities together for a single patient admission
Expand Down
2 changes: 1 addition & 1 deletion mimic-iii/concepts/pivot/pivoted_sofa.sql
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ WITH co AS
-- Cardiovascular
, cast(case
when rate_dopamine > 15 or rate_epinephrine > 0.1 or rate_norepinephrine > 0.1 then 4
when rate_dopamine > 5 or rate_epinephrine <= 0.1 or rate_norepinephrine <= 0.1 then 3
when rate_dopamine > 5 or (rate_epinephrine > 0 and rate_epinephrine <= 0.1) or (rate_norepinephrine > 0 and rate_norepinephrine <= 0.1) then 3
when rate_dopamine > 0 or rate_dobutamine > 0 then 2
when meanbp_min < 70 then 1
when coalesce(meanbp_min, rate_dopamine, rate_dobutamine, rate_epinephrine, rate_norepinephrine) is null then null
Expand Down
2 changes: 1 addition & 1 deletion mimic-iii/concepts/severityscores/sofa.sql
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ left join `physionet-data.mimiciii_derived.gcs_first_day` gcs
-- Cardiovascular
, case
when rate_dopamine > 15 or rate_epinephrine > 0.1 or rate_norepinephrine > 0.1 then 4
when rate_dopamine > 5 or rate_epinephrine <= 0.1 or rate_norepinephrine <= 0.1 then 3
when rate_dopamine > 5 or (rate_epinephrine > 0 and rate_epinephrine <= 0.1) or (rate_norepinephrine > 0 and rate_norepinephrine <= 0.1) then 3
when rate_dopamine > 0 or rate_dobutamine > 0 then 2
when meanbp_min < 70 then 1
when coalesce(meanbp_min, rate_dopamine, rate_dobutamine, rate_epinephrine, rate_norepinephrine) is null then null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
-- 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
WITH eliflg AS (
WITH icd AS (
SELECT
hadm_id,
seq_num,
RTRIM(icd9_code) AS icd9_code
FROM mimiciii.diagnoses_icd
WHERE
seq_num <> 1
), eliflg AS (
SELECT
hadm_id,
seq_num,
Expand Down Expand Up @@ -559,9 +567,7 @@ WITH eliflg AS (
WHEN icd9_code = '311'
THEN 1
END AS depress
FROM mimiciii.diagnoses_icd AS icd
WHERE
seq_num = 1
FROM icd
), eligrp AS (
SELECT
hadm_id,
Expand Down
8 changes: 7 additions & 1 deletion mimic-iii/concepts_duckdb/pivot/pivoted_sofa.sql
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ WITH co AS (
CAST(CASE
WHEN rate_dopamine > 15 OR rate_epinephrine > 0.1 OR rate_norepinephrine > 0.1
THEN 4
WHEN rate_dopamine > 5 OR rate_epinephrine <= 0.1 OR rate_norepinephrine <= 0.1
WHEN rate_dopamine > 5
OR (
rate_epinephrine > 0 AND rate_epinephrine <= 0.1
)
OR (
rate_norepinephrine > 0 AND rate_norepinephrine <= 0.1
)
THEN 3
WHEN rate_dopamine > 0 OR rate_dobutamine > 0
THEN 2
Expand Down
8 changes: 7 additions & 1 deletion mimic-iii/concepts_duckdb/severityscores/sofa.sql
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ WITH wt AS (
CASE
WHEN rate_dopamine > 15 OR rate_epinephrine > 0.1 OR rate_norepinephrine > 0.1
THEN 4
WHEN rate_dopamine > 5 OR rate_epinephrine <= 0.1 OR rate_norepinephrine <= 0.1
WHEN rate_dopamine > 5
OR (
rate_epinephrine > 0 AND rate_epinephrine <= 0.1
)
OR (
rate_norepinephrine > 0 AND rate_norepinephrine <= 0.1
)
THEN 3
WHEN rate_dopamine > 0 OR rate_dobutamine > 0
THEN 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
-- 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 */
WITH eliflg 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 */
/* RTRIM icd9_code so space-padded values still match BETWEEN/equality */
WITH icd AS (
SELECT
hadm_id,
seq_num,
RTRIM(icd9_code) AS icd9_code
FROM mimiciii.diagnoses_icd
WHERE
seq_num <> 1
), eliflg AS (
SELECT
hadm_id,
seq_num,
Expand Down Expand Up @@ -562,9 +576,7 @@ WITH eliflg AS (
WHEN icd9_code = '311'
THEN 1
END AS depress /* Depression */
FROM mimiciii.diagnoses_icd AS icd
WHERE
seq_num = 1
FROM icd
), eligrp /* collapse the icd9_code specific flags into hadm_id specific flags */ /* this groups comorbidities together for a single patient admission */ AS (
SELECT
hadm_id,
Expand Down Expand Up @@ -613,7 +625,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
44 changes: 41 additions & 3 deletions mimic-iii/concepts_postgres/pivot/pivoted_sofa.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -189,7 +221,13 @@ WITH co AS (
CAST(CASE
WHEN rate_dopamine > 15 OR rate_epinephrine > 0.1 OR rate_norepinephrine > 0.1
THEN 4
WHEN rate_dopamine > 5 OR rate_epinephrine <= 0.1 OR rate_norepinephrine <= 0.1
WHEN rate_dopamine > 5
OR (
rate_epinephrine > 0 AND rate_epinephrine <= 0.1
)
OR (
rate_norepinephrine > 0 AND rate_norepinephrine <= 0.1
)
THEN 3
WHEN rate_dopamine > 0 OR rate_dobutamine > 0
THEN 2
Expand Down
44 changes: 40 additions & 4 deletions mimic-iii/concepts_postgres/severityscores/sofa.sql
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -199,7 +229,13 @@ WITH wt AS (
CASE
WHEN rate_dopamine > 15 OR rate_epinephrine > 0.1 OR rate_norepinephrine > 0.1
THEN 4
WHEN rate_dopamine > 5 OR rate_epinephrine <= 0.1 OR rate_norepinephrine <= 0.1
WHEN rate_dopamine > 5
OR (
rate_epinephrine > 0 AND rate_epinephrine <= 0.1
)
OR (
rate_norepinephrine > 0 AND rate_norepinephrine <= 0.1
)
THEN 3
WHEN rate_dopamine > 0 OR rate_dobutamine > 0
THEN 2
Expand Down
4 changes: 2 additions & 2 deletions mimic-iv/concepts/firstday/first_day_sofa.sql
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ WITH vaso_stg AS (
OR rate_norepinephrine > 0.1
THEN 4
WHEN rate_dopamine > 5
OR rate_epinephrine <= 0.1
OR rate_norepinephrine <= 0.1
OR (rate_epinephrine > 0 AND rate_epinephrine <= 0.1)
OR (rate_norepinephrine > 0 AND rate_norepinephrine <= 0.1)
THEN 3
WHEN rate_dopamine > 0 OR rate_dobutamine > 0 THEN 2
WHEN mbp_min < 70 THEN 1
Expand Down
Loading
Loading