nazrulworld / fhir.resources

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

Subscription issue with FHIR DSTU2 #88

Closed abdulazizibrahim closed 2 years ago

abdulazizibrahim commented 2 years ago

Hi,

I was trying out this library and I faced an issue while creating a subscription object from a json request. You may see the code and the error below.

code :

`
from fhir.resources.DSTU2.subscription import Subscription

data = {

"resourceType": "Subscription",

"id": "1882f571-520c-4c07-ba41-9b83fdb4eb3d",

"criteria": "ReferralRequest?_practitioner=Beck,Rachel MD&_encounter=Encounter/27300-AM0000120709",
"reason": "callback",

"channel": {

    "type": "rest-hook",

    "endpoint": "TBD",

    "payload": "application/json"

}
}

sub = Subscription(**data)

error:

ValidationError Traceback (most recent call last)
in
----> 1 sub = Subscription(**data)

~/.local/lib/python3.9/site-packages/fhir/resources/DSTU2/fhirabstractmodel.py in init(pydantic_self, **data)
134 )
135 if errors:
--> 136 raise ValidationError(errors, pydantic_self.class)
137
138 BaseModel.init(pydantic_self, **data)

ValidationError: 1 validation error for Subscription
resource_type
Wrong ResourceType: fhir.resources.DSTU2.subscription.Subscription expects resource type Substance, but got Subscription. Make sure resource type name is correct and right ModelClass has been chosen. (type=value_error.wrong.resource_type; error=fhir.resources.DSTU2.subscription.Subscription expects resource type Substance, but got Subscription. Make sure resource type name is correct and right ModelClass has been chosen.)

`

nazrulworld commented 2 years ago

Fixed https://github.com/nazrulworld/fhir.resources/commit/352260c87a07a1dcddfe451cc5238b7b02e4ed53