-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88c3712
commit f18c7f8
Showing
37 changed files
with
828 additions
and
1,001 deletions.
There are no files selected for viewing
45 changes: 0 additions & 45 deletions
45
src/main/java/org/hisp/dhis/rules/models/RuleVariable.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.hisp.dhis.rules.models | ||
|
||
import org.hisp.dhis.rules.Option | ||
import org.hisp.dhis.rules.RuleVariableValue | ||
import org.hisp.dhis.rules.RuleVariableValueMapBuilder | ||
import java.util.function.Predicate | ||
import javax.annotation.Nonnull | ||
|
||
interface RuleVariable { | ||
fun options(): List<Option> | ||
fun createValues( | ||
builder: RuleVariableValueMapBuilder, | ||
allEventValues: Map<String, List<RuleDataValue>>, | ||
currentEnrollmentValues: Map<String, RuleAttributeValue>, | ||
currentEventValues: Map<String, RuleDataValue> | ||
): Map<String, RuleVariableValue> | ||
|
||
fun getOptionName(value: String?): String? { | ||
// if no option found then existing value in the context will be used | ||
return options() | ||
.filter{ (_, code): Option -> value == code } | ||
.map(Option::name) | ||
.getOrElse(0) {_ -> value} | ||
} | ||
} |
55 changes: 0 additions & 55 deletions
55
src/main/java/org/hisp/dhis/rules/models/RuleVariableAttribute.java
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
src/main/java/org/hisp/dhis/rules/models/RuleVariableAttribute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.hisp.dhis.rules.models | ||
|
||
import org.hisp.dhis.rules.Option | ||
import org.hisp.dhis.rules.RuleVariableValue | ||
import org.hisp.dhis.rules.RuleVariableValueMapBuilder | ||
import org.hisp.dhis.rules.dateFormat | ||
import java.util.* | ||
import javax.annotation.Nonnull | ||
|
||
data class RuleVariableAttribute( | ||
val name: String, | ||
val useCodeForOptionSet: Boolean, | ||
val options: List<Option>, | ||
val trackedEntityAttribute: String, | ||
val trackedEntityAttributeType: RuleValueType | ||
) : RuleVariable { | ||
override fun options(): List<Option> { | ||
return options | ||
} | ||
|
||
override fun createValues( | ||
builder: RuleVariableValueMapBuilder, | ||
allEventValues: Map<String, List<RuleDataValue>>, | ||
currentEnrollmentValues: Map<String, RuleAttributeValue>, | ||
currentEventValues: Map<String, RuleDataValue> | ||
): Map<String, RuleVariableValue> { | ||
val valueMap: MutableMap<String, RuleVariableValue> = HashMap() | ||
val currentDate = dateFormat.format(Date()) | ||
val variableValue: RuleVariableValue | ||
variableValue = if (currentEnrollmentValues.containsKey(trackedEntityAttribute)) { | ||
val value = currentEnrollmentValues[trackedEntityAttribute] | ||
val optionValue = if (useCodeForOptionSet) value!!.value else getOptionName(value!!.value)!! | ||
RuleVariableValue.create( | ||
optionValue, trackedEntityAttributeType, | ||
java.util.List.of(optionValue), currentDate | ||
) | ||
} else { | ||
RuleVariableValue.create(trackedEntityAttributeType) | ||
} | ||
valueMap[name] = variableValue | ||
return valueMap | ||
} | ||
} |
67 changes: 0 additions & 67 deletions
67
src/main/java/org/hisp/dhis/rules/models/RuleVariableCalculatedValue.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
src/main/java/org/hisp/dhis/rules/models/RuleVariableCalculatedValue.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.hisp.dhis.rules.models | ||
|
||
import org.hisp.dhis.rules.* | ||
import javax.annotation.Nonnull | ||
|
||
/* | ||
* Copyright (c) 2004-2018, University of Oslo | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* Neither the name of the HISP project nor the names of its contributors may | ||
* be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ /** | ||
* @author Zubair Asghar. | ||
*/ | ||
class RuleVariableCalculatedValue( | ||
val name: String, | ||
val useCodeForOptionSet: Boolean, | ||
val options: List<Option>, | ||
val calculatedValueVariable: String, | ||
val calculatedValueType: RuleValueType | ||
) : RuleVariable { | ||
override fun options(): List<Option> { | ||
return options | ||
} | ||
|
||
override fun createValues( | ||
builder: RuleVariableValueMapBuilder, | ||
allEventValues: Map<String, List<RuleDataValue>>, | ||
currentEnrollmentValues: Map<String, RuleAttributeValue>, | ||
currentEventValues: Map<String, RuleDataValue> | ||
): Map<String, RuleVariableValue> { | ||
val valueMap: MutableMap<String, RuleVariableValue> = HashMap() | ||
valueMap[name] = RuleVariableValue.create(calculatedValueType) | ||
return valueMap | ||
} | ||
} |
51 changes: 0 additions & 51 deletions
51
src/main/java/org/hisp/dhis/rules/models/RuleVariableCurrentEvent.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
src/main/java/org/hisp/dhis/rules/models/RuleVariableCurrentEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.hisp.dhis.rules.models | ||
|
||
import org.hisp.dhis.rules.* | ||
import javax.annotation.Nonnull | ||
|
||
class RuleVariableCurrentEvent( | ||
val name: String, | ||
val useCodeForOptionSet: Boolean, | ||
val options: List<Option>, | ||
val dataElement: String, | ||
val dataElementType: RuleValueType | ||
) : RuleVariableDataElement { | ||
override fun dataElement(): String { | ||
return dataElement | ||
} | ||
|
||
override fun dataElementType(): RuleValueType { | ||
return dataElementType | ||
} | ||
|
||
override fun options(): List<Option> { | ||
return options | ||
} | ||
|
||
override fun createValues( | ||
builder: RuleVariableValueMapBuilder, | ||
allEventValues: Map<String, List<RuleDataValue>>, | ||
currentEnrollmentValues: Map<String, RuleAttributeValue>, | ||
currentEventValues: Map<String, RuleDataValue> | ||
): Map<String, RuleVariableValue> { | ||
val valueMap: MutableMap<String, RuleVariableValue> = HashMap() | ||
val variableValue: RuleVariableValue | ||
variableValue = if (currentEventValues.containsKey(dataElement)) { | ||
val value = currentEventValues[dataElement] | ||
val optionValue = if (useCodeForOptionSet) value!!.value else getOptionName(value!!.value)!! | ||
RuleVariableValue.create( | ||
optionValue, dataElementType, | ||
java.util.List.of(optionValue), getLastUpdateDate(java.util.List.of(value)) | ||
) | ||
} else { | ||
RuleVariableValue.create(dataElementType) | ||
} | ||
valueMap[name] = variableValue | ||
return valueMap | ||
} | ||
} |
Oops, something went wrong.