Skip to content

Commit 84e5713

Browse files
committed
Added _add_criteria_subject_lower_lynch_age method
1 parent 95b6e76 commit 84e5713

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

utils/oracle/mock_selection_builder.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
import os
44

55
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
6-
# print("PYTHONPATH set to:", sys.path[0]) # Uncomment for local debug
76
from classes.selection_builder_exception import SelectionBuilderException
87

98

109
class MockSelectionBuilder:
1110
"""
1211
Lightweight test harness that mimics SubjectSelectionQueryBuilder behavior.
1312
14-
This class is meant for local testing of SQL fragment builders without the full
15-
application context. Developers can copy/paste individual _add_criteria_* methods
16-
from the real builder and test inputs/outputs directly.
13+
This class is used for local testing of SQL fragment builder methods without requiring
14+
the full application context. Developers can reimplement individual _add_criteria_*
15+
methods here for isolated evaluation.
1716
1817
Usage:
19-
- Create an instance with a criteria key and value
20-
- Call the appropriate criteria builder method
21-
- Use dump_sql() to inspect the resulting SQL
18+
- Add your _add_criteria_* method to this class
19+
- Then create tests in utils/oracle/test_subject_criteria_dev.py to run it
20+
- Use dump_sql() to inspect the generated SQL fragment
2221
"""
2322

2423
def __init__(self, criteria_key, criteria_value, criteria_comparator=">="):
@@ -28,31 +27,30 @@ def __init__(self, criteria_key, criteria_value, criteria_comparator=">="):
2827
self.criteria_comparator = criteria_comparator
2928
self.sql_where = []
3029

31-
# === Example testable method ===
30+
def dump_sql(self):
31+
return "\n".join(self.sql_where)
32+
33+
# === Example testable method below ===
3234
# Replace this with the one you want to test,
3335
# then use utils/oracle/test_subject_criteria_dev.py to run your scenarios
3436

35-
def _add_criteria_subject_lower_fobt_age(self) -> None:
37+
def _add_criteria_subject_lower_lynch_age(self) -> None:
3638
"""
37-
Adds a SQL constraint that compares a subject's lower FOBT age eligibility
38-
using a comparator and a value (e.g. '>= 55' or '>= default').
39+
Adds a SQL constraint for Lynch syndrome lower-age eligibility.
3940
40-
If value is 'default', it's replaced with a national parameter lookup:
41-
pkg_parameters.f_get_national_param_val(10)
41+
If value is 'default', it's replaced with '35'.
42+
Uses comparator to build the WHERE clause.
4243
"""
4344
try:
4445
value = self.criteria_value
4546
comparator = self.criteria_comparator
4647

4748
if value.lower() == "default":
48-
value = "pkg_parameters.f_get_national_param_val (10)"
49+
value = "35"
4950

5051
self.sql_where.append(
51-
f"AND pkg_bcss_common.f_get_ss_lower_age_limit (ss.screening_subject_id) "
52+
f"AND pkg_bcss_common.f_get_lynch_lower_age_limit (ss.screening_subject_id) "
5253
f"{comparator} {value}"
5354
)
5455
except Exception:
5556
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
56-
57-
def dump_sql(self):
58-
return "\n".join(self.sql_where)

utils/oracle/subject_selection_query_builder.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,27 @@ def _add_criteria_subject_lower_fobt_age(self) -> None:
643643
except Exception:
644644
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
645645

646+
def _add_criteria_subject_lower_lynch_age(self) -> None:
647+
"""
648+
Adds a SQL constraint for Lynch syndrome lower-age eligibility.
649+
650+
If value is 'default', it's replaced with '35'.
651+
Uses comparator to build the WHERE clause.
652+
"""
653+
try:
654+
value = self.criteria_value
655+
comparator = self.criteria_comparator
656+
657+
if value.lower() == "default":
658+
value = "35"
659+
660+
self.sql_where.append(
661+
f"AND pkg_bcss_common.f_get_lynch_lower_age_limit (ss.screening_subject_id) "
662+
f"{comparator} {value}"
663+
)
664+
except Exception:
665+
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
666+
646667
def _add_criteria_subject_hub_code(self, user: "User") -> None:
647668
hub_code = None
648669
try:

0 commit comments

Comments
 (0)