|
17 | 17 | from ..models import ( |
18 | 18 | Nucc, |
19 | 19 | EndpointInstanceToPayload, |
| 20 | + OrganizationToName, |
| 21 | + Provider, |
20 | 22 | ProviderToOrganization, |
21 | 23 | ProviderToLocation, |
22 | 24 | ProviderToTaxonomy, |
23 | 25 | PayloadType, |
24 | 26 | Location, |
25 | 27 | LocationToEndpointInstance, |
| 28 | + IndividualToName |
26 | 29 | ) |
27 | 30 |
|
28 | 31 |
|
@@ -160,6 +163,7 @@ def setUpTestData(cls): |
160 | 163 |
|
161 | 164 | # Create organization and location |
162 | 165 | cls.org_name = "Sunshine Health" |
| 166 | + cls.orgs.append(cls.org_name) |
163 | 167 | org = create_organization( |
164 | 168 | name=cls.org_name, organization_type=taxonomy_code.code if taxonomy_code else None |
165 | 169 | ) |
@@ -266,23 +270,69 @@ def test_list_with_greater_than_max_page_size(self): |
266 | 270 |
|
267 | 271 | # Filter tests |
268 | 272 | def test_list_filter_by_name(self): |
| 273 | + sample_name = "Charlie" |
269 | 274 | url = reverse("fhir-practitionerrole-list") |
270 | | - response = self.client.get(url, {"name": "Cumberland"}) |
| 275 | + response = self.client.get(url, {"practitioner_name": sample_name}) |
271 | 276 | self.assertEqual(response.status_code, status.HTTP_200_OK) |
272 | 277 | assert_has_results(self, response) |
273 | 278 |
|
| 279 | + for entry in response.data["results"]["entry"]: |
| 280 | + #Query the practitioner names based on the returned id |
| 281 | + practitioner_id = entry["resource"]["practitioner"]["reference"].split("/")[-1] |
| 282 | + provider = Provider.objects.select_related("individual").get( |
| 283 | + individual_id=practitioner_id |
| 284 | + ) |
| 285 | + |
| 286 | + name_objects = IndividualToName.objects.filter(individual=provider.individual).all() |
| 287 | + |
| 288 | + #Save if the search matches an individual name associated with a provider |
| 289 | + match_conditions = [] |
| 290 | + |
| 291 | + for name in name_objects: |
| 292 | + name_string = "" |
| 293 | + name_string += f"{name.prefix or ""}" |
| 294 | + name_string += f"{name.first_name or ""} {name.middle_name or ""}" |
| 295 | + name_string += f"{name.last_name or ""} {name.suffix or ""}" |
| 296 | + |
| 297 | + match_conditions.append(sample_name in name_string) |
| 298 | + |
| 299 | + #Make sure that the provider has any individual name that matches |
| 300 | + self.assertTrue(any(match_conditions)) |
| 301 | + |
274 | 302 | def test_list_filter_by_practitioner_gender(self): |
275 | 303 | url = reverse("fhir-practitionerrole-list") |
276 | 304 | response = self.client.get(url, {"practitioner_gender": "Female"}) |
277 | 305 | self.assertEqual(response.status_code, status.HTTP_200_OK) |
278 | 306 | assert_has_results(self, response) |
279 | 307 |
|
| 308 | + for entry in response.data["results"]["entry"]: |
| 309 | + #Query the practitioner individual based on the returned id |
| 310 | + practitioner_id = entry["resource"]["practitioner"]["reference"].split("/")[-1] |
| 311 | + provider = Provider.objects.select_related("individual").get( |
| 312 | + individual_id=practitioner_id |
| 313 | + ) |
| 314 | + |
| 315 | + self.assertEqual('F', provider.individual.gender) |
| 316 | + |
280 | 317 | def test_list_filter_by_organization_name(self): |
| 318 | + name_search = "MEDICAL" |
281 | 319 | url = reverse("fhir-practitionerrole-list") |
282 | | - response = self.client.get(url, {"organization_name": "MEDICAL"}) |
| 320 | + response = self.client.get(url, {"organization_name": name_search}) |
283 | 321 | self.assertEqual(response.status_code, status.HTTP_200_OK) |
284 | 322 | assert_has_results(self, response) |
285 | 323 |
|
| 324 | + for entry in response.data["results"]["entry"]: |
| 325 | + #Query the practitioner names based on the returned id |
| 326 | + org_id = entry["resource"]["organization"]["reference"].split("/")[-1] |
| 327 | + org_name = ( |
| 328 | + OrganizationToName.objects |
| 329 | + .filter(organization_id=org_id) |
| 330 | + .values_list("name", flat=True) |
| 331 | + .first() |
| 332 | + ) |
| 333 | + |
| 334 | + self.assertIn(name_search, org_name) |
| 335 | + |
286 | 336 | def test_filter_by_distance_with_km(self): |
287 | 337 | lat = -90.194315 |
288 | 338 | lon = 38.629267 |
|
0 commit comments