|
6 | 6 | from classes.selection_builder_exception import SelectionBuilderException |
7 | 7 |
|
8 | 8 |
|
| 9 | +# Add helper class stubs below |
| 10 | +class AppointmentSlotType: |
| 11 | + """ |
| 12 | + Mocked appointment slot type mapping for test purposes. |
| 13 | + Replace IDs with real values from production enum if needed. |
| 14 | + """ |
| 15 | + |
| 16 | + _mapping = { |
| 17 | + "clinic": 1001, |
| 18 | + "phone": 1002, |
| 19 | + "video": 1003, |
| 20 | + } |
| 21 | + |
| 22 | + @classmethod |
| 23 | + def get_id(cls, description: str) -> int: |
| 24 | + key = description.strip().lower() |
| 25 | + if key not in cls._mapping: |
| 26 | + raise ValueError(f"Unknown appointment slot type: {description}") |
| 27 | + return cls._mapping[key] |
| 28 | + |
| 29 | + |
9 | 30 | class MockSelectionBuilder: |
10 | 31 | """ |
11 | 32 | Lightweight test harness that mimics SubjectSelectionQueryBuilder behavior. |
@@ -52,47 +73,21 @@ def _add_join_to_latest_episode(self) -> None: |
52 | 73 | # Replace this with the one you want to test, |
53 | 74 | # then use utils/oracle/test_subject_criteria_dev.py to run your scenarios |
54 | 75 |
|
55 | | - def _add_join_to_appointments(self) -> None: |
| 76 | + def _add_criteria_appointment_type(self) -> None: |
56 | 77 | """ |
57 | | - Adds join to appointment_t table based on appointment selection strategy. |
58 | | - Requires prior join to latest episode (ep). Aliases the appointment table as 'ap'. |
59 | | -
|
60 | | - Accepts values: |
61 | | - - "any_appointment_in_latest_episode" |
62 | | - - "latest_appointment_in_latest_episode" |
63 | | - - "earlier_appointment_in_latest_episode" |
64 | | - - "later_appointment_in_latest_episode" |
| 78 | + Filters appointments by slot type (e.g. clinic, phone). |
| 79 | + Requires prior join to appointment_t as alias 'ap' (via WHICH_APPOINTMENT). |
| 80 | +
|
| 81 | + Uses comparator and resolves slot type label to ID via AppointmentSlotType. |
65 | 82 | """ |
66 | 83 | try: |
67 | | - value = self.criteria_value.strip().lower() |
68 | | - ap_alias = "ap" |
69 | | - apr_alias = "ap_prev" # Simulated prior alias for test support |
| 84 | + comparator = self.criteria_comparator |
| 85 | + value = self.criteria_value.strip() |
| 86 | + slot_type_id = AppointmentSlotType.get_id(value) |
70 | 87 |
|
71 | | - self._add_join_to_latest_episode() |
72 | | - self.sql_from.append( |
73 | | - f"INNER JOIN appointment_t {ap_alias} ON {ap_alias}.subject_epis_id = ep.subject_epis_id" |
| 88 | + self.sql_where.append( |
| 89 | + f"AND ap.appointment_slot_type_id {comparator} {slot_type_id}" |
74 | 90 | ) |
75 | 91 |
|
76 | | - if value == "any_appointment_in_latest_episode": |
77 | | - return |
78 | | - elif value == "latest_appointment_in_latest_episode": |
79 | | - self.sql_from.append( |
80 | | - f"AND {ap_alias}.appointment_id = (" |
81 | | - f" SELECT MAX(apx.appointment_id)" |
82 | | - f" FROM appointment_t apx" |
83 | | - f" WHERE apx.subject_epis_id = ep.subject_epis_id" |
84 | | - f" AND apx.void = 'N')" |
85 | | - ) |
86 | | - elif value == "earlier_appointment_in_latest_episode": |
87 | | - self.sql_from.append( |
88 | | - f"AND {ap_alias}.appointment_id < {apr_alias}.appointment_id" |
89 | | - ) |
90 | | - elif value == "later_appointment_in_latest_episode": |
91 | | - self.sql_from.append( |
92 | | - f"AND {ap_alias}.appointment_id > {apr_alias}.appointment_id" |
93 | | - ) |
94 | | - else: |
95 | | - raise ValueError(f"Invalid appointment selection value: {value}") |
96 | | - |
97 | 92 | except Exception: |
98 | 93 | raise SelectionBuilderException(self.criteria_key_name, self.criteria_value) |
0 commit comments