Skip to content

Commit 9676b5f

Browse files
Code change is implemented for JIRA Ticket - BCSS - 20615 - Selenium to Playwright - Regression Tests - Subject Episodes - Diagnosis Date
1 parent 08be31f commit 9676b5f

File tree

1 file changed

+23
-46
lines changed

1 file changed

+23
-46
lines changed

utils/oracle/subject_selection_query_builder.py

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from classes.selection_builder_exception import SelectionBuilderException
2929
from classes.appointments_slot_type import AppointmentSlotType
3030
from classes.appointment_status_type import AppointmentStatusType
31+
from classes.diagnosis_date_reason_type import DiagnosisDateReasonType
3132
from classes.which_diagnostic_test import WhichDiagnosticTest
3233
from classes.diagnostic_test_type import DiagnosticTestType
3334
from classes.diagnostic_test_is_void import DiagnosticTestIsVoid
@@ -739,30 +740,18 @@ def _add_criteria_latest_episode_type(self) -> None:
739740
Translates a human-readable episode type string into an internal numeric ID.
740741
"""
741742
try:
742-
value = self.criteria_value.lower()
743-
comparator = self.criteria_comparator
744-
745-
# Simulate EpisodeType enum mapping
746-
episode_type_map = {
747-
"referral": 1,
748-
"invitation": 2,
749-
"test_kit_sent": 3,
750-
"reminder": 4,
751-
"episode_end": 5,
752-
# Add more mappings as needed
753-
}
754-
755-
if value not in episode_type_map:
756-
raise ValueError(f"Unknown episode type: {value}")
757-
758-
episode_type_id = episode_type_map[value]
743+
episode_type = EpisodeType.by_description_case_insensitive(
744+
self.criteria_value
745+
)
746+
if episode_type is None:
747+
raise SelectionBuilderException(
748+
self.criteria_key_name, self.criteria_value
749+
)
759750

760-
# Simulate the required join (docs only—no real SQL execution here)
761-
# In real builder this would ensure join to 'latest_episode' alias (ep)
751+
self._add_join_to_latest_episode()
762752
self.sql_where.append(
763-
f"AND ep.episode_type_id {comparator} {episode_type_id}"
753+
f" AND ep.episode_type_id {self.criteria_comparator}{episode_type.valid_value_id}"
764754
)
765-
766755
except Exception:
767756
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
768757

@@ -816,6 +805,9 @@ def _add_criteria_latest_episode_status(self) -> None:
816805
"pending": 102,
817806
"cancelled": 103,
818807
"invalid": 104,
808+
"open": 11352,
809+
"closed": 11353,
810+
"paused": 11354,
819811
# Add actual mappings as needed
820812
}
821813

@@ -1206,34 +1198,19 @@ def _add_criteria_has_diagnostic_test(self, latest_episode_only: bool) -> None:
12061198

12071199
def _add_criteria_diagnosis_date_reason(self) -> None:
12081200
"""
1209-
Adds a filter on ep.diagnosis_date_reason_id.
1210-
Supports symbolic matches (via ID) and special values: NULL, NOT_NULL.
1201+
Adds a SQL WHERE clause for the latest episode's diagnosis_date_reason_id based on self.criteria_value.
1202+
Assumes self.sql_where, self.criteria_comparator, and self.criteria_value are set.
12111203
"""
12121204
try:
1213-
value = self.criteria_value.strip().lower()
1214-
comparator = self.criteria_comparator
1215-
1216-
# Simulated DiagnosisDateReasonType
1217-
reason_map = {
1218-
"patient informed": 900,
1219-
"clinician notified": 901,
1220-
"screening outcome": 902,
1221-
"null": "NULL",
1222-
"not_null": "NOT NULL",
1223-
# Extend as needed
1224-
}
1225-
1226-
if value not in reason_map:
1227-
raise ValueError(f"Unknown diagnosis date reason: {value}")
1228-
1229-
resolved = reason_map[value]
1230-
if resolved in ("NULL", "NOT NULL"):
1231-
self.sql_where.append(f"AND ep.diagnosis_date_reason_id IS {resolved}")
1205+
diagnosis_date_reason = DiagnosisDateReasonType.by_description_case_insensitive(self.criteria_value)
1206+
if diagnosis_date_reason is None:
1207+
raise ValueError(f"Unknown diagnosis date reason: {self.criteria_value}")
1208+
self._add_join_to_latest_episode()
1209+
self.sql_where.append(" AND ep.diagnosis_date_reason_id ")
1210+
if diagnosis_date_reason in (DiagnosisDateReasonType.NULL, DiagnosisDateReasonType.NOT_NULL):
1211+
self.sql_where.append(f" IS {diagnosis_date_reason.get_description()}")
12321212
else:
1233-
self.sql_where.append(
1234-
f"AND ep.diagnosis_date_reason_id {comparator} {resolved}"
1235-
)
1236-
1213+
self.sql_where.append(f"{self.criteria_comparator}{diagnosis_date_reason.get_valid_value_id()}")
12371214
except Exception:
12381215
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
12391216

0 commit comments

Comments
 (0)