Skip to content

Commit

Permalink
Convert item elements starting with _ to fce and to fhir
Browse files Browse the repository at this point in the history
  • Loading branch information
vesnushka committed Nov 18, 2024
1 parent e77648b commit 4918d79
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sdc-qrf/src/converter/__tests__/fce.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import fce_allergies from './resources/questionnaire_fce/allergies.json';
import fce_beverages from './resources/questionnaire_fce/beverages.json';
import fce_choice_answer_option from './resources/questionnaire_fce/choice_answer_option.json';
import fce_consent from './resources/questionnaire_fce/consent.json';
import fce_cqf_examples from './resources/questionnaire_fce/cqf-examples.json';
import fce_enable_when from './resources/questionnaire_fce/enable_when.json';
import fce_encounter_create from './resources/questionnaire_fce/encounter_create.json';
import fce_gad_7 from './resources/questionnaire_fce/gad_7.json';
Expand All @@ -37,6 +38,7 @@ import fhir_allergies from './resources/questionnaire_fhir/allergies.json';
import fhir_beverages from './resources/questionnaire_fhir/beverages.json';
import fhir_choice_answer_option from './resources/questionnaire_fhir/choice_answer_option.json';
import fhir_consent from './resources/questionnaire_fhir/consent.json';
import fhir_cqf_examples from './resources/questionnaire_fhir/cqf-examples.json';
import fhir_enable_when from './resources/questionnaire_fhir/enable_when.json';
import fhir_encounter_create from './resources/questionnaire_fhir/encounter_create.json';
import fhir_gad_7 from './resources/questionnaire_fhir/gad_7.json';
Expand Down Expand Up @@ -134,6 +136,7 @@ describe('Questionanire and QuestionnaireResponses transformation', () => {
[fhir_practitioner_create_structure_map, fce_practitioner_create_structure_map],
[fhir_consent, fce_consent],
[fhir_enable_when, fce_enable_when],
[fhir_cqf_examples, fce_cqf_examples],
])(
'Each FHIR Questionnaire should convert to FCE',
async (fhir_questionnaire, fce_questionnaire) => {
Expand Down Expand Up @@ -166,6 +169,7 @@ describe('Questionanire and QuestionnaireResponses transformation', () => {
[fce_practitioner_create_structure_map, fhir_practitioner_create_structure_map],
[fce_consent, fhir_consent],
[fce_enable_when, fhir_enable_when],
[fce_cqf_examples, fhir_cqf_examples],
])(
'Each FCE Questionnaire should convert to FHIR',
async (fce_questionnaire, fhir_questionnaire) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"subjectType": [
"Encounter",
"Patient"
],
"meta": {
"profile": [
"https://beda.software/beda-emr-questionnaire"
],
"lastUpdated": "2024-11-18T13:35:34.455065Z",
"createdAt": "2024-11-15T17:04:52.598486Z",
"versionId": "11968"
},
"name": "CQF Examples",
"item": [
{
"text": "Click on this checkbox to see result",
"type": "boolean",
"linkId": "input-1"
},
{
"text": "This is default input label",
"type": "string",
"_text": {
"cqfExpression": {
"language": "text/fhirpath",
"expression": "iif(%QuestionnaireResponse.item.where(linkId='input-1').answer.value.boolean = true, 'Now the input label changed', null)"
}
},
"linkId": "input-2"
},
{
"item": [
{
"text": "This input is disabled if the checkbox is unchecked",
"type": "string",
"linkId": "input-5",
"readOnly": true,
"_readOnly": {
"cqfExpression": {
"language": "text/fhirpath",
"expression": "%QuestionnaireResponse.item.where(linkId='input-1').answer.value.boolean = false"
}
}
},
{
"text": "This input is required if the checkbox is checked",
"type": "string",
"linkId": "input-6",
"required": false,
"_required": {
"cqfExpression": {
"language": "text/fhirpath",
"expression": "%QuestionnaireResponse.item.where(linkId='input-1').answer.value.boolean = true"
}
}
}
],
"text": "This is default group label",
"type": "group",
"_text": {
"cqfExpression": {
"language": "text/fhirpath",
"expression": "iif(%QuestionnaireResponse.item.where(linkId='input-1').answer.value.boolean = true, 'Now the group label changed', null)"
}
},
"linkId": "input-3"
}
],
"resourceType": "Questionnaire",
"title": "CQF Examples",
"status": "active",
"id": "cqf-examples",
"url": "https://aidbox.emr.beda.software/ui/console#/entities/Questionnaire/cqf-examples"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"subjectType": [
"Encounter",
"Patient"
],
"meta": {
"profile": [
"https://beda.software/beda-emr-questionnaire"
],
"lastUpdated": "2024-11-18T13:35:34.455065Z",
"versionId": "11968",
"extension": [
{
"url": "ex:createdAt",
"valueInstant": "2024-11-15T17:04:52.598486Z"
}
]
},
"name": "CQF Examples",
"item": [
{
"text": "Click on this checkbox to see result",
"type": "boolean",
"linkId": "input-1"
},
{
"text": "This is default input label",
"type": "string",
"_text": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/cqf-expression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%QuestionnaireResponse.item.where(linkId='input-1').answer.value.boolean = true, 'Now the input label changed', null)"
}
}
]
},
"linkId": "input-2"
},
{
"item": [
{
"text": "This input is disabled if the checkbox is unchecked",
"type": "string",
"linkId": "input-5",
"readOnly": true,
"_readOnly": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/cqf-expression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%QuestionnaireResponse.item.where(linkId='input-1').answer.value.boolean = false"
}
}
]
}
},
{
"text": "This input is required if the checkbox is checked",
"type": "string",
"linkId": "input-6",
"required": false,
"_required": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/cqf-expression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%QuestionnaireResponse.item.where(linkId='input-1').answer.value.boolean = true"
}
}
]
}
}
],
"text": "This is default group label",
"type": "group",
"_text": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/cqf-expression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "iif(%QuestionnaireResponse.item.where(linkId='input-1').answer.value.boolean = true, 'Now the group label changed', null)"
}
}
]
},
"linkId": "input-3"
}
],
"resourceType": "Questionnaire",
"title": "CQF Examples",
"status": "active",
"id": "cqf-examples",
"url": "https://aidbox.emr.beda.software/ui/console#/entities/Questionnaire/cqf-examples"
}
5 changes: 5 additions & 0 deletions sdc-qrf/src/converter/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export enum ExtensionIdentifier {
CalculatedExpression = 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression',
EnableWhenExpression = 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression',
AnswerExpression = 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression',
CqfExpression = 'http://hl7.org/fhir/StructureDefinition/cqf-expression',

AdjustLastToRight = 'https://beda.software/fhir-emr-questionnaire/adjust-last-to-right',
SliderStart = 'https://beda.software/fhir-emr-questionnaire/slider-start',
Expand Down Expand Up @@ -219,6 +220,10 @@ export const extensionTransformers: ExtensionTransformer = {
},
},
},
[ExtensionIdentifier.CqfExpression]: {
// @ts-ignore
path: { extension: 'valueExpression', questionnaire: 'cqfExpression' },
},

[ExtensionIdentifier.AdjustLastToRight]: {
path: { extension: 'valueBoolean', questionnaire: 'adjustLastToRight' },
Expand Down
13 changes: 13 additions & 0 deletions sdc-qrf/src/converter/fceToFhir/questionnaire/processItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ export function processItems(items: FCEQuestionnaireItem[]): FHIRQuestionnaireIt
type: type as FHIRQuestionnaireItem['type'],
};

for (const property of Object.keys(item)) {
const element = item[property as keyof FCEQuestionnaireItem];

if (property.startsWith('_') && element instanceof Object) {
// @ts-ignore
fhirItem[property] = {
// TODO: update convertToFHIRExtension to accept element type to convert
// @ts-ignore
extension: convertToFHIRExtension(element),
};
}
}

if (answerOption !== undefined) {
fhirItem.answerOption = processAnswerOption(answerOption);
}
Expand Down
16 changes: 16 additions & 0 deletions sdc-qrf/src/converter/fhirToFce/questionnaire/processItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
QuestionnaireItem as FHIRQuestionnaireItem,
QuestionnaireItemAnswerOption as FHIRQuestionnaireItemAnswerOption,
QuestionnaireItemInitial as FHIRQuestionnaireItemInitial,
Element as FHIRElement,
} from 'fhir/r4b';
import _ from 'lodash';

Expand Down Expand Up @@ -52,6 +53,21 @@ function getUpdatedPropertiesFromItem(item: FHIRQuestionnaireItem) {
continue;
}

for (const property of Object.keys(item)) {
const element = item[property as keyof FHIRQuestionnaireItem];
if (property.startsWith('_') && element instanceof Object) {
const primitiveExtensions = (element as FHIRElement)?.extension ?? [];
for (const extension of primitiveExtensions) {
if (extension.url === identifier) {
updatedProperties = {
...updatedProperties,
...{ [property]: convertFromFHIRExtension(extension) },
};
}
}
}
}

const extension = findExtension(item, identifier);
if (extension !== undefined) {
updatedProperties = {
Expand Down

0 comments on commit 4918d79

Please sign in to comment.