|
8 | 8 |
|
9 | 9 |
|
10 | 10 | # Add helper class stubs below |
11 | | -class EpisodeResultType: |
| 11 | +class SymptomaticProcedureResultType: |
12 | 12 | """ |
13 | | - Represents various episode result types including special symbolic values. |
| 13 | + Maps symptom-driven surgery result descriptions to valid value IDs. |
14 | 14 | """ |
15 | 15 |
|
16 | | - NULL = "null" |
17 | | - NOT_NULL = "not_null" |
18 | | - ANY_SURVEILLANCE_NON_PARTICIPATION = "any_surveillance_non_participation" |
19 | | - |
20 | 16 | _label_to_id = { |
21 | | - # Add actual mappings here, for example: |
22 | | - "normal": 9501, |
23 | | - "abnormal": 9502, |
24 | | - "surveillance offered": 9503, |
25 | | - # etc. |
| 17 | + "normal": 9601, |
| 18 | + "inconclusive": 9602, |
| 19 | + "cancer detected": 9603, |
| 20 | + # Extend as needed |
26 | 21 | } |
27 | 22 |
|
28 | 23 | @classmethod |
29 | | - def from_description(cls, description: str): |
| 24 | + def get_id(cls, description: str) -> int: |
30 | 25 | key = description.strip().lower() |
31 | | - if key in {cls.NULL, cls.NOT_NULL, cls.ANY_SURVEILLANCE_NON_PARTICIPATION}: |
32 | | - return key |
33 | | - if key in cls._label_to_id: |
34 | | - return cls._label_to_id[key] |
35 | | - raise ValueError(f"Unknown episode result type: '{description}'") |
| 26 | + if key not in cls._label_to_id: |
| 27 | + raise ValueError(f"Unknown symptomatic procedure result: '{description}'") |
| 28 | + return cls._label_to_id[key] |
36 | 29 |
|
37 | 30 |
|
38 | 31 | class MockSelectionBuilder: |
@@ -101,27 +94,21 @@ def _add_join_to_surveillance_review(self): |
101 | 94 | # Replace this with the one you want to test, |
102 | 95 | # then use utils/oracle/test_subject_criteria_dev.py to run your scenarios |
103 | 96 |
|
104 | | - def _add_criteria_latest_episode_accumulated_episode_result(self) -> None: |
| 97 | + def _add_criteria_symptomatic_procedure_result(self) -> None: |
105 | 98 | """ |
106 | | - Filters subjects based on the result of their latest episode. |
| 99 | + Filters based on symptomatic surgery result value or presence. |
107 | 100 | """ |
108 | 101 | try: |
109 | | - self._add_join_to_latest_episode() |
110 | | - value = EpisodeResultType.from_description(self.criteria_value) |
111 | | - |
112 | | - if value == EpisodeResultType.NULL: |
113 | | - self.sql_where.append("AND ep.episode_result_id IS NULL") |
114 | | - elif value == EpisodeResultType.NOT_NULL: |
115 | | - self.sql_where.append("AND ep.episode_result_id IS NOT NULL") |
116 | | - elif value == EpisodeResultType.ANY_SURVEILLANCE_NON_PARTICIPATION: |
| 102 | + column = "xt.surgery_result_id" |
| 103 | + value = self.criteria_value.strip().lower() |
| 104 | + |
| 105 | + if value == "null": |
| 106 | + self.sql_where.append(f"AND {column} IS NULL") |
| 107 | + else: |
| 108 | + result_id = SymptomaticProcedureResultType.get_id(self.criteria_value) |
117 | 109 | self.sql_where.append( |
118 | | - "AND ep.episode_result_id IN (" |
119 | | - "SELECT snp.valid_value_id FROM valid_values snp " |
120 | | - "WHERE snp.domain = 'OTHER_EPISODE_RESULT' " |
121 | | - "AND LOWER(snp.description) LIKE '%surveillance non-participation')" |
| 110 | + f"AND {column} {self.criteria_comparator} {result_id}" |
122 | 111 | ) |
123 | | - else: |
124 | | - self.sql_where.append(f"AND ep.episode_result_id = {value}") |
125 | 112 |
|
126 | 113 | except Exception: |
127 | 114 | raise SelectionBuilderException(self.criteria_key_name, self.criteria_value) |
0 commit comments