FHIR Chat · HAPI JSON parser drops contained element · hapi

Stream: hapi

Topic: HAPI JSON parser drops contained element


view this post on Zulip 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.

view this post on Zulip Oliver Egger (Oct 08 2021 at 13:49):

add an extension to the QuestionnaireResponse which references the contained resource via the contained id

view this post on Zulip 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?

view this post on Zulip 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.

view this post on Zulip 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"
}

view this post on Zulip Oliver Egger (Oct 09 2021 at 06:26):

  1. Use valueReference in extension insteaf of valueCanonical,
  2. Use for the extension an url /domain which is under your control

view this post on Zulip Oliver Egger (Oct 09 2021 at 06:31):

See example L174

view this post on Zulip Yolanda (Oct 11 2021 at 13:40):

@Oliver Egger Your example really helped me! Really appreciate it.

view this post on Zulip 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?

view this post on Zulip 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.

view this post on Zulip Patrick Werner (Oct 11 2021 at 13:47):

If there is none -> drop contained resource.

view this post on Zulip Patrick Werner (Oct 11 2021 at 13:48):

So any extension containing the neede reference will stop dropping the contained resource

view this post on Zulip Patrick Werner (Oct 11 2021 at 13:48):

@James Agnew what do you think of (re)moving this check from the parser?

view this post on Zulip 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

view this post on Zulip 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.

view this post on Zulip Patrick Werner (Oct 11 2021 at 17:26):

i totally missed that, sorry. Thanks for the heads-up

view this post on Zulip Yolanda (Oct 11 2021 at 17:31):

Ah, I see. Thanks for the information.

view this post on Zulip James Agnew (Oct 11 2021 at 21:34):

No worries!


Last updated: Apr 12 2022 at 19:14 UTC