beda-software / fhir-py

FHIR Client for python
MIT License
168 stars 31 forks source link

Error in V1.0.0 of fhirpy #33

Closed diegokaminker closed 4 years ago

diegokaminker commented 4 years ago

Hi I created a repl.it program using fhirpy. You can test it here https://repl.it/@fhirinterm/TryFhirPy

It just runs this:

import asyncio from fhirpy import AsyncFHIRClient

async def main():

Create an instance

client = AsyncFHIRClient(
    'http://test.fhir.org/r4',
    fhir_version='4.0.0',
    authorization='Bearer TOKEN',
)

# Iterate over search set
org_resources = client.resources('Patient')
async for org_resource in org_resources:
    print(org_resource.serialize())

if name == 'main': loop = asyncio.get_event_loop() loop.run_until_complete(main())

I got this error message:

Traceback (most recent call last): File "main.py", line 22, in loop.run_until_complete(main()) File "/usr/local/lib/python3.7/asyncio/base_events.py", line 579, in run_until_complete return future.result() File "main.py", line 16, in main async for org_resource in org_resources: File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/fhirpy/base/lib.py", line496, in aiter items = await iterable_coroutine File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/fhirpy/base/lib.py", line522, in fetch resource = self._perform_resource(data, skip_caching) File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/fhirpy/base/lib.py", line282, in _perform_resource resource = self.client.resource(resource_type, data) File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/fhirpy/base/lib.py", line90, in resource return self.resource_class(self, resource_type=resource_type, kwargs) File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/fhirpy/base/lib.py", line709, in init super(BaseResource, self).init(client, **converted_kwargs) File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/fhirpy/base/lib.py", line597, in init self._raise_error_if_invalid_keys(kwargs.keys()) File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/fhirpy/base/lib.py", line684, in _raise_error_if_invalid_keys key, ', '.join(root_attrs) KeyError: 'Invalid key _birthDate. Possible keys are multipleBirthInteger, text, active, deceasedBoolean, identifier, multipleBirthBoolean, language, extension, contained, address, gender, modifierExtension, id, communication, managingOrganization, resourceType, maritalStatus, photo, telecom, birthDate, name, generalPractitioner, meta, contact, implicitRules, deceasedDateTime, link'

Interestingly, if you replace 'Patient' with 'Organization' It works perfectly KInd regards DK

mkizesov commented 4 years ago

Hi fhir-py validates resources structure in accordance with the specified fhir_version and prohibits any additional elements. The problem here is that some Patient resources on this server (like this http://test.fhir.org/r4/Patient/1254098989) have an element "_birthDate", which doesn't match the FHIR specification because all resource extensions should be stored in "extensions" element.

We'll add some flag to disable resource structure validation in fhir-py soon.

ir4y commented 4 years ago

Right now you can disable validation by assigning schema attribute to None.

client.schema = None
diegokaminker commented 4 years ago

Hi Miron _birthDate is indeed valid as Json FHIR Please see the example at https://www.hl7.org/fhir/json.html Kind regards DK

El jue., 21 nov. 2019 17:21, Miron Kizesov notifications@github.com escribió:

Hi fhir-py validates resources structure in accordance with the specified fhir_version and prohibits any additional elements. The problem here is that some Patient resources on this server (like this http://test.fhir.org/r4/Patient/_search?_id=1254098989) have an element "_birthDate", which doesn't match the FHIR specification because all resource extensions should be stored in "extensions" element.

We'll add some flag to disable resource structure validation in fhir-py soon.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/beda-software/fhir-py/issues/33?email_source=notifications&email_token=ADRQWHMS5DKZ6CNPTJ6PWYTQU2YO7A5CNFSM4JQA6E5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE2ZOKA#issuecomment-557160232, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRQWHLK545DBFMJV4J423TQU2YO7ANCNFSM4JQA6E5A .

mkizesov commented 4 years ago

_birthDate is indeed valid as Json FHIR Please see the example at https://www.hl7.org/fhir/json.html

Hi Diego Thank you for pointing that out, we'll fix this bug soon

mkizesov commented 4 years ago

We decided to remove schemas and schema validation because it doesn't make much sense now. fhir-py will support $validate operation and we also going to add autogenerated type hints for autocompletion.