fhir-py icon indicating copy to clipboard operation
fhir-py copied to clipboard

Add fetch_raw_all support

Open ruscoder opened this issue 3 years ago • 3 comments

Currently, it's impossible to have the same behavior for fetch_raw as we have for fetch_all.

ruscoder avatar Jan 04 '23 11:01 ruscoder

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)

ruscoder avatar Mar 17 '23 10:03 ruscoder

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

ruscoder avatar Aug 02 '24 17:08 ruscoder

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.

ir4y avatar Aug 03 '24 00:08 ir4y