Skip to content

Commit 43c2af7

Browse files
authored
Merge pull request #43 from beda-software/chart-range-and-highlight
Add support for chartYAxis and chartHighlight extensions
2 parents d094db8 + b2a8de4 commit 43c2af7

7 files changed

Lines changed: 345 additions & 0 deletions

File tree

src/converter/__tests__/fce.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import fce_allergies from './resources/questionnaire_fce/allergies.json';
66
import fce_answer_options_toggle_expression from './resources/questionnaire_fce/answerOptionsToggleExpression.json';
77
import fce_assemble_context from './resources/questionnaire_fce/assemble_context.json';
88
import fce_beverages from './resources/questionnaire_fce/beverages.json';
9+
import fce_chart_highlight from './resources/questionnaire_fce/chart_highlight.json';
10+
import fce_chart_y_axis_range from './resources/questionnaire_fce/chart_y_axis_range.json';
911
import fce_choice_answer_option from './resources/questionnaire_fce/choice_answer_option.json';
1012
import fce_consent from './resources/questionnaire_fce/consent.json';
1113
import fce_constraint from './resources/questionnaire_fce/constraint.json';
@@ -45,6 +47,8 @@ import fhir_allergies from './resources/questionnaire_fhir/allergies.json';
4547
import fhir_answer_options_toggle_expression from './resources/questionnaire_fhir/answerOptionsToggleExpression.json';
4648
import fhir_assemble_context from './resources/questionnaire_fhir/assemble_context.json';
4749
import fhir_beverages from './resources/questionnaire_fhir/beverages.json';
50+
import fhir_chart_highlight from './resources/questionnaire_fhir/chart_highlight.json';
51+
import fhir_chart_y_axis_range from './resources/questionnaire_fhir/chart_y_axis_range.json';
4852
import fhir_choice_answer_option from './resources/questionnaire_fhir/choice_answer_option.json';
4953
import fhir_consent from './resources/questionnaire_fhir/consent.json';
5054
import fhir_constraint from './resources/questionnaire_fhir/constraint.json';
@@ -130,6 +134,8 @@ describe('Questionanire and QuestionnaireResponses transformation', () => {
130134
['enable-sort', fhir_enable_sort, fce_enable_sort],
131135
['default-sort', fhir_default_sort, fce_default_sort],
132136
['md-editor-features', fhir_md_editor_feature, fce_md_editor_feature],
137+
['chart-y-axis-range', fhir_chart_y_axis_range, fce_chart_y_axis_range],
138+
['chart-highlight', fhir_chart_highlight, fce_chart_highlight],
133139
])('Each FHIR Questionnaire should convert to FCE %s', async (_, fhir_questionnaire, fce_questionnaire) => {
134140
expect(toFirstClassExtension(fhir_questionnaire as FHIRQuestionnaire)).toStrictEqual(fce_questionnaire);
135141
});
@@ -177,6 +183,8 @@ describe('Questionanire and QuestionnaireResponses transformation', () => {
177183
['enable-sort', fce_enable_sort, fhir_enable_sort],
178184
['default-sort', fce_default_sort, fhir_default_sort],
179185
['md-editor-features', fce_md_editor_feature, fhir_md_editor_feature],
186+
['chart-y-axis-range', fce_chart_y_axis_range, fhir_chart_y_axis_range],
187+
['chart-highlight', fce_chart_highlight, fhir_chart_highlight],
180188
])('Each FCE Questionnaire should convert to FHIR %s', async (_, fce_questionnaire, fhir_questionnaire) => {
181189
expect(sortExtensionsList(fromFirstClassExtension(fce_questionnaire as FCEQuestionnaire))).toStrictEqual(
182190
sortExtensionsList(fhir_questionnaire),
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"item": [
3+
{
4+
"text": "Table",
5+
"type": "group",
6+
"repeats": true,
7+
"itemControl": {
8+
"Coding": [
9+
{
10+
"code": "group-table"
11+
}
12+
]
13+
},
14+
"chartHighlight": [
15+
{
16+
"to": 5,
17+
"color": "#FFCCC766"
18+
},
19+
{
20+
"from": 5,
21+
"to": 10,
22+
"color": "#FFFBE6CC"
23+
},
24+
{
25+
"from": 25,
26+
"to": 30,
27+
"color": "#FFFBE6CC"
28+
},
29+
{
30+
"from": 30,
31+
"color": "#FFCCC766"
32+
}
33+
],
34+
"item": [
35+
{
36+
"text": "Date",
37+
"type": "date",
38+
"linkId": "date"
39+
},
40+
{
41+
"text": "Value",
42+
"type": "decimal",
43+
"linkId": "value"
44+
}
45+
]
46+
}
47+
],
48+
"status": "draft",
49+
"subjectType": ["Patient"],
50+
"assembledFrom": "chart-highlight",
51+
"id": "example",
52+
"resourceType": "Questionnaire",
53+
"meta": {
54+
"profile": ["https://emr-core.beda.software/StructureDefinition/fhir-emr-questionnaire"],
55+
"lastUpdated": "2026-02-10T00:09:00.000000Z",
56+
"versionId": "205"
57+
}
58+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"item": [
3+
{
4+
"text": "Table",
5+
"type": "group",
6+
"repeats": true,
7+
"itemControl": {
8+
"Coding": [
9+
{
10+
"code": "group-table"
11+
}
12+
]
13+
},
14+
"chartYAxisRange": {
15+
"low": {
16+
"value": 0
17+
},
18+
"high": {
19+
"value": 40
20+
}
21+
},
22+
"item": [
23+
{
24+
"text": "Date",
25+
"type": "date",
26+
"linkId": "date"
27+
},
28+
{
29+
"text": "Value",
30+
"type": "decimal",
31+
"linkId": "value"
32+
}
33+
]
34+
}
35+
],
36+
"status": "draft",
37+
"subjectType": ["Patient"],
38+
"assembledFrom": "chart-y-axis-range",
39+
"id": "example",
40+
"resourceType": "Questionnaire",
41+
"meta": {
42+
"profile": ["https://emr-core.beda.software/StructureDefinition/fhir-emr-questionnaire"],
43+
"lastUpdated": "2026-02-10T00:09:00.000000Z",
44+
"versionId": "205"
45+
}
46+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"item": [
3+
{
4+
"text": "Table",
5+
"type": "group",
6+
"repeats": true,
7+
"extension": [
8+
{
9+
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
10+
"valueCodeableConcept": {
11+
"Coding": [
12+
{
13+
"code": "group-table"
14+
}
15+
]
16+
}
17+
},
18+
{
19+
"url": "https://emr-core.beda.software/StructureDefinition/chartHighlight",
20+
"extension": [
21+
{
22+
"url": "to",
23+
"valueDecimal": 5
24+
},
25+
{
26+
"url": "color",
27+
"valueString": "#FFCCC766"
28+
}
29+
]
30+
},
31+
{
32+
"url": "https://emr-core.beda.software/StructureDefinition/chartHighlight",
33+
"extension": [
34+
{
35+
"url": "from",
36+
"valueDecimal": 5
37+
},
38+
{
39+
"url": "to",
40+
"valueDecimal": 10
41+
},
42+
{
43+
"url": "color",
44+
"valueString": "#FFFBE6CC"
45+
}
46+
]
47+
},
48+
{
49+
"url": "https://emr-core.beda.software/StructureDefinition/chartHighlight",
50+
"extension": [
51+
{
52+
"url": "from",
53+
"valueDecimal": 25
54+
},
55+
{
56+
"url": "to",
57+
"valueDecimal": 30
58+
},
59+
{
60+
"url": "color",
61+
"valueString": "#FFFBE6CC"
62+
}
63+
]
64+
},
65+
{
66+
"url": "https://emr-core.beda.software/StructureDefinition/chartHighlight",
67+
"extension": [
68+
{
69+
"url": "from",
70+
"valueDecimal": 30
71+
},
72+
{
73+
"url": "color",
74+
"valueString": "#FFCCC766"
75+
}
76+
]
77+
}
78+
],
79+
"item": [
80+
{
81+
"text": "Date",
82+
"type": "date",
83+
"linkId": "date"
84+
},
85+
{
86+
"text": "Value",
87+
"type": "decimal",
88+
"linkId": "value"
89+
}
90+
]
91+
}
92+
],
93+
"status": "draft",
94+
"subjectType": ["Patient"],
95+
"extension": [
96+
{
97+
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-assembledFrom",
98+
"valueCanonical": "chart-highlight"
99+
}
100+
],
101+
"id": "example",
102+
"resourceType": "Questionnaire",
103+
"meta": {
104+
"profile": ["https://emr-core.beda.software/StructureDefinition/fhir-emr-questionnaire"],
105+
"lastUpdated": "2026-02-10T00:09:00.000000Z",
106+
"versionId": "205"
107+
}
108+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"item": [
3+
{
4+
"text": "Table",
5+
"type": "group",
6+
"repeats": true,
7+
"extension": [
8+
{
9+
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
10+
"valueCodeableConcept": {
11+
"Coding": [
12+
{
13+
"code": "group-table"
14+
}
15+
]
16+
}
17+
},
18+
{
19+
"url": "https://emr-core.beda.software/StructureDefinition/chartYAxisRange",
20+
"valueRange": {
21+
"low": {
22+
"value": 0
23+
},
24+
"high": {
25+
"value": 40
26+
}
27+
}
28+
}
29+
],
30+
"item": [
31+
{
32+
"text": "Date",
33+
"type": "date",
34+
"linkId": "date"
35+
},
36+
{
37+
"text": "Value",
38+
"type": "decimal",
39+
"linkId": "value"
40+
}
41+
]
42+
}
43+
],
44+
"status": "draft",
45+
"subjectType": ["Patient"],
46+
"extension": [
47+
{
48+
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-assembledFrom",
49+
"valueCanonical": "chart-y-axis-range"
50+
}
51+
],
52+
"id": "example",
53+
"resourceType": "Questionnaire",
54+
"meta": {
55+
"profile": ["https://emr-core.beda.software/StructureDefinition/fhir-emr-questionnaire"],
56+
"lastUpdated": "2026-02-10T00:09:00.000000Z",
57+
"versionId": "205"
58+
}
59+
}

src/converter/extensions.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export enum ExtensionIdentifier {
5757
EnableSort = 'https://emr-core.beda.software/StructureDefinition/enableSort',
5858
DefaultSort = 'https://emr-core.beda.software/StructureDefinition/defaultSort',
5959
MDEditorFeature = 'https://emr-core.beda.software/StructureDefinition/mdEditorFeature',
60+
ChartYAxisRange = 'https://emr-core.beda.software/StructureDefinition/chartYAxisRange',
61+
ChartHighlight = 'https://emr-core.beda.software/StructureDefinition/chartHighlight',
6062
}
6163

6264
export type ExtensionTransformer = {
@@ -455,6 +457,61 @@ export const extensionTransformers: ExtensionTransformer = {
455457
[ExtensionIdentifier.MDEditorFeature]: {
456458
path: { extension: 'valueCode', questionnaire: 'mdEditorFeature', isCollection: true },
457459
},
460+
[ExtensionIdentifier.ChartYAxisRange]: {
461+
path: { extension: 'valueRange', questionnaire: 'chartYAxisRange' },
462+
},
463+
[ExtensionIdentifier.ChartHighlight]: {
464+
transform: {
465+
fromExtensions: (extensions) => {
466+
return {
467+
chartHighlight: extensions.map((extension) => {
468+
const chartHighlightExtension = extension.extension!;
469+
470+
return {
471+
from: chartHighlightExtension.find((obj) => obj.url === 'from')?.valueDecimal ?? undefined,
472+
to: chartHighlightExtension.find((obj) => obj.url === 'to')?.valueDecimal ?? undefined,
473+
color: chartHighlightExtension.find((obj) => obj.url === 'color')?.valueString ?? undefined,
474+
};
475+
}),
476+
};
477+
},
478+
toExtensions: (item) => {
479+
if (item.chartHighlight) {
480+
return item.chartHighlight.map((chartHighlight) => ({
481+
url: ExtensionIdentifier.ChartHighlight,
482+
extension: [
483+
...(chartHighlight.from
484+
? [
485+
{
486+
url: 'from',
487+
valueDecimal: chartHighlight.from,
488+
},
489+
]
490+
: []),
491+
...(chartHighlight.to
492+
? [
493+
{
494+
url: 'to',
495+
valueDecimal: chartHighlight.to,
496+
},
497+
]
498+
: []),
499+
...(chartHighlight.color
500+
? [
501+
{
502+
url: 'color',
503+
valueString: chartHighlight.color,
504+
},
505+
]
506+
: []),
507+
],
508+
}));
509+
}
510+
511+
return [];
512+
},
513+
},
514+
},
458515
};
459516

460517
function getExtensionValue(extension: FHIRExtension) {

0 commit comments

Comments
 (0)