-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Describe the bug
Due to how formUpdateQueueStore
's replaceLatestFormUpdate()
works and how calculatedExpressions are implemented (with useEffect). Chained calculatedExpressions do not work.
i.e. Item A's input triggers a calcExp update in Item B, which triggers a calcExp in C.
Another scenario is that when multiple useEffects are updating the QR, replaceLatestFormUpdate()
only looks at the first task
and throws the rest away. This causes only one (or some) fields to be updated, which can be super inconsistent.
Upon inspection of LHC forms and Aidbox forms, both works flawlessly on their renderers.
To Reproduce
Plug below questionnaire into the Playground.
{
"resourceType": "Questionnaire",
"status": "draft",
"item": [ {
"linkId": "my-input",
"text": "Type a number",
"type": "decimal"
},
{
"linkId": "calc-result",
"text": "Input x 2",
"type": "decimal",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%resource.item.where(linkId='my-input').answer.value * 2"
}
}
]
},
{
"linkId": "boolean-field",
"text": "Is result equal to 4?",
"type": "boolean",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%resource.item.where(linkId='calc-result').answer.value = 4"
}
}
]
},
{
"linkId": "dropdown-answeroption",
"text": "Select dropdown",
"type": "choice",
"answerOption": [
{ "valueInteger": 3 },
{ "valueInteger": 4 }
],
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%resource.item.where(linkId='calc-result').answer.value = 4, 4, 3)"
}
}
]
},
{
"linkId": "radio-answeroption",
"text": "Select radio",
"type": "choice",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{ "system": "http://hl7.org/fhir/questionnaire-item-control", "code": "radio-button", "display": "Radio Button" }
]
}
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%resource.item.where(linkId='calc-result').answer.value = 4, 4, 3)"
}
}
],
"answerOption": [
{ "valueInteger": 3 },
{ "valueInteger": 4 }
]
},
{
"linkId": "choice-answeroption",
"text": "Select choice",
"type": "choice",
"answerOption": [
{ "valueInteger": 3 },
{ "valueInteger": 4 }
],
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%resource.item.where(linkId='calc-result').answer.value = 4, 4, 3)"
}
}
]
},
{
"linkId": "dropdown-valueset",
"text": "Dropdown (ValueSet)",
"type": "choice",
"answerValueSet": "#simple-valueset",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%resource.item.where(linkId='calc-result').answer.value = 4 , '4', '3')"
}
}
]
},
{
"linkId": "radio-valueset",
"text": "Radio (ValueSet)",
"type": "choice",
"answerValueSet": "#simple-valueset",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{ "system": "http://hl7.org/fhir/questionnaire-item-control", "code": "radio-button", "display": "Radio Button" }
]
}
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%resource.item.where(linkId='calc-result').answer.value = 4, '4', '3')"
}
}
]
},
{
"linkId": "choice-valueset",
"text": "Choice (ValueSet)",
"type": "choice",
"answerValueSet": "#simple-valueset",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%resource.item.where(linkId='calc-result').answer.value = 4, '4', '3')"
}
}
]
},
{
"linkId": "date-result",
"text": "Today's Date (if result is 4)",
"type": "date",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%resource.item.where(linkId='calc-result').answer.value = 4, today(), null)"
}
}
]
},
{
"linkId": "datetime-result",
"text": "Today's DateTime (if result is 4)",
"type": "dateTime",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%resource.item.where(linkId='calc-result').answer.value = 4, today(), null)"
}
}
]
},
{
"linkId": "string-field",
"text": "String field",
"type": "string",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%resource.item.where(linkId='calc-result').answer.value.exists(), %resource.item.where(linkId='calc-result').answer.value.toString(), '')"
}
}
]
},
{
"linkId": "decimal-field",
"text": "Decimal field",
"type": "decimal",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%resource.item.where(linkId='calc-result').answer.value"
}
}
]
},
{
"linkId": "integer-field",
"text": "Integer field",
"type": "integer",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%resource.item.where(linkId='calc-result').answer.value"
}
}
]
},
{
"linkId": "quantity-field",
"text": "Quantity (kg)",
"type": "quantity",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-unit",
"valueCoding": { "system": "http://unitsofmeasure.org", "code": "kg", "display": "kg" }
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%resource.item.where(linkId='calc-result').answer.value"
}
}
]
},
{
"linkId": "text-field",
"text": "Text (long)",
"type": "text",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%resource.item.where(linkId='calc-result').answer.value.exists(), %resource.item.where(linkId='calc-result').answer.value.toString(), '')"
}
}
]
}
],
"contained": [
{
"resourceType": "ValueSet",
"id": "simple-valueset",
"status": "active",
"compose": {
"include": [
{
"system": "http://example.org/test",
"concept": [
{ "code": "3", "display": "3" },
{ "code": "4", "display": "4" }
]
}
]
},
"expansion": {
"identifier": "urn:uuid:5baa5444-e553-4412-a08c-9ce93d3271e0",
"timestamp": "2023-09-01T11:16:50+10:00",
"total": 2,
"parameter": [ {
"name": "version",
"valueUri": "http://terminology.hl7.org/CodeSystem/v2-0532|2.1.0"
}, {
"name": "used-codesystem",
"valueUri": "http://terminology.hl7.org/CodeSystem/v2-0532|2.1.0"
} ],
"contains": [ { "code": "3", "display": "3" }, { "code": "4", "display": "4" } ]
}
}
]
}
Expected behavior
All fields driven by calculatedExpression should be update at the same time.