Repository navigation
fix(mimic-iv): restart KDIGO stage smoothing on each ICU stay - #2188
Open
eastagile-tracker wants to merge 1 commit into
Open
eastagile-tracker wants to merge 1 commit into
eastagile-tracker wants to merge 1 commit into
Conversation
aki_stage_smoothed takes the max stage over the preceding six hours, ordered by seconds since ie.intime, but partitioned by subject_id. The clock restarts on every stay, so rows from a different stay of the same patient land in the window: a stage 3 observation two hours into a later stay raised an earlier stay's smoothed stage from 0 to 3. Partition by stay_id so the window only sees the stay's own rows, and add a DuckDB regression test that runs the concept on synthetic tables.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR proposes restarting the KDIGO
aki_stage_smoothedwindow on each ICU stay (Fixes #2184). We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/1460. You can sign in with your GitHub ID to claim ownership of the project.What changed and why
In
mimic-iv/concepts/organfailure/kdigo_stages.sql,aki_stage_smoothedtakes the max stage over the preceding six hours, ordered byDATETIME_DIFF(tm.charttime, ie.intime, SECOND)but partitioned byie.subject_id. That clock restarts at every ICU admission, so rows from a different stay of the same patient fall inside the window: as #2184 reports, a stage 3 creatinine two hours into a July stay raises the smoothed stage of a January row three hours into its stay from 0 to 3. The fix partitions byie.stay_id, which matches the per-stay example in the comment above the window. The DuckDB and Postgres copies get the same one-line change; I confirmed the DuckDB file is byte-identical tomimic_utils convert_folderoutput, and the Postgres diff is the same single line.If the intent was to carry a stage across a short gap between stays, the alternative from the issue (keep
subject_idand order by the absolutecharttime) would also work; happy to switch if you prefer that.Reproduction at current
main(e3e0310)On an in-memory DuckDB with synthetic
icustays/kdigo_creatinine/kdigo_uo/crrttables (one patient, stays 10 and 20 six months apart, creatinine 1.0 at 03:00 in stay 10 and 4.0 at 02:00 in stay 20, baseline 1.0), running both the transpiled BigQuery source and the checked-inconcepts_duckdbfile returns(stay_id, charttime, aki_stage, aki_stage_smoothed):Verification
tests/test_kdigo_stages.pyruns the concept (BigQuery source transpiled to DuckDB) on that fixture.test_smoothing_does_not_borrow_stage_from_a_later_stayfails onmain(3 != 0) and passes with the fix;test_smoothing_carries_highest_stage_forward_within_a_staypasses on both, confirming the six-hour carry-forward within a stay is unchanged (stage 3 still carried at +5h, dropped at +6.5h).pytestbefore: 402 passed, 1 failed; after: 404 passed, 1 failed. The one failure is the same pre-existingtest_sqlfluff.py::test_concept_passes_sqlfluff[score/sirs.sql]on both trees.tests/test_transpile.py, so the new test runs withpytest tests/test_kdigo_stages.py(or a plainpytest) until you add it there.How this was managed
This work was tracked as https://eastagiletracker.com/projects/1460/stories/1568266 on https://eastagiletracker.com/projects/1460, a board imported from this repo's 1,807 issues and pull requests.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com