@aehrc/smart-forms-renderer 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/lib/components/FormComponents/ChoiceItems/ChoiceAutocompleteItem.js +1 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceAutocompleteItem.js.map +1 -1
- package/lib/components/FormComponents/DecimalItem/DecimalItem.js +3 -2
- package/lib/components/FormComponents/DecimalItem/DecimalItem.js.map +1 -1
- package/lib/components/FormComponents/GridGroup/GridGroup.js +2 -2
- package/lib/components/FormComponents/GridGroup/GridGroup.js.map +1 -1
- package/lib/components/FormComponents/GridGroup/GridRow.js +2 -2
- package/lib/components/FormComponents/GridGroup/GridRow.js.map +1 -1
- package/lib/components/FormComponents/GroupItem/GroupChildItemSwitcher.d.ts +10 -0
- package/lib/components/FormComponents/GroupItem/GroupChildItemSwitcher.js +73 -0
- package/lib/components/FormComponents/GroupItem/GroupChildItemSwitcher.js.map +1 -0
- package/lib/components/FormComponents/GroupItem/GroupItem.js +3 -3
- package/lib/components/FormComponents/GroupItem/GroupItem.js.map +1 -1
- package/lib/components/FormComponents/GroupItem/ItemSwitcher.d.ts +10 -0
- package/lib/components/FormComponents/GroupItem/ItemSwitcher.js +81 -0
- package/lib/components/FormComponents/GroupItem/ItemSwitcher.js.map +1 -0
- package/lib/components/FormComponents/GroupItem/TopLevelGroupItemSwitcher.d.ts +10 -0
- package/lib/components/FormComponents/GroupItem/TopLevelGroupItemSwitcher.js +45 -0
- package/lib/components/FormComponents/GroupItem/TopLevelGroupItemSwitcher.js.map +1 -0
- package/lib/components/FormComponents/IntegerItem/IntegerItem.js +3 -2
- package/lib/components/FormComponents/IntegerItem/IntegerItem.js.map +1 -1
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteItem.js +2 -2
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteItem.js.map +1 -1
- package/lib/components/FormComponents/RepeatGroup/RepeatGroup.js +4 -3
- package/lib/components/FormComponents/RepeatGroup/RepeatGroup.js.map +1 -1
- package/lib/components/FormComponents/RepeatGroup/index.d.ts +1 -0
- package/lib/{theme/overrides/Typography.js → components/FormComponents/RepeatGroup/index.js} +2 -15
- package/lib/components/FormComponents/RepeatGroup/index.js.map +1 -0
- package/lib/components/FormComponents/RepeatItem/RepeatItem.js +1 -1
- package/lib/components/FormComponents/RepeatItem/RepeatItem.js.map +1 -1
- package/lib/components/FormComponents/SingleItem/index.d.ts +1 -0
- package/lib/components/FormComponents/SingleItem/index.js +18 -0
- package/lib/components/FormComponents/SingleItem/index.js.map +1 -0
- package/lib/components/FormComponents/StringItem/StringItem.js +3 -2
- package/lib/components/FormComponents/StringItem/StringItem.js.map +1 -1
- package/lib/components/FormComponents/Tables/QItemGroupTable.js +7 -5
- package/lib/components/FormComponents/Tables/QItemGroupTable.js.map +1 -1
- package/lib/components/FormComponents/Tables/QItemGroupTableRow.js +2 -2
- package/lib/components/FormComponents/Tables/QItemGroupTableRow.js.map +1 -1
- package/lib/components/FormComponents/Tables/index.d.ts +1 -0
- package/lib/components/FormComponents/Tables/index.js +18 -0
- package/lib/components/FormComponents/Tables/index.js.map +1 -0
- package/lib/components/FormComponents/TextItem/TextItem.js +3 -2
- package/lib/components/FormComponents/TextItem/TextItem.js.map +1 -1
- package/lib/components/FormComponents/index.d.ts +3 -0
- package/lib/components/FormComponents/index.js +20 -0
- package/lib/components/FormComponents/index.js.map +1 -0
- package/lib/components/Renderer/BaseRenderer.js +26 -14
- package/lib/components/Renderer/BaseRenderer.js.map +1 -1
- package/lib/components/Renderer/FormBodyCollapsible.js +2 -2
- package/lib/components/Renderer/FormBodyCollapsible.js.map +1 -1
- package/lib/components/Renderer/FormBodyTabbed.js +2 -2
- package/lib/components/Renderer/FormBodyTabbed.js.map +1 -1
- package/lib/components/Renderer/FormTopLevelItem.d.ts +4 -4
- package/lib/components/Renderer/FormTopLevelItem.js +14 -1
- package/lib/components/Renderer/FormTopLevelItem.js.map +1 -1
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +1 -0
- package/lib/components/index.js.map +1 -1
- package/lib/hooks/useDecimalUpdateFromProp.d.ts +2 -0
- package/lib/{utils/isHidden.js → hooks/useDecimalUpdateFromProp.js} +12 -13
- package/lib/hooks/useDecimalUpdateFromProp.js.map +1 -0
- package/lib/hooks/useInitialiseRepeatAnswers.d.ts +2 -2
- package/lib/hooks/useInitialiseRepeatAnswers.js +21 -15
- package/lib/hooks/useInitialiseRepeatAnswers.js.map +1 -1
- package/lib/hooks/useInitialiseRepeatGroups.d.ts +2 -1
- package/lib/hooks/useInitialiseRepeatGroups.js +21 -15
- package/lib/hooks/useInitialiseRepeatGroups.js.map +1 -1
- package/lib/hooks/useIntegerUpdateFromProp.d.ts +2 -0
- package/lib/hooks/useIntegerUpdateFromProp.js +29 -0
- package/lib/hooks/useIntegerUpdateFromProp.js.map +1 -0
- package/lib/hooks/useNumberInput.d.ts +3 -0
- package/lib/hooks/useNumberInput.js +31 -0
- package/lib/hooks/useNumberInput.js.map +1 -0
- package/lib/hooks/useNumberUpdateFromProp.d.ts +2 -0
- package/lib/hooks/useNumberUpdateFromProp.js +29 -0
- package/lib/hooks/useNumberUpdateFromProp.js.map +1 -0
- package/lib/hooks/useRepeatItemState.d.ts +5 -0
- package/lib/hooks/useRepeatItemState.js +35 -0
- package/lib/hooks/useRepeatItemState.js.map +1 -0
- package/lib/hooks/useRepeatItemUpdateFromProp.d.ts +2 -0
- package/lib/hooks/useRepeatItemUpdateFromProp.js +29 -0
- package/lib/hooks/useRepeatItemUpdateFromProp.js.map +1 -0
- package/lib/hooks/useStringField.d.ts +2 -0
- package/lib/hooks/useStringField.js +29 -0
- package/lib/hooks/useStringField.js.map +1 -0
- package/lib/hooks/useStringInput.d.ts +3 -0
- package/lib/hooks/useStringInput.js +31 -0
- package/lib/hooks/useStringInput.js.map +1 -0
- package/lib/hooks/useStringUpdateFromProp.d.ts +2 -0
- package/lib/hooks/useStringUpdateFromProp.js +29 -0
- package/lib/hooks/useStringUpdateFromProp.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +27 -0
- package/lib/index.js.map +1 -1
- package/lib/interfaces/questionnaireStore.interface.d.ts +1 -0
- package/lib/stores/useQuestionnaireResponseStore.d.ts +1 -1
- package/lib/stores/useQuestionnaireResponseStore.js +15 -10
- package/lib/stores/useQuestionnaireResponseStore.js.map +1 -1
- package/lib/stores/useQuestionnaireStore.d.ts +2 -1
- package/lib/stores/useQuestionnaireStore.js +5 -2
- package/lib/stores/useQuestionnaireStore.js.map +1 -1
- package/lib/theme/overrides/Overrides.js +1 -2
- package/lib/theme/overrides/Overrides.js.map +1 -1
- package/lib/utils/calculatedExpression.js +2 -2
- package/lib/utils/calculatedExpression.js.map +1 -1
- package/lib/utils/formChanges.d.ts +18 -0
- package/lib/utils/formChanges.js +91 -0
- package/lib/utils/formChanges.js.map +1 -0
- package/lib/utils/formChangesOld.d.ts +18 -0
- package/lib/utils/formChangesOld.js +91 -0
- package/lib/utils/formChangesOld.js.map +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +18 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/mapItem.d.ts +2 -2
- package/lib/utils/mapItem.js +3 -3
- package/lib/utils/mapItem.js.map +1 -1
- package/lib/utils/qItem.d.ts +2 -0
- package/lib/utils/qItem.js +22 -0
- package/lib/utils/qItem.js.map +1 -1
- package/lib/utils/qrItem.d.ts +1 -1
- package/lib/utils/qrItem.js +92 -93
- package/lib/utils/qrItem.js.map +1 -1
- package/lib/utils/questionnaireStoreUtils/createQuestionaireModel.js +4 -0
- package/lib/utils/questionnaireStoreUtils/createQuestionaireModel.js.map +1 -1
- package/lib/utils/repopulate.d.ts +9 -0
- package/lib/utils/repopulate.js +133 -0
- package/lib/utils/repopulate.js.map +1 -0
- package/lib/utils/repopulateGenerateItems.d.ts +9 -0
- package/lib/utils/repopulateGenerateItems.js +133 -0
- package/lib/utils/repopulateGenerateItems.js.map +1 -0
- package/lib/utils/repopulateIntoResponse.d.ts +3 -0
- package/lib/utils/repopulateIntoResponse.js +92 -0
- package/lib/utils/repopulateIntoResponse.js.map +1 -0
- package/lib/utils/repopulateItems.d.ts +9 -0
- package/lib/utils/repopulateItems.js +131 -0
- package/lib/utils/repopulateItems.js.map +1 -0
- package/lib/utils/repopulateRepeatGroup.d.ts +4 -0
- package/lib/utils/repopulateRepeatGroup.js +54 -0
- package/lib/utils/repopulateRepeatGroup.js.map +1 -0
- package/package.json +3 -1
- package/src/components/FormComponents/ChoiceItems/ChoiceAutocompleteItem.tsx +1 -1
- package/src/components/FormComponents/DecimalItem/DecimalItem.tsx +3 -2
- package/src/components/FormComponents/GridGroup/GridGroup.tsx +2 -2
- package/src/components/FormComponents/GridGroup/GridRow.tsx +2 -2
- package/src/components/FormComponents/GroupItem/GroupItem.tsx +3 -3
- package/src/components/FormComponents/IntegerItem/IntegerItem.tsx +3 -2
- package/src/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteItem.tsx +1 -1
- package/src/components/FormComponents/RepeatGroup/RepeatGroup.tsx +4 -3
- package/src/{theme/overrides/Backdrop.ts → components/FormComponents/RepeatGroup/index.ts} +1 -17
- package/src/components/FormComponents/RepeatItem/RepeatItem.tsx +1 -1
- package/src/components/FormComponents/SingleItem/index.ts +18 -0
- package/src/components/FormComponents/StringItem/StringItem.tsx +3 -2
- package/src/components/FormComponents/Tables/QItemGroupTable.tsx +15 -6
- package/src/components/FormComponents/Tables/QItemGroupTableRow.tsx +2 -2
- package/src/components/FormComponents/Tables/index.ts +18 -0
- package/src/components/FormComponents/TextItem/TextItem.tsx +3 -2
- package/src/components/FormComponents/index.ts +20 -0
- package/src/components/Renderer/BaseRenderer.tsx +39 -18
- package/src/components/Renderer/FormBodyCollapsible.tsx +2 -2
- package/src/components/Renderer/FormBodyTabbed.tsx +2 -2
- package/src/components/Renderer/FormTopLevelItem.tsx +33 -4
- package/src/components/index.ts +1 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useInitialiseRepeatAnswers.ts +28 -17
- package/src/hooks/useInitialiseRepeatGroups.ts +28 -17
- package/src/hooks/useNumberInput.ts +37 -0
- package/src/hooks/useStringInput.ts +37 -0
- package/src/index.ts +43 -0
- package/src/interfaces/questionnaireStore.interface.ts +1 -0
- package/src/stores/useQuestionnaireResponseStore.ts +14 -10
- package/src/stores/useQuestionnaireStore.ts +10 -3
- package/src/theme/overrides/Overrides.ts +0 -2
- package/src/utils/calculatedExpression.ts +2 -2
- package/src/utils/formChanges.ts +141 -0
- package/src/utils/index.ts +18 -0
- package/src/utils/mapItem.ts +6 -4
- package/src/utils/qItem.ts +29 -0
- package/src/utils/qrItem.ts +104 -94
- package/src/utils/questionnaireStoreUtils/createQuestionaireModel.ts +4 -0
- package/src/utils/repopulateIntoResponse.ts +153 -0
- package/src/utils/repopulateItems.ts +207 -0
- package/src/utils/repopulateRepeatGroup.ts +68 -0
- package/lib/theme/overrides/Typography.d.ts +0 -13
- package/lib/theme/overrides/Typography.js.map +0 -1
- package/lib/utils/isHidden.d.ts +0 -3
- package/lib/utils/isHidden.js.map +0 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Questionnaire,
|
|
3
|
+
QuestionnaireItem,
|
|
4
|
+
QuestionnaireResponse,
|
|
5
|
+
QuestionnaireResponseItem
|
|
6
|
+
} from 'fhir/r4';
|
|
7
|
+
import { ItemToRepopulate } from './repopulateItems';
|
|
8
|
+
import { getQrItemsIndex, mapQItemsIndex } from './mapItem';
|
|
9
|
+
import { updateQrItemsInGroup } from './qrItem';
|
|
10
|
+
|
|
11
|
+
export function repopulateItemsIntoResponse(
|
|
12
|
+
questionnaire: Questionnaire,
|
|
13
|
+
updatableResponse: QuestionnaireResponse,
|
|
14
|
+
checkedItemsToRepopulate: Record<string, ItemToRepopulate>
|
|
15
|
+
): QuestionnaireResponse {
|
|
16
|
+
if (
|
|
17
|
+
!questionnaire.item ||
|
|
18
|
+
questionnaire.item.length === 0 ||
|
|
19
|
+
!updatableResponse.item ||
|
|
20
|
+
updatableResponse.item.length === 0
|
|
21
|
+
) {
|
|
22
|
+
return updatableResponse;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const topLevelQrItems: QuestionnaireResponseItem[] = [];
|
|
26
|
+
for (const [index, topLevelQItem] of questionnaire.item.entries()) {
|
|
27
|
+
const repopulatedTopLevelQrItem = updatableResponse.item[index] ?? {
|
|
28
|
+
linkId: topLevelQItem.linkId,
|
|
29
|
+
text: topLevelQItem.text,
|
|
30
|
+
item: []
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const updatedTopLevelQRItem = repopulateItemRecursive(
|
|
34
|
+
topLevelQItem,
|
|
35
|
+
repopulatedTopLevelQrItem,
|
|
36
|
+
checkedItemsToRepopulate
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (Array.isArray(updatedTopLevelQRItem)) {
|
|
40
|
+
if (updatedTopLevelQRItem.length > 0) {
|
|
41
|
+
topLevelQrItems.push(...updatedTopLevelQRItem);
|
|
42
|
+
}
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (updatedTopLevelQRItem) {
|
|
47
|
+
topLevelQrItems.push(updatedTopLevelQRItem);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return { ...updatableResponse, item: topLevelQrItems };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function repopulateItemRecursive(
|
|
55
|
+
qItem: QuestionnaireItem,
|
|
56
|
+
qrItem: QuestionnaireResponseItem | undefined,
|
|
57
|
+
checkedItemsToRepopulate: Record<string, ItemToRepopulate>
|
|
58
|
+
): QuestionnaireResponseItem[] | QuestionnaireResponseItem | null {
|
|
59
|
+
const childQItems = qItem.item;
|
|
60
|
+
if (childQItems && childQItems.length > 0) {
|
|
61
|
+
// iterate through items of item recursively
|
|
62
|
+
const childQrItems = qrItem?.item ?? [];
|
|
63
|
+
// const updatedChildQrItems: QuestionnaireResponseItem[] = [];
|
|
64
|
+
|
|
65
|
+
// FIXME Not implemented for repeat groups
|
|
66
|
+
if (qItem.type === 'group' && qItem.repeats) {
|
|
67
|
+
return qrItem ?? null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const indexMap = mapQItemsIndex(qItem);
|
|
71
|
+
const qrItemsByIndex = getQrItemsIndex(childQItems, childQrItems, indexMap);
|
|
72
|
+
|
|
73
|
+
// Otherwise loop through qItem as usual
|
|
74
|
+
for (const [index, childQItem] of childQItems.entries()) {
|
|
75
|
+
const childQrItem = qrItemsByIndex[index];
|
|
76
|
+
|
|
77
|
+
// FIXME Not implemented for repeat groups
|
|
78
|
+
if (Array.isArray(childQrItem)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const newQrItem = repopulateItemRecursive(childQItem, childQrItem, checkedItemsToRepopulate);
|
|
83
|
+
|
|
84
|
+
// FIXME Not implemented for repeat groups
|
|
85
|
+
if (Array.isArray(newQrItem)) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (newQrItem) {
|
|
90
|
+
updateQrItemsInGroup(
|
|
91
|
+
newQrItem,
|
|
92
|
+
null,
|
|
93
|
+
qrItem ?? { linkId: qItem.linkId, text: qItem.text, item: [] },
|
|
94
|
+
indexMap
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return constructGroupItem(qItem, qrItem, checkedItemsToRepopulate);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return constructSingleItem(qItem, qrItem, checkedItemsToRepopulate);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function constructGroupItem(
|
|
106
|
+
qItem: QuestionnaireItem,
|
|
107
|
+
qrItem: QuestionnaireResponseItem | undefined,
|
|
108
|
+
checkedItemsToRepopulate: Record<string, ItemToRepopulate>
|
|
109
|
+
): QuestionnaireResponseItem | null {
|
|
110
|
+
const itemToRepopulate = checkedItemsToRepopulate[qItem.linkId];
|
|
111
|
+
|
|
112
|
+
if (!itemToRepopulate) {
|
|
113
|
+
return qrItem ?? null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (qrItem) {
|
|
117
|
+
return {
|
|
118
|
+
...qrItem,
|
|
119
|
+
answer: itemToRepopulate.newQRItem.answer
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
linkId: qItem.linkId,
|
|
125
|
+
text: qItem.text,
|
|
126
|
+
answer: itemToRepopulate.newQRItem.answer
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function constructSingleItem(
|
|
131
|
+
qItem: QuestionnaireItem,
|
|
132
|
+
qrItem: QuestionnaireResponseItem | undefined,
|
|
133
|
+
checkedItemsToRepopulate: Record<string, ItemToRepopulate>
|
|
134
|
+
): QuestionnaireResponseItem | null {
|
|
135
|
+
const itemToRepopulate = checkedItemsToRepopulate[qItem.linkId];
|
|
136
|
+
|
|
137
|
+
if (!itemToRepopulate) {
|
|
138
|
+
return qrItem ?? null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (qrItem) {
|
|
142
|
+
return {
|
|
143
|
+
...qrItem,
|
|
144
|
+
answer: itemToRepopulate.newQRItem.answer
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
linkId: qItem.linkId,
|
|
150
|
+
text: qItem.text,
|
|
151
|
+
answer: itemToRepopulate.newQRItem.answer
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
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 type {
|
|
19
|
+
Questionnaire,
|
|
20
|
+
QuestionnaireItem,
|
|
21
|
+
QuestionnaireResponse,
|
|
22
|
+
QuestionnaireResponseItem
|
|
23
|
+
} from 'fhir/r4';
|
|
24
|
+
import type { Tabs } from '../interfaces/tab.interface';
|
|
25
|
+
import _isEqual from 'lodash/isEqual';
|
|
26
|
+
import { containsTabs, isTabContainer } from './tabs';
|
|
27
|
+
import { getShortText } from './itemControl';
|
|
28
|
+
import {
|
|
29
|
+
checkIsRepeatGroupToRepopulate,
|
|
30
|
+
getRepeatGroupToRepopulate
|
|
31
|
+
} from './repopulateRepeatGroup';
|
|
32
|
+
|
|
33
|
+
export interface ItemToRepopulate {
|
|
34
|
+
qItem: QuestionnaireItem | null;
|
|
35
|
+
heading: string | null;
|
|
36
|
+
newQRItem: QuestionnaireResponseItem;
|
|
37
|
+
oldQRItem?: QuestionnaireResponseItem;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getItemsToRepopulate(
|
|
41
|
+
sourceQuestionnaire: Questionnaire,
|
|
42
|
+
itemTypes: Record<string, string>,
|
|
43
|
+
tabs: Tabs,
|
|
44
|
+
populatedResponse: QuestionnaireResponse,
|
|
45
|
+
updatableResponse: QuestionnaireResponse
|
|
46
|
+
): Record<string, ItemToRepopulate> {
|
|
47
|
+
if (
|
|
48
|
+
!sourceQuestionnaire.item ||
|
|
49
|
+
sourceQuestionnaire.item.length === 0 ||
|
|
50
|
+
!populatedResponse.item ||
|
|
51
|
+
populatedResponse.item.length === 0 ||
|
|
52
|
+
!updatableResponse.item ||
|
|
53
|
+
updatableResponse.item.length === 0
|
|
54
|
+
) {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const populatedItems: QuestionnaireResponseItem[] = [];
|
|
59
|
+
for (const topLevelItem of populatedResponse.item) {
|
|
60
|
+
populatedItems.push(...getPopulatedItemsRecursive(topLevelItem, itemTypes));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const itemsToRepopulate = populatedItems.reduce(
|
|
64
|
+
(mapping: Record<string, ItemToRepopulate>, item) => {
|
|
65
|
+
mapping[item.linkId] = {
|
|
66
|
+
qItem: null,
|
|
67
|
+
heading: null,
|
|
68
|
+
newQRItem: item
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return mapping;
|
|
72
|
+
},
|
|
73
|
+
{}
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// Get corresponding old items from updatableResponse if they are different
|
|
77
|
+
for (const topLevelItem of updatableResponse.item) {
|
|
78
|
+
checkCorrespondingOldItemsRecursive(topLevelItem, itemTypes, itemsToRepopulate);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Get corresponding old items from updatableResponse if they are different
|
|
82
|
+
for (const topLevelItem of sourceQuestionnaire.item) {
|
|
83
|
+
const heading = topLevelItem.text ?? null;
|
|
84
|
+
const hasTabs = isTabContainer(topLevelItem) || containsTabs(topLevelItem);
|
|
85
|
+
getCorrespondingQuestionnaireItemsRecursive(
|
|
86
|
+
topLevelItem,
|
|
87
|
+
heading,
|
|
88
|
+
tabs,
|
|
89
|
+
hasTabs,
|
|
90
|
+
itemsToRepopulate
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return itemsToRepopulate;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 1. Get items to repopulate (only new items)
|
|
98
|
+
// 2. Get corresponding old items from updatableResponse (if they are different)
|
|
99
|
+
// 3. Compare old and new items in dialog - if there are none, show a dialog saying there is no new data
|
|
100
|
+
// 4. Have checkboxes in dialog to update response
|
|
101
|
+
// 5. Replace old answers with new answers
|
|
102
|
+
|
|
103
|
+
function getCorrespondingQuestionnaireItemsRecursive(
|
|
104
|
+
qItem: QuestionnaireItem,
|
|
105
|
+
heading: string | null,
|
|
106
|
+
tabs: Tabs,
|
|
107
|
+
hasTabs: boolean,
|
|
108
|
+
itemsToRepopulate: Record<string, ItemToRepopulate>
|
|
109
|
+
): void {
|
|
110
|
+
if (qItem.type === 'group' && qItem.item && qItem.item.length > 0) {
|
|
111
|
+
const isTab = !!tabs[qItem.linkId];
|
|
112
|
+
if (isTab) {
|
|
113
|
+
heading = getShortText(qItem) ?? qItem.text ?? null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// TODO it seems like there can only be one answer per linkId, we might need to do repeat groups differently
|
|
117
|
+
// so we need to fix this one first it seems like
|
|
118
|
+
|
|
119
|
+
/* Repeat group implementation */
|
|
120
|
+
if (qItem.type === 'group' && qItem.repeats) {
|
|
121
|
+
const isRepeatGroupToRepopulate = checkIsRepeatGroupToRepopulate(qItem, itemsToRepopulate);
|
|
122
|
+
if (isRepeatGroupToRepopulate) {
|
|
123
|
+
const repeatGroupToRepopulate = getRepeatGroupToRepopulate(qItem, itemsToRepopulate);
|
|
124
|
+
if (repeatGroupToRepopulate) {
|
|
125
|
+
itemsToRepopulate[qItem.linkId] = repeatGroupToRepopulate;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// /* Grid implementation */
|
|
132
|
+
// if (qItem.type === 'group' && isSpecificItemControl(qItem, 'grid')) {
|
|
133
|
+
// const isRepeatGroupToRepopulate = checkIsRepeatGroupToRepopulate(qItem, itemsToRepopulate);
|
|
134
|
+
// if (isRepeatGroupToRepopulate) {
|
|
135
|
+
// getRepeatGroupToRepopulate(qItem, itemsToRepopulate);
|
|
136
|
+
// }
|
|
137
|
+
// }
|
|
138
|
+
|
|
139
|
+
for (const childItem of qItem.item) {
|
|
140
|
+
getCorrespondingQuestionnaireItemsRecursive(
|
|
141
|
+
childItem,
|
|
142
|
+
heading,
|
|
143
|
+
tabs,
|
|
144
|
+
hasTabs,
|
|
145
|
+
itemsToRepopulate
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!itemsToRepopulate[qItem.linkId]) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
itemsToRepopulate[qItem.linkId].qItem = qItem;
|
|
157
|
+
itemsToRepopulate[qItem.linkId].heading = heading;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function getPopulatedItemsRecursive(
|
|
161
|
+
qrItem: QuestionnaireResponseItem,
|
|
162
|
+
itemTypes: Record<string, string>
|
|
163
|
+
): QuestionnaireResponseItem[] {
|
|
164
|
+
const itemType = itemTypes[qrItem.linkId];
|
|
165
|
+
if (itemType === 'group' && qrItem.item && qrItem.item.length > 0) {
|
|
166
|
+
const populatedChildItems: QuestionnaireResponseItem[] = [];
|
|
167
|
+
for (const childItem of qrItem.item) {
|
|
168
|
+
populatedChildItems.push(...getPopulatedItemsRecursive(childItem, itemTypes));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return populatedChildItems;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// record item if it is not a group item
|
|
175
|
+
return [qrItem];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function checkCorrespondingOldItemsRecursive(
|
|
179
|
+
qrItem: QuestionnaireResponseItem,
|
|
180
|
+
itemTypes: Record<string, string>,
|
|
181
|
+
itemsToRepopulate: Record<string, ItemToRepopulate>
|
|
182
|
+
): void {
|
|
183
|
+
const itemType = itemTypes[qrItem.linkId];
|
|
184
|
+
if (itemType === 'group' && qrItem.item && qrItem.item.length > 0) {
|
|
185
|
+
for (const childItem of qrItem.item) {
|
|
186
|
+
checkCorrespondingOldItemsRecursive(childItem, itemTypes, itemsToRepopulate);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const oldItem = qrItem;
|
|
193
|
+
const newItem = itemsToRepopulate[qrItem.linkId]?.newQRItem;
|
|
194
|
+
|
|
195
|
+
if (!newItem) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (_isEqual(oldItem, newItem)) {
|
|
200
|
+
delete itemsToRepopulate[qrItem.linkId];
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// const filteredNewItems = newItems.filter((newItem) => !_isEqual(oldItem, newItem));
|
|
205
|
+
|
|
206
|
+
itemsToRepopulate[qrItem.linkId].oldQRItem = oldItem;
|
|
207
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 type { QuestionnaireItem } from 'fhir/r4';
|
|
19
|
+
import type { ItemToRepopulate } from './repopulateItems';
|
|
20
|
+
|
|
21
|
+
export function checkIsRepeatGroupToRepopulate(
|
|
22
|
+
qItem: QuestionnaireItem,
|
|
23
|
+
itemsToRepopulate: Record<string, ItemToRepopulate>
|
|
24
|
+
) {
|
|
25
|
+
if (!qItem.item) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
for (const childItem of qItem.item) {
|
|
30
|
+
if (itemsToRepopulate[childItem.linkId]) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getRepeatGroupToRepopulate(
|
|
37
|
+
qItem: QuestionnaireItem,
|
|
38
|
+
itemsToRepopulate: Record<string, ItemToRepopulate>
|
|
39
|
+
) {
|
|
40
|
+
if (!qItem.item) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const childLinkIds = qItem.item
|
|
45
|
+
.filter((childItem) => !!itemsToRepopulate[childItem.linkId])
|
|
46
|
+
.map((childItem) => childItem.linkId);
|
|
47
|
+
|
|
48
|
+
const childQRItemsToRepopulate = childLinkIds
|
|
49
|
+
.reduce((result: ItemToRepopulate[], linkId) => {
|
|
50
|
+
if (itemsToRepopulate[linkId]) {
|
|
51
|
+
result.push(itemsToRepopulate[linkId]);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}, [])
|
|
55
|
+
.map((itemToRepopulate) => itemToRepopulate.newQRItem);
|
|
56
|
+
|
|
57
|
+
const repeatGroupToRepopulate: ItemToRepopulate = {
|
|
58
|
+
heading: qItem.text ?? null,
|
|
59
|
+
qItem: qItem,
|
|
60
|
+
newQRItem: {
|
|
61
|
+
linkId: qItem.linkId,
|
|
62
|
+
text: qItem.text,
|
|
63
|
+
item: childQRItemsToRepopulate
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return repeatGroupToRepopulate;
|
|
68
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Typography.js","sourceRoot":"","sources":["../../../src/theme/overrides/Typography.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,KAAY;IAC7C,OAAO;QACL,aAAa,EAAE;YACb,cAAc,EAAE;gBACd,SAAS,EAAE;oBACT,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;iBAC/B;gBACD,YAAY,EAAE;oBACZ,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;iBAC/B;aACF;SACF;KACF,CAAC;AACJ,CAAC"}
|
package/lib/utils/isHidden.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { EnableWhenExpression, EnableWhenItems } from '../interfaces/enableWhen.interface';
|
|
2
|
-
import { QuestionnaireItem } from 'fhir/r4';
|
|
3
|
-
export declare function IsHidden(qItem: QuestionnaireItem, enableWhenIsActivated: boolean, enableWhenItems: EnableWhenItems, enableWhenExpressions: Record<string, EnableWhenExpression>): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isHidden.js","sourceRoot":"","sources":["../../src/utils/isHidden.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAIhD,MAAM,UAAU,QAAQ,CACtB,KAAwB,EACxB,qBAA8B,EAC9B,eAAgC,EAChC,qBAA2D;IAE3D,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE;QAC7B,OAAO,IAAI,CAAC;KACb;IAED,OAAO,qBAAqB,CAAC;QAC3B,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,qBAAqB;QACrB,eAAe;QACf,qBAAqB;KACtB,CAAC,CAAC;AACL,CAAC"}
|