Skip to content

Commit 1c87525

Browse files
committed
Added note count filter using subquery against SUPPORTING_NOTES_T
1 parent f30f065 commit 1c87525

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

utils/oracle/mock_selection_builder.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,19 @@ def _add_join_to_surveillance_review(self):
9595
# Replace this with the one you want to test,
9696
# then use utils/oracle/test_subject_criteria_dev.py to run your scenarios
9797

98-
def _add_criteria_invited_since_age_extension(self) -> None:
98+
def _add_criteria_note_count(self) -> None:
9999
"""
100-
Filters subjects based on whether they were invited since age extension began.
100+
Filters subjects based on the count of associated supporting notes.
101101
"""
102102
try:
103-
self._add_join_to_latest_episode()
104-
value = InvitedSinceAgeExtension.from_description(self.criteria_value)
105-
clause = "EXISTS" if value == "yes" else "NOT EXISTS"
103+
# Assumes criteriaValue contains both comparator and numeric literal, e.g., '>= 2'
104+
comparator_clause = self.criteria_value.strip()
106105

107106
self.sql_where.append(
108-
f"AND {clause} (SELECT 'sagex' FROM screening_subject_attribute_t sagex "
109-
"INNER JOIN valid_values vvagex ON vvagex.valid_value_id = sagex.attribute_id "
110-
"AND vvagex.domain = 'FOBT_AGEX_LOWER_AGE' "
111-
"WHERE sagex.screening_subject_id = ep.screening_subject_id "
112-
"AND sagex.start_date < ep.episode_start_date)"
107+
"AND (SELECT COUNT(*) FROM SUPPORTING_NOTES_T snt "
108+
"WHERE snt.screening_subject_id = ss.screening_subject_id) "
109+
f"{comparator_clause}"
113110
)
111+
114112
except Exception:
115113
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
116-

utils/oracle/subject_selection_query_builder.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,6 +2082,23 @@ def _add_criteria_invited_since_age_extension(self) -> None:
20822082
except Exception:
20832083
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
20842084

2085+
def _add_criteria_note_count(self) -> None:
2086+
"""
2087+
Filters subjects based on the count of associated supporting notes.
2088+
"""
2089+
try:
2090+
# Assumes criteriaValue contains both comparator and numeric literal, e.g., '>= 2'
2091+
comparator_clause = self.criteria_value.strip()
2092+
2093+
self.sql_where.append(
2094+
"AND (SELECT COUNT(*) FROM SUPPORTING_NOTES_T snt "
2095+
"WHERE snt.screening_subject_id = ss.screening_subject_id) "
2096+
f"{comparator_clause}"
2097+
)
2098+
2099+
except Exception:
2100+
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
2101+
20852102
# ------------------------------------------------------------------------
20862103
# 🧬 CADS Clinical Dataset Filters
20872104
# ------------------------------------------------------------------------

utils/oracle/test_subject_criteria_dev.py

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

4343

44-
# === Test: INVITED_SINCE_AGE_EXTENSION (yes) ===
45-
b = make_builder(SubjectSelectionCriteriaKey.INVITED_SINCE_AGE_EXTENSION, "yes")
46-
b._add_criteria_invited_since_age_extension()
47-
print("=== INVITED_SINCE_AGE_EXTENSION (yes) ===")
48-
print(b.dump_sql(), end="\n\n")
49-
50-
# === Test: INVITED_SINCE_AGE_EXTENSION (no) ===
51-
b = make_builder(SubjectSelectionCriteriaKey.INVITED_SINCE_AGE_EXTENSION, "no")
52-
b._add_criteria_invited_since_age_extension()
53-
print("=== INVITED_SINCE_AGE_EXTENSION (no) ===")
44+
# === Test: NOTE_COUNT >= 2 ===
45+
b = make_builder(SubjectSelectionCriteriaKey.NOTE_COUNT, ">= 2")
46+
b._add_criteria_note_count()
47+
print("=== NOTE_COUNT >= 2 ===")
5448
print(b.dump_sql(), end="\n\n")

0 commit comments

Comments
 (0)