Skip to content

Commit 5aeb1fb

Browse files
committed
Added FOBT prevalent/incident episode status filter using symbolic NULL checks
1 parent 6345048 commit 5aeb1fb

File tree

4 files changed

+50
-29
lines changed

4 files changed

+50
-29
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class PrevalentIncidentStatusType:
2+
"""
3+
Maps symbolic values for FOBT prevalent/incident episode classification.
4+
"""
5+
6+
PREVALENT = "prevalent"
7+
INCIDENT = "incident"
8+
9+
_valid_values = {PREVALENT, INCIDENT}
10+
11+
@classmethod
12+
def from_description(cls, description: str) -> str:
13+
key = description.strip().lower()
14+
if key not in cls._valid_values:
15+
raise ValueError(f"Unknown FOBT episode status: '{description}'")
16+
return key

utils/oracle/mock_selection_builder.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,21 @@ def __init__(self, lynch_due_date_change_reason_id):
1414
self.lynch_due_date_change_reason_id = lynch_due_date_change_reason_id
1515

1616

17-
class LynchIncidentEpisodeType:
17+
class PrevalentIncidentStatusType:
1818
"""
19-
Maps symbolic criteria values for Lynch incident episode linkage.
19+
Maps symbolic values for FOBT prevalent/incident episode classification.
2020
"""
2121

22-
NULL = "null"
23-
NOT_NULL = "not_null"
24-
LATEST_EPISODE = "latest_episode"
25-
EARLIER_EPISODE = "earlier_episode"
22+
PREVALENT = "prevalent"
23+
INCIDENT = "incident"
2624

27-
_symbolics = {NULL, NOT_NULL, LATEST_EPISODE, EARLIER_EPISODE}
25+
_valid_values = {PREVALENT, INCIDENT}
2826

2927
@classmethod
3028
def from_description(cls, description: str) -> str:
3129
key = description.strip().lower()
32-
if key not in cls._symbolics:
33-
raise ValueError(
34-
f"Unknown Lynch incident episode criteria: '{description}'"
35-
)
30+
if key not in cls._valid_values:
31+
raise ValueError(f"Unknown FOBT episode status: '{description}'")
3632
return key
3733

3834

@@ -106,26 +102,18 @@ def _add_join_to_surveillance_review(self):
106102
# Replace this with the one you want to test,
107103
# then use utils/oracle/test_subject_criteria_dev.py to run your scenarios
108104

109-
def _add_criteria_lynch_incident_episode(self) -> None:
105+
def _add_criteria_fobt_prevalent_incident_status(self) -> None:
110106
"""
111-
Filters based on linkage to a Lynch incident episode.
107+
Filters subjects by whether their FOBT episode is prevalent or incident.
112108
"""
113109
try:
114-
self._add_join_to_latest_episode()
115-
column = "ss.lynch_incident_subject_epis_id"
116-
value = LynchIncidentEpisodeType.from_description(self.criteria_value)
110+
value = PrevalentIncidentStatusType.from_description(self.criteria_value)
111+
column = "ss.fobt_incident_subject_epis_id"
117112

118-
if value == LynchIncidentEpisodeType.NULL:
113+
if value == PrevalentIncidentStatusType.PREVALENT:
119114
self.sql_where.append(f"AND {column} IS NULL")
120-
121-
elif value == LynchIncidentEpisodeType.NOT_NULL:
115+
elif value == PrevalentIncidentStatusType.INCIDENT:
122116
self.sql_where.append(f"AND {column} IS NOT NULL")
123117

124-
elif value == LynchIncidentEpisodeType.LATEST_EPISODE:
125-
self.sql_where.append(f"AND {column} = ep.subject_epis_id")
126-
127-
elif value == LynchIncidentEpisodeType.EARLIER_EPISODE:
128-
self.sql_where.append(f"AND {column} < ep.subject_epis_id")
129-
130118
except Exception:
131119
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)

utils/oracle/subject_selection_query_builder.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from classes.lynch_incident_episode_type import (
5454
LynchIncidentEpisodeType,
5555
)
56+
from classes.prevalent_incident_status_type import PrevalentIncidentStatusType
5657

5758

5859
class SubjectSelectionQueryBuilder:
@@ -2230,6 +2231,22 @@ def _add_criteria_lynch_incident_episode(self) -> None:
22302231
except Exception:
22312232
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
22322233

2234+
def _add_criteria_fobt_prevalent_incident_status(self) -> None:
2235+
"""
2236+
Filters subjects by whether their FOBT episode is prevalent or incident.
2237+
"""
2238+
try:
2239+
value = PrevalentIncidentStatusType.from_description(self.criteria_value)
2240+
column = "ss.fobt_incident_subject_epis_id"
2241+
2242+
if value == PrevalentIncidentStatusType.PREVALENT:
2243+
self.sql_where.append(f"AND {column} IS NULL")
2244+
elif value == PrevalentIncidentStatusType.INCIDENT:
2245+
self.sql_where.append(f"AND {column} IS NOT NULL")
2246+
2247+
except Exception:
2248+
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
2249+
22332250
# ------------------------------------------------------------------------
22342251
# 🧬 CADS Clinical Dataset Filters
22352252
# ------------------------------------------------------------------------

utils/oracle/test_subject_criteria_dev.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def make_builder(key, value, index=0, comparator="="):
4141
return b
4242

4343

44-
# === Test: LYNCH_INCIDENT_EPISODE (earlier_episode) ===
45-
b = make_builder(SubjectSelectionCriteriaKey.LYNCH_INCIDENT_EPISODE, "earlier_episode")
46-
b._add_criteria_lynch_incident_episode()
47-
print("=== LYNCH_INCIDENT_EPISODE (earlier_episode) ===")
44+
# === Test: FOBT_PREVALENT_INCIDENT_STATUS (incident) ===
45+
b = make_builder(SubjectSelectionCriteriaKey.FOBT_PREVALENT_INCIDENT_STATUS, "incident")
46+
b._add_criteria_fobt_prevalent_incident_status()
47+
print("=== FOBT_PREVALENT_INCIDENT_STATUS (incident) ===")
4848
print(b.dump_sql(), end="\n\n")

0 commit comments

Comments
 (0)