From 6aa33067a2b03dcb785fde0aae0774a7db375f85 Mon Sep 17 00:00:00 2001 From: Taksh Date: Fri, 31 Jul 2026 13:16:23 +0300 Subject: [PATCH 1/4] docs(mimic-iv): document ICD-10-CM extensions in charlson.sql Explain why C4A/C7A/C7B are handled separately from Quan et al. (2005). Co-authored-by: Cursor --- mimic-iv/concepts/comorbidity/charlson.sql | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mimic-iv/concepts/comorbidity/charlson.sql b/mimic-iv/concepts/comorbidity/charlson.sql index 15911b37b..e94c39796 100644 --- a/mimic-iv/concepts/comorbidity/charlson.sql +++ b/mimic-iv/concepts/comorbidity/charlson.sql @@ -15,6 +15,12 @@ -- (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 extensions (C4A, C7A, C7B) are not part of WHO ICD-10 and +-- were not defined in Quan et al. (2005). The malignant_cancer mapping +-- below follows Quan by excluding skin malignancy (C4A Merkel cell) and +-- by not mapping C7A/C7B neuroendocrine categories, which fall outside +-- the WHO ICD-10 code ranges used in the publication. -- ------------------------------------------------------------------ WITH diag AS ( @@ -302,7 +308,12 @@ WITH diag AS ( OR SUBSTR(icd10_code, 1, 3) BETWEEN 'C37' AND 'C41' OR - SUBSTR(icd10_code, 1, 3) BETWEEN 'C45' AND 'C58' + -- Split C45-C58 to exclude C4A (Merkel cell carcinoma), which + -- lexically falls inside BETWEEN 'C45' AND 'C58' but is skin + -- malignancy excluded by Quan et al. (2005). + SUBSTR(icd10_code, 1, 3) BETWEEN 'C45' AND 'C49' + OR + SUBSTR(icd10_code, 1, 3) BETWEEN 'C50' AND 'C58' OR SUBSTR(icd10_code, 1, 3) BETWEEN 'C60' AND 'C76' OR From a599d030ae217b172d6a455677715b6a32d5f351 Mon Sep 17 00:00:00 2001 From: Taksh Date: Fri, 31 Jul 2026 13:16:28 +0300 Subject: [PATCH 2/4] chore(mimic-iv): regenerate postgres and duckdb charlson copies Co-authored-by: Cursor --- mimic-iv/concepts_duckdb/comorbidity/charlson.sql | 3 ++- mimic-iv/concepts_postgres/comorbidity/charlson.sql | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mimic-iv/concepts_duckdb/comorbidity/charlson.sql b/mimic-iv/concepts_duckdb/comorbidity/charlson.sql index be191aa82..c3a916ac6 100644 --- a/mimic-iv/concepts_duckdb/comorbidity/charlson.sql +++ b/mimic-iv/concepts_duckdb/comorbidity/charlson.sql @@ -275,7 +275,8 @@ WITH diag AS ( OR SUBSTRING(icd10_code, 1, 3) BETWEEN 'C00' AND 'C26' OR SUBSTRING(icd10_code, 1, 3) BETWEEN 'C30' AND 'C34' OR SUBSTRING(icd10_code, 1, 3) BETWEEN 'C37' AND 'C41' - OR SUBSTRING(icd10_code, 1, 3) BETWEEN 'C45' AND 'C58' + OR SUBSTRING(icd10_code, 1, 3) BETWEEN 'C45' AND 'C49' + OR SUBSTRING(icd10_code, 1, 3) BETWEEN 'C50' AND 'C58' OR SUBSTRING(icd10_code, 1, 3) BETWEEN 'C60' AND 'C76' OR SUBSTRING(icd10_code, 1, 3) BETWEEN 'C81' AND 'C85' OR SUBSTRING(icd10_code, 1, 3) BETWEEN 'C90' AND 'C97' diff --git a/mimic-iv/concepts_postgres/comorbidity/charlson.sql b/mimic-iv/concepts_postgres/comorbidity/charlson.sql index 1655dba02..5c34f29e8 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 extensions (C4A, C7A, C7B) are not part of WHO ICD-10 and */ /* were not defined in Quan et al. (2005). The malignant_cancer mapping */ /* below follows Quan by excluding skin malignancy (C4A Merkel cell) and */ /* by not mapping C7A/C7B neuroendocrine categories, which fall outside */ /* the WHO ICD-10 code ranges used in the publication. */ /* ------------------------------------------------------------------ */ WITH diag AS ( SELECT hadm_id, @@ -276,7 +276,8 @@ WITH diag AS ( OR SUBSTRING(icd10_code FROM 1 FOR 3) BETWEEN 'C00' AND 'C26' OR SUBSTRING(icd10_code FROM 1 FOR 3) BETWEEN 'C30' AND 'C34' OR SUBSTRING(icd10_code FROM 1 FOR 3) BETWEEN 'C37' AND 'C41' - OR SUBSTRING(icd10_code FROM 1 FOR 3) BETWEEN 'C45' AND 'C58' + OR SUBSTRING(icd10_code FROM 1 FOR 3) /* Split C45-C58 to exclude C4A (Merkel cell carcinoma), which */ /* lexically falls inside BETWEEN 'C45' AND 'C58' but is skin */ /* malignancy excluded by Quan et al. (2005). */ BETWEEN 'C45' AND 'C49' + OR SUBSTRING(icd10_code FROM 1 FOR 3) BETWEEN 'C50' AND 'C58' OR SUBSTRING(icd10_code FROM 1 FOR 3) BETWEEN 'C60' AND 'C76' OR SUBSTRING(icd10_code FROM 1 FOR 3) BETWEEN 'C81' AND 'C85' OR SUBSTRING(icd10_code FROM 1 FOR 3) BETWEEN 'C90' AND 'C97' From 5fd2acfef1c808ccbe534ebc38581198a2d5fe88 Mon Sep 17 00:00:00 2001 From: Taksh Date: Sat, 1 Aug 2026 15:14:21 +0300 Subject: [PATCH 3/4] 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 87130a7e66ed0293d7d8a12f353507ba6bed301d Mon Sep 17 00:00:00 2001 From: Taksh Date: Sat, 1 Aug 2026 15:16:28 +0300 Subject: [PATCH 4/4] 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 }}"