Skip to content

Commit

Permalink
feat: [ANDROAPP-6426] quick actions on dashboard (#3963)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmateos authored Feb 11, 2025
1 parent 834b46a commit c21fe8a
Show file tree
Hide file tree
Showing 22 changed files with 422 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import dhis2.org.analytics.charts.Charts
import io.reactivex.Observable
import org.dhis2.R
import org.dhis2.android.rtsm.utils.NetworkUtils
import org.dhis2.commons.data.ProgramConfigurationRepository
import org.dhis2.commons.featureconfig.data.FeatureConfigRepository
import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.prefs.PreferenceProvider
import org.dhis2.commons.resources.MetadataIconProvider
Expand Down Expand Up @@ -50,6 +52,8 @@ class TeiDashboardMobileActivityTest {
private val charts: Charts = mock()
private val teiAttributesProvider: TeiAttributesProvider = mock()
private val preferences: PreferenceProvider = mock()
private val programConfigurationRepository: ProgramConfigurationRepository = mock()
private val featureConfigRepository: FeatureConfigRepository = mock()

private val metadataIconProvider: MetadataIconProvider = mock {
on { invoke(any()) }doReturn MetadataIconData.defaultIcon()
Expand Down Expand Up @@ -120,10 +124,10 @@ class TeiDashboardMobileActivityTest {
ENROLLMENT_UID,
teiAttributesProvider,
preferences,
metadataIconProvider
metadataIconProvider,
programConfigurationRepository,
featureConfigRepository,
)


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ import org.dhis2.usescases.event.entity.TEIProgramStagesUIModel
import org.dhis2.usescases.flow.teiFlow.entity.DateRegistrationUIModel
import org.dhis2.usescases.programStageSelection.ProgramStageSelectionViewHolder
import org.dhis2.usescases.teiDashboard.dashboardfragments.teidata.teievents.EventViewHolder
import org.dhis2.usescases.teiDashboard.ui.STATE_INFO_BAR_TEST_TAG
import org.dhis2.usescases.teiDashboard.ui.INFO_BAR_TEST_TAG
import org.dhis2.usescases.teiDashboard.ui.TEST_ADD_EVENT_BUTTON
import org.dhis2.usescases.teiDashboard.ui.TEST_ADD_EVENT_BUTTON_IN_TIMELINE
import org.dhis2.usescases.teiDashboard.ui.model.InfoBarType
import org.dhis2.usescases.teidashboard.entity.EnrollmentUIModel
import org.dhis2.usescases.teidashboard.entity.UpperEnrollmentUIModel
import org.hamcrest.CoreMatchers.allOf
Expand Down Expand Up @@ -94,7 +95,7 @@ class TeiDashboardRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {
}

fun checkCancelledStateInfoBarIsDisplay() {
composeTestRule.onNodeWithTag(STATE_INFO_BAR_TEST_TAG).assertIsDisplayed()
composeTestRule.onNodeWithTag(INFO_BAR_TEST_TAG + InfoBarType.ENROLLMENT_STATUS.name).assertIsDisplayed()
composeTestRule.onNodeWithText("Enrollment cancelled").assertIsDisplayed()
}

Expand Down Expand Up @@ -170,7 +171,7 @@ class TeiDashboardRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {
}

fun checkCompleteStateInfoBarIsDisplay() {
composeTestRule.onNodeWithTag(STATE_INFO_BAR_TEST_TAG).assertIsDisplayed()
composeTestRule.onNodeWithTag(INFO_BAR_TEST_TAG + InfoBarType.ENROLLMENT_STATUS.name).assertIsDisplayed()
composeTestRule.onNodeWithText("Enrollment completed").assertIsDisplayed()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data class DashboardEnrollmentModel(
override val teiHeader: String?,
override val avatarPath: String?,
override val ownerOrgUnit: OrganisationUnit?,
val quickActions: List<String>,
) : DashboardModel(
trackedEntityInstance,
trackedEntityAttributeValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.functions.Function
import org.dhis2.bindings.profilePicturePath
import org.dhis2.commons.data.ProgramConfigurationRepository
import org.dhis2.commons.data.tuples.Pair
import org.dhis2.commons.featureconfig.data.FeatureConfigRepository
import org.dhis2.commons.prefs.Preference
import org.dhis2.commons.prefs.PreferenceProvider
import org.dhis2.commons.resources.MetadataIconProvider
Expand Down Expand Up @@ -47,6 +49,8 @@ class DashboardRepositoryImpl(
private val teiAttributesProvider: TeiAttributesProvider,
private val preferenceProvider: PreferenceProvider,
private val metadataIconProvider: MetadataIconProvider,
private val programConfigurationRepository: ProgramConfigurationRepository,
private val featureConfigRepository: FeatureConfigRepository,
) : DashboardRepository {
override fun getTeiHeader(): String? {
return d2.trackedEntityModule().trackedEntitySearch()
Expand Down Expand Up @@ -413,10 +417,19 @@ class DashboardRepositoryImpl(
getTeiHeader(),
getTeiProfilePath(),
getOwnerOrgUnit(teiUid),
getQuickActions(programUid),
)
}
}

private fun getQuickActions(programUid: String): List<String> {
return programConfigurationRepository
.getConfigurationByProgram(programUid)
?.quickActions()
?.map { it.actionId() }
?: emptyList()
}

override fun getTeiActivePrograms(
teiUid: String,
showOnlyActive: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ class DashboardViewModel(
).blockingFirst()

if (result == StatusChangeResultCode.CHANGED) {
_showStatusBar.value = status
_syncNeeded.value = true
_state.value = State.TO_UPDATE
fetchDashboardModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package org.dhis2.usescases.teiDashboard
import dagger.Module
import dagger.Provides
import dhis2.org.analytics.charts.Charts
import org.dhis2.commons.data.ProgramConfigurationRepository
import org.dhis2.commons.di.dagger.PerActivity
import org.dhis2.commons.featureconfig.data.FeatureConfigRepository
import org.dhis2.commons.matomo.MatomoAnalyticsController
import org.dhis2.commons.prefs.PreferenceProvider
import org.dhis2.commons.resources.EventResourcesProvider
Expand Down Expand Up @@ -89,6 +91,8 @@ class TeiDashboardModule(
preferenceProvider: PreferenceProvider,
teiAttributesProvider: TeiAttributesProvider,
metadataIconProvider: MetadataIconProvider,
programConfigurationRepository: ProgramConfigurationRepository,
featureConfigRepository: FeatureConfigRepository,
): DashboardRepository {
return DashboardRepositoryImpl(
d2,
Expand All @@ -99,6 +103,8 @@ class TeiDashboardModule(
teiAttributesProvider,
preferenceProvider,
metadataIconProvider,
programConfigurationRepository,
featureConfigRepository,
)
}

Expand Down Expand Up @@ -145,4 +151,11 @@ class TeiDashboardModule(
resourcesManager,
)
}

@Provides
fun provideProgramConfigurationRepository(
d2: D2,
): ProgramConfigurationRepository {
return ProgramConfigurationRepository(d2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ import org.dhis2.usescases.teiDashboard.dialogs.scheduling.SchedulingDialog.Comp
import org.dhis2.usescases.teiDashboard.dialogs.scheduling.SchedulingDialog.Companion.SCHEDULING_EVENT_SKIPPED
import org.dhis2.usescases.teiDashboard.ui.TeiDetailDashboard
import org.dhis2.usescases.teiDashboard.ui.mapper.InfoBarMapper
import org.dhis2.usescases.teiDashboard.ui.mapper.QuickActionsMapper
import org.dhis2.usescases.teiDashboard.ui.mapper.TeiDashboardCardMapper
import org.dhis2.usescases.teiDashboard.ui.model.InfoBarType
import org.dhis2.usescases.teiDashboard.ui.model.QuickActionType
import org.dhis2.usescases.teiDashboard.ui.model.TimelineEventsHeaderModel
import org.dhis2.utils.extension.setIcon
import org.dhis2.utils.granularsync.SyncStatusDialog
Expand All @@ -91,6 +93,9 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
@Inject
lateinit var infoBarMapper: InfoBarMapper

@Inject
lateinit var quickActionsMapper: QuickActionsMapper

@Inject
lateinit var contractHandler: TeiDataContractHandler

Expand Down Expand Up @@ -289,9 +294,7 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
}

TeiDetailDashboard(
syncData = syncInfoBar,
followUpData = followUpInfoBar,
enrollmentData = enrollmentInfoBar,
infoBarModels = listOfNotNull(syncInfoBar, followUpInfoBar, enrollmentInfoBar),
card = card,
isGrouped = groupingEvents ?: true,
timelineEventHeaderModel = TimelineEventsHeaderModel(
Expand All @@ -303,10 +306,35 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
timelineOnEventCreationOptionSelected = {
presenter.onAddNewEventOptionSelected(it, null)
},
quickActions = (dashboardModel as? DashboardEnrollmentModel)?.let {
quickActionsMapper.map(it) { quickActionType ->
onQuickAction(quickActionType)
}
} ?: emptyList(),
)
}
}
}
private fun onQuickAction(quickActionType: QuickActionType) {
val teiDashboardActivity = activity as TeiDashboardMobileActivity
when (quickActionType) {
QuickActionType.MARK_FOLLOW_UP -> dashboardViewModel.onFollowUp()
QuickActionType.TRANSFER -> programUid?.let {
teiDashboardActivity.showOrgUnitSelector(it)
}
QuickActionType.COMPLETE_ENROLLMENT -> dashboardViewModel.updateEnrollmentStatus(
EnrollmentStatus.COMPLETED,
)
QuickActionType.CANCEL_ENROLLMENT -> dashboardViewModel.updateEnrollmentStatus(
EnrollmentStatus.CANCELLED,
)
QuickActionType.REOPEN_ENROLLMENT -> dashboardViewModel.updateEnrollmentStatus(
EnrollmentStatus.ACTIVE,
)
QuickActionType.MORE_ENROLLMENTS ->
teiDashboardActivity.goToEnrollmentList()
}
}

private fun showLegacyCard(dashboardModel: DashboardTEIModel?) {
binding.noEnrollmentSelected = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.dhis2.usescases.teiDashboard.DashboardRepository
import org.dhis2.usescases.teiDashboard.dashboardfragments.teidata.teievents.ui.mapper.TEIEventCardMapper
import org.dhis2.usescases.teiDashboard.domain.GetNewEventCreationTypeOptions
import org.dhis2.usescases.teiDashboard.ui.mapper.InfoBarMapper
import org.dhis2.usescases.teiDashboard.ui.mapper.QuickActionsMapper
import org.dhis2.usescases.teiDashboard.ui.mapper.TeiDashboardCardMapper
import org.dhis2.utils.analytics.AnalyticsHelper
import org.hisp.dhis.android.core.D2
Expand Down Expand Up @@ -132,13 +133,6 @@ class TEIDataModule(
return GetNewEventCreationTypeOptions(programConfigurationRepository)
}

@Provides
fun provideProgramConfigurationRepository(
d2: D2,
): ProgramConfigurationRepository {
return ProgramConfigurationRepository(d2)
}

@Provides
fun provideEventCreationsOptionsMapper(
resourceManager: ResourceManager,
Expand All @@ -160,6 +154,13 @@ class TEIDataModule(
return InfoBarMapper(resourceManager)
}

@Provides
fun provideQuickActionMapper(
resourceManager: ResourceManager,
): QuickActionsMapper {
return QuickActionsMapper(programUid, resourceManager)
}

@Provides
fun provideContractHandler() = TeiDataContractHandler(registry)

Expand Down
Loading

0 comments on commit c21fe8a

Please sign in to comment.