Surgery date window#10
Merged
Merged
Conversation
…history that is effectively undated
There was a problem hiding this comment.
Pull request overview
This PR fixes treatment-envelope windowing around surgery by (1) properly attributing surgery events to condition episodes via a bounded date window (excluding historical “surgery history” observations), and (2) ensuring surgery contributes to both earliest and latest treatment dates in the episode-level treatment envelope.
Changes:
- Add episode-attribution windowing for surgical Procedure_Occurrence rows and exclude historical surgery observations from timing calculations.
- Compute a surgery-specific first/last surgery window and include it in
latest_treatment(and align surgery timestamps toDatefor day-based scalars). - Expand construct catalog documentation to describe episode/event attachment strategy and treatment envelope semantics.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| src/omop_constructs/alchemy/episodes/treatment_envelope_query.py | Adds surgery first/last window and includes surgery in latest-treatment + day-based scalar calculations. |
| src/omop_constructs/alchemy/episodes/surgical_joins.py | Splits active vs historical surgery sources and applies episode date-window attribution for active surgeries (plus similar logic for radioisotopes). |
| docs/construct-catalog.md | Major documentation expansion describing constructs, windowing/attachment behavior, and treatment envelope fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+117
to
+121
| sa.func.least( | ||
| treatment_window.c.first_surgery, | ||
| treatment_window.c.first_sact_exposure, | ||
| treatment_window.c.first_rt_exposure, | ||
| ).label('earliest_treatment'), |
Comment on lines
+123
to
+127
| sa.func.greatest( | ||
| treatment_window.c.last_surgery, | ||
| treatment_window.c.last_sact_exposure, | ||
| treatment_window.c.last_rt_exposure, | ||
| ).label('latest_treatment'), |
Comment on lines
+6
to
+10
| from ..events.event_factories import ( | ||
| DEFAULT_EPISODE_WINDOW_DAYS_POST, | ||
| DEFAULT_EPISODE_WINDOW_DAYS_PRIOR, | ||
| DEFAULT_EPISODE_OPEN_END_FALLBACK_DAYS, | ||
| ) |
Comment on lines
+194
to
198
| _surgery_date >= ConditionEpisodeMV.episode_start_date - DEFAULT_EPISODE_WINDOW_DAYS_PRIOR, | ||
| _surgery_date <= _episode_end_bound, | ||
| ), | ||
| isouter=True, | ||
| ) |
Comment on lines
+245
to
249
| _ri_date >= ConditionEpisodeMV.episode_start_date - DEFAULT_EPISODE_WINDOW_DAYS_PRIOR, | ||
| _ri_date <= _episode_end_bound, | ||
| ), | ||
| isouter=True, | ||
| ) |
Comment on lines
+123
to
+127
| sa.func.greatest( | ||
| treatment_window.c.last_surgery, | ||
| treatment_window.c.last_sact_exposure, | ||
| treatment_window.c.last_rt_exposure, | ||
| ).label('latest_treatment'), |
Comment on lines
+6
to
+10
| from ..events.event_factories import ( | ||
| DEFAULT_EPISODE_WINDOW_DAYS_POST, | ||
| DEFAULT_EPISODE_WINDOW_DAYS_PRIOR, | ||
| DEFAULT_EPISODE_OPEN_END_FALLBACK_DAYS, | ||
| ) |
Comment on lines
+194
to
198
| _surgery_date >= ConditionEpisodeMV.episode_start_date - DEFAULT_EPISODE_WINDOW_DAYS_PRIOR, | ||
| _surgery_date <= _episode_end_bound, | ||
| ), | ||
| isouter=True, | ||
| ) |
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.
closes: #11