All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
commonMain.org.hisp.dhis.rules.engine.RuleEngineMultipleExecution.kt Maven / Gradle / Ivy
package org.hisp.dhis.rules.engine
import org.hisp.dhis.rules.models.*
internal class RuleEngineMultipleExecution {
fun execute(
rules: List,
ruleVariableValueMap: RuleVariableValueMap,
supplementaryData: Map>,
): List {
val ruleEffects: MutableList = ArrayList()
for ((enrollment, valueMap) in ruleVariableValueMap.enrollmentMap) {
val enrollmentRuleEffects =
RuleConditionEvaluator()
.getEvaluatedAndErrorRuleEffects(
TrackerObjectType.ENROLLMENT,
enrollment.enrollment,
valueMap,
supplementaryData,
filterRules(rules),
)
ruleEffects.add(
RuleEffects(
TrackerObjectType.ENROLLMENT,
enrollment.enrollment,
enrollmentRuleEffects,
),
)
}
for ((event, valueMap) in ruleVariableValueMap.eventMap) {
ruleEffects.add(
RuleEffects(
TrackerObjectType.EVENT,
event.event,
RuleConditionEvaluator().getEvaluatedAndErrorRuleEffects(
TrackerObjectType.EVENT,
event.event,
valueMap,
supplementaryData,
filterRules(rules, event),
),
),
)
}
return ruleEffects
}
private fun filterRules(rules: List): List {
val filteredRules: MutableList = mutableListOf()
for (rule in rules) {
val programStage: String? = rule.programStage
if (programStage.isNullOrEmpty()) {
val ruleActions =
filterActionRules(
rule.actions,
AttributeType.TRACKED_ENTITY_ATTRIBUTE,
)
filteredRules.add(rule.copy(actions = ruleActions))
}
}
return filteredRules
}
private fun filterRules(
rules: List,
ruleEvent: RuleEvent,
): List {
val filteredRules: MutableList = mutableListOf()
for (rule in rules) {
val programStage: String? = rule.programStage
if (programStage.isNullOrEmpty() || programStage == ruleEvent.programStage) {
val ruleActions =
filterActionRules(
rule.actions,
AttributeType.DATA_ELEMENT,
)
filteredRules.add(rule.copy(actions = ruleActions))
}
}
return filteredRules
}
private fun filterActionRules(
ruleActions: List,
attributeType: AttributeType,
): List {
val filteredRuleActions: MutableList = mutableListOf()
for (ruleAction in ruleActions) {
if (ruleAction.attributeType() == null ||
ruleAction.attributeType() == attributeType.name ||
ruleAction.attributeType() == AttributeType.UNKNOWN.name
) {
filteredRuleActions.add(ruleAction)
}
}
return filteredRuleActions
}
}