66from ..models import (
77 EhrVendor ,
88 LocationToEndpointInstance ,
9+ Location ,
910 Nucc ,
1011 Organization ,
1112 OtherIdType ,
@@ -73,6 +74,10 @@ def setUpTestData(cls):
7374 loc_good_1 = create_location (
7475 organization = cls .org_good_1 ,
7576 name = "Good Location 1" ,
77+ city = "Albuquerque" ,
78+ state = "NM" ,
79+ zipcode = "87101" ,
80+ addr_line_1 = "807 Dusty Ln"
7681 )
7782
7883 endpoint_instance = create_endpoint_instance (
@@ -96,8 +101,15 @@ def setUpTestData(cls):
96101
97102 cls .orgs .append (cls .org_good_2 )
98103
99- loc_good_2a = create_location (organization = cls .org_good_2 , name = "Location A" )
100- loc_good_2b = create_location (organization = cls .org_good_2 , name = "Location B" )
104+ loc_good_2a = create_location (
105+ organization = cls .org_good_2 ,
106+ name = "Location A" ,
107+ city = "Springfield" ,
108+ state = "MO" ,
109+ zipcode = "65203" ,
110+ addr_line_1 = "403 Spring Ln"
111+ )
112+ loc_good_2b = create_location (organization = cls .org_good_2 , name = "Location B" , zipcode = "01234" )
101113
102114 endpoint_good_2a = create_endpoint_instance (
103115 organization = cls .org_good_2 ,
@@ -332,6 +344,121 @@ def test_retrieve_single_organization_affil(self):
332344 self .assertIn ("organization" , org_affiliation_entry )
333345 self .assertIn ("participatingOrganization" , org_affiliation_entry )
334346 self .assertIn ("endpoint" , org_affiliation_entry )
347+
348+ def test_list_filter_by_address (self ):
349+ address_search = "807 Dusty Ln"
350+ url = reverse ("fhir-organizationaffiliation-list" )
351+ response = self .client .get (url , {"address" : address_search })
352+ self .assertEqual (response .status_code , status .HTTP_200_OK )
353+ assert_has_results (self , response )
354+
355+ bundle = response .data ["results" ]
356+
357+ for entry in bundle ["entry" ]:
358+ self .assertIn ("resource" , entry )
359+ location_entry = entry ["resource" ]
360+
361+ address_lines = []
362+ for location in location_entry ['location' ]:
363+ loc_id = location ['reference' ].split ('/' )[- 1 ]
364+ loc_obj = (
365+ Location .objects .filter (pk = loc_id ).first ()
366+ )
367+ address_lines .append (loc_obj .address .address_us .delivery_line_1 )
368+
369+ self .assertIn (address_search , address_lines )
370+
371+ def test_list_filter_by_address_city (self ):
372+ address_search = "Springfield"
373+ url = reverse ("fhir-organizationaffiliation-list" )
374+ response = self .client .get (url , {"address_city" : address_search })
375+ self .assertEqual (response .status_code , status .HTTP_200_OK )
376+ assert_has_results (self , response )
377+
378+ bundle = response .data ["results" ]
379+
380+ for entry in bundle ["entry" ]:
381+ self .assertIn ("resource" , entry )
382+ location_entry = entry ["resource" ]
383+
384+ address_lines = []
385+ for location in location_entry ['location' ]:
386+ loc_id = location ['reference' ].split ('/' )[- 1 ]
387+ loc_obj = (
388+ Location .objects .filter (pk = loc_id ).first ()
389+ )
390+ address_lines .append (loc_obj .address .address_us .city_name )
391+
392+ self .assertIn (address_search , address_lines )
393+
394+ def test_list_filter_by_address_state (self ):
395+ address_search = "NY"
396+ url = reverse ("fhir-organizationaffiliation-list" )
397+ response = self .client .get (url , {"address_state" : address_search })
398+ self .assertEqual (response .status_code , status .HTTP_200_OK )
399+ assert_has_results (self , response )
400+
401+ bundle = response .data ["results" ]
402+
403+ for entry in bundle ["entry" ]:
404+ self .assertIn ("resource" , entry )
405+ location_entry = entry ["resource" ]
406+
407+ address_lines = []
408+ for location in location_entry ['location' ]:
409+ loc_id = location ['reference' ].split ('/' )[- 1 ]
410+ loc_obj = (
411+ Location .objects .filter (pk = loc_id ).first ()
412+ )
413+ address_lines .append (loc_obj .address .address_us .state_code .abbreviation )
414+
415+ self .assertIn (address_search , address_lines )
416+
417+ def test_list_filter_by_address_zipcode (self ):
418+ address_search = "87101"
419+ url = reverse ("fhir-organizationaffiliation-list" )
420+ response = self .client .get (url , {"address_postalcode" : address_search })
421+ self .assertEqual (response .status_code , status .HTTP_200_OK )
422+ assert_has_results (self , response )
423+
424+ bundle = response .data ["results" ]
425+
426+ for entry in bundle ["entry" ]:
427+ self .assertIn ("resource" , entry )
428+ location_entry = entry ["resource" ]
429+
430+ address_lines = []
431+ for location in location_entry ['location' ]:
432+ loc_id = location ['reference' ].split ('/' )[- 1 ]
433+ loc_obj = (
434+ Location .objects .filter (pk = loc_id ).first ()
435+ )
436+ address_lines .append (loc_obj .address .address_us .zipcode )
437+
438+ self .assertIn (address_search , address_lines )
439+
440+ def test_list_filter_by_address_zipcode_leading_zero (self ):
441+ address_search = "01234"
442+ url = reverse ("fhir-organizationaffiliation-list" )
443+ response = self .client .get (url , {"address_postalcode" : address_search })
444+ self .assertEqual (response .status_code , status .HTTP_200_OK )
445+ assert_has_results (self , response )
446+
447+ bundle = response .data ["results" ]
448+
449+ for entry in bundle ["entry" ]:
450+ self .assertIn ("resource" , entry )
451+ location_entry = entry ["resource" ]
452+
453+ address_lines = []
454+ for location in location_entry ['location' ]:
455+ loc_id = location ['reference' ].split ('/' )[- 1 ]
456+ loc_obj = (
457+ Location .objects .filter (pk = loc_id ).first ()
458+ )
459+ address_lines .append (loc_obj .address .address_us .zipcode )
460+
461+ self .assertIn (address_search , address_lines )
335462
336463 def test_retrieve_non_existant_organization_affil (self ):
337464 url = reverse (
0 commit comments