@aehrc/smart-forms-renderer 0.40.3 → 0.42.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 (126) hide show
  1. package/lib/components/FormComponents/AttachmentItem/AttachmentItem.js +2 -3
  2. package/lib/components/FormComponents/AttachmentItem/AttachmentItem.js.map +1 -1
  3. package/lib/components/FormComponents/DateTimeItems/CustomDateItem/CustomDateItem.js +1 -2
  4. package/lib/components/FormComponents/DateTimeItems/CustomDateItem/CustomDateItem.js.map +1 -1
  5. package/lib/components/FormComponents/DateTimeItems/CustomDateTimeItem/CustomDateTimeItem.js +3 -4
  6. package/lib/components/FormComponents/DateTimeItems/CustomDateTimeItem/CustomDateTimeItem.js.map +1 -1
  7. package/lib/components/FormComponents/DecimalItem/DecimalItem.js +2 -3
  8. package/lib/components/FormComponents/DecimalItem/DecimalItem.js.map +1 -1
  9. package/lib/components/FormComponents/IntegerItem/IntegerItem.js +2 -3
  10. package/lib/components/FormComponents/IntegerItem/IntegerItem.js.map +1 -1
  11. package/lib/components/FormComponents/QuantityItem/QuantityItem.js +1 -2
  12. package/lib/components/FormComponents/QuantityItem/QuantityItem.js.map +1 -1
  13. package/lib/components/FormComponents/RepeatGroup/AddItemButton.d.ts +2 -2
  14. package/lib/components/FormComponents/RepeatGroup/RepeatGroup.js +4 -6
  15. package/lib/components/FormComponents/RepeatGroup/RepeatGroup.js.map +1 -1
  16. package/lib/components/FormComponents/RepeatGroup/RepeatGroupView.d.ts +2 -2
  17. package/lib/components/FormComponents/StringItem/StringItem.js +2 -3
  18. package/lib/components/FormComponents/StringItem/StringItem.js.map +1 -1
  19. package/lib/components/FormComponents/Tables/AddRowButton.d.ts +2 -2
  20. package/lib/components/FormComponents/Tables/GroupTable.js +3 -1
  21. package/lib/components/FormComponents/Tables/GroupTable.js.map +1 -1
  22. package/lib/components/FormComponents/TextItem/TextItem.js +2 -3
  23. package/lib/components/FormComponents/TextItem/TextItem.js.map +1 -1
  24. package/lib/components/FormComponents/UrlItem/UrlItem.js +2 -3
  25. package/lib/components/FormComponents/UrlItem/UrlItem.js.map +1 -1
  26. package/lib/components/Renderer/BaseRenderer.js +7 -7
  27. package/lib/components/Renderer/BaseRenderer.js.map +1 -1
  28. package/lib/hooks/useGroupTableRows.d.ts +4 -4
  29. package/lib/hooks/useGroupTableRows.js +3 -5
  30. package/lib/hooks/useGroupTableRows.js.map +1 -1
  31. package/lib/hooks/useInitialiseGroupTableRows.d.ts +4 -0
  32. package/lib/hooks/{useNumberInput.js → useInitialiseGroupTableRows.js} +16 -13
  33. package/lib/hooks/useInitialiseGroupTableRows.js.map +1 -0
  34. package/lib/hooks/useInitialiseRepeatGroups.d.ts +2 -2
  35. package/lib/interfaces/repeatGroup.interface.d.ts +1 -1
  36. package/lib/stores/questionnaireResponseStore.d.ts +3 -0
  37. package/lib/stores/questionnaireResponseStore.js +10 -6
  38. package/lib/stores/questionnaireResponseStore.js.map +1 -1
  39. package/lib/stores/questionnaireStore.js +3 -4
  40. package/lib/stores/questionnaireStore.js.map +1 -1
  41. package/lib/stories/storybookWrappers/InitialiseFormWrapperForStorybook.d.ts +1 -0
  42. package/lib/stories/storybookWrappers/InitialiseFormWrapperForStorybook.js +1 -0
  43. package/lib/stories/storybookWrappers/InitialiseFormWrapperForStorybook.js.map +1 -1
  44. package/lib/tests/test-data/removeIdSample.d.ts +3 -0
  45. package/lib/tests/test-data/removeIdSample.js +99 -0
  46. package/lib/tests/test-data/removeIdSample.js.map +1 -0
  47. package/lib/theme/Theme.js +0 -2
  48. package/lib/theme/Theme.js.map +1 -1
  49. package/lib/utils/calculatedExpression.js +4 -5
  50. package/lib/utils/calculatedExpression.js.map +1 -1
  51. package/lib/utils/enableWhen.js +1 -2
  52. package/lib/utils/enableWhen.js.map +1 -1
  53. package/lib/utils/extractObservation.d.ts +1 -0
  54. package/lib/utils/extractObservation.js +1 -1
  55. package/lib/utils/extractObservation.js.map +1 -1
  56. package/lib/utils/groupTable.js +1 -2
  57. package/lib/utils/groupTable.js.map +1 -1
  58. package/lib/utils/initialise.js +0 -3
  59. package/lib/utils/initialise.js.map +1 -1
  60. package/lib/utils/manageForm.js +2 -3
  61. package/lib/utils/manageForm.js.map +1 -1
  62. package/lib/utils/openChoice.js +3 -3
  63. package/lib/utils/openChoice.js.map +1 -1
  64. package/lib/utils/questionnaireStoreUtils/extractOtherExtensions.js +1 -2
  65. package/lib/utils/questionnaireStoreUtils/extractOtherExtensions.js.map +1 -1
  66. package/lib/utils/removeEmptyAnswers.js +1 -2
  67. package/lib/utils/removeEmptyAnswers.js.map +1 -1
  68. package/lib/utils/repopulateItems.js +9 -10
  69. package/lib/utils/repopulateItems.js.map +1 -1
  70. package/package.json +8 -3
  71. package/src/components/FormComponents/AttachmentItem/AttachmentItem.tsx +2 -3
  72. package/src/components/FormComponents/DateTimeItems/CustomDateItem/CustomDateItem.tsx +1 -2
  73. package/src/components/FormComponents/DateTimeItems/CustomDateTimeItem/CustomDateTimeItem.tsx +3 -4
  74. package/src/components/FormComponents/DecimalItem/DecimalItem.tsx +2 -3
  75. package/src/components/FormComponents/IntegerItem/IntegerItem.tsx +2 -3
  76. package/src/components/FormComponents/QuantityItem/QuantityItem.tsx +1 -2
  77. package/src/components/FormComponents/RepeatGroup/AddItemButton.tsx +2 -2
  78. package/src/components/FormComponents/RepeatGroup/RepeatGroup.tsx +4 -6
  79. package/src/components/FormComponents/RepeatGroup/RepeatGroupView.tsx +2 -2
  80. package/src/components/FormComponents/StringItem/StringItem.tsx +2 -3
  81. package/src/components/FormComponents/Tables/AddRowButton.tsx +2 -2
  82. package/src/components/FormComponents/Tables/GroupTable.tsx +5 -5
  83. package/src/components/FormComponents/TextItem/TextItem.tsx +2 -3
  84. package/src/components/FormComponents/UrlItem/UrlItem.tsx +2 -3
  85. package/src/components/Renderer/BaseRenderer.tsx +7 -7
  86. package/src/hooks/useGroupTableRows.ts +4 -9
  87. package/src/hooks/{useInitialiseGroupTable.ts → useInitialiseGroupTableRows.ts} +15 -11
  88. package/src/hooks/useInitialiseRepeatGroups.ts +2 -2
  89. package/src/interfaces/repeatGroup.interface.ts +1 -1
  90. package/src/stores/questionnaireResponseStore.ts +12 -6
  91. package/src/stores/questionnaireStore.ts +3 -4
  92. package/src/stories/assets/questionnaires/QButtonTester.ts +117 -0
  93. package/src/stories/assets/questionnaires/QChoice.ts +1 -1
  94. package/src/stories/storybookWrappers/BuildFormButtonTesterWrapperForStorybook.tsx +1 -0
  95. package/src/stories/storybookWrappers/BuildFormWrapperForStorybook.tsx +1 -0
  96. package/src/stories/storybookWrappers/FormValidationTesterWrapperForStorybook.tsx +1 -0
  97. package/src/stories/storybookWrappers/IdRemoverButtonForStorybook.tsx +3 -5
  98. package/src/stories/storybookWrappers/IdRemoverDebuggerWrapperForStorybook.tsx +1 -0
  99. package/src/stories/storybookWrappers/InitialiseFormWrapperForStorybook.tsx +1 -0
  100. package/src/stories/storybookWrappers/PrePopWrapperForStorybook.tsx +7 -1
  101. package/{lib/hooks/useInitialiseGroupTable.js → src/tests/removeId.test.ts} +11 -14
  102. package/src/tests/test-data/removeIdSample.ts +101 -0
  103. package/src/theme/Theme.tsx +0 -2
  104. package/src/utils/calculatedExpression.ts +4 -5
  105. package/src/utils/enableWhen.ts +1 -2
  106. package/src/utils/extractObservation.ts +1 -1
  107. package/src/utils/groupTable.ts +1 -2
  108. package/src/utils/initialise.ts +0 -4
  109. package/src/utils/manageForm.ts +2 -3
  110. package/src/utils/openChoice.ts +3 -3
  111. package/src/utils/questionnaireStoreUtils/extractOtherExtensions.ts +1 -2
  112. package/src/utils/removeEmptyAnswers.ts +1 -2
  113. package/src/utils/repopulateItems.ts +9 -10
  114. package/lib/hooks/useInitialiseGroupTable.d.ts +0 -4
  115. package/lib/hooks/useInitialiseGroupTable.js.map +0 -1
  116. package/lib/hooks/useNumberInput.d.ts +0 -3
  117. package/lib/hooks/useNumberInput.js.map +0 -1
  118. package/lib/hooks/useRepeatGroups.d.ts +0 -4
  119. package/lib/hooks/useRepeatGroups.js +0 -38
  120. package/lib/hooks/useRepeatGroups.js.map +0 -1
  121. package/lib/hooks/useStringInput.d.ts +0 -3
  122. package/lib/hooks/useStringInput.js +0 -32
  123. package/lib/hooks/useStringInput.js.map +0 -1
  124. package/src/hooks/useNumberInput.ts +0 -38
  125. package/src/hooks/useRepeatGroups.ts +0 -51
  126. package/src/hooks/useStringInput.ts +0 -39
@@ -28,6 +28,7 @@ import { populateQuestionnaire } from '@aehrc/sdc-populate';
28
28
  import { fetchResourceCallback } from './populateCallbackForStorybook';
29
29
  import { buildForm } from '../../utils';
30
30
  import { STORYBOOK_TERMINOLOGY_SERVER_URL } from './globals';
31
+ import '@iframe-resizer/child';
31
32
 
32
33
  interface PrePopWrapperForStorybookProps {
33
34
  questionnaire: Questionnaire;
@@ -51,7 +52,12 @@ function PrePopWrapperForStorybook(props: PrePopWrapperForStorybookProps) {
51
52
 
52
53
  const [isPopulating, setIsPopulating] = useState(false);
53
54
 
54
- const isBuilding = useBuildForm(questionnaire);
55
+ const isBuilding = useBuildForm(
56
+ questionnaire,
57
+ undefined,
58
+ undefined,
59
+ STORYBOOK_TERMINOLOGY_SERVER_URL
60
+ );
55
61
 
56
62
  const queryClient = useRendererQueryClient();
57
63
 
@@ -14,17 +14,14 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { generateExistingRepeatId, generateNewRepeatId } from '../utils/repeatId';
18
- function useInitialiseGroupTable(linkId, qrItems) {
19
- if (qrItems.length === 0) {
20
- return [{ id: generateNewRepeatId(linkId), qrItem: null }];
21
- }
22
- return qrItems.map((qrItem, index) => {
23
- return {
24
- id: generateExistingRepeatId(linkId, index),
25
- qrItem
26
- };
27
- });
28
- }
29
- export default useInitialiseGroupTable;
30
- //# sourceMappingURL=useInitialiseGroupTable.js.map
17
+
18
+ import { expect, test } from '@jest/globals';
19
+ import { removeInternalIdsFromResponse } from '../utils';
20
+ import { qrRemoveIdResult, qrRemoveIdSample } from './test-data/removeIdSample';
21
+ import { qMyPatient } from '../stories/assets/questionnaires/QIdRemoverDebugger';
22
+
23
+ test('item.initial is properly pre-filled into QuestionnaireResponse', () => {
24
+ const outputResponse = removeInternalIdsFromResponse(qMyPatient, qrRemoveIdSample);
25
+
26
+ expect(outputResponse).toStrictEqual(qrRemoveIdResult);
27
+ });
@@ -0,0 +1,101 @@
1
+ import type { QuestionnaireResponse } from 'fhir/r4';
2
+
3
+ export const qrRemoveIdSample: QuestionnaireResponse = {
4
+ resourceType: 'QuestionnaireResponse',
5
+ status: 'in-progress',
6
+ questionnaire: 'http://canshare.co.nz/questionnaire/myPatient1',
7
+ item: [
8
+ {
9
+ linkId: 'myPatient1',
10
+ text: 'myPatient1',
11
+ item: [
12
+ {
13
+ linkId: 'myPatient1.name',
14
+ text: 'name *',
15
+ item: [
16
+ {
17
+ linkId: 'myPatient1.name.first',
18
+ text: 'firstName *',
19
+ answer: [
20
+ {
21
+ id: 'myPatient1.name.first-repeat-000000',
22
+ valueString: '1st firstName 1.0'
23
+ }
24
+ ]
25
+ }
26
+ ]
27
+ },
28
+ {
29
+ linkId: 'myPatient1.name',
30
+ text: 'name *',
31
+ item: [
32
+ {
33
+ linkId: 'myPatient1.name.first',
34
+ text: 'firstName *',
35
+ answer: [
36
+ {
37
+ id: 'myPatient1.name.first-repeat-000000',
38
+ valueString: '2nd firstName 1.0'
39
+ },
40
+ {
41
+ id: 'myPatient1.name.first-repeat-O-r6YSxx81TBFf_yiHWk6',
42
+ valueString: '2nd firstName 2.0'
43
+ },
44
+ {
45
+ id: 'myPatient1.name.first-repeat-ZQR77gdy6utsT_JkbuHKc'
46
+ }
47
+ ]
48
+ }
49
+ ]
50
+ }
51
+ ]
52
+ }
53
+ ]
54
+ };
55
+
56
+ export const qrRemoveIdResult: QuestionnaireResponse = {
57
+ resourceType: 'QuestionnaireResponse',
58
+ status: 'in-progress',
59
+ questionnaire: 'http://canshare.co.nz/questionnaire/myPatient1',
60
+ item: [
61
+ {
62
+ linkId: 'myPatient1',
63
+ text: 'myPatient1',
64
+ item: [
65
+ {
66
+ linkId: 'myPatient1.name',
67
+ text: 'name *',
68
+ item: [
69
+ {
70
+ linkId: 'myPatient1.name.first',
71
+ text: 'firstName *',
72
+ answer: [
73
+ {
74
+ valueString: '1st firstName 1.0'
75
+ }
76
+ ]
77
+ }
78
+ ]
79
+ },
80
+ {
81
+ linkId: 'myPatient1.name',
82
+ text: 'name *',
83
+ item: [
84
+ {
85
+ linkId: 'myPatient1.name.first',
86
+ text: 'firstName *',
87
+ answer: [
88
+ {
89
+ valueString: '2nd firstName 1.0'
90
+ },
91
+ {
92
+ valueString: '2nd firstName 2.0'
93
+ }
94
+ ]
95
+ }
96
+ ]
97
+ }
98
+ ]
99
+ }
100
+ ]
101
+ };
@@ -23,7 +23,6 @@ import {
23
23
  StyledEngineProvider,
24
24
  ThemeProvider as MUIThemeProvider
25
25
  } from '@mui/material/styles';
26
- import CssBaseline from '@mui/material/CssBaseline';
27
26
  import palette from './palette';
28
27
  import typography from './typography';
29
28
  import CustomGlobalStyles from './customGlobalStyles';
@@ -102,7 +101,6 @@ export function RendererThemeProvider({ children }: { children: ReactNode }) {
102
101
  return (
103
102
  <StyledEngineProvider injectFirst>
104
103
  <MUIThemeProvider theme={theme}>
105
- <CssBaseline />
106
104
  <CustomGlobalStyles />
107
105
  {children}
108
106
  </MUIThemeProvider>
@@ -27,14 +27,13 @@ import type {
27
27
  QuestionnaireResponseItem,
28
28
  QuestionnaireResponseItemAnswer
29
29
  } from 'fhir/r4';
30
- import _isEqual from 'lodash/isEqual';
31
30
  import { emptyResponse } from './emptyResource';
32
31
  import { createFhirPathContext } from './fhirpath';
33
32
  import { getQrItemsIndex, mapQItemsIndex } from './mapItem';
34
33
  import { updateQrItemsInGroup } from './qrItem';
35
- import cloneDeep from 'lodash.clonedeep';
36
34
  import dayjs from 'dayjs';
37
35
  import { updateQuestionnaireResponse } from './genericRecursive';
36
+ import isEqual from 'lodash.isequal';
38
37
 
39
38
  interface EvaluateInitialCalculatedExpressionsParams {
40
39
  initialResponse: QuestionnaireResponse;
@@ -60,7 +59,7 @@ export function evaluateInitialCalculatedExpressions(
60
59
 
61
60
  // Return early if initialResponse is empty or there are no calculated expressions to evaluate
62
61
  if (
63
- _isEqual(initialResponse, cloneDeep(emptyResponse)) ||
62
+ isEqual(initialResponse, structuredClone(emptyResponse)) ||
64
63
  Object.keys(calculatedExpressions).length === 0
65
64
  ) {
66
65
  return {
@@ -93,7 +92,7 @@ export function evaluateInitialCalculatedExpressions(
93
92
  );
94
93
 
95
94
  // Only update calculatedExpressions if length of result array > 0
96
- if (result.length > 0 && !_isEqual(calcExpression.value, result[0])) {
95
+ if (result.length > 0 && !isEqual(calcExpression.value, result[0])) {
97
96
  calcExpression.value = result[0];
98
97
  }
99
98
  } catch (e) {
@@ -136,7 +135,7 @@ export function evaluateCalculatedExpressions(
136
135
 
137
136
  // Update calculatedExpressions if length of result array > 0
138
137
  // Only update when current calcExpression value is different from the result, otherwise it will result in an infinite loop as per issue #733
139
- if (result.length > 0 && !_isEqual(calcExpression.value, result[0])) {
138
+ if (result.length > 0 && !isEqual(calcExpression.value, result[0])) {
140
139
  isUpdated = true;
141
140
  calcExpression.value = result[0];
142
141
  }
@@ -22,7 +22,6 @@ import type {
22
22
  QuestionnaireResponseItem,
23
23
  QuestionnaireResponseItemAnswer
24
24
  } from 'fhir/r4';
25
- import cloneDeep from 'lodash.clonedeep';
26
25
  import type {
27
26
  EnableWhenItems,
28
27
  EnableWhenRepeatItemProperties,
@@ -257,7 +256,7 @@ export function setInitialAnswers(
257
256
  items: EnableWhenItems,
258
257
  linkedQuestionsMap: Record<string, string[]>
259
258
  ): EnableWhenItems {
260
- let updatedItems = cloneDeep(items);
259
+ let updatedItems = structuredClone(items);
261
260
 
262
261
  if (initialAnswers) {
263
262
  for (const linkId in initialAnswers) {
@@ -261,7 +261,7 @@ export function createObservation(
261
261
 
262
262
  let ID_COUNTER = 0;
263
263
 
264
- function generateUniqueId(prefix: string) {
264
+ export function generateUniqueId(prefix: string) {
265
265
  if (ID_COUNTER) {
266
266
  ID_COUNTER = 0;
267
267
  }
@@ -16,7 +16,6 @@
16
16
  */
17
17
 
18
18
  import type { GroupTableRowModel } from '../interfaces/groupTable.interface';
19
- import cloneDeep from 'lodash.clonedeep';
20
19
 
21
20
  export function reorderRows(
22
21
  rows: GroupTableRowModel[],
@@ -33,5 +32,5 @@ export function reorderRows(
33
32
  export function getGroupTableItemsToUpdate(tableRows: GroupTableRowModel[], selectedIds: string[]) {
34
33
  return tableRows
35
34
  .filter((row) => selectedIds.includes(row.id))
36
- .flatMap((singleRow) => (singleRow.qrItem ? [cloneDeep(singleRow.qrItem)] : []));
35
+ .flatMap((singleRow) => (singleRow.qrItem ? [structuredClone(singleRow.qrItem)] : []));
37
36
  }
@@ -58,10 +58,6 @@ export function initialiseQuestionnaireResponse(
58
58
  questionnaireResponse.status = 'in-progress';
59
59
  }
60
60
 
61
- // if (!questionnaireResponse.id) {
62
- // questionnaireResponse.id = 'in-progress';
63
- // }
64
-
65
61
  const firstTopLevelItem = questionnaire?.item?.[0];
66
62
  if (firstTopLevelItem && !questionnaireResponse.item) {
67
63
  const initialItems = readQuestionnaireResponse(
@@ -9,7 +9,6 @@ import { initialiseQuestionnaireResponse } from './initialise';
9
9
  import { removeEmptyAnswers } from './removeEmptyAnswers';
10
10
  import { readEncounter, readPatient, readUser } from '../api/smartClient';
11
11
  import type Client from 'fhirclient/lib/Client';
12
- import cloneDeep from 'lodash.clonedeep';
13
12
  import { updateQuestionnaireResponse } from './genericRecursive';
14
13
  import { removeInternalRepeatIdsRecursive } from './removeRepeatId';
15
14
 
@@ -102,7 +101,7 @@ export function getResponse(): QuestionnaireResponse {
102
101
  questionnaireStore.getState().sourceQuestionnaire,
103
102
  questionnaireResponseStore.getState().updatableResponse
104
103
  );
105
- return cloneDeep(cleanResponse);
104
+ return structuredClone(cleanResponse);
106
105
  }
107
106
 
108
107
  /**
@@ -139,7 +138,7 @@ export function removeInternalIdsFromResponse(
139
138
  questionnaire: Questionnaire,
140
139
  questionnaireResponse: QuestionnaireResponse
141
140
  ): QuestionnaireResponse {
142
- const questionnaireResponseToUpdate = cloneDeep(questionnaireResponse);
141
+ const questionnaireResponseToUpdate = structuredClone(questionnaireResponse);
143
142
 
144
143
  return updateQuestionnaireResponse(
145
144
  questionnaire,
@@ -23,7 +23,7 @@ import type {
23
23
  } from 'fhir/r4';
24
24
  import { OpenChoiceItemControl } from '../interfaces/choice.enum';
25
25
  import { isSpecificItemControl } from './itemControl';
26
- import _isEqual from 'lodash/isEqual';
26
+ import isEqual from 'lodash.isequal';
27
27
 
28
28
  /**
29
29
  * Update open choice answer based on open label value
@@ -100,7 +100,7 @@ export function updateOpenLabelAnswer(
100
100
 
101
101
  // Old open label answer equals to new open label answer
102
102
  // This should not happen, but return oldQrItem
103
- if (_isEqual(oldOpenLabelAnswer, newOpenLabelAnswer)) {
103
+ if (isEqual(oldOpenLabelAnswer, newOpenLabelAnswer)) {
104
104
  return oldQrItem;
105
105
  }
106
106
 
@@ -122,7 +122,7 @@ export function getOldOpenLabelAnswer(
122
122
  options: QuestionnaireItemAnswerOption[]
123
123
  ): QuestionnaireResponseItemAnswer | null {
124
124
  const openLabelAnswer = answers.find(
125
- (answer) => !options.some((option) => _isEqual(option, answer))
125
+ (answer) => !options.some((option) => isEqual(option, answer))
126
126
  );
127
127
  return openLabelAnswer ?? null;
128
128
  }
@@ -40,7 +40,6 @@ import type { Variables } from '../../interfaces/variables.interface';
40
40
  import { getFhirPathVariables, getXFhirQueryVariables } from './extractVariables';
41
41
  import { getRepeatGroupParentItem } from '../misc';
42
42
  import { checkItemIsEnabledRepeat } from '../enableWhen';
43
- import cloneDeep from 'lodash.clonedeep';
44
43
  import { emptyResponse } from '../emptyResource';
45
44
  import { evaluateEnableWhenRepeatExpressionInstance } from '../enableWhenExpression';
46
45
  import {
@@ -429,7 +428,7 @@ function initialiseEnableWhenExpression(
429
428
 
430
429
  const { isEnabled } = evaluateEnableWhenRepeatExpressionInstance(
431
430
  qItem.linkId,
432
- { resource: cloneDeep(emptyResponse) },
431
+ { resource: structuredClone(emptyResponse) },
433
432
  enableWhenRepeatExpression,
434
433
  enableWhenRepeatExpression.expression.lastIndexOf('.where(linkId'),
435
434
  0
@@ -23,7 +23,6 @@ import type {
23
23
  } from 'fhir/r4';
24
24
  import type { EnableWhenExpressions, EnableWhenItems } from '../interfaces/enableWhen.interface';
25
25
  import { isHiddenByEnableWhen } from './qItem';
26
- import cloneDeep from 'lodash.clonedeep';
27
26
  import { qrItemHasItemsOrAnswer } from './manageForm';
28
27
 
29
28
  interface removeEmptyAnswersParams {
@@ -56,7 +55,7 @@ export function removeEmptyAnswers(params: removeEmptyAnswersParams): Questionna
56
55
  !topLevelQRItems ||
57
56
  topLevelQRItems.length === 0
58
57
  ) {
59
- const updatedQuestionnaireResponse = cloneDeep(questionnaireResponse);
58
+ const updatedQuestionnaireResponse = structuredClone(questionnaireResponse);
60
59
  delete updatedQuestionnaireResponse.item;
61
60
  return updatedQuestionnaireResponse;
62
61
  }
@@ -22,18 +22,17 @@ import type {
22
22
  QuestionnaireResponseItem
23
23
  } from 'fhir/r4';
24
24
  import type { Tabs } from '../interfaces/tab.interface';
25
- import _isEqual from 'lodash/isEqual';
26
- import _intersection from 'lodash/intersection';
27
- import _difference from 'lodash/difference';
28
25
  import { containsTabs, isTabContainer } from './tabs';
29
26
  import { getShortText, isSpecificItemControl } from './itemControl';
30
27
  import { getQrItemsIndex, mapQItemsIndex } from './mapItem';
31
28
  import type { EnableWhenExpressions, EnableWhenItems } from '../interfaces/enableWhen.interface';
32
29
  import { isHiddenByEnableWhen } from './qItem';
33
30
  import { questionnaireResponseStore, questionnaireStore } from '../stores';
34
- import cloneDeep from 'lodash.clonedeep';
35
31
  import { createQuestionnaireResponseItemMap } from './questionnaireResponseStoreUtils/updatableResponseItems';
36
32
  import { getQuestionnaireItem, getSectionHeading } from './misc';
33
+ import difference from 'lodash.difference';
34
+ import intersection from 'lodash.intersection';
35
+ import isEqual from 'lodash.isequal';
37
36
 
38
37
  /**
39
38
  * ItemToRepopulate interface
@@ -99,11 +98,11 @@ export function generateItemsToRepopulate(populatedResponse: QuestionnaireRespon
99
98
  // Get linkIds that are different between current QRItems and populated QRItems
100
99
  // Doesn't work with repeat groups, but at the same time I'm not sure if it's needed, given you can't delete completely the first repeat group
101
100
  const populatedResponseItemMap = createQuestionnaireResponseItemMap(populatedResponse);
102
- const diffLinkIds = _difference(
101
+ const diffLinkIds = difference(
103
102
  Object.keys(updatableResponseItems),
104
103
  Object.keys(populatedResponseItemMap)
105
104
  );
106
- const diffLinkIdsWithInitialExpressions = _intersection(
105
+ const diffLinkIdsWithInitialExpressions = intersection(
107
106
  Object.keys(initialExpressions),
108
107
  diffLinkIds
109
108
  );
@@ -316,7 +315,7 @@ function getSingleItemToRepopulate(
316
315
  ) {
317
316
  if (qItem.linkId === 'encounter-reason') {
318
317
  console.log(
319
- cloneDeep({
318
+ structuredClone({
320
319
  qItem: qItem,
321
320
  heading: heading,
322
321
  newQRItem: qrItem,
@@ -468,7 +467,7 @@ function retrieveSingleOldQRItem(
468
467
  return;
469
468
  }
470
469
 
471
- if (_isEqual(oldQRItem, newQRItem)) {
470
+ if (isEqual(oldQRItem, newQRItem)) {
472
471
  delete itemsToRepopulate[qItem.linkId];
473
472
  return;
474
473
  }
@@ -490,7 +489,7 @@ function retrieveRepeatGroupOldQRItems(
490
489
  return;
491
490
  }
492
491
 
493
- if (_isEqual(oldQRItems, newQRItems)) {
492
+ if (isEqual(oldQRItems, newQRItems)) {
494
493
  delete itemsToRepopulate[qItem.linkId];
495
494
  return;
496
495
  }
@@ -535,7 +534,7 @@ function retrieveGridGroupOldQRItems(
535
534
  continue;
536
535
  }
537
536
 
538
- if (_isEqual(oldGridChildQrItem, newGridChildQRItem)) {
537
+ if (isEqual(oldGridChildQrItem, newGridChildQRItem)) {
539
538
  newGridChildQRItemMap.delete(gridChildQItem.linkId);
540
539
  } else {
541
540
  oldGridChildQRItems.push(oldGridChildQrItem);
@@ -1,4 +0,0 @@
1
- import type { QuestionnaireResponseItem } from 'fhir/r4';
2
- import type { GroupTableRowModel } from '../interfaces/groupTable.interface';
3
- declare function useInitialiseGroupTable(linkId: string, qrItems: QuestionnaireResponseItem[]): GroupTableRowModel[];
4
- export default useInitialiseGroupTable;
@@ -1 +0,0 @@
1
- {"version":3,"file":"useInitialiseGroupTable.js","sourceRoot":"","sources":["../../src/hooks/useInitialiseGroupTable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAElF,SAAS,uBAAuB,CAC9B,MAAc,EACd,OAAoC;IAEpC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,OAAO,CAAC,EAAE,EAAE,EAAE,mBAAmB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;KAC5D;IAED,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACnC,OAAO;YACL,EAAE,EAAE,wBAAwB,CAAC,MAAM,EAAE,KAAK,CAAC;YAC3C,MAAM;SACP,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,eAAe,uBAAuB,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { Dispatch, SetStateAction } from 'react';
2
- declare function useNumberInput(valueFromProps: number): [number, Dispatch<SetStateAction<number>>];
3
- export default useNumberInput;
@@ -1 +0,0 @@
1
- {"version":3,"file":"useNumberInput.js","sourceRoot":"","sources":["../../src/hooks/useNumberInput.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,SAAS,cAAc,CAAC,cAAsB;IAC5C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC;IAEnD,SAAS,CACP,GAAG,EAAE;QACH,IAAI,KAAK,KAAK,cAAc,EAAE;YAC5B,QAAQ,CAAC,cAAc,CAAC,CAAC;SAC1B;IACH,CAAC;IACD,iDAAiD;IACjD,uDAAuD;IACvD,CAAC,cAAc,CAAC,CACjB,CAAC;IAEF,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC3B,CAAC;AAED,eAAe,cAAc,CAAC"}
@@ -1,4 +0,0 @@
1
- import type { Dispatch, SetStateAction } from 'react';
2
- import type { RepeatGroupSingle } from '../interfaces/repeatGroup.interface';
3
- declare function useRepeatGroups(valueFromProps: RepeatGroupSingle[]): [RepeatGroupSingle[], Dispatch<SetStateAction<RepeatGroupSingle[]>>];
4
- export default useRepeatGroups;
@@ -1,38 +0,0 @@
1
- /*
2
- * Copyright 2024 Commonwealth Scientific and Industrial Research
3
- * Organisation (CSIRO) ABN 41 687 119 230.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- import { useEffect, useState } from 'react';
18
- import _isEqual from 'lodash/isEqual';
19
- function useRepeatGroups(valueFromProps) {
20
- const [repeatGroups, setRepeatGroups] = useState(valueFromProps);
21
- useEffect(() => {
22
- const valueFromPropsQRItems = valueFromProps
23
- .map((repeatGroupSingle) => repeatGroupSingle.qrItem)
24
- .filter((qrItem) => qrItem !== null);
25
- const repeatGroupsQRItems = repeatGroups
26
- .map((repeatGroupSingle) => repeatGroupSingle.qrItem)
27
- .filter((qrItem) => qrItem !== null);
28
- if (!_isEqual(valueFromPropsQRItems, repeatGroupsQRItems)) {
29
- setRepeatGroups(valueFromProps);
30
- }
31
- },
32
- // Only trigger this effect if prop value changes
33
- // eslint-disable-next-line react-hooks/exhaustive-deps
34
- [valueFromProps]);
35
- return [repeatGroups, setRepeatGroups];
36
- }
37
- export default useRepeatGroups;
38
- //# sourceMappingURL=useRepeatGroups.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useRepeatGroups.js","sourceRoot":"","sources":["../../src/hooks/useRepeatGroups.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAGtC,SAAS,eAAe,CACtB,cAAmC;IAEnC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC;IAEjE,SAAS,CACP,GAAG,EAAE;QACH,MAAM,qBAAqB,GAAG,cAAc;aACzC,GAAG,CAAC,CAAC,iBAAiB,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC;aACpD,MAAM,CAAC,CAAC,MAAM,EAAuC,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC;QAE5E,MAAM,mBAAmB,GAAG,YAAY;aACrC,GAAG,CAAC,CAAC,iBAAiB,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC;aACpD,MAAM,CAAC,CAAC,MAAM,EAAuC,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC;QAE5E,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EAAE,mBAAmB,CAAC,EAAE;YACzD,eAAe,CAAC,cAAc,CAAC,CAAC;SACjC;IACH,CAAC;IACD,iDAAiD;IACjD,uDAAuD;IACvD,CAAC,cAAc,CAAC,CACjB,CAAC;IAEF,OAAO,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;AACzC,CAAC;AAED,eAAe,eAAe,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { Dispatch, SetStateAction } from 'react';
2
- declare function useStringInput(valueFromProps: string): [string, Dispatch<SetStateAction<string>>];
3
- export default useStringInput;
@@ -1,32 +0,0 @@
1
- /*
2
- * Copyright 2024 Commonwealth Scientific and Industrial Research
3
- * Organisation (CSIRO) ABN 41 687 119 230.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- import { useEffect, useState } from 'react';
18
- // The purpose of this hook to sync the string state from external changes i.e. re-population changes etc.
19
- function useStringInput(valueFromProps) {
20
- const [input, setInput] = useState(valueFromProps);
21
- useEffect(() => {
22
- if (input !== valueFromProps) {
23
- setInput(valueFromProps);
24
- }
25
- },
26
- // Only trigger this effect if prop value changes
27
- // eslint-disable-next-line react-hooks/exhaustive-deps
28
- [valueFromProps]);
29
- return [input, setInput];
30
- }
31
- export default useStringInput;
32
- //# sourceMappingURL=useStringInput.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStringInput.js","sourceRoot":"","sources":["../../src/hooks/useStringInput.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,0GAA0G;AAC1G,SAAS,cAAc,CAAC,cAAsB;IAC5C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC;IAEnD,SAAS,CACP,GAAG,EAAE;QACH,IAAI,KAAK,KAAK,cAAc,EAAE;YAC5B,QAAQ,CAAC,cAAc,CAAC,CAAC;SAC1B;IACH,CAAC;IACD,iDAAiD;IACjD,uDAAuD;IACvD,CAAC,cAAc,CAAC,CACjB,CAAC;IAEF,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC3B,CAAC;AAED,eAAe,cAAc,CAAC"}
@@ -1,38 +0,0 @@
1
- /*
2
- * Copyright 2024 Commonwealth Scientific and Industrial Research
3
- * Organisation (CSIRO) ABN 41 687 119 230.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- import type { Dispatch, SetStateAction } from 'react';
19
- import { useEffect, useState } from 'react';
20
-
21
- function useNumberInput(valueFromProps: number): [number, Dispatch<SetStateAction<number>>] {
22
- const [value, setValue] = useState(valueFromProps);
23
-
24
- useEffect(
25
- () => {
26
- if (value !== valueFromProps) {
27
- setValue(valueFromProps);
28
- }
29
- },
30
- // Only trigger this effect if prop value changes
31
- // eslint-disable-next-line react-hooks/exhaustive-deps
32
- [valueFromProps]
33
- );
34
-
35
- return [value, setValue];
36
- }
37
-
38
- export default useNumberInput;
@@ -1,51 +0,0 @@
1
- /*
2
- * Copyright 2024 Commonwealth Scientific and Industrial Research
3
- * Organisation (CSIRO) ABN 41 687 119 230.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- import type { Dispatch, SetStateAction } from 'react';
19
- import { useEffect, useState } from 'react';
20
- import type { RepeatGroupSingle } from '../interfaces/repeatGroup.interface';
21
- import _isEqual from 'lodash/isEqual';
22
- import type { QuestionnaireResponseItem } from 'fhir/r4';
23
-
24
- function useRepeatGroups(
25
- valueFromProps: RepeatGroupSingle[]
26
- ): [RepeatGroupSingle[], Dispatch<SetStateAction<RepeatGroupSingle[]>>] {
27
- const [repeatGroups, setRepeatGroups] = useState(valueFromProps);
28
-
29
- useEffect(
30
- () => {
31
- const valueFromPropsQRItems = valueFromProps
32
- .map((repeatGroupSingle) => repeatGroupSingle.qrItem)
33
- .filter((qrItem): qrItem is QuestionnaireResponseItem => qrItem !== null);
34
-
35
- const repeatGroupsQRItems = repeatGroups
36
- .map((repeatGroupSingle) => repeatGroupSingle.qrItem)
37
- .filter((qrItem): qrItem is QuestionnaireResponseItem => qrItem !== null);
38
-
39
- if (!_isEqual(valueFromPropsQRItems, repeatGroupsQRItems)) {
40
- setRepeatGroups(valueFromProps);
41
- }
42
- },
43
- // Only trigger this effect if prop value changes
44
- // eslint-disable-next-line react-hooks/exhaustive-deps
45
- [valueFromProps]
46
- );
47
-
48
- return [repeatGroups, setRepeatGroups];
49
- }
50
-
51
- export default useRepeatGroups;