@@ -151,6 +151,14 @@ def _list_api_request(self, path: str, **kwargs) -> Generator[dict[str, Any]]:
151151 yield from r ["results" ]
152152 # TODO: handle pagination fields
153153
154+ @staticmethod
155+ def _get_link (bundle , rel ):
156+ """Get link from FHIR link list"""
157+ for link in bundle ["link" ]:
158+ if link ["relation" ] == rel :
159+ return link ["url" ]
160+ return None
161+
154162 def _fhir_list_api_request (
155163 self , path : str , * , limit = None , ** kwargs
156164 ) -> Generator [dict [str , Any ]]:
@@ -165,7 +173,7 @@ def _fhir_list_api_request(
165173 while True :
166174 new_records = False
167175 requests += 1
168- for result in r ["results " ]:
176+ for result in r ["entry " ]:
169177 entry = result ["resource" ]
170178 if entry ["id" ] in seen_ids :
171179 # FIXME: skip duplicate records
@@ -180,7 +188,7 @@ def _fhir_list_api_request(
180188 return
181189
182190 # paginated request
183- next_url = r . get ( "next" )
191+ next_url = self . _get_link ( r , "next" )
184192 # only proceed to the next page if this page is not empty
185193 if next_url and new_records :
186194 kwargs .pop ("params" , None )
@@ -481,7 +489,7 @@ def list_observations(
481489 raise ValueError ("Must specify at least one of patient_id or study_id" )
482490 params : dict [str , str | int ] = {}
483491 if study_id :
484- params ["_has:Group:member:_id" ] = study_id
492+ params ["patient. _has:Group:member:_id" ] = study_id
485493 if patient_id :
486494 params ["patient" ] = patient_id
487495 if code :
0 commit comments