From 6eb9ef2e5eef5e65e6f3c2ee23744485e6cb28ac Mon Sep 17 00:00:00 2001 From: Taksh Date: Fri, 31 Jul 2026 13:17:11 +0300 Subject: [PATCH 1/6] fix(mimic-iv): exclude non-positive values in cardiac_marker Align with other lab measurement concepts that require valuenum > 0. Co-authored-by: Cursor --- mimic-iv/concepts/measurement/cardiac_marker.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/mimic-iv/concepts/measurement/cardiac_marker.sql b/mimic-iv/concepts/measurement/cardiac_marker.sql index ed612191..57c08e27 100644 --- a/mimic-iv/concepts/measurement/cardiac_marker.sql +++ b/mimic-iv/concepts/measurement/cardiac_marker.sql @@ -18,5 +18,6 @@ WHERE le.itemid IN , 50963 -- N-terminal (NT)-pro hormone BNP (NT-proBNP) ) AND valuenum IS NOT NULL + AND valuenum > 0 GROUP BY le.specimen_id ; From e18f4b9cf4383070a25e67382429acc80f7a2528 Mon Sep 17 00:00:00 2001 From: Taksh Date: Fri, 31 Jul 2026 13:17:11 +0300 Subject: [PATCH 2/6] fix(mimic-iv): exclude non-positive values in coagulation Co-authored-by: Cursor --- mimic-iv/concepts/measurement/coagulation.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/mimic-iv/concepts/measurement/coagulation.sql b/mimic-iv/concepts/measurement/coagulation.sql index 241ac06a..58158b86 100644 --- a/mimic-iv/concepts/measurement/coagulation.sql +++ b/mimic-iv/concepts/measurement/coagulation.sql @@ -27,5 +27,6 @@ WHERE le.itemid IN , 51275 -- PTT ) AND valuenum IS NOT NULL + AND valuenum > 0 GROUP BY le.specimen_id ; From 44f176b72b65eb8a2b28282d39f7c8bbf61cadf6 Mon Sep 17 00:00:00 2001 From: Taksh Date: Fri, 31 Jul 2026 13:17:13 +0300 Subject: [PATCH 3/6] chore(mimic-iv): regenerate postgres and duckdb cardiac/coag copies Co-authored-by: Cursor --- mimic-iv/concepts_duckdb/measurement/cardiac_marker.sql | 2 +- mimic-iv/concepts_duckdb/measurement/coagulation.sql | 4 +++- mimic-iv/concepts_postgres/measurement/cardiac_marker.sql | 1 + mimic-iv/concepts_postgres/measurement/coagulation.sql | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mimic-iv/concepts_duckdb/measurement/cardiac_marker.sql b/mimic-iv/concepts_duckdb/measurement/cardiac_marker.sql index 7dc6cf26..370970a6 100644 --- a/mimic-iv/concepts_duckdb/measurement/cardiac_marker.sql +++ b/mimic-iv/concepts_duckdb/measurement/cardiac_marker.sql @@ -10,6 +10,6 @@ SELECT MAX(CASE WHEN itemid = 50963 THEN valuenum ELSE NULL END) AS ntprobnp FROM mimiciv_hosp.labevents AS le WHERE - le.itemid IN (51003, 50911, 50963) AND NOT valuenum IS NULL + le.itemid IN (51003, 50911, 50963) AND NOT valuenum IS NULL AND valuenum > 0 GROUP BY le.specimen_id \ No newline at end of file diff --git a/mimic-iv/concepts_duckdb/measurement/coagulation.sql b/mimic-iv/concepts_duckdb/measurement/coagulation.sql index 69d00552..5eddc60d 100644 --- a/mimic-iv/concepts_duckdb/measurement/coagulation.sql +++ b/mimic-iv/concepts_duckdb/measurement/coagulation.sql @@ -13,6 +13,8 @@ SELECT MAX(CASE WHEN itemid = 51275 THEN valuenum ELSE NULL END) AS ptt FROM mimiciv_hosp.labevents AS le WHERE - le.itemid IN (51196, 51214, 51297, 51237, 51274, 51275) AND NOT valuenum IS NULL + le.itemid IN (51196, 51214, 51297, 51237, 51274, 51275) + AND NOT valuenum IS NULL + AND valuenum > 0 GROUP BY le.specimen_id \ No newline at end of file diff --git a/mimic-iv/concepts_postgres/measurement/cardiac_marker.sql b/mimic-iv/concepts_postgres/measurement/cardiac_marker.sql index 4a783cc3..84a1b346 100644 --- a/mimic-iv/concepts_postgres/measurement/cardiac_marker.sql +++ b/mimic-iv/concepts_postgres/measurement/cardiac_marker.sql @@ -17,5 +17,6 @@ WHERE 50963 /* N-terminal (NT)-pro hormone BNP (NT-proBNP) */ ) AND NOT valuenum IS NULL + AND valuenum > 0 GROUP BY le.specimen_id \ No newline at end of file diff --git a/mimic-iv/concepts_postgres/measurement/coagulation.sql b/mimic-iv/concepts_postgres/measurement/coagulation.sql index 8891338d..be698bb3 100644 --- a/mimic-iv/concepts_postgres/measurement/coagulation.sql +++ b/mimic-iv/concepts_postgres/measurement/coagulation.sql @@ -22,5 +22,6 @@ WHERE 51275 /* PTT */ ) AND NOT valuenum IS NULL + AND valuenum > 0 GROUP BY le.specimen_id \ No newline at end of file From f13218b183962283ecb470134b2bf238f4baade5 Mon Sep 17 00:00:00 2001 From: Taksh Date: Fri, 31 Jul 2026 13:17:13 +0300 Subject: [PATCH 4/6] docs(mimic-iv): note lab valuenum and valueuom filtering conventions Co-authored-by: Cursor --- mimic-iv/concepts/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mimic-iv/concepts/README.md b/mimic-iv/concepts/README.md index f2c55041..f5e87730 100644 --- a/mimic-iv/concepts/README.md +++ b/mimic-iv/concepts/README.md @@ -3,6 +3,10 @@ This folder contains scripts to generate useful abstractions of raw MIMIC-IV data ("concepts"). The scripts are written using the **BigQuery Standard SQL Dialect**. Concepts are categorized into folders if possible, otherwise they remain in the top-level directory. The [concepts_postgres](/mimic-iv/concepts_postgres) and [concepts_duckdb](/mimic-iv/concepts_duckdb) folders contain automatically generated PostgreSQL and DuckDB versions of these scripts; see the [top-level readme](/mimic-iv/README.md#generating-the-concepts) for how these were generated. +Lab measurement concepts under `measurement/` generally exclude non-positive `valuenum` rows +(`valuenum IS NOT NULL AND valuenum > 0`) and, where documented in the source SQL, filter +`valueuom` to the expected unit for a given `itemid`. + The concepts are organized into individual SQL scripts, with each script generating a table. The BigQuery `mimiciv_derived` dataset under `physionet-data` contains the concepts pregenerated. Access to this dataset is available to MIMIC-IV approved users: see the [cloud instructions](https://mimic.mit.edu/docs/gettingstarted/cloud/) on how to access MIMIC-IV on BigQuery (which includes the derived concepts). See the [top-level readme](/mimic-iv/README.md) for more information about generating the concepts. From 710be8152e196719651db845a5364be2e820d9fe Mon Sep 17 00:00:00 2001 From: Taksh Date: Sat, 1 Aug 2026 15:14:15 +0300 Subject: [PATCH 5/6] 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 0986785b..71f08fca 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 292bec710068e77a23f8d37005988183486cc14e Mon Sep 17 00:00:00 2001 From: Taksh Date: Sat, 1 Aug 2026 15:16:21 +0300 Subject: [PATCH 6/6] 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 71f08fca..d6e1c3f0 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 }}"