@aehrc/smart-forms-renderer 0.9.2 → 0.10.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 (156) hide show
  1. package/.swcrc +11 -0
  2. package/lib/components/FormComponents/GroupItem/NextTabButtonWrapper.js +5 -5
  3. package/lib/components/FormComponents/GroupItem/NextTabButtonWrapper.js.map +1 -1
  4. package/lib/components/FormComponents/RepeatGroup/DeleteItemButton.js +1 -1
  5. package/lib/components/FormComponents/RepeatItem/RemoveItemButton.d.ts +10 -0
  6. package/lib/components/FormComponents/RepeatItem/RemoveItemButton.js +30 -0
  7. package/lib/components/FormComponents/RepeatItem/RemoveItemButton.js.map +1 -0
  8. package/lib/components/FormComponents/RepeatItem/RepeatField.js +2 -2
  9. package/lib/components/FormComponents/SingleItem/SingleItem.js +2 -2
  10. package/lib/components/FormComponents/SingleItem/SingleItem.js.map +1 -1
  11. package/lib/components/FormComponents/Tables/GroupTable.d.ts +1 -2
  12. package/lib/components/FormComponents/Tables/GroupTable.js +44 -59
  13. package/lib/components/FormComponents/Tables/GroupTable.js.map +1 -1
  14. package/lib/components/FormComponents/Tables/GroupTableBody.d.ts +17 -0
  15. package/lib/components/FormComponents/Tables/GroupTableBody.js +48 -0
  16. package/lib/components/FormComponents/Tables/GroupTableBody.js.map +1 -0
  17. package/lib/components/FormComponents/Tables/GroupTableRow.d.ts +18 -5
  18. package/lib/components/FormComponents/Tables/GroupTableRow.js +17 -25
  19. package/lib/components/FormComponents/Tables/GroupTableRow.js.map +1 -1
  20. package/lib/components/FormComponents/Tables/GroupTableRowCells.d.ts +11 -0
  21. package/lib/components/FormComponents/Tables/GroupTableRowCells.js +57 -0
  22. package/lib/components/FormComponents/Tables/GroupTableRowCells.js.map +1 -0
  23. package/lib/components/FormComponents/Tables/GroupTableRows.d.ts +17 -0
  24. package/lib/components/FormComponents/Tables/GroupTableRows.js +45 -0
  25. package/lib/components/FormComponents/Tables/GroupTableRows.js.map +1 -0
  26. package/lib/components/FormComponents/Tables/GroupTableTestRow.d.ts +22 -0
  27. package/lib/components/FormComponents/Tables/GroupTableTestRow.js +43 -0
  28. package/lib/components/FormComponents/Tables/GroupTableTestRow.js.map +1 -0
  29. package/lib/components/FormComponents/Tables/GroupTableView.d.ts +21 -0
  30. package/lib/components/FormComponents/Tables/GroupTableView.js +65 -0
  31. package/lib/components/FormComponents/Tables/GroupTableView.js.map +1 -0
  32. package/lib/components/FormComponents/Tables/RemoveRowButton.d.ts +10 -0
  33. package/lib/components/FormComponents/Tables/RemoveRowButton.js +32 -0
  34. package/lib/components/FormComponents/Tables/RemoveRowButton.js.map +1 -0
  35. package/lib/components/FormComponents/Tables/SelectRowButton.d.ts +7 -0
  36. package/lib/components/FormComponents/Tables/SelectRowButton.js +26 -0
  37. package/lib/components/FormComponents/Tables/SelectRowButton.js.map +1 -0
  38. package/lib/components/FormComponents/Tables/Table.styles.d.ts +8 -0
  39. package/lib/components/FormComponents/Tables/Table.styles.js +17 -0
  40. package/lib/components/FormComponents/Tables/Table.styles.js.map +1 -1
  41. package/lib/components/Renderer/BaseRenderer.js +5 -6
  42. package/lib/components/Renderer/BaseRenderer.js.map +1 -1
  43. package/lib/components/Renderer/FormBodyCollapsible.js +4 -4
  44. package/lib/components/Renderer/FormBodyCollapsible.js.map +1 -1
  45. package/lib/components/Renderer/FormBodyTabbed.js +3 -3
  46. package/lib/components/Renderer/FormBodyTabbed.js.map +1 -1
  47. package/lib/components/Tabs/CompleteTabButton.js +2 -2
  48. package/lib/components/Tabs/CompleteTabButton.js.map +1 -1
  49. package/lib/components/Tabs/FormBodySingleTab.js +2 -2
  50. package/lib/components/Tabs/FormBodySingleTab.js.map +1 -1
  51. package/lib/components/Tabs/FormBodyTabList.js +4 -4
  52. package/lib/components/Tabs/FormBodyTabList.js.map +1 -1
  53. package/lib/hooks/useDecimalCalculatedExpression.js +2 -2
  54. package/lib/hooks/useDecimalCalculatedExpression.js.map +1 -1
  55. package/lib/hooks/useHidden.js +4 -4
  56. package/lib/hooks/useHidden.js.map +1 -1
  57. package/lib/hooks/useInitialiseGroupTable.d.ts +2 -2
  58. package/lib/hooks/useInitialiseGroupTable.js.map +1 -1
  59. package/lib/hooks/useInitialiseRenderer.js +11 -14
  60. package/lib/hooks/useInitialiseRenderer.js.map +1 -1
  61. package/lib/hooks/useIntegerCalculatedExpression.js +2 -2
  62. package/lib/hooks/useIntegerCalculatedExpression.js.map +1 -1
  63. package/lib/hooks/useMinimalStringCalculatedExpression.js +25 -13
  64. package/lib/hooks/useStringCalculatedExpression.js +2 -2
  65. package/lib/hooks/useStringCalculatedExpression.js.map +1 -1
  66. package/lib/hooks/useTerminologyServerQuery.js +3 -4
  67. package/lib/hooks/useTerminologyServerQuery.js.map +1 -1
  68. package/lib/hooks/useValueSetCodings.js +10 -12
  69. package/lib/hooks/useValueSetCodings.js.map +1 -1
  70. package/lib/index.js +19 -20
  71. package/lib/index.js.map +1 -1
  72. package/lib/interfaces/groupTable.interface.d.ts +1 -1
  73. package/lib/setup-jest.js +1 -0
  74. package/lib/setup-jest.js.map +1 -0
  75. package/lib/stores/index.d.ts +4 -3
  76. package/lib/stores/index.js +4 -3
  77. package/lib/stores/index.js.map +1 -1
  78. package/lib/stores/questionnaireResponseStore.d.ts +28 -0
  79. package/lib/stores/questionnaireResponseStore.js +64 -0
  80. package/lib/stores/questionnaireResponseStore.js.map +1 -0
  81. package/lib/stores/questionnaireStore.d.ts +65 -0
  82. package/lib/stores/questionnaireStore.js +172 -0
  83. package/lib/stores/questionnaireStore.js.map +1 -0
  84. package/lib/stores/smartConfigStore.d.ts +25 -0
  85. package/lib/stores/smartConfigStore.js +30 -0
  86. package/lib/stores/smartConfigStore.js.map +1 -0
  87. package/lib/stores/terminologyServerStore.d.ts +14 -0
  88. package/lib/stores/terminologyServerStore.js +26 -0
  89. package/lib/stores/terminologyServerStore.js.map +1 -0
  90. package/lib/stores/useQuestionnaireResponseStore.d.ts +14 -2
  91. package/lib/stores/useQuestionnaireResponseStore.js +4 -2
  92. package/lib/stores/useQuestionnaireResponseStore.js.map +1 -1
  93. package/lib/stores/useQuestionnaireStore.d.ts +30 -2
  94. package/lib/stores/useQuestionnaireStore.js +4 -2
  95. package/lib/stores/useQuestionnaireStore.js.map +1 -1
  96. package/lib/stories/MedicalHistoryTable.stories.js +49 -0
  97. package/lib/stories/MedicalHistoryTable.stories.js.map +1 -0
  98. package/lib/stories/SmartFormsRenderer.stories.js +103 -0
  99. package/lib/stories/SmartFormsRenderer.stories.js.map +1 -0
  100. package/lib/theme/overrides/Table.d.ts +1 -0
  101. package/lib/theme/overrides/Table.js +2 -1
  102. package/lib/theme/overrides/Table.js.map +1 -1
  103. package/lib/utils/calculatedExpression.js +1 -2
  104. package/lib/utils/calculatedExpression.js.map +1 -1
  105. package/lib/utils/groupTable.d.ts +3 -0
  106. package/lib/utils/groupTable.js +29 -0
  107. package/lib/utils/groupTable.js.map +1 -0
  108. package/package.json +10 -5
  109. package/src/components/FormComponents/GroupItem/NextTabButtonWrapper.tsx +5 -5
  110. package/src/components/FormComponents/RepeatGroup/DeleteItemButton.tsx +1 -1
  111. package/src/components/FormComponents/RepeatItem/{DeleteItemButton.tsx → RemoveItemButton.tsx} +4 -4
  112. package/src/components/FormComponents/RepeatItem/RepeatField.tsx +2 -2
  113. package/src/components/FormComponents/SingleItem/SingleItem.tsx +2 -2
  114. package/src/components/FormComponents/Tables/GroupTable.tsx +71 -120
  115. package/src/components/FormComponents/Tables/GroupTableBody.tsx +116 -0
  116. package/src/components/FormComponents/Tables/GroupTableRow.tsx +89 -49
  117. package/src/components/FormComponents/Tables/GroupTableRowCells.tsx +87 -0
  118. package/src/components/FormComponents/Tables/GroupTableView.tsx +169 -0
  119. package/src/components/FormComponents/Tables/{DeleteRowButton.tsx → RemoveRowButton.tsx} +7 -7
  120. package/src/components/FormComponents/Tables/SelectRowButton.tsx +37 -0
  121. package/src/components/FormComponents/Tables/Table.styles.tsx +25 -0
  122. package/src/components/Renderer/BaseRenderer.tsx +5 -6
  123. package/src/components/Renderer/FormBodyCollapsible.tsx +4 -5
  124. package/src/components/Renderer/FormBodyTabbed.tsx +3 -3
  125. package/src/components/Tabs/CompleteTabButton.tsx +2 -2
  126. package/src/components/Tabs/FormBodySingleTab.tsx +2 -3
  127. package/src/components/Tabs/FormBodyTabList.tsx +4 -4
  128. package/src/hooks/useDecimalCalculatedExpression.ts +2 -2
  129. package/src/hooks/useHidden.ts +4 -4
  130. package/src/hooks/useInitialiseGroupTable.ts +3 -3
  131. package/src/hooks/useInitialiseRenderer.ts +17 -18
  132. package/src/hooks/useIntegerCalculatedExpression.ts +2 -2
  133. package/src/hooks/useStringCalculatedExpression.ts +2 -2
  134. package/src/hooks/useTerminologyServerQuery.ts +3 -4
  135. package/src/hooks/useValueSetCodings.ts +10 -12
  136. package/src/index.ts +19 -20
  137. package/src/interfaces/groupTable.interface.ts +1 -1
  138. package/src/stores/index.ts +7 -3
  139. package/src/stores/questionnaireResponseStore.ts +83 -0
  140. package/src/stores/{useQuestionnaireStore.ts → questionnaireStore.ts} +7 -6
  141. package/src/stores/smartConfigStore.ts +45 -0
  142. package/src/stores/{useTerminologyServerStore.ts → terminologyServerStore.ts} +5 -4
  143. package/src/stories/MedicalHistoryTable.stories.tsx +61 -0
  144. package/src/stories/SmartFormsRenderer.stories.ts +15 -5
  145. package/src/stories/assets/QItems-and-QRItems/QR_GTableMedicalHistory.json +80 -0
  146. package/src/stories/assets/QItems-and-QRItems/Q_GTableMedicalHistory.json +109 -0
  147. package/src/stories/assets/Qs-and-QRs/QDev715.json +16081 -0
  148. package/src/theme/overrides/Table.ts +2 -1
  149. package/src/utils/calculatedExpression.ts +1 -2
  150. package/src/utils/groupTable.ts +37 -0
  151. package/src/stores/useQuestionnaireResponseStore.ts +0 -63
  152. package/src/stores/useSmartConfigStore.ts +0 -27
  153. /package/src/stories/assets/{Q715.json → Qs-and-QRs/Q715.json} +0 -0
  154. /package/src/stories/assets/{QTestGrid.json → Qs-and-QRs/QTestGrid.json} +0 -0
  155. /package/src/stories/assets/{R715.json → Qs-and-QRs/R715.json} +0 -0
  156. /package/src/stories/assets/{RTestGrid.json → Qs-and-QRs/RTestGrid.json} +0 -0
@@ -23,7 +23,8 @@ export default function Table(theme: Theme) {
23
23
  styleOverrides: {
24
24
  head: {
25
25
  color: theme.palette.text.secondary,
26
- backgroundColor: theme.palette.customBackground.neutral
26
+ backgroundColor: theme.palette.customBackground.neutral,
27
+ borderBottom: '1px solid #e5e7eb'
27
28
  }
28
29
  }
29
30
  }
@@ -34,7 +34,6 @@ import { getQrItemsIndex, mapQItemsIndex } from './mapItem';
34
34
  import { updateQrItemsInGroup } from './qrItem';
35
35
  import cloneDeep from 'lodash.clonedeep';
36
36
  import dayjs from 'dayjs';
37
- import moment from 'moment';
38
37
 
39
38
  interface EvaluateInitialCalculatedExpressionsParams {
40
39
  initialResponse: QuestionnaireResponse;
@@ -354,7 +353,7 @@ function parseValueToAnswer(qItem: QuestionnaireItem, value: any): Questionnaire
354
353
  export function checkIsDateTime(value: string): boolean {
355
354
  const acceptedFormats = ['YYYY', 'YYYY-MM', 'YYYY-MM-DD', 'YYYY-MM-DDTHH:mm:ssZ'];
356
355
  const formattedDate = dayjs(value).format();
357
- return moment(formattedDate, acceptedFormats, true).isValid();
356
+ return dayjs(formattedDate, acceptedFormats, true).isValid();
358
357
  }
359
358
 
360
359
  /**
@@ -0,0 +1,37 @@
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 { GroupTableRowModel } from '../interfaces/groupTable.interface';
19
+ import cloneDeep from 'lodash.clonedeep';
20
+
21
+ export function reorderRows(
22
+ rows: GroupTableRowModel[],
23
+ sourceIndex: number,
24
+ destinationIndex: number
25
+ ) {
26
+ const result = Array.from(rows);
27
+ const [removed] = result.splice(sourceIndex, 1);
28
+ result.splice(destinationIndex, 0, removed);
29
+
30
+ return result;
31
+ }
32
+
33
+ export function getGroupTableItemsToUpdate(tableRows: GroupTableRowModel[], selectedIds: string[]) {
34
+ return tableRows
35
+ .filter((row) => selectedIds.includes(row.nanoId))
36
+ .flatMap((singleRow) => (singleRow.qrItem ? [cloneDeep(singleRow.qrItem)] : []));
37
+ }
@@ -1,63 +0,0 @@
1
- import { create } from 'zustand';
2
- import type { QuestionnaireResponse } from 'fhir/r4';
3
- import { emptyResponse } from '../utils/emptyResource';
4
- import cloneDeep from 'lodash.clonedeep';
5
- import type { Diff } from 'deep-diff';
6
- import { diff } from 'deep-diff';
7
-
8
- export interface UseQuestionnaireResponseStoreType {
9
- sourceResponse: QuestionnaireResponse;
10
- updatableResponse: QuestionnaireResponse;
11
- formChangesHistory: (Diff<QuestionnaireResponse, QuestionnaireResponse>[] | null)[];
12
- buildSourceResponse: (response: QuestionnaireResponse) => void;
13
- setUpdatableResponseAsPopulated: (populatedResponse: QuestionnaireResponse) => void;
14
- updateResponse: (updatedResponse: QuestionnaireResponse) => void;
15
- setUpdatableResponseAsSaved: (savedResponse: QuestionnaireResponse) => void;
16
- setUpdatableResponseAsEmpty: (clearedResponse: QuestionnaireResponse) => void;
17
- destroySourceResponse: () => void;
18
- }
19
-
20
- const useQuestionnaireResponseStore = create<UseQuestionnaireResponseStoreType>()((set, get) => ({
21
- sourceResponse: cloneDeep(emptyResponse),
22
- updatableResponse: cloneDeep(emptyResponse),
23
- formChangesHistory: [],
24
- buildSourceResponse: (questionnaireResponse: QuestionnaireResponse) => {
25
- set(() => ({
26
- sourceResponse: questionnaireResponse,
27
- updatableResponse: questionnaireResponse
28
- }));
29
- },
30
- setUpdatableResponseAsPopulated: (populatedResponse: QuestionnaireResponse) => {
31
- const formChanges = diff(get().updatableResponse, populatedResponse) ?? null;
32
- set(() => ({
33
- updatableResponse: populatedResponse,
34
- formChangesHistory: [...get().formChangesHistory, formChanges]
35
- }));
36
- },
37
- updateResponse: (updatedResponse: QuestionnaireResponse) => {
38
- const formChanges = diff(get().updatableResponse, updatedResponse) ?? null;
39
- set(() => ({
40
- updatableResponse: updatedResponse,
41
- formChangesHistory: [...get().formChangesHistory, formChanges]
42
- }));
43
- },
44
- setUpdatableResponseAsSaved: (savedResponse: QuestionnaireResponse) =>
45
- set(() => ({
46
- sourceResponse: savedResponse,
47
- updatableResponse: savedResponse,
48
- formChangesHistory: []
49
- })),
50
- setUpdatableResponseAsEmpty: (clearedResponse: QuestionnaireResponse) =>
51
- set(() => ({
52
- updatableResponse: clearedResponse,
53
- formChangesHistory: []
54
- })),
55
- destroySourceResponse: () =>
56
- set(() => ({
57
- sourceResponse: cloneDeep(emptyResponse),
58
- updatableResponse: cloneDeep(emptyResponse),
59
- formChangesHistory: []
60
- }))
61
- }));
62
-
63
- export default useQuestionnaireResponseStore;
@@ -1,27 +0,0 @@
1
- import { create } from 'zustand';
2
- import type { Encounter, Patient, Practitioner } from 'fhir/r4';
3
- import type Client from 'fhirclient/lib/Client';
4
-
5
- export interface UseSmartConfigStoreType {
6
- client: Client | null;
7
- patient: Patient | null;
8
- user: Practitioner | null;
9
- encounter: Encounter | null;
10
- setClient: (client: Client) => void;
11
- setPatient: (patient: Patient) => void;
12
- setUser: (user: Practitioner) => void;
13
- setEncounter: (encounter: Encounter) => void;
14
- }
15
-
16
- const useSmartConfigStore = create<UseSmartConfigStoreType>()((set) => ({
17
- client: null,
18
- patient: null,
19
- user: null,
20
- encounter: null,
21
- setClient: (client: Client) => set(() => ({ client: client })),
22
- setPatient: (patient: Patient) => set(() => ({ patient: patient })),
23
- setUser: (user: Practitioner) => set(() => ({ user: user })),
24
- setEncounter: (encounter: Encounter) => set(() => ({ encounter: encounter }))
25
- }));
26
-
27
- export default useSmartConfigStore;