diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt index 657a53312c..c92295d179 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt @@ -603,7 +603,7 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { ) .onSelection { selectedOrgUnits -> if (selectedOrgUnits.isNotEmpty()) { - presenter.onOrgUnitForNewEventSelected( + presenter.onNewEventSelected( orgUnitUid = selectedOrgUnits.first().uid(), programStageUid = programStageUid, ) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt index c910d79cbe..a5906c722e 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt @@ -367,7 +367,8 @@ class TEIDataPresenter( if (stage != null) { when (eventCreationType) { EventCreationType.ADDNEW -> programUid?.let { program -> - checkOrgUnitCount(program, stage.uid()) + val orgUnitUid = d2.enrollment(enrollmentUid)?.organisationUnit() + orgUnitUid?.let { onNewEventSelected(orgUnitUid, stage.uid()) } ?: checkOrgUnitCount(program, stage.uid()) } EventCreationType.SCHEDULE -> { @@ -425,14 +426,14 @@ class TEIDataPresenter( CoroutineScope(dispatcher.io()).launch { val orgUnits = teiDataRepository.programOrgListInCaptureScope(programUid) if (orgUnits.count() == 1) { - onOrgUnitForNewEventSelected(orgUnits.first().uid(), programStageUid) + onNewEventSelected(orgUnits.first().uid(), programStageUid) } else { view.displayOrgUnitSelectorForNewEvent(programUid, programStageUid) } } } - fun onOrgUnitForNewEventSelected(orgUnitUid: String, programStageUid: String) { + fun onNewEventSelected(orgUnitUid: String, programStageUid: String) { CoroutineScope(dispatcher.io()).launch { programUid?.let { createEventUseCase( diff --git a/app/src/test/java/org/dhis2/usescases/teiDashboard/dashboardfragments/data/TeiDataPresenterTest.kt b/app/src/test/java/org/dhis2/usescases/teiDashboard/dashboardfragments/data/TeiDataPresenterTest.kt index 81f92f4d9f..a561ad4581 100644 --- a/app/src/test/java/org/dhis2/usescases/teiDashboard/dashboardfragments/data/TeiDataPresenterTest.kt +++ b/app/src/test/java/org/dhis2/usescases/teiDashboard/dashboardfragments/data/TeiDataPresenterTest.kt @@ -289,7 +289,7 @@ class TeiDataPresenterTest { ), ) doReturn (Result.success(eventUid)) - teiDataPresenter.onOrgUnitForNewEventSelected( + teiDataPresenter.onNewEventSelected( orgUnitUid, programStageUid, ) @@ -319,7 +319,7 @@ class TeiDataPresenterTest { whenever(d2ErrorUtils.getErrorMessage(d2Error)) doReturn (errorMessage) - teiDataPresenter.onOrgUnitForNewEventSelected( + teiDataPresenter.onNewEventSelected( orgUnitUid, programStageUid, )