Open ruscoder opened 1 year ago
We already have __iter__/__aiter__
implemented and fetch/fetch_all
uses it.
I suggest to rename __iter__/__aiter__
to .iterator()/.aiterator()
, and re-use it in __iter__/__aiter__
. And in addition, I suggest adding.raw_iterator()/.raw_aiterator()
methods that will return iterators similar to fetch_raw
. And then add fetch_all_raw
that just invokes the iterator and concatenates Bundle.entry
.
This logic will give an ability to paginate over resources/raw resources easily, e.g.
ss_iter = client.resources("Patient").limit(5).iterator()
first_chunk = next(ss_iter)
second_chunk = next(ss_iter)
ss_raw_iter = client.resources("Patient").limit(5).raw_iterator()
first_raw_chunk = next(ss_raw_iter)
second_raw_chunk = next(ss_raw_iter)
fetch_raw has issues with typing model #126, because it might contain multiple resources returned. Unfortunately, it does implicit transformation into resources
def fetch_raw(self) -> Any:
...
if data_resource_type == "Bundle":
for item in data["entry"]:
item.resource = self._dict_to_resource(item.resource)
return data
so, if we have Patient resources with included Practitioners, the output will be Bundle with resources as Patients and SyncFHIRResource/AsyncFHIRResource for included resources
The whole idea behind fetch_raw
is not to provide an iterator and just return a Bundle resource as it is.
The naming could be improve to make It more obvious.
Currently, it's impossible to have the same behavior for fetch_raw as we have for fetch_all.