diff --git a/.github/workflows/job-check-new-version.yml b/.github/workflows/job-check-new-version.yml new file mode 100644 index 00000000..e48e41a0 --- /dev/null +++ b/.github/workflows/job-check-new-version.yml @@ -0,0 +1,28 @@ +on: + workflow_call: + outputs: + isNewVersion: + description: "Indicates if this build generates a new version" + value: ${{ jobs.check-new-version.outputs.isNewVersion }} + +jobs: + check-new-version: + name: Check new version + runs-on: ubuntu-latest + outputs: + isNewVersion: ${{ steps.newVersion.outputs.isNewVersion }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: temurin + cache: 'gradle' + - name: Change wrapper permission + run: chmod +x ./gradlew + - id: newVersion + name: Check new version + run: ./.github/workflows/scripts/check-new-version.sh \ No newline at end of file diff --git a/.github/workflows/job-publish.yml b/.github/workflows/job-publish.yml new file mode 100644 index 00000000..bce2865e --- /dev/null +++ b/.github/workflows/job-publish.yml @@ -0,0 +1,41 @@ +on: + workflow_call + +jobs: + publish: + name: Publish + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: temurin + cache: 'gradle' + - name: Change wrapper permission + run: chmod +x ./gradlew + + - uses: actions/setup-node@v4 + with: + node-version: 14.x + + - name: Create tag and publish Github release + run: ./gradlew :nyxPublish + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish Maven + run: ./.github/workflows/scripts/publish-maven.sh + env: + OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }} + SIGNING_PRIVATE_KEY: ${{ secrets.PGP_PRIVATE_KEY }} + SIGNING_PASSWORD: ${{ secrets.PGP_PASSPHRASE }} + + - name: Publish NPMJS + run: ./.github/workflows/scripts/publish-npm.sh + env: + NPMJS_TOKEN: ${{ secrets.DHIS2_BOT_NPM_TOKEN }} diff --git a/.github/workflows/job-test.yml b/.github/workflows/job-test.yml new file mode 100644 index 00000000..4d6e58aa --- /dev/null +++ b/.github/workflows/job-test.yml @@ -0,0 +1,19 @@ +on: + workflow_call + +jobs: + unit-test: + name: Run tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: temurin + cache: 'gradle' + - name: Change wrapper permission + run: chmod +x ./gradlew + - name: Test + run: ./gradlew clean allTests \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1b5006df..85feb67e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,40 +1,22 @@ -name: Run tests +name: Main -on: [pull_request] +on: + push: + branches: + - 'main' + - 'master' + - 'beta' jobs: unit-test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: 17 - distribution: temurin - cache: 'gradle' - - name: Change wrapper permission - run: chmod +x ./gradlew - - name: Test - run: ./gradlew clean allTests + uses: ./.github/workflows/job-test.yml - artifact: - name: Publish - Nexus - runs-on: ubuntu-latest + check-new-version: needs: unit-test + uses: ./.github/workflows/job-check-new-version.yml - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: 17 - distribution: temurin - cache: 'gradle' - - name: Change wrapper permission - run: chmod +x ./gradlew - - name: Release Maven package - run: ./gradlew publishAllPublicationsToSonatypeRepository - env: - OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }} - OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }} \ No newline at end of file + publish: + needs: check-new-version + if: ${{ needs.check-new-version.outputs.isNewVersion == 'true' }} + uses: ./.github/workflows/job-publish.yml + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml deleted file mode 100644 index 1a046812..00000000 --- a/.github/workflows/master.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Merge to Master - -on: - push: - branches: - - 'master' - -jobs: - unit-test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: 17 - distribution: temurin - cache: 'gradle' - - name: Change wrapper permission - run: chmod +x ./gradlew - - name: Test - run: ./gradlew clean allTests - - artifact: - name: Publish - runs-on: ubuntu-latest - needs: unit-test - - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: 17 - distribution: temurin - cache: 'gradle' - - name: Change wrapper permission - run: chmod +x ./gradlew - - name: Publish to Maven - #run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshot - run: ./gradlew assemble -PremoveSnapshot - env: - OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }} - OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }} - SIGNING_PRIVATE_KEY: ${{ secrets.PGP_PRIVATE_KEY }} - SIGNING_PASSWORD: ${{ secrets.PGP_PASSPHRASE }} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 00000000..424092b4 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,7 @@ +name: Pull request + +on: [pull_request] + +jobs: + unit-test: + uses: ./.github/workflows/job-test.yml diff --git a/.github/workflows/scripts/check-new-version.sh b/.github/workflows/scripts/check-new-version.sh new file mode 100755 index 00000000..1d80e584 --- /dev/null +++ b/.github/workflows/scripts/check-new-version.sh @@ -0,0 +1,8 @@ +# Check if new version +./gradlew checkIsNewVersion -q; newVersion=$? + +if [ $newVersion -ne 0 ]; then + echo "isNewVersion=false" >> "$GITHUB_OUTPUT" +else + echo "isNewVersion=true" >> "$GITHUB_OUTPUT" +fi \ No newline at end of file diff --git a/.github/workflows/scripts/publish-maven.sh b/.github/workflows/scripts/publish-maven.sh new file mode 100755 index 00000000..c6efaee3 --- /dev/null +++ b/.github/workflows/scripts/publish-maven.sh @@ -0,0 +1,9 @@ +set -x + +branch=$(git rev-parse --abbrev-ref HEAD) + +if [ "$branch" = "main" ] || [ "$branch" = "master" ]; then + ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository +elif [ "$branch" = "beta" ]; then + ./gradlew publishToSonatype -PbetaToSnapshot +fi diff --git a/.github/workflows/scripts/publish-npm.sh b/.github/workflows/scripts/publish-npm.sh new file mode 100755 index 00000000..86fab572 --- /dev/null +++ b/.github/workflows/scripts/publish-npm.sh @@ -0,0 +1,17 @@ +set -x + +branch=$(git rev-parse --abbrev-ref HEAD) + +./gradlew packJsPackage +./gradlew packJsPackage -PuseCommonJs + +cd build/packages/js || exit + +# Set authentication token for npmjs registry +npm set //registry.npmjs.org/:_authToken="$NPMJS_TOKEN" + +if [ "$branch" = "main" ] || [ "$branch" = "master" ]; then + npm publish +elif [ "$branch" = "beta" ]; then + npm publish --tag beta +fi diff --git a/.nyx.yaml b/.nyx.yaml new file mode 100644 index 00000000..a55f70d4 --- /dev/null +++ b/.nyx.yaml @@ -0,0 +1,57 @@ +--- +# starting from the "simple" preset gives us: +# - the Conventional Commits convention +preset: "simple" +changelog: + path: "CHANGELOG.md" + sections: + "Added": "^feat$" + "Fixed": "^fix$" +releaseTypes: + enabled: + - mainline + - maturity + - internal + publicationServices: + - github + items: + mainline: + description: "{{#fileContent}}CHANGELOG.md{{/fileContent}}" + filterTags: "^({{configuration.releasePrefix}})?([0-9]\\d*)\\.([0-9]\\d*)\\.([0-9]\\d*)$" + gitPush: "true" + gitTag: "true" + matchBranches: "^(master|main)$" + matchEnvironmentVariables: + CI: "^true$" + matchWorkspaceStatus: "CLEAN" + publish: "true" + maturity: + description: "{{#fileContent}}CHANGELOG.md{{/fileContent}}" + collapseVersions: true + collapsedVersionQualifier: "{{#sanitizeLower}}{{branch}}{{/sanitizeLower}}" + filterTags: "^({{configuration.releasePrefix}})?([0-9]\\d*)\\.([0-9]\\d*)\\.([0-9]\\d*)(-(alpha|beta)(\\.([0-9]\\d*))?)?$" + gitPush: "true" + gitTag: "true" + matchBranches: "^(alpha|beta)$" + matchEnvironmentVariables: + CI: "^true$" + matchWorkspaceStatus: "CLEAN" + publish: "true" + publishPreRelease: "true" + internal: + collapseVersions: true + collapsedVersionQualifier: "internal" + gitPush: "false" + gitTag: "false" + identifiers: + - + qualifier: "{{#timestampYYYYMMDDHHMMSS}}{{timestamp}}{{/timestampYYYYMMDDHHMMSS}}" + position: "BUILD" + publish: "false" +services: + github: + type: "GITHUB" + options: + AUTHENTICATION_TOKEN: "{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}" + REPOSITORY_NAME: "dhis2-rule-engine" + REPOSITORY_OWNER: "dhis2" \ No newline at end of file diff --git a/README.md b/README.md index 0e9ac61d..e003bd78 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -### RuleEngine (WIP) +### RuleEngine (WIP) #### Initialization `RuleEngine` is initialized in two steps. @@ -60,7 +60,28 @@ List of supported environment (contextual) variables: - enrollment_id - enrollment_count - incident_date - - tei_count + - tei_count + +### Development +This library implements the semantic release setup, which means that version numbers are not manually maintained but +derived from the commit/PR history. + +Branches: +- `main`: a push to `main` branch will trigger a new production release (both Maven and NPMJS). +- `beta`: a push to `beta` branch will trigger a SNAPSHOT release in Maven and a new beta release in NPMJS. + +Version number are determined by the presence of commits with these suffixes: +- `fix:`: it will increase the patch number. +- `feat:`: it will increase the minor version number. +- `feat!:`: it will increase the major version number. + +If there is not any commit with any of this tags between the previous version and the current commit, nothing will be published. + +Typical workflow: +1. Do work in a feature branch. There is no need to add tags to the commits. +2. Create a PR to `beta` branch including a tag in the PR title depending on the kind of changes. +3. Merge the PR using **Squash and merge**. It will publish a SNAPSHOT/BETA release if there is a version change. +4. Create a PR to `main` branch. Once merged, it will publish a production release. --- WIP diff --git a/build.gradle.kts b/build.gradle.kts index 63d1aeef..68799eb0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,5 @@ +import com.mooltiverse.oss.nyx.gradle.CoreTask + plugins { kotlin("multiplatform") id("maven-publish-conventions") @@ -10,11 +12,21 @@ repositories { } group = "org.hisp.dhis.rules" -version = "3.0.0-SNAPSHOT" -val isReleaseVersion = project.hasProperty("removeSnapshot") -if (isReleaseVersion) { - version = (version as String).replace("-SNAPSHOT", "") +if (project.hasProperty("betaToSnapshot")) { + val mainVersion = (version as String).split("-beta")[0] + version = "$mainVersion-SNAPSHOT" +} + +tasks.register("checkIsNewVersion") { + val state = project.properties[CoreTask.NYX_STATE_PROPERTY] as com.mooltiverse.oss.nyx.state.State + + if (state.newVersion) { + println("This build generates a new version ${state.version}") + } else { + println("This build does not generate a new version ${state.version}") + throw StopExecutionException("There is no new version") + } } kotlin { @@ -29,9 +41,13 @@ kotlin { } js { nodejs() - useEsModules() + if (project.hasProperty("useCommonJs")) { + useCommonJs() + } else { + useEsModules() + generateTypeScriptDefinitions() + } binaries.library() - generateTypeScriptDefinitions() } val hostOs = System.getProperty("os.name") val isArm64 = System.getProperty("os.arch") == "aarch64" @@ -47,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") implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1") } } @@ -60,7 +81,11 @@ kotlin { } val jvmMain by getting val jvmTest by getting - val jsMain by getting + val jsMain by getting { + dependencies { + api("org.jetbrains.kotlin-wrappers:kotlin-js:1.0.0-pre.722") + } + } val jsTest by getting val nativeMain by getting val nativeTest by getting 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/buildSrc/src/main/kotlin/maven-publish-conventions.gradle.kts b/buildSrc/src/main/kotlin/maven-publish-conventions.gradle.kts index c9100530..485d8e5b 100644 --- a/buildSrc/src/main/kotlin/maven-publish-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/maven-publish-conventions.gradle.kts @@ -10,14 +10,12 @@ val ossrhPassword: String? = System.getenv("OSSRH_PASSWORD") val signingPrivateKey: String? = System.getenv("SIGNING_PRIVATE_KEY") val signingPassword: String? = System.getenv("SIGNING_PASSWORD") -val isReleaseVersion = (version as String).contains("SNAPSHOT") - val dokkaHtml = tasks.findByName("dokkaHtml")!! val dokkaHtmlJar = tasks.register("dokkaHtmlJar") { dependsOn(dokkaHtml) from(dokkaHtml.outputs) - archiveClassifier.set("docs") + archiveClassifier.set("javadoc") } publishing { @@ -70,7 +68,14 @@ nexusPublishing { } signing { - isRequired = isReleaseVersion + setRequired({ !version.toString().endsWith("-SNAPSHOT") }) useInMemoryPgpKeys(signingPrivateKey, signingPassword) sign(publishing.publications) } + +// Fix Gradle warning about signing tasks using publishing task outputs without explicit dependencies +// https://github.com/gradle/gradle/issues/26091 +tasks.withType().configureEach { + val signingTasks = tasks.withType() + mustRunAfter(signingTasks) +} diff --git a/buildSrc/src/main/kotlin/npm-publish-conventions.gradle.kts b/buildSrc/src/main/kotlin/npm-publish-conventions.gradle.kts index 82070d1e..dbe291a9 100644 --- a/buildSrc/src/main/kotlin/npm-publish-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/npm-publish-conventions.gradle.kts @@ -4,20 +4,22 @@ plugins { id("dev.petuska.npm.publish") } -val npmjsToken: String? = System.getenv("NPMJS_TOKEN") - project.afterEvaluate { npmPublish { access.set(NpmAccess.PUBLIC) packages { named("js") { scope.set("dhis2") + packageName.set("rule-engine") readme.set(File("./README.md")) packageJson { "module" by "${project.name}.mjs" - "main" by "" + "main" by "${project.name}.js" "exports" by { - "import" by "./${project.name}.mjs" + "." by { + "import" by "./${project.name}.mjs" + "require" by "./${project.name}.js" + } } "contributors" by Props.DEVELOPERS.map { developer -> "${developer.name} <${developer.email}>" @@ -31,22 +33,9 @@ project.afterEvaluate { "publishConfig" by { "access" by "public" } + "private" by false } } } - registries { - npmjs { - authToken.set(npmjsToken) - } - } - } - - tasks.named("assembleJsPackage") { - doLast { - val file = file("${layout.buildDirectory.get()}/packages/js/package.json") - val mainRegex = "\n \"main\": \"\"," - val removedMain = file.readText().replace(mainRegex, "") - file.writeText(removedMain) - } } } diff --git a/settings.gradle.kts b/settings.gradle.kts index c4debce4..10f3cc1e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,4 +5,8 @@ pluginManagement { } } +plugins { + id("com.mooltiverse.oss.nyx") version "2.5.2" +} + rootProject.name = "rule-engine" 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/RuleEngineGetDescriptionTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineGetDescriptionTest.kt index 2150cbd0..bd9b89dc 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineGetDescriptionTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineGetDescriptionTest.kt @@ -81,6 +81,11 @@ class RuleEngineGetDescriptionTest { test_var_number, ItemValueType.NUMBER ) + + val var_10 = DataItem( + test_var_four, + ItemValueType.TEXT + ) itemStore["test_var_one"] = var_1 itemStore["test_var_two"] = var_2 itemStore["test_var_date_one"] = var_3 @@ -90,6 +95,7 @@ class RuleEngineGetDescriptionTest { itemStore["current_date"] = var_7 itemStore["test_var_three"] = var_8 itemStore["test_var_number"] = var_9 + itemStore["test_var_four"] = var_10 } @Test @@ -294,12 +300,20 @@ class RuleEngineGetDescriptionTest { assertTrue(result.exception is RuleEngineValidationException) } + @Test + fun testGetDescriptionForNestedExpression() { + val result = ruleEngine.validate("d2:validatePattern(d2:right(A{test_var_four},1),'\\/202\\d{1}')",itemStore) + assertNotNull(result) + assertTrue(result.valid) + } + companion object { private const val test_var_one = "Variable_ONE" private const val test_var_two = "Variable_TWO" private const val test_var_three = "Variable_THREE" private const val test_var_date_one = "2020-01-01" private const val test_var_date_two = "2020-02-02" + private const val test_var_four = "Variable_FOUR" private const val completionDate = "Completion date" private const val currentDate = "Current date" private const val constant = "PI" 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 b7a5c912..43d5714c 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleActionJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleActionJs.kt @@ -1,11 +1,10 @@ package org.hisp.dhis.rules -import org.hisp.dhis.lib.expression.js.Entry +import js.collections.JsMap @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleActionJs( val data: String?, val type: String, - val values: Array> = emptyArray() + val values: JsMap = JsMap() ) \ No newline at end of file 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 e9f37464..16ad837c 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineContextJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineContextJs.kt @@ -1,12 +1,11 @@ package org.hisp.dhis.rules -import org.hisp.dhis.lib.expression.js.Entry +import js.collections.JsMap @JsExport -@OptIn(ExperimentalJsExport::class) data class RuleEngineContextJs( val rules: Array, val ruleVariables: Array, - val supplementaryData: Array>> = emptyArray(), - val constantsValues: Array> = emptyArray() + val supplementaryData: JsMap> = JsMap(), + val constantsValues: JsMap = JsMap() ) diff --git a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineJs.kt b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineJs.kt index f97aea95..af98c5e3 100644 --- a/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineJs.kt +++ b/src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineJs.kt @@ -1,21 +1,20 @@ package org.hisp.dhis.rules +import js.array.tupleOf +import js.collections.JsMap import kotlinx.datetime.Instant import kotlinx.datetime.LocalDate -import org.hisp.dhis.lib.expression.js.Entry 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: Array>): RuleValidationResult{ + fun validate(expression: String, dataItemStore: JsMap): RuleValidationResult{ return RuleEngine.getInstance().validate(expression, toMap(dataItemStore, {it}, ::toDataItemJava)) } - fun validateDataFieldExpression(expression: String, dataItemStore: Array>): RuleValidationResult{ + fun validateDataFieldExpression(expression: String, dataItemStore: JsMap): RuleValidationResult{ return RuleEngine.getInstance().validateDataFieldExpression(expression, toMap(dataItemStore, {it}, ::toDataItemJava)) } fun evaluateAll(enrollmentTarget: RuleEnrollmentJs?, eventsTarget: Array, executionContext: RuleEngineContextJs): Array{ @@ -38,15 +37,15 @@ class RuleEngineJs { .map(::toRuleEffectJs).toTypedArray() } - private fun toMap(map: Array>, key: (Kf) -> K, value: (Vf) -> V): Map { + private fun toMap(map: JsMap, key: (Kf) -> K, value: (Vf) -> V): Map { val res : MutableMap = mutableMapOf() - map.forEach { e -> res[key(e.key)] = value(e.value) } + map.forEach { v, k -> res[key(k)] = value(v) } return res } private fun toDataItemJava(item: DataItemJs) : DataItem { return DataItem( - valueType = ItemValueType.valueOf(item.valueType), + valueType = item.valueType, displayName = item.displayName ) } @@ -59,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() @@ -71,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), @@ -122,7 +121,7 @@ class RuleEngineJs { return RuleActionJs( data = ruleAction.data, type = ruleAction.type, - values = ruleAction.values.entries.map { e -> Entry(e.key, e.value) }.toTypedArray() + values = JsMap(ruleAction.values.entries.map { e -> tupleOf(e.key, e.value) }.toTypedArray()) ) } @@ -136,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() ) @@ -153,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( @@ -167,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 1809d73d..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