Stream: questionnaire
Topic: How to define enable-when according group score
SAM TSAI (Sep 24 2021 at 03:54):
How to define an enable-when for a group according another group's score ?
For example, Group 1 and Group 2.
Group 2 only show when the score of Group 1 is more than 10.
Tilo Christ (Sep 24 2021 at 14:28):
I think that might be a combination of calculatedExpression to score the groups, and enableWhenExpression to evaluate the score and show/hide group 2 accordingly. If you don't care about the score for group 1 as an individual field/variable then you could potentially also bake the scoring into the enableWhenExpression.
Lloyd McKenzie (Sep 24 2021 at 14:38):
Typically if you have a score for group 1, you'll have a read-only (or maybe hidden) question that has the score as an answer. However, you could just calculate it in a variable if you wished. If it's a question, you can access it the same way you access any question answer. If it's a variable, the variable needs to be defined on a common ancestor of group 1 and group 2 so that it's available in the context that group 2's enableWhen is evaluated in
SAM TSAI (Sep 27 2021 at 22:03):
@Tilo Christ
Do you define a calculatedExpression under a group by adding "modifierExtension" with sdc-questionnaire-calculatedExpression ?
Like this:
{
"code": [
{
"code": "DemoGroup081721",
"display": "DemoGroup"
}
],
"item": [
{
"key": 0,
"code": [
{
"code": "714DemoYesNo",
"display": "Are you taking prescription medications?"
}
],
"text": "Are you taking prescription medications?",
"type": "boolean",
"linkId": "714DemoYesNo",
"required": false,
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"code": "radio-button",
"system": "http://hl7.org/fhir/questionnaire-item-control",
"display": "Radio Button"
}
]
}
}
],
"answerOption": [
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/ordinalValue",
"valueDecimal": "1"
}
],
"valueCoding": {
"code": "false",
"display": "No"
}
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/ordinalValue",
"valueDecimal": "2"
}
],
"valueCoding": {
"code": "true",
"display": "Yes"
}
}
],
"groupDisplay": true
}
],
"text": "DemoGroup",
"type": "group",
"linkId": "DemoGroup081721",
"required": false,
"groupDisplay": true,
"modifierExtension": {
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"value": "??"
}
}
Lloyd McKenzie (Sep 27 2021 at 22:12):
calculatedExpression is not a modifier extension. It doesn't change the meaning of other elements
SAM TSAI (Sep 28 2021 at 01:49):
@Lloyd McKenzie
Is this correct ?
"text": "DemoGroup",
"type": "group",
"linkId": "DemoGroup081721",
"required": false,
"groupDisplay": true,
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%resource.repeat(item).where(linkId='4.3.b').item.answer.oridinalValue().aggregate($this +$total,0)",
"description": "Total score"
}
}
]
Lloyd McKenzie (Sep 28 2021 at 02:03):
What is 'groupDisplay'? And you can't put a calculatedExpression on a 'group' item - it has to be a question item that can actually hold the value as an answer.
SAM TSAI (Sep 28 2021 at 02:14):
@Lloyd McKenzie
ok. got it. Thanks a lot!
SAM TSAI (Sep 28 2021 at 02:15):
@Tilo Christ
"If you don't care about the score for group 1 as an individual field/variable then you could potentially also bake the scoring into the enableWhenExpression."
Do you mean I can just reply on enableWhenExpression defined in group 2 to complete this whole functionality?
Like this:
{
"code": [
{
"code": "G2",
"display": "Multiple Levels Branching Sample"
}
],
"text": "Prescription drugs - ENABLE WHEN -New",
"type": "group",
"linkId": "G2",
"required": false,
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%resource.repeat(item).where(linkId='G1').item.answer.oridinalValue().aggregate($this +$total,0) > 10"
}
}
]
}
Lloyd McKenzie (Sep 28 2021 at 02:17):
Yup, that should work if you have no need to actually capture the score in the QuestionnaireResponse.
SAM TSAI (Sep 28 2021 at 02:19):
@Lloyd McKenzie
Thanks a lot!
This is super helpful!
Last updated: Apr 12 2022 at 19:14 UTC