@aehrc/smart-forms-renderer 0.31.5 → 0.32.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/README.md +3 -101
- package/lib/components/Renderer/SmartFormsRenderer.d.ts +1 -1
- package/lib/components/Renderer/SmartFormsRenderer.js +1 -1
- package/lib/stores/questionnaireResponseStore.d.ts +7 -7
- package/lib/stores/questionnaireStore.d.ts +13 -13
- package/lib/stores/smartConfigStore.d.ts +4 -4
- package/lib/stores/terminologyServerStore.d.ts +2 -2
- package/lib/stories/StorybookWrappers/InitialiseFormWrapperForStorybook.d.ts +4 -4
- package/lib/stories/StorybookWrappers/InitialiseFormWrapperForStorybook.js +4 -4
- package/lib/theme/Theme.d.ts +1 -1
- package/lib/theme/Theme.js +1 -1
- package/lib/utils/manageForm.d.ts +2 -1
- package/lib/utils/manageForm.js +9 -2
- package/lib/utils/manageForm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Renderer/SmartFormsRenderer.tsx +1 -1
- package/src/stores/questionnaireResponseStore.ts +7 -7
- package/src/stores/questionnaireStore.ts +13 -13
- package/src/stores/smartConfigStore.ts +4 -4
- package/src/stores/terminologyServerStore.ts +2 -2
- package/src/stories/storybookWrappers/BuildFormButtonTesterWrapperForStorybook.tsx +1 -1
- package/src/stories/storybookWrappers/InitialiseFormWrapperForStorybook.tsx +4 -4
- package/src/stories/storybookWrappers/PrePopWrapperForStorybook.tsx +1 -1
- package/src/stories/storybookWrappers/populateCallbackForStorybook.ts +1 -1
- package/src/stories/testing/BuildFormButtonTesterWrapper.stories.tsx +4 -4
- package/src/theme/Theme.tsx +1 -1
- package/src/utils/manageForm.ts +14 -2
package/README.md
CHANGED
|
@@ -1,108 +1,10 @@
|
|
|
1
1
|
# Smart Forms Renderer
|
|
2
|
-
This React-based package acts as the rendering engine for the [Smart Forms app](https://github.com/aehrc/smart-forms).
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
A React-based library that contains the Questionnaire renderer used in the Smart Forms app.
|
|
4
|
+
It acts as a reference implementation for the [SDC Form Filler](https://hl7.org/fhir/uv/sdc/CapabilityStatement-sdc-form-filler.html).
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @aehrc/smart-forms-renderer
|
|
9
|
-
```
|
|
6
|
+
<h4><a href="https://smartforms.csiro.au/docs/devUsage">Check out the documentation 📚</a></h4>
|
|
10
7
|
|
|
11
|
-
## Basic Usage
|
|
12
|
-
|
|
13
|
-
```typescript jsx
|
|
14
|
-
import React from 'react';
|
|
15
|
-
import { SmartFormsRenderer, getResponse } from '@aehrc/smart-forms-renderer';
|
|
16
|
-
|
|
17
|
-
export default function App () {
|
|
18
|
-
const questionnaire = {...} // FHIR R4.Questionnaire
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<div>
|
|
22
|
-
<SmartFormsRenderer questionnaire={questionnaire}/>
|
|
23
|
-
<button onClick={() => {
|
|
24
|
-
const response = getResponse()
|
|
25
|
-
// Do something with the questionnaire response
|
|
26
|
-
}}/>
|
|
27
|
-
</div>
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
Note: The SmartFormsRenderer component trades customisability for simplicity. If you need more control over the rendering engine, refer to the Advanced Usage section.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
### SmartFormsRenderer Props
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
| Name | Type | Description | Required? |
|
|
38
|
-
|-----------------------|-------------------------------|---------------------------------------------------------------------------------------------------------------------|-----------|
|
|
39
|
-
| questionnaire | FHIR R4.Questionnaire | Questionnaire to be rendered | Required |
|
|
40
|
-
| questionnaireResponse | FHIR R4.QuestionnaireResponse | Pre-populated QuestionnaireResponse to be rendered | Optional |
|
|
41
|
-
| additionalVariables | `Record<string, Extension>` | Key-value pair of [SDC variables](http://hl7.org/fhir/R4/extension-variable.html) `Record<name, variable extension>` | Optional |
|
|
42
|
-
| terminologyServerUrl | string | Terminology server url to fetch terminology | Optional |
|
|
43
|
-
|
|
44
|
-
The below props are not supported at the moment, but will be in the future.
|
|
45
|
-
|
|
46
|
-
| Name | Type | Description |
|
|
47
|
-
|----------------------|------------------------------------------------------|---------------------------------------------|
|
|
48
|
-
| fhirClient | [Client](https://github.com/smart-on-fhir/client-js) | FhirClient to perform further FHIR calls |
|
|
49
|
-
|
|
50
|
-
### Functions
|
|
51
|
-
|
|
52
|
-
```javascript
|
|
53
|
-
/**
|
|
54
|
-
* Get the filled QuestionnaireResponse at its current state.
|
|
55
|
-
* If no changes have been made to the form, the initial or an empty QuestionnaireResponse is returned.
|
|
56
|
-
*
|
|
57
|
-
* @returns {FHIR R4.QuestionnaireResponse} The filled QuestionnaireResponse
|
|
58
|
-
*/
|
|
59
|
-
function getResponse() {}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
## Advanced Usage (If basic usage does not suffice)
|
|
64
|
-
|
|
65
|
-
```typescript
|
|
66
|
-
/* Components */
|
|
67
|
-
// A self-initialising wrapper around the rendering engine. This is sufficient for most use cases.
|
|
68
|
-
|
|
69
|
-
function SmartFormsRenderer(props: {
|
|
70
|
-
questionnaire: Questionnaire,
|
|
71
|
-
questionnaireResponse?: QuestionnaireResponse,
|
|
72
|
-
additionalVariables?: Record<string, Extension>,
|
|
73
|
-
terminologyServerUrl?: string,
|
|
74
|
-
}): JSX.Element {}
|
|
75
|
-
|
|
76
|
-
// BaseRenderer underneath the SmartFormsRenderer wrapper. Requires buildForm() to initialise form.
|
|
77
|
-
function BaseRenderer(): JSX.Element {}
|
|
78
|
-
|
|
79
|
-
/* Functions */
|
|
80
|
-
// Get the filled QuestionnaireResponse at its current state.
|
|
81
|
-
// If no changes have been made to the form, the initial QuestionnaireResponse is returned.
|
|
82
|
-
function getResponse(): QuestionnaireResponse {}
|
|
83
|
-
|
|
84
|
-
// Build the form with an initial Questionnaire and an optional filled QuestionnaireResponse.
|
|
85
|
-
// If a QuestionnaireResponse is not provided, an empty QuestionnaireResponse is set as the initial QuestionnaireResponse.
|
|
86
|
-
async function buildForm(
|
|
87
|
-
questionnaire: Questionnaire,
|
|
88
|
-
questionnaireResponse?: QuestionnaireResponse
|
|
89
|
-
): Promise<void> {}
|
|
90
|
-
|
|
91
|
-
// Destroy the form to clean up the questionnaire and questionnaireResponse stores.
|
|
92
|
-
function destroyForm(): void {}
|
|
93
|
-
|
|
94
|
-
// Remove all hidden answers from the filled QuestionnaireResponse.
|
|
95
|
-
// This takes into account the questionnaire-hidden extension, enableWhens and enableWhenExpressions.
|
|
96
|
-
function removeHiddenAnswersFromResponse(
|
|
97
|
-
questionnaire: Questionnaire,
|
|
98
|
-
questionnaireResponse: QuestionnaireResponse
|
|
99
|
-
): QuestionnaireResponse {}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
The Smart Forms app uses a even finer-grained control which directly interacts with the state management stores.
|
|
103
|
-
|
|
104
|
-
At the moment there are no plans to document state management methods, but happy to do so if there is demand for it.
|
|
105
|
-
Raise a request in https://github.com/aehrc/smart-forms/issues if you want to see it happen!
|
|
106
8
|
|
|
107
9
|
---
|
|
108
10
|
|
|
@@ -24,7 +24,7 @@ export interface SmartFormsRendererProps {
|
|
|
24
24
|
/**
|
|
25
25
|
* A self-initialising wrapper around the BaseRenderer rendering engine.
|
|
26
26
|
* Will be deprecated in version 1.0.0. For alternative usage, see:
|
|
27
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
27
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/InitialiseFormWrapperForStorybook.tsx#L40-L57
|
|
28
28
|
*
|
|
29
29
|
* @see SmartFormsRendererProps for props.
|
|
30
30
|
*
|
|
@@ -27,7 +27,7 @@ import BaseRenderer from './BaseRenderer';
|
|
|
27
27
|
/**
|
|
28
28
|
* A self-initialising wrapper around the BaseRenderer rendering engine.
|
|
29
29
|
* Will be deprecated in version 1.0.0. For alternative usage, see:
|
|
30
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
30
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/InitialiseFormWrapperForStorybook.tsx#L40-L57
|
|
31
31
|
*
|
|
32
32
|
* @see SmartFormsRendererProps for props.
|
|
33
33
|
*
|
|
@@ -11,13 +11,13 @@ import type { Diff } from 'deep-diff';
|
|
|
11
11
|
* @property formChangesHistory - Array of form changes history in the form of deep-diff objects
|
|
12
12
|
* @property invalidItems - Key-value pair of invalid items based on defined value constraints in the questionnaire `Record<linkId, OperationOutcome>`
|
|
13
13
|
* @property responseIsValid - Whether there are any invalid items in the response
|
|
14
|
-
* @
|
|
15
|
-
* @
|
|
16
|
-
* @
|
|
17
|
-
* @
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
20
|
-
* @
|
|
14
|
+
* @property validateQuestionnaire - Used to validate the questionnaire response based on the questionnaire
|
|
15
|
+
* @property buildSourceResponse - Used to build the source response when the form is first initialised
|
|
16
|
+
* @property setUpdatableResponseAsPopulated - Used to set a pre-populated response as the current response
|
|
17
|
+
* @property updateResponse - Used to update the current response
|
|
18
|
+
* @property setUpdatableResponseAsSaved - Used to set a saved response as the current response
|
|
19
|
+
* @property setUpdatableResponseAsEmpty - Used to set an empty response as the current response
|
|
20
|
+
* @property destroySourceResponse - Used to destroy the source response and reset all properties
|
|
21
21
|
*
|
|
22
22
|
* @author Sean Fong
|
|
23
23
|
*/
|
|
@@ -29,19 +29,19 @@ import type { Tabs } from '../interfaces/tab.interface';
|
|
|
29
29
|
* @property populatedContext - Key-value pair of one-off pre-populated FHIRPath values `Record<variable/launchContext/sourceQueries batch name, evaluated value(s)>`
|
|
30
30
|
* @property focusedLinkId - LinkId of the currently focused item
|
|
31
31
|
* @property readOnly - Flag to set the form to read-only mode
|
|
32
|
-
* @
|
|
33
|
-
* @
|
|
34
|
-
* @
|
|
35
|
-
* @
|
|
36
|
-
* @
|
|
37
|
-
* @
|
|
38
|
-
* @
|
|
39
|
-
* @
|
|
40
|
-
* @
|
|
41
|
-
* @
|
|
42
|
-
* @
|
|
43
|
-
* @
|
|
44
|
-
* @
|
|
32
|
+
* @property buildSourceQuestionnaire - Used to build the source questionnaire with the provided questionnaire and optionally questionnaire response, additional variables, terminology server url and readyOnly flag
|
|
33
|
+
* @property destroySourceQuestionnaire - Used to destroy the source questionnaire and reset all properties
|
|
34
|
+
* @property switchTab - Used to switch the current tab index
|
|
35
|
+
* @property markTabAsComplete - Used to mark a tab index as complete
|
|
36
|
+
* @property updateEnableWhenItem - Used to update linked enableWhen items by updating a question with a new answer
|
|
37
|
+
* @property mutateRepeatEnableWhenItems - Used to add or remove instances of repeating enableWhen items
|
|
38
|
+
* @property toggleEnableWhenActivation - Used to toggle enableWhen checks on/off
|
|
39
|
+
* @property updateExpressions - Used to update all SDC expressions based on the updated questionnaire response
|
|
40
|
+
* @property addCodingToCache - Used to add a coding to the cached value set codings
|
|
41
|
+
* @property updatePopulatedProperties - Used to update all SDC expressions based on a pre-populated questionnaire response
|
|
42
|
+
* @property onFocusLinkId - Used to set the focused linkId
|
|
43
|
+
* @property setPopulatedContext - Used to set the populated contexts (launchContext, sourceQueries, x-fhir-query vars) for debugging purposes
|
|
44
|
+
* @property setFormAsReadOnly - Used to set the form as read-only
|
|
45
45
|
*
|
|
46
46
|
* @author Sean Fong
|
|
47
47
|
*/
|
|
@@ -9,10 +9,10 @@ import type Client from 'fhirclient/lib/Client';
|
|
|
9
9
|
* @property patient - The patient resource in context
|
|
10
10
|
* @property user - The user resource in context
|
|
11
11
|
* @property encounter - The encounter resource in context
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
15
|
-
* @
|
|
12
|
+
* @property setClient - Set the FHIRClient object when launching via SMART App Launch
|
|
13
|
+
* @property setPatient - Set the patient resource in context
|
|
14
|
+
* @property setUser - Set the user resource in context
|
|
15
|
+
* @property setEncounter - Set the encounter resource in context
|
|
16
16
|
*
|
|
17
17
|
* @author Sean Fong
|
|
18
18
|
*/
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Methods are usually used internally, using them from an external source is not recommended.
|
|
5
5
|
*
|
|
6
6
|
* @property url - The current terminology server URL
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
7
|
+
* @property setUrl - Set the terminology server URL
|
|
8
|
+
* @property resetUrl - Reset the terminology server URL to the default
|
|
9
9
|
*
|
|
10
10
|
* @author Sean Fong
|
|
11
11
|
*/
|
|
@@ -20,10 +20,10 @@ export interface InitialiseFormWrapperProps {
|
|
|
20
20
|
* - The initialised FHIRClient is only used for further FHIR calls. It does not provide pre-population capabilities.
|
|
21
21
|
*
|
|
22
22
|
* For button click usage examples of buildForm(), see:
|
|
23
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
24
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
25
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
26
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
23
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/BuildFormButtonTesterWrapperForStorybook.tsx
|
|
24
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/BuildFormButtonForStorybook.tsx
|
|
25
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/PrePopWrapperForStorybook.tsx
|
|
26
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/PrePopButtonForStorybook.tsx
|
|
27
27
|
*
|
|
28
28
|
* @author Sean Fong
|
|
29
29
|
*/
|
|
@@ -35,10 +35,10 @@ import Typography from '@mui/material/Typography';
|
|
|
35
35
|
* - The initialised FHIRClient is only used for further FHIR calls. It does not provide pre-population capabilities.
|
|
36
36
|
*
|
|
37
37
|
* For button click usage examples of buildForm(), see:
|
|
38
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
39
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
40
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
41
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
38
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/BuildFormButtonTesterWrapperForStorybook.tsx
|
|
39
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/BuildFormButtonForStorybook.tsx
|
|
40
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/PrePopWrapperForStorybook.tsx
|
|
41
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/PrePopButtonForStorybook.tsx
|
|
42
42
|
*
|
|
43
43
|
* @author Sean Fong
|
|
44
44
|
*/
|
package/lib/theme/Theme.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ declare module '@mui/material/styles' {
|
|
|
33
33
|
}
|
|
34
34
|
export declare const themeOptions: ThemeOptions;
|
|
35
35
|
/**
|
|
36
|
-
* Default
|
|
36
|
+
* Default theme used by the renderer using Material UI. You can customise your own theme by defining a new ThemeProvider.
|
|
37
37
|
* @see {@link https://mui.com/material-ui/customization/theming/}
|
|
38
38
|
*
|
|
39
39
|
* @author Sean Fong
|
package/lib/theme/Theme.js
CHANGED
|
@@ -27,7 +27,7 @@ export const themeOptions = {
|
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
|
-
* Default
|
|
30
|
+
* Default theme used by the renderer using Material UI. You can customise your own theme by defining a new ThemeProvider.
|
|
31
31
|
* @see {@link https://mui.com/material-ui/customization/theming/}
|
|
32
32
|
*
|
|
33
33
|
* @author Sean Fong
|
|
@@ -37,8 +37,9 @@ export declare function initialiseFhirClient(fhirClient: Client): Promise<void>;
|
|
|
37
37
|
*/
|
|
38
38
|
export declare function getResponse(): QuestionnaireResponse;
|
|
39
39
|
/**
|
|
40
|
-
* Remove all hidden answers from the filled QuestionnaireResponse.
|
|
40
|
+
* Remove all empty/hidden answers from the filled QuestionnaireResponse.
|
|
41
41
|
* This takes into account enableWhens, enableWhenExpressions, items without item.answer, empty item.answer arrays and empty strings.
|
|
42
|
+
* This does not remove items that are hidden by the http://hl7.org/fhir/StructureDefinition/questionnaire-hidden extension.
|
|
42
43
|
*
|
|
43
44
|
* @author Sean Fong
|
|
44
45
|
*/
|
package/lib/utils/manageForm.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { questionnaireResponseStore, questionnaireStore, smartConfigStore } from '../stores';
|
|
10
|
+
import { questionnaireResponseStore, questionnaireStore, smartConfigStore, terminologyServerStore } from '../stores';
|
|
11
11
|
import { initialiseQuestionnaireResponse } from './initialise';
|
|
12
12
|
import { removeEmptyAnswers } from './removeEmptyAnswers';
|
|
13
13
|
import { readEncounter, readPatient, readUser } from '../api/smartClient';
|
|
@@ -26,6 +26,12 @@ import { readEncounter, readPatient, readUser } from '../api/smartClient';
|
|
|
26
26
|
*/
|
|
27
27
|
export function buildForm(questionnaire, questionnaireResponse, readOnly, terminologyServerUrl, additionalVariables) {
|
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
if (terminologyServerUrl) {
|
|
30
|
+
terminologyServerStore.getState().setUrl(terminologyServerUrl);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
terminologyServerStore.getState().resetUrl();
|
|
34
|
+
}
|
|
29
35
|
// QR is set to undefined here to prevent it from being initialised twice. This is defined like that for backward compatibility purposes.
|
|
30
36
|
yield questionnaireStore
|
|
31
37
|
.getState()
|
|
@@ -81,8 +87,9 @@ export function getResponse() {
|
|
|
81
87
|
return questionnaireResponseStore.getState().updatableResponse;
|
|
82
88
|
}
|
|
83
89
|
/**
|
|
84
|
-
* Remove all hidden answers from the filled QuestionnaireResponse.
|
|
90
|
+
* Remove all empty/hidden answers from the filled QuestionnaireResponse.
|
|
85
91
|
* This takes into account enableWhens, enableWhenExpressions, items without item.answer, empty item.answer arrays and empty strings.
|
|
92
|
+
* This does not remove items that are hidden by the http://hl7.org/fhir/StructureDefinition/questionnaire-hidden extension.
|
|
86
93
|
*
|
|
87
94
|
* @author Sean Fong
|
|
88
95
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manageForm.js","sourceRoot":"","sources":["../../src/utils/manageForm.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"manageForm.js","sourceRoot":"","sources":["../../src/utils/manageForm.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aehrc/smart-forms-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "FHIR Structured Data Captured (SDC) rendering engine for Smart Forms",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/aehrc/smart-forms#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@aehrc/sdc-populate": "^2.0.
|
|
30
|
+
"@aehrc/sdc-populate": "^2.0.3",
|
|
31
31
|
"@iconify/react": "^4.1.1",
|
|
32
32
|
"dayjs": "^1.11.10",
|
|
33
33
|
"deep-diff": "^1.0.2",
|
|
@@ -54,7 +54,7 @@ export interface SmartFormsRendererProps {
|
|
|
54
54
|
/**
|
|
55
55
|
* A self-initialising wrapper around the BaseRenderer rendering engine.
|
|
56
56
|
* Will be deprecated in version 1.0.0. For alternative usage, see:
|
|
57
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
57
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/InitialiseFormWrapperForStorybook.tsx#L40-L57
|
|
58
58
|
*
|
|
59
59
|
* @see SmartFormsRendererProps for props.
|
|
60
60
|
*
|
|
@@ -42,13 +42,13 @@ import { createQuestionnaireResponseItemMap } from '../utils/questionnaireRespon
|
|
|
42
42
|
* @property formChangesHistory - Array of form changes history in the form of deep-diff objects
|
|
43
43
|
* @property invalidItems - Key-value pair of invalid items based on defined value constraints in the questionnaire `Record<linkId, OperationOutcome>`
|
|
44
44
|
* @property responseIsValid - Whether there are any invalid items in the response
|
|
45
|
-
* @
|
|
46
|
-
* @
|
|
47
|
-
* @
|
|
48
|
-
* @
|
|
49
|
-
* @
|
|
50
|
-
* @
|
|
51
|
-
* @
|
|
45
|
+
* @property validateQuestionnaire - Used to validate the questionnaire response based on the questionnaire
|
|
46
|
+
* @property buildSourceResponse - Used to build the source response when the form is first initialised
|
|
47
|
+
* @property setUpdatableResponseAsPopulated - Used to set a pre-populated response as the current response
|
|
48
|
+
* @property updateResponse - Used to update the current response
|
|
49
|
+
* @property setUpdatableResponseAsSaved - Used to set a saved response as the current response
|
|
50
|
+
* @property setUpdatableResponseAsEmpty - Used to set an empty response as the current response
|
|
51
|
+
* @property destroySourceResponse - Used to destroy the source response and reset all properties
|
|
52
52
|
*
|
|
53
53
|
* @author Sean Fong
|
|
54
54
|
*/
|
|
@@ -71,19 +71,19 @@ import { createQuestionnaireResponseItemMap } from '../utils/questionnaireRespon
|
|
|
71
71
|
* @property populatedContext - Key-value pair of one-off pre-populated FHIRPath values `Record<variable/launchContext/sourceQueries batch name, evaluated value(s)>`
|
|
72
72
|
* @property focusedLinkId - LinkId of the currently focused item
|
|
73
73
|
* @property readOnly - Flag to set the form to read-only mode
|
|
74
|
-
* @
|
|
75
|
-
* @
|
|
76
|
-
* @
|
|
77
|
-
* @
|
|
78
|
-
* @
|
|
79
|
-
* @
|
|
80
|
-
* @
|
|
81
|
-
* @
|
|
82
|
-
* @
|
|
83
|
-
* @
|
|
84
|
-
* @
|
|
85
|
-
* @
|
|
86
|
-
* @
|
|
74
|
+
* @property buildSourceQuestionnaire - Used to build the source questionnaire with the provided questionnaire and optionally questionnaire response, additional variables, terminology server url and readyOnly flag
|
|
75
|
+
* @property destroySourceQuestionnaire - Used to destroy the source questionnaire and reset all properties
|
|
76
|
+
* @property switchTab - Used to switch the current tab index
|
|
77
|
+
* @property markTabAsComplete - Used to mark a tab index as complete
|
|
78
|
+
* @property updateEnableWhenItem - Used to update linked enableWhen items by updating a question with a new answer
|
|
79
|
+
* @property mutateRepeatEnableWhenItems - Used to add or remove instances of repeating enableWhen items
|
|
80
|
+
* @property toggleEnableWhenActivation - Used to toggle enableWhen checks on/off
|
|
81
|
+
* @property updateExpressions - Used to update all SDC expressions based on the updated questionnaire response
|
|
82
|
+
* @property addCodingToCache - Used to add a coding to the cached value set codings
|
|
83
|
+
* @property updatePopulatedProperties - Used to update all SDC expressions based on a pre-populated questionnaire response
|
|
84
|
+
* @property onFocusLinkId - Used to set the focused linkId
|
|
85
|
+
* @property setPopulatedContext - Used to set the populated contexts (launchContext, sourceQueries, x-fhir-query vars) for debugging purposes
|
|
86
|
+
* @property setFormAsReadOnly - Used to set the form as read-only
|
|
87
87
|
*
|
|
88
88
|
* @author Sean Fong
|
|
89
89
|
*/
|
|
@@ -29,10 +29,10 @@ import { createSelectors } from './selector';
|
|
|
29
29
|
* @property patient - The patient resource in context
|
|
30
30
|
* @property user - The user resource in context
|
|
31
31
|
* @property encounter - The encounter resource in context
|
|
32
|
-
* @
|
|
33
|
-
* @
|
|
34
|
-
* @
|
|
35
|
-
* @
|
|
32
|
+
* @property setClient - Set the FHIRClient object when launching via SMART App Launch
|
|
33
|
+
* @property setPatient - Set the patient resource in context
|
|
34
|
+
* @property setUser - Set the user resource in context
|
|
35
|
+
* @property setEncounter - Set the encounter resource in context
|
|
36
36
|
*
|
|
37
37
|
* @author Sean Fong
|
|
38
38
|
*/
|
|
@@ -26,8 +26,8 @@ const ONTOSERVER_R4 = 'https://r4.ontoserver.csiro.au/fhir';
|
|
|
26
26
|
* Methods are usually used internally, using them from an external source is not recommended.
|
|
27
27
|
*
|
|
28
28
|
* @property url - The current terminology server URL
|
|
29
|
-
* @
|
|
30
|
-
* @
|
|
29
|
+
* @property setUrl - Set the terminology server URL
|
|
30
|
+
* @property resetUrl - Reset the terminology server URL to the default
|
|
31
31
|
*
|
|
32
32
|
* @author Sean Fong
|
|
33
33
|
*/
|
|
@@ -35,7 +35,7 @@ interface BuildFormButtonTesterWrapperForStorybookProps {
|
|
|
35
35
|
* It was done as a two-step process for demo purposes.
|
|
36
36
|
*
|
|
37
37
|
* Use this pattern if you already have a pre-populated/pre-filled/draft response.
|
|
38
|
-
* If you want to pre-pop on the fly, see https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
38
|
+
* If you want to pre-pop on the fly, see https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/PrePopWrapperForStorybook.tsx instead
|
|
39
39
|
*
|
|
40
40
|
* @author Sean Fong
|
|
41
41
|
*/
|
|
@@ -48,10 +48,10 @@ export interface InitialiseFormWrapperProps {
|
|
|
48
48
|
* - The initialised FHIRClient is only used for further FHIR calls. It does not provide pre-population capabilities.
|
|
49
49
|
*
|
|
50
50
|
* For button click usage examples of buildForm(), see:
|
|
51
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
52
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
53
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
54
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
51
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/BuildFormButtonTesterWrapperForStorybook.tsx
|
|
52
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/BuildFormButtonForStorybook.tsx
|
|
53
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/PrePopWrapperForStorybook.tsx
|
|
54
|
+
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/PrePopButtonForStorybook.tsx
|
|
55
55
|
*
|
|
56
56
|
* @author Sean Fong
|
|
57
57
|
*/
|
|
@@ -41,7 +41,7 @@ interface PrePopWrapperForStorybookProps {
|
|
|
41
41
|
* This does in-app population and you have to define your own callback function to retrieve resources from your source server.
|
|
42
42
|
*
|
|
43
43
|
* Use this pattern if you do not have a pre-populated/pre-filled/draft response and want to pre-populate on the fly.
|
|
44
|
-
* If you already have a questionnaireResponse, see https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
44
|
+
* If you already have a questionnaireResponse, see https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/BuildFormButtonTesterWrapperForStorybook.tsx instead
|
|
45
45
|
*
|
|
46
46
|
* @author Sean Fong
|
|
47
47
|
*/
|
|
@@ -27,7 +27,7 @@ interface RequestConfig {
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Sample callback function to fetch resources from your source server when using populate() or populateQuestionnaire() from @aehrc/sdc-populate.
|
|
30
|
-
* See https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/
|
|
30
|
+
* See https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/PrePopWrapperForStorybook.tsx for usage.
|
|
31
31
|
*
|
|
32
32
|
* @author Sean Fong
|
|
33
33
|
*/
|
|
@@ -35,14 +35,14 @@ type Story = StoryObj<typeof meta>;
|
|
|
35
35
|
|
|
36
36
|
export const BuildFormButtonTester: Story = {
|
|
37
37
|
args: {
|
|
38
|
-
questionnaire:
|
|
39
|
-
questionnaireResponse:
|
|
38
|
+
questionnaire: qButtonTester,
|
|
39
|
+
questionnaireResponse: qrButtonTesterResponse
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
export const BuildFormButtonTesterBoolean: Story = {
|
|
44
44
|
args: {
|
|
45
|
-
questionnaire:
|
|
46
|
-
questionnaireResponse:
|
|
45
|
+
questionnaire: qBooleanBasic,
|
|
46
|
+
questionnaireResponse: qrBooleanBasicResponse
|
|
47
47
|
}
|
|
48
48
|
};
|
package/src/theme/Theme.tsx
CHANGED
|
@@ -90,7 +90,7 @@ export const themeOptions: ThemeOptions = {
|
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
|
-
* Default
|
|
93
|
+
* Default theme used by the renderer using Material UI. You can customise your own theme by defining a new ThemeProvider.
|
|
94
94
|
* @see {@link https://mui.com/material-ui/customization/theming/}
|
|
95
95
|
*
|
|
96
96
|
* @author Sean Fong
|
package/src/utils/manageForm.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Questionnaire, QuestionnaireResponse } from 'fhir/r4';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
questionnaireResponseStore,
|
|
4
|
+
questionnaireStore,
|
|
5
|
+
smartConfigStore,
|
|
6
|
+
terminologyServerStore
|
|
7
|
+
} from '../stores';
|
|
3
8
|
import { initialiseQuestionnaireResponse } from './initialise';
|
|
4
9
|
import { removeEmptyAnswers } from './removeEmptyAnswers';
|
|
5
10
|
import { readEncounter, readPatient, readUser } from '../api/smartClient';
|
|
@@ -25,6 +30,12 @@ export async function buildForm(
|
|
|
25
30
|
terminologyServerUrl?: string,
|
|
26
31
|
additionalVariables?: Record<string, object>
|
|
27
32
|
): Promise<void> {
|
|
33
|
+
if (terminologyServerUrl) {
|
|
34
|
+
terminologyServerStore.getState().setUrl(terminologyServerUrl);
|
|
35
|
+
} else {
|
|
36
|
+
terminologyServerStore.getState().resetUrl();
|
|
37
|
+
}
|
|
38
|
+
|
|
28
39
|
// QR is set to undefined here to prevent it from being initialised twice. This is defined like that for backward compatibility purposes.
|
|
29
40
|
await questionnaireStore
|
|
30
41
|
.getState()
|
|
@@ -87,8 +98,9 @@ export function getResponse(): QuestionnaireResponse {
|
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
/**
|
|
90
|
-
* Remove all hidden answers from the filled QuestionnaireResponse.
|
|
101
|
+
* Remove all empty/hidden answers from the filled QuestionnaireResponse.
|
|
91
102
|
* This takes into account enableWhens, enableWhenExpressions, items without item.answer, empty item.answer arrays and empty strings.
|
|
103
|
+
* This does not remove items that are hidden by the http://hl7.org/fhir/StructureDefinition/questionnaire-hidden extension.
|
|
92
104
|
*
|
|
93
105
|
* @author Sean Fong
|
|
94
106
|
*/
|