Stream: implementers
Topic: HAPI FHIR Parsing Issue
Dennis Warren (Jan 18 2017 at 03:42):
Wondering if anyone here can help me with an odd validation error while attempting to use HAPI to create a DSTU2 FHIR ReferralRequest context from a JSON string. Specifically with the HAPI method: FhirContext.forDstu2().newJsonParser().parseResource( <JSON string> ).
The JSON string is well formed and seems to pass validation in the FHIR test server. But in my code I get validation errors for perfectly valid elements.
This is the error log:
INFO: Creating new FHIR context for FHIR version [DSTU2]
Jan 17, 2017 6:44:37 PM ca.uhn.fhir.parser.LenientErrorHandler unknownElement
WARNING: Unknown element 'name' found while parsing
Jan 17, 2017 6:44:37 PM ca.uhn.fhir.parser.LenientErrorHandler unknownElement
WARNING: Unknown element 'telecom' found while parsing
Jan 17, 2017 6:44:37 PM ca.uhn.fhir.parser.LenientErrorHandler unknownElement
WARNING: Unknown element 'telecom' found while parsing
Jan 17, 2017 6:44:37 PM ca.uhn.fhir.parser.LenientErrorHandler unknownElement
WARNING: Unknown element 'telecom' found while parsing
Jan 17, 2017 6:44:37 PM ca.uhn.fhir.parser.LenientErrorHandler unknownElement
WARNING: Unknown element 'gender' found while parsing
Jan 17, 2017 6:44:37 PM ca.uhn.fhir.parser.LenientErrorHandler unknownElement
WARNING: Unknown element 'birthDate' found while parsing
Jan 17, 2017 6:44:37 PM ca.uhn.fhir.parser.LenientErrorHandler unknownElement
WARNING: Unknown element 'address' found while parsing
Jan 17, 2017 6:44:37 PM ca.uhn.fhir.parser.LenientErrorHandler unknownElement
WARNING: Unknown element 'careProvider' found while parsing
Jan 17, 2017 6:44:37 PM ca.uhn.fhir.parser.LenientErrorHandler unknownElement
WARNING: Unknown element 'id' found while parsing
Jan 17, 2017 6:44:37 PM ca.uhn.fhir.context.FhirContext <init>
James Agnew (Jan 18 2017 at 20:15):
Hi @Dennis Warren, that should work properly for sure.
Would you be able to provide the string you're passing in (or even a subset of it?)
Dennis Warren (Jan 19 2017 at 18:56):
Thank you James;
This is the JSON string being passed:
{
"resourceType": "ReferralRequest",
"id": "Ref/4597856131",
"status": "requested",
"date": "2017-01-18T15:32:00-05:00",
"patient": {
"resourceType": "Patient",
"name": [
{
"given": [
“Test"
],
"family": [
“Patient"
],
"text": “Test Patient"
}
],
"telecom": [
{
"system": "phone",
"value": "604-334-2344",
"use": "home"
},
{
"system": "phone",
"value": "778-238-2342",
"use": "work"
},
{
"system": "email",
"value": "thepatient@patient.com",
"use": "home"
}
],
"gender": "male",
"birthDate": "1966-06-17",
"address": [
{
"line": [
"123 Abc Street"
],
"city": "Vancouver",
"state": "BC"
}
],
"careProvider": [
{
"resourceType": "Practitioner",
"name": {
"given": [
"Doctor"
],
"family": [
"Love"
],
"text": "Doctor Love"
},
"telecom": [
{
"system": "phone",
"value": "604-498-3456",
"use": "work"
}
],
"id": "Practitioner/1"
}
],
"id": "Patient/1"
},
"priority": {
"text": ""
}
}
James Agnew (Jan 20 2017 at 23:41):
Hi @Dennis Warren,
Ahh, you can't nest resources like that in FHIR. The patient element needs to have a reference to the patient, not an actual patient resource. See the example here: http://hl7.org/fhir/referralrequest-example.json.html
There is a mechanism called "contained resources" that you can use for nesting one resource inside another, but it's intended as a last resort. You can learn about the syntax here: http://www.hl7.org/FHIR/references.html
Dennis Warren (Jan 22 2017 at 03:52):
Thank you James. Referenced resources makes much more sense and really does demonstrate the power of FHIR.
In this case my goal was to create a complete Referral Request into a single payload because it is not possible for the target server (host) to callback to the origin (client) for resources. It seemed to me that the Contained Resources approach made the most sense. Is it not possible for the parser to separate each Contained Resource through the unique Resource identifiers? And, I guess - as a work around - would be too dangerous to pull the resources out of the JSON string prior to parsing them?
BTW: This conclusion was drawn by reading HAPI's resource description here: http://hapifhir.io/doc_resource_references.html
I see now that the best way to transmit a single payload is as a Bundle of Resources containing relative URL's. Right? Is it then possible for the HAPI parser to parse each resource in the Bundle automatically?
Lloyd McKenzie (Jan 22 2017 at 15:38):
If you want to pass multiple resources in a single payload, the preferred solution is to use Bundle. "contained" is for when resources *cannot* stand alone - i.e. they'll never be referenced by anything else and don't have enough information to exist as independent entities. The URLs used in the Bundle can be relative, absolute or simple UUIDs, depending on whether the resources are available RESTfully and whether they're all on the same server or not.
Last updated: Apr 12 2022 at 19:14 UTC