@aehrc/smart-forms-renderer 1.2.10 → 1.2.11
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/jest.config.ts +5 -5
- package/lib/utils/manageForm.js +4 -4
- package/lib/utils/manageForm.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/manageForm.ts +9 -9
- package/lib/components/FormComponents/ItemParts/AccessibleFeedback.d.ts +0 -7
- package/lib/components/FormComponents/ItemParts/AccessibleFeedback.js +0 -7
- package/lib/components/FormComponents/ItemParts/AccessibleFeedback.js.map +0 -1
- package/lib/interfaces/itemPath.interface.d.ts +0 -31
- package/lib/interfaces/itemPath.interface.js +0 -2
- package/lib/interfaces/itemPath.interface.js.map +0 -1
- package/lib/stories/storybookWrappers/InitialiseFormWrapperForStorybook.d.ts +0 -30
- package/lib/stories/storybookWrappers/InitialiseFormWrapperForStorybook.js +0 -46
- package/lib/stories/storybookWrappers/InitialiseFormWrapperForStorybook.js.map +0 -1
- package/lib/stories/storybookWrappers/index.d.ts +0 -2
- package/lib/stories/storybookWrappers/index.js +0 -18
- package/lib/stories/storybookWrappers/index.js.map +0 -1
- package/lib/stories/testUtils.d.ts +0 -23
- package/lib/stories/testUtils.js +0 -249
- package/lib/stories/testUtils.js.map +0 -1
- package/lib/utils/itemPath.d.ts +0 -57
- package/lib/utils/itemPath.js +0 -75
- package/lib/utils/itemPath.js.map +0 -1
package/jest.config.ts
CHANGED
|
@@ -29,12 +29,12 @@ const config: JestConfigWithTsJest = {
|
|
|
29
29
|
],
|
|
30
30
|
coverageThreshold: {
|
|
31
31
|
"global": {
|
|
32
|
-
"statements":
|
|
33
|
-
"branches":
|
|
34
|
-
"functions":
|
|
35
|
-
"lines":
|
|
32
|
+
"statements": 75,
|
|
33
|
+
"branches": 70,
|
|
34
|
+
"functions": 75,
|
|
35
|
+
"lines": 75,
|
|
36
36
|
}
|
|
37
|
-
}
|
|
37
|
+
},
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
export default config;
|
package/lib/utils/manageForm.js
CHANGED
|
@@ -34,13 +34,13 @@ export async function buildForm(params) {
|
|
|
34
34
|
else {
|
|
35
35
|
terminologyServerStore.getState().resetUrl();
|
|
36
36
|
}
|
|
37
|
-
// QR is set to undefined here to prevent it from being initialised twice. This is defined like that for backward compatibility purposes.
|
|
38
|
-
await questionnaireStore
|
|
39
|
-
.getState()
|
|
40
|
-
.buildSourceQuestionnaire(questionnaire, undefined, additionalContext, terminologyServerUrl, readOnly, qItemOverrideComponents, sdcUiOverrideComponents);
|
|
41
37
|
// Initialise an empty questionnaireResponse from a given questionnaire
|
|
42
38
|
// Optionally takes in an existing questionnaireResponse to be initialised
|
|
43
39
|
const initialisedQuestionnaireResponse = initialiseQuestionnaireResponse(questionnaire, questionnaireResponse);
|
|
40
|
+
// The buildSourceQuestionnaire function now takes the initialisedQuestionnaireResponse, which includes item.initial values from the Questionnaire.
|
|
41
|
+
await questionnaireStore
|
|
42
|
+
.getState()
|
|
43
|
+
.buildSourceQuestionnaire(questionnaire, initialisedQuestionnaireResponse, additionalContext, terminologyServerUrl, readOnly, qItemOverrideComponents, sdcUiOverrideComponents);
|
|
44
44
|
// Set initialised QuestionnaireResponse as the source response in the store
|
|
45
45
|
questionnaireResponseStore.getState().buildSourceResponse(initialisedQuestionnaireResponse);
|
|
46
46
|
// Process expressions asynchronously
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manageForm.js","sourceRoot":"","sources":["../../src/utils/manageForm.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,mCAAmC,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,MAA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AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAiC;IACtE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACpG,CAAC"}
|
package/package.json
CHANGED
package/src/utils/manageForm.ts
CHANGED
|
@@ -116,12 +116,19 @@ export async function buildForm(params: BuildFormParams): Promise<void> {
|
|
|
116
116
|
terminologyServerStore.getState().resetUrl();
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
//
|
|
119
|
+
// Initialise an empty questionnaireResponse from a given questionnaire
|
|
120
|
+
// Optionally takes in an existing questionnaireResponse to be initialised
|
|
121
|
+
const initialisedQuestionnaireResponse = initialiseQuestionnaireResponse(
|
|
122
|
+
questionnaire,
|
|
123
|
+
questionnaireResponse
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// The buildSourceQuestionnaire function now takes the initialisedQuestionnaireResponse, which includes item.initial values from the Questionnaire.
|
|
120
127
|
await questionnaireStore
|
|
121
128
|
.getState()
|
|
122
129
|
.buildSourceQuestionnaire(
|
|
123
130
|
questionnaire,
|
|
124
|
-
|
|
131
|
+
initialisedQuestionnaireResponse,
|
|
125
132
|
additionalContext,
|
|
126
133
|
terminologyServerUrl,
|
|
127
134
|
readOnly,
|
|
@@ -129,13 +136,6 @@ export async function buildForm(params: BuildFormParams): Promise<void> {
|
|
|
129
136
|
sdcUiOverrideComponents
|
|
130
137
|
);
|
|
131
138
|
|
|
132
|
-
// Initialise an empty questionnaireResponse from a given questionnaire
|
|
133
|
-
// Optionally takes in an existing questionnaireResponse to be initialised
|
|
134
|
-
const initialisedQuestionnaireResponse = initialiseQuestionnaireResponse(
|
|
135
|
-
questionnaire,
|
|
136
|
-
questionnaireResponse
|
|
137
|
-
);
|
|
138
|
-
|
|
139
139
|
// Set initialised QuestionnaireResponse as the source response in the store
|
|
140
140
|
questionnaireResponseStore.getState().buildSourceResponse(initialisedQuestionnaireResponse);
|
|
141
141
|
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from 'react';
|
|
2
|
-
interface AccessibleFeedbackProps {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
id?: string;
|
|
5
|
-
}
|
|
6
|
-
declare function AccessibleFeedback(props: AccessibleFeedbackProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
-
export default AccessibleFeedback;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
function AccessibleFeedback(props) {
|
|
3
|
-
const { children, id } = props;
|
|
4
|
-
return (_jsx("span", { id: id, role: "alert", "aria-live": "assertive", children: children }));
|
|
5
|
-
}
|
|
6
|
-
export default AccessibleFeedback;
|
|
7
|
-
//# sourceMappingURL=AccessibleFeedback.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AccessibleFeedback.js","sourceRoot":"","sources":["../../../../src/components/FormComponents/ItemParts/AccessibleFeedback.tsx"],"names":[],"mappings":";AAwBA,SAAS,kBAAkB,CAAC,KAA8B;IACxD,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC;IAE/B,OAAO,CACL,eAAM,EAAE,EAAE,EAAE,EAAE,IAAI,EAAC,OAAO,eAAW,WAAW,YAC7C,QAAQ,GACJ,CACR,CAAC;AACJ,CAAC;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a single step in the path to an item within a nested QuestionnaireResponse.
|
|
3
|
-
* Each step is identified by its `linkId`, and optionally a `repeatIndex` if the item
|
|
4
|
-
* occurs within a repeating group.
|
|
5
|
-
*/
|
|
6
|
-
export interface ItemPathSegment {
|
|
7
|
-
/** The `linkId` of the QuestionnaireResponseItem at this path segment. */
|
|
8
|
-
linkId: string;
|
|
9
|
-
/**
|
|
10
|
-
* The index of the repeated item if this segment occurs within a repeating group.
|
|
11
|
-
* Omitted if the item is not part of a repeating group.
|
|
12
|
-
*/
|
|
13
|
-
repeatIndex?: number;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Represents a full path from the root of a QuestionnaireResponse to a deeply nested item.
|
|
17
|
-
* Each segment corresponds to one level of the item hierarchy.
|
|
18
|
-
*
|
|
19
|
-
* Example:
|
|
20
|
-
* [
|
|
21
|
-
* { linkId: 'sectionA' },
|
|
22
|
-
* { linkId: 'groupB', repeatIndex: 1 },
|
|
23
|
-
* { linkId: 'questionC' }
|
|
24
|
-
* ]
|
|
25
|
-
*
|
|
26
|
-
* This path navigates through `sectionA`, into the second instance of `groupB`,
|
|
27
|
-
* and finally to `questionC`.
|
|
28
|
-
*
|
|
29
|
-
* @author Sean Fong
|
|
30
|
-
*/
|
|
31
|
-
export type ItemPath = ItemPathSegment[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"itemPath.interface.js","sourceRoot":"","sources":["../../src/interfaces/itemPath.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Questionnaire, QuestionnaireResponse } from 'fhir/r4';
|
|
2
|
-
import type Client from 'fhirclient/lib/Client';
|
|
3
|
-
export interface InitialiseFormWrapperProps {
|
|
4
|
-
questionnaire: Questionnaire;
|
|
5
|
-
questionnaireResponse?: QuestionnaireResponse;
|
|
6
|
-
readOnly?: boolean;
|
|
7
|
-
terminologyServerUrl?: string;
|
|
8
|
-
additionalContext?: Record<string, any>;
|
|
9
|
-
fhirClient?: Client;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* This is a one-to-one replacement for the SmartFormsRenderer for demo purposes.
|
|
13
|
-
* Instead of using this React component, define your own wrapper component that uses the BaseRenderer directly.
|
|
14
|
-
* Things to note:
|
|
15
|
-
* - It is required to wrap the BaseRenderer with the QueryClientProvider to make requests.
|
|
16
|
-
* - You can wrap the BaseRenderer with the RendererThemeProvider to apply the default renderer theme used in Smart Forms. Optionally, you can define your own ThemeProvider https://mui.com/material-ui/customization/theming/.
|
|
17
|
-
* - Make your buildForm() call in a button click or other event handler. Alternatively, you can use the useInitialiseForm hook to initialise the form.
|
|
18
|
-
* - Make your own initialiseFhirClient() call in a button click or other event handler. Alternatively, you can use the useInitialiseForm hook to initialise the form.
|
|
19
|
-
* - The initialised FHIRClient is only used for further FHIR calls. It does not provide pre-population capabilities.
|
|
20
|
-
*
|
|
21
|
-
* For button click usage examples of buildForm(), see:
|
|
22
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/BuildFormButtonTesterWrapperForStorybook.tsx
|
|
23
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/BuildFormButtonForStorybook.tsx
|
|
24
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/PrePopWrapperForStorybook.tsx
|
|
25
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/PrePopButtonForStorybook.tsx
|
|
26
|
-
*
|
|
27
|
-
* @author Sean Fong
|
|
28
|
-
*/
|
|
29
|
-
declare function InitialiseFormWrapperForStorybook(props: InitialiseFormWrapperProps): import("react/jsx-runtime").JSX.Element;
|
|
30
|
-
export default InitialiseFormWrapperForStorybook;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { BaseRenderer } from '../../components';
|
|
3
|
-
import { QueryClientProvider } from '@tanstack/react-query';
|
|
4
|
-
import useRendererQueryClient from '../../hooks/useRendererQueryClient';
|
|
5
|
-
import useInitialiseForm from '../../hooks/useInitialiseForm';
|
|
6
|
-
import Box from '@mui/material/Box';
|
|
7
|
-
import CircularProgress from '@mui/material/CircularProgress';
|
|
8
|
-
import Typography from '@mui/material/Typography';
|
|
9
|
-
import RendererThemeProvider from '../../theme/RendererThemeProvider';
|
|
10
|
-
/**
|
|
11
|
-
* This is a one-to-one replacement for the SmartFormsRenderer for demo purposes.
|
|
12
|
-
* Instead of using this React component, define your own wrapper component that uses the BaseRenderer directly.
|
|
13
|
-
* Things to note:
|
|
14
|
-
* - It is required to wrap the BaseRenderer with the QueryClientProvider to make requests.
|
|
15
|
-
* - You can wrap the BaseRenderer with the RendererThemeProvider to apply the default renderer theme used in Smart Forms. Optionally, you can define your own ThemeProvider https://mui.com/material-ui/customization/theming/.
|
|
16
|
-
* - Make your buildForm() call in a button click or other event handler. Alternatively, you can use the useInitialiseForm hook to initialise the form.
|
|
17
|
-
* - Make your own initialiseFhirClient() call in a button click or other event handler. Alternatively, you can use the useInitialiseForm hook to initialise the form.
|
|
18
|
-
* - The initialised FHIRClient is only used for further FHIR calls. It does not provide pre-population capabilities.
|
|
19
|
-
*
|
|
20
|
-
* For button click usage examples of buildForm(), see:
|
|
21
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/BuildFormButtonTesterWrapperForStorybook.tsx
|
|
22
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/BuildFormButtonForStorybook.tsx
|
|
23
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/PrePopWrapperForStorybook.tsx
|
|
24
|
-
* - https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/storybookWrappers/PrePopButtonForStorybook.tsx
|
|
25
|
-
*
|
|
26
|
-
* @author Sean Fong
|
|
27
|
-
*/
|
|
28
|
-
function InitialiseFormWrapperForStorybook(props) {
|
|
29
|
-
const { questionnaire, questionnaireResponse, readOnly, terminologyServerUrl, additionalContext, fhirClient } = props;
|
|
30
|
-
// The renderer requires a @tanstack/react-query QueryClientProvider to make requests
|
|
31
|
-
const queryClient = useRendererQueryClient();
|
|
32
|
-
/**
|
|
33
|
-
* The useInitialiseForm hook provides initialisation logic for the form
|
|
34
|
-
* Alternatively (and recommended to do so), you can initialise your form via a button click or other event handler.
|
|
35
|
-
*
|
|
36
|
-
* @see {@link https://github.com/aehrc/smart-forms/blob/main/packages/smart-forms-renderer/src/stories/BuildFormButtonForStorybook.tsx} for button click usage examples.
|
|
37
|
-
*/
|
|
38
|
-
const isInitialising = useInitialiseForm(questionnaire, questionnaireResponse, readOnly, terminologyServerUrl, additionalContext, fhirClient);
|
|
39
|
-
// Free feel to customise your loading animation here
|
|
40
|
-
if (isInitialising) {
|
|
41
|
-
return (_jsxs(Box, { display: "flex", alignItems: "center", columnGap: 2, children: [_jsx(CircularProgress, {}), _jsx(Typography, { children: "Loading questionnaire..." })] }));
|
|
42
|
-
}
|
|
43
|
-
return (_jsx(RendererThemeProvider, { children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(BaseRenderer, {}) }) }));
|
|
44
|
-
}
|
|
45
|
-
export default InitialiseFormWrapperForStorybook;
|
|
46
|
-
//# sourceMappingURL=InitialiseFormWrapperForStorybook.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InitialiseFormWrapperForStorybook.js","sourceRoot":"","sources":["../../../src/stories/storybookWrappers/InitialiseFormWrapperForStorybook.tsx"],"names":[],"mappings":";AAoBA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,sBAAsB,MAAM,oCAAoC,CAAC;AAExE,OAAO,iBAAiB,MAAM,+BAA+B,CAAC;AAC9D,OAAO,GAAG,MAAM,mBAAmB,CAAC;AACpC,OAAO,gBAAgB,MAAM,gCAAgC,CAAC;AAC9D,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAClD,OAAO,qBAAqB,MAAM,mCAAmC,CAAC;AAWtE;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAS,iCAAiC,CAAC,KAAiC;IAC1E,MAAM,EACJ,aAAa,EACb,qBAAqB,EACrB,QAAQ,EACR,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACX,GAAG,KAAK,CAAC;IAEV,qFAAqF;IACrF,MAAM,WAAW,GAAG,sBAAsB,EAAE,CAAC;IAE7C;;;;;OAKG;IACH,MAAM,cAAc,GAAG,iBAAiB,CACtC,aAAa,EACb,qBAAqB,EACrB,QAAQ,EACR,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,CACX,CAAC;IAEF,qDAAqD;IACrD,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,CACL,MAAC,GAAG,IAAC,OAAO,EAAC,MAAM,EAAC,UAAU,EAAC,QAAQ,EAAC,SAAS,EAAE,CAAC,aAClD,KAAC,gBAAgB,KAAG,EACpB,KAAC,UAAU,2CAAsC,IAC7C,CACP,CAAC;IACJ,CAAC;IAED,OAAO,CACL,KAAC,qBAAqB,cACpB,KAAC,mBAAmB,IAAC,MAAM,EAAE,WAAW,YACtC,KAAC,YAAY,KAAG,GACI,GACA,CACzB,CAAC;AACJ,CAAC;AAED,eAAe,iCAAiC,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2025 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
|
-
export { default as InitialiseFormWrapperForStorybook } from './InitialiseFormWrapperForStorybook';
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stories/storybookWrappers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,OAAO,IAAI,iCAAiC,EAAE,MAAM,qCAAqC,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Extension, Questionnaire, QuestionnaireItem, QuestionnaireResponse, QuestionnaireResponseItem } from 'fhir/r4';
|
|
2
|
-
export declare function getAnswers(linkId: string): Promise<any[]>;
|
|
3
|
-
export declare function getGroupAnswers(groupLinkid: string, answerLinkid: string): Promise<any[]>;
|
|
4
|
-
export declare function questionnaireFactory(items: QuestionnaireItem[]): Questionnaire;
|
|
5
|
-
export declare function qrFactory(items: QuestionnaireResponseItem[]): QuestionnaireResponse;
|
|
6
|
-
export declare function itemControlExtFactory(code: string): Extension;
|
|
7
|
-
export declare function openLabelExtFactory(text: string): Extension;
|
|
8
|
-
export declare function inputText(canvasElement: HTMLElement, linkId: string, text: string | boolean | number): Promise<void>;
|
|
9
|
-
export declare function checkCheckBox(canvasElement: HTMLElement, linkId: string): Promise<void>;
|
|
10
|
-
export declare function inputFile(canvasElement: HTMLElement, linkId: string, files: File | File[], url: string, filename: string): Promise<void>;
|
|
11
|
-
export declare function inputDate(canvasElement: HTMLElement, linkId: string, text: string | boolean): Promise<void>;
|
|
12
|
-
export declare function inputTime(canvasElement: HTMLElement, linkId: string, text: string | boolean): Promise<void>;
|
|
13
|
-
export declare function inputReference(canvasElement: HTMLElement, linkId: string, text: string | boolean): Promise<void>;
|
|
14
|
-
export declare function inputDecimal(canvasElement: HTMLElement, linkId: string, text: number): Promise<void>;
|
|
15
|
-
export declare function inputUrl(canvasElement: HTMLElement, linkId: string, text: string): Promise<void>;
|
|
16
|
-
export declare function inputInteger(canvasElement: HTMLElement, linkId: string, text: number): Promise<void>;
|
|
17
|
-
export declare function inputDateTime(canvasElement: HTMLElement, linkId: string, date: string, time: string, amPm: string): Promise<void>;
|
|
18
|
-
export declare function checkRadioOption(canvasElement: HTMLElement, linkId: string, text: string): Promise<void>;
|
|
19
|
-
export declare function getInputText(canvasElement: HTMLElement, linkId: string): Promise<string>;
|
|
20
|
-
export declare function chooseSelectOption(canvasElement: HTMLElement, linkId: string, optionLabel: string): Promise<void>;
|
|
21
|
-
export declare function chooseQuantityOption(canvasElement: HTMLElement, linkId: string, quantity: number | string, quantityComparator?: string): Promise<void>;
|
|
22
|
-
export declare function findByLinkIdOrLabel(canvasElement: HTMLElement, linkId: string): Promise<HTMLElement>;
|
|
23
|
-
export declare function inputOpenChoiceOtherText(canvasElement: HTMLElement, linkId: string, text: string): Promise<void>;
|
package/lib/stories/testUtils.js
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { evaluate } from 'fhirpath';
|
|
11
|
-
import { questionnaireResponseStore } from '../stores';
|
|
12
|
-
import { fireEvent, screen, waitFor } from '@testing-library/react';
|
|
13
|
-
import { userEvent } from '@testing-library/user-event';
|
|
14
|
-
export function getAnswers(linkId) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const qr = questionnaireResponseStore.getState().updatableResponse;
|
|
17
|
-
const result = yield evaluate(qr, `QuestionnaireResponse.item.where(linkId='${linkId}').answer`);
|
|
18
|
-
return result;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
export function getGroupAnswers(groupLinkid, answerLinkid) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const qr = questionnaireResponseStore.getState().updatableResponse;
|
|
24
|
-
const result = yield evaluate(qr, groupLinkid
|
|
25
|
-
? `QuestionnaireResponse.item.where(linkId='${groupLinkid}').item.where(linkId='${answerLinkid}').answer`
|
|
26
|
-
: `QuestionnaireResponse.item.where(linkId='${answerLinkid}').answer`);
|
|
27
|
-
return result;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
export function questionnaireFactory(items) {
|
|
31
|
-
return {
|
|
32
|
-
resourceType: 'Questionnaire',
|
|
33
|
-
status: 'active',
|
|
34
|
-
item: items
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
export function qrFactory(items) {
|
|
38
|
-
return {
|
|
39
|
-
resourceType: 'QuestionnaireResponse',
|
|
40
|
-
status: 'completed',
|
|
41
|
-
item: items
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
export function itemControlExtFactory(code) {
|
|
45
|
-
return {
|
|
46
|
-
url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl',
|
|
47
|
-
valueCodeableConcept: {
|
|
48
|
-
coding: [
|
|
49
|
-
{
|
|
50
|
-
system: 'http://hl7.org/fhir/questionnaire-item-control',
|
|
51
|
-
code: code
|
|
52
|
-
}
|
|
53
|
-
]
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
export function openLabelExtFactory(text) {
|
|
58
|
-
return {
|
|
59
|
-
url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-openLabel',
|
|
60
|
-
valueString: text
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
export function inputText(canvasElement, linkId, text) {
|
|
64
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
var _a;
|
|
66
|
-
const questionElement = yield findByLinkIdOrLabel(canvasElement, linkId);
|
|
67
|
-
const input = (_a = questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector('input')) !== null && _a !== void 0 ? _a : questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector('textarea');
|
|
68
|
-
if (!input) {
|
|
69
|
-
throw new Error(`Input or textarea was not found inside ${`[data-linkid=${linkId}] block`}`);
|
|
70
|
-
}
|
|
71
|
-
fireEvent.change(input, { target: { value: text } });
|
|
72
|
-
// Here we await for debounced store update
|
|
73
|
-
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
export function checkCheckBox(canvasElement, linkId) {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
var _a;
|
|
79
|
-
const questionElement = yield findByLinkIdOrLabel(canvasElement, linkId);
|
|
80
|
-
const input = (_a = questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector('input')) !== null && _a !== void 0 ? _a : questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector('textarea');
|
|
81
|
-
if (!input) {
|
|
82
|
-
throw new Error(`Input or textarea was not found inside ${`[data-linkid=${linkId}] block`}`);
|
|
83
|
-
}
|
|
84
|
-
fireEvent.click(input);
|
|
85
|
-
// Here we await for debounced store update
|
|
86
|
-
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
export function inputFile(canvasElement, linkId, files, url, filename) {
|
|
90
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
const questionElement = yield findByLinkIdOrLabel(canvasElement, linkId);
|
|
92
|
-
const input = questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector('input');
|
|
93
|
-
const textareaUrl = questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector(`textarea[data-test="q-item-attachment-url"]`);
|
|
94
|
-
const textareaName = questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector(`textarea[data-test="q-item-attachment-file-name"]`);
|
|
95
|
-
if (!input) {
|
|
96
|
-
throw new Error(`File input was not found inside [data-linkid=${linkId}] block`);
|
|
97
|
-
}
|
|
98
|
-
if (!textareaUrl) {
|
|
99
|
-
throw new Error(`File input was not found inside [data-linkid="URL"] block`);
|
|
100
|
-
}
|
|
101
|
-
if (!textareaName) {
|
|
102
|
-
throw new Error(`File input was not found inside [data-linkid="File name (optional)"] block`);
|
|
103
|
-
}
|
|
104
|
-
const fileList = Array.isArray(files) ? files : [files];
|
|
105
|
-
yield userEvent.upload(input, fileList);
|
|
106
|
-
fireEvent.change(textareaUrl, { target: { value: url } });
|
|
107
|
-
fireEvent.change(textareaName, { target: { value: filename } });
|
|
108
|
-
// Here we await for debounced store update
|
|
109
|
-
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
export function inputDate(canvasElement, linkId, text) {
|
|
113
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
return yield inputText(canvasElement, linkId, text);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
export function inputTime(canvasElement, linkId, text) {
|
|
118
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
return yield inputText(canvasElement, linkId, text);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
export function inputReference(canvasElement, linkId, text) {
|
|
123
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
return yield inputText(canvasElement, linkId, text);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
export function inputDecimal(canvasElement, linkId, text) {
|
|
128
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
return yield inputText(canvasElement, linkId, text);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
export function inputUrl(canvasElement, linkId, text) {
|
|
133
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
return yield inputText(canvasElement, linkId, text);
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
export function inputInteger(canvasElement, linkId, text) {
|
|
138
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
return yield inputText(canvasElement, linkId, text);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
export function inputDateTime(canvasElement, linkId, date, time, amPm) {
|
|
143
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
const questionElement = yield findByLinkIdOrLabel(canvasElement, linkId);
|
|
145
|
-
const inputDate = questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector('div[data-test="date"] input');
|
|
146
|
-
const inputTime = questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector('div[data-test="time"] input');
|
|
147
|
-
const inputAmPm = questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector('div[data-test="ampm"] input');
|
|
148
|
-
if (!inputTime) {
|
|
149
|
-
throw new Error(`Input or textarea was not found inside ${`[data-linkid=${linkId}] block`}`);
|
|
150
|
-
}
|
|
151
|
-
if (!inputDate) {
|
|
152
|
-
throw new Error(`Input or textarea was not found inside ${`[data-linkid=${linkId}] block`}`);
|
|
153
|
-
}
|
|
154
|
-
if (!inputAmPm) {
|
|
155
|
-
throw new Error(`Input or textarea was not found inside ${`[data-linkid=${linkId}] block`}`);
|
|
156
|
-
}
|
|
157
|
-
fireEvent.change(inputDate, { target: { value: date } });
|
|
158
|
-
fireEvent.change(inputTime, { target: { value: time } });
|
|
159
|
-
fireEvent.change(inputAmPm, { target: { value: amPm } });
|
|
160
|
-
// Here we await for debounced store update
|
|
161
|
-
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
export function checkRadioOption(canvasElement, linkId, text) {
|
|
165
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
-
const questionElement = yield findByLinkIdOrLabel(canvasElement, linkId);
|
|
167
|
-
const radio = questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector(`span[data-test="radio-single-${text}"] input`);
|
|
168
|
-
if (!radio) {
|
|
169
|
-
throw new Error(`Input or textarea was not found inside ${`[data-linkid=${linkId}] block`}`);
|
|
170
|
-
}
|
|
171
|
-
fireEvent.click(radio);
|
|
172
|
-
// Here we await for debounced store update
|
|
173
|
-
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
export function getInputText(canvasElement, linkId) {
|
|
177
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
-
var _a;
|
|
179
|
-
const questionElement = yield findByLinkIdOrLabel(canvasElement, linkId);
|
|
180
|
-
const input = (_a = questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector('input')) !== null && _a !== void 0 ? _a : questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector('textarea');
|
|
181
|
-
if (!input) {
|
|
182
|
-
throw new Error(`Input or textarea was not found inside ${`[data-linkid=${linkId}] block`}`);
|
|
183
|
-
}
|
|
184
|
-
return input.value;
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
export function chooseSelectOption(canvasElement, linkId, optionLabel) {
|
|
188
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
-
const questionElement = yield findByLinkIdOrLabel(canvasElement, linkId);
|
|
190
|
-
const input = questionElement.querySelector('input, textarea');
|
|
191
|
-
if (!input) {
|
|
192
|
-
throw new Error(`There is no input inside ${linkId}`);
|
|
193
|
-
}
|
|
194
|
-
fireEvent.focus(input);
|
|
195
|
-
fireEvent.keyDown(input, { key: 'ArrowDown', code: 'ArrowDown' });
|
|
196
|
-
const option = yield screen.findByText(optionLabel);
|
|
197
|
-
fireEvent.click(option);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
export function chooseQuantityOption(canvasElement, linkId, quantity, quantityComparator) {
|
|
201
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
-
const questionElement = yield findByLinkIdOrLabel(canvasElement, linkId);
|
|
203
|
-
const inputComaparator = questionElement.querySelector('div[data-test="q-item-quantity-comparator"] input');
|
|
204
|
-
const inputWeight = questionElement.querySelector('div[data-test="q-item-quantity-field"] input');
|
|
205
|
-
if (!inputComaparator) {
|
|
206
|
-
throw new Error(`There is no input inside ${linkId}`);
|
|
207
|
-
}
|
|
208
|
-
if (!inputWeight) {
|
|
209
|
-
throw new Error(`There is no input inside ${linkId}`);
|
|
210
|
-
}
|
|
211
|
-
fireEvent.focus(inputComaparator);
|
|
212
|
-
fireEvent.keyDown(inputComaparator, { key: 'ArrowDown', code: 'ArrowDown' });
|
|
213
|
-
if (quantityComparator) {
|
|
214
|
-
const option = yield screen.findByText(quantityComparator);
|
|
215
|
-
fireEvent.click(option);
|
|
216
|
-
fireEvent.change(inputComaparator, { target: { value: quantityComparator } });
|
|
217
|
-
}
|
|
218
|
-
fireEvent.change(inputWeight, { target: { value: quantity } });
|
|
219
|
-
// Here we await for debounced store update
|
|
220
|
-
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
export function findByLinkIdOrLabel(canvasElement, linkId) {
|
|
224
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
-
const selectorByLinkId = `[data-linkid="${linkId}"]`;
|
|
226
|
-
const selectorByLabel = `[data-label="${linkId}"]`;
|
|
227
|
-
return yield waitFor(() => {
|
|
228
|
-
var _a;
|
|
229
|
-
const el = (_a = canvasElement.querySelector(selectorByLinkId)) !== null && _a !== void 0 ? _a : canvasElement.querySelector(selectorByLabel);
|
|
230
|
-
if (!el) {
|
|
231
|
-
throw new Error(`Element with selectors "${selectorByLinkId}" or "${selectorByLabel}" not found`);
|
|
232
|
-
}
|
|
233
|
-
return el;
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
export function inputOpenChoiceOtherText(canvasElement, linkId, text) {
|
|
238
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
-
const questionElement = yield findByLinkIdOrLabel(canvasElement, linkId);
|
|
240
|
-
const textarea = questionElement === null || questionElement === void 0 ? void 0 : questionElement.querySelector('div[data-test="q-item-radio-open-label-box"] textarea');
|
|
241
|
-
if (!textarea) {
|
|
242
|
-
throw new Error(`Input or textarea was not found inside ${`[data-test=${linkId}] block`}`);
|
|
243
|
-
}
|
|
244
|
-
fireEvent.change(textarea, { target: { value: text } });
|
|
245
|
-
// Here we await for debounced store update
|
|
246
|
-
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
//# sourceMappingURL=testUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testUtils.js","sourceRoot":"","sources":["../../src/stories/testUtils.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AAQvD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD,MAAM,UAAgB,UAAU,CAAC,MAAc;;QAC7C,MAAM,EAAE,GAAG,0BAA0B,CAAC,QAAQ,EAAE,CAAC,iBAAiB,CAAC;QACnE,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,EAAE,EAAE,4CAA4C,MAAM,WAAW,CAAC,CAAC;QACjG,OAAO,MAAM,CAAC;IAChB,CAAC;CAAA;AACD,MAAM,UAAgB,eAAe,CAAC,WAAmB,EAAE,YAAoB;;QAC7E,MAAM,EAAE,GA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,MAAM,gBAAgB,GAAG,iBAAiB,MAAM,IAAI,CAAC;QACrD,MAAM,eAAe,GAAG,gBAAgB,MAAM,IAAI,CAAC;QAEnD,OAAO,MAAM,OAAO,CAAC,GAAG,EAAE;;YACxB,MAAM,EAAE,GACN,MAAA,aAAa,CAAC,aAAa,CAAc,gBAAgB,CAAC,mCAC1D,aAAa,CAAC,aAAa,CAAc,eAAe,CAAC,CAAC;YAE5D,IAAI,CAAC,EAAE,EAAE,CAAC;gBACR,MAAM,IAAI,KAAK,CACb,2BAA2B,gBAAgB,SAAS,eAAe,aAAa,CACjF,CAAC;YACJ,CAAC;YAED,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;CAAA;AAED,MAAM,UAAgB,wBAAwB,CAC5C,aAA0B,EAC1B,MAAc,EACd,IAAY;;QAEZ,MAAM,eAAe,GAAG,MAAM,mBAAmB,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAEzE,MAAM,QAAQ,GAAG,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,aAAa,CAC7C,uDAAuD,CACxD,CAAC;QAEF,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,0CAA0C,cAAc,MAAM,SAAS,EAAE,CAAC,CAAC;QAC7F,CAAC;QAED,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAExD,2CAA2C;QAC3C,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;CAAA"}
|
package/lib/utils/itemPath.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { ItemPath } from '../interfaces/itemPath.interface';
|
|
2
|
-
/**
|
|
3
|
-
* Creates an `ItemPath` containing a single segment for the given `linkId`.
|
|
4
|
-
* This is useful when you want to construct a path to a specific item without referencing its ancestry,
|
|
5
|
-
* such as when working with top-level items or when only the item's identity is relevant.
|
|
6
|
-
*
|
|
7
|
-
* @param linkId - The `linkId` of the item.
|
|
8
|
-
* @param repeatIndex - (Optional) If the item is part of a repeating group, specify its index.
|
|
9
|
-
* @returns An `ItemPath` containing one segment.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const path = createSingleItemPath('question-1');
|
|
14
|
-
* // Output: [{ linkId: 'question-1' }]
|
|
15
|
-
*
|
|
16
|
-
* const pathWithRepeat = createSingleItemPath('question-1', 2);
|
|
17
|
-
* // Output: [{ linkId: 'question-1', repeatIndex: 2 }]
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function createSingleItemPath(linkId: string, repeatIndex?: number): ItemPath;
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new `ItemPath` by extending the given path with a new segment for the provided `linkId`.
|
|
23
|
-
* This version does NOT include a `repeatIndex`. If repeat handling is needed,
|
|
24
|
-
* use `appendRepeatIndexToLastSegment` after extending.
|
|
25
|
-
*
|
|
26
|
-
* @param currentPath - The existing item path.
|
|
27
|
-
* @param linkId - The `linkId` to use in the new path segment.
|
|
28
|
-
* @returns A new `ItemPath` with the added segment.
|
|
29
|
-
*/
|
|
30
|
-
export declare function extendItemPath(currentPath: linkId: string): ItemPath;
|
|
31
|
-
/**
|
|
32
|
-
* Returns a new `ItemPath` with a `repeatIndex` applied to the last segment.
|
|
33
|
-
* Useful for denoting which repetition of a group is being accessed.
|
|
34
|
-
*
|
|
35
|
-
* @param path - The item path to modify.
|
|
36
|
-
* @param repeatIndex - The index to assign to the final segment.
|
|
37
|
-
* @returns A new `ItemPath` with the last segment modified to include `repeatIndex`.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* const basePath = [{ linkId: 'groupA' }, { linkId: 'groupB' }];
|
|
41
|
-
* appendRepeatIndexToLastSegment(basePath, 2);
|
|
42
|
-
* // → [{ linkId: 'groupA' }, { linkId: 'groupB', repeatIndex: 2 }]
|
|
43
|
-
*/
|
|
44
|
-
export declare function appendRepeatIndexToLastSegment(path: repeatIndex: number): ItemPath;
|
|
45
|
-
/**
|
|
46
|
-
* Converts an `ItemPath` to a FHIRPath-compatible string.
|
|
47
|
-
*
|
|
48
|
-
* For example, the path:
|
|
49
|
-
* [
|
|
50
|
-
* { linkId: 'groupA' },
|
|
51
|
-
* { linkId: 'repeatingGroup', repeatIndex: 1 },
|
|
52
|
-
* { linkId: 'questionB' }
|
|
53
|
-
* ]
|
|
54
|
-
*
|
|
55
|
-
* Returns: "item.where(linkId='groupA').item.where(linkId='repeatingGroup')[1].item.where(linkId='questionB')"
|
|
56
|
-
*/
|
|
57
|
-
export declare function itemPathToFhirPathString(path: ItemPath): string;
|
package/lib/utils/itemPath.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates an `ItemPath` containing a single segment for the given `linkId`.
|
|
3
|
-
* This is useful when you want to construct a path to a specific item without referencing its ancestry,
|
|
4
|
-
* such as when working with top-level items or when only the item's identity is relevant.
|
|
5
|
-
*
|
|
6
|
-
* @param linkId - The `linkId` of the item.
|
|
7
|
-
* @param repeatIndex - (Optional) If the item is part of a repeating group, specify its index.
|
|
8
|
-
* @returns An `ItemPath` containing one segment.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* const path = createSingleItemPath('question-1');
|
|
13
|
-
* // Output: [{ linkId: 'question-1' }]
|
|
14
|
-
*
|
|
15
|
-
* const pathWithRepeat = createSingleItemPath('question-1', 2);
|
|
16
|
-
* // Output: [{ linkId: 'question-1', repeatIndex: 2 }]
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export function createSingleItemPath(linkId, repeatIndex) {
|
|
20
|
-
return repeatIndex !== undefined ? [{ linkId, repeatIndex }] : [{ linkId }];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new `ItemPath` by extending the given path with a new segment for the provided `linkId`.
|
|
24
|
-
* This version does NOT include a `repeatIndex`. If repeat handling is needed,
|
|
25
|
-
* use `appendRepeatIndexToLastSegment` after extending.
|
|
26
|
-
*
|
|
27
|
-
* @param currentPath - The existing item path.
|
|
28
|
-
* @param linkId - The `linkId` to use in the new path segment.
|
|
29
|
-
* @returns A new `ItemPath` with the added segment.
|
|
30
|
-
*/
|
|
31
|
-
export function extendItemPath(currentPath, linkId) {
|
|
32
|
-
return [...currentPath, { linkId }];
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Returns a new `ItemPath` with a `repeatIndex` applied to the last segment.
|
|
36
|
-
* Useful for denoting which repetition of a group is being accessed.
|
|
37
|
-
*
|
|
38
|
-
* @param path - The item path to modify.
|
|
39
|
-
* @param repeatIndex - The index to assign to the final segment.
|
|
40
|
-
* @returns A new `ItemPath` with the last segment modified to include `repeatIndex`.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* const basePath = [{ linkId: 'groupA' }, { linkId: 'groupB' }];
|
|
44
|
-
* appendRepeatIndexToLastSegment(basePath, 2);
|
|
45
|
-
* // → [{ linkId: 'groupA' }, { linkId: 'groupB', repeatIndex: 2 }]
|
|
46
|
-
*/
|
|
47
|
-
export function appendRepeatIndexToLastSegment(path, repeatIndex) {
|
|
48
|
-
if (path.length === 0)
|
|
49
|
-
return [];
|
|
50
|
-
const newPath = [...path];
|
|
51
|
-
newPath[path.length - 1] = Object.assign(Object.assign({}, newPath[path.length - 1]), { repeatIndex });
|
|
52
|
-
return newPath;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Converts an `ItemPath` to a FHIRPath-compatible string.
|
|
56
|
-
*
|
|
57
|
-
* For example, the path:
|
|
58
|
-
* [
|
|
59
|
-
* { linkId: 'groupA' },
|
|
60
|
-
* { linkId: 'repeatingGroup', repeatIndex: 1 },
|
|
61
|
-
* { linkId: 'questionB' }
|
|
62
|
-
* ]
|
|
63
|
-
*
|
|
64
|
-
* Returns: "item.where(linkId='groupA').item.where(linkId='repeatingGroup')[1].item.where(linkId='questionB')"
|
|
65
|
-
*/
|
|
66
|
-
export function itemPathToFhirPathString(path) {
|
|
67
|
-
return path
|
|
68
|
-
.map((segment, index) => {
|
|
69
|
-
const base = `where(linkId='${segment.linkId}')`;
|
|
70
|
-
const repeat = segment.repeatIndex !== undefined ? `[${segment.repeatIndex}]` : '';
|
|
71
|
-
return (index === 0 ? 'item.' : '') + base + repeat;
|
|
72
|
-
})
|
|
73
|
-
.join('.item.');
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=itemPath.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"itemPath.js","sourceRoot":"","sources":["../../src/utils/itemPath.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAc,EAAE,WAAoB;IACvE,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AAC9E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,WAAqB,EAAE,MAAc;IAClE,OAAO,CAAC,GAAG,WAAW,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,8BAA8B,CAAC,IAAc,EAAE,WAAmB;IAChF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEjC,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1B,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,mCAAQ,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,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