@aehrc/smart-forms-renderer 0.7.0 → 0.7.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 (189) hide show
  1. package/README.md +5 -5
  2. package/lib/components/FormComponents/ChoiceItems/ChoiceAutocompleteItem.js +1 -1
  3. package/lib/components/FormComponents/ChoiceItems/ChoiceAutocompleteItem.js.map +1 -1
  4. package/lib/components/FormComponents/DecimalItem/DecimalItem.js +3 -2
  5. package/lib/components/FormComponents/DecimalItem/DecimalItem.js.map +1 -1
  6. package/lib/components/FormComponents/GridGroup/GridGroup.js +2 -2
  7. package/lib/components/FormComponents/GridGroup/GridGroup.js.map +1 -1
  8. package/lib/components/FormComponents/GridGroup/GridRow.js +2 -2
  9. package/lib/components/FormComponents/GridGroup/GridRow.js.map +1 -1
  10. package/lib/components/FormComponents/GroupItem/GroupChildItemSwitcher.d.ts +10 -0
  11. package/lib/components/FormComponents/GroupItem/GroupChildItemSwitcher.js +73 -0
  12. package/lib/components/FormComponents/GroupItem/GroupChildItemSwitcher.js.map +1 -0
  13. package/lib/components/FormComponents/GroupItem/GroupItem.js +3 -3
  14. package/lib/components/FormComponents/GroupItem/GroupItem.js.map +1 -1
  15. package/lib/components/FormComponents/GroupItem/ItemSwitcher.d.ts +10 -0
  16. package/lib/components/FormComponents/GroupItem/ItemSwitcher.js +81 -0
  17. package/lib/components/FormComponents/GroupItem/ItemSwitcher.js.map +1 -0
  18. package/lib/components/FormComponents/GroupItem/TopLevelGroupItemSwitcher.d.ts +10 -0
  19. package/lib/components/FormComponents/GroupItem/TopLevelGroupItemSwitcher.js +45 -0
  20. package/lib/components/FormComponents/GroupItem/TopLevelGroupItemSwitcher.js.map +1 -0
  21. package/lib/components/FormComponents/IntegerItem/IntegerItem.js +3 -2
  22. package/lib/components/FormComponents/IntegerItem/IntegerItem.js.map +1 -1
  23. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteItem.js +2 -2
  24. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteItem.js.map +1 -1
  25. package/lib/components/FormComponents/RepeatGroup/RepeatGroup.js +4 -3
  26. package/lib/components/FormComponents/RepeatGroup/RepeatGroup.js.map +1 -1
  27. package/lib/components/FormComponents/RepeatGroup/index.d.ts +1 -0
  28. package/lib/{theme/overrides/Typography.js → components/FormComponents/RepeatGroup/index.js} +2 -15
  29. package/lib/components/FormComponents/RepeatGroup/index.js.map +1 -0
  30. package/lib/components/FormComponents/RepeatItem/RepeatItem.js +1 -1
  31. package/lib/components/FormComponents/RepeatItem/RepeatItem.js.map +1 -1
  32. package/lib/components/FormComponents/SingleItem/index.d.ts +1 -0
  33. package/lib/components/FormComponents/SingleItem/index.js +18 -0
  34. package/lib/components/FormComponents/SingleItem/index.js.map +1 -0
  35. package/lib/components/FormComponents/StringItem/StringItem.js +3 -2
  36. package/lib/components/FormComponents/StringItem/StringItem.js.map +1 -1
  37. package/lib/components/FormComponents/Tables/QItemGroupTable.js +7 -5
  38. package/lib/components/FormComponents/Tables/QItemGroupTable.js.map +1 -1
  39. package/lib/components/FormComponents/Tables/QItemGroupTableRow.js +2 -2
  40. package/lib/components/FormComponents/Tables/QItemGroupTableRow.js.map +1 -1
  41. package/lib/components/FormComponents/Tables/index.d.ts +1 -0
  42. package/lib/components/FormComponents/Tables/index.js +18 -0
  43. package/lib/components/FormComponents/Tables/index.js.map +1 -0
  44. package/lib/components/FormComponents/TextItem/TextItem.js +3 -2
  45. package/lib/components/FormComponents/TextItem/TextItem.js.map +1 -1
  46. package/lib/components/FormComponents/index.d.ts +3 -0
  47. package/lib/components/FormComponents/index.js +20 -0
  48. package/lib/components/FormComponents/index.js.map +1 -0
  49. package/lib/components/Renderer/BaseRenderer.js +26 -14
  50. package/lib/components/Renderer/BaseRenderer.js.map +1 -1
  51. package/lib/components/Renderer/FormBodyCollapsible.js +2 -2
  52. package/lib/components/Renderer/FormBodyCollapsible.js.map +1 -1
  53. package/lib/components/Renderer/FormBodyTabbed.js +2 -2
  54. package/lib/components/Renderer/FormBodyTabbed.js.map +1 -1
  55. package/lib/components/Renderer/FormTopLevelItem.d.ts +4 -4
  56. package/lib/components/Renderer/FormTopLevelItem.js +14 -1
  57. package/lib/components/Renderer/FormTopLevelItem.js.map +1 -1
  58. package/lib/components/index.d.ts +1 -0
  59. package/lib/components/index.js +1 -0
  60. package/lib/components/index.js.map +1 -1
  61. package/lib/hooks/useDecimalUpdateFromProp.d.ts +2 -0
  62. package/lib/{utils/isHidden.js → hooks/useDecimalUpdateFromProp.js} +12 -13
  63. package/lib/hooks/useDecimalUpdateFromProp.js.map +1 -0
  64. package/lib/hooks/useInitialiseRepeatAnswers.d.ts +2 -2
  65. package/lib/hooks/useInitialiseRepeatAnswers.js +21 -15
  66. package/lib/hooks/useInitialiseRepeatAnswers.js.map +1 -1
  67. package/lib/hooks/useInitialiseRepeatGroups.d.ts +2 -1
  68. package/lib/hooks/useInitialiseRepeatGroups.js +21 -15
  69. package/lib/hooks/useInitialiseRepeatGroups.js.map +1 -1
  70. package/lib/hooks/useIntegerUpdateFromProp.d.ts +2 -0
  71. package/lib/hooks/useIntegerUpdateFromProp.js +29 -0
  72. package/lib/hooks/useIntegerUpdateFromProp.js.map +1 -0
  73. package/lib/hooks/useNumberInput.d.ts +3 -0
  74. package/lib/hooks/useNumberInput.js +31 -0
  75. package/lib/hooks/useNumberInput.js.map +1 -0
  76. package/lib/hooks/useNumberUpdateFromProp.d.ts +2 -0
  77. package/lib/hooks/useNumberUpdateFromProp.js +29 -0
  78. package/lib/hooks/useNumberUpdateFromProp.js.map +1 -0
  79. package/lib/hooks/useRepeatItemState.d.ts +5 -0
  80. package/lib/hooks/useRepeatItemState.js +35 -0
  81. package/lib/hooks/useRepeatItemState.js.map +1 -0
  82. package/lib/hooks/useRepeatItemUpdateFromProp.d.ts +2 -0
  83. package/lib/hooks/useRepeatItemUpdateFromProp.js +29 -0
  84. package/lib/hooks/useRepeatItemUpdateFromProp.js.map +1 -0
  85. package/lib/hooks/useStringField.d.ts +2 -0
  86. package/lib/hooks/useStringField.js +29 -0
  87. package/lib/hooks/useStringField.js.map +1 -0
  88. package/lib/hooks/useStringInput.d.ts +3 -0
  89. package/lib/hooks/useStringInput.js +31 -0
  90. package/lib/hooks/useStringInput.js.map +1 -0
  91. package/lib/hooks/useStringUpdateFromProp.d.ts +2 -0
  92. package/lib/hooks/useStringUpdateFromProp.js +29 -0
  93. package/lib/hooks/useStringUpdateFromProp.js.map +1 -0
  94. package/lib/index.d.ts +16 -0
  95. package/lib/index.js +27 -0
  96. package/lib/index.js.map +1 -1
  97. package/lib/interfaces/questionnaireStore.interface.d.ts +1 -0
  98. package/lib/stores/useQuestionnaireResponseStore.d.ts +1 -1
  99. package/lib/stores/useQuestionnaireResponseStore.js +15 -10
  100. package/lib/stores/useQuestionnaireResponseStore.js.map +1 -1
  101. package/lib/stores/useQuestionnaireStore.d.ts +2 -1
  102. package/lib/stores/useQuestionnaireStore.js +5 -2
  103. package/lib/stores/useQuestionnaireStore.js.map +1 -1
  104. package/lib/theme/overrides/Overrides.js +1 -2
  105. package/lib/theme/overrides/Overrides.js.map +1 -1
  106. package/lib/utils/calculatedExpression.js +2 -2
  107. package/lib/utils/calculatedExpression.js.map +1 -1
  108. package/lib/utils/formChanges.d.ts +18 -0
  109. package/lib/utils/formChanges.js +91 -0
  110. package/lib/utils/formChanges.js.map +1 -0
  111. package/lib/utils/formChangesOld.d.ts +18 -0
  112. package/lib/utils/formChangesOld.js +91 -0
  113. package/lib/utils/formChangesOld.js.map +1 -0
  114. package/lib/utils/index.d.ts +1 -0
  115. package/lib/utils/index.js +18 -0
  116. package/lib/utils/index.js.map +1 -0
  117. package/lib/utils/mapItem.d.ts +2 -2
  118. package/lib/utils/mapItem.js +3 -3
  119. package/lib/utils/mapItem.js.map +1 -1
  120. package/lib/utils/qItem.d.ts +2 -0
  121. package/lib/utils/qItem.js +22 -0
  122. package/lib/utils/qItem.js.map +1 -1
  123. package/lib/utils/qrItem.d.ts +1 -1
  124. package/lib/utils/qrItem.js +92 -93
  125. package/lib/utils/qrItem.js.map +1 -1
  126. package/lib/utils/questionnaireStoreUtils/createQuestionaireModel.js +4 -0
  127. package/lib/utils/questionnaireStoreUtils/createQuestionaireModel.js.map +1 -1
  128. package/lib/utils/repopulate.d.ts +9 -0
  129. package/lib/utils/repopulate.js +133 -0
  130. package/lib/utils/repopulate.js.map +1 -0
  131. package/lib/utils/repopulateGenerateItems.d.ts +9 -0
  132. package/lib/utils/repopulateGenerateItems.js +133 -0
  133. package/lib/utils/repopulateGenerateItems.js.map +1 -0
  134. package/lib/utils/repopulateIntoResponse.d.ts +3 -0
  135. package/lib/utils/repopulateIntoResponse.js +92 -0
  136. package/lib/utils/repopulateIntoResponse.js.map +1 -0
  137. package/lib/utils/repopulateItems.d.ts +9 -0
  138. package/lib/utils/repopulateItems.js +131 -0
  139. package/lib/utils/repopulateItems.js.map +1 -0
  140. package/lib/utils/repopulateRepeatGroup.d.ts +4 -0
  141. package/lib/utils/repopulateRepeatGroup.js +54 -0
  142. package/lib/utils/repopulateRepeatGroup.js.map +1 -0
  143. package/package.json +3 -1
  144. package/src/components/FormComponents/ChoiceItems/ChoiceAutocompleteItem.tsx +1 -1
  145. package/src/components/FormComponents/DecimalItem/DecimalItem.tsx +3 -2
  146. package/src/components/FormComponents/GridGroup/GridGroup.tsx +2 -2
  147. package/src/components/FormComponents/GridGroup/GridRow.tsx +2 -2
  148. package/src/components/FormComponents/GroupItem/GroupItem.tsx +3 -3
  149. package/src/components/FormComponents/IntegerItem/IntegerItem.tsx +3 -2
  150. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteItem.tsx +1 -1
  151. package/src/components/FormComponents/RepeatGroup/RepeatGroup.tsx +4 -3
  152. package/src/{theme/overrides/Backdrop.ts → components/FormComponents/RepeatGroup/index.ts} +1 -17
  153. package/src/components/FormComponents/RepeatItem/RepeatItem.tsx +1 -1
  154. package/src/components/FormComponents/SingleItem/index.ts +18 -0
  155. package/src/components/FormComponents/StringItem/StringItem.tsx +3 -2
  156. package/src/components/FormComponents/Tables/QItemGroupTable.tsx +15 -6
  157. package/src/components/FormComponents/Tables/QItemGroupTableRow.tsx +2 -2
  158. package/src/components/FormComponents/Tables/index.ts +18 -0
  159. package/src/components/FormComponents/TextItem/TextItem.tsx +3 -2
  160. package/src/components/FormComponents/index.ts +20 -0
  161. package/src/components/Renderer/BaseRenderer.tsx +39 -18
  162. package/src/components/Renderer/FormBodyCollapsible.tsx +2 -2
  163. package/src/components/Renderer/FormBodyTabbed.tsx +2 -2
  164. package/src/components/Renderer/FormTopLevelItem.tsx +33 -4
  165. package/src/components/index.ts +1 -0
  166. package/src/hooks/index.ts +1 -0
  167. package/src/hooks/useInitialiseRepeatAnswers.ts +28 -17
  168. package/src/hooks/useInitialiseRepeatGroups.ts +28 -17
  169. package/src/hooks/useNumberInput.ts +37 -0
  170. package/src/hooks/useStringInput.ts +37 -0
  171. package/src/index.ts +43 -0
  172. package/src/interfaces/questionnaireStore.interface.ts +1 -0
  173. package/src/stores/useQuestionnaireResponseStore.ts +14 -10
  174. package/src/stores/useQuestionnaireStore.ts +10 -3
  175. package/src/theme/overrides/Overrides.ts +0 -2
  176. package/src/utils/calculatedExpression.ts +2 -2
  177. package/src/utils/formChanges.ts +141 -0
  178. package/src/utils/index.ts +18 -0
  179. package/src/utils/mapItem.ts +6 -4
  180. package/src/utils/qItem.ts +29 -0
  181. package/src/utils/qrItem.ts +104 -94
  182. package/src/utils/questionnaireStoreUtils/createQuestionaireModel.ts +4 -0
  183. package/src/utils/repopulateIntoResponse.ts +153 -0
  184. package/src/utils/repopulateItems.ts +207 -0
  185. package/src/utils/repopulateRepeatGroup.ts +68 -0
  186. package/lib/theme/overrides/Typography.d.ts +0 -13
  187. package/lib/theme/overrides/Typography.js.map +0 -1
  188. package/lib/utils/isHidden.d.ts +0 -3
  189. package/lib/utils/isHidden.js.map +0 -1
@@ -0,0 +1,92 @@
1
+ import { getQrItemsIndex, mapQItemsIndex } from './mapItem';
2
+ import { updateQrItemsInGroup } from './qrItem';
3
+ export function repopulateItemsIntoResponse(questionnaire, updatableResponse, checkedItemsToRepopulate) {
4
+ var _a;
5
+ if (!questionnaire.item ||
6
+ questionnaire.item.length === 0 ||
7
+ !updatableResponse.item ||
8
+ updatableResponse.item.length === 0) {
9
+ return updatableResponse;
10
+ }
11
+ const topLevelQrItems = [];
12
+ for (const [index, topLevelQItem] of questionnaire.item.entries()) {
13
+ const repopulatedTopLevelQrItem = (_a = updatableResponse.item[index]) !== null && _a !== void 0 ? _a : {
14
+ linkId: topLevelQItem.linkId,
15
+ text: topLevelQItem.text,
16
+ item: []
17
+ };
18
+ const updatedTopLevelQRItem = repopulateItemRecursive(topLevelQItem, repopulatedTopLevelQrItem, checkedItemsToRepopulate);
19
+ if (Array.isArray(updatedTopLevelQRItem)) {
20
+ if (updatedTopLevelQRItem.length > 0) {
21
+ topLevelQrItems.push(...updatedTopLevelQRItem);
22
+ }
23
+ continue;
24
+ }
25
+ if (updatedTopLevelQRItem) {
26
+ topLevelQrItems.push(updatedTopLevelQRItem);
27
+ }
28
+ }
29
+ return Object.assign(Object.assign({}, updatableResponse), { item: topLevelQrItems });
30
+ }
31
+ function repopulateItemRecursive(qItem, qrItem, checkedItemsToRepopulate) {
32
+ var _a;
33
+ const childQItems = qItem.item;
34
+ if (childQItems && childQItems.length > 0) {
35
+ // iterate through items of item recursively
36
+ const childQrItems = (_a = qrItem === null || qrItem === void 0 ? void 0 : qrItem.item) !== null && _a !== void 0 ? _a : [];
37
+ // const updatedChildQrItems: QuestionnaireResponseItem[] = [];
38
+ // FIXME Not implemented for repeat groups
39
+ if (qItem.type === 'group' && qItem.repeats) {
40
+ return qrItem !== null && qrItem !== void 0 ? qrItem : null;
41
+ }
42
+ const indexMap = mapQItemsIndex(qItem);
43
+ const qrItemsByIndex = getQrItemsIndex(childQItems, childQrItems, indexMap);
44
+ // Otherwise loop through qItem as usual
45
+ for (const [index, childQItem] of childQItems.entries()) {
46
+ const childQrItem = qrItemsByIndex[index];
47
+ // FIXME Not implemented for repeat groups
48
+ if (Array.isArray(childQrItem)) {
49
+ continue;
50
+ }
51
+ const newQrItem = repopulateItemRecursive(childQItem, childQrItem, checkedItemsToRepopulate);
52
+ // FIXME Not implemented for repeat groups
53
+ if (Array.isArray(newQrItem)) {
54
+ continue;
55
+ }
56
+ if (newQrItem) {
57
+ updateQrItemsInGroup(newQrItem, null, qrItem !== null && qrItem !== void 0 ? qrItem : { linkId: qItem.linkId, text: qItem.text, item: [] }, indexMap);
58
+ }
59
+ }
60
+ return constructGroupItem(qItem, qrItem, checkedItemsToRepopulate);
61
+ }
62
+ return constructSingleItem(qItem, qrItem, checkedItemsToRepopulate);
63
+ }
64
+ function constructGroupItem(qItem, qrItem, checkedItemsToRepopulate) {
65
+ const itemToRepopulate = checkedItemsToRepopulate[qItem.linkId];
66
+ if (!itemToRepopulate) {
67
+ return qrItem !== null && qrItem !== void 0 ? qrItem : null;
68
+ }
69
+ if (qrItem) {
70
+ return Object.assign(Object.assign({}, qrItem), { answer: itemToRepopulate.newQRItem.answer });
71
+ }
72
+ return {
73
+ linkId: qItem.linkId,
74
+ text: qItem.text,
75
+ answer: itemToRepopulate.newQRItem.answer
76
+ };
77
+ }
78
+ function constructSingleItem(qItem, qrItem, checkedItemsToRepopulate) {
79
+ const itemToRepopulate = checkedItemsToRepopulate[qItem.linkId];
80
+ if (!itemToRepopulate) {
81
+ return qrItem !== null && qrItem !== void 0 ? qrItem : null;
82
+ }
83
+ if (qrItem) {
84
+ return Object.assign(Object.assign({}, qrItem), { answer: itemToRepopulate.newQRItem.answer });
85
+ }
86
+ return {
87
+ linkId: qItem.linkId,
88
+ text: qItem.text,
89
+ answer: itemToRepopulate.newQRItem.answer
90
+ };
91
+ }
92
+ //# sourceMappingURL=repopulateIntoResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repopulateIntoResponse.js","sourceRoot":"","sources":["../../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BAAwB,CAAC,CAAC;KACpE;IAED,OAAO,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,wBAAwB,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,kBAAkB,CACzB,KAAwB,EACxB,MAA6C,EAC7C,wBAA0D;IAE1D,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAEhE,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,IAAI,CAAC;KACvB;IAED,IAAI,MAAM,EAAE;QACV,uCACK,MAAM,KACT,MAAM,EAAE,gBAAgB,CAAC,SAAS,CAAC,MAAM,IACzC;KACH;IAED,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,MAAM,EAAE,gBAAgB,CAAC,SAAS,CAAC,MAAM;KAC1C,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAC1B,KAAwB,EACxB,MAA6C,EAC7C,wBAA0D;IAE1D,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAEhE,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,IAAI,CAAC;KACvB;IAED,IAAI,MAAM,EAAE;QACV,uCACK,MAAM,KACT,MAAM,EAAE,gBAAgB,CAAC,SAAS,CAAC,MAAM,IACzC;KACH;IAED,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,MAAM,EAAE,gBAAgB,CAAC,SAAS,CAAC,MAAM;KAC1C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Questionnaire, QuestionnaireItem, QuestionnaireResponse, QuestionnaireResponseItem } from 'fhir/r4';
2
+ import type { Tabs } from '../interfaces/tab.interface';
3
+ export interface ItemToRepopulate {
4
+ qItem: QuestionnaireItem | null;
5
+ heading: string | null;
6
+ newQRItem: QuestionnaireResponseItem;
7
+ oldQRItem?: QuestionnaireResponseItem;
8
+ }
9
+ export declare function getItemsToRepopulate(sourceQuestionnaire: Questionnaire, itemTypes: Record<string, string>, tabs: Tabs, populatedResponse: QuestionnaireResponse, updatableResponse: QuestionnaireResponse): Record<string, ItemToRepopulate>;
@@ -0,0 +1,131 @@
1
+ /*
2
+ * Copyright 2023 Commonwealth Scientific and Industrial Research
3
+ * Organisation (CSIRO) ABN 41 687 119 230.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import _isEqual from 'lodash/isEqual';
18
+ import { containsTabs, isTabContainer } from './tabs';
19
+ import { getShortText } from './itemControl';
20
+ import { checkIsRepeatGroupToRepopulate, getRepeatGroupToRepopulate } from './repopulateRepeatGroup';
21
+ export function getItemsToRepopulate(sourceQuestionnaire, itemTypes, tabs, populatedResponse, updatableResponse) {
22
+ var _a;
23
+ if (!sourceQuestionnaire.item ||
24
+ sourceQuestionnaire.item.length === 0 ||
25
+ !populatedResponse.item ||
26
+ populatedResponse.item.length === 0 ||
27
+ !updatableResponse.item ||
28
+ updatableResponse.item.length === 0) {
29
+ return {};
30
+ }
31
+ const populatedItems = [];
32
+ for (const topLevelItem of populatedResponse.item) {
33
+ populatedItems.push(...getPopulatedItemsRecursive(topLevelItem, itemTypes));
34
+ }
35
+ const itemsToRepopulate = populatedItems.reduce((mapping, item) => {
36
+ mapping[item.linkId] = {
37
+ qItem: null,
38
+ heading: null,
39
+ newQRItem: item
40
+ };
41
+ return mapping;
42
+ }, {});
43
+ // Get corresponding old items from updatableResponse if they are different
44
+ for (const topLevelItem of updatableResponse.item) {
45
+ checkCorrespondingOldItemsRecursive(topLevelItem, itemTypes, itemsToRepopulate);
46
+ }
47
+ // Get corresponding old items from updatableResponse if they are different
48
+ for (const topLevelItem of sourceQuestionnaire.item) {
49
+ const heading = (_a = topLevelItem.text) !== null && _a !== void 0 ? _a : null;
50
+ const hasTabs = isTabContainer(topLevelItem) || containsTabs(topLevelItem);
51
+ getCorrespondingQuestionnaireItemsRecursive(topLevelItem, heading, tabs, hasTabs, itemsToRepopulate);
52
+ }
53
+ return itemsToRepopulate;
54
+ }
55
+ // 1. Get items to repopulate (only new items)
56
+ // 2. Get corresponding old items from updatableResponse (if they are different)
57
+ // 3. Compare old and new items in dialog - if there are none, show a dialog saying there is no new data
58
+ // 4. Have checkboxes in dialog to update response
59
+ // 5. Replace old answers with new answers
60
+ function getCorrespondingQuestionnaireItemsRecursive(qItem, heading, tabs, hasTabs, itemsToRepopulate) {
61
+ var _a, _b;
62
+ if (qItem.type === 'group' && qItem.item && qItem.item.length > 0) {
63
+ const isTab = !!tabs[qItem.linkId];
64
+ if (isTab) {
65
+ heading = (_b = (_a = getShortText(qItem)) !== null && _a !== void 0 ? _a : qItem.text) !== null && _b !== void 0 ? _b : null;
66
+ }
67
+ // TODO it seems like there can only be one answer per linkId, we might need to do repeat groups differently
68
+ // so we need to fix this one first it seems like
69
+ /* Repeat group implementation */
70
+ if (qItem.type === 'group' && qItem.repeats) {
71
+ const isRepeatGroupToRepopulate = checkIsRepeatGroupToRepopulate(qItem, itemsToRepopulate);
72
+ if (isRepeatGroupToRepopulate) {
73
+ const repeatGroupToRepopulate = getRepeatGroupToRepopulate(qItem, itemsToRepopulate);
74
+ if (repeatGroupToRepopulate) {
75
+ itemsToRepopulate[qItem.linkId] = repeatGroupToRepopulate;
76
+ return;
77
+ }
78
+ }
79
+ }
80
+ // /* Grid implementation */
81
+ // if (qItem.type === 'group' && isSpecificItemControl(qItem, 'grid')) {
82
+ // const isRepeatGroupToRepopulate = checkIsRepeatGroupToRepopulate(qItem, itemsToRepopulate);
83
+ // if (isRepeatGroupToRepopulate) {
84
+ // getRepeatGroupToRepopulate(qItem, itemsToRepopulate);
85
+ // }
86
+ // }
87
+ for (const childItem of qItem.item) {
88
+ getCorrespondingQuestionnaireItemsRecursive(childItem, heading, tabs, hasTabs, itemsToRepopulate);
89
+ }
90
+ return;
91
+ }
92
+ if (!itemsToRepopulate[qItem.linkId]) {
93
+ return;
94
+ }
95
+ itemsToRepopulate[qItem.linkId].qItem = qItem;
96
+ itemsToRepopulate[qItem.linkId].heading = heading;
97
+ }
98
+ function getPopulatedItemsRecursive(qrItem, itemTypes) {
99
+ const itemType = itemTypes[qrItem.linkId];
100
+ if (itemType === 'group' && qrItem.item && qrItem.item.length > 0) {
101
+ const populatedChildItems = [];
102
+ for (const childItem of qrItem.item) {
103
+ populatedChildItems.push(...getPopulatedItemsRecursive(childItem, itemTypes));
104
+ }
105
+ return populatedChildItems;
106
+ }
107
+ // record item if it is not a group item
108
+ return [qrItem];
109
+ }
110
+ function checkCorrespondingOldItemsRecursive(qrItem, itemTypes, itemsToRepopulate) {
111
+ var _a;
112
+ const itemType = itemTypes[qrItem.linkId];
113
+ if (itemType === 'group' && qrItem.item && qrItem.item.length > 0) {
114
+ for (const childItem of qrItem.item) {
115
+ checkCorrespondingOldItemsRecursive(childItem, itemTypes, itemsToRepopulate);
116
+ }
117
+ return;
118
+ }
119
+ const oldItem = qrItem;
120
+ const newItem = (_a = itemsToRepopulate[qrItem.linkId]) === null || _a === void 0 ? void 0 : _a.newQRItem;
121
+ if (!newItem) {
122
+ return;
123
+ }
124
+ if (_isEqual(oldItem, newItem)) {
125
+ delete itemsToRepopulate[qrItem.linkId];
126
+ return;
127
+ }
128
+ // const filteredNewItems = newItems.filter((newItem) => !_isEqual(oldItem, newItem));
129
+ itemsToRepopulate[qrItem.linkId].oldQRItem = oldItem;
130
+ }
131
+ //# sourceMappingURL=repopulateItems.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repopulateItems.js","sourceRoot":"","sources":["../../src/utils/repopulateItems.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AASH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC3B,MAAM,yBAAyB,CAAC;AASjC,MAAM,UAAU,oBAAoB,CAClC,mBAAkC,EAClC,SAAiC,EACjC,IAAU,EACV,iBAAwC,EACxC,iBAAwC;;IAExC,IACE,CAAC,mBAAmB,CAAC,IAAI;QACzB,mBAAmB,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;QACrC,CAAC,iBAAiB,CAAC,IAAI;QACvB,iBAAiB,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;QACnC,CAAC,iBAAiB,CAAC,IAAI;QACvB,iBAAiB,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EACnC;QACA,OAAO,EAAE,CAAC;KACX;IAED,MAAM,cAAc,GAAgC,EAAE,CAAC;IACvD,KAAK,MAAM,YAAY,IAAI,iBAAiB,CAAC,IAAI,EAAE;QACjD,cAAc,CAAC,IAAI,CAAC,GAAG,0BAA0B,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;KAC7E;IAED,MAAM,iBAAiB,GAAG,cAAc,CAAC,MAAM,CAC7C,CAAC,OAAyC,EAAE,IAAI,EAAE,EAAE;QAClD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG;YACrB,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,IAAI;YACb,SAAS,EAAE,IAAI;SAChB,CAAC;QAEF,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,EAAE,CACH,CAAC;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,iBAAmD;;IAEnD,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,QAAQ,KAAK,OAAO,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;QACjE,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,IAAI,EAAE;YACnC,mCAAmC,CAAC,SAAS,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC;SAC9E;QAED,OAAO;KACR;IAED,MAAM,OAAO,GAAG,MAAM,CAAC;IACvB,MAAM,OAAO,GAAG,MAAA,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,0CAAE,SAAS,CAAC;IAE5D,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO;KACR;IAED,IAAI,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE;QAC9B,OAAO,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO;KACR;IAED,sFAAsF;IAEtF,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,GAAG,OAAO,CAAC;AACvD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { QuestionnaireItem } from 'fhir/r4';
2
+ import type { ItemToRepopulate } from './repopulateItems';
3
+ export declare function checkIsRepeatGroupToRepopulate(qItem: QuestionnaireItem, itemsToRepopulate: Record<string, ItemToRepopulate>): boolean | undefined;
4
+ export declare function getRepeatGroupToRepopulate(qItem: QuestionnaireItem, itemsToRepopulate: Record<string, ItemToRepopulate>): ItemToRepopulate | null;
@@ -0,0 +1,54 @@
1
+ /*
2
+ * Copyright 2023 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
+ export function checkIsRepeatGroupToRepopulate(qItem, itemsToRepopulate) {
18
+ if (!qItem.item) {
19
+ return false;
20
+ }
21
+ for (const childItem of qItem.item) {
22
+ if (itemsToRepopulate[childItem.linkId]) {
23
+ return true;
24
+ }
25
+ }
26
+ }
27
+ export function getRepeatGroupToRepopulate(qItem, itemsToRepopulate) {
28
+ var _a;
29
+ if (!qItem.item) {
30
+ return null;
31
+ }
32
+ const childLinkIds = qItem.item
33
+ .filter((childItem) => !!itemsToRepopulate[childItem.linkId])
34
+ .map((childItem) => childItem.linkId);
35
+ const childQRItemsToRepopulate = childLinkIds
36
+ .reduce((result, linkId) => {
37
+ if (itemsToRepopulate[linkId]) {
38
+ result.push(itemsToRepopulate[linkId]);
39
+ }
40
+ return result;
41
+ }, [])
42
+ .map((itemToRepopulate) => itemToRepopulate.newQRItem);
43
+ const repeatGroupToRepopulate = {
44
+ heading: (_a = qItem.text) !== null && _a !== void 0 ? _a : null,
45
+ qItem: qItem,
46
+ newQRItem: {
47
+ linkId: qItem.linkId,
48
+ text: qItem.text,
49
+ item: childQRItemsToRepopulate
50
+ }
51
+ };
52
+ return repeatGroupToRepopulate;
53
+ }
54
+ //# sourceMappingURL=repopulateRepeatGroup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repopulateRepeatGroup.js","sourceRoot":"","sources":["../../src/utils/repopulateRepeatGroup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,MAAM,UAAU,8BAA8B,CAC5C,KAAwB,EACxB,iBAAmD;IAEnD,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;QACf,OAAO,KAAK,CAAC;KACd;IAED,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE;QAClC,IAAI,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;YACvC,OAAO,IAAI,CAAC;SACb;KACF;AACH,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,KAAwB,EACxB,iBAAmD;;IAEnD,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;QACf,OAAO,IAAI,CAAC;KACb;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI;SAC5B,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;SAC5D,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAExC,MAAM,wBAAwB,GAAG,YAAY;SAC1C,MAAM,CAAC,CAAC,MAA0B,EAAE,MAAM,EAAE,EAAE;QAC7C,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAE;YAC7B,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;SACxC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,EAAE,CAAC;SACL,GAAG,CAAC,CAAC,gBAAgB,EAAE,EAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAEzD,MAAM,uBAAuB,GAAqB;QAChD,OAAO,EAAE,MAAA,KAAK,CAAC,IAAI,mCAAI,IAAI;QAC3B,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE;YACT,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,wBAAwB;SAC/B;KACF,CAAC;IAEF,OAAO,uBAAuB,CAAC;AACjC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aehrc/smart-forms-renderer",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "FHIR Structured Data Captured (SDC) rendering engine for Smart Forms",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -23,6 +23,7 @@
23
23
  },
24
24
  "homepage": "https://github.com/aehrc/smart-forms#readme",
25
25
  "dependencies": {
26
+ "json-diff": "^1.0.6",
26
27
  "@iconify/react": "^4.1.1",
27
28
  "dayjs": "^1.11.9",
28
29
  "fhirclient": "^2.5.2",
@@ -62,6 +63,7 @@
62
63
  "@testing-library/react": "^14.0.0",
63
64
  "@testing-library/react-hooks": "^7.0.2",
64
65
  "@types/jest": "^29.5.4",
66
+ "@types/json-diff": "^1.0.0",
65
67
  "@types/react": "^18.2.18",
66
68
  "@types/react-dom": "^18.2.7",
67
69
  "jest": "^29.6.4",
@@ -106,6 +106,7 @@ function ChoiceAutocompleteItem(props: ChoiceAutocompleteItemProps) {
106
106
  options={options}
107
107
  getOptionLabel={(option) => `${option.display}`}
108
108
  isOptionEqualToValue={(option, value) => option.id === value.id}
109
+ disabled={readOnly}
109
110
  loading={loading}
110
111
  loadingText={'Fetching results...'}
111
112
  clearOnEscape
@@ -118,7 +119,6 @@ function ChoiceAutocompleteItem(props: ChoiceAutocompleteItemProps) {
118
119
  {...params}
119
120
  onChange={(e: ChangeEvent<HTMLInputElement>) => setInput(e.target.value)}
120
121
  isTabled={isTabled}
121
- disabled={readOnly}
122
122
  label={displayPrompt}
123
123
  size="small"
124
124
  InputProps={{
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
 
18
- import React, { useCallback, useState } from 'react';
18
+ import React, { useCallback } from 'react';
19
19
  import type {
20
20
  PropsWithIsRepeatedAttribute,
21
21
  PropsWithIsTabledAttribute,
@@ -36,6 +36,7 @@ import {
36
36
  } from '../../../utils/parseInputs';
37
37
  import { getDecimalPrecision } from '../../../utils/itemControl';
38
38
  import useDecimalCalculatedExpression from '../../../hooks/useDecimalCalculatedExpression';
39
+ import useStringInput from '../../../hooks/useStringInput';
39
40
 
40
41
  interface DecimalItemProps
41
42
  extends PropsWithQrItemChangeHandler<QuestionnaireResponseItem>,
@@ -74,7 +75,7 @@ function DecimalItem(props: DecimalItemProps) {
74
75
 
75
76
  initialInput = precision ? valueDecimal.toFixed(precision) : valueDecimal.toString();
76
77
  }
77
- const [input, setInput] = useState(initialInput);
78
+ const [input, setInput] = useStringInput(initialInput);
78
79
 
79
80
  // Perform validation checks
80
81
  const feedback = useValidationError(input, regexValidation, maxLength);
@@ -18,7 +18,7 @@
18
18
  import React, { useMemo } from 'react';
19
19
  import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
20
20
  import type { PropsWithQrItemChangeHandler } from '../../../interfaces/renderProps.interface';
21
- import { createQrGroup, updateQrGroup } from '../../../utils/qrItem';
21
+ import { createQrGroup, updateQrItemsInGroup } from '../../../utils/qrItem';
22
22
  import useHidden from '../../../hooks/useHidden';
23
23
  import { QGroupContainerBox } from '../../Box.styles';
24
24
  import Divider from '@mui/material/Divider';
@@ -66,7 +66,7 @@ function GridGroup(props: GridGroupProps) {
66
66
  // Event Handlers
67
67
  function handleRowChange(newQrItem: QuestionnaireResponseItem) {
68
68
  const updatedQrGroup: QuestionnaireResponseItem = { ...qrGroup };
69
- updateQrGroup(newQrItem, null, updatedQrGroup, qItemsIndexMap);
69
+ updateQrItemsInGroup(newQrItem, null, updatedQrGroup, qItemsIndexMap);
70
70
  onQrItemChange(updatedQrGroup);
71
71
  }
72
72
 
@@ -18,7 +18,7 @@
18
18
  import React, { useMemo } from 'react';
19
19
  import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
20
20
  import type { PropsWithQrItemChangeHandler } from '../../../interfaces/renderProps.interface';
21
- import { createQrGroup, updateQrGroup } from '../../../utils/qrItem';
21
+ import { createQrGroup, updateQrItemsInGroup } from '../../../utils/qrItem';
22
22
  import { GridAnswerTableCell, GridTextTableCell } from '../Tables/Table.styles';
23
23
  import SingleItem from '../SingleItem/SingleItem';
24
24
  import { getQrItemsIndex, mapQItemsIndex } from '../../../utils/mapItem';
@@ -52,7 +52,7 @@ function GridRow(props: GridRowProps) {
52
52
 
53
53
  function handleQrRowItemChange(newQrRowItem: QuestionnaireResponseItem) {
54
54
  const qrRow: QuestionnaireResponseItem = { ...row };
55
- updateQrGroup(newQrRowItem, null, qrRow, qItemsIndexMap);
55
+ updateQrItemsInGroup(newQrRowItem, null, qrRow, qItemsIndexMap);
56
56
  onQrItemChange(qrRow);
57
57
  }
58
58
 
@@ -18,7 +18,7 @@
18
18
  import React, { useMemo } from 'react';
19
19
  import { getQrItemsIndex, mapQItemsIndex } from '../../../utils/mapItem';
20
20
  import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
21
- import { createQrGroup, updateQrGroup } from '../../../utils/qrItem';
21
+ import { createQrGroup, updateQrItemsInGroup } from '../../../utils/qrItem';
22
22
  import { QGroupContainerBox } from '../../Box.styles';
23
23
  import type {
24
24
  PropsWithIsRepeatedAttribute,
@@ -70,13 +70,13 @@ function GroupItem(props: GroupItemProps) {
70
70
  // Event Handlers
71
71
  function handleQrItemChange(newQrItem: QuestionnaireResponseItem) {
72
72
  const updatedQrGroup: QuestionnaireResponseItem = { ...qrGroup };
73
- updateQrGroup(newQrItem, null, updatedQrGroup, qItemsIndexMap);
73
+ updateQrItemsInGroup(newQrItem, null, updatedQrGroup, qItemsIndexMap);
74
74
  onQrItemChange(updatedQrGroup);
75
75
  }
76
76
 
77
77
  function handleQrRepeatGroupChange(qrRepeatGroup: QrRepeatGroup) {
78
78
  const updatedQrGroup: QuestionnaireResponseItem = { ...qrGroup };
79
- updateQrGroup(null, qrRepeatGroup, updatedQrGroup, qItemsIndexMap);
79
+ updateQrItemsInGroup(null, qrRepeatGroup, updatedQrGroup, qItemsIndexMap);
80
80
  onQrItemChange(updatedQrGroup);
81
81
  }
82
82
 
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
 
18
- import React, { useCallback, useState } from 'react';
18
+ import React, { useCallback } from 'react';
19
19
  import type {
20
20
  PropsWithIsRepeatedAttribute,
21
21
  PropsWithIsTabledAttribute,
@@ -32,6 +32,7 @@ import IntegerField from './IntegerField';
32
32
  import useIntegerCalculatedExpression from '../../../hooks/useIntegerCalculatedExpression';
33
33
  import { parseValidInteger } from '../../../utils/parseInputs';
34
34
  import ItemFieldGrid from '../ItemParts/ItemFieldGrid';
35
+ import useNumberInput from '../../../hooks/useNumberInput';
35
36
 
36
37
  interface IntegerItemProps
37
38
  extends PropsWithQrItemChangeHandler<QuestionnaireResponseItem>,
@@ -65,7 +66,7 @@ function IntegerItem(props: IntegerItemProps) {
65
66
  valueInteger = Math.round(qrItem.answer[0].valueDecimal);
66
67
  }
67
68
  }
68
- const [value, setValue] = useState(valueInteger);
69
+ const [value, setValue] = useNumberInput(valueInteger);
69
70
 
70
71
  // Perform validation checks
71
72
  const feedback = useValidationError(value.toString(), regexValidation, maxLength);
@@ -122,6 +122,7 @@ function OpenChoiceAutocompleteItem(props: OpenChoiceAutocompleteItemProps) {
122
122
  value={valueAutocomplete}
123
123
  options={options}
124
124
  getOptionLabel={(option) => (typeof option === 'string' ? option : `${option.display}`)}
125
+ disabled={readOnly}
125
126
  loading={loading}
126
127
  loadingText={'Fetching results...'}
127
128
  clearOnEscape
@@ -146,7 +147,6 @@ function OpenChoiceAutocompleteItem(props: OpenChoiceAutocompleteItemProps) {
146
147
  }}
147
148
  onChange={(e: ChangeEvent<HTMLInputElement>) => setInput(e.target.value)}
148
149
  isTabled={isTabled}
149
- disabled={readOnly}
150
150
  label={displayPrompt}
151
151
  size="small"
152
152
  InputProps={{
@@ -31,6 +31,7 @@ import { nanoid } from 'nanoid';
31
31
  import RepeatGroupItem from './RepeatGroupItem';
32
32
  import AddItemButton from './AddItemButton';
33
33
  import LabelWrapper from '../ItemParts/ItemLabelWrapper';
34
+ import cloneDeep from 'lodash.clonedeep';
34
35
 
35
36
  interface RepeatGroupProps extends PropsWithQrRepeatGroupChangeHandler {
36
37
  qItem: QuestionnaireItem;
@@ -41,7 +42,7 @@ interface RepeatGroupProps extends PropsWithQrRepeatGroupChangeHandler {
41
42
  function RepeatGroup(props: RepeatGroupProps) {
42
43
  const { qItem, qrItems, groupCardElevation, onQrRepeatGroupChange } = props;
43
44
 
44
- const initialRepeatGroups = useInitialiseRepeatGroups(qrItems);
45
+ const initialRepeatGroups = useInitialiseRepeatGroups(qItem, qrItems);
45
46
 
46
47
  const [repeatGroups, setRepeatGroups] = useState(initialRepeatGroups);
47
48
 
@@ -60,7 +61,7 @@ function RepeatGroup(props: RepeatGroupProps) {
60
61
  onQrRepeatGroupChange({
61
62
  linkId: qItem.linkId,
62
63
  qrItems: updatedRepeatGroups.flatMap((singleGroup) =>
63
- singleGroup.qrItem ? [singleGroup.qrItem] : []
64
+ singleGroup.qrItem ? [cloneDeep(singleGroup.qrItem)] : []
64
65
  )
65
66
  });
66
67
  }
@@ -74,7 +75,7 @@ function RepeatGroup(props: RepeatGroupProps) {
74
75
  onQrRepeatGroupChange({
75
76
  linkId: qItem.linkId,
76
77
  qrItems: updatedRepeatGroups.flatMap((singleGroup) =>
77
- singleGroup.qrItem ? [singleGroup.qrItem] : []
78
+ singleGroup.qrItem ? [cloneDeep(singleGroup.qrItem)] : []
78
79
  )
79
80
  });
80
81
  }
@@ -15,20 +15,4 @@
15
15
  * limitations under the License.
16
16
  */
17
17
 
18
- import type { Theme } from '@mui/material/styles';
19
- import { alpha } from '@mui/material/styles';
20
-
21
- export default function Backdrop(theme: Theme) {
22
- return {
23
- MuiBackdrop: {
24
- styleOverrides: {
25
- root: {
26
- backgroundColor: alpha(theme.palette.grey[800], 0.8)
27
- },
28
- invisible: {
29
- background: 'transparent'
30
- }
31
- }
32
- }
33
- };
34
- }
18
+ export { default as RepeatGroup } from './RepeatGroup';
@@ -40,7 +40,7 @@ function RepeatItem(props: RepeatItemProps) {
40
40
  // Get additional rendering extensions
41
41
  const { displayInstructions } = useRenderingExtensions(qItem);
42
42
 
43
- const initialRepeatAnswers = useInitialiseRepeatAnswers(qrItem);
43
+ const initialRepeatAnswers = useInitialiseRepeatAnswers(qItem, qrItem);
44
44
 
45
45
  const [repeatAnswers, setRepeatAnswers] = useState(initialRepeatAnswers);
46
46
 
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright 2023 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
+ export { default as SingleItem } from './SingleItem';
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
 
18
- import React, { useCallback, useState } from 'react';
18
+ import React, { useCallback } from 'react';
19
19
  import type {
20
20
  PropsWithIsRepeatedAttribute,
21
21
  PropsWithIsTabledAttribute,
@@ -31,6 +31,7 @@ import { FullWidthFormComponentBox } from '../../Box.styles';
31
31
  import StringField from './StringField';
32
32
  import ItemFieldGrid from '../ItemParts/ItemFieldGrid';
33
33
  import useStringCalculatedExpression from '../../../hooks/useStringCalculatedExpression';
34
+ import useStringInput from '../../../hooks/useStringInput';
34
35
 
35
36
  interface StringItemProps
36
37
  extends PropsWithQrItemChangeHandler<QuestionnaireResponseItem>,
@@ -58,7 +59,7 @@ function StringItem(props: StringItemProps) {
58
59
  if (qrItem?.answer && qrItem?.answer[0].valueString) {
59
60
  valueString = qrItem.answer[0].valueString;
60
61
  }
61
- const [input, setInput] = useState(valueString);
62
+ const [input, setInput] = useStringInput(valueString);
62
63
 
63
64
  // Perform validation checks
64
65
  const feedback = useValidationError(input, regexValidation, maxLength);
@@ -41,6 +41,7 @@ import { nanoid } from 'nanoid';
41
41
  import { createEmptyQrItem } from '../../../utils/qrItem';
42
42
  import DeleteRowButton from './DeleteRowButton';
43
43
  import LabelWrapper from '../ItemParts/ItemLabelWrapper';
44
+ import cloneDeep from 'lodash.clonedeep';
44
45
 
45
46
  interface Props extends PropsWithQrRepeatGroupChangeHandler {
46
47
  qItem: QuestionnaireItem;
@@ -84,7 +85,9 @@ function QItemGroupTable(props: Props) {
84
85
  setTableRows(updatedTableRows);
85
86
  onQrRepeatGroupChange({
86
87
  linkId: qItem.linkId,
87
- qrItems: updatedTableRows.flatMap((singleRow) => (singleRow.qrItem ? [singleRow.qrItem] : []))
88
+ qrItems: updatedTableRows.flatMap((singleRow) =>
89
+ singleRow.qrItem ? [cloneDeep(singleRow.qrItem)] : []
90
+ )
88
91
  });
89
92
  }
90
93
 
@@ -96,7 +99,9 @@ function QItemGroupTable(props: Props) {
96
99
  setTableRows(updatedTableRows);
97
100
  onQrRepeatGroupChange({
98
101
  linkId: qItem.linkId,
99
- qrItems: updatedTableRows.flatMap((singleRow) => (singleRow.qrItem ? [singleRow.qrItem] : []))
102
+ qrItems: updatedTableRows.flatMap((singleRow) =>
103
+ singleRow.qrItem ? [cloneDeep(singleRow.qrItem)] : []
104
+ )
100
105
  });
101
106
  }
102
107
 
@@ -112,10 +117,14 @@ function QItemGroupTable(props: Props) {
112
117
 
113
118
  return (
114
119
  <QGroupContainerBox cardElevation={groupCardElevation} isRepeated={false} py={3}>
115
- <Typography fontSize={13} variant="h6">
116
- <LabelWrapper qItem={qItem} />
117
- </Typography>
118
- <Divider sx={{ my: 1 }} light />
120
+ {groupCardElevation !== 1 ? (
121
+ <>
122
+ <Typography fontSize={13} variant="h6">
123
+ <LabelWrapper qItem={qItem} />
124
+ </Typography>
125
+ <Divider sx={{ my: 1 }} light />
126
+ </>
127
+ ) : null}
119
128
  <TableContainer component={Paper} elevation={groupCardElevation}>
120
129
  <Table>
121
130
  <caption>