nazrulworld / fhir.resources

FHIR Resources https://www.hl7.org/fhir/resourcelist.html
https://pypi.org/project/fhir.resources/
Other
365 stars 104 forks source link

AllergyIntolerance object gives "Extra fields not permitted" error for reaction object. #155

Open vshah11 opened 2 months ago

vshah11 commented 2 months ago

Description

I am using fhir.resources to parse the AllergyIntolerance resource object. According to latest version of pydantic v2 and fhir.resources, it should be accepting the reaction.manifestation fields but I keep getting the - extra fields not permitted (type=value_error.extra) error.

Screenshot 2024-06-14 at 12 25 18 PM

The fhir documentation specifying that this is a valid AllergyIntolerance field and not an Extra -

https://hl7.org/fhir/R4/allergyintolerance.html

I wish to understand if there are some breaking changes when upgrading fhir.resources to version 7.1 and pydantic to version 2.*? My previous setup had "fhir.resources==6.4.0", "pydantic==1.10.14" and I did not face this issue.

What I Did

from fhir.resources.allergyintolerance import AllergyIntolerance
resource = AllergyIntolerance.parse_obj(data_object)
AniMukherjee commented 3 days ago

I'm facing similar issue with fhir.resources version: 7.1.0 for Organization.

from fhir.resources.organization import Organization
from fhir.resources.address import Address

data = {"id": "f001", "active": True, "name": "Acme Corporation", "address": [{"country": "Switzerland"}]}
org = Organization(**data)

same code from example is throwing "Extra fields not permitted" error.

nazrulworld commented 2 days ago

It seems you chose the wrong FHIR version. In FHIR R5 https://www.hl7.org/fhir/organization.html there is no property named "address", so naturally you are getting this error.

AniMukherjee commented 2 days ago

Thank you for your response. I'm actually looking for some assistance here. I'm new in Health Care technologies and not very sure of the latest standards.

I went through the documentation and understood that R4 only had "address" in "Organization". Is there any old version of fhir.resources that parses R4 version?

nazrulworld commented 2 days ago

You can try

from fhir.resources.R4B.organization import Organization
from fhir.resources.R4B.address import Address

data = {"id": "f001", "active": True, "name": "Acme Corporation", "address": [{"country": "Switzerland"}]}
org = Organization(**data)
AniMukherjee commented 2 days ago

Thank you again for your help. I'm able to parse my JSONs now!