Skip to content

Commit 0e68a6f

Browse files
committed
Added surveillance review case type filter using review_case_type_id mapping
1 parent df37956 commit 0e68a6f

File tree

4 files changed

+58
-31
lines changed

4 files changed

+58
-31
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class SurveillanceReviewCaseType:
2+
"""
3+
Maps surveillance review case type labels to valid value IDs.
4+
"""
5+
6+
_label_to_id = {
7+
"routine": 9401,
8+
"escalation": 9402,
9+
"clinical discussion": 9403,
10+
# Extend with additional mappings as needed
11+
}
12+
13+
@classmethod
14+
def get_id(cls, description: str) -> int:
15+
key = description.strip().lower()
16+
if key not in cls._label_to_id:
17+
raise ValueError(f"Unknown review case type: '{description}'")
18+
return cls._label_to_id[key]

utils/oracle/mock_selection_builder.py

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

1010

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

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

2124
@classmethod
22-
def from_description(cls, description: str) -> str:
25+
def get_id(cls, description: str) -> int:
2326
key = description.strip().lower()
24-
if key not in cls._mapping:
25-
raise ValueError(
26-
f"Unknown surveillance review case presence: '{description}'"
27-
)
28-
return cls._mapping[key]
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]
2930

3031

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

97-
def _add_criteria_does_subject_have_surveillance_review_case(self) -> None:
98+
def _add_criteria_surveillance_review_type(self) -> None:
9899
"""
99-
Filters subjects based on presence or absence of a surveillance review case.
100+
Filters subjects based on review_case_type_id in the surveillance review dataset.
100101
"""
101102
try:
102-
value = DoesSubjectHaveSurveillanceReviewCase.from_description(self.criteria_value)
103-
104-
clause = "AND EXISTS" if value == "yes" else "AND NOT EXISTS"
103+
self._add_join_to_surveillance_review()
104+
type_id = SurveillanceReviewCaseType.get_id(self.criteria_value)
105105

106106
self.sql_where.append(
107-
f"{clause} (SELECT 'sr' FROM surveillance_review sr "
108-
"WHERE sr.subject_id = ss.screening_subject_id)"
107+
f"AND sr.review_case_type_id {self.criteria_comparator} {type_id}"
109108
)
110109

111110
except Exception:

utils/oracle/subject_selection_query_builder.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from classes.does_subject_have_surveillance_review_case import (
4444
DoesSubjectHaveSurveillanceReviewCase,
4545
)
46+
from classes.surveillance_review_case_type import SurveillanceReviewCaseType
4647

4748

4849
class SubjectSelectionQueryBuilder:
@@ -2028,6 +2029,21 @@ def _add_criteria_does_subject_have_surveillance_review_case(self) -> None:
20282029
except Exception:
20292030
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
20302031

2032+
def _add_criteria_surveillance_review_type(self) -> None:
2033+
"""
2034+
Filters subjects based on review_case_type_id in the surveillance review dataset.
2035+
"""
2036+
try:
2037+
self._add_join_to_surveillance_review()
2038+
type_id = SurveillanceReviewCaseType.get_id(self.criteria_value)
2039+
2040+
self.sql_where.append(
2041+
f"AND sr.review_case_type_id {self.criteria_comparator} {type_id}"
2042+
)
2043+
2044+
except Exception:
2045+
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
2046+
20312047
# ------------------------------------------------------------------------
20322048
# 🧬 CADS Clinical Dataset Filters
20332049
# ------------------------------------------------------------------------

utils/oracle/test_subject_criteria_dev.py

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

4343

44-
# === Test: HAS_EXISTING_SURVEILLANCE_REVIEW_CASE (yes) ===
44+
# === Test: SURVEILLANCE_REVIEW_CASE_TYPE (escalation) ===
4545
b = make_builder(
46-
SubjectSelectionCriteriaKey.HAS_EXISTING_SURVEILLANCE_REVIEW_CASE, "yes"
46+
SubjectSelectionCriteriaKey.SURVEILLANCE_REVIEW_CASE_TYPE,
47+
"escalation",
48+
comparator="=",
4749
)
48-
b._add_criteria_does_subject_have_surveillance_review_case()
49-
print("=== HAS_EXISTING_SURVEILLANCE_REVIEW_CASE (yes) ===")
50-
print(b.dump_sql(), end="\n\n")
51-
52-
# === Test: HAS_EXISTING_SURVEILLANCE_REVIEW_CASE (no) ===
53-
b = make_builder(
54-
SubjectSelectionCriteriaKey.HAS_EXISTING_SURVEILLANCE_REVIEW_CASE, "no", index=1
55-
)
56-
b._add_criteria_does_subject_have_surveillance_review_case()
57-
print("=== HAS_EXISTING_SURVEILLANCE_REVIEW_CASE (no) ===")
50+
b._add_criteria_surveillance_review_type()
51+
print("=== SURVEILLANCE_REVIEW_CASE_TYPE (escalation) ===")
5852
print(b.dump_sql(), end="\n\n")

0 commit comments

Comments
 (0)