@aehrc/smart-forms-renderer 0.30.1 → 0.30.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/FormComponents/ItemParts/ItemLabelText.js +2 -2
- package/lib/components/FormComponents/ItemParts/ItemLabelText.js.map +1 -1
- package/lib/hooks/useDisplayCqfAndCalculatedExpression.d.ts +3 -0
- package/lib/hooks/useDisplayCqfAndCalculatedExpression.js +40 -0
- package/lib/hooks/useDisplayCqfAndCalculatedExpression.js.map +1 -0
- package/lib/utils/debounce.d.ts +1 -1
- package/lib/utils/debounce.js +1 -1
- package/lib/utils/getExpressionsFromItem.js +16 -3
- package/lib/utils/getExpressionsFromItem.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FormComponents/ItemParts/ItemLabelText.tsx +2 -2
- package/src/hooks/{useDisplayCalculatedExpression.ts → useDisplayCqfAndCalculatedExpression.ts} +11 -11
- package/src/stories/assets/questionnaires/QDisplay.ts +77 -0
- package/src/stories/assets/questionnaires/index.ts +0 -2
- package/src/stories/itemTypes/Display.stories.tsx +7 -1
- package/src/utils/debounce.ts +1 -1
- package/src/utils/getExpressionsFromItem.ts +16 -4
- package/storybook.log +0 -6
|
@@ -20,11 +20,11 @@ import parse from 'html-react-parser';
|
|
|
20
20
|
import Box from '@mui/material/Box';
|
|
21
21
|
import ReactMarkdown from 'react-markdown';
|
|
22
22
|
import Typography from '@mui/material/Typography';
|
|
23
|
-
import
|
|
23
|
+
import useDisplayCqfAndCalculatedExpression from '../../../hooks/useDisplayCqfAndCalculatedExpression';
|
|
24
24
|
const ItemLabelText = memo(function ItemLabelText(props) {
|
|
25
25
|
const { qItem, readOnly } = props;
|
|
26
26
|
// Use calculatedExpressionString if available
|
|
27
|
-
const calculatedExpressionString =
|
|
27
|
+
const calculatedExpressionString = useDisplayCqfAndCalculatedExpression(qItem);
|
|
28
28
|
if (calculatedExpressionString) {
|
|
29
29
|
return (React.createElement(Typography, { color: readOnly ? 'text.disabled' : 'text.primary', sx: { mt: 0.25 } }, calculatedExpressionString));
|
|
30
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemLabelText.js","sourceRoot":"","sources":["../../../../src/components/FormComponents/ItemParts/ItemLabelText.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,KAAK,MAAM,mBAAmB,CAAC;AACtC,OAAO,GAAG,MAAM,mBAAmB,CAAC;AACpC,OAAO,aAAa,MAAM,gBAAgB,CAAC;AAC3C,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"ItemLabelText.js","sourceRoot":"","sources":["../../../../src/components/FormComponents/ItemParts/ItemLabelText.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,KAAK,MAAM,mBAAmB,CAAC;AACtC,OAAO,GAAG,MAAM,mBAAmB,CAAC;AACpC,OAAO,aAAa,MAAM,gBAAgB,CAAC;AAC3C,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAClD,OAAO,oCAAoC,MAAM,qDAAqD,CAAC;AAOvG,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,aAAa,CAAC,KAAyB;IACzE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAElC,8CAA8C;IAC9C,MAAM,0BAA0B,GAAG,oCAAoC,CAAC,KAAK,CAAC,CAAC;IAC/E,IAAI,0BAA0B,EAAE;QAC9B,OAAO,CACL,oBAAC,UAAU,IAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,cAAc,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,IAC7E,0BAA0B,CAChB,CACd,CAAC;KACH;IAED,uBAAuB;IACvB,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAE1C,IAAI,WAAW,EAAE;QACf,OAAO,oBAAC,GAAG,QAAE,KAAK,CAAC,WAAW,CAAC,CAAO,CAAC;KACxC;IAED,0BAA0B;IAC1B,MAAM,cAAc,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAChD,IAAI,cAAc,EAAE;QAClB,OAAO,CACL,oBAAC,GAAG;YACF,oBAAC,aAAa,QAAE,cAAc,CAAiB,CAC3C,CACP,CAAC;KACH;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;QAC1B,OAAO,0CAAG,KAAK,CAAC,IAAI,CAAI,CAAC;KAC1B;IAED,qBAAqB;IACrB,OAAO,CACL,oBAAC,UAAU,IAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,cAAc,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,IAC7E,KAAK,CAAC,IAAI,CACA,CACd,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { useQuestionnaireStore } from '../stores';
|
|
18
|
+
function useDisplayCqfAndCalculatedExpression(qItem) {
|
|
19
|
+
var _a;
|
|
20
|
+
const calculatedExpressions = useQuestionnaireStore.use.calculatedExpressions();
|
|
21
|
+
const cqfOrCalcExpression = (_a = calculatedExpressions[qItem.linkId]) === null || _a === void 0 ? void 0 : _a.find((exp) => exp.from === 'item._text');
|
|
22
|
+
if (!cqfOrCalcExpression) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (typeof cqfOrCalcExpression.value === 'string' ||
|
|
26
|
+
typeof cqfOrCalcExpression.value === 'number' ||
|
|
27
|
+
cqfOrCalcExpression.value === null) {
|
|
28
|
+
// calculatedExpression value is null
|
|
29
|
+
if (cqfOrCalcExpression.value === null) {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
// calculatedExpression value is string or number
|
|
33
|
+
return typeof cqfOrCalcExpression.value === 'string'
|
|
34
|
+
? cqfOrCalcExpression.value
|
|
35
|
+
: cqfOrCalcExpression.value.toString();
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
export default useDisplayCqfAndCalculatedExpression;
|
|
40
|
+
//# sourceMappingURL=useDisplayCqfAndCalculatedExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDisplayCqfAndCalculatedExpression.js","sourceRoot":"","sources":["../../src/hooks/useDisplayCqfAndCalculatedExpression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAGlD,SAAS,oCAAoC,CAAC,KAAwB;;IACpE,MAAM,qBAAqB,GAAG,qBAAqB,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;IAEhF,MAAM,mBAAmB,GAAG,MAAA,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,0CAAE,IAAI,CACnE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,YAAY,CACnC,CAAC;IAEF,IAAI,CAAC,mBAAmB,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;IAED,IACE,OAAO,mBAAmB,CAAC,KAAK,KAAK,QAAQ;QAC7C,OAAO,mBAAmB,CAAC,KAAK,KAAK,QAAQ;QAC7C,mBAAmB,CAAC,KAAK,KAAK,IAAI,EAClC;QACA,qCAAqC;QACrC,IAAI,mBAAmB,CAAC,KAAK,KAAK,IAAI,EAAE;YACtC,OAAO,EAAE,CAAC;SACX;QAED,iDAAiD;QACjD,OAAO,OAAO,mBAAmB,CAAC,KAAK,KAAK,QAAQ;YAClD,CAAC,CAAC,mBAAmB,CAAC,KAAK;YAC3B,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;KAC1C;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,eAAe,oCAAoC,CAAC"}
|
package/lib/utils/debounce.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const DEBOUNCE_DURATION =
|
|
1
|
+
export declare const DEBOUNCE_DURATION = 300;
|
|
2
2
|
export declare const AUTOCOMPLETE_DEBOUNCE_DURATION = 300;
|
package/lib/utils/debounce.js
CHANGED
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
export const DEBOUNCE_DURATION =
|
|
17
|
+
export const DEBOUNCE_DURATION = 300;
|
|
18
18
|
export const AUTOCOMPLETE_DEBOUNCE_DURATION = 300;
|
|
19
19
|
//# sourceMappingURL=debounce.js.map
|
|
@@ -38,7 +38,8 @@ export function getEnableWhenExpression(qItem) {
|
|
|
38
38
|
* @author Sean Fong
|
|
39
39
|
*/
|
|
40
40
|
export function getCalculatedExpressions(qItem) {
|
|
41
|
-
var _a, _b, _c;
|
|
41
|
+
var _a, _b, _c, _d, _e;
|
|
42
|
+
// For questions - calculatedExpressions
|
|
42
43
|
const calculatedExpressionsInItem = findCalculatedExpressionsInExtensions((_a = qItem.extension) !== null && _a !== void 0 ? _a : [])
|
|
43
44
|
.map((calculatedExpression) => {
|
|
44
45
|
var _a, _b;
|
|
@@ -48,7 +49,12 @@ export function getCalculatedExpressions(qItem) {
|
|
|
48
49
|
});
|
|
49
50
|
})
|
|
50
51
|
.filter((calculatedExpression) => calculatedExpression.expression !== '');
|
|
51
|
-
|
|
52
|
+
// For item._text - calculatedExpressions and cqfExpressions
|
|
53
|
+
// FIXME this is a band aid addition, eventually we want to fully support cqfExpressions
|
|
54
|
+
const calculatedAndCqfExpressionsInText = [
|
|
55
|
+
...findCqfExpressionsInExtensions((_c = (_b = qItem._text) === null || _b === void 0 ? void 0 : _b.extension) !== null && _c !== void 0 ? _c : []),
|
|
56
|
+
...findCalculatedExpressionsInExtensions((_e = (_d = qItem._text) === null || _d === void 0 ? void 0 : _d.extension) !== null && _e !== void 0 ? _e : [])
|
|
57
|
+
]
|
|
52
58
|
.map((calculatedExpression) => {
|
|
53
59
|
var _a, _b;
|
|
54
60
|
return ({
|
|
@@ -57,7 +63,7 @@ export function getCalculatedExpressions(qItem) {
|
|
|
57
63
|
});
|
|
58
64
|
})
|
|
59
65
|
.filter((calculatedExpression) => calculatedExpression.expression !== '');
|
|
60
|
-
return [...calculatedExpressionsInItem, ...
|
|
66
|
+
return [...calculatedExpressionsInItem, ...calculatedAndCqfExpressionsInText];
|
|
61
67
|
}
|
|
62
68
|
function findCalculatedExpressionsInExtensions(extensions) {
|
|
63
69
|
return extensions.filter((extension) => {
|
|
@@ -67,6 +73,13 @@ function findCalculatedExpressionsInExtensions(extensions) {
|
|
|
67
73
|
((_a = extension.valueExpression) === null || _a === void 0 ? void 0 : _a.language) === 'text/fhirpath';
|
|
68
74
|
});
|
|
69
75
|
}
|
|
76
|
+
function findCqfExpressionsInExtensions(extensions) {
|
|
77
|
+
return extensions.filter((extension) => {
|
|
78
|
+
var _a;
|
|
79
|
+
return extension.url === 'http://hl7.org/fhir/StructureDefinition/cqf-expression' &&
|
|
80
|
+
((_a = extension.valueExpression) === null || _a === void 0 ? void 0 : _a.language) === 'text/fhirpath';
|
|
81
|
+
});
|
|
82
|
+
}
|
|
70
83
|
/**
|
|
71
84
|
* Get answerExpression.valueExpression if its present in item
|
|
72
85
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getExpressionsFromItem.js","sourceRoot":"","sources":["../../src/utils/getExpressionsFromItem.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAwB;;IAC9D,MAAM,oBAAoB,GAAG,MAAA,KAAK,CAAC,SAAS,0CAAE,IAAI,CAChD,CAAC,SAAoB,EAAE,EAAE;;QACvB,OAAA,SAAS,CAAC,GAAG;YACX,uFAAuF;YACzF,CAAA,MAAA,SAAS,CAAC,eAAe,0CAAE,QAAQ,MAAK,eAAe,CAAA;KAAA,CAC1D,CAAC;IAEF,IAAI,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAE,eAAe,EAAE;QACzC,OAAO,oBAAoB,CAAC,eAAe,CAAC;KAC7C;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAAwB;;IAC/D,MAAM,2BAA2B,GAAG,qCAAqC,CAAC,MAAA,KAAK,CAAC,SAAS,mCAAI,EAAE,CAAC;SAC7F,GAAG,CACF,CAAC,oBAAoB,EAAwB,EAAE;;QAAC,OAAA,CAAC;YAC/C,UAAU,EAAE,MAAA,MAAA,oBAAoB,CAAC,eAAe,0CAAE,U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AA,MAAA,SAAS,CAAC,eAAe,0CAAE,QAAQ,MAAK,eAAe,CAAA;KAAA,CAC1D,CAAC;IACF,IAAI,WAAW,EAAE;QACf,IAAI,WAAW,CAAC,eAAe,EAAE;YAC/B,OAAO,WAAW,CAAC,eAAe,CAAC;SACpC;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@ import parse from 'html-react-parser';
|
|
|
22
22
|
import Box from '@mui/material/Box';
|
|
23
23
|
import ReactMarkdown from 'react-markdown';
|
|
24
24
|
import Typography from '@mui/material/Typography';
|
|
25
|
-
import
|
|
25
|
+
import useDisplayCqfAndCalculatedExpression from '../../../hooks/useDisplayCqfAndCalculatedExpression';
|
|
26
26
|
|
|
27
27
|
interface ItemLabelTextProps {
|
|
28
28
|
qItem: QuestionnaireItem;
|
|
@@ -33,7 +33,7 @@ const ItemLabelText = memo(function ItemLabelText(props: ItemLabelTextProps) {
|
|
|
33
33
|
const { qItem, readOnly } = props;
|
|
34
34
|
|
|
35
35
|
// Use calculatedExpressionString if available
|
|
36
|
-
const calculatedExpressionString =
|
|
36
|
+
const calculatedExpressionString = useDisplayCqfAndCalculatedExpression(qItem);
|
|
37
37
|
if (calculatedExpressionString) {
|
|
38
38
|
return (
|
|
39
39
|
<Typography color={readOnly ? 'text.disabled' : 'text.primary'} sx={{ mt: 0.25 }}>
|
package/src/hooks/{useDisplayCalculatedExpression.ts → useDisplayCqfAndCalculatedExpression.ts}
RENAMED
|
@@ -18,34 +18,34 @@
|
|
|
18
18
|
import { useQuestionnaireStore } from '../stores';
|
|
19
19
|
import type { QuestionnaireItem } from 'fhir/r4';
|
|
20
20
|
|
|
21
|
-
function
|
|
21
|
+
function useDisplayCqfAndCalculatedExpression(qItem: QuestionnaireItem): string | null {
|
|
22
22
|
const calculatedExpressions = useQuestionnaireStore.use.calculatedExpressions();
|
|
23
23
|
|
|
24
|
-
const
|
|
24
|
+
const cqfOrCalcExpression = calculatedExpressions[qItem.linkId]?.find(
|
|
25
25
|
(exp) => exp.from === 'item._text'
|
|
26
26
|
);
|
|
27
27
|
|
|
28
|
-
if (!
|
|
28
|
+
if (!cqfOrCalcExpression) {
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
if (
|
|
33
|
-
typeof
|
|
34
|
-
typeof
|
|
35
|
-
|
|
33
|
+
typeof cqfOrCalcExpression.value === 'string' ||
|
|
34
|
+
typeof cqfOrCalcExpression.value === 'number' ||
|
|
35
|
+
cqfOrCalcExpression.value === null
|
|
36
36
|
) {
|
|
37
37
|
// calculatedExpression value is null
|
|
38
|
-
if (
|
|
38
|
+
if (cqfOrCalcExpression.value === null) {
|
|
39
39
|
return '';
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// calculatedExpression value is string or number
|
|
43
|
-
return typeof
|
|
44
|
-
?
|
|
45
|
-
:
|
|
43
|
+
return typeof cqfOrCalcExpression.value === 'string'
|
|
44
|
+
? cqfOrCalcExpression.value
|
|
45
|
+
: cqfOrCalcExpression.value.toString();
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
return null;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export default
|
|
51
|
+
export default useDisplayCqfAndCalculatedExpression;
|
|
@@ -36,3 +36,80 @@ export const qDisplayBasic: Questionnaire = {
|
|
|
36
36
|
}
|
|
37
37
|
]
|
|
38
38
|
};
|
|
39
|
+
|
|
40
|
+
export const qDisplayCalculation: Questionnaire = {
|
|
41
|
+
resourceType: 'Questionnaire',
|
|
42
|
+
id: 'DisplayCalculation',
|
|
43
|
+
name: 'DisplayCalculation',
|
|
44
|
+
title: 'Display Calculation',
|
|
45
|
+
version: '0.1.0',
|
|
46
|
+
status: 'draft',
|
|
47
|
+
publisher: 'AEHRC CSIRO',
|
|
48
|
+
date: '2024-05-01',
|
|
49
|
+
url: 'https://smartforms.csiro.au/docs/components/display/calculation',
|
|
50
|
+
extension: [
|
|
51
|
+
{
|
|
52
|
+
url: 'http://hl7.org/fhir/StructureDefinition/variable',
|
|
53
|
+
valueExpression: {
|
|
54
|
+
name: 'gender',
|
|
55
|
+
language: 'text/fhirpath',
|
|
56
|
+
expression: "item.where(linkId = 'gender-controller').answer.valueCoding.code"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
item: [
|
|
61
|
+
{
|
|
62
|
+
linkId: 'gender-controller',
|
|
63
|
+
text: 'Gender',
|
|
64
|
+
type: 'choice',
|
|
65
|
+
repeats: false,
|
|
66
|
+
answerOption: [
|
|
67
|
+
{
|
|
68
|
+
valueCoding: {
|
|
69
|
+
system: 'http://hl7.org/fhir/administrative-gender',
|
|
70
|
+
code: 'female',
|
|
71
|
+
display: 'Female'
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
valueCoding: {
|
|
76
|
+
system: 'http://hl7.org/fhir/administrative-gender',
|
|
77
|
+
code: 'male',
|
|
78
|
+
display: 'Male'
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
valueCoding: {
|
|
83
|
+
system: 'http://hl7.org/fhir/administrative-gender',
|
|
84
|
+
code: 'other',
|
|
85
|
+
display: 'Other'
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
valueCoding: {
|
|
90
|
+
system: 'http://hl7.org/fhir/administrative-gender',
|
|
91
|
+
code: 'unknown',
|
|
92
|
+
display: 'Unknown'
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
linkId: 'gender-display',
|
|
99
|
+
type: 'display',
|
|
100
|
+
repeats: false,
|
|
101
|
+
_text: {
|
|
102
|
+
extension: [
|
|
103
|
+
{
|
|
104
|
+
url: 'http://hl7.org/fhir/StructureDefinition/cqf-expression',
|
|
105
|
+
valueExpression: {
|
|
106
|
+
language: 'text/fhirpath',
|
|
107
|
+
expression: "'Gender: '+ %gender"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
text: ''
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
};
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
19
19
|
import BuildFormWrapper from '../BuildFormWrapper';
|
|
20
|
-
import { qDisplayBasic } from '../assets/questionnaires/QDisplay';
|
|
20
|
+
import { qDisplayBasic, qDisplayCalculation } from '../assets/questionnaires/QDisplay';
|
|
21
21
|
|
|
22
22
|
// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
|
|
23
23
|
const meta = {
|
|
@@ -37,3 +37,9 @@ export const DisplayBasic: Story = {
|
|
|
37
37
|
questionnaire: qDisplayBasic
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
+
|
|
41
|
+
export const DisplayCalculation: Story = {
|
|
42
|
+
args: {
|
|
43
|
+
questionnaire: qDisplayCalculation
|
|
44
|
+
}
|
|
45
|
+
};
|
package/src/utils/debounce.ts
CHANGED
|
@@ -43,6 +43,7 @@ export function getEnableWhenExpression(qItem: QuestionnaireItem): Expression |
|
|
|
43
43
|
* @author Sean Fong
|
|
44
44
|
*/
|
|
45
45
|
export function getCalculatedExpressions(qItem: QuestionnaireItem): CalculatedExpression[] {
|
|
46
|
+
// For questions - calculatedExpressions
|
|
46
47
|
const calculatedExpressionsInItem = findCalculatedExpressionsInExtensions(qItem.extension ?? [])
|
|
47
48
|
.map(
|
|
48
49
|
(calculatedExpression): CalculatedExpression => ({
|
|
@@ -52,9 +53,12 @@ export function getCalculatedExpressions(qItem: QuestionnaireItem): CalculatedEx
|
|
|
52
53
|
)
|
|
53
54
|
.filter((calculatedExpression) => calculatedExpression.expression !== '');
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
// For item._text - calculatedExpressions and cqfExpressions
|
|
57
|
+
// FIXME this is a band aid addition, eventually we want to fully support cqfExpressions
|
|
58
|
+
const calculatedAndCqfExpressionsInText = [
|
|
59
|
+
...findCqfExpressionsInExtensions(qItem._text?.extension ?? []),
|
|
60
|
+
...findCalculatedExpressionsInExtensions(qItem._text?.extension ?? [])
|
|
61
|
+
]
|
|
58
62
|
.map(
|
|
59
63
|
(calculatedExpression): CalculatedExpression => ({
|
|
60
64
|
expression: calculatedExpression.valueExpression?.expression ?? '',
|
|
@@ -63,7 +67,7 @@ export function getCalculatedExpressions(qItem: QuestionnaireItem): CalculatedEx
|
|
|
63
67
|
)
|
|
64
68
|
.filter((calculatedExpression) => calculatedExpression.expression !== '');
|
|
65
69
|
|
|
66
|
-
return [...calculatedExpressionsInItem, ...
|
|
70
|
+
return [...calculatedExpressionsInItem, ...calculatedAndCqfExpressionsInText];
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
function findCalculatedExpressionsInExtensions(extensions: Extension[]): Extension[] {
|
|
@@ -75,6 +79,14 @@ function findCalculatedExpressionsInExtensions(extensions: Extension[]): Extensi
|
|
|
75
79
|
);
|
|
76
80
|
}
|
|
77
81
|
|
|
82
|
+
function findCqfExpressionsInExtensions(extensions: Extension[]): Extension[] {
|
|
83
|
+
return extensions.filter(
|
|
84
|
+
(extension) =>
|
|
85
|
+
extension.url === 'http://hl7.org/fhir/StructureDefinition/cqf-expression' &&
|
|
86
|
+
extension.valueExpression?.language === 'text/fhirpath'
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
78
90
|
/**
|
|
79
91
|
* Get answerExpression.valueExpression if its present in item
|
|
80
92
|
*
|
package/storybook.log
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
npm ERR! code ETARGET
|
|
2
|
-
npm ERR! notarget No matching version found for @storybook/addon-queryparams@^8.0.10.
|
|
3
|
-
npm ERR! notarget In most cases you or one of your dependencies are requesting
|
|
4
|
-
npm ERR! notarget a package version that doesn't exist.
|
|
5
|
-
|
|
6
|
-
npm ERR! A complete log of this run can be found in: /Users/fon026/.npm/_logs/2024-05-17T03_53_47_310Z-debug-0.log
|