Stream: hapi
Topic: HAPI JSON parser drops contained element
Yolanda (Oct 08 2021 at 13:41):
Hi, all, I am using HAPI 5.3 to convert a QuestionnaireResponse which has contained a Questionnaire. In QuestionnaireResponse, I have the QuestionnaireResponse.questionnaire with canonical ID referred to the contained Questionnaire. I can see the contained list is set from debugger, however, when I used ctx.newJsonParser().encodeResourceToString(), the contained element disappeared. Noticed that encodeResourceToString() takes IBaseResource as the parameter; "contained" is defined in IDomainResource. I am wondering if other people have seen this issue and if there is any solution to resolve it. Thanks for any help in advance.
Oliver Egger (Oct 08 2021 at 13:49):
add an extension to the QuestionnaireResponse which references the contained resource via the contained id
Yolanda (Oct 08 2021 at 19:30):
Thanks @Oliver Egger for your reply. Can you elaborate more details? Is there an existing extension I can use or do I need define my own extension, then the IParser would acknowledge it?
Oliver Egger (Oct 08 2021 at 19:41):
Contained resources need to be referenced, the canonical is for hapi not sufficient, just use your own extension.
Yolanda (Oct 08 2021 at 20:09):
Does this look right? Thanks
{
"resourceType": "QuestionnaireResponse",
"meta": {
"profile": [
"http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaireresponse-adapt"
]
},
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/contained-id",
"valueCanonical": "#q"
}
],
"contained": [
{
"resourceType": "Questionnaire",
"id": "q",
"meta": {
"profile": [
"http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-adapt"
]
}
}
],
"questionnaire": "#q",
"status": "in-progress"
}
Oliver Egger (Oct 09 2021 at 06:26):
- Use valueReference in extension insteaf of valueCanonical,
- Use for the extension an url /domain which is under your control
Oliver Egger (Oct 09 2021 at 06:31):
See example L174
Yolanda (Oct 11 2021 at 13:40):
@Oliver Egger Your example really helped me! Really appreciate it.
Yolanda (Oct 11 2021 at 13:42):
I am still wondering how HAPI works with respect to those customer defined extensions. Is there any documentation mentions this behavior?
Patrick Werner (Oct 11 2021 at 13:47):
No not that i am aware of.
It doesn't matter what extension you are using, what matters to hapi: is there an actual reference to or from the contained resource to the surrounding resource.
Patrick Werner (Oct 11 2021 at 13:47):
If there is none -> drop contained resource.
Patrick Werner (Oct 11 2021 at 13:48):
So any extension containing the neede reference will stop dropping the contained resource
Patrick Werner (Oct 11 2021 at 13:48):
@James Agnew what do you think of (re)moving this check from the parser?
Patrick Werner (Oct 11 2021 at 13:49):
I think this is some kind of business/FHIR logic which shouldn't be applied while parsing
James Agnew (Oct 11 2021 at 17:02):
This check was removed in HAPI FHIR 5.4.0 - As of that release HAPI FHIR will not string contained resources that are manually added to the list for any reason.
Patrick Werner (Oct 11 2021 at 17:26):
i totally missed that, sorry. Thanks for the heads-up
Yolanda (Oct 11 2021 at 17:31):
Ah, I see. Thanks for the information.
James Agnew (Oct 11 2021 at 21:34):
No worries!
Last updated: Apr 12 2022 at 19:14 UTC