Skip to content

Commit

Permalink
Merge pull request #935 from aehrc/fix/calculated-expression
Browse files Browse the repository at this point in the history
Fix/calculated expression
  • Loading branch information
fongsean authored Jul 23, 2024
2 parents ca2a855 + c80e4cd commit 3ffbd9d
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 84 deletions.
2 changes: 1 addition & 1 deletion apps/smart-forms-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"@aehrc/sdc-assemble": "^1.3.1",
"@aehrc/sdc-populate": "^2.3.0",
"@aehrc/smart-forms-renderer": "^0.36.0",
"@aehrc/smart-forms-renderer": "^0.36.1",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@fontsource/material-icons": "^5.0.18",
Expand Down
2 changes: 1 addition & 1 deletion documentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"typecheck": "tsc"
},
"dependencies": {
"@aehrc/smart-forms-renderer": "^0.36.0",
"@aehrc/smart-forms-renderer": "^0.36.1",
"@docusaurus/core": "^3.4.0",
"@docusaurus/preset-classic": "^3.4.0",
"@docusaurus/theme-live-codeblock": "^3.4.0",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/smart-forms-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aehrc/smart-forms-renderer",
"version": "0.36.0",
"version": "0.36.1",
"description": "FHIR Structured Data Captured (SDC) rendering engine for Smart Forms",
"main": "lib/index.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { useEffect, useState } from 'react';
import type { QuestionnaireItem } from 'fhir/r4';
import type { Coding, QuestionnaireItem } from 'fhir/r4';
import { useQuestionnaireStore } from '../stores';

interface UseCodingCalculatedExpression {
Expand Down Expand Up @@ -56,6 +56,7 @@ function useCodingCalculatedExpression(
calcExpression.value !== valueInString &&
(typeof calcExpression.value === 'string' ||
typeof calcExpression.value === 'number' ||
typeof calcExpression.value === 'object' ||
calcExpression.value === null)
) {
// update ui to show calculated value changes
Expand All @@ -70,6 +71,14 @@ function useCodingCalculatedExpression(
return;
}

// calculatedExpression value is object, check if it is a Coding object
if (typeof calcExpression.value === 'object' && objectIsCoding(calcExpression.value)) {
if (calcExpression.value.code) {
onChangeByCalcExpressionString(calcExpression.value.code);
return;
}
}

// calculatedExpression value is a string or number
const newValueString =
typeof calcExpression.value === 'string'
Expand All @@ -87,4 +96,8 @@ function useCodingCalculatedExpression(
return { calcExpUpdated: calcExpUpdated };
}

function objectIsCoding(obj: any): obj is Coding {
return obj && obj.code && typeof obj.code === 'string';
}

export default useCodingCalculatedExpression;
Loading

0 comments on commit 3ffbd9d

Please sign in to comment.