Skip to content

Commit f6d7894

Browse files
committed
Added appointment status type filter and AppointmentStatusType mapping class to selection query builder
1 parent 6f4d6a9 commit f6d7894

File tree

4 files changed

+61
-21
lines changed

4 files changed

+61
-21
lines changed

classes/appointment_status_type.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class AppointmentStatusType:
2+
"""
3+
Maps descriptive appointment statuses to internal IDs.
4+
Extend with real values as needed.
5+
"""
6+
7+
_mapping = {
8+
"booked": 2001,
9+
"attended": 2002,
10+
"cancelled": 2003,
11+
"dna": 2004, # Did Not Attend
12+
}
13+
14+
@classmethod
15+
def get_id(cls, description: str) -> int:
16+
key = description.strip().lower()
17+
if key not in cls._mapping:
18+
raise ValueError(f"Unknown appointment status: {description}")
19+
return cls._mapping[key]

utils/oracle/mock_selection_builder.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@
77

88

99
# Add helper class stubs below
10-
class AppointmentSlotType:
10+
class AppointmentStatusType:
1111
"""
12-
Mocked appointment slot type mapping for test purposes.
13-
Replace IDs with real values from production enum if needed.
12+
Mocked appointment status mapping for test purposes.
13+
Replace IDs with real values from production if needed.
1414
"""
1515

1616
_mapping = {
17-
"clinic": 1001,
18-
"phone": 1002,
19-
"video": 1003,
17+
"booked": 2001,
18+
"attended": 2002,
19+
"cancelled": 2003,
20+
"dna": 2004, # Did Not Attend
2021
}
2122

2223
@classmethod
2324
def get_id(cls, description: str) -> int:
2425
key = description.strip().lower()
2526
if key not in cls._mapping:
26-
raise ValueError(f"Unknown appointment slot type: {description}")
27+
raise ValueError(f"Unknown appointment status: {description}")
2728
return cls._mapping[key]
2829

2930

@@ -73,20 +74,20 @@ def _add_join_to_latest_episode(self) -> None:
7374
# Replace this with the one you want to test,
7475
# then use utils/oracle/test_subject_criteria_dev.py to run your scenarios
7576

76-
def _add_criteria_appointment_type(self) -> None:
77+
def _add_criteria_appointment_status(self) -> None:
7778
"""
78-
Filters appointments by slot type (e.g. clinic, phone).
79-
Requires prior join to appointment_t as alias 'ap' (via WHICH_APPOINTMENT).
79+
Filters appointments by status (e.g. booked, attended).
80+
Requires prior join to appointment_t as alias 'ap'.
8081
81-
Uses comparator and resolves slot type label to ID via AppointmentSlotType.
82+
Uses comparator and resolves status label to ID via AppointmentStatusType.
8283
"""
8384
try:
8485
comparator = self.criteria_comparator
8586
value = self.criteria_value.strip()
86-
slot_type_id = AppointmentSlotType.get_id(value)
87+
status_id = AppointmentStatusType.get_id(value)
8788

8889
self.sql_where.append(
89-
f"AND ap.appointment_slot_type_id {comparator} {slot_type_id}"
90+
f"AND ap.appointment_status_id {comparator} {status_id}"
9091
)
9192

9293
except Exception:

utils/oracle/subject_selection_query_builder.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from classes.user import User
2727
from classes.selection_builder_exception import SelectionBuilderException
2828
from classes.appointments_slot_type import AppointmentSlotType
29+
from classes.appointment_status_type import AppointmentStatusType
2930

3031

3132
class SubjectSelectionQueryBuilder:
@@ -1582,6 +1583,25 @@ def _add_criteria_appointment_type(self) -> None:
15821583
except Exception:
15831584
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
15841585

1586+
def _add_criteria_appointment_status(self) -> None:
1587+
"""
1588+
Filters appointments by status (e.g. booked, attended).
1589+
Requires prior join to appointment_t as alias 'ap'.
1590+
1591+
Uses comparator and resolves status label to ID via AppointmentStatusType.
1592+
"""
1593+
try:
1594+
comparator = self.criteria_comparator
1595+
value = self.criteria_value.strip()
1596+
status_id = AppointmentStatusType.get_id(value)
1597+
1598+
self.sql_where.append(
1599+
f"AND ap.appointment_status_id {comparator} {status_id}"
1600+
)
1601+
1602+
except Exception:
1603+
raise SelectionBuilderException(self.criteria_key_name, self.criteria_value)
1604+
15851605
# ------------------------------------------------------------------------
15861606
# 🧬 CADS Clinical Dataset Filters
15871607
# ------------------------------------------------------------------------

utils/oracle/test_subject_criteria_dev.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929
# === Example usage ===
3030
# Replace the examples below with your tests for the method you want to test
3131

32-
# === Test: APPOINTMENT_TYPEphone ===
33-
builder = MockSelectionBuilder(SubjectSelectionCriteriaKey.APPOINTMENT_TYPE, "phone")
32+
# === Test: APPOINTMENT_STATUSbooked ===
33+
builder = MockSelectionBuilder(SubjectSelectionCriteriaKey.APPOINTMENT_STATUS, "booked")
3434
builder.criteria_comparator = "="
35-
builder._add_criteria_appointment_type()
36-
print("=== APPOINTMENT_TYPEphone ===")
35+
builder._add_criteria_appointment_status()
36+
print("=== APPOINTMENT_STATUSbooked ===")
3737
print(builder.dump_sql(), end="\n\n")
3838

39-
# === Test: APPOINTMENT_TYPEclinic !== ===
40-
builder = MockSelectionBuilder(SubjectSelectionCriteriaKey.APPOINTMENT_TYPE, "clinic")
39+
# === Test: APPOINTMENT_STATUSdna !== ===
40+
builder = MockSelectionBuilder(SubjectSelectionCriteriaKey.APPOINTMENT_STATUS, "dna")
4141
builder.criteria_comparator = "!="
42-
builder._add_criteria_appointment_type()
43-
print("=== APPOINTMENT_TYPEclinic !== ===")
42+
builder._add_criteria_appointment_status()
43+
print("=== APPOINTMENT_STATUSdna !== ===")
4444
print(builder.dump_sql(), end="\n\n")

0 commit comments

Comments
 (0)