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

Inactive versus ineligible structure colours #891

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -123,5 +125,9 @@ interface Presenter extends BaseContract.BasePresenter {
void findLastEvent(String featureId, String eventType);

void onFociBoundaryLongClicked();

void onMarkStructureActiveConfirmed();

void onStructureMarkedActive(Task task);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class BaseInteractor implements BaseContract.BaseInteractor {

protected RevealClientProcessor clientProcessor;

private TaskUtils taskUtils;
protected TaskUtils taskUtils;

private SQLiteDatabase database;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.smartregister.reveal.interactor;

import android.content.Context;

import com.mapbox.geojson.Feature;

import net.sqlcipher.Cursor;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
});

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,7 +122,7 @@ public void processClient(List<EventClient> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down Expand Up @@ -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";
Expand All @@ -244,6 +247,7 @@ interface EventType {

List<String> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions opensrp-reveal/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@
<string name="device_data_synced">Device data synced</string>
<string name="device_data_not_synced">Device data not synced</string>
<string name="manifest_version_parenthesis_placeholder">(%1$s)</string>
<string name="mark_location_active">Mark Location Active</string>
<string name="confirm_mark_location_active">Please confirm that this location should be marked active</string>

<string name="filled_forms">Filled Forms</string>
<string name="event_date">Date</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.smartregister.reveal.presenter;

import android.content.Context;

import androidx.appcompat.app.AlertDialog;

import com.mapbox.geojson.Feature;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down