sdc-qrf 0.0.1

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.
@@ -0,0 +1,8 @@
1
+ import { ReactChild } from 'react';
2
+ import { QRFContextData, QuestionItemProps, QuestionItemsProps } from './types';
3
+ export declare function usePreviousValue<T = any>(value: T): T | undefined;
4
+ export declare function QuestionItems(props: QuestionItemsProps): JSX.Element;
5
+ export declare function QuestionItem(props: QuestionItemProps): JSX.Element | null;
6
+ export declare function QuestionnaireResponseFormProvider({ children, ...props }: QRFContextData & {
7
+ children: ReactChild;
8
+ }): JSX.Element;
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QuestionnaireResponseFormProvider = exports.QuestionItem = exports.QuestionItems = exports.usePreviousValue = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var jsx_runtime_1 = require("react/jsx-runtime");
6
+ var classnames_1 = tslib_1.__importDefault(require("classnames"));
7
+ var fhirpath_1 = tslib_1.__importDefault(require("fhirpath"));
8
+ var lodash_1 = tslib_1.__importDefault(require("lodash"));
9
+ var isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual"));
10
+ var react_1 = require("react");
11
+ var _1 = require(".");
12
+ var context_1 = require("./context");
13
+ var utils_1 = require("./utils");
14
+ function usePreviousValue(value) {
15
+ var prevValue = (0, react_1.useRef)();
16
+ (0, react_1.useEffect)(function () {
17
+ prevValue.current = value;
18
+ return function () {
19
+ prevValue.current = undefined;
20
+ };
21
+ });
22
+ return prevValue.current;
23
+ }
24
+ exports.usePreviousValue = usePreviousValue;
25
+ function QuestionItems(props) {
26
+ var questionItems = props.questionItems, parentPath = props.parentPath, context = props.context;
27
+ var formValues = (0, _1.useQuestionnaireResponseFormContext)().formValues;
28
+ var cleanValues = (0, utils_1.removeDisabledAnswers)(context.questionnaire.item, formValues);
29
+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, utils_1.getEnabledQuestions)(questionItems, parentPath, cleanValues).map(function (item, index) {
30
+ return ((0, jsx_runtime_1.jsx)("div", tslib_1.__assign({ className: (0, classnames_1.default)('questionFormItem', item.linkId) }, { children: (0, jsx_runtime_1.jsx)(QuestionItem, { questionItem: item, context: context, parentPath: parentPath }, index) })));
31
+ }) }));
32
+ }
33
+ exports.QuestionItems = QuestionItems;
34
+ function QuestionItem(props) {
35
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
36
+ var questionItem = props.questionItem, initialContext = props.context, parentPath = props.parentPath;
37
+ var _s = (0, react_1.useContext)(context_1.QRFContext), questionItemComponents = _s.questionItemComponents, customWidgets = _s.customWidgets, groupItemComponent = _s.groupItemComponent, itemControlQuestionItemComponents = _s.itemControlQuestionItemComponents, itemControlGroupItemComponents = _s.itemControlGroupItemComponents;
38
+ var _t = (0, _1.useQuestionnaireResponseFormContext)(), formValues = _t.formValues, setFormValues = _t.setFormValues;
39
+ var type = questionItem.type, linkId = questionItem.linkId, calculatedExpression = questionItem.calculatedExpression, variable = questionItem.variable, repeats = questionItem.repeats, itemControl = questionItem.itemControl;
40
+ var fieldPath = (0, react_1.useMemo)(function () { return tslib_1.__spreadArray(tslib_1.__spreadArray([], parentPath, true), [linkId], false); }, [parentPath, linkId]);
41
+ // TODO: how to do when item is not in QR (e.g. default element of repeatable group)
42
+ var branchItems = (0, utils_1.getBranchItems)(fieldPath, initialContext.questionnaire, initialContext.resource);
43
+ var context = type === 'group'
44
+ ? branchItems.qrItems.map(function (curQRItem) {
45
+ return (0, utils_1.calcContext)(initialContext, variable, branchItems.qItem, curQRItem);
46
+ })
47
+ : (0, utils_1.calcContext)(initialContext, variable, branchItems.qItem, branchItems.qrItems[0]);
48
+ var prevAnswers = usePreviousValue(lodash_1.default.get(formValues, fieldPath));
49
+ (0, react_1.useEffect)(function () {
50
+ if (!isGroupItem(questionItem, context) && calculatedExpression) {
51
+ // TODO: Add support for x-fhir-query
52
+ if (calculatedExpression.language === 'text/fhirpath') {
53
+ var newValues = fhirpath_1.default.evaluate(context.context || {}, calculatedExpression.expression, context);
54
+ var newAnswers = newValues.length
55
+ ? repeats
56
+ ? newValues.map(function (answer) { return ({ value: (0, utils_1.wrapAnswerValue)(type, answer) }); })
57
+ : [{ value: (0, utils_1.wrapAnswerValue)(type, newValues[0]) }]
58
+ : undefined;
59
+ if (!(0, isEqual_1.default)(newAnswers, prevAnswers)) {
60
+ setFormValues(lodash_1.default.set(lodash_1.default.cloneDeep(formValues), fieldPath, newAnswers));
61
+ }
62
+ }
63
+ }
64
+ }, [
65
+ setFormValues,
66
+ formValues,
67
+ calculatedExpression,
68
+ context,
69
+ parentPath,
70
+ repeats,
71
+ type,
72
+ questionItem,
73
+ prevAnswers,
74
+ fieldPath,
75
+ ]);
76
+ if (isGroupItem(questionItem, context)) {
77
+ if (itemControl) {
78
+ if (!itemControlGroupItemComponents ||
79
+ !itemControlGroupItemComponents[(_b = (_a = itemControl === null || itemControl === void 0 ? void 0 : itemControl.coding) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.code]) {
80
+ console.warn("QRF: Unsupported group itemControl '".concat((_d = (_c = itemControl === null || itemControl === void 0 ? void 0 : itemControl.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.code, "'. \n Please define 'itemControlGroupWidgets' for '").concat((_f = (_e = itemControl === null || itemControl === void 0 ? void 0 : itemControl.coding) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.code, "'"));
81
+ return null;
82
+ }
83
+ var Component = itemControlGroupItemComponents[(_h = (_g = itemControl === null || itemControl === void 0 ? void 0 : itemControl.coding) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.code];
84
+ return ((0, jsx_runtime_1.jsx)(Component, { context: context, parentPath: parentPath, questionItem: questionItem }));
85
+ }
86
+ if (!groupItemComponent) {
87
+ console.warn("QRF: groupWidget is not specified but used in questionnaire.");
88
+ return null;
89
+ }
90
+ var GroupWidgetComponent = groupItemComponent;
91
+ return ((0, jsx_runtime_1.jsx)(GroupWidgetComponent, { context: context, parentPath: parentPath, questionItem: questionItem }));
92
+ }
93
+ if (itemControl) {
94
+ if (!itemControlQuestionItemComponents ||
95
+ !itemControlQuestionItemComponents[(_k = (_j = itemControl.coding) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.code]) {
96
+ console.warn("QRF: Unsupported itemControl '".concat((_m = (_l = itemControl === null || itemControl === void 0 ? void 0 : itemControl.coding) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.code, "'.\nPlease define 'itemControlWidgets' for '").concat((_p = (_o = itemControl === null || itemControl === void 0 ? void 0 : itemControl.coding) === null || _o === void 0 ? void 0 : _o[0]) === null || _p === void 0 ? void 0 : _p.code, "'"));
97
+ return null;
98
+ }
99
+ var Component = itemControlQuestionItemComponents[(_r = (_q = itemControl === null || itemControl === void 0 ? void 0 : itemControl.coding) === null || _q === void 0 ? void 0 : _q[0]) === null || _r === void 0 ? void 0 : _r.code];
100
+ return (0, jsx_runtime_1.jsx)(Component, { context: context, parentPath: parentPath, questionItem: questionItem });
101
+ }
102
+ // TODO: deprecate!
103
+ if (customWidgets && linkId && linkId in customWidgets) {
104
+ console.warn("QRF: 'customWidgets' are deprecated, use 'Questionnaire.item.itemControl' instead");
105
+ if (type === 'group') {
106
+ console.error("QRF: Use 'itemControl' for group custom widgets");
107
+ return null;
108
+ }
109
+ var Component = customWidgets[linkId];
110
+ return (0, jsx_runtime_1.jsx)(Component, { context: context, parentPath: parentPath, questionItem: questionItem });
111
+ }
112
+ if (type in questionItemComponents) {
113
+ var Component = questionItemComponents[type];
114
+ return (0, jsx_runtime_1.jsx)(Component, { context: context, parentPath: parentPath, questionItem: questionItem });
115
+ }
116
+ console.error("QRF: Unsupported item type '".concat(type, "'"));
117
+ return null;
118
+ }
119
+ exports.QuestionItem = QuestionItem;
120
+ function QuestionnaireResponseFormProvider(_a) {
121
+ var children = _a.children, props = tslib_1.__rest(_a, ["children"]);
122
+ return (0, jsx_runtime_1.jsx)(context_1.QRFContext.Provider, tslib_1.__assign({ value: props }, { children: children }));
123
+ }
124
+ exports.QuestionnaireResponseFormProvider = QuestionnaireResponseFormProvider;
125
+ /* Helper that resolves right context type */
126
+ function isGroupItem(questionItem, context) {
127
+ return questionItem.type === 'group';
128
+ }
129
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.tsx"],"names":[],"mappings":";;;;;AAAA,kEAAoC;AACpC,8DAAgC;AAChC,0DAAuB;AACvB,mEAAqC;AACrC,+BAA2E;AAI3E,sBAAwD;AACxD,qCAAuC;AAEvC,iCAMiB;AAEjB,SAAgB,gBAAgB,CAAU,KAAQ;IAC9C,IAAM,SAAS,GAAG,IAAA,cAAM,GAAK,CAAC;IAE9B,IAAA,iBAAS,EAAC;QACN,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC;QAE1B,OAAO;YACH,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC;QAClC,CAAC,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC,OAAO,CAAC;AAC7B,CAAC;AAZD,4CAYC;AAED,SAAgB,aAAa,CAAC,KAAyB;IAC3C,IAAA,aAAa,GAA0B,KAAK,cAA/B,EAAE,UAAU,GAAc,KAAK,WAAnB,EAAE,OAAO,GAAK,KAAK,QAAV,CAAW;IAC7C,IAAA,UAAU,GAAK,IAAA,sCAAmC,GAAE,WAA1C,CAA2C;IAC7D,IAAM,WAAW,GAAG,IAAA,6BAAqB,EAAC,OAAO,CAAC,aAAa,CAAC,IAAK,EAAE,UAAU,CAAC,CAAC;IAEnF,OAAO,CACH,2DACK,IAAA,2BAAmB,EAAC,aAAa,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,UAAC,I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,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,GAAI,CAAC;KAC9F;IAED,OAAO,CAAC,KAAK,CAAC,sCAA+B,IAAI,MAAG,CAAC,CAAC;IAEtD,OAAO,IAAI,CAAC;AAChB,CAAC;AA5ID,oCA4IC;AAED,SAAgB,iCAAiC,CAAC,EAGN;IAFxC,IAAA,QAAQ,cAAA,EACL,KAAK,sBAFsC,YAGjD,CADW;IAER,OAAO,uBAAC,oBAAU,CAAC,QAAQ,qBAAC,KAAK,EAAE,KAAK,gBAAG,QAAQ,IAAuB,CAAC;AAC/E,CAAC;AALD,8EAKC;AAED,6CAA6C;AAC7C,SAAS,WAAW,CAChB,YAA+B,EAC/B,OAAoC;IAEpC,OAAO,YAAY,CAAC,IAAI,KAAK,OAAO,CAAC;AACzC,CAAC"}
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { QRFContextData } from './types';
3
+ export declare const QRFContext: import("react").Context<QRFContextData>;
package/lib/context.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QRFContext = void 0;
4
+ var react_1 = require("react");
5
+ exports.QRFContext = (0, react_1.createContext)({});
6
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AAAA,+BAAsC;AAIzB,QAAA,UAAU,GAAG,IAAA,qBAAa,EAAiB,EAAS,CAAC,CAAC"}
package/lib/hooks.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function useQuestionnaireResponseFormContext(): import("./types").QRFContextData;
package/lib/hooks.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useQuestionnaireResponseFormContext = void 0;
4
+ var react_1 = require("react");
5
+ var context_1 = require("./context");
6
+ function useQuestionnaireResponseFormContext() {
7
+ return (0, react_1.useContext)(context_1.QRFContext);
8
+ }
9
+ exports.useQuestionnaireResponseFormContext = useQuestionnaireResponseFormContext;
10
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AAEnC,qCAAuC;AAEvC,SAAgB,mCAAmC;IAC/C,OAAO,IAAA,kBAAU,EAAC,oBAAU,CAAC,CAAC;AAClC,CAAC;AAFD,kFAEC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './types';
2
+ export * from './utils';
3
+ export * from './hooks';
4
+ export * from './components';
package/lib/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./types"), exports);
5
+ tslib_1.__exportStar(require("./utils"), exports);
6
+ tslib_1.__exportStar(require("./hooks"), exports);
7
+ tslib_1.__exportStar(require("./components"), exports);
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,kDAAwB;AACxB,kDAAwB;AACxB,uDAA6B"}
package/lib/types.d.ts ADDED
@@ -0,0 +1,73 @@
1
+ import { ComponentType } from 'react';
2
+ import { Observation, ParametersParameter, Questionnaire, QuestionnaireItem, QuestionnaireResponse, QuestionnaireResponseItem, QuestionnaireResponseItemAnswer } from 'shared/src/contrib/aidbox';
3
+ export declare type GroupItemComponent = ComponentType<GroupItemProps>;
4
+ export declare type QuestionItemComponent = ComponentType<QuestionItemProps>;
5
+ export declare type CustomWidgetsMapping = {
6
+ [linkId: string]: QuestionItemComponent;
7
+ };
8
+ export declare type QuestionItemComponentMapping = {
9
+ [type: string]: QuestionItemComponent;
10
+ };
11
+ export declare type ItemControlQuestionItemComponentMapping = {
12
+ [code: string]: QuestionItemComponent;
13
+ };
14
+ export declare type ItemControlGroupItemComponentMapping = {
15
+ [code: string]: GroupItemComponent;
16
+ };
17
+ export declare type ItemContext = {
18
+ resource: QuestionnaireResponse;
19
+ questionnaire: Questionnaire;
20
+ context: QuestionnaireResponseItem | QuestionnaireResponse;
21
+ qitem?: QuestionnaireItem;
22
+ [x: string]: any;
23
+ };
24
+ export interface QRFContextData {
25
+ questionItemComponents: QuestionItemComponentMapping;
26
+ groupItemComponent?: GroupItemComponent;
27
+ customWidgets?: CustomWidgetsMapping;
28
+ itemControlQuestionItemComponents?: ItemControlQuestionItemComponentMapping;
29
+ itemControlGroupItemComponents?: ItemControlGroupItemComponentMapping;
30
+ readOnly?: boolean;
31
+ formValues: FormItems;
32
+ setFormValues: (values: FormItems) => void;
33
+ }
34
+ export interface QuestionItemsProps {
35
+ questionItems: QuestionnaireItem[];
36
+ context: ItemContext;
37
+ parentPath: string[];
38
+ }
39
+ export interface QuestionItemProps {
40
+ questionItem: QuestionnaireItem;
41
+ context: ItemContext;
42
+ parentPath: string[];
43
+ }
44
+ export interface GroupItemProps {
45
+ questionItem: QuestionnaireItem;
46
+ context: ItemContext[];
47
+ parentPath: string[];
48
+ }
49
+ export declare type AnswerValue = Required<QuestionnaireResponseItemAnswer>['value'] & Required<Observation>['value'];
50
+ export interface RepeatableFormGroupItems {
51
+ question?: string;
52
+ items?: FormItems[];
53
+ }
54
+ interface NotRepeatableFormGroupItems {
55
+ question?: string;
56
+ items?: FormItems;
57
+ }
58
+ export declare type FormGroupItems = RepeatableFormGroupItems | NotRepeatableFormGroupItems;
59
+ export interface FormAnswerItems<T = any> {
60
+ value: T;
61
+ question?: string;
62
+ items?: FormItems;
63
+ }
64
+ export declare type FormItems = Record<string, FormGroupItems | FormAnswerItems[]>;
65
+ export interface QuestionnaireResponseFormData {
66
+ formValues: FormItems;
67
+ context: {
68
+ questionnaire: Questionnaire;
69
+ questionnaireResponse: QuestionnaireResponse;
70
+ launchContextParameters: ParametersParameter[];
71
+ };
72
+ }
73
+ export {};
package/lib/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ import { Questionnaire, QuestionnaireItem, QuestionnaireResponse, QuestionnaireResponseItem } from 'shared/src/contrib/aidbox';
2
+ import { AnswerValue, FormAnswerItems, FormItems, ItemContext, QuestionnaireResponseFormData } from './types';
3
+ export declare function wrapAnswerValue(type: QuestionnaireItem['type'], answer: any): {
4
+ Coding: any;
5
+ string?: undefined;
6
+ Attachment?: undefined;
7
+ Reference?: undefined;
8
+ Quantity?: undefined;
9
+ } | {
10
+ string: any;
11
+ Coding?: undefined;
12
+ Attachment?: undefined;
13
+ Reference?: undefined;
14
+ Quantity?: undefined;
15
+ } | {
16
+ Attachment: any;
17
+ Coding?: undefined;
18
+ string?: undefined;
19
+ Reference?: undefined;
20
+ Quantity?: undefined;
21
+ } | {
22
+ Reference: any;
23
+ Coding?: undefined;
24
+ string?: undefined;
25
+ Attachment?: undefined;
26
+ Quantity?: undefined;
27
+ } | {
28
+ Quantity: any;
29
+ Coding?: undefined;
30
+ string?: undefined;
31
+ Attachment?: undefined;
32
+ Reference?: undefined;
33
+ } | {
34
+ [x: string]: any;
35
+ Coding?: undefined;
36
+ string?: undefined;
37
+ Attachment?: undefined;
38
+ Reference?: undefined;
39
+ Quantity?: undefined;
40
+ };
41
+ export declare function getBranchItems(fieldPath: string[], questionnaire: Questionnaire, questionnaireResponse: QuestionnaireResponse): {
42
+ qItem: QuestionnaireItem;
43
+ qrItems: QuestionnaireResponseItem[];
44
+ };
45
+ export declare function calcContext(initialContext: ItemContext, variables: QuestionnaireItem['variable'], qItem: QuestionnaireItem, qrItem: QuestionnaireResponseItem): ItemContext;
46
+ export declare function compareValue(firstAnswerValue: AnswerValue, secondAnswerValue: AnswerValue): 0 | 1 | -1;
47
+ export declare function mapFormToResponse(values: FormItems, questionnaire: Questionnaire, keepDisabledAnswers?: boolean): Pick<QuestionnaireResponse, 'item'>;
48
+ export declare function mapResponseToForm(resource: QuestionnaireResponse, questionnaire: Questionnaire): FormItems;
49
+ export declare function findAnswersForQuestionsRecursive(linkId: string, values?: FormItems): any | null;
50
+ export declare function findAnswersForQuestion<T = any>(linkId: string, parentPath: string[], values: FormItems): Array<FormAnswerItems<T>>;
51
+ export declare function isValueEqual(firstValue: AnswerValue, secondValue: AnswerValue): boolean;
52
+ export declare function getChecker(operator: string): (values: Array<{
53
+ value: any;
54
+ }>, answerValue: any) => boolean;
55
+ export declare function removeDisabledAnswers(questionnaireItems: QuestionnaireItem[], values: FormItems): FormItems;
56
+ export declare function getEnabledQuestions(questionnaireItems: QuestionnaireItem[], parentPath: string[], values: FormItems): QuestionnaireItem[];
57
+ export declare function calcInitialContext(qrfDataContext: QuestionnaireResponseFormData['context'], values: FormItems): ItemContext;
58
+ export declare function parseFhirQueryExpression(expression: string, context: ItemContext): any[];