From fa07680a0d033bad781157fa5f6a76ad41ba9f69 Mon Sep 17 00:00:00 2001 From: Enrico Date: Wed, 17 Jan 2024 10:52:50 +0100 Subject: [PATCH 1/3] feat: Add Js API --- .../org/hisp/dhis/rules/models/Option.kt | 8 +- .../dhis/rules/models/RuleAttributeValue.kt | 5 + .../dhis/rules/models/RuleValidationResult.kt | 8 +- .../hisp/dhis/rules/models/RuleVariable.kt | 4 + .../rules/models/RuleVariableAttribute.kt | 16 +- .../models/RuleVariableCalculatedValue.kt | 10 +- .../rules/models/RuleVariableCurrentEvent.kt | 18 +- .../rules/models/RuleVariableDataElement.kt | 7 - .../rules/models/RuleVariableNewestEvent.kt | 16 +- .../models/RuleVariableNewestStageEvent.kt | 16 +- .../rules/models/RuleVariablePreviousEvent.kt | 16 +- .../rules/models/RuleVariableAttributeTest.kt | 16 -- .../models/RuleVariableCurrentEventTest.kt | 16 -- .../models/RuleVariableNewestEventTest.kt | 15 -- .../RuleVariableNewestStageEventTest.kt | 16 -- .../models/RuleVariablePreviousEventTest.kt | 16 -- .../kotlin/org/hisp/dhis/rules/DataItemJs.kt | 15 ++ .../kotlin/org/hisp/dhis/rules/Logger.kt | 2 + .../org/hisp/dhis/rules/RuleActionJs.kt | 11 + .../org/hisp/dhis/rules/RuleDataValueJs.kt | 12 ++ .../org/hisp/dhis/rules/RuleEffectJs.kt | 9 + .../org/hisp/dhis/rules/RuleEffectsJs.kt | 19 ++ .../hisp/dhis/rules/RuleEngineContextJs.kt | 16 ++ .../org/hisp/dhis/rules/RuleEngineJs.kt | 202 ++++++++++++++++++ .../org/hisp/dhis/rules/RuleEnrollmentJs.kt | 18 ++ .../kotlin/org/hisp/dhis/rules/RuleEventJs.kt | 21 ++ .../kotlin/org/hisp/dhis/rules/RuleJs.kt | 12 ++ .../org/hisp/dhis/rules/RuleVariableJs.kt | 31 +++ .../org/hisp/dhis/rules/RuleVariableType.kt | 10 + 29 files changed, 445 insertions(+), 136 deletions(-) delete mode 100644 src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleVariableDataElement.kt delete mode 100644 src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableAttributeTest.kt delete mode 100644 src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableCurrentEventTest.kt delete mode 100644 src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableNewestEventTest.kt delete mode 100644 src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableNewestStageEventTest.kt delete mode 100644 src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariablePreviousEventTest.kt create mode 100644 src/jsMain/kotlin/org/hisp/dhis/rules/DataItemJs.kt create mode 100644 src/jsMain/kotlin/org/hisp/dhis/rules/RuleActionJs.kt create mode 100644 src/jsMain/kotlin/org/hisp/dhis/rules/RuleDataValueJs.kt create mode 100644 src/jsMain/kotlin/org/hisp/dhis/rules/RuleEffectJs.kt create mode 100644 src/jsMain/kotlin/org/hisp/dhis/rules/RuleEffectsJs.kt create mode 100644 src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineContextJs.kt create mode 100644 src/jsMain/kotlin/org/hisp/dhis/rules/RuleEngineJs.kt create mode 100644 src/jsMain/kotlin/org/hisp/dhis/rules/RuleEnrollmentJs.kt create mode 100644 src/jsMain/kotlin/org/hisp/dhis/rules/RuleEventJs.kt create mode 100644 src/jsMain/kotlin/org/hisp/dhis/rules/RuleJs.kt create mode 100644 src/jsMain/kotlin/org/hisp/dhis/rules/RuleVariableJs.kt create mode 100644 src/jsMain/kotlin/org/hisp/dhis/rules/RuleVariableType.kt 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 51eae686..43b597a3 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/models/Option.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/Option.kt @@ -1,6 +1,8 @@ package org.hisp.dhis.rules.models -/** - * @author rajazubair - */ +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 404b3542..353b14e1 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleAttributeValue.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleAttributeValue.kt @@ -1,5 +1,10 @@ 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/RuleValidationResult.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleValidationResult.kt index 65d9e9c6..6d62ebe2 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleValidationResult.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleValidationResult.kt @@ -1,5 +1,9 @@ package org.hisp.dhis.rules.models +import kotlin.js.ExperimentalJsExport +import kotlin.js.JsExport +import kotlin.jvm.JvmOverloads + /* * Copyright (c) 2004-2020, University of Oslo * All rights reserved. @@ -29,7 +33,9 @@ package org.hisp.dhis.rules.models */ /** * @author Zubair Asghar */ -data class RuleValidationResult( +@JsExport +@OptIn(ExperimentalJsExport::class) +data class RuleValidationResult @JvmOverloads constructor( val valid: Boolean, val errorMessage: String? = null, val exception: Throwable? = null, diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleVariable.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleVariable.kt index 9013a37c..3850bd47 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleVariable.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/models/RuleVariable.kt @@ -4,7 +4,11 @@ import org.hisp.dhis.rules.engine.RuleVariableValue import org.hisp.dhis.rules.engine.RuleVariableValueMapBuilder interface RuleVariable { + val name: String + val useCodeForOptionSet: Boolean val options: List