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-6185] dashboard event list not updated #3658

Merged
merged 2 commits into from
May 31, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.dhis2.usescases.teiDashboard
import org.dhis2.ui.MetadataIconData
import org.hisp.dhis.android.core.enrollment.Enrollment
import org.hisp.dhis.android.core.enrollment.EnrollmentStatus
import org.hisp.dhis.android.core.event.Event
import org.hisp.dhis.android.core.organisationunit.OrganisationUnit
import org.hisp.dhis.android.core.program.Program
import org.hisp.dhis.android.core.program.ProgramStage
Expand Down Expand Up @@ -31,7 +30,6 @@ sealed class DashboardModel(
data class DashboardEnrollmentModel(
val currentEnrollment: Enrollment,
val programStages: List<ProgramStage>,
val eventModels: List<Event>,
override val trackedEntityInstance: TrackedEntityInstance,
val trackedEntityAttributes: List<Pair<TrackedEntityAttribute, TrackedEntityAttributeValue>>,
override val trackedEntityAttributeValues: List<TrackedEntityAttributeValue>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ interface DashboardRepository {

fun getEnrollment(): Observable<Enrollment>

fun getTEIEnrollmentEvents(programUid: String?, teiUid: String): Observable<List<Event>>

fun getEnrollmentEventsWithDisplay(
programUid: String?,
teiUid: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.dhis2.commons.prefs.Preference
import org.dhis2.commons.prefs.PreferenceProvider
import org.dhis2.commons.resources.MetadataIconProvider
import org.dhis2.ui.MetadataIconData
import org.dhis2.utils.DateUtils
import org.dhis2.utils.ValueUtils
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.arch.helpers.UidsHelper.getUidsList
Expand Down Expand Up @@ -68,30 +67,6 @@ class DashboardRepositoryImpl(
.toObservable()
}

override fun getTEIEnrollmentEvents(
programUid: String?,
teiUid: String,
): Observable<List<Event>> {
return d2.eventModule().events().byEnrollmentUid().eq(enrollmentUid)
.byDeleted().isFalse
.orderByTimeline(RepositoryScope.OrderByDirection.ASC)
.get().toFlowable().flatMapIterable { events: List<Event>? -> events }.distinct()
.map { event: Event ->
var event = event
if (java.lang.Boolean.FALSE
== d2.programModule().programs().uid(programUid).blockingGet()!!
.ignoreOverdueEvents()
) if (event.status() == EventStatus.SCHEDULE &&
event.dueDate()!!
.before(DateUtils.getInstance().today)
) {
event = updateState(event, EventStatus.OVERDUE)
}
event
}.toList()
.toObservable()
}

override fun getEnrollmentEventsWithDisplay(
programUid: String?,
teiUid: String,
Expand Down Expand Up @@ -388,7 +363,6 @@ class DashboardRepositoryImpl(
DashboardEnrollmentModel(
getEnrollment().blockingFirst(),
getProgramStages(programUid).blockingFirst(),
getTEIEnrollmentEvents(programUid, teiUid).blockingFirst(),
getTrackedEntityInstance(teiUid).blockingFirst(),
getAttributesMap(programUid, teiUid).blockingFirst(),
getTEIAttributeValues(programUid, teiUid).blockingFirst(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import io.reactivex.Completable
import io.reactivex.Flowable
import io.reactivex.Observable
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.processors.BehaviorProcessor
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -197,32 +196,6 @@ class TEIDataPresenter(
dashboardRepository.saveCatOption(eventUid, catOptionComboUid)
}

fun areEventsCompleted() {
compositeDisposable.add(
dashboardRepository.getEnrollmentEventsWithDisplay(programUid, teiUid)
.flatMap { events ->
if (events.isEmpty()) {
dashboardRepository.getTEIEnrollmentEvents(
programUid,
teiUid,
)
} else {
Observable.just(events)
}
}
.map { events ->
Observable.fromIterable(events)
.all { event -> event.status() == EventStatus.COMPLETED }
}
.subscribeOn(schedulerProvider.io())
.observeOn(schedulerProvider.ui())
.subscribe(
view.areEventsCompleted(),
Timber.Forest::d,
),
)
}

fun displayGenerateEvent(eventUid: String?) {
compositeDisposable.add(
dashboardRepository.displayGenerateEvent(eventUid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.dhis2.utils.analytics.CLICK
import org.dhis2.utils.analytics.DELETE_TEI
import org.hisp.dhis.android.core.enrollment.Enrollment
import org.hisp.dhis.android.core.enrollment.EnrollmentStatus
import org.hisp.dhis.android.core.event.Event
import org.hisp.dhis.android.core.organisationunit.OrganisationUnit
import org.hisp.dhis.android.core.program.Program
import org.hisp.dhis.android.core.program.ProgramStage
Expand Down Expand Up @@ -70,7 +69,6 @@ class TeiDashboardPresenterTest {
val trackedEntityInstance = TrackedEntityInstance.builder().uid(teiUid).build()
val enrollment = Enrollment.builder().uid("enrollmentUid").build()
val programStages = listOf(ProgramStage.builder().uid("programStageUid").build())
val events = listOf(Event.builder().uid("eventUid").build())
val trackedEntityAttributes = listOf(
Pair(
TrackedEntityAttribute.builder().uid("teiAttr").build(),
Expand All @@ -95,9 +93,6 @@ class TeiDashboardPresenterTest {
whenever(
repository.getProgramStages(programUid),
) doReturn Observable.just(programStages)
whenever(
repository.getTEIEnrollmentEvents(programUid, teiUid),
) doReturn Observable.just(events)
whenever(
repository.getAttributesMap(programUid, teiUid),
) doReturn Observable.just(trackedEntityAttributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.dhis2.usescases.teiDashboard.ui.model.InfoBarType
import org.hisp.dhis.android.core.common.State
import org.hisp.dhis.android.core.enrollment.Enrollment
import org.hisp.dhis.android.core.enrollment.EnrollmentStatus
import org.hisp.dhis.android.core.event.Event
import org.hisp.dhis.android.core.organisationunit.OrganisationUnit
import org.hisp.dhis.android.core.program.Program
import org.hisp.dhis.android.core.program.ProgramStage
Expand Down Expand Up @@ -108,7 +107,6 @@ class InfoBarMapperTest {
val model = DashboardEnrollmentModel(
setEnrollment(state, status, followup),
emptyList<ProgramStage>(),
emptyList<Event>(),
setTei(state),
attributeValues,
emptyList<TrackedEntityAttributeValue>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.dhis2.usescases.teiDashboard.DashboardEnrollmentModel
import org.hisp.dhis.android.core.common.State
import org.hisp.dhis.android.core.enrollment.Enrollment
import org.hisp.dhis.android.core.enrollment.EnrollmentStatus
import org.hisp.dhis.android.core.event.Event
import org.hisp.dhis.android.core.organisationunit.OrganisationUnit
import org.hisp.dhis.android.core.program.Program
import org.hisp.dhis.android.core.program.ProgramStage
Expand Down Expand Up @@ -61,7 +60,6 @@ class TEIDetailMapperTest {
val model = DashboardEnrollmentModel(
setEnrollment(),
emptyList<ProgramStage>(),
emptyList<Event>(),
setTei(),
attributeValues,
emptyList<TrackedEntityAttributeValue>(),
Expand Down
Loading