@aehrc/smart-forms-renderer 0.23.1 → 0.24.1
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/ChoiceItems/ChoiceRadioAnswerOptionView.d.ts +13 -0
- package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionView.js +31 -0
- package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionView.js.map +1 -0
- package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionView.d.ts +13 -0
- package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionView.js +31 -0
- package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionView.js.map +1 -0
- package/lib/components/FormComponents/GroupItem/GroupItem.styles.d.ts +1 -1
- package/lib/components/FormComponents/ItemParts/ItemLabelText.js +7 -1
- package/lib/components/FormComponents/ItemParts/ItemLabelText.js.map +1 -1
- package/lib/hooks/useBooleanCalculatedExpression.d.ts +11 -0
- package/lib/hooks/useBooleanCalculatedExpression.js +47 -0
- package/lib/hooks/useBooleanCalculatedExpression.js.map +1 -0
- package/lib/hooks/useCodingCalculatedExpression.d.ts +11 -0
- package/lib/hooks/useCodingCalculatedExpression.js +51 -0
- package/lib/hooks/useCodingCalculatedExpression.js.map +1 -0
- package/lib/hooks/useDecimalCalculatedExpression.js +6 -2
- package/lib/hooks/useDecimalCalculatedExpression.js.map +1 -1
- package/lib/hooks/useDisplayCalculatedExpression.d.ts +3 -0
- package/lib/hooks/useDisplayCalculatedExpression.js +33 -0
- package/lib/hooks/useDisplayCalculatedExpression.js.map +1 -0
- package/lib/hooks/useIntegerCalculatedExpression.js +6 -2
- package/lib/hooks/useIntegerCalculatedExpression.js.map +1 -1
- package/lib/hooks/useStringCalculatedExpression.js +13 -5
- package/lib/hooks/useStringCalculatedExpression.js.map +1 -1
- package/lib/hooks/useValueSetCodings.js +1 -1
- package/lib/hooks/useValueSetCodings.js.map +1 -1
- package/lib/interfaces/calculatedExpression.interface.d.ts +1 -0
- package/lib/interfaces/questionnaireStore.interface.d.ts +1 -1
- package/lib/stores/questionnaireStore.d.ts +2 -2
- package/lib/utils/calculatedExpression.d.ts +5 -5
- package/lib/utils/calculatedExpression.js +43 -29
- package/lib/utils/calculatedExpression.js.map +1 -1
- package/lib/utils/enableWhen.js +11 -10
- package/lib/utils/enableWhen.js.map +1 -1
- package/lib/utils/fhirpath.d.ts +2 -2
- package/lib/utils/getExpressionsFromItem.d.ts +20 -0
- package/lib/utils/getExpressionsFromItem.js +90 -0
- package/lib/utils/getExpressionsFromItem.js.map +1 -0
- package/lib/utils/initialise.d.ts +2 -2
- package/lib/utils/itemControl.d.ts +1 -7
- package/lib/utils/itemControl.js +0 -20
- package/lib/utils/itemControl.js.map +1 -1
- package/lib/utils/questionnaireStoreUtils/extractOtherExtensions.d.ts +2 -14
- package/lib/utils/questionnaireStoreUtils/extractOtherExtensions.js +6 -46
- package/lib/utils/questionnaireStoreUtils/extractOtherExtensions.js.map +1 -1
- package/lib/utils/removeEmptyAnswers.js +3 -0
- package/lib/utils/removeEmptyAnswers.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FormComponents/ItemParts/ItemLabelText.tsx +12 -1
- package/src/hooks/useDecimalCalculatedExpression.ts +8 -2
- package/src/hooks/useDisplayCalculatedExpression.ts +40 -0
- package/src/hooks/useIntegerCalculatedExpression.ts +8 -2
- package/src/hooks/useStringCalculatedExpression.ts +19 -5
- package/src/hooks/useValueSetCodings.ts +1 -1
- package/src/interfaces/calculatedExpression.interface.ts +1 -0
- package/src/interfaces/questionnaireStore.interface.ts +1 -1
- package/src/stores/questionnaireStore.ts +1 -1
- package/src/utils/calculatedExpression.ts +76 -60
- package/src/utils/enableWhen.ts +32 -10
- package/src/utils/fhirpath.ts +2 -2
- package/src/utils/getExpressionsFromItem.ts +96 -0
- package/src/utils/initialise.ts +2 -2
- package/src/utils/itemControl.ts +1 -21
- package/src/utils/questionnaireStoreUtils/extractOtherExtensions.ts +13 -50
- package/src/utils/removeEmptyAnswers.ts +4 -0
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
|
|
18
|
+
import type { Expression, Extension, QuestionnaireItem } from 'fhir/r4';
|
|
19
|
+
import type { CalculatedExpression } from '../interfaces/calculatedExpression.interface';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get enableWhenExpression.valueExpression if its present in item
|
|
23
|
+
*
|
|
24
|
+
* @author Sean Fong
|
|
25
|
+
*/
|
|
26
|
+
export function getEnableWhenExpression(qItem: QuestionnaireItem): Expression | null {
|
|
27
|
+
const enableWhenExpression = qItem.extension?.find(
|
|
28
|
+
(extension: Extension) =>
|
|
29
|
+
extension.url ===
|
|
30
|
+
'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression' &&
|
|
31
|
+
extension.valueExpression?.language === 'text/fhirpath'
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (enableWhenExpression?.valueExpression) {
|
|
35
|
+
return enableWhenExpression.valueExpression;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get calculatedExpression.valueExpression if its present in item or item._text
|
|
42
|
+
*
|
|
43
|
+
* @author Sean Fong
|
|
44
|
+
*/
|
|
45
|
+
export function getCalculatedExpressions(qItem: QuestionnaireItem): CalculatedExpression[] {
|
|
46
|
+
const calculatedExpressionsInItem = findCalculatedExpressionsInExtensions(qItem.extension ?? [])
|
|
47
|
+
.map(
|
|
48
|
+
(calculatedExpression): CalculatedExpression => ({
|
|
49
|
+
expression: calculatedExpression.valueExpression?.expression ?? '',
|
|
50
|
+
from: 'item'
|
|
51
|
+
})
|
|
52
|
+
)
|
|
53
|
+
.filter((calculatedExpression) => calculatedExpression.expression !== '');
|
|
54
|
+
|
|
55
|
+
const calculatedExpressionsInText = findCalculatedExpressionsInExtensions(
|
|
56
|
+
qItem._text?.extension ?? []
|
|
57
|
+
)
|
|
58
|
+
.map(
|
|
59
|
+
(calculatedExpression): CalculatedExpression => ({
|
|
60
|
+
expression: calculatedExpression.valueExpression?.expression ?? '',
|
|
61
|
+
from: 'item._text'
|
|
62
|
+
})
|
|
63
|
+
)
|
|
64
|
+
.filter((calculatedExpression) => calculatedExpression.expression !== '');
|
|
65
|
+
|
|
66
|
+
return [...calculatedExpressionsInItem, ...calculatedExpressionsInText];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function findCalculatedExpressionsInExtensions(extensions: Extension[]): Extension[] {
|
|
70
|
+
return extensions.filter(
|
|
71
|
+
(extension) =>
|
|
72
|
+
extension.url ===
|
|
73
|
+
'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression' &&
|
|
74
|
+
extension.valueExpression?.language === 'text/fhirpath'
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get answerExpression.valueExpression if its present in item
|
|
80
|
+
*
|
|
81
|
+
* @author Sean Fong
|
|
82
|
+
*/
|
|
83
|
+
export function getAnswerExpression(qItem: QuestionnaireItem): Expression | null {
|
|
84
|
+
const itemControl = qItem.extension?.find(
|
|
85
|
+
(extension: Extension) =>
|
|
86
|
+
extension.url ===
|
|
87
|
+
'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression' &&
|
|
88
|
+
extension.valueExpression?.language === 'text/fhirpath'
|
|
89
|
+
);
|
|
90
|
+
if (itemControl) {
|
|
91
|
+
if (itemControl.valueExpression) {
|
|
92
|
+
return itemControl.valueExpression;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
package/src/utils/initialise.ts
CHANGED
|
@@ -316,7 +316,7 @@ export interface initialFormFromResponseParams {
|
|
|
316
316
|
questionnaireResponse: QuestionnaireResponse;
|
|
317
317
|
enableWhenItems: EnableWhenItems;
|
|
318
318
|
enableWhenExpressions: EnableWhenExpressions;
|
|
319
|
-
calculatedExpressions: Record<string, CalculatedExpression>;
|
|
319
|
+
calculatedExpressions: Record<string, CalculatedExpression[]>;
|
|
320
320
|
variablesFhirPath: Record<string, Expression[]>;
|
|
321
321
|
tabs: Tabs;
|
|
322
322
|
fhirPathContext: Record<string, any>;
|
|
@@ -326,7 +326,7 @@ export function initialiseFormFromResponse(params: initialFormFromResponseParams
|
|
|
326
326
|
initialEnableWhenItems: EnableWhenItems;
|
|
327
327
|
initialEnableWhenLinkedQuestions: Record<string, string[]>;
|
|
328
328
|
initialEnableWhenExpressions: EnableWhenExpressions;
|
|
329
|
-
initialCalculatedExpressions: Record<string, CalculatedExpression>;
|
|
329
|
+
initialCalculatedExpressions: Record<string, CalculatedExpression[]>;
|
|
330
330
|
firstVisibleTab: number;
|
|
331
331
|
updatedFhirPathContext: Record<string, any>;
|
|
332
332
|
} {
|
package/src/utils/itemControl.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import type { Coding,
|
|
18
|
+
import type { Coding, Extension, QuestionnaireItem } from 'fhir/r4';
|
|
19
19
|
import type { RegexValidation } from '../interfaces/regex.interface';
|
|
20
20
|
import { structuredDataCapture } from 'fhir-sdc-helpers';
|
|
21
21
|
|
|
@@ -101,26 +101,6 @@ export function hasHiddenExtension(qItem: QuestionnaireItem): boolean {
|
|
|
101
101
|
return false;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
/**
|
|
105
|
-
* Check if an answerExpression extension is present
|
|
106
|
-
*
|
|
107
|
-
* @author Sean Fong
|
|
108
|
-
*/
|
|
109
|
-
export function getAnswerExpression(qItem: QuestionnaireItem): Expression | null {
|
|
110
|
-
const itemControl = qItem.extension?.find(
|
|
111
|
-
(extension: Extension) =>
|
|
112
|
-
extension.url ===
|
|
113
|
-
'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression' &&
|
|
114
|
-
extension.valueExpression?.language === 'text/fhirpath'
|
|
115
|
-
);
|
|
116
|
-
if (itemControl) {
|
|
117
|
-
if (itemControl.valueExpression) {
|
|
118
|
-
return itemControl.valueExpression;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
104
|
/**
|
|
125
105
|
* Check if the extension has url for items that use open label
|
|
126
106
|
*
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
import type {
|
|
19
19
|
Expression,
|
|
20
|
-
Extension,
|
|
21
20
|
Questionnaire,
|
|
22
21
|
QuestionnaireItem,
|
|
23
22
|
QuestionnaireItemEnableWhen
|
|
@@ -35,7 +34,6 @@ import type {
|
|
|
35
34
|
} from '../../interfaces';
|
|
36
35
|
import type { AnswerExpression } from '../../interfaces/answerExpression.interface';
|
|
37
36
|
import type { ValueSetPromise } from '../../interfaces/valueSet.interface';
|
|
38
|
-
import { getAnswerExpression } from '../itemControl';
|
|
39
37
|
import { getTerminologyServerUrl, getValueSetPromise } from '../valueSet';
|
|
40
38
|
import type { Variables } from '../../interfaces/variables.interface';
|
|
41
39
|
import { getFhirPathVariables, getXFhirQueryVariables } from './extractVariables';
|
|
@@ -44,12 +42,17 @@ import { checkItemIsEnabledRepeat } from '../enableWhen';
|
|
|
44
42
|
import cloneDeep from 'lodash.clonedeep';
|
|
45
43
|
import { emptyResponse } from '../emptyResource';
|
|
46
44
|
import { evaluateEnableWhenRepeatExpressionInstance } from '../enableWhenExpression';
|
|
45
|
+
import {
|
|
46
|
+
getAnswerExpression,
|
|
47
|
+
getCalculatedExpressions,
|
|
48
|
+
getEnableWhenExpression
|
|
49
|
+
} from '../getExpressionsFromItem';
|
|
47
50
|
|
|
48
51
|
interface ReturnParamsRecursive {
|
|
49
52
|
variables: Variables;
|
|
50
53
|
enableWhenItems: EnableWhenItems;
|
|
51
54
|
enableWhenExpressions: EnableWhenExpressions;
|
|
52
|
-
calculatedExpressions: Record<string, CalculatedExpression>;
|
|
55
|
+
calculatedExpressions: Record<string, CalculatedExpression[]>;
|
|
53
56
|
answerExpressions: Record<string, AnswerExpression>;
|
|
54
57
|
valueSetPromises: Record<string, ValueSetPromise>;
|
|
55
58
|
}
|
|
@@ -65,7 +68,7 @@ export function extractOtherExtensions(
|
|
|
65
68
|
singleExpressions: {},
|
|
66
69
|
repeatExpressions: {}
|
|
67
70
|
};
|
|
68
|
-
const calculatedExpressions: Record<string, CalculatedExpression> = {};
|
|
71
|
+
const calculatedExpressions: Record<string, CalculatedExpression[]> = {};
|
|
69
72
|
const answerExpressions: Record<string, AnswerExpression> = {};
|
|
70
73
|
|
|
71
74
|
if (!questionnaire.item || questionnaire.item.length === 0) {
|
|
@@ -114,7 +117,7 @@ interface extractExtensionsFromItemRecursiveParams {
|
|
|
114
117
|
variables: Variables;
|
|
115
118
|
enableWhenItems: EnableWhenItems;
|
|
116
119
|
enableWhenExpressions: EnableWhenExpressions;
|
|
117
|
-
calculatedExpressions: Record<string, CalculatedExpression>;
|
|
120
|
+
calculatedExpressions: Record<string, CalculatedExpression[]>;
|
|
118
121
|
answerExpressions: Record<string, AnswerExpression>;
|
|
119
122
|
valueSetPromises: Record<string, ValueSetPromise>;
|
|
120
123
|
defaultTerminologyServerUrl: string;
|
|
@@ -184,13 +187,13 @@ function extractExtensionsFromItemRecursive(
|
|
|
184
187
|
}
|
|
185
188
|
}
|
|
186
189
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
};
|
|
190
|
+
// Get calculatedExpressions
|
|
191
|
+
const calculatedExpressionsOfItem = getCalculatedExpressions(item);
|
|
192
|
+
if (calculatedExpressionsOfItem.length > 0) {
|
|
193
|
+
calculatedExpressions[item.linkId] = calculatedExpressionsOfItem;
|
|
192
194
|
}
|
|
193
195
|
|
|
196
|
+
// Get answerExpressions
|
|
194
197
|
const answerExpression = getAnswerExpression(item);
|
|
195
198
|
if (answerExpression) {
|
|
196
199
|
answerExpressions[item.linkId] = {
|
|
@@ -417,43 +420,3 @@ function initialiseEnableWhenExpression(
|
|
|
417
420
|
}
|
|
418
421
|
};
|
|
419
422
|
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Check if an enableWhenExpression extension is present
|
|
423
|
-
*
|
|
424
|
-
* @author Sean Fong
|
|
425
|
-
*/
|
|
426
|
-
export function getEnableWhenExpression(qItem: QuestionnaireItem): Expression | null {
|
|
427
|
-
const itemControl = qItem.extension?.find(
|
|
428
|
-
(extension: Extension) =>
|
|
429
|
-
extension.url ===
|
|
430
|
-
'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression' &&
|
|
431
|
-
extension.valueExpression?.language === 'text/fhirpath'
|
|
432
|
-
);
|
|
433
|
-
if (itemControl) {
|
|
434
|
-
if (itemControl.valueExpression) {
|
|
435
|
-
return itemControl.valueExpression;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
return null;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Check if an calculatedExpression extension is present
|
|
443
|
-
*
|
|
444
|
-
* @author Sean Fong
|
|
445
|
-
*/
|
|
446
|
-
export function getCalculatedExpression(qItem: QuestionnaireItem): Expression | null {
|
|
447
|
-
const itemControl = qItem.extension?.find(
|
|
448
|
-
(extension: Extension) =>
|
|
449
|
-
extension.url ===
|
|
450
|
-
'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression' &&
|
|
451
|
-
extension.valueExpression?.language === 'text/fhirpath'
|
|
452
|
-
);
|
|
453
|
-
if (itemControl) {
|
|
454
|
-
if (itemControl.valueExpression) {
|
|
455
|
-
return itemControl.valueExpression;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
return null;
|
|
459
|
-
}
|