From a47e429fc7148cf7c86c0b7865e87147cdbe1cfa Mon Sep 17 00:00:00 2001 From: Simona Domnisoru Date: Mon, 4 Dec 2023 08:32:29 +0100 Subject: [PATCH] test: [TECH-887] improve rules engine unit test coverage (#3462) --- packages/rules-engine/src/RulesEngine.js | 2 +- .../src/helpers/previousValueCheck.js | 2 +- .../rulesEffectsProcessor.js | 27 +- .../helpers/structureEvents.js | 6 +- ...eRuleEffectsForTrackerProgram.test.js.snap | 2 +- ...icableRuleEffectsForTrackerProgram.test.js | 150 +- ...licableRulesEffectsForEventProgram.test.js | 68 +- .../__tests__/postProcessRulesEffects.test.js | 211 ++ .../ruleEffectsForEventProgram.test.js | 2854 +++++++++++++++-- .../rulesEffectsForTrackerProgram.test.js | 889 ++++- .../rules/__tests__/rulesEngine.test.js | 717 +++++ 11 files changed, 4522 insertions(+), 406 deletions(-) create mode 100644 src/core_modules/capture-core/rules/__tests__/postProcessRulesEffects.test.js create mode 100644 src/core_modules/capture-core/rules/__tests__/rulesEngine.test.js diff --git a/packages/rules-engine/src/RulesEngine.js b/packages/rules-engine/src/RulesEngine.js index bbd6f279d1..d634f5d558 100644 --- a/packages/rules-engine/src/RulesEngine.js +++ b/packages/rules-engine/src/RulesEngine.js @@ -1,6 +1,6 @@ // @flow import log from 'loglevel'; -import { VariableService } from './services/VariableService/VariableService'; +import { VariableService } from './services/VariableService'; import { ValueProcessor } from './processors/ValueProcessor'; import { executeExpression } from './services/expressionService'; import { getD2Functions } from './d2Functions'; diff --git a/packages/rules-engine/src/helpers/previousValueCheck.js b/packages/rules-engine/src/helpers/previousValueCheck.js index 628900c6be..5745315d04 100644 --- a/packages/rules-engine/src/helpers/previousValueCheck.js +++ b/packages/rules-engine/src/helpers/previousValueCheck.js @@ -59,7 +59,7 @@ export const getOutputEffectsWithPreviousValueCheck = ({ onProcessValue: (value: any, type: $Values) => any, }) => outputEffects.reduce((acc, outputEffect) => { - if (formValues && outputEffect.targetDataType) { + if (formValues && Object.keys(formValues).length !== 0 && outputEffect.targetDataType) { const formValue = formValues[outputEffect.id]; const rawValue = mapByTargetDataTypes[outputEffect.targetDataType]({ dataElementId, diff --git a/packages/rules-engine/src/processors/rulesEffectsProcessor/rulesEffectsProcessor.js b/packages/rules-engine/src/processors/rulesEffectsProcessor/rulesEffectsProcessor.js index 15951dbc57..72cbd2f20f 100644 --- a/packages/rules-engine/src/processors/rulesEffectsProcessor/rulesEffectsProcessor.js +++ b/packages/rules-engine/src/processors/rulesEffectsProcessor/rulesEffectsProcessor.js @@ -296,26 +296,23 @@ export function getRulesEffectsProcessor( formValues, onProcessValue, }: { - effects: ?Array, + effects: Array, dataElements: ?DataElements, trackedEntityAttributes: ?TrackedEntityAttributes, formValues?: ?{ [key: string]: any }, onProcessValue: (value: any, type: $Values) => any, }): OutputEffects { - if (effects) { - return effects - .filter(({ action }) => mapActionsToProcessor[action]) - .flatMap(effect => mapActionsToProcessor[effect.action]( - effect, - dataElements, - trackedEntityAttributes, - formValues, - onProcessValue, - )) - // when mapActionsToProcessor function returns `null` we filter those value out. - .filter(keepTruthyValues => keepTruthyValues); - } - return []; + return effects + .filter(({ action }) => mapActionsToProcessor[action]) + .flatMap(effect => mapActionsToProcessor[effect.action]( + effect, + dataElements, + trackedEntityAttributes, + formValues, + onProcessValue, + )) + // when mapActionsToProcessor function returns `null` we filter those value out. + .filter(keepTruthyValues => keepTruthyValues); } return processRulesEffects; diff --git a/packages/rules-engine/src/services/VariableService/helpers/structureEvents.js b/packages/rules-engine/src/services/VariableService/helpers/structureEvents.js index e0e1422616..7c4fcab7f8 100644 --- a/packages/rules-engine/src/services/VariableService/helpers/structureEvents.js +++ b/packages/rules-engine/src/services/VariableService/helpers/structureEvents.js @@ -38,9 +38,9 @@ export const getStructureEvents = (compareDates: CompareDates) => { event.eventId !== currentEvent.eventId, ); - const events = [...otherEventsFiltered, currentEvent] - .sort(compareEvents); + const events = Object.keys(currentEvent).length !== 0 ? otherEventsFiltered.concat(currentEvent) : otherEventsFiltered; + const sortedEvents = events.sort(compareEvents); - return createEventsContainer(events); + return createEventsContainer(sortedEvents); }; }; diff --git a/src/core_modules/capture-core/rules/__tests__/__snapshots__/getApplicableRuleEffectsForTrackerProgram.test.js.snap b/src/core_modules/capture-core/rules/__tests__/__snapshots__/getApplicableRuleEffectsForTrackerProgram.test.js.snap index 2c73fac45b..f2fb347ece 100644 --- a/src/core_modules/capture-core/rules/__tests__/__snapshots__/getApplicableRuleEffectsForTrackerProgram.test.js.snap +++ b/src/core_modules/capture-core/rules/__tests__/__snapshots__/getApplicableRuleEffectsForTrackerProgram.test.js.snap @@ -125,7 +125,7 @@ Object { "trackedEntityAttributes": Object { "lZGmxYbs96q": Object { "id": "lZGmxYbs96q", - "optionSetId": undefined, + "optionSetId": "optionSet", "valueType": "DATE", }, "lZGmxYbs97q": Object { diff --git a/src/core_modules/capture-core/rules/__tests__/getApplicableRuleEffectsForTrackerProgram.test.js b/src/core_modules/capture-core/rules/__tests__/getApplicableRuleEffectsForTrackerProgram.test.js index 0ad48833c4..23e05892ba 100644 --- a/src/core_modules/capture-core/rules/__tests__/getApplicableRuleEffectsForTrackerProgram.test.js +++ b/src/core_modules/capture-core/rules/__tests__/getApplicableRuleEffectsForTrackerProgram.test.js @@ -1,3 +1,4 @@ +import { variableSourceTypes } from '@dhis2/rules-engine-javascript'; import { TrackerProgram, ProgramStage, @@ -10,24 +11,27 @@ import { } from '../../metaData'; import { getApplicableRuleEffectsForTrackerProgram } from '..'; -const mockGetProgramRuleEffects = jest.fn().mockImplementation(() => [{ - id: 'effectId', - type: 'DISPLAYTEXT', - message: 'display effect', -}]); +const mockGetProgramRuleEffects = jest.fn().mockImplementation(() => [ + { + id: 'effectId', + type: 'DISPLAYTEXT', + message: 'display effect', + }, +]); const mockOptionSet = new OptionSet('optionSet1', [new Option('option1', 'opt1')]); jest.mock('@dhis2/rules-engine-javascript/build/cjs/RulesEngine', () => ({ - RulesEngine: jest.fn().mockImplementation(() => - ({ getProgramRuleEffects: (...args) => mockGetProgramRuleEffects(...args) })), + RulesEngine: jest + .fn() + .mockImplementation(() => ({ getProgramRuleEffects: (...args) => mockGetProgramRuleEffects(...args) })), })); jest.mock('../../metaDataMemoryStores/constants/constants.store', () => ({ - constantsStore: ({ get: () => [{ id: 'constantId1', value: '1' }] }), + constantsStore: { get: () => [{ id: 'constantId1', value: '1' }] }, })); jest.mock('../../metaDataMemoryStores/optionSets/optionSets.store', () => ({ - optionSetStore: ({ get: () => [mockOptionSet] }), + optionSetStore: { get: () => [mockOptionSet] }, })); describe('getApplicableRuleEffectsForTrackerProgram', () => { @@ -46,20 +50,22 @@ describe('getApplicableRuleEffectsForTrackerProgram', () => { trackedEntityInstanceId: 'vCGpQAWG17I', }; - const otherEvents = [{ - da1Id: 'otherEventText', - dueDate: '2021-05-31T09:51:38.134', - enrollmentId: 'vVtmDlsu3me', - enrollmentStatus: 'ACTIVE', - eventDate: '2021-05-31T00:00:00.000', - eventId: 'BxGzDJK3JqN', - orgUnitId: 'DiszpKrYNg8', - orgUnitName: 'Ngelehun CHC', - programId: 'IpHINAT79UW', - programStageId: 'A03MvHHogjR', - status: 'ACTIVE', - trackedEntityInstanceId: 'vCGpQAWG17I', - }]; + const otherEvents = [ + { + da1Id: 'otherEventText', + dueDate: '2021-05-31T09:51:38.134', + enrollmentId: 'vVtmDlsu3me', + enrollmentStatus: 'ACTIVE', + eventDate: '2021-05-31T00:00:00.000', + eventId: 'BxGzDJK3JqN', + orgUnitId: 'DiszpKrYNg8', + orgUnitName: 'Ngelehun CHC', + programId: 'IpHINAT79UW', + programStageId: 'A03MvHHogjR', + status: 'ACTIVE', + trackedEntityInstanceId: 'vCGpQAWG17I', + }, + ]; const orgUnit = { id: 'DiszpKrYNg8', code: 'Ngelehun CHC' }; @@ -72,16 +78,18 @@ describe('getApplicableRuleEffectsForTrackerProgram', () => { const programStage = new ProgramStage((stage) => { stage.id = 'st1Id'; stage.name = 'stage1'; - stage.programRules = [{ - id: 'rule1Id', - name: 'rule1', - displayName: 'rule1', - priority: 1, - condition: 'true', - programId: 'IpHINAT79UW', - programStageId: 'st1Id', - programRuleActions: [], - }]; + stage.programRules = [ + { + id: 'rule1Id', + name: 'rule1', + displayName: 'rule1', + priority: 1, + condition: 'true', + programId: 'IpHINAT79UW', + programStageId: 'st1Id', + programRuleActions: [], + }, + ]; stage.stageForm = new RenderFoundation((foundation) => { const section = new Section((initSection) => { @@ -115,6 +123,7 @@ describe('getApplicableRuleEffectsForTrackerProgram', () => { element3.id = 'lZGmxYbs96q'; element3.name = 'SomeDate'; element3.type = dataElementTypes.DATE; + element3.optionSet = { id: 'optionSet', name: 'optionSet', code: 'optionSet' }; }), new DataElement((element4) => { element4.id = 'w75KJ2mc4zz'; @@ -129,7 +138,7 @@ describe('getApplicableRuleEffectsForTrackerProgram', () => { displayName: 'Test', id: 'PUQZWgmQ0jx', programId: 'IpHINAT79UW', - programRuleVariableSourceType: 'DATAELEMENT_NEWEST_EVENT_PROGRAM', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, useNameForOptionSet: true, }, { @@ -137,7 +146,7 @@ describe('getApplicableRuleEffectsForTrackerProgram', () => { displayName: 'apgarcomment', id: 'aKpfPKSRQnv', programId: 'IpHINAT79UW', - programRuleVariableSourceType: 'DATAELEMENT_NEWEST_EVENT_PROGRAM', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, useNameForOptionSet: true, }, { @@ -145,23 +154,27 @@ describe('getApplicableRuleEffectsForTrackerProgram', () => { displayName: 'apgarscore', id: 'g2GooOydipB', programId: 'IpHINAT79UW', - programRuleVariableSourceType: 'DATAELEMENT_NEWEST_EVENT_PROGRAM', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, useNameForOptionSet: true, }, ]; - initProgram.programRules = [{ - condition: 'true', - displayName: 'TestRule', - id: 'JJDQxgHuuL2', - programId: 'IpHINAT79UW', - programRuleActions: [{ - data: '#{Test}', - id: 'CQaifjkoFEU', - location: 'feedback', - programRuleActionType: 'DISPLAYTEXT', - }], - }]; + initProgram.programRules = [ + { + condition: 'true', + displayName: 'TestRule', + id: 'JJDQxgHuuL2', + programId: 'IpHINAT79UW', + programRuleActions: [ + { + data: '#{Test}', + id: 'CQaifjkoFEU', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + ], + }, + ]; }); const attributeValues = { @@ -210,16 +223,51 @@ describe('getApplicableRuleEffectsForTrackerProgram', () => { }); test('Flat result', () => { + const effects = getApplicableRuleEffectsForTrackerProgram( + { + program, + stage: programStage, + orgUnit, + currentEvent, + otherEvents, + attributeValues, + enrollmentData, + }, + true, + ); + + expect(Array.isArray(effects)).toBe(true); + }); + + test('RulesEngine called without programRules', () => { + const effects = getApplicableRuleEffectsForTrackerProgram({ + program: new TrackerProgram((initProgram) => { + initProgram.programRules = []; + }), + stage: new ProgramStage((stage) => { + stage.programRules = []; + }), + orgUnit, + currentEvent, + otherEvents, + attributeValues, + enrollmentData, + }); + + expect(effects).toStrictEqual([]); + }); + + test('currentEvent without a programStageId', () => { const effects = getApplicableRuleEffectsForTrackerProgram({ program, stage: programStage, orgUnit, - currentEvent, + currentEvent: {}, otherEvents, attributeValues, enrollmentData, - }, true); + }); - expect(Array.isArray(effects)).toBe(true); + expect(effects.DISPLAYTEXT).toBeDefined(); }); }); diff --git a/src/core_modules/capture-core/rules/__tests__/getApplicableRulesEffectsForEventProgram.test.js b/src/core_modules/capture-core/rules/__tests__/getApplicableRulesEffectsForEventProgram.test.js index 0fd9ac1510..7efadd5453 100644 --- a/src/core_modules/capture-core/rules/__tests__/getApplicableRulesEffectsForEventProgram.test.js +++ b/src/core_modules/capture-core/rules/__tests__/getApplicableRulesEffectsForEventProgram.test.js @@ -1,3 +1,4 @@ +import { variableSourceTypes } from '@dhis2/rules-engine-javascript'; import { EventProgram, ProgramStage, @@ -10,24 +11,27 @@ import { } from '../../metaData'; import { getApplicableRuleEffectsForEventProgram } from '..'; -const mockGetProgramRuleEffects = jest.fn().mockImplementation(() => [{ - id: 'effectId', - type: 'DISPLAYTEXT', - message: 'display effect', -}]); +const mockGetProgramRuleEffects = jest.fn().mockImplementation(() => [ + { + id: 'effectId', + type: 'DISPLAYTEXT', + message: 'display effect', + }, +]); const mockOptionSet = new OptionSet('optionSet1', [new Option('option1', 'opt1')]); jest.mock('@dhis2/rules-engine-javascript/build/cjs/RulesEngine', () => ({ - RulesEngine: jest.fn().mockImplementation(() => - ({ getProgramRuleEffects: (...args) => mockGetProgramRuleEffects(...args) })), + RulesEngine: jest + .fn() + .mockImplementation(() => ({ getProgramRuleEffects: (...args) => mockGetProgramRuleEffects(...args) })), })); jest.mock('../../metaDataMemoryStores/constants/constants.store', () => ({ - constantsStore: ({ get: () => [{ id: 'constantId1', value: '1' }] }), + constantsStore: { get: () => [{ id: 'constantId1', value: '1' }] }, })); jest.mock('../../metaDataMemoryStores/optionSets/optionSets.store', () => ({ - optionSetStore: ({ get: () => [mockOptionSet] }), + optionSetStore: { get: () => [mockOptionSet] }, })); describe('getApplicableRuleEffectsForEventProgram', () => { @@ -75,7 +79,7 @@ describe('getApplicableRuleEffectsForEventProgram', () => { displayName: 'Test', id: 'PUQZWgmQ0jx', programId: 'IpHINAT79UW', - programRuleVariableSourceType: 'DATAELEMENT_NEWEST_EVENT_PROGRAM', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, useNameForOptionSet: true, }, { @@ -83,7 +87,7 @@ describe('getApplicableRuleEffectsForEventProgram', () => { displayName: 'apgarcomment', id: 'aKpfPKSRQnv', programId: 'IpHINAT79UW', - programRuleVariableSourceType: 'DATAELEMENT_NEWEST_EVENT_PROGRAM', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, useNameForOptionSet: true, }, { @@ -91,23 +95,27 @@ describe('getApplicableRuleEffectsForEventProgram', () => { displayName: 'apgarscore', id: 'g2GooOydipB', programId: 'IpHINAT79UW', - programRuleVariableSourceType: 'DATAELEMENT_NEWEST_EVENT_PROGRAM', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, useNameForOptionSet: true, }, ]; - initProgram.programRules = [{ - condition: 'true', - displayName: 'TestRule', - id: 'JJDQxgHuuL2', - programId: 'IpHINAT79UW', - programRuleActions: [{ - data: '#{Test}', - id: 'CQaifjkoFEU', - location: 'feedback', - programRuleActionType: 'DISPLAYTEXT', - }], - }]; + initProgram.programRules = [ + { + condition: 'true', + displayName: 'TestRule', + id: 'JJDQxgHuuL2', + programId: 'IpHINAT79UW', + programRuleActions: [ + { + data: '#{Test}', + id: 'CQaifjkoFEU', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + ], + }, + ]; }); test('RulesEngine called with computed arguments from getApplicableRuleEffectsForEventProgram', () => { @@ -139,4 +147,16 @@ describe('getApplicableRuleEffectsForEventProgram', () => { expect(effects.DISPLAYTEXT).toBeDefined(); }); + + test('RulesEngine called without programRules', () => { + const effects = getApplicableRuleEffectsForEventProgram({ + program: new EventProgram((initProgram) => { + initProgram.programRules = []; + }), + orgUnit, + currentEvent, + }); + + expect(effects).toStrictEqual([]); + }); }); diff --git a/src/core_modules/capture-core/rules/__tests__/postProcessRulesEffects.test.js b/src/core_modules/capture-core/rules/__tests__/postProcessRulesEffects.test.js new file mode 100644 index 0000000000..6792dc777f --- /dev/null +++ b/src/core_modules/capture-core/rules/__tests__/postProcessRulesEffects.test.js @@ -0,0 +1,211 @@ +import { postProcessRulesEffects } from '../index'; +import { RenderFoundation, Section, DataElement, dataElementTypes } from '../../metaData'; + +test('Post process rules effects', () => { + // given + const rulesEffects = [ + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Eeb7Ixr4Pv6', message: 'd2:floor((5+5) / 2) = 5' }, + }, + { type: 'HIDEPROGRAMSTAGE', id: 'PUZaKR0Jh2k' }, + { id: 'SWfdBhglX0fk', type: 'HIDESECTION' }, + { id: 'w75KJ2mc4zz', type: 'ASSIGN', value: 'true' }, + { id: 'wasdJ2mc4zz', type: 'ASSIGN', value: 'true' }, + { + id: 'w75KJ2mc4zz', + message: ' true', + type: 'ERRORONCOMPLETE', + }, + { + id: 'w75KJ2mc4zz', + message: ' true', + type: 'WARNINGONCOMPLETE', + }, + { + id: 'w75KJ2mc4zz', + type: 'SETMANDATORYFIELD', + }, + { + content: undefined, + id: 'zDhUuAYrxNC', + targetDataType: 'trackedEntityAttribute', + type: 'HIDEFIELD', + hadValue: true, + name: undefined, + }, + { + content: undefined, + id: 'unknown', + type: 'HIDEFIELD', + }, + { + displayKeyValuePair: { + id: 'khy8GmlwpgZ', + key: "d2:weeksBetween('2020-01-28', V{unknown} ) = ", + value: '', + }, + id: 'feedback', + type: 'DISPLAYKEYVALUEPAIR', + }, + ]; + + const foundation = new RenderFoundation(() => {}); + const section1 = new Section((initSection) => { + initSection.id = 's1Id'; + initSection.name = 'section1'; + const dataElement1 = new DataElement((o) => { + o.id = 'w75KJ2mc4zz'; + o.name = 'dataElement1'; + o.type = dataElementTypes.TEXT; + o.optionSet = { + id: 'optionSet', + name: 'optionSet', + code: 'optionSet', + options: [{ option: { value: false } }], + }; + }); + + const dataElement2 = new DataElement((o) => { + o.id = 'wasdJ2mc4zz'; + o.name = 'dataElement1'; + o.type = dataElementTypes.NUMBER; + o.compulsory = true; + }); + initSection.addElement(dataElement1); + initSection.addElement(dataElement2); + }); + + const section2 = new Section((initSection) => { + initSection.id = 'SWfdBhglX0fk'; + initSection.name = 'section2'; + const dataElement = new DataElement((o) => { + o.id = 'da1Id'; + o.name = 'dataElement1'; + o.type = dataElementTypes.TEXT; + }); + + initSection.addElement(dataElement); + }); + + foundation.addSection(section1); + foundation.addSection(section2); + + // when + const processedRulesEffects = postProcessRulesEffects(rulesEffects, foundation); + + // then + expect(processedRulesEffects).toEqual([ + { + displayText: { + id: 'Eeb7Ixr4Pv6', + message: 'd2:floor((5+5) / 2) = 5', + }, + id: 'feedback', + type: 'DISPLAYTEXT', + }, + { + id: 'PUZaKR0Jh2k', + type: 'HIDEPROGRAMSTAGE', + }, + { + id: 'w75KJ2mc4zz', + message: ' true', + type: 'ERRORONCOMPLETE', + }, + { + id: 'w75KJ2mc4zz', + message: ' true', + type: 'WARNINGONCOMPLETE', + }, + { + id: 'w75KJ2mc4zz', + type: 'SETMANDATORYFIELD', + }, + { + displayKeyValuePair: { + id: 'khy8GmlwpgZ', + key: "d2:weeksBetween('2020-01-28', V{unknown} ) = ", + value: '', + }, + id: 'feedback', + type: 'DISPLAYKEYVALUEPAIR', + }, + { + content: undefined, + id: 'unknown', + type: 'HIDEFIELD', + }, + { + id: 'da1Id', + type: 'HIDEFIELD', + }, + { + id: 'unknown', + type: 'ASSIGN', + value: null, + }, + { + id: 'w75KJ2mc4zz', + type: 'ASSIGN', + value: null, + }, + { + id: 'wasdJ2mc4zz', + type: 'ASSIGN', + value: 'true', + }, + ]); +}); + +test('the rules effects are not defined', () => { + // given + + const foundation = new RenderFoundation(() => {}); + const section1 = new Section((initSection) => { + initSection.id = 's1Id'; + initSection.name = 'section1'; + const dataElement1 = new DataElement((o) => { + o.id = 'da1Id'; + o.name = 'dataElement1'; + o.type = dataElementTypes.TEXT; + }); + + initSection.addElement(dataElement1); + }); + + foundation.addSection(section1); + + // when + const processedRulesEffects = postProcessRulesEffects(undefined, foundation); + + // then + expect(processedRulesEffects).toEqual([]); +}); + +test('HIDESECTION effect sectionId do not match the formFoundation sectionId', () => { + // given + const rulesEffects = [{ id: 'SWfdBhglX0fk', type: 'HIDESECTION' }]; + + const foundation = new RenderFoundation(() => {}); + const section1 = new Section((initSection) => { + initSection.id = 's1Id'; + initSection.name = 'section1'; + const dataElement1 = new DataElement((o) => { + o.id = 'da1Id'; + o.name = 'dataElement1'; + o.type = dataElementTypes.TEXT; + }); + + initSection.addElement(dataElement1); + }); + + foundation.addSection(section1); + + // when + const processedRulesEffects = postProcessRulesEffects(rulesEffects, foundation); + + // then + expect(processedRulesEffects).toEqual([]); +}); diff --git a/src/core_modules/capture-core/rules/__tests__/ruleEffectsForEventProgram.test.js b/src/core_modules/capture-core/rules/__tests__/ruleEffectsForEventProgram.test.js index 8fd6054d3c..215b2a8ea0 100644 --- a/src/core_modules/capture-core/rules/__tests__/ruleEffectsForEventProgram.test.js +++ b/src/core_modules/capture-core/rules/__tests__/ruleEffectsForEventProgram.test.js @@ -1,19 +1,95 @@ -import { rulesEngineEffectTargetDataTypes } from '@dhis2/rules-engine-javascript'; +import { rulesEngineEffectTargetDataTypes, variableSourceTypes } from '@dhis2/rules-engine-javascript'; import { rulesEngine } from '../rulesEngine'; +import { systemSettingsStore } from '../../metaDataMemoryStores'; describe('Event Event rules engine', () => { // these variables are shared between each test - const constants = [{ id: 'Gfd3ppDfq8E', displayName: 'Commodity ordering overhead', value: 5 }, { id: 'bCqvfPR02Im', displayName: 'Pi', value: 3.14 }]; - const dataElementsInProgram = { sWoqcoByYmD: { id: 'sWoqcoByYmD', valueType: 'BOOLEAN' }, Ok9OQpitjQr: { id: 'Ok9OQpitjQr', valueType: 'BOOLEAN' }, vANAXwtLwcT: { id: 'vANAXwtLwcT', valueType: 'NUMBER' } }; - const programRules = [{ id: 'GC4gpdoSD4r', condition: '#{hemoglobin} < 9', description: 'Show warning if hemoglobin is dangerously low', displayName: 'Hemoglobin warning', programId: 'lxAQ7Zs9VYR', programRuleActions: [{ id: 'suS9GnraCx1', content: 'Hemoglobin value lower than normal', displayContent: 'Hemoglobin value lower than normal', dataElementId: 'vANAXwtLwcT', programRuleActionType: 'SHOWWARNING' }] }, { id: 'dahuKlP7jR2', condition: '#{hemoglobin} > 99', description: 'Show error for hemoglobin value higher than 99', displayName: 'Show error for high hemoglobin value', programId: 'lxAQ7Zs9VYR', programRuleActions: [{ id: 'UUwZWS8uirn', content: 'The hemoglobin value cannot be above 99', displayContent: 'The hemoglobin value cannot be above 99', dataElementId: 'vANAXwtLwcT', programRuleActionType: 'SHOWERROR' }] }, { id: 'xOe5qCzRS0Y', condition: '!#{womanSmoking} ', description: 'Hide smoking cessation councelling dataelement unless patient is smoking', displayName: 'Hide smoking cessation councelling', programId: 'lxAQ7Zs9VYR', programRuleActions: [{ id: 'hwgyO59SSxu', dataElementId: 'Ok9OQpitjQr', programRuleActionType: 'HIDEFIELD' }] }]; - const programRuleVariables = [{ id: 'Z92dJO9gIje', dataElementId: 'sWoqcoByYmD', displayName: 'womanSmoking', programId: 'lxAQ7Zs9VYR', programRuleVariableSourceType: 'DATAELEMENT_NEWEST_EVENT_PROGRAM', useNameForOptionSet: true }, { id: 'omrL0gtPpDL', dataElementId: 'vANAXwtLwcT', displayName: 'hemoglobin', programId: 'lxAQ7Zs9VYR', programRuleVariableSourceType: 'DATAELEMENT_NEWEST_EVENT_PROGRAM', useNameForOptionSet: true }]; + const constants = [ + { id: 'Gfd3ppDfq8E', displayName: 'Commodity ordering overhead', value: 5 }, + { id: 'bCqvfPR02Im', displayName: 'Pi', value: 3.14 }, + ]; + const dataElementsInProgram = { + sWoqcoByYmD: { id: 'sWoqcoByYmD', valueType: 'BOOLEAN' }, + Ok9OQpitjQr: { id: 'Ok9OQpitjQr', valueType: 'BOOLEAN' }, + vANAXwtLwcT: { id: 'vANAXwtLwcT', valueType: 'NUMBER' }, + }; + const programRules = [ + { + id: 'GC4gpdoSD4r', + condition: '#{hemoglobin} < 9', + description: 'Show warning if hemoglobin is dangerously low', + displayName: 'Hemoglobin warning', + programId: 'lxAQ7Zs9VYR', + programRuleActions: [ + { + id: 'suS9GnraCx1', + content: 'Hemoglobin value lower than normal', + displayContent: 'Hemoglobin value lower than normal', + dataElementId: 'vANAXwtLwcT', + programRuleActionType: 'SHOWWARNING', + }, + ], + }, + { + id: 'dahuKlP7jR2', + condition: '#{hemoglobin} > 99', + description: 'Show error for hemoglobin value higher than 99', + displayName: 'Show error for high hemoglobin value', + programId: 'lxAQ7Zs9VYR', + programRuleActions: [ + { + id: 'UUwZWS8uirn', + content: 'The hemoglobin value cannot be above 99', + displayContent: 'The hemoglobin value cannot be above 99', + dataElementId: 'vANAXwtLwcT', + programRuleActionType: 'SHOWERROR', + }, + ], + }, + { + id: 'xOe5qCzRS0Y', + condition: '!#{womanSmoking} ', + description: 'Hide smoking cessation councelling dataelement unless patient is smoking', + displayName: 'Hide smoking cessation councelling', + programId: 'lxAQ7Zs9VYR', + programRuleActions: [ + { id: 'hwgyO59SSxu', dataElementId: 'Ok9OQpitjQr', programRuleActionType: 'HIDEFIELD' }, + ], + }, + ]; + const programRuleVariables = [ + { + id: 'Z92dJO9gIje', + dataElementId: 'sWoqcoByYmD', + displayName: 'womanSmoking', + programId: 'lxAQ7Zs9VYR', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, + useNameForOptionSet: true, + }, + { + id: 'omrL0gtPpDL', + dataElementId: 'vANAXwtLwcT', + displayName: 'hemoglobin', + programId: 'lxAQ7Zs9VYR', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, + useNameForOptionSet: true, + }, + ]; const orgUnit = { id: 'DiszpKrYNg8', name: 'Ngelehun CHC' }; const optionSets = {}; describe.each([ [ { vANAXwtLwcT: 0 }, - [{ id: 'vANAXwtLwcT', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, message: 'Hemoglobin value lower than normal ', type: 'SHOWWARNING' }, { id: 'Ok9OQpitjQr', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, type: 'HIDEFIELD' }], + [ + { + id: 'vANAXwtLwcT', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + message: 'Hemoglobin value lower than normal ', + type: 'SHOWWARNING', + }, + { id: 'Ok9OQpitjQr', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, type: 'HIDEFIELD' }, + ], ], [ { vANAXwtLwcT: 9 }, @@ -25,7 +101,15 @@ describe('Event Event rules engine', () => { ], [ { vANAXwtLwcT: 100 }, - [{ id: 'vANAXwtLwcT', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, message: 'The hemoglobin value cannot be above 99 ', type: 'SHOWERROR' }, { id: 'Ok9OQpitjQr', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, type: 'HIDEFIELD' }], + [ + { + id: 'vANAXwtLwcT', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + message: 'The hemoglobin value cannot be above 99 ', + type: 'SHOWERROR', + }, + { id: 'Ok9OQpitjQr', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, type: 'HIDEFIELD' }, + ], ], ])('where value needs to >= 9 and <= 99', (currentEvent, expected) => { test(`and given value(s): ${JSON.stringify(currentEvent)}`, () => { @@ -44,11 +128,26 @@ describe('Event Event rules engine', () => { describe.each([ [ { sWoqcoByYmD: true }, - [{ id: 'vANAXwtLwcT', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, message: 'Hemoglobin value lower than normal ', type: 'SHOWWARNING' }], + [ + { + id: 'vANAXwtLwcT', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + message: 'Hemoglobin value lower than normal ', + type: 'SHOWWARNING', + }, + ], ], [ { sWoqcoByYmD: false }, - [{ id: 'vANAXwtLwcT', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, message: 'Hemoglobin value lower than normal ', type: 'SHOWWARNING' }, { id: 'Ok9OQpitjQr', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, type: 'HIDEFIELD' }], + [ + { + id: 'vANAXwtLwcT', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + message: 'Hemoglobin value lower than normal ', + type: 'SHOWWARNING', + }, + { id: 'Ok9OQpitjQr', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, type: 'HIDEFIELD' }, + ], ], ])('where field is hidden regarding a boolean value', (currentEvent, expected) => { test(`and given value(s): ${JSON.stringify(currentEvent)}`, () => { @@ -67,25 +166,138 @@ describe('Event Event rules engine', () => { describe('Event rules engine', () => { // these variables are shared between each test - const constants = [{ id: 'Gfd3ppDfq8E', displayName: 'Commodity ordering overhead', value: 5 }, { id: 'bCqvfPR02Im', displayName: 'Pi', value: 3.14 }]; - const dataElementsInProgram = { oZg33kd9taw: { id: 'oZg33kd9taw', valueType: 'TEXT', optionSetId: 'pC3N9N77UmT' }, SWfdB5lX0fk: { id: 'SWfdB5lX0fk', valueType: 'BOOLEAN', optionSetId: undefined }, qrur9Dvnyt5: { id: 'qrur9Dvnyt5', valueType: 'INTEGER', optionSetId: undefined }, GieVkTxp4HH: { id: 'GieVkTxp4HH', valueType: 'NUMBER', optionSetId: undefined }, vV9UWAZohSf: { id: 'vV9UWAZohSf', valueType: 'INTEGER_POSITIVE', optionSetId: undefined }, eMyVanycQSC: { id: 'eMyVanycQSC', valueType: 'DATE', optionSetId: undefined }, K6uUAvq500H: { id: 'K6uUAvq500H', valueType: 'TEXT', optionSetId: 'eUZ79clX7y1' }, msodh3rEMJa: { id: 'msodh3rEMJa', valueType: 'DATE', optionSetId: undefined }, S33cRBsnXPo: { id: 'S33cRBsnXPo', valueType: 'ORGANISATION_UNIT', optionSetId: undefined }, fWIAEtYVEGk: { id: 'fWIAEtYVEGk', valueType: 'TEXT', optionSetId: 'iDFPKpFTiVw' }, ulD2zW0TIy2: { id: 'ulD2zW0TIy2', valueType: 'FILE_RESOURCE' } }; - const programRules = [{ id: 'fd3wL1quxGb', condition: "#{gender} == 'Male'", description: 'Hide pregnant if gender is male', displayName: 'Hide pregnant if gender is male', programId: 'eBAyeGv0exc', programRuleActions: [{ id: 'IrmpncBsypT', dataElementId: 'SWfdB5lX0fk', programRuleActionType: 'HIDEFIELD', programStageSectionId: 'd7ZILSbPgYh' }] }, { id: 'x7PaHGvgWY2', condition: 'true', description: 'Body Mass Index. Weight in kg / height in m square.', displayName: 'BMI', programId: 'eBAyeGv0exc', programRuleActions: [{ id: 'x7PaHGvgWY2', content: 'BMI', displayContent: 'BMI', data: '#{Zj7UnCAulEk.vV9UWAZohSf}/((#{Zj7UnCAulEk.GieVkTxp4HH}/100)*(#{Zj7UnCAulEk.GieVkTxp4HH}/100))', programRuleActionType: 'DISPLAYKEYVALUEPAIR', location: 'indicators' }] }]; - const programRuleVariables = [{ id: 'RycV5uDi66i', dataElementId: 'qrur9Dvnyt5', displayName: 'age', programId: 'eBAyeGv0exc', programRuleVariableSourceType: 'DATAELEMENT_NEWEST_EVENT_PROGRAM', useNameForOptionSet: true }, { id: 'zINGRka3g9N', dataElementId: 'oZg33kd9taw', displayName: 'gender', programId: 'eBAyeGv0exc', programRuleVariableSourceType: 'DATAELEMENT_NEWEST_EVENT_PROGRAM', useNameForOptionSet: true }, { id: 'Zj7UnCAulEk.vV9UWAZohSf', displayName: 'Zj7UnCAulEk.vV9UWAZohSf', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', dataElementId: 'vV9UWAZohSf', programId: 'eBAyeGv0exc' }, { id: 'Zj7UnCAulEk.GieVkTxp4HH', displayName: 'Zj7UnCAulEk.GieVkTxp4HH', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', dataElementId: 'GieVkTxp4HH', programId: 'eBAyeGv0exc' }, { id: 'Zj7UnCAulEk.GieVkTxp4HH', displayName: 'Zj7UnCAulEk.GieVkTxp4HH', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', dataElementId: 'GieVkTxp4HH', programId: 'eBAyeGv0exc' }]; + const constants = [ + { id: 'Gfd3ppDfq8E', displayName: 'Commodity ordering overhead', value: 5 }, + { id: 'bCqvfPR02Im', displayName: 'Pi', value: 3.14 }, + ]; + const dataElementsInProgram = { + oZg33kd9taw: { id: 'oZg33kd9taw', valueType: 'TEXT', optionSetId: 'pC3N9N77UmT' }, + SWfdB5lX0fk: { id: 'SWfdB5lX0fk', valueType: 'TRUE_ONLY', optionSetId: undefined }, + qrur9Dvnyt5: { id: 'qrur9Dvnyt5', valueType: 'INTEGER', optionSetId: undefined }, + GieVkTxp4HH: { id: 'GieVkTxp4HH', valueType: 'NUMBER', optionSetId: undefined }, + vV9UWAZohSf: { id: 'vV9UWAZohSf', valueType: 'INTEGER_POSITIVE', optionSetId: undefined }, + eMyVanycQSC: { id: 'eMyVanycQSC', valueType: 'DATE', optionSetId: undefined }, + K6uUAvq500H: { id: 'K6uUAvq500H', valueType: 'TEXT', optionSetId: 'eUZ79clX7y1' }, + msodh3rEMJa: { id: 'msodh3rEMJa', valueType: 'DATE', optionSetId: undefined }, + S33cRBsnXPo: { id: 'S33cRBsnXPo', valueType: 'ORGANISATION_UNIT', optionSetId: undefined }, + fWIAEtYVEGk: { id: 'fWIAEtYVEGk', valueType: 'TEXT', optionSetId: 'iDFPKpFTiVw' }, + ulD2zW0TIy2: { id: 'ulD2zW0TIy2', valueType: 'FILE_RESOURCE' }, + }; + const programRules = [ + { + id: 'fd3wL1quxGb', + condition: "#{gender} == 'Male'", + description: 'Hide pregnant if gender is male', + displayName: 'Hide pregnant if gender is male', + programId: 'eBAyeGv0exc', + programRuleActions: [ + { + id: 'IrmpncBsypT', + dataElementId: 'SWfdB5lX0fk', + programRuleActionType: 'HIDEFIELD', + programStageSectionId: 'd7ZILSbPgYh', + }, + ], + }, + { + id: 'x7PaHGvgWY2', + condition: 'true', + description: 'Body Mass Index. Weight in kg / height in m square.', + displayName: 'BMI', + programId: 'eBAyeGv0exc', + programRuleActions: [ + { + id: 'x7PaHGvgWY2', + content: 'BMI', + displayContent: 'BMI', + data: '#{Zj7UnCAulEk.vV9UWAZohSf}/((#{Zj7UnCAulEk.GieVkTxp4HH}/100)*(#{Zj7UnCAulEk.GieVkTxp4HH}/100))', + programRuleActionType: 'DISPLAYKEYVALUEPAIR', + location: 'indicators', + }, + ], + }, + ]; + const programRuleVariables = [ + { + id: 'RycV5uDi66i', + dataElementId: 'qrur9Dvnyt5', + displayName: 'age', + programId: 'eBAyeGv0exc', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, + useNameForOptionSet: true, + }, + { + id: 'zINGRka3g9N', + dataElementId: 'oZg33kd9taw', + displayName: 'gender', + programId: 'eBAyeGv0exc', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, + useNameForOptionSet: true, + }, + { + id: 'Zj7UnCAulEk.vV9UWAZohSf', + displayName: 'Zj7UnCAulEk.vV9UWAZohSf', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + dataElementId: 'vV9UWAZohSf', + programId: 'eBAyeGv0exc', + }, + { + id: 'Zj7UnCAulEk.GieVkTxp4HH', + displayName: 'Zj7UnCAulEk.GieVkTxp4HH', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + dataElementId: 'GieVkTxp4HH', + programId: 'eBAyeGv0exc', + }, + { + id: 'Zj7UnCAulEk.GieVkTxp4HH', + displayName: 'Zj7UnCAulEk.GieVkTxp4HH', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + dataElementId: 'GieVkTxp4HH', + programId: 'eBAyeGv0exc', + }, + ]; const orgUnit = { id: 'DiszpKrYNg8', name: 'Ngelehun CHC' }; - const optionSets = { pC3N9N77UmT: { id: 'pC3N9N77UmT', displayName: 'Gender', version: 0, valueType: 'TEXT', options: [{ id: 'rBvjJYbMCVx', displayName: 'Male', code: 'Male', translations: [] }, { id: 'Mnp3oXrpAbK', displayName: 'Female', code: 'Female', translations: [] }] } }; + const optionSets = { + pC3N9N77UmT: { + id: 'pC3N9N77UmT', + displayName: 'Gender', + version: 0, + valueType: 'TEXT', + options: undefined, + }, + }; describe.each([ [ { oZg33kd9taw: 'Female', SWfdB5lX0fk: null }, - [{ displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, id: 'indicators', type: 'DISPLAYKEYVALUEPAIR' }], + [ + { + displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, + id: 'indicators', + type: 'DISPLAYKEYVALUEPAIR', + }, + ], ], [ { oZg33kd9taw: 'Male', SWfdB5lX0fk: null }, - [{ id: 'SWfdB5lX0fk', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, type: 'HIDEFIELD' }, { displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, id: 'indicators', type: 'DISPLAYKEYVALUEPAIR' }], + [ + { id: 'SWfdB5lX0fk', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, type: 'HIDEFIELD' }, + { + displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, + id: 'indicators', + type: 'DISPLAYKEYVALUEPAIR', + }, + ], ], [ { oZg33kd9taw: null, SWfdB5lX0fk: null }, - [{ displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, id: 'indicators', type: 'DISPLAYKEYVALUEPAIR' }], + [ + { + displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, + id: 'indicators', + type: 'DISPLAYKEYVALUEPAIR', + }, + ], ], ])('where field is hidden regarding the gender of the event', (currentEvent, expected) => { test(`and given value(s): ${JSON.stringify(currentEvent)}`, () => { @@ -104,35 +316,83 @@ describe('Event rules engine', () => { describe.each([ [ { qrur9Dvnyt5: null, GieVkTxp4HH: null, vV9UWAZohSf: null }, - [{ displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, id: 'indicators', type: 'DISPLAYKEYVALUEPAIR' }], + [ + { + displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, + id: 'indicators', + type: 'DISPLAYKEYVALUEPAIR', + }, + ], ], [ { qrur9Dvnyt5: null, GieVkTxp4HH: null, vV9UWAZohSf: 85 }, - [{ displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, id: 'indicators', type: 'DISPLAYKEYVALUEPAIR' }], + [ + { + displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, + id: 'indicators', + type: 'DISPLAYKEYVALUEPAIR', + }, + ], ], [ { qrur9Dvnyt5: null, GieVkTxp4HH: 180, vV9UWAZohSf: null }, - [{ displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '0' }, id: 'indicators', type: 'DISPLAYKEYVALUEPAIR' }], + [ + { + displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '0' }, + id: 'indicators', + type: 'DISPLAYKEYVALUEPAIR', + }, + ], ], [ { qrur9Dvnyt5: null, GieVkTxp4HH: 180, vV9UWAZohSf: 85 }, - [{ displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '26.234567901234566' }, id: 'indicators', type: 'DISPLAYKEYVALUEPAIR' }], + [ + { + displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '26.234567901234566' }, + id: 'indicators', + type: 'DISPLAYKEYVALUEPAIR', + }, + ], ], [ { qrur9Dvnyt5: 40, GieVkTxp4HH: null, vV9UWAZohSf: null }, - [{ displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, id: 'indicators', type: 'DISPLAYKEYVALUEPAIR' }], + [ + { + displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, + id: 'indicators', + type: 'DISPLAYKEYVALUEPAIR', + }, + ], ], [ { qrur9Dvnyt5: 40, GieVkTxp4HH: null, vV9UWAZohSf: 85 }, - [{ displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, id: 'indicators', type: 'DISPLAYKEYVALUEPAIR' }], + [ + { + displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '' }, + id: 'indicators', + type: 'DISPLAYKEYVALUEPAIR', + }, + ], ], [ { qrur9Dvnyt5: 40, GieVkTxp4HH: 180, vV9UWAZohSf: null }, - [{ displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '0' }, id: 'indicators', type: 'DISPLAYKEYVALUEPAIR' }], + [ + { + displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '0' }, + id: 'indicators', + type: 'DISPLAYKEYVALUEPAIR', + }, + ], ], [ { qrur9Dvnyt5: 40, GieVkTxp4HH: 180, vV9UWAZohSf: 85 }, - [{ displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '26.234567901234566' }, id: 'indicators', type: 'DISPLAYKEYVALUEPAIR' }], + [ + { + displayKeyValuePair: { id: 'x7PaHGvgWY2', key: 'BMI', value: '26.234567901234566' }, + id: 'indicators', + type: 'DISPLAYKEYVALUEPAIR', + }, + ], ], ])('where BMI is calculated', (currentEvent, expected) => { test(`and given value(s): ${JSON.stringify(currentEvent)}`, () => { @@ -151,14 +411,503 @@ describe('Event rules engine', () => { describe('Event rules engine', () => { // these variables are shared between each test - const constants = [{ id: 'Gfd3ppDfq8E', displayName: 'Commodity ordering overhead', value: 5 }, { id: 'bCqvfPR02Im', displayName: 'Pi', value: 3.14 }]; - const dataElementsInProgram = { dyfYIsTFTjG: { id: 'dyfYIsTFTjG', valueType: 'TEXT' }, XOaXLWuhKzV: { id: 'XOaXLWuhKzV', valueType: 'TEXT', optionSetId: 'WDUwjiW2rGH' }, AtFlciXnstG: { id: 'AtFlciXnstG', valueType: 'INTEGER_ZERO_OR_POSITIVE' }, JGnHr6WI3AY: { id: 'JGnHr6WI3AY', valueType: 'TEXT', optionSetId: 'L6eMZDJkCwX' }, s3eoonJ8OJb: { id: 's3eoonJ8OJb', valueType: 'DATE' }, gktroFPckdr: { id: 'gktroFPckdr', valueType: 'TEXT', optionSetId: 'UYDsNdpo2BU' }, QQLXTXVidW2: { id: 'QQLXTXVidW2', valueType: 'TEXT', optionSetId: 'L6eMZDJkCwX' }, ovY6E8BSdto: { id: 'ovY6E8BSdto', valueType: 'TEXT', optionSetId: 'dsgBmIZ0Yrq' }, Z5z8vFQy0w0: { id: 'Z5z8vFQy0w0', valueType: 'TEXT' }, TzqawmlPkI5: { id: 'TzqawmlPkI5', valueType: 'TEXT', optionSetId: 'L6eMZDJkCwX' }, f8j4XDEozvj: { id: 'f8j4XDEozvj', valueType: 'TEXT', optionSetId: 'xD9QOIvNAjw' }, jBBkFuPKctq: { id: 'jBBkFuPKctq', valueType: 'TEXT', optionSetId: 'T9zjyaIkRqH' }, A4Fg6jgWauf: { id: 'A4Fg6jgWauf', valueType: 'TEXT', optionSetId: 'w1vUkxq8IOl' }, CUbZcLm9LyN: { id: 'CUbZcLm9LyN', valueType: 'TEXT', optionSetId: 'L6eMZDJkCwX' }, p8htbyJHydl: { id: 'p8htbyJHydl', valueType: 'TEXT', optionSetId: 'L6eMZDJkCwX' }, SbXES4EPgqP: { id: 'SbXES4EPgqP', valueType: 'NUMBER' }, bOYWVEBaWy6: { id: 'bOYWVEBaWy6', valueType: 'TEXT', optionSetId: 'qI4cs9ocBwn' }, PFXeJV8d7ja: { id: 'PFXeJV8d7ja', valueType: 'DATE' } }; - const programRules = [{ id: 'DOz4wl8ErDD', condition: 'true', description: 'Hide Irrelevant Test Result Options', displayName: 'Hide Test Result Options', programId: 'PNClHaZARtz', programRuleActions: [{ id: 'XuM1JizlcF1', dataElementId: 'ovY6E8BSdto', programRuleActionType: 'HIDEOPTION', optionId: 'MkeWrqeqZXL' }, { id: 'FRfTFXSwKDU', dataElementId: 'ovY6E8BSdto', programRuleActionType: 'HIDEOPTION', optionId: 'fPV0gQ8ds6D' }] }, { id: 'DtfaG1TgyZk', condition: "(d2:hasValue( #{LAB_TEST} ) && #{LAB_TEST} == 'No') ||\n(d2:hasValue( #{LAB_TEST} ) && #{LAB_TEST} == 'Yes' && #{TEST_RESULT} == 'Inconclusive')", description: "Automation: Assign 'Probable Case' to Case Classification", displayName: "Assign 'Probable Case' to Case Classification", programId: 'PNClHaZARtz', programRuleActions: [{ id: 'NPvy6sF6axT', data: "'Probable Case'", dataElementId: 'Z5z8vFQy0w0', programRuleActionType: 'ASSIGN' }], priority: 4 }, { id: 'E9ghdhg6ABQ', condition: "#{SYMPTOMS} != 'Yes'", description: 'Hide Onset of Symptoms Date if no symptoms', displayName: 'Hide Onset of Symptoms Date', programId: 'PNClHaZARtz', programRuleActions: [{ id: 'VcnnsBPtzlW', dataElementId: 's3eoonJ8OJb', programRuleActionType: 'HIDEFIELD' }] }, { id: 'FnSVDp8v0H9', condition: 'true', description: 'Hide Irrelevant Unknown Options', displayName: 'Hide Unknown Options', programId: 'PNClHaZARtz', programRuleActions: [{ id: 'UqDEcMuF5DF', dataElementId: 'JGnHr6WI3AY', programRuleActionType: 'HIDEOPTION', optionId: 'pqxvAQU1z9W' }, { id: 'GrFjkYTT07o', dataElementId: 'p8htbyJHydl', programRuleActionType: 'HIDEOPTION', optionId: 'pqxvAQU1z9W' }, { id: 'HlyTQaTz00f', dataElementId: 'CUbZcLm9LyN', programRuleActionType: 'HIDEOPTION', optionId: 'pqxvAQU1z9W' }] }, { id: 'L8bP6GifQXL', condition: "!d2:hasValue( #{INFECTION_SOURCE} ) || #{INFECTION_SOURCE} == 'IMPORTED_CASE' || #{INFECTION_SOURCE} == 'EXPOSURE_UNKNOWN'", description: 'Hide Case Type for Imported Cases', displayName: 'Hide Case Type', programId: 'PNClHaZARtz', programRuleActions: [{ id: 'k05Owr8pwIn', dataElementId: 'A4Fg6jgWauf', programRuleActionType: 'HIDEFIELD' }] }, { id: 'MLS5vZLguQM', condition: "#{INFECTION_SOURCE} != 'LOCAL_TRANSMISSION'", description: "Hide 'Specify Local Infection Source' unless Local Transmission is selected", displayName: "Hide 'Specify Local Infection Source'", programId: 'PNClHaZARtz', programRuleActions: [{ id: 'ho7xRPUB0Gl', dataElementId: 'jBBkFuPKctq', programRuleActionType: 'HIDEFIELD' }] }, { id: 'NXWk8sq70OV', condition: "#{TRAVEL_HISTORY} == 'No'", description: "Hide 'Imported Case' if not traveled", displayName: "Hide 'Imported Case'", programId: 'PNClHaZARtz', programRuleActions: [{ id: 'fJIgmDK53Vp', dataElementId: 'f8j4XDEozvj', programRuleActionType: 'HIDEOPTION', optionId: 'PMGTqmVIF4T' }] }, { id: 'NZaVqr7dPfQ', condition: '!d2:hasValue( #{ONSET_DATE} ) && !d2:hasValue(V{event_date})', description: 'Automation: Assign Empty date if no Onset date and no event date is available', displayName: 'Assign Empty Date', programId: 'PNClHaZARtz', programRuleActions: [{ id: 'q060xuOwQx3', data: "''", dataElementId: 'PFXeJV8d7ja', programRuleActionType: 'ASSIGN' }], priority: 3 }, { id: 'QrJx9LI9KRo', condition: "d2:hasValue( #{LAB_TEST} ) && #{LAB_TEST} == 'Yes' && !d2:hasValue( #{TEST_RESULT} )", description: 'Automation: Assign Empty Value to Class Classification', displayName: 'Assign Empty Value to Class Classification', programId: 'PNClHaZARtz', programRuleActions: [{ id: 'rFaZAbOgMSz', data: "''", dataElementId: 'Z5z8vFQy0w0', programRuleActionType: 'ASSIGN' }], priority: 2 }, { id: 'R6oEX1xlQma', condition: 'true', description: 'Hide irrelevant Outcome Options', displayName: 'Hide Outcome Options', programId: 'PNClHaZARtz', programRuleActions: [{ id: 'Ov7qHXf0Q2s', dataElementId: 'bOYWVEBaWy6', programRuleActionType: 'HIDEOPTION', optionId: 'dUeRcF2cApV' }, { id: 'V95rgvUlqY0', dataElementId: 'bOYWVEBaWy6', programRuleActionType: 'HIDEOPTION', optionId: 'bYt4why1tL3' }, { id: 'eZUUOjykbLv', dataElementId: 'bOYWVEBaWy6', programRuleActionType: 'HIDEOPTION', optionId: 'xBoo6HyaYcd' }, { id: 'Zcs7rz5VEF7', dataElementId: 'bOYWVEBaWy6', programRuleActionType: 'HIDEOPTION', optionId: 'RCT079wdeKT' }] }, { id: 'dZsTiQEUg5L', condition: '!d2:hasValue( #{ONSET_DATE} ) && d2:hasValue(V{event_date})', description: 'Automation: Assign Event date if no Onset date is available', displayName: 'Assign Event Date', programId: 'PNClHaZARtz', programRuleActions: [{ id: 'sQKFBORp5P1', data: 'V{event_date}', dataElementId: 'PFXeJV8d7ja', programRuleActionType: 'ASSIGN' }], priority: 2 }, { id: 'kVBrxwODyTj', condition: '!d2:hasValue( #{LAB_TEST} )', description: 'Hide Case Classification Field until Lab Test question is answered', displayName: 'Hide Case Classification Field', programId: 'PNClHaZARtz', programRuleActions: [{ id: 'ZT8AexxBPl0', dataElementId: 'Z5z8vFQy0w0', programRuleActionType: 'HIDEFIELD' }] }, { id: 'q2QbEfeDlI9', condition: "!d2:hasValue( #{HOSPITALISED} ) || #{HOSPITALISED} == 'No'", description: 'Hide ICU field unless Hospitalised', displayName: 'Hide ICU field', programId: 'PNClHaZARtz', programRuleActions: [{ id: 'wwvxLCpuOCx', dataElementId: 'p8htbyJHydl', programRuleActionType: 'HIDEFIELD' }] }, { id: 'rZUpiMuJIKH', condition: "d2:hasValue( #{LAB_TEST} ) && #{LAB_TEST} == 'Yes' && #{TEST_RESULT} == 'Positive'", description: "Automation: Assign 'Laboratory Confirmed Case' to Case Classification", displayName: "Assign 'Laboratory Confirmed Case' to Case Classification", programId: 'PNClHaZARtz', programRuleActions: [{ id: 'hcamYSDn00P', data: "'Laboratory Confirmed Case'", dataElementId: 'Z5z8vFQy0w0', programRuleActionType: 'ASSIGN' }], priority: 3 }, { id: 'sEQsGGAQSJT', condition: "(d2:hasValue( #{LAB_TEST} ) && #{LAB_TEST} == 'Unknown') ||\n(d2:hasValue( #{LAB_TEST} ) && #{LAB_TEST} == 'Yes' && (#{TEST_RESULT} == 'Negative' || #{TEST_RESULT} == 'Unknown'))", description: "Automation: Assign Suspected Case' to Case Classification", displayName: "Assign 'Suspected Case' to Case Classification", programId: 'PNClHaZARtz', programRuleActions: [{ id: 'zxb2XDboGAF', data: "'Suspected Case'", dataElementId: 'Z5z8vFQy0w0', programRuleActionType: 'ASSIGN' }], priority: 1 }, { id: 'sKCZMuWwOKA', condition: 'd2:hasValue( #{ONSET_DATE} )', description: 'Automation: Assign Symptoms Onset Date if available', displayName: 'Assign Onset Date', programId: 'PNClHaZARtz', programRuleActions: [{ id: 'lJOYxhjupxz', data: '#{ONSET_DATE}', dataElementId: 'PFXeJV8d7ja', programRuleActionType: 'ASSIGN' }], priority: 1 }, { id: 'vj5GWKIrhKh', condition: "#{LAB_TEST} != 'Yes'", description: 'Hide Test Result Field until Lab Test question is answered with yes', displayName: 'Hide Test Result Field', programId: 'PNClHaZARtz', programRuleActions: [{ id: 'VxxxIX2598r', dataElementId: 'ovY6E8BSdto', programRuleActionType: 'HIDEFIELD' }] }]; - const programRuleVariables = [{ id: 'DoRHHfNPccb', dataElementId: 'f8j4XDEozvj', displayName: 'INFECTION_SOURCE', programId: 'PNClHaZARtz', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', useNameForOptionSet: false }, { id: 'EnpvdmYrwLb', dataElementId: 'TzqawmlPkI5', displayName: 'TRAVEL_HISTORY', programId: 'PNClHaZARtz', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', useNameForOptionSet: true }, { id: 'JPIyrAmJapV', dataElementId: 'CUbZcLm9LyN', displayName: 'HOSPITALISED', programId: 'PNClHaZARtz', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', useNameForOptionSet: true }, { id: 'LAaPMTz69L7', displayName: 'CASE_CLASSIFICATION', programId: 'PNClHaZARtz', programRuleVariableSourceType: 'CALCULATED_VALUE', useNameForOptionSet: true, valueType: 'TEXT' }, { id: 'MpixycZvu0m', dataElementId: 'ovY6E8BSdto', displayName: 'TEST_RESULT', programId: 'PNClHaZARtz', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', useNameForOptionSet: true }, { id: 'XcPYCpTOPwB', dataElementId: 'QQLXTXVidW2', displayName: 'LAB_TEST', programId: 'PNClHaZARtz', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', useNameForOptionSet: true }, { id: 'cZSslcAEupI', dataElementId: 's3eoonJ8OJb', displayName: 'ONSET_DATE', programId: 'PNClHaZARtz', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', useNameForOptionSet: true }, { id: 'eSq3nc1t2F6', dataElementId: 'dyfYIsTFTjG', displayName: 'PATIENT_ID', programId: 'PNClHaZARtz', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', useNameForOptionSet: true }, { id: 'lY0yJGU1D4e', dataElementId: 'JGnHr6WI3AY', displayName: 'SYMPTOMS', programId: 'PNClHaZARtz', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', useNameForOptionSet: false }]; + const constants = [ + { id: 'Gfd3ppDfq8E', displayName: 'Commodity ordering overhead', value: 5 }, + { id: 'bCqvfPR02Im', displayName: 'Pi', value: 3.14 }, + ]; + const dataElementsInProgram = { + dyfYIsTFTjG: { id: 'dyfYIsTFTjG', valueType: 'TEXT' }, + XOaXLWuhKzV: { id: 'XOaXLWuhKzV', valueType: 'TEXT', optionSetId: 'WDUwjiW2rGH' }, + AtFlciXnstG: { id: 'AtFlciXnstG', valueType: 'INTEGER_ZERO_OR_POSITIVE' }, + JGnHr6WI3AY: { id: 'JGnHr6WI3AY', valueType: 'TEXT', optionSetId: 'L6eMZDJkCwX' }, + s3eoonJ8OJb: { id: 's3eoonJ8OJb', valueType: 'DATE' }, + gktroFPckdr: { id: 'gktroFPckdr', valueType: 'TEXT', optionSetId: 'UYDsNdpo2BU' }, + QQLXTXVidW2: { id: 'QQLXTXVidW2', valueType: 'TEXT', optionSetId: 'L6eMZDJkCwX' }, + ovY6E8BSdto: { id: 'ovY6E8BSdto', valueType: 'TEXT', optionSetId: 'dsgBmIZ0Yrq' }, + Z5z8vFQy0w0: { id: 'Z5z8vFQy0w0', valueType: 'TEXT' }, + TzqawmlPkI5: { id: 'TzqawmlPkI5', valueType: 'TEXT', optionSetId: 'L6eMZDJkCwX' }, + f8j4XDEozvj: { id: 'f8j4XDEozvj', valueType: 'TEXT', optionSetId: 'xD9QOIvNAjw' }, + jBBkFuPKctq: { id: 'jBBkFuPKctq', valueType: 'TEXT', optionSetId: 'T9zjyaIkRqH' }, + A4Fg6jgWauf: { id: 'A4Fg6jgWauf', valueType: 'TEXT', optionSetId: 'w1vUkxq8IOl' }, + CUbZcLm9LyN: { id: 'CUbZcLm9LyN', valueType: 'TEXT', optionSetId: 'L6eMZDJkCwX' }, + p8htbyJHydl: { id: 'p8htbyJHydl', valueType: 'TEXT', optionSetId: 'L6eMZDJkCwX' }, + SbXES4EPgqP: { id: 'SbXES4EPgqP', valueType: 'NUMBER' }, + bOYWVEBaWy6: { id: 'bOYWVEBaWy6', valueType: 'TEXT', optionSetId: 'qI4cs9ocBwn' }, + PFXeJV8d7ja: { id: 'PFXeJV8d7ja', valueType: 'DATE' }, + }; + const programRules = [ + { + id: 'DOz4wl8ErDD', + condition: 'true', + description: 'Hide Irrelevant Test Result Options', + displayName: 'Hide Test Result Options', + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'XuM1JizlcF1', + dataElementId: 'ovY6E8BSdto', + programRuleActionType: 'HIDEOPTION', + optionId: 'MkeWrqeqZXL', + }, + { + id: 'FRfTFXSwKDU', + dataElementId: 'ovY6E8BSdto', + programRuleActionType: 'HIDEOPTION', + optionId: 'fPV0gQ8ds6D', + }, + ], + }, + { + id: 'DtfaG1TgyZk', + condition: + "(d2:hasValue( #{LAB_TEST} ) && #{LAB_TEST} == 'No') ||\n(d2:hasValue( #{LAB_TEST} ) && #{LAB_TEST} == 'Yes' && #{TEST_RESULT} == 'Inconclusive')", + description: "Automation: Assign 'Probable Case' to Case Classification", + displayName: "Assign 'Probable Case' to Case Classification", + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'NPvy6sF6axT', + data: "'Probable Case'", + dataElementId: 'Z5z8vFQy0w0', + programRuleActionType: 'ASSIGN', + }, + ], + priority: 4, + }, + { + id: 'E9ghdhg6ABQ', + condition: "#{SYMPTOMS} != 'Yes'", + description: 'Hide Onset of Symptoms Date if no symptoms', + displayName: 'Hide Onset of Symptoms Date', + programId: 'PNClHaZARtz', + programRuleActions: [ + { id: 'VcnnsBPtzlW', dataElementId: 's3eoonJ8OJb', programRuleActionType: 'HIDEFIELD' }, + ], + }, + { + id: 'FnSVDp8v0H9', + condition: 'true', + description: 'Hide Irrelevant Unknown Options', + displayName: 'Hide Unknown Options', + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'UqDEcMuF5DF', + dataElementId: 'JGnHr6WI3AY', + programRuleActionType: 'HIDEOPTION', + optionId: 'pqxvAQU1z9W', + }, + { + id: 'GrFjkYTT07o', + dataElementId: 'p8htbyJHydl', + programRuleActionType: 'HIDEOPTION', + optionId: 'pqxvAQU1z9W', + }, + { + id: 'HlyTQaTz00f', + dataElementId: 'CUbZcLm9LyN', + programRuleActionType: 'HIDEOPTION', + optionId: 'pqxvAQU1z9W', + }, + ], + }, + { + id: 'L8bP6GifQXL', + condition: + "!d2:hasValue( #{INFECTION_SOURCE} ) || #{INFECTION_SOURCE} == 'IMPORTED_CASE' || #{INFECTION_SOURCE} == 'EXPOSURE_UNKNOWN'", + description: 'Hide Case Type for Imported Cases', + displayName: 'Hide Case Type', + programId: 'PNClHaZARtz', + programRuleActions: [ + { id: 'k05Owr8pwIn', dataElementId: 'A4Fg6jgWauf', programRuleActionType: 'HIDEFIELD' }, + ], + }, + { + id: 'MLS5vZLguQM', + condition: "#{INFECTION_SOURCE} != 'LOCAL_TRANSMISSION'", + description: "Hide 'Specify Local Infection Source' unless Local Transmission is selected", + displayName: "Hide 'Specify Local Infection Source'", + programId: 'PNClHaZARtz', + programRuleActions: [ + { id: 'ho7xRPUB0Gl', dataElementId: 'jBBkFuPKctq', programRuleActionType: 'HIDEFIELD' }, + ], + }, + { + id: 'NXWk8sq70OV', + condition: "#{TRAVEL_HISTORY} == 'No'", + description: "Hide 'Imported Case' if not traveled", + displayName: "Hide 'Imported Case'", + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'fJIgmDK53Vp', + dataElementId: 'f8j4XDEozvj', + programRuleActionType: 'HIDEOPTION', + optionId: 'PMGTqmVIF4T', + }, + ], + }, + { + id: 'NZaVqr7dPfQ', + condition: '!d2:hasValue( #{ONSET_DATE} ) && !d2:hasValue(V{event_date})', + description: 'Automation: Assign Empty date if no Onset date and no event date is available', + displayName: 'Assign Empty Date', + programId: 'PNClHaZARtz', + programRuleActions: [ + { id: 'q060xuOwQx3', data: "''", dataElementId: 'PFXeJV8d7ja', programRuleActionType: 'ASSIGN' }, + ], + priority: 3, + }, + { + id: 'QrJx9LI9KRo', + condition: "d2:hasValue( #{LAB_TEST} ) && #{LAB_TEST} == 'Yes' && !d2:hasValue( #{TEST_RESULT} )", + description: 'Automation: Assign Empty Value to Class Classification', + displayName: 'Assign Empty Value to Class Classification', + programId: 'PNClHaZARtz', + programRuleActions: [ + { id: 'rFaZAbOgMSz', data: "''", dataElementId: 'Z5z8vFQy0w0', programRuleActionType: 'ASSIGN' }, + ], + priority: 2, + }, + { + id: 'R6oEX1xlQma', + condition: 'true', + description: 'Hide irrelevant Outcome Options', + displayName: 'Hide Outcome Options', + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'Ov7qHXf0Q2s', + dataElementId: 'bOYWVEBaWy6', + programRuleActionType: 'HIDEOPTION', + optionId: 'dUeRcF2cApV', + }, + { + id: 'V95rgvUlqY0', + dataElementId: 'bOYWVEBaWy6', + programRuleActionType: 'HIDEOPTION', + optionId: 'bYt4why1tL3', + }, + { + id: 'eZUUOjykbLv', + dataElementId: 'bOYWVEBaWy6', + programRuleActionType: 'HIDEOPTION', + optionId: 'xBoo6HyaYcd', + }, + { + id: 'Zcs7rz5VEF7', + dataElementId: 'bOYWVEBaWy6', + programRuleActionType: 'HIDEOPTION', + optionId: 'RCT079wdeKT', + }, + ], + }, + { + id: 'dZsTiQEUg5L', + condition: '!d2:hasValue( #{ONSET_DATE} ) && d2:hasValue(V{event_date})', + description: 'Automation: Assign Event date if no Onset date is available', + displayName: 'Assign Event Date', + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'sQKFBORp5P1', + data: 'V{event_date}', + dataElementId: 'PFXeJV8d7ja', + programRuleActionType: 'ASSIGN', + }, + ], + priority: 2, + }, + { + id: 'kVBrxwODyTj', + condition: '!d2:hasValue( #{LAB_TEST} )', + description: 'Hide Case Classification Field until Lab Test question is answered', + displayName: 'Hide Case Classification Field', + programId: 'PNClHaZARtz', + programRuleActions: [ + { id: 'ZT8AexxBPl0', dataElementId: 'Z5z8vFQy0w0', programRuleActionType: 'HIDEFIELD' }, + ], + }, + { + id: 'q2QbEfeDlI9', + condition: "!d2:hasValue( #{HOSPITALISED} ) || #{HOSPITALISED} == 'No'", + description: 'Hide ICU field unless Hospitalised', + displayName: 'Hide ICU field', + programId: 'PNClHaZARtz', + programRuleActions: [ + { id: 'wwvxLCpuOCx', dataElementId: 'p8htbyJHydl', programRuleActionType: 'HIDEFIELD' }, + ], + }, + { + id: 'rZUpiMuJIKH', + condition: "d2:hasValue( #{LAB_TEST} ) && #{LAB_TEST} == 'Yes' && #{TEST_RESULT} == 'Positive'", + description: "Automation: Assign 'Laboratory Confirmed Case' to Case Classification", + displayName: "Assign 'Laboratory Confirmed Case' to Case Classification", + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'hcamYSDn00P', + data: "'Laboratory Confirmed Case'", + dataElementId: 'Z5z8vFQy0w0', + programRuleActionType: 'ASSIGN', + }, + ], + priority: 3, + }, + { + id: 'sEQsGGAQSJT', + condition: + "(d2:hasValue( #{LAB_TEST} ) && #{LAB_TEST} == 'Unknown') ||\n(d2:hasValue( #{LAB_TEST} ) && #{LAB_TEST} == 'Yes' && (#{TEST_RESULT} == 'Negative' || #{TEST_RESULT} == 'Unknown'))", + description: "Automation: Assign Suspected Case' to Case Classification", + displayName: "Assign 'Suspected Case' to Case Classification", + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'zxb2XDboGAF', + data: "'Suspected Case'", + dataElementId: 'Z5z8vFQy0w0', + programRuleActionType: 'ASSIGN', + }, + ], + priority: 1, + }, + { + id: 'sKCZMuWwOKA', + condition: 'd2:hasValue( #{ONSET_DATE} )', + description: 'Automation: Assign Symptoms Onset Date if available', + displayName: 'Assign Onset Date', + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'lJOYxhjupxz', + data: '#{ONSET_DATE}', + dataElementId: 'PFXeJV8d7ja', + programRuleActionType: 'ASSIGN', + }, + ], + priority: 1, + }, + { + id: 'vj5GWKIrhKh', + condition: "#{LAB_TEST} != 'Yes'", + description: 'Hide Test Result Field until Lab Test question is answered with yes', + displayName: 'Hide Test Result Field', + programId: 'PNClHaZARtz', + programRuleActions: [ + { id: 'VxxxIX2598r', dataElementId: 'ovY6E8BSdto', programRuleActionType: 'HIDEFIELD' }, + ], + }, + ]; + const programRuleVariables = [ + { + id: 'DoRHHfNPccb', + dataElementId: 'f8j4XDEozvj', + displayName: 'INFECTION_SOURCE', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: false, + }, + { + id: 'EnpvdmYrwLb', + dataElementId: 'TzqawmlPkI5', + displayName: 'TRAVEL_HISTORY', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: true, + }, + { + id: 'JPIyrAmJapV', + dataElementId: 'CUbZcLm9LyN', + displayName: 'HOSPITALISED', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: true, + }, + { + id: 'LAaPMTz69L7', + displayName: 'CASE_CLASSIFICATION', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.CALCULATED_VALUE, + useNameForOptionSet: true, + valueType: 'TEXT', + }, + { + id: 'MpixycZvu0m', + dataElementId: 'ovY6E8BSdto', + displayName: 'TEST_RESULT', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: true, + }, + { + id: 'XcPYCpTOPwB', + dataElementId: 'QQLXTXVidW2', + displayName: 'LAB_TEST', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: true, + }, + { + id: 'cZSslcAEupI', + dataElementId: 's3eoonJ8OJb', + displayName: 'ONSET_DATE', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: true, + }, + { + id: 'eSq3nc1t2F6', + dataElementId: 'dyfYIsTFTjG', + displayName: 'PATIENT_ID', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: true, + }, + { + id: 'lY0yJGU1D4e', + dataElementId: 'JGnHr6WI3AY', + displayName: 'SYMPTOMS', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: false, + }, + ]; const orgUnit = { id: 'DiszpKrYNg8', name: 'Ngelehun CHC' }; const optionSets = { - L6eMZDJkCwX: { id: 'L6eMZDJkCwX', displayName: 'Yes/No/Unknown', version: 3, valueType: 'TEXT', options: [{ id: 'x9yVKkv9koc', displayName: 'Yes', code: 'Yes', translations: [{ property: 'NAME', locale: 'uz@Latn', value: 'Ha' }, { property: 'NAME', locale: 'fr', value: 'Oui' }, { property: 'NAME', locale: 'pt', value: 'Sim' }, { property: 'NAME', locale: 'uz@Cyrl', value: 'Ҳа' }, { property: 'NAME', locale: 'es', value: 'Sí' }, { property: 'NAME', locale: 'nb', value: 'Ja' }, { property: 'NAME', locale: 'ru', value: 'да' }] }, { id: 'R98tI2c6rF5', displayName: 'No', code: 'No', translations: [{ property: 'NAME', locale: 'nb', value: 'Nei' }, { property: 'NAME', locale: 'es', value: 'No' }, { property: 'NAME', locale: 'uz@Latn', value: 'Yo`q' }, { property: 'NAME', locale: 'ru', value: 'нет' }, { property: 'NAME', locale: 'pt', value: 'Não' }, { property: 'NAME', locale: 'fr', value: 'Non' }, { property: 'NAME', locale: 'uz@Cyrl', value: 'Йўқ' }] }, { id: 'pqxvAQU1z9W', displayName: 'Unknown', code: 'Unknown', translations: [{ property: 'NAME', locale: 'es', value: 'DEsconocido' }, { property: 'NAME', locale: 'nb', value: 'Ukjent' }, { property: 'NAME', locale: 'uz@Cyrl', value: 'Ноаниқ' }, { property: 'NAME', locale: 'fr', value: 'Inconnu' }, { property: 'NAME', locale: 'uz@Latn', value: 'Noaniq' }, { property: 'NAME', locale: 'pt', value: 'Desconhecido' }, { property: 'NAME', locale: 'ru', value: 'Неизвестно' }] }] }, - dsgBmIZ0Yrq: { id: 'dsgBmIZ0Yrq', displayName: 'Test Result', version: 6, valueType: 'TEXT', options: [{ id: 'B44lkxTWbGO', displayName: 'Inconclusive', code: 'Inconclusive', translations: [{ property: 'NAME', locale: 'fr', value: 'Non concluant' }, { property: 'NAME', locale: 'pt', value: 'Inconclusivo' }, { property: 'NAME', locale: 'nb', value: 'Mangelfull' }, { property: 'NAME', locale: 'es', value: 'No concluyente' }, { property: 'NAME', locale: 'ru', value: 'Неокончательный' }] }, { id: 'ljClr1z2aE7', displayName: 'Negative', code: 'Negative', translations: [{ property: 'NAME', locale: 'fr', value: 'Négatif' }, { property: 'NAME', locale: 'nb', value: 'Negativ' }, { property: 'NAME', locale: 'es', value: 'Negativo' }, { property: 'NAME', locale: 'uz@Latn', value: 'Manfiy' }, { property: 'NAME', locale: 'pt', value: 'Negativo' }, { property: 'NAME', locale: 'ru', value: 'Отрицательный' }, { property: 'NAME', locale: 'uz@Cyrl', value: 'Манфий' }] }, { id: 'LKbwTJwocOk', displayName: 'Positive', code: 'Positive', translations: [{ property: 'NAME', locale: 'ru', value: 'Положительный' }, { property: 'NAME', locale: 'es', value: 'Positivo' }, { property: 'NAME', locale: 'uz@Latn', value: 'Musbat' }, { property: 'NAME', locale: 'uz@Cyrl', value: 'Мусбат' }, { property: 'NAME', locale: 'nb', value: 'Positiv' }, { property: 'NAME', locale: 'fr', value: 'Positif' }, { property: 'NAME', locale: 'pt', value: 'Positivo' }] }, { id: 'MkeWrqeqZXL', displayName: 'Not performed', code: 'Not performed', translations: [{ property: 'NAME', locale: 'ru', value: 'Не выполнен' }, { property: 'NAME', locale: 'pt', value: 'Não realizado' }, { property: 'NAME', locale: 'nb', value: 'Ikke utført' }, { property: 'NAME', locale: 'fr', value: 'Non réalisé' }, { property: 'NAME', locale: 'es', value: 'No realizado' }] }, { id: 'fPV0gQ8ds6D', displayName: 'Invalid', code: 'Invalid', translations: [{ property: 'NAME', locale: 'es', value: 'Inválido' }, { property: 'NAME', locale: 'fr', value: 'Invalide' }, { property: 'NAME', locale: 'pt', value: 'Inválido' }, { property: 'NAME', locale: 'nb', value: 'Ugyldig' }, { property: 'NAME', locale: 'ru', value: 'Недействительный' }] }, { id: 'YV3jCZlvwZe', displayName: 'Unknown', code: 'Unknown', translations: [{ property: 'NAME', locale: 'es', value: 'DEsconocido' }, { property: 'NAME', locale: 'nb', value: 'Ukjent' }, { property: 'NAME', locale: 'uz@Cyrl', value: 'Ноаниқ' }, { property: 'NAME', locale: 'fr', value: 'Inconnu' }, { property: 'NAME', locale: 'uz@Latn', value: 'Noaniq' }, { property: 'NAME', locale: 'pt', value: 'Desconhecido' }, { property: 'NAME', locale: 'ru', value: 'Неизвестно' }] }] }, + L6eMZDJkCwX: { + id: 'L6eMZDJkCwX', + displayName: 'Yes/No/Unknown', + version: 3, + valueType: 'TEXT', + options: [ + { + id: 'x9yVKkv9koc', + displayName: 'Yes', + code: 'Yes', + translations: [ + { property: 'NAME', locale: 'uz@Latn', value: 'Ha' }, + { property: 'NAME', locale: 'fr', value: 'Oui' }, + { property: 'NAME', locale: 'pt', value: 'Sim' }, + { property: 'NAME', locale: 'uz@Cyrl', value: 'Ҳа' }, + { property: 'NAME', locale: 'es', value: 'Sí' }, + { property: 'NAME', locale: 'nb', value: 'Ja' }, + { property: 'NAME', locale: 'ru', value: 'да' }, + ], + }, + { + id: 'R98tI2c6rF5', + displayName: 'No', + code: 'No', + translations: [ + { property: 'NAME', locale: 'nb', value: 'Nei' }, + { property: 'NAME', locale: 'es', value: 'No' }, + { property: 'NAME', locale: 'uz@Latn', value: 'Yo`q' }, + { property: 'NAME', locale: 'ru', value: 'нет' }, + { property: 'NAME', locale: 'pt', value: 'Não' }, + { property: 'NAME', locale: 'fr', value: 'Non' }, + { property: 'NAME', locale: 'uz@Cyrl', value: 'Йўқ' }, + ], + }, + { + id: 'pqxvAQU1z9W', + code: 'Unknown', + translations: [ + { property: 'NAME', locale: 'es', value: 'DEsconocido' }, + { property: 'NAME', locale: 'nb', value: 'Ukjent' }, + { property: 'NAME', locale: 'uz@Cyrl', value: 'Ноаниқ' }, + { property: 'NAME', locale: 'fr', value: 'Inconnu' }, + { property: 'NAME', locale: 'uz@Latn', value: 'Noaniq' }, + { property: 'NAME', locale: 'pt', value: 'Desconhecido' }, + { property: 'NAME', locale: 'ru', value: 'Неизвестно' }, + ], + }, + ], + }, + dsgBmIZ0Yrq: { + id: 'dsgBmIZ0Yrq', + displayName: 'Test Result', + version: 6, + valueType: 'TEXT', + options: [ + { + id: 'B44lkxTWbGO', + code: 'Inconclusive', + translations: [ + { property: 'NAME', locale: 'fr', value: 'Non concluant' }, + { property: 'NAME', locale: 'pt', value: 'Inconclusivo' }, + { property: 'NAME', locale: 'nb', value: 'Mangelfull' }, + { property: 'NAME', locale: 'es', value: 'No concluyente' }, + { property: 'NAME', locale: 'ru', value: 'Неокончательный' }, + ], + }, + { + id: 'ljClr1z2aE7', + displayName: 'Negative', + code: 'Negative', + translations: [ + { property: 'NAME', locale: 'fr', value: 'Négatif' }, + { property: 'NAME', locale: 'nb', value: 'Negativ' }, + { property: 'NAME', locale: 'es', value: 'Negativo' }, + { property: 'NAME', locale: 'uz@Latn', value: 'Manfiy' }, + { property: 'NAME', locale: 'pt', value: 'Negativo' }, + { property: 'NAME', locale: 'ru', value: 'Отрицательный' }, + { property: 'NAME', locale: 'uz@Cyrl', value: 'Манфий' }, + ], + }, + { + id: 'LKbwTJwocOk', + displayName: 'Positive', + code: 'Positive', + translations: [ + { property: 'NAME', locale: 'ru', value: 'Положительный' }, + { property: 'NAME', locale: 'es', value: 'Positivo' }, + { property: 'NAME', locale: 'uz@Latn', value: 'Musbat' }, + { property: 'NAME', locale: 'uz@Cyrl', value: 'Мусбат' }, + { property: 'NAME', locale: 'nb', value: 'Positiv' }, + { property: 'NAME', locale: 'fr', value: 'Positif' }, + { property: 'NAME', locale: 'pt', value: 'Positivo' }, + ], + }, + { + id: 'MkeWrqeqZXL', + displayName: 'Not performed', + code: 'Not performed', + translations: [ + { property: 'NAME', locale: 'ru', value: 'Не выполнен' }, + { property: 'NAME', locale: 'pt', value: 'Não realizado' }, + { property: 'NAME', locale: 'nb', value: 'Ikke utført' }, + { property: 'NAME', locale: 'fr', value: 'Non réalisé' }, + { property: 'NAME', locale: 'es', value: 'No realizado' }, + ], + }, + { + id: 'fPV0gQ8ds6D', + displayName: 'Invalid', + code: 'Invalid', + translations: [ + { property: 'NAME', locale: 'es', value: 'Inválido' }, + { property: 'NAME', locale: 'fr', value: 'Invalide' }, + { property: 'NAME', locale: 'pt', value: 'Inválido' }, + { property: 'NAME', locale: 'nb', value: 'Ugyldig' }, + { property: 'NAME', locale: 'ru', value: 'Недействительный' }, + ], + }, + { + id: 'YV3jCZlvwZe', + displayName: 'Unknown', + code: 'Unknown', + translations: [ + { property: 'NAME', locale: 'es', value: 'DEsconocido' }, + { property: 'NAME', locale: 'nb', value: 'Ukjent' }, + { property: 'NAME', locale: 'uz@Cyrl', value: 'Ноаниқ' }, + { property: 'NAME', locale: 'fr', value: 'Inconnu' }, + { property: 'NAME', locale: 'uz@Latn', value: 'Noaniq' }, + { property: 'NAME', locale: 'pt', value: 'Desconhecido' }, + { property: 'NAME', locale: 'ru', value: 'Неизвестно' }, + ], + }, + ], + }, }; // NOTE: in this test we dont use toMatchSnapshot instead we test again hardcoded values. Since the effects are plenty @@ -167,18 +916,68 @@ describe('Event rules engine', () => { [ { JGnHr6WI3AY: 'Yes' }, [ - { type: 'ASSIGN', id: 'PFXeJV8d7ja', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'MkeWrqeqZXL' }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'fPV0gQ8ds6D' }, - { type: 'HIDEOPTION', id: 'JGnHr6WI3AY', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'CUbZcLm9LyN', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, + { + type: 'ASSIGN', + id: 'PFXeJV8d7ja', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'MkeWrqeqZXL', + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'fPV0gQ8ds6D', + }, + { + type: 'HIDEOPTION', + id: 'JGnHr6WI3AY', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'p8htbyJHydl', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'CUbZcLm9LyN', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, { type: 'HIDEFIELD', id: 'A4Fg6jgWauf', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'jBBkFuPKctq', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'dUeRcF2cApV' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'bYt4why1tL3' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'xBoo6HyaYcd' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'RCT079wdeKT' }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'dUeRcF2cApV', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'bYt4why1tL3', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'xBoo6HyaYcd', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'RCT079wdeKT', + }, { type: 'HIDEFIELD', id: 'Z5z8vFQy0w0', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, @@ -187,40 +986,150 @@ describe('Event rules engine', () => { [ { QQLXTXVidW2: 'Yes' }, [ - { type: 'ASSIGN', id: 'Z5z8vFQy0w0', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'ASSIGN', id: 'PFXeJV8d7ja', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'MkeWrqeqZXL' }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'fPV0gQ8ds6D' }, + { + type: 'ASSIGN', + id: 'Z5z8vFQy0w0', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'ASSIGN', + id: 'PFXeJV8d7ja', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'MkeWrqeqZXL', + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'fPV0gQ8ds6D', + }, { type: 'HIDEFIELD', id: 's3eoonJ8OJb', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'JGnHr6WI3AY', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'CUbZcLm9LyN', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, + { + type: 'HIDEOPTION', + id: 'JGnHr6WI3AY', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'p8htbyJHydl', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'CUbZcLm9LyN', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, { type: 'HIDEFIELD', id: 'A4Fg6jgWauf', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'jBBkFuPKctq', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'dUeRcF2cApV' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'bYt4why1tL3' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'xBoo6HyaYcd' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'RCT079wdeKT' }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'dUeRcF2cApV', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'bYt4why1tL3', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'xBoo6HyaYcd', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'RCT079wdeKT', + }, { type: 'HIDEFIELD', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, ], ], [ { QQLXTXVidW2: 'No' }, [ - { type: 'ASSIGN', id: 'PFXeJV8d7ja', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'ASSIGN', id: 'Z5z8vFQy0w0', value: 'Probable Case', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'MkeWrqeqZXL' }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'fPV0gQ8ds6D' }, + { + type: 'ASSIGN', + id: 'PFXeJV8d7ja', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'ASSIGN', + id: 'Z5z8vFQy0w0', + value: 'Probable Case', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'MkeWrqeqZXL', + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'fPV0gQ8ds6D', + }, { type: 'HIDEFIELD', id: 's3eoonJ8OJb', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'JGnHr6WI3AY', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'CUbZcLm9LyN', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, + { + type: 'HIDEOPTION', + id: 'JGnHr6WI3AY', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'p8htbyJHydl', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'CUbZcLm9LyN', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, { type: 'HIDEFIELD', id: 'A4Fg6jgWauf', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'jBBkFuPKctq', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'dUeRcF2cApV' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'bYt4why1tL3' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'xBoo6HyaYcd' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'RCT079wdeKT' }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'dUeRcF2cApV', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'bYt4why1tL3', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'xBoo6HyaYcd', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'RCT079wdeKT', + }, { type: 'HIDEFIELD', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, ], @@ -228,20 +1137,75 @@ describe('Event rules engine', () => { [ { QQLXTXVidW2: 'Unknown' }, [ - { type: 'ASSIGN', id: 'Z5z8vFQy0w0', value: 'Suspected Case', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'ASSIGN', id: 'PFXeJV8d7ja', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'MkeWrqeqZXL' }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'fPV0gQ8ds6D' }, + { + type: 'ASSIGN', + id: 'Z5z8vFQy0w0', + value: 'Suspected Case', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'ASSIGN', + id: 'PFXeJV8d7ja', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'MkeWrqeqZXL', + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'fPV0gQ8ds6D', + }, { type: 'HIDEFIELD', id: 's3eoonJ8OJb', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'JGnHr6WI3AY', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'CUbZcLm9LyN', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, + { + type: 'HIDEOPTION', + id: 'JGnHr6WI3AY', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'p8htbyJHydl', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'CUbZcLm9LyN', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, { type: 'HIDEFIELD', id: 'A4Fg6jgWauf', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'jBBkFuPKctq', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'dUeRcF2cApV' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'bYt4why1tL3' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'xBoo6HyaYcd' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'RCT079wdeKT' }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'dUeRcF2cApV', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'bYt4why1tL3', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'xBoo6HyaYcd', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'RCT079wdeKT', + }, { type: 'HIDEFIELD', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, ], @@ -249,19 +1213,69 @@ describe('Event rules engine', () => { [ { CUbZcLm9LyN: 'Yes' }, [ - { type: 'ASSIGN', id: 'PFXeJV8d7ja', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'MkeWrqeqZXL' }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'fPV0gQ8ds6D' }, + { + type: 'ASSIGN', + id: 'PFXeJV8d7ja', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'MkeWrqeqZXL', + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'fPV0gQ8ds6D', + }, { type: 'HIDEFIELD', id: 's3eoonJ8OJb', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'JGnHr6WI3AY', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'CUbZcLm9LyN', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, + { + type: 'HIDEOPTION', + id: 'JGnHr6WI3AY', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'p8htbyJHydl', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'CUbZcLm9LyN', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, { type: 'HIDEFIELD', id: 'A4Fg6jgWauf', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'jBBkFuPKctq', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'dUeRcF2cApV' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'bYt4why1tL3' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'xBoo6HyaYcd' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'RCT079wdeKT' }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'dUeRcF2cApV', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'bYt4why1tL3', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'xBoo6HyaYcd', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'RCT079wdeKT', + }, { type: 'HIDEFIELD', id: 'Z5z8vFQy0w0', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, ], @@ -269,80 +1283,300 @@ describe('Event rules engine', () => { [ { QQLXTXVidW2: 'Yes', ovY6E8BSdto: 'Inconclusive' }, [ - { type: 'ASSIGN', id: 'PFXeJV8d7ja', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'ASSIGN', id: 'Z5z8vFQy0w0', value: 'Probable Case', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'MkeWrqeqZXL' }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'fPV0gQ8ds6D' }, + { + type: 'ASSIGN', + id: 'PFXeJV8d7ja', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'ASSIGN', + id: 'Z5z8vFQy0w0', + value: 'Probable Case', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'MkeWrqeqZXL', + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'fPV0gQ8ds6D', + }, { type: 'HIDEFIELD', id: 's3eoonJ8OJb', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'JGnHr6WI3AY', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'CUbZcLm9LyN', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, + { + type: 'HIDEOPTION', + id: 'JGnHr6WI3AY', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'p8htbyJHydl', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'CUbZcLm9LyN', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, { type: 'HIDEFIELD', id: 'A4Fg6jgWauf', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'jBBkFuPKctq', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'dUeRcF2cApV' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'bYt4why1tL3' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'xBoo6HyaYcd' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'RCT079wdeKT' }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'dUeRcF2cApV', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'bYt4why1tL3', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'xBoo6HyaYcd', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'RCT079wdeKT', + }, { type: 'HIDEFIELD', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, ], ], [ { QQLXTXVidW2: 'Yes', ovY6E8BSdto: 'Positive' }, [ - { type: 'ASSIGN', id: 'PFXeJV8d7ja', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'ASSIGN', id: 'Z5z8vFQy0w0', value: 'Laboratory Confirmed Case', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'MkeWrqeqZXL' }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'fPV0gQ8ds6D' }, + { + type: 'ASSIGN', + id: 'PFXeJV8d7ja', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'ASSIGN', + id: 'Z5z8vFQy0w0', + value: 'Laboratory Confirmed Case', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'MkeWrqeqZXL', + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'fPV0gQ8ds6D', + }, { type: 'HIDEFIELD', id: 's3eoonJ8OJb', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'JGnHr6WI3AY', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'CUbZcLm9LyN', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, + { + type: 'HIDEOPTION', + id: 'JGnHr6WI3AY', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'p8htbyJHydl', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'CUbZcLm9LyN', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, { type: 'HIDEFIELD', id: 'A4Fg6jgWauf', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'jBBkFuPKctq', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'dUeRcF2cApV' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'bYt4why1tL3' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'xBoo6HyaYcd' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'RCT079wdeKT' }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'dUeRcF2cApV', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'bYt4why1tL3', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'xBoo6HyaYcd', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'RCT079wdeKT', + }, { type: 'HIDEFIELD', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, ], ], [ { QQLXTXVidW2: 'Yes', ovY6E8BSdto: 'Negative' }, [ - { type: 'ASSIGN', id: 'Z5z8vFQy0w0', value: 'Suspected Case', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'ASSIGN', id: 'PFXeJV8d7ja', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'MkeWrqeqZXL' }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'fPV0gQ8ds6D' }, + { + type: 'ASSIGN', + id: 'Z5z8vFQy0w0', + value: 'Suspected Case', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'ASSIGN', + id: 'PFXeJV8d7ja', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'MkeWrqeqZXL', + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'fPV0gQ8ds6D', + }, { type: 'HIDEFIELD', id: 's3eoonJ8OJb', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'JGnHr6WI3AY', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'CUbZcLm9LyN', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, + { + type: 'HIDEOPTION', + id: 'JGnHr6WI3AY', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'p8htbyJHydl', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'CUbZcLm9LyN', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, { type: 'HIDEFIELD', id: 'A4Fg6jgWauf', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'jBBkFuPKctq', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'dUeRcF2cApV' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'bYt4why1tL3' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'xBoo6HyaYcd' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'RCT079wdeKT' }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'dUeRcF2cApV', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'bYt4why1tL3', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'xBoo6HyaYcd', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'RCT079wdeKT', + }, { type: 'HIDEFIELD', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, ], ], [ { QQLXTXVidW2: 'Yes', ovY6E8BSdto: 'Unknown' }, [ - { type: 'ASSIGN', id: 'Z5z8vFQy0w0', value: 'Suspected Case', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'ASSIGN', id: 'PFXeJV8d7ja', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'MkeWrqeqZXL' }, - { type: 'HIDEOPTION', id: 'ovY6E8BSdto', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'fPV0gQ8ds6D' }, + { + type: 'ASSIGN', + id: 'Z5z8vFQy0w0', + value: 'Suspected Case', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'ASSIGN', + id: 'PFXeJV8d7ja', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'MkeWrqeqZXL', + }, + { + type: 'HIDEOPTION', + id: 'ovY6E8BSdto', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'fPV0gQ8ds6D', + }, { type: 'HIDEFIELD', id: 's3eoonJ8OJb', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'JGnHr6WI3AY', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, - { type: 'HIDEOPTION', id: 'CUbZcLm9LyN', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'pqxvAQU1z9W' }, + { + type: 'HIDEOPTION', + id: 'JGnHr6WI3AY', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'p8htbyJHydl', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, + { + type: 'HIDEOPTION', + id: 'CUbZcLm9LyN', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'pqxvAQU1z9W', + }, { type: 'HIDEFIELD', id: 'A4Fg6jgWauf', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, { type: 'HIDEFIELD', id: 'jBBkFuPKctq', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'dUeRcF2cApV' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'bYt4why1tL3' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'xBoo6HyaYcd' }, - { type: 'HIDEOPTION', id: 'bOYWVEBaWy6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, optionId: 'RCT079wdeKT' }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'dUeRcF2cApV', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'bYt4why1tL3', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'xBoo6HyaYcd', + }, + { + type: 'HIDEOPTION', + id: 'bOYWVEBaWy6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + optionId: 'RCT079wdeKT', + }, { type: 'HIDEFIELD', id: 'p8htbyJHydl', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, ], ], @@ -361,15 +1595,261 @@ describe('Event rules engine', () => { }); }); - describe('Event rules engine effects with functions and effects', () => { // these variables are shared between each test - const constants = [{ id: 'Gfd3ppDfq8E', displayName: 'Commodity ordering overhead', value: 5 }, { id: 'bCqvfPR02Im', displayName: 'Pi', value: 3.14 }]; - const dataElementsInProgram = { oZg33kd9taw: { id: 'oZg33kd9taw', valueType: 'TEXT', optionSetId: 'pC3N9N77UmT' }, SWfdB5lX0fk: { id: 'SWfdB5lX0fk', valueType: 'BOOLEAN' }, qrur9Dvnyt5: { id: 'qrur9Dvnyt5', valueType: 'INTEGER' }, GieVkTxp4HH: { id: 'GieVkTxp4HH', valueType: 'NUMBER' }, vV9UWAZohSf: { id: 'vV9UWAZohSf', valueType: 'INTEGER_POSITIVE' }, eMyVanycQSC: { id: 'eMyVanycQSC', valueType: 'DATE' }, K6uUAvq500H: { id: 'K6uUAvq500H', valueType: 'TEXT', optionSetId: 'eUZ79clX7y1' }, msodh3rEMJa: { id: 'msodh3rEMJa', valueType: 'DATE' }, S33cRBsnXPo: { id: 'S33cRBsnXPo', valueType: 'ORGANISATION_UNIT' }, fWIAEtYVEGk: { id: 'fWIAEtYVEGk', valueType: 'TEXT', optionSetId: 'iDFPKpFTiVw' }, ulD2zW0TIy2: { id: 'ulD2zW0TIy2', valueType: 'FILE_RESOURCE' } }; - const programRules = [{ id: 'CTzRoPyvf8v', condition: 'true', displayName: 'Testing the functions!', programId: 'eBAyeGv0exc', programRuleActions: [{ id: 'isP0uvT24jf', displayContent: "d2:yearsBetween( '2010-01-28', V{event_date}) =", data: "d2:yearsBetween( '2010-01-28', V{event_date})", programRuleActionType: 'DISPLAYTEXT' }, { id: 'vQCRnX6w9pM', displayContent: 'd2:oizp( -10000000 ) =', data: 'd2:oizp( -10000000 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'SYAL0GIDnxI', displayContent: 'display age = ', data: 'd2:hasValue(#{age}) && #{age}', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'Xa0tKyNk5YE', displayContent: 'org_unit = ', data: 'V{orgunit_code}', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'JXssEpbJdO2', displayContent: 'd2:right(#{age}, 3) = ', data: 'd2:hasValue(#{age}) && d2:right(#{age}, 3)', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'o0LLNIYsliy', displayContent: "d2:monthsBetween( '2020-01-28', V{event_date}) = ", data: "d2:monthsBetween( '2020-01-28', V{event_date})", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'k07KnI11Sf4', displayContent: 'd2:left(#{age}, 3) = ', data: 'd2:hasValue(#{age}) && d2:left(#{age}, 3)', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'OITs4nPfMQ3', displayContent: "d2:split('these-are-testing-values', '-', 2) = ", data: "d2:split('these-are-testing-values', '-', 2)", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'EzkFLDtAxCR', displayContent: 'd2:modulus( 12 , 100 ) = ', data: 'd2:modulus( 12 , 100 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'RCYEyOly0Mi', displayContent: "d2:countIfValue( #{gender}, 'Male' ) = ", data: "d2:countIfValue( #{gender}, 'Male' )", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'bRnjbxIwIRd', displayContent: 'd2:round( 12.5 ) = ', data: 'd2:round( 12.5 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'BuEcHNoD98P', displayContent: 'd2:ceil(11.3) = ', data: 'd2:ceil(11.3)', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'Foc3PhzoAVr', displayContent: 'd2:count(#{age}) = ', data: 'd2:count(#{age})', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'QpeF2WDjwIV', displayContent: "d2:addDays( '2020-01-12', 5 ) = ", data: "d2:addDays( '2020-01-12', 5 )", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'WJTjezLR4cJ', displayContent: "d2:weeksBetween('2020-01-28', V{event_date} ) = ", data: "d2:weeksBetween('2020-01-28', V{event_date} )", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'YnE4dNJVF2P', displayContent: 'd2:zing( -2 ) = ', data: 'd2:zing( -2 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'bZsv2cUkbB7', displayContent: 'd2:floor( 11.5 ) =', data: 'd2:floor( 11.5 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'J8RxAbHlnO3', displayContent: 'd2:oizp( 10000000 ) = ', data: 'd2:oizp( 10000000 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'NT1wojA2RdT', displayContent: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking') = ", data: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking')", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'NUGe7EUVouK', displayContent: "d2:substring('hello dhis 2', 6, 10) = ", data: "d2:substring('hello dhis 2', 6, 10)", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'Ma6nCIGrBrd', displayContent: "d2:length( 'dhis2 rocks' ) = ", data: "d2:length( 'dhis2 rocks' )", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'RRSDsxWiUMc', displayContent: 'd2:round( 0 ) = ', data: 'd2:round( 0 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'QUe0Pks4ckc', displayContent: 'd2:countIfValue( #{age}, 1 ) = ', data: 'd2:countIfValue( #{age}, 1 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'sHaE1YI0ur2', displayContent: 'd2:zing( 1000 ) = ', data: 'd2:zing( 1000 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'EojHcBMpW7q', displayContent: 'd2:hasValue( #{age} ) = ', data: 'd2:hasValue( #{age} )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }] }]; - const programRuleVariables = [{ id: 'RycV5uDi66i', dataElementId: 'qrur9Dvnyt5', displayName: 'age', programId: 'eBAyeGv0exc', programRuleVariableSourceType: 'DATAELEMENT_NEWEST_EVENT_PROGRAM', useNameForOptionSet: true }, { id: 'zINGRka3g9N', dataElementId: 'oZg33kd9taw', displayName: 'gender', programId: 'eBAyeGv0exc', programRuleVariableSourceType: 'DATAELEMENT_NEWEST_EVENT_PROGRAM', useNameForOptionSet: true }, { id: 'Zj7UnCAulEk.vV9UWAZohSf', displayName: 'Zj7UnCAulEk.vV9UWAZohSf', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', dataElementId: 'vV9UWAZohSf', programId: 'eBAyeGv0exc' }, { id: 'Zj7UnCAulEk.GieVkTxp4HH', displayName: 'Zj7UnCAulEk.GieVkTxp4HH', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', dataElementId: 'GieVkTxp4HH', programId: 'eBAyeGv0exc' }, { id: 'Zj7UnCAulEk.GieVkTxp4HH', displayName: 'Zj7UnCAulEk.GieVkTxp4HH', programRuleVariableSourceType: 'DATAELEMENT_CURRENT_EVENT', dataElementId: 'GieVkTxp4HH', programId: 'eBAyeGv0exc' }]; + const constants = [ + { id: 'Gfd3ppDfq8E', displayName: 'Commodity ordering overhead', value: 5 }, + { id: 'bCqvfPR02Im', displayName: 'Pi', value: 3.14 }, + ]; + const dataElementsInProgram = { + oZg33kd9taw: { id: 'oZg33kd9taw', valueType: 'TEXT', optionSetId: 'pC3N9N77UmT' }, + SWfdB5lX0fk: { id: 'SWfdB5lX0fk', valueType: 'BOOLEAN' }, + qrur9Dvnyt5: { id: 'qrur9Dvnyt5', valueType: 'INTEGER' }, + GieVkTxp4HH: { id: 'GieVkTxp4HH', valueType: 'NUMBER' }, + vV9UWAZohSf: { id: 'vV9UWAZohSf', valueType: 'INTEGER_POSITIVE' }, + eMyVanycQSC: { id: 'eMyVanycQSC', valueType: 'DATE' }, + K6uUAvq500H: { id: 'K6uUAvq500H', valueType: 'TEXT', optionSetId: 'eUZ79clX7y1' }, + msodh3rEMJa: { id: 'msodh3rEMJa', valueType: 'DATE' }, + S33cRBsnXPo: { id: 'S33cRBsnXPo', valueType: 'ORGANISATION_UNIT' }, + fWIAEtYVEGk: { id: 'fWIAEtYVEGk', valueType: 'TEXT', optionSetId: 'iDFPKpFTiVw' }, + ulD2zW0TIy2: { id: 'ulD2zW0TIy2', valueType: 'FILE_RESOURCE' }, + }; + const programRules = [ + { + id: 'CTzRoPyvf8v', + condition: 'true', + displayName: 'Testing the functions!', + programId: 'eBAyeGv0exc', + programRuleActions: [ + { + id: 'isP0uvT24jf', + displayContent: "d2:yearsBetween( '2010-01-28', V{event_date}) =", + data: "d2:yearsBetween( '2010-01-28', V{event_date})", + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'vQCRnX6w9pM', + displayContent: 'd2:oizp( -10000000 ) =', + data: 'd2:oizp( -10000000 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'SYAL0GIDnxI', + displayContent: 'display age = ', + data: 'd2:hasValue(#{age}) && #{age}', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'Xa0tKyNk5YE', + displayContent: 'org_unit = ', + data: 'V{orgunit_code}', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'JXssEpbJdO2', + displayContent: 'd2:right(#{age}, 3) = ', + data: 'd2:hasValue(#{age}) && d2:right(#{age}, 3)', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'o0LLNIYsliy', + displayContent: "d2:monthsBetween( '2020-01-28', V{event_date}) = ", + data: "d2:monthsBetween( '2020-01-28', V{event_date})", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'k07KnI11Sf4', + displayContent: 'd2:left(#{age}, 3) = ', + data: 'd2:hasValue(#{age}) && d2:left(#{age}, 3)', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'OITs4nPfMQ3', + displayContent: "d2:split('these-are-testing-values', '-', 2) = ", + data: "d2:split('these-are-testing-values', '-', 2)", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'EzkFLDtAxCR', + displayContent: 'd2:modulus( 12 , 100 ) = ', + data: 'd2:modulus( 12 , 100 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'RCYEyOly0Mi', + displayContent: "d2:countIfValue( #{gender}, 'Male' ) = ", + data: "d2:countIfValue( #{gender}, 'Male' )", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'bRnjbxIwIRd', + displayContent: 'd2:round( 12.5 ) = ', + data: 'd2:round( 12.5 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'BuEcHNoD98P', + displayContent: 'd2:ceil(11.3) = ', + data: 'd2:ceil(11.3)', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'Foc3PhzoAVr', + displayContent: 'd2:count(#{age}) = ', + data: 'd2:count(#{age})', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'QpeF2WDjwIV', + displayContent: "d2:addDays( '2020-01-12', 5 ) = ", + data: "d2:addDays( '2020-01-12', 5 )", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'WJTjezLR4cJ', + displayContent: "d2:weeksBetween('2020-01-28', V{event_date} ) = ", + data: "d2:weeksBetween('2020-01-28', V{event_date} )", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'YnE4dNJVF2P', + displayContent: 'd2:zing( -2 ) = ', + data: 'd2:zing( -2 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'bZsv2cUkbB7', + displayContent: 'd2:floor( 11.5 ) =', + data: 'd2:floor( 11.5 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'J8RxAbHlnO3', + displayContent: 'd2:oizp( 10000000 ) = ', + data: 'd2:oizp( 10000000 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'NT1wojA2RdT', + displayContent: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking') = ", + data: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'NUGe7EUVouK', + displayContent: "d2:substring('hello dhis 2', 6, 10) = ", + data: "d2:substring('hello dhis 2', 6, 10)", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'Ma6nCIGrBrd', + displayContent: "d2:length( 'dhis2 rocks' ) = ", + data: "d2:length( 'dhis2 rocks' )", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'RRSDsxWiUMc', + displayContent: 'd2:round( 0 ) = ', + data: 'd2:round( 0 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'QUe0Pks4ckc', + displayContent: 'd2:countIfValue( #{age}, 1 ) = ', + data: 'd2:countIfValue( #{age}, 1 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'sHaE1YI0ur2', + displayContent: 'd2:zing( 1000 ) = ', + data: 'd2:zing( 1000 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'EojHcBMpW7q', + displayContent: 'd2:hasValue( #{age} ) = ', + data: 'd2:hasValue( #{age} )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + ], + }, + ]; + const programRuleVariables = [ + { + id: 'RycV5uDi66i', + dataElementId: 'qrur9Dvnyt5', + displayName: 'age', + programId: 'eBAyeGv0exc', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, + useNameForOptionSet: true, + }, + { + id: 'zINGRka3g9N', + dataElementId: 'oZg33kd9taw', + displayName: 'gender', + programId: 'eBAyeGv0exc', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, + useNameForOptionSet: true, + }, + { + id: 'Zj7UnCAulEk.vV9UWAZohSf', + displayName: 'Zj7UnCAulEk.vV9UWAZohSf', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_PREVIOUS_EVENT, + dataElementId: 'vV9UWAZohSf', + programId: 'eBAyeGv0exc', + }, + { + id: 'Zj7UnCAulEk.GieVkTxp4HH', + displayName: 'Zj7UnCAulEk.GieVkTxp4HH', + programRuleVariableSourceType: variableSourceTypes.TEI_ATTRIBUTE, + dataElementId: 'GieVkTxp4HH', + programId: 'eBAyeGv0exc', + }, + { + id: 'Zj7UnCAulEk.GieVkTxp4HH', + displayName: 'Zj7UnCAulEk.GieVkTxp4HH', + programRuleVariableSourceType: 'UNKNOWN', + dataElementId: 'GieVkTxp4HH', + programId: 'eBAyeGv0exc', + }, + ]; const orgUnit = { id: 'DiszpKrYNg8', name: 'Ngelehun CHC', code: 'OU_559' }; - const optionSets = { pC3N9N77UmT: { id: 'pC3N9N77UmT', displayName: 'Gender', version: 0, valueType: 'TEXT', options: [{ id: 'rBvjJYbMCVx', displayName: 'Male', code: 'Male', translations: [] }, { id: 'Mnp3oXrpAbK', displayName: 'Female', code: 'Female', translations: [] }] } }; + const optionSets = { + pC3N9N77UmT: { + id: 'pC3N9N77UmT', + displayName: 'Gender', + version: 0, + valueType: 'TEXT', + options: [ + { id: 'rBvjJYbMCVx', displayName: 'Male', code: 'Male', translations: [] }, + { id: 'Mnp3oXrpAbK', displayName: 'Female', code: 'Female', translations: [] }, + ], + }, + }; // NOTE: in this test we dont use toMatchSnapshot instead we test again hardcoded values. Since the effects are plenty // here each time this way we can avoid mistakes in comparing snapshots @@ -377,95 +1857,410 @@ describe('Event rules engine effects with functions and effects', () => { [ {}, [ - { type: 'DISPLAYTEXT', displayText: { id: 'isP0uvT24jf', message: "d2:yearsBetween( '2010-01-28', V{event_date}) = " } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'vQCRnX6w9pM', message: 'd2:oizp( -10000000 ) = 0' } }, + { + type: 'DISPLAYTEXT', + displayText: { id: 'isP0uvT24jf', message: "d2:yearsBetween( '2010-01-28', V{event_date}) = " }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'vQCRnX6w9pM', message: 'd2:oizp( -10000000 ) = 0' }, + }, { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'SYAL0GIDnxI', message: 'display age = ' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'Xa0tKyNk5YE', message: 'org_unit = OU_559' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'JXssEpbJdO2', message: 'd2:right(#{age}, 3) = ' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'o0LLNIYsliy', message: "d2:monthsBetween( '2020-01-28', V{event_date}) = " } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'k07KnI11Sf4', message: 'd2:left(#{age}, 3) = ' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'OITs4nPfMQ3', message: "d2:split('these-are-testing-values', '-', 2) = testing" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'EzkFLDtAxCR', message: 'd2:modulus( 12 , 100 ) = 12' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'RCYEyOly0Mi', message: "d2:countIfValue( #{gender}, 'Male' ) = 0" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'bRnjbxIwIRd', message: 'd2:round( 12.5 ) = 13' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'BuEcHNoD98P', message: 'd2:ceil(11.3) = 12' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'Foc3PhzoAVr', message: 'd2:count(#{age}) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'QpeF2WDjwIV', message: "d2:addDays( '2020-01-12', 5 ) = 2020-01-17" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'WJTjezLR4cJ', message: "d2:weeksBetween('2020-01-28', V{event_date} ) = " } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'YnE4dNJVF2P', message: 'd2:zing( -2 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'bZsv2cUkbB7', message: 'd2:floor( 11.5 ) = 11' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'J8RxAbHlnO3', message: 'd2:oizp( 10000000 ) = 1' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'NT1wojA2RdT', message: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking') = dhis2isrocking" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'NUGe7EUVouK', message: "d2:substring('hello dhis 2', 6, 10) = dhis" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'Ma6nCIGrBrd', message: "d2:length( 'dhis2 rocks' ) = 11" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'RRSDsxWiUMc', message: 'd2:round( 0 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'QUe0Pks4ckc', message: 'd2:countIfValue( #{age}, 1 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'sHaE1YI0ur2', message: 'd2:zing( 1000 ) = 1000' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'EojHcBMpW7q', message: 'd2:hasValue( #{age} ) = ' } }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Xa0tKyNk5YE', message: 'org_unit = OU_559' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'JXssEpbJdO2', message: 'd2:right(#{age}, 3) = ' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'o0LLNIYsliy', message: "d2:monthsBetween( '2020-01-28', V{event_date}) = " }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'k07KnI11Sf4', message: 'd2:left(#{age}, 3) = ' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'OITs4nPfMQ3', + message: "d2:split('these-are-testing-values', '-', 2) = testing", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'EzkFLDtAxCR', message: 'd2:modulus( 12 , 100 ) = 12' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'RCYEyOly0Mi', message: "d2:countIfValue( #{gender}, 'Male' ) = 0" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'bRnjbxIwIRd', message: 'd2:round( 12.5 ) = 13' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'BuEcHNoD98P', message: 'd2:ceil(11.3) = 12' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Foc3PhzoAVr', message: 'd2:count(#{age}) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'QpeF2WDjwIV', message: "d2:addDays( '2020-01-12', 5 ) = 2020-01-17" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'WJTjezLR4cJ', message: "d2:weeksBetween('2020-01-28', V{event_date} ) = " }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'YnE4dNJVF2P', message: 'd2:zing( -2 ) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'bZsv2cUkbB7', message: 'd2:floor( 11.5 ) = 11' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'J8RxAbHlnO3', message: 'd2:oizp( 10000000 ) = 1' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'NT1wojA2RdT', + message: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking') = dhis2isrocking", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'NUGe7EUVouK', message: "d2:substring('hello dhis 2', 6, 10) = dhis" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Ma6nCIGrBrd', message: "d2:length( 'dhis2 rocks' ) = 11" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'RRSDsxWiUMc', message: 'd2:round( 0 ) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'QUe0Pks4ckc', message: 'd2:countIfValue( #{age}, 1 ) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'sHaE1YI0ur2', message: 'd2:zing( 1000 ) = 1000' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'EojHcBMpW7q', message: 'd2:hasValue( #{age} ) = ' }, + }, ], ], [ { - oZg33kd9taw: 'Male', qrur9Dvnyt5: 0, occurredAt: '2020-04-30T22:00:00.000Z', + oZg33kd9taw: 'Male', + qrur9Dvnyt5: 0, + occurredAt: '2020-04-30T22:00:00.000Z', }, [ - { type: 'DISPLAYTEXT', displayText: { id: 'isP0uvT24jf', message: "d2:yearsBetween( '2010-01-28', V{event_date}) = 10" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'vQCRnX6w9pM', message: 'd2:oizp( -10000000 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'SYAL0GIDnxI', message: 'display age = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'Xa0tKyNk5YE', message: 'org_unit = OU_559' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'JXssEpbJdO2', message: 'd2:right(#{age}, 3) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'o0LLNIYsliy', message: "d2:monthsBetween( '2020-01-28', V{event_date}) = 3" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'k07KnI11Sf4', message: 'd2:left(#{age}, 3) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'OITs4nPfMQ3', message: "d2:split('these-are-testing-values', '-', 2) = testing" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'EzkFLDtAxCR', message: 'd2:modulus( 12 , 100 ) = 12' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'RCYEyOly0Mi', message: "d2:countIfValue( #{gender}, 'Male' ) = 1" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'bRnjbxIwIRd', message: 'd2:round( 12.5 ) = 13' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'BuEcHNoD98P', message: 'd2:ceil(11.3) = 12' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'Foc3PhzoAVr', message: 'd2:count(#{age}) = 1' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'QpeF2WDjwIV', message: "d2:addDays( '2020-01-12', 5 ) = 2020-01-17" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'WJTjezLR4cJ', message: "d2:weeksBetween('2020-01-28', V{event_date} ) = 13" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'YnE4dNJVF2P', message: 'd2:zing( -2 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'bZsv2cUkbB7', message: 'd2:floor( 11.5 ) = 11' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'J8RxAbHlnO3', message: 'd2:oizp( 10000000 ) = 1' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'NT1wojA2RdT', message: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking') = dhis2isrocking" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'NUGe7EUVouK', message: "d2:substring('hello dhis 2', 6, 10) = dhis" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'Ma6nCIGrBrd', message: "d2:length( 'dhis2 rocks' ) = 11" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'RRSDsxWiUMc', message: 'd2:round( 0 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'QUe0Pks4ckc', message: 'd2:countIfValue( #{age}, 1 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'sHaE1YI0ur2', message: 'd2:zing( 1000 ) = 1000' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'EojHcBMpW7q', message: 'd2:hasValue( #{age} ) = true' } }, + { + type: 'DISPLAYTEXT', + displayText: { id: 'isP0uvT24jf', message: "d2:yearsBetween( '2010-01-28', V{event_date}) = 10" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'vQCRnX6w9pM', message: 'd2:oizp( -10000000 ) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'SYAL0GIDnxI', message: 'display age = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Xa0tKyNk5YE', message: 'org_unit = OU_559' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'JXssEpbJdO2', message: 'd2:right(#{age}, 3) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'o0LLNIYsliy', message: "d2:monthsBetween( '2020-01-28', V{event_date}) = 3" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'k07KnI11Sf4', message: 'd2:left(#{age}, 3) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'OITs4nPfMQ3', + message: "d2:split('these-are-testing-values', '-', 2) = testing", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'EzkFLDtAxCR', message: 'd2:modulus( 12 , 100 ) = 12' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'RCYEyOly0Mi', message: "d2:countIfValue( #{gender}, 'Male' ) = 1" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'bRnjbxIwIRd', message: 'd2:round( 12.5 ) = 13' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'BuEcHNoD98P', message: 'd2:ceil(11.3) = 12' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Foc3PhzoAVr', message: 'd2:count(#{age}) = 1' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'QpeF2WDjwIV', message: "d2:addDays( '2020-01-12', 5 ) = 2020-01-17" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'WJTjezLR4cJ', message: "d2:weeksBetween('2020-01-28', V{event_date} ) = 13" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'YnE4dNJVF2P', message: 'd2:zing( -2 ) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'bZsv2cUkbB7', message: 'd2:floor( 11.5 ) = 11' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'J8RxAbHlnO3', message: 'd2:oizp( 10000000 ) = 1' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'NT1wojA2RdT', + message: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking') = dhis2isrocking", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'NUGe7EUVouK', message: "d2:substring('hello dhis 2', 6, 10) = dhis" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Ma6nCIGrBrd', message: "d2:length( 'dhis2 rocks' ) = 11" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'RRSDsxWiUMc', message: 'd2:round( 0 ) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'QUe0Pks4ckc', message: 'd2:countIfValue( #{age}, 1 ) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'sHaE1YI0ur2', message: 'd2:zing( 1000 ) = 1000' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'EojHcBMpW7q', message: 'd2:hasValue( #{age} ) = true' }, + }, ], ], [ { - oZg33kd9taw: 'Male', qrur9Dvnyt5: 1000000000, occurredAt: '2020-04-30T22:00:00.000Z', + oZg33kd9taw: 'Male', + qrur9Dvnyt5: 1000000000, + occurredAt: '2020-04-30T22:00:00.000Z', }, [ - { type: 'DISPLAYTEXT', displayText: { id: 'isP0uvT24jf', message: "d2:yearsBetween( '2010-01-28', V{event_date}) = 10" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'vQCRnX6w9pM', message: 'd2:oizp( -10000000 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'SYAL0GIDnxI', message: 'display age = 1000000000' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'Xa0tKyNk5YE', message: 'org_unit = OU_559' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'JXssEpbJdO2', message: 'd2:right(#{age}, 3) = 000' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'o0LLNIYsliy', message: "d2:monthsBetween( '2020-01-28', V{event_date}) = 3" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'k07KnI11Sf4', message: 'd2:left(#{age}, 3) = 100' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'OITs4nPfMQ3', message: "d2:split('these-are-testing-values', '-', 2) = testing" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'EzkFLDtAxCR', message: 'd2:modulus( 12 , 100 ) = 12' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'RCYEyOly0Mi', message: "d2:countIfValue( #{gender}, 'Male' ) = 1" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'bRnjbxIwIRd', message: 'd2:round( 12.5 ) = 13' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'BuEcHNoD98P', message: 'd2:ceil(11.3) = 12' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'Foc3PhzoAVr', message: 'd2:count(#{age}) = 1' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'QpeF2WDjwIV', message: "d2:addDays( '2020-01-12', 5 ) = 2020-01-17" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'WJTjezLR4cJ', message: "d2:weeksBetween('2020-01-28', V{event_date} ) = 13" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'YnE4dNJVF2P', message: 'd2:zing( -2 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'bZsv2cUkbB7', message: 'd2:floor( 11.5 ) = 11' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'J8RxAbHlnO3', message: 'd2:oizp( 10000000 ) = 1' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'NT1wojA2RdT', message: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking') = dhis2isrocking" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'NUGe7EUVouK', message: "d2:substring('hello dhis 2', 6, 10) = dhis" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'Ma6nCIGrBrd', message: "d2:length( 'dhis2 rocks' ) = 11" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'RRSDsxWiUMc', message: 'd2:round( 0 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'QUe0Pks4ckc', message: 'd2:countIfValue( #{age}, 1 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'sHaE1YI0ur2', message: 'd2:zing( 1000 ) = 1000' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'EojHcBMpW7q', message: 'd2:hasValue( #{age} ) = true' } }, + { + type: 'DISPLAYTEXT', + displayText: { id: 'isP0uvT24jf', message: "d2:yearsBetween( '2010-01-28', V{event_date}) = 10" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'vQCRnX6w9pM', message: 'd2:oizp( -10000000 ) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'SYAL0GIDnxI', message: 'display age = 1000000000' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Xa0tKyNk5YE', message: 'org_unit = OU_559' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'JXssEpbJdO2', message: 'd2:right(#{age}, 3) = 000' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'o0LLNIYsliy', message: "d2:monthsBetween( '2020-01-28', V{event_date}) = 3" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'k07KnI11Sf4', message: 'd2:left(#{age}, 3) = 100' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'OITs4nPfMQ3', + message: "d2:split('these-are-testing-values', '-', 2) = testing", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'EzkFLDtAxCR', message: 'd2:modulus( 12 , 100 ) = 12' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'RCYEyOly0Mi', message: "d2:countIfValue( #{gender}, 'Male' ) = 1" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'bRnjbxIwIRd', message: 'd2:round( 12.5 ) = 13' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'BuEcHNoD98P', message: 'd2:ceil(11.3) = 12' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Foc3PhzoAVr', message: 'd2:count(#{age}) = 1' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'QpeF2WDjwIV', message: "d2:addDays( '2020-01-12', 5 ) = 2020-01-17" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'WJTjezLR4cJ', message: "d2:weeksBetween('2020-01-28', V{event_date} ) = 13" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'YnE4dNJVF2P', message: 'd2:zing( -2 ) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'bZsv2cUkbB7', message: 'd2:floor( 11.5 ) = 11' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'J8RxAbHlnO3', message: 'd2:oizp( 10000000 ) = 1' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'NT1wojA2RdT', + message: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking') = dhis2isrocking", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'NUGe7EUVouK', message: "d2:substring('hello dhis 2', 6, 10) = dhis" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Ma6nCIGrBrd', message: "d2:length( 'dhis2 rocks' ) = 11" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'RRSDsxWiUMc', message: 'd2:round( 0 ) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'QUe0Pks4ckc', message: 'd2:countIfValue( #{age}, 1 ) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'sHaE1YI0ur2', message: 'd2:zing( 1000 ) = 1000' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'EojHcBMpW7q', message: 'd2:hasValue( #{age} ) = true' }, + }, ], ], ])('where functions take place', (currentEvent, expected) => { @@ -485,8 +2280,71 @@ describe('Event rules engine effects with functions and effects', () => { describe('Event rules engine effects with functions and effects', () => { // these variables are shared between each test const constants = []; - const dataElementsInProgram = { oZg33kd9taw: { id: 'oZg33kd9taw', valueType: 'TEXT', optionSetId: 'pC3N9N77UmT' }, SWfdB5lX0fk: { id: 'SWfdB5lX0fk', valueType: 'BOOLEAN' }, qrur9Dvnyt5: { id: 'qrur9Dvnyt5', valueType: 'INTEGER' }, GieVkTxp4HH: { id: 'GieVkTxp4HH', valueType: 'NUMBER' }, vV9UWAZohSf: { id: 'vV9UWAZohSf', valueType: 'INTEGER_POSITIVE' }, eMyVanycQSC: { id: 'eMyVanycQSC', valueType: 'DATE' }, K6uUAvq500H: { id: 'K6uUAvq500H', valueType: 'TEXT', optionSetId: 'eUZ79clX7y1' }, msodh3rEMJa: { id: 'msodh3rEMJa', valueType: 'DATE' }, S33cRBsnXPo: { id: 'S33cRBsnXPo', valueType: 'ORGANISATION_UNIT' }, fWIAEtYVEGk: { id: 'fWIAEtYVEGk', valueType: 'TEXT', optionSetId: 'iDFPKpFTiVw' }, ulD2zW0TIy2: { id: 'ulD2zW0TIy2', valueType: 'FILE_RESOURCE' } }; - const programRules = [{ id: 'cq1dwUY4lVU', condition: 'true', displayName: 'testing the z-scores', programId: 'eBAyeGv0exc', programRuleActions: [{ id: 'I6pDcSm2m0g', displayContent: "d2:zScoreWFA( 20, 15, 'M' ) = ", data: "d2:zScoreWFA( 20, 15, 'M' )", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'No0T9TgN1Px', displayContent: "d2:zScoreWFH( 100, 20, 'M' ) = ", data: "d2:zScoreWFH( 100, 20, 'M' )", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'n1GUxR8fShY', displayContent: "d2:zScoreHFA( 15, 20, 'F' ) =", data: "d2:zScoreHFA( 15, 20, 'F' ) ", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'QJlZHo0GoVK', displayContent: "d2:zScoreWFH( 100, 20, 'F' ) = ", data: "d2:zScoreWFH( 100, 20, 'F' ) ", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'ItuKGBUuJgK', displayContent: "d2:zScoreWFA( 20, 15, 'F' ) = ", data: "d2:zScoreWFA( 20, 15, 'F' )", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, { id: 'uhyaCDzzivm', displayContent: "d2:zScoreHFA( 15, 20, 'M' ) =", data: "d2:zScoreHFA( 15, 20, 'M' )", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }] }]; + const dataElementsInProgram = { + oZg33kd9taw: { id: 'oZg33kd9taw', valueType: 'TEXT', optionSetId: 'pC3N9N77UmT' }, + SWfdB5lX0fk: { id: 'SWfdB5lX0fk', valueType: 'BOOLEAN' }, + qrur9Dvnyt5: { id: 'qrur9Dvnyt5', valueType: 'INTEGER' }, + GieVkTxp4HH: { id: 'GieVkTxp4HH', valueType: 'NUMBER' }, + vV9UWAZohSf: { id: 'vV9UWAZohSf', valueType: 'INTEGER_POSITIVE' }, + eMyVanycQSC: { id: 'eMyVanycQSC', valueType: 'DATE' }, + K6uUAvq500H: { id: 'K6uUAvq500H', valueType: 'TEXT', optionSetId: 'eUZ79clX7y1' }, + msodh3rEMJa: { id: 'msodh3rEMJa', valueType: 'DATE' }, + S33cRBsnXPo: { id: 'S33cRBsnXPo', valueType: 'ORGANISATION_UNIT' }, + fWIAEtYVEGk: { id: 'fWIAEtYVEGk', valueType: 'TEXT', optionSetId: 'iDFPKpFTiVw' }, + ulD2zW0TIy2: { id: 'ulD2zW0TIy2', valueType: 'FILE_RESOURCE' }, + }; + const programRules = [ + { + id: 'cq1dwUY4lVU', + condition: 'true', + displayName: 'testing the z-scores', + programId: 'eBAyeGv0exc', + programRuleActions: [ + { + id: 'I6pDcSm2m0g', + displayContent: "d2:zScoreWFA( 20, 15, 'M' ) = ", + data: "d2:zScoreWFA( 20, 15, 'M' )", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'No0T9TgN1Px', + displayContent: "d2:zScoreWFH( 100, 20, 'M' ) = ", + data: "d2:zScoreWFH( 100, 20, 'M' )", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'n1GUxR8fShY', + displayContent: "d2:zScoreHFA( 15, 20, 'F' ) =", + data: "d2:zScoreHFA( 15, 20, 'F' ) ", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'QJlZHo0GoVK', + displayContent: "d2:zScoreWFH( 100, 20, 'F' ) = ", + data: "d2:zScoreWFH( 100, 20, 'F' ) ", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'ItuKGBUuJgK', + displayContent: "d2:zScoreWFA( 20, 15, 'F' ) = ", + data: "d2:zScoreWFA( 20, 15, 'F' )", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'uhyaCDzzivm', + displayContent: "d2:zScoreHFA( 15, 20, 'M' ) =", + data: "d2:zScoreHFA( 15, 20, 'M' )", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + ], + }, + ]; const programRuleVariables = []; const orgUnit = { id: 'DiszpKrYNg8', name: 'Ngelehun CHC' }; const optionSets = {}; @@ -505,12 +2363,36 @@ describe('Event rules engine effects with functions and effects', () => { // then expect(rulesEffects).toEqual([ - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'I6pDcSm2m0g', message: "d2:zScoreWFA( 20, 15, 'M' ) = 2.47" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'No0T9TgN1Px', message: "d2:zScoreWFH( 100, 20, 'M' ) = 3.5" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'n1GUxR8fShY', message: "d2:zScoreHFA( 15, 20, 'F' ) = -3.5" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'QJlZHo0GoVK', message: "d2:zScoreWFH( 100, 20, 'F' ) = 2.84" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'ItuKGBUuJgK', message: "d2:zScoreWFA( 20, 15, 'F' ) = 2.65" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'uhyaCDzzivm', message: "d2:zScoreHFA( 15, 20, 'M' ) = -3.5" } }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'I6pDcSm2m0g', message: "d2:zScoreWFA( 20, 15, 'M' ) = 2.47" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'No0T9TgN1Px', message: "d2:zScoreWFH( 100, 20, 'M' ) = 3.5" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'n1GUxR8fShY', message: "d2:zScoreHFA( 15, 20, 'F' ) = -3.5" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'QJlZHo0GoVK', message: "d2:zScoreWFH( 100, 20, 'F' ) = 2.84" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'ItuKGBUuJgK', message: "d2:zScoreWFA( 20, 15, 'F' ) = 2.65" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'uhyaCDzzivm', message: "d2:zScoreHFA( 15, 20, 'M' ) = -3.5" }, + }, ]); }); }); @@ -519,7 +2401,11 @@ describe('Event rules engine effects with functions and effects', () => { describe('Event rules engine', () => { // these variables are shared between each test const constants = []; - const dataElementsInProgram = { oZg33kd9taw: { id: 'oZg33kd9taw', valueType: 'BOOLEAN' }, SWfdB5lX0fk: { id: 'SWfdB5lX0fk', valueType: 'TRUE_ONLY' }, qrur9Dvnyt5: { id: 'qrur9Dvnyt5', valueType: 'NUMBER' } }; + const dataElementsInProgram = { + oZg33kd9taw: { id: 'oZg33kd9taw', valueType: 'BOOLEAN' }, + SWfdB5lX0fk: { id: 'SWfdB5lX0fk', valueType: 'TRUE_ONLY' }, + qrur9Dvnyt5: { id: 'qrur9Dvnyt5', valueType: 'NUMBER' }, + }; const programRuleVariables = []; const orgUnit = { id: 'DiszpKrYNg8', name: 'Ngelehun CHC' }; const optionSets = {}; @@ -527,50 +2413,110 @@ describe('Event rules engine', () => { describe.each([ [ - [{ - id: 'cq1dwUY4lVU', - condition: 'true', - displayName: 'testing assign actions', - programId: 'eBAyeGv0exc', - programRuleActions: [ - { id: 'lJOYxhjupxz', data: 'true', dataElementId: 'oZg33kd9taw', programRuleActionType: 'ASSIGN' }, - { id: 'lJOYxhjupx1', data: 'true', dataElementId: 'SWfdB5lX0fk', programRuleActionType: 'ASSIGN' }, - { id: 'lJOYxhjupx2', data: '6', dataElementId: 'qrur9Dvnyt5', programRuleActionType: 'ASSIGN' }, - ], - }], [ - { type: 'ASSIGN', id: 'oZg33kd9taw', value: 'true', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'ASSIGN', id: 'SWfdB5lX0fk', value: 'true', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'ASSIGN', id: 'qrur9Dvnyt5', value: '6', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, + { + id: 'cq1dwUY4lVU', + condition: 'true', + displayName: 'testing assign actions', + programId: 'eBAyeGv0exc', + programRuleActions: [ + { + id: 'lJOYxhjupxz', + data: 'true', + dataElementId: 'oZg33kd9taw', + programRuleActionType: 'ASSIGN', + }, + { + id: 'lJOYxhjupx1', + data: 'true', + dataElementId: 'SWfdB5lX0fk', + programRuleActionType: 'ASSIGN', + }, + { id: 'lJOYxhjupx2', data: '6', dataElementId: 'qrur9Dvnyt5', programRuleActionType: 'ASSIGN' }, + ], + }, ], - ], [ - [{ - id: 'cq1dwUY4lVU', - condition: 'true', - displayName: 'testing assign actions', - programId: 'eBAyeGv0exc', - programRuleActions: [ - { id: 'lJOYxhjupxz', data: '', dataElementId: 'oZg33kd9taw', programRuleActionType: 'ASSIGN' }, - { id: 'lJOYxhjupx1', data: '', dataElementId: 'SWfdB5lX0fk', programRuleActionType: 'ASSIGN' }, - { id: 'lJOYxhjupx2', data: '', dataElementId: 'qrur9Dvnyt5', programRuleActionType: 'ASSIGN' }, - ], - }], [ - { type: 'ASSIGN', id: 'oZg33kd9taw', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'ASSIGN', id: 'SWfdB5lX0fk', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, - { type: 'ASSIGN', id: 'qrur9Dvnyt5', value: null, targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }, + { + type: 'ASSIGN', + id: 'oZg33kd9taw', + value: 'true', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'ASSIGN', + id: 'SWfdB5lX0fk', + value: 'true', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'ASSIGN', + id: 'qrur9Dvnyt5', + value: '6', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + ], + ], + [ + [ + { + id: 'cq1dwUY4lVU', + condition: 'true', + displayName: 'testing assign actions', + programId: 'eBAyeGv0exc', + programRuleActions: [ + { id: 'lJOYxhjupxz', data: '', dataElementId: 'oZg33kd9taw', programRuleActionType: 'ASSIGN' }, + { id: 'lJOYxhjupx1', data: '', dataElementId: 'SWfdB5lX0fk', programRuleActionType: 'ASSIGN' }, + { id: 'lJOYxhjupx2', data: '', dataElementId: 'qrur9Dvnyt5', programRuleActionType: 'ASSIGN' }, + ], + }, + ], + [ + { + type: 'ASSIGN', + id: 'oZg33kd9taw', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'ASSIGN', + id: 'SWfdB5lX0fk', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + { + type: 'ASSIGN', + id: 'qrur9Dvnyt5', + value: null, + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, + ], + ], + [ + [ + { + id: 'cq1dwUY4lVU', + condition: 'true', + displayName: 'testing assign actions', + programId: 'eBAyeGv0exc', + programRuleActions: [ + { + id: 'lJOYxhjupxz', + data: 'false', + dataElementId: 'oZg33kd9taw', + programRuleActionType: 'ASSIGN', + }, + ], + }, + ], + [ + { + type: 'ASSIGN', + id: 'oZg33kd9taw', + value: 'false', + targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT, + }, ], - ], [ - [{ - id: 'cq1dwUY4lVU', - condition: 'true', - displayName: 'testing assign actions', - programId: 'eBAyeGv0exc', - programRuleActions: [ - { id: 'lJOYxhjupxz', data: 'false', dataElementId: 'oZg33kd9taw', programRuleActionType: 'ASSIGN' }, - ], - }], - [{ type: 'ASSIGN', id: 'oZg33kd9taw', value: 'false', targetDataType: rulesEngineEffectTargetDataTypes.DATA_ELEMENT }], ], ])('where assign actions are triggered', (programRules, expected) => { test(`with given value(s): ${JSON.stringify(programRules)}`, () => { @@ -586,3 +2532,393 @@ describe('Event rules engine', () => { }); }); }); + +describe('Assign effects', () => { + // these variables are shared between each test + const constants = []; + const dataElementsInProgram = { + qrur9Dvnyt5: { id: 'qrur9Dvnyt5', valueType: 'NUMBER' }, + hrur9Dvnyt5: { id: 'hrur9Dvnyt5', valueType: 'TRUE_ONLY' }, + g67r9Dvnyt5: { id: 'g67r9Dvnyt5', valueType: 'TRUE_ONLY' }, + sfer9Dvnyt5: { id: 'sfer9Dvnyt5', valueType: 'LONG_TEXT' }, + oZg33kd9taw: { id: 'oZg33kd9taw', valueType: 'BOOLEAN' }, + hjrr9Dvnyt5: { id: 'hjrr9Dvnyt5', valueType: 'LETTER' }, + lowr9Dvnyt5: { id: 'lowr9Dvnyt5', valueType: 'PHONE_NUMBER' }, + kht29Dvnyt5: { id: 'kht29Dvnyt5', valueType: 'EMAIL' }, + hyrt9Dvnyt5: { id: 'hyrt9Dvnyt5', valueType: 'DATE' }, + loir9Dvnyt5: { id: 'loir9Dvnyt5', valueType: 'DATETIME' }, + sldkjfjfjfe: { id: 'sldkjfjfjfe', valueType: 'TIME' }, + kyt49Dvnyt5: { id: 'kyt49Dvnyt5', valueType: 'PERCENTAGE' }, + kiyu9Dvnyt5: { id: 'kiyu9Dvnyt5', valueType: 'INTEGER' }, + frt59Dvnyt5: { id: 'frt59Dvnyt5', valueType: 'INTEGER_POSITIVE' }, + jhty9Dvnyt5: { id: 'jhty9Dvnyt5', valueType: 'INTEGER_NEGATIVE' }, + jhrr9Dvnyt5: { id: 'jhrr9Dvnyt5', valueType: 'INTEGER_ZERO_OR_POSITIVE' }, + plor9Dvnyt5: { id: 'plor9Dvnyt5', valueType: 'USERNAME' }, + frg39Dvnyt5: { id: 'frg39Dvnyt5', valueType: 'COORDINATE' }, + kjyu9Dvnyt5: { id: 'kjyu9Dvnyt5', valueType: 'ORGANISATION_UNIT' }, + kjfr9Dvnyt5: { id: 'kjfr9Dvnyt5', valueType: 'AGE' }, + lqwr9Dvnyt5: { id: 'lqwr9Dvnyt5', valueType: 'URL' }, + mjus9Dvnyt5: { id: 'mjus9Dvnyt5', valueType: 'FILE_RESOURCE' }, + fgrr9Dvnyt5: { id: 'fgrr9Dvnyt5', valueType: 'IMAGE' }, + oZ3fhkd9taw: { id: 'oZ3fhkd9taw', valueType: 'UNKNOWN' }, + }; + const orgUnit = { id: 'DiszpKrYNg8', name: 'Ngelehun CHC' }; + const optionSets = {}; + const currentEvent = {}; + + test('Assign effect corner cases', () => { + const programRules = [ + { + id: 'cq1dwUY4lVU', + condition: 'true', + displayName: 'testing assign actions', + programId: 'eBAyeGv0exc', + programRuleActions: [ + { + id: 'lJOYxhjupx2', + data: "'string'", + dataElementId: 'qrur9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { id: 'lJOYxkjupx2', data: "'10'", dataElementId: 'qrur9Dvnyt5', programRuleActionType: 'ASSIGN' }, + { + id: 'lJhYxhjupxz', + data: "'string'", + dataElementId: 'oZg33kd9taw', + programRuleActionType: 'ASSIGN', + }, + { + id: 'lJfYxhjupxz', + data: "'string'", + dataElementId: 'oZ3fhkd9taw', + programRuleActionType: 'ASSIGN', + }, + { + id: 'sdfsd34567h', + data: 'value', + dataElementId: 'hrur9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'g67rgyvnyt5', + data: null, + dataElementId: 'g67r9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'fsafYxhjux2', + data: "'LONG_TEXT'", + dataElementId: 'sfer9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'o8rr9Dvnyt5', + data: "'LETTER'", + dataElementId: 'hjrr9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'lsdjlks4ffs', + data: '34535353', + dataElementId: 'lowr9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'hsjd7574jfj', + data: 'test@test.com', + dataElementId: 'kht29Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'sdf57549jco', + data: '11-11-2013', + dataElementId: 'hyrt9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'gtir9Dvnyt5', + data: '2021-05-31', + dataElementId: 'loir9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 's678jfjfjfe', + data: '11:11', + dataElementId: 'sldkjfjfjfe', + programRuleActionType: 'ASSIGN', + }, + { + id: 'sdhsfjks35f', + data: '30', + dataElementId: 'kyt49Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'kjosfjks35f', + data: '30', + dataElementId: 'kiyu9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'kjyofjks35f', + data: '30', + dataElementId: 'frt59Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'jhkj9Dvnyt5', + data: '-30', + dataElementId: 'jhty9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'hjyur9Dvnyt5', + data: '-30', + dataElementId: 'jhrr9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'lopr9Dvnyt5', + data: 'username', + dataElementId: 'plor9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'kjy39Dvnyt5', + data: "'12,4343'", + dataElementId: 'frg39Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'loiu9Dvnyt5', + data: 'ORGANISATION_UNIT', + dataElementId: 'kjyu9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'kjfr9Dvnyt5', + data: 'Invalid date', + dataElementId: 'kjfr9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'hywr9Dvnyt5', + data: 'urlPath', + dataElementId: 'lqwr9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'gt769Dvnyt5', + data: 'FILE_RESOURCE', + dataElementId: 'mjus9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + { + id: 'gt659Dvnyt5', + data: 'IMAGE', + dataElementId: 'fgrr9Dvnyt5', + programRuleActionType: 'ASSIGN', + }, + ], + }, + ]; + const programRuleVariables = []; + systemSettingsStore.set({ dateFormat: 'YYYY-MM-DD' }); + // when + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + currentEvent, + dataElements: dataElementsInProgram, + selectedOrgUnit: orgUnit, + optionSets, + }); + + // then + expect(rulesEffects).toEqual([ + { type: 'ASSIGN', id: 'qrur9Dvnyt5', value: null, targetDataType: 'dataElement' }, + { type: 'ASSIGN', id: 'qrur9Dvnyt5', value: '10', targetDataType: 'dataElement' }, + { type: 'ASSIGN', id: 'oZg33kd9taw', value: 'false', targetDataType: 'dataElement' }, + { type: 'ASSIGN', id: 'oZ3fhkd9taw', value: '', targetDataType: 'dataElement' }, + { + id: 'hrur9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: 'false', + }, + { + id: 'g67r9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: null, + }, + { + id: 'sfer9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: 'LONG_TEXT', + }, + { + id: 'hjrr9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: 'LETTER', + }, + { + id: 'lowr9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: 34535353, + }, + { + id: 'kht29Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: false, + }, + { + id: 'hyrt9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: '2013-01-01', + }, + { + id: 'loir9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: { + date: 'Invalid date', + time: 'Invalid date', + }, + }, + { + id: 'sldkjfjfjfe', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: false, + }, + { + id: 'kyt49Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: '30', + }, + { + id: 'kiyu9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: '30', + }, + { + id: 'frt59Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: '30', + }, + { + id: 'jhty9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: '-30', + }, + { + id: 'jhrr9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: '-30', + }, + { + id: 'plor9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: '', + }, + { + id: 'frg39Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: { + latitude: 2, + longitude: 434, + }, + }, + { + id: 'kjyu9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: '', + }, + { + id: 'kjfr9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: { + date: 'Invalid date', + days: 'NaN', + months: 'NaN', + years: 'NaN', + }, + }, + { + id: 'lqwr9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: false, + }, + { + id: 'mjus9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: '', + }, + { + id: 'fgrr9Dvnyt5', + targetDataType: 'dataElement', + type: 'ASSIGN', + value: '', + }, + ]); + }); + + test('Assign effect with the program rule variable id found in the content key', () => { + const programRules = [ + { + id: 'cq1dwUY4lVU', + condition: 'true', + displayName: 'testing assign actions', + programId: 'eBAyeGv0exc', + programRuleActions: [ + { + id: 'lJOYxhjupx2', + data: 'rowExpresion', + dataElementId: 'qrur9Dvnyt5', + programRuleActionType: 'ASSIGN', + content: 'Hemoglobin value lower than normal RycV5uDi66i', + }, + ], + }, + ]; + const programRuleVariables = [ + { + id: 'RycV5uDi66i', + dataElementId: 'qrur9Dvnyt5', + displayName: 'age', + programId: 'eBAyeGv0exc', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, + useNameForOptionSet: true, + }, + ]; + // when + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + currentEvent, + dataElements: dataElementsInProgram, + selectedOrgUnit: orgUnit, + optionSets, + }); + + // then + expect(rulesEffects).toEqual([ + { type: 'ASSIGN', id: 'qrur9Dvnyt5', value: 'false', targetDataType: 'dataElement' }, + ]); + }); +}); diff --git a/src/core_modules/capture-core/rules/__tests__/rulesEffectsForTrackerProgram.test.js b/src/core_modules/capture-core/rules/__tests__/rulesEffectsForTrackerProgram.test.js index bbd2514ae8..213c6c5abf 100644 --- a/src/core_modules/capture-core/rules/__tests__/rulesEffectsForTrackerProgram.test.js +++ b/src/core_modules/capture-core/rules/__tests__/rulesEffectsForTrackerProgram.test.js @@ -1,78 +1,865 @@ +import { variableSourceTypes } from '@dhis2/rules-engine-javascript'; import { rulesEngine } from '../rulesEngine'; test('expressions with d2Functions in tracker program', () => { // given const constants = []; - const trackedEntityAttributes = { w75KJ2mc4zz: { id: 'w75KJ2mc4zz', valueType: 'TEXT' }, zDhUuAYrxNC: { id: 'zDhUuAYrxNC', valueType: 'TEXT' }, cejWyOfXge6: { id: 'cejWyOfXge6', valueType: 'TEXT', optionSetId: 'pC3N9N77UmT' }, lZGmxYbs97q: { id: 'lZGmxYbs97q', valueType: 'NUMBER' } }; - const programRules = [{ - id: 'g82J3xsNer9', - condition: 'true', - displayName: 'Testing the functions!', - programId: 'IpHINAT79UW', - programRuleActions: [ - { id: 'Eeb7Ixr4Pvx', displayContent: "d2:left('dhis', 3) = ", data: "d2:left('dhis', 3)", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'lbIGJYVI57u', displayContent: 'd2:zing( -2 ) = ', data: 'd2:zing( -2 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'kwKhYpVRDyj', displayContent: "d2:monthsBetween( '2020-01-28', V{enrollment_date}) = ", data: "d2:monthsBetween( '2020-01-28', V{enrollment_date})", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'AFkfzcDf4Fs', displayContent: "d2:inOrgUnitGroup('CHC') = ", data: "d2:inOrgUnitGroup('CHC')", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'wmAQnxbs7V8', displayContent: 'd2:round( 12.5 ) = ', data: 'd2:round( 12.5 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'tFGwyDBQk3b', displayContent: 'd2:round( 0 ) = ', data: 'd2:round( 0 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'NSQV537qvyu', displayContent: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking') = ", data: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking')", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'M7vYMD5uNwD', displayContent: 'd2:ceil(11.3) = ', data: 'd2:ceil(11.3)', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'cgdUEJkqq0J', displayContent: "d2:yearsBetween( '2010-01-28', V{enrollment_date}) = ", data: "d2:yearsBetween( '2010-01-28', V{enrollment_date})", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'xZpYbFPXWG2', displayContent: 'd2:zing( 1000 ) = ', data: 'd2:zing( 1000 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'IGpzruAKVzk', displayContent: "d2:split('these-are-testing-values', '-', 2) = ", data: "d2:split('these-are-testing-values', '-', 2)", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'NLsawa3P5hc', displayContent: "d2:substring('hello dhis 2', 6, 10) = ", data: "d2:substring('hello dhis 2', 6, 10)", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'i0OgulFyVPQ', displayContent: 'd2:oizp( -10000000 ) = ', data: 'd2:oizp( -10000000 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'PqzKFmEMmuz', displayContent: "d2:right('dhis', 3) = ", data: "d2:right('dhis', 3)", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'xIUDr1lRV6N', displayContent: "d2:addDays( '2018-04-20', 100 ) = ", data: "d2:addDays( '2018-04-20', 100 )", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'RXmprywJ0Rb', displayContent: 'd2:floor( 11.5 ) = ', data: 'd2:floor( 11.5 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'cZQngI2IC1a', displayContent: "d2:length( 'dhis2 rocks' ) = ", data: "d2:length( 'dhis2 rocks' )", location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'qSe8GmlwpgZ', displayContent: "d2:weeksBetween('2020-01-28', V{enrollment_date} ) = ", data: "d2:weeksBetween('2020-01-28', V{enrollment_date} )", location: 'feedback', programRuleActionType: 'DISPLAYKEYVALUEPAIR' }, - { id: 'Tx4gHcLselM', displayContent: 'd2:oizp( 10000000 ) = ', data: 'd2:oizp( 10000000 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'f3MrrcCf1z2', displayContent: 'd2:modulus( 12 , 100 ) = ', data: 'd2:modulus( 12 , 100 )', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'Eeb7Ixr4Pv6', displayContent: 'd2:floor((5+5) / 2) = ', data: 'd2:floor((5+5) / 2)', location: 'feedback', programRuleActionType: 'DISPLAYTEXT' }, - { id: 'nKNmayYigcy', programStageId: 'PUZaKR0Jh2k', programRuleActionType: 'HIDEPROGRAMSTAGE' }, - ], - }]; - const programRulesVariables = []; + const trackedEntityAttributes = { + w75KJ2mc4zz: { id: 'w75KJ2mc4zz', valueType: 'TEXT' }, + zDhUuAYrxNC: { id: 'zDhUuAYrxNC', valueType: 'TEXT' }, + cejWyOfXge6: { id: 'cejWyOfXge6', valueType: 'TEXT', optionSetId: 'pC3N9N77UmT' }, + lZGmxYbs97q: { id: 'lZGmxYbs97q', valueType: 'NUMBER' }, + Z5z8vFQy0w0: { id: 'Z5z8vFQy0w0', valueType: 'URL' }, + TzqawmlPkI5: { id: 'TzqawmlPkI5', valueType: 'AGE' }, + f8j4XDEozvj: { id: 'f8j4XDEozvj', valueType: 'FILE_RESOURCE' }, + jBBkFuPKctq: { id: 'jBBkFuPKctq', valueType: 'ORGANISATION_UNIT' }, + A4Fg6jgWauf: { id: 'A4Fg6jgWauf', valueType: 'IMAGE' }, + CUbZcLm9LyN: { id: 'CUbZcLm9LyN', valueType: 'USERNAME' }, + p8htbyJHydl: { id: 'p8htbyJHydl', valueType: 'COORDINATE' }, + }; + const programRules = [ + { + id: 'g82J3xsNer9', + condition: 'true', + displayName: 'Testing the functions!', + programId: 'IpHINAT79UW', + programRuleActions: [ + { + id: 'Eeb7Ixr4Pvx', + displayContent: "d2:left('dhis', 3) = ", + data: "d2:left('dhis', 3)", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'lbIGJYVI57u', + displayContent: 'd2:zing( -2 ) = ', + data: 'd2:zing( -2 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'kwKhYpVRDyj', + displayContent: "d2:monthsBetween( '2020-01-28', V{enrollment_date}) = ", + data: "d2:monthsBetween( '2020-01-28', V{enrollment_date})", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'polhYpVRDyj', + displayContent: "d2:daysBetween( '2020-01-28', V{enrollment_date}) = ", + data: "d2:daysBetween( '2020-01-28', V{enrollment_date})", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'FkeGdlkYAVr', + displayContent: "d2:validatePattern('d2:daysBetween( '2020-01-28', V{enrollment_date})', 108)", + data: "d2:validatePattern(d2:daysBetween( '2020-01-28', V{enrollment_date}), 108)", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'Foc3PhzoAVr', + displayContent: 'd2:count(#{undefinedVariable}) = ', + data: 'd2:count(#{unknow})', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'FjkwPhzoAVr', + displayContent: "d2:countIfValue(#{undefinedVariable}, 'Male') = ", + data: "d2:countIfValue(#{undefinedVariable}, 'Male') = ", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'TkgrHcLselM', + displayContent: 'd2:countIfZeroPos(100) = ', + data: 'd2:countIfZeroPos(100)', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'Foc3PhzoAVr', + displayContent: 'd2:hasValue(#{undefinedVariable})', + data: 'd2:hasValue(#{undefinedVariable})', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'FoljdkeoAVr', + displayContent: "d2:validatePattern('Male', 'a')", + data: "d2:validatePattern('Male','a')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'FoljdlkYAVr', + displayContent: "d2:validatePattern('Male', 'Male')", + data: "d2:validatePattern('Male','Male')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'kpljdlkYAVr', + displayContent: 'd2:validatePattern()', + data: 'd2:validatePattern()', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'FoljdjkRAVr', + displayContent: "d2:hasUserRole('admin')", + data: "d2:hasUserRole('admin')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'FoljdkLRAVr', + displayContent: "d2:extractDataMatrixValue('batch number', 3)", + data: "d2:extractDataMatrixValue('batch number', 3)", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'FollkyLRAVr', + displayContent: "d2:extractDataMatrixValue('batch number', 'unknow')", + data: "d2:extractDataMatrixValue('batch number', 'unknow')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'lkEUdkLRAVr', + displayContent: "d2:extractDataMatrixValue('gtin', ']d2')", + data: "d2:extractDataMatrixValue('gtin', ']d2')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'FlkodkLRAVr', + displayContent: "d2:extractDataMatrixValue('batch number', ']d2')", + data: "d2:extractDataMatrixValue('batch number', ']d2')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'kuYodkLRAVr', + displayContent: "d2:extractDataMatrixValue('production date', ']Q3unknown')", + data: "d2:extractDataMatrixValue('production date', ']Q3unknown')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'kuYookLRAVr', + displayContent: "d2:extractDataMatrixValue('lot number', ']Q3703')", + data: "d2:extractDataMatrixValue('lot number', ']Q3703')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'lkyodkLRAVr', + displayContent: "d2:extractDataMatrixValue('best before date', ']Q3369')", + data: "d2:extractDataMatrixValue('best before date', ']Q3369')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'lkpyodkLRAVr', + displayContent: "d2:extractDataMatrixValue('expiration date', ']Q3369')", + data: "d2:extractDataMatrixValue('expiration date', ']Q3369')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'lkyohgyRAVr', + displayContent: "d2:extractDataMatrixValue('serial number', ']Q3369')", + data: "d2:extractDataMatrixValue('serial number', ']Q3369')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'lkyolktRAVr', + displayContent: "d2:extractDataMatrixValue('unknow key', ']d2')", + data: "d2:extractDataMatrixValue('unknow key', ']d2')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'FolpqkLRAVr', + displayContent: 'd2:lastEventDate(V{event_id})', + data: 'd2:lastEventDate(V{event_id})', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'FolkokLRAVr', + displayContent: 'd2:lastEventDate(V{enrollment_date})', + data: 'd2:lastEventDate(V{enrollment_date})', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'FolkwkLRAVr', + displayContent: 'd2:lastEventDate(#{undefinedVariable})', + data: 'd2:lastEventDate(#{undefinedVariable})', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'llokowfRAVr', + displayContent: "d2:addControlDigits('2')", + data: "d2:addControlDigits('2')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'lloksfegwAVr', + displayContent: "d2:addControlDigits('7')", + data: "d2:addControlDigits('7')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'lkyksfegwAVr', + displayContent: "d2:addControlDigits('9')", + data: "d2:addControlDigits('9')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'llolkyfRAVr', + displayContent: "d2:addControlDigits('12345678912')", + data: "d2:addControlDigits('12345678912')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'FollowfRAVr', + displayContent: 'd2:checkControlDigits(1)', + data: 'd2:checkControlDigits(1)', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'AFkfzcDf4Fs', + displayContent: "d2:inOrgUnitGroup('CHC') = ", + data: "d2:inOrgUnitGroup('CHC')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'wmAQnxbs7V8', + displayContent: 'd2:round( 12.5, 1 ) = ', + data: 'd2:round( 12.5, 1 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'tFGwyDBQk3b', + displayContent: 'd2:round( 0 ) = ', + data: 'd2:round( 0 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'NSQV537qvyu', + displayContent: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking') = ", + data: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking')", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'M7vYMD5uNwD', + displayContent: 'd2:ceil(11.3) = ', + data: 'd2:ceil(11.3)', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'cgdUEJkqq0J', + displayContent: "d2:yearsBetween( '2010-01-28', V{enrollment_date}) = ", + data: "d2:yearsBetween( '2010-01-28', V{enrollment_date})", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'xZpYbFPXWG2', + displayContent: 'd2:zing( 1000 ) = ', + data: 'd2:zing( 1000 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'IGpzruAKVzk', + displayContent: "d2:split('these-are-testing-values', '-', 2) = ", + data: "d2:split('these-are-testing-values', '-', 2)", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'NLsawa3P5hc', + displayContent: "d2:substring('hello dhis 2', -1, 10) = ", + data: "d2:substring('hello dhis 2', -1, 10)", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'i0OgulFyVPQ', + displayContent: 'd2:oizp( -10000000 ) = ', + data: 'd2:oizp( -10000000 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'PqzKFmEMmuz', + displayContent: "d2:right('dhis', 3) = ", + data: "d2:right('dhis', 3)", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'xIUDr1lRV6N', + displayContent: "d2:addDays( '2018-04-20', 100 ) = ", + data: "d2:addDays( '2018-04-20', 100 )", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'RXmprywJ0Rb', + displayContent: 'd2:floor( 11.5 ) = ', + data: 'd2:floor( 11.5 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'cZQngI2IC1a', + displayContent: "d2:length( 'dhis2 rocks' ) = ", + data: "d2:length( 'dhis2 rocks' )", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'qSe8GmlwpgZ', + displayContent: "d2:weeksBetween('2020-01-28', V{enrollment_date} ) = ", + data: "d2:weeksBetween('2020-01-28', V{enrollment_date} )", + location: 'feedback', + programRuleActionType: 'DISPLAYKEYVALUEPAIR', + }, + { + id: 'Tx4gHcLselM', + displayContent: 'd2:oizp( 10000000 ) = ', + data: 'd2:oizp( 10000000 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'f3MrrcCf1z2', + displayContent: 'd2:modulus( 12 , 100 ) = ', + data: 'd2:modulus( 12 , 100 )', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'Eeb7Ixr4Pv6', + displayContent: 'd2:floor((5+5) / 2) = ', + data: 'd2:floor((5+5) / 2)', + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { id: 'nKNmayYigcy', programStageId: 'PUZaKR0Jh2k', programRuleActionType: 'HIDEPROGRAMSTAGE' }, + { + id: 'nKNmayYigcy', + programStageSectionId: 'SWfdBhglX0fk', + programRuleActionType: 'HIDESECTION', + }, + { + id: 'lJOYxhjupxz', + data: 'true', + trackedEntityAttributeId: 'w75KJ2mc4zz', + programRuleActionType: 'ASSIGN', + }, + { + id: 'lJOdxhjupxz', + data: 'true', + trackedEntityAttributeId: 'w75KJ2mc4zz', + programRuleActionType: 'ERRORONCOMPLETE', + }, + { + id: 'ljlYxhjupxz', + data: 'true', + trackedEntityAttributeId: 'w75KJ2mc4zz', + programRuleActionType: 'WARNINGONCOMPLETE', + }, + { + id: 'lljoxhjupxz', + data: 'true', + trackedEntityAttributeId: 'w75KJ2mc4zz', + programRuleActionType: 'SETMANDATORYFIELD', + }, + { + id: 'lgjoxhjupxz', + data: 'true', + optionGroupId: 'w75KJ2mc4zz', + programRuleActionType: 'HIDEOPTIONGROUP', + }, + { + id: 'lljljhjupxz', + data: 'true', + optionGroupId: 'w75KJ2mc4zz', + programRuleActionType: 'SHOWOPTIONGROUP', + }, + { id: 'hwgyO59SSxu', trackedEntityAttributeId: 'zDhUuAYrxNC', programRuleActionType: 'HIDEFIELD' }, + { id: 'khygyO59Sxu', trackedEntityAttributeId: 'unknown', programRuleActionType: 'HIDEFIELD' }, + { id: 'khtgyO5SSxu', trackedEntityAttributeId: 'Z5z8vFQy0w0', programRuleActionType: 'HIDEFIELD' }, + { id: 'hwgyOgy4Sxu', trackedEntityAttributeId: 'TzqawmlPkI5', programRuleActionType: 'HIDEFIELD' }, + { id: 'hwgyloeSSxu', trackedEntityAttributeId: 'f8j4XDEozvj', programRuleActionType: 'HIDEFIELD' }, + { id: 'lkoeO59SSxu', trackedEntityAttributeId: 'jBBkFuPKctq', programRuleActionType: 'HIDEFIELD' }, + { id: 'poe4O59SSxu', trackedEntityAttributeId: 'A4Fg6jgWauf', programRuleActionType: 'HIDEFIELD' }, + { id: 'gtyyO59SSxu', trackedEntityAttributeId: 'CUbZcLm9LyN', programRuleActionType: 'HIDEFIELD' }, + { id: 'kopyO59SSxu', trackedEntityAttributeId: 'p8htbyJHydl', programRuleActionType: 'HIDEFIELD' }, + { id: 'dsfsdfsw4rh', dataElementId: 'unknown', programRuleActionType: 'HIDEFIELD' }, + { + id: 'khy8GmlwpgZ', + displayContent: "d2:weeksBetween('2020-01-28', V{unknown} ) = ", + data: "d2:weeksBetween('2020-01-28', V{unknown} )", + location: 'feedback', + programRuleActionType: 'DISPLAYKEYVALUEPAIR', + }, + ], + }, + ]; + const programRuleVariables = [ + { + id: 'DoRHHfNPccb', + trackedEntityAttributeId: 'w75KJ2mc4zz', + displayName: 'INFECTION_SOURCE', + programId: 'IpHINAT79UW', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: false, + }, + { + id: 'lokHHfNPccb', + trackedEntityAttributeId: 'w75KJ2mc4zz', + displayName: 'INFECTION_SOURCE', + programId: 'IpHINAT79UW', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: false, + }, + { + id: 'Zj7UnCAulEk', + displayName: 'Zj7UnCAulEk', + programRuleVariableSourceType: variableSourceTypes.TEI_ATTRIBUTE, + trackedEntityAttributeId: 'w75KJ2mc4zz', + programId: 'IpHINAT79UW', + }, + ]; const optionSets = {}; - const teiValues = {}; + const teiValues = { + zDhUuAYrxNC: 'value', + Z5z8vFQy0w0: 'https://www.google.com/', + TzqawmlPkI5: '30', + f8j4XDEozvj: 'FILE_RESOURCE', + jBBkFuPKctq: 'ORGANISATION_UNIT', + A4Fg6jgWauf: 'IMAGE', + CUbZcLm9LyN: 'USERNAME', + p8htbyJHydl: { latitude: '12.4353', longitude: '67.34534' }, + }; const orgUnit = { id: 'DiszpKrYNg8', name: 'Ngelehun CHC' }; - const enrollmentData = { enrolledAt: '2020-05-14T22:00:00.000Z' }; + const enrollmentData = { enrolledAt: '2020-05-14T10:00:00.000Z' }; + const currentEvent = { + occurredAt: '2020-07-14T10:00:00.000Z', + da1Id: 'currentEventText', + dueDate: '2021-05-31T09:51:38.134', + enrollmentId: 'vVtmDlsu3me', + enrollmentStatus: 'ACTIVE', + eventDate: '2021-05-31T00:00:00.000', + eventId: 'BxGzDJK3JqN', + orgUnitId: 'DiszpKrYNg8', + orgUnitName: 'Ngelehun CHC', + programId: 'IpHINAT79UW', + programStageId: 'A03MvHHogjR', + status: 'ACTIVE', + trackedEntityInstanceId: 'vCGpQAWG17I', + }; // when const rulesEffects = rulesEngine.getProgramRuleEffects({ - programRulesContainer: { programRulesVariables, programRules, constants }, + programRulesContainer: { programRuleVariables, programRules, constants }, trackedEntityAttributes, selectedEntity: teiValues, selectedEnrollment: enrollmentData, selectedOrgUnit: orgUnit, optionSets, + currentEvent, }); // then expect(rulesEffects).toEqual([ - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'Eeb7Ixr4Pvx', message: "d2:left('dhis', 3) = dhi" } }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Eeb7Ixr4Pvx', message: "d2:left('dhis', 3) = dhi" }, + }, { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'lbIGJYVI57u', message: 'd2:zing( -2 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'kwKhYpVRDyj', message: "d2:monthsBetween( '2020-01-28', V{enrollment_date}) = 3" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'AFkfzcDf4Fs', message: "d2:inOrgUnitGroup('CHC') = " } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'wmAQnxbs7V8', message: 'd2:round( 12.5 ) = 13' } }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'kwKhYpVRDyj', message: "d2:monthsBetween( '2020-01-28', V{enrollment_date}) = 3" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'polhYpVRDyj', message: "d2:daysBetween( '2020-01-28', V{enrollment_date}) = 107" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'FkeGdlkYAVr', + message: "d2:validatePattern('d2:daysBetween( '2020-01-28', V{enrollment_date})', 108) ", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Foc3PhzoAVr', message: 'd2:count(#{undefinedVariable}) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'FjkwPhzoAVr', message: "d2:countIfValue(#{undefinedVariable}, 'Male') = " }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'TkgrHcLselM', message: 'd2:countIfZeroPos(100) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Foc3PhzoAVr', message: 'd2:hasValue(#{undefinedVariable}) ' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'FoljdkeoAVr', message: "d2:validatePattern('Male', 'a') " }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'FoljdlkYAVr', message: "d2:validatePattern('Male', 'Male') true" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'kpljdlkYAVr', message: 'd2:validatePattern() ' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'FoljdjkRAVr', message: "d2:hasUserRole('admin') " }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'FoljdkLRAVr', + message: "d2:extractDataMatrixValue('batch number', 3) Incomplete DataMatrix input", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'FollkyLRAVr', + message: + "d2:extractDataMatrixValue('batch number', 'unknow') Unsupported GS1 identifier: {gs1Identifier}", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'lkEUdkLRAVr', + message: "d2:extractDataMatrixValue('gtin', ']d2') ", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'FlkodkLRAVr', + message: "d2:extractDataMatrixValue('batch number', ']d2') ", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'kuYodkLRAVr', + message: "d2:extractDataMatrixValue('production date', ']Q3unknown') ", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'kuYookLRAVr', + message: "d2:extractDataMatrixValue('lot number', ']Q3703') ", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'lkyodkLRAVr', + message: "d2:extractDataMatrixValue('best before date', ']Q3369') ", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'lkpyodkLRAVr', + message: "d2:extractDataMatrixValue('expiration date', ']Q3369') ", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'lkyohgyRAVr', + message: "d2:extractDataMatrixValue('serial number', ']Q3369') ", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'lkyolktRAVr', + message: "d2:extractDataMatrixValue('unknow key', ']d2') ", + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'FolpqkLRAVr', message: 'd2:lastEventDate(V{event_id}) 2020-07-14' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'FolkokLRAVr', message: 'd2:lastEventDate(V{enrollment_date}) ' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'FolkwkLRAVr', message: 'd2:lastEventDate(#{undefinedVariable}) ' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'llokowfRAVr', message: "d2:addControlDigits('2') 261" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'lloksfegwAVr', message: "d2:addControlDigits('7') 709" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'lkyksfegwAVr', message: "d2:addControlDigits('9') 950" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'llolkyfRAVr', message: "d2:addControlDigits('12345678912') 1234567891200" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'FollowfRAVr', message: 'd2:checkControlDigits(1) 1' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'AFkfzcDf4Fs', message: "d2:inOrgUnitGroup('CHC') = " }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'wmAQnxbs7V8', message: 'd2:round( 12.5, 1 ) = 12.5' }, + }, { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'tFGwyDBQk3b', message: 'd2:round( 0 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'NSQV537qvyu', message: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking') = dhis2isrocking" } }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { + id: 'NSQV537qvyu', + message: "d2:concatenate( 'dh', 'is', 2, 'is', 'rocking') = dhis2isrocking", + }, + }, { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'M7vYMD5uNwD', message: 'd2:ceil(11.3) = 12' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'cgdUEJkqq0J', message: "d2:yearsBetween( '2010-01-28', V{enrollment_date}) = 10" } }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'cgdUEJkqq0J', message: "d2:yearsBetween( '2010-01-28', V{enrollment_date}) = 10" }, + }, { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'xZpYbFPXWG2', message: 'd2:zing( 1000 ) = 1000' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'IGpzruAKVzk', message: "d2:split('these-are-testing-values', '-', 2) = testing" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'NLsawa3P5hc', message: "d2:substring('hello dhis 2', 6, 10) = dhis" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'i0OgulFyVPQ', message: 'd2:oizp( -10000000 ) = 0' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'PqzKFmEMmuz', message: "d2:right('dhis', 3) = his" } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'xIUDr1lRV6N', message: "d2:addDays( '2018-04-20', 100 ) = 2018-07-29" } }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'IGpzruAKVzk', message: "d2:split('these-are-testing-values', '-', 2) = testing" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'NLsawa3P5hc', message: "d2:substring('hello dhis 2', -1, 10) = " }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'i0OgulFyVPQ', message: 'd2:oizp( -10000000 ) = 0' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'PqzKFmEMmuz', message: "d2:right('dhis', 3) = his" }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'xIUDr1lRV6N', message: "d2:addDays( '2018-04-20', 100 ) = 2018-07-29" }, + }, { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'RXmprywJ0Rb', message: 'd2:floor( 11.5 ) = 11' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'cZQngI2IC1a', message: "d2:length( 'dhis2 rocks' ) = 11" } }, - { type: 'DISPLAYKEYVALUEPAIR', id: 'feedback', displayKeyValuePair: { id: 'qSe8GmlwpgZ', key: "d2:weeksBetween('2020-01-28', V{enrollment_date} ) = ", value: '15' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'Tx4gHcLselM', message: 'd2:oizp( 10000000 ) = 1' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'f3MrrcCf1z2', message: 'd2:modulus( 12 , 100 ) = 12' } }, - { type: 'DISPLAYTEXT', id: 'feedback', displayText: { id: 'Eeb7Ixr4Pv6', message: 'd2:floor((5+5) / 2) = 5' } }, // check double parentheses + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'cZQngI2IC1a', message: "d2:length( 'dhis2 rocks' ) = 11" }, + }, + { + type: 'DISPLAYKEYVALUEPAIR', + id: 'feedback', + displayKeyValuePair: { + id: 'qSe8GmlwpgZ', + key: "d2:weeksBetween('2020-01-28', V{enrollment_date} ) = ", + value: '15', + }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Tx4gHcLselM', message: 'd2:oizp( 10000000 ) = 1' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'f3MrrcCf1z2', message: 'd2:modulus( 12 , 100 ) = 12' }, + }, + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Eeb7Ixr4Pv6', message: 'd2:floor((5+5) / 2) = 5' }, + }, { type: 'HIDEPROGRAMSTAGE', id: 'PUZaKR0Jh2k' }, + { id: 'SWfdBhglX0fk', type: 'HIDESECTION' }, + { id: 'w75KJ2mc4zz', targetDataType: 'trackedEntityAttribute', type: 'ASSIGN', value: 'true' }, + { + id: 'w75KJ2mc4zz', + message: ' true', + targetDataType: 'trackedEntityAttribute', + type: 'ERRORONCOMPLETE', + }, + { + id: 'w75KJ2mc4zz', + message: ' true', + targetDataType: 'trackedEntityAttribute', + type: 'WARNINGONCOMPLETE', + }, + { + id: 'w75KJ2mc4zz', + targetDataType: 'trackedEntityAttribute', + type: 'SETMANDATORYFIELD', + }, + { + content: undefined, + id: 'zDhUuAYrxNC', + targetDataType: 'trackedEntityAttribute', + type: 'HIDEFIELD', + hadValue: true, + name: undefined, + }, + { + content: undefined, + id: 'unknown', + targetDataType: 'trackedEntityAttribute', + type: 'HIDEFIELD', + }, + { + content: undefined, + id: 'Z5z8vFQy0w0', + targetDataType: 'trackedEntityAttribute', + type: 'HIDEFIELD', + hadValue: true, + name: undefined, + }, + { + content: undefined, + id: 'TzqawmlPkI5', + targetDataType: 'trackedEntityAttribute', + type: 'HIDEFIELD', + hadValue: true, + name: undefined, + }, + { + content: undefined, + id: 'f8j4XDEozvj', + targetDataType: 'trackedEntityAttribute', + type: 'HIDEFIELD', + }, + { + content: undefined, + id: 'jBBkFuPKctq', + targetDataType: 'trackedEntityAttribute', + type: 'HIDEFIELD', + }, + { + content: undefined, + id: 'A4Fg6jgWauf', + targetDataType: 'trackedEntityAttribute', + type: 'HIDEFIELD', + }, + { + content: undefined, + id: 'CUbZcLm9LyN', + targetDataType: 'trackedEntityAttribute', + type: 'HIDEFIELD', + hadValue: true, + name: undefined, + }, + { + content: undefined, + id: 'p8htbyJHydl', + targetDataType: 'trackedEntityAttribute', + type: 'HIDEFIELD', + hadValue: true, + name: undefined, + }, + { + content: undefined, + id: 'unknown', + targetDataType: 'dataElement', + type: 'HIDEFIELD', + }, + { + displayKeyValuePair: { + id: 'khy8GmlwpgZ', + key: "d2:weeksBetween('2020-01-28', V{unknown} ) = ", + value: '', + }, + id: 'feedback', + type: 'DISPLAYKEYVALUEPAIR', + }, ]); }); diff --git a/src/core_modules/capture-core/rules/__tests__/rulesEngine.test.js b/src/core_modules/capture-core/rules/__tests__/rulesEngine.test.js new file mode 100644 index 0000000000..4a0f04e813 --- /dev/null +++ b/src/core_modules/capture-core/rules/__tests__/rulesEngine.test.js @@ -0,0 +1,717 @@ +import { variableSourceTypes } from '@dhis2/rules-engine-javascript'; +import { rulesEngine } from '../rulesEngine'; + +describe('Rules engine', () => { + const constants = []; + const dataElementsInProgram = {}; + const programRuleVariables = []; + const orgUnit = { id: 'DiszpKrYNg8', name: 'Ngelehun CHC' }; + const optionSets = {}; + const currentEvent = {}; + + test('Rules engine without programRules', () => { + // when + const programRules = undefined; + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + currentEvent, + dataElements: dataElementsInProgram, + selectedOrgUnit: orgUnit, + optionSets, + }); + + // then + expect(rulesEffects).toEqual([]); + }); + + test('Program rule without an condition', () => { + // when + const programRules = [ + { + id: 'GC4gpdoSD4r', + condition: undefined, + description: 'Show warning if hemoglobin is dangerously low', + displayName: 'Hemoglobin warning', + programId: 'lxAQ7Zs9VYR', + programRuleActions: [ + { + id: 'suS9GnraCx1', + content: 'Hemoglobin value lower than normal', + displayContent: 'Hemoglobin value lower than normal', + dataElementId: 'vANAXwtLwcT', + programRuleActionType: 'SHOWWARNING', + }, + ], + }, + ]; + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + currentEvent, + dataElements: dataElementsInProgram, + selectedOrgUnit: orgUnit, + optionSets, + }); + + // then + expect(rulesEffects).toEqual([]); + }); + + test('Program rule condition error handeling', () => { + const programRules = [ + { + id: 'GC4gpdoSD4r', + condition: 'i am a condition with error', + description: 'Show warning if hemoglobin is dangerously low', + displayName: 'Hemoglobin warning', + programId: 'lxAQ7Zs9VYR', + programRuleActions: [ + { + id: 'suS9GnraCx1', + content: 'Hemoglobin value lower than normal', + displayContent: 'Hemoglobin value lower than normal', + dataElementId: 'vANAXwtLwcT', + programRuleActionType: 'SHOWWARNING', + }, + ], + }, + ]; + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + currentEvent, + dataElements: dataElementsInProgram, + selectedOrgUnit: orgUnit, + optionSets, + }); + + // then + expect(rulesEffects).toEqual([]); + }); + + test('user roles', () => { + rulesEngine.setSelectedUserRoles(['ADMIN']); + expect(rulesEngine.userRoles).toEqual(['ADMIN']); + }); + + test('SHOW_WARNING program rule effect with a general target', () => { + const programRules = [ + { + id: 'GC4gpdoSD4r', + condition: 'true', + description: 'Show warning if hemoglobin is dangerously low', + displayName: 'Hemoglobin warning', + programId: 'lxAQ7Zs9VYR', + programRuleActions: [ + { + id: 'SWfdB5lX0fk', + content: 'Hemoglobin value lower than normal', + displayContent: 'Hemoglobin value lower than normal', + programRuleActionType: 'SHOWWARNING', + }, + ], + }, + ]; + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + currentEvent, + dataElements: dataElementsInProgram, + selectedOrgUnit: orgUnit, + optionSets, + }); + + // then + expect(rulesEffects).toEqual([ + { + id: 'general', + type: 'SHOWWARNING', + warning: { + id: 'SWfdB5lX0fk', + message: 'Hemoglobin value lower than normal ', + }, + }, + ]); + }); + + test('SHOW_ERROR program rule effect with a general target', () => { + const programRules = [ + { + id: 'GC4gpdoSD4r', + condition: 'true', + description: 'Show error if hemoglobin is dangerously low', + displayName: 'Hemoglobin error', + programId: 'lxAQ7Zs9VYR', + programRuleActions: [ + { + id: 'SWfdB5lX0fk', + content: 'Hemoglobin value lower than normal', + displayContent: 'Hemoglobin value lower than normal', + programRuleActionType: 'SHOWERROR', + }, + ], + }, + ]; + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + currentEvent, + dataElements: dataElementsInProgram, + selectedOrgUnit: orgUnit, + optionSets, + }); + + // then + expect(rulesEffects).toEqual([ + { + id: 'general', + type: 'SHOWERROR', + error: { + id: 'SWfdB5lX0fk', + message: 'Hemoglobin value lower than normal ', + }, + }, + ]); + }); + + test('HIDE_PROGRAM_STAGE program rule effect corner case. The action does not have a program stage id', () => { + const programRules = [ + { + id: 'GC4gpdoSD4r', + condition: 'true', + description: 'Show warning if hemoglobin is dangerously low', + displayName: 'Hemoglobin warning', + programId: 'lxAQ7Zs9VYR', + programRuleActions: [ + { + id: 'nKNmayYigcy', + programRuleActionType: 'HIDEPROGRAMSTAGE', + }, + ], + }, + ]; + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + currentEvent, + dataElements: dataElementsInProgram, + selectedOrgUnit: orgUnit, + optionSets, + }); + + // then + expect(rulesEffects).toEqual([]); + }); + + test('HIDE_SECTION program rule effect corner case. The action does not have a program stage section id', () => { + const programRules = [ + { + id: 'GC4gpdoSD4r', + condition: 'true', + description: 'Show warning if hemoglobin is dangerously low', + displayName: 'Hemoglobin warning', + programId: 'lxAQ7Zs9VYR', + programRuleActions: [ + { + id: 'nKNmayYigcy', + programRuleActionType: 'HIDESECTION', + }, + ], + }, + ]; + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + currentEvent, + dataElements: dataElementsInProgram, + selectedOrgUnit: orgUnit, + optionSets, + }); + + // then + expect(rulesEffects).toEqual([]); + }); +}); + +describe('Program Rule Variables corner cases', () => { + const constants = []; + const orgUnit = { id: 'DiszpKrYNg8', name: 'Ngelehun CHC' }; + const optionSets = {}; + + test('without currentEvent and without otherEvents', () => { + // given + const programRules = [ + { + id: 'g82J3xsNer9', + condition: 'true', + displayName: 'Testing the variables source type', + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'Eeb7Ixr4Pvx', + displayContent: "d2:left('dhis', 3) = ", + data: "d2:left('dhis', 3)", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'ElktIxr4Pvx', + displayContent: "d2:left('dhis', 3) = ", + data: "d2:left('dhis', 3)", + content: 'event_status', + programRuleActionType: 'ASSIGN', + }, + ], + }, + ]; + const dataElementsInProgram = { + f8j4XDEozvj: { id: 'f8j4XDEozvj', valueType: 'INTEGER', optionSetId: undefined }, + }; + const currentEvent = undefined; + const programRuleVariables = [ + { + id: 'DoRHHfNPccb', + dataElementId: 'f8j4XDEozvj', + displayName: 'INFECTION_SOURCE', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: false, + }, + { + id: 'lokHHfNPccb', + dataElementId: 'f8j4XDEozvj', + displayName: 'INFECTION_SOURCE', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_PREVIOUS_EVENT, + useNameForOptionSet: false, + }, + { + id: 'DolgHfNPccb', + dataElementId: 'f8j4XDEozvj', + displayName: 'INFECTION_SOURCE', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM, + useNameForOptionSet: false, + }, + ]; + + // when + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + selectedOrgUnit: orgUnit, + optionSets, + currentEvent, + dataElements: dataElementsInProgram, + }); + + // then + expect(rulesEffects).toEqual([ + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Eeb7Ixr4Pvx', message: "d2:left('dhis', 3) = dhi" }, + }, + ]); + }); + + test('without currentEvent and with otherEvents', () => { + // given + const programRules = [ + { + id: 'g82J3xsNer9', + condition: 'true', + displayName: 'Testing the variables source type', + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'Eeb7Ixr4Pvx', + displayContent: "d2:left('dhis', 3) = ", + data: "d2:left('dhis', 3)", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'ElktIxr4Pvx', + displayContent: "d2:left('dhis', 3) = ", + data: "d2:left('dhis', 3)", + content: 'event_status', + programRuleActionType: 'ASSIGN', + }, + ], + }, + ]; + const dataElementsInProgram = { + f8j4XDEozvj: { id: 'f8j4XDEozvj', valueType: 'INTEGER', optionSetId: undefined }, + }; + const currentEvent = undefined; + const otherEvents = [ + { + da1Id: 'otherEventText', + dueDate: '2021-05-31T09:51:38.134', + enrollmentId: 'vVtmDlsu3me', + enrollmentStatus: 'ACTIVE', + eventDate: '2021-05-31T00:00:00.000', + eventId: 'BxGzDJK3JqN', + orgUnitId: 'DiszpKrYNg8', + orgUnitName: 'Ngelehun CHC', + programId: 'IpHINAT79UW', + programStageId: 'A03MvHHogjR', + status: 'ACTIVE', + trackedEntityInstanceId: 'vCGpQAWG17I', + occurredAt: '2021-05-31T00:00:00.000', + }, + ]; + const programRuleVariables = [ + { + id: 'lokHHfNPccb', + dataElementId: 'f8j4XDEozvj', + displayName: 'INFECTION_SOURCE', + programId: 'PNClHaZARtz', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_PREVIOUS_EVENT, + useNameForOptionSet: false, + }, + ]; + + // when + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + selectedOrgUnit: orgUnit, + optionSets, + currentEvent, + dataElements: dataElementsInProgram, + otherEvents, + }); + + // then + expect(rulesEffects).toEqual([ + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Eeb7Ixr4Pvx', message: "d2:left('dhis', 3) = dhi" }, + }, + ]); + }); + + test('with currentEvent and with otherEvents', () => { + // given + const programRules = [ + { + id: 'g82J3xsNer9', + condition: 'true', + displayName: 'Testing the variables source type', + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'Eeb7Ixr4Pvx', + displayContent: "d2:left('dhis', 3) = ", + data: "d2:left('dhis', 3)", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'ElktIxr4Pvx', + displayContent: "d2:left('dhis', 3) = ", + data: "d2:left('dhis', 3)", + content: 'event_status', + programRuleActionType: 'ASSIGN', + }, + ], + }, + ]; + const dataElementsInProgram = { + f8j4XDEozvj: { id: 'f8j4XDEozvj', valueType: 'INTEGER', optionSetId: undefined }, + GieVkTxp4HH: { id: 'GieVkTxp4HH', valueType: 'NUMBER', optionSetId: undefined }, + }; + const currentEvent = { + occurredAt: '2020-07-14T22:00:00.000Z', + da1Id: 'currentEventText', + dueDate: '2021-05-31T09:51:38.134', + enrollmentId: 'vVtmDlsu3me', + enrollmentStatus: 'ACTIVE', + eventDate: '2021-05-31T00:00:00.000', + eventId: 'BlgrDJK3JqN', + orgUnitId: 'DiszpKrYNg8', + orgUnitName: 'Ngelehun CHC', + programId: 'IpHINAT79UW', + programStageId: 'A03MvHHogjR', + status: 'ACTIVE', + trackedEntityInstanceId: 'vCsfsAWG17I', + }; + const otherEvents = [ + { + da1Id: 'otherEventText', + dueDate: '2021-05-31T09:51:38.134', + enrollmentId: 'vVtmDlsu3me', + enrollmentStatus: 'ACTIVE', + eventDate: '2021-05-31T00:00:00.000', + eventId: 'BxGzDJK3JqN', + orgUnitId: 'DiszpKrYNg8', + orgUnitName: 'Ngelehun CHC', + programId: 'IpHINAT79UW', + programStageId: 'A03MvHHogjR', + status: 'ACTIVE', + trackedEntityInstanceId: 'vCGpQAWG17I', + occurredAt: '2021-05-31T00:00:00.000', + }, + ]; + const programRuleVariables = [ + { + id: 'lokHHfNPccb', + dataElementId: 'f8j4XDEozvj', + displayName: 'INFECTION_SOURCE', + programId: 'IpHINAT79UW', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_PREVIOUS_EVENT, + useNameForOptionSet: false, + }, + { + id: 'ZghUnCAulEk.GieVkTxp4HH', + displayName: 'ZghUnCAulEk.GieVkTxp4HH', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE, + programStageId: 'A03MvHHogjR', + dataElementId: 'GieVkTxp4HH', + programId: 'IpHINAT79UW', + }, + { + id: 'Zj7UnsdhlEk.GieVkTxp4HH', + displayName: 'Zj7UnsdhlEk.GieVkTxp4HH', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE, + dataElementId: 'GieVkTxp4HH', + programId: 'IpHINAT79UW', + }, + { + id: 'Zj7luCAulEk.GieVkTxp4HH', + displayName: 'Zj7luCAulEk.GieVkTxp4HH', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE, + programStageId: 'AsdfMvHHgjR', + dataElementId: 'GieVkTxp4HH', + programId: 'IpHINAT79UW', + }, + ]; + + // when + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + selectedOrgUnit: orgUnit, + optionSets, + currentEvent, + dataElements: dataElementsInProgram, + otherEvents, + }); + + // then + expect(rulesEffects).toEqual([ + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Eeb7Ixr4Pvx', message: "d2:left('dhis', 3) = dhi" }, + }, + ]); + }); + + test('currentEvent without occurredAt date', () => { + // given + const programRules = [ + { + id: 'g82J3xsNer9', + condition: 'true', + displayName: 'Testing the variables source type', + programId: 'PNClHaZARtz', + programRuleActions: [ + { + id: 'Eeb7Ixr4Pvx', + displayContent: "d2:left('dhis', 3) = ", + data: "d2:left('dhis', 3)", + location: 'feedback', + programRuleActionType: 'DISPLAYTEXT', + }, + { + id: 'ElktIxr4Pvx', + displayContent: "d2:left('dhis', 3) = ", + data: "d2:left('dhis', 3)", + content: 'event_status', + programRuleActionType: 'ASSIGN', + }, + ], + }, + ]; + const dataElementsInProgram = { + f8j4XDEozvj: { id: 'f8j4XDEozvj', valueType: 'INTEGER', optionSetId: undefined }, + GieVkTxp4HH: { id: 'GieVkTxp4HH', valueType: 'NUMBER', optionSetId: undefined }, + }; + const currentEvent = { + da1Id: 'currentEventText', + dueDate: '2021-05-31T09:51:38.134', + enrollmentId: 'vVtmDlsu3me', + enrollmentStatus: 'ACTIVE', + eventDate: '2021-05-31T00:00:00.000', + eventId: 'BlgrDJK3JqN', + orgUnitId: 'DiszpKrYNg8', + orgUnitName: 'Ngelehun CHC', + programId: 'IpHINAT79UW', + programStageId: 'A03MvHHogjR', + status: 'ACTIVE', + trackedEntityInstanceId: 'vCsfsAWG17I', + }; + const otherEvents = [ + { + da1Id: 'otherEventText', + dueDate: '2021-05-31T09:51:38.134', + enrollmentId: 'vVtmDlsu3me', + enrollmentStatus: 'ACTIVE', + eventDate: '2021-05-31T00:00:00.000', + eventId: 'BxGzDJK3JqN', + orgUnitId: 'DiszpKrYNg8', + orgUnitName: 'Ngelehun CHC', + programId: 'IpHINAT79UW', + programStageId: 'A03MvHHogjR', + status: 'ACTIVE', + trackedEntityInstanceId: 'vCGpQAWG17I', + occurredAt: '2021-05-31T00:00:00.000', + }, + ]; + const programRuleVariables = [ + { + id: 'lokHHfNPccb', + dataElementId: 'f8j4XDEozvj', + displayName: 'INFECTION_SOURCE', + programId: 'IpHINAT79UW', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_PREVIOUS_EVENT, + useNameForOptionSet: false, + }, + { + id: 'ZghUnCAulEk.GieVkTxp4HH', + displayName: 'ZghUnCAulEk.GieVkTxp4HH', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE, + programStageId: 'A03MvHHogjR', + dataElementId: 'GieVkTxp4HH', + programId: 'IpHINAT79UW', + }, + { + id: 'Zj7UnsdhlEk.GieVkTxp4HH', + displayName: 'Zj7UnsdhlEk.GieVkTxp4HH', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE, + dataElementId: 'GieVkTxp4HH', + programId: 'IpHINAT79UW', + }, + { + id: 'Zj7luCAulEk.GieVkTxp4HH', + displayName: 'Zj7luCAulEk.GieVkTxp4HH', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE, + programStageId: 'AsdfMvHHgjR', + dataElementId: 'GieVkTxp4HH', + programId: 'IpHINAT79UW', + }, + ]; + + // when + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + selectedOrgUnit: orgUnit, + optionSets, + currentEvent, + dataElements: dataElementsInProgram, + otherEvents, + }); + + // then + expect(rulesEffects).toEqual([ + { + type: 'DISPLAYTEXT', + id: 'feedback', + displayText: { id: 'Eeb7Ixr4Pvx', message: "d2:left('dhis', 3) = dhi" }, + }, + ]); + }); + + test('programRuleVariable with a value type not supported', () => { + // given + const trackedEntityAttributes = { + w75KJ2mc4zz: { id: 'w75KJ2mc4zz', valueType: 'UNKNOWN' }, + }; + const programRules = []; + const currentEvent = {}; + const programRuleVariables = [ + { + id: 'DoRHHfNPccb', + displayName: 'INFECTION_SOURCE', + trackedEntityAttributeId: 'w75KJ2mc4zz', + programId: 'IpHINAT79UW', + programRuleVariableSourceType: variableSourceTypes.TEI_ATTRIBUTE, + useNameForOptionSet: false, + }, + ]; + + // when + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + selectedOrgUnit: orgUnit, + optionSets, + currentEvent, + trackedEntityAttributes, + }); + + // then + expect(rulesEffects).toEqual([]); + }); + + test('HIDEFIELD effect when the form values are empty', () => { + // given + const programRules = [ + { + id: 'g82J3xsNer9', + condition: 'true', + displayName: 'Testing the variables source type', + programId: 'PNClHaZARtz', + programRuleActions: [ + { id: 'hwgyO59SSxu', trackedEntityAttributeId: 'zDhUuAYrxNC', programRuleActionType: 'HIDEFIELD' }, + ], + }, + ]; + const trackedEntityAttributes = { + zDhUuAYrxNC: { id: 'zDhUuAYrxNC', valueType: 'TEXT' }, + }; + const programRuleVariables = [ + { + id: 'DoRHHfNPccb', + trackedEntityAttributeId: 'w75KJ2mc4zz', + displayName: 'INFECTION_SOURCE', + programId: 'IpHINAT79UW', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: false, + }, + { + id: 'lokHHfNPccb', + trackedEntityAttributeId: 'w75KJ2mc4zz', + displayName: 'INFECTION_SOURCE', + programId: 'IpHINAT79UW', + programRuleVariableSourceType: variableSourceTypes.DATAELEMENT_CURRENT_EVENT, + useNameForOptionSet: false, + }, + { + id: 'Zj7UnCAulEk', + displayName: 'Zj7UnCAulEk', + programRuleVariableSourceType: variableSourceTypes.TEI_ATTRIBUTE, + trackedEntityAttributeId: 'w75KJ2mc4zz', + programId: 'IpHINAT79UW', + }, + ]; + const teiValues = {}; + const enrollmentData = { enrolledAt: '2020-05-14T22:00:00.000Z' }; + const currentEvent = undefined; + + // when + const rulesEffects = rulesEngine.getProgramRuleEffects({ + programRulesContainer: { programRuleVariables, programRules, constants }, + trackedEntityAttributes, + selectedEntity: teiValues, + selectedEnrollment: enrollmentData, + selectedOrgUnit: orgUnit, + optionSets, + currentEvent, + }); + + // then + expect(rulesEffects).toEqual([ + { + content: undefined, + id: 'zDhUuAYrxNC', + targetDataType: 'trackedEntityAttribute', + type: 'HIDEFIELD', + }, + ]); + }); +});