Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,7 @@
- added primary diagnosis condition mv, registry compile/drift checks, postgres CI coverage, and schema snapshot artifact export

## 0.4.7
- fixed treatment envelope window issues
- fixed treatment envelope window issues

## 0.4.8
- treatment envelope should left join to death (bug fix)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "omop-constructs"
version = "0.4.7"
version = "0.4.8"
description = "For building complex constructs on top of the omop-alchemy library."
readme = "README.md"
authors = [
Expand Down
14 changes: 10 additions & 4 deletions src/omop_constructs/alchemy/episodes/treatment_envelope_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,18 @@


# ---------------------------------------------------------------------------
# treatment_envelope — person-level envelope joined to death
# treatment_envelope — condition-episode spine joined to death
# ---------------------------------------------------------------------------
# The spine is treatment_window (rooted at ModifiedCondition / ConditionEpisodeMV)
# so that every condition episode appears regardless of mortality status.
# Death is outer-joined on person_id to attach death_datetime where it exists.
# Using Death as the spine instead would silently exclude all living patients —
# treatment timing scalars such as days_from_dx_to_treatment are meaningful for
# the full cohort, not only for those with a death record.
treatment_envelope = (
sa.select(
sa.func.row_number().over().label('mv_id'),
Death.person_id,
treatment_window.c.person_id,
treatment_window.c.condition_episode,
treatment_window.c.condition_start_date,
treatment_window.c.concurrent_chemort,
Expand Down Expand Up @@ -135,8 +141,8 @@
).label('latest_treatment'),
Death.death_datetime,
)
.select_from(Death)
.join(treatment_window, treatment_window.c.person_id == Death.person_id, isouter=True)
.select_from(treatment_window)
.join(Death, Death.person_id == treatment_window.c.person_id, isouter=True)
.subquery()
)

Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading