From 8754a45b6d0d8f0f25c4b35bec79cf3b95e3ab9f Mon Sep 17 00:00:00 2001 From: FerdyRod Date: Thu, 21 Nov 2024 16:48:23 +0100 Subject: [PATCH] tei list cards only show overdue label when greater than 1+ day/s overdue --- .../SearchRepositoryImpl.java | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchRepositoryImpl.java b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchRepositoryImpl.java index 7aecc48978..377fff6329 100644 --- a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchRepositoryImpl.java +++ b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchRepositoryImpl.java @@ -389,39 +389,17 @@ private void setOverdueEvents(@NonNull SearchTeiModel tei, Program selectedProgr String teiId = tei.getTei() != null && tei.getTei().uid() != null ? tei.getTei().uid() : ""; List enrollments = d2.enrollmentModule().enrollments().byTrackedEntityInstance().eq(teiId).blockingGet(); - EventCollectionRepository scheduledEvents = d2.eventModule().events().byEnrollmentUid().in(UidsHelper.getUidsList(enrollments)) - .byStatus().eq(EventStatus.SCHEDULE) - .byDueDate().beforeOrEqual(new Date()); - EventCollectionRepository overdueEvents = d2.eventModule().events().byEnrollmentUid().in(UidsHelper.getUidsList(enrollments)).byStatus().eq(EventStatus.OVERDUE); if (selectedProgram != null) { - scheduledEvents = scheduledEvents.byProgramUid().eq(selectedProgram.uid()).orderByDueDate(RepositoryScope.OrderByDirection.DESC); - overdueEvents = overdueEvents.byProgramUid().eq(selectedProgram.uid()).orderByDueDate(RepositoryScope.OrderByDirection.DESC); + overdueEvents = overdueEvents.byProgramUid().eq(selectedProgram.uid()); } - int count; - List scheduleList = scheduledEvents.blockingGet(); - List overdueList = overdueEvents.blockingGet(); - count = overdueList.size() + scheduleList.size(); + List overdueList = overdueEvents.orderByDueDate(RepositoryScope.OrderByDirection.DESC).blockingGet(); - if (count > 0) { + if (!overdueList.isEmpty()) { tei.setHasOverdue(true); - Date scheduleDate = !scheduleList.isEmpty() ? scheduleList.get(0).dueDate() : null; - Date overdueDate = !overdueList.isEmpty() ? overdueList.get(0).dueDate() : null; - Date dateToShow = null; - if (scheduleDate != null && overdueDate != null) { - if (scheduleDate.before(overdueDate)) { - dateToShow = overdueDate; - } else { - dateToShow = scheduleDate; - } - } else if (scheduleDate != null) { - dateToShow = scheduleDate; - } else if (overdueDate != null) { - dateToShow = overdueDate; - } - tei.setOverdueDate(dateToShow); + tei.setOverdueDate(overdueList.get(0).dueDate()); } }