Skip to content

Commit

Permalink
Merge branch 'opensrp-0.2.5' into 2489-hh-register-tasklist-status
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin authored Aug 21, 2023
2 parents ab7b815 + 8c2ba64 commit 096d401
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,12 @@ constructor(
}
}

val careplanTasks =
output.contained.filter { it.resourceType == ResourceType.Task }.map { it as Task }

if (carePlanModified) saveCarePlan(output)

fhirTaskUtil.updateTaskStatuses()
fhirTaskUtil.updateTaskStatuses(careplanTasks)

return if (output.hasActivity()) output else null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,26 @@ constructor(@ApplicationContext val appContext: Context, val defaultRepository:
?.lastOrNull()
?.extractId() == task.logicalId

suspend fun updateTaskStatuses() {
suspend fun updateTaskStatuses(tasks: List<Task>? = null) {
Timber.i("Update tasks statuses")

val tasks =
defaultRepository.fhirEngine.search<Task> {
filter(
Task.STATUS,
{ value = of(TaskStatus.REQUESTED.toCoding()) },
{ value = of(TaskStatus.ACCEPTED.toCoding()) },
{ value = of(TaskStatus.RECEIVED.toCoding()) }
)
filter(
Task.PERIOD,
{
prefix = ParamPrefixEnum.LESSTHAN_OR_EQUALS
value = of(DateTimeType(Date()))
}
)
}
tasks
?: defaultRepository.fhirEngine.search {
filter(
Task.STATUS,
{ value = of(TaskStatus.REQUESTED.toCoding()) },
{ value = of(TaskStatus.ACCEPTED.toCoding()) },
{ value = of(TaskStatus.RECEIVED.toCoding()) }
)
filter(
Task.PERIOD,
{
prefix = ParamPrefixEnum.LESSTHAN_OR_EQUALS
value = of(DateTimeType(Date()))
}
)
}

Timber.i("Found ${tasks.size} tasks to be updated")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,50 @@ class FhirTaskUtilTest : RobolectricTest() {

coVerify { defaultRepository.update(task) }

assertEquals(TaskStatus.READY, task.status)
}
@Test
fun testUpdateTaskStatusesGivenTasks() {

val task =
Task().apply {
id = "test-task-id"
partOf = listOf(Reference("Task/parent-test-task-id"))
executionPeriod =
Period().apply {
start = Date().plusDays(-5)
status = TaskStatus.REQUESTED
}
}

coEvery {
fhirEngine.search<Task> {
filter(
Task.STATUS,
{ value = of(TaskStatus.REQUESTED.toCoding()) },
{ value = of(TaskStatus.ACCEPTED.toCoding()) },
{ value = of(TaskStatus.RECEIVED.toCoding()) },
)
filter(
Task.PERIOD,
{
prefix = ParamPrefixEnum.LESSTHAN_OR_EQUALS
value = of(DateTimeType(Date().plusDays(-1)))
}
)
}
} returns listOf(task)

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

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

assertEquals(TaskStatus.REQUESTED, task.status)

runBlocking { fhirTaskUtil.updateTaskStatuses(listOf(task)) }

coVerify { defaultRepository.update(task) }

assertEquals(TaskStatus.READY, task.status)
}
}
4 changes: 2 additions & 2 deletions android/quest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ android {
applicationId = "org.smartregister.opensrp"
minSdk = 26
targetSdk = 33
versionCode = 3
versionName = "0.2.5"
versionCode = 4
versionName = "1.0.0"
multiDexEnabled = true

buildConfigField("boolean", "SKIP_AUTH_CHECK", "false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ constructor(
val existingValidReports = mutableListOf<MeasureReport>()

existingReports?.groupBy { it.subject.reference }?.forEach { entry ->
if (entry.value.size > 1) {
if (entry.value.size > 1 &&
entry.value.distinctBy { it.measure }.size > 1 &&
entry.value.distinctBy { it.type }.size > 1
) {
return@forEach
} else {
existingValidReports.addAll(entry.value)
Expand Down

0 comments on commit 096d401

Please sign in to comment.