Skip to content

Commit 28f77a5

Browse files
committed
Merge branch 'release/0.9.0'
2 parents 9a33090 + ec32317 commit 28f77a5

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fhirformjs",
33
"description": "FHIR Questionnaire To Form Converter for rendering",
4-
"version": "0.8.1",
4+
"version": "0.9.0",
55
"license": "MIT",
66
"main": "dist/index.js",
77
"typings": "dist/index.d.ts",

src/ques-mapper.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const FhirJsonForm = (
1313
fhirQuestionnaire: R4.IQuestionnaire
1414
): FhirForm => {
1515
let ALL_PROPERTIES: any = {};
16+
let requiredProperties: string[] = [];
1617
let UISchema: any = {};
1718

1819
let fhirQuestionnaireResponse: R4.IQuestionnaireResponse = {
@@ -53,21 +54,35 @@ export const FhirJsonForm = (
5354
myProperty
5455
] = GetItemProperties(groupItem);
5556

57+
if (groupItem.required) {
58+
if (ALL_PROPERTIES[groupProperty]['required'] === undefined) {
59+
ALL_PROPERTIES[groupProperty]['required'] = []
60+
}
61+
ALL_PROPERTIES[groupProperty]['required'].push(myProperty)
62+
}
63+
5664
if (GetWidget(groupItem) !== '') {
5765
UISchema[groupProperty][myProperty] = {
5866
'ui:widget': GetWidget(groupItem),
5967
};
6068
}
6169

62-
if (GetUIOptions(groupItem) !== '') {
70+
const uiOptions = GetUIOptions(groupItem)
71+
if (uiOptions !== '') {
6372
UISchema[groupProperty][myProperty] = {
64-
'ui:options': GetUIOptions(groupItem),
73+
'ui:options': uiOptions,
6574
};
75+
76+
if (uiOptions.unit) {
77+
UISchema[groupProperty][myProperty]['ui:placeholder'] = uiOptions.unit
78+
}
6679
}
6780

6881
fhirQuestionnaireResponse.item?.push(CreateResponseItem(groupItem));
6982
});
7083

84+
item.required && requiredProperties.push(groupProperty)
85+
7186
// Just push the fields if not a group
7287
} else {
7388
let myProperty =
@@ -88,13 +103,16 @@ export const FhirJsonForm = (
88103
}
89104

90105
fhirQuestionnaireResponse.item?.push(CreateResponseItem(item));
106+
107+
item.required && requiredProperties.push(myProperty)
91108
}
92109
});
93110

94111
let fhirJsonSchema: FhirJsonSchema = {
95112
type: 'object',
96113
title: fhirQuestionnaire.id?.toString(),
97114
properties: ALL_PROPERTIES,
115+
required: requiredProperties,
98116
};
99117
let fhirForm: FhirForm = {
100118
model: fhirQuestionnaireResponse,
@@ -244,9 +262,19 @@ const GetControlType = (item: R4.IQuestionnaire_Item) => {
244262
return 'array'
245263
}
246264
}
265+
247266
if (item.type === R4.Questionnaire_ItemTypeKind._boolean) {
248267
return 'boolean';
249268
}
269+
270+
if (item.type == R4.Questionnaire_ItemTypeKind._decimal) {
271+
return 'number';
272+
}
273+
274+
if (item.type == R4.Questionnaire_ItemTypeKind._integer) {
275+
return 'integer';
276+
}
277+
250278
return 'string';
251279
};
252280

@@ -288,7 +316,7 @@ const CreateResponseItem = (item: R4.IQuestionnaire_Item) => {
288316
case R4.Questionnaire_ItemTypeKind._openChoice:
289317
const option = (item.answerOption || [])[0]
290318
ans[key] = Object
291-
.keys(option.valueCoding || {})
319+
.keys(option?.valueCoding || {})
292320
.reduce((acc, prop) => ({...acc, [prop]: ''}), {})
293321
break;
294322

src/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export default interface FhirJsonSchema {
22
type?: string;
33
title?: string;
44
properties?: any;
5+
required?: string[];
56
}

0 commit comments

Comments
 (0)