From 4ea354c902956267b96217816b82e90cc31df134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Tar=C3=AD?= Date: Thu, 5 Sep 2024 10:37:49 +0200 Subject: [PATCH] chore: [ANDROAPP-6341] Use displayContent with fallback to content in rule actions (#3786) * chore: [ANDROAPP-6341] Use displayContent with fallback to content in rule actions * refactor common definition --- .../RuleEngineExtensions.kt | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/dhis2-mobile-program-rules/src/main/java/org/dhis2/mobileProgramRules/RuleEngineExtensions.kt b/dhis2-mobile-program-rules/src/main/java/org/dhis2/mobileProgramRules/RuleEngineExtensions.kt index 4f24f78f24..3668c00194 100644 --- a/dhis2-mobile-program-rules/src/main/java/org/dhis2/mobileProgramRules/RuleEngineExtensions.kt +++ b/dhis2-mobile-program-rules/src/main/java/org/dhis2/mobileProgramRules/RuleEngineExtensions.kt @@ -103,6 +103,8 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { else -> "" } + val contentToDisplay = displayContent() ?: content() + return when (programRuleActionType()) { ProgramRuleActionType.HIDEFIELD -> RuleAction( @@ -111,7 +113,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { values = mutableMapOf( Pair("field", field), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) @@ -122,7 +124,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { values = mutableMapOf( Pair("location", location() ?: "indicators"), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) @@ -133,7 +135,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { values = mutableMapOf( Pair("location", location()!!), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) @@ -178,7 +180,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { values = mutableMapOf( Pair("field", field), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) } @@ -190,7 +192,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { values = mutableMapOf( Pair("field", field), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) @@ -200,7 +202,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { values = mutableMapOf( Pair("field", field), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) @@ -211,7 +213,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { values = mutableMapOf( Pair("field", field), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) @@ -222,7 +224,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { values = mutableMapOf( Pair("field", field), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) @@ -234,7 +236,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { values = mutableMapOf( Pair("programStage", stageUid), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) } ?: RuleAction( @@ -249,7 +251,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { values = mutableMapOf( Pair("field", field), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) @@ -262,7 +264,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { Pair("field", field), Pair("option", optionUid), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) } ?: RuleAction( @@ -279,7 +281,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { Pair("field", field), Pair("optionGroup", optionGroupUid), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) } ?: RuleAction( @@ -296,7 +298,7 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { Pair("field", field), Pair("optionGroup", optionGroupUid), ).also { map -> - content()?.let { map["content"] = it } + contentToDisplay?.let { map["content"] = it } }, ) } ?: RuleAction(