@aehrc/smart-forms-renderer 0.7.2 → 0.8.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 (199) hide show
  1. package/lib/components/FormComponents/ChoiceItems/ChoiceAutocompleteItem.js +0 -1
  2. package/lib/components/FormComponents/ChoiceItems/ChoiceAutocompleteItem.js.map +1 -1
  3. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionFields.d.ts +12 -0
  4. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionFields.js +39 -0
  5. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionFields.js.map +1 -0
  6. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionItem.d.ts +3 -3
  7. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionItem.js +14 -27
  8. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionItem.js.map +1 -1
  9. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetFields.d.ts +13 -0
  10. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetFields.js +42 -0
  11. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetFields.js.map +1 -0
  12. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetItem.d.ts +4 -3
  13. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetItem.js +14 -22
  14. package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetItem.js.map +1 -1
  15. package/lib/components/FormComponents/ChoiceItems/ChoiceItemSwitcher.d.ts +2 -2
  16. package/lib/components/FormComponents/ChoiceItems/ChoiceItemSwitcher.js +3 -3
  17. package/lib/components/FormComponents/ChoiceItems/ChoiceItemSwitcher.js.map +1 -1
  18. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionFields.d.ts +12 -0
  19. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionFields.js +27 -0
  20. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionFields.js.map +1 -0
  21. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionItem.d.ts +1 -1
  22. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionItem.js +9 -24
  23. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionItem.js.map +1 -1
  24. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetFields.d.ts +14 -0
  25. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetFields.js +42 -0
  26. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetFields.js.map +1 -0
  27. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetItem.d.ts +1 -1
  28. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetItem.js +8 -21
  29. package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetItem.js.map +1 -1
  30. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionFields.d.ts +10 -0
  31. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionFields.js +41 -0
  32. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionFields.js.map +1 -0
  33. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionItem.js +7 -23
  34. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionItem.js.map +1 -1
  35. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetFields.d.ts +12 -0
  36. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetFields.js +42 -0
  37. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetFields.js.map +1 -0
  38. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetItem.js +8 -18
  39. package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetItem.js.map +1 -1
  40. package/lib/components/FormComponents/GroupItem/GroupItemSwitcher.js +4 -4
  41. package/lib/components/FormComponents/GroupItem/GroupItemSwitcher.js.map +1 -1
  42. package/lib/components/FormComponents/Item.styles.d.ts +2 -2
  43. package/lib/components/FormComponents/Item.styles.js +2 -2
  44. package/lib/components/FormComponents/Item.styles.js.map +1 -1
  45. package/lib/components/FormComponents/ItemParts/RadioAnswerOptionButtons.d.ts +8 -0
  46. package/lib/components/FormComponents/ItemParts/RadioAnswerOptionButtons.js +37 -0
  47. package/lib/components/FormComponents/ItemParts/RadioAnswerOptionButtons.js.map +1 -0
  48. package/lib/components/FormComponents/ItemParts/RadioButtons.d.ts +8 -0
  49. package/lib/components/FormComponents/ItemParts/RadioButtons.js +37 -0
  50. package/lib/components/FormComponents/ItemParts/RadioButtons.js.map +1 -0
  51. package/lib/components/FormComponents/ItemParts/RadioButtonsAnswerOption.d.ts +8 -0
  52. package/lib/components/FormComponents/ItemParts/RadioButtonsAnswerOption.js +37 -0
  53. package/lib/components/FormComponents/ItemParts/RadioButtonsAnswerOption.js.map +1 -0
  54. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteField.d.ts +20 -0
  55. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteField.js +49 -0
  56. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteField.js.map +1 -0
  57. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteFieldEndAdornment.d.ts +0 -0
  58. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteFieldEndAdornment.js +2 -0
  59. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteFieldEndAdornment.js.map +1 -0
  60. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteItem.js +11 -35
  61. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteItem.js.map +1 -1
  62. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionFields.d.ts +17 -0
  63. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionFields.js +42 -0
  64. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionFields.js.map +1 -0
  65. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionItem.d.ts +3 -3
  66. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionItem.js +23 -36
  67. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionItem.js.map +1 -1
  68. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceItemSwitcher.d.ts +2 -2
  69. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceItemSwitcher.js +3 -3
  70. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceItemSwitcher.js.map +1 -1
  71. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionFields.d.ts +15 -0
  72. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionFields.js +29 -0
  73. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionFields.js.map +1 -0
  74. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionItem.d.ts +1 -1
  75. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionItem.js +3 -23
  76. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionItem.js.map +1 -1
  77. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionField.d.ts +11 -0
  78. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionField.js +14 -0
  79. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionField.js.map +1 -0
  80. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionFields.d.ts +0 -0
  81. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionFields.js +2 -0
  82. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionFields.js.map +1 -0
  83. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionItem.js +18 -23
  84. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionItem.js.map +1 -1
  85. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetField.d.ts +12 -0
  86. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetField.js +16 -0
  87. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetField.js.map +1 -0
  88. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetItem.js +8 -14
  89. package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetItem.js.map +1 -1
  90. package/lib/components/FormComponents/SingleItem/SingleItem.d.ts +2 -2
  91. package/lib/components/FormComponents/SingleItem/SingleItem.js +2 -2
  92. package/lib/components/FormComponents/SingleItem/SingleItem.js.map +1 -1
  93. package/lib/components/FormComponents/SingleItem/SingleItemSwitcher.d.ts +2 -2
  94. package/lib/components/FormComponents/SingleItem/SingleItemSwitcher.js +3 -3
  95. package/lib/components/FormComponents/SingleItem/SingleItemSwitcher.js.map +1 -1
  96. package/lib/components/FormComponents/Tables/AddItemButton.d.ts +8 -0
  97. package/lib/components/FormComponents/Tables/AddItemButton.js +28 -0
  98. package/lib/components/FormComponents/Tables/AddItemButton.js.map +1 -0
  99. package/lib/components/FormComponents/Tables/AddRowButton.d.ts +8 -0
  100. package/lib/components/FormComponents/Tables/AddRowButton.js +28 -0
  101. package/lib/components/FormComponents/Tables/AddRowButton.js.map +1 -0
  102. package/lib/components/FormComponents/Tables/GroupTable.d.ts +10 -0
  103. package/lib/components/FormComponents/Tables/GroupTable.js +108 -0
  104. package/lib/components/FormComponents/Tables/GroupTable.js.map +1 -0
  105. package/lib/components/FormComponents/Tables/GroupTableRow.d.ts +10 -0
  106. package/lib/components/FormComponents/Tables/GroupTableRow.js +46 -0
  107. package/lib/components/FormComponents/Tables/GroupTableRow.js.map +1 -0
  108. package/lib/components/FormComponents/Tables/index.d.ts +1 -1
  109. package/lib/components/FormComponents/Tables/index.js +1 -1
  110. package/lib/components/FormComponents/Tables/index.js.map +1 -1
  111. package/lib/components/Renderer/FormBodyTabbed.js +1 -1
  112. package/lib/components/Renderer/FormBodyTabbed.js.map +1 -1
  113. package/lib/components/Tabs/FormBodySingleTab.js +1 -1
  114. package/lib/components/Tabs/FormBodySingleTab.js.map +1 -1
  115. package/lib/components/Tabs/FormBodyTabList.d.ts +1 -0
  116. package/lib/components/Tabs/FormBodyTabList.js +3 -4
  117. package/lib/components/Tabs/FormBodyTabList.js.map +1 -1
  118. package/lib/components/Tabs/FormBodyTabListWrapper.d.ts +1 -1
  119. package/lib/components/Tabs/FormBodyTabListWrapper.js +6 -13
  120. package/lib/components/Tabs/FormBodyTabListWrapper.js.map +1 -1
  121. package/lib/components/Tabs/ShowCompletedTabsSection.d.ts +7 -0
  122. package/lib/components/Tabs/ShowCompletedTabsSection.js +34 -0
  123. package/lib/components/Tabs/ShowCompletedTabsSection.js.map +1 -0
  124. package/lib/hooks/useContextDisplayItems.d.ts +6 -0
  125. package/lib/hooks/useContextDisplayItems.js +30 -0
  126. package/lib/hooks/useContextDisplayItems.js.map +1 -0
  127. package/lib/hooks/useInitialiseRenderer.js +2 -2
  128. package/lib/hooks/useInitialiseRenderer.js.map +1 -1
  129. package/lib/hooks/useInitialiseRepeatGroups.d.ts +1 -1
  130. package/lib/hooks/useNumberInput.d.ts +1 -1
  131. package/lib/hooks/useNumberInput.js.map +1 -1
  132. package/lib/hooks/useStringInput.d.ts +1 -1
  133. package/lib/hooks/useStringInput.js.map +1 -1
  134. package/lib/hooks/useTerminologyServerQuery.js +3 -6
  135. package/lib/hooks/useTerminologyServerQuery.js.map +1 -1
  136. package/lib/index.js +2 -2
  137. package/lib/index.js.map +1 -1
  138. package/lib/interfaces/renderProps.interface.d.ts +3 -0
  139. package/lib/stores/useQuestionnaireResponseStore.d.ts +2 -1
  140. package/lib/stores/useQuestionnaireResponseStore.js +5 -3
  141. package/lib/stores/useQuestionnaireResponseStore.js.map +1 -1
  142. package/lib/utils/qrItem.d.ts +2 -3
  143. package/lib/utils/qrItem.js +2 -3
  144. package/lib/utils/qrItem.js.map +1 -1
  145. package/lib/utils/repopulateIntoResponse.d.ts +2 -2
  146. package/lib/utils/repopulateItems.js +0 -1
  147. package/lib/utils/repopulateItems.js.map +1 -1
  148. package/package.json +7 -7
  149. package/src/components/FormComponents/ChoiceItems/ChoiceAutocompleteItem.tsx +0 -1
  150. package/src/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionFields.tsx +85 -0
  151. package/src/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionItem.tsx +35 -58
  152. package/src/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetFields.tsx +79 -0
  153. package/src/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetItem.tsx +37 -50
  154. package/src/components/FormComponents/ChoiceItems/ChoiceItemSwitcher.tsx +10 -5
  155. package/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionFields.tsx +48 -0
  156. package/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionItem.tsx +25 -53
  157. package/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetFields.tsx +83 -0
  158. package/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetItem.tsx +27 -49
  159. package/src/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionFields.tsx +81 -0
  160. package/src/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionItem.tsx +19 -54
  161. package/src/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetFields.tsx +97 -0
  162. package/src/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetItem.tsx +22 -60
  163. package/src/components/FormComponents/GroupItem/GroupItemSwitcher.tsx +4 -4
  164. package/src/components/FormComponents/Item.styles.ts +2 -2
  165. package/src/components/FormComponents/ItemParts/RadioAnswerOptionButtons.tsx +72 -0
  166. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteField.tsx +131 -0
  167. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteItem.tsx +38 -93
  168. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionFields.tsx +112 -0
  169. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceCheckboxAnswerOptionItem.tsx +57 -76
  170. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceItemSwitcher.tsx +8 -5
  171. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionFields.tsx +72 -0
  172. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceRadioAnswerOptionItem.tsx +12 -59
  173. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionField.tsx +54 -0
  174. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionItem.tsx +40 -64
  175. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetField.tsx +63 -0
  176. package/src/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetItem.tsx +22 -50
  177. package/src/components/FormComponents/SingleItem/SingleItem.tsx +6 -3
  178. package/src/components/FormComponents/SingleItem/SingleItemSwitcher.tsx +7 -3
  179. package/src/components/FormComponents/Tables/AddRowButton.tsx +49 -0
  180. package/src/components/FormComponents/Tables/{QItemGroupTable.tsx → GroupTable.tsx} +6 -17
  181. package/src/components/FormComponents/Tables/{QItemGroupTableRow.tsx → GroupTableRow.tsx} +2 -2
  182. package/src/components/FormComponents/Tables/index.ts +1 -1
  183. package/src/components/Renderer/FormBodyTabbed.tsx +1 -1
  184. package/src/components/Tabs/FormBodySingleTab.tsx +1 -1
  185. package/src/components/Tabs/FormBodyTabList.tsx +5 -8
  186. package/src/components/Tabs/FormBodyTabListWrapper.tsx +15 -26
  187. package/src/components/Tabs/ShowCompletedTabsSection.tsx +52 -0
  188. package/src/hooks/useContextDisplayItems.ts +40 -0
  189. package/src/hooks/useInitialiseRenderer.ts +2 -2
  190. package/src/hooks/useInitialiseRepeatGroups.ts +1 -1
  191. package/src/hooks/useNumberInput.ts +2 -1
  192. package/src/hooks/useStringInput.ts +2 -1
  193. package/src/hooks/useTerminologyServerQuery.ts +3 -6
  194. package/src/index.ts +2 -2
  195. package/src/interfaces/renderProps.interface.ts +4 -0
  196. package/src/stores/useQuestionnaireResponseStore.ts +5 -4
  197. package/src/utils/qrItem.ts +4 -3
  198. package/src/utils/repopulateIntoResponse.ts +2 -2
  199. package/src/utils/repopulateItems.ts +0 -1
@@ -15,18 +15,14 @@
15
15
  * limitations under the License.
16
16
  */
17
17
 
18
- import type { SyntheticEvent } from 'react';
19
18
  import React from 'react';
20
- import Autocomplete from '@mui/material/Autocomplete';
21
19
  import Grid from '@mui/material/Grid';
22
20
  import type {
23
21
  QuestionnaireItem,
24
22
  QuestionnaireItemAnswerOption,
25
23
  QuestionnaireResponseItem
26
24
  } from 'fhir/r4';
27
- import { getAnswerOptionLabel } from '../../../utils/openChoice';
28
25
  import { createEmptyQrItem } from '../../../utils/qrItem';
29
- import { StandardTextField } from '../Textfield.styles';
30
26
  import { FullWidthFormComponentBox } from '../../Box.styles';
31
27
  import useRenderingExtensions from '../../../hooks/useRenderingExtensions';
32
28
  import type {
@@ -36,6 +32,7 @@ import type {
36
32
  } from '../../../interfaces/renderProps.interface';
37
33
  import DisplayInstructions from '../DisplayItem/DisplayInstructions';
38
34
  import LabelWrapper from '../ItemParts/ItemLabelWrapper';
35
+ import OpenChoiceSelectAnswerOptionField from './OpenChoiceSelectAnswerOptionField';
39
36
 
40
37
  interface OpenChoiceSelectAnswerOptionItemProps
41
38
  extends PropsWithQrItemChangeHandler<QuestionnaireResponseItem>,
@@ -49,88 +46,61 @@ function OpenChoiceSelectAnswerOptionItem(props: OpenChoiceSelectAnswerOptionIte
49
46
  const { qItem, qrItem, isRepeated, isTabled, onQrItemChange } = props;
50
47
 
51
48
  // Get additional rendering extensions
52
- const { displayUnit, displayPrompt, displayInstructions, readOnly, entryFormat } =
53
- useRenderingExtensions(qItem);
49
+ const { displayInstructions } = useRenderingExtensions(qItem);
54
50
 
55
51
  // Init input value
56
52
  const answerOptions = qItem.answerOption;
57
53
  if (!answerOptions) return null;
58
54
 
59
55
  const qrOpenChoice = qrItem ?? createEmptyQrItem(qItem);
60
- let valueSelect: QuestionnaireItemAnswerOption | undefined = undefined;
56
+ let valueSelect: QuestionnaireItemAnswerOption | null = null;
61
57
  if (qrOpenChoice.answer) {
62
- valueSelect = qrOpenChoice.answer[0];
58
+ valueSelect = qrOpenChoice.answer[0] ?? null;
63
59
  }
64
60
 
65
61
  // Event handlers
66
- function handleChange(
67
- _: SyntheticEvent<Element, Event>,
68
- newValue: QuestionnaireItemAnswerOption | string | null
69
- ) {
62
+ function handleChange(newValue: QuestionnaireItemAnswerOption | string | null) {
70
63
  if (newValue) {
71
64
  if (typeof newValue === 'string') {
72
65
  onQrItemChange({
73
66
  ...qrOpenChoice,
74
67
  answer: [{ valueString: newValue }]
75
68
  });
76
- } else {
77
- const option = newValue;
78
- if (option['valueCoding']) {
79
- onQrItemChange({
80
- ...qrOpenChoice,
81
- answer: [{ valueCoding: option.valueCoding }]
82
- });
83
- } else if (option['valueString']) {
84
- onQrItemChange({
85
- ...qrOpenChoice,
86
- answer: [{ valueString: option.valueString }]
87
- });
88
- } else if (option['valueInteger']) {
89
- onQrItemChange({
90
- ...qrOpenChoice,
91
- answer: [{ valueInteger: option.valueInteger }]
92
- });
93
- }
69
+ return;
70
+ }
71
+
72
+ const option = newValue;
73
+ if (option['valueCoding']) {
74
+ onQrItemChange({
75
+ ...qrOpenChoice,
76
+ answer: [{ valueCoding: option.valueCoding }]
77
+ });
78
+ } else if (option['valueString']) {
79
+ onQrItemChange({
80
+ ...qrOpenChoice,
81
+ answer: [{ valueString: option.valueString }]
82
+ });
83
+ } else if (option['valueInteger']) {
84
+ onQrItemChange({
85
+ ...qrOpenChoice,
86
+ answer: [{ valueInteger: option.valueInteger }]
87
+ });
94
88
  }
95
89
  return;
96
90
  }
97
91
  onQrItemChange(createEmptyQrItem(qItem));
98
92
  }
99
93
 
100
- const openOpenChoiceSelectAnswerOption = (
101
- <Autocomplete
102
- id={qItem.id}
103
- value={valueSelect ?? null}
104
- options={answerOptions}
105
- getOptionLabel={(option) => getAnswerOptionLabel(option)}
106
- onChange={handleChange}
107
- freeSolo
108
- autoHighlight
109
- sx={{ maxWidth: !isTabled ? 280 : 3000, minWidth: 160, flexGrow: 1 }}
110
- disabled={readOnly}
111
- size="small"
112
- placeholder={entryFormat}
113
- renderInput={(params) => (
114
- <StandardTextField
115
- isTabled={isTabled}
116
- label={displayPrompt}
117
- {...params}
118
- InputProps={{
119
- ...params.InputProps,
120
- endAdornment: (
121
- <>
122
- {params.InputProps.endAdornment}
123
- {displayUnit}
124
- </>
125
- )
126
- }}
127
- />
128
- )}
129
- />
130
- );
131
-
132
94
  if (isRepeated) {
133
- return <>{openOpenChoiceSelectAnswerOption}</>;
95
+ return (
96
+ <OpenChoiceSelectAnswerOptionField
97
+ qItem={qItem}
98
+ options={answerOptions}
99
+ valueSelect={valueSelect}
100
+ isTabled={isTabled}
101
+ onChange={handleChange}
102
+ />
103
+ );
134
104
  }
135
105
 
136
106
  return (
@@ -140,7 +110,13 @@ function OpenChoiceSelectAnswerOptionItem(props: OpenChoiceSelectAnswerOptionIte
140
110
  <LabelWrapper qItem={qItem} />
141
111
  </Grid>
142
112
  <Grid item xs={7}>
143
- {openOpenChoiceSelectAnswerOption}
113
+ <OpenChoiceSelectAnswerOptionField
114
+ qItem={qItem}
115
+ options={answerOptions}
116
+ valueSelect={valueSelect}
117
+ isTabled={isTabled}
118
+ onChange={handleChange}
119
+ />
144
120
  <DisplayInstructions displayInstructions={displayInstructions} />
145
121
  </Grid>
146
122
  </Grid>
@@ -0,0 +1,63 @@
1
+ import React from 'react';
2
+ import Autocomplete from '@mui/material/Autocomplete';
3
+ import { StandardTextField } from '../Textfield.styles';
4
+ import Typography from '@mui/material/Typography';
5
+ import type { PropsWithIsTabledAttribute } from '../../../interfaces/renderProps.interface';
6
+ import type { Coding, QuestionnaireItem } from 'fhir/r4';
7
+ import useRenderingExtensions from '../../../hooks/useRenderingExtensions';
8
+
9
+ interface OpenChoiceSelectAnswerValueSetFieldProps extends PropsWithIsTabledAttribute {
10
+ qItem: QuestionnaireItem;
11
+ options: Coding[];
12
+ valueSelect: Coding | null;
13
+ serverError: Error | null;
14
+ onValueChange: (newValue: Coding | string | null) => void;
15
+ }
16
+
17
+ function OpenChoiceSelectAnswerValueSetField(props: OpenChoiceSelectAnswerValueSetFieldProps) {
18
+ const { qItem, options, valueSelect, serverError, isTabled, onValueChange } = props;
19
+
20
+ const { displayUnit, displayPrompt, readOnly, entryFormat } = useRenderingExtensions(qItem);
21
+
22
+ return (
23
+ <>
24
+ <Autocomplete
25
+ id={qItem.id}
26
+ value={valueSelect ?? null}
27
+ options={options}
28
+ getOptionLabel={(option) => (typeof option === 'string' ? option : `${option.display}`)}
29
+ onChange={(_, newValue) => onValueChange(newValue)}
30
+ onInputChange={(_, newValue) => onValueChange(newValue)}
31
+ freeSolo
32
+ autoHighlight
33
+ sx={{ maxWidth: !isTabled ? 280 : 3000, minWidth: 160, flexGrow: 1 }}
34
+ disabled={readOnly}
35
+ size="small"
36
+ placeholder={entryFormat}
37
+ renderInput={(params) => (
38
+ <StandardTextField
39
+ isTabled={isTabled}
40
+ label={displayPrompt}
41
+ {...params}
42
+ InputProps={{
43
+ ...params.InputProps,
44
+ endAdornment: (
45
+ <>
46
+ {params.InputProps.endAdornment}
47
+ {displayUnit}
48
+ </>
49
+ )
50
+ }}
51
+ />
52
+ )}
53
+ />
54
+ {serverError ? (
55
+ <Typography variant="subtitle2">
56
+ There was an error fetching options from the terminology server.
57
+ </Typography>
58
+ ) : null}
59
+ </>
60
+ );
61
+ }
62
+
63
+ export default OpenChoiceSelectAnswerValueSetField;
@@ -15,14 +15,10 @@
15
15
  * limitations under the License.
16
16
  */
17
17
 
18
- import type { SyntheticEvent } from 'react';
19
18
  import React from 'react';
20
- import Autocomplete from '@mui/material/Autocomplete';
21
19
  import Grid from '@mui/material/Grid';
22
- import Typography from '@mui/material/Typography';
23
20
  import type { Coding, QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
24
21
  import { createEmptyQrItem } from '../../../utils/qrItem';
25
- import { StandardTextField } from '../Textfield.styles';
26
22
  import { FullWidthFormComponentBox } from '../../Box.styles';
27
23
  import useValueSetCodings from '../../../hooks/useValueSetCodings';
28
24
  import useRenderingExtensions from '../../../hooks/useRenderingExtensions';
@@ -33,6 +29,7 @@ import type {
33
29
  } from '../../../interfaces/renderProps.interface';
34
30
  import DisplayInstructions from '../DisplayItem/DisplayInstructions';
35
31
  import LabelWrapper from '../ItemParts/ItemLabelWrapper';
32
+ import OpenChoiceSelectAnswerValueSetField from './OpenChoiceSelectAnswerValueSetField';
36
33
 
37
34
  interface OpenChoiceSelectAnswerValueSetItemProps
38
35
  extends PropsWithQrItemChangeHandler<QuestionnaireResponseItem>,
@@ -47,20 +44,19 @@ function OpenChoiceSelectAnswerValueSetItem(props: OpenChoiceSelectAnswerValueSe
47
44
 
48
45
  // Init input value
49
46
  const qrOpenChoice = qrItem ?? createEmptyQrItem(qItem);
50
- let valueSelect: Coding | undefined = undefined;
47
+ let valueSelect: Coding | null = null;
51
48
  if (qrOpenChoice['answer']) {
52
- valueSelect = qrOpenChoice['answer'][0].valueCoding;
49
+ valueSelect = qrOpenChoice['answer'][0].valueCoding ?? null;
53
50
  }
54
51
 
55
52
  // Get codings/options from valueSet
56
53
  const { codings, serverError } = useValueSetCodings(qItem);
57
54
 
58
55
  // Get additional rendering extensions
59
- const { displayUnit, displayPrompt, displayInstructions, readOnly, entryFormat } =
60
- useRenderingExtensions(qItem);
56
+ const { displayInstructions } = useRenderingExtensions(qItem);
61
57
 
62
58
  // Event handlers
63
- function handleValueChange(_: SyntheticEvent<Element, Event>, newValue: Coding | string | null) {
59
+ function handleValueChange(newValue: Coding | string | null) {
64
60
  if (newValue) {
65
61
  if (typeof newValue === 'string') {
66
62
  onQrItemChange({
@@ -78,48 +74,17 @@ function OpenChoiceSelectAnswerValueSetItem(props: OpenChoiceSelectAnswerValueSe
78
74
  onQrItemChange(createEmptyQrItem(qItem));
79
75
  }
80
76
 
81
- const openChoiceSelectAnswerValueSet = (
82
- <>
83
- <Autocomplete
84
- id={qItem.id}
85
- value={valueSelect ?? null}
77
+ if (isRepeated) {
78
+ return (
79
+ <OpenChoiceSelectAnswerValueSetField
80
+ qItem={qItem}
86
81
  options={codings}
87
- getOptionLabel={(option) => (typeof option === 'string' ? option : `${option.display}`)}
88
- onChange={handleValueChange}
89
- onInputChange={(event, newValue) => handleValueChange(event, newValue)}
90
- freeSolo
91
- autoHighlight
92
- sx={{ maxWidth: !isTabled ? 280 : 3000, minWidth: 160, flexGrow: 1 }}
93
- disabled={readOnly}
94
- size="small"
95
- placeholder={entryFormat}
96
- renderInput={(params) => (
97
- <StandardTextField
98
- isTabled={isTabled}
99
- label={displayPrompt}
100
- {...params}
101
- InputProps={{
102
- ...params.InputProps,
103
- endAdornment: (
104
- <>
105
- {params.InputProps.endAdornment}
106
- {displayUnit}
107
- </>
108
- )
109
- }}
110
- />
111
- )}
82
+ valueSelect={valueSelect}
83
+ serverError={serverError}
84
+ isTabled={isTabled}
85
+ onValueChange={handleValueChange}
112
86
  />
113
- {serverError ? (
114
- <Typography variant="subtitle2">
115
- There was an error fetching options from the terminology server.
116
- </Typography>
117
- ) : null}
118
- </>
119
- );
120
-
121
- if (isRepeated) {
122
- return <>{openChoiceSelectAnswerValueSet}</>;
87
+ );
123
88
  }
124
89
 
125
90
  return (
@@ -129,7 +94,14 @@ function OpenChoiceSelectAnswerValueSetItem(props: OpenChoiceSelectAnswerValueSe
129
94
  <LabelWrapper qItem={qItem} />
130
95
  </Grid>
131
96
  <Grid item xs={7}>
132
- {openChoiceSelectAnswerValueSet}
97
+ <OpenChoiceSelectAnswerValueSetField
98
+ qItem={qItem}
99
+ options={codings}
100
+ valueSelect={valueSelect}
101
+ serverError={serverError}
102
+ isTabled={isTabled}
103
+ onValueChange={handleValueChange}
104
+ />
133
105
  <DisplayInstructions displayInstructions={displayInstructions} />
134
106
  </Grid>
135
107
  </Grid>
@@ -20,7 +20,8 @@ import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
20
20
  import type {
21
21
  PropsWithIsRepeatedAttribute,
22
22
  PropsWithIsTabledAttribute,
23
- PropsWithQrItemChangeHandler
23
+ PropsWithQrItemChangeHandler,
24
+ PropsWithTextShownAttribute
24
25
  } from '../../../interfaces/renderProps.interface';
25
26
  import useQuestionnaireStore from '../../../stores/useQuestionnaireStore';
26
27
  import SingleItemSwitcher from './SingleItemSwitcher';
@@ -29,13 +30,14 @@ import useHidden from '../../../hooks/useHidden';
29
30
  interface SingleItemProps
30
31
  extends PropsWithQrItemChangeHandler<QuestionnaireResponseItem>,
31
32
  PropsWithIsRepeatedAttribute,
32
- PropsWithIsTabledAttribute {
33
+ PropsWithIsTabledAttribute,
34
+ PropsWithTextShownAttribute {
33
35
  qItem: QuestionnaireItem;
34
36
  qrItem: QuestionnaireResponseItem;
35
37
  }
36
38
 
37
39
  function SingleItem(props: SingleItemProps) {
38
- const { qItem, qrItem, isRepeated, isTabled, onQrItemChange } = props;
40
+ const { qItem, qrItem, isRepeated, isTabled, textShown, onQrItemChange } = props;
39
41
 
40
42
  const updateEnableWhenItem = useQuestionnaireStore((state) => state.updateEnableWhenItem);
41
43
 
@@ -60,6 +62,7 @@ function SingleItem(props: SingleItemProps) {
60
62
  qrItem={qrItem}
61
63
  isRepeated={isRepeated}
62
64
  isTabled={isTabled}
65
+ textShown={textShown}
63
66
  onQrItemChange={handleQrItemChange}
64
67
  />
65
68
  );
@@ -23,7 +23,8 @@ import Typography from '@mui/material/Typography';
23
23
  import type {
24
24
  PropsWithIsRepeatedAttribute,
25
25
  PropsWithIsTabledAttribute,
26
- PropsWithQrItemChangeHandler
26
+ PropsWithQrItemChangeHandler,
27
+ PropsWithTextShownAttribute
27
28
  } from '../../../interfaces/renderProps.interface';
28
29
  import StringItem from '../StringItem/StringItem';
29
30
  import BooleanItem from '../BooleanItem/BooleanItem';
@@ -39,13 +40,14 @@ import UrlItem from '../UrlItem/UrlItem';
39
40
  interface SingleItemSwitcherProps
40
41
  extends PropsWithQrItemChangeHandler<QuestionnaireResponseItem>,
41
42
  PropsWithIsRepeatedAttribute,
42
- PropsWithIsTabledAttribute {
43
+ PropsWithIsTabledAttribute,
44
+ PropsWithTextShownAttribute {
43
45
  qItem: QuestionnaireItem;
44
46
  qrItem: QuestionnaireResponseItem;
45
47
  }
46
48
 
47
49
  function SingleItemSwitcher(props: SingleItemSwitcherProps) {
48
- const { qItem, qrItem, isRepeated, isTabled, onQrItemChange } = props;
50
+ const { qItem, qrItem, isRepeated, isTabled, textShown, onQrItemChange } = props;
49
51
 
50
52
  switch (qItem.type) {
51
53
  case 'string':
@@ -136,6 +138,7 @@ function SingleItemSwitcher(props: SingleItemSwitcherProps) {
136
138
  qrItem={qrItem}
137
139
  isRepeated={isRepeated}
138
140
  isTabled={isTabled}
141
+ textShown={textShown}
139
142
  onQrItemChange={onQrItemChange}
140
143
  />
141
144
  );
@@ -146,6 +149,7 @@ function SingleItemSwitcher(props: SingleItemSwitcherProps) {
146
149
  qrItem={qrItem}
147
150
  isRepeated={isRepeated}
148
151
  isTabled={isTabled}
152
+ textShown={textShown}
149
153
  onQrItemChange={onQrItemChange}
150
154
  />
151
155
  );
@@ -0,0 +1,49 @@
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
+ import React from 'react';
19
+ import Box from '@mui/material/Box';
20
+ import Button from '@mui/material/Button';
21
+ import AddIcon from '@mui/icons-material/Add';
22
+ import type { RepeatGroupSingle } from '../../../interfaces/repeatGroup.interface';
23
+
24
+ interface AddItemButtonProps {
25
+ repeatGroups: RepeatGroupSingle[];
26
+ onAddItem: () => void;
27
+ }
28
+
29
+ function AddRowButton(props: AddItemButtonProps) {
30
+ const { repeatGroups, onAddItem } = props;
31
+
32
+ const isDisabled = repeatGroups[repeatGroups.length - 1].qrItem === null;
33
+
34
+ return (
35
+ <Box display="flex" flexDirection="row-reverse">
36
+ <Button
37
+ variant="contained"
38
+ size="small"
39
+ startIcon={<AddIcon />}
40
+ disabled={isDisabled}
41
+ onClick={onAddItem}
42
+ data-test="button-add-repeat-item">
43
+ Add Row
44
+ </Button>
45
+ </Box>
46
+ );
47
+ }
48
+
49
+ export default AddRowButton;
@@ -18,10 +18,8 @@
18
18
  import React, { useMemo, useState } from 'react';
19
19
 
20
20
  import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
21
- import Button from '@mui/material/Button';
22
21
  import Divider from '@mui/material/Divider';
23
22
  import Paper from '@mui/material/Paper';
24
- import Stack from '@mui/material/Stack';
25
23
  import Table from '@mui/material/Table';
26
24
  import TableBody from '@mui/material/TableBody';
27
25
  import TableCell from '@mui/material/TableCell';
@@ -29,9 +27,7 @@ import TableContainer from '@mui/material/TableContainer';
29
27
  import TableHead from '@mui/material/TableHead';
30
28
  import TableRow from '@mui/material/TableRow';
31
29
  import Typography from '@mui/material/Typography';
32
-
33
- import AddIcon from '@mui/icons-material/Add';
34
- import QItemGroupTableRow from './QItemGroupTableRow';
30
+ import GroupTableRow from './GroupTableRow';
35
31
  import { HeaderTableCell } from './Table.styles';
36
32
  import { QGroupContainerBox } from '../../Box.styles';
37
33
  import { mapQItemsIndex } from '../../../utils/mapItem';
@@ -42,6 +38,7 @@ import { createEmptyQrItem } from '../../../utils/qrItem';
42
38
  import DeleteRowButton from './DeleteRowButton';
43
39
  import LabelWrapper from '../ItemParts/ItemLabelWrapper';
44
40
  import cloneDeep from 'lodash.clonedeep';
41
+ import AddRowButton from './AddRowButton';
45
42
 
46
43
  interface Props extends PropsWithQrRepeatGroupChangeHandler {
47
44
  qItem: QuestionnaireItem;
@@ -49,7 +46,7 @@ interface Props extends PropsWithQrRepeatGroupChangeHandler {
49
46
  groupCardElevation: number;
50
47
  }
51
48
 
52
- function QItemGroupTable(props: Props) {
49
+ function GroupTable(props: Props) {
53
50
  const { qItem, qrItems, groupCardElevation, onQrRepeatGroupChange } = props;
54
51
 
55
52
  const initialisedGroupTables = useInitialiseGroupTable(qrItems);
@@ -128,15 +125,7 @@ function QItemGroupTable(props: Props) {
128
125
  <TableContainer component={Paper} elevation={groupCardElevation}>
129
126
  <Table>
130
127
  <caption>
131
- <Stack direction="row" justifyContent="end">
132
- <Button
133
- variant="contained"
134
- size="small"
135
- startIcon={<AddIcon />}
136
- onClick={handleAddRow}>
137
- Add Row
138
- </Button>
139
- </Stack>
128
+ <AddRowButton repeatGroups={tableRows} onAddItem={handleAddRow} />
140
129
  </caption>
141
130
  <TableHead>
142
131
  <TableRow>
@@ -155,7 +144,7 @@ function QItemGroupTable(props: Props) {
155
144
 
156
145
  return (
157
146
  <TableRow key={nanoId}>
158
- <QItemGroupTableRow
147
+ <GroupTableRow
159
148
  qItem={qItem}
160
149
  qrItem={answeredQrItem}
161
150
  qItemsIndexMap={qItemsIndexMap}
@@ -176,4 +165,4 @@ function QItemGroupTable(props: Props) {
176
165
  );
177
166
  }
178
167
 
179
- export default QItemGroupTable;
168
+ export default GroupTable;
@@ -29,7 +29,7 @@ interface Props extends PropsWithQrItemChangeHandler<QuestionnaireResponseItem>
29
29
  qItemsIndexMap: Record<string, number>;
30
30
  }
31
31
 
32
- function QItemGroupTableRow(props: Props) {
32
+ function GroupTableRow(props: Props) {
33
33
  const { qItem, qrItem, qItemsIndexMap, onQrItemChange } = props;
34
34
 
35
35
  const rowItems = qItem.item;
@@ -74,4 +74,4 @@ function QItemGroupTableRow(props: Props) {
74
74
  );
75
75
  }
76
76
 
77
- export default QItemGroupTableRow;
77
+ export default GroupTableRow;
@@ -15,4 +15,4 @@
15
15
  * limitations under the License.
16
16
  */
17
17
 
18
- export { default as GroupTable } from './QItemGroupTable';
18
+ export { default as GroupTable } from './GroupTable';
@@ -61,7 +61,7 @@ function FormBodyTabbed(props: FormBodyTabbedProps) {
61
61
  <Grid container spacing={2}>
62
62
  <TabContext value={currentTab.toString()}>
63
63
  <Grid item xs={12} md={3.5} lg={3} xl={2.75}>
64
- <FormBodyTabListWrapper qFormItems={qItems} currentTabIndex={currentTab} tabs={tabs} />
64
+ <FormBodyTabListWrapper topLevelItems={qItems} currentTabIndex={currentTab} tabs={tabs} />
65
65
  </Grid>
66
66
 
67
67
  <Grid item xs={12} md={8.5} lg={9} xl={9.25}>
@@ -46,7 +46,7 @@ const FormBodySingleTab = memo(function FormBodySingleTab(props: FormBodySingleT
46
46
  <>
47
47
  <ListItemButton
48
48
  selected={selected}
49
- sx={{ my: 0.2, minHeight: '36px' }}
49
+ sx={{ my: 0.15, minHeight: '36px' }}
50
50
  onClick={handleTabClick}>
51
51
  <ListItemText
52
52
  primary={
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
 
18
- import React, { memo, useMemo } from 'react';
18
+ import React, { memo } from 'react';
19
19
  import Collapse from '@mui/material/Collapse';
20
20
  import { TransitionGroup } from 'react-transition-group';
21
21
  import { getShortText } from '../../utils/itemControl';
@@ -23,27 +23,24 @@ import type { QuestionnaireItem } from 'fhir/r4';
23
23
  import FormBodySingleTab from './FormBodySingleTab';
24
24
  import type { Tabs } from '../../interfaces/tab.interface';
25
25
  import useQuestionnaireStore from '../../stores/useQuestionnaireStore';
26
- import { getContextDisplays, isTabHidden } from '../../utils/tabs';
26
+ import { isTabHidden } from '../../utils/tabs';
27
27
 
28
28
  interface FormBodyTabListProps {
29
29
  topLevelItems: QuestionnaireItem[];
30
30
  currentTabIndex: number;
31
31
  tabs: Tabs;
32
32
  completedTabsCollapsed: boolean;
33
+ allContextDisplayItems: QuestionnaireItem[][];
33
34
  }
34
35
 
35
36
  const FormBodyTabList = memo(function FormBodyTabList(props: FormBodyTabListProps) {
36
- const { topLevelItems, currentTabIndex, tabs, completedTabsCollapsed } = props;
37
+ const { topLevelItems, currentTabIndex, tabs, completedTabsCollapsed, allContextDisplayItems } =
38
+ props;
37
39
 
38
40
  const enableWhenIsActivated = useQuestionnaireStore((state) => state.enableWhenIsActivated);
39
41
  const enableWhenItems = useQuestionnaireStore((state) => state.enableWhenItems);
40
42
  const enableWhenExpressions = useQuestionnaireStore((state) => state.enableWhenExpressions);
41
43
 
42
- const allContextDisplayItems = useMemo(
43
- () => topLevelItems.map((topLevelItem) => getContextDisplays(topLevelItem)),
44
- [topLevelItems]
45
- );
46
-
47
44
  return (
48
45
  <TransitionGroup>
49
46
  {topLevelItems.map((qItem, i) => {