From 3d103eeb337fa15ed4f9fd16936f5f1db0262ccc Mon Sep 17 00:00:00 2001 From: Marco Ferreira Date: Mon, 17 May 2021 04:31:25 +0200 Subject: [PATCH 1/3] Add support for number types and required items --- src/ques-mapper.ts | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/ques-mapper.ts b/src/ques-mapper.ts index b0ab482..3dc1f61 100644 --- a/src/ques-mapper.ts +++ b/src/ques-mapper.ts @@ -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 = { @@ -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 = @@ -88,6 +103,8 @@ export const FhirJsonForm = ( } fhirQuestionnaireResponse.item?.push(CreateResponseItem(item)); + + item.required && requiredProperties.push(myProperty) } }); @@ -95,6 +112,7 @@ export const FhirJsonForm = ( type: 'object', title: fhirQuestionnaire.id?.toString(), properties: ALL_PROPERTIES, + required: requiredProperties, }; let fhirForm: FhirForm = { model: fhirQuestionnaireResponse, @@ -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'; }; @@ -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; From 6f283ce16b63e14c058d76602b621b66b6889f19 Mon Sep 17 00:00:00 2001 From: Marco Ferreira Date: Mon, 17 May 2021 04:44:59 +0200 Subject: [PATCH 2/3] Add missing interface type for required inputs --- src/schema.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/schema.ts b/src/schema.ts index 3935a13..613af55 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -2,4 +2,5 @@ export default interface FhirJsonSchema { type?: string; title?: string; properties?: any; + required?: string[]; } From ec3231764680b565182208f9b17a969094524df3 Mon Sep 17 00:00:00 2001 From: Bellraj Eapen Date: Mon, 17 May 2021 12:34:06 -0400 Subject: [PATCH 3/3] update version 0.9.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 86a61d3..17f1935 100644 --- a/package.json +++ b/package.json @@ -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",