Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: Clean up description call to rule engine #117

Merged
merged 12 commits into from
Jan 17, 2024
120 changes: 0 additions & 120 deletions src/commonMain/kotlin/org/hisp/dhis/rules/RuleEngine.kt

This file was deleted.

13 changes: 0 additions & 13 deletions src/commonMain/kotlin/org/hisp/dhis/rules/RuleEngineContext.kt

This file was deleted.

28 changes: 0 additions & 28 deletions src/commonMain/kotlin/org/hisp/dhis/rules/RuleEngineExecution.kt

This file was deleted.

70 changes: 0 additions & 70 deletions src/commonMain/kotlin/org/hisp/dhis/rules/RuleEngineFilter.kt

This file was deleted.

36 changes: 0 additions & 36 deletions src/commonMain/kotlin/org/hisp/dhis/rules/RuleEngineIntent.kt

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.hisp.dhis.rules
package org.hisp.dhis.rules.api

/**
* Class is place holder for program rule variable, Constant and program environment variable display name and type.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.hisp.dhis.rules.api

import org.hisp.dhis.rules.utils.RuleEngineUtils

object EnvironmentVariables {
val ENV_VARIABLES = mapOf(
Pair(RuleEngineUtils.ENV_VAR_COMPLETED_DATE, ItemValueType.DATE),
Pair(RuleEngineUtils.ENV_VAR_CURRENT_DATE, ItemValueType.DATE),
Pair(RuleEngineUtils.ENV_VAR_EVENT_DATE, ItemValueType.DATE),
Pair(RuleEngineUtils.ENV_VAR_INCIDENT_DATE, ItemValueType.DATE),
Pair(RuleEngineUtils.ENV_VAR_ENROLLMENT_DATE, ItemValueType.DATE),
Pair(RuleEngineUtils.ENV_VAR_DUE_DATE, ItemValueType.DATE),
Pair(RuleEngineUtils.ENV_VAR_EVENT_COUNT, ItemValueType.NUMBER),
Pair(RuleEngineUtils.ENV_VAR_TEI_COUNT, ItemValueType.NUMBER),
Pair(RuleEngineUtils.ENV_VAR_ENROLLMENT_COUNT, ItemValueType.NUMBER),
Pair(RuleEngineUtils.ENV_VAR_EVENT_ID, ItemValueType.NUMBER),
Pair(RuleEngineUtils.ENV_VAR_PROGRAM_STAGE_ID, ItemValueType.NUMBER),
Pair(RuleEngineUtils.ENV_VAR_ENROLLMENT_ID, ItemValueType.NUMBER),
Pair(RuleEngineUtils.ENV_VAR_ENROLLMENT_STATUS, ItemValueType.TEXT),
Pair(RuleEngineUtils.ENV_VAR_EVENT_STATUS, ItemValueType.TEXT),
Pair(RuleEngineUtils.ENV_VAR_OU, ItemValueType.TEXT),
Pair(RuleEngineUtils.ENV_VAR_OU_CODE, ItemValueType.TEXT),
Pair(RuleEngineUtils.ENV_VAR_ENVIRONMENT, ItemValueType.TEXT),
Pair(RuleEngineUtils.ENV_VAR_PROGRAM_NAME, ItemValueType.TEXT),
Pair(RuleEngineUtils.ENV_VAR_PROGRAM_STAGE_NAME, ItemValueType.TEXT)
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.hisp.dhis.rules
package org.hisp.dhis.rules.api

import org.hisp.dhis.lib.expression.spi.ValueType

Expand Down
20 changes: 20 additions & 0 deletions src/commonMain/kotlin/org/hisp/dhis/rules/api/RuleEngine.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.hisp.dhis.rules.api

import org.hisp.dhis.rules.engine.DefaultRuleEngine
import org.hisp.dhis.rules.models.*
import kotlin.jvm.JvmStatic

interface RuleEngine {
fun validate(expression: String, dataItemStore: Map<String, DataItem>): RuleValidationResult
fun validateDataFieldExpression(expression: String, dataItemStore: Map<String, DataItem>): RuleValidationResult
fun evaluateAll(enrollmentTarget: RuleEnrollment?, eventsTarget: List<RuleEvent>, executionContext: RuleEngineContext): List<RuleEffects>
fun evaluate(target: RuleEnrollment, ruleEvents: List<RuleEvent>, executionContext: RuleEngineContext): List<RuleEffect>
fun evaluate(target: RuleEvent, ruleEnrollment: RuleEnrollment?, ruleEvents: List<RuleEvent>, executionContext: RuleEngineContext): List<RuleEffect>

companion object {
@JvmStatic
fun getInstance(): RuleEngine {
vgarciabnz marked this conversation as resolved.
Show resolved Hide resolved
return DefaultRuleEngine()
}
}
}
13 changes: 13 additions & 0 deletions src/commonMain/kotlin/org/hisp/dhis/rules/api/RuleEngineContext.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.hisp.dhis.rules.api

import org.hisp.dhis.rules.models.Rule
import org.hisp.dhis.rules.models.RuleEnrollment
import org.hisp.dhis.rules.models.RuleEvent
import org.hisp.dhis.rules.models.RuleVariable

data class RuleEngineContext(
val rules: List<Rule>,
val ruleVariables: List<RuleVariable> = emptyList(),
val supplementaryData: Map<String, List<String>> = emptyMap(),
val constantsValues: Map<String, String> = emptyMap()
)
Loading