Skip to content

Surgery date window#10

Merged
gkennos merged 4 commits into
mainfrom
surgery_date_window
May 29, 2026
Merged

Surgery date window#10
gkennos merged 4 commits into
mainfrom
surgery_date_window

Conversation

@gkennos
Copy link
Copy Markdown
Member

@gkennos gkennos commented May 29, 2026

closes: #11

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 to Date for 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,
)
Comment thread src/omop_constructs/alchemy/episodes/surgical_joins.py
Comment thread docs/construct-catalog.md
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread src/omop_constructs/alchemy/episodes/treatment_envelope_query.py
Comment thread src/omop_constructs/alchemy/episodes/treatment_envelope_query.py
Comment thread src/omop_constructs/alchemy/episodes/surgical_joins.py
@gkennos gkennos merged commit b3a0be6 into main May 29, 2026
2 checks passed
@gkennos gkennos deleted the surgery_date_window branch May 29, 2026 03:30
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.

treatment envelope mat view calculation bug

2 participants