Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [ANDROAPP-6505] Handles program rules with calculated values #3844

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,18 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction {
RuleAction(
data = data() ?: "",
type = ProgramRuleActionType.ASSIGN.name,
values = mutableMapOf(
Pair("field", field),
).also { map ->
contentToDisplay?.let { map["content"] = it }
values = if (field.isNotEmpty()) {
mutableMapOf(
Pair("field", field),
).also { map ->
contentToDisplay?.let { map["content"] = it }
}
} else {
contentToDisplay?.let {
mutableMapOf(
Pair("content", it),
)
} ?: emptyMap()
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.hisp.dhis.android.core.event.Event
import org.hisp.dhis.android.core.option.Option
import org.hisp.dhis.android.core.option.OptionCollectionRepository
import org.hisp.dhis.android.core.program.ProgramRuleAction
import org.hisp.dhis.android.core.program.ProgramRuleActionType
import org.hisp.dhis.android.core.program.ProgramRuleVariable
import org.hisp.dhis.android.core.program.ProgramRuleVariableCollectionRepository
import org.hisp.dhis.android.core.program.ProgramRuleVariableSourceType
Expand Down Expand Up @@ -368,6 +369,19 @@ class RuleEngineExtensionsTest {
assertTrue(ruleEngineAction.type == "unsupported")
}

@Test
fun `Should parse program rule action to rule action with calculated value`() {
val ruleAction = ProgramRuleAction.builder()
.uid("uid")
.data("")
.content("calculated value")
.programRuleActionType(ProgramRuleActionType.ASSIGN)
.build()
val ruleEngineAction = ruleAction.toRuleEngineObject()
assertTrue(!ruleEngineAction.values.containsKey("field"))
assertTrue(ruleEngineAction.values["content"] == "calculated value")
}

@Test
fun `should parse ProgramRuleVariable to RuleVariable`() {
val programRuleVariable = ProgramRuleVariable.builder()
Expand Down