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

fix: [ANDROAPP-6480] Tei list card shows overdue label when events are one or more days overdue #3898

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions app/src/main/java/org/dhis2/bindings/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import java.text.DecimalFormat

fun <T : Any?> MutableLiveData<T>.default(initialValue: T) = this.apply { setValue(initialValue) }

@Deprecated("Use ProfilePictureProvider instead")
fun TrackedEntityInstance.profilePicturePath(d2: D2, programUid: String?): String {
var path: String? = null

Expand Down
ferdyrod marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.dhis2.metadata.usecases.FileResourceConfiguration;
import org.dhis2.metadata.usecases.ProgramConfiguration;
import org.dhis2.metadata.usecases.TrackedEntityInstanceConfiguration;
import org.dhis2.tracker.data.ProfilePictureProvider;
import org.dhis2.tracker.relationships.model.RelationshipDirection;
import org.dhis2.tracker.relationships.model.RelationshipModel;
import org.dhis2.tracker.relationships.model.RelationshipOwnerType;
Expand Down Expand Up @@ -121,6 +122,7 @@ public class SearchRepositoryImpl implements SearchRepository {
private HashMap<String, List<String>> trackedEntityTypeAttributesUidsCache = new HashMap();

private final MetadataIconProvider metadataIconProvider;
private final ProfilePictureProvider profilePictureProvider;

SearchRepositoryImpl(String teiType,
@Nullable String initialProgram,
Expand All @@ -134,7 +136,8 @@ public class SearchRepositoryImpl implements SearchRepository {
NetworkUtils networkUtils,
SearchTEIRepository searchTEIRepository,
ThemeManager themeManager,
MetadataIconProvider metadataIconProvider
MetadataIconProvider metadataIconProvider,
ProfilePictureProvider profilePictureProvider
) {
this.teiType = teiType;
this.d2 = d2;
Expand All @@ -155,6 +158,7 @@ public class SearchRepositoryImpl implements SearchRepository {
currentProgram,
resources);
this.metadataIconProvider = metadataIconProvider;
this.profilePictureProvider = profilePictureProvider;
}


Expand Down Expand Up @@ -389,39 +393,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 Expand Up @@ -768,7 +750,7 @@ public SearchTeiModel transform(TrackedEntitySearchItem searchItem, @Nullable Pr
} else {
searchTei.setEnrolledOrgUnit(orgUnitName(searchTei.getTei().organisationUnit()));
}
searchTei.setProfilePicture(profilePicturePath(dbTei, selectedProgram));
searchTei.setProfilePicture(profilePictureProvider.invoke(dbTei, selectedProgram != null ? selectedProgram.uid() : null));
} else {
searchTei.setTei(teiFromItem);
searchTei.setEnrolledOrgUnit(orgUnitName(searchTei.getTei().organisationUnit()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ SearchRepository searchRepository(@NonNull D2 d2,
SearchTEIRepository searchTEIRepository,
ThemeManager themeManager,
MetadataIconProvider metadataIconProvider) {
ProfilePictureProvider profilePictureProvider = new ProfilePictureProvider(d2);
return new SearchRepositoryImpl(teiType,
initialProgram,
d2,
Expand All @@ -167,7 +168,8 @@ SearchRepository searchRepository(@NonNull D2 d2,
networkUtils,
searchTEIRepository,
themeManager,
metadataIconProvider);
metadataIconProvider,
profilePictureProvider);
}

@Provides
Expand Down
Loading