@aehrc/smart-forms-renderer 0.36.0 → 0.37.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/CHANGELOG.md +40 -0
- package/lib/components/FormComponents/Button.styles.d.ts +4 -0
- package/lib/components/FormComponents/Button.styles.js +10 -0
- package/lib/components/FormComponents/Button.styles.js.map +1 -0
- package/lib/components/FormComponents/GroupItem/GroupHeading.d.ts +1 -0
- package/lib/components/FormComponents/GroupItem/GroupHeading.js +3 -2
- package/lib/components/FormComponents/GroupItem/GroupHeading.js.map +1 -1
- package/lib/components/FormComponents/GroupItem/GroupItem.d.ts +4 -0
- package/lib/components/FormComponents/GroupItem/GroupItem.js +3 -3
- package/lib/components/FormComponents/GroupItem/GroupItem.js.map +1 -1
- package/lib/components/FormComponents/GroupItem/GroupItemView.d.ts +4 -0
- package/lib/components/FormComponents/GroupItem/GroupItemView.js +8 -5
- package/lib/components/FormComponents/GroupItem/GroupItemView.js.map +1 -1
- package/lib/components/FormComponents/GroupItem/NextPageButton.d.ts +7 -0
- package/lib/components/FormComponents/GroupItem/NextPageButton.js +26 -0
- package/lib/components/FormComponents/GroupItem/NextPageButton.js.map +1 -0
- package/lib/components/FormComponents/GroupItem/PageButtonWrapper.d.ts +8 -0
- package/lib/components/FormComponents/GroupItem/PageButtonWrapper.js +46 -0
- package/lib/components/FormComponents/GroupItem/PageButtonWrapper.js.map +1 -0
- package/lib/components/FormComponents/GroupItem/PreviousPageButton.d.ts +7 -0
- package/lib/components/FormComponents/GroupItem/PreviousPageButton.js +26 -0
- package/lib/components/FormComponents/GroupItem/PreviousPageButton.js.map +1 -0
- package/lib/components/Renderer/BaseRenderer.js +8 -0
- package/lib/components/Renderer/BaseRenderer.js.map +1 -1
- 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/FormTopLevelItem.js +7 -0
- package/lib/components/Renderer/FormTopLevelItem.js.map +1 -1
- 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/hooks/useCodingCalculatedExpression.js +11 -0
- package/lib/hooks/useCodingCalculatedExpression.js.map +1 -1
- package/lib/hooks/useNextAndPreviousVisiblePages.d.ts +7 -0
- package/lib/hooks/useNextAndPreviousVisiblePages.js +47 -0
- package/lib/hooks/useNextAndPreviousVisiblePages.js.map +1 -0
- package/lib/interfaces/page.interface.d.ts +16 -0
- package/lib/interfaces/page.interface.js +2 -0
- package/lib/interfaces/page.interface.js.map +1 -0
- package/lib/interfaces/questionnaireStore.interface.d.ts +2 -0
- package/lib/stores/questionnaireStore.d.ts +13 -0
- package/lib/stores/questionnaireStore.js +19 -3
- package/lib/stores/questionnaireStore.js.map +1 -1
- package/lib/utils/calculatedExpression.js +1 -1
- package/lib/utils/calculatedExpression.js.map +1 -1
- package/lib/utils/fhirpath.js +0 -4
- package/lib/utils/fhirpath.js.map +1 -1
- package/lib/utils/initialise.d.ts +3 -0
- package/lib/utils/initialise.js +6 -1
- package/lib/utils/initialise.js.map +1 -1
- package/lib/utils/page.d.ts +43 -0
- package/lib/utils/page.js +101 -0
- package/lib/utils/page.js.map +1 -0
- package/lib/utils/questionnaireStoreUtils/createQuestionaireModel.js +4 -0
- package/lib/utils/questionnaireStoreUtils/createQuestionaireModel.js.map +1 -1
- package/lib/utils/questionnaireStoreUtils/extractPages.d.ts +3 -0
- package/lib/utils/questionnaireStoreUtils/extractPages.js +18 -0
- package/lib/utils/questionnaireStoreUtils/extractPages.js.map +1 -0
- package/package.json +4 -4
- package/src/components/FormComponents/Button.styles.ts +10 -0
- package/src/components/FormComponents/GroupItem/GroupHeading.tsx +5 -3
- package/src/components/FormComponents/GroupItem/GroupItem.tsx +11 -1
- package/src/components/FormComponents/GroupItem/GroupItemView.tsx +12 -0
- package/src/components/FormComponents/GroupItem/NextPageButton.tsx +37 -0
- package/src/components/FormComponents/GroupItem/PageButtonWrapper.tsx +78 -0
- package/src/components/FormComponents/GroupItem/PreviousPageButton.tsx +41 -0
- package/src/components/Renderer/BaseRenderer.tsx +21 -0
- package/src/components/Renderer/FormBodyPage.tsx +93 -0
- package/src/components/Renderer/FormTopLevelItem.tsx +17 -0
- package/src/components/Renderer/FormTopLevelPage.tsx +70 -0
- package/src/hooks/useCodingCalculatedExpression.ts +14 -1
- package/src/hooks/useNextAndPreviousVisiblePages.ts +69 -0
- package/src/interfaces/page.interface.ts +13 -0
- package/src/interfaces/questionnaireStore.interface.ts +2 -0
- package/src/stores/questionnaireStore.ts +33 -2
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreAllergyIntolerance.json +209 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreCondition.json +220 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreEncounter.json +299 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreImmunization.json +175 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreMedicationRequest.json +229 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreObservationBP.json +359 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreObservationBodyHeight.json +195 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreObservationBodyWeight.json +195 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreObservationHeartRate.json +195 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreObservationSmokingStatus.json +174 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCorePatient.json +495 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCorePractitioner.json +139 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCorePractitionerRole.json +216 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreProcedure.json +199 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreRespirationRate.json +195 -0
- package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreWaistCircumference.json +195 -0
- package/src/stories/assets/questionnaires/QAuCoreTesting.ts +3796 -0
- package/src/stories/assets/questionnaires/QItemControlGroup.ts +673 -0
- package/src/stories/assets/questionnaires/QPrePopTester.ts +266 -71
- package/src/stories/sdc/ItemControlGroup.stories.tsx +22 -1
- package/src/stories/testing/AuCoreTester.stories.tsx +196 -0
- package/src/utils/calculatedExpression.ts +1 -1
- package/src/utils/fhirpath.ts +0 -5
- package/src/utils/initialise.ts +11 -0
- package/src/utils/page.ts +134 -0
- package/src/utils/questionnaireStoreUtils/createQuestionaireModel.ts +5 -0
- package/src/utils/questionnaireStoreUtils/extractPages.ts +24 -0
- package/stats.html +0 -4842
- package/stats1.html +0 -4842
- package/stats3.html +0 -4842
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { isSpecificItemControl } from './itemControl';
|
|
2
|
+
import { isHiddenByEnableWhen } from './qItem';
|
|
3
|
+
import { structuredDataCapture } from 'fhir-sdc-helpers';
|
|
4
|
+
export function getFirstVisiblePage(pages, enableWhenItems, enableWhenExpressions) {
|
|
5
|
+
// Only singleEnableWhenItems are relevant for page operations
|
|
6
|
+
const { singleItems } = enableWhenItems;
|
|
7
|
+
const { singleExpressions } = enableWhenExpressions;
|
|
8
|
+
return Object.entries(pages)
|
|
9
|
+
.sort(([, pageA], [, pageB]) => pageA.pageIndex - pageB.pageIndex)
|
|
10
|
+
.findIndex(([pageLinkId, page]) => {
|
|
11
|
+
if (page.isHidden) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const singleItem = singleItems[pageLinkId];
|
|
15
|
+
if (singleItem) {
|
|
16
|
+
return singleItem.isEnabled;
|
|
17
|
+
}
|
|
18
|
+
const singleExpression = singleExpressions[pageLinkId];
|
|
19
|
+
if (singleExpression) {
|
|
20
|
+
return singleExpression.isEnabled;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Checks if all of the items in a qItem array is a page item
|
|
27
|
+
* Returns true if all items is page item
|
|
28
|
+
* Returns false if only have one item
|
|
29
|
+
*
|
|
30
|
+
* @author Riza Nafis
|
|
31
|
+
*/
|
|
32
|
+
export function everyIsPages(topLevelQItem) {
|
|
33
|
+
if (!topLevelQItem)
|
|
34
|
+
return false;
|
|
35
|
+
if (isPageContainer(topLevelQItem))
|
|
36
|
+
return false;
|
|
37
|
+
return topLevelQItem.every((i) => isPage(i));
|
|
38
|
+
}
|
|
39
|
+
export function isPageContainer(topLevelQItem) {
|
|
40
|
+
const anyPage = topLevelQItem === null || topLevelQItem === void 0 ? void 0 : topLevelQItem.filter(isPage);
|
|
41
|
+
if (!anyPage)
|
|
42
|
+
return false;
|
|
43
|
+
return anyPage.some((page) => { var _a; return ((_a = page.item) === null || _a === void 0 ? void 0 : _a.every((i) => i.type === 'group')) || false; });
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Checks if any of the items in a qItem array is a page item
|
|
47
|
+
* Returns true if there is at least one page item
|
|
48
|
+
*
|
|
49
|
+
* @author Riza Nafis
|
|
50
|
+
*/
|
|
51
|
+
export function containsPages(topLevelQItem) {
|
|
52
|
+
if (!topLevelQItem.item) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const pages = topLevelQItem.item.filter((i) => isPage(i));
|
|
56
|
+
return pages.length > 0;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if a qItem is a page item
|
|
60
|
+
*
|
|
61
|
+
* @author Riza Nafis
|
|
62
|
+
*/
|
|
63
|
+
export function isPage(item) {
|
|
64
|
+
return isSpecificItemControl(item, 'page');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a `Record<linkId, Pages>` key-value pair for all page items in a qItem array
|
|
68
|
+
*
|
|
69
|
+
* @author Riza Nafis
|
|
70
|
+
*/
|
|
71
|
+
export function constructPagesWithProperties(qItems, hasPageContainer) {
|
|
72
|
+
var _a;
|
|
73
|
+
if (!qItems)
|
|
74
|
+
return {};
|
|
75
|
+
const qItemPages = hasPageContainer ? qItems : qItems.filter(isPage);
|
|
76
|
+
const pages = {};
|
|
77
|
+
for (const [i, qItem] of qItemPages.entries()) {
|
|
78
|
+
pages[qItem.linkId] = {
|
|
79
|
+
pageIndex: i,
|
|
80
|
+
isComplete: false,
|
|
81
|
+
isHidden: (_a = structuredDataCapture.getHidden(qItem)) !== null && _a !== void 0 ? _a : false
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return pages;
|
|
85
|
+
}
|
|
86
|
+
export function constructPagesWithVisibility(params) {
|
|
87
|
+
const { pages, enableWhenIsActivated, enableWhenItems, enableWhenExpressions } = params;
|
|
88
|
+
return Object.entries(pages).map(([linkId]) => {
|
|
89
|
+
const isVisible = !isHiddenByEnableWhen({
|
|
90
|
+
linkId,
|
|
91
|
+
enableWhenIsActivated,
|
|
92
|
+
enableWhenItems,
|
|
93
|
+
enableWhenExpressions
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
linkId,
|
|
97
|
+
isVisible
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/utils/page.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,MAAM,UAAU,mBAAmB,CACjC,KAAY,EACZ,eAAgC,EAChC,qBAA4C;IAE5C,8DAA8D;IAC9D,MAAM,EAAE,WAAW,EAAE,GAAG,eAAe,CA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EAAE,qBAAqB,EAAE,eAAe,EAAE,qBAAqB,EAAE,GAAG,MAAM,CAAC;IAExF,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE;QAC5C,MAAM,SAAS,GAAG,CAAC,oBAAoB,CAAC;YACtC,MAAM;YACN,qBAAqB;YACrB,eAAe;YACf,qBAAqB;SACtB,CAAC,CAAC;QAEH,OAAO;YACL,MAAM;YACN,SAAS;SACV,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -26,6 +26,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
26
26
|
import { extractLaunchContexts } from './extractLaunchContext';
|
|
27
27
|
import { extractQuestionnaireLevelVariables } from './extractVariables';
|
|
28
28
|
import { extractTabs } from './extractTabs';
|
|
29
|
+
import { extractPages } from './extractPages';
|
|
29
30
|
import { extractContainedValueSets } from './extractContainedValueSets';
|
|
30
31
|
import { extractOtherExtensions } from './extractOtherExtensions';
|
|
31
32
|
import { resolveValueSets } from './resolveValueSets';
|
|
@@ -39,6 +40,7 @@ export function createQuestionnaireModel(questionnaire, additionalVariables, ter
|
|
|
39
40
|
}
|
|
40
41
|
const itemTypes = Object.fromEntries(getLinkIdTypeTuples(questionnaire));
|
|
41
42
|
const tabs = extractTabs(questionnaire);
|
|
43
|
+
const pages = extractPages(questionnaire);
|
|
42
44
|
const launchContexts = extractLaunchContexts(questionnaire);
|
|
43
45
|
let variables = extractQuestionnaireLevelVariables(questionnaire);
|
|
44
46
|
variables = addAdditionalVariables(variables, additionalVariables);
|
|
@@ -60,6 +62,7 @@ export function createQuestionnaireModel(questionnaire, additionalVariables, ter
|
|
|
60
62
|
return {
|
|
61
63
|
itemTypes,
|
|
62
64
|
tabs,
|
|
65
|
+
pages,
|
|
63
66
|
variables,
|
|
64
67
|
launchContexts,
|
|
65
68
|
enableWhenItems,
|
|
@@ -78,6 +81,7 @@ function createEmptyModel() {
|
|
|
78
81
|
return {
|
|
79
82
|
itemTypes: {},
|
|
80
83
|
tabs: {},
|
|
84
|
+
pages: {},
|
|
81
85
|
variables: { fhirPathVariables: {}, xFhirQueryVariables: {} },
|
|
82
86
|
launchContexts: {},
|
|
83
87
|
calculatedExpressions: {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createQuestionaireModel.js","sourceRoot":"","sources":["../../../src/utils/questionnaireStoreUtils/createQuestionaireModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"createQuestionaireModel.js","sourceRoot":"","sources":["../../../src/utils/questionnaireStoreUtils/createQuestionaireModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;AAOH,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,kCAAkC,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAEhG,MAAM,UAAgB,wBAAwB,CAC5C,aAA4B,EAC5B,mBAA2C,EAC3C,oBAA4B;;QAE5B,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE;YACvB,OAAO,gBAAgB,EAAE,CAAC;SAC3B;QAED,MAAM,SA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,MAAM,qBAAqB,GAAG,MAAM,yBAAyB,CAC3D,aAAa,EACb,oBAAoB,CACrB,CAAC;QAEF,OAAO;YACL,SAAS;YACT,IAAI;YACJ,KAAK;YACL,SAAS;YACT,cAAc;YACd,eAAe;YACf,qBAAqB;YACrB,qBAAqB;YACrB,kBAAkB;YAClB,iBAAiB;YACjB,aAAa,EAAE,qBAAqB;YACpC,wBAAwB;YACxB,qBAAqB;YACrB,eAAe,EAAE,EAAE;SACpB,CAAC;IACJ,CAAC;CAAA;AAED,SAAS,gBAAgB;IACvB,OAAO;QACL,SAAS,EAAE,EAAE;QACb,IAAI,EAAE,EAAE;QACR,KAAK,EAAE,EAAE;QACT,SAAS,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,mBAAmB,EAAE,EAAE,EAAE;QAC7D,cAAc,EAAE,EAAE;QAClB,qBAAqB,EAAE,EAAE;QACzB,kBAAkB,EAAE,EAAE;QACtB,qBAAqB,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE;QACvE,iBAAiB,EAAE,EAAE;QACrB,aAAa,EAAE,EAAE;QACjB,eAAe,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE;QACrD,wBAAwB,EAAE,EAAE;QAC5B,qBAAqB,EAAE,EAAE;QACzB,eAAe,EAAE,EAAE;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { constructPagesWithProperties, isPage, isPageContainer } from '../page';
|
|
2
|
+
export function extractPages(questionnaire) {
|
|
3
|
+
if (!questionnaire.item || questionnaire.item.length === 0) {
|
|
4
|
+
return {};
|
|
5
|
+
}
|
|
6
|
+
if (!isPageContainer(questionnaire.item)) {
|
|
7
|
+
return constructPagesWithProperties(questionnaire.item, false);
|
|
8
|
+
}
|
|
9
|
+
let totalPages = {};
|
|
10
|
+
for (const topLevelItem of questionnaire.item) {
|
|
11
|
+
const items = topLevelItem.item;
|
|
12
|
+
const topLevelItemIsPageContainer = isPage(topLevelItem);
|
|
13
|
+
const pages = constructPagesWithProperties(items, topLevelItemIsPageContainer);
|
|
14
|
+
totalPages = Object.assign(Object.assign({}, totalPages), pages);
|
|
15
|
+
}
|
|
16
|
+
return totalPages;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=extractPages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractPages.js","sourceRoot":"","sources":["../../../src/utils/questionnaireStoreUtils/extractPages.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEhF,MAAM,UAAU,YAAY,CAAC,aAA4B;IACvD,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QAC1D,OAAO,EAAE,CAAC;KACX;IAED,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE;QACxC,OAAO,4BAA4B,CAAC,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;KAChE;IAED,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,KAAK,MAAM,YAAY,IAAI,aAAa,CAAC,IAAI,EAAE;QAC7C,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC;QAChC,MAAM,2BAA2B,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;QAEzD,MAAM,KAAK,GAAG,4BAA4B,CAAC,KAAK,EAAE,2BAA2B,CAAC,CAAC;QAC/E,UAAU,mCAAQ,UAAU,GAAK,KAAK,CAAE,CAAC;KAC1C;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aehrc/smart-forms-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.2",
|
|
4
4
|
"description": "FHIR Structured Data Captured (SDC) rendering engine for Smart Forms",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/aehrc/smart-forms#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@aehrc/sdc-populate": "^2.3.
|
|
30
|
+
"@aehrc/sdc-populate": "^2.3.1",
|
|
31
31
|
"@iconify/react": "^4.1.1",
|
|
32
32
|
"dayjs": "^1.11.10",
|
|
33
33
|
"deep-diff": "^1.0.2",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"react-dnd-html5-backend": "^16.0.1",
|
|
46
46
|
"react-markdown": "^8.0.7",
|
|
47
47
|
"style-to-object": "^1.0.6",
|
|
48
|
-
"zustand": "^4.5.
|
|
48
|
+
"zustand": "^4.5.4"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@emotion/react": "^11.11.3",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@storybook/addon-links": "^8.0.10",
|
|
67
67
|
"@storybook/addon-onboarding": "^8.0.10",
|
|
68
68
|
"@storybook/blocks": "^8.0.10",
|
|
69
|
-
"@storybook/react": "^8.
|
|
69
|
+
"@storybook/react": "^8.2.6",
|
|
70
70
|
"@storybook/react-vite": "^8.0.10",
|
|
71
71
|
"@storybook/test": "^8.0.10",
|
|
72
72
|
"@swc/cli": "^0.1.63",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { styled } from '@mui/material/styles';
|
|
2
|
+
import Fab from '@mui/material/Fab';
|
|
3
|
+
|
|
4
|
+
export const SecondaryFab = styled(Fab)(({ theme }) => ({
|
|
5
|
+
color: '#fff',
|
|
6
|
+
background: theme.palette.secondary.main,
|
|
7
|
+
'&:hover': {
|
|
8
|
+
background: theme.palette.secondary.dark
|
|
9
|
+
}
|
|
10
|
+
}));
|
|
@@ -29,10 +29,11 @@ interface GroupHeadingProps extends PropsWithIsRepeatedAttribute {
|
|
|
29
29
|
qItem: QuestionnaireItem;
|
|
30
30
|
readOnly: boolean;
|
|
31
31
|
tabIsMarkedAsComplete?: boolean;
|
|
32
|
+
pageIsMarkedAsComplete?: boolean;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
const GroupHeading = memo(function GroupHeading(props: GroupHeadingProps) {
|
|
35
|
-
const { qItem, readOnly, tabIsMarkedAsComplete, isRepeated } = props;
|
|
36
|
+
const { qItem, readOnly, tabIsMarkedAsComplete, pageIsMarkedAsComplete, isRepeated } = props;
|
|
36
37
|
|
|
37
38
|
const contextDisplayItems = getContextDisplays(qItem);
|
|
38
39
|
|
|
@@ -41,14 +42,15 @@ const GroupHeading = memo(function GroupHeading(props: GroupHeadingProps) {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
const isTabHeading = tabIsMarkedAsComplete !== undefined;
|
|
45
|
+
const isPageHeading = pageIsMarkedAsComplete !== undefined;
|
|
44
46
|
|
|
45
47
|
return (
|
|
46
48
|
<>
|
|
47
49
|
<Box display="flex" alignItems="center" width="100%">
|
|
48
50
|
<Typography
|
|
49
51
|
variant="h6"
|
|
50
|
-
fontSize={isTabHeading ? 16 : 15}
|
|
51
|
-
color={readOnly && !isTabHeading ? 'text.secondary' : 'text.primary'}>
|
|
52
|
+
fontSize={isTabHeading || isPageHeading ? 16 : 15}
|
|
53
|
+
color={readOnly && (!isTabHeading || !isPageHeading) ? 'text.secondary' : 'text.primary'}>
|
|
52
54
|
<ItemLabelText qItem={qItem} />
|
|
53
55
|
</Typography>
|
|
54
56
|
<Box flexGrow={1} />
|
|
@@ -28,6 +28,7 @@ import type {
|
|
|
28
28
|
import type { QrRepeatGroup } from '../../../interfaces/repeatGroup.interface';
|
|
29
29
|
import useHidden from '../../../hooks/useHidden';
|
|
30
30
|
import type { Tabs } from '../../../interfaces/tab.interface';
|
|
31
|
+
import type { Pages } from '../../../interfaces/page.interface';
|
|
31
32
|
import GroupItemView from './GroupItemView';
|
|
32
33
|
|
|
33
34
|
interface GroupItemProps
|
|
@@ -41,6 +42,9 @@ interface GroupItemProps
|
|
|
41
42
|
tabIsMarkedAsComplete?: boolean;
|
|
42
43
|
tabs?: Tabs;
|
|
43
44
|
currentTabIndex?: number;
|
|
45
|
+
pageIsMarkedAsComplete?: boolean;
|
|
46
|
+
pages?: Pages;
|
|
47
|
+
currentPageIndex?: number;
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
function GroupItem(props: GroupItemProps) {
|
|
@@ -52,6 +56,9 @@ function GroupItem(props: GroupItemProps) {
|
|
|
52
56
|
tabIsMarkedAsComplete,
|
|
53
57
|
tabs,
|
|
54
58
|
currentTabIndex,
|
|
59
|
+
pageIsMarkedAsComplete,
|
|
60
|
+
pages,
|
|
61
|
+
currentPageIndex,
|
|
55
62
|
parentIsReadOnly,
|
|
56
63
|
parentIsRepeatGroup,
|
|
57
64
|
parentRepeatGroupIndex,
|
|
@@ -83,7 +90,7 @@ function GroupItem(props: GroupItemProps) {
|
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
if (!qItems || !qrItems) {
|
|
86
|
-
return <>Unable to load group, something has gone terribly wrong.</>;
|
|
93
|
+
return <>Group Item: Unable to load group, something has gone terribly wrong.</>;
|
|
87
94
|
}
|
|
88
95
|
|
|
89
96
|
// If an item has multiple answers, it is a repeat group
|
|
@@ -99,6 +106,9 @@ function GroupItem(props: GroupItemProps) {
|
|
|
99
106
|
tabIsMarkedAsComplete={tabIsMarkedAsComplete}
|
|
100
107
|
tabs={tabs}
|
|
101
108
|
currentTabIndex={currentTabIndex}
|
|
109
|
+
pageIsMarkedAsComplete={pageIsMarkedAsComplete}
|
|
110
|
+
pages={pages}
|
|
111
|
+
currentPageIndex={currentPageIndex}
|
|
102
112
|
parentIsReadOnly={parentIsReadOnly}
|
|
103
113
|
parentIsRepeatGroup={parentIsRepeatGroup}
|
|
104
114
|
parentRepeatGroupIndex={parentRepeatGroupIndex}
|
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
PropsWithQrRepeatGroupChangeHandler
|
|
27
27
|
} from '../../../interfaces/renderProps.interface';
|
|
28
28
|
import type { Tabs } from '../../../interfaces/tab.interface';
|
|
29
|
+
import type { Pages } from '../../../interfaces/page.interface';
|
|
29
30
|
import GroupHeading from './GroupHeading';
|
|
30
31
|
import { GroupCard } from './GroupItem.styles';
|
|
31
32
|
import TabButtonsWrapper from './TabButtonsWrapper';
|
|
@@ -37,6 +38,7 @@ import Divider from '@mui/material/Divider';
|
|
|
37
38
|
import { getGroupCollapsible } from '../../../utils/qItem';
|
|
38
39
|
import useReadOnly from '../../../hooks/useReadOnly';
|
|
39
40
|
import { GroupAccordion } from './GroupAccordion.styles';
|
|
41
|
+
import PageButtonsWrapper from './PageButtonWrapper';
|
|
40
42
|
|
|
41
43
|
interface GroupItemViewProps
|
|
42
44
|
extends PropsWithQrItemChangeHandler,
|
|
@@ -51,6 +53,9 @@ interface GroupItemViewProps
|
|
|
51
53
|
tabIsMarkedAsComplete?: boolean;
|
|
52
54
|
tabs?: Tabs;
|
|
53
55
|
currentTabIndex?: number;
|
|
56
|
+
pageIsMarkedAsComplete?: boolean;
|
|
57
|
+
pages?: Pages;
|
|
58
|
+
currentPageIndex?: number;
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
function GroupItemView(props: GroupItemViewProps) {
|
|
@@ -63,6 +68,9 @@ function GroupItemView(props: GroupItemViewProps) {
|
|
|
63
68
|
tabIsMarkedAsComplete,
|
|
64
69
|
tabs,
|
|
65
70
|
currentTabIndex,
|
|
71
|
+
pageIsMarkedAsComplete,
|
|
72
|
+
pages,
|
|
73
|
+
currentPageIndex,
|
|
66
74
|
parentIsReadOnly,
|
|
67
75
|
parentIsRepeatGroup,
|
|
68
76
|
parentRepeatGroupIndex,
|
|
@@ -91,6 +99,7 @@ function GroupItemView(props: GroupItemViewProps) {
|
|
|
91
99
|
qItem={qItem}
|
|
92
100
|
readOnly={readOnly}
|
|
93
101
|
tabIsMarkedAsComplete={tabIsMarkedAsComplete}
|
|
102
|
+
pageIsMarkedAsComplete={pageIsMarkedAsComplete}
|
|
94
103
|
isRepeated={isRepeated}
|
|
95
104
|
/>
|
|
96
105
|
</AccordionSummary>
|
|
@@ -117,6 +126,7 @@ function GroupItemView(props: GroupItemViewProps) {
|
|
|
117
126
|
|
|
118
127
|
{/* Next tab button at the end of each tab group */}
|
|
119
128
|
<TabButtonsWrapper currentTabIndex={currentTabIndex} tabs={tabs} />
|
|
129
|
+
<PageButtonsWrapper currentPageIndex={currentPageIndex} pages={pages} />
|
|
120
130
|
</>
|
|
121
131
|
</AccordionDetails>
|
|
122
132
|
</GroupAccordion>
|
|
@@ -133,6 +143,7 @@ function GroupItemView(props: GroupItemViewProps) {
|
|
|
133
143
|
qItem={qItem}
|
|
134
144
|
readOnly={readOnly}
|
|
135
145
|
tabIsMarkedAsComplete={tabIsMarkedAsComplete}
|
|
146
|
+
pageIsMarkedAsComplete={pageIsMarkedAsComplete}
|
|
136
147
|
isRepeated={isRepeated}
|
|
137
148
|
/>
|
|
138
149
|
{childQItems.map((qItem: QuestionnaireItem, i) => {
|
|
@@ -155,6 +166,7 @@ function GroupItemView(props: GroupItemViewProps) {
|
|
|
155
166
|
|
|
156
167
|
{/* Next tab button at the end of each tab group */}
|
|
157
168
|
<TabButtonsWrapper currentTabIndex={currentTabIndex} tabs={tabs} />
|
|
169
|
+
<PageButtonsWrapper currentPageIndex={currentPageIndex} pages={pages} />
|
|
158
170
|
</GroupCard>
|
|
159
171
|
</QGroupContainerBox>
|
|
160
172
|
);
|
|
@@ -0,0 +1,37 @@
|
|
|
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 React from 'react';
|
|
19
|
+
import Iconify from '../../Iconify/Iconify';
|
|
20
|
+
import { SecondaryFab } from '../Button.styles';
|
|
21
|
+
|
|
22
|
+
interface NextPageButtonProps {
|
|
23
|
+
isDisabled: boolean;
|
|
24
|
+
onNextPageClick: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function NextPageButton(props: NextPageButtonProps) {
|
|
28
|
+
const { isDisabled, onNextPageClick } = props;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<SecondaryFab size="small" aria-label="next" disabled={isDisabled} onClick={onNextPageClick}>
|
|
32
|
+
<Iconify icon="material-symbols:chevron-right-rounded" />
|
|
33
|
+
</SecondaryFab>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default NextPageButton;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React, { memo } from 'react';
|
|
2
|
+
import Box from '@mui/material/Box';
|
|
3
|
+
import Typography from '@mui/material/Typography';
|
|
4
|
+
import type { Pages } from '../../../interfaces/page.interface';
|
|
5
|
+
import { useQuestionnaireStore } from '../../../stores';
|
|
6
|
+
import NextPageButton from './NextPageButton';
|
|
7
|
+
import PreviousPageButton from './PreviousPageButton';
|
|
8
|
+
import useNextAndPreviousVisiblePages from '../../../hooks/useNextAndPreviousVisiblePages';
|
|
9
|
+
|
|
10
|
+
interface PageButtonsWrapperProps {
|
|
11
|
+
currentPageIndex?: number;
|
|
12
|
+
pages?: Pages;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const PageButtonsWrapper = memo(function PageButtonsWrapper(props: PageButtonsWrapperProps) {
|
|
16
|
+
const { currentPageIndex, pages } = props;
|
|
17
|
+
|
|
18
|
+
const switchPage = useQuestionnaireStore.use.switchPage();
|
|
19
|
+
|
|
20
|
+
const { previousPageIndex, nextPageIndex, numOfVisiblePages } = useNextAndPreviousVisiblePages(
|
|
21
|
+
currentPageIndex,
|
|
22
|
+
pages
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const pagesNotDefined = currentPageIndex === undefined || pages === undefined;
|
|
26
|
+
|
|
27
|
+
// Event handlers
|
|
28
|
+
function handlePreviousPageButtonClick() {
|
|
29
|
+
if (previousPageIndex === null) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
switchPage(previousPageIndex);
|
|
34
|
+
|
|
35
|
+
// Scroll to top of page
|
|
36
|
+
window.scrollTo(0, 0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function handleNextPageButtonClick() {
|
|
40
|
+
if (nextPageIndex === null) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
switchPage(nextPageIndex);
|
|
45
|
+
|
|
46
|
+
// Scroll to top of page
|
|
47
|
+
window.scrollTo(0, 0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (pagesNotDefined) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const previousPageButtonHidden = previousPageIndex === null;
|
|
55
|
+
const nextPageButtonHidden = nextPageIndex === null;
|
|
56
|
+
|
|
57
|
+
// This is more of a fallback check to prevent the user from navigating to an invisble page if buttons are visble for some reason
|
|
58
|
+
const pageButtonsDisabled = numOfVisiblePages <= 1;
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<Box display="flex" mt={3} gap={2} alignItems="center">
|
|
62
|
+
<Box flexGrow={1} />
|
|
63
|
+
<Typography variant="subtitle2" color="text.secondary">
|
|
64
|
+
Page {`${currentPageIndex + 1} / ${numOfVisiblePages}`}
|
|
65
|
+
</Typography>
|
|
66
|
+
<PreviousPageButton
|
|
67
|
+
isDisabled={pageButtonsDisabled || previousPageButtonHidden}
|
|
68
|
+
onPreviousPageClick={handlePreviousPageButtonClick}
|
|
69
|
+
/>
|
|
70
|
+
<NextPageButton
|
|
71
|
+
isDisabled={pageButtonsDisabled || nextPageButtonHidden}
|
|
72
|
+
onNextPageClick={handleNextPageButtonClick}
|
|
73
|
+
/>
|
|
74
|
+
</Box>
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export default PageButtonsWrapper;
|
|
@@ -0,0 +1,41 @@
|
|
|
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 React from 'react';
|
|
19
|
+
import Iconify from '../../Iconify/Iconify';
|
|
20
|
+
import { SecondaryFab } from '../Button.styles';
|
|
21
|
+
|
|
22
|
+
interface PreviousPageButtonProps {
|
|
23
|
+
isDisabled: boolean;
|
|
24
|
+
onPreviousPageClick: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function PreviousPageButton(props: PreviousPageButtonProps) {
|
|
28
|
+
const { isDisabled, onPreviousPageClick } = props;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<SecondaryFab
|
|
32
|
+
size="small"
|
|
33
|
+
aria-label="back"
|
|
34
|
+
disabled={isDisabled}
|
|
35
|
+
onClick={onPreviousPageClick}>
|
|
36
|
+
<Iconify icon="material-symbols:chevron-left-rounded" />
|
|
37
|
+
</SecondaryFab>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default PreviousPageButton;
|
|
@@ -24,7 +24,9 @@ import { useQuestionnaireResponseStore, useQuestionnaireStore } from '../../stor
|
|
|
24
24
|
import cloneDeep from 'lodash.clonedeep';
|
|
25
25
|
import { getQrItemsIndex, mapQItemsIndex } from '../../utils/mapItem';
|
|
26
26
|
import { updateQrItemsInGroup } from '../../utils/qrItem';
|
|
27
|
+
import { everyIsPages } from '../../utils/page';
|
|
27
28
|
import type { QrRepeatGroup } from '../../interfaces/repeatGroup.interface';
|
|
29
|
+
import FormTopLevelPage from './FormTopLevelPage';
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* Main component of the form-rendering engine.
|
|
@@ -74,6 +76,25 @@ function BaseRenderer() {
|
|
|
74
76
|
// If an item has multiple answers, it is a repeat group
|
|
75
77
|
const topLevelQRItemsByIndex = getQrItemsIndex(topLevelQItems, topLevelQRItems, qItemsIndexMap);
|
|
76
78
|
|
|
79
|
+
const everyItemIsPage = everyIsPages(topLevelQItems);
|
|
80
|
+
|
|
81
|
+
if (everyItemIsPage) {
|
|
82
|
+
return (
|
|
83
|
+
<Fade in={true} timeout={500}>
|
|
84
|
+
<Container maxWidth="xl">
|
|
85
|
+
<FormTopLevelPage
|
|
86
|
+
topLevelQItems={topLevelQItems}
|
|
87
|
+
topLevelQRItems={topLevelQRItemsByIndex}
|
|
88
|
+
parentIsReadOnly={readOnly}
|
|
89
|
+
onQrItemChange={(newTopLevelQRItem) =>
|
|
90
|
+
handleTopLevelQRItemSingleChange(newTopLevelQRItem)
|
|
91
|
+
}
|
|
92
|
+
/>
|
|
93
|
+
</Container>
|
|
94
|
+
</Fade>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
77
98
|
return (
|
|
78
99
|
<Fade in={true} timeout={500}>
|
|
79
100
|
<Container maxWidth="xl">
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import Grid from '@mui/material/Grid';
|
|
3
|
+
import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
|
|
4
|
+
import TabContext from '@mui/lab/TabContext';
|
|
5
|
+
import TabPanel from '@mui/lab/TabPanel';
|
|
6
|
+
import GroupItem from '../FormComponents/GroupItem/GroupItem';
|
|
7
|
+
import type {
|
|
8
|
+
PropsWithParentIsReadOnlyAttribute,
|
|
9
|
+
PropsWithQrItemChangeHandler
|
|
10
|
+
} from '../../interfaces/renderProps.interface';
|
|
11
|
+
import { useQuestionnaireStore } from '../../stores';
|
|
12
|
+
import { getQrItemsIndex, mapQItemsIndex } from '../../utils/mapItem';
|
|
13
|
+
import { createEmptyQrGroup, updateQrItemsInGroup } from '../../utils/qrItem';
|
|
14
|
+
|
|
15
|
+
interface FormBodyPageProps
|
|
16
|
+
extends PropsWithQrItemChangeHandler,
|
|
17
|
+
PropsWithParentIsReadOnlyAttribute {
|
|
18
|
+
topLevelQItem: QuestionnaireItem;
|
|
19
|
+
topLevelQRItem: QuestionnaireResponseItem | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function FormBodyPage(props: FormBodyPageProps) {
|
|
23
|
+
const { topLevelQItem, topLevelQRItem, parentIsReadOnly, onQrItemChange } = props;
|
|
24
|
+
|
|
25
|
+
const pages = useQuestionnaireStore.use.pages();
|
|
26
|
+
const currentPage = useQuestionnaireStore.use.currentPageIndex();
|
|
27
|
+
|
|
28
|
+
const indexMap: Record<string, number> = useMemo(
|
|
29
|
+
() => mapQItemsIndex(topLevelQItem),
|
|
30
|
+
[topLevelQItem]
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const nonNullTopLevelQRItem = topLevelQRItem ?? createEmptyQrGroup(topLevelQItem);
|
|
34
|
+
|
|
35
|
+
const qItems = topLevelQItem.item;
|
|
36
|
+
const qrItems = nonNullTopLevelQRItem.item;
|
|
37
|
+
|
|
38
|
+
function handleQrGroupChange(qrItem: QuestionnaireResponseItem) {
|
|
39
|
+
updateQrItemsInGroup(qrItem, null, nonNullTopLevelQRItem, indexMap);
|
|
40
|
+
onQrItemChange(nonNullTopLevelQRItem);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!qItems || !qrItems) {
|
|
44
|
+
return <>Unable to load form</>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const qrItemsByIndex = getQrItemsIndex(qItems, qrItems, indexMap);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Grid container spacing={1.5}>
|
|
51
|
+
<TabContext value={currentPage.toString()}>
|
|
52
|
+
<Grid item xs={12} md={12} lg={12}>
|
|
53
|
+
{qItems.map((qItem, i) => {
|
|
54
|
+
const qrItem = qrItemsByIndex[i];
|
|
55
|
+
|
|
56
|
+
const isNotRepeatGroup = !Array.isArray(qrItem);
|
|
57
|
+
const isPage = !!pages[qItem.linkId];
|
|
58
|
+
|
|
59
|
+
if (!isPage || !isNotRepeatGroup) {
|
|
60
|
+
// Something has gone horribly wrong
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const isRepeated = qItem.repeats ?? false;
|
|
65
|
+
const pageIsMarkedAsComplete = pages[qItem.linkId].isComplete ?? false;
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<TabPanel
|
|
69
|
+
key={qItem.linkId}
|
|
70
|
+
sx={{ p: 0 }}
|
|
71
|
+
value={i.toString()}
|
|
72
|
+
data-test="renderer-page-panel">
|
|
73
|
+
<GroupItem
|
|
74
|
+
qItem={qItem}
|
|
75
|
+
qrItem={qrItem ?? null}
|
|
76
|
+
isRepeated={isRepeated}
|
|
77
|
+
groupCardElevation={1}
|
|
78
|
+
pageIsMarkedAsComplete={pageIsMarkedAsComplete}
|
|
79
|
+
pages={pages}
|
|
80
|
+
currentPageIndex={currentPage}
|
|
81
|
+
parentIsReadOnly={parentIsReadOnly}
|
|
82
|
+
onQrItemChange={handleQrGroupChange}
|
|
83
|
+
/>
|
|
84
|
+
</TabPanel>
|
|
85
|
+
);
|
|
86
|
+
})}
|
|
87
|
+
</Grid>
|
|
88
|
+
</TabContext>
|
|
89
|
+
</Grid>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default FormBodyPage;
|