@aehrc/smart-forms-renderer 0.37.2 → 0.38.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/FormComponents/QuantityItem/QuantityComparatorField.d.ts +12 -0
- package/lib/components/FormComponents/QuantityItem/QuantityComparatorField.js +13 -0
- package/lib/components/FormComponents/QuantityItem/QuantityComparatorField.js.map +1 -0
- package/lib/components/FormComponents/QuantityItem/QuantityField.d.ts +15 -0
- package/lib/components/FormComponents/QuantityItem/QuantityField.js +14 -0
- package/lib/components/FormComponents/QuantityItem/QuantityField.js.map +1 -0
- package/lib/components/FormComponents/QuantityItem/QuantityItem.d.ts +9 -0
- package/lib/components/FormComponents/QuantityItem/QuantityItem.js +144 -0
- package/lib/components/FormComponents/QuantityItem/QuantityItem.js.map +1 -0
- package/lib/components/FormComponents/QuantityItem/QuantityUnitField.d.ts +12 -0
- package/lib/components/FormComponents/QuantityItem/QuantityUnitField.js +10 -0
- package/lib/components/FormComponents/QuantityItem/QuantityUnitField.js.map +1 -0
- package/lib/components/FormComponents/SingleItem/SingleItemSwitcher.js +2 -1
- package/lib/components/FormComponents/SingleItem/SingleItemSwitcher.js.map +1 -1
- package/lib/hooks/useDecimalCalculatedExpression.d.ts +2 -2
- package/lib/hooks/useQuantityCalculatedExpression.d.ts +14 -0
- package/lib/hooks/useQuantityCalculatedExpression.js +105 -0
- package/lib/hooks/useQuantityCalculatedExpression.js.map +1 -0
- package/lib/hooks/useRenderingExtensions.d.ts +2 -1
- package/lib/hooks/useRenderingExtensions.js +3 -2
- package/lib/hooks/useRenderingExtensions.js.map +1 -1
- package/lib/hooks/useStringInput.js +1 -0
- package/lib/hooks/useStringInput.js.map +1 -1
- package/lib/interfaces/valueSet.interface.d.ts +15 -0
- package/lib/utils/calculatedExpression.js +4 -1
- package/lib/utils/calculatedExpression.js.map +1 -1
- package/lib/utils/itemControl.d.ts +7 -1
- package/lib/utils/itemControl.js +14 -0
- package/lib/utils/itemControl.js.map +1 -1
- package/lib/utils/quantity.d.ts +4 -0
- package/lib/utils/quantity.js +49 -0
- package/lib/utils/quantity.js.map +1 -0
- package/lib/utils/valueSet.d.ts +2 -1
- package/lib/utils/valueSet.js +22 -0
- package/lib/utils/valueSet.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FormComponents/QuantityItem/QuantityComparatorField.tsx +40 -0
- package/src/components/FormComponents/QuantityItem/QuantityField.tsx +60 -0
- package/src/components/FormComponents/QuantityItem/QuantityItem.tsx +286 -0
- package/src/components/FormComponents/QuantityItem/QuantityUnitField.tsx +38 -0
- package/src/components/FormComponents/SingleItem/SingleItemSwitcher.tsx +2 -1
- package/src/hooks/useDecimalCalculatedExpression.ts +2 -2
- package/src/hooks/useQuantityCalculatedExpression.ts +177 -0
- package/src/hooks/useRenderingExtensions.ts +5 -2
- package/src/hooks/useStringInput.ts +1 -0
- package/src/interfaces/valueSet.interface.ts +19 -0
- package/src/stories/assets/questionnaires/QPrePopTester.ts +30 -0
- package/src/stories/assets/questionnaires/QQuantity.ts +283 -1
- package/src/stories/itemTypes/Quantity.stories.tsx +33 -1
- package/src/utils/calculatedExpression.ts +5 -1
- package/src/utils/itemControl.ts +19 -1
- package/src/utils/quantity.ts +62 -0
- package/src/utils/valueSet.ts +32 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {
|
|
19
|
+
Quantity,
|
|
20
|
+
QuestionnaireItemAnswerOption,
|
|
21
|
+
QuestionnaireResponseItemAnswer
|
|
22
|
+
} from 'fhir/r4';
|
|
23
|
+
import { parseDecimalStringToFloat } from './parseInputs';
|
|
24
|
+
|
|
25
|
+
export const quantityComparators: Quantity['comparator'][] = ['<', '<=', '>=', '>'];
|
|
26
|
+
|
|
27
|
+
export function stringIsComparator(str: string | undefined): str is Quantity['comparator'] {
|
|
28
|
+
return str === '<' || str === '<=' || str === '>=' || str === '>';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function createQuantityItemAnswer(
|
|
32
|
+
precision: number | null,
|
|
33
|
+
parsedNewInput: string,
|
|
34
|
+
comparatorInput: Quantity['comparator'] | null,
|
|
35
|
+
unitInput: QuestionnaireItemAnswerOption | null
|
|
36
|
+
): QuestionnaireResponseItemAnswer[] {
|
|
37
|
+
if (precision) {
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
valueQuantity: {
|
|
41
|
+
value: parseDecimalStringToFloat(parsedNewInput, precision),
|
|
42
|
+
comparator: comparatorInput ?? undefined,
|
|
43
|
+
unit: unitInput?.valueCoding?.display,
|
|
44
|
+
system: unitInput?.valueCoding?.system,
|
|
45
|
+
code: unitInput?.valueCoding?.code
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
valueQuantity: {
|
|
54
|
+
value: parseFloat(parsedNewInput),
|
|
55
|
+
comparator: comparatorInput ?? undefined,
|
|
56
|
+
unit: unitInput?.valueCoding?.display,
|
|
57
|
+
system: unitInput?.valueCoding?.system,
|
|
58
|
+
code: unitInput?.valueCoding?.code
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
}
|
package/src/utils/valueSet.ts
CHANGED
|
@@ -29,7 +29,7 @@ import type {
|
|
|
29
29
|
import * as FHIR from 'fhirclient';
|
|
30
30
|
import type { FhirResourceString } from '../interfaces/populate.interface';
|
|
31
31
|
import type { VariableXFhirQuery } from '../interfaces/variables.interface';
|
|
32
|
-
import type { ValueSetPromise } from '../interfaces/valueSet.interface';
|
|
32
|
+
import type { ValidateCodeResponse, ValueSetPromise } from '../interfaces/valueSet.interface';
|
|
33
33
|
|
|
34
34
|
const VALID_VALUE_SET_URL_REGEX =
|
|
35
35
|
/https?:\/\/(www\.)?[-\w@:%.+~#=]{2,256}\.[a-z]{2,4}\b([-@\w:%+.~#?&/=]*ValueSet[-@\w:%+.~#?&/=]*)/;
|
|
@@ -65,6 +65,37 @@ export function getValueSetPromise(url: string, terminologyServerUrl: string): P
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
function validateCodeResponseIsValid(response: any): response is ValidateCodeResponse {
|
|
69
|
+
return (
|
|
70
|
+
response &&
|
|
71
|
+
response.resourceType === 'Parameters' &&
|
|
72
|
+
response.parameter &&
|
|
73
|
+
response.parameter.find((p: any) => p.name === 'code') &&
|
|
74
|
+
response.parameter.find((p: any) => p.name === 'code').valueCode &&
|
|
75
|
+
response.parameter.find((p: any) => p.name === 'system') &&
|
|
76
|
+
response.parameter.find((p: any) => p.name === 'system').valueUri &&
|
|
77
|
+
response.parameter.find((p: any) => p.name === 'display') &&
|
|
78
|
+
response.parameter.find((p: any) => p.name === 'display').valueString
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function validateCodePromise(
|
|
83
|
+
url: string,
|
|
84
|
+
system: string,
|
|
85
|
+
code: string,
|
|
86
|
+
terminologyServerUrl: string
|
|
87
|
+
): Promise<ValidateCodeResponse | null> {
|
|
88
|
+
const validateCodeResponse = await FHIR.client({ serverUrl: terminologyServerUrl }).request({
|
|
89
|
+
url: `ValueSet/$validate-code?url=${url}&system=${system}&code=${code}`
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (validateCodeResponse && validateCodeResponseIsValid(validateCodeResponse)) {
|
|
93
|
+
return validateCodeResponse;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
68
99
|
async function addTimeoutToPromise(promise: Promise<any>, timeoutMs: number) {
|
|
69
100
|
const timeoutPromise = new Promise((_, reject) => {
|
|
70
101
|
setTimeout(() => {
|