|
| 1 | +from utils.base_test import ImmunizationBaseTest |
| 2 | +from utils.resource import generate_imms_resource |
| 3 | +from lib.env import get_service_base_path |
| 4 | + |
| 5 | + |
| 6 | +class TestSearchImmunizationByIdentifier(ImmunizationBaseTest): |
| 7 | + |
| 8 | + def store_records(self, *resources): |
| 9 | + ids = [] |
| 10 | + for res in resources: |
| 11 | + imms_id = self.default_imms_api.create_immunization_resource(res) |
| 12 | + ids.append(imms_id) |
| 13 | + return ids[0] if len(ids) == 1 else tuple(ids) |
| 14 | + |
| 15 | + def test_search_imms(self): |
| 16 | + for imms_api in self.imms_apis: |
| 17 | + with self.subTest(imms_api): |
| 18 | + covid_19_p1 = generate_imms_resource() |
| 19 | + covid_ids = self.store_records(covid_19_p1) |
| 20 | + |
| 21 | + # Retrieve the resources to get the identifier system and value via read API |
| 22 | + covid_resource = imms_api.get_immunization_by_id(covid_ids).json() |
| 23 | + |
| 24 | + # Extract identifier components safely for covid resource |
| 25 | + identifiers = covid_resource.get("identifier", []) |
| 26 | + identifier_system = identifiers[0].get("system") |
| 27 | + identifier_value = identifiers[0].get("value") |
| 28 | + |
| 29 | + # When |
| 30 | + search_response = imms_api.search_immunization_by_identifier_and_elements( |
| 31 | + identifier_system, identifier_value) |
| 32 | + self.assertEqual(search_response.status_code, 200, search_response.text) |
| 33 | + bundle = search_response.json() |
| 34 | + self.assertEqual(bundle.get("resourceType"), "Bundle", bundle) |
| 35 | + entries = bundle.get("entry", []) |
| 36 | + self.assertTrue(entries, "Expected at least one match in Bundle.entry") |
| 37 | + self.assertEqual(len(entries), 1, f"Expected exactly one match, got {len(entries)}") |
| 38 | + self.assertIn("meta", entries[0]["resource"]) |
| 39 | + self.assertEqual(entries[0]["resource"]["id"], covid_ids) |
| 40 | + self.assertEqual(entries[0]["resource"]["meta"]["versionId"], 1) |
| 41 | + self.assertTrue(entries[0]["fullUrl"].startswith("https://")) |
| 42 | + self.assertEqual( |
| 43 | + entries[0]["fullUrl"], f"{get_service_base_path()}/Immunization/{covid_ids}" |
| 44 | + ) |
0 commit comments