smart-on-fhir / client-py

Python SMART on FHIR client
http://docs.smarthealthit.org
Other
574 stars 209 forks source link

error fetching HAPI open FHIR R4 server? #145

Open DiTo97 opened 6 months ago

DiTo97 commented 6 months ago

Hello,

when I try to the fetch the HAPI open FHIR R4 server using the latest version of the library:

from fhirclient import client
from fhirclient.models import patient

settings = {
    "app_id": "fhir",
    "api_base": "https://hapi.fhir.org/baseR4"
}

smart = client.FHIRClient(settings=settings)

if not smart.prepare():
    # TODO: authorize
    pass

assert smart.ready is True

search_patients = patient.Patient.where(
      struct={"active": "true"}
)

patients = search_patients.perform_resources(smart.server)

if patients:
    print(patients[0].birthDate.isostring)
    print(smart.human_name(patients[0].name[0]))

I get the following error in the response due to the formatting of the FHIR resource itself:

FHIRValidationError: {root}:
  entry.5:
    resource:
      text:
        'Non-optional property "div" on <fhirclient.models.narrative.Narrative object at 0x7f11a1d31ff0> is missing'

I guess the error comes from the built-in pydantic validation, but is there a way to filter out all the responses matching the search pattern that violate the validation, while still letting all the others through, instead of blocking them all?