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

How can I validate any FHIR? #78

Open gitpushdashf opened 3 years ago

gitpushdashf commented 3 years ago

Hi,

I'd like to validate any type of FHIR dictionary. Whether a Bundle, MedicationRequest, etc. I just want to know that it's valid FHIR.

So far I have:

from fhir.resources.bundle import Bundle

Bundle(**fhir_dict)

Which works great for bundles. I tried Resource, but it doesn't seem to automatically map the resource.

Is this possible with fhir.resources, or easily atainable? I like the error messages a lot more than JSON Schema.

Thank you!

nazrulworld commented 3 years ago

Hi, @gitpushdashf thanks for your interest in this project. Can you please add the problem with the details, perhaps with an example? //I tried Resource, but it doesn't seem to automatically map the resource.// you mean fhir.resources.resource.Resource?

gitpushdashf commented 3 years ago

We're wanting to make sure the FHIR that developer write is valid. We have some fields that can be any JSON FHIR, whether MedicationRequest or Bundle. So we load the JSON into a dict, and then try to process it. However, we don't know in advance if it might be a MedicationRequest, Bundle, etc. We just want to raise an error if it's invalid.

We've been using jsonschema for this, but the error messages are terrible. These are much easier to read.

Yes, that's right. I meant fhir.resources.resource.Resource.

gitpushdashf commented 3 years ago

Ok, here's what I came up with:

from fhir.resources import construct_fhir_element

construct_fhir_element(resource["resourceType"], resource)

Piggybacking off of #76.