@hisp-amr/assign-value-rule-engine
v0.0.4
Published
DHIS2 program rule engine for assign data value actions
Downloads
2
Readme
assign-value-rule-engine
Installation
yarn add @hisp-amr/assign-value-rule-engine
# or
npm i @hisp-amr/assign-value-rule-engine
Usage
You need to pass along some metadata. In the example app the bellow query was used with @dhis2/app-runtime. See AppContent.js
const query = {
metadata: {
resource: 'metadata',
params: {
optionGroups: 'true', // not strictly needed, but was used to find the correct program based on organism
programs: 'true',
programRules: 'true',
programRuleVariables: 'true',
fields: [
'id',
'options[code,displayName]',
'dataElement',
'name',
'condition',
'programRuleActions[programRuleActionType,dataElement,data]',
'programStages[id,programStageDataElements]',
'program',
],
},
},
}
See RuleRunner.js
import { runAssignValueRules } from '@hisp-amr/assign-value-rule-engine'
const newDataValues = runAssignValueRules(
event.dataValues,
programStage.programStageDataElements, // programStage of the event
{
programRules: metadata.programRules.filter(
({ program }) => program.id === programId
),
programRuleVariables: metadata.programRuleVariables,
}
)