Skip to content

Commit

Permalink
Merge branch 'master' into 354-generic-resource-list
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlipovka committed Dec 10, 2024
2 parents 73fc700 + 7f55b0d commit 3491c3b
Show file tree
Hide file tree
Showing 14 changed files with 1,303 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ auth:
refresh_token: true
secret_required: false
access_token_expiration: 36000
type: smart-on-fhir
type: smart-on-fhir-practitioner
smart:
launch_uri: https://www.smartforms.io/launch
name: SmartForms
Expand Down
15 changes: 15 additions & 0 deletions resources/seeds/Client/a57d90e3-5f69-4b92-aa2e-2992180863c2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
auth:
authorization_code:
redirect_uri: https://portal-xrp.digitalhealth.gov.au/FormsPortal/authorisation
refresh_token: true
secret_required: false
access_token_expiration: 36000
type: smart-on-fhir-practitioner
smart:
name: ADHA CHAP Form
launch_uri: https://portal-xrp.digitalhealth.gov.au/FormsPortal/launch
description: ADHA CHAP Form
grant_types:
- authorization_code
id: a57d90e3-5f69-4b92-aa2e-2992180863c2
resourceType: Client
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ auth:
refresh_token: true
secret_required: false
access_token_expiration: 36000
type: smart-on-fhir
type: smart-on-fhir-practitioner
smart:
name: Clinical guidelines
launch_uri: https://beda.caresofa.com/
Expand Down
63 changes: 34 additions & 29 deletions src/containers/PatientDetails/DocumentPrint/utils.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
import { QuestionnaireItem, QuestionnaireResponse } from 'fhir/r4b';

import { evaluate } from 'src/utils';
import { compileAsFirst } from 'src/utils';

export function findQRItemValue(linkId: string, type = 'String') {
return `repeat(item).where(linkId='${linkId}').answer.value${type}`;
}
const qItemIsHidden = compileAsFirst<QuestionnaireItem, boolean>(
"extension.where(url='http://hl7.org/fhir/StructureDefinition/questionnaire-hidden').exists() and extension.where(url='http://hl7.org/fhir/StructureDefinition/questionnaire-hidden').valueBoolean=true",
);

const getQrItemValueByLinkIdAndType = (linkId: string, type: string) =>
compileAsFirst<QuestionnaireResponse, string>(`repeat(item).where(linkId='${linkId}').answer.value${type}`);

const questionnaireItemValueTypeMap: Record<QuestionnaireItem['type'], string> = {
display: 'String',
group: 'String',
text: 'String',
string: 'String',
decimal: 'Decimal',
integer: 'Integer',
date: 'Date',
dateTime: 'DateTime',
time: 'Time',
choice: 'Coding.display',
boolean: 'Boolean',
reference: 'Reference.display',
'open-choice': '',
attachment: '',
quantity: '',
question: '',
url: '',
};

export function getQuestionnaireItemValue(
questionnaireItem: QuestionnaireItem,
questionnaireResponse: QuestionnaireResponse,
) {
switch (questionnaireItem.type) {
case 'display':
case 'group':
return '';
case 'text':
case 'string':
return evaluate(questionnaireResponse, findQRItemValue(questionnaireItem.linkId, 'String'))[0];
case 'decimal':
return evaluate(questionnaireResponse, findQRItemValue(questionnaireItem.linkId, 'Decimal'))[0];
case 'integer':
return evaluate(questionnaireResponse, findQRItemValue(questionnaireItem.linkId, 'Integer'))[0];
case 'date':
return evaluate(questionnaireResponse, findQRItemValue(questionnaireItem.linkId, 'Date'))[0];
case 'dateTime':
return evaluate(questionnaireResponse, findQRItemValue(questionnaireItem.linkId, 'DateTime'))[0];
case 'time':
return evaluate(questionnaireResponse, findQRItemValue(questionnaireItem.linkId, 'Time'))[0];
case 'choice':
return evaluate(questionnaireResponse, findQRItemValue(questionnaireItem.linkId, 'Coding.display'))[0];
case 'boolean':
return evaluate(questionnaireResponse, findQRItemValue(questionnaireItem.linkId, 'Boolean'))[0];
case 'reference':
return evaluate(questionnaireResponse, findQRItemValue(questionnaireItem.linkId, 'Reference.display'))[0];
default:
return evaluate(questionnaireResponse, findQRItemValue(questionnaireItem.linkId))[0];
if (qItemIsHidden(questionnaireItem)) {
return undefined;
}

return getQrItemValueByLinkIdAndType(
questionnaireItem.linkId,
questionnaireItemValueTypeMap[questionnaireItem.type],
)(questionnaireResponse);
}

export function flattenQuestionnaireGroupItems(item: QuestionnaireItem): QuestionnaireItem[] {
Expand Down
152 changes: 152 additions & 0 deletions src/utils/__tests__/enableWhen/equal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import {
CONTROL_ITEM_LINK_ID,
generateQAndQRData,
QuestionnaireData,
testEnableWhenCases,
ENABLE_WHEN_TESTS_TITLE,
} from './utils';

const ENABLE_WHEN_EQUAL_QUESTIONAIRES: QuestionnaireData[] = [
{
...generateQAndQRData({
type: 'integer',
enableWhen: [
{
question: 'q1',
operator: '=',
answer: { integer: 1 },
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { integer: 1 } }],
},
{
linkId: 'q2',
answer: [],
},
{
linkId: CONTROL_ITEM_LINK_ID,
answer: [],
},
],
}),
},
{
...generateQAndQRData({
type: 'integer',
enableWhen: [
{
question: 'q1',
operator: '=',
answer: { string: 'test' },
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { string: 'test2' } }],
},
{
linkId: 'q2',
answer: [],
},
],
}),
},
{
...generateQAndQRData({
type: 'integer',
enableWhen: [
{
question: 'q1',
operator: '=',
answer: { string: 'test1' },
},
{
question: 'q2',
operator: '=',
answer: { string: 'test2' },
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { string: 'test1' } }],
},
{
linkId: 'q2',
answer: [{ value: { string: 'test2' } }],
},
{
linkId: CONTROL_ITEM_LINK_ID,
answer: [],
},
],
}),
},
{
...generateQAndQRData({
type: 'integer',
enableWhen: [
{
question: 'q1',
operator: '=',
answer: { string: 'test1' },
},
{
question: 'q2',
operator: '=',
answer: { string: 'test2' },
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { string: 'asd' } }],
},
{
linkId: 'q2',
answer: [{ value: { string: 'test2' } }],
},
],
}),
},
{
...generateQAndQRData({
type: 'integer',
enableBehavior: 'any',
enableWhen: [
{
question: 'q1',
operator: '=',
answer: { Coding: { code: 'test1', display: 'test1' } },
},
{
question: 'q2',
operator: '=',
answer: { Coding: { code: 'test2', display: 'test2' } },
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { Coding: { code: 'asd', display: 'asd' } } }],
},
{
linkId: 'q2',
answer: [{ value: { Coding: { code: 'test2', display: 'Different display' } } }],
},
{
linkId: CONTROL_ITEM_LINK_ID,
answer: [],
},
],
}),
},
];

describe('Enable when: "="', () => {
test.each(ENABLE_WHEN_EQUAL_QUESTIONAIRES)(ENABLE_WHEN_TESTS_TITLE, testEnableWhenCases);
});
Loading

0 comments on commit 3491c3b

Please sign in to comment.