Skip to content

Commit b2a8de4

Browse files
committed
Add support for chartHighlight complex extension
1 parent 310bf85 commit b2a8de4

5 files changed

Lines changed: 230 additions & 0 deletions

File tree

src/converter/__tests__/fce.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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';
910
import fce_chart_y_axis_range from './resources/questionnaire_fce/chart_y_axis_range.json';
1011
import fce_choice_answer_option from './resources/questionnaire_fce/choice_answer_option.json';
1112
import fce_consent from './resources/questionnaire_fce/consent.json';
@@ -46,6 +47,7 @@ import fhir_allergies from './resources/questionnaire_fhir/allergies.json';
4647
import fhir_answer_options_toggle_expression from './resources/questionnaire_fhir/answerOptionsToggleExpression.json';
4748
import fhir_assemble_context from './resources/questionnaire_fhir/assemble_context.json';
4849
import fhir_beverages from './resources/questionnaire_fhir/beverages.json';
50+
import fhir_chart_highlight from './resources/questionnaire_fhir/chart_highlight.json';
4951
import fhir_chart_y_axis_range from './resources/questionnaire_fhir/chart_y_axis_range.json';
5052
import fhir_choice_answer_option from './resources/questionnaire_fhir/choice_answer_option.json';
5153
import fhir_consent from './resources/questionnaire_fhir/consent.json';
@@ -133,6 +135,7 @@ describe('Questionanire and QuestionnaireResponses transformation', () => {
133135
['default-sort', fhir_default_sort, fce_default_sort],
134136
['md-editor-features', fhir_md_editor_feature, fce_md_editor_feature],
135137
['chart-y-axis-range', fhir_chart_y_axis_range, fce_chart_y_axis_range],
138+
['chart-highlight', fhir_chart_highlight, fce_chart_highlight],
136139
])('Each FHIR Questionnaire should convert to FCE %s', async (_, fhir_questionnaire, fce_questionnaire) => {
137140
expect(toFirstClassExtension(fhir_questionnaire as FHIRQuestionnaire)).toStrictEqual(fce_questionnaire);
138141
});
@@ -181,6 +184,7 @@ describe('Questionanire and QuestionnaireResponses transformation', () => {
181184
['default-sort', fce_default_sort, fhir_default_sort],
182185
['md-editor-features', fce_md_editor_feature, fhir_md_editor_feature],
183186
['chart-y-axis-range', fce_chart_y_axis_range, fhir_chart_y_axis_range],
187+
['chart-highlight', fce_chart_highlight, fhir_chart_highlight],
184188
])('Each FCE Questionnaire should convert to FHIR %s', async (_, fce_questionnaire, fhir_questionnaire) => {
185189
expect(sortExtensionsList(fromFirstClassExtension(fce_questionnaire as FCEQuestionnaire))).toStrictEqual(
186190
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: 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+
}

src/converter/extensions.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export enum ExtensionIdentifier {
5858
DefaultSort = 'https://emr-core.beda.software/StructureDefinition/defaultSort',
5959
MDEditorFeature = 'https://emr-core.beda.software/StructureDefinition/mdEditorFeature',
6060
ChartYAxisRange = 'https://emr-core.beda.software/StructureDefinition/chartYAxisRange',
61+
ChartHighlight = 'https://emr-core.beda.software/StructureDefinition/chartHighlight',
6162
}
6263

6364
export type ExtensionTransformer = {
@@ -459,6 +460,58 @@ export const extensionTransformers: ExtensionTransformer = {
459460
[ExtensionIdentifier.ChartYAxisRange]: {
460461
path: { extension: 'valueRange', questionnaire: 'chartYAxisRange' },
461462
},
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+
},
462515
};
463516

464517
function getExtensionValue(extension: FHIRExtension) {

src/fce.types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export interface FCEQuestionnaireItem extends QuestionnaireItem {
121121
defaultSort?: FCEQuestionnaireItemDefaultSort;
122122
mdEditorFeature?: string[];
123123
chartYAxisRange?: Range;
124+
chartHighlight?: FCEQuestionnaireItemChartHighlight[];
124125
}
125126

126127
export interface FCEQuestionnaireItemText {
@@ -189,6 +190,12 @@ export interface FCEQuestionnaireItemDefaultSort {
189190
sort?: 'asc' | 'desc';
190191
}
191192

193+
export interface FCEQuestionnaireItemChartHighlight {
194+
from?: number;
195+
to?: number;
196+
color?: string;
197+
}
198+
192199
export interface FCEQuestionnaireLaunchContext {
193200
/** NOTE: from extension description */
194201
description?: string;

0 commit comments

Comments
 (0)