- * Global executor pools for the whole application. - *
- * Grouping tasks like this avoids the effects of task starvation (e.g. disk reads don't wait behind
- * webservice requests).
- */
-public class AppExecutors {
-
- private static final int THREAD_COUNT = 3;
-
- private final Executor diskIO;
-
- private final Executor networkIO;
-
- private final Executor mainThread;
-
- public AppExecutors(Executor diskIO, Executor networkIO, Executor mainThread) {
- this.diskIO = diskIO;
- this.networkIO = networkIO;
- this.mainThread = mainThread;
- }
-
- public AppExecutors() {
- this(new DiskIOThreadExecutor(), Executors.newFixedThreadPool(THREAD_COUNT),
- new MainThreadExecutor());
- }
-
- public Executor diskIO() {
- return diskIO;
- }
-
- public Executor networkIO() {
- return networkIO;
- }
-
- public Executor mainThread() {
- return mainThread;
- }
-
- private static class MainThreadExecutor implements Executor {
- private Handler mainThreadHandler = new Handler(Looper.getMainLooper());
-
- @Override
- public void execute(@NonNull Runnable command) {
- mainThreadHandler.post(command);
- }
- }
-
- /**
- * Executor that runs a task on a new background thread.
- */
- private static class DiskIOThreadExecutor implements Executor {
-
- private final Executor mDiskIO;
-
- public DiskIOThreadExecutor() {
- mDiskIO = Executors.newSingleThreadExecutor();
- }
-
- @Override
- public void execute(@NonNull Runnable command) {
- mDiskIO.execute(command);
- }
- }
-}
diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/util/CardDetailsUtil.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/util/CardDetailsUtil.java
index 6f1cf6471a..324352c6b2 100644
--- a/opensrp-reveal/src/main/java/org/smartregister/reveal/util/CardDetailsUtil.java
+++ b/opensrp-reveal/src/main/java/org/smartregister/reveal/util/CardDetailsUtil.java
@@ -1,7 +1,6 @@
package org.smartregister.reveal.util;
import android.app.Activity;
-import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.view.View;
@@ -11,25 +10,13 @@
import org.smartregister.AllConstants;
import org.smartregister.reveal.R;
-import org.smartregister.reveal.application.RevealApplication;
-import org.smartregister.reveal.model.CardDetails;
import org.smartregister.reveal.model.FamilyCardDetails;
import org.smartregister.reveal.model.IRSVerificationCardDetails;
import org.smartregister.reveal.model.MosquitoHarvestCardDetails;
import org.smartregister.reveal.model.SprayCardDetails;
-import org.smartregister.reveal.util.Constants.BusinessStatus;
import timber.log.Timber;
-import static org.smartregister.reveal.util.Constants.BusinessStatus.COMPLETE;
-import static org.smartregister.reveal.util.Constants.BusinessStatus.INCOMPLETE;
-import static org.smartregister.reveal.util.Constants.BusinessStatus.IN_PROGRESS;
-import static org.smartregister.reveal.util.Constants.BusinessStatus.NOT_ELIGIBLE;
-import static org.smartregister.reveal.util.Constants.BusinessStatus.NOT_SPRAYABLE;
-import static org.smartregister.reveal.util.Constants.BusinessStatus.NOT_SPRAYED;
-import static org.smartregister.reveal.util.Constants.BusinessStatus.NOT_VISITED;
-import static org.smartregister.reveal.util.Constants.BusinessStatus.PARTIALLY_SPRAYED;
-import static org.smartregister.reveal.util.Constants.BusinessStatus.SPRAYED;
import static org.smartregister.reveal.util.Constants.Intervention.LARVAL_DIPPING;
import static org.smartregister.reveal.util.Constants.Intervention.MOSQUITO_COLLECTION;
import static org.smartregister.reveal.util.Constants.Intervention.PAOT;
@@ -37,43 +24,7 @@
/**
* Created by samuelgithengi on 3/22/19.
*/
-public class CardDetailsUtil {
-
- public static void formatCardDetails(CardDetails cardDetails) {
- if (cardDetails == null || cardDetails.getStatus() == null)
- return;
- // extract status color
- String status = cardDetails.getStatus();
- switch (status) {
- case BusinessStatus.NOT_SPRAYED:
- case BusinessStatus.INCOMPLETE:
- case BusinessStatus.IN_PROGRESS:
- case BusinessStatus.NONE_RECEIVED:
- cardDetails.setStatusColor(R.color.unsprayed);
- cardDetails.setStatusMessage(R.string.details_not_sprayed);
- break;
- case BusinessStatus.SPRAYED:
- case BusinessStatus.COMPLETE:
- case BusinessStatus.FULLY_RECEIVED:
- cardDetails.setStatusColor(R.color.sprayed);
- cardDetails.setStatusMessage(R.string.details_sprayed);
- cardDetails.setReason(null);
- break;
- case BusinessStatus.NOT_SPRAYABLE:
- case BusinessStatus.NOT_ELIGIBLE:
- cardDetails.setStatusColor(R.color.unsprayable);
- cardDetails.setStatusMessage(R.string.details_not_sprayable);
- cardDetails.setReason(null);
- break;
- case PARTIALLY_SPRAYED:
- cardDetails.setStatusColor(R.color.partially_sprayed);
- cardDetails.setStatusMessage(R.string.partially_sprayed);
- break;
- default:
- Timber.w("business status not defined :" + cardDetails.getStatus());
- break;
- }
- }
+public class CardDetailsUtil extends org.smartregister.tasking.util.CardDetailsUtil {
public void populateSprayCardTextViews(SprayCardDetails sprayCardDetails, Activity activity) {
try {
@@ -212,68 +163,5 @@ public void populateFamilyCard(FamilyCardDetails familyCardDetails, Activity act
}
}
- /**
- * Takes in a business status and returns the translated value according to locale set.
- *
- * @param businessStatus Business status of the task attached to a structure
- * @return status Translated status according to locale set
- */
- public static String getTranslatedBusinessStatus(String businessStatus) {
- Context context = RevealApplication.getInstance().getApplicationContext();
-
- if (businessStatus == null)
- return context.getString(R.string.not_eligible);
- switch (businessStatus) {
- case NOT_VISITED:
- return context.getString(R.string.not_visited);
- case NOT_SPRAYED:
- return context.getString(R.string.not_sprayed);
- case SPRAYED:
- return context.getString(R.string.sprayed);
- case NOT_SPRAYABLE:
- return context.getString(R.string.not_sprayable);
- case COMPLETE:
- return context.getString(R.string.complete);
- case INCOMPLETE:
- return context.getString(R.string.incomplete);
- case NOT_ELIGIBLE:
- return context.getString(R.string.not_eligible);
- case IN_PROGRESS:
- return context.getString(R.string.in_progress);
- case PARTIALLY_SPRAYED:
- return context.getString(R.string.partially_sprayed);
- default:
- return businessStatus;
- }
-
- }
-
- /**
- * Takes in a IRS intervention status and returns the translated value .
- *
- * @param status Status of the IRS Verification type
- * @return status Translated status
- */
- public static String getTranslatedIRSVerificationStatus(String status) {
- Context context = RevealApplication.getInstance().getApplicationContext();
-
- if (status == null)
- return context.getString(R.string.not_sprayed);
- switch (status) {
- case Constants.IRSVerificationStatus.SPRAYED:
- return context.getString(R.string.sprayed);
- case Constants.IRSVerificationStatus.NOT_SPRAYED:
- return context.getString(R.string.not_sprayed);
- case Constants.IRSVerificationStatus.NOT_FOUND_OR_VISITED:
- return context.getString(R.string.structure_not_found_or_visited_during_campaign);
- case Constants.IRSVerificationStatus.OTHER:
- return context.getString(R.string.other);
- default:
- return status;
- }
-
-
- }
-
}
diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/util/FamilyJsonFormUtils.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/util/FamilyJsonFormUtils.java
index 0cc6e3ed17..b48fd090c4 100644
--- a/opensrp-reveal/src/main/java/org/smartregister/reveal/util/FamilyJsonFormUtils.java
+++ b/opensrp-reveal/src/main/java/org/smartregister/reveal/util/FamilyJsonFormUtils.java
@@ -284,7 +284,7 @@ public static Event createFamilyEvent(String baseEntityId, String locationId, Ma
(Event) new Event().withBaseEntityId(baseEntityId).withEventDate(new Date()).withEventType(eventType)
.withLocationId(locationId).withEntityType(familyMetadata.familyMemberRegister.tableName)
.withFormSubmissionId(UUID.randomUUID().toString()).withDateCreated(new Date());
- org.smartregister.reveal.util.Utils.tagEventMetadata(updateMemberNameEvent, org.smartregister.reveal.util.Utils.getFormTag());
+ org.smartregister.tasking.util.Utils.tagEventMetadata(updateMemberNameEvent, org.smartregister.tasking.util.Utils.getFormTag());
updateMemberNameEvent.setDetails(details);
return updateMemberNameEvent;
}
diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/util/GeoJsonUtils.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/util/GeoJsonUtils.java
index e668f0699b..66de9b7600 100644
--- a/opensrp-reveal/src/main/java/org/smartregister/reveal/util/GeoJsonUtils.java
+++ b/opensrp-reveal/src/main/java/org/smartregister/reveal/util/GeoJsonUtils.java
@@ -5,6 +5,7 @@
import org.smartregister.domain.Location;
import org.smartregister.domain.Task;
import org.smartregister.reveal.model.StructureDetails;
+import org.smartregister.tasking.util.Utils;
import java.util.HashMap;
import java.util.List;
diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/util/IndicatorUtils.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/util/IndicatorUtils.java
index 69670c355a..176912386a 100644
--- a/opensrp-reveal/src/main/java/org/smartregister/reveal/util/IndicatorUtils.java
+++ b/opensrp-reveal/src/main/java/org/smartregister/reveal/util/IndicatorUtils.java
@@ -5,7 +5,7 @@
import org.smartregister.domain.Task;
import org.smartregister.reveal.R;
import org.smartregister.reveal.model.IndicatorDetails;
-import org.smartregister.reveal.model.TaskDetails;
+import org.smartregister.tasking.model.TaskDetails;
import java.util.ArrayList;
import java.util.HashMap;
diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/util/InteractorUtils.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/util/InteractorUtils.java
deleted file mode 100644
index 1d4161db41..0000000000
--- a/opensrp-reveal/src/main/java/org/smartregister/reveal/util/InteractorUtils.java
+++ /dev/null
@@ -1,222 +0,0 @@
-package org.smartregister.reveal.util;
-
-import android.database.Cursor;
-
-import net.sqlcipher.database.SQLiteDatabase;
-
-import org.joda.time.DateTime;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.smartregister.clientandeventmodel.Event;
-import org.smartregister.clientandeventmodel.Obs;
-import org.smartregister.commonregistry.CommonPersonObject;
-import org.smartregister.commonregistry.CommonRepository;
-import org.smartregister.domain.Client;
-import org.smartregister.domain.db.EventClient;
-import org.smartregister.repository.BaseRepository;
-import org.smartregister.repository.EventClientRepository;
-import org.smartregister.repository.TaskRepository;
-import org.smartregister.reveal.application.RevealApplication;
-import org.smartregister.reveal.model.BaseTaskDetails;
-import org.smartregister.reveal.sync.RevealClientProcessor;
-import org.smartregister.reveal.util.FamilyConstants.EventType;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import timber.log.Timber;
-
-import static org.smartregister.reveal.util.Constants.BEHAVIOUR_CHANGE_COMMUNICATION;
-import static org.smartregister.reveal.util.Constants.DatabaseKeys.BASE_ENTITY_ID;
-import static org.smartregister.reveal.util.Constants.DatabaseKeys.CASE_CONFIRMATION_FIELD;
-import static org.smartregister.reveal.util.Constants.DatabaseKeys.EVENT_TASK_TABLE;
-import static org.smartregister.reveal.util.Constants.DatabaseKeys.EVENT_TYPE_FIELD;
-import static org.smartregister.reveal.util.Constants.DatabaseKeys.FORM_SUBMISSION_ID;
-import static org.smartregister.reveal.util.Constants.DatabaseKeys.SPRAYED_STRUCTURES;
-import static org.smartregister.reveal.util.Constants.DatabaseKeys.TASK_ID;
-import static org.smartregister.reveal.util.Constants.Intervention.BCC;
-import static org.smartregister.reveal.util.Constants.Intervention.CASE_CONFIRMATION;
-import static org.smartregister.reveal.util.Constants.Intervention.IRS;
-import static org.smartregister.util.JsonFormUtils.gson;
-
-public class InteractorUtils {
-
- private TaskRepository taskRepository;
-
- private EventClientRepository eventClientRepository;
-
- private RevealClientProcessor clientProcessor;
-
- private RevealJsonFormUtils jsonFormUtils;
-
- public InteractorUtils(TaskRepository taskRepository, EventClientRepository eventClientRepository, RevealClientProcessor clientProcessor) {
- this.taskRepository = taskRepository;
- this.eventClientRepository = eventClientRepository;
- this.clientProcessor = clientProcessor;
- jsonFormUtils = new RevealJsonFormUtils();
- }
-
-
- public InteractorUtils() {
- }
-
- public CommonPersonObject fetchSprayDetails(String interventionType, String structureId, EventClientRepository eventClientRepository, CommonRepository commonRepository) {
- CommonPersonObject commonPersonObject = null;
- if (IRS.equals(interventionType)) {
- Cursor cursor = null;
- try {
- cursor = eventClientRepository.getWritableDatabase().rawQuery(
- String.format("select s.*, id as _id from %s s where %s = ?", SPRAYED_STRUCTURES, Constants.DatabaseKeys.BASE_ENTITY_ID), new String[]{structureId});
- if (cursor.moveToFirst()) {
- commonPersonObject = commonRepository.getCommonPersonObjectFromCursor(cursor);
- }
- } catch (Exception e) {
- Timber.e(e);
- } finally {
- if (cursor != null) {
- cursor.close();
- }
- }
- }
- return commonPersonObject;
- }
-
-
- public boolean archiveClient(String baseEntityId, boolean isFamily) {
- taskRepository.cancelTasksForEntity(baseEntityId);
- taskRepository.archiveTasksForEntity(baseEntityId);
- JSONObject eventsByBaseEntityId = eventClientRepository.getEventsByBaseEntityId(baseEntityId);
- JSONArray events = eventsByBaseEntityId.optJSONArray("events");
- JSONObject clientJsonObject = eventsByBaseEntityId.optJSONObject("client");
- DateTime now = new DateTime();
- if (events != null) {
- for (int i = 0; i < events.length(); i++) {
- try {
- JSONObject event = events.getJSONObject(i);
- event.put("dateVoided", now);
- event.put(EventClientRepository.event_column.syncStatus.name(), BaseRepository.TYPE_Unsynced);
- } catch (JSONException e) {
- Timber.e(e);
- }
- }
- }
-
- boolean saved;
- try {
- eventClientRepository.batchInsertEvents(events, 0);
- clientJsonObject.put("dateVoided", now);
- clientJsonObject.put(EventClientRepository.client_column.syncStatus.name(), BaseRepository.TYPE_Unsynced);
- clientJsonObject.getJSONObject("attributes").put("dateRemoved", now);
- eventClientRepository.addorUpdateClient(baseEntityId, clientJsonObject);
- RevealApplication.getInstance().setSynced(false);
- Event archiveEvent = FamilyJsonFormUtils.createFamilyEvent(baseEntityId, Utils.getCurrentLocationId(),
- null, isFamily ? EventType.ARCHIVE_FAMILY : EventType.ARCHIVE_FAMILY_MEMBER);
- archiveEvent.addObs(new Obs().withValue(now).withFieldCode("dateArchived").withFieldType("formsubmissionField"));
-
- JSONObject eventJson = new JSONObject(gson.toJson(archiveEvent));
- eventJson.put(EventClientRepository.event_column.syncStatus.name(), BaseRepository.TYPE_Unsynced);
- eventClientRepository.addEvent(baseEntityId, eventJson);
-
- clientProcessor.processClient(Collections.singletonList(new EventClient(
- gson.fromJson(eventJson.toString(), org.smartregister.domain.Event.class),
- gson.fromJson(clientJsonObject.toString(), Client.class))), true);
- saved = true;
-
- } catch (JSONException e) {
- Timber.e(e);
- saved = false;
- }
- return saved;
- }
-
- public boolean archiveEventsForTask(SQLiteDatabase db, BaseTaskDetails taskDetails) {
- boolean archived = true;
-
- if (taskDetails == null) {
- return false;
- }
- List
- * Adapted from https://stackoverflow.com/questions/37599561/drawing-a-circle-with-the-radius-in-miles-meters-with-mapbox-gl-js/39006388#39006388
- *
- * @param center - Coordinates for the center of the circle
- * @param radius - Radius of the circle in meters
- * @param points - Since this is a GeoJSON polygon, we need to have a large number of sides
- * so that it gets as close as possible to being a circle
- * @return
- * @throws Exception
- */
-
- public static Feature createCircleFeature(LatLng center, Float radius, Float points) throws JSONException {
- Float radiusInKm = radius / METERS_PER_KILOMETER;
-
- JSONArray coordinates = new JSONArray();
- JSONArray coordinate = new JSONArray();
- JSONArray bufferArray = new JSONArray();
- double distanceX = radiusInKm / (KILOMETERS_PER_DEGREE_OF_LONGITUDE_AT_EQUITOR * Math.cos(center.getLatitude() * Math.PI / 180));
- double distanceY = radiusInKm / KILOMETERS_PER_DEGREE_OF_LATITUDE_AT_EQUITOR;
-
- double theta;
- double x;
- double y;
- for (int i = 0; i < points; i++) {
- theta = (i / points) * (2 * Math.PI);
- x = distanceX * Math.cos(theta);
- y = distanceY * Math.sin(theta);
-
- Double longitude = center.getLongitude() + x;
- Double latitude = center.getLatitude() + y;
- coordinate.put(longitude);
- coordinate.put(latitude);
- bufferArray.put(coordinate);
- coordinate = new JSONArray();
- }
-
- coordinates.put(bufferArray);
-
- JSONObject feature = new JSONObject();
- feature.put("type", "Feature");
- JSONObject geometry = new JSONObject();
-
- geometry.put("type", "Polygon");
- geometry.put("coordinates", coordinates);
- feature.put("geometry", geometry);
-
- return Feature.fromJson(feature.toString());
+ public static String getAge(String dob) {
+ String dobString = org.smartregister.family.util.Utils.getDuration(dob);
+ return dobString.contains("y") ? dobString.substring(0, dobString.indexOf("y")) : dobString;
}
- /**
- * Determines whether a structure is a residence based on the Task Code value
- *
- * @param taskCode
- * @return isResidentialStructure
- */
- public static boolean isResidentialStructure(String taskCode) {
- if (StringUtils.isEmpty(taskCode)) {
- return false;
- }
- return !(MOSQUITO_COLLECTION.equals(taskCode) || LARVAL_DIPPING.equals(taskCode) || PAOT.equals(taskCode));
- }
/**
* Uses the server setting "display_add_structure_out_of_boundary_warning_dialog" to determine
@@ -307,100 +38,20 @@ public static Boolean displayAddStructureOutOfBoundaryWarningDialog() {
return Boolean.valueOf(getGlobalConfig(CONFIGURATION.DISPLAY_ADD_STRUCTURE_OUT_OF_BOUNDARY_WARNING_DIALOG, CONFIGURATION.DEFAULT_DISPLAY_ADD_STRUCTURE_OUT_OF_BOUNDARY_WARNING_DIALOG.toString()));
}
- public static boolean isFocusInvestigation() {
- return getInterventionLabel() == R.string.focus_investigation;
- }
-
- public static boolean isMDA() {
- return getInterventionLabel() == R.string.mda;
- }
-
- public static boolean isFocusInvestigationOrMDA() {
- return isFocusInvestigation() || isMDA();
- }
-
- public static String getCurrentLocationId() {
- Location currentOperationalArea = getOperationalAreaLocation(PreferencesUtil.getInstance().getCurrentOperationalArea());
- return currentOperationalArea == null ? null : currentOperationalArea.getId();
- }
-
- public static FormTag getFormTag() {
- FormTag formTag = new FormTag();
- AllSharedPreferences sharedPreferences = RevealApplication.getInstance().getContext().allSharedPreferences();
- formTag.providerId = sharedPreferences.fetchRegisteredANM();
- formTag.locationId = PreferencesUtil.getInstance().getCurrentOperationalAreaId();
- formTag.teamId = sharedPreferences.fetchDefaultTeamId(formTag.providerId);
- formTag.team = sharedPreferences.fetchDefaultTeam(formTag.providerId);
- formTag.databaseVersion = BuildConfig.DATABASE_VERSION;
- formTag.appVersion = BuildConfig.VERSION_CODE;
- formTag.appVersionName = BuildConfig.VERSION_NAME;
- return formTag;
- }
-
-
- public static void tagEventMetadata(Event event, FormTag formTag) {
- event.setProviderId(formTag.providerId);
- event.setLocationId(formTag.locationId);
- event.setChildLocationId(formTag.childLocationId);
- event.setTeam(formTag.team);
- event.setTeamId(formTag.teamId);
- event.setClientDatabaseVersion(formTag.databaseVersion);
- event.setClientApplicationVersion(formTag.appVersion);
- event.addDetails(Properties.APP_VERSION_NAME, formTag.appVersionName);
- }
-
- public static void recreateEventAndClients(String query, String[] params, SQLiteDatabase db, FormTag formTag, String tableName, String eventType, String entityType, RecreateECUtil util) {
- try {
- if (!DatabaseMigrationUtils.isColumnExists(db, tableName, "id")) {
- return;
- }
- Pair
- * It handles the text and color displayed on an Action View. Also attaches a clickListener
- * which handles clicks on the action view.
- *
- * @param actionLabel Text that shows what action to take when action view is clicked
- * @param task TaskDetails object used to populate info in a particular row
- * @param cardDetails Object that contains status, status message and status color
- * @param onClickListener Click listener that handles clicks events on the Task Action
- */
- public void setTaskAction(String actionLabel, TaskDetails task, CardDetails cardDetails, View.OnClickListener onClickListener) {
- actionView.setText(actionLabel);
-
- // registered family with multiple tasks
- if (cardDetails != null && task.getTaskCount() != null) { // task grouping only for FI
- if (task.getTaskCount() > 1) {
- if (task.getTaskCount() != task.getCompleteTaskCount()) {
-
-
- Pair, Map
, List
, Map
, Map