|
13 | 13 | parse_imms_int_imms_event_response, |
14 | 14 | validate_imms_delta_record_with_created_event, |
15 | 15 | ) |
| 16 | +from src.objectModels.api_data_objects import CodeableConcept, Coding |
16 | 17 | from src.objectModels.api_immunization_builder import ( |
17 | 18 | build_site_route, |
18 | 19 | build_vaccine_procedure_code, |
19 | 20 | build_vaccine_procedure_extension, |
| 21 | + create_extension, |
20 | 22 | get_vaccine_details, |
21 | 23 | ) |
22 | 24 | from utilities.api_fhir_immunization_helper import ( |
@@ -121,6 +123,81 @@ def createValidJsonPayloadWithProcedureMultipleCodingsDifferentSystem(context): |
121 | 123 | context.immunization_object.route.coding[0].system = "http://example.com/different-system" |
122 | 124 |
|
123 | 125 |
|
| 126 | +def build_coding(system, code, display, value_string, value_id): |
| 127 | + return Coding( |
| 128 | + system=system, |
| 129 | + code=code, |
| 130 | + display=display, |
| 131 | + extension=[ |
| 132 | + create_extension( |
| 133 | + "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-CodingSCTDescDisplay", |
| 134 | + stringValue=value_string, |
| 135 | + ), |
| 136 | + create_extension( |
| 137 | + "http://hl7.org/fhir/StructureDefinition/coding-sctdescid", |
| 138 | + idValue=value_id, |
| 139 | + ), |
| 140 | + ], |
| 141 | + ) |
| 142 | + |
| 143 | + |
| 144 | +@given("Valid json payload is created where site and route have multiple SNOMED codings after an invalid system") |
| 145 | +def create_valid_json_payload_with_multiple_site_route_snomed_codings(context): |
| 146 | + valid_json_payload_is_created(context) |
| 147 | + context.immunization_object.site = CodeableConcept( |
| 148 | + coding=[ |
| 149 | + build_coding( |
| 150 | + "http://snomed.info/test", |
| 151 | + "368208006", |
| 152 | + "Right upper arm structure (body structure)", |
| 153 | + "Test Value string site 111", |
| 154 | + "5306706018", |
| 155 | + ), |
| 156 | + build_coding( |
| 157 | + "http://snomed.info/sct", |
| 158 | + "368209003", |
| 159 | + "Left upper arm structure (body structure)", |
| 160 | + "Test Value string site 222", |
| 161 | + "5306706020", |
| 162 | + ), |
| 163 | + build_coding( |
| 164 | + "http://snomed.info/sct", |
| 165 | + "368208008", |
| 166 | + "Mid upper arm structure (body structure)", |
| 167 | + "Test Value string site 333", |
| 168 | + "5306706030", |
| 169 | + ), |
| 170 | + ], |
| 171 | + text="Test String for site", |
| 172 | + ) |
| 173 | + context.immunization_object.route = CodeableConcept( |
| 174 | + coding=[ |
| 175 | + build_coding( |
| 176 | + "http://snomed.info/test", |
| 177 | + "78421000", |
| 178 | + "Intramuscular route (qualifier value)", |
| 179 | + "Test Value string route 111", |
| 180 | + "5306706040", |
| 181 | + ), |
| 182 | + build_coding( |
| 183 | + "http://snomed.info/sct", |
| 184 | + "78421000", |
| 185 | + "Intramuscular route (qualifier value)", |
| 186 | + "Test Value string route 222", |
| 187 | + "5306706050", |
| 188 | + ), |
| 189 | + build_coding( |
| 190 | + "http://snomed.info/sct", |
| 191 | + "34206005", |
| 192 | + "Subcutaneous route (qualifier value)", |
| 193 | + "Test Value string route 333", |
| 194 | + "5306706060", |
| 195 | + ), |
| 196 | + ], |
| 197 | + text="Test String for route", |
| 198 | + ) |
| 199 | + |
| 200 | + |
124 | 201 | @given( |
125 | 202 | "Valid json payload is created where vaccination terms has one instance of coding with no text or value string field" |
126 | 203 | ) |
@@ -267,6 +344,37 @@ def validate_procedure_term_correct_coding_in_delta_table(context): |
267 | 344 | ) |
268 | 345 |
|
269 | 346 |
|
| 347 | +@then("The delta table will use the first valid SNOMED site and route coding") |
| 348 | +def validate_delta_table_uses_first_valid_snomed_site_route_coding(context): |
| 349 | + actual_terms = get_all_term_text(context) |
| 350 | + expected_site_term = context.create_object.site.coding[1].extension[0].valueString |
| 351 | + expected_route_term = context.create_object.route.coding[1].extension[0].valueString |
| 352 | + assert actual_terms["site_term"] == expected_site_term, ( |
| 353 | + f"Expected site of vaccination term '{expected_site_term}', but got '{actual_terms['site_term']}'" |
| 354 | + ) |
| 355 | + assert actual_terms["route_term"] == expected_route_term, ( |
| 356 | + f"Expected route of vaccination term '{expected_route_term}', but got '{actual_terms['route_term']}'" |
| 357 | + ) |
| 358 | + |
| 359 | + |
| 360 | +@then("The imms event table will preserve every site and route coding from the request") |
| 361 | +def validate_imms_event_table_preserves_all_site_route_codings(context): |
| 362 | + table_query_response = fetch_immunization_events_detail(context.aws_profile_name, context.ImmsID, context.S3_env) |
| 363 | + assert "Item" in table_query_response, f"Item not found in response for ImmsID: {context.ImmsID}" |
| 364 | + |
| 365 | + resource_json_str = table_query_response["Item"].get("Resource") |
| 366 | + assert resource_json_str, "Resource field missing in item." |
| 367 | + resource = json.loads(resource_json_str) |
| 368 | + |
| 369 | + for field_name in ("site", "route"): |
| 370 | + expected = context.request[field_name] |
| 371 | + actual = resource[field_name] |
| 372 | + assert len(actual["coding"]) == 3, ( |
| 373 | + f"Expected {field_name}.coding to contain 3 entries, but got {len(actual['coding'])}" |
| 374 | + ) |
| 375 | + assert actual == expected, f"Expected {field_name} to match request, but got {actual}" |
| 376 | + |
| 377 | + |
270 | 378 | @then("The terms are mapped to correct coding.display fields in imms delta table") |
271 | 379 | def validate_procedure_term_second_display_in_delta_table(context): |
272 | 380 | actual_terms = get_all_term_text(context) |
|
0 commit comments