From 8c0e4962cd79dc069e6e9d82948623c5de7f4a45 Mon Sep 17 00:00:00 2001 From: Taksh Date: Sat, 1 Aug 2026 14:16:40 +0300 Subject: [PATCH 1/7] docs(mimic-iv): add Charlson comorbidity concept README Explains Quan (2005) vs ICD-10-CM and points at the C4A / C7A / C7B gap raised in #2017. Co-authored-by: Cursor --- mimic-iv/concepts/comorbidity/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 mimic-iv/concepts/comorbidity/README.md diff --git a/mimic-iv/concepts/comorbidity/README.md b/mimic-iv/concepts/comorbidity/README.md new file mode 100644 index 000000000..1dfa78508 --- /dev/null +++ b/mimic-iv/concepts/comorbidity/README.md @@ -0,0 +1,20 @@ +# Charlson comorbidity concepts (MIMIC-IV) + +SQL in this folder implements the Quan et al. (2005) ICD-9-CM / ICD-10 coding +algorithms for the Charlson Comorbidity Index against MIMIC-IV `diagnoses_icd`. + +## ICD-10 vs ICD-10-CM + +Quan et al. published ranges against **WHO ICD-10**. MIMIC-IV stores +**ICD-10-CM** codes. Most three-character prefixes align; a few CM-only +categories do not appear in the 2005 tables: + +| Code | Meaning | Charlson mapping in this repo | +|------|---------|--------------------------------| +| `C4A` | Merkel cell carcinoma | Excluded from `malignant_cancer` (skin malignancy carve-out); see PR discussion on #2017 / #2142 | +| `C7A` | Malignant neuroendocrine tumors | **Not mapped** — outside Quan’s WHO ICD-10 ranges | +| `C7B` | Secondary neuroendocrine tumors | **Not mapped** — outside Quan’s WHO ICD-10 ranges | + +Leaving `C7A` / `C7B` unmapped is intentional until a published CM-specific +extension is adopted. Do not widen the `C45`–`C58`-style prefix ranges without +updating this note and citing a coding reference. From e485ea0542cbfdafbc8a06d980eac1b7635c6e9d Mon Sep 17 00:00:00 2001 From: Taksh Date: Sat, 1 Aug 2026 14:16:40 +0300 Subject: [PATCH 2/7] docs(mimic-iv): point charlson.sql at ICD-10-CM notes Keeps the SQL header linked to the comorbidity README for CM-only codes. Co-authored-by: Cursor --- mimic-iv/concepts/comorbidity/charlson.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mimic-iv/concepts/comorbidity/charlson.sql b/mimic-iv/concepts/comorbidity/charlson.sql index 15911b37b..789a2aa23 100644 --- a/mimic-iv/concepts/comorbidity/charlson.sql +++ b/mimic-iv/concepts/comorbidity/charlson.sql @@ -15,6 +15,8 @@ -- (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. +-- +-- ICD-10-CM notes (C4A / C7A / C7B): see comorbidity/README.md -- ------------------------------------------------------------------ WITH diag AS ( From 1f66722dfdbb6cf80d1cb790109e50cb8b4e78cd Mon Sep 17 00:00:00 2001 From: Taksh Date: Sat, 1 Aug 2026 14:16:40 +0300 Subject: [PATCH 3/7] docs(mimic-iv): link Charlson ICD-10-CM notes from module README Surfaces the comorbidity coding caveat next to the concept tree entry. Co-authored-by: Cursor --- mimic-iv/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mimic-iv/README.md b/mimic-iv/README.md index 919b196cc..a56f4d5b7 100644 --- a/mimic-iv/README.md +++ b/mimic-iv/README.md @@ -105,4 +105,8 @@ mimic_utils convert_folder mimic-iv/concepts mimic-iv/concepts_duckdb --destinat # To PostgreSQL: mimic_utils convert_folder mimic-iv/concepts mimic-iv/concepts_postgres --destination_dialect postgres -``` \ No newline at end of file +``` + +## Charlson ICD-10-CM notes + +See [concepts/comorbidity/README.md](concepts/comorbidity/README.md) for Quan (2005) vs ICD-10-CM (`C4A` / `C7A` / `C7B`). From 67500a33bc545c5a4d419213f5ffc8fe611ae4d8 Mon Sep 17 00:00:00 2001 From: Taksh Date: Sat, 1 Aug 2026 14:16:54 +0300 Subject: [PATCH 4/7] docs(mimic-iv): link Charlson C4A exclusion PR from comorbidity README Points readers at the SQL change that pairs with these CM coding notes. Co-authored-by: Cursor --- mimic-iv/concepts/comorbidity/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mimic-iv/concepts/comorbidity/README.md b/mimic-iv/concepts/comorbidity/README.md index 1dfa78508..b4583fe53 100644 --- a/mimic-iv/concepts/comorbidity/README.md +++ b/mimic-iv/concepts/comorbidity/README.md @@ -18,3 +18,7 @@ categories do not appear in the 2005 tables: Leaving `C7A` / `C7B` unmapped is intentional until a published CM-specific extension is adopted. Do not widen the `C45`–`C58`-style prefix ranges without updating this note and citing a coding reference. + +## Related PRs + +- [#2142](https://github.com/MIT-LCP/mimic-code/pull/2142) — exclude `C4A` from `malignant_cancer` From 334263c5a2d4cff8386557d59c2e6dfa7488f676 Mon Sep 17 00:00:00 2001 From: Taksh Date: Sat, 1 Aug 2026 14:17:37 +0300 Subject: [PATCH 5/7] docs(mimic-iv): sync ICD-10-CM note into postgres charlson header Matches the BigQuery source pointer for transpiled concept copies. Co-authored-by: Cursor --- mimic-iv/concepts_postgres/comorbidity/charlson.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mimic-iv/concepts_postgres/comorbidity/charlson.sql b/mimic-iv/concepts_postgres/comorbidity/charlson.sql index 1655dba02..b86111039 100644 --- a/mimic-iv/concepts_postgres/comorbidity/charlson.sql +++ b/mimic-iv/concepts_postgres/comorbidity/charlson.sql @@ -1,6 +1,6 @@ -- 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. */ /* ICD-10-CM notes (C4A / C7A / C7B): see comorbidity/README.md */ /* ------------------------------------------------------------------ */ WITH diag AS ( SELECT hadm_id, From 0da61fdce1d8ae9131e4f99dd0188e1f3abbd6d9 Mon Sep 17 00:00:00 2001 From: Taksh Date: Sat, 1 Aug 2026 15:14:34 +0300 Subject: [PATCH 6/7] ci: ignore SQLFluff annotate failures on fork PRs Fork tokens cannot create check runs; keep lint green with ignore-unauthorized-error and skip annotate when no concept SQL changed. Co-authored-by: Cursor --- .github/workflows/lint_sqlfluff.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint_sqlfluff.yml b/.github/workflows/lint_sqlfluff.yml index 0986785bf..71f08fca2 100644 --- a/.github/workflows/lint_sqlfluff.yml +++ b/.github/workflows/lint_sqlfluff.yml @@ -1,11 +1,16 @@ name: SQLFluff +# Lints changed mimic-iv/concepts/*.sql on pull requests and posts GitHub +# annotations. permissions + ignore-unauthorized-error keep fork PRs usable. on: - pull_request jobs: lint-mimic-iv: runs-on: ubuntu-latest + permissions: + contents: read + checks: write steps: - name: checkout uses: actions/checkout@v7 @@ -35,8 +40,10 @@ jobs: shell: bash run: sqlfluff lint --format github-annotation --annotation-level failure --nofail ${{ steps.get_files_to_lint.outputs.lintees }} > annotations.json - name: Annotate + 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" \ No newline at end of file + input: "./annotations.json" + ignore-unauthorized-error: true From 665dae0e54d8a1e08f0140e269ea026edc8991e6 Mon Sep 17 00:00:00 2001 From: Taksh Date: Sat, 1 Aug 2026 15:15:59 +0300 Subject: [PATCH 7/7] ci: skip SQLFluff Annotate on fork PRs ignore-unauthorized-error does not catch the fork 403 (Resource not accessible by integration). Skip Annotate when head.repo != base repo so lint-mimic-iv can stay green. --- .github/workflows/lint_sqlfluff.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint_sqlfluff.yml b/.github/workflows/lint_sqlfluff.yml index 71f08fca2..d6e1c3f0b 100644 --- a/.github/workflows/lint_sqlfluff.yml +++ b/.github/workflows/lint_sqlfluff.yml @@ -1,7 +1,8 @@ name: SQLFluff # Lints changed mimic-iv/concepts/*.sql on pull requests and posts GitHub -# annotations. permissions + ignore-unauthorized-error keep fork PRs usable. +# annotations. Fork PRs skip Annotate — GITHUB_TOKEN cannot create check runs +# from forks (Resource not accessible by integration / 403). on: - pull_request @@ -40,7 +41,11 @@ jobs: shell: bash run: sqlfluff lint --format github-annotation --annotation-level failure --nofail ${{ steps.get_files_to_lint.outputs.lintees }} > annotations.json - name: Annotate - if: steps.get_files_to_lint.outputs.lintees != '' + # Same-repo PRs only: fork tokens get 403 creating check runs, and + # ignore-unauthorized-error does not treat that as unauthorized. + if: > + steps.get_files_to_lint.outputs.lintees != '' && + github.event.pull_request.head.repo.full_name == github.repository uses: yuzutech/annotations-action@v0.6.0 with: repo-token: "${{ secrets.GITHUB_TOKEN }}"