Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix enableWhenExpression to query against FHIR format #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sdc-qrf/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
QuestionnaireResponseItemAnswer,
} from 'shared/src/contrib/aidbox';

import { fromFirstClassExtension } from './converter';
import {
AnswerValue,
FormAnswerItems,
Expand Down Expand Up @@ -502,8 +503,9 @@ function isQuestionEnabled(args: IsQuestionEnabledArgs) {

if (enableWhenExpression && enableWhenExpression.language === 'text/fhirpath') {
const expressionResult = fhirpath.evaluate(
args.context.resource,
fromFirstClassExtension(args.context.resource),
enableWhenExpression.expression!,
//TODO convert context
args.context ?? {},
)[0];

Expand Down
98 changes: 98 additions & 0 deletions sdc-qrf/tests/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Questionnaire as FHIRQuestionnaire } from 'fhir/r4b';

import { Questionnaire, QuestionnaireResponse } from 'shared/src/contrib/aidbox';

import { allergiesQuestionnaire } from './resources/questionnaire';
Expand All @@ -7,6 +9,7 @@ import {
mapFormToResponse,
mapResponseToForm,
removeDisabledAnswers,
toFirstClassExtension,
} from '../src';

test('Transform nested repeatable-groups from new resource to new resource', () => {
Expand Down Expand Up @@ -765,3 +768,98 @@ describe('isValueEmpty method test', () => {
expect(isValueEmpty(valueType.value)).toEqual(valueType.expect);
});
});

describe('enableWhenExpression', () => {
const fhirQuestionnaire: FHIRQuestionnaire = {
resourceType: 'Questionnaire',
status: 'active',
meta: {
profile: ['https://beda.software/beda-emr-questionnaire'],
},
item: [
{
type: 'string',
linkId: 'patient-id',
},
{
text: 'Patient',
type: 'reference',
linkId: 'patient-reference',
extension: [
{
url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression',
valueExpression: {
language: 'text/fhirpath',
expression:
"QuestionnaireResponse.repeat(item).where(linkId='patient-id').answer.valueString.empty()",
},
},
],
},
],
};
const questionnaire = toFirstClassExtension(fhirQuestionnaire);

test('Empty answer check', () => {
const qr: QuestionnaireResponse = {
resourceType: 'QuestionnaireResponse',
status: 'completed',
item: [
{
linkId: 'patient-id',
},
],
};
const formItems = mapResponseToForm(qr, questionnaire);
const enabledFormItems = getEnabledQuestions(questionnaire.item!, [], formItems, {
questionnaire,
resource: qr,
context: qr,
});
expect(enabledFormItems).toEqual([
{
linkId: 'patient-id',
type: 'string',
},
{
enableWhenExpression: {
expression:
"QuestionnaireResponse.repeat(item).where(linkId='patient-id').answer.valueString.empty()",
language: 'text/fhirpath',
},
linkId: 'patient-reference',
text: 'Patient',
type: 'reference',
},
]);
});

test('Non empty answer check', () => {
const qr: QuestionnaireResponse = {
resourceType: 'QuestionnaireResponse',
status: 'completed',
item: [
{
linkId: 'patient-id',
answer: [
{
value: { string: '123' },
},
],
},
],
};
const formItems = mapResponseToForm(qr, questionnaire);
const enabledFormItems = getEnabledQuestions(questionnaire.item!, [], formItems, {
questionnaire,
resource: qr,
context: qr,
});
expect(enabledFormItems).toEqual([
{
linkId: 'patient-id',
type: 'string',
},
]);
});
});
Loading