Skip to content

Commit 9c9c1c8

Browse files
committed
Added filter for presence of date-of-death removal record using rad_type_id
1 parent 0e68a6f commit 9c9c1c8

File tree

4 files changed

+65
-26
lines changed

4 files changed

+65
-26
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class HasDateOfDeathRemoval:
2+
"""
3+
Maps binary filter for presence of date-of-death removal record.
4+
"""
5+
6+
YES = "yes"
7+
NO = "no"
8+
9+
_valid_values = {YES, NO}
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(
16+
f"Invalid value for date-of-death removal filter: '{description}'"
17+
)
18+
return key

utils/oracle/mock_selection_builder.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,23 @@
99

1010

1111
# Add helper class stubs below
12-
class SurveillanceReviewCaseType:
13-
"""
14-
Maps surveillance review case type labels to valid value IDs.
15-
"""
12+
class HasDateOfDeathRemoval:
13+
YES = "yes"
14+
NO = "no"
1615

17-
_label_to_id = {
18-
"routine": 9401,
19-
"escalation": 9402,
20-
"clinical discussion": 9403,
21-
# Extend as needed
16+
_mapping = {
17+
"yes": YES,
18+
"no": NO,
2219
}
2320

2421
@classmethod
25-
def get_id(cls, description: str) -> int:
22+
def from_description(cls, description: str) -> str:
2623
key = description.strip().lower()
27-
if key not in cls._label_to_id:
28-
raise ValueError(f"Unknown surveillance review case type: '{description}'")
29-
return cls._label_to_id[key]
24+
if key not in cls._mapping:
25+
raise ValueError(
26+
f"Unknown input for HasDateOfDeathRemoval: '{description}'"
27+
)
28+
return cls._mapping[key]
3029

3130

3231
class MockSelectionBuilder:
@@ -95,16 +94,18 @@ def _add_join_to_surveillance_review(self):
9594
# Replace this with the one you want to test,
9695
# then use utils/oracle/test_subject_criteria_dev.py to run your scenarios
9796

98-
def _add_criteria_surveillance_review_type(self) -> None:
97+
def _add_criteria_has_date_of_death_removal(self) -> None:
9998
"""
100-
Filters subjects based on review_case_type_id in the surveillance review dataset.
99+
Filters subjects based on presence or absence of a date-of-death removal record.
101100
"""
102101
try:
103-
self._add_join_to_surveillance_review()
104-
type_id = SurveillanceReviewCaseType.get_id(self.criteria_value)
102+
value = HasDateOfDeathRemoval.from_description(self.criteria_value)
103+
clause = "EXISTS" if value == "yes" else "NOT EXISTS"
105104

106105
self.sql_where.append(
107-
f"AND sr.review_case_type_id {self.criteria_comparator} {type_id}"
106+
f"AND {clause} (SELECT 'dodr' FROM report_additional_data_t dodr "
107+
"WHERE dodr.rad_type_id = 15901 "
108+
"AND dodr.entity_id = c.contact_id)"
108109
)
109110

110111
except Exception:

utils/oracle/subject_selection_query_builder.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
DoesSubjectHaveSurveillanceReviewCase,
4545
)
4646
from classes.surveillance_review_case_type import SurveillanceReviewCaseType
47+
from classes.has_date_of_death_removal import HasDateOfDeathRemoval
4748

4849

4950
class SubjectSelectionQueryBuilder:
@@ -2044,6 +2045,23 @@ def _add_criteria_surveillance_review_type(self) -> None:
20442045
except Exception:
20452046
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
20462047

2048+
def _add_criteria_has_date_of_death_removal(self) -> None:
2049+
"""
2050+
Filters subjects based on presence or absence of a date-of-death removal record.
2051+
"""
2052+
try:
2053+
value = HasDateOfDeathRemoval.from_description(self.criteria_value)
2054+
clause = "EXISTS" if value == "yes" else "NOT EXISTS"
2055+
2056+
self.sql_where.append(
2057+
f"AND {clause} (SELECT 'dodr' FROM report_additional_data_t dodr "
2058+
"WHERE dodr.rad_type_id = 15901 "
2059+
"AND dodr.entity_id = c.contact_id)"
2060+
)
2061+
2062+
except Exception:
2063+
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
2064+
20472065
# ------------------------------------------------------------------------
20482066
# 🧬 CADS Clinical Dataset Filters
20492067
# ------------------------------------------------------------------------

utils/oracle/test_subject_criteria_dev.py

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

4343

44-
# === Test: SURVEILLANCE_REVIEW_CASE_TYPE (escalation) ===
45-
b = make_builder(
46-
SubjectSelectionCriteriaKey.SURVEILLANCE_REVIEW_CASE_TYPE,
47-
"escalation",
48-
comparator="=",
49-
)
50-
b._add_criteria_surveillance_review_type()
51-
print("=== SURVEILLANCE_REVIEW_CASE_TYPE (escalation) ===")
44+
# === Test: HAS_HAD_A_DATE_OF_DEATH_REMOVAL (yes) ===
45+
b = make_builder(SubjectSelectionCriteriaKey.HAS_HAD_A_DATE_OF_DEATH_REMOVAL, "yes")
46+
b._add_criteria_has_date_of_death_removal()
47+
print("=== HAS_HAD_A_DATE_OF_DEATH_REMOVAL (yes) ===")
48+
print(b.dump_sql(), end="\n\n")
49+
50+
# === Test: HAS_HAD_A_DATE_OF_DEATH_REMOVAL (no) ===
51+
b = make_builder(SubjectSelectionCriteriaKey.HAS_HAD_A_DATE_OF_DEATH_REMOVAL, "no")
52+
b._add_criteria_has_date_of_death_removal()
53+
print("=== HAS_HAD_A_DATE_OF_DEATH_REMOVAL (no) ===")
5254
print(b.dump_sql(), end="\n\n")

0 commit comments

Comments
 (0)