Stream: shorthand
Topic: Questionnaire item extensions
Brian Kaney (Oct 01 2020 at 18:23):
I am trying to use this extension http://build.fhir.org/ig/HL7/sdc/StructureDefinition-sdc-questionnaire-behave-definitions.html#Questionnaire.item.extension:unitOption on a questionnaire.item.item:
Alias: $sdc-questionnaire-unitOption = http://hl7.org/fhir/StructureDefinition/questionnaire-unitOption
...
* item[0].item[0].extension[$sdc-questionnaire-unitOption].valueCoding = #d
And get the "does not exist" failure:
error The element or path you referenced does not exist: item.item[1].extension[$sdc-questionnaire-unitOption].valueCoding
But it works if I use it on the 1st layer, e.g.:
* item.extension[$sdc-questionnaire-unitOption].valueCoding = #d
Any ideas?
Chris Moesel (Oct 01 2020 at 18:56):
This is in an Instance
not a Profile
, right?
Brian Kaney (Oct 01 2020 at 19:06):
Correct, I am making an instance of a Questionnaire
Chris Moesel (Oct 01 2020 at 19:26):
OK. So I'm guessing that this instance is based on a profile that declares the extension on item
? Because if I try it with InstanceOf: Questionnaire
, then even the "1st layer" example doesn't work. It has to be an instance of a profile that declares that extension on item
.
I discovered that if I updated the profile to include:
* item.item.extension contains $sdc-questionnaire-unitOption named sdc 0..1
then your original example worked too.
So the extension in the profile isn't propagating to the recursive item
children. At one point it was unclear if it should because the FHIR doc was ambiguous about that.
So this leads to two more questions:
- Shouldn't you be able to use an extension in an instance even if that extension isn't declared in the profile? I think yes, but obviously SUSHI thinks no. @Mark Kramer ? @Nick Freiter? Would you agree that you should be able to do
* somepath.extension[http://example.org/arbitraryextension].valueString = "Foo"
in an instance of even a base resource? - Should extension declarations propagate through contentreferences? I'll have to try to dig up some old threads to see if we resolved that.
Chris Moesel (Oct 01 2020 at 19:30):
OK. Looks like the answer to #2 is yes, it should propagate.
Brian Kaney (Oct 01 2020 at 19:32):
@Chris Moesel -- incidentally, when I try this one http://hl7.org/fhir/StructureDefinition/questionnaire-unitOption I have the same problem (only working on item
and fails on item.item
). In this case, they specify the extension on Questionnaire.item and Questionnaire.item.item.
Brian Kaney (Oct 01 2020 at 19:35):
(e.g. see the context as specified -- https://www.hl7.org/fhir/extension-questionnaire-unitoption.json.html)
Mark Kramer (Oct 01 2020 at 19:36):
It should be possible to add ad hoc extensions to an instance, certainly.
Chris Moesel (Oct 01 2020 at 19:36):
@Brian Kaney -- I meant declared on the profile itself -- not via the extension context. For example, this is the FSH I used to test it:
Alias: $sdc-questionnaire-unitOption = http://hl7.org/fhir/StructureDefinition/questionnaire-unitOption
Profile: MyQuestionnaireProfile
Parent: Questionnaire
* item.extension contains $sdc-questionnaire-unitOption named sdc 0..1
* item.item.extension contains $sdc-questionnaire-unitOption named sdc 0..1
Instance: MyQuestionnaire
InstanceOf: MyQuestionnaireProfile
* item.extension[$sdc-questionnaire-unitOption].valueCoding = #d
* item[0].text = "A"
* item[0].item[0].text = "B"
* item[0].item[0].extension[$sdc-questionnaire-unitOption].valueCoding = #d
Again, not saying this is how it should be -- just saying how it currently appears to be working.
Brian Kaney (Oct 01 2020 at 19:43):
Right. I think the question here is more of a general profiling one and not a sushi one. I would have expected the behavior to automatically apply to all nested children. Then, if you want to constrain to a particular level you would create an invariant.
The way it is now, you end up with things like http://hl7.org/fhir/StructureDefinition/questionnaire-unitOption where it seems to arbitrarily go 2-levels deep...
Brian Kaney (Oct 01 2020 at 19:44):
Questionnaire.item, PlanDef.action, RequestGroup.action, etc.
Nick Freiter (Oct 01 2020 at 19:49):
Just in reference to the question of adding extensions on an Instance
that do not exist on the corresponding profile, that is definitely a bug. If you do the following:
Instance: MyQ
InstanceOf: Questionnaire
* extension[us-core-race].id = "string"
* item[0].extension[us-core-race].id = "string"
* item[0].item[0].extension[us-core-race].id = "string"
the first line works correctly, while the second two fail.
Nick Freiter (Oct 01 2020 at 20:03):
Tracked here: https://github.com/FHIR/sushi/issues/621
Brian Kaney (Nov 09 2020 at 21:08):
I am still having problems on this, and deeply nested structure more generally..
I feel like there is misunderstanding (likely me being confused) on profiling deeply nested structures. I see this sort of problem present with Questionnaire.item, QuestionnaireResponse.item, PlanDefinition.action, RequestGroup.action, etc. Initially (from before), I would have thought when you define an extension to Questionnaire.item, it should apply to all *.item
, no matter how deep. And if you want to constrain to a certain depth, you would add an invariant rule. But this does not seem to be the case? Right?
Here is an example today (sushi 0.16.0 and IGPublisher v1.1.39). Looking at https://www.hl7.org/fhir/questionnaire-profiles.html. We see some extensions only applied to .item
(e.g. does maxSize
really only apply if the item at root level? is this really the intention of the author of the extension?) While others are on .item
and .item.item
(for instance, questionnaire-minOccurs
, why only one-nesting, why not two or more?). So what I find myself doing, in the case of minValue
where I need it to be nested (e.g. the item is in a group), is explicitly adding (via sushi):
Profile: AdvancedQuestionnaire
Parent: Questionnaire
* item.item.extension contains
minValue named minValue
0..1 MS
This passes sushi build just fine, but then IGPublisher gives me an error:
Questionnaire/MyQuestionnaire: Questionnaire.item[0].item[0] error The extension http://hl7.org/fhir/StructureDefinition/minValue is not allowed to be used at this point (allowed = e:Questionnaire.item; this element is [[Questionnaire.item.item, BackboneElement.item, BackboneElement])
This leads me to creating a new duplicate extension but with a slightly different name, like myMinValue
. Is there a better way to do this? I hope!
Brian Kaney (Nov 09 2020 at 21:21):
I see that it should propagate, from https://chat.fhir.org/#narrow/stream/179252-IG-creation/topic/Clarification.20on.20contentReference/near/204963141 .. (if so, why do we see explicitly profiled .item.item
?).
But in any case, the tooling fails if I only add to the root (sushi error):
Profile: AdvancedQuestionnaire
Parent: Questionnaire
* item.extension contains
minValue named minValue
0..1 MS
Instance: MyQuestionnaire
InstanceOf: AdvancedQuestionnaire
* item.item.extension[minValue].valueInteger = 130
Fails sushi build with:
The element or path you referenced does not exist: item.item.extension[minValue].valueInteger
File: /Users/bkaney/code/myig/fsh/test.fsh
Line: 25
Brian Kaney (Dec 18 2020 at 14:41):
Back on my hobbyhorse here about nested structures...
Is this a feature/bug in FSH or FHIR to have to explicitly define depth? From before, @Grahame Grieve said "the extension automatically applies to the recursive instances"[1], so it looks like a bug?
Chris Moesel (Dec 18 2020 at 15:36):
Thanks for bringing this up again @Brian Kaney. I think we lost the thread on this one, and for that I apologize. I'll add it to our backlog -- but given the time of year, it probably won't get scheduled for someone to actually do until after January 4.
Brian Kaney (Dec 18 2020 at 15:38):
NP! I am generally confused as to what the behavior is supposed to be in FHIR, let alone FSH...
Chris Moesel (Dec 18 2020 at 15:39):
It's still not totally clear to me exactly what constraints do and don't get inherited by recursive content references, but as you noted, Grahame at least confirmed that extensions do carry over -- so we'll make that happen.
Brian Kaney (Dec 18 2020 at 15:41):
Right, but if that's the case, why do we see explicit nesting specified in the FHIR spec (https://www.hl7.org/fhir/questionnaire-profiles.html)?
Chris Moesel (Dec 18 2020 at 15:41):
¯\_(ツ)_/¯
Brian Kaney (Dec 18 2020 at 15:42):
¯\_(ツ)_/¯
correct!
Chris Moesel (Dec 18 2020 at 15:43):
Morten Ernebjerg (Jun 24 2021 at 10:44):
@Chris Moesel Stumbled over this topic & fell right into the same confusions everyone else, so sorry if am repeating old stuff here :smile: My use case is also that I have a profile on QuestionnaireI and want to add a given extension to Questionnaire.item
, Questionnaire.item.item
etc. recursively. The extension has both Questionnaire.item
and Questionnaire.item.item
as allowed context. Adding the extension to only Questionnaire.item
in FSH does not propagate them - at least when I look at the generated profile in firely Forge, it does not show the extension on item/item
. Conversely, explicitly adding the extension to Questionnaire.item.item
in addition causes Forge to give a warning about the generated profile:
Message : If the element definition has a contentReference, it cannot have type, defaultValue, fixed, pattern, example, minValue, maxValue, maxLength, or binding.
I saw that you have a non-FHS solution for this this IG creation thread. But I am not sure how to achieve this in FSH - is that possible or are there other approaches?
Chris Moesel (Jun 24 2021 at 12:46):
Hey @Morten Ernebjerg -- we added support for this in SUSHI 2.0.0 Beta 1 (release notes have some details). But basically, you will do something like this to set it up:
* Questionnaire.item ^type.profile = http://example.org/StructureDefinition/MyQuestionnaire
* Questionnaire.item ^type.profile.extension.url = http://hl7.org/fhir/StructureDefinition/elementdefinition-profile-element
* Questionnaire.item ^type.profile.extension.valueString = "Questionnaire.item"
Then constrain Questionnaire.item
further as you wish. That said, I don't know if the constraints (like item.extensions that you add) will actually be visible in rendered views of Questionnaire.item.item
in Forge or in the documentation produced by the publisher. This is a fairly advanced feature. In SUSHI, however, when we do any processing on Questionnaire.item.item
(or further sub-items), we'll recognize the constraints as being there and act appropriately.
Morten Ernebjerg (Jun 24 2021 at 14:19):
Thanks @Chris Moesel! I will look forward to 2.0, then, and keep the declaration in the profile to the top item
level for simplicity (seeing how tooling support for full recursion seems limited ATM).
Chris Moesel (Jun 24 2021 at 14:40):
OK. Just in case it is not clear, however, you can use SUSHI 2.0.0 beta 1 now. Instructions for installing it are in the release notes (as well as how to tell IG Publisher to use it in auto builds).
Morten Ernebjerg (Jun 24 2021 at 14:57):
Ah, OK :thumbs_up:
Last updated: Apr 12 2022 at 19:14 UTC