Skip to content

Commit

Permalink
chore: [ANDROAPP-6529] update rule engine version to 3.1.0 (#3939)
Browse files Browse the repository at this point in the history
  • Loading branch information
taridepaco authored Dec 23, 2024
1 parent c4e82db commit e71cf6a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,6 @@ fun List<TrackedEntityDataValue>.toRuleDataValue(
value = ""
}
RuleDataValue(
eventDate = event.eventDate()!!.toRuleEngineInstant(),
programStage = event.programStage()!!,
dataElement = it.dataElement()!!,
value = value!!,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.dhis2.mobileProgramRules

import android.os.Build
import android.text.TextUtils.isEmpty
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
Expand Down Expand Up @@ -115,6 +116,9 @@ class RulesRepository(private val d2: D2) {
.uid(
event.organisationUnit(),
).blockingGet()?.code(),
createdDate = event.created()
?.let { Instant.fromEpochMilliseconds(it.time) }
?: Clock.System.now(),
dataValues = event.trackedEntityDataValues()?.toRuleDataValue(
event,
d2.dataElementModule().dataElements(),
Expand Down Expand Up @@ -202,6 +206,9 @@ class RulesRepository(private val d2: D2) {
organisationUnitCode = d2.organisationUnitModule()
.organisationUnits().uid(event.organisationUnit())
.blockingGet()?.code(),
createdDate = event.created()
?.let { Instant.fromEpochMilliseconds(it.time) }
?: Clock.System.now(),
dataValues =
event.trackedEntityDataValues()?.toRuleDataValue(
event,
Expand Down Expand Up @@ -319,6 +326,9 @@ class RulesRepository(private val d2: D2) {
completedDate = event.completedDate()?.toRuleEngineLocalDate(),
organisationUnit = event.organisationUnit()!!,
organisationUnitCode = d2.organisationUnit(event.organisationUnit()!!)?.code(),
createdDate = event.created()
?.let { Instant.fromEpochMilliseconds(it.time) }
?: Clock.System.now(),
dataValues = emptyList(),
)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ hilt = '2.47'
jacoco = '0.8.10'
designSystem = "0.4.1-20241212.083942-7"
dhis2sdk = "1.11.1-SNAPSHOT"
ruleEngine = "3.0.0"
ruleEngine = "3.2.0"
expressionParser = "1.1.0"
appcompat = "1.6.1"
annotation = "1.6.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.dhis2.android.rtsm.services.rules

import io.reactivex.Flowable
import io.reactivex.Single
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import org.apache.commons.lang3.math.NumberUtils
import org.dhis2.android.rtsm.data.AppConfig
import org.dhis2.android.rtsm.data.TransactionType
Expand Down Expand Up @@ -58,9 +60,7 @@ class RuleValidationHelperImpl @Inject constructor(
addAll(
entryDataValues(
entry.qty,
programStage.uid(),
transaction,
entry.date,
appConfig,
),
)
Expand All @@ -73,8 +73,6 @@ class RuleValidationHelperImpl @Inject constructor(
ruleEffect.data?.let { data ->
dataValues.add(
RuleDataValue(
entry.date.toRuleEngineInstant(),
programStage.uid(),
ruleAction.field()!!,
data,
),
Expand Down Expand Up @@ -132,6 +130,7 @@ class RuleValidationHelperImpl @Inject constructor(
programStage.name()!!,
RuleEventStatus.ACTIVE,
period.toRuleEngineInstant(),
period.toRuleEngineInstant(),
period.toRuleEngineLocalDate(),
period.toRuleEngineLocalDate(),
organisationUnit,
Expand Down Expand Up @@ -225,23 +224,28 @@ class RuleValidationHelperImpl @Inject constructor(
.toFlowable().flatMapIterable { events -> events }
.map { event ->
RuleEvent(
event.uid(),
event.programStage()!!,
event = event.uid(),
programStage = event.programStage()!!,
programStageName =
d2.programModule().programStages().uid(event.programStage())
.blockingGet()!!.name()!!,
status =
if (event.status() == EventStatus.VISITED) {
RuleEventStatus.ACTIVE
} else {
RuleEventStatus.valueOf(event.status()!!.name)
},
(event.eventDate() ?: Date()).toRuleEngineInstant(),
event.dueDate()?.toRuleEngineLocalDate(),
event.completedDate()?.toRuleEngineLocalDate(),
event.organisationUnit()!!,
d2.organisationUnitModule()
eventDate = (event.eventDate() ?: Date()).toRuleEngineInstant(),
createdDate = event.created()
?.let { Instant.fromEpochMilliseconds(it.time) }
?: Clock.System.now(),
dueDate = event.dueDate()?.toRuleEngineLocalDate(),
completedDate = event.completedDate()?.toRuleEngineLocalDate(),
organisationUnit = event.organisationUnit()!!,
organisationUnitCode = d2.organisationUnitModule()
.organisationUnits().uid(event.organisationUnit())
.blockingGet()?.code(),
event.trackedEntityDataValues()?.toRuleDataValue(
dataValues = event.trackedEntityDataValues()?.toRuleDataValue(
event,
d2.dataElementModule().dataElements(),
d2.programModule().programRuleVariables(),
Expand Down Expand Up @@ -271,9 +275,7 @@ class RuleValidationHelperImpl @Inject constructor(

private fun entryDataValues(
qty: String?,
programStage: String,
transaction: Transaction,
eventDate: Date,
appConfig: AppConfig,
): List<RuleDataValue> {
val values = mutableListOf<RuleDataValue>()
Expand All @@ -284,8 +286,6 @@ class RuleValidationHelperImpl @Inject constructor(
ConfigUtils.getTransactionDataElement(transaction.transactionType, appConfig)
values.add(
RuleDataValue(
eventDate = eventDate.toRuleEngineInstant(),
programStage = programStage,
dataElement = deUid,
value = qty,
),
Expand All @@ -301,8 +301,6 @@ class RuleValidationHelperImpl @Inject constructor(
?.code()?.let { code ->
values.add(
RuleDataValue(
eventDate = eventDate.toRuleEngineInstant(),
programStage = programStage,
dataElement = appConfig.distributedTo,
value = code,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fun printRuleEffects(
dataValues?.forEach {
printRuleEngineData(
buffer,
" DE = ${it.dataElement}, value = ${it.value}, eventDate= ${it.eventDate}",
" DE = ${it.dataElement}, value = ${it.value}",
)
}
printSeparator(buffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,43 +138,34 @@ class ProgramRuleTests {
"",
RuleEventStatus.ACTIVE,
Date().toRuleEngineInstant(),
Date().toRuleEngineInstant(),
Date().toRuleEngineLocalDate(),
null,
"",
"",
listOf(
// PRevious Stock Balance
RuleDataValue(
Date().toRuleEngineInstant(),
"",
"oc8tn8CewiP",
"3",
),
// PSM Stock received
RuleDataValue(
Date().toRuleEngineInstant(),
"",
"j3ydinp6Qp8",
"4",
),
// PSM- Stock consumed distributed
RuleDataValue(
Date().toRuleEngineInstant(),
"",
"lpGYJoVUudr",
"2",
),
// PSM- Stock discarded
RuleDataValue(
Date().toRuleEngineInstant(),
"",
"I7cmT3iXT0y",
"1",
),
// PSM- Stock corrected
RuleDataValue(
Date().toRuleEngineInstant(),
"",
"ej1YwWaYGmm",
"3",
),
Expand Down

0 comments on commit e71cf6a

Please sign in to comment.