diff --git a/packages/smart-forms-renderer/src/hooks/useValueSetCodings.ts b/packages/smart-forms-renderer/src/hooks/useValueSetCodings.ts index 88843411..068427cd 100644 --- a/packages/smart-forms-renderer/src/hooks/useValueSetCodings.ts +++ b/packages/smart-forms-renderer/src/hooks/useValueSetCodings.ts @@ -77,12 +77,12 @@ function useValueSetCodings( }, [cachedValueSetCodings, processedValueSetCodings, valueSetUrl]); // Attempt to get codings from answer expression - const answerExpression = getAnswerExpression(qItem)?.expression; + const qItemAnswerExpression = getAnswerExpression(qItem)?.expression; initialCodings = useMemo(() => { - if (initialCodings.length === 0 && answerExpression) { - const variable = answerExpression.substring( - answerExpression.indexOf('%') + 1, - answerExpression.indexOf('.') + if (initialCodings.length === 0 && qItemAnswerExpression) { + const variable = qItemAnswerExpression.substring( + qItemAnswerExpression.indexOf('%') + 1, + qItemAnswerExpression.indexOf('.') ); const contextMap: Record = {}; @@ -104,7 +104,7 @@ function useValueSetCodings( try { const evaluated: any[] = fhirpath.evaluate( {}, - answerExpression, + qItemAnswerExpression, contextMap, fhirpath_r4_model ); @@ -124,7 +124,7 @@ function useValueSetCodings( return initialCodings; }, [ - answerExpression, + qItemAnswerExpression, encounter, initialCodings, launchContexts, @@ -137,6 +137,7 @@ function useValueSetCodings( const [loading, setLoading] = useState(false); const [serverError, setServerError] = useState(null); + // Use dynamic valueSet via embeddings in contained ValueSet let dynamicValueSet: DynamicValueSet | null = null; if (cleanValueSetUrl) { dynamicValueSet = dynamicValueSets[cleanValueSetUrl]; @@ -146,8 +147,6 @@ function useValueSetCodings( return; } - // Get ValueSet resource from dynamic value set - // dynamicValueSet is not complete if (!dynamicValueSet.isComplete || !dynamicValueSet.completeResource) { setCodings([]); @@ -197,6 +196,18 @@ function useValueSetCodings( } }, [qItem, dynamicValueSet?.version]); + // Instead of using dynamic answerValueSets, use answerExpressions + // useEffect(() => { + // const answerExpression = answerExpressions[qItem.linkId]; + // + // if (!answerExpression) { + // return; + // } + // + // console.log('answerExpression____'); + // console.log(answerExpression); + // }, [answerExpressions]); + // get options from answerValueSet on render useEffect(() => { const valueSetUrl = qItem.answerValueSet; diff --git a/packages/smart-forms-renderer/src/utils/fhirpathAsyncUtils/fhirpath-async.ts b/packages/smart-forms-renderer/src/utils/fhirpathAsyncUtils/fhirpath-async.ts index 98152f15..ecc02fd1 100644 --- a/packages/smart-forms-renderer/src/utils/fhirpathAsyncUtils/fhirpath-async.ts +++ b/packages/smart-forms-renderer/src/utils/fhirpathAsyncUtils/fhirpath-async.ts @@ -185,7 +185,6 @@ export async function evaluateFhirpathAsync( } // Evaluate the expression - logMessage(debugAsyncFhirpath, outcome, 'performing iteration: ', iterations); try { results = fhirpath.evaluate(fhirData, path, context, model, options); } catch (err: any) { @@ -198,7 +197,6 @@ export async function evaluateFhirpathAsync( if (iterations > 1) { logMessage(debugAsyncFhirpath, outcome, 'total iterations', iterations); } - console.log(outcome); return results; } diff --git a/resources/Questionnaire/QFhirpathAsyncTester.json b/resources/Questionnaire/QFhirpathAsyncTester.json index f1b21e46..cb7bd4d9 100644 --- a/resources/Questionnaire/QFhirpathAsyncTester.json +++ b/resources/Questionnaire/QFhirpathAsyncTester.json @@ -7,14 +7,6 @@ "source": "#CwlqsoGwV8CY9l7l" }, "extension": [ - { - "url": "http://hl7.org/fhir/StructureDefinition/variable", - "valueExpression": { - "name": "ValueSetFhirpathAsync", - "language": "application/x-fhir-query", - "expression": "ValueSet/TestFhirpathAsync" - } - }, { "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-launchContext", "extension": [ @@ -63,7 +55,26 @@ }, { "resourceType": "ValueSet", - "id": "TestFhirpathAsync", + "id": "TestFhirpathAsync2", + "status": "draft", + "compose": { + "include": [ + { + "system": "http://snomed.info/sct", + "filter": [ + { + "property": "constraint", + "op": "=", + "value": "<<{{%conditionResultSctCode2}}.<<363704007|Site|" + } + ] + } + ] + } + }, + { + "resourceType": "ValueSet", + "id": "TestFhirpathAsync3", "status": "draft", "compose": { "include": [ @@ -73,7 +84,7 @@ { "property": "constraint", "op": "=", - "value": "<<{{%conditionResultSctCode}}.<<363704007|Site|" + "value": "<<{{%conditionResultSctCode3}}.<<363704007|Site|" } ] } @@ -89,12 +100,25 @@ "date": "2024-05-01", "publisher": "AEHRC CSIRO", "item": [ + { + "linkId": "Disclaimer", + "text": "This is a proof-of-concept of dynamic terminology usage. The logic might not be fully reliable, and visual elements like loading indicators and error messages are not finalized.", + "_text": { + "extension": [ + { + "url": "http://hl7.org/fhir/StructureDefinition/rendering-xhtml", + "valueString": "
\r\n This is a proof-of-concept of dynamic terminology usage. The logic might not be fully reliable, and visual elements like loading indicators and error messages are not finalized.\r\n
" + } + ] + }, + "type": "display" + }, { "extension": [ { "url": "http://hl7.org/fhir/StructureDefinition/variable", "valueExpression": { - "name": "conditionResult", + "name": "conditionResult2", "language": "text/fhirpath", "expression": "item.where(linkId='scenario-2-condition').answer.value" } @@ -102,18 +126,42 @@ { "url": "http://hl7.org/fhir/StructureDefinition/variable", "valueExpression": { - "name": "conditionResultSctCode", + "name": "conditionResultSctCode2", "language": "text/fhirpath", - "expression": "%conditionResult.code" + "expression": "%conditionResult2.code" } }, { "url": "http://hl7.org/fhir/StructureDefinition/variable", "valueExpression": { - "name": "conditionResult", + "name": "conditionResult2", "language": "text/fhirpath", "expression": "item.where(linkId='scenario-2-condition').answer.value" } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "associatedSite2", + "language": "text/fhirpath", + "expression": "item.where(linkId='scenario-2-associated-site').answer.value" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "enableAssociateSite2", + "language": "text/fhirpath", + "expression": "%conditionResult2.exists()" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "enableLateralityComponents2", + "language": "text/fhirpath", + "expression": "%associatedSite2.memberOf('http://snomed.info/sct?fhir_vs=refset/723264001') = true and %conditionResult2.exists()" + } } ], "linkId": "scenario-2", @@ -132,76 +180,162 @@ } ] } - }, - { - "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-collapsible", - "valueCode": "default-open" } ], "linkId": "scenario-2-condition", - "text": "Condition", + "text": "Procedure", "type": "choice", - "answerValueSet": "#MedicalHistory", - "item": [ - { - "extension": [ - { - "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression", - "valueExpression": { - "description": "Condition result system", - "language": "text/fhirpath", - "expression": "%conditionResult.system" - } - }, - { - "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden", - "valueBoolean": true - } - ], - "linkId": "scenario-2-condition-result-system", - "text": "Condition system", - "type": "string" + "answerValueSet": "#MedicalHistory" + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression", + "valueExpression": { + "description": "Condition result system", + "language": "text/fhirpath", + "expression": "%conditionResult2.system" + } }, { - "extension": [ - { - "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression", - "valueExpression": { - "description": "Condition result code", - "language": "text/fhirpath", - "expression": "%conditionResultSctCode" - } - }, - { - "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden", - "valueBoolean": true - } - ], - "linkId": "scenario-2-condition-result-code", - "text": "Condition code", - "type": "string" + "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden", + "valueBoolean": true + } + ], + "linkId": "scenario-2-condition-result-system", + "text": "Condition system", + "type": "string" + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression", + "valueExpression": { + "description": "Condition result code", + "language": "text/fhirpath", + "expression": "%conditionResultSctCode2" + } }, { - "extension": [ - { - "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression", - "valueExpression": { - "description": "Condition result display", - "language": "text/fhirpath", - "expression": "%conditionResult.display" - } - }, - { - "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden", - "valueBoolean": true - } - ], - "linkId": "scenario-2-condition-result-display", - "text": "Condition display", - "type": "string" + "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden", + "valueBoolean": true + } + ], + "linkId": "scenario-2-condition-result-code", + "text": "Condition code", + "type": "string" + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression", + "valueExpression": { + "description": "Condition result display", + "language": "text/fhirpath", + "expression": "%conditionResult2.display" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden", + "valueBoolean": true + } + ], + "linkId": "scenario-2-condition-result-display", + "text": "Condition display", + "type": "string" + }, + { + "linkId": "scenario-2-associated-site", + "text": "Associated site", + "type": "choice", + "answerValueSet": "#TestFhirpathAsync2", + "enableWhen": [ + { + "question": "scenario-2-condition", + "operator": "exists", + "answerBoolean": true } ] }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression", + "valueExpression": { + "language": "text/fhirpath", + "expression": "%enableLateralityComponents2" + } + } + ], + "linkId": "scenario-2-laterality", + "text": "(Associated site laterality components is enabled)", + "type": "display" + } + ] + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "conditionResult3", + "language": "text/fhirpath", + "expression": "item.where(linkId='scenario-3-condition').answer.value" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "conditionResultSctCode3", + "language": "text/fhirpath", + "expression": "%conditionResult3.code" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "conditionResult3", + "language": "text/fhirpath", + "expression": "item.where(linkId='scenario-3-condition').answer.value" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "associatedSite3", + "language": "text/fhirpath", + "expression": "item.where(linkId='scenario-3-associated-site').answer.value" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "procedureHasSiteBoolean", + "language": "text/fhirpath", + "expression": "expand('http://snomed.info/sct?fhir_vs%3Decl%2F%3C%3C' + iif(%conditionResultSctCode3.exists(), %conditionResultSctCode3, '363704007') + '.%3C%3C363704007').expansion.contains.count() > 0" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "enableAssociateSite3", + "language": "text/fhirpath", + "expression": "%conditionResult3.exists() and %procedureHasSiteBoolean" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "enableLateralityComponents3", + "language": "text/fhirpath", + "expression": "%associatedSite3.memberOf('http://snomed.info/sct?fhir_vs=refset/723264001') = true and %conditionResult3.exists()" + } + } + ], + "linkId": "scenario-3", + "text": "3. Request for MRI of Brain 'Procedure + Site'", + "type": "group", + "item": [ { "extension": [ { @@ -216,25 +350,96 @@ } } ], - "linkId": "scenario-2-associated-site", - "text": "Associated site", + "linkId": "scenario-3-condition", + "text": "Procedure", "type": "choice", - "answerValueSet": "#TestFhirpathAsync" + "answerValueSet": "#MedicalHistory" }, { - "linkId": "medical-history-ref-valueset-instructions", - "text": "The valueSet below is used by fhirpath to dynamically generate a valueSet.", - "type": "display" + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression", + "valueExpression": { + "description": "Condition result system", + "language": "text/fhirpath", + "expression": "%conditionResult3.system" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden", + "valueBoolean": true + } + ], + "linkId": "scenario-2-condition-result-system", + "text": "Condition system", + "type": "string" }, { - "linkId": "medical-history-ref-valueset", - "text": "Reference Valueset", - "type": "reference", - "initial": [ + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression", + "valueExpression": { + "description": "Condition result code", + "language": "text/fhirpath", + "expression": "%conditionResultSctCode3" + } + }, { - "valueString": "ValueSet/123" + "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden", + "valueBoolean": true } - ] + ], + "linkId": "scenario-3-condition-result-code", + "text": "Condition code", + "type": "string" + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression", + "valueExpression": { + "description": "Condition result display", + "language": "text/fhirpath", + "expression": "%conditionResult3.display" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden", + "valueBoolean": true + } + ], + "linkId": "scenario-3-condition-result-display", + "text": "Condition display", + "type": "string" + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression", + "valueExpression": { + "language": "text/fhirpath", + "expression": "%enableAssociateSite3" + } + } + ], + "linkId": "scenario-3-associated-site", + "text": "Associated site", + "type": "choice", + "answerValueSet": "#TestFhirpathAsync3" + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression", + "valueExpression": { + "language": "text/fhirpath", + "expression": "%enableLateralityComponents3" + } + } + ], + "linkId": "scenario-3-laterality", + "text": "(Associated site laterality components is enabled)", + "type": "display" } ] } diff --git a/resources/Questionnaire/QFhirpathAsyncTesterAE.json b/resources/Questionnaire/QFhirpathAsyncTesterAE.json new file mode 100644 index 00000000..3cf7c5b6 --- /dev/null +++ b/resources/Questionnaire/QFhirpathAsyncTesterAE.json @@ -0,0 +1,264 @@ +{ + "resourceType": "Questionnaire", + "id": "CalculatedExpressionCvdRiskCalculatorPrepop", + "meta": { + "versionId": "1", + "lastUpdated": "2024-06-11T10:15:22.026+00:00", + "source": "#CwlqsoGwV8CY9l7l" + }, + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-launchContext", + "extension": [ + { + "url": "name", + "valueCoding": { + "system": "http://hl7.org/fhir/uv/sdc/CodeSystem/launchContext", + "code": "patient" + } + }, + { + "url": "type", + "valueCode": "Patient" + }, + { + "url": "description", + "valueString": "The patient that is to be used to pre-populate the form" + } + ] + } + ], + "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|" + } + ] + } + ] + } + } + ], + "url": "https://smartforms.csiro.au/docs/sdc/population/calculated-expression-2", + "version": "0.1.0", + "name": "CalculatedExpressionCvdRiskCalculatorPrepop", + "title": "Calculated Expression CVD Risk Calculator - Pre-population", + "status": "draft", + "date": "2024-05-01", + "publisher": "AEHRC CSIRO", + "item": [ + { + "linkId": "Disclaimer", + "text": "This is a proof-of-concept of dynamic terminology usage. The logic might not be fully reliable, and visual elements like loading indicators and error messages are not finalized.", + "_text": { + "extension": [ + { + "url": "http://hl7.org/fhir/StructureDefinition/rendering-xhtml", + "valueString": "
\r\n This is a proof-of-concept of dynamic terminology usage. The logic might not be fully reliable, and visual elements like loading indicators and error messages are not finalized.\r\n
" + } + ] + }, + "type": "display" + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "conditionResult2", + "language": "text/fhirpath", + "expression": "item.where(linkId='scenario-2-condition').answer.value" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "conditionResultSctCode2", + "language": "text/fhirpath", + "expression": "%conditionResult2.code" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "conditionResult2", + "language": "text/fhirpath", + "expression": "item.where(linkId='scenario-2-condition').answer.value" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "conditionResult2", + "language": "text/fhirpath", + "expression": "item.where(linkId='scenario-2-condition').answer.value" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "associatedSiteExpandCodings2", + "language": "text/fhirpath", + "expression": "expand('http://snomed.info/sct?fhir_vs%3Decl%2F%3C%3C' + iif(%conditionResultSctCode2.exists(), %conditionResultSctCode2, '') + '.%3C%3C363704007')" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "associatedSite2", + "language": "text/fhirpath", + "expression": "item.where(linkId='scenario-2-associated-site').answer.value" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "enableAssociateSite2", + "language": "text/fhirpath", + "expression": "%conditionResult2.exists()" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/variable", + "valueExpression": { + "name": "enableLateralityComponents2", + "language": "text/fhirpath", + "expression": "%associatedSite2.memberOf('http://snomed.info/sct?fhir_vs=refset/723264001') = true and %conditionResult2.exists()" + } + } + ], + "linkId": "scenario-2", + "text": "Request for X-Ray Right Foot as 'Procedure + Laterality'", + "type": "group", + "item": [ + { + "extension": [ + { + "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl", + "valueCodeableConcept": { + "coding": [ + { + "system": "http://hl7.org/fhir/questionnaire-item-control", + "code": "autocomplete" + } + ] + } + } + ], + "linkId": "scenario-2-condition", + "text": "Procedure", + "type": "choice", + "answerValueSet": "#MedicalHistory" + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression", + "valueExpression": { + "description": "Condition result system", + "language": "text/fhirpath", + "expression": "%conditionResult2.system" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden", + "valueBoolean": true + } + ], + "linkId": "scenario-2-condition-result-system", + "text": "Condition system", + "type": "string" + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression", + "valueExpression": { + "description": "Condition result code", + "language": "text/fhirpath", + "expression": "%conditionResultSctCode2" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden", + "valueBoolean": true + } + ], + "linkId": "scenario-2-condition-result-code", + "text": "Condition code", + "type": "string" + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression", + "valueExpression": { + "description": "Condition result display", + "language": "text/fhirpath", + "expression": "%conditionResult2.display" + } + }, + { + "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden", + "valueBoolean": true + } + ], + "linkId": "scenario-2-condition-result-display", + "text": "Condition display", + "type": "string" + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression", + "valueExpression": { + "name": "AssociatedSites", + "language": "text/fhirpath", + "expression": "%associatedSiteExpandCodings2.expansion.contains" + } + } + ], + "linkId": "scenario-2-associated-site", + "text": "Associated site", + "type": "choice", + "enableWhen": [ + { + "question": "scenario-2-condition", + "operator": "exists", + "answerBoolean": true + } + ] + }, + { + "extension": [ + { + "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression", + "valueExpression": { + "language": "text/fhirpath", + "expression": "%enableLateralityComponents2" + } + } + ], + "linkId": "scenario-2-laterality", + "text": "(Associated site laterality components is enabled)", + "type": "display" + } + ] + } + ] +}