sdc-qrf 0.3.31 → 0.3.34
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/dist/converter/extensions.d.ts +4 -1
- package/dist/converter/extensions.d.ts.map +1 -1
- package/dist/converter/extensions.js +81 -0
- package/dist/converter/extensions.js.map +1 -1
- package/dist/converter/fhirToFce/questionnaire/processItems.js +38 -27
- package/dist/converter/fhirToFce/questionnaire/processItems.js.map +1 -1
- package/dist/converter/index.d.ts +1 -2
- package/dist/converter/index.d.ts.map +1 -1
- package/dist/converter/index.js +2 -6
- package/dist/converter/index.js.map +1 -1
- package/package.json +1 -1
- package/src/converter/__tests__/fce.test.ts +84 -58
- package/src/converter/__tests__/resources/questionnaire_fce/answerOptionsToggleExpression.json +98 -0
- package/src/converter/__tests__/resources/questionnaire_fce/mixed-fce-with-extensions.json +26 -0
- package/src/converter/__tests__/resources/questionnaire_fce/occurs.json +16 -0
- package/src/converter/__tests__/resources/questionnaire_fce/unknown-extensions.json +58 -0
- package/src/converter/__tests__/resources/questionnaire_fhir/answerOptionsToggleExpression.json +96 -0
- package/src/converter/__tests__/resources/questionnaire_fhir/mixed-fce-with-extensions.json +27 -0
- package/src/converter/__tests__/resources/questionnaire_fhir/occurs.json +24 -0
- package/src/converter/__tests__/resources/questionnaire_fhir/unknown-extensions.json +62 -0
- package/src/converter/extensions.ts +90 -1
- package/src/converter/fhirToFce/questionnaire/processItems.ts +49 -43
- package/src/converter/index.ts +4 -10
package/src/converter/__tests__/resources/questionnaire_fce/answerOptionsToggleExpression.json
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"resourceType": "Questionnaire",
|
|
3
|
+
"id": "answerOptionsToggleExpression",
|
|
4
|
+
"meta": {
|
|
5
|
+
"profile": ["https://emr-core.beda.software/StructureDefinition/fhir-emr-questionnaire"]
|
|
6
|
+
},
|
|
7
|
+
"status": "active",
|
|
8
|
+
"item": [
|
|
9
|
+
{
|
|
10
|
+
"type": "choice",
|
|
11
|
+
"linkId": "answerOptions",
|
|
12
|
+
"answerOption": [
|
|
13
|
+
{
|
|
14
|
+
"value": {
|
|
15
|
+
"Coding": {
|
|
16
|
+
"code": "code-1",
|
|
17
|
+
"display": "display-1"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"value": {
|
|
23
|
+
"Coding": {
|
|
24
|
+
"code": "code-2",
|
|
25
|
+
"display": "display-2"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"value": {
|
|
31
|
+
"Coding": {
|
|
32
|
+
"code": "code-3",
|
|
33
|
+
"display": "display-3"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"value": {
|
|
39
|
+
"Coding": {
|
|
40
|
+
"code": "code-4",
|
|
41
|
+
"display": "display-4"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"answerOptionsToggleExpression": [
|
|
47
|
+
{
|
|
48
|
+
"option": [
|
|
49
|
+
{
|
|
50
|
+
"value": {
|
|
51
|
+
"Coding": {
|
|
52
|
+
"code": "code-1",
|
|
53
|
+
"display": "display-1"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"value": {
|
|
59
|
+
"Coding": {
|
|
60
|
+
"code": "code-2",
|
|
61
|
+
"display": "display-2"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"expression": {
|
|
67
|
+
"language": "text/fhirpath",
|
|
68
|
+
"expression": "1 = 1"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"option": [
|
|
73
|
+
{
|
|
74
|
+
"value": {
|
|
75
|
+
"Coding": {
|
|
76
|
+
"code": "code-3",
|
|
77
|
+
"display": "display-3"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"value": {
|
|
83
|
+
"Coding": {
|
|
84
|
+
"code": "code-4",
|
|
85
|
+
"display": "display-4"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
"expression": {
|
|
91
|
+
"language": "text/fhirpath",
|
|
92
|
+
"expression": "1 != 1"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"resourceType": "Questionnaire",
|
|
3
|
+
"id": "fce-with-extensions",
|
|
4
|
+
"meta": {
|
|
5
|
+
"profile": [
|
|
6
|
+
"https://emr-core.beda.software/StructureDefinition/fhir-emr-questionnaire"
|
|
7
|
+
]
|
|
8
|
+
},
|
|
9
|
+
"status": "active",
|
|
10
|
+
"item": [
|
|
11
|
+
{
|
|
12
|
+
"type": "string",
|
|
13
|
+
"linkId": "question",
|
|
14
|
+
"entryFormat": "This is FCE",
|
|
15
|
+
"extension": [
|
|
16
|
+
{
|
|
17
|
+
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression",
|
|
18
|
+
"valueExpression": {
|
|
19
|
+
"language": "text/fhirpath",
|
|
20
|
+
"expression": "'This is extension'"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"resourceType": "Questionnaire",
|
|
3
|
+
"id": "occurs",
|
|
4
|
+
"meta": {
|
|
5
|
+
"profile": ["https://beda.software/beda-emr-questionnaire"]
|
|
6
|
+
},
|
|
7
|
+
"status": "active",
|
|
8
|
+
"item": [
|
|
9
|
+
{
|
|
10
|
+
"type": "number",
|
|
11
|
+
"linkId": "number",
|
|
12
|
+
"minOccurs": 1,
|
|
13
|
+
"maxOccurs": 2
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"resourceType": "Questionnaire",
|
|
3
|
+
"id": "unknown-extensions",
|
|
4
|
+
"meta": {
|
|
5
|
+
"profile": [
|
|
6
|
+
"https://emr-core.beda.software/StructureDefinition/fhir-emr-questionnaire"
|
|
7
|
+
]
|
|
8
|
+
},
|
|
9
|
+
"status": "active",
|
|
10
|
+
"item": [
|
|
11
|
+
{
|
|
12
|
+
"type": "string",
|
|
13
|
+
"linkId": "question-1",
|
|
14
|
+
"initialExpression": {
|
|
15
|
+
"language": "text/fhirpath",
|
|
16
|
+
"expression": "'This is known extension'"
|
|
17
|
+
},
|
|
18
|
+
"readOnly": true,
|
|
19
|
+
"_readOnly": {
|
|
20
|
+
"cqfExpression": {
|
|
21
|
+
"language": "text/fhirpath",
|
|
22
|
+
"expression": "{}"
|
|
23
|
+
},
|
|
24
|
+
"extension": [
|
|
25
|
+
{
|
|
26
|
+
"url": "urn:unknown-primitive-extension-1",
|
|
27
|
+
"valueString": "This is unknown primitive extension along with known extension"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"extension": [
|
|
32
|
+
{
|
|
33
|
+
"url": "urn:unknown-extension-1",
|
|
34
|
+
"valueString": "This is unknown extension along with known extension"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"type": "string",
|
|
40
|
+
"linkId": "question-2",
|
|
41
|
+
"readOnly": true,
|
|
42
|
+
"_readOnly": {
|
|
43
|
+
"extension": [
|
|
44
|
+
{
|
|
45
|
+
"url": "urn:unknown-primitive-extension-2",
|
|
46
|
+
"valueString": "This is single unknown primitive extension"
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"extension": [
|
|
51
|
+
{
|
|
52
|
+
"url": "urn:unknown-extension-2",
|
|
53
|
+
"valueString": "This is single unknown extension"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
package/src/converter/__tests__/resources/questionnaire_fhir/answerOptionsToggleExpression.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"item": [
|
|
3
|
+
{
|
|
4
|
+
"type": "choice",
|
|
5
|
+
"linkId": "answerOptions",
|
|
6
|
+
"answerOption": [
|
|
7
|
+
{
|
|
8
|
+
"valueCoding": {
|
|
9
|
+
"code": "code-1",
|
|
10
|
+
"display": "display-1"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"valueCoding": {
|
|
15
|
+
"code": "code-2",
|
|
16
|
+
"display": "display-2"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"valueCoding": {
|
|
21
|
+
"code": "code-3",
|
|
22
|
+
"display": "display-3"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"valueCoding": {
|
|
27
|
+
"code": "code-4",
|
|
28
|
+
"display": "display-4"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"extension": [
|
|
33
|
+
{
|
|
34
|
+
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerOptionsToggleExpression",
|
|
35
|
+
"extension": [
|
|
36
|
+
{
|
|
37
|
+
"url": "option",
|
|
38
|
+
"valueCoding": {
|
|
39
|
+
"code": "code-1",
|
|
40
|
+
"display": "display-1"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"url": "option",
|
|
45
|
+
"valueCoding": {
|
|
46
|
+
"code": "code-2",
|
|
47
|
+
"display": "display-2"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"url": "expression",
|
|
52
|
+
"valueExpression": {
|
|
53
|
+
"language": "text/fhirpath",
|
|
54
|
+
"expression": "1 = 1"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerOptionsToggleExpression",
|
|
61
|
+
"extension": [
|
|
62
|
+
{
|
|
63
|
+
"url": "option",
|
|
64
|
+
"valueCoding": {
|
|
65
|
+
"code": "code-3",
|
|
66
|
+
"display": "display-3"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"url": "option",
|
|
71
|
+
"valueCoding": {
|
|
72
|
+
"code": "code-4",
|
|
73
|
+
"display": "display-4"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"url": "expression",
|
|
78
|
+
"valueExpression": {
|
|
79
|
+
"language": "text/fhirpath",
|
|
80
|
+
"expression": "1 != 1"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
"meta": {
|
|
89
|
+
"profile": [
|
|
90
|
+
"https://emr-core.beda.software/StructureDefinition/fhir-emr-questionnaire"
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
"status": "active",
|
|
94
|
+
"resourceType": "Questionnaire",
|
|
95
|
+
"id": "answerOptionsToggleExpression"
|
|
96
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"item": [
|
|
3
|
+
{
|
|
4
|
+
"type": "string",
|
|
5
|
+
"linkId": "question",
|
|
6
|
+
"extension": [
|
|
7
|
+
{
|
|
8
|
+
"url": "http://hl7.org/fhir/StructureDefinition/entryFormat",
|
|
9
|
+
"valueString": "This is FCE"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression",
|
|
13
|
+
"valueExpression": {
|
|
14
|
+
"language": "text/fhirpath",
|
|
15
|
+
"expression": "'This is extension'"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"meta": {
|
|
22
|
+
"profile": ["https://emr-core.beda.software/StructureDefinition/fhir-emr-questionnaire"]
|
|
23
|
+
},
|
|
24
|
+
"status": "active",
|
|
25
|
+
"id": "fce-with-extensions",
|
|
26
|
+
"resourceType": "Questionnaire"
|
|
27
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"item": [
|
|
3
|
+
{
|
|
4
|
+
"type": "number",
|
|
5
|
+
"linkId": "number",
|
|
6
|
+
"extension": [
|
|
7
|
+
{
|
|
8
|
+
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-minOccurs",
|
|
9
|
+
"valueInteger": 1
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-maxOccurs",
|
|
13
|
+
"valueInteger": 2
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"meta": {
|
|
19
|
+
"profile": ["https://beda.software/beda-emr-questionnaire"]
|
|
20
|
+
},
|
|
21
|
+
"status": "active",
|
|
22
|
+
"resourceType": "Questionnaire",
|
|
23
|
+
"id": "occurs"
|
|
24
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"item": [
|
|
3
|
+
{
|
|
4
|
+
"type": "string",
|
|
5
|
+
"linkId": "question-1",
|
|
6
|
+
"readOnly": true,
|
|
7
|
+
"_readOnly": {
|
|
8
|
+
"extension": [
|
|
9
|
+
{
|
|
10
|
+
"url": "http://hl7.org/fhir/StructureDefinition/cqf-expression",
|
|
11
|
+
"valueExpression": {
|
|
12
|
+
"language": "text/fhirpath",
|
|
13
|
+
"expression": "{}"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"url": "urn:unknown-primitive-extension-1",
|
|
18
|
+
"valueString": "This is unknown primitive extension along with known extension"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"extension": [
|
|
23
|
+
{
|
|
24
|
+
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression",
|
|
25
|
+
"valueExpression": {
|
|
26
|
+
"language": "text/fhirpath",
|
|
27
|
+
"expression": "'This is known extension'"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"url": "urn:unknown-extension-1",
|
|
32
|
+
"valueString": "This is unknown extension along with known extension"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"type": "string",
|
|
38
|
+
"linkId": "question-2",
|
|
39
|
+
"readOnly": true,
|
|
40
|
+
"_readOnly": {
|
|
41
|
+
"extension": [
|
|
42
|
+
{
|
|
43
|
+
"url": "urn:unknown-primitive-extension-2",
|
|
44
|
+
"valueString": "This is single unknown primitive extension"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
"extension": [
|
|
49
|
+
{
|
|
50
|
+
"url": "urn:unknown-extension-2",
|
|
51
|
+
"valueString": "This is single unknown extension"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"meta": {
|
|
57
|
+
"profile": ["https://emr-core.beda.software/StructureDefinition/fhir-emr-questionnaire"]
|
|
58
|
+
},
|
|
59
|
+
"status": "active",
|
|
60
|
+
"id": "unknown-extensions",
|
|
61
|
+
"resourceType": "Questionnaire"
|
|
62
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Extension as FHIRExtension } from 'fhir/r4b';
|
|
2
2
|
|
|
3
3
|
import { QuestionnaireItem as FCEQuestionnaireItem } from '@beda.software/aidbox-types';
|
|
4
|
+
import { lowerFirst, upperFirst } from 'lodash';
|
|
4
5
|
|
|
5
6
|
export enum ExtensionIdentifier {
|
|
6
7
|
Hidden = 'http://hl7.org/fhir/StructureDefinition/questionnaire-hidden',
|
|
@@ -31,6 +32,7 @@ export enum ExtensionIdentifier {
|
|
|
31
32
|
|
|
32
33
|
ItemPopulationContext = 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemPopulationContext',
|
|
33
34
|
ItemConstraint = 'http://hl7.org/fhir/StructureDefinition/questionnaire-constraint',
|
|
35
|
+
AnswerOptionsToggleExpression = 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerOptionsToggleExpression',
|
|
34
36
|
InitialExpression = 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression',
|
|
35
37
|
ChoiceColumn = 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-choiceColumn',
|
|
36
38
|
CalculatedExpression = 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression',
|
|
@@ -48,6 +50,8 @@ export enum ExtensionIdentifier {
|
|
|
48
50
|
Macro = 'https://beda.software/fhir-emr-questionnaire/macro',
|
|
49
51
|
RowsNumber = 'https://beda.software/fhir-emr-questionnaire/rows-number',
|
|
50
52
|
SubQuestionnaire = 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-subQuestionnaire',
|
|
53
|
+
MinOccurs = 'http://hl7.org/fhir/StructureDefinition/questionnaire-minOccurs',
|
|
54
|
+
MaxOccurs = 'http://hl7.org/fhir/StructureDefinition/questionnaire-maxOccurs',
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
export type ExtensionTransformer = {
|
|
@@ -181,7 +185,12 @@ export const extensionTransformers: ExtensionTransformer = {
|
|
|
181
185
|
[ExtensionIdentifier.ChoiceColumns]: {
|
|
182
186
|
path: { extension: 'valueInteger', questionnaire: 'choiceColumns' },
|
|
183
187
|
},
|
|
184
|
-
|
|
188
|
+
[ExtensionIdentifier.MinOccurs]: {
|
|
189
|
+
path: { extension: 'valueInteger', questionnaire: 'minOccurs' },
|
|
190
|
+
},
|
|
191
|
+
[ExtensionIdentifier.MaxOccurs]: {
|
|
192
|
+
path: { extension: 'valueInteger', questionnaire: 'maxOccurs' },
|
|
193
|
+
},
|
|
185
194
|
[ExtensionIdentifier.ItemPopulationContext]: {
|
|
186
195
|
path: { extension: 'valueExpression', questionnaire: 'itemPopulationContext' },
|
|
187
196
|
},
|
|
@@ -236,6 +245,44 @@ export const extensionTransformers: ExtensionTransformer = {
|
|
|
236
245
|
},
|
|
237
246
|
},
|
|
238
247
|
},
|
|
248
|
+
[ExtensionIdentifier.AnswerOptionsToggleExpression]: {
|
|
249
|
+
transform: {
|
|
250
|
+
fromExtensions: (extensions) => {
|
|
251
|
+
return {
|
|
252
|
+
answerOptionsToggleExpression: extensions.map((extension) => {
|
|
253
|
+
const answerOptionsToggleExpression = extension.extension!;
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
expression: answerOptionsToggleExpression.find((obj) => obj.url === 'expression')!
|
|
257
|
+
.valueExpression!,
|
|
258
|
+
option: answerOptionsToggleExpression
|
|
259
|
+
.filter((obj) => obj.url === 'option')
|
|
260
|
+
.map((obj) => toAidboxUnionType(obj, 'value')),
|
|
261
|
+
};
|
|
262
|
+
}),
|
|
263
|
+
};
|
|
264
|
+
},
|
|
265
|
+
toExtensions: (item) => {
|
|
266
|
+
if (item.answerOptionsToggleExpression) {
|
|
267
|
+
return item.answerOptionsToggleExpression.map((answerOptionsToggleExpression) => ({
|
|
268
|
+
url: ExtensionIdentifier.AnswerOptionsToggleExpression,
|
|
269
|
+
extension: [
|
|
270
|
+
...answerOptionsToggleExpression.option.map((option) => ({
|
|
271
|
+
url: 'option',
|
|
272
|
+
...fromAidboxUnionType(option.value, 'value'),
|
|
273
|
+
})),
|
|
274
|
+
{
|
|
275
|
+
url: 'expression',
|
|
276
|
+
valueExpression: answerOptionsToggleExpression.expression,
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
}));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return [];
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
},
|
|
239
286
|
[ExtensionIdentifier.Variable]: {
|
|
240
287
|
path: { extension: 'valueExpression', questionnaire: 'variable', isCollection: true },
|
|
241
288
|
},
|
|
@@ -314,3 +361,45 @@ export const extensionTransformers: ExtensionTransformer = {
|
|
|
314
361
|
path: { extension: 'valueString', questionnaire: 'macro' },
|
|
315
362
|
},
|
|
316
363
|
};
|
|
364
|
+
|
|
365
|
+
// fromAidboxUnionType({string: '1'}, 'value) => {valueString: '1'}
|
|
366
|
+
function fromAidboxUnionType(obj: any, prefix: string): any {
|
|
367
|
+
const key = Object.keys(obj)[0]!;
|
|
368
|
+
const mappedObjKey = prefix + upperFirst(key);
|
|
369
|
+
|
|
370
|
+
return { [mappedObjKey]: obj[key] };
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const FHIRPrimitiveTypes = [
|
|
374
|
+
'base64Binary',
|
|
375
|
+
'boolean',
|
|
376
|
+
'canonical',
|
|
377
|
+
'code',
|
|
378
|
+
'date',
|
|
379
|
+
'dateTime',
|
|
380
|
+
'decimal',
|
|
381
|
+
'id',
|
|
382
|
+
'instant',
|
|
383
|
+
'integer',
|
|
384
|
+
'integer64',
|
|
385
|
+
'markdown',
|
|
386
|
+
'oid',
|
|
387
|
+
'positiveInt',
|
|
388
|
+
'string',
|
|
389
|
+
'time',
|
|
390
|
+
'unsignedInt',
|
|
391
|
+
'uri',
|
|
392
|
+
'url',
|
|
393
|
+
'uuid',
|
|
394
|
+
];
|
|
395
|
+
// toAidboxUnionType({valueString: '1'}, 'value') => {value: {string: '1'}}
|
|
396
|
+
// toAidboxUnionType({valueCoding: '1'}, 'value') => {value: {Coding: '1'}}
|
|
397
|
+
function toAidboxUnionType(obj: any, prefix: string): any {
|
|
398
|
+
const prefixKey = Object.keys(obj).filter((key: string) => key.startsWith(prefix))[0]!;
|
|
399
|
+
const key = lowerFirst(prefixKey.slice(prefix.length));
|
|
400
|
+
const answerKey = FHIRPrimitiveTypes.includes(key) ? key : upperFirst(key);
|
|
401
|
+
|
|
402
|
+
return {
|
|
403
|
+
[prefix]: { [answerKey]: obj[prefixKey] },
|
|
404
|
+
};
|
|
405
|
+
}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
QuestionnaireItem as FHIRQuestionnaireItem,
|
|
5
5
|
QuestionnaireItemAnswerOption as FHIRQuestionnaireItemAnswerOption,
|
|
6
6
|
QuestionnaireItemInitial as FHIRQuestionnaireItemInitial,
|
|
7
|
-
|
|
7
|
+
Extension as FHIRExtension,
|
|
8
8
|
} from 'fhir/r4b';
|
|
9
9
|
import _ from 'lodash';
|
|
10
10
|
|
|
@@ -16,71 +16,77 @@ import {
|
|
|
16
16
|
QuestionnaireItemInitial as FCEQuestionnaireItemInitial,
|
|
17
17
|
} from '@beda.software/aidbox-types';
|
|
18
18
|
|
|
19
|
-
import { convertFromFHIRExtension,
|
|
19
|
+
import { convertFromFHIRExtension, fromFHIRReference } from '../../../converter';
|
|
20
20
|
import { ExtensionIdentifier } from '../../extensions';
|
|
21
21
|
|
|
22
22
|
export function processItems(fhirQuestionnaire: FHIRQuestionnaire, extensionsOnly: boolean) {
|
|
23
23
|
return fhirQuestionnaire.item?.map((item) => convertItemProperties(item, extensionsOnly));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function convertItemProperties(
|
|
27
|
-
item
|
|
28
|
-
extensionsOnly: boolean,
|
|
29
|
-
): FCEQuestionnaireItem {
|
|
30
|
-
const updatedProperties = getUpdatedPropertiesFromItem(item, extensionsOnly);
|
|
31
|
-
const newItem = { ...item, ...updatedProperties };
|
|
26
|
+
function convertItemProperties(item: FHIRQuestionnaireItem, extensionsOnly: boolean): FCEQuestionnaireItem {
|
|
27
|
+
const newItem = getUpdatedPropertiesFromItem(item, extensionsOnly);
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
convertItemProperties(nestedItem, extensionsOnly)
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
if (newItem.extension) {
|
|
38
|
-
delete newItem.extension;
|
|
29
|
+
if (item.item) {
|
|
30
|
+
newItem.item = item.item.map((nestedItem) => convertItemProperties(nestedItem, extensionsOnly));
|
|
39
31
|
}
|
|
40
|
-
|
|
41
32
|
return newItem;
|
|
42
33
|
}
|
|
43
34
|
|
|
44
35
|
function getUpdatedPropertiesFromItem(item: FHIRQuestionnaireItem, extensionsOnly: boolean) {
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
36
|
+
let newItem: FCEQuestionnaireItem = { ...item };
|
|
37
|
+
|
|
38
|
+
// Primitive extensions
|
|
39
|
+
for (const property of Object.keys(item)) {
|
|
40
|
+
const element = item[property as keyof FHIRQuestionnaireItem];
|
|
41
|
+
if (property.startsWith('_') && element instanceof Object && !Array.isArray(element)) {
|
|
42
|
+
newItem = {
|
|
43
|
+
...newItem,
|
|
44
|
+
...{
|
|
45
|
+
[property]: processExtensibleElement(element),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
61
48
|
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!extensionsOnly) {
|
|
52
|
+
newItem.answerOption = item.answerOption?.map(processItemOption);
|
|
53
|
+
newItem.initial = item.initial?.map(processItemOption);
|
|
54
|
+
newItem.enableWhen = item.enableWhen?.map(processEnableWhenItem);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return processExtensibleElement(newItem);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function processExtensibleElement<T extends { extension?: FHIRExtension[] }>(element: T): T {
|
|
61
|
+
let newElement = { ...element };
|
|
62
|
+
const knownExtensionUrls = Object.values(ExtensionIdentifier) as string[];
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const allExtensions = element.extension ?? [];
|
|
65
|
+
const knownExtensions = allExtensions.filter((ext) => knownExtensionUrls.includes(ext.url));
|
|
66
|
+
const unknownExtensions = allExtensions.filter((ext) => !knownExtensionUrls.includes(ext.url));
|
|
67
|
+
|
|
68
|
+
if (knownExtensions.length) {
|
|
69
|
+
const uniqueExtensionUrls = new Set(knownExtensions.map((ext) => ext.url));
|
|
70
|
+
for (const extensionUrl of uniqueExtensionUrls) {
|
|
71
|
+
const extensions = knownExtensions.filter((ext) => ext.url === extensionUrl);
|
|
72
|
+
|
|
73
|
+
newElement = {
|
|
74
|
+
...newElement,
|
|
67
75
|
...convertFromFHIRExtension(extensions),
|
|
68
76
|
};
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
if (unknownExtensions.length) {
|
|
81
|
+
newElement.extension = unknownExtensions;
|
|
82
|
+
} else {
|
|
83
|
+
delete newElement.extension;
|
|
76
84
|
}
|
|
77
85
|
|
|
78
|
-
return
|
|
86
|
+
return newElement;
|
|
79
87
|
}
|
|
80
88
|
|
|
81
|
-
function processEnableWhenItem(
|
|
82
|
-
item: FHIRQuestionnaireItemEnableWhen,
|
|
83
|
-
): FCEQuestionnaireItemEnableWhen {
|
|
89
|
+
function processEnableWhenItem(item: FHIRQuestionnaireItemEnableWhen): FCEQuestionnaireItemEnableWhen {
|
|
84
90
|
return {
|
|
85
91
|
question: item.question,
|
|
86
92
|
operator: item.operator,
|