Skip to content

Commit

Permalink
tei list cards only show overdue label when greater than 1+ day/s ove…
Browse files Browse the repository at this point in the history
…rdue
  • Loading branch information
ferdyrod committed Dec 4, 2024
1 parent 802a4f4 commit 606c017
Showing 1 changed file with 4 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Enrollment> 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<Event> scheduleList = scheduledEvents.blockingGet();
List<Event> overdueList = overdueEvents.blockingGet();
count = overdueList.size() + scheduleList.size();
List<Event> 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());
}
}

Expand Down

0 comments on commit 606c017

Please sign in to comment.