From d08598a5ea8378b085446da591275e7601947bb9 Mon Sep 17 00:00:00 2001 From: manu Date: Tue, 9 Jan 2024 17:24:06 +0100 Subject: [PATCH] fix: [ANDROAPP-5803] ignore deleted events on schedule creation --- .../eventDetails/data/EventDetailsRepository.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/data/EventDetailsRepository.kt b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/data/EventDetailsRepository.kt index d51d0100f5..6f1ca16d3d 100644 --- a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/data/EventDetailsRepository.kt +++ b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/data/EventDetailsRepository.kt @@ -75,10 +75,12 @@ class EventDetailsRepository( val activeEvents = d2.eventModule().events().byEnrollmentUid().eq(enrollmentUid).byProgramStageUid() .eq(programStageUid) + .byDeleted().isFalse .orderByEventDate(RepositoryScope.OrderByDirection.DESC).blockingGet() val scheduleEvents = d2.eventModule().events().byEnrollmentUid().eq(enrollmentUid).byProgramStageUid() .eq(programStageUid) + .byDeleted().isFalse .orderByDueDate(RepositoryScope.OrderByDirection.DESC).blockingGet() var activeDate: Date? = null @@ -88,7 +90,12 @@ class EventDetailsRepository( } if (scheduleEvents.isNotEmpty()) scheduleDate = scheduleEvents[0].dueDate() - return activeDate ?: scheduleDate + return when { + scheduleDate == null -> activeDate + activeDate == null -> scheduleDate + activeDate.before(scheduleDate) -> scheduleDate + else -> activeDate + } } fun hasAccessDataWrite(): Boolean {