Skip to content

Commit 10c9e4c

Browse files
committed
Added DiagnosticTestIsVoid mapping class and criteria method for filtering voided diagnostic tests
1 parent 1ced119 commit 10c9e4c

File tree

4 files changed

+65
-43
lines changed

4 files changed

+65
-43
lines changed

classes/diagnostic_test_is_void.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class DiagnosticTestIsVoid:
2+
"""
3+
Maps descriptive yes/no flags to test void state checks.
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(f"Unknown test void flag: '{description}'")
16+
return key

utils/oracle/mock_selection_builder.py

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@
77

88

99
# Add helper class stubs below
10-
class DiagnosticTestType:
10+
class DiagnosticTestIsVoid:
1111
"""
12-
Mock mapping of diagnostic test type names to valid value IDs.
12+
Maps yes/no descriptions to boolean flags for test void criteria.
1313
"""
1414

15+
YES = "yes"
16+
NO = "no"
17+
1518
_mapping = {
16-
"pcr": 3001,
17-
"antigen": 3002,
18-
"lateral flow": 3003,
19+
"yes": YES,
20+
"no": NO,
1921
}
2022

2123
@classmethod
22-
def get_valid_value_id(cls, description: str) -> int:
24+
def from_description(cls, description: str) -> str:
2325
key = description.strip().lower()
2426
if key not in cls._mapping:
25-
raise ValueError(f"Unknown diagnostic test type: {description}")
27+
raise ValueError(f"Unknown void flag: {description}")
2628
return cls._mapping[key]
2729

2830

@@ -73,35 +75,22 @@ def _add_join_to_latest_episode(self) -> None:
7375
# Replace this with the one you want to test,
7476
# then use utils/oracle/test_subject_criteria_dev.py to run your scenarios
7577

76-
def _add_criteria_diagnostic_test_type(self, proposed_or_confirmed: str) -> None:
78+
def _add_criteria_diagnostic_test_is_void(self) -> None:
7779
"""
78-
Filters diagnostic tests by type—proposed or confirmed.
79-
Requires prior join to external_tests_t (xt aliasing assumed).
80+
Adds WHERE clause to check whether diagnostic test is voided ('Y' or 'N').
81+
Requires prior join to external_tests_t using alias xtN.
8082
"""
8183
try:
8284
idx = getattr(self, "criteria_index", 0)
8385
xt = f"xt{idx}"
86+
value = DiagnosticTestIsVoid.from_description(self.criteria_value)
8487

85-
if proposed_or_confirmed == "proposed":
86-
column = f"{xt}.proposed_type_id"
87-
elif proposed_or_confirmed == "confirmed":
88-
column = f"{xt}.confirmed_type_id"
89-
else:
90-
raise SelectionBuilderException(
91-
self.criteria_key_name, self.criteria_value
92-
)
93-
94-
self.sql_where.append(f"AND {column} ")
95-
96-
value = self.criteria_value.strip().lower()
97-
if value == "null":
98-
self.sql_where.append("IS NULL")
99-
elif value == "not null":
100-
self.sql_where.append("IS NOT NULL")
88+
if value == DiagnosticTestIsVoid.YES:
89+
self.sql_where.append(f"AND {xt}.void = 'Y'")
90+
elif value == DiagnosticTestIsVoid.NO:
91+
self.sql_where.append(f"AND {xt}.void = 'N'")
10192
else:
102-
comparator = self.criteria_comparator
103-
type_id = DiagnosticTestType.get_valid_value_id(self.criteria_value)
104-
self.sql_where.append(f"{comparator} {type_id}")
93+
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
10594

10695
except Exception:
10796
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)

utils/oracle/subject_selection_query_builder.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from classes.appointment_status_type import AppointmentStatusType
3030
from classes.which_diagnostic_test import WhichDiagnosticTest
3131
from classes.diagnostic_test_type import DiagnosticTestType
32+
from classes.diagnostic_test_is_void import DiagnosticTestIsVoid
3233

3334

3435
class SubjectSelectionQueryBuilder:
@@ -1724,6 +1725,28 @@ def _add_criteria_diagnostic_test_type(self, proposed_or_confirmed: str) -> None
17241725
except Exception:
17251726
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
17261727

1728+
def _add_criteria_diagnostic_test_is_void(self) -> None:
1729+
"""
1730+
Adds WHERE clause to check whether diagnostic test is voided ('Y' or 'N').
1731+
Requires prior join to external_tests_t using alias xtN.
1732+
"""
1733+
try:
1734+
idx = getattr(self, "criteria_index", 0)
1735+
xt = f"xt{idx}"
1736+
value = DiagnosticTestIsVoid.from_description(self.criteria_value)
1737+
1738+
if value == DiagnosticTestIsVoid.YES:
1739+
self.sql_where.append(f"AND {xt}.void = 'Y'")
1740+
elif value == DiagnosticTestIsVoid.NO:
1741+
self.sql_where.append(f"AND {xt}.void = 'N'")
1742+
else:
1743+
raise SelectionBuilderException(
1744+
self.criteria_key_name, self.criteria_value
1745+
)
1746+
1747+
except Exception:
1748+
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
1749+
17271750
# ------------------------------------------------------------------------
17281751
# 🧬 CADS Clinical Dataset Filters
17291752
# ------------------------------------------------------------------------

utils/oracle/test_subject_criteria_dev.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,14 @@ def make_builder(key, value, index=0):
3737
return b
3838

3939

40-
# === Test: DIAGNOSTIC_TEST_CONFIRMED_TYPE (valid value) ===
41-
b = make_builder(SubjectSelectionCriteriaKey.DIAGNOSTIC_TEST_CONFIRMED_TYPE, "PCR")
42-
b._add_criteria_diagnostic_test_type("confirmed")
43-
print("=== DIAGNOSTIC_TEST_CONFIRMED_TYPE (valid value) ===")
40+
# === Test: DIAGNOSTIC_TEST_IS_VOID ===
41+
b = make_builder(SubjectSelectionCriteriaKey.DIAGNOSTIC_TEST_IS_VOID, "yes")
42+
b._add_criteria_diagnostic_test_is_void()
43+
print("=== DIAGNOSTIC_TEST_IS_VOID ===")
4444
print(b.dump_sql(), end="\n\n")
4545

46-
# === Test: DIAGNOSTIC_TEST_PROPOSED_TYPE (null) ===
47-
b = make_builder(SubjectSelectionCriteriaKey.DIAGNOSTIC_TEST_PROPOSED_TYPE, "null")
48-
b._add_criteria_diagnostic_test_type("proposed")
49-
print("=== DIAGNOSTIC_TEST_PROPOSED_TYPE (null) ===")
50-
print(b.dump_sql(), end="\n\n")
51-
52-
# === Test: DIAGNOSTIC_TEST_PROPOSED_TYPE (not null) ===
53-
b = make_builder(SubjectSelectionCriteriaKey.DIAGNOSTIC_TEST_PROPOSED_TYPE, "not null")
54-
b._add_criteria_diagnostic_test_type("proposed")
55-
print("=== DIAGNOSTIC_TEST_PROPOSED_TYPE (not null) ===")
46+
# === Test: DIAGNOSTIC_TEST_IS_VOID (not void) ===
47+
b = make_builder(SubjectSelectionCriteriaKey.DIAGNOSTIC_TEST_IS_VOID, "no", index=1)
48+
b._add_criteria_diagnostic_test_is_void()
49+
print("=== DIAGNOSTIC_TEST_IS_VOID (not void) ===")
5650
print(b.dump_sql(), end="\n\n")

0 commit comments

Comments
 (0)