From c10ce74015c5ef8ae1b38aca4b985d1d8f1ba87c Mon Sep 17 00:00:00 2001 From: Mutesasira Moses Date: Fri, 20 Oct 2023 13:04:16 +0300 Subject: [PATCH] TaskRequest Object should only be created if incoming task is persisted --- .../api/scheduler/FetchTaskUpdates.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/labonfhir/api/scheduler/FetchTaskUpdates.java b/api/src/main/java/org/openmrs/module/labonfhir/api/scheduler/FetchTaskUpdates.java index 13d4289..8a343f3 100644 --- a/api/src/main/java/org/openmrs/module/labonfhir/api/scheduler/FetchTaskUpdates.java +++ b/api/src/main/java/org/openmrs/module/labonfhir/api/scheduler/FetchTaskUpdates.java @@ -126,11 +126,12 @@ public void execute() { taskBundle = client.loadPage().next(taskBundle).execute(); taskBundles.add(taskBundle); } - updateTasksInBundle(taskBundles); - - TaskRequest request = new TaskRequest(); - request.setRequestDate(newDate); - labOnFhirService.saveOrUpdateTaskRequest(request); + Boolean tasksUpdated = updateTasksInBundle(taskBundles); + if (tasksUpdated) { + TaskRequest request = new TaskRequest(); + request.setRequestDate(newDate); + labOnFhirService.saveOrUpdateTaskRequest(request); + } } catch (Exception e) { log.error("ERROR executing FetchTaskUpdates : " + e.toString() + getStackTrace(e)); @@ -146,7 +147,8 @@ public void shutdown() { this.stopExecuting(); } - private void updateTasksInBundle(List taskBundles) { + private Boolean updateTasksInBundle(List taskBundles) { + Boolean tasksUpdated = false; for (Bundle bundle : taskBundles) { for (Iterator tasks = bundle.getEntry().iterator(); tasks.hasNext();) { String openmrsTaskUuid = null; @@ -170,6 +172,7 @@ private void updateTasksInBundle(List taskBundles) { } if (taskOutPutUpdated) { taskService.update(openmrsTaskUuid, openmrsTask); + tasksUpdated = taskOutPutUpdated; } } } @@ -178,6 +181,7 @@ private void updateTasksInBundle(List taskBundles) { } } } + return tasksUpdated; } private Boolean updateOutput(List output, Task openmrsTask) {