|
7 | 7 |
|
8 | 8 |
|
9 | 9 | # Add helper class stubs below |
10 | | -class DiagnosticTestHasOutcomeOfResult: |
| 10 | +class IntendedExtentType: |
11 | 11 | """ |
12 | | - Maps outcome-of-result criteria values to either flags or valid value IDs. |
| 12 | + Resolves intended extent descriptions to valid value IDs or null-check constants. |
13 | 13 | """ |
14 | 14 |
|
15 | | - YES = "yes" |
16 | | - NO = "no" |
| 15 | + NULL = "null" |
| 16 | + NOT_NULL = "not null" |
17 | 17 |
|
18 | 18 | _mapping = { |
19 | | - "yes": YES, |
20 | | - "no": NO, |
21 | | - "referred": 9101, |
22 | | - "treated": 9102, |
23 | | - "not required": 9103, |
| 19 | + "null": NULL, |
| 20 | + "not null": NOT_NULL, |
| 21 | + "full": 9201, |
| 22 | + "partial": 9202, |
| 23 | + "none": 9203, |
24 | 24 | } |
25 | 25 |
|
26 | 26 | @classmethod |
27 | 27 | def from_description(cls, description: str): |
28 | 28 | key = description.strip().lower() |
29 | 29 | if key not in cls._mapping: |
30 | | - raise ValueError(f"Unknown outcome description: '{description}'") |
| 30 | + raise ValueError(f"Unknown intended extent: '{description}'") |
31 | 31 | return cls._mapping[key] |
32 | 32 |
|
33 | 33 | @classmethod |
34 | 34 | def get_id(cls, description: str) -> int: |
35 | 35 | val = cls.from_description(description) |
36 | 36 | if isinstance(val, int): |
37 | 37 | return val |
38 | | - raise ValueError(f"No ID associated with outcome: '{description}'") |
| 38 | + raise ValueError(f"No ID associated with extent: '{description}'") |
| 39 | + |
| 40 | + @classmethod |
| 41 | + def get_description(cls, sentinel: str) -> str: |
| 42 | + if sentinel == cls.NULL: |
| 43 | + return "NULL" |
| 44 | + if sentinel == cls.NOT_NULL: |
| 45 | + return "NOT NULL" |
| 46 | + raise ValueError(f"Unknown null sentinel: {sentinel}") |
39 | 47 |
|
40 | 48 |
|
41 | 49 | class MockSelectionBuilder: |
@@ -85,25 +93,22 @@ def _add_join_to_latest_episode(self) -> None: |
85 | 93 | # Replace this with the one you want to test, |
86 | 94 | # then use utils/oracle/test_subject_criteria_dev.py to run your scenarios |
87 | 95 |
|
88 | | - def _add_criteria_diagnostic_test_has_outcome_of_result(self) -> None: |
| 96 | + def _add_criteria_diagnostic_test_intended_extent(self) -> None: |
89 | 97 | """ |
90 | | - Adds WHERE clause filtering on whether the diagnostic test has an outcome-of-result. |
| 98 | + Adds WHERE clause filtering diagnostic tests by intended_extent_id. |
| 99 | + Supports null checks and value comparisons. |
91 | 100 | """ |
92 | 101 | try: |
93 | 102 | idx = getattr(self, "criteria_index", 0) |
94 | 103 | xt = f"xt{idx}" |
95 | | - value = self.criteria_value.strip().lower() |
96 | | - outcome = DiagnosticTestHasOutcomeOfResult.from_description(value) |
| 104 | + extent = IntendedExtentType.from_description(self.criteria_value) |
97 | 105 |
|
98 | | - self.sql_where.append(f"AND {xt}.outcome_of_result_id ") |
| 106 | + self.sql_where.append(f"AND {xt}.intended_extent_id ") |
99 | 107 |
|
100 | | - if outcome == DiagnosticTestHasOutcomeOfResult.YES: |
101 | | - self.sql_where.append("IS NOT NULL") |
102 | | - elif outcome == DiagnosticTestHasOutcomeOfResult.NO: |
103 | | - self.sql_where.append("IS NULL") |
| 108 | + if extent in (IntendedExtentType.NULL, IntendedExtentType.NOT_NULL): |
| 109 | + self.sql_where.append(f"IS {IntendedExtentType.get_description(extent)}") |
104 | 110 | else: |
105 | | - outcome_id = DiagnosticTestHasOutcomeOfResult.get_id(value) |
106 | | - self.sql_where.append(f"= {outcome_id}") |
| 111 | + self.sql_where.append(f"{self.criteria_comparator} {IntendedExtentType.get_id(self.criteria_value)}") |
107 | 112 |
|
108 | 113 | except Exception: |
109 | 114 | raise SelectionBuilderException(self.criteria_key_name, self.criteria_value) |
0 commit comments