Skip to content

Commit

Permalink
Merge branch 'mwcore-dev' into check-missing-tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenreup committed Aug 12, 2024
2 parents ffc9a58 + 3890584 commit 1beca75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import org.hl7.fhir.r4.model.IdType
import org.hl7.fhir.r4.model.Parameters
import org.hl7.fhir.r4.model.PlanDefinition
import org.hl7.fhir.r4.model.Resource
import org.hl7.fhir.r4.model.ResourceType
import org.hl7.fhir.r4.model.StructureMap
import org.hl7.fhir.r4.model.Task
import org.hl7.fhir.r4.utils.FHIRPathEngine
import org.hl7.fhir.r4.utils.StructureMapUtilities
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.util.extension.asReference
import org.smartregister.fhircore.engine.util.extension.encodeResourceToString
import org.smartregister.fhircore.engine.util.extension.getCarePlanId
import org.smartregister.fhircore.engine.util.extension.taskStatusToCarePlanActivityStatus
Expand Down Expand Up @@ -133,12 +135,17 @@ constructor(val fhirEngine: FhirEngine, val transformSupportServices: TransformS
}
}

suspend fun completeTask(id: String, encounterStatus: EncounterStatus?) {
suspend fun completeTask(
id: String,
encounterStatus: EncounterStatus?,
encounterReference: String,
) {
val resourcesToUpdate = mutableListOf<Resource>()
val task =
fhirEngine.get<Task>(id).apply {
this.status = encounterStatusToTaskStatus(encounterStatus)
this.lastModified = Date()
this.encounter = encounterReference.asReference(ResourceType.Encounter)
}
resourcesToUpdate.add(task)
val carePlanId = task.getCarePlanId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,12 @@ constructor(

private suspend fun updateCarePlanAndTask(extras: List<Resource>, backReference: String?) {
if (backReference != null && backReference != "notify") {
extras.forEach {
if (it is Encounter) {
fhirCarePlanGenerator.completeTask(
backReference.asReference(ResourceType.Task).extractId(),
it.status,
)
extras.forEach { resource ->
if (resource is Encounter) {
val taskReference = backReference.asReference(ResourceType.Task).extractId()
val encounterStatus = resource.status
val encounterReference = resource.logicalId.removePrefix("#")
fhirCarePlanGenerator.completeTask(taskReference, encounterStatus, encounterReference)
}
}
}
Expand Down

0 comments on commit 1beca75

Please sign in to comment.