diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/view/ButtonProperties.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/view/ButtonProperties.kt index 760dc05662..8996c628f5 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/view/ButtonProperties.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/view/ButtonProperties.kt @@ -70,6 +70,7 @@ data class ButtonProperties( ServiceStatus.COMPLETED -> DefaultColor ServiceStatus.IN_PROGRESS -> WarningColor ServiceStatus.EXPIRED -> DefaultColor + ServiceStatus.FAILED -> DangerColor } } diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/domain/model/ServiceStatus.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/domain/model/ServiceStatus.kt index b18b49811f..dddc09a595 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/domain/model/ServiceStatus.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/domain/model/ServiceStatus.kt @@ -23,4 +23,5 @@ enum class ServiceStatus { COMPLETED, IN_PROGRESS, EXPIRED, + FAILED, } diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/rulesengine/RulesFactory.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/rulesengine/RulesFactory.kt index 68664ffc4d..94ac19d590 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/rulesengine/RulesFactory.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/rulesengine/RulesFactory.kt @@ -554,7 +554,6 @@ constructor( serviceStatus = when (task.status) { Task.TaskStatus.NULL, - Task.TaskStatus.FAILED, Task.TaskStatus.RECEIVED, Task.TaskStatus.ENTEREDINERROR, Task.TaskStatus.ACCEPTED, @@ -564,6 +563,7 @@ constructor( Timber.e("Task.status is null", Exception()) ServiceStatus.UPCOMING.name } + Task.TaskStatus.FAILED -> ServiceStatus.FAILED.name Task.TaskStatus.REQUESTED -> ServiceStatus.UPCOMING.name Task.TaskStatus.READY -> ServiceStatus.DUE.name Task.TaskStatus.CANCELLED -> ServiceStatus.EXPIRED.name diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/task/FhirResourceUtil.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/task/FhirResourceUtil.kt index af99a0e8dd..30db2d7b83 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/task/FhirResourceUtil.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/task/FhirResourceUtil.kt @@ -199,14 +199,17 @@ constructor( /** * Check if current [Task] is part of another [Task] then return true if the [Task.TaskStatus] of - * the parent [Task](that the current [Task] is part of) is [Task.TaskStatus.COMPLETED], otherwise - * return false. + * the parent [Task](that the current [Task] is part of) is [Task.TaskStatus.COMPLETED] or + * [Task.TaskStatus.FAILED], otherwise return false. */ private suspend fun Task.preRequisiteConditionSatisfied() = this.partOf .find { it.reference.startsWith(ResourceType.Task.name + "/") } ?.let { - defaultRepository.fhirEngine.get(it.extractId()).status.isIn(TaskStatus.COMPLETED) + defaultRepository.fhirEngine + .get(it.extractId()) + .status + .isIn(TaskStatus.COMPLETED, TaskStatus.FAILED) } ?: false suspend fun closeRelatedResources(resource: Resource) { diff --git a/android/engine/src/test/java/org/smartregister/fhircore/engine/configuration/ButtonPropertiesTest.kt b/android/engine/src/test/java/org/smartregister/fhircore/engine/configuration/ButtonPropertiesTest.kt index 53020f6e7e..747c398262 100644 --- a/android/engine/src/test/java/org/smartregister/fhircore/engine/configuration/ButtonPropertiesTest.kt +++ b/android/engine/src/test/java/org/smartregister/fhircore/engine/configuration/ButtonPropertiesTest.kt @@ -95,5 +95,8 @@ class ButtonPropertiesTest : RobolectricTest() { map["status"] = "UPCOMING" val statusColorUpcoming = buttonProperties.statusColor(map) Assert.assertEquals(statusColorUpcoming, DefaultColor) + map["status"] = "FAILED" + val statusColorFailed = buttonProperties.statusColor(map) + Assert.assertEquals(statusColorFailed, DangerColor) } } diff --git a/android/engine/src/test/java/org/smartregister/fhircore/engine/rulesengine/RulesEngineServiceTest.kt b/android/engine/src/test/java/org/smartregister/fhircore/engine/rulesengine/RulesEngineServiceTest.kt index fd5ea42f64..c919bd3d91 100644 --- a/android/engine/src/test/java/org/smartregister/fhircore/engine/rulesengine/RulesEngineServiceTest.kt +++ b/android/engine/src/test/java/org/smartregister/fhircore/engine/rulesengine/RulesEngineServiceTest.kt @@ -235,6 +235,16 @@ class RulesEngineServiceTest : RobolectricTest() { ) } + @Test + fun `generateTaskServiceStatus() should return FAILED when Task#status is FAILED`() { + val task = Task().apply { status = Task.TaskStatus.FAILED } + + Assert.assertEquals( + ServiceStatus.FAILED.name, + rulesEngineService.generateTaskServiceStatus(task), + ) + } + @Test fun `generateTaskServiceStatus() should return OVERDUE when Task#executionPeriod#hasEnd() and Task#executionPeriod#end#before(today())`() { val sdf = SimpleDateFormat("dd/MM/yyyy") diff --git a/android/engine/src/test/java/org/smartregister/fhircore/engine/task/FhirResourceUtilTest.kt b/android/engine/src/test/java/org/smartregister/fhircore/engine/task/FhirResourceUtilTest.kt index 60ed36e886..ee0010e637 100644 --- a/android/engine/src/test/java/org/smartregister/fhircore/engine/task/FhirResourceUtilTest.kt +++ b/android/engine/src/test/java/org/smartregister/fhircore/engine/task/FhirResourceUtilTest.kt @@ -267,7 +267,9 @@ class FhirResourceUtilTest : RobolectricTest() { } } - coEvery { fhirEngine.get(any()).status.isIn(TaskStatus.COMPLETED) } returns true + coEvery { + fhirEngine.get(any()).status.isIn(TaskStatus.COMPLETED, TaskStatus.FAILED) + } returns true coEvery { defaultRepository.update(any()) } just runs diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/ActionableButton.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/ActionableButton.kt index 7fdf5069fe..77a7b46631 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/ActionableButton.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/ActionableButton.kt @@ -32,6 +32,7 @@ import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Check +import androidx.compose.material.icons.filled.Clear import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -53,6 +54,7 @@ import org.smartregister.fhircore.engine.configuration.view.ButtonType import org.smartregister.fhircore.engine.configuration.view.ImageProperties import org.smartregister.fhircore.engine.domain.model.ResourceData import org.smartregister.fhircore.engine.domain.model.ServiceStatus +import org.smartregister.fhircore.engine.ui.theme.DangerColor import org.smartregister.fhircore.engine.ui.theme.DefaultColor import org.smartregister.fhircore.engine.ui.theme.SuccessColor import org.smartregister.fhircore.engine.util.annotation.PreviewWithBackgroundExcludeGenerated @@ -148,6 +150,7 @@ fun ActionableButton( if (isButtonEnabled) { when (status) { ServiceStatus.COMPLETED.name -> SuccessColor + ServiceStatus.FAILED.name -> DangerColor else -> statusColor } } else { @@ -163,9 +166,15 @@ fun ActionableButton( } else { Icon( imageVector = - if (status == ServiceStatus.COMPLETED.name) { - Icons.Filled.Check - } else Icons.Filled.Add, + when (status) { + ServiceStatus.COMPLETED.name -> { + Icons.Filled.Check + } + ServiceStatus.FAILED.name -> { + Icons.Filled.Clear + } + else -> Icons.Filled.Add + }, contentDescription = null, tint = iconTintColor, modifier = Modifier.size(16.dp),