@aehrc/smart-forms-renderer 0.28.0 → 0.30.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/lib/components/FormComponents/DateTimeItems/CustomDateItem/CustomDateItem.js +2 -1
- package/lib/components/FormComponents/DateTimeItems/CustomDateItem/CustomDateItem.js.map +1 -1
- package/lib/components/FormComponents/DateTimeItems/CustomDateTimeItem/CustomDateTimeItem.js +4 -3
- package/lib/components/FormComponents/DateTimeItems/CustomDateTimeItem/CustomDateTimeItem.js.map +1 -1
- package/lib/components/FormComponents/RepeatGroup/RepeatGroup.js +3 -2
- package/lib/components/FormComponents/RepeatGroup/RepeatGroup.js.map +1 -1
- package/lib/components/FormComponents/RepeatItem/RepeatItem.js +3 -2
- package/lib/components/FormComponents/RepeatItem/RepeatItem.js.map +1 -1
- package/lib/components/FormComponents/UrlItem/UrlItem.js +3 -2
- package/lib/components/FormComponents/UrlItem/UrlItem.js.map +1 -1
- package/lib/hooks/useInitialiseRepeatAnswers.js +2 -2
- package/lib/hooks/useInitialiseRepeatAnswers.js.map +1 -1
- package/lib/hooks/useInitialiseRepeatGroups.d.ts +1 -2
- package/lib/hooks/useInitialiseRepeatGroups.js +2 -2
- package/lib/hooks/useInitialiseRepeatGroups.js.map +1 -1
- package/lib/hooks/useRepeatAnswers.d.ts +4 -0
- package/lib/hooks/useRepeatAnswers.js +34 -0
- package/lib/hooks/useRepeatAnswers.js.map +1 -0
- package/lib/hooks/useRepeatGroups.d.ts +4 -0
- package/lib/hooks/useRepeatGroups.js +34 -0
- package/lib/hooks/useRepeatGroups.js.map +1 -0
- package/lib/hooks/useRepeatitemState.d.ts +0 -0
- package/lib/hooks/useRepeatitemState.js +2 -0
- package/lib/hooks/useRepeatitemState.js.map +1 -0
- package/lib/utils/calculatedExpression.js +3 -3
- package/lib/utils/calculatedExpression.js.map +1 -1
- package/package.json +2 -1
- package/src/components/FormComponents/DateTimeItems/CustomDateItem/CustomDateItem.tsx +2 -1
- package/src/components/FormComponents/DateTimeItems/CustomDateTimeItem/CustomDateTimeItem.tsx +4 -3
- package/src/components/FormComponents/RepeatGroup/RepeatGroup.tsx +3 -2
- package/src/components/FormComponents/RepeatItem/RepeatItem.tsx +3 -2
- package/src/components/FormComponents/UrlItem/UrlItem.tsx +3 -2
- package/src/hooks/useInitialiseRepeatAnswers.ts +2 -2
- package/src/hooks/useInitialiseRepeatGroups.ts +3 -4
- package/src/hooks/useRepeatAnswers.ts +45 -0
- package/src/hooks/useRepeatGroups.ts +47 -0
- package/src/stories/BuildFormButtonForStorybook.tsx +41 -0
- package/src/stories/BuildFormButtonTesterWrapper.tsx +61 -0
- package/src/stories/BuildFormWrapper.tsx +6 -11
- package/src/stories/PrePopButtonForStorybook.tsx +54 -0
- package/src/stories/PrePopWrapper.tsx +92 -0
- package/src/stories/assets/fhirClient/mockFhirClient.ts +52 -0
- package/src/stories/assets/patients/PatSmartForm.ts +281 -0
- package/src/stories/assets/practitioners/PracPrimaryPeter.ts +38 -0
- package/src/stories/assets/questionnaires/QBehaviorCalculations.ts +17 -19
- package/src/stories/assets/questionnaires/QBuildFormButtonTester.ts +270 -0
- package/src/stories/assets/questionnaires/QFormPopulation.ts +1349 -0
- package/src/stories/populateCallbackForStorybook.ts +56 -0
- package/src/stories/populateUtilsForStorybook.ts +545 -0
- package/src/stories/rebuildForm/BuildFormTesterWrapper.stories.tsx +43 -0
- package/src/stories/sdc/FormPopulation.stories.tsx +97 -0
- package/src/stories/useBuildFormForStorybook.ts +37 -0
- package/src/utils/calculatedExpression.ts +3 -2
- package/storybook.log +6 -0
- package/vite.config.ts +11 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
19
|
+
import { useEffect, useState } from 'react';
|
|
20
|
+
import type { RepeatAnswer } from '../interfaces/repeatItem.interface';
|
|
21
|
+
import _isEqual from 'lodash/isEqual';
|
|
22
|
+
|
|
23
|
+
function useRepeatAnswers(
|
|
24
|
+
valueFromProps: RepeatAnswer[]
|
|
25
|
+
): [RepeatAnswer[], Dispatch<SetStateAction<RepeatAnswer[]>>] {
|
|
26
|
+
const [repeatAnswers, setRepeatAnswers] = useState(valueFromProps);
|
|
27
|
+
|
|
28
|
+
useEffect(
|
|
29
|
+
() => {
|
|
30
|
+
const valueFromPropsQRItemAnswers = valueFromProps.map((answer) => answer.answer);
|
|
31
|
+
const repeatAnswersQRItemAnswers = repeatAnswers.map((answer) => answer.answer);
|
|
32
|
+
|
|
33
|
+
if (!_isEqual(valueFromPropsQRItemAnswers, repeatAnswersQRItemAnswers)) {
|
|
34
|
+
setRepeatAnswers(valueFromProps);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
// Only trigger this effect if prop value changes
|
|
38
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
39
|
+
[valueFromProps]
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return [repeatAnswers, setRepeatAnswers];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default useRepeatAnswers;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
19
|
+
import { useEffect, useState } from 'react';
|
|
20
|
+
import type { RepeatGroupSingle } from '../interfaces/repeatGroup.interface';
|
|
21
|
+
import _isEqual from 'lodash/isEqual';
|
|
22
|
+
|
|
23
|
+
function useRepeatGroups(
|
|
24
|
+
valueFromProps: RepeatGroupSingle[]
|
|
25
|
+
): [RepeatGroupSingle[], Dispatch<SetStateAction<RepeatGroupSingle[]>>] {
|
|
26
|
+
const [repeatGroups, setRepeatGroups] = useState(valueFromProps);
|
|
27
|
+
|
|
28
|
+
useEffect(
|
|
29
|
+
() => {
|
|
30
|
+
const valueFromPropsQRItems = valueFromProps.map(
|
|
31
|
+
(repeatGroupSingle) => repeatGroupSingle.qrItem
|
|
32
|
+
);
|
|
33
|
+
const repeatGroupsQRItems = repeatGroups.map((repeatGroupSingle) => repeatGroupSingle.qrItem);
|
|
34
|
+
|
|
35
|
+
if (!_isEqual(valueFromPropsQRItems, repeatGroupsQRItems)) {
|
|
36
|
+
setRepeatGroups(valueFromProps);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
// Only trigger this effect if prop value changes
|
|
40
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
41
|
+
[valueFromProps]
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return [repeatGroups, setRepeatGroups];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default useRepeatGroups;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
import React from 'react';
|
|
20
|
+
import { Box, IconButton, Tooltip } from '@mui/material';
|
|
21
|
+
import Iconify from '../components/Iconify/Iconify';
|
|
22
|
+
|
|
23
|
+
interface BuildFormButtonProps {
|
|
24
|
+
onBuild: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function BuildFormButtonForStorybook(props: BuildFormButtonProps) {
|
|
28
|
+
const { onBuild } = props;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<Box display="flex" mb={0.5} alignItems="center" columnGap={3}>
|
|
32
|
+
<Tooltip title="Build form" placement="right">
|
|
33
|
+
<IconButton onClick={onBuild} size="small" color="primary">
|
|
34
|
+
<Iconify icon="ph:hammer" sx={{ mb: 0.5 }} />
|
|
35
|
+
</IconButton>
|
|
36
|
+
</Tooltip>
|
|
37
|
+
</Box>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default BuildFormButtonForStorybook;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
import React from 'react';
|
|
20
|
+
import type { Questionnaire, QuestionnaireResponse } from 'fhir/r4';
|
|
21
|
+
import { BaseRenderer } from '../components';
|
|
22
|
+
import { QueryClientProvider } from '@tanstack/react-query';
|
|
23
|
+
import ThemeProvider from '../theme/Theme';
|
|
24
|
+
import useQueryClient from '../hooks/useQueryClient';
|
|
25
|
+
import useBuildFormForStorybook from './useBuildFormForStorybook';
|
|
26
|
+
import { buildForm } from '../utils';
|
|
27
|
+
import BuildFormButtonForStorybook from './BuildFormButtonForStorybook';
|
|
28
|
+
|
|
29
|
+
interface BuildFormButtonTesterWrapperProps {
|
|
30
|
+
questionnaire: Questionnaire;
|
|
31
|
+
questionnaireResponse?: QuestionnaireResponse;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function BuildFormButtonTesterWrapper(props: BuildFormButtonTesterWrapperProps) {
|
|
35
|
+
const { questionnaire, questionnaireResponse } = props;
|
|
36
|
+
|
|
37
|
+
const queryClient = useQueryClient();
|
|
38
|
+
|
|
39
|
+
const isBuilding = useBuildFormForStorybook(questionnaire);
|
|
40
|
+
|
|
41
|
+
async function handleBuildForm() {
|
|
42
|
+
await buildForm(questionnaire, questionnaireResponse);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (isBuilding) {
|
|
46
|
+
return <div>Loading...</div>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<ThemeProvider>
|
|
51
|
+
<QueryClientProvider client={queryClient}>
|
|
52
|
+
<div>
|
|
53
|
+
<BuildFormButtonForStorybook onBuild={handleBuildForm} />
|
|
54
|
+
<BaseRenderer />
|
|
55
|
+
</div>
|
|
56
|
+
</QueryClientProvider>
|
|
57
|
+
</ThemeProvider>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default BuildFormButtonTesterWrapper;
|
|
@@ -15,13 +15,14 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
import React from 'react';
|
|
19
20
|
import type { Questionnaire, QuestionnaireResponse } from 'fhir/r4';
|
|
20
21
|
import { BaseRenderer } from '../components';
|
|
21
22
|
import { QueryClientProvider } from '@tanstack/react-query';
|
|
22
23
|
import ThemeProvider from '../theme/Theme';
|
|
23
24
|
import useQueryClient from '../hooks/useQueryClient';
|
|
24
|
-
import
|
|
25
|
+
import useBuildFormForStorybook from './useBuildFormForStorybook';
|
|
25
26
|
|
|
26
27
|
interface BuildFormWrapperProps {
|
|
27
28
|
questionnaire: Questionnaire;
|
|
@@ -31,17 +32,11 @@ interface BuildFormWrapperProps {
|
|
|
31
32
|
function BuildFormWrapper(props: BuildFormWrapperProps) {
|
|
32
33
|
const { questionnaire, questionnaireResponse } = props;
|
|
33
34
|
|
|
34
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
35
|
-
|
|
36
|
-
useLayoutEffect(() => {
|
|
37
|
-
buildForm(questionnaire, questionnaireResponse).then(() => {
|
|
38
|
-
setIsLoading(false);
|
|
39
|
-
});
|
|
40
|
-
}, [questionnaire, questionnaireResponse]);
|
|
41
|
-
|
|
42
35
|
const queryClient = useQueryClient();
|
|
43
36
|
|
|
44
|
-
|
|
37
|
+
const isBuilding = useBuildFormForStorybook(questionnaire, questionnaireResponse);
|
|
38
|
+
|
|
39
|
+
if (isBuilding) {
|
|
45
40
|
return <div>Loading...</div>;
|
|
46
41
|
}
|
|
47
42
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
import React from 'react';
|
|
20
|
+
import { Box, CircularProgress, Fade, IconButton, Tooltip } from '@mui/material';
|
|
21
|
+
import PlayCircleIcon from '@mui/icons-material/PlayCircle';
|
|
22
|
+
import Typography from '@mui/material/Typography';
|
|
23
|
+
|
|
24
|
+
interface PrePopButtonProps {
|
|
25
|
+
isPopulating: boolean;
|
|
26
|
+
onPopulate: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function PrePopButtonForStorybook(props: PrePopButtonProps) {
|
|
30
|
+
const { isPopulating, onPopulate } = props;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Box display="flex" mb={0.5} alignItems="center" columnGap={3}>
|
|
34
|
+
<Tooltip title="Pre-populate form" placement="right">
|
|
35
|
+
<IconButton disabled={isPopulating} onClick={onPopulate} size="small" color="primary">
|
|
36
|
+
{isPopulating ? (
|
|
37
|
+
<CircularProgress size={20} color="inherit" sx={{ mb: 0.5 }} />
|
|
38
|
+
) : (
|
|
39
|
+
<PlayCircleIcon />
|
|
40
|
+
)}
|
|
41
|
+
</IconButton>
|
|
42
|
+
</Tooltip>
|
|
43
|
+
{isPopulating ? (
|
|
44
|
+
<Fade in={true} timeout={100}>
|
|
45
|
+
<Typography variant="body2" color="text.secondary">
|
|
46
|
+
Pre-populating form...
|
|
47
|
+
</Typography>
|
|
48
|
+
</Fade>
|
|
49
|
+
) : null}
|
|
50
|
+
</Box>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default PrePopButtonForStorybook;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
import React, { useState } from 'react';
|
|
20
|
+
import type { Patient, Practitioner, Questionnaire } from 'fhir/r4';
|
|
21
|
+
import { BaseRenderer } from '../components';
|
|
22
|
+
import { QueryClientProvider } from '@tanstack/react-query';
|
|
23
|
+
import ThemeProvider from '../theme/Theme';
|
|
24
|
+
import useQueryClient from '../hooks/useQueryClient';
|
|
25
|
+
import type Client from 'fhirclient/lib/Client';
|
|
26
|
+
import useBuildFormForStorybook from './useBuildFormForStorybook';
|
|
27
|
+
import { buildForm } from '../utils';
|
|
28
|
+
import PrePopButtonForStorybook from './PrePopButtonForStorybook';
|
|
29
|
+
import { populateQuestionnaire } from '@aehrc/sdc-populate';
|
|
30
|
+
import { fetchResourceCallback } from './populateCallbackForStorybook';
|
|
31
|
+
|
|
32
|
+
interface PrePopWrapperProps {
|
|
33
|
+
questionnaire: Questionnaire;
|
|
34
|
+
fhirClient: Client;
|
|
35
|
+
patient: Patient;
|
|
36
|
+
user: Practitioner;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function PrePopWrapper(props: PrePopWrapperProps) {
|
|
40
|
+
const { questionnaire, fhirClient, patient, user } = props;
|
|
41
|
+
|
|
42
|
+
const [isPopulating, setIsPopulating] = useState(false);
|
|
43
|
+
|
|
44
|
+
const isBuilding = useBuildFormForStorybook(questionnaire);
|
|
45
|
+
|
|
46
|
+
const queryClient = useQueryClient();
|
|
47
|
+
|
|
48
|
+
function handlePrepopulate() {
|
|
49
|
+
setIsPopulating(true);
|
|
50
|
+
|
|
51
|
+
populateQuestionnaire({
|
|
52
|
+
questionnaire: questionnaire,
|
|
53
|
+
fetchResourceCallback: fetchResourceCallback,
|
|
54
|
+
requestConfig: {
|
|
55
|
+
clientEndpoint: fhirClient.state.serverUrl,
|
|
56
|
+
authToken: null
|
|
57
|
+
},
|
|
58
|
+
patient: patient,
|
|
59
|
+
user: user
|
|
60
|
+
}).then(async ({ populateSuccess, populateResult }) => {
|
|
61
|
+
if (!populateSuccess || !populateResult) {
|
|
62
|
+
setIsPopulating(false);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const { populatedResponse } = populateResult;
|
|
67
|
+
|
|
68
|
+
// buildForm is used here because there is a really bizarre bug - using the store hooks directly doesn't update the baseRenderer
|
|
69
|
+
// could be the fact that it doesn't play well with storybook
|
|
70
|
+
await buildForm(questionnaire, populatedResponse);
|
|
71
|
+
|
|
72
|
+
setIsPopulating(false);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (isBuilding) {
|
|
77
|
+
return <div>Loading...</div>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<ThemeProvider>
|
|
82
|
+
<QueryClientProvider client={queryClient}>
|
|
83
|
+
<div>
|
|
84
|
+
<PrePopButtonForStorybook isPopulating={isPopulating} onPopulate={handlePrepopulate} />
|
|
85
|
+
{isPopulating ? null : <BaseRenderer />}
|
|
86
|
+
</div>
|
|
87
|
+
</QueryClientProvider>
|
|
88
|
+
</ThemeProvider>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default PrePopWrapper;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type Client from 'fhirclient/lib/Client';
|
|
19
|
+
|
|
20
|
+
const iss = 'https://proxy.smartforms.io/v/r4/fhir';
|
|
21
|
+
|
|
22
|
+
const clientId = 'smart-forms-storybook';
|
|
23
|
+
|
|
24
|
+
const scope =
|
|
25
|
+
'fhirUser online_access openid profile patient/Condition.rs patient/Observation.rs launch patient/Encounter.rs patient/Patient.rs';
|
|
26
|
+
|
|
27
|
+
// This must be a patient ID that exists in the EHR
|
|
28
|
+
const patientId = 'pat-sf';
|
|
29
|
+
|
|
30
|
+
// This must be a practitioner ID that exists in the EHR
|
|
31
|
+
const userId = 'primary-peter';
|
|
32
|
+
|
|
33
|
+
export const mockFhirClient = {
|
|
34
|
+
state: {
|
|
35
|
+
clientId: clientId,
|
|
36
|
+
scope: scope,
|
|
37
|
+
serverUrl: iss,
|
|
38
|
+
tokenResponse: {
|
|
39
|
+
access_token: 'mock_access_token'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
patient: {
|
|
43
|
+
id: patientId
|
|
44
|
+
},
|
|
45
|
+
encounter: { id: null },
|
|
46
|
+
|
|
47
|
+
user: {
|
|
48
|
+
id: userId,
|
|
49
|
+
fhirUser: `Practitioner/${userId}`,
|
|
50
|
+
resourceType: 'Practitioner'
|
|
51
|
+
}
|
|
52
|
+
} as unknown as Client;
|