Skip to content

Commit 72a8acc

Browse files
Exclude primary dx and RTRIM ICD-9 in Elixhauser no_drg
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 70998b9 commit 72a8acc

3 files changed

Lines changed: 38 additions & 13 deletions

File tree

‎mimic-iii/concepts/comorbidity/elixhauser_ahrq_v37_no_drg.sql‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
-- The code:
66
-- removes "primary" ICD9_CODE (seq_num != 1)
77
-- uses AHRQ published rules to define comorbidities
8+
-- RTRIM icd9_code so space-padded values still match BETWEEN/equality
89
with
9-
eliflg as
10+
icd as
11+
(
12+
select hadm_id, seq_num, RTRIM(icd9_code) as icd9_code
13+
from `physionet-data.mimiciii_clinical.diagnoses_icd`
14+
where seq_num != 1
15+
)
16+
, eliflg as
1017
(
1118
select hadm_id, seq_num, icd9_code
1219
-- note that these codes will seem incomplete at first
@@ -390,8 +397,7 @@ select hadm_id, seq_num, icd9_code
390397
when icd9_code = '3091' then 1
391398
when icd9_code = '311' then 1
392399
end as depress /* Depression */
393-
from `physionet-data.mimiciii_clinical.diagnoses_icd` icd
394-
WHERE seq_num = 1
400+
from icd
395401
)
396402
-- collapse the icd9_code specific flags into hadm_id specific flags
397403
-- this groups comorbidities together for a single patient admission

‎mimic-iii/concepts_duckdb/comorbidity/elixhauser_ahrq_v37_no_drg.sql‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
22
DROP TABLE IF EXISTS mimiciii_derived.elixhauser_ahrq_v37_no_drg; CREATE TABLE mimiciii_derived.elixhauser_ahrq_v37_no_drg AS
3-
WITH eliflg AS (
3+
WITH icd AS (
4+
SELECT
5+
hadm_id,
6+
seq_num,
7+
RTRIM(icd9_code) AS icd9_code
8+
FROM mimiciii.diagnoses_icd
9+
WHERE
10+
seq_num <> 1
11+
), eliflg AS (
412
SELECT
513
hadm_id,
614
seq_num,
@@ -559,9 +567,7 @@ WITH eliflg AS (
559567
WHEN icd9_code = '311'
560568
THEN 1
561569
END AS depress
562-
FROM mimiciii.diagnoses_icd AS icd
563-
WHERE
564-
seq_num = 1
570+
FROM icd
565571
), eligrp AS (
566572
SELECT
567573
hadm_id,

‎mimic-iii/concepts_postgres/comorbidity/elixhauser_ahrq_v37_no_drg.sql‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
22
DROP TABLE IF EXISTS mimiciii_derived.elixhauser_ahrq_v37_no_drg; CREATE TABLE mimiciii_derived.elixhauser_ahrq_v37_no_drg AS
3-
/* 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 */
4-
WITH eliflg AS (
3+
/* This code uses the latest version of Elixhauser provided by AHRQ */
4+
/* However, it does *not* filter based on diagnosis related groups (DRGs) */
5+
/* As such, "comorbidities" identified are more likely to be associated with the primary reason for their hospital stay */
6+
/* The code: */
7+
/* removes "primary" ICD9_CODE (seq_num != 1) */
8+
/* uses AHRQ published rules to define comorbidities */
9+
/* RTRIM icd9_code so space-padded values still match BETWEEN/equality */
10+
WITH icd AS (
11+
SELECT
12+
hadm_id,
13+
seq_num,
14+
RTRIM(icd9_code) AS icd9_code
15+
FROM mimiciii.diagnoses_icd
16+
WHERE
17+
seq_num <> 1
18+
), eliflg AS (
519
SELECT
620
hadm_id,
721
seq_num,
@@ -562,9 +576,7 @@ WITH eliflg AS (
562576
WHEN icd9_code = '311'
563577
THEN 1
564578
END AS depress /* Depression */
565-
FROM mimiciii.diagnoses_icd AS icd
566-
WHERE
567-
seq_num = 1
579+
FROM icd
568580
), eligrp /* collapse the icd9_code specific flags into hadm_id specific flags */ /* this groups comorbidities together for a single patient admission */ AS (
569581
SELECT
570582
hadm_id,
@@ -613,7 +625,8 @@ WITH eliflg AS (
613625
GROUP BY
614626
hadm_id
615627
)
616-
/* now merge these flags together to define elixhauser */ /* most are straightforward.. but hypertension flags are a bit more complicated */
628+
/* now merge these flags together to define elixhauser */
629+
/* most are straightforward.. but hypertension flags are a bit more complicated */
617630
SELECT
618631
adm.subject_id,
619632
adm.hadm_id,

0 commit comments

Comments
 (0)