Skip to content

Commit 4c1109b

Browse files
committed
modailty treatment now linked to condition
1 parent b5ef8f4 commit 4c1109b

6 files changed

Lines changed: 93 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,7 @@
129129
- correcting fraction filter
130130

131131
## 0.3.17
132-
- modality treatment join
132+
- modality treatment join
133+
134+
## 0.3.18
135+
- modailty treatment now linked to condition

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "omop-constructs"
3-
version = "0.3.17"
3+
version = "0.3.18"
44
description = "For building complex constructs on top of the omop-alchemy library."
55
readme = "README.md"
66
authors = [

src/omop_constructs/alchemy/episodes/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from .fraction_mv import FractionMV
88
from .treatment_summary_mv import ConditionTreatmentEpisode
99
from .treatment_envelope_mv import TreatmentEnvelopeMV
10-
from .modality_intent_mv import EpisodeTreatmentMV
10+
from .modality_intent_mv import TreatmentIntentMV, ConditionTreatmentIntentMV
11+
1112
__all__ = [
1213
"OverarchingDiseaseEpisodeMV",
1314
"TreatmentRegimenCycleMV",
@@ -21,5 +22,6 @@
2122
"FractionMV",
2223
"ConditionTreatmentEpisode",
2324
"TreatmentEnvelopeMV",
24-
"EpisodeTreatmentMV",
25+
"TreatmentIntentMV",
26+
"ConditionTreatmentIntentMV",
2527
]

src/omop_constructs/alchemy/episodes/modality_intent_join.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
.distinct(Episode_Event.episode_id)
2222
.subquery()
2323
)
24+
2425
modality_rt = (
2526
sa.select(
2627
sa.literal(True).label('rt'),
@@ -39,11 +40,13 @@
3940
.distinct(Episode_Event.episode_id)
4041
.subquery()
4142
)
43+
4244
episode_intent = (
4345
sa.select(
4446
Episode.episode_id,
4547
Episode.episode_start_date,
4648
Episode.episode_end_date,
49+
Episode.episode_parent_id,
4750
Measurement.measurement_concept_id,
4851
intent_concept.concept_name,
4952
)
@@ -55,17 +58,21 @@
5558
)
5659
)
5760
.join(intent_concept, intent_concept.concept_id==Measurement.measurement_concept_id)
61+
.filter(
62+
Measurement.measurement_concept_id.in_(runtime.treatment_modifiers.treatment_intent.ids)
63+
)
5864
.subquery()
5965
)
6066

6167
episode_join = (
6268
sa.select(
6369
sa.func.row_number().over().label("mv_id"),
64-
episode_intent.c.episode_id,
65-
episode_intent.c.episode_start_date,
66-
episode_intent.c.episode_end_date,
67-
episode_intent.c.measurement_concept_id,
68-
episode_intent.c.concept_name,
70+
episode_intent.c.episode_id.label('treatment_episode_id'),
71+
episode_intent.c.episode_start_date.label('treatment_episode_start_date'),
72+
episode_intent.c.episode_end_date.label('treatment_episode_end_date'),
73+
episode_intent.c.episode_parent_id.label('treatment_episode_parent_id'),
74+
episode_intent.c.measurement_concept_id.label('treatment_intent_concept_id'),
75+
episode_intent.c.concept_name.label('treatment_intent_name'),
6976
modality_rt.c.rt,
7077
modality_sact.c.sact,
7178
sa.and_(

src/omop_constructs/alchemy/episodes/modality_intent_mv.py

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .modality_intent_join import episode_join
88

99
@register_construct
10-
class EpisodeTreatmentMV(
10+
class TreatmentIntentMV(
1111
MaterializedViewMixin,
1212
Base,
1313
):
@@ -21,13 +21,78 @@ class EpisodeTreatmentMV(
2121

2222
mv_id: so.Mapped[int] = so.mapped_column(sa.Integer, primary_key=True)
2323

24+
treatment_episode_id: so.Mapped[int] = so.mapped_column(sa.Integer)
25+
treatment_episode_start_date: so.Mapped[date] = so.mapped_column(sa.Date)
26+
treatment_episode_end_date: so.Mapped[date] = so.mapped_column(sa.Date)
27+
treatment_episode_parent_id: so.Mapped[int] = so.mapped_column(sa.Integer)
28+
29+
treatment_intent_concept_id: so.Mapped[int] = so.mapped_column(sa.Integer)
30+
treatment_intent_name: so.Mapped[str] = so.mapped_column(sa.String)
31+
32+
rt: so.Mapped[bool | None] = so.mapped_column(sa.Boolean)
33+
sact: so.Mapped[bool | None] = so.mapped_column(sa.Boolean)
34+
concurrent: so.Mapped[bool] = so.mapped_column(sa.Boolean)
35+
36+
37+
from .condition_episode_mv import ConditionEpisodeMV
38+
39+
episode_summary_select = (
40+
sa.select(
41+
ConditionEpisodeMV.episode_id,
42+
ConditionEpisodeMV.person_id,
43+
44+
ConditionEpisodeMV.episode_concept_id,
45+
ConditionEpisodeMV.episode_label,
46+
47+
ConditionEpisodeMV.episode_start_date,
48+
ConditionEpisodeMV.episode_end_date,
49+
50+
TreatmentIntentMV.treatment_episode_id,
51+
TreatmentIntentMV.treatment_episode_start_date,
52+
TreatmentIntentMV.treatment_episode_end_date,
53+
TreatmentIntentMV.treatment_intent_concept_id,
54+
TreatmentIntentMV.treatment_intent_name,
55+
56+
sa.func.coalesce(TreatmentIntentMV.rt, False).label("rt"),
57+
sa.func.coalesce(TreatmentIntentMV.sact, False).label("sact"),
58+
sa.func.coalesce(TreatmentIntentMV.concurrent, False).label("concurrent"),
59+
)
60+
.outerjoin(
61+
TreatmentIntentMV,
62+
TreatmentIntentMV.treatment_episode_parent_id
63+
== ConditionEpisodeMV.episode_id
64+
)
65+
)
66+
67+
@register_construct
68+
class ConditionTreatmentIntentMV(
69+
MaterializedViewMixin,
70+
Base,
71+
):
72+
__mv_name__ = "episode_treatment_mv"
73+
__mv_select__ = episode_summary_select
74+
__mv_index__ = "episode_id"
75+
__deps__ = (ConditionEpisodeMV.__mv_name__, TreatmentIntentMV.__mv_name__)
76+
__tablename__ = __mv_name__
77+
__table_args__ = {"extend_existing": True}
78+
79+
mv_id: so.Mapped[int] = so.mapped_column(sa.Integer, primary_key=True)
80+
2481
episode_id: so.Mapped[int] = so.mapped_column(sa.Integer)
82+
person_id: so.Mapped[int] = so.mapped_column(sa.Integer)
83+
84+
episode_concept_id: so.Mapped[int] = so.mapped_column(sa.Integer)
85+
episode_label: so.Mapped[str] = so.mapped_column(sa.String)
86+
2587
episode_start_date: so.Mapped[date] = so.mapped_column(sa.Date)
2688
episode_end_date: so.Mapped[date] = so.mapped_column(sa.Date)
2789

28-
measurement_concept_id: so.Mapped[int] = so.mapped_column(sa.Integer)
29-
concept_name: so.Mapped[str] = so.mapped_column(sa.String)
90+
treatment_episode_id: so.Mapped[int | None] = so.mapped_column(sa.Integer, nullable=True)
91+
treatment_episode_start_date: so.Mapped[date | None] = so.mapped_column(sa.Date, nullable=True)
92+
treatment_episode_end_date: so.Mapped[date | None] = so.mapped_column(sa.Date, nullable=True)
93+
treatment_intent_concept_id: so.Mapped[int | None] = so.mapped_column(sa.Integer, nullable=True)
94+
treatment_intent_name: so.Mapped[str | None] = so.mapped_column(sa.String, nullable=True)
3095

31-
rt: so.Mapped[bool | None] = so.mapped_column(sa.Boolean)
32-
sact: so.Mapped[bool | None] = so.mapped_column(sa.Boolean)
33-
concurrent: so.Mapped[bool] = so.mapped_column(sa.Boolean)
96+
rt: so.Mapped[bool | None] = so.mapped_column(sa.Boolean, nullable=True)
97+
sact: so.Mapped[bool | None] = so.mapped_column(sa.Boolean, nullable=True)
98+
concurrent: so.Mapped[bool | None] = so.mapped_column(sa.Boolean, nullable=True)

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)