-
Notifications
You must be signed in to change notification settings - Fork 24
- Fixing Missing calculatedExpression animations Fixes #1643 #1776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Test with below Questionnaire
{
"resourceType": "Questionnaire",
"id": "AssemblyInstructions",
"meta": {
"profile": []
},
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/variable",
"valueExpression": {
"name": "heightValue",
"language": "text/fhirpath",
"expression": "%resource.descendants().where(linkId='heightValue').answer.valueDecimal"
}
},
{
"url": "http://hl7.org/fhir/StructureDefinition/variable",
"valueExpression": {
"name": "mxValueDisplay",
"language": "text/fhirpath",
"expression": "%resource.descendants().where(linkId='medical-history-condition1').answer.valueCoding.display"
}
},
{
"url": "http://hl7.org/fhir/StructureDefinition/variable",
"valueExpression": {
"name": "mxValue",
"language": "text/fhirpath",
"expression": "%resource.descendants().where(linkId='medical-history-condition1').answer.valueCoding"
}
},
{
"url": "http://hl7.org/fhir/StructureDefinition/variable",
"valueExpression": {
"name": "dob",
"language": "text/fhirpath",
"expression": "%resource.descendants().where(linkId='dob1').answer.value"
}
}
],
"contained": [
{
"resourceType": "ValueSet",
"id": "MedicalHistory",
"url": "https://smartforms.csiro.au/ig/ValueSet/MedicalHistory",
"name": "MedicalHistory",
"title": "Medical History",
"status": "draft",
"experimental": false,
"description": "The Medical History value set includes values that may be used to represent medical history, operations and hospital admissions.",
"compose": {
"include": [
{
"system": "http://snomed.info/sct",
"filter": [
{
"property": "constraint",
"op": "=",
"value": "^32570581000036105|Problem/Diagnosis reference set| OR ^32570141000036105|Procedure foundation reference set|"
}
]
}
]
}
},
{
"resourceType": "ValueSet",
"id": "MedicalHistory2",
"url": "https://smartforms.csiro.au/ig/ValueSet/MedicalHistory",
"name": "MedicalHistory",
"title": "Medical History",
"status": "draft",
"experimental": false,
"description": "The Medical History value set includes values that may be used to represent medical history, operations and hospital admissions.",
"compose": {
"include": [
{
"system": "http://snomed.info/sct",
"filter": [
{
"property": "constraint",
"op": "=",
"value": "^32570581000036105|Problem/Diagnosis reference set| OR ^32570141000036105|Procedure foundation reference set|"
}
]
}
]
}
}
],
"url": "http://www.health.gov.au/assessments/mbs/715",
"version": "0.3.0-assembled",
"name": "AboriginalTorresStraitIslanderHealthCheck",
"title": "Aboriginal and Torres Strait Islander Health Check",
"status": "draft",
"experimental": false,
"subjectType": [
"Patient"
],
"date": "2025-03-14",
"publisher": "AEHRC CSIRO",
"contact": [
{
"name": "AEHRC CSIRO",
"telecom": [
{
"system": "url",
"value": "https://confluence.csiro.au/display/PCDQFPhase2/Primary+Care+Data+Quality+Foundations+-+Phase+2"
}
]
}
],
"jurisdiction": [
{
"coding": [
{
"system": "urn:iso:std:iso:3166",
"code": "AU",
"display": "Australia"
}
]
}
],
"copyright": "Copyright © 2022+ Australian Government Department of Health and Aged Care - All rights reserved.\nThis content is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.\nSee https://creativecommons.org/licenses/by-sa/4.0/.\n",
"item": [
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/entryFormat",
"valueString": "Height"
}
],
"linkId": "heightValue",
"text": "Height (Change Here)",
"type": "decimal",
"required": true,
"item": [
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "unit"
}
]
}
}
],
"linkId": "bmi-height-unit1",
"text": "m",
"type": "display"
}
]
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/entryFormat",
"valueString": "Height"
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(exists(%heightValue), %heightValue, 0.0)"
}
}
],
"linkId": "bmi-height-decimal",
"text": "Height Calc Expr Animation",
"type": "decimal",
"required": true,
"item": [
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "unit"
}
]
}
}
],
"linkId": "bmi-height-unit",
"text": "m",
"type": "display"
}
]
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "autocomplete"
}
]
}
}
],
"linkId": "medical-history-condition1",
"text": "Medical History Condition (Change Here)",
"type": "open-choice",
"answerValueSet": "#MedicalHistory"
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "autocomplete"
}
]
}
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%resource.descendants().where(linkId='medical-history-condition1').answer.valueCoding"
}
}
],
"linkId": "medical-history-condition2",
"text": "Medical History Condition Open Choice CalcExp Animation",
"type": "open-choice",
"answerValueSet": "#MedicalHistory2"
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "autocomplete"
}
]
}
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%mxValue"
}
}
],
"linkId": "medical-history-condition3",
"text": "Medical History Condition Choice CalcExp Animation",
"type": "choice",
"answerValueSet": "#MedicalHistory2"
},
{
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%mxValue.exists(), %mxValue.code, {})"
}
}
],
"linkId": "medical-health-condition-text",
"text": "Medical History Condition Text",
"type": "text"
},
{
"linkId": "dob1",
"type": "dateTime",
"repeats": false,
"text": "Datetime of birth change here"
},
{
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%dob.exists(), %dob, {} )"
}
}
],
"linkId": "dob2",
"type": "dateTime",
"repeats": false,
"text": "Datetime of birth CalcExpr Animation"
}
]
}
leoniedickson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Jana! As discussed, the animation is now also running when a calculatedExpression item is edited by the user, which likely shouldn't be the case as nothing is being calculated by the system
- Introduced `getQRItemId` utility function to manage QR Item IDs, ensuring that IDs generated from calculated expressions are unique. - Updated multiple form components (AttachmentItem, BooleanItem, ChoiceAutocompleteItem, etc.) to utilize `getQRItemId` for initializing answer keys. - This change enhances the reliability of ID handling in components that rely on QR Item answers, particularly in scenarios involving calculated expressions.
|
Thanks @leoniedickson , Good catch, Can you please review the change? The animations fire because the answerId still had the calculatedExpression string which automatically triggers the animation. This behaviour is now changed in the components. |
leoniedickson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Jana - looks like everything's working as it should! Just made one comment on if it's possible to simplify the code a bit
Could you also pop a note in the change log?
| // Create a snapshot of the answer object so the hook can detect value changes | ||
| // even when the answer id stays the same. We stringify the answer to keep the | ||
| // comparison cheap and deterministic. | ||
| const answerSnapshot = qrItem?.answer?.[0] ? JSON.stringify(qrItem.answer[0]) : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering if this is still needed after the qrItem answerKey refactor if all changes are already reflected in changes to answerKey - and if not needed, if it's better to simplify the code
Test with below Questionnaire
{
"resourceType": "Questionnaire",
"id": "AssemblyInstructions",
"meta": {
"profile": []
},
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/variable",
"valueExpression": {
"name": "heightValue",
"language": "text/fhirpath",
"expression": "%resource.descendants().where(linkId='heightValue').answer.valueDecimal"
}
},
],
"contained": [
{
"resourceType": "ValueSet",
"id": "MedicalHistory",
"url": "https://smartforms.csiro.au/ig/ValueSet/MedicalHistory",
"name": "MedicalHistory",
"title": "Medical History",
"status": "draft",
"experimental": false,
"description": "The Medical History value set includes values that may be used to represent medical history, operations and hospital admissions.",
"compose": {
"include": [
{
"system": "http://snomed.info/sct",
"filter": [
{
"property": "constraint",
"op": "=",
"value": "^32570581000036105|Problem/Diagnosis reference set| OR ^32570141000036105|Procedure foundation reference set|"
}
]
}
]
}
},
{
"resourceType": "ValueSet",
"id": "MedicalHistory2",
"url": "https://smartforms.csiro.au/ig/ValueSet/MedicalHistory",
"name": "MedicalHistory",
"title": "Medical History",
"status": "draft",
"experimental": false,
"description": "The Medical History value set includes values that may be used to represent medical history, operations and hospital admissions.",
"compose": {
"include": [
{
"system": "http://snomed.info/sct",
"filter": [
{
"property": "constraint",
"op": "=",
"value": "^32570581000036105|Problem/Diagnosis reference set| OR ^32570141000036105|Procedure foundation reference set|"
}
]
}
]
}
}
],
"url": "http://www.health.gov.au/assessments/mbs/715",
"version": "0.3.0-assembled",
"name": "AboriginalTorresStraitIslanderHealthCheck",
"title": "Aboriginal and Torres Strait Islander Health Check",
"status": "draft",
"experimental": false,
"subjectType": [
"Patient"
],
"date": "2025-03-14",
"publisher": "AEHRC CSIRO",
"contact": [
{
"name": "AEHRC CSIRO",
"telecom": [
{
"system": "url",
"value": "https://confluence.csiro.au/display/PCDQFPhase2/Primary+Care+Data+Quality+Foundations+-+Phase+2"
}
]
}
],
"jurisdiction": [
{
"coding": [
{
"system": "urn:iso:std:iso:3166",
"code": "AU",
"display": "Australia"
}
]
}
],
"copyright": "Copyright © 2022+ Australian Government Department of Health and Aged Care - All rights reserved.\nThis content is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.\nSee https://creativecommons.org/licenses/by-sa/4.0/.\n",
"item": [
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/entryFormat",
"valueString": "Height"
}
],
"linkId": "heightValue",
"text": "Height (Change Here)",
"type": "decimal",
"required": true,
"item": [
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "unit"
}
]
}
}
],
"linkId": "bmi-height-unit1",
"text": "m",
"type": "display"
}
]
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/entryFormat",
"valueString": "Height"
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(exists(%heightValue), %heightValue, 0.0)"
}
}
],
"linkId": "bmi-height-decimal",
"text": "Height Calc Expr Animation",
"type": "decimal",
"required": true,
"item": [
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "unit"
}
]
}
}
],
"linkId": "bmi-height-unit",
"text": "m",
"type": "display"
}
]
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "autocomplete"
}
]
}
}
],
"linkId": "medical-history-condition1",
"text": "Medical History Condition (Change Here)",
"type": "open-choice",
"answerValueSet": "#MedicalHistory"
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "autocomplete"
}
]
}
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%resource.descendants().where(linkId='medical-history-condition1').answer.valueCoding"
}
}
],
"linkId": "medical-history-condition2",
"text": "Medical History Condition Open Choice CalcExp Animation",
"type": "open-choice",
"answerValueSet": "#MedicalHistory2"
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "autocomplete"
}
]
}
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%mxValue"
}
}
],
"linkId": "medical-history-condition3",
"text": "Medical History Condition Choice CalcExp Animation",
"type": "choice",
"answerValueSet": "#MedicalHistory2"
},
{
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%mxValue.exists(), %mxValue.code, {})"
}
}
],
"linkId": "medical-health-condition-text",
"text": "Medical History Condition Text",
"type": "text"
]
}