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

chore: [ANDROAPP-6135] Update rule engine and expression parser to re… #3623

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.hisp.dhis.android.core.program.Program
import org.hisp.dhis.android.core.program.ProgramRuleActionType
import org.hisp.dhis.antlr.ParserExceptionWithoutContext
import org.hisp.dhis.lib.expression.Expression
import org.hisp.dhis.lib.expression.ExpressionMode
import org.hisp.dhis.lib.expression.spi.ExpressionData
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor
import org.hisp.dhis.rules.api.EnvironmentVariables.ENV_VARIABLES
Expand Down Expand Up @@ -40,7 +41,7 @@ class TroubleshootingRepository(
rule.condition,
valueMap,
null,
Expression.Mode.RULE_ENGINE_CONDITION,
ExpressionMode.RULE_ENGINE_CONDITION,
)
if (ruleConditionResult.isNotEmpty()) {
ruleValidationItem = ruleValidationItem.copy(conditionError = ruleConditionResult)
Expand Down Expand Up @@ -164,7 +165,7 @@ class TroubleshootingRepository(
condition: String,
valueMap: Map<String, RuleVariableValue>,
ruleActionType: String? = null,
mode: Expression.Mode,
mode: ExpressionMode,
): String {
if (condition.isEmpty()) {
return if (ruleActionType != null) {
Expand Down Expand Up @@ -230,7 +231,7 @@ class TroubleshootingRepository(
ruleAction.data ?: "",
valueMap,
ruleAction.ruleActionType(),
Expression.Mode.RULE_ENGINE_ACTION,
ExpressionMode.RULE_ENGINE_ACTION,
)
actionConditionResult.ifEmpty {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import org.hisp.dhis.rules.models.Rule
import org.hisp.dhis.rules.models.RuleAttributeValue
import org.hisp.dhis.rules.models.RuleDataValue
import org.hisp.dhis.rules.models.RuleEnrollment
import org.hisp.dhis.rules.models.RuleEnrollmentStatus
import org.hisp.dhis.rules.models.RuleEvent
import org.hisp.dhis.rules.models.RuleEventStatus
import org.hisp.dhis.rules.models.RuleVariable
import java.util.Calendar
import java.util.Date
Expand Down Expand Up @@ -112,9 +114,9 @@ class RulesRepository(private val d2: D2) {
.uid(event.programStage())
.blockingGet()!!.name()!!,
status = if (event.status() == EventStatus.VISITED) {
RuleEvent.Status.ACTIVE
RuleEventStatus.ACTIVE
} else {
RuleEvent.Status.valueOf(event.status()!!.name)
RuleEventStatus.valueOf(event.status()!!.name)
},
eventDate = Instant.fromEpochMilliseconds(event.eventDate()!!.time),
dueDate = event.dueDate()?.let {
Expand Down Expand Up @@ -206,9 +208,9 @@ class RulesRepository(private val d2: D2) {
.blockingGet()!!.name()!!,
status =
if (event.status() == EventStatus.VISITED) {
RuleEvent.Status.ACTIVE
RuleEventStatus.ACTIVE
} else {
RuleEvent.Status.valueOf(event.status()!!.name)
RuleEventStatus.valueOf(event.status()!!.name)
},
eventDate = event.eventDate()!!.toRuleEngineInstant(),
dueDate = event.dueDate()?.toRuleEngineLocalDate(),
Expand Down Expand Up @@ -242,7 +244,7 @@ class RulesRepository(private val d2: D2) {
programName!!,
Calendar.getInstance().time.toRuleEngineLocalDate(),
Calendar.getInstance().time.toRuleEngineLocalDate(),
RuleEnrollment.Status.CANCELLED,
RuleEnrollmentStatus.CANCELLED,
event.organisationUnit()!!,
ouCode,
ArrayList(),
Expand All @@ -255,7 +257,7 @@ class RulesRepository(private val d2: D2) {
programName!!,
(enrollment.incidentDate() ?: Date()).toRuleEngineLocalDate(),
enrollment.enrollmentDate()!!.toRuleEngineLocalDate(),
RuleEnrollment.Status.valueOf(enrollment.status()!!.name),
RuleEnrollmentStatus.valueOf(enrollment.status()!!.name),
event.organisationUnit()!!,
ouCode,
getAttributesValues(enrollment),
Expand Down Expand Up @@ -314,7 +316,7 @@ class RulesRepository(private val d2: D2) {
programName = d2.program(enrollment.program()!!)?.name()!!,
incidentDate = (enrollment.incidentDate() ?: Date()).toRuleEngineLocalDate(),
enrollmentDate = (enrollment.enrollmentDate() ?: Date()).toRuleEngineLocalDate(),
status = RuleEnrollment.Status.valueOf(enrollment.status()!!.name),
status = RuleEnrollmentStatus.valueOf(enrollment.status()!!.name),
organisationUnit = enrollment.organisationUnit()!!,
organisationUnitCode = d2.organisationUnit(enrollment.organisationUnit()!!)
?.code() ?: "",
Expand All @@ -328,7 +330,7 @@ class RulesRepository(private val d2: D2) {
event = event.uid(),
programStage = event.programStage()!!,
programStageName = d2.programStage(event.programStage()!!)?.name()!!,
status = RuleEvent.Status.valueOf(event.status()!!.name),
status = RuleEventStatus.valueOf(event.status()!!.name),
eventDate = event.eventDate()!!.toRuleEngineInstant(),
dueDate = event.dueDate()?.toRuleEngineLocalDate(),
completedDate = event.completedDate()?.toRuleEngineLocalDate(),
Expand Down
14 changes: 8 additions & 6 deletions form/src/main/java/org/dhis2/form/data/RulesRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import org.hisp.dhis.android.core.program.ProgramRule
import org.hisp.dhis.rules.models.Rule
import org.hisp.dhis.rules.models.RuleAttributeValue
import org.hisp.dhis.rules.models.RuleEnrollment
import org.hisp.dhis.rules.models.RuleEnrollmentStatus
import org.hisp.dhis.rules.models.RuleEvent
import org.hisp.dhis.rules.models.RuleEventStatus
import org.hisp.dhis.rules.models.RuleVariable
import java.util.Calendar
import java.util.Date
Expand Down Expand Up @@ -131,9 +133,9 @@ class RulesRepository(private val d2: D2) {
.uid(event.programStage())
.blockingGet()!!.name()!!,
status = if (event.status() == EventStatus.VISITED) {
RuleEvent.Status.ACTIVE
RuleEventStatus.ACTIVE
} else {
RuleEvent.Status.valueOf(event.status()!!.name)
RuleEventStatus.valueOf(event.status()!!.name)
},
eventDate = Instant.fromEpochMilliseconds(event.eventDate()!!.time),
dueDate = event.dueDate()?.let {
Expand Down Expand Up @@ -226,9 +228,9 @@ class RulesRepository(private val d2: D2) {
.blockingGet()!!.name()!!,
status =
if (event.status() == EventStatus.VISITED) {
RuleEvent.Status.ACTIVE
RuleEventStatus.ACTIVE
} else {
RuleEvent.Status.valueOf(event.status()!!.name)
RuleEventStatus.valueOf(event.status()!!.name)
},
eventDate = event.eventDate()!!.toRuleEngineInstant(),
dueDate = event.dueDate()?.toRuleEngineLocalDate(),
Expand Down Expand Up @@ -263,7 +265,7 @@ class RulesRepository(private val d2: D2) {
programName!!,
Calendar.getInstance().time.toRuleEngineLocalDate(),
Calendar.getInstance().time.toRuleEngineLocalDate(),
RuleEnrollment.Status.CANCELLED,
RuleEnrollmentStatus.CANCELLED,
event.organisationUnit()!!,
ouCode,
ArrayList(),
Expand All @@ -278,7 +280,7 @@ class RulesRepository(private val d2: D2) {
programName!!,
(enrollment.incidentDate() ?: Date()).toRuleEngineLocalDate(),
enrollment.enrollmentDate()!!.toRuleEngineLocalDate(),
RuleEnrollment.Status.valueOf(enrollment.status()!!.name),
RuleEnrollmentStatus.valueOf(enrollment.status()!!.name),
event.organisationUnit()!!,
ouCode,
getAttributesValues(enrollment),
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ hiltCompiler = '1.0.0'
jacoco = '0.8.10'
designSystem = "0.2-20240430.062706-60"
dhis2sdk = "1.10.0-20240426.151240-44"
ruleEngine = "3.0.0-20240119.134348-12"
expressionParser = "1.1.0-20240219.115041-14"
ruleEngine = "3.0.0"
expressionParser = "1.1.0"
appcompat = "1.6.1"
annotation = "1.6.0"
cardview = "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.hisp.dhis.rules.api.RuleEngine
import org.hisp.dhis.rules.models.RuleDataValue
import org.hisp.dhis.rules.models.RuleEffect
import org.hisp.dhis.rules.models.RuleEvent
import org.hisp.dhis.rules.models.RuleEventStatus
import org.hisp.dhis.rules.models.RuleVariable
import timber.log.Timber
import java.util.Date
Expand Down Expand Up @@ -129,7 +130,7 @@ class RuleValidationHelperImpl @Inject constructor(
eventUid ?: UUID.randomUUID().toString(),
programStage.uid(),
programStage.name()!!,
RuleEvent.Status.ACTIVE,
RuleEventStatus.ACTIVE,
period.toRuleEngineInstant(),
period.toRuleEngineLocalDate(),
period.toRuleEngineLocalDate(),
Expand Down Expand Up @@ -230,9 +231,9 @@ class RuleValidationHelperImpl @Inject constructor(
d2.programModule().programStages().uid(event.programStage())
.blockingGet()!!.name()!!,
if (event.status() == EventStatus.VISITED) {
RuleEvent.Status.ACTIVE
RuleEventStatus.ACTIVE
} else {
RuleEvent.Status.valueOf(event.status()!!.name)
RuleEventStatus.valueOf(event.status()!!.name)
},
(event.eventDate() ?: Date()).toRuleEngineInstant(),
event.dueDate()?.toRuleEngineLocalDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import org.hisp.dhis.rules.models.Rule
import org.hisp.dhis.rules.models.RuleAction
import org.hisp.dhis.rules.models.RuleDataValue
import org.hisp.dhis.rules.models.RuleEnrollment
import org.hisp.dhis.rules.models.RuleEnrollmentStatus
import org.hisp.dhis.rules.models.RuleEvent
import org.hisp.dhis.rules.models.RuleEventStatus
import org.hisp.dhis.rules.models.RuleValueType
import org.hisp.dhis.rules.models.RuleVariable
import org.hisp.dhis.rules.models.RuleVariableCurrentEvent
Expand Down Expand Up @@ -124,7 +126,7 @@ class ProgramRuleTests {
"test_program",
Date().toRuleEngineLocalDate(),
Date().toRuleEngineLocalDate(),
RuleEnrollment.Status.ACTIVE,
RuleEnrollmentStatus.ACTIVE,
"test_ou",
"test_ou_code",
emptyList(),
Expand All @@ -134,7 +136,7 @@ class ProgramRuleTests {
"test_event",
"test_program_stage",
"",
RuleEvent.Status.ACTIVE,
RuleEventStatus.ACTIVE,
Date().toRuleEngineInstant(),
Date().toRuleEngineLocalDate(),
null,
Expand Down
Loading