From c6ff765237002aefdf436ef0622eb779c6b6a133 Mon Sep 17 00:00:00 2001 From: Enrico Colasante Date: Thu, 11 Apr 2024 12:59:56 +0200 Subject: [PATCH] feat!: Extract enums to top level and use them in Js interface (#126) * Use enums in Js interface * Fix tests * Opt-in for JsExport annotation * Fix code review comments * Use last snapshot version of expression-parser * Use last snapshot version of expression-parser --- build.gradle.kts | 7 +- buildSrc/build.gradle.kts | 2 +- .../org/hisp/dhis/rules/api/ItemValueType.kt | 5 +- .../dhis/rules/engine/DefaultRuleEngine.kt | 7 +- .../rules/engine/RuleConditionEvaluator.kt | 11 +- .../org/hisp/dhis/rules/models/Option.kt | 2 - .../dhis/rules/models/RuleAttributeValue.kt | 2 - .../hisp/dhis/rules/models/RuleEnrollment.kt | 10 +- .../dhis/rules/models/RuleEnrollmentStatus.kt | 10 ++ .../org/hisp/dhis/rules/models/RuleEvent.kt | 13 +- .../hisp/dhis/rules/models/RuleEventStatus.kt | 13 ++ .../dhis/rules/models/RuleValidationResult.kt | 5 - .../hisp/dhis/rules/models/RuleValueType.kt | 3 + .../dhis/rules/models/TrackerObjectType.kt | 3 + .../org/hisp/dhis/rules/ConstantsValueTest.kt | 8 +- .../dhis/rules/ProgramRuleVariableTest.kt | 6 +- .../dhis/rules/RuleEngineEffectTypesTest.kt | 13 +- .../hisp/dhis/rules/RuleEngineFunctionTest.kt | 158 +++++++++--------- .../org/hisp/dhis/rules/RuleEngineTest.kt | 3 +- .../dhis/rules/RuleEngineValueTypesTest.kt | 6 +- .../dhis/rules/RuleEngineVariableNameTest.kt | 70 ++++---- .../hisp/dhis/rules/VariableValueTypeTest.kt | 4 +- .../dhis/rules/models/CalculatedValueTest.kt | 12 +- .../dhis/rules/models/RuleEnrollmentTest.kt | 4 +- .../hisp/dhis/rules/models/RuleEventTest.kt | 8 +- .../models/RuleVariableValueMapBuilderTest.kt | 70 ++++---- .../kotlin/org/hisp/dhis/rules/DataItemJs.kt | 11 +- .../org/hisp/dhis/rules/RuleActionJs.kt | 1 - .../org/hisp/dhis/rules/RuleDataValueJs.kt | 1 - .../org/hisp/dhis/rules/RuleEffectJs.kt | 1 - .../org/hisp/dhis/rules/RuleEffectsJs.kt | 13 +- .../hisp/dhis/rules/RuleEngineContextJs.kt | 1 - .../org/hisp/dhis/rules/RuleEngineJs.kt | 24 ++- .../org/hisp/dhis/rules/RuleEnrollmentJs.kt | 4 +- .../kotlin/org/hisp/dhis/rules/RuleEventJs.kt | 4 +- .../kotlin/org/hisp/dhis/rules/RuleJs.kt | 1 - .../org/hisp/dhis/rules/RuleVariableJs.kt | 17 +- .../org/hisp/dhis/rules/RuleVariableType.kt | 1 + 38 files changed, 254 insertions(+), 280 deletions(-) create mode 100644 src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentStatus.kt create mode 100644 src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEventStatus.kt diff --git a/build.gradle.kts b/build.gradle.kts index a30560fb..c56d87b9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -63,9 +63,14 @@ kotlin { sourceSets { + all { + languageSettings.apply { + optIn("kotlin.js.ExperimentalJsExport") + } + } val commonMain by getting { dependencies { - implementation("org.hisp.dhis.lib.expression:expression-parser:1.1.0-SNAPSHOT") + implementation("org.hisp.dhis.lib.expression:expression-parser:1.1.0-20240411.094221-16") implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1") } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 3c95aa85..d3aa0b81 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -2,7 +2,7 @@ plugins { `kotlin-dsl` } -val kotlinVersion = "1.9.21" +val kotlinVersion = "1.9.22" val dokkaVersion = "1.9.10" val nexusPluginVersion = "1.3.0" val npmPluginVersion = "3.4.1" diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/api/ItemValueType.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/api/ItemValueType.kt index f9fdf634..f4ea6899 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/api/ItemValueType.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/api/ItemValueType.kt @@ -1,6 +1,7 @@ package org.hisp.dhis.rules.api import org.hisp.dhis.lib.expression.spi.ValueType +import kotlin.js.JsExport /* * Copyright (c) 2004-2020, University of Oslo @@ -30,9 +31,7 @@ import org.hisp.dhis.lib.expression.spi.ValueType * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/** - * @author Zubair Asghar - */ +@JsExport enum class ItemValueType(val value: String) { NUMBER("1.0"), DATE("2020-01-01"), diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/engine/DefaultRuleEngine.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/engine/DefaultRuleEngine.kt index bf2d4f7b..6941f296 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/engine/DefaultRuleEngine.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/engine/DefaultRuleEngine.kt @@ -1,6 +1,7 @@ package org.hisp.dhis.rules.engine import org.hisp.dhis.lib.expression.Expression +import org.hisp.dhis.lib.expression.ExpressionMode import org.hisp.dhis.lib.expression.spi.IllegalExpressionException import org.hisp.dhis.lib.expression.spi.ParseException import org.hisp.dhis.lib.expression.spi.ValueType @@ -51,15 +52,15 @@ internal class DefaultRuleEngine: RuleEngine { override fun validate(expression: String, dataItemStore: Map): RuleValidationResult { // Rule condition expression should be evaluated against Boolean - return getExpressionDescription(expression, Expression.Mode.RULE_ENGINE_CONDITION, dataItemStore) + return getExpressionDescription(expression, ExpressionMode.RULE_ENGINE_CONDITION, dataItemStore) } override fun validateDataFieldExpression(expression: String, dataItemStore: Map): RuleValidationResult { // Rule action data field should be evaluated against all i.e Boolean, String, Date and Numerical value - return getExpressionDescription(expression, Expression.Mode.RULE_ENGINE_ACTION, dataItemStore) + return getExpressionDescription(expression, ExpressionMode.RULE_ENGINE_ACTION, dataItemStore) } - private fun getExpressionDescription(expression: String, mode: Expression.Mode, dataItemStore: Map): RuleValidationResult { + private fun getExpressionDescription(expression: String, mode: ExpressionMode, dataItemStore: Map): RuleValidationResult { return try { val validationMap: Map = dataItemStore.mapValues { e -> e.value.valueType.toValueType() } Expression(expression, mode, false).validate(validationMap) diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/engine/RuleConditionEvaluator.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/engine/RuleConditionEvaluator.kt index 50577304..a4239d7f 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/engine/RuleConditionEvaluator.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/engine/RuleConditionEvaluator.kt @@ -1,6 +1,7 @@ package org.hisp.dhis.rules.engine 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.lib.expression.spi.IllegalExpressionException import org.hisp.dhis.rules.createLogger @@ -57,7 +58,7 @@ internal class RuleConditionEvaluator { rule.condition, valueMap, supplementaryData, - Expression.Mode.RULE_ENGINE_CONDITION + ExpressionMode.RULE_ENGINE_CONDITION ).toBoolean() ) { for (action in rule.actions) { @@ -68,7 +69,7 @@ internal class RuleConditionEvaluator { unwrapVariableName(action.content()!!), RuleVariableValue( RuleValueType.TEXT, - process(action.data, valueMap, supplementaryData, Expression.Mode.RULE_ENGINE_ACTION), + process(action.data, valueMap, supplementaryData, ExpressionMode.RULE_ENGINE_ACTION), listOf(), null ), @@ -134,7 +135,7 @@ internal class RuleConditionEvaluator { private fun process( condition: String?, valueMap: Map, - supplementaryData: Map>, mode: Expression.Mode + supplementaryData: Map>, mode: ExpressionMode ): String { if (condition==null || condition.isEmpty()) { return "" @@ -180,7 +181,7 @@ internal class RuleConditionEvaluator { supplementaryData: Map> ): RuleEffect { if (ruleAction.type == "ASSIGN") { - val data = process(ruleAction.data, valueMap, supplementaryData, Expression.Mode.RULE_ENGINE_ACTION) + val data = process(ruleAction.data, valueMap, supplementaryData, ExpressionMode.RULE_ENGINE_ACTION) updateValueMap(ruleAction.field()!!, RuleVariableValue(RuleValueType.TEXT, data, listOf(), null), valueMap) return if (data.isEmpty()) { RuleEffect(rule.uid, ruleAction, null) @@ -188,7 +189,7 @@ internal class RuleConditionEvaluator { RuleEffect(rule.uid, ruleAction, data) } } - val data = if (!ruleAction.data.isNullOrEmpty()) process(ruleAction.data, valueMap, supplementaryData, Expression.Mode.RULE_ENGINE_ACTION) else "" + val data = if (!ruleAction.data.isNullOrEmpty()) process(ruleAction.data, valueMap, supplementaryData, ExpressionMode.RULE_ENGINE_ACTION) else "" return RuleEffect( rule.uid, ruleAction, diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/models/Option.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/models/Option.kt index 43b597a3..91f26b2e 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/models/Option.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/Option.kt @@ -1,8 +1,6 @@ package org.hisp.dhis.rules.models -import kotlin.js.ExperimentalJsExport import kotlin.js.JsExport @JsExport -@OptIn(ExperimentalJsExport::class) data class Option(val name: String, val code: String) diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleAttributeValue.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleAttributeValue.kt index 353b14e1..3c9e1570 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleAttributeValue.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleAttributeValue.kt @@ -1,10 +1,8 @@ package org.hisp.dhis.rules.models -import kotlin.js.ExperimentalJsExport import kotlin.js.JsExport @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleAttributeValue( val trackedEntityAttribute: String, val value: String diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEnrollment.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEnrollment.kt index 6976a637..e146de3d 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEnrollment.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEnrollment.kt @@ -7,14 +7,8 @@ data class RuleEnrollment( val programName: String, val incidentDate: LocalDate, val enrollmentDate: LocalDate, - val status: Status, + val status: RuleEnrollmentStatus, val organisationUnit: String, val organisationUnitCode: String, val attributeValues: List -) { - enum class Status { - ACTIVE, - COMPLETED, - CANCELLED - } -} +) diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentStatus.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentStatus.kt new file mode 100644 index 00000000..11c96d4d --- /dev/null +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentStatus.kt @@ -0,0 +1,10 @@ +package org.hisp.dhis.rules.models + +import kotlin.js.JsExport + +@JsExport +enum class RuleEnrollmentStatus { + ACTIVE, + COMPLETED, + CANCELLED +} \ No newline at end of file diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEvent.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEvent.kt index 3dfc934a..411643fa 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEvent.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEvent.kt @@ -7,20 +7,11 @@ data class RuleEvent( val event: String, val programStage: String, val programStageName: String, - val status: Status, + val status: RuleEventStatus, val eventDate: Instant, val dueDate: LocalDate?, val completedDate: LocalDate?, val organisationUnit: String, val organisationUnitCode: String?, val dataValues: List -) { - enum class Status { - ACTIVE, - COMPLETED, - SCHEDULE, - SKIPPED, - VISITED, - OVERDUE - } -} +) diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEventStatus.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEventStatus.kt new file mode 100644 index 00000000..5476f787 --- /dev/null +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleEventStatus.kt @@ -0,0 +1,13 @@ +package org.hisp.dhis.rules.models + +import kotlin.js.JsExport + +@JsExport +enum class RuleEventStatus { + ACTIVE, + COMPLETED, + SCHEDULE, + SKIPPED, + VISITED, + OVERDUE +} \ No newline at end of file diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleValidationResult.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleValidationResult.kt index 7b6837dc..150d4327 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleValidationResult.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleValidationResult.kt @@ -1,10 +1,6 @@ package org.hisp.dhis.rules.models -import org.hisp.dhis.rules.api.RuleEngine -import org.hisp.dhis.rules.engine.DefaultRuleEngine -import kotlin.js.ExperimentalJsExport import kotlin.js.JsExport -import kotlin.jvm.JvmOverloads import kotlin.jvm.JvmStatic /* @@ -36,7 +32,6 @@ import kotlin.jvm.JvmStatic */ @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleValidationResult( val valid: Boolean, val errorMessage: String? = null, diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleValueType.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleValueType.kt index 758fa5ee..1df5f8b3 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleValueType.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleValueType.kt @@ -1,5 +1,8 @@ package org.hisp.dhis.rules.models +import kotlin.js.JsExport + +@JsExport enum class RuleValueType(private val defaultValue: Any) { TEXT(""), NUMERIC(0.0), diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/models/TrackerObjectType.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/models/TrackerObjectType.kt index 74f7df85..dae11115 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/models/TrackerObjectType.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/TrackerObjectType.kt @@ -1,8 +1,11 @@ package org.hisp.dhis.rules.models +import kotlin.js.JsExport + /** * This Enum specify the type of tracker object. */ +@JsExport enum class TrackerObjectType(private val type: String) { EVENT("event"), ENROLLMENT("enrollment") diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/ConstantsValueTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/ConstantsValueTest.kt index b034a7cd..8aef755e 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/ConstantsValueTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/ConstantsValueTest.kt @@ -50,7 +50,7 @@ class ConstantsValueTest { programName = "test_program", incidentDate = LocalDate.Companion.currentDate(), enrollmentDate = LocalDate.Companion.currentDate(), - status = RuleEnrollment.Status.ACTIVE, + status = RuleEnrollmentStatus.ACTIVE, organisationUnit = "test_ou", organisationUnitCode = "test_ou_code", attributeValues = listOf(RuleAttributeValue("test_attribute", "test_value")) @@ -76,7 +76,7 @@ class ConstantsValueTest { programName = "test_program", incidentDate = LocalDate.Companion.currentDate(), enrollmentDate = LocalDate.Companion.currentDate(), - status = RuleEnrollment.Status.ACTIVE, + status = RuleEnrollmentStatus.ACTIVE, organisationUnit = "test_ou", organisationUnitCode = "test_ou_code", attributeValues = listOf(RuleAttributeValue("test_attribute", "test_value")) @@ -104,7 +104,7 @@ class ConstantsValueTest { programName = "test_program", incidentDate = LocalDate.Companion.currentDate(), enrollmentDate = LocalDate.Companion.currentDate(), - status = RuleEnrollment.Status.ACTIVE, + status = RuleEnrollmentStatus.ACTIVE, organisationUnit = "test_ou", organisationUnitCode = "test_ou_code", attributeValues = listOf(RuleAttributeValue("test_attribute", "test_value")) @@ -126,7 +126,7 @@ class ConstantsValueTest { event = "test_event", programStage = "test_program_stage", programStageName = "", - status = RuleEvent.Status.ACTIVE, + status = RuleEventStatus.ACTIVE, eventDate = Clock.System.now(), dueDate = LocalDate.currentDate(), organisationUnit = "", diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/ProgramRuleVariableTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/ProgramRuleVariableTest.kt index b08a641b..90417cda 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/ProgramRuleVariableTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/ProgramRuleVariableTest.kt @@ -224,7 +224,7 @@ class ProgramRuleVariableTest { PROGRAM_NAME, INCIDENT_DATE, ENROLLMENT_DATE, - RuleEnrollment.Status.ACTIVE, + RuleEnrollmentStatus.ACTIVE, ORGANISATION_UNIT, ORGANISATION_UNIT_CODE, listOf(RuleAttributeValue("test_attribute", "test_value")) @@ -246,11 +246,11 @@ class ProgramRuleVariableTest { private val INCIDENT_DATE = LocalDate.parse(INCIDENT_DATE_STRING) private const val PROGRAM_STAGE = "program stage" private const val PROGRAM_STAGE_NAME = "program stage name" - private val RULE_EVENT_STATUS = RuleEvent.Status.ACTIVE + private val RULE_EVENT_STATUS = RuleEventStatus.ACTIVE private const val ORGANISATION_UNIT = "organisation unit" private const val ORGANISATION_UNIT_CODE = "organisation unit code" private const val ENROLLMENT_ID = "enrollment id" - private val ENROLLMENT_STATUS = RuleEnrollment.Status.ACTIVE + private val ENROLLMENT_STATUS = RuleEnrollmentStatus.ACTIVE private const val EVENT_ID = "event id" private const val PROGRAM_NAME = "program name" } diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt index ade1de99..66d35103 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt @@ -5,10 +5,7 @@ import kotlinx.datetime.LocalDate import org.hisp.dhis.rules.RuleEngineTestUtils.getRuleEngineContext import org.hisp.dhis.rules.api.RuleEngine import org.hisp.dhis.rules.api.RuleEngineContext -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.RuleEvent +import org.hisp.dhis.rules.models.* import org.hisp.dhis.rules.utils.currentDate import kotlin.test.Test import kotlin.test.assertEquals @@ -16,7 +13,7 @@ import kotlin.test.assertEquals // ToDo: function tests (check that function invocations are producing expected values; check nested function invocation) // ToDo: various source type tests (referencing variables from different events) class RuleEngineEffectTypesTest { - private fun getTestRuleEvent(status: RuleEvent.Status): RuleEvent { + private fun getTestRuleEvent(status: RuleEventStatus): RuleEvent { return RuleEvent( event = "test_event", programStage = "test_program_stage", @@ -39,7 +36,7 @@ class RuleEngineEffectTypesTest { fun simpleConditionMustResultInAssignEffect() { val ruleAction = RuleAction("'test_string'", "ASSIGN", mapOf(Pair("field", "test_data_element"))) val rule = Rule("true", listOf(ruleAction)) - val ruleEffects = RuleEngine.getInstance().evaluate(getTestRuleEvent(RuleEvent.Status.ACTIVE), null, emptyList(), RuleEngineContext(listOf(rule))) + val ruleEffects = RuleEngine.getInstance().evaluate(getTestRuleEvent(RuleEventStatus.ACTIVE), null, emptyList(), RuleEngineContext(listOf(rule))) assertEquals(1, ruleEffects.size) assertEquals("test_string", ruleEffects[0].data) assertEquals(ruleAction, ruleEffects[0].ruleAction) @@ -49,7 +46,7 @@ class RuleEngineEffectTypesTest { fun simpleConditionMustResultInAssignEffectMultipleExecution() { val ruleAction = RuleAction("'test_string'", "ASSIGN", mapOf(Pair("field", "test_data_element"))) val rule = Rule("true", listOf(ruleAction)) - val ruleEffects = RuleEngine.getInstance().evaluateAll(null, listOf(getTestRuleEvent(RuleEvent.Status.ACTIVE)), getRuleEngineContext(listOf(rule))) + val ruleEffects = RuleEngine.getInstance().evaluateAll(null, listOf(getTestRuleEvent(RuleEventStatus.ACTIVE)), getRuleEngineContext(listOf(rule))) assertEquals(1, ruleEffects.size) assertEquals("test_string", ruleEffects[0].ruleEffects[0].data) assertEquals(ruleAction, ruleEffects[0].ruleEffects[0].ruleAction) @@ -59,7 +56,7 @@ class RuleEngineEffectTypesTest { fun testEnvironmentVariableExpression() { val ruleAction = RuleAction("", "HIDEFIELD", mapOf(Pair("content", "test_action_content"), Pair("field", "test_data_element"))) val rule = Rule("V{event_status} =='COMPLETED'", listOf(ruleAction)) - val ruleEffects = RuleEngine.getInstance().evaluate(getTestRuleEvent(RuleEvent.Status.COMPLETED), null, emptyList(), RuleEngineContext(listOf(rule))) + val ruleEffects = RuleEngine.getInstance().evaluate(getTestRuleEvent(RuleEventStatus.COMPLETED), null, emptyList(), RuleEngineContext(listOf(rule))) assertEquals(1, ruleEffects.size) assertEquals("", ruleEffects[0].data) assertEquals(ruleAction, ruleEffects[0].ruleAction) diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt index dffd933f..10ae08e0 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt @@ -23,7 +23,7 @@ class RuleEngineFunctionTest { val ruleEngineContext = RuleEngineTestUtils.getRuleEngineContext(listOf(failingRule, validRule)) val ruleEnrollment = RuleEnrollment( "test_enrollment", "", - enrollmentDate, enrollmentDate, RuleEnrollment.Status.ACTIVE, + enrollmentDate, enrollmentDate, RuleEnrollmentStatus.ACTIVE, "", "", listOf(), ) val ruleEffects = RuleEngine.getInstance().evaluate(ruleEnrollment, emptyList(), ruleEngineContext) @@ -43,13 +43,13 @@ class RuleEngineFunctionTest { ) val ruleEnrollment = RuleEnrollment( "test_enrollment", "", - today, today, RuleEnrollment.Status.ACTIVE, "", "", listOf() + today, today, RuleEnrollmentStatus.ACTIVE, "", "", listOf() ) val ruleEvent = RuleEvent( "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -66,7 +66,7 @@ class RuleEngineFunctionTest { ) val ruleNotFailingEvent = RuleEvent( "test_not_failing_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, yesterday, today, null, "", + RuleEventStatus.ACTIVE, yesterday, today, null, "", null, listOf( RuleDataValue( Clock.System.now(), @@ -106,7 +106,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -141,7 +141,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -178,7 +178,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -212,7 +212,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -245,7 +245,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -276,7 +276,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage_id", "test_program_stage_name", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -313,7 +313,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -356,7 +356,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -399,7 +399,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -437,7 +437,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -474,7 +474,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -512,7 +512,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -549,7 +549,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -578,7 +578,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -617,7 +617,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -636,7 +636,7 @@ class RuleEngineFunctionTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -655,7 +655,7 @@ class RuleEngineFunctionTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -689,7 +689,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -708,7 +708,7 @@ class RuleEngineFunctionTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -727,7 +727,7 @@ class RuleEngineFunctionTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -763,7 +763,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -782,7 +782,7 @@ class RuleEngineFunctionTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -801,7 +801,7 @@ class RuleEngineFunctionTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -820,7 +820,7 @@ class RuleEngineFunctionTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -856,7 +856,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -875,7 +875,7 @@ class RuleEngineFunctionTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -911,7 +911,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -930,7 +930,7 @@ class RuleEngineFunctionTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -967,7 +967,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -986,7 +986,7 @@ class RuleEngineFunctionTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1005,7 +1005,7 @@ class RuleEngineFunctionTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1024,7 +1024,7 @@ class RuleEngineFunctionTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1057,7 +1057,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1090,7 +1090,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1123,7 +1123,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1162,7 +1162,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1207,7 +1207,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1255,7 +1255,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1303,7 +1303,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1326,7 +1326,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1349,7 +1349,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1375,7 +1375,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1394,7 +1394,7 @@ class RuleEngineFunctionTest { "test_event1", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1413,7 +1413,7 @@ class RuleEngineFunctionTest { "test_event1", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1447,7 +1447,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1466,7 +1466,7 @@ class RuleEngineFunctionTest { "test_event1", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1485,7 +1485,7 @@ class RuleEngineFunctionTest { "test_event1", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1518,7 +1518,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1551,7 +1551,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1584,7 +1584,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1617,7 +1617,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1640,7 +1640,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1673,7 +1673,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1706,7 +1706,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1748,7 +1748,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1802,7 +1802,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1849,7 +1849,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1896,7 +1896,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1943,7 +1943,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1990,7 +1990,7 @@ class RuleEngineFunctionTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2034,7 +2034,7 @@ class RuleEngineFunctionTest { "test_event1", "test_program_stage1", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2059,7 +2059,7 @@ class RuleEngineFunctionTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2084,7 +2084,7 @@ class RuleEngineFunctionTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2129,7 +2129,7 @@ class RuleEngineFunctionTest { "test_event1", "test_program_stage1", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2154,7 +2154,7 @@ class RuleEngineFunctionTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2179,7 +2179,7 @@ class RuleEngineFunctionTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2223,7 +2223,7 @@ class RuleEngineFunctionTest { "test_event1", "test_program_stage1", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2248,7 +2248,7 @@ class RuleEngineFunctionTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2273,7 +2273,7 @@ class RuleEngineFunctionTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2318,7 +2318,7 @@ class RuleEngineFunctionTest { "test_event1", "test_program_stage1", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2343,7 +2343,7 @@ class RuleEngineFunctionTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2368,7 +2368,7 @@ class RuleEngineFunctionTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -2411,7 +2411,7 @@ class RuleEngineFunctionTest { "test_event1", "test_program_stage1", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, dayBeforeYesterday, LocalDate.currentDate(), null, @@ -2430,7 +2430,7 @@ class RuleEngineFunctionTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, yesterday, LocalDate.currentDate(), null, @@ -2449,7 +2449,7 @@ class RuleEngineFunctionTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, dayAfterTomorrowInstant, LocalDate.currentDate(), null, diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineTest.kt index f7681f74..86f001b2 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineTest.kt @@ -4,6 +4,7 @@ import kotlinx.datetime.Clock import kotlinx.datetime.LocalDate import org.hisp.dhis.rules.api.RuleEngine import org.hisp.dhis.rules.api.RuleEngineContext +import org.hisp.dhis.rules.models.RuleEventStatus import org.hisp.dhis.rules.models.Rule import org.hisp.dhis.rules.models.RuleEvent import org.hisp.dhis.rules.utils.currentDate @@ -21,7 +22,7 @@ internal class RuleEngineTest { "test_event", "test_programstage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineValueTypesTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineValueTypesTest.kt index 373f2e64..dd2fd7e0 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineValueTypesTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineValueTypesTest.kt @@ -20,7 +20,7 @@ class RuleEngineValueTypesTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -45,7 +45,7 @@ class RuleEngineValueTypesTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -70,7 +70,7 @@ class RuleEngineValueTypesTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineVariableNameTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineVariableNameTest.kt index 51dd115d..0f30f947 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineVariableNameTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineVariableNameTest.kt @@ -63,7 +63,7 @@ class RuleEngineVariableNameTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -168,7 +168,7 @@ class RuleEngineVariableNameTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -198,7 +198,7 @@ class RuleEngineVariableNameTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -228,7 +228,7 @@ class RuleEngineVariableNameTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -247,7 +247,7 @@ class RuleEngineVariableNameTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -266,7 +266,7 @@ class RuleEngineVariableNameTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -299,7 +299,7 @@ class RuleEngineVariableNameTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -318,7 +318,7 @@ class RuleEngineVariableNameTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -337,7 +337,7 @@ class RuleEngineVariableNameTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -373,7 +373,7 @@ class RuleEngineVariableNameTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -392,7 +392,7 @@ class RuleEngineVariableNameTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -411,7 +411,7 @@ class RuleEngineVariableNameTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -430,7 +430,7 @@ class RuleEngineVariableNameTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -463,7 +463,7 @@ class RuleEngineVariableNameTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -482,7 +482,7 @@ class RuleEngineVariableNameTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -501,7 +501,7 @@ class RuleEngineVariableNameTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -520,7 +520,7 @@ class RuleEngineVariableNameTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -553,7 +553,7 @@ class RuleEngineVariableNameTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -572,7 +572,7 @@ class RuleEngineVariableNameTest { "test_event1", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -591,7 +591,7 @@ class RuleEngineVariableNameTest { "test_event1", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -624,7 +624,7 @@ class RuleEngineVariableNameTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -643,7 +643,7 @@ class RuleEngineVariableNameTest { "test_event1", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -662,7 +662,7 @@ class RuleEngineVariableNameTest { "test_event1", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -706,7 +706,7 @@ class RuleEngineVariableNameTest { "test_event1", "test_program_stage1", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -731,7 +731,7 @@ class RuleEngineVariableNameTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -756,7 +756,7 @@ class RuleEngineVariableNameTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -805,7 +805,7 @@ class RuleEngineVariableNameTest { "test_event1", "test_program_stage1", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -830,7 +830,7 @@ class RuleEngineVariableNameTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -855,7 +855,7 @@ class RuleEngineVariableNameTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -899,7 +899,7 @@ class RuleEngineVariableNameTest { "test_event1", "test_program_stage1", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -924,7 +924,7 @@ class RuleEngineVariableNameTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -949,7 +949,7 @@ class RuleEngineVariableNameTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -994,7 +994,7 @@ class RuleEngineVariableNameTest { "test_event1", "test_program_stage1", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1019,7 +1019,7 @@ class RuleEngineVariableNameTest { "test_event2", "test_program_stage2", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -1044,7 +1044,7 @@ class RuleEngineVariableNameTest { "test_event3", "test_program_stage3", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/VariableValueTypeTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/VariableValueTypeTest.kt index 9e6ed506..06875c21 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/VariableValueTypeTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/VariableValueTypeTest.kt @@ -48,7 +48,7 @@ class VariableValueTypeTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, now, LocalDate.fromEpochDays(1), null, @@ -77,7 +77,7 @@ class VariableValueTypeTest { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, now, LocalDate.fromEpochDays(1), null, diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/models/CalculatedValueTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/CalculatedValueTest.kt index 7cc445b3..060b9396 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/models/CalculatedValueTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/models/CalculatedValueTest.kt @@ -45,7 +45,7 @@ class CalculatedValueTest { "test_program", LocalDate.currentDate(), LocalDate.currentDate(), - RuleEnrollment.Status.ACTIVE, + RuleEnrollmentStatus.ACTIVE, "test_ou", "test_ou_code", listOf() @@ -54,7 +54,7 @@ class CalculatedValueTest { event = "test_event", programStage = "test_program_stage", programStageName = "", - status = RuleEvent.Status.ACTIVE, + status = RuleEventStatus.ACTIVE, eventDate = Clock.System.now(), dueDate = LocalDate.currentDate(), organisationUnit = "", @@ -86,7 +86,7 @@ class CalculatedValueTest { "test_program", LocalDate.currentDate(), LocalDate.currentDate(), - RuleEnrollment.Status.ACTIVE, + RuleEnrollmentStatus.ACTIVE, "test_ou", "test_ou_code", listOf() @@ -95,7 +95,7 @@ class CalculatedValueTest { event = "test_event", programStage = "test_program_stage", programStageName = "", - status = RuleEvent.Status.ACTIVE, + status = RuleEventStatus.ACTIVE, eventDate = Clock.System.now(), dueDate = LocalDate.currentDate(), organisationUnit = "", @@ -146,7 +146,7 @@ class CalculatedValueTest { "test_program", LocalDate.currentDate(), LocalDate.currentDate(), - RuleEnrollment.Status.ACTIVE, + RuleEnrollmentStatus.ACTIVE, "test_ou", "test_ou_code", listOf() @@ -155,7 +155,7 @@ class CalculatedValueTest { event = "test_event", programStage = "test_program_stage", programStageName = "", - status = RuleEvent.Status.ACTIVE, + status = RuleEventStatus.ACTIVE, eventDate = Clock.System.now(), dueDate = LocalDate.currentDate(), organisationUnit = "", diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentTest.kt index ad5dc8e2..5c629243 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentTest.kt @@ -15,13 +15,13 @@ class RuleEnrollmentTest { val enrollmentDate = LocalDate.Companion.currentDate() val ruleEnrollment = RuleEnrollment( "test_enrollment", "", - incidentDate, enrollmentDate, RuleEnrollment.Status.ACTIVE, "", "", + incidentDate, enrollmentDate, RuleEnrollmentStatus.ACTIVE, "", "", listOf(ruleAttributeValueOne, ruleAttributeValueTwo, ruleAttributeValueThree) ) assertEquals("test_enrollment", ruleEnrollment.enrollment) assertEquals(incidentDate, ruleEnrollment.incidentDate) assertEquals(enrollmentDate, ruleEnrollment.enrollmentDate) - assertEquals(RuleEnrollment.Status.ACTIVE, ruleEnrollment.status) + assertEquals(RuleEnrollmentStatus.ACTIVE, ruleEnrollment.status) assertEquals(3, ruleEnrollment.attributeValues.size) assertEquals(ruleAttributeValueOne, ruleEnrollment.attributeValues[0]) assertEquals(ruleAttributeValueTwo, ruleEnrollment.attributeValues[1]) diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEventTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEventTest.kt index fb021c42..5582b550 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEventTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEventTest.kt @@ -17,10 +17,10 @@ class RuleEventTest { val dueDate = LocalDate.Companion.currentDate() val (event, programStage, _, status, eventDate1, dueDate1, _, _, _, dataValues) = RuleEvent( "test_event_uid", "test_stage_uid", "", - RuleEvent.Status.ACTIVE, eventDate, dueDate, null, "", "", ruleDataValues + RuleEventStatus.ACTIVE, eventDate, dueDate, null, "", "", ruleDataValues ) assertEquals("test_event_uid", event) - assertEquals(RuleEvent.Status.ACTIVE, status) + assertEquals(RuleEventStatus.ACTIVE, status) assertEquals("test_stage_uid", programStage) assertEquals(eventDate, eventDate1) assertEquals(dueDate, dueDate1) @@ -33,12 +33,12 @@ class RuleEventTest { val ruleEvents: List = listOf( RuleEvent( - "test_event_one", "test_program_stage_one", "", RuleEvent.Status.ACTIVE, + "test_event_one", "test_program_stage_one", "", RuleEventStatus.ACTIVE, Instant.parse("2014-02-11T01:00:00Z"), LocalDate.parse("2014-02-11"), null, "", null, emptyList() ), RuleEvent( - "test_event_two", "test_program_stage_two", "", RuleEvent.Status.ACTIVE, + "test_event_two", "test_program_stage_two", "", RuleEventStatus.ACTIVE, Instant.parse("2017-03-22T01:00:00Z"), LocalDate.parse("2017-03-22"), null, "", null, emptyList() ) diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableValueMapBuilderTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableValueMapBuilderTest.kt index c1da2f15..844870bf 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableValueMapBuilderTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableValueMapBuilderTest.kt @@ -21,7 +21,7 @@ class RuleVariableValueMapBuilderTest { val ruleEnrollment = RuleEnrollment( "test_enrollment", "", LocalDate.parse("2015-01-01"), LocalDate.parse("2015-01-01"), - RuleEnrollment.Status.ACTIVE, "", "", listOf( + RuleEnrollmentStatus.ACTIVE, "", "", listOf( RuleAttributeValue("test_attribute_one", "test_attribute_value_one"), RuleAttributeValue("test_attribute_two", "test_attribute_value_two") ) @@ -30,7 +30,7 @@ class RuleVariableValueMapBuilderTest { "test_context_event_one", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -73,7 +73,7 @@ class RuleVariableValueMapBuilderTest { "test_context_event_one", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -94,7 +94,7 @@ class RuleVariableValueMapBuilderTest { "test_context_event_two", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -114,7 +114,7 @@ class RuleVariableValueMapBuilderTest { // values from current ruleEvent should be propagated to the variable values val currentEvent = RuleEvent( "test_event_uid", "test_program_stage", "", - RuleEvent.Status.ACTIVE, eventInstant, dueDate, null, "", null, listOf( + RuleEventStatus.ACTIVE, eventInstant, dueDate, null, "", null, listOf( RuleDataValue( eventInstant, "test_program_stage", "test_dataelement_one", "test_value_one" @@ -139,8 +139,8 @@ class RuleVariableValueMapBuilderTest { eventDate.toString()) .isTypeOf(RuleValueType.TEXT).hasCandidates(eventDate.toString()) RuleVariableValueAssert.assertThatVariable(valueMap["event_status"]!!) - .hasValue(RuleEvent.Status.ACTIVE.toString()) - .isTypeOf(RuleValueType.TEXT).hasCandidates(RuleEvent.Status.ACTIVE.toString()) + .hasValue(RuleEventStatus.ACTIVE.toString()) + .isTypeOf(RuleValueType.TEXT).hasCandidates(RuleEventStatus.ACTIVE.toString()) // event count variable should respect current event RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("3") @@ -174,7 +174,7 @@ class RuleVariableValueMapBuilderTest { "test_event_uid_oldest", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, oldestEventDate, LocalDate.currentDate(), null, @@ -195,7 +195,7 @@ class RuleVariableValueMapBuilderTest { "test_event_uid_newest", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, newestEventDate, LocalDate.currentDate(), null, @@ -216,7 +216,7 @@ class RuleVariableValueMapBuilderTest { "test_event_uid_current", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, currentEventInstant, currentEventDueDate, null, @@ -278,7 +278,7 @@ class RuleVariableValueMapBuilderTest { val dateEventDueCurrent = LocalDate.parse("2016-01-01") val firstRuleEvent = RuleEvent( "test_event_uid_one", "test_program_stage", "", - RuleEvent.Status.ACTIVE, dateEventOne, LocalDate.currentDate(), null, "", null, listOf( + RuleEventStatus.ACTIVE, dateEventOne, LocalDate.currentDate(), null, "", null, listOf( RuleDataValue( dateEventOne, "test_program_stage", "test_dataelement_one", "test_value_dataelement_one_first" @@ -291,7 +291,7 @@ class RuleVariableValueMapBuilderTest { ) val secondRuleEvent = RuleEvent( "test_event_uid_two", "test_program_stage", "", - RuleEvent.Status.ACTIVE, dateEventTwo, LocalDate.currentDate(), null, "", null, listOf( + RuleEventStatus.ACTIVE, dateEventTwo, LocalDate.currentDate(), null, "", null, listOf( RuleDataValue( dateEventTwo, "test_program_stage", "test_dataelement_one", "test_value_dataelement_one_second" @@ -306,7 +306,7 @@ class RuleVariableValueMapBuilderTest { "test_event_uid_current", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, instantEventCurrent, dateEventDueCurrent, null, @@ -372,7 +372,7 @@ class RuleVariableValueMapBuilderTest { val dateEventDueCurrent = LocalDate.parse("2011-02-03") val eventOne = RuleEvent( "test_event_uid_one", "test_program_stage_one", "", - RuleEvent.Status.ACTIVE, dateEventOne, LocalDate.currentDate(), null, "", null, listOf( + RuleEventStatus.ACTIVE, dateEventOne, LocalDate.currentDate(), null, "", null, listOf( RuleDataValue( dateEventOne, "test_program_stage_one", "test_dataelement", "test_value_one" @@ -381,7 +381,7 @@ class RuleVariableValueMapBuilderTest { ) val eventTwo = RuleEvent( "test_event_uid_two", "test_program_stage_two", "", - RuleEvent.Status.ACTIVE, dateEventTwo, LocalDate.currentDate(), null, "", null, listOf( + RuleEventStatus.ACTIVE, dateEventTwo, LocalDate.currentDate(), null, "", null, listOf( RuleDataValue( dateEventTwo, "test_program_stage_two", "test_dataelement", "test_value_two" @@ -390,7 +390,7 @@ class RuleVariableValueMapBuilderTest { ) val eventThree = RuleEvent( "test_event_uid_three", "test_program_stage_two", "", - RuleEvent.Status.ACTIVE, dateEventThree, LocalDate.currentDate(), null, "", null, listOf( + RuleEventStatus.ACTIVE, dateEventThree, LocalDate.currentDate(), null, "", null, listOf( RuleDataValue( dateEventThree, "test_program_stage_two", "test_dataelement", "test_value_three" @@ -401,7 +401,7 @@ class RuleVariableValueMapBuilderTest { "test_event_uid_current", "test_program_stage_one", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, instantEventCurrent, dateEventDueCurrent, null, @@ -450,7 +450,7 @@ class RuleVariableValueMapBuilderTest { val dueDateEventTwo = LocalDate.parse("2015-02-03") val ruleEventOne = RuleEvent( "test_event_uid_one", "test_program_stage_two", "", - RuleEvent.Status.ACTIVE, dateEventOne, dueDateEventTwo, null, "", null, listOf( + RuleEventStatus.ACTIVE, dateEventOne, dueDateEventTwo, null, "", null, listOf( RuleDataValue( dateEventOne, "test_program_stage_two", "test_dataelement", "test_value_one" @@ -459,7 +459,7 @@ class RuleVariableValueMapBuilderTest { ) val ruleEventTwo = RuleEvent( "test_event_uid_two", "test_program_stage_two", "", - RuleEvent.Status.ACTIVE, instantEventTwo, dueDateEventTwo, null, "", null, listOf( + RuleEventStatus.ACTIVE, instantEventTwo, dueDateEventTwo, null, "", null, listOf( RuleDataValue( instantEventTwo, "test_program_stage_two", "test_dataelement", "test_value_two" @@ -505,7 +505,7 @@ class RuleVariableValueMapBuilderTest { val dueDateEventCurrent = LocalDate.parse("2014-05-03") val ruleEventOne = RuleEvent( "test_event_uid_one", "test_program_stage", "", - RuleEvent.Status.ACTIVE, dateEventOne, LocalDate.currentDate(), null, "", null, listOf( + RuleEventStatus.ACTIVE, dateEventOne, LocalDate.currentDate(), null, "", null, listOf( RuleDataValue( dateEventOne, "test_program_stage_one", "test_dataelement", "test_value_one" @@ -514,7 +514,7 @@ class RuleVariableValueMapBuilderTest { ) val ruleEventTwo = RuleEvent( "test_event_uid_two", "test_program_stage", "", - RuleEvent.Status.ACTIVE, dateEventTwo, LocalDate.currentDate(), null, "", null, listOf( + RuleEventStatus.ACTIVE, dateEventTwo, LocalDate.currentDate(), null, "", null, listOf( RuleDataValue( dateEventTwo, "test_program_stage_two", "test_dataelement", "test_value_two" @@ -523,7 +523,7 @@ class RuleVariableValueMapBuilderTest { ) val ruleEventThree = RuleEvent( "test_event_uid_three", "test_program_stage", "", - RuleEvent.Status.ACTIVE, dateEventThree, LocalDate.currentDate(), null, "", null, listOf( + RuleEventStatus.ACTIVE, dateEventThree, LocalDate.currentDate(), null, "", null, listOf( RuleDataValue( dateEventThree, "test_program_stage_two", "test_dataelement", "test_value_three" @@ -534,7 +534,7 @@ class RuleVariableValueMapBuilderTest { "test_event_uid_current", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, instantEventCurrent, dueDateEventCurrent, null, @@ -590,7 +590,7 @@ class RuleVariableValueMapBuilderTest { // values from enrollment should end up in ruleVariables val ruleEnrollment = RuleEnrollment( "test_enrollment", "", - enrollmentDate, enrollmentDate, RuleEnrollment.Status.ACTIVE, "", "", listOf( + enrollmentDate, enrollmentDate, RuleEnrollmentStatus.ACTIVE, "", "", listOf( RuleAttributeValue("test_attribute_one", "test_attribute_value_one"), RuleAttributeValue("test_attribute_two", "test_attribute_value_two") ) @@ -601,7 +601,7 @@ class RuleVariableValueMapBuilderTest { "test_context_event_one", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, eventInstant, dueEventDate, null, @@ -620,7 +620,7 @@ class RuleVariableValueMapBuilderTest { ) val currentEvent = RuleEvent( "test_event_uid", "test_program_stage", "", - RuleEvent.Status.ACTIVE, eventInstant, dueEventDate, null, "", null, listOf( + RuleEventStatus.ACTIVE, eventInstant, dueEventDate, null, "", null, listOf( RuleDataValue( eventInstant, "test_program_stage", "test_dataelement_one", "test_value_one" @@ -655,8 +655,8 @@ class RuleVariableValueMapBuilderTest { dueEventDate.toString()) .isTypeOf(RuleValueType.TEXT).hasCandidates(dueEventDate.toString()) RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_status"]!!) - .hasValue(RuleEnrollment.Status.ACTIVE.toString()) - .isTypeOf(RuleValueType.TEXT).hasCandidates(RuleEnrollment.Status.ACTIVE.toString()) + .hasValue(RuleEnrollmentStatus.ACTIVE.toString()) + .isTypeOf(RuleValueType.TEXT).hasCandidates(RuleEnrollmentStatus.ACTIVE.toString()) RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_date"]!!) .hasValue(enrollmentDate.toString()) .isTypeOf(RuleValueType.TEXT).hasCandidates(enrollmentDate.toString()) @@ -694,7 +694,7 @@ class RuleVariableValueMapBuilderTest { val incidentDate = LocalDate.parse("2017-04-02") val ruleEnrollment = RuleEnrollment( "test_enrollment", "", incidentDate, - enrollmentDate, RuleEnrollment.Status.ACTIVE, "", "", listOf( + enrollmentDate, RuleEnrollmentStatus.ACTIVE, "", "", listOf( RuleAttributeValue("test_attribute_one", "test_attribute_value_one"), RuleAttributeValue("test_attribute_two", "test_attribute_value_two"), RuleAttributeValue("test_attribute_three", "test_attribute_value_three") @@ -704,7 +704,7 @@ class RuleVariableValueMapBuilderTest { "test_event_one", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -716,7 +716,7 @@ class RuleVariableValueMapBuilderTest { "test_event_two", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, @@ -771,7 +771,7 @@ class RuleVariableValueMapBuilderTest { val incidentDate = LocalDate.parse("2017-04-02") val ruleEnrollment = RuleEnrollment( "test_enrollment", "", incidentDate, - enrollmentDate, RuleEnrollment.Status.ACTIVE, "", "", listOf( + enrollmentDate, RuleEnrollmentStatus.ACTIVE, "", "", listOf( RuleAttributeValue("test_attribute_one", "test_attribute_value_one"), RuleAttributeValue("test_attribute_two", "test_attribute_value_two"), RuleAttributeValue("test_attribute_three", "test_attribute_value_three") @@ -788,7 +788,7 @@ class RuleVariableValueMapBuilderTest { "test_event_one", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, eventOneInstant, eventOneDueDate, null, @@ -800,7 +800,7 @@ class RuleVariableValueMapBuilderTest { "test_event_two", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, eventTwoInstant, eventTwoDueDate, null, @@ -910,7 +910,7 @@ class RuleVariableValueMapBuilderTest { "test_event_two", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Clock.System.now(), LocalDate.currentDate(), null, diff --git a/src/jsMain/kotlin/org/hisp/dhis/rules/DataItemJs.kt b/src/jsMain/kotlin/org/hisp/dhis/rules/DataItemJs.kt index 72f4b326..8897195d 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/DataItemJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/DataItemJs.kt @@ -3,13 +3,4 @@ package org.hisp.dhis.rules import org.hisp.dhis.rules.api.ItemValueType @JsExport -@OptIn(ExperimentalJsExport::class) -data class DataItemJs(val displayName: String, val valueType: String){ - init { - require(TYPES.contains(valueType)) { "ItemValueType type must be one of: $TYPES" } - } - - companion object { - val TYPES = ItemValueType.entries.map { it.name } .toTypedArray() - } -} \ No newline at end of file +data class DataItemJs(val displayName: String, val valueType: ItemValueType) \ No newline at end of file diff --git a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleActionJs.kt b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleActionJs.kt index 409e38a6..43d5714c 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleActionJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleActionJs.kt @@ -3,7 +3,6 @@ package org.hisp.dhis.rules import js.collections.JsMap @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleActionJs( val data: String?, val type: String, diff --git a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleDataValueJs.kt b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleDataValueJs.kt index 268f71a7..40fef0fd 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleDataValueJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleDataValueJs.kt @@ -3,7 +3,6 @@ package org.hisp.dhis.rules import kotlinx.datetime.internal.JSJoda.Instant @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleDataValueJs( val eventDate: Instant, val programStage: String, diff --git a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEffectJs.kt b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEffectJs.kt index 3cc61d55..6e9a2409 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEffectJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEffectJs.kt @@ -1,7 +1,6 @@ package org.hisp.dhis.rules @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleEffectJs( val ruleId: String, val ruleAction: RuleActionJs, diff --git a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEffectsJs.kt b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEffectsJs.kt index 6cd2aba4..6316e4b1 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEffectsJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEffectsJs.kt @@ -3,17 +3,8 @@ package org.hisp.dhis.rules import org.hisp.dhis.rules.models.TrackerObjectType @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleEffectsJs( - val trackerObjectType: String, + val trackerObjectType: TrackerObjectType, val trackerObjectUid: String, val ruleEffects: Array -) { - init { - require(TYPES.contains(trackerObjectType)) { "trackerObjectType type must be one of: $TYPES" } - } - - companion object { - val TYPES = TrackerObjectType.entries.map { it.name } .toTypedArray() - } -} +) diff --git a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineContextJs.kt b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineContextJs.kt index 078f8864..16ad837c 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineContextJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineContextJs.kt @@ -3,7 +3,6 @@ package org.hisp.dhis.rules import js.collections.JsMap @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleEngineContextJs( val rules: Array, val ruleVariables: Array, diff --git a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineJs.kt b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineJs.kt index ead95989..af98c5e3 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineJs.kt @@ -5,13 +5,11 @@ import js.collections.JsMap import kotlinx.datetime.Instant import kotlinx.datetime.LocalDate import org.hisp.dhis.rules.api.DataItem -import org.hisp.dhis.rules.api.ItemValueType import org.hisp.dhis.rules.api.RuleEngine import org.hisp.dhis.rules.api.RuleEngineContext import org.hisp.dhis.rules.models.* @JsExport -@OptIn(ExperimentalJsExport::class) class RuleEngineJs { fun validate(expression: String, dataItemStore: JsMap): RuleValidationResult{ return RuleEngine.getInstance().validate(expression, toMap(dataItemStore, {it}, ::toDataItemJava)) @@ -47,7 +45,7 @@ class RuleEngineJs { private fun toDataItemJava(item: DataItemJs) : DataItem { return DataItem( - valueType = ItemValueType.valueOf(item.valueType), + valueType = item.valueType, displayName = item.displayName ) } @@ -60,7 +58,7 @@ class RuleEngineJs { programName = enrollmentTarget.programName, incidentDate = LocalDate.fromEpochDays(enrollmentTarget.incidentDate.toEpochDay().toInt()), enrollmentDate = LocalDate.fromEpochDays(enrollmentTarget.enrollmentDate.toEpochDay().toInt()), - status = RuleEnrollment.Status.valueOf(enrollmentTarget.status), + status = enrollmentTarget.status, organisationUnit = enrollmentTarget.organisationUnit, organisationUnitCode = enrollmentTarget.organisationUnitCode, attributeValues = enrollmentTarget.attributeValues.toList() @@ -72,7 +70,7 @@ class RuleEngineJs { event = event.event, programStage = event.programStage, programStageName = event.programStageName, - status = RuleEvent.Status.valueOf(event.status), + status = event.status, eventDate = Instant.fromEpochMilliseconds(event.eventDate.toEpochMilli().toLong()), dueDate = toLocalDate(event.dueDate), completedDate = toLocalDate(event.completedDate), @@ -137,7 +135,7 @@ class RuleEngineJs { private fun toRuleEffectsJs(ruleEffects: RuleEffects): RuleEffectsJs { return RuleEffectsJs( - trackerObjectType = ruleEffects.trackerObjectType.name, + trackerObjectType = ruleEffects.trackerObjectType, trackerObjectUid = ruleEffects.trackerObjectUid, ruleEffects = ruleEffects.ruleEffects.map(::toRuleEffectJs).toTypedArray() ) @@ -154,13 +152,13 @@ class RuleEngineJs { } private fun toRuleVariableJava(ruleVariableJs: RuleVariableJs): RuleVariable { - return when(RuleVariableType.valueOf(ruleVariableJs.type)){ + return when(ruleVariableJs.type){ RuleVariableType.DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE -> RuleVariableNewestStageEvent( name = ruleVariableJs.name, useCodeForOptionSet = ruleVariableJs.useCodeForOptionSet, options = ruleVariableJs.options.toList(), field = ruleVariableJs.field, - fieldType = RuleValueType.valueOf(ruleVariableJs.fieldType), + fieldType = ruleVariableJs.fieldType, programStage = ruleVariableJs.programStage ?: "" ) RuleVariableType.DATAELEMENT_NEWEST_EVENT_PROGRAM -> RuleVariableNewestEvent( @@ -168,35 +166,35 @@ class RuleEngineJs { useCodeForOptionSet = ruleVariableJs.useCodeForOptionSet, options = ruleVariableJs.options.toList(), field = ruleVariableJs.field, - fieldType = RuleValueType.valueOf(ruleVariableJs.fieldType) + fieldType = ruleVariableJs.fieldType ) RuleVariableType.DATAELEMENT_CURRENT_EVENT -> RuleVariableCurrentEvent( name = ruleVariableJs.name, useCodeForOptionSet = ruleVariableJs.useCodeForOptionSet, options = ruleVariableJs.options.toList(), field = ruleVariableJs.field, - fieldType = RuleValueType.valueOf(ruleVariableJs.fieldType) + fieldType = ruleVariableJs.fieldType ) RuleVariableType.DATAELEMENT_PREVIOUS_EVENT -> RuleVariablePreviousEvent( name = ruleVariableJs.name, useCodeForOptionSet = ruleVariableJs.useCodeForOptionSet, options = ruleVariableJs.options.toList(), field = ruleVariableJs.field, - fieldType = RuleValueType.valueOf(ruleVariableJs.fieldType) + fieldType = ruleVariableJs.fieldType ) RuleVariableType.CALCULATED_VALUE -> RuleVariableCalculatedValue( name = ruleVariableJs.name, useCodeForOptionSet = ruleVariableJs.useCodeForOptionSet, options = ruleVariableJs.options.toList(), field = ruleVariableJs.field, - fieldType = RuleValueType.valueOf(ruleVariableJs.fieldType) + fieldType = ruleVariableJs.fieldType ) RuleVariableType.TEI_ATTRIBUTE -> RuleVariableAttribute( name = ruleVariableJs.name, useCodeForOptionSet = ruleVariableJs.useCodeForOptionSet, options = ruleVariableJs.options.toList(), field = ruleVariableJs.field, - fieldType = RuleValueType.valueOf(ruleVariableJs.fieldType) + fieldType = ruleVariableJs.fieldType ) } } diff --git a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEnrollmentJs.kt b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEnrollmentJs.kt index e0db012c..c0bc91df 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEnrollmentJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEnrollmentJs.kt @@ -1,15 +1,15 @@ package org.hisp.dhis.rules +import org.hisp.dhis.rules.models.RuleEnrollmentStatus import org.hisp.dhis.rules.models.RuleAttributeValue @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleEnrollmentJs( val enrollment: String, val programName: String, val incidentDate: kotlinx.datetime.internal.JSJoda.LocalDate, val enrollmentDate: kotlinx.datetime.internal.JSJoda.LocalDate, - val status: String, + val status: RuleEnrollmentStatus, val organisationUnit: String, val organisationUnitCode: String, val attributeValues: Array diff --git a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEventJs.kt b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEventJs.kt index 26bba962..d06979ab 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEventJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEventJs.kt @@ -2,14 +2,14 @@ package org.hisp.dhis.rules import kotlinx.datetime.internal.JSJoda.Instant import kotlinx.datetime.internal.JSJoda.LocalDate +import org.hisp.dhis.rules.models.RuleEventStatus @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleEventJs( val event: String, val programStage: String, val programStageName: String, - val status: String, + val status: RuleEventStatus, val eventDate: Instant, val dueDate: LocalDate?, val completedDate: LocalDate?, diff --git a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleJs.kt b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleJs.kt index dd09da2c..a3a96b42 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleJs.kt @@ -1,7 +1,6 @@ package org.hisp.dhis.rules @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleJs( val condition: String, val actions: Array, diff --git a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleVariableJs.kt b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleVariableJs.kt index 74a694ea..ed551277 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleVariableJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleVariableJs.kt @@ -4,23 +4,12 @@ import org.hisp.dhis.rules.models.Option import org.hisp.dhis.rules.models.RuleValueType @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleVariableJs( - val type: String, + val type: RuleVariableType, val name: String, val useCodeForOptionSet: Boolean, val options: Array