@aehrc/smart-forms-renderer 0.27.3 → 0.28.0

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 (193) hide show
  1. package/.storybook/main.ts +2 -1
  2. package/.storybook/preview.ts +6 -1
  3. package/.swcrc +2 -2
  4. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionFields.d.ts +3 -2
  5. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionFields.js +9 -17
  6. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionFields.js.map +1 -1
  7. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionItem.js +12 -9
  8. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionItem.js.map +1 -1
  9. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetFields.d.ts +2 -2
  10. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetFields.js +7 -9
  11. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetFields.js.map +1 -1
  12. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetItem.js +12 -8
  13. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetItem.js.map +1 -1
  14. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionFields.d.ts +3 -1
  15. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionFields.js +14 -4
  16. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionFields.js.map +1 -1
  17. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionItem.js +9 -4
  18. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionItem.js.map +1 -1
  19. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionView.d.ts +3 -1
  20. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionView.js +3 -3
  21. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionView.js.map +1 -1
  22. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetFields.d.ts +3 -2
  23. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetFields.js +16 -8
  24. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetFields.js.map +1 -1
  25. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetItem.js +7 -4
  26. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetItem.js.map +1 -1
  27. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionFields.d.ts +2 -1
  28. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionFields.js +2 -3
  29. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionFields.js.map +1 -1
  30. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionItem.js +8 -3
  31. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionItem.js.map +1 -1
  32. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionView.d.ts +3 -1
  33. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionView.js +3 -3
  34. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionView.js.map +1 -1
  35. package/lib/components/FormComponents/DateTimeItems/CustomDateTimeItem/DateTimeField.d.ts +2 -1
  36. package/lib/components/FormComponents/DateTimeItems/CustomDateTimeItem/DateTimeField.js.map +1 -1
  37. package/lib/components/FormComponents/DecimalItem/DecimalItem.js +3 -1
  38. package/lib/components/FormComponents/DecimalItem/DecimalItem.js.map +1 -1
  39. package/lib/components/FormComponents/GroupItem/TabButtonsWrapper.js +20 -20
  40. package/lib/components/FormComponents/GroupItem/TabButtonsWrapper.js.map +1 -1
  41. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionFields.d.ts +3 -2
  42. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionFields.js +7 -19
  43. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionFields.js.map +1 -1
  44. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionItem.js +40 -40
  45. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionItem.js.map +1 -1
  46. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceItemSwitcher.js +15 -3
  47. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceItemSwitcher.js.map +1 -1
  48. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionFields.d.ts +2 -1
  49. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionFields.js +3 -3
  50. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionFields.js.map +1 -1
  51. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionItem.js +27 -26
  52. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionItem.js.map +1 -1
  53. package/lib/components/FormComponents/StringItem/StringField.js +1 -1
  54. package/lib/components/FormComponents/StringItem/StringField.js.map +1 -1
  55. package/lib/hooks/useInitialiseRenderer.js +1 -1
  56. package/lib/hooks/useInitialiseRenderer.js.map +1 -1
  57. package/lib/hooks/useNextAndPreviousVisibleTabs.d.ts +7 -0
  58. package/lib/hooks/useNextAndPreviousVisibleTabs.js +63 -0
  59. package/lib/hooks/useNextAndPreviousVisibleTabs.js.map +1 -0
  60. package/lib/hooks/useNextPreviousVisibleTabs.d.ts +6 -0
  61. package/lib/hooks/useNextPreviousVisibleTabs.js +63 -0
  62. package/lib/hooks/useNextPreviousVisibleTabs.js.map +1 -0
  63. package/lib/hooks/useValidationFeedback.js +1 -1
  64. package/lib/index.d.ts +0 -7
  65. package/lib/index.js +0 -24
  66. package/lib/index.js.map +1 -1
  67. package/lib/utils/choice.d.ts +1 -7
  68. package/lib/utils/choice.js +10 -20
  69. package/lib/utils/choice.js.map +1 -1
  70. package/lib/utils/enableWhen.js +5 -7
  71. package/lib/utils/enableWhen.js.map +1 -1
  72. package/lib/utils/index.d.ts +1 -0
  73. package/lib/utils/index.js +1 -0
  74. package/lib/utils/index.js.map +1 -1
  75. package/lib/utils/openChoice.d.ts +9 -4
  76. package/lib/utils/openChoice.js +47 -78
  77. package/lib/utils/openChoice.js.map +1 -1
  78. package/lib/utils/tabs.d.ts +0 -21
  79. package/lib/utils/tabs.js +0 -51
  80. package/lib/utils/tabs.js.map +1 -1
  81. package/lib/utils/validateQuestionnaire.js.map +1 -1
  82. package/package.json +9 -6
  83. package/src/components/FormComponents/ChoiceItems/CheckboxOptionList.tsx +82 -0
  84. package/src/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionFields.tsx +23 -52
  85. package/src/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionItem.tsx +15 -9
  86. package/src/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetFields.tsx +17 -19
  87. package/src/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetItem.tsx +13 -8
  88. package/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionFields.tsx +32 -4
  89. package/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionItem.tsx +12 -2
  90. package/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionView.tsx +10 -2
  91. package/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetFields.tsx +29 -17
  92. package/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetItem.tsx +10 -4
  93. package/src/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionFields.tsx +4 -3
  94. package/src/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionItem.tsx +10 -2
  95. package/src/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionView.tsx +8 -2
  96. package/src/components/FormComponents/DateTimeItems/CustomDateTimeItem/DateTimeField.tsx +2 -1
  97. package/src/components/FormComponents/DecimalItem/DecimalItem.tsx +15 -12
  98. package/src/components/FormComponents/GroupItem/TabButtonsWrapper.tsx +28 -25
  99. package/src/components/FormComponents/ItemParts/{RadioAnswerOptionButtons.tsx → RadioOptionList.tsx} +7 -7
  100. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionFields.tsx +18 -50
  101. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionItem.tsx +70 -68
  102. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerValueSetFields.tsx +110 -0
  103. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerValueSetItem.tsx +188 -0
  104. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceItemSwitcher.tsx +46 -19
  105. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionFields.tsx +5 -3
  106. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionItem.tsx +37 -29
  107. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerValueSetFields.tsx +104 -0
  108. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerValueSetItem.tsx +156 -0
  109. package/src/components/FormComponents/StringItem/StringField.tsx +1 -1
  110. package/src/hooks/useInitialiseRenderer.ts +1 -1
  111. package/src/hooks/useNextAndPreviousVisibleTabs.ts +86 -0
  112. package/src/hooks/useOpenLabel.ts +43 -0
  113. package/src/hooks/useValidationFeedback.ts +1 -1
  114. package/src/index.ts +0 -21
  115. package/src/stories/BuildFormWrapper.tsx +57 -0
  116. package/src/stories/assets/questionnaires/QAdvancedAdditionalDisplayContent.ts +113 -0
  117. package/src/stories/assets/questionnaires/QAdvancedControlAppearance.ts +294 -0
  118. package/src/stories/assets/questionnaires/QAdvancedOther.ts +494 -0
  119. package/src/stories/assets/questionnaires/QAdvancedTextApperance.ts +216 -0
  120. package/src/stories/assets/questionnaires/QAttachment.ts +38 -0
  121. package/src/stories/assets/questionnaires/QBehaviorCalculations.ts +645 -0
  122. package/src/stories/assets/questionnaires/QBehaviorChoiceRestriction.ts +281 -0
  123. package/src/stories/assets/questionnaires/QBehaviorOther.ts +1149 -0
  124. package/src/stories/assets/questionnaires/QBehaviorValueConstraints.ts +508 -0
  125. package/src/stories/assets/questionnaires/QBoolean.ts +130 -0
  126. package/src/stories/assets/questionnaires/QChoice.ts +493 -0
  127. package/src/stories/assets/questionnaires/QDate.ts +56 -0
  128. package/src/stories/assets/questionnaires/QDateTime.ts +56 -0
  129. package/src/stories/assets/questionnaires/QDecimal.ts +56 -0
  130. package/src/stories/assets/questionnaires/QDisplay.ts +38 -0
  131. package/src/stories/assets/questionnaires/QGroup.ts +52 -0
  132. package/src/stories/assets/questionnaires/QInteger.ts +119 -0
  133. package/src/stories/assets/questionnaires/QItemControlDisplay.ts +557 -0
  134. package/src/stories/assets/questionnaires/QItemControlGroup.ts +633 -0
  135. package/src/stories/assets/questionnaires/QItemControlQuestion.ts +1271 -0
  136. package/src/stories/assets/questionnaires/QOpenChoice.ts +151 -0
  137. package/src/stories/assets/questionnaires/QQuantity.ts +44 -0
  138. package/src/stories/assets/questionnaires/QReference.ts +38 -0
  139. package/src/stories/assets/questionnaires/QSingleItems.ts +251 -0
  140. package/src/stories/assets/questionnaires/QString.ts +131 -0
  141. package/src/stories/assets/questionnaires/QText.ts +169 -0
  142. package/src/stories/assets/questionnaires/QTime.ts +38 -0
  143. package/src/stories/assets/questionnaires/QUrl.ts +38 -0
  144. package/src/stories/assets/questionnaires/index.ts +44 -0
  145. package/src/stories/itemTypes/Attachment.stories.tsx +39 -0
  146. package/src/stories/{MedicalHistoryTable.stories.tsx → itemTypes/Boolean.stories.tsx} +24 -26
  147. package/src/stories/itemTypes/Choice.stories.tsx +78 -0
  148. package/src/stories/itemTypes/Date.stories.tsx +46 -0
  149. package/src/stories/itemTypes/DateTime.stories.tsx +45 -0
  150. package/src/stories/itemTypes/Decimal.stories.tsx +56 -0
  151. package/src/stories/itemTypes/Display.stories.tsx +39 -0
  152. package/src/stories/itemTypes/Group.stories.tsx +39 -0
  153. package/src/stories/itemTypes/Integer.stories.tsx +55 -0
  154. package/src/stories/itemTypes/OpenChoice.stories.tsx +64 -0
  155. package/src/stories/itemTypes/Quantity.stories.tsx +39 -0
  156. package/src/stories/itemTypes/Reference.stories.tsx +39 -0
  157. package/src/stories/itemTypes/String.stories.tsx +51 -0
  158. package/src/stories/itemTypes/Text.stories.tsx +51 -0
  159. package/src/stories/itemTypes/Time.stories.tsx +39 -0
  160. package/src/stories/itemTypes/Url.stories.tsx +39 -0
  161. package/src/stories/sdc/AdvancedAdditionalDisplayContent.stories.tsx +51 -0
  162. package/src/stories/sdc/AdvancedControlAppearance.stories.tsx +51 -0
  163. package/src/stories/sdc/AdvancedOther.stories.tsx +76 -0
  164. package/src/stories/sdc/AdvancedTextAppearance.stories.tsx +76 -0
  165. package/src/stories/sdc/BehaviorCalculations.stories.tsx +69 -0
  166. package/src/stories/sdc/BehaviorChoiceRestriction.stories.tsx +76 -0
  167. package/src/stories/sdc/BehaviorOther.stories.tsx +90 -0
  168. package/src/stories/sdc/BehaviorValueConstraints.stories.tsx +88 -0
  169. package/src/stories/sdc/ItemControlDisplay.stories.tsx +69 -0
  170. package/src/stories/sdc/ItemControlGroup.stories.tsx +62 -0
  171. package/src/stories/sdc/ItemControlQuestion.stories.tsx +118 -0
  172. package/src/tests/enableWhen.test.ts +112 -0
  173. package/src/tests/test-data/enable-when-items-sample.json +3848 -0
  174. package/src/tests/test-data/initial-answers-sample.json +16 -0
  175. package/src/tests/test-data/linked-questions-map.json +217 -0
  176. package/src/tests/test-data/questionnaire-response-sample.json +650 -0
  177. package/src/utils/buildForm.ts +23 -0
  178. package/src/utils/choice.ts +16 -23
  179. package/src/utils/enableWhen.ts +5 -7
  180. package/src/utils/index.ts +1 -0
  181. package/src/utils/openChoice.ts +83 -98
  182. package/src/utils/tabs.ts +0 -75
  183. package/src/utils/validateQuestionnaire.ts +18 -6
  184. package/vite.config.ts +23 -0
  185. package/doctor-storybook.log +0 -18
  186. package/src/stories/SmartFormsRenderer.stories.ts +0 -139
  187. package/src/stories/assets/QItems-and-QRItems/QR_GTableMedicalHistory.json +0 -80
  188. package/src/stories/assets/QItems-and-QRItems/Q_GTableMedicalHistory.json +0 -109
  189. package/src/stories/assets/Qs-and-QRs/Q715.json +0 -15086
  190. package/src/stories/assets/Qs-and-QRs/QDev715.json +0 -16081
  191. package/src/stories/assets/Qs-and-QRs/QTestGrid.json +0 -411
  192. package/src/stories/assets/Qs-and-QRs/R715.json +0 -311
  193. package/src/stories/assets/Qs-and-QRs/RTestGrid.json +0 -34
@@ -0,0 +1,86 @@
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 { useQuestionnaireStore } from '../stores';
19
+ import type { Tabs } from '../interfaces/tab.interface';
20
+ import { constructTabsWithVisibility } from '../utils/tabs';
21
+
22
+ function useNextAndPreviousVisibleTabs(
23
+ currentTabIndex?: number,
24
+ tabs?: Tabs
25
+ ): { previousTabIndex: number | null; nextTabIndex: number | null; numOfVisibleTabs: number } {
26
+ const enableWhenIsActivated = useQuestionnaireStore.use.enableWhenIsActivated();
27
+ const enableWhenItems = useQuestionnaireStore.use.enableWhenItems();
28
+ const enableWhenExpressions = useQuestionnaireStore.use.enableWhenExpressions();
29
+
30
+ const tabsNotDefined = currentTabIndex === undefined || tabs === undefined;
31
+
32
+ if (tabsNotDefined) {
33
+ return { previousTabIndex: null, nextTabIndex: null, numOfVisibleTabs: 0 };
34
+ }
35
+
36
+ const tabsWithVisibility = constructTabsWithVisibility({
37
+ tabs,
38
+ enableWhenIsActivated,
39
+ enableWhenItems,
40
+ enableWhenExpressions
41
+ });
42
+
43
+ return {
44
+ previousTabIndex: getPreviousTabIndex(currentTabIndex, tabsWithVisibility),
45
+ nextTabIndex: getNextTabIndex(currentTabIndex, tabsWithVisibility),
46
+ numOfVisibleTabs: tabsWithVisibility.filter((tab) => tab.isVisible).length
47
+ };
48
+ }
49
+
50
+ function getPreviousTabIndex(
51
+ currentTabIndex: number,
52
+ tabsWithVisibility: { linkId: string; isVisible: boolean }[]
53
+ ): number | null {
54
+ const previousTabs = tabsWithVisibility.slice(0, currentTabIndex);
55
+ const foundIndex = previousTabs.reverse().findIndex((tab) => tab.isVisible);
56
+
57
+ // Previous visible tab not found
58
+ if (foundIndex === -1) {
59
+ return null;
60
+ }
61
+
62
+ // Previous visible tab less than 0
63
+ const previousTabIndex = currentTabIndex - foundIndex - 1;
64
+ if (previousTabIndex < 0) {
65
+ return null;
66
+ }
67
+
68
+ return previousTabIndex;
69
+ }
70
+
71
+ function getNextTabIndex(
72
+ currentTabIndex: number,
73
+ tabsWithVisibility: { linkId: string; isVisible: boolean }[]
74
+ ): number | null {
75
+ const subsequentTabs = tabsWithVisibility.slice(currentTabIndex + 1);
76
+ const foundIndex = subsequentTabs.findIndex((tab) => tab.isVisible);
77
+
78
+ // Next visible tab not found, something is wrong
79
+ if (foundIndex === -1) {
80
+ return null;
81
+ }
82
+
83
+ return currentTabIndex + foundIndex + 1;
84
+ }
85
+
86
+ export default useNextAndPreviousVisibleTabs;
@@ -0,0 +1,43 @@
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 { getOldOpenLabelAnswer } from '../utils/openChoice';
19
+ import { useState } from 'react';
20
+ import type { QuestionnaireItemAnswerOption, QuestionnaireResponseItemAnswer } from 'fhir/r4';
21
+
22
+ function useOpenLabel(
23
+ options: QuestionnaireItemAnswerOption[],
24
+ answers: QuestionnaireResponseItemAnswer[]
25
+ ) {
26
+ let initialOpenLabelValue = '';
27
+ let initialOpenLabelChecked = false;
28
+
29
+ if (options.length > 0) {
30
+ const oldLabelAnswer = getOldOpenLabelAnswer(answers, options);
31
+ if (oldLabelAnswer && oldLabelAnswer.valueString) {
32
+ initialOpenLabelValue = oldLabelAnswer.valueString;
33
+ initialOpenLabelChecked = true;
34
+ }
35
+ }
36
+
37
+ const [openLabelValue, setOpenLabelValue] = useState(initialOpenLabelValue);
38
+ const [openLabelChecked, setOpenLabelChecked] = useState(initialOpenLabelChecked);
39
+
40
+ return { openLabelValue, setOpenLabelValue, openLabelChecked, setOpenLabelChecked };
41
+ }
42
+
43
+ export default useOpenLabel;
@@ -70,7 +70,7 @@ function useValidationFeedback(qItem: QuestionnaireItem, input: string): string
70
70
  return `Input is lower than the expected minimum value of ${minValue}.`;
71
71
  }
72
72
 
73
- // Test min value
73
+ // Test max value
74
74
  if (
75
75
  invalidType === ValidationResult.maxValue &&
76
76
  (typeof maxValue === 'string' || typeof maxValue === 'number')
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { questionnaireResponseStore, questionnaireStore } from './stores';
2
2
  import type { Questionnaire, QuestionnaireResponse } from 'fhir/r4';
3
- import { initialiseQuestionnaireResponse } from './utils/initialise';
4
3
  import { removeEmptyAnswers } from './utils/removeEmptyAnswers';
5
4
  import type { ItemToRepopulate } from './utils/repopulateItems';
6
5
  import { getItemsToRepopulate } from './utils/repopulateItems';
@@ -13,26 +12,6 @@ export * from './utils';
13
12
  export * from './interfaces';
14
13
  export type { ItemToRepopulate };
15
14
 
16
- /**
17
- * Build the form with an initial Questionnaire and an optional filled QuestionnaireResponse.
18
- * If a QuestionnaireResponse is not provided, an empty QuestionnaireResponse is set as the initial QuestionnaireResponse.
19
- *
20
- * @author Sean Fong
21
- */
22
- export async function buildForm(
23
- questionnaire: Questionnaire,
24
- questionnaireResponse?: QuestionnaireResponse
25
- ): Promise<void> {
26
- await questionnaireStore.getState().buildSourceQuestionnaire(questionnaire);
27
-
28
- const initialisedQuestionnaireResponse = initialiseQuestionnaireResponse(
29
- questionnaire,
30
- questionnaireResponse
31
- );
32
- questionnaireResponseStore.getState().buildSourceResponse(initialisedQuestionnaireResponse);
33
- questionnaireStore.getState().updatePopulatedProperties(initialisedQuestionnaireResponse);
34
- }
35
-
36
15
  /**
37
16
  * Destroy the form to clean up the questionnaire and questionnaireResponse stores.
38
17
  *
@@ -0,0 +1,57 @@
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, { useLayoutEffect, useState } from 'react';
19
+ import type { Questionnaire, QuestionnaireResponse } from 'fhir/r4';
20
+ import { BaseRenderer } from '../components';
21
+ import { QueryClientProvider } from '@tanstack/react-query';
22
+ import ThemeProvider from '../theme/Theme';
23
+ import useQueryClient from '../hooks/useQueryClient';
24
+ import { buildForm } from '../utils';
25
+
26
+ interface BuildFormWrapperProps {
27
+ questionnaire: Questionnaire;
28
+ questionnaireResponse?: QuestionnaireResponse;
29
+ }
30
+
31
+ function BuildFormWrapper(props: BuildFormWrapperProps) {
32
+ const { questionnaire, questionnaireResponse } = props;
33
+
34
+ const [isLoading, setIsLoading] = useState(true);
35
+
36
+ useLayoutEffect(() => {
37
+ buildForm(questionnaire, questionnaireResponse).then(() => {
38
+ setIsLoading(false);
39
+ });
40
+ }, [questionnaire, questionnaireResponse]);
41
+
42
+ const queryClient = useQueryClient();
43
+
44
+ if (isLoading) {
45
+ return <div>Loading...</div>;
46
+ }
47
+
48
+ return (
49
+ <ThemeProvider>
50
+ <QueryClientProvider client={queryClient}>
51
+ <BaseRenderer />
52
+ </QueryClientProvider>
53
+ </ThemeProvider>
54
+ );
55
+ }
56
+
57
+ export default BuildFormWrapper;
@@ -0,0 +1,113 @@
1
+ import type { Questionnaire } from 'fhir/r4';
2
+
3
+ export const qEntryFormat: Questionnaire = {
4
+ resourceType: 'Questionnaire',
5
+ id: 'EntryFormat',
6
+ name: 'EntryFormat',
7
+ title: 'Entry Format',
8
+ version: '0.1.0',
9
+ status: 'draft',
10
+ publisher: 'AEHRC CSIRO',
11
+ date: '2024-05-01',
12
+ url: 'https://smartforms.csiro.au/docs/advanced/additional-display/entry-format',
13
+ item: [
14
+ {
15
+ extension: [
16
+ {
17
+ url: 'http://hl7.org/fhir/StructureDefinition/entryFormat',
18
+ valueString: '####'
19
+ }
20
+ ],
21
+ linkId: 'postcode',
22
+ definition: 'http://hl7.org.au/fhir/StructureDefinition/au-address#Address.postalCode',
23
+ text: 'Postcode',
24
+ type: 'string',
25
+ repeats: false
26
+ }
27
+ ]
28
+ };
29
+
30
+ export const qShortText: Questionnaire = {
31
+ resourceType: 'Questionnaire',
32
+ id: 'ShortText',
33
+ name: 'ShortText',
34
+ title: 'Short Text',
35
+ version: '0.1.0',
36
+ status: 'draft',
37
+ publisher: 'AEHRC CSIRO',
38
+ date: '2024-05-01',
39
+ url: 'https://smartforms.csiro.au/docs/advanced/additional-display/short-text',
40
+ item: [
41
+ {
42
+ extension: [
43
+ {
44
+ url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl',
45
+ valueCodeableConcept: {
46
+ coding: [
47
+ {
48
+ system: 'http://hl7.org/fhir/questionnaire-item-control',
49
+ version: '1.0.0',
50
+ code: 'tab-container'
51
+ }
52
+ ]
53
+ }
54
+ }
55
+ ],
56
+ linkId: 'tab-container',
57
+ type: 'group',
58
+ repeats: false,
59
+ item: [
60
+ {
61
+ extension: [
62
+ {
63
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-shortText',
64
+ valueString: 'Regular medications'
65
+ }
66
+ ],
67
+ linkId: 'tab-regular-medications',
68
+ text: 'Regular medications: check if still required, appropriate dose, understanding of medication and adherence',
69
+ type: 'group',
70
+ repeats: false,
71
+ item: [
72
+ {
73
+ linkId: 'highlight-short-text',
74
+ text: 'Notice the short text is used in the tab. The group title still displays the full text.',
75
+ type: 'display',
76
+ repeats: false
77
+ }
78
+ ]
79
+ }
80
+ ]
81
+ }
82
+ ]
83
+ };
84
+
85
+ export const qQuestionnaireUnit: Questionnaire = {
86
+ resourceType: 'Questionnaire',
87
+ id: 'QuestionnaireUnit',
88
+ name: 'QuestionnaireUnit',
89
+ title: 'Questionnaire Unit',
90
+ version: '0.1.0',
91
+ status: 'draft',
92
+ publisher: 'AEHRC CSIRO',
93
+ date: '2024-05-01',
94
+ url: 'https://smartforms.csiro.au/docs/advanced/additional-display/questionnaire-unit',
95
+ item: [
96
+ {
97
+ extension: [
98
+ {
99
+ url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-unit',
100
+ valueCoding: {
101
+ system: 'http://unitsofmeasure.org',
102
+ code: 'cm',
103
+ display: 'cm'
104
+ }
105
+ }
106
+ ],
107
+ linkId: 'height',
108
+ text: 'Height',
109
+ type: 'decimal',
110
+ repeats: false
111
+ }
112
+ ]
113
+ };
@@ -0,0 +1,294 @@
1
+ /*
2
+ * Copyright 2024 Commonwealth Scientific and Industrial Research
3
+ * Organisation (CSIRO) ABN 41 687 119 230.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ import type { Questionnaire } from 'fhir/r4';
19
+
20
+ export const qItemControl: Questionnaire = {
21
+ resourceType: 'Questionnaire',
22
+ id: 'ItemControl',
23
+ name: 'ItemControl',
24
+ title: 'Item Control',
25
+ version: '0.1.0',
26
+ status: 'draft',
27
+ publisher: 'AEHRC CSIRO',
28
+ date: '2024-05-01',
29
+ url: 'https://smartforms.csiro.au/docs/advanced/text/item-control',
30
+ item: [
31
+ {
32
+ linkId: 'item-control-instructions',
33
+ _text: {
34
+ extension: [
35
+ {
36
+ url: 'http://hl7.org/fhir/StructureDefinition/rendering-xhtml',
37
+ valueString:
38
+ '<div xmlns="http://www.w3.org/1999/xhtml">\r\n <p style="font-size:0.875em"> Please refer to the respective itemControl sections for group, display and question items.</p></div>'
39
+ }
40
+ ]
41
+ },
42
+ text: 'Please refer to the respective itemControl sections for group, display and question items.',
43
+ type: 'display',
44
+ repeats: false
45
+ }
46
+ ]
47
+ };
48
+
49
+ export const qChoiceOrientation: Questionnaire = {
50
+ resourceType: 'Questionnaire',
51
+ id: 'ChoiceOrientation',
52
+ name: 'ChoiceOrientation',
53
+ title: 'Choice Orientation',
54
+ version: '0.1.0',
55
+ status: 'draft',
56
+ publisher: 'AEHRC CSIRO',
57
+ date: '2024-05-08',
58
+ url: 'https://smartforms.csiro.au/docs/advanced/text/choice-orientation',
59
+ contained: [
60
+ {
61
+ resourceType: 'ValueSet',
62
+ id: 'administrative-gender',
63
+ meta: {
64
+ profile: ['http://hl7.org/fhir/StructureDefinition/shareablevalueset']
65
+ },
66
+ extension: [
67
+ {
68
+ url: 'http://hl7.org/fhir/StructureDefinition/structuredefinition-wg',
69
+ valueCode: 'pa'
70
+ },
71
+ {
72
+ url: 'http://hl7.org/fhir/StructureDefinition/structuredefinition-standards-status',
73
+ valueCode: 'normative'
74
+ },
75
+ {
76
+ url: 'http://hl7.org/fhir/StructureDefinition/structuredefinition-fmm',
77
+ valueInteger: 5
78
+ },
79
+ {
80
+ url: 'http://hl7.org/fhir/StructureDefinition/structuredefinition-normative-version',
81
+ valueCode: '4.0.0'
82
+ }
83
+ ],
84
+ url: 'http://hl7.org/fhir/ValueSet/administrative-gender',
85
+ identifier: [
86
+ {
87
+ system: 'urn:ietf:rfc:3986',
88
+ value: 'urn:oid:2.16.840.1.113883.4.642.3.1'
89
+ }
90
+ ],
91
+ version: '4.0.1',
92
+ name: 'AdministrativeGender',
93
+ title: 'AdministrativeGender',
94
+ status: 'active',
95
+ experimental: false,
96
+ date: '2019-11-01T09:29:23+11:00',
97
+ publisher: 'HL7 (FHIR Project)',
98
+ contact: [
99
+ {
100
+ telecom: [
101
+ {
102
+ system: 'url',
103
+ value: 'http://hl7.org/fhir'
104
+ },
105
+ {
106
+ system: 'email',
107
+ value: 'fhir@lists.hl7.org'
108
+ }
109
+ ]
110
+ }
111
+ ],
112
+ description: 'The gender of a person used for administrative purposes.',
113
+ immutable: true,
114
+ copyright: 'Copyright © 2011+ HL7. Licensed under Creative Commons "No Rights Reserved".',
115
+ compose: {
116
+ include: [
117
+ {
118
+ system: 'http://hl7.org/fhir/administrative-gender'
119
+ }
120
+ ]
121
+ },
122
+ expansion: {
123
+ identifier: 'urn:uuid:50f050c9-3975-48d6-bdb7-baae4ebc70cd',
124
+ timestamp: '2024-04-05T12:31:27+10:00',
125
+ total: 4,
126
+ parameter: [
127
+ {
128
+ name: 'version',
129
+ valueUri: 'http://hl7.org/fhir/administrative-gender|4.0.1'
130
+ },
131
+ {
132
+ name: 'used-codesystem',
133
+ valueUri: 'http://hl7.org/fhir/administrative-gender|4.0.1'
134
+ }
135
+ ],
136
+ contains: [
137
+ {
138
+ system: 'http://hl7.org/fhir/administrative-gender',
139
+ code: 'female',
140
+ display: 'Female'
141
+ },
142
+ {
143
+ system: 'http://hl7.org/fhir/administrative-gender',
144
+ code: 'male',
145
+ display: 'Male'
146
+ },
147
+ {
148
+ system: 'http://hl7.org/fhir/administrative-gender',
149
+ code: 'other',
150
+ display: 'Other'
151
+ },
152
+ {
153
+ system: 'http://hl7.org/fhir/administrative-gender',
154
+ code: 'unknown',
155
+ display: 'Unknown'
156
+ }
157
+ ]
158
+ }
159
+ }
160
+ ],
161
+ item: [
162
+ {
163
+ extension: [
164
+ {
165
+ url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-choiceOrientation',
166
+ valueCode: 'vertical'
167
+ },
168
+ {
169
+ url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl',
170
+ valueCodeableConcept: {
171
+ coding: [
172
+ {
173
+ system: 'http://hl7.org/fhir/questionnaire-item-control',
174
+ code: 'radio-button'
175
+ }
176
+ ]
177
+ }
178
+ }
179
+ ],
180
+ linkId: 'administrative-gender-vertical',
181
+ text: 'Administrative gender (vertical)',
182
+ type: 'choice',
183
+ repeats: false,
184
+ answerValueSet: '#administrative-gender'
185
+ },
186
+ {
187
+ extension: [
188
+ {
189
+ url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-choiceOrientation',
190
+ valueCode: 'horizontal'
191
+ },
192
+ {
193
+ url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl',
194
+ valueCodeableConcept: {
195
+ coding: [
196
+ {
197
+ system: 'http://hl7.org/fhir/questionnaire-item-control',
198
+ code: 'radio-button'
199
+ }
200
+ ]
201
+ }
202
+ }
203
+ ],
204
+ linkId: 'administrative-gender-horizontal',
205
+ text: 'Administrative gender (horizontal)',
206
+ type: 'choice',
207
+ repeats: false,
208
+ answerValueSet: '#administrative-gender'
209
+ }
210
+ ]
211
+ };
212
+
213
+ export const qSliderStepValue: Questionnaire = {
214
+ resourceType: 'Questionnaire',
215
+ id: 'SliderStepValue',
216
+ name: 'SliderStepValue',
217
+ title: 'Slider Step Value',
218
+ version: '0.1.0',
219
+ status: 'draft',
220
+ publisher: 'AEHRC CSIRO',
221
+ date: '2024-05-08',
222
+ url: 'https://smartforms.csiro.au/docs/advanced/text/slider-step-value',
223
+ item: [
224
+ {
225
+ extension: [
226
+ {
227
+ url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl',
228
+ valueCodeableConcept: {
229
+ coding: [
230
+ {
231
+ system: 'http://hl7.org/fhir/questionnaire-item-control',
232
+ code: 'slider'
233
+ }
234
+ ]
235
+ }
236
+ },
237
+ {
238
+ url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-sliderStepValue',
239
+ valueInteger: 1
240
+ },
241
+ {
242
+ url: 'http://hl7.org/fhir/StructureDefinition/minValue',
243
+ valueInteger: 0
244
+ },
245
+ {
246
+ url: 'http://hl7.org/fhir/StructureDefinition/maxValue',
247
+ valueInteger: 10
248
+ }
249
+ ],
250
+ linkId: 'pain-measure',
251
+ text: 'Pain measure',
252
+ type: 'integer',
253
+ repeats: false,
254
+ item: [
255
+ {
256
+ extension: [
257
+ {
258
+ url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl',
259
+ valueCodeableConcept: {
260
+ coding: [
261
+ {
262
+ system: 'http://hl7.org/fhir/questionnaire-item-control',
263
+ code: 'lower'
264
+ }
265
+ ]
266
+ }
267
+ }
268
+ ],
269
+ linkId: 'pain-measure-lower',
270
+ text: 'No pain',
271
+ type: 'display'
272
+ },
273
+ {
274
+ extension: [
275
+ {
276
+ url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl',
277
+ valueCodeableConcept: {
278
+ coding: [
279
+ {
280
+ system: 'http://hl7.org/fhir/questionnaire-item-control',
281
+ code: 'upper'
282
+ }
283
+ ]
284
+ }
285
+ }
286
+ ],
287
+ linkId: 'pain-measure-upper',
288
+ text: 'Unbearable pain',
289
+ type: 'display'
290
+ }
291
+ ]
292
+ }
293
+ ]
294
+ };