Stream: hapi
Topic: QuestionnaireResponse with contained Questionnaire
Josh Mandel (Sep 29 2021 at 16:50):
@Raheel Sayeed asked at https://chat.fhir.org/#narrow/stream/179166-implementers/topic/Open.20FHIR.20Servers.20that.20support.20Contained.20Resource/near/255396789 about the behavior of some HAPI-based servers including the SMART and Logica sandboxes, where Questionnaires contained within QuestionnaireResponses are stripped at creation time. Is there a HAPI setting that might be responsible for this behavior?
Daniel Venton (Sep 29 2021 at 18:21):
Last I knew there was a bug in HAPI. There are 3 categories of contained resources allowed. 1) Resources that are referenced by the wrapper resource 2) Resources that are referenced by a(nother) resource in the contained list 3) Resources that reference the wrapper resource.
When I was dealing with this, if your contained resource is of category 3, then HAPI doesn't honor that when serializing the resource. It only honors categories 1 and 2. In my case I was trying to stash the Provenance resource into the .contained list. In order to get HAPI to work, I had to code the Provenance to reference itself.
Raheel Sayeed (Sep 29 2021 at 19:06):
1, 2 did work .But this issue seems to specifically affect QuestionnaireResponse resource type when it contains and references its own Questionnaire.
Raheel Sayeed (Sep 29 2021 at 19:07):
Also noting--> UHN HAPI FHIR @ hapi.fhir.org/baseR4 did work. But not SMART and Logica sandboxes
Morten Ernebjerg (Sep 30 2021 at 06:05):
I think contained resources of type 3 are explicitly not allowed - the spec says:
A contained resource SHALL only be included in a resource if something in that resource (potentially another contained resource) has a reference to it.
Morten Ernebjerg (Sep 30 2021 at 06:17):
Is the issue here perhaps that QuestionnaireResponses reference Questionnaires through canonical URLs and that HAPI does not recognize that as a valid link? That is, maybe it only checks the id
element in the contained resource and expects that to occur in a reference inside the wrapper resource or in another contained resource. But in the Q/QR case, the relevant ID used for referencing is the canonical in the url
element. I'm not sure if the spec says smt. about that case.
Morten Ernebjerg (Sep 30 2021 at 07:08):
Indeed, the spec does say smt. about that, viz. that references by canonical are allowed:
Both Reference and canonical types may refer to contained resources
So it could be that HAPI has not yet implemented handling of such references for contained resources.
Patrick Werner (Sep 30 2021 at 15:00):
I assume so. Hapi checks for references to or from the contained resource. If none are found the contained resource won‘t be serialized.
Brian Postlethwaite (Oct 06 2021 at 08:41):
Shouldn't the canonical be referencing the contained resource? Which would make it a type 1 reference from your list? Otherwise you'd need an extension under the questionnaire canonical ref field in the QR
Yolanda (Oct 06 2021 at 14:41):
I ran into an issue while working with "contained" resource using HAPI. Wondering if people have seen this issue? Would appreciate any help to resolve the issue. We are using ca.uhn.hapi.fhir:hapi-fhir-base:5.3.0 and the same version of FHIR structure. The issue is that I can't get the "contained" resources when using the context jsonParser to convert the json string to IResource. I can see the Resource in the contained list but when trying to referencing it, got null. In the mean time, setContained() and addContained() don't work either if I manually create a QuestionnaireResponse and trying to set one Questionnaire in the contained list. Here is the screen shot from my debugger: I can see the "Id" and "meta" but the Quesstionnaire is shown as null. Screen-Shot-2021-10-06-at-10.38.27-AM.png
I am using the cannonical reference: Here is the JSON payload:
{
"resourceType": "QuestionnaireResponse",
"meta": {
"profile": [
"http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaireresponse-adapt"
]
},
"contained": [
{
"resourceType": "Questionnaire",
"id": "q",
"meta": {
"profile": [
"http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-adapt"
]
}
}
],
"questionnaire": "#q",
"status": "in-progress"
}
Yolanda (Oct 06 2021 at 20:01):
By casting IBaseResource to IDomainResource solved the parsing issue.
Yolanda (Oct 06 2021 at 22:57):
Here is the problem with another direction. I am setting the contained with setContained() or addContained(), then use ctx.newJsonParser().encodeResourceToString(Resource). The method encodeResourceToString takes IBaseResource, after that, I don't see the "contained" is retained anymore. Any thoughts?
Last updated: Apr 12 2022 at 19:14 UTC