Skip to content

Commit

Permalink
Introduce FAILED ServiceStatus
Browse files Browse the repository at this point in the history
* Add a new "failed" task status for skipped vaccines dosages

* Add tests

* Add tests

* Fix tests

---------

Co-authored-by: aurangzaibumer <[email protected]>
  • Loading branch information
qaziabubakar-vd and aurangzaibumer authored May 28, 2024
1 parent 7057c38 commit f148a3a
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ data class ButtonProperties(
ServiceStatus.COMPLETED -> DefaultColor
ServiceStatus.IN_PROGRESS -> WarningColor
ServiceStatus.EXPIRED -> DefaultColor
ServiceStatus.FAILED -> DangerColor
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ enum class ServiceStatus {
COMPLETED,
IN_PROGRESS,
EXPIRED,
FAILED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ constructor(
serviceStatus =
when (task.status) {
Task.TaskStatus.NULL,
Task.TaskStatus.FAILED,
Task.TaskStatus.RECEIVED,
Task.TaskStatus.ENTEREDINERROR,
Task.TaskStatus.ACCEPTED,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Task>(it.extractId()).status.isIn(TaskStatus.COMPLETED)
defaultRepository.fhirEngine
.get<Task>(it.extractId())
.status
.isIn(TaskStatus.COMPLETED, TaskStatus.FAILED)
} ?: false

suspend fun closeRelatedResources(resource: Resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ class FhirResourceUtilTest : RobolectricTest() {
}
}

coEvery { fhirEngine.get<Task>(any()).status.isIn(TaskStatus.COMPLETED) } returns true
coEvery {
fhirEngine.get<Task>(any()).status.isIn(TaskStatus.COMPLETED, TaskStatus.FAILED)
} returns true

coEvery { defaultRepository.update(any()) } just runs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -148,6 +150,7 @@ fun ActionableButton(
if (isButtonEnabled) {
when (status) {
ServiceStatus.COMPLETED.name -> SuccessColor
ServiceStatus.FAILED.name -> DangerColor
else -> statusColor
}
} else {
Expand All @@ -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),
Expand Down

0 comments on commit f148a3a

Please sign in to comment.