Created
June 23, 2016 16:16
-
-
Save jmandel/824b102c7513d847cef4f4260780aec5 to your computer and use it in GitHub Desktop.
Python resource validation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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