@@ -87,7 +87,35 @@ def __init__(
87
87
self .chunk_number : Optional [int ] = chunk_number
88
88
self .cache_hits : Optional [int ] = cache_hits
89
89
90
- def append (self , others : List ["FhirGetResponse" ]) -> "FhirGetResponse" :
90
+ def append (self , other_response : "FhirGetResponse" ) -> "FhirGetResponse" :
91
+ """
92
+ Append the responses from other to self
93
+
94
+ :param other_response: FhirGetResponse object to append to current one
95
+ :return: self
96
+ """
97
+ bundle_entries : List [BundleEntry ] = self .get_bundle_entries ()
98
+ if other_response .responses :
99
+ other_bundle_entries : List [BundleEntry ] = (
100
+ other_response .get_bundle_entries ()
101
+ )
102
+ bundle_entries .extend (other_bundle_entries )
103
+ bundle = {
104
+ "resourceType" : "Bundle" ,
105
+ "entry" : bundle_entries ,
106
+ }
107
+ self .responses = json .dumps (bundle , cls = FhirJSONEncoder )
108
+ if other_response .chunk_number and (other_response .chunk_number or 0 ) > (
109
+ self .chunk_number or 0
110
+ ):
111
+ self .chunk_number = other_response .chunk_number
112
+ if other_response .next_url :
113
+ self .next_url = other_response .next_url
114
+ self .access_token = other_response .access_token
115
+ self .cache_hits = (self .cache_hits or 0 ) + (other_response .cache_hits or 0 )
116
+ return self
117
+
118
+ def extend (self , others : List ["FhirGetResponse" ]) -> "FhirGetResponse" :
91
119
"""
92
120
Append the responses from other to self
93
121
@@ -373,10 +401,10 @@ def get_resource_type_and_ids(self) -> List[str]:
373
401
f"Could not get resourceType and id from resources: { json .dumps (resources , cls = FhirJSONEncoder )} "
374
402
) from e
375
403
376
- @staticmethod
404
+ @classmethod
377
405
async def from_async_generator (
378
- generator : AsyncGenerator ["FhirGetResponse" , None ]
379
- ) -> "FhirGetResponse" :
406
+ cls , generator : AsyncGenerator ["FhirGetResponse" , None ]
407
+ ) -> Optional [ "FhirGetResponse" ] :
380
408
"""
381
409
Reads a generator of FhirGetResponse and returns a single FhirGetResponse by appending all the FhirGetResponse
382
410
@@ -388,7 +416,7 @@ async def from_async_generator(
388
416
if not result :
389
417
result = value
390
418
else :
391
- result .append ([ value ] )
419
+ result .append (value )
392
420
393
421
assert result
394
422
return result
0 commit comments