@aehrc/smart-forms-renderer 0.36.1 → 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.
Files changed (113) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/lib/components/FormComponents/Button.styles.d.ts +4 -0
  3. package/lib/components/FormComponents/Button.styles.js +10 -0
  4. package/lib/components/FormComponents/Button.styles.js.map +1 -0
  5. package/lib/components/FormComponents/GroupItem/GroupHeading.d.ts +1 -0
  6. package/lib/components/FormComponents/GroupItem/GroupHeading.js +3 -2
  7. package/lib/components/FormComponents/GroupItem/GroupHeading.js.map +1 -1
  8. package/lib/components/FormComponents/GroupItem/GroupItem.d.ts +4 -0
  9. package/lib/components/FormComponents/GroupItem/GroupItem.js +3 -3
  10. package/lib/components/FormComponents/GroupItem/GroupItem.js.map +1 -1
  11. package/lib/components/FormComponents/GroupItem/GroupItemView.d.ts +4 -0
  12. package/lib/components/FormComponents/GroupItem/GroupItemView.js +8 -5
  13. package/lib/components/FormComponents/GroupItem/GroupItemView.js.map +1 -1
  14. package/lib/components/FormComponents/GroupItem/NextPageButton.d.ts +7 -0
  15. package/lib/{hooks/useQueryClient.js → components/FormComponents/GroupItem/NextPageButton.js} +9 -12
  16. package/lib/components/FormComponents/GroupItem/NextPageButton.js.map +1 -0
  17. package/lib/components/FormComponents/GroupItem/PageButtonWrapper.d.ts +8 -0
  18. package/lib/components/FormComponents/GroupItem/PageButtonWrapper.js +46 -0
  19. package/lib/components/FormComponents/GroupItem/PageButtonWrapper.js.map +1 -0
  20. package/lib/components/FormComponents/GroupItem/PreviousPageButton.d.ts +7 -0
  21. package/lib/components/FormComponents/GroupItem/PreviousPageButton.js +26 -0
  22. package/lib/components/FormComponents/GroupItem/PreviousPageButton.js.map +1 -0
  23. package/lib/components/Renderer/BaseRenderer.js +8 -0
  24. package/lib/components/Renderer/BaseRenderer.js.map +1 -1
  25. package/lib/components/Renderer/FormBodyPage.d.ts +9 -0
  26. package/lib/components/Renderer/FormBodyPage.js +43 -0
  27. package/lib/components/Renderer/FormBodyPage.js.map +1 -0
  28. package/lib/components/Renderer/FormTopLevelItem.js +7 -0
  29. package/lib/components/Renderer/FormTopLevelItem.js.map +1 -1
  30. package/lib/components/Renderer/FormTopLevelPage.d.ts +9 -0
  31. package/lib/components/Renderer/FormTopLevelPage.js +29 -0
  32. package/lib/components/Renderer/FormTopLevelPage.js.map +1 -0
  33. package/lib/hooks/useNextAndPreviousVisiblePages.d.ts +7 -0
  34. package/lib/hooks/useNextAndPreviousVisiblePages.js +47 -0
  35. package/lib/hooks/useNextAndPreviousVisiblePages.js.map +1 -0
  36. package/lib/interfaces/page.interface.d.ts +16 -0
  37. package/lib/interfaces/page.interface.js +2 -0
  38. package/lib/interfaces/page.interface.js.map +1 -0
  39. package/lib/interfaces/questionnaireStore.interface.d.ts +2 -0
  40. package/lib/stores/questionnaireStore.d.ts +13 -0
  41. package/lib/stores/questionnaireStore.js +19 -3
  42. package/lib/stores/questionnaireStore.js.map +1 -1
  43. package/lib/utils/initialise.d.ts +3 -0
  44. package/lib/utils/initialise.js +6 -1
  45. package/lib/utils/initialise.js.map +1 -1
  46. package/lib/utils/page.d.ts +43 -0
  47. package/lib/utils/page.js +101 -0
  48. package/lib/utils/page.js.map +1 -0
  49. package/lib/utils/questionnaireStoreUtils/createQuestionaireModel.js +4 -0
  50. package/lib/utils/questionnaireStoreUtils/createQuestionaireModel.js.map +1 -1
  51. package/lib/utils/questionnaireStoreUtils/extractPages.d.ts +3 -0
  52. package/lib/utils/questionnaireStoreUtils/extractPages.js +18 -0
  53. package/lib/utils/questionnaireStoreUtils/extractPages.js.map +1 -0
  54. package/package.json +4 -4
  55. package/src/components/FormComponents/Button.styles.ts +10 -0
  56. package/src/components/FormComponents/GroupItem/GroupHeading.tsx +5 -3
  57. package/src/components/FormComponents/GroupItem/GroupItem.tsx +11 -1
  58. package/src/components/FormComponents/GroupItem/GroupItemView.tsx +12 -0
  59. package/src/components/FormComponents/GroupItem/NextPageButton.tsx +37 -0
  60. package/src/components/FormComponents/GroupItem/PageButtonWrapper.tsx +78 -0
  61. package/src/components/FormComponents/GroupItem/PreviousPageButton.tsx +41 -0
  62. package/src/components/Renderer/BaseRenderer.tsx +21 -0
  63. package/src/components/Renderer/FormBodyPage.tsx +93 -0
  64. package/src/components/Renderer/FormTopLevelItem.tsx +17 -0
  65. package/src/components/Renderer/FormTopLevelPage.tsx +70 -0
  66. package/src/hooks/useNextAndPreviousVisiblePages.ts +69 -0
  67. package/src/interfaces/page.interface.ts +13 -0
  68. package/src/interfaces/questionnaireStore.interface.ts +2 -0
  69. package/src/stores/questionnaireStore.ts +33 -2
  70. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreAllergyIntolerance.json +1 -1
  71. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreCondition.json +1 -1
  72. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreEncounter.json +137 -58
  73. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreImmunization.json +175 -0
  74. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreMedicationRequest.json +229 -0
  75. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreObservationBP.json +359 -0
  76. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreObservationBodyHeight.json +195 -0
  77. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreObservationBodyWeight.json +195 -0
  78. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreObservationHeartRate.json +195 -0
  79. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreObservationSmokingStatus.json +174 -0
  80. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCorePatient.json +495 -0
  81. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCorePractitioner.json +139 -0
  82. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCorePractitionerRole.json +216 -0
  83. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreProcedure.json +199 -0
  84. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreRespirationRate.json +195 -0
  85. package/src/stories/assets/questionnaires/AuCoreTestingJson/AuCoreWaistCircumference.json +195 -0
  86. package/src/stories/assets/questionnaires/QAuCoreTesting.ts +3342 -1
  87. package/src/stories/assets/questionnaires/QItemControlGroup.ts +673 -0
  88. package/src/stories/sdc/ItemControlGroup.stories.tsx +22 -1
  89. package/src/stories/testing/AuCoreTester.stories.tsx +140 -1
  90. package/src/utils/initialise.ts +11 -0
  91. package/src/utils/page.ts +134 -0
  92. package/src/utils/questionnaireStoreUtils/createQuestionaireModel.ts +5 -0
  93. package/src/utils/questionnaireStoreUtils/extractPages.ts +24 -0
  94. package/lib/components/FormComponents/DateTimeItem/DateTimeField.d.ts +0 -12
  95. package/lib/components/FormComponents/DateTimeItem/DateTimeField.js +0 -34
  96. package/lib/components/FormComponents/DateTimeItem/DateTimeField.js.map +0 -1
  97. package/lib/components/FormComponents/DateTimeItem/DateTimeItem.d.ts +0 -9
  98. package/lib/components/FormComponents/DateTimeItem/DateTimeItem.js +0 -60
  99. package/lib/components/FormComponents/DateTimeItem/DateTimeItem.js.map +0 -1
  100. package/lib/hooks/useDisplayCalculatedExpression.d.ts +0 -3
  101. package/lib/hooks/useDisplayCalculatedExpression.js +0 -40
  102. package/lib/hooks/useDisplayCalculatedExpression.js.map +0 -1
  103. package/lib/hooks/useInitialiseRenderer.d.ts +0 -4
  104. package/lib/hooks/useInitialiseRenderer.js +0 -85
  105. package/lib/hooks/useInitialiseRenderer.js.map +0 -1
  106. package/lib/hooks/useQueryClient.d.ts +0 -3
  107. package/lib/hooks/useQueryClient.js.map +0 -1
  108. package/lib/utils/buildForm.d.ts +0 -8
  109. package/lib/utils/buildForm.js +0 -26
  110. package/lib/utils/buildForm.js.map +0 -1
  111. package/stats.html +0 -4842
  112. package/stats1.html +0 -4842
  113. package/stats3.html +0 -4842
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aehrc/smart-forms-renderer",
3
- "version": "0.36.1",
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.0",
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.2"
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.0.10",
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;
@@ -18,7 +18,9 @@
18
18
  import React from 'react';
19
19
  import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
20
20
  import FormBodyTabbed from './FormBodyTabbed';
21
+ import FormBodyPage from './FormBodyPage';
21
22
  import { containsTabs, isTabContainer } from '../../utils/tabs';
23
+ import { containsPages, isPage } from '../../utils/page';
22
24
  import GroupItem from '../FormComponents/GroupItem/GroupItem';
23
25
  import SingleItem from '../FormComponents/SingleItem/SingleItem';
24
26
  import type {
@@ -53,6 +55,9 @@ function FormTopLevelItem(props: FormTopLevelItemProps) {
53
55
  const itemIsTabContainer = isTabContainer(topLevelQItem);
54
56
  const itemContainsTabs = containsTabs(topLevelQItem);
55
57
 
58
+ const itemIsPageContainer = isPage(topLevelQItem);
59
+ const itemContainsPages = containsPages(topLevelQItem);
60
+
56
61
  const isTablet = useResponsive('up', 'md');
57
62
 
58
63
  const itemIsGroup = topLevelQItem.type === 'group';
@@ -106,6 +111,18 @@ function FormTopLevelItem(props: FormTopLevelItemProps) {
106
111
  );
107
112
  }
108
113
 
114
+ if (itemContainsPages || itemIsPageContainer) {
115
+ return (
116
+ <FormBodyPage
117
+ key={topLevelQItem.linkId}
118
+ topLevelQItem={topLevelQItem}
119
+ topLevelQRItem={topLevelQRItem}
120
+ parentIsReadOnly={readOnly}
121
+ onQrItemChange={onQrItemChange}
122
+ />
123
+ );
124
+ }
125
+
109
126
  // If form is untabbed, it is rendered as a regular group
110
127
  if (itemIsGroup) {
111
128
  return (
@@ -0,0 +1,70 @@
1
+ import React 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
+
13
+ interface FormTopLevelPageProps
14
+ extends PropsWithQrItemChangeHandler,
15
+ PropsWithParentIsReadOnlyAttribute {
16
+ topLevelQItems: QuestionnaireItem[];
17
+ topLevelQRItems: (QuestionnaireResponseItem | QuestionnaireResponseItem[] | undefined)[];
18
+ }
19
+
20
+ function FormTopLevelPage(props: FormTopLevelPageProps) {
21
+ const { topLevelQItems, topLevelQRItems, parentIsReadOnly, onQrItemChange } = props;
22
+
23
+ const pages = useQuestionnaireStore.use.pages();
24
+ const currentPage = useQuestionnaireStore.use.currentPageIndex();
25
+
26
+ return (
27
+ <Grid container spacing={1.5}>
28
+ <TabContext value={currentPage.toString()}>
29
+ <Grid item xs={12} md={12} lg={12}>
30
+ {topLevelQItems.map((qItem, i) => {
31
+ const qrItem = topLevelQRItems[i];
32
+
33
+ const isNotRepeatGroup = !Array.isArray(qrItem);
34
+ const isPage = !!pages[qItem.linkId];
35
+
36
+ if (!isPage || !isNotRepeatGroup) {
37
+ // Something has gone horribly wrong
38
+ return null;
39
+ }
40
+
41
+ const isRepeated = qItem.repeats ?? false;
42
+ const pageIsMarkedAsComplete = pages[qItem.linkId].isComplete ?? false;
43
+
44
+ return (
45
+ <TabPanel
46
+ key={qItem.linkId}
47
+ sx={{ p: 0 }}
48
+ value={i.toString()}
49
+ data-test="renderer-page-panel">
50
+ <GroupItem
51
+ qItem={qItem}
52
+ qrItem={qrItem ?? null}
53
+ isRepeated={isRepeated}
54
+ groupCardElevation={1}
55
+ pageIsMarkedAsComplete={pageIsMarkedAsComplete}
56
+ pages={pages}
57
+ currentPageIndex={currentPage}
58
+ parentIsReadOnly={parentIsReadOnly}
59
+ onQrItemChange={onQrItemChange}
60
+ />
61
+ </TabPanel>
62
+ );
63
+ })}
64
+ </Grid>
65
+ </TabContext>
66
+ </Grid>
67
+ );
68
+ }
69
+
70
+ export default FormTopLevelPage;
@@ -0,0 +1,69 @@
1
+ import { useQuestionnaireStore } from '../stores';
2
+ import type { Pages } from '../interfaces/page.interface';
3
+ import { constructPagesWithVisibility } from '../utils/page';
4
+
5
+ function useNextAndPreviousVisiblePages(
6
+ currentPageIndex?: number,
7
+ pages?: Pages
8
+ ): { previousPageIndex: number | null; nextPageIndex: number | null; numOfVisiblePages: number } {
9
+ const enableWhenIsActivated = useQuestionnaireStore.use.enableWhenIsActivated();
10
+ const enableWhenItems = useQuestionnaireStore.use.enableWhenItems();
11
+ const enableWhenExpressions = useQuestionnaireStore.use.enableWhenExpressions();
12
+
13
+ const pagesNotDefined = currentPageIndex === undefined || pages === undefined;
14
+
15
+ if (pagesNotDefined) {
16
+ return { previousPageIndex: null, nextPageIndex: null, numOfVisiblePages: 0 };
17
+ }
18
+
19
+ const pagesWithVisibility = constructPagesWithVisibility({
20
+ pages,
21
+ enableWhenIsActivated,
22
+ enableWhenItems,
23
+ enableWhenExpressions
24
+ });
25
+
26
+ return {
27
+ previousPageIndex: getPreviousPageIndex(currentPageIndex, pagesWithVisibility),
28
+ nextPageIndex: getNextPageIndex(currentPageIndex, pagesWithVisibility),
29
+ numOfVisiblePages: pagesWithVisibility.filter((tab) => tab.isVisible).length
30
+ };
31
+ }
32
+
33
+ function getPreviousPageIndex(
34
+ currentPageIndex: number,
35
+ pagesWithVisibility: { linkId: string; isVisible: boolean }[]
36
+ ): number | null {
37
+ const previousPages = pagesWithVisibility.slice(0, currentPageIndex);
38
+ const foundIndex = previousPages.reverse().findIndex((tab) => tab.isVisible);
39
+
40
+ // Previous visible tab not found
41
+ if (foundIndex === -1) {
42
+ return null;
43
+ }
44
+
45
+ // Previous visible tab less than 0
46
+ const previousPageIndex = currentPageIndex - foundIndex - 1;
47
+ if (previousPageIndex < 0) {
48
+ return null;
49
+ }
50
+
51
+ return previousPageIndex;
52
+ }
53
+
54
+ function getNextPageIndex(
55
+ currentPageIndex: number,
56
+ pagesWithVisibility: { linkId: string; isVisible: boolean }[]
57
+ ): number | null {
58
+ const subsequentPages = pagesWithVisibility.slice(currentPageIndex + 1);
59
+ const foundIndex = subsequentPages.findIndex((tab) => tab.isVisible);
60
+
61
+ // Next visible tab not found, something is wrong
62
+ if (foundIndex === -1) {
63
+ return null;
64
+ }
65
+
66
+ return currentPageIndex + foundIndex + 1;
67
+ }
68
+
69
+ export default useNextAndPreviousVisiblePages;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Page interface
3
+ *
4
+ * @property pageIndex - The index of the page
5
+ * @property isComplete - Whether the page is marked as complete
6
+ * @property isHidden - Whether the page is hidden
7
+ */
8
+ export type Page = { pageIndex: number; isComplete: boolean; isHidden: boolean };
9
+
10
+ /**
11
+ * Key-value pair of pages `Record<linkId, Page>`
12
+ */
13
+ export type Pages = Record<string, Page>;