Skip to content

Commit

Permalink
Fix fetch_raw for typed using
Browse files Browse the repository at this point in the history
  • Loading branch information
ruscoder committed Sep 30, 2024
1 parent b3cda90 commit a7b2dee
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.12

* Fix fetch_raw for custom resource class

## 2.0.11

* Rename dump to dump_resource
Expand Down
2 changes: 1 addition & 1 deletion fhirpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .lib import AsyncFHIRClient, SyncFHIRClient

__title__ = "fhir-py"
__version__ = "2.0.11"
__version__ = "2.0.12"
__author__ = "beda.software"
__license__ = "None"
__copyright__ = "Copyright 2024 beda.software"
Expand Down
4 changes: 2 additions & 2 deletions fhirpy/base/lib_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ async def fetch_raw(self) -> Any:
data = await self.client._fetch_resource(self.resource_type, self.params)
data_resource_type = data.get("resourceType", None)

if data_resource_type == "Bundle":
for item in data["entry"]:
if data_resource_type == "Bundle" and not self.custom_resource_class:
for item in data.get("entry", []):
item.resource = self._dict_to_resource(item.resource)

return data
Expand Down
4 changes: 2 additions & 2 deletions fhirpy/base/lib_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ def fetch_raw(self) -> Any:
data = self.client._fetch_resource(self.resource_type, self.params)
data_resource_type = data.get("resourceType", None)

if data_resource_type == "Bundle":
for item in data["entry"]:
if data_resource_type == "Bundle" and not self.custom_resource_class:
for item in data.get("entry", []):
item.resource = self._dict_to_resource(item.resource)

return data
Expand Down
10 changes: 10 additions & 0 deletions tests/test_lib_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,16 @@ async def test_fetch_raw(self):
assert isinstance(entry.resource, AsyncFHIRResource)
assert len(bundle.entry) == 2 # noqa: PLR2004

@pytest.mark.asyncio()
async def test_typed_fetch_raw(self):
await self.create_resource("Patient", name=[{"text": "RareName"}])
await self.create_resource("Patient", name=[{"text": "RareName"}])
bundle = await self.client.resources(Patient).search(name="RareName").fetch_raw()
assert bundle.resourceType == "Bundle"
for entry in bundle.entry:
assert not isinstance(entry.resource, AsyncFHIRResource)
assert len(bundle.entry) == 2 # noqa: PLR2004

async def create_test_patients(self, count=10, name="Not Rare Name"):
bundle = {
"type": "transaction",
Expand Down
9 changes: 9 additions & 0 deletions tests/test_lib_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,15 @@ def test_fetch_raw(self):
assert isinstance(entry.resource, SyncFHIRResource)
assert len(bundle.entry) == 2 # noqa: PLR2004

def test_typed_fetch_raw(self):
self.create_resource("Patient", name=[{"text": "RareName"}])
self.create_resource("Patient", name=[{"text": "RareName"}])
bundle = self.client.resources(Patient).search(name="RareName").fetch_raw()
assert bundle.resourceType == "Bundle"
for entry in bundle.entry:
assert not isinstance(entry.resource, SyncFHIRResource)
assert len(bundle.entry) == 2 # noqa: PLR2004

def create_test_patients(self, count=10, name="Not Rare Name"):
bundle = {
"type": "transaction",
Expand Down

0 comments on commit a7b2dee

Please sign in to comment.