Skip to content

Commit

Permalink
[ANDROAPP-5787] Use search scope in a referral
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan committed Apr 25, 2024
1 parent e5192ff commit 2a05d35
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package org.dhis2.usescases.eventsWithoutRegistration.eventDetails.data
import io.reactivex.Observable
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import org.dhis2.commons.data.EventCreationType
import org.dhis2.commons.date.DateUtils
import org.dhis2.data.dhislogic.AUTH_ALL
import org.dhis2.data.dhislogic.AUTH_UNCOMPLETE_EVENT
import org.dhis2.form.model.FieldUiModel
import org.dhis2.form.ui.FieldViewModelFactory
import org.dhis2.utils.DateUtils
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope
import org.hisp.dhis.android.core.category.CategoryCombo
Expand Down Expand Up @@ -36,6 +37,7 @@ class EventDetailsRepository(
private val eventUid: String?,
private val programStageUid: String?,
private val fieldFactory: FieldViewModelFactory?,
private val eventCreationType: EventCreationType,
private val onError: (Throwable) -> String?,
) {

Expand Down Expand Up @@ -148,10 +150,15 @@ class EventDetailsRepository(
return d2.organisationUnitModule().organisationUnits()
.byProgramUids(listOf(programUid))
.byParentUid().eq(parentUid)
.byOrganisationUnitScope(OrganisationUnit.Scope.SCOPE_DATA_CAPTURE)
.byOrganisationUnitScope(getOrgUnitScope())
.blockingGet()
}

private fun getOrgUnitScope() = when (eventCreationType) {
EventCreationType.REFERAL -> OrganisationUnit.Scope.SCOPE_TEI_SEARCH
else -> OrganisationUnit.Scope.SCOPE_DATA_CAPTURE
}

fun getOrganisationUnit(orgUnitUid: String): OrganisationUnit? {
return d2.organisationUnitModule().organisationUnits()
.byUid()
Expand All @@ -161,7 +168,7 @@ class EventDetailsRepository(

fun getOrganisationUnits(): List<OrganisationUnit> {
return d2.organisationUnitModule().organisationUnits()
.byOrganisationUnitScope(OrganisationUnit.Scope.SCOPE_DATA_CAPTURE)
.byOrganisationUnitScope(getOrgUnitScope())
.byProgramUids(listOf(programUid))
.blockingGet()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class EventDetailsModule(
programUid = programUid,
eventUid = eventUid,
programStageUid = programStageUid,
eventCreationType = eventCreationType,
fieldFactory = FieldViewModelFactoryImpl(
UiStyleProviderImpl(
FormUiModelColorFactoryImpl(context, colorUtils),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class SchedulingViewModel(
eventUid = null,
programStageUid = programStage.value.uid(),
fieldFactory = null,
eventCreationType = EventCreationType.SCHEDULE,
onError = resourceManager::parseD2Error,
)
configureEventReportDate = ConfigureEventReportDate(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dhis2.usescases.eventsWithoutRegistration.eventDetails.data

import org.dhis2.commons.data.EventCreationType
import org.dhis2.form.ui.FieldViewModelFactory
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope.OrderByDirection.DESC
Expand Down Expand Up @@ -35,6 +36,7 @@ class EventDetailsRepositoryTest {
EVENT_UID,
PROGRAM_STAGE_UID,
fieldViewModelFactory,
EventCreationType.ADDNEW,
) { d2Error -> "" }

whenever(
Expand Down

0 comments on commit 2a05d35

Please sign in to comment.