Skip to content

Commit

Permalink
Merge branch 'release/0.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dermatologist committed May 17, 2021
2 parents 9a33090 + ec32317 commit 28f77a5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fhirformjs",
"description": "FHIR Questionnaire To Form Converter for rendering",
"version": "0.8.1",
"version": "0.9.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
34 changes: 31 additions & 3 deletions src/ques-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const FhirJsonForm = (
fhirQuestionnaire: R4.IQuestionnaire
): FhirForm => {
let ALL_PROPERTIES: any = {};
let requiredProperties: string[] = [];
let UISchema: any = {};

let fhirQuestionnaireResponse: R4.IQuestionnaireResponse = {
Expand Down Expand Up @@ -53,21 +54,35 @@ export const FhirJsonForm = (
myProperty
] = GetItemProperties(groupItem);

if (groupItem.required) {
if (ALL_PROPERTIES[groupProperty]['required'] === undefined) {
ALL_PROPERTIES[groupProperty]['required'] = []
}
ALL_PROPERTIES[groupProperty]['required'].push(myProperty)
}

if (GetWidget(groupItem) !== '') {
UISchema[groupProperty][myProperty] = {
'ui:widget': GetWidget(groupItem),
};
}

if (GetUIOptions(groupItem) !== '') {
const uiOptions = GetUIOptions(groupItem)
if (uiOptions !== '') {
UISchema[groupProperty][myProperty] = {
'ui:options': GetUIOptions(groupItem),
'ui:options': uiOptions,
};

if (uiOptions.unit) {
UISchema[groupProperty][myProperty]['ui:placeholder'] = uiOptions.unit
}
}

fhirQuestionnaireResponse.item?.push(CreateResponseItem(groupItem));
});

item.required && requiredProperties.push(groupProperty)

// Just push the fields if not a group
} else {
let myProperty =
Expand All @@ -88,13 +103,16 @@ export const FhirJsonForm = (
}

fhirQuestionnaireResponse.item?.push(CreateResponseItem(item));

item.required && requiredProperties.push(myProperty)
}
});

let fhirJsonSchema: FhirJsonSchema = {
type: 'object',
title: fhirQuestionnaire.id?.toString(),
properties: ALL_PROPERTIES,
required: requiredProperties,
};
let fhirForm: FhirForm = {
model: fhirQuestionnaireResponse,
Expand Down Expand Up @@ -244,9 +262,19 @@ const GetControlType = (item: R4.IQuestionnaire_Item) => {
return 'array'
}
}

if (item.type === R4.Questionnaire_ItemTypeKind._boolean) {
return 'boolean';
}

if (item.type == R4.Questionnaire_ItemTypeKind._decimal) {
return 'number';
}

if (item.type == R4.Questionnaire_ItemTypeKind._integer) {
return 'integer';
}

return 'string';
};

Expand Down Expand Up @@ -288,7 +316,7 @@ const CreateResponseItem = (item: R4.IQuestionnaire_Item) => {
case R4.Questionnaire_ItemTypeKind._openChoice:
const option = (item.answerOption || [])[0]
ans[key] = Object
.keys(option.valueCoding || {})
.keys(option?.valueCoding || {})
.reduce((acc, prop) => ({...acc, [prop]: ''}), {})
break;

Expand Down
1 change: 1 addition & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export default interface FhirJsonSchema {
type?: string;
title?: string;
properties?: any;
required?: string[];
}

0 comments on commit 28f77a5

Please sign in to comment.