@aehrc/smart-forms-renderer 0.2.0 → 0.3.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.
- package/dist/components/FormComponents/Lists.styles.d.ts +1 -1
- package/dist/components/FormRenderer/BaseFormRenderer.d.ts +3 -0
- package/dist/components/FormRenderer/BaseRenderer.d.ts +3 -0
- package/dist/components/FormRenderer/Form.d.ts +3 -0
- package/dist/components/FormRenderer/index.d.ts +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.esm.js +369 -201
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +384 -201
- package/dist/index.js.map +1 -1
- package/dist/utils/removeHidden.d.ts +16 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var React = require('react');
|
|
6
5
|
var zustand = require('zustand');
|
|
7
6
|
var cloneDeep = require('lodash.clonedeep');
|
|
8
7
|
var fhirpath = require('fhirpath');
|
|
9
8
|
var fhirpath_r4_model = require('fhirpath/fhir-context/r4');
|
|
10
9
|
var FHIR = require('fhirclient');
|
|
10
|
+
var React = require('react');
|
|
11
11
|
var material = require('@mui/material');
|
|
12
12
|
var reactQuery = require('@tanstack/react-query');
|
|
13
13
|
var lab = require('@mui/lab');
|
|
@@ -52,11 +52,11 @@ function _interopNamespace(e) {
|
|
|
52
52
|
return Object.freeze(n);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
56
55
|
var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
|
|
57
56
|
var fhirpath__default = /*#__PURE__*/_interopDefaultLegacy(fhirpath);
|
|
58
57
|
var fhirpath_r4_model__default = /*#__PURE__*/_interopDefaultLegacy(fhirpath_r4_model);
|
|
59
58
|
var FHIR__namespace = /*#__PURE__*/_interopNamespace(FHIR);
|
|
59
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
60
60
|
var parse__default = /*#__PURE__*/_interopDefaultLegacy(parse);
|
|
61
61
|
var ReactMarkdown__default = /*#__PURE__*/_interopDefaultLegacy(ReactMarkdown);
|
|
62
62
|
var AddIcon__default = /*#__PURE__*/_interopDefaultLegacy(AddIcon);
|
|
@@ -73,200 +73,6 @@ var RemoveCircleOutlineIcon__default = /*#__PURE__*/_interopDefaultLegacy(Remove
|
|
|
73
73
|
var ExpandMoreIcon__default = /*#__PURE__*/_interopDefaultLegacy(ExpandMoreIcon);
|
|
74
74
|
var useMediaQuery__default = /*#__PURE__*/_interopDefaultLegacy(useMediaQuery);
|
|
75
75
|
|
|
76
|
-
/*
|
|
77
|
-
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
78
|
-
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
79
|
-
*
|
|
80
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
81
|
-
* you may not use this file except in compliance with the License.
|
|
82
|
-
* You may obtain a copy of the License at
|
|
83
|
-
*
|
|
84
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
85
|
-
*
|
|
86
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
87
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
88
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
89
|
-
* See the License for the specific language governing permissions and
|
|
90
|
-
* limitations under the License.
|
|
91
|
-
*/
|
|
92
|
-
/**
|
|
93
|
-
* Create a questionnaireResponse from a given questionnaire form item
|
|
94
|
-
* A questionnaire form item is the first item of a questionnaire
|
|
95
|
-
*
|
|
96
|
-
* @author Sean Fong
|
|
97
|
-
*/
|
|
98
|
-
function createQuestionnaireResponse(questionnaire) {
|
|
99
|
-
var _a;
|
|
100
|
-
const questionnaireResponse = {
|
|
101
|
-
resourceType: 'QuestionnaireResponse',
|
|
102
|
-
status: 'in-progress'
|
|
103
|
-
};
|
|
104
|
-
const firstTopLevelItem = (_a = questionnaire === null || questionnaire === void 0 ? void 0 : questionnaire.item) === null || _a === void 0 ? void 0 : _a[0];
|
|
105
|
-
if (firstTopLevelItem) {
|
|
106
|
-
questionnaireResponse.item = [
|
|
107
|
-
{
|
|
108
|
-
linkId: firstTopLevelItem.linkId,
|
|
109
|
-
text: firstTopLevelItem.text,
|
|
110
|
-
item: []
|
|
111
|
-
}
|
|
112
|
-
];
|
|
113
|
-
}
|
|
114
|
-
if (questionnaire.id) {
|
|
115
|
-
questionnaireResponse.questionnaire = `Questionnaire/${questionnaire.id}`;
|
|
116
|
-
}
|
|
117
|
-
return questionnaireResponse;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Create an empty group qrItem from a given group qItem
|
|
121
|
-
*
|
|
122
|
-
* @author Sean Fong
|
|
123
|
-
*/
|
|
124
|
-
function createQrGroup(qItem) {
|
|
125
|
-
return {
|
|
126
|
-
linkId: qItem.linkId,
|
|
127
|
-
text: qItem.text,
|
|
128
|
-
item: []
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Create an empty qrItem from a given qItem
|
|
133
|
-
*
|
|
134
|
-
* @author Sean Fong
|
|
135
|
-
*/
|
|
136
|
-
function createEmptyQrItem(qItem) {
|
|
137
|
-
return {
|
|
138
|
-
linkId: qItem.linkId,
|
|
139
|
-
text: qItem.text
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Create an empty qrItem from a given qItem with its display unit
|
|
144
|
-
*
|
|
145
|
-
* @author Sean Fong
|
|
146
|
-
*/
|
|
147
|
-
function createEmptyQrItemWithUnit(qItem, unit) {
|
|
148
|
-
return {
|
|
149
|
-
linkId: qItem.linkId,
|
|
150
|
-
text: unit !== '' ? `${qItem.text} (${unit})` : qItem.text
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Updates the QuestionnaireResponseItem group by adding/removing a new/modified child QuestionnaireResponseItem into/from a qrGroup
|
|
155
|
-
* Takes either a single newQrItem or an array of newQrItems
|
|
156
|
-
*
|
|
157
|
-
* @author Sean Fong
|
|
158
|
-
*/
|
|
159
|
-
function updateQrGroup(newQrItem, newQrRepeatGroup, qrGroup, qItemsIndexMap) {
|
|
160
|
-
var _a, _b;
|
|
161
|
-
if (qrGroup['item']) {
|
|
162
|
-
// Get actual sequence indexes of qrItems present within a qrGroup
|
|
163
|
-
// e.g. qrGroup has 4 fields but only the 2nd and 3rd field have values - resulting array is [1, 2]
|
|
164
|
-
const qrItemsRealIndexArr = qrGroup.item.map((qrItem) => qItemsIndexMap[qrItem.linkId]);
|
|
165
|
-
if (newQrItem && newQrItem.linkId in qItemsIndexMap) {
|
|
166
|
-
if (qrGroup.item.length === 0) {
|
|
167
|
-
qrGroup.item.push(newQrItem);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
// Get actual sequence index of qrItem within qrGroup
|
|
171
|
-
const newQrItemIndex = qItemsIndexMap[newQrItem.linkId];
|
|
172
|
-
for (let i = 0; i < qrItemsRealIndexArr.length; i++) {
|
|
173
|
-
// Add qrItem at the end of qrGroup if it is larger than the other indexes
|
|
174
|
-
if (newQrItemIndex > qrItemsRealIndexArr[i]) {
|
|
175
|
-
if (i === qrItemsRealIndexArr.length - 1) {
|
|
176
|
-
qrGroup.item.push(newQrItem);
|
|
177
|
-
}
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
// Replace or delete qrItem at its supposed position if its index is already present within qrGroup
|
|
181
|
-
if (newQrItemIndex === qrItemsRealIndexArr[i]) {
|
|
182
|
-
if (((_a = newQrItem.item) === null || _a === void 0 ? void 0 : _a.length) || ((_b = newQrItem.answer) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
183
|
-
// newQrItem has answer value
|
|
184
|
-
qrGroup.item[i] = newQrItem;
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
// newQrItem has no answer value
|
|
188
|
-
qrGroup.item.splice(i, 1);
|
|
189
|
-
}
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
// Add qrItem at its supposed position if its index is not present within qrGroup
|
|
193
|
-
if (newQrItemIndex < qrItemsRealIndexArr[i]) {
|
|
194
|
-
qrGroup.item.splice(i, 0, newQrItem);
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
else if (newQrRepeatGroup && newQrRepeatGroup.linkId in qItemsIndexMap) {
|
|
201
|
-
const newQrItems = newQrRepeatGroup.qrItems;
|
|
202
|
-
if (qrGroup.item.length === 0) {
|
|
203
|
-
qrGroup.item.push(...newQrItems);
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
// Get actual sequence index of qrItems within qrGroup
|
|
207
|
-
const newQrItemIndex = qItemsIndexMap[newQrRepeatGroup.linkId];
|
|
208
|
-
for (let i = 0; i < qrItemsRealIndexArr.length; i++) {
|
|
209
|
-
// Add qrItem at the end of qrGroup if it is larger than the other indexes
|
|
210
|
-
if (newQrItemIndex > qrItemsRealIndexArr[i]) {
|
|
211
|
-
if (i === qrItemsRealIndexArr.length - 1) {
|
|
212
|
-
qrGroup.item.push(...newQrItems);
|
|
213
|
-
}
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
// Replace or delete qrItem at its supposed position if its index is already present within qrGroup
|
|
217
|
-
if (newQrItemIndex === qrItemsRealIndexArr[i]) {
|
|
218
|
-
// Get number of repeatGroupItems that has the same linkId present in qrGroup
|
|
219
|
-
let repeatGroupItemCount = 0;
|
|
220
|
-
while (newQrItemIndex === qrItemsRealIndexArr[i + repeatGroupItemCount]) {
|
|
221
|
-
repeatGroupItemCount++;
|
|
222
|
-
}
|
|
223
|
-
// Replace each repeat group qrItem with their new counterparts
|
|
224
|
-
if (newQrItems.length === repeatGroupItemCount) {
|
|
225
|
-
for (let j = 0; j < newQrItems.length; j++) {
|
|
226
|
-
qrGroup.item[i + j] = newQrItems[j];
|
|
227
|
-
}
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
else if (newQrItems.length > repeatGroupItemCount) {
|
|
231
|
-
// Replace each repeat group qrItem with their new counterparts,
|
|
232
|
-
// followed by adding an extra newQrItem behind the newly replaced qrItems
|
|
233
|
-
for (let j = 0, k = repeatGroupItemCount; j < newQrItems.length; j++, k--) {
|
|
234
|
-
if (k > 0) {
|
|
235
|
-
qrGroup.item[i + j] = newQrItems[j];
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
qrGroup.item.splice(i + j, 0, newQrItems[j]);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
break;
|
|
242
|
-
}
|
|
243
|
-
else if (newQrItems.length < repeatGroupItemCount) {
|
|
244
|
-
// Replace each repeat group qrItem with their new counterparts (except the last one),
|
|
245
|
-
// followed by deleting the last newQrItem which wasn't replaced
|
|
246
|
-
for (let j = 0; j < repeatGroupItemCount; j++) {
|
|
247
|
-
if (j <= newQrItems.length - 1) {
|
|
248
|
-
qrGroup.item[i + j] = newQrItems[j];
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
qrGroup.item.splice(i + j, 1);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
// Add qrItem at its supposed position if its index is not present within qrGroup
|
|
258
|
-
if (newQrItemIndex < qrItemsRealIndexArr[i]) {
|
|
259
|
-
for (let j = 0; j < newQrItems.length; j++) {
|
|
260
|
-
qrGroup.item.splice(i + j, 0, newQrItems[j]);
|
|
261
|
-
}
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
76
|
/******************************************************************************
|
|
271
77
|
Copyright (c) Microsoft Corporation.
|
|
272
78
|
|
|
@@ -412,7 +218,7 @@ function readInitialAnswers(questionnaireResponse, linkedQuestionsMap) {
|
|
|
412
218
|
return {};
|
|
413
219
|
const initialValuesMap = {};
|
|
414
220
|
questionnaireResponse.item.forEach((item) => {
|
|
415
|
-
readQuestionnaireResponseItemRecursive(item, initialValuesMap, linkedQuestionsMap);
|
|
221
|
+
readQuestionnaireResponseItemRecursive$1(item, initialValuesMap, linkedQuestionsMap);
|
|
416
222
|
});
|
|
417
223
|
return initialValuesMap;
|
|
418
224
|
}
|
|
@@ -421,12 +227,12 @@ function readInitialAnswers(questionnaireResponse, linkedQuestionsMap) {
|
|
|
421
227
|
*
|
|
422
228
|
* @author Sean Fong
|
|
423
229
|
*/
|
|
424
|
-
function readQuestionnaireResponseItemRecursive(item, initialValues, linkedQuestionsMap) {
|
|
230
|
+
function readQuestionnaireResponseItemRecursive$1(item, initialValues, linkedQuestionsMap) {
|
|
425
231
|
const items = item.item;
|
|
426
232
|
if (items && items.length > 0) {
|
|
427
233
|
// iterate through items of item recursively
|
|
428
234
|
items.forEach((item) => {
|
|
429
|
-
readQuestionnaireResponseItemRecursive(item, initialValues, linkedQuestionsMap);
|
|
235
|
+
readQuestionnaireResponseItemRecursive$1(item, initialValues, linkedQuestionsMap);
|
|
430
236
|
});
|
|
431
237
|
return;
|
|
432
238
|
}
|
|
@@ -3591,6 +3397,200 @@ function mapQItemsIndex(qGroup) {
|
|
|
3591
3397
|
}, {});
|
|
3592
3398
|
}
|
|
3593
3399
|
|
|
3400
|
+
/*
|
|
3401
|
+
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
3402
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
3403
|
+
*
|
|
3404
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3405
|
+
* you may not use this file except in compliance with the License.
|
|
3406
|
+
* You may obtain a copy of the License at
|
|
3407
|
+
*
|
|
3408
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3409
|
+
*
|
|
3410
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
3411
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3412
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3413
|
+
* See the License for the specific language governing permissions and
|
|
3414
|
+
* limitations under the License.
|
|
3415
|
+
*/
|
|
3416
|
+
/**
|
|
3417
|
+
* Create a questionnaireResponse from a given questionnaire form item
|
|
3418
|
+
* A questionnaire form item is the first item of a questionnaire
|
|
3419
|
+
*
|
|
3420
|
+
* @author Sean Fong
|
|
3421
|
+
*/
|
|
3422
|
+
function createQuestionnaireResponse(questionnaire) {
|
|
3423
|
+
var _a;
|
|
3424
|
+
const questionnaireResponse = {
|
|
3425
|
+
resourceType: 'QuestionnaireResponse',
|
|
3426
|
+
status: 'in-progress'
|
|
3427
|
+
};
|
|
3428
|
+
const firstTopLevelItem = (_a = questionnaire === null || questionnaire === void 0 ? void 0 : questionnaire.item) === null || _a === void 0 ? void 0 : _a[0];
|
|
3429
|
+
if (firstTopLevelItem) {
|
|
3430
|
+
questionnaireResponse.item = [
|
|
3431
|
+
{
|
|
3432
|
+
linkId: firstTopLevelItem.linkId,
|
|
3433
|
+
text: firstTopLevelItem.text,
|
|
3434
|
+
item: []
|
|
3435
|
+
}
|
|
3436
|
+
];
|
|
3437
|
+
}
|
|
3438
|
+
if (questionnaire.id) {
|
|
3439
|
+
questionnaireResponse.questionnaire = `Questionnaire/${questionnaire.id}`;
|
|
3440
|
+
}
|
|
3441
|
+
return questionnaireResponse;
|
|
3442
|
+
}
|
|
3443
|
+
/**
|
|
3444
|
+
* Create an empty group qrItem from a given group qItem
|
|
3445
|
+
*
|
|
3446
|
+
* @author Sean Fong
|
|
3447
|
+
*/
|
|
3448
|
+
function createQrGroup(qItem) {
|
|
3449
|
+
return {
|
|
3450
|
+
linkId: qItem.linkId,
|
|
3451
|
+
text: qItem.text,
|
|
3452
|
+
item: []
|
|
3453
|
+
};
|
|
3454
|
+
}
|
|
3455
|
+
/**
|
|
3456
|
+
* Create an empty qrItem from a given qItem
|
|
3457
|
+
*
|
|
3458
|
+
* @author Sean Fong
|
|
3459
|
+
*/
|
|
3460
|
+
function createEmptyQrItem(qItem) {
|
|
3461
|
+
return {
|
|
3462
|
+
linkId: qItem.linkId,
|
|
3463
|
+
text: qItem.text
|
|
3464
|
+
};
|
|
3465
|
+
}
|
|
3466
|
+
/**
|
|
3467
|
+
* Create an empty qrItem from a given qItem with its display unit
|
|
3468
|
+
*
|
|
3469
|
+
* @author Sean Fong
|
|
3470
|
+
*/
|
|
3471
|
+
function createEmptyQrItemWithUnit(qItem, unit) {
|
|
3472
|
+
return {
|
|
3473
|
+
linkId: qItem.linkId,
|
|
3474
|
+
text: unit !== '' ? `${qItem.text} (${unit})` : qItem.text
|
|
3475
|
+
};
|
|
3476
|
+
}
|
|
3477
|
+
/**
|
|
3478
|
+
* Updates the QuestionnaireResponseItem group by adding/removing a new/modified child QuestionnaireResponseItem into/from a qrGroup
|
|
3479
|
+
* Takes either a single newQrItem or an array of newQrItems
|
|
3480
|
+
*
|
|
3481
|
+
* @author Sean Fong
|
|
3482
|
+
*/
|
|
3483
|
+
function updateQrGroup(newQrItem, newQrRepeatGroup, qrGroup, qItemsIndexMap) {
|
|
3484
|
+
var _a, _b;
|
|
3485
|
+
if (qrGroup['item']) {
|
|
3486
|
+
// Get actual sequence indexes of qrItems present within a qrGroup
|
|
3487
|
+
// e.g. qrGroup has 4 fields but only the 2nd and 3rd field have values - resulting array is [1, 2]
|
|
3488
|
+
const qrItemsRealIndexArr = qrGroup.item.map((qrItem) => qItemsIndexMap[qrItem.linkId]);
|
|
3489
|
+
if (newQrItem && newQrItem.linkId in qItemsIndexMap) {
|
|
3490
|
+
if (qrGroup.item.length === 0) {
|
|
3491
|
+
qrGroup.item.push(newQrItem);
|
|
3492
|
+
}
|
|
3493
|
+
else {
|
|
3494
|
+
// Get actual sequence index of qrItem within qrGroup
|
|
3495
|
+
const newQrItemIndex = qItemsIndexMap[newQrItem.linkId];
|
|
3496
|
+
for (let i = 0; i < qrItemsRealIndexArr.length; i++) {
|
|
3497
|
+
// Add qrItem at the end of qrGroup if it is larger than the other indexes
|
|
3498
|
+
if (newQrItemIndex > qrItemsRealIndexArr[i]) {
|
|
3499
|
+
if (i === qrItemsRealIndexArr.length - 1) {
|
|
3500
|
+
qrGroup.item.push(newQrItem);
|
|
3501
|
+
}
|
|
3502
|
+
continue;
|
|
3503
|
+
}
|
|
3504
|
+
// Replace or delete qrItem at its supposed position if its index is already present within qrGroup
|
|
3505
|
+
if (newQrItemIndex === qrItemsRealIndexArr[i]) {
|
|
3506
|
+
if (((_a = newQrItem.item) === null || _a === void 0 ? void 0 : _a.length) || ((_b = newQrItem.answer) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
3507
|
+
// newQrItem has answer value
|
|
3508
|
+
qrGroup.item[i] = newQrItem;
|
|
3509
|
+
}
|
|
3510
|
+
else {
|
|
3511
|
+
// newQrItem has no answer value
|
|
3512
|
+
qrGroup.item.splice(i, 1);
|
|
3513
|
+
}
|
|
3514
|
+
break;
|
|
3515
|
+
}
|
|
3516
|
+
// Add qrItem at its supposed position if its index is not present within qrGroup
|
|
3517
|
+
if (newQrItemIndex < qrItemsRealIndexArr[i]) {
|
|
3518
|
+
qrGroup.item.splice(i, 0, newQrItem);
|
|
3519
|
+
break;
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
else if (newQrRepeatGroup && newQrRepeatGroup.linkId in qItemsIndexMap) {
|
|
3525
|
+
const newQrItems = newQrRepeatGroup.qrItems;
|
|
3526
|
+
if (qrGroup.item.length === 0) {
|
|
3527
|
+
qrGroup.item.push(...newQrItems);
|
|
3528
|
+
}
|
|
3529
|
+
else {
|
|
3530
|
+
// Get actual sequence index of qrItems within qrGroup
|
|
3531
|
+
const newQrItemIndex = qItemsIndexMap[newQrRepeatGroup.linkId];
|
|
3532
|
+
for (let i = 0; i < qrItemsRealIndexArr.length; i++) {
|
|
3533
|
+
// Add qrItem at the end of qrGroup if it is larger than the other indexes
|
|
3534
|
+
if (newQrItemIndex > qrItemsRealIndexArr[i]) {
|
|
3535
|
+
if (i === qrItemsRealIndexArr.length - 1) {
|
|
3536
|
+
qrGroup.item.push(...newQrItems);
|
|
3537
|
+
}
|
|
3538
|
+
continue;
|
|
3539
|
+
}
|
|
3540
|
+
// Replace or delete qrItem at its supposed position if its index is already present within qrGroup
|
|
3541
|
+
if (newQrItemIndex === qrItemsRealIndexArr[i]) {
|
|
3542
|
+
// Get number of repeatGroupItems that has the same linkId present in qrGroup
|
|
3543
|
+
let repeatGroupItemCount = 0;
|
|
3544
|
+
while (newQrItemIndex === qrItemsRealIndexArr[i + repeatGroupItemCount]) {
|
|
3545
|
+
repeatGroupItemCount++;
|
|
3546
|
+
}
|
|
3547
|
+
// Replace each repeat group qrItem with their new counterparts
|
|
3548
|
+
if (newQrItems.length === repeatGroupItemCount) {
|
|
3549
|
+
for (let j = 0; j < newQrItems.length; j++) {
|
|
3550
|
+
qrGroup.item[i + j] = newQrItems[j];
|
|
3551
|
+
}
|
|
3552
|
+
break;
|
|
3553
|
+
}
|
|
3554
|
+
else if (newQrItems.length > repeatGroupItemCount) {
|
|
3555
|
+
// Replace each repeat group qrItem with their new counterparts,
|
|
3556
|
+
// followed by adding an extra newQrItem behind the newly replaced qrItems
|
|
3557
|
+
for (let j = 0, k = repeatGroupItemCount; j < newQrItems.length; j++, k--) {
|
|
3558
|
+
if (k > 0) {
|
|
3559
|
+
qrGroup.item[i + j] = newQrItems[j];
|
|
3560
|
+
}
|
|
3561
|
+
else {
|
|
3562
|
+
qrGroup.item.splice(i + j, 0, newQrItems[j]);
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
break;
|
|
3566
|
+
}
|
|
3567
|
+
else if (newQrItems.length < repeatGroupItemCount) {
|
|
3568
|
+
// Replace each repeat group qrItem with their new counterparts (except the last one),
|
|
3569
|
+
// followed by deleting the last newQrItem which wasn't replaced
|
|
3570
|
+
for (let j = 0; j < repeatGroupItemCount; j++) {
|
|
3571
|
+
if (j <= newQrItems.length - 1) {
|
|
3572
|
+
qrGroup.item[i + j] = newQrItems[j];
|
|
3573
|
+
}
|
|
3574
|
+
else {
|
|
3575
|
+
qrGroup.item.splice(i + j, 1);
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
break;
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
// Add qrItem at its supposed position if its index is not present within qrGroup
|
|
3582
|
+
if (newQrItemIndex < qrItemsRealIndexArr[i]) {
|
|
3583
|
+
for (let j = 0; j < newQrItems.length; j++) {
|
|
3584
|
+
qrGroup.item.splice(i + j, 0, newQrItems[j]);
|
|
3585
|
+
}
|
|
3586
|
+
break;
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3594
3594
|
/*
|
|
3595
3595
|
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
3596
3596
|
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
@@ -4867,6 +4867,109 @@ const useQuestionnaireResponseStore = zustand.create()((set) => ({
|
|
|
4867
4867
|
}))
|
|
4868
4868
|
}));
|
|
4869
4869
|
|
|
4870
|
+
/*
|
|
4871
|
+
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
4872
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4873
|
+
*
|
|
4874
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4875
|
+
* you may not use this file except in compliance with the License.
|
|
4876
|
+
* You may obtain a copy of the License at
|
|
4877
|
+
*
|
|
4878
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4879
|
+
*
|
|
4880
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
4881
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4882
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4883
|
+
* See the License for the specific language governing permissions and
|
|
4884
|
+
* limitations under the License.
|
|
4885
|
+
*/
|
|
4886
|
+
/**
|
|
4887
|
+
* Recursively go through the questionnaireResponse and remove qrItems whose qItems are hidden in the form
|
|
4888
|
+
*
|
|
4889
|
+
* @author Sean Fong
|
|
4890
|
+
*/
|
|
4891
|
+
function removeHiddenAnswers(params) {
|
|
4892
|
+
const { questionnaire, questionnaireResponse, enableWhenIsActivated, enableWhenItems, enableWhenExpressions } = params;
|
|
4893
|
+
const topLevelQItems = questionnaire.item;
|
|
4894
|
+
const topLevelQRItems = questionnaireResponse.item;
|
|
4895
|
+
if (!topLevelQItems ||
|
|
4896
|
+
topLevelQItems.length === 0 ||
|
|
4897
|
+
!topLevelQRItems ||
|
|
4898
|
+
topLevelQRItems.length === 0) {
|
|
4899
|
+
return questionnaireResponse;
|
|
4900
|
+
}
|
|
4901
|
+
topLevelQRItems.forEach((qrItem, i) => {
|
|
4902
|
+
const qItem = topLevelQItems[i];
|
|
4903
|
+
const newTopLevelQRItem = readQuestionnaireResponseItemRecursive({
|
|
4904
|
+
qItem,
|
|
4905
|
+
qrItem,
|
|
4906
|
+
enableWhenIsActivated,
|
|
4907
|
+
enableWhenItems,
|
|
4908
|
+
enableWhenExpressions
|
|
4909
|
+
});
|
|
4910
|
+
if (newTopLevelQRItem && questionnaireResponse.item) {
|
|
4911
|
+
questionnaireResponse.item[i] = Object.assign({}, newTopLevelQRItem);
|
|
4912
|
+
}
|
|
4913
|
+
});
|
|
4914
|
+
return questionnaireResponse;
|
|
4915
|
+
}
|
|
4916
|
+
function readQuestionnaireResponseItemRecursive(params) {
|
|
4917
|
+
const { qItem, qrItem, enableWhenIsActivated, enableWhenItems, enableWhenExpressions } = params;
|
|
4918
|
+
const qItems = qItem.item;
|
|
4919
|
+
const qrItems = qrItem.item;
|
|
4920
|
+
// Process group items
|
|
4921
|
+
if (qItems && qItems.length > 0) {
|
|
4922
|
+
// Return nothing if corresponding qItem is hidden
|
|
4923
|
+
if (isHidden({
|
|
4924
|
+
questionnaireItem: qItem,
|
|
4925
|
+
enableWhenIsActivated,
|
|
4926
|
+
enableWhenItems,
|
|
4927
|
+
enableWhenExpressions
|
|
4928
|
+
}))
|
|
4929
|
+
return null;
|
|
4930
|
+
if (qrItems && qrItems.length > 0) {
|
|
4931
|
+
const newQrItems = [];
|
|
4932
|
+
// Loop over qItems - but end loop if we either reach the end of qItems or qrItems
|
|
4933
|
+
// Under normal circumstances we will reach the end of both arrays together
|
|
4934
|
+
for (let qItemIndex = 0, qrItemIndex = 0; qItemIndex < qItems.length || qrItemIndex < qrItems.length; qItemIndex++) {
|
|
4935
|
+
// Save qrItem if linkIds of current qItem and qrItem are the same
|
|
4936
|
+
if (qrItems[qrItemIndex] && qItems[qItemIndex].linkId === qrItems[qrItemIndex].linkId) {
|
|
4937
|
+
const newQrItem = readQuestionnaireResponseItemRecursive({
|
|
4938
|
+
qItem: qItems[qItemIndex],
|
|
4939
|
+
qrItem: qrItems[qrItemIndex],
|
|
4940
|
+
enableWhenIsActivated,
|
|
4941
|
+
enableWhenItems,
|
|
4942
|
+
enableWhenExpressions
|
|
4943
|
+
});
|
|
4944
|
+
if (newQrItem) {
|
|
4945
|
+
newQrItems.push(newQrItem);
|
|
4946
|
+
}
|
|
4947
|
+
// Decrement qItem index if the next qrItem is an answer from a repeatGroup
|
|
4948
|
+
// Essentially persisting the current qItem linked to be matched up with the next qrItem linkId
|
|
4949
|
+
if (qrItems.length !== qrItemIndex + 1 &&
|
|
4950
|
+
qrItems[qrItemIndex].linkId === qrItems[qrItemIndex + 1].linkId) {
|
|
4951
|
+
qItemIndex--;
|
|
4952
|
+
}
|
|
4953
|
+
// Only Increment qrItem index whenever the current qrItem linkId matches up with the current qItem
|
|
4954
|
+
qrItemIndex++;
|
|
4955
|
+
}
|
|
4956
|
+
}
|
|
4957
|
+
return Object.assign(Object.assign({}, qrItem), { item: newQrItems });
|
|
4958
|
+
}
|
|
4959
|
+
// Also perform checking if answer exists
|
|
4960
|
+
return qrItem['answer'] ? qrItem : null;
|
|
4961
|
+
}
|
|
4962
|
+
// Process non-group items
|
|
4963
|
+
return isHidden({
|
|
4964
|
+
questionnaireItem: qItem,
|
|
4965
|
+
enableWhenIsActivated,
|
|
4966
|
+
enableWhenItems,
|
|
4967
|
+
enableWhenExpressions
|
|
4968
|
+
})
|
|
4969
|
+
? null
|
|
4970
|
+
: Object.assign({}, qrItem);
|
|
4971
|
+
}
|
|
4972
|
+
|
|
4870
4973
|
/*
|
|
4871
4974
|
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
4872
4975
|
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
@@ -10455,7 +10558,7 @@ function FormTopLevelItem(props) {
|
|
|
10455
10558
|
* See the License for the specific language governing permissions and
|
|
10456
10559
|
* limitations under the License.
|
|
10457
10560
|
*/
|
|
10458
|
-
function
|
|
10561
|
+
function BaseRenderer() {
|
|
10459
10562
|
const sourceQuestionnaire = useQuestionnaireStore((state) => state.sourceQuestionnaire);
|
|
10460
10563
|
const updateExpressions = useQuestionnaireStore((state) => state.updateExpressions);
|
|
10461
10564
|
const updatableResponse = useQuestionnaireResponseStore((state) => state.updatableResponse);
|
|
@@ -10520,8 +10623,88 @@ function SmartFormsRenderer(props) {
|
|
|
10520
10623
|
React__default["default"].createElement(material.Typography, null, "Loading questionnaire...")));
|
|
10521
10624
|
}
|
|
10522
10625
|
return (React__default["default"].createElement(reactQuery.QueryClientProvider, { client: queryClient },
|
|
10523
|
-
React__default["default"].createElement(
|
|
10626
|
+
React__default["default"].createElement(BaseRenderer, null)));
|
|
10627
|
+
}
|
|
10628
|
+
|
|
10629
|
+
function useSourceQuestionnaire() {
|
|
10630
|
+
return useQuestionnaireStore.getState().sourceQuestionnaire;
|
|
10631
|
+
}
|
|
10632
|
+
function useSourceResponse() {
|
|
10633
|
+
return useQuestionnaireResponseStore.getState().sourceResponse;
|
|
10634
|
+
}
|
|
10635
|
+
function useUpdatableResponse() {
|
|
10636
|
+
return useQuestionnaireResponseStore.getState().updatableResponse;
|
|
10637
|
+
}
|
|
10638
|
+
function useFormHasChanges() {
|
|
10639
|
+
return useQuestionnaireResponseStore.getState().hasChanges;
|
|
10640
|
+
}
|
|
10641
|
+
function useEnableWhenActivated() {
|
|
10642
|
+
return useQuestionnaireStore.getState().enableWhenIsActivated;
|
|
10643
|
+
}
|
|
10644
|
+
function setSourceQuestionnaire(questionnaire) {
|
|
10645
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10646
|
+
yield useQuestionnaireStore.getState().buildSourceQuestionnaire(questionnaire);
|
|
10647
|
+
});
|
|
10648
|
+
}
|
|
10649
|
+
function buildForm(questionnaire, questionnaireResponse) {
|
|
10650
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10651
|
+
yield useQuestionnaireStore.getState().buildSourceQuestionnaire(questionnaire);
|
|
10652
|
+
if (!questionnaireResponse) {
|
|
10653
|
+
useQuestionnaireResponseStore
|
|
10654
|
+
.getState()
|
|
10655
|
+
.buildSourceResponse(createQuestionnaireResponse(questionnaire));
|
|
10656
|
+
return;
|
|
10657
|
+
}
|
|
10658
|
+
useQuestionnaireResponseStore.getState().buildSourceResponse(questionnaireResponse);
|
|
10659
|
+
useQuestionnaireStore.getState().updatePopulatedProperties(questionnaireResponse);
|
|
10660
|
+
});
|
|
10661
|
+
}
|
|
10662
|
+
function destroyForm() {
|
|
10663
|
+
useQuestionnaireStore.getState().destroySourceQuestionnaire();
|
|
10664
|
+
useQuestionnaireResponseStore.getState().destroySourceResponse();
|
|
10665
|
+
}
|
|
10666
|
+
function setEnableWhenActivation(isActivated) {
|
|
10667
|
+
useQuestionnaireStore.getState().toggleEnableWhenActivation(isActivated);
|
|
10668
|
+
}
|
|
10669
|
+
function setPopulatedResponse(populatedResponse) {
|
|
10670
|
+
const updatedResponse = useQuestionnaireStore
|
|
10671
|
+
.getState()
|
|
10672
|
+
.updatePopulatedProperties(populatedResponse);
|
|
10673
|
+
useQuestionnaireResponseStore.getState().populateResponse(updatedResponse);
|
|
10674
|
+
}
|
|
10675
|
+
function setEmptyResponse(emptyResponse) {
|
|
10676
|
+
return useQuestionnaireResponseStore.getState().clearResponse(emptyResponse);
|
|
10677
|
+
}
|
|
10678
|
+
function setSavedResponse(savedResponse) {
|
|
10679
|
+
return useQuestionnaireResponseStore.getState().saveResponse(savedResponse);
|
|
10680
|
+
}
|
|
10681
|
+
function removeHiddenAnswersFromResponse(questionnaire, questionnaireResponse) {
|
|
10682
|
+
const enableWhenIsActivated = useQuestionnaireStore.getState().enableWhenIsActivated;
|
|
10683
|
+
const enableWhenItems = useQuestionnaireStore.getState().enableWhenItems;
|
|
10684
|
+
const enableWhenExpressions = useQuestionnaireStore.getState().enableWhenExpressions;
|
|
10685
|
+
return removeHiddenAnswers({
|
|
10686
|
+
questionnaire,
|
|
10687
|
+
questionnaireResponse,
|
|
10688
|
+
enableWhenIsActivated,
|
|
10689
|
+
enableWhenItems,
|
|
10690
|
+
enableWhenExpressions
|
|
10691
|
+
});
|
|
10524
10692
|
}
|
|
10525
10693
|
|
|
10694
|
+
exports.BaseRenderer = BaseRenderer;
|
|
10526
10695
|
exports.SmartFormsRenderer = SmartFormsRenderer;
|
|
10696
|
+
exports.buildForm = buildForm;
|
|
10697
|
+
exports.destroyForm = destroyForm;
|
|
10698
|
+
exports.removeHiddenAnswersFromResponse = removeHiddenAnswersFromResponse;
|
|
10699
|
+
exports.setEmptyResponse = setEmptyResponse;
|
|
10700
|
+
exports.setEnableWhenActivation = setEnableWhenActivation;
|
|
10701
|
+
exports.setPopulatedResponse = setPopulatedResponse;
|
|
10702
|
+
exports.setSavedResponse = setSavedResponse;
|
|
10703
|
+
exports.setSourceQuestionnaire = setSourceQuestionnaire;
|
|
10704
|
+
exports.useEnableWhenActivated = useEnableWhenActivated;
|
|
10705
|
+
exports.useFormHasChanges = useFormHasChanges;
|
|
10706
|
+
exports.useHidden = useHidden;
|
|
10707
|
+
exports.useSourceQuestionnaire = useSourceQuestionnaire;
|
|
10708
|
+
exports.useSourceResponse = useSourceResponse;
|
|
10709
|
+
exports.useUpdatableResponse = useUpdatableResponse;
|
|
10527
10710
|
//# sourceMappingURL=index.js.map
|