diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/contract/ListTaskContract.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/contract/ListTaskContract.java index 0e4475fd96..ad66b84a7b 100644 --- a/opensrp-reveal/src/main/java/org/smartregister/reveal/contract/ListTaskContract.java +++ b/opensrp-reveal/src/main/java/org/smartregister/reveal/contract/ListTaskContract.java @@ -77,6 +77,8 @@ interface ListTaskView extends UserLocationView, BaseDrawerContract.DrawerActivi void setSearchPhrase(String searchPhrase); void toggleProgressBarView(boolean syncing); + + void displayMarkStructureActiveDialog(); } interface Presenter extends BaseContract.BasePresenter { @@ -123,5 +125,9 @@ interface Presenter extends BaseContract.BasePresenter { void findLastEvent(String featureId, String eventType); void onFociBoundaryLongClicked(); + + void onMarkStructureActiveConfirmed(); + + void onStructureMarkedActive(Task task); } } diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/interactor/BaseInteractor.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/interactor/BaseInteractor.java index 27a5eebf33..60ddb6ca12 100644 --- a/opensrp-reveal/src/main/java/org/smartregister/reveal/interactor/BaseInteractor.java +++ b/opensrp-reveal/src/main/java/org/smartregister/reveal/interactor/BaseInteractor.java @@ -132,7 +132,7 @@ public class BaseInteractor implements BaseContract.BaseInteractor { protected RevealClientProcessor clientProcessor; - private TaskUtils taskUtils; + protected TaskUtils taskUtils; private SQLiteDatabase database; diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/interactor/ListTaskInteractor.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/interactor/ListTaskInteractor.java index 35c1456e34..b217a09d19 100644 --- a/opensrp-reveal/src/main/java/org/smartregister/reveal/interactor/ListTaskInteractor.java +++ b/opensrp-reveal/src/main/java/org/smartregister/reveal/interactor/ListTaskInteractor.java @@ -1,5 +1,7 @@ package org.smartregister.reveal.interactor; +import android.content.Context; + import com.mapbox.geojson.Feature; import net.sqlcipher.Cursor; @@ -38,6 +40,7 @@ import org.smartregister.reveal.util.GeoJsonUtils; import org.smartregister.reveal.util.IndicatorUtils; import org.smartregister.reveal.util.InteractorUtils; +import org.smartregister.reveal.util.RevealJsonFormUtils; import org.smartregister.reveal.util.Utils; import java.util.HashMap; @@ -47,6 +50,7 @@ import timber.log.Timber; +import static org.smartregister.domain.LocationProperty.PropertyStatus.ACTIVE; import static org.smartregister.domain.LocationProperty.PropertyStatus.INACTIVE; import static org.smartregister.family.util.Constants.KEY.FAMILY_HEAD_NAME; import static org.smartregister.family.util.DBConstants.KEY.DATE_REMOVED; @@ -79,6 +83,7 @@ import static org.smartregister.reveal.util.Constants.DatabaseKeys.STRUCTURE_NAME; import static org.smartregister.reveal.util.Constants.DatabaseKeys.TASK_TABLE; import static org.smartregister.reveal.util.Constants.DatabaseKeys.TRUE_STRUCTURE; +import static org.smartregister.reveal.util.Constants.EventType.ACTIVATE_LOCATION_EVENT; import static org.smartregister.reveal.util.Constants.Intervention.CASE_CONFIRMATION; import static org.smartregister.reveal.util.Constants.Intervention.IRS; import static org.smartregister.reveal.util.Constants.Intervention.IRS_VERIFICATION; @@ -88,6 +93,7 @@ import static org.smartregister.reveal.util.Constants.Intervention.REGISTER_FAMILY; import static org.smartregister.reveal.util.Constants.Properties.TASK_CODE; import static org.smartregister.reveal.util.Constants.Properties.TASK_IDENTIFIER; +import static org.smartregister.reveal.util.Constants.Properties.TYPE; import static org.smartregister.reveal.util.Constants.Tables.IRS_VERIFICATION_TABLE; import static org.smartregister.reveal.util.Constants.Tables.LARVAL_DIPPINGS_TABLE; import static org.smartregister.reveal.util.Constants.Tables.MOSQUITO_COLLECTIONS_TABLE; @@ -506,4 +512,44 @@ public void handleLasteventFound(org.smartregister.domain.Event event) { getPresenter().onEventFound(event); } + + public void markStructureAsActive(Feature feature) { + + appExecutors.diskIO().execute(() -> { + try { + Location structure = structureRepository.getLocationById(feature.id()); + structure.getProperties().setStatus(ACTIVE); + structureRepository.addOrUpdate(structure); + revealApplication.setSynced(false); + + Context applicationContext = revealApplication.getApplicationContext(); + String structureType = getPropertyValue(feature, TYPE); + Task task = null; + if (Constants.StructureType.MOSQUITO_COLLECTION_POINT.equals(structureType)) { + task = taskUtils.generateTask(applicationContext, structure.getId(), structure.getId(), + Constants.BusinessStatus.NOT_VISITED, MOSQUITO_COLLECTION, R.string.mosquito_collection_task_description); + } else if (Constants.StructureType.LARVAL_BREEDING_SITE.equals(structureType)) { + task = taskUtils.generateTask(applicationContext, structure.getId(), structure.getId(), + Constants.BusinessStatus.NOT_VISITED, LARVAL_DIPPING, R.string.larval_dipping_task_description); + } else if (Constants.StructureType.POTENTIAL_AREA_OF_TRANSMISSION.equals(structureType)) { + task = taskUtils.generateTask(applicationContext, structure.getId(), structure.getId(), + Constants.BusinessStatus.NOT_VISITED, PAOT, R.string.poat_task_description); + } + + Event event = RevealJsonFormUtils.createTaskEvent(structure.getId(), Utils.getCurrentLocationId(), + null, ACTIVATE_LOCATION_EVENT, Constants.STRUCTURE); + + eventClientRepository.addEvent(feature.id(), new JSONObject(gson.toJson(event))); + + Task finalTask = task; + appExecutors.mainThread().execute(() -> { + ((ListTaskPresenter) presenterCallBack).onStructureMarkedActive(finalTask); + }); + } catch (Exception e) { + Timber.e(e); + } + }); + + } + } diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/presenter/ListTaskPresenter.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/presenter/ListTaskPresenter.java index 878276af1a..bee0664028 100644 --- a/opensrp-reveal/src/main/java/org/smartregister/reveal/presenter/ListTaskPresenter.java +++ b/opensrp-reveal/src/main/java/org/smartregister/reveal/presenter/ListTaskPresenter.java @@ -44,6 +44,7 @@ import org.smartregister.reveal.task.IndicatorsCalculatorTask; import org.smartregister.reveal.util.AlertDialogUtils; import org.smartregister.reveal.util.CardDetailsUtil; +import org.smartregister.reveal.util.Constants; import org.smartregister.reveal.util.Constants.CONFIGURATION; import org.smartregister.reveal.util.Constants.Filter; import org.smartregister.reveal.util.Constants.JsonForm; @@ -104,6 +105,7 @@ import static org.smartregister.reveal.util.Constants.Properties.TASK_CODE_LIST; import static org.smartregister.reveal.util.Constants.Properties.TASK_IDENTIFIER; import static org.smartregister.reveal.util.Constants.Properties.TASK_STATUS; +import static org.smartregister.reveal.util.Constants.Properties.TYPE; import static org.smartregister.reveal.util.Constants.REGISTER_STRUCTURE_EVENT; import static org.smartregister.reveal.util.Constants.SPRAY_EVENT; import static org.smartregister.reveal.util.Utils.formatDate; @@ -288,6 +290,7 @@ private void onFeatureSelected(Feature feature, boolean isLongclick) { listTaskView.closeAllCardViews(); listTaskView.displaySelectedFeature(feature, clickedPoint); + if (isLongclick && BuildConfig.BUILD_COUNTRY != Country.ZAMBIA) { onFeatureSelectedByLongClick(feature); } else { @@ -297,8 +300,13 @@ private void onFeatureSelected(Feature feature, boolean isLongclick) { private void onFeatureSelectedByNormalClick(Feature feature) { if (!feature.hasProperty(TASK_IDENTIFIER)) { - listTaskView.displayNotification(listTaskView.getContext().getString(R.string.task_not_found, prefsUtil.getCurrentOperationalArea())); - return; + String structureType = getPropertyValue(feature, TYPE); + if (Constants.StructureType.RESIDENTIAL.equals(structureType)) { + listTaskView.displayNotification(listTaskView.getContext().getString(R.string.task_not_found, prefsUtil.getCurrentOperationalArea())); + } else { + listTaskView.displayMarkStructureActiveDialog(); + } + return; } String businessStatus = getPropertyValue(feature, FEATURE_SELECT_TASK_BUSINESS_STATUS); @@ -392,6 +400,27 @@ public void onFociBoundaryLongClicked() { listTaskView.getActivity().startActivity(intent); } + @Override + public void onMarkStructureActiveConfirmed() { + listTaskInteractor.markStructureAsActive(selectedFeature); + } + + @Override + public void onStructureMarkedActive(Task task) { + for (Feature feature : getFeatureCollection().features()) { + if (selectedFeature.id().equals(feature.id()) && task != null) { + feature.addStringProperty(TASK_BUSINESS_STATUS, task.getBusinessStatus()); + feature.addStringProperty(FEATURE_SELECT_TASK_BUSINESS_STATUS, task.getBusinessStatus()); + feature.addStringProperty(TASK_IDENTIFIER, task.getIdentifier()); + feature.addStringProperty(TASK_STATUS, task.getStatus().name()); + feature.addStringProperty(TASK_CODE, task.getCode()); + break; + } + } + + listTaskView.setGeoJsonSource(getFeatureCollection(), operationalArea, false); + } + @Override public void onInterventionFormDetailsFetched(CardDetails cardDetails) { this.cardDetails = cardDetails; diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/sync/RevealClientProcessor.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/sync/RevealClientProcessor.java index 613e5bccfa..572bd1168e 100644 --- a/opensrp-reveal/src/main/java/org/smartregister/reveal/sync/RevealClientProcessor.java +++ b/opensrp-reveal/src/main/java/org/smartregister/reveal/sync/RevealClientProcessor.java @@ -39,6 +39,7 @@ import static org.smartregister.reveal.util.Constants.BEDNET_DISTRIBUTION_EVENT; import static org.smartregister.reveal.util.Constants.BEHAVIOUR_CHANGE_COMMUNICATION; import static org.smartregister.reveal.util.Constants.CONFIGURATION.LOCAL_SYNC_DONE; +import static org.smartregister.reveal.util.Constants.EventType.ACTIVATE_LOCATION_EVENT; import static org.smartregister.reveal.util.Constants.EventType.IRS_VERIFICATION; import static org.smartregister.reveal.util.Constants.EventType.PAOT_EVENT; import static org.smartregister.reveal.util.Constants.EventType.SUMMARY_EVENT_TYPES; @@ -121,7 +122,7 @@ public void processClient(List eventClients, boolean localEvents) { processUpdateFamilyRegistrationEvent(event, eventClient.getClient(), clientClassification, localEvents); } else if (eventType.equals(PAOT_EVENT)) { operationalAreaId = processEvent(event, clientClassification, localEvents, JsonForm.PAOT_STATUS); - } else if (eventType.equals(TASK_RESET_EVENT)) { + } else if (eventType.equals(TASK_RESET_EVENT) || eventType.equals(ACTIVATE_LOCATION_EVENT)) { continue; } else if (SUMMARY_EVENT_TYPES.contains(event.getEventType())) { processSummaryFormEvent(event, clientClassification); diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/util/Constants.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/util/Constants.java index 06f5a146e3..dfdb30d6a7 100644 --- a/opensrp-reveal/src/main/java/org/smartregister/reveal/util/Constants.java +++ b/opensrp-reveal/src/main/java/org/smartregister/reveal/util/Constants.java @@ -151,6 +151,7 @@ interface Properties { String TASK_CODE_LIST = "task_code_list"; String FAMILY_MEMBER_NAMES = "family_member_names"; String PLAN_IDENTIFIER = "planIdentifier"; + String TYPE = "type"; String LOCATION_STATUS = "status"; } @@ -228,6 +229,8 @@ interface EventType { String IRS_VERIFICATION = "irs_verification"; + String ACTIVATE_LOCATION_EVENT = "activate_location"; + String DAILY_SUMMARY_EVENT = "daily_summary"; String IRS_FIELD_OFFICER_EVENT = "irs_field_officer"; @@ -244,6 +247,7 @@ interface EventType { List SUMMARY_EVENT_TYPES = Arrays.asList(DAILY_SUMMARY_EVENT, IRS_FIELD_OFFICER_EVENT, IRS_SA_DECISION_EVENT, MOBILIZATION_EVENT, TEAM_LEADER_DOS_EVENT, VERIFICATION_EVENT); + } interface Tables { diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/view/ListTasksActivity.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/view/ListTasksActivity.java index 99f2f51a05..a61f7aef8c 100644 --- a/opensrp-reveal/src/main/java/org/smartregister/reveal/view/ListTasksActivity.java +++ b/opensrp-reveal/src/main/java/org/smartregister/reveal/view/ListTasksActivity.java @@ -918,6 +918,19 @@ public void toggleProgressBarView(boolean syncing) { drawerView.toggleProgressBarView(syncing); } + @Override + public void displayMarkStructureActiveDialog() { + AlertDialogUtils.displayNotificationWithCallback(this, R.string.mark_location_active, + R.string.confirm_mark_location_active, R.string.confirm, R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (which == BUTTON_POSITIVE) + listTaskPresenter.onMarkStructureActiveConfirmed(); + dialog.dismiss(); + } + }); + } + @Override public void onSyncProgress(SyncProgress syncProgress) { int progress = syncProgress.getPercentageSynced(); diff --git a/opensrp-reveal/src/main/res/values/strings.xml b/opensrp-reveal/src/main/res/values/strings.xml index a1774fefc6..83b0bd32bf 100644 --- a/opensrp-reveal/src/main/res/values/strings.xml +++ b/opensrp-reveal/src/main/res/values/strings.xml @@ -386,6 +386,8 @@ Device data synced Device data not synced (%1$s) + Mark Location Active + Please confirm that this location should be marked active Filled Forms Date diff --git a/opensrp-reveal/src/test/java/org/smartregister/reveal/presenter/ListTaskPresenterPowerMockTest.java b/opensrp-reveal/src/test/java/org/smartregister/reveal/presenter/ListTaskPresenterPowerMockTest.java index f2cc97050e..2282c168a1 100644 --- a/opensrp-reveal/src/test/java/org/smartregister/reveal/presenter/ListTaskPresenterPowerMockTest.java +++ b/opensrp-reveal/src/test/java/org/smartregister/reveal/presenter/ListTaskPresenterPowerMockTest.java @@ -1,6 +1,7 @@ package org.smartregister.reveal.presenter; import android.content.Context; + import androidx.appcompat.app.AlertDialog; import com.mapbox.geojson.Feature; @@ -75,6 +76,7 @@ import static org.smartregister.reveal.util.Constants.Properties.TASK_BUSINESS_STATUS; import static org.smartregister.reveal.util.Constants.Properties.TASK_CODE; import static org.smartregister.reveal.util.Constants.Properties.TASK_IDENTIFIER; +import static org.smartregister.reveal.util.Constants.Properties.TYPE; /** * @author Vincent Karuri @@ -318,6 +320,7 @@ public void testOnInterventionFormDetailsFetchedDisabledPasswordValidationStatus @Test public void testOnFeatureSelectedShouldShowErrorDialogWhenTaskIdentifierIsNull() throws Exception { Feature feature = mock(Feature.class); + PowerMockito.when(Utils.getPropertyValue(feature, TYPE)).thenReturn(Constants.StructureType.RESIDENTIAL); PreferencesUtil preferencesUtil = mock(PreferencesUtil.class); Whitebox.setInternalState(listTaskPresenter, "prefsUtil", preferencesUtil);