Skip to content

Commit

Permalink
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenreup committed Jun 27, 2023
2 parents 7e5da06 + a8a2918 commit a72ff10
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,20 @@ constructor(
}

internal suspend fun Patient.activeTasks(): List<Task> {
return this.activeCarePlans()
.flatMap { it.activity }
.flatMap { it.outcomeReference }
.filter { it.reference.startsWith(ResourceType.Task.name) }
.map { defaultRepository.loadResource(it) as Task }
return this.activeCarePlans().flatMap { it.activity }.flatMap {
it.outcomeReference
.filter { outcomeRef -> outcomeRef.reference.startsWith(ResourceType.Task.name) }
.map { reference ->
val task = defaultRepository.loadResource(reference) as Task
task.apply {
if (it.detail.status == CarePlan.CarePlanActivityStatus.COMPLETED &&
status != Task.TaskStatus.COMPLETED
) {
status = Task.TaskStatus.COMPLETED
}
}
}
}
}

internal suspend fun Patient.activeCarePlans() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import org.smartregister.fhircore.engine.util.extension.extractId
import org.smartregister.fhircore.engine.util.extension.hasPastEnd
import org.smartregister.fhircore.engine.util.extension.hasStarted
import org.smartregister.fhircore.engine.util.extension.isLastTask
import org.smartregister.fhircore.engine.util.extension.toCoding
import timber.log.Timber

@HiltWorker
Expand All @@ -52,13 +51,23 @@ constructor(
.search<Task> {
filter(
Task.STATUS,
{ value = of(Task.TaskStatus.REQUESTED.toCoding()) },
{ value = of(Task.TaskStatus.READY.toCoding()) },
{ value = of(Task.TaskStatus.ACCEPTED.toCoding()) },
{ value = of(Task.TaskStatus.INPROGRESS.toCoding()) },
{ value = of(Task.TaskStatus.RECEIVED.toCoding()) },
{ value = of(Task.TaskStatus.REQUESTED.toCode()) },
{ value = of(Task.TaskStatus.READY.toCode()) },
{ value = of(Task.TaskStatus.ACCEPTED.toCode()) },
{ value = of(Task.TaskStatus.INPROGRESS.toCode()) },
{ value = of(Task.TaskStatus.RECEIVED.toCode()) },
)
}
.filter {
it.status in
arrayOf(
Task.TaskStatus.REQUESTED,
Task.TaskStatus.READY,
Task.TaskStatus.ACCEPTED,
Task.TaskStatus.INPROGRESS,
Task.TaskStatus.RECEIVED
)
}
.forEach { task ->
if (task.hasPastEnd()) {
task.status = Task.TaskStatus.FAILED
Expand All @@ -75,7 +84,7 @@ constructor(
fhirEngine.update(carePlan)
}
}
} else if (task.hasStarted()) {
} else if (task.hasStarted() && task.status != Task.TaskStatus.READY) {
task.status = Task.TaskStatus.READY
fhirEngine.update(task)
}
Expand Down

0 comments on commit a72ff10

Please sign in to comment.