1313 # extract_resource_ids,
1414)
1515
16- from ..models import (
17- OrganizationToName ,
18- Provider ,
19- Location ,
20- IndividualToName ,
21- Organization
22- )
16+ from ..models import OrganizationToName , Provider , IndividualToName , Organization , OrganizationView
2317
2418from .fixtures .location import create_location
2519from .fixtures .practitioner import (
@@ -155,6 +149,8 @@ def setUpTestData(cls):
155149
156150 cls .roles_with_params .append (pr )
157151
152+ OrganizationView .refresh_materialized_view ()
153+
158154 return super ().setUpTestData ()
159155
160156 # Basic tests
@@ -563,17 +559,18 @@ def test_list_filter_by_address_city(self):
563559 bundle = response .data ["results" ]
564560
565561 for entry in bundle ["entry" ]:
566- location_id = entry ["resource" ]["location" ][0 ]["reference" ].split ("/" )[- 1 ]
567562 self .assertIn ("resource" , entry )
568563 location_entry = entry ["resource" ]
569564
570565 self .assertEqual (location_entry ["resourceType" ], "PractitionerRole" )
571566 self .assertIn ("id" , location_entry )
572567 self .assertIn ("active" , location_entry )
573568
574- location_obj = Location .objects .get (pk = location_id )
575-
576- self .assertEqual (city_search , location_obj .address .address_us .city_name )
569+ for entry in bundle ["entry" ]:
570+ self .assertEqual (1 , len (entry ["resource" ]["location" ]))
571+ location_url = entry ["resource" ]["location" ][0 ]["reference" ]
572+ returned_location = self .client .get (location_url ).data
573+ self .assertEqual (city_search , returned_location ["address" ]["city" ])
577574
578575 def test_list_filter_by_address_state (self ):
579576 state_search = "CA"
@@ -585,17 +582,18 @@ def test_list_filter_by_address_state(self):
585582 bundle = response .data ["results" ]
586583
587584 for entry in bundle ["entry" ]:
588- location_id = entry ["resource" ]["location" ][0 ]["reference" ].split ("/" )[- 1 ]
589585 self .assertIn ("resource" , entry )
590586 location_entry = entry ["resource" ]
591587
592588 self .assertEqual (location_entry ["resourceType" ], "PractitionerRole" )
593589 self .assertIn ("id" , location_entry )
594590 self .assertIn ("active" , location_entry )
595591
596- location_obj = Location .objects .get (pk = location_id )
597-
598- self .assertEqual (state_search , location_obj .address .address_us .state_code .abbreviation )
592+ for entry in bundle ["entry" ]:
593+ self .assertEqual (1 , len (entry ["resource" ]["location" ]))
594+ location_url = entry ["resource" ]["location" ][0 ]["reference" ]
595+ returned_location = self .client .get (location_url ).data
596+ self .assertEqual (state_search , returned_location ["address" ]["state" ])
599597
600598 def test_list_filter_by_address_zip (self ):
601599 zip_search = "90001"
@@ -607,17 +605,18 @@ def test_list_filter_by_address_zip(self):
607605 bundle = response .data ["results" ]
608606
609607 for entry in bundle ["entry" ]:
610- location_id = entry ["resource" ]["location" ][0 ]["reference" ].split ("/" )[- 1 ]
611608 self .assertIn ("resource" , entry )
612609 location_entry = entry ["resource" ]
613610
614611 self .assertEqual (location_entry ["resourceType" ], "PractitionerRole" )
615612 self .assertIn ("id" , location_entry )
616613 self .assertIn ("active" , location_entry )
617614
618- location_obj = Location .objects .get (pk = location_id )
619-
620- self .assertEqual (zip_search , location_obj .address .address_us .zipcode )
615+ for entry in bundle ["entry" ]:
616+ self .assertEqual (1 , len (entry ["resource" ]["location" ]))
617+ location_url = entry ["resource" ]["location" ][0 ]["reference" ]
618+ returned_location = self .client .get (location_url ).data
619+ self .assertEqual (zip_search , returned_location ["address" ]["postalCode" ])
621620
622621 def test_list_filter_by_address_zip_leading_zero (self ):
623622 zip_search = "05555"
@@ -629,39 +628,45 @@ def test_list_filter_by_address_zip_leading_zero(self):
629628 bundle = response .data ["results" ]
630629
631630 for entry in bundle ["entry" ]:
632- location_id = entry ["resource" ]["location" ][0 ]["reference" ].split ("/" )[- 1 ]
633631 self .assertIn ("resource" , entry )
634632 location_entry = entry ["resource" ]
635633
636634 self .assertEqual (location_entry ["resourceType" ], "PractitionerRole" )
637635 self .assertIn ("id" , location_entry )
638636 self .assertIn ("active" , location_entry )
639637
640- location_obj = Location .objects .get (pk = location_id )
638+ for entry in bundle ["entry" ]:
639+ self .assertEqual (1 , len (entry ["resource" ]["location" ]))
640+ location_url = entry ["resource" ]["location" ][0 ]["reference" ]
641+ returned_location = self .client .get (location_url ).data
642+ self .assertEqual (zip_search , returned_location ["address" ]["postalCode" ])
641643
642- self .assertEqual (zip_search , location_obj .address .address_us .zipcode )
643-
644644 def test_list_filter_by_address_general_zip_leading_zero (self ):
645- zip_search = "404 Great Amazing Avenue San Diego CA 05555"
645+ address_line_1 = "404 Great Amazing Avenue"
646+ city = "San Diego"
647+ state = "CA"
648+ zip_code = "05555"
649+ address_search = " " .join ([address_line_1 , city , state , zip_code ])
646650 url = reverse ("fhir-practitionerrole-list" )
647- response = self .client .get (url , {"location_address" : zip_search })
651+ response = self .client .get (url , {"location_address" : address_search })
648652 self .assertEqual (response .status_code , status .HTTP_200_OK )
649653 assert_has_results (self , response )
650654
651655 bundle = response .data ["results" ]
652656
653657 for entry in bundle ["entry" ]:
654- location_id = entry ["resource" ]["location" ][0 ]["reference" ].split ("/" )[- 1 ]
655658 self .assertIn ("resource" , entry )
656659 location_entry = entry ["resource" ]
657660
658661 self .assertEqual (location_entry ["resourceType" ], "PractitionerRole" )
659662 self .assertIn ("id" , location_entry )
660663 self .assertIn ("active" , location_entry )
661664
662- location_obj = Location .objects .get (pk = location_id )
663-
664- self .assertEqual (zip_search .split ()[- 1 ], location_obj .address .address_us .zipcode )
665- self .assertEqual ("404 Great Amazing Avenue" , location_obj .address .address_us .delivery_line_1 )
666- self .assertEqual ("San Diego" , location_obj .address .address_us .city_name )
667- self .assertEqual ("CA" , location_obj .address .address_us .state_code .abbreviation )
665+ for entry in bundle ["entry" ]:
666+ self .assertEqual (1 , len (entry ["resource" ]["location" ]))
667+ location_url = entry ["resource" ]["location" ][0 ]["reference" ]
668+ returned_location = self .client .get (location_url ).data
669+ self .assertEqual (zip_code , returned_location ["address" ]["postalCode" ])
670+ self .assertEqual (state , returned_location ["address" ]["state" ])
671+ self .assertEqual (city , returned_location ["address" ]["city" ])
672+ self .assertIn (address_line_1 , returned_location ["address" ]["line" ])
0 commit comments