Skip to content

Instantly share code, notes, and snippets.

@jmandel
Created June 23, 2016 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmandel/824b102c7513d847cef4f4260780aec5 to your computer and use it in GitHub Desktop.
Save jmandel/824b102c7513d847cef4f4260780aec5 to your computer and use it in GitHub Desktop.
Python resource validation example
import json
from fhirclient.models.fhirabstractbase import FHIRValidationError
from fhirclient.models.fhirelementfactory import FHIRElementFactory
resource = json.loads("""{
"resourceType": "Condition",
"patient": {
"reference": "Patient/123"
}
}""")
assert "resourceType" in resource, \
"Resource has no resourceType: {res}".format(res=resource)
try:
FHIRElementFactory.instantiate(resource['resourceType'], resource)
except FHIRValidationError as e:
print(e)
"""
Results in:
{root}:
'Non-optional property "code" on <fhirclient.models.condition.Condition object at 0x7f799a39bd10> is missing'
'Non-optional property "verificationStatus" on <fhirclient.models.condition.Condition object at 0x7f799a39bd10> is missing'
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment