Stream: shorthand
Topic: Setting value[x] to a string in an example
Jean Duteau (Nov 06 2020 at 22:27):
I'm having some trouble with creating some examples where I either get a validation error or a "cannot fix string value" error from SUSHI.
Questionnaire.item.answerOption is the element that I'm trying to set.
If I do:
item[RadioGroup].answerOption[0].valueString = "1"
I get:
Element Questionnaire.item.answerOption.value[x] has minimum cardinality 1 but occurs 0 time(s)
If I do:
item[RadioGroup].answerOption[0].value[x] = "1"
I get:
Cannot fix string value on this element since this element does not have a single type
I'm reading the language reference and I can't see how to get out of this dilemma.
Elliot Silver (Nov 06 2020 at 22:40):
Are you profiling or creating an instance? For an instance, shouldn't that be:
item[1234].answerOption[0].valueString = "1"
Jean Duteau (Nov 07 2020 at 02:33):
duouh! mixing my profiling and my instancing :)
Chris Moesel (Nov 09 2020 at 13:45):
Actually, if there is a slice called "RadioGroup", then I think you should be able to say:
item[RadioGroup].answerOption[0].valueString = "1"
IIRC, that would create an instance of item
w/ the RadioGroup
constraints. That said, I don't remember how that works if the RadioGroup
slice has upper card > 1 (i.e., how you specify the second item in the RadioGroup
slice).
So, @Jean Duteau -- this may be a real bug. If you can provide more detail to help us reproduce it, we can take a look.
Patrick Werner (Feb 24 2022 at 11:59):
I think this is a bug. Ended up with something similar: error Element Questionnaire.item.item:currentValue.answerOption.value[x] has minimum cardinality 1 but occurs 0 time(s).
Patrick Werner (Feb 24 2022 at 12:01):
answerOption.value[x] is populated:
* item[=].item[=].answerOption[+].valueCoding = exampleUserDefinedAnswer#answer-a
* item[=].item[=].answerOption[+].valueCoding = exampleUserDefinedAnswer#answer-b "Antwort B"
Patrick Werner (Feb 24 2022 at 12:03):
It seems, that sushi doesn't accept valueConcept as value[x] in the cardinality check.
Patrick Werner (Feb 24 2022 at 12:04):
The generated Profiles/Instances are valid. I checked them with the java validator.
Patrick Werner (Feb 24 2022 at 12:04):
Example: https://fshschool.org/FSHOnline/#/share/3C0Uxkl
Chris Moesel (Feb 24 2022 at 14:29):
Hi @Patrick Werner. Thank you for the FSH Online link to reproduce this. That is extremely helpful!
It seems there are a few things going on with SUSHI here, and that's confusing matters. In general, if you're trying to assign things to slices, SUSHI does better if you name the slices in your path, rather than using indices. This is because SUSHI is not a full-on validator/conformance engine, so it can't determine what elements are in what slices unless you tell it. E.g., don't say
* item[=].item[+].linkId = "a_current_value"
but instead say
* item[=].item[currentValue].linkId = "a_current_value"
That said, the error above is curious, because it is complaining about the answerOption.value[x]
in the currentValue
slice. But... looking at your example, your currentValue
slice does not have an answerOption
at all. And your profile doesn't require one. So SUSHI is definitely confused here.
I changed your example to call out all slices by name like this and it worked:
* item[=].item[question].linkId = "a_question"
* item[=].item[question].type = #choice
* item[=].item[question].readOnly = false
* item[=].item[question].text = "This is the Question"
* item[=].item[question].answerOption[+].valueCoding = exampleUserDefinedAnswer#answer-a
* item[=].item[question].answerOption[+].valueCoding = exampleUserDefinedAnswer#answer-b "Antwort B"
* item[=].item[currentValue].linkId = "a_current_value"
* item[=].item[currentValue].type = #string
* item[=].item[currentValue].readOnly = true
* item[=].item[currentValue].text = "Current Value"
* item[=].item[answerSuggestion].linkId = "a_answer_suggestion"
* item[=].item[answerSuggestion].type = #choice
* item[=].item[answerSuggestion].readOnly = true
* item[=].item[answerSuggestion].text = "Answer Suggestion"
* item[=].item[answerSuggestion].answerOption[+].valueCoding = exampleUserDefinedAnswer#answer-a "Antwort A"
* item[=].item[answerSuggestion].answerOption[+].valueCoding = exampleUserDefinedAnswer#answer-b "Antwort B"
(FSH Online: https://fshschool.org/FSHOnline/#/share/3Hljd7Y)
The downside, however, is that it outputs the items in a different order: currentValue
, answerSuggestion
, question
. This is neither the order you specified in the instance, nor the order you declared the slices in your profile, so I'm not sure where this ordering is coming from. But, order is important in Questionnaire.item
, so... this is not a good thing.
We'll have to look into this some more.
Patrick Werner (Feb 24 2022 at 14:38):
thanks for diggin into it.
Patrick Werner (Feb 24 2022 at 15:26):
(deleted)
Chris Moesel (Feb 24 2022 at 15:30):
Oh. Shoot. I think I kind of know what's happening here. Since those are required slices, SUSHI tries to be "helpful" and auto-populates them into the instance before processing your rules. Which means that the currentValue
is already at index 0, answerSuggestion
is at index 1, and question
is at index 2. Then your rules w/ soft-indexing are applied, your first item gets merged into the currentValue
already at index 0, the next item gets merged into the answerSuggestion
already at index 1, and the last item gets merged into the question
already at index 2. (sigh).
Chris Moesel (Feb 24 2022 at 16:52):
@Patrick Werner - your use case resulted in the following two issues: SUSHI-1028 and SUSHI-1029.
Last updated: Apr 12 2022 at 19:14 UTC