Skip to content

fix(mimic-iii): do not bridge paused vasopressor gaps - #2121

Open
acnimma wants to merge 1 commit into
MIT-LCP:mainfrom
acnimma:fix/iii-vasopressor-paused-gaps
Open

fix(mimic-iii): do not bridge paused vasopressor gaps#2121
acnimma wants to merge 1 commit into
MIT-LCP:mainfrom
acnimma:fix/iii-vasopressor-paused-gaps

Conversation

@acnimma

@acnimma acnimma commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Stop collapsing MetaVision vasopressor rows with GROUP BY linkorderid + min/max times
  • Keep each inputevents_mv row as its own interval; vasomv_grp still merges contiguous/overlapping intervals
  • Update postgres and duckdb dialect copies
  • Document the paused-gap rationale in SQL (BigQuery source + postgres copy cite paused vasopressor durations #1808)

Why

vasopressor_durations grouped MetaVision rows by linkorderid and took min(starttime) / max(endtime). That is correct when successive rows abut, but after statusdescription = 'Paused' there is often a multi-hour gap (example linkorderid = 8781494, ~6h; see #1808, median ~1h 11m). Bridging that gap overstates vasopressor exposure.

Duration threshold / behavior

  • Paused gaps: leave as separate intervals (do not bridge via linkorderid)
  • Contiguous / overlapping: still merged by vasomv_grp

Test plan

  • No GROUP BY linkorderid remains in vasomv
  • SQL comments cite paused-gap / paused vasopressor durations #1808 in BigQuery + postgres (duckdb transpile drops comments)
  • linkorderid = 8781494 (Paused gap ~6h) yields separate durations, not one bridged interval
  • Contiguous non-paused orders still merge via vasomv_grp

Fixes #1808

MetaVision vasopressor_durations collapsed rows by linkorderid with
min(starttime)/max(endtime). After a Paused status that leaves a gap
(median ~1h), that incorrectly counted the pause as infusion time.
Keep each inputevents_mv row as its own interval; vasomv_grp still merges
contiguous/overlapping intervals.

Fixes MIT-LCP#1808

@Chessing234 Chessing234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch on the linkorderid collapse — that paused gap example (~6h) really shouldn't get glued into one interval. leaving vasomv_grp to merge only contiguous/overlapping bits feels like the right split. maybe worth a one-liner in the test plan for a non-paused contiguous pair still merging, just so nobody regresses that later.

@Chessing234

Copy link
Copy Markdown
Contributor

not bridging paused vaso gaps is the right clinical call. can you cite the duration threshold you used in the pr description?

@Chessing234

Copy link
Copy Markdown
Contributor

keeping paused gaps as separate intervals matches the raw inputevents_mv semantics better than collapsing on linkorderid. can you add a short comment in the sql citing the paused-gap example so future edits dont reintroduce the group by?

@Chessing234 Chessing234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dropping the linkorderid min/max collapse is the right fix for paused vaso gaps — contiguous merge in vasomv_grp still covers true overlaps. mirrored across dialects which is what this repo needs. a one-line comment in the postgres/duckdb copies pointing at #1808 (like the bq file already has) would help the next reader.

@acnimma

acnimma commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Addressing the review notes:

  • Duration threshold: documented in the PR body — example paused gap is linkorderid = 8781494 (~6h); paused vasopressor durations #1808 reports median ~1h 11m. We do not bridge those gaps.
  • SQL comments: BigQuery source has the paused-gap / linkorderid note above vasomv; postgres dialect copy carries an inline /* ... #1808 */ on the vasomv CTE (duckdb transpile strips comments by design).
  • Contiguous merge: still covered by vasomv_grp; called out explicitly in the test plan so that path is not regressed.

@Chessing234 Chessing234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two things here, one mechanical and one i'd like your read on.

the postgres copy doesn't match what the transpiler produces. i ran the repo's own transpiler (sqlglot 30.11.0 from requirements-lock) over your bigquery source and diffed against mimic-iii/concepts_postgres/durations/vasopressor_durations.sql as committed on this branch: sqlglot renders your four-line comment as a run of separate /* ... */ fragments on one line, but the branch has a single hand-written /* keep each MetaVision interval; do not bridge Paused gaps via linkorderid (#1808) */. the duckdb copy is byte-identical to transpiler output, so it's only the postgres file. running the same check against main returns identical for this file, so the drift starts in this branch. the generated-up-to-date job in transpile.yml diffs that folder against transpiler output, and the file header says not to edit it directly.

on the substance — i think not bridging paused gaps is the right call, but as written the query has no threshold at all despite the "duration threshold / behavior" heading. vasomv_grp only merges where s1.starttime <= t1.endtime, so once the linkorderid grouping is gone, two rows of the same order separated by one second become two separate durations. #1808's median gap of ~1h11m establishes that the paused gaps are large; it doesn't establish that small ones are absent. could you post the distribution of gaps between consecutive rows within a linkorderid — specifically how many fall under a few minutes? if there's a tail of sub-minute charting gaps then this needs a tolerance rather than zero, and that's also the number that would let the two unchecked boxes in your test plan be checked.

separately, worth calling out explicitly: the carevue branch above keeps its own gap handling, so after this change the same output table carries two different definitions of when an interval breaks depending on which system the stay came from. a line in the sql or the pr body would help anyone unioning the two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

paused vasopressor durations

2 participants