@aehrc/smart-forms-renderer 1.2.0 → 1.2.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/FadingCheckIcon.d.ts +7 -0
- package/lib/components/FormComponents/ItemParts/FadingCheckIcon.js +26 -0
- package/lib/components/FormComponents/ItemParts/FadingCheckIcon.js.map +1 -0
- package/lib/components/FormComponents/ItemParts/ItemLabelText.d.ts +8 -0
- package/lib/components/FormComponents/ItemParts/ItemLabelText.js +63 -0
- package/lib/components/FormComponents/ItemParts/ItemLabelText.js.map +1 -0
- package/lib/components/FormComponents/ItemParts/ItemLabelWrapper.d.ts +8 -0
- package/lib/components/FormComponents/ItemParts/ItemLabelWrapper.js +53 -0
- package/lib/components/FormComponents/ItemParts/ItemLabelWrapper.js.map +1 -0
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteItem.js +4 -3
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteItem.js.map +1 -1
- package/lib/components/FormComponents/RepeatGroup/DeleteItemButton.d.ts +10 -0
- package/lib/components/FormComponents/RepeatGroup/DeleteItemButton.js +30 -0
- package/lib/components/FormComponents/RepeatGroup/DeleteItemButton.js.map +1 -0
- package/lib/components/FormComponents/SingleItem/SingleItem.js +15 -2
- package/lib/components/FormComponents/SingleItem/SingleItem.js.map +1 -1
- package/lib/components/FormComponents/SingleItem/SingleNestedItems.js +8 -8
- package/lib/components/FormComponents/SingleItem/SingleNestedItems.js.map +1 -1
- package/lib/components/Iconify/Iconify.d.ts +10 -0
- package/lib/components/Iconify/Iconify.js +26 -0
- package/lib/components/Iconify/Iconify.js.map +1 -0
- package/lib/components/Renderer/FormBodyPage.d.ts +9 -0
- package/lib/components/Renderer/FormBodyPage.js +43 -0
- package/lib/components/Renderer/FormBodyPage.js.map +1 -0
- package/lib/components/Renderer/FormTitle.d.ts +7 -0
- package/lib/components/Renderer/FormTitle.js +30 -0
- package/lib/components/Renderer/FormTitle.js.map +1 -0
- package/lib/components/Renderer/FormTopLevelPage.d.ts +9 -0
- package/lib/components/Renderer/FormTopLevelPage.js +29 -0
- package/lib/components/Renderer/FormTopLevelPage.js.map +1 -0
- package/lib/components/Tabs/FormBodyTabListWrapper.js +1 -1
- package/lib/components/Tabs/FormBodyTabListWrapper.js.map +1 -1
- package/lib/hooks/useBooleanCalculatedExpression.d.ts +12 -0
- package/lib/hooks/useBooleanCalculatedExpression.js +53 -0
- package/lib/hooks/useBooleanCalculatedExpression.js.map +1 -0
- package/lib/hooks/useDecimalCalculatedExpression.d.ts +13 -0
- package/lib/hooks/useDecimalCalculatedExpression.js +59 -0
- package/lib/hooks/useDecimalCalculatedExpression.js.map +1 -0
- package/lib/hooks/useIntegerCalculatedExpression.d.ts +12 -0
- package/lib/hooks/useIntegerCalculatedExpression.js +56 -0
- package/lib/hooks/useIntegerCalculatedExpression.js.map +1 -0
- package/lib/hooks/useQuantityCalculatedExpression.d.ts +14 -0
- package/lib/hooks/useQuantityCalculatedExpression.js +107 -0
- package/lib/hooks/useQuantityCalculatedExpression.js.map +1 -0
- package/lib/hooks/useStringCalculatedExpression.d.ts +12 -0
- package/lib/hooks/useStringCalculatedExpression.js +58 -0
- package/lib/hooks/useStringCalculatedExpression.js.map +1 -0
- package/lib/stores/rendererConfigStore.d.ts +1 -1
- package/lib/stories/storybookWrappers/InitialiseFormWrapperForStorybook.d.ts +3 -2
- package/lib/stories/storybookWrappers/InitialiseFormWrapperForStorybook.js +27 -6
- package/lib/stories/storybookWrappers/InitialiseFormWrapperForStorybook.js.map +1 -1
- package/lib/stories/storybookWrappers/index.js +1 -1
- package/lib/theme/Theme.d.ts +44 -0
- package/lib/theme/Theme.js +43 -0
- package/lib/theme/Theme.js.map +1 -0
- package/lib/theme/customGlobalStyles.d.ts +2 -0
- package/lib/theme/customGlobalStyles.js +61 -0
- package/lib/theme/customGlobalStyles.js.map +1 -0
- package/lib/theme/overrides/Accordion.d.ts +14 -0
- package/lib/theme/overrides/Accordion.js +32 -0
- package/lib/theme/overrides/Accordion.js.map +1 -0
- package/lib/theme/overrides/Autocomplete.d.ts +10 -0
- package/lib/theme/overrides/Autocomplete.js +28 -0
- package/lib/theme/overrides/Autocomplete.js.map +1 -0
- package/lib/theme/overrides/Button.d.ts +33 -0
- package/lib/theme/overrides/Button.js +52 -0
- package/lib/theme/overrides/Button.js.map +1 -0
- package/lib/theme/overrides/Card.d.ts +35 -0
- package/lib/theme/overrides/Card.js +49 -0
- package/lib/theme/overrides/Card.js.map +1 -0
- package/lib/theme/overrides/Input.d.ts +64 -0
- package/lib/theme/overrides/Input.js +81 -0
- package/lib/theme/overrides/Input.js.map +1 -0
- package/lib/theme/overrides/Overrides.d.ts +3 -0
- package/lib/theme/overrides/Overrides.js +29 -0
- package/lib/theme/overrides/Overrides.js.map +1 -0
- package/lib/theme/overrides/Paper.d.ts +12 -0
- package/lib/theme/overrides/Paper.js +31 -0
- package/lib/theme/overrides/Paper.js.map +1 -0
- package/lib/theme/overrides/SpeedDial.d.ts +16 -0
- package/lib/theme/overrides/SpeedDial.js +34 -0
- package/lib/theme/overrides/SpeedDial.js.map +1 -0
- package/lib/theme/overrides/Table.d.ts +12 -0
- package/lib/theme/overrides/Table.js +30 -0
- package/lib/theme/overrides/Table.js.map +1 -0
- package/lib/theme/palette.d.ts +27 -0
- package/lib/theme/palette.js +63 -0
- package/lib/theme/palette.js.map +1 -0
- package/lib/theme/shadows.d.ts +2 -0
- package/lib/theme/shadows.js +52 -0
- package/lib/theme/shadows.js.map +1 -0
- package/lib/utils/calculatedExpression.js +11 -0
- package/lib/utils/calculatedExpression.js.map +1 -1
- package/lib/utils/dayjsExtend.d.ts +1 -0
- package/lib/utils/dayjsExtend.js +22 -0
- package/lib/utils/dayjsExtend.js.map +1 -0
- package/lib/utils/initialise.js +8 -1
- package/lib/utils/initialise.js.map +1 -1
- package/lib/utils/itemControl.d.ts +103 -0
- package/lib/utils/itemControl.js +350 -0
- package/lib/utils/itemControl.js.map +1 -0
- package/lib/utils/mapItem.d.ts +1 -1
- package/lib/utils/mapItem.js +2 -0
- package/lib/utils/mapItem.js.map +1 -1
- package/lib/utils/qrItem.d.ts +13 -0
- package/lib/utils/qrItem.js +76 -0
- package/lib/utils/qrItem.js.map +1 -1
- package/lib/utils/questionnaireStoreUtils/addAdditionalVariables.d.ts +2 -0
- package/lib/utils/questionnaireStoreUtils/addAdditionalVariables.js +43 -0
- package/lib/utils/questionnaireStoreUtils/addAdditionalVariables.js.map +1 -0
- package/lib/utils/questionnaireStoreUtils/createQuestionaireModel.d.ts +3 -0
- package/lib/utils/questionnaireStoreUtils/createQuestionaireModel.js +101 -0
- package/lib/utils/questionnaireStoreUtils/createQuestionaireModel.js.map +1 -0
- package/lib/utils/questionnaireStoreUtils/extractOtherExtensions.js +4 -2
- package/lib/utils/questionnaireStoreUtils/extractOtherExtensions.js.map +1 -1
- package/lib/utils/validateQuestionnaire.d.ts +66 -0
- package/lib/utils/validateQuestionnaire.js +559 -0
- package/lib/utils/validateQuestionnaire.js.map +1 -0
- package/package.json +1 -1
- package/src/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteItem.tsx +4 -3
- package/src/components/FormComponents/SingleItem/SingleItem.tsx +16 -2
- package/src/components/FormComponents/SingleItem/SingleNestedItems.tsx +8 -9
- package/src/components/Tabs/FormBodyTabListWrapper.tsx +1 -1
- package/src/stores/rendererConfigStore.ts +1 -1
- package/src/utils/calculatedExpression.ts +11 -0
- package/src/utils/initialise.ts +8 -1
- package/src/utils/mapItem.ts +3 -1
- package/src/utils/qrItem.ts +91 -0
- package/src/utils/questionnaireStoreUtils/extractOtherExtensions.ts +4 -2
- package/lib/interfaces/itemPath.interface.d.ts +0 -31
- package/lib/interfaces/itemPath.interface.js +0 -2
- package/lib/interfaces/itemPath.interface.js.map +0 -1
- package/lib/utils/itemPath.d.ts +0 -57
- package/lib/utils/itemPath.js +0 -75
- package/lib/utils/itemPath.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { QuestionnaireItem } from 'fhir/r4';
|
|
2
|
+
interface UseBooleanCalculatedExpression {
|
|
3
|
+
calcExpUpdated: boolean;
|
|
4
|
+
}
|
|
5
|
+
interface UseBooleanCalculatedExpressionProps {
|
|
6
|
+
qItem: QuestionnaireItem;
|
|
7
|
+
booleanValue: boolean | undefined;
|
|
8
|
+
onChangeByCalcExpressionBoolean: (newValueBoolean: boolean) => void;
|
|
9
|
+
onChangeByCalcExpressionNull: () => void;
|
|
10
|
+
}
|
|
11
|
+
declare function useBooleanCalculatedExpression(props: UseBooleanCalculatedExpressionProps): UseBooleanCalculatedExpression;
|
|
12
|
+
export default useBooleanCalculatedExpression;
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { useEffect, useState } from 'react';
|
|
18
|
+
import { useQuestionnaireStore } from '../stores';
|
|
19
|
+
function useBooleanCalculatedExpression(props) {
|
|
20
|
+
const { qItem, booleanValue, onChangeByCalcExpressionBoolean, onChangeByCalcExpressionNull } = props;
|
|
21
|
+
const calculatedExpressions = useQuestionnaireStore.use.calculatedExpressions();
|
|
22
|
+
const [calcExpUpdated, setCalcExpUpdated] = useState(false);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
var _a;
|
|
25
|
+
const calcExpression = (_a = calculatedExpressions[qItem.linkId]) === null || _a === void 0 ? void 0 : _a.find((exp) => exp.from === 'item');
|
|
26
|
+
if (!calcExpression) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// only update if calculated value is different from current value
|
|
30
|
+
if (calcExpression.value !== booleanValue &&
|
|
31
|
+
(typeof calcExpression.value === 'boolean' || calcExpression.value === null)) {
|
|
32
|
+
// update ui to show calculated value changes
|
|
33
|
+
setCalcExpUpdated(true);
|
|
34
|
+
const timeoutId = setTimeout(() => {
|
|
35
|
+
setCalcExpUpdated(false);
|
|
36
|
+
}, 500);
|
|
37
|
+
// calculatedExpression value is null
|
|
38
|
+
if (calcExpression.value === null) {
|
|
39
|
+
onChangeByCalcExpressionNull();
|
|
40
|
+
return () => clearTimeout(timeoutId);
|
|
41
|
+
}
|
|
42
|
+
// calculatedExpression value is boolean
|
|
43
|
+
onChangeByCalcExpressionBoolean(calcExpression.value);
|
|
44
|
+
return () => clearTimeout(timeoutId);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
// Only trigger this effect if calculatedExpression of item changes
|
|
48
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
|
+
[calculatedExpressions]);
|
|
50
|
+
return { calcExpUpdated: calcExpUpdated };
|
|
51
|
+
}
|
|
52
|
+
export default useBooleanCalculatedExpression;
|
|
53
|
+
//# sourceMappingURL=useBooleanCalculatedExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBooleanCalculatedExpression.js","sourceRoot":"","sources":["../../src/hooks/useBooleanCalculatedExpression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAal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C,CACxB,CAAC;IAEF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAC5C,CAAC;AAED,eAAe,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { QuestionnaireItem } from 'fhir/r4';
|
|
2
|
+
interface UseDecimalCalculatedExpression {
|
|
3
|
+
calcExpUpdated: boolean;
|
|
4
|
+
}
|
|
5
|
+
interface UseDecimalCalculatedExpressionProps {
|
|
6
|
+
qItem: QuestionnaireItem;
|
|
7
|
+
inputValue: string;
|
|
8
|
+
precision: number | null;
|
|
9
|
+
onChangeByCalcExpressionDecimal: (calcExpressionValue: number) => void;
|
|
10
|
+
onChangeByCalcExpressionNull: () => void;
|
|
11
|
+
}
|
|
12
|
+
declare function useDecimalCalculatedExpression(props: UseDecimalCalculatedExpressionProps): UseDecimalCalculatedExpression;
|
|
13
|
+
export default useDecimalCalculatedExpression;
|
|
@@ -0,0 +1,59 @@
|
|
|
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 { useEffect, useState } from 'react';
|
|
18
|
+
import { useQuestionnaireStore } from '../stores';
|
|
19
|
+
function useDecimalCalculatedExpression(props) {
|
|
20
|
+
const { qItem, inputValue, precision, onChangeByCalcExpressionDecimal, onChangeByCalcExpressionNull } = props;
|
|
21
|
+
const calculatedExpressions = useQuestionnaireStore.use.calculatedExpressions();
|
|
22
|
+
const [calcExpUpdated, setCalcExpUpdated] = useState(false);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
var _a;
|
|
25
|
+
const calcExpression = (_a = calculatedExpressions[qItem.linkId]) === null || _a === void 0 ? void 0 : _a.find((exp) => exp.from === 'item');
|
|
26
|
+
if (!calcExpression) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// only update if calculated value is different from current value
|
|
30
|
+
if (calcExpression.value !== inputValue &&
|
|
31
|
+
(typeof calcExpression.value === 'number' || calcExpression.value === null)) {
|
|
32
|
+
const calcExpressionValue = typeof calcExpression.value === 'number' && typeof precision === 'number'
|
|
33
|
+
? parseFloat(calcExpression.value.toFixed(precision))
|
|
34
|
+
: calcExpression.value;
|
|
35
|
+
// only update if calculated value is different from current value
|
|
36
|
+
if (calcExpressionValue !== parseFloat(inputValue)) {
|
|
37
|
+
// update ui to show calculated value changes
|
|
38
|
+
setCalcExpUpdated(true);
|
|
39
|
+
const timeoutId = setTimeout(() => {
|
|
40
|
+
setCalcExpUpdated(false);
|
|
41
|
+
}, 500);
|
|
42
|
+
// calculatedExpression value is null
|
|
43
|
+
if (calcExpressionValue === null) {
|
|
44
|
+
onChangeByCalcExpressionNull();
|
|
45
|
+
return () => clearTimeout(timeoutId);
|
|
46
|
+
}
|
|
47
|
+
// calculatedExpression value is a number
|
|
48
|
+
onChangeByCalcExpressionDecimal(calcExpressionValue);
|
|
49
|
+
return () => clearTimeout(timeoutId);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
// Only trigger this effect if calculatedExpression of item changes
|
|
54
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
55
|
+
[calculatedExpressions]);
|
|
56
|
+
return { calcExpUpdated: calcExpUpdated };
|
|
57
|
+
}
|
|
58
|
+
export default useDecimalCalculatedExpression;
|
|
59
|
+
//# sourceMappingURL=useDecimalCalculatedExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDecimalCalculatedExpression.js","sourceRoot":"","sources":["../../src/hooks/useDecimalCalculatedExpression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAclD,SAAS,8BAA8B,CACrC,KAA0C;IAE1C,MAAM,EACJ,KAAK,EACL,UAAU,EACV,SAAS,EACT,+BAA+B,EAC/B,4BAA4B,EAC7B,GAAG,KAAK,CAAC;IAEV,MAAM,qBAAqB,GAAG,qBAAqB,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;IAEhF,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE5D,SAAS,CACP,GAAG,EAAE;;QACH,MAAM,cAAc,GAAG,MAAA,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,0CAAE,IAAI,CAC9D,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,CAC7B,CAAC;QAEF,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,kEAAkE;QAClE,IACE,cAAc,CAAC,KAAK,KAAK,UAAU;YACnC,CAAC,OAAO,cAAc,CAAC,KAAK,KAAK,QAAQ,IAAI,cAAc,CAAC,KAAK,KAAK,IAAI,CAAC,EAC3E,CAAC;YACD,MAAM,mBAAmB,GACvB,OAAO,cAAc,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,SAAS,KAAK,QAAQ;gBACvE,CAAC,CAAC,UAAU,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;gBACrD,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC;YAE3B,kEAAkE;YAClE,IAAI,mBAAmB,KAAK,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;gBACnD,6CAA6C;gBAC7C,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBACxB,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;oBAChC,iBAAiB,CAAC,KAAK,CAAC,CAAC;gBAC3B,CAAC,EAAE,GAAG,CAAC,CAAC;gBAER,qCAAqC;gBACrC,IAAI,mBAAmB,KAAK,IAAI,EAAE,CAAC;oBACjC,4BAA4B,EAAE,CAAC;oBAC/B,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;gBACvC,CAAC;gBAED,yCAAyC;gBACzC,+BAA+B,CAAC,mBAAmB,CAAC,CAAC;gBACrD,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;IACH,CAAC;IACD,mEAAmE;IACnE,uDAAuD;IACvD,CAAC,qBAAqB,CAAC,CACxB,CAAC;IAEF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAC5C,CAAC;AAED,eAAe,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { QuestionnaireItem } from 'fhir/r4';
|
|
2
|
+
interface UseIntegerCalculatedExpression {
|
|
3
|
+
calcExpUpdated: boolean;
|
|
4
|
+
}
|
|
5
|
+
interface useIntegerCalculatedExpressionProps {
|
|
6
|
+
qItem: QuestionnaireItem;
|
|
7
|
+
inputValue: string;
|
|
8
|
+
onChangeByCalcExpressionInteger: (calcExpressionValue: number) => void;
|
|
9
|
+
onChangeByCalcExpressionNull: () => void;
|
|
10
|
+
}
|
|
11
|
+
declare function useIntegerCalculatedExpression(props: useIntegerCalculatedExpressionProps): UseIntegerCalculatedExpression;
|
|
12
|
+
export default useIntegerCalculatedExpression;
|
|
@@ -0,0 +1,56 @@
|
|
|
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 { useEffect, useState } from 'react';
|
|
18
|
+
import { useQuestionnaireStore } from '../stores';
|
|
19
|
+
function useIntegerCalculatedExpression(props) {
|
|
20
|
+
const { qItem, inputValue, onChangeByCalcExpressionInteger, onChangeByCalcExpressionNull } = props;
|
|
21
|
+
const calculatedExpressions = useQuestionnaireStore.use.calculatedExpressions();
|
|
22
|
+
const [calcExpUpdated, setCalcExpUpdated] = useState(false);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
var _a;
|
|
25
|
+
const calcExpression = (_a = calculatedExpressions[qItem.linkId]) === null || _a === void 0 ? void 0 : _a.find((exp) => exp.from === 'item');
|
|
26
|
+
if (!calcExpression) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// only update if calculated value is different from current value
|
|
30
|
+
if (calcExpression.value !== inputValue &&
|
|
31
|
+
(typeof calcExpression.value === 'number' || calcExpression.value === null)) {
|
|
32
|
+
const calcExpressionValue = calcExpression.value;
|
|
33
|
+
if (calcExpressionValue !== parseInt(inputValue)) {
|
|
34
|
+
// update ui to show calculated value changes
|
|
35
|
+
setCalcExpUpdated(true);
|
|
36
|
+
const timeoutId = setTimeout(() => {
|
|
37
|
+
setCalcExpUpdated(false);
|
|
38
|
+
}, 500);
|
|
39
|
+
// calculatedExpression value is null
|
|
40
|
+
if (calcExpressionValue === null) {
|
|
41
|
+
onChangeByCalcExpressionNull();
|
|
42
|
+
return () => clearTimeout(timeoutId);
|
|
43
|
+
}
|
|
44
|
+
// calculatedExpression value is a number
|
|
45
|
+
onChangeByCalcExpressionInteger(calcExpressionValue);
|
|
46
|
+
return () => clearTimeout(timeoutId);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
// Only trigger this effect if calculatedExpression of item changes
|
|
51
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
|
+
[calculatedExpressions]);
|
|
53
|
+
return { calcExpUpdated: calcExpUpdated };
|
|
54
|
+
}
|
|
55
|
+
export default useIntegerCalculatedExpression;
|
|
56
|
+
//# sourceMappingURL=useIntegerCalculatedExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIntegerCalculatedExpression.js","sourceRoot":"","sources":["../../src/hooks/useIntegerCalculatedExpression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAalD,SAAS,8BAA8B,CACrC,KAA0C;IAE1C,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,+BAA+B,EAAE,4BAA4B,EAAE,GACxF,KAAK,CAAC;IAER,MAAM,qBAAqB,GAAG,qBAAqB,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;IAEhF,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE5D,SAAS,CACP,GAAG,EAAE;;QACH,MAAM,cAAc,GAAG,MAAA,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,0CAAE,IAAI,CAC9D,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,CAC7B,CAAC;QAEF,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,kEAAkE;QAClE,IACE,cAAc,CAAC,KAAK,KAAK,UAAU;YACnC,CAAC,OAAO,cAAc,CAAC,KAAK,KAAK,QAAQ,IAAI,cAAc,CAAC,KAAK,KAAK,IAAI,CAAC,EAC3E,CAAC;YACD,MAAM,mBAAmB,GAAG,cAAc,CAAC,KAAK,CAAC;YAEjD,IAAI,mBAAmB,KAAK,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;gBACjD,6CAA6C;gBAC7C,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBACxB,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;oBAChC,iBAAiB,CAAC,KAAK,CAAC,CAAC;gBAC3B,CAAC,EAAE,GAAG,CAAC,CAAC;gBAER,qCAAqC;gBACrC,IAAI,mBAAmB,KAAK,IAAI,EAAE,CAAC;oBACjC,4BAA4B,EAAE,CAAC;oBAC/B,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;gBACvC,CAAC;gBAED,yCAAyC;gBACzC,+BAA+B,CAAC,mBAAmB,CAAC,CAAC;gBACrD,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;IACH,CAAC;IACD,mEAAmE;IACnE,uDAAuD;IACvD,CAAC,qBAAqB,CAAC,CACxB,CAAC;IAEF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAC5C,CAAC;AAED,eAAe,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { QuestionnaireItem } from 'fhir/r4';
|
|
2
|
+
interface UseQuantityCalculatedExpression {
|
|
3
|
+
calcExpUpdated: boolean;
|
|
4
|
+
}
|
|
5
|
+
interface UseQuantityCalculatedExpressionProps {
|
|
6
|
+
qItem: QuestionnaireItem;
|
|
7
|
+
inputValue: string;
|
|
8
|
+
precision: number | null;
|
|
9
|
+
onChangeByCalcExpressionDecimal: (newValue: number) => void;
|
|
10
|
+
onChangeByCalcExpressionQuantity: (newValue: number, newUnitSystem: string, newUnitCode: string, newUnitDisplay: string) => void;
|
|
11
|
+
onChangeByCalcExpressionNull: () => void;
|
|
12
|
+
}
|
|
13
|
+
declare function useQuantityCalculatedExpression(props: UseQuantityCalculatedExpressionProps): UseQuantityCalculatedExpression;
|
|
14
|
+
export default useQuantityCalculatedExpression;
|
|
@@ -0,0 +1,107 @@
|
|
|
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 { useEffect, useState } from 'react';
|
|
18
|
+
import { useQuestionnaireStore } from '../stores';
|
|
19
|
+
import { validateCodePromise } from '../utils/valueSet';
|
|
20
|
+
import { TERMINOLOGY_SERVER_URL } from '../globals';
|
|
21
|
+
function useQuantityCalculatedExpression(props) {
|
|
22
|
+
const { qItem, inputValue, precision, onChangeByCalcExpressionDecimal, onChangeByCalcExpressionQuantity, onChangeByCalcExpressionNull } = props;
|
|
23
|
+
const calculatedExpressions = useQuestionnaireStore.use.calculatedExpressions();
|
|
24
|
+
const [calcExpUpdated, setCalcExpUpdated] = useState(false);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
var _a;
|
|
27
|
+
const calcExpression = (_a = calculatedExpressions[qItem.linkId]) === null || _a === void 0 ? void 0 : _a.find((exp) => exp.from === 'item');
|
|
28
|
+
if (!calcExpression) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// only update if calculated value is different from current value
|
|
32
|
+
if (calcExpression.value !== inputValue &&
|
|
33
|
+
(typeof calcExpression.value === 'number' ||
|
|
34
|
+
typeof calcExpression.value === 'string' ||
|
|
35
|
+
calcExpression.value === null)) {
|
|
36
|
+
// Null path
|
|
37
|
+
if (calcExpression.value === null) {
|
|
38
|
+
onChangeByCalcExpressionNull();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// Number path
|
|
42
|
+
if (typeof calcExpression.value === 'number') {
|
|
43
|
+
const calcExpressionValue = typeof precision === 'number'
|
|
44
|
+
? parseFloat(calcExpression.value.toFixed(precision))
|
|
45
|
+
: calcExpression.value;
|
|
46
|
+
// only update if calculated value is different from current value
|
|
47
|
+
if (calcExpressionValue !== parseFloat(inputValue)) {
|
|
48
|
+
// update ui to show calculated value changes
|
|
49
|
+
setCalcExpUpdated(true);
|
|
50
|
+
const timeoutId = setTimeout(() => {
|
|
51
|
+
setCalcExpUpdated(false);
|
|
52
|
+
}, 500);
|
|
53
|
+
// calculatedExpression value is null
|
|
54
|
+
if (calcExpressionValue === null) {
|
|
55
|
+
onChangeByCalcExpressionNull();
|
|
56
|
+
return () => clearTimeout(timeoutId);
|
|
57
|
+
}
|
|
58
|
+
// calculatedExpression value is a number
|
|
59
|
+
onChangeByCalcExpressionDecimal(calcExpressionValue);
|
|
60
|
+
return () => clearTimeout(timeoutId);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// String path (quantity)
|
|
64
|
+
if (typeof calcExpression.value === 'string') {
|
|
65
|
+
try {
|
|
66
|
+
const [value, unitCode] = calcExpression.value.split(' ');
|
|
67
|
+
const unitCodeFormatted = unitCode.replace(/'/g, '');
|
|
68
|
+
const ucumValueSet = 'http://hl7.org/fhir/ValueSet/ucum-units';
|
|
69
|
+
const ucumSystem = 'http://unitsofmeasure.org';
|
|
70
|
+
validateCodePromise(ucumValueSet, ucumSystem, unitCodeFormatted, TERMINOLOGY_SERVER_URL).then((validateCodeResponse) => {
|
|
71
|
+
// Return early if validate-code request fails
|
|
72
|
+
if (!validateCodeResponse) {
|
|
73
|
+
onChangeByCalcExpressionNull();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (validateCodeResponse.parameter) {
|
|
77
|
+
const systemParameter = validateCodeResponse.parameter.find((p) => p.name === 'system');
|
|
78
|
+
const codeParameter = validateCodeResponse.parameter.find((p) => p.name === 'code');
|
|
79
|
+
const displayParameter = validateCodeResponse.parameter.find((p) => p.name === 'display');
|
|
80
|
+
if (systemParameter.valueUri &&
|
|
81
|
+
codeParameter.valueCode &&
|
|
82
|
+
displayParameter.valueString) {
|
|
83
|
+
// update ui to show calculated value changes
|
|
84
|
+
setCalcExpUpdated(true);
|
|
85
|
+
const timeoutId = setTimeout(() => {
|
|
86
|
+
setCalcExpUpdated(false);
|
|
87
|
+
}, 500);
|
|
88
|
+
onChangeByCalcExpressionQuantity(parseFloat(value), systemParameter.valueUri, codeParameter.valueCode, displayParameter.valueString);
|
|
89
|
+
return () => clearTimeout(timeoutId);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
console.error(e);
|
|
96
|
+
onChangeByCalcExpressionNull();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
// Only trigger this effect if calculatedExpression of item changes
|
|
102
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
103
|
+
[calculatedExpressions]);
|
|
104
|
+
return { calcExpUpdated: calcExpUpdated };
|
|
105
|
+
}
|
|
106
|
+
export default useQuantityCalculatedExpression;
|
|
107
|
+
//# sourceMappingURL=useQuantityCalculatedExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQuantityCalculatedExpression.js","sourceRoot":"","sources":["../../src/hooks/useQuantityCalculatedExpression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAyBpD,SAAS,+BAA+B,CACtC,KAA2C;IAE3C,MAAM,EACJ,KAAK,EACL,UAAU,EACV,SAAS,EACT,+BAA+B,EAC/B,gCAAgC,EAChC,4BAA4B,EAC7B,GAAG,KAAK,CAAC;IAEV,MAAM,qBAAqB,GAAG,qBAAqB,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;IAEhF,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE5D,SAAS,CACP,GAAG,EAAE;;QACH,MAAM,cAAc,GAAG,MAAA,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,0CAAE,IAAI,CAC9D,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,CAC7B,CAAC;QAEF,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,kEAAkE;QAClE,IACE,cAAc,CAAC,KAAK,KAAK,UAAU;YACnC,CAAC,OAAO,cAAc,CAAC,KAAK,KAAK,QAAQ;gBACvC,OAAO,cAAc,CAAC,KAAK,KAAK,QAAQ;gBACxC,cAAc,CAAC,KAAK,KAAK,IAAI,CAAC,EAChC,CAAC;YACD,YAAY;YACZ,IAAI,cAAc,CAAC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,CAAC,CAAC,CAAC;gBACL,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBACjB,4BAA4B,EAAE,CAAC;gBACjC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,mEAAmE;IACnE,uDAAuD;IACvD,CAAC,qBAAqB,CAAC,CACxB,CAAC;IAEF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAC5C,CAAC;AAED,eAAe,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { QuestionnaireItem } from 'fhir/r4';
|
|
2
|
+
interface UseStringCalculatedExpression {
|
|
3
|
+
calcExpUpdated: boolean;
|
|
4
|
+
}
|
|
5
|
+
interface useStringCalculatedExpressionProps {
|
|
6
|
+
qItem: QuestionnaireItem;
|
|
7
|
+
inputValue: string;
|
|
8
|
+
onChangeByCalcExpressionString: (newValueString: string) => void;
|
|
9
|
+
onChangeByCalcExpressionNull: () => void;
|
|
10
|
+
}
|
|
11
|
+
declare function useStringCalculatedExpression(props: useStringCalculatedExpressionProps): UseStringCalculatedExpression;
|
|
12
|
+
export default useStringCalculatedExpression;
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { useEffect, useState } from 'react';
|
|
18
|
+
import { useQuestionnaireStore } from '../stores';
|
|
19
|
+
function useStringCalculatedExpression(props) {
|
|
20
|
+
const { qItem, inputValue, onChangeByCalcExpressionString, onChangeByCalcExpressionNull } = props;
|
|
21
|
+
const calculatedExpressions = useQuestionnaireStore.use.calculatedExpressions();
|
|
22
|
+
const [calcExpUpdated, setCalcExpUpdated] = useState(false);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
var _a;
|
|
25
|
+
const calcExpression = (_a = calculatedExpressions[qItem.linkId]) === null || _a === void 0 ? void 0 : _a.find((exp) => exp.from === 'item');
|
|
26
|
+
if (!calcExpression) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// only update if calculated value is different from current value
|
|
30
|
+
if (calcExpression.value !== inputValue &&
|
|
31
|
+
(typeof calcExpression.value === 'string' ||
|
|
32
|
+
typeof calcExpression.value === 'number' ||
|
|
33
|
+
calcExpression.value === null)) {
|
|
34
|
+
// update ui to show calculated value changes
|
|
35
|
+
setCalcExpUpdated(true);
|
|
36
|
+
const timeoutId = setTimeout(() => {
|
|
37
|
+
setCalcExpUpdated(false);
|
|
38
|
+
}, 500);
|
|
39
|
+
// calculatedExpression value is null
|
|
40
|
+
if (calcExpression.value === null) {
|
|
41
|
+
onChangeByCalcExpressionNull();
|
|
42
|
+
return () => clearTimeout(timeoutId);
|
|
43
|
+
}
|
|
44
|
+
// calculatedExpression value is a string or number
|
|
45
|
+
const newInputValue = typeof calcExpression.value === 'string'
|
|
46
|
+
? calcExpression.value
|
|
47
|
+
: calcExpression.value.toString();
|
|
48
|
+
onChangeByCalcExpressionString(newInputValue);
|
|
49
|
+
return () => clearTimeout(timeoutId);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
// Only trigger this effect if calculatedExpression of item changes
|
|
53
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
|
+
[calculatedExpressions]);
|
|
55
|
+
return { calcExpUpdated: calcExpUpdated };
|
|
56
|
+
}
|
|
57
|
+
export default useStringCalculatedExpression;
|
|
58
|
+
//# sourceMappingURL=useStringCalculatedExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStringCalculatedExpression.js","sourceRoot":"","sources":["../../src/hooks/useStringCalculatedExpression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAalD,SAAS,6BAA6B,CACpC,KAAyC;IAEzC,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,8BAA8B,EAAE,4BAA4B,EAAE,GAAG,KAAK,CAAC;IAElG,MAAM,qBAAqB,GAAG,qBAAqB,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;IAEhF,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE5D,SAAS,CACP,GAAG,EAAE;;QACH,MAAM,cAAc,GAAG,MAAA,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,0CAAE,IAAI,CAC9D,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,CAC7B,CAAC;QAEF,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,kEAAkE;QAClE,IACE,cAAc,CAAC,KAAK,KAAK,UAAU;YACnC,CAAC,OAAO,cAAc,CAAC,KAAK,KAAK,QAAQ;gBACvC,OAAO,cAAc,CAAC,KAAK,KAAK,QAAQ;gBACxC,cAAc,CAAC,KAAK,KAAK,IAAI,CAAC,EAChC,CAAC;YACD,6CAA6C;YAC7C,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACxB,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;gBAChC,iBAAiB,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC,EAAE,GAAG,CAAC,CAAC;YAER,qCAAqC;YACrC,IAAI,cAAc,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;gBAClC,4BAA4B,EAAE,CAAC;gBAC/B,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;YACvC,CAAC;YAED,mDAAmD;YACnD,MAAM,aAAa,GACjB,OAAO,cAAc,CAAC,KAAK,KAAK,QAAQ;gBACtC,CAAC,CAAC,cAAc,CAAC,KAAK;gBACtB,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YAEtC,8BAA8B,CAAC,aAAa,CAAC,CAAC;YAC9C,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IACD,mEAAmE;IACnE,uDAAuD;IACvD,CAAC,qBAAqB,CAAC,CACxB,CAAC;IAEF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAC5C,CAAC;AAED,eAAe,6BAA6B,CAAC"}
|
|
@@ -54,7 +54,7 @@ import type { Breakpoints } from '@mui/material';
|
|
|
54
54
|
* @property disableTabButtons - If `true`, hides navigation buttons for tabs.
|
|
55
55
|
* - Default: `false`
|
|
56
56
|
*
|
|
57
|
-
* @property disableHeadingFocusOnTabSwitch - If `true`, the first heading
|
|
57
|
+
* @property disableHeadingFocusOnTabSwitch - If `true`, disables automatic focus on the first heading when switching tabs.
|
|
58
58
|
* - Default: `false`
|
|
59
59
|
*
|
|
60
60
|
* @property readOnlyVisualStyle - If `true`, item.readOnly will result in form fields having MUI disabled property and styles (recommended from usability perspective). If `false`, item.readOnly will result in form fields having HTML readonly property (less stable, but recommended from accessibility perspective).
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import type { Questionnaire, QuestionnaireResponse } from 'fhir/r4';
|
|
2
3
|
import type Client from 'fhirclient/lib/Client';
|
|
3
4
|
export interface InitialiseFormWrapperProps {
|
|
@@ -5,7 +6,7 @@ export interface InitialiseFormWrapperProps {
|
|
|
5
6
|
questionnaireResponse?: QuestionnaireResponse;
|
|
6
7
|
readOnly?: boolean;
|
|
7
8
|
terminologyServerUrl?: string;
|
|
8
|
-
|
|
9
|
+
additionalVariables?: Record<string, object>;
|
|
9
10
|
fhirClient?: Client;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
@@ -26,5 +27,5 @@ export interface InitialiseFormWrapperProps {
|
|
|
26
27
|
*
|
|
27
28
|
* @author Sean Fong
|
|
28
29
|
*/
|
|
29
|
-
declare function InitialiseFormWrapperForStorybook(props: InitialiseFormWrapperProps):
|
|
30
|
+
declare function InitialiseFormWrapperForStorybook(props: InitialiseFormWrapperProps): React.JSX.Element;
|
|
30
31
|
export default InitialiseFormWrapperForStorybook;
|
|
@@ -1,12 +1,29 @@
|
|
|
1
|
-
|
|
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
|
+
// @ts-ignore
|
|
18
|
+
import React from 'react';
|
|
2
19
|
import { BaseRenderer } from '../../components';
|
|
3
20
|
import { QueryClientProvider } from '@tanstack/react-query';
|
|
21
|
+
import RendererThemeProvider from '../../theme/Theme';
|
|
4
22
|
import useRendererQueryClient from '../../hooks/useRendererQueryClient';
|
|
5
23
|
import useInitialiseForm from '../../hooks/useInitialiseForm';
|
|
6
24
|
import Box from '@mui/material/Box';
|
|
7
25
|
import CircularProgress from '@mui/material/CircularProgress';
|
|
8
26
|
import Typography from '@mui/material/Typography';
|
|
9
|
-
import RendererThemeProvider from '../../theme/RendererThemeProvider';
|
|
10
27
|
/**
|
|
11
28
|
* This is a one-to-one replacement for the SmartFormsRenderer for demo purposes.
|
|
12
29
|
* Instead of using this React component, define your own wrapper component that uses the BaseRenderer directly.
|
|
@@ -26,7 +43,7 @@ import RendererThemeProvider from '../../theme/RendererThemeProvider';
|
|
|
26
43
|
* @author Sean Fong
|
|
27
44
|
*/
|
|
28
45
|
function InitialiseFormWrapperForStorybook(props) {
|
|
29
|
-
const { questionnaire, questionnaireResponse, readOnly, terminologyServerUrl,
|
|
46
|
+
const { questionnaire, questionnaireResponse, readOnly, terminologyServerUrl, additionalVariables, fhirClient } = props;
|
|
30
47
|
// The renderer requires a @tanstack/react-query QueryClientProvider to make requests
|
|
31
48
|
const queryClient = useRendererQueryClient();
|
|
32
49
|
/**
|
|
@@ -35,12 +52,16 @@ function InitialiseFormWrapperForStorybook(props) {
|
|
|
35
52
|
*
|
|
36
53
|
* @see {@link https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/BuildFormButtonForStorybook.tsx} for button click usage examples.
|
|
37
54
|
*/
|
|
38
|
-
const isInitialising = useInitialiseForm(questionnaire, questionnaireResponse, readOnly, terminologyServerUrl,
|
|
55
|
+
const isInitialising = useInitialiseForm(questionnaire, questionnaireResponse, readOnly, terminologyServerUrl, additionalVariables, fhirClient);
|
|
39
56
|
// Free feel to customise your loading animation here
|
|
40
57
|
if (isInitialising) {
|
|
41
|
-
return (
|
|
58
|
+
return (React.createElement(Box, { display: "flex", alignItems: "center", columnGap: 2 },
|
|
59
|
+
React.createElement(CircularProgress, null),
|
|
60
|
+
React.createElement(Typography, null, "Loading questionnaire...")));
|
|
42
61
|
}
|
|
43
|
-
return (
|
|
62
|
+
return (React.createElement(RendererThemeProvider, null,
|
|
63
|
+
React.createElement(QueryClientProvider, { client: queryClient },
|
|
64
|
+
React.createElement(BaseRenderer, null))));
|
|
44
65
|
}
|
|
45
66
|
export default InitialiseFormWrapperForStorybook;
|
|
46
67
|
//# sourceMappingURL=InitialiseFormWrapperForStorybook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InitialiseFormWrapperForStorybook.js","sourceRoot":"","sources":["../../../src/stories/storybookWrappers/InitialiseFormWrapperForStorybook.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"InitialiseFormWrapperForStorybook.js","sourceRoot":"","sources":["../../../src/stories/storybookWrappers/InitialiseFormWrapperForStorybook.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,aAAa;AACb,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,qBAAqB,MAAM,mBAAmB,CAAC;AACtD,OAAO,sBAAsB,MAAM,oCAAoC,CAAC;AAExE,OAAO,iBAAiB,MAAM,+BAA+B,CAAC;AAC9D,OAAO,GAAG,MAAM,mBAAmB,CAAC;AACpC,OAAO,gBAAgB,MAAM,gCAAgC,CAAC;AAC9D,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAWlD;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAS,iCAAiC,CAAC,KAAiC;IAC1E,MAAM,EACJ,aAAa,EACb,qBAAqB,EACrB,QAAQ,EACR,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,EACX,GAAG,KAAK,CAAC;IAEV,qFAAqF;IACrF,MAAM,WAAW,GAAG,sBAAsB,EAAE,CAAC;IAE7C;;;;;OAKG;IACH,MAAM,cAAc,GAAG,iBAAiB,CACtC,aAAa,EACb,qBAAqB,EACrB,QAAQ,EACR,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,CACX,CAAC;IAEF,qDAAqD;IACrD,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,CACL,oBAAC,GAAG,IAAC,OAAO,EAAC,MAAM,EAAC,UAAU,EAAC,QAAQ,EAAC,SAAS,EAAE,CAAC;YAClD,oBAAC,gBAAgB,OAAG;YACpB,oBAAC,UAAU,mCAAsC,CAC7C,CACP,CAAC;IACJ,CAAC;IAED,OAAO,CACL,oBAAC,qBAAqB;QACpB,oBAAC,mBAAmB,IAAC,MAAM,EAAE,WAAW;YACtC,oBAAC,YAAY,OAAG,CACI,CACA,CACzB,CAAC;AACJ,CAAC;AAED,eAAe,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { ThemeOptions } from '@mui/material/styles';
|
|
4
|
+
declare module '@mui/material/styles' {
|
|
5
|
+
interface Theme {
|
|
6
|
+
customShadows: {
|
|
7
|
+
z1: string;
|
|
8
|
+
z4: string;
|
|
9
|
+
z8: string;
|
|
10
|
+
z12: string;
|
|
11
|
+
z16: string;
|
|
12
|
+
z20: string;
|
|
13
|
+
z24: string;
|
|
14
|
+
card: string;
|
|
15
|
+
dialog: string;
|
|
16
|
+
dropdown: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
interface ThemeOptions {
|
|
20
|
+
customShadows: {
|
|
21
|
+
z1: string;
|
|
22
|
+
z4: string;
|
|
23
|
+
z8: string;
|
|
24
|
+
z12: string;
|
|
25
|
+
z16: string;
|
|
26
|
+
z20: string;
|
|
27
|
+
z24: string;
|
|
28
|
+
card: string;
|
|
29
|
+
dialog: string;
|
|
30
|
+
dropdown: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export declare const themeOptions: ThemeOptions;
|
|
35
|
+
/**
|
|
36
|
+
* Default theme used by the renderer using Material UI. You can customise your own theme by defining a new ThemeProvider.
|
|
37
|
+
* @see {@link https://mui.com/material-ui/customization/theming/}
|
|
38
|
+
*
|
|
39
|
+
* @author Sean Fong
|
|
40
|
+
*/
|
|
41
|
+
export declare function RendererThemeProvider({ children }: {
|
|
42
|
+
children: ReactNode;
|
|
43
|
+
}): React.JSX.Element;
|
|
44
|
+
export default RendererThemeProvider;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { alpha, createTheme, StyledEngineProvider, ThemeProvider as MUIThemeProvider } from '@mui/material/styles';
|
|
3
|
+
import palette from './palette';
|
|
4
|
+
import typography from './typography';
|
|
5
|
+
import CustomGlobalStyles from './customGlobalStyles';
|
|
6
|
+
import componentsOverride from './overrides/Overrides';
|
|
7
|
+
import { grey } from '@mui/material/colors';
|
|
8
|
+
// ----------------------------------------------------------------------
|
|
9
|
+
const transparent = alpha(grey[500], 0.16);
|
|
10
|
+
export const themeOptions = {
|
|
11
|
+
palette,
|
|
12
|
+
shape: { borderRadius: 6 },
|
|
13
|
+
typography,
|
|
14
|
+
customShadows: {
|
|
15
|
+
z1: `0 1px 2px 0 ${transparent}`,
|
|
16
|
+
z4: `0 4px 8px 0 ${transparent}`,
|
|
17
|
+
z8: `0 8px 16px 0 ${transparent}`,
|
|
18
|
+
z12: `0 12px 24px -4px ${transparent}`,
|
|
19
|
+
z16: `0 16px 32px -4px ${transparent}`,
|
|
20
|
+
z20: `0 20px 40px -4px ${transparent}`,
|
|
21
|
+
z24: `0 24px 48px 0 ${transparent}`,
|
|
22
|
+
//
|
|
23
|
+
card: `0 0 2px 0 ${alpha(grey[500], 0.2)}, 0 12px 24px -4px ${alpha(grey[500], 0.12)}`,
|
|
24
|
+
dialog: `-40px 40px 80px -8px ${alpha(grey[500], 0.24)}`,
|
|
25
|
+
dropdown: `0 0 2px 0 ${alpha(grey[500], 0.24)}, -20px 20px 40px -4px ${alpha(grey[500], 0.24)}`
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Default theme used by the renderer using Material UI. You can customise your own theme by defining a new ThemeProvider.
|
|
30
|
+
* @see {@link https://mui.com/material-ui/customization/theming/}
|
|
31
|
+
*
|
|
32
|
+
* @author Sean Fong
|
|
33
|
+
*/
|
|
34
|
+
export function RendererThemeProvider({ children }) {
|
|
35
|
+
const theme = createTheme(themeOptions);
|
|
36
|
+
theme.components = componentsOverride(theme);
|
|
37
|
+
return (React.createElement(StyledEngineProvider, { injectFirst: true },
|
|
38
|
+
React.createElement(MUIThemeProvider, { theme: theme },
|
|
39
|
+
React.createElement(CustomGlobalStyles, null),
|
|
40
|
+
children)));
|
|
41
|
+
}
|
|
42
|
+
export default RendererThemeProvider;
|
|
43
|
+
//# sourceMappingURL=Theme.js.map
|