Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link encounter with task #93

Merged
merged 6 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,13 @@ 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 taskID = taskReference

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be one line, why are we creating a taskReference and the taskID?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright noted

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sevenreup changes made

val encounterStatus = resource.status
val encounterReference = resource.logicalId.removePrefix("#")
fhirCarePlanGenerator.completeTask(taskID, encounterStatus, encounterReference)
}
}
}
Expand Down
Loading