@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
|
@@ -8,4 +8,4 @@ export declare const PrimarySelectableList: import("@emotion/styled").StyledComp
|
|
|
8
8
|
sx?: import("@mui/material").SxProps<import("@mui/material").Theme>;
|
|
9
9
|
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLUListElement>, HTMLUListElement>, "ref"> & {
|
|
10
10
|
ref?: import("react").Ref<HTMLUListElement>;
|
|
11
|
-
}, "children" | "sx" | keyof import("@mui/material/OverridableComponent").CommonProps | "
|
|
11
|
+
}, "children" | "sx" | "dense" | keyof import("@mui/material/OverridableComponent").CommonProps | "disablePadding" | "subheader"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useHidden } from './useHidden';
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
+
import type { Questionnaire, QuestionnaireResponse } from 'fhir/r4';
|
|
1
2
|
export * from './components';
|
|
3
|
+
export * from './hooks';
|
|
4
|
+
export declare function useSourceQuestionnaire(): Questionnaire;
|
|
5
|
+
export declare function useSourceResponse(): QuestionnaireResponse;
|
|
6
|
+
export declare function useUpdatableResponse(): QuestionnaireResponse;
|
|
7
|
+
export declare function useFormHasChanges(): boolean;
|
|
8
|
+
export declare function useEnableWhenActivated(): boolean;
|
|
9
|
+
export declare function setSourceQuestionnaire(questionnaire: Questionnaire): Promise<void>;
|
|
10
|
+
export declare function buildForm(questionnaire: Questionnaire, questionnaireResponse?: QuestionnaireResponse): Promise<void>;
|
|
11
|
+
export declare function destroyForm(): void;
|
|
12
|
+
export declare function setEnableWhenActivation(isActivated: boolean): void;
|
|
13
|
+
export declare function setPopulatedResponse(populatedResponse: QuestionnaireResponse): void;
|
|
14
|
+
export declare function setEmptyResponse(emptyResponse: QuestionnaireResponse): void;
|
|
15
|
+
export declare function setSavedResponse(savedResponse: QuestionnaireResponse): void;
|
|
16
|
+
export declare function removeHiddenAnswersFromResponse(questionnaire: Questionnaire, questionnaireResponse: QuestionnaireResponse): QuestionnaireResponse;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, { useState, useLayoutEffect, memo, forwardRef, Fragment as Fragment$1, useEffect, useMemo, useCallback, Children, isValidElement, cloneElement } from 'react';
|
|
2
1
|
import { create } from 'zustand';
|
|
3
2
|
import cloneDeep from 'lodash.clonedeep';
|
|
4
3
|
import fhirpath from 'fhirpath';
|
|
5
4
|
import fhirpath_r4_model from 'fhirpath/fhir-context/r4';
|
|
6
5
|
import * as FHIR from 'fhirclient';
|
|
6
|
+
import React, { useState, useLayoutEffect, memo, forwardRef, Fragment as Fragment$1, useEffect, useMemo, useCallback, Children, isValidElement, cloneElement } from 'react';
|
|
7
7
|
import { styled, Box, Typography, FormGroup, RadioGroup, Divider, Card, Button, FormControlLabel, Radio, Grid, Select, InputAdornment, MenuItem, Checkbox, TextField as TextField$1, Autocomplete, CircularProgress, Fade, Tooltip, ListItemIcon, TableCell, IconButton, TableContainer, Paper, Table, Stack as Stack$1, TableHead, TableRow, TableBody, Collapse, List, ListItemButton, ListItemText, Accordion, AccordionSummary, AccordionDetails, Container } from '@mui/material';
|
|
8
8
|
import { QueryClient, useQuery, QueryClientProvider } from '@tanstack/react-query';
|
|
9
9
|
import { TabContext, TabPanel } from '@mui/lab';
|
|
@@ -28,200 +28,6 @@ import RemoveCircleOutlineIcon from '@mui/icons-material/RemoveCircleOutline';
|
|
|
28
28
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
29
29
|
import useMediaQuery from '@mui/material/useMediaQuery';
|
|
30
30
|
|
|
31
|
-
/*
|
|
32
|
-
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
33
|
-
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
34
|
-
*
|
|
35
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
36
|
-
* you may not use this file except in compliance with the License.
|
|
37
|
-
* You may obtain a copy of the License at
|
|
38
|
-
*
|
|
39
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
40
|
-
*
|
|
41
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
42
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
43
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
44
|
-
* See the License for the specific language governing permissions and
|
|
45
|
-
* limitations under the License.
|
|
46
|
-
*/
|
|
47
|
-
/**
|
|
48
|
-
* Create a questionnaireResponse from a given questionnaire form item
|
|
49
|
-
* A questionnaire form item is the first item of a questionnaire
|
|
50
|
-
*
|
|
51
|
-
* @author Sean Fong
|
|
52
|
-
*/
|
|
53
|
-
function createQuestionnaireResponse(questionnaire) {
|
|
54
|
-
var _a;
|
|
55
|
-
const questionnaireResponse = {
|
|
56
|
-
resourceType: 'QuestionnaireResponse',
|
|
57
|
-
status: 'in-progress'
|
|
58
|
-
};
|
|
59
|
-
const firstTopLevelItem = (_a = questionnaire === null || questionnaire === void 0 ? void 0 : questionnaire.item) === null || _a === void 0 ? void 0 : _a[0];
|
|
60
|
-
if (firstTopLevelItem) {
|
|
61
|
-
questionnaireResponse.item = [
|
|
62
|
-
{
|
|
63
|
-
linkId: firstTopLevelItem.linkId,
|
|
64
|
-
text: firstTopLevelItem.text,
|
|
65
|
-
item: []
|
|
66
|
-
}
|
|
67
|
-
];
|
|
68
|
-
}
|
|
69
|
-
if (questionnaire.id) {
|
|
70
|
-
questionnaireResponse.questionnaire = `Questionnaire/${questionnaire.id}`;
|
|
71
|
-
}
|
|
72
|
-
return questionnaireResponse;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Create an empty group qrItem from a given group qItem
|
|
76
|
-
*
|
|
77
|
-
* @author Sean Fong
|
|
78
|
-
*/
|
|
79
|
-
function createQrGroup(qItem) {
|
|
80
|
-
return {
|
|
81
|
-
linkId: qItem.linkId,
|
|
82
|
-
text: qItem.text,
|
|
83
|
-
item: []
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Create an empty qrItem from a given qItem
|
|
88
|
-
*
|
|
89
|
-
* @author Sean Fong
|
|
90
|
-
*/
|
|
91
|
-
function createEmptyQrItem(qItem) {
|
|
92
|
-
return {
|
|
93
|
-
linkId: qItem.linkId,
|
|
94
|
-
text: qItem.text
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Create an empty qrItem from a given qItem with its display unit
|
|
99
|
-
*
|
|
100
|
-
* @author Sean Fong
|
|
101
|
-
*/
|
|
102
|
-
function createEmptyQrItemWithUnit(qItem, unit) {
|
|
103
|
-
return {
|
|
104
|
-
linkId: qItem.linkId,
|
|
105
|
-
text: unit !== '' ? `${qItem.text} (${unit})` : qItem.text
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Updates the QuestionnaireResponseItem group by adding/removing a new/modified child QuestionnaireResponseItem into/from a qrGroup
|
|
110
|
-
* Takes either a single newQrItem or an array of newQrItems
|
|
111
|
-
*
|
|
112
|
-
* @author Sean Fong
|
|
113
|
-
*/
|
|
114
|
-
function updateQrGroup(newQrItem, newQrRepeatGroup, qrGroup, qItemsIndexMap) {
|
|
115
|
-
var _a, _b;
|
|
116
|
-
if (qrGroup['item']) {
|
|
117
|
-
// Get actual sequence indexes of qrItems present within a qrGroup
|
|
118
|
-
// e.g. qrGroup has 4 fields but only the 2nd and 3rd field have values - resulting array is [1, 2]
|
|
119
|
-
const qrItemsRealIndexArr = qrGroup.item.map((qrItem) => qItemsIndexMap[qrItem.linkId]);
|
|
120
|
-
if (newQrItem && newQrItem.linkId in qItemsIndexMap) {
|
|
121
|
-
if (qrGroup.item.length === 0) {
|
|
122
|
-
qrGroup.item.push(newQrItem);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
// Get actual sequence index of qrItem within qrGroup
|
|
126
|
-
const newQrItemIndex = qItemsIndexMap[newQrItem.linkId];
|
|
127
|
-
for (let i = 0; i < qrItemsRealIndexArr.length; i++) {
|
|
128
|
-
// Add qrItem at the end of qrGroup if it is larger than the other indexes
|
|
129
|
-
if (newQrItemIndex > qrItemsRealIndexArr[i]) {
|
|
130
|
-
if (i === qrItemsRealIndexArr.length - 1) {
|
|
131
|
-
qrGroup.item.push(newQrItem);
|
|
132
|
-
}
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
// Replace or delete qrItem at its supposed position if its index is already present within qrGroup
|
|
136
|
-
if (newQrItemIndex === qrItemsRealIndexArr[i]) {
|
|
137
|
-
if (((_a = newQrItem.item) === null || _a === void 0 ? void 0 : _a.length) || ((_b = newQrItem.answer) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
138
|
-
// newQrItem has answer value
|
|
139
|
-
qrGroup.item[i] = newQrItem;
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
// newQrItem has no answer value
|
|
143
|
-
qrGroup.item.splice(i, 1);
|
|
144
|
-
}
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
// Add qrItem at its supposed position if its index is not present within qrGroup
|
|
148
|
-
if (newQrItemIndex < qrItemsRealIndexArr[i]) {
|
|
149
|
-
qrGroup.item.splice(i, 0, newQrItem);
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
else if (newQrRepeatGroup && newQrRepeatGroup.linkId in qItemsIndexMap) {
|
|
156
|
-
const newQrItems = newQrRepeatGroup.qrItems;
|
|
157
|
-
if (qrGroup.item.length === 0) {
|
|
158
|
-
qrGroup.item.push(...newQrItems);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
// Get actual sequence index of qrItems within qrGroup
|
|
162
|
-
const newQrItemIndex = qItemsIndexMap[newQrRepeatGroup.linkId];
|
|
163
|
-
for (let i = 0; i < qrItemsRealIndexArr.length; i++) {
|
|
164
|
-
// Add qrItem at the end of qrGroup if it is larger than the other indexes
|
|
165
|
-
if (newQrItemIndex > qrItemsRealIndexArr[i]) {
|
|
166
|
-
if (i === qrItemsRealIndexArr.length - 1) {
|
|
167
|
-
qrGroup.item.push(...newQrItems);
|
|
168
|
-
}
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
// Replace or delete qrItem at its supposed position if its index is already present within qrGroup
|
|
172
|
-
if (newQrItemIndex === qrItemsRealIndexArr[i]) {
|
|
173
|
-
// Get number of repeatGroupItems that has the same linkId present in qrGroup
|
|
174
|
-
let repeatGroupItemCount = 0;
|
|
175
|
-
while (newQrItemIndex === qrItemsRealIndexArr[i + repeatGroupItemCount]) {
|
|
176
|
-
repeatGroupItemCount++;
|
|
177
|
-
}
|
|
178
|
-
// Replace each repeat group qrItem with their new counterparts
|
|
179
|
-
if (newQrItems.length === repeatGroupItemCount) {
|
|
180
|
-
for (let j = 0; j < newQrItems.length; j++) {
|
|
181
|
-
qrGroup.item[i + j] = newQrItems[j];
|
|
182
|
-
}
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
else if (newQrItems.length > repeatGroupItemCount) {
|
|
186
|
-
// Replace each repeat group qrItem with their new counterparts,
|
|
187
|
-
// followed by adding an extra newQrItem behind the newly replaced qrItems
|
|
188
|
-
for (let j = 0, k = repeatGroupItemCount; j < newQrItems.length; j++, k--) {
|
|
189
|
-
if (k > 0) {
|
|
190
|
-
qrGroup.item[i + j] = newQrItems[j];
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
qrGroup.item.splice(i + j, 0, newQrItems[j]);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
else if (newQrItems.length < repeatGroupItemCount) {
|
|
199
|
-
// Replace each repeat group qrItem with their new counterparts (except the last one),
|
|
200
|
-
// followed by deleting the last newQrItem which wasn't replaced
|
|
201
|
-
for (let j = 0; j < repeatGroupItemCount; j++) {
|
|
202
|
-
if (j <= newQrItems.length - 1) {
|
|
203
|
-
qrGroup.item[i + j] = newQrItems[j];
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
qrGroup.item.splice(i + j, 1);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
// Add qrItem at its supposed position if its index is not present within qrGroup
|
|
213
|
-
if (newQrItemIndex < qrItemsRealIndexArr[i]) {
|
|
214
|
-
for (let j = 0; j < newQrItems.length; j++) {
|
|
215
|
-
qrGroup.item.splice(i + j, 0, newQrItems[j]);
|
|
216
|
-
}
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
31
|
/******************************************************************************
|
|
226
32
|
Copyright (c) Microsoft Corporation.
|
|
227
33
|
|
|
@@ -367,7 +173,7 @@ function readInitialAnswers(questionnaireResponse, linkedQuestionsMap) {
|
|
|
367
173
|
return {};
|
|
368
174
|
const initialValuesMap = {};
|
|
369
175
|
questionnaireResponse.item.forEach((item) => {
|
|
370
|
-
readQuestionnaireResponseItemRecursive(item, initialValuesMap, linkedQuestionsMap);
|
|
176
|
+
readQuestionnaireResponseItemRecursive$1(item, initialValuesMap, linkedQuestionsMap);
|
|
371
177
|
});
|
|
372
178
|
return initialValuesMap;
|
|
373
179
|
}
|
|
@@ -376,12 +182,12 @@ function readInitialAnswers(questionnaireResponse, linkedQuestionsMap) {
|
|
|
376
182
|
*
|
|
377
183
|
* @author Sean Fong
|
|
378
184
|
*/
|
|
379
|
-
function readQuestionnaireResponseItemRecursive(item, initialValues, linkedQuestionsMap) {
|
|
185
|
+
function readQuestionnaireResponseItemRecursive$1(item, initialValues, linkedQuestionsMap) {
|
|
380
186
|
const items = item.item;
|
|
381
187
|
if (items && items.length > 0) {
|
|
382
188
|
// iterate through items of item recursively
|
|
383
189
|
items.forEach((item) => {
|
|
384
|
-
readQuestionnaireResponseItemRecursive(item, initialValues, linkedQuestionsMap);
|
|
190
|
+
readQuestionnaireResponseItemRecursive$1(item, initialValues, linkedQuestionsMap);
|
|
385
191
|
});
|
|
386
192
|
return;
|
|
387
193
|
}
|
|
@@ -3546,6 +3352,200 @@ function mapQItemsIndex(qGroup) {
|
|
|
3546
3352
|
}, {});
|
|
3547
3353
|
}
|
|
3548
3354
|
|
|
3355
|
+
/*
|
|
3356
|
+
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
3357
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
3358
|
+
*
|
|
3359
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3360
|
+
* you may not use this file except in compliance with the License.
|
|
3361
|
+
* You may obtain a copy of the License at
|
|
3362
|
+
*
|
|
3363
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3364
|
+
*
|
|
3365
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
3366
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3367
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3368
|
+
* See the License for the specific language governing permissions and
|
|
3369
|
+
* limitations under the License.
|
|
3370
|
+
*/
|
|
3371
|
+
/**
|
|
3372
|
+
* Create a questionnaireResponse from a given questionnaire form item
|
|
3373
|
+
* A questionnaire form item is the first item of a questionnaire
|
|
3374
|
+
*
|
|
3375
|
+
* @author Sean Fong
|
|
3376
|
+
*/
|
|
3377
|
+
function createQuestionnaireResponse(questionnaire) {
|
|
3378
|
+
var _a;
|
|
3379
|
+
const questionnaireResponse = {
|
|
3380
|
+
resourceType: 'QuestionnaireResponse',
|
|
3381
|
+
status: 'in-progress'
|
|
3382
|
+
};
|
|
3383
|
+
const firstTopLevelItem = (_a = questionnaire === null || questionnaire === void 0 ? void 0 : questionnaire.item) === null || _a === void 0 ? void 0 : _a[0];
|
|
3384
|
+
if (firstTopLevelItem) {
|
|
3385
|
+
questionnaireResponse.item = [
|
|
3386
|
+
{
|
|
3387
|
+
linkId: firstTopLevelItem.linkId,
|
|
3388
|
+
text: firstTopLevelItem.text,
|
|
3389
|
+
item: []
|
|
3390
|
+
}
|
|
3391
|
+
];
|
|
3392
|
+
}
|
|
3393
|
+
if (questionnaire.id) {
|
|
3394
|
+
questionnaireResponse.questionnaire = `Questionnaire/${questionnaire.id}`;
|
|
3395
|
+
}
|
|
3396
|
+
return questionnaireResponse;
|
|
3397
|
+
}
|
|
3398
|
+
/**
|
|
3399
|
+
* Create an empty group qrItem from a given group qItem
|
|
3400
|
+
*
|
|
3401
|
+
* @author Sean Fong
|
|
3402
|
+
*/
|
|
3403
|
+
function createQrGroup(qItem) {
|
|
3404
|
+
return {
|
|
3405
|
+
linkId: qItem.linkId,
|
|
3406
|
+
text: qItem.text,
|
|
3407
|
+
item: []
|
|
3408
|
+
};
|
|
3409
|
+
}
|
|
3410
|
+
/**
|
|
3411
|
+
* Create an empty qrItem from a given qItem
|
|
3412
|
+
*
|
|
3413
|
+
* @author Sean Fong
|
|
3414
|
+
*/
|
|
3415
|
+
function createEmptyQrItem(qItem) {
|
|
3416
|
+
return {
|
|
3417
|
+
linkId: qItem.linkId,
|
|
3418
|
+
text: qItem.text
|
|
3419
|
+
};
|
|
3420
|
+
}
|
|
3421
|
+
/**
|
|
3422
|
+
* Create an empty qrItem from a given qItem with its display unit
|
|
3423
|
+
*
|
|
3424
|
+
* @author Sean Fong
|
|
3425
|
+
*/
|
|
3426
|
+
function createEmptyQrItemWithUnit(qItem, unit) {
|
|
3427
|
+
return {
|
|
3428
|
+
linkId: qItem.linkId,
|
|
3429
|
+
text: unit !== '' ? `${qItem.text} (${unit})` : qItem.text
|
|
3430
|
+
};
|
|
3431
|
+
}
|
|
3432
|
+
/**
|
|
3433
|
+
* Updates the QuestionnaireResponseItem group by adding/removing a new/modified child QuestionnaireResponseItem into/from a qrGroup
|
|
3434
|
+
* Takes either a single newQrItem or an array of newQrItems
|
|
3435
|
+
*
|
|
3436
|
+
* @author Sean Fong
|
|
3437
|
+
*/
|
|
3438
|
+
function updateQrGroup(newQrItem, newQrRepeatGroup, qrGroup, qItemsIndexMap) {
|
|
3439
|
+
var _a, _b;
|
|
3440
|
+
if (qrGroup['item']) {
|
|
3441
|
+
// Get actual sequence indexes of qrItems present within a qrGroup
|
|
3442
|
+
// e.g. qrGroup has 4 fields but only the 2nd and 3rd field have values - resulting array is [1, 2]
|
|
3443
|
+
const qrItemsRealIndexArr = qrGroup.item.map((qrItem) => qItemsIndexMap[qrItem.linkId]);
|
|
3444
|
+
if (newQrItem && newQrItem.linkId in qItemsIndexMap) {
|
|
3445
|
+
if (qrGroup.item.length === 0) {
|
|
3446
|
+
qrGroup.item.push(newQrItem);
|
|
3447
|
+
}
|
|
3448
|
+
else {
|
|
3449
|
+
// Get actual sequence index of qrItem within qrGroup
|
|
3450
|
+
const newQrItemIndex = qItemsIndexMap[newQrItem.linkId];
|
|
3451
|
+
for (let i = 0; i < qrItemsRealIndexArr.length; i++) {
|
|
3452
|
+
// Add qrItem at the end of qrGroup if it is larger than the other indexes
|
|
3453
|
+
if (newQrItemIndex > qrItemsRealIndexArr[i]) {
|
|
3454
|
+
if (i === qrItemsRealIndexArr.length - 1) {
|
|
3455
|
+
qrGroup.item.push(newQrItem);
|
|
3456
|
+
}
|
|
3457
|
+
continue;
|
|
3458
|
+
}
|
|
3459
|
+
// Replace or delete qrItem at its supposed position if its index is already present within qrGroup
|
|
3460
|
+
if (newQrItemIndex === qrItemsRealIndexArr[i]) {
|
|
3461
|
+
if (((_a = newQrItem.item) === null || _a === void 0 ? void 0 : _a.length) || ((_b = newQrItem.answer) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
3462
|
+
// newQrItem has answer value
|
|
3463
|
+
qrGroup.item[i] = newQrItem;
|
|
3464
|
+
}
|
|
3465
|
+
else {
|
|
3466
|
+
// newQrItem has no answer value
|
|
3467
|
+
qrGroup.item.splice(i, 1);
|
|
3468
|
+
}
|
|
3469
|
+
break;
|
|
3470
|
+
}
|
|
3471
|
+
// Add qrItem at its supposed position if its index is not present within qrGroup
|
|
3472
|
+
if (newQrItemIndex < qrItemsRealIndexArr[i]) {
|
|
3473
|
+
qrGroup.item.splice(i, 0, newQrItem);
|
|
3474
|
+
break;
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
3479
|
+
else if (newQrRepeatGroup && newQrRepeatGroup.linkId in qItemsIndexMap) {
|
|
3480
|
+
const newQrItems = newQrRepeatGroup.qrItems;
|
|
3481
|
+
if (qrGroup.item.length === 0) {
|
|
3482
|
+
qrGroup.item.push(...newQrItems);
|
|
3483
|
+
}
|
|
3484
|
+
else {
|
|
3485
|
+
// Get actual sequence index of qrItems within qrGroup
|
|
3486
|
+
const newQrItemIndex = qItemsIndexMap[newQrRepeatGroup.linkId];
|
|
3487
|
+
for (let i = 0; i < qrItemsRealIndexArr.length; i++) {
|
|
3488
|
+
// Add qrItem at the end of qrGroup if it is larger than the other indexes
|
|
3489
|
+
if (newQrItemIndex > qrItemsRealIndexArr[i]) {
|
|
3490
|
+
if (i === qrItemsRealIndexArr.length - 1) {
|
|
3491
|
+
qrGroup.item.push(...newQrItems);
|
|
3492
|
+
}
|
|
3493
|
+
continue;
|
|
3494
|
+
}
|
|
3495
|
+
// Replace or delete qrItem at its supposed position if its index is already present within qrGroup
|
|
3496
|
+
if (newQrItemIndex === qrItemsRealIndexArr[i]) {
|
|
3497
|
+
// Get number of repeatGroupItems that has the same linkId present in qrGroup
|
|
3498
|
+
let repeatGroupItemCount = 0;
|
|
3499
|
+
while (newQrItemIndex === qrItemsRealIndexArr[i + repeatGroupItemCount]) {
|
|
3500
|
+
repeatGroupItemCount++;
|
|
3501
|
+
}
|
|
3502
|
+
// Replace each repeat group qrItem with their new counterparts
|
|
3503
|
+
if (newQrItems.length === repeatGroupItemCount) {
|
|
3504
|
+
for (let j = 0; j < newQrItems.length; j++) {
|
|
3505
|
+
qrGroup.item[i + j] = newQrItems[j];
|
|
3506
|
+
}
|
|
3507
|
+
break;
|
|
3508
|
+
}
|
|
3509
|
+
else if (newQrItems.length > repeatGroupItemCount) {
|
|
3510
|
+
// Replace each repeat group qrItem with their new counterparts,
|
|
3511
|
+
// followed by adding an extra newQrItem behind the newly replaced qrItems
|
|
3512
|
+
for (let j = 0, k = repeatGroupItemCount; j < newQrItems.length; j++, k--) {
|
|
3513
|
+
if (k > 0) {
|
|
3514
|
+
qrGroup.item[i + j] = newQrItems[j];
|
|
3515
|
+
}
|
|
3516
|
+
else {
|
|
3517
|
+
qrGroup.item.splice(i + j, 0, newQrItems[j]);
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
break;
|
|
3521
|
+
}
|
|
3522
|
+
else if (newQrItems.length < repeatGroupItemCount) {
|
|
3523
|
+
// Replace each repeat group qrItem with their new counterparts (except the last one),
|
|
3524
|
+
// followed by deleting the last newQrItem which wasn't replaced
|
|
3525
|
+
for (let j = 0; j < repeatGroupItemCount; j++) {
|
|
3526
|
+
if (j <= newQrItems.length - 1) {
|
|
3527
|
+
qrGroup.item[i + j] = newQrItems[j];
|
|
3528
|
+
}
|
|
3529
|
+
else {
|
|
3530
|
+
qrGroup.item.splice(i + j, 1);
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
break;
|
|
3534
|
+
}
|
|
3535
|
+
}
|
|
3536
|
+
// Add qrItem at its supposed position if its index is not present within qrGroup
|
|
3537
|
+
if (newQrItemIndex < qrItemsRealIndexArr[i]) {
|
|
3538
|
+
for (let j = 0; j < newQrItems.length; j++) {
|
|
3539
|
+
qrGroup.item.splice(i + j, 0, newQrItems[j]);
|
|
3540
|
+
}
|
|
3541
|
+
break;
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
|
|
3549
3549
|
/*
|
|
3550
3550
|
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
3551
3551
|
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
@@ -4822,6 +4822,109 @@ const useQuestionnaireResponseStore = create()((set) => ({
|
|
|
4822
4822
|
}))
|
|
4823
4823
|
}));
|
|
4824
4824
|
|
|
4825
|
+
/*
|
|
4826
|
+
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
4827
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4828
|
+
*
|
|
4829
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4830
|
+
* you may not use this file except in compliance with the License.
|
|
4831
|
+
* You may obtain a copy of the License at
|
|
4832
|
+
*
|
|
4833
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4834
|
+
*
|
|
4835
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
4836
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4837
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4838
|
+
* See the License for the specific language governing permissions and
|
|
4839
|
+
* limitations under the License.
|
|
4840
|
+
*/
|
|
4841
|
+
/**
|
|
4842
|
+
* Recursively go through the questionnaireResponse and remove qrItems whose qItems are hidden in the form
|
|
4843
|
+
*
|
|
4844
|
+
* @author Sean Fong
|
|
4845
|
+
*/
|
|
4846
|
+
function removeHiddenAnswers(params) {
|
|
4847
|
+
const { questionnaire, questionnaireResponse, enableWhenIsActivated, enableWhenItems, enableWhenExpressions } = params;
|
|
4848
|
+
const topLevelQItems = questionnaire.item;
|
|
4849
|
+
const topLevelQRItems = questionnaireResponse.item;
|
|
4850
|
+
if (!topLevelQItems ||
|
|
4851
|
+
topLevelQItems.length === 0 ||
|
|
4852
|
+
!topLevelQRItems ||
|
|
4853
|
+
topLevelQRItems.length === 0) {
|
|
4854
|
+
return questionnaireResponse;
|
|
4855
|
+
}
|
|
4856
|
+
topLevelQRItems.forEach((qrItem, i) => {
|
|
4857
|
+
const qItem = topLevelQItems[i];
|
|
4858
|
+
const newTopLevelQRItem = readQuestionnaireResponseItemRecursive({
|
|
4859
|
+
qItem,
|
|
4860
|
+
qrItem,
|
|
4861
|
+
enableWhenIsActivated,
|
|
4862
|
+
enableWhenItems,
|
|
4863
|
+
enableWhenExpressions
|
|
4864
|
+
});
|
|
4865
|
+
if (newTopLevelQRItem && questionnaireResponse.item) {
|
|
4866
|
+
questionnaireResponse.item[i] = Object.assign({}, newTopLevelQRItem);
|
|
4867
|
+
}
|
|
4868
|
+
});
|
|
4869
|
+
return questionnaireResponse;
|
|
4870
|
+
}
|
|
4871
|
+
function readQuestionnaireResponseItemRecursive(params) {
|
|
4872
|
+
const { qItem, qrItem, enableWhenIsActivated, enableWhenItems, enableWhenExpressions } = params;
|
|
4873
|
+
const qItems = qItem.item;
|
|
4874
|
+
const qrItems = qrItem.item;
|
|
4875
|
+
// Process group items
|
|
4876
|
+
if (qItems && qItems.length > 0) {
|
|
4877
|
+
// Return nothing if corresponding qItem is hidden
|
|
4878
|
+
if (isHidden({
|
|
4879
|
+
questionnaireItem: qItem,
|
|
4880
|
+
enableWhenIsActivated,
|
|
4881
|
+
enableWhenItems,
|
|
4882
|
+
enableWhenExpressions
|
|
4883
|
+
}))
|
|
4884
|
+
return null;
|
|
4885
|
+
if (qrItems && qrItems.length > 0) {
|
|
4886
|
+
const newQrItems = [];
|
|
4887
|
+
// Loop over qItems - but end loop if we either reach the end of qItems or qrItems
|
|
4888
|
+
// Under normal circumstances we will reach the end of both arrays together
|
|
4889
|
+
for (let qItemIndex = 0, qrItemIndex = 0; qItemIndex < qItems.length || qrItemIndex < qrItems.length; qItemIndex++) {
|
|
4890
|
+
// Save qrItem if linkIds of current qItem and qrItem are the same
|
|
4891
|
+
if (qrItems[qrItemIndex] && qItems[qItemIndex].linkId === qrItems[qrItemIndex].linkId) {
|
|
4892
|
+
const newQrItem = readQuestionnaireResponseItemRecursive({
|
|
4893
|
+
qItem: qItems[qItemIndex],
|
|
4894
|
+
qrItem: qrItems[qrItemIndex],
|
|
4895
|
+
enableWhenIsActivated,
|
|
4896
|
+
enableWhenItems,
|
|
4897
|
+
enableWhenExpressions
|
|
4898
|
+
});
|
|
4899
|
+
if (newQrItem) {
|
|
4900
|
+
newQrItems.push(newQrItem);
|
|
4901
|
+
}
|
|
4902
|
+
// Decrement qItem index if the next qrItem is an answer from a repeatGroup
|
|
4903
|
+
// Essentially persisting the current qItem linked to be matched up with the next qrItem linkId
|
|
4904
|
+
if (qrItems.length !== qrItemIndex + 1 &&
|
|
4905
|
+
qrItems[qrItemIndex].linkId === qrItems[qrItemIndex + 1].linkId) {
|
|
4906
|
+
qItemIndex--;
|
|
4907
|
+
}
|
|
4908
|
+
// Only Increment qrItem index whenever the current qrItem linkId matches up with the current qItem
|
|
4909
|
+
qrItemIndex++;
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
return Object.assign(Object.assign({}, qrItem), { item: newQrItems });
|
|
4913
|
+
}
|
|
4914
|
+
// Also perform checking if answer exists
|
|
4915
|
+
return qrItem['answer'] ? qrItem : null;
|
|
4916
|
+
}
|
|
4917
|
+
// Process non-group items
|
|
4918
|
+
return isHidden({
|
|
4919
|
+
questionnaireItem: qItem,
|
|
4920
|
+
enableWhenIsActivated,
|
|
4921
|
+
enableWhenItems,
|
|
4922
|
+
enableWhenExpressions
|
|
4923
|
+
})
|
|
4924
|
+
? null
|
|
4925
|
+
: Object.assign({}, qrItem);
|
|
4926
|
+
}
|
|
4927
|
+
|
|
4825
4928
|
/*
|
|
4826
4929
|
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
4827
4930
|
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
@@ -10410,7 +10513,7 @@ function FormTopLevelItem(props) {
|
|
|
10410
10513
|
* See the License for the specific language governing permissions and
|
|
10411
10514
|
* limitations under the License.
|
|
10412
10515
|
*/
|
|
10413
|
-
function
|
|
10516
|
+
function BaseRenderer() {
|
|
10414
10517
|
const sourceQuestionnaire = useQuestionnaireStore((state) => state.sourceQuestionnaire);
|
|
10415
10518
|
const updateExpressions = useQuestionnaireStore((state) => state.updateExpressions);
|
|
10416
10519
|
const updatableResponse = useQuestionnaireResponseStore((state) => state.updatableResponse);
|
|
@@ -10475,8 +10578,73 @@ function SmartFormsRenderer(props) {
|
|
|
10475
10578
|
React.createElement(Typography, null, "Loading questionnaire...")));
|
|
10476
10579
|
}
|
|
10477
10580
|
return (React.createElement(QueryClientProvider, { client: queryClient },
|
|
10478
|
-
React.createElement(
|
|
10581
|
+
React.createElement(BaseRenderer, null)));
|
|
10582
|
+
}
|
|
10583
|
+
|
|
10584
|
+
function useSourceQuestionnaire() {
|
|
10585
|
+
return useQuestionnaireStore.getState().sourceQuestionnaire;
|
|
10586
|
+
}
|
|
10587
|
+
function useSourceResponse() {
|
|
10588
|
+
return useQuestionnaireResponseStore.getState().sourceResponse;
|
|
10589
|
+
}
|
|
10590
|
+
function useUpdatableResponse() {
|
|
10591
|
+
return useQuestionnaireResponseStore.getState().updatableResponse;
|
|
10592
|
+
}
|
|
10593
|
+
function useFormHasChanges() {
|
|
10594
|
+
return useQuestionnaireResponseStore.getState().hasChanges;
|
|
10595
|
+
}
|
|
10596
|
+
function useEnableWhenActivated() {
|
|
10597
|
+
return useQuestionnaireStore.getState().enableWhenIsActivated;
|
|
10598
|
+
}
|
|
10599
|
+
function setSourceQuestionnaire(questionnaire) {
|
|
10600
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10601
|
+
yield useQuestionnaireStore.getState().buildSourceQuestionnaire(questionnaire);
|
|
10602
|
+
});
|
|
10603
|
+
}
|
|
10604
|
+
function buildForm(questionnaire, questionnaireResponse) {
|
|
10605
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10606
|
+
yield useQuestionnaireStore.getState().buildSourceQuestionnaire(questionnaire);
|
|
10607
|
+
if (!questionnaireResponse) {
|
|
10608
|
+
useQuestionnaireResponseStore
|
|
10609
|
+
.getState()
|
|
10610
|
+
.buildSourceResponse(createQuestionnaireResponse(questionnaire));
|
|
10611
|
+
return;
|
|
10612
|
+
}
|
|
10613
|
+
useQuestionnaireResponseStore.getState().buildSourceResponse(questionnaireResponse);
|
|
10614
|
+
useQuestionnaireStore.getState().updatePopulatedProperties(questionnaireResponse);
|
|
10615
|
+
});
|
|
10616
|
+
}
|
|
10617
|
+
function destroyForm() {
|
|
10618
|
+
useQuestionnaireStore.getState().destroySourceQuestionnaire();
|
|
10619
|
+
useQuestionnaireResponseStore.getState().destroySourceResponse();
|
|
10620
|
+
}
|
|
10621
|
+
function setEnableWhenActivation(isActivated) {
|
|
10622
|
+
useQuestionnaireStore.getState().toggleEnableWhenActivation(isActivated);
|
|
10623
|
+
}
|
|
10624
|
+
function setPopulatedResponse(populatedResponse) {
|
|
10625
|
+
const updatedResponse = useQuestionnaireStore
|
|
10626
|
+
.getState()
|
|
10627
|
+
.updatePopulatedProperties(populatedResponse);
|
|
10628
|
+
useQuestionnaireResponseStore.getState().populateResponse(updatedResponse);
|
|
10629
|
+
}
|
|
10630
|
+
function setEmptyResponse(emptyResponse) {
|
|
10631
|
+
return useQuestionnaireResponseStore.getState().clearResponse(emptyResponse);
|
|
10632
|
+
}
|
|
10633
|
+
function setSavedResponse(savedResponse) {
|
|
10634
|
+
return useQuestionnaireResponseStore.getState().saveResponse(savedResponse);
|
|
10635
|
+
}
|
|
10636
|
+
function removeHiddenAnswersFromResponse(questionnaire, questionnaireResponse) {
|
|
10637
|
+
const enableWhenIsActivated = useQuestionnaireStore.getState().enableWhenIsActivated;
|
|
10638
|
+
const enableWhenItems = useQuestionnaireStore.getState().enableWhenItems;
|
|
10639
|
+
const enableWhenExpressions = useQuestionnaireStore.getState().enableWhenExpressions;
|
|
10640
|
+
return removeHiddenAnswers({
|
|
10641
|
+
questionnaire,
|
|
10642
|
+
questionnaireResponse,
|
|
10643
|
+
enableWhenIsActivated,
|
|
10644
|
+
enableWhenItems,
|
|
10645
|
+
enableWhenExpressions
|
|
10646
|
+
});
|
|
10479
10647
|
}
|
|
10480
10648
|
|
|
10481
|
-
export { SmartFormsRenderer };
|
|
10649
|
+
export { BaseRenderer, SmartFormsRenderer, buildForm, destroyForm, removeHiddenAnswersFromResponse, setEmptyResponse, setEnableWhenActivation, setPopulatedResponse, setSavedResponse, setSourceQuestionnaire, useEnableWhenActivated, useFormHasChanges, useHidden, useSourceQuestionnaire, useSourceResponse, useUpdatableResponse };
|
|
10482
10650
|
//# sourceMappingURL=index.esm.js.map
|