Stream: shorthand
Topic: Indicating that an extension is mandatory in a slice?
Jean Duteau (Nov 07 2020 at 03:09):
I want to indicate that an extension in one of my slices is mandatory:
* item[DateTime].type from DateTimeItemTypes (required)
* item[DateTime].extension contains http://hl7.org/fhir/StructureDefinition/regex named regex 1..1 MS
But I can't seem to then set this in my instance. When I do item[2].extension[regex].valueString = "asd"
, I get the following error: The element or path you referenced does not exist: item[2].extension[regex].valueString
.
I'm assuming that is because the named regex
part is in the slice and not in the profile itself?
Elliot Silver (Nov 07 2020 at 19:58):
Again, is this mixing profiling and instances? Wouldn't the instance be:
item[2].extension[0].url = http://hl7.org/fhir/StructureDefinition/regex
item[2].extension[0].valueString = "asd"
And then it matches the profiling you've specified?
Elliot Silver (Nov 07 2020 at 20:02):
I have to say, I find that the shorthand documentation is a little lacking in differentiating how to use extensions in instances versus defining them.
PS. Actually, I think the language is a little lacking in that regard too. It would be nicer if using an extension was easier than having to hand code the elements.
PPS. Actually, I think the language is a little lacking in capabilities for instance creation generally. It would be nicer if creating an instance was easier than having to hand code majority of the elements.
Jean Duteau (Nov 09 2020 at 03:02):
hmm, i've always specified the extensions in my instances using the name that I've given to them.
Elliot Silver (Nov 09 2020 at 03:13):
Really? I tried that once and couldn't get it to work, so I figured I was mis-reading the documentation and that approach only worked for profiling. Hmm, maybe I'll have to go back and try it again.
Jean Duteau (Nov 09 2020 at 03:14):
yeah, here is other extensions that I specify in my instance and they work properly:
* item[0].extension[requiredText].valueMarkdown = "Please answer this"
* item[0].extension[sasVariableName].valueString = "SLT"
Jean Duteau (Nov 09 2020 at 03:14):
and my profile has the following:
* item.extension contains ItemTitle named title 1..1 MS and
ItemSASVariableName named sasVariableName 1..1 MS and
ItemRequiredText named requiredText 0..1 MS and
http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl named itemControl 0..1 MS
Elliot Silver (Nov 09 2020 at 03:16):
Ah, ok. my instances aren't profiled, they're just instances of Questionnaire. I wonder if that changes things.
Jean Duteau (Nov 09 2020 at 03:17):
sure, if you haven't defined the extension already, then it probably wouldn't work like I'm doing it.
Nick Freiter (Nov 09 2020 at 13:13):
You should be able to add any extension that SUSHI knows about, even if that extension is not on the profile. So the line:
item[2].extension[regex].valueString = "asd"
should work on an Instance
of a Questionnaire, or a profile of Questionnaire. I've tried testing out that line on an Instance of Questionnaire, and it was working for me. If you're able to share the full Instance you are defining that is causing the error, that could help so we could recreate this.
Chris Moesel (Nov 09 2020 at 13:51):
To add one important clarification to @Nick Freiter's note above, the example above (for adding an arbitrary extension) only works if regex
resolves to an extension by name, id, or url (which, in this case, works out because regex
is the actual id of the extension). The only other way for it to work is for it to resolve to the slice name of an extension in the profile this is an instance of.
Chris Moesel (Nov 09 2020 at 13:56):
@Elliot Silver and @Jean Duteau -- I'm sorry the documentation is lacking. You should be able to reference slices by name in instances. Since extensions are just slices of extension, it should work for them as well.
As for item[2].extension[regex].valueString = "asd"
, @Nick Freiter already noted why this should work no matter what -- but one thing to note is that item[2]
will not be recognized by SUSHI as an item in the DateTime
slice, so therefore it does not use any of the constraints you specified in item[DateTime]
. You would have to say item[DateTime].extension[regex].valueString = "asd"
for it to recognize and use those constraints. I don't recall for sure, but I think if you want to access the 2nd item in the DateTime
slice, you would do item[DateTime][1].extension[regex].valueString = "asd"
.
Elliot Silver (Nov 09 2020 at 15:33):
Thanks.
Nick Freiter said:
You should be able to add any extension that SUSHI knows about, even if that extension is not on the profile.
What constitutes SUSHI knowing about an extension? Does that require a "contains...named" line, and if so, can I do that when invoking an extension rather than profiling the resource the extension is used in? (In my case, the resource and extension are both defined in FHIR core, and I'm just creating an instance using it.)
Nick Freiter (Nov 09 2020 at 16:31):
SUSHI "knows" about an extension if that extension is defined in FSH using the Extension
keyword, or that extension is defined as a StructureDefinition in the dependencies that are specified in the sushi-config.yaml
file, or that extension is defined in FHIR Core (since the FHIR Core definitions are always loaded by SUSHI, without the need for specifying a dependency). It does not require a contains...named
line on the profile.
Nick Freiter (Nov 09 2020 at 16:35):
I'm not sure what you mean by "invoking an extension", but I think an example could help clarify what I mean. The following definition is valid:
Instance: Foo
InstanceOf: Questionnaire
* item[0].extension[regex].valueString = "asd"
Even though Foo
is an instance of Questionnaire
directly, and not a profile of Questionnaire
, I can reference the regex
extension as shown, since SUSHI has loaded the regex
extension from the core FHIR definitions. There is no need to profile Questionnaire
with a rule like:
* extension contains http://hl7.org/fhir/StructureDefinition/regex named regex
Elliot Silver (Nov 09 2020 at 16:54):
OK, assuming I have the dependencies in there, how do I define the name "regex"? Can I do:
Instance: Foo
InstanceOf: Questionnaire
* item[0].extension["http://hl7.org/fhir/StructureDefinition/regex"].valueString = "asd"
Nick Freiter (Nov 09 2020 at 17:00):
You can refer to an extension by its name, id, or url, and SUSHI will look for an extension with a matching name, id, or url. So in this case, the regex
extension is defined in FHIR to have and id and name of regex
, so you can reference it directly as I showed:
* item[0].extension[regex].valueString = "asd"
There is no need to define the name "regex". If you are in a situation where names may conflict, it is usually best to use the URL. In that case I think the most common approach would be to use an alias, like so:
Alias: REGEX = http://hl7.org/fhir/StructureDefinition/regex
Instance: foo
InstanceOf: Questionnaire
* item[0].extension[REGEX].valueString = "asd"
Elliot Silver (Nov 12 2020 at 06:03):
Hmm, so I just retried this.
I have Alias: $ext-questionnaire-itemControl = http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl
defined.
And in my Questionnaire instance, the following works:
...
* item[7].item[2].item[0].linkId = "outcome_asymp_help"
* item[7].item[2].item[0].text = "No: the case remains asymptomatic; Yes: the previously asymptomatic case developed symptoms and/or signs of illness."
* item[7].item[2].item[0].type = #display
* item[7].item[2].item[0].extension[0].url = $ext-questionnaire-itemControl
* item[7].item[2].item[0].extension[0].valueCodeableConcept = $cs-itemControl#help
But none of these work:
* item[7].item[2].item[0].extension[$ext-questionnaire-itemControl].valueCodeableConcept = $cs-itemControl#help
* item[7].item[2].item[0].extension[http://hl7.org/fhir/questionnaire-item-control].valueCodeableConcept = $cs-itemControl#help
* item[7].item[2].item[0].extension["http://hl7.org/fhir/questionnaire-item-control"].valueCodeableConcept = $cs-itemControl#help
All result in the error
Sushi: error The element or path you referenced does not exist: item[7].item[2].item.extension[http://hl7.org/fhir/questionnaire-item-control].valueCodeableConcept (00:08.0336)
Nick Freiter (Nov 12 2020 at 12:42):
Which version of SUSHI are you using? There was a bug in SUSHI versions 0.16.0 or earlier which caused SUSHI to fail to find the path of an extension being added to an Instance, if the extension was nested within another element. See the bug report here.
Elliot Silver (Nov 12 2020 at 14:32):
OK, I'm using 1.6.0. I wasn't ready jump over to the beta.
Last updated: Apr 12 2022 at 19:14 UTC