Skip to content

Commit

Permalink
add multidistrict select feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bennsimon committed Aug 20, 2021
1 parent 1377fd3 commit 9da04c7
Show file tree
Hide file tree
Showing 20 changed files with 256 additions and 107 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ subprojects {

group = 'org.smartregister'

ext.androidToolsBuildGradle = '27.0.3'
ext.androidBuildToolsVersion = '27.0.3'
ext.androidMinSdkVersion = 16
ext.androidCompileSdkVersion = 28
ext.androidTargetSdkVersion = 27
ext.androidToolsBuildGradle = '29.0.3'
ext.androidBuildToolsVersion = '29.0.3'
ext.androidMinSdkVersion = 18
ext.androidCompileSdkVersion = 29
ext.androidTargetSdkVersion = 29

ext.androidAnnotationsVersion = '3.0.1';
ext.androidAnnotationsAPIVersion = '3.0.1';
Expand Down
16 changes: 8 additions & 8 deletions opensrp-eusm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jacoco {


android {
compileSdkVersion 28
buildToolsVersion "29.0.3"
compileSdkVersion androidCompileSdkVersion
buildToolsVersion androidToolsBuildGradle

compileOptions {
coreLibraryDesugaringEnabled true
Expand All @@ -48,10 +48,10 @@ android {

defaultConfig {
applicationId "org.smartregister.eusm"
minSdkVersion 18
targetSdkVersion 28
minSdkVersion androidMinSdkVersion
targetSdkVersion androidTargetSdkVersion
versionCode 1
versionName "0.0.9"
versionName "0.1.0"
multiDexEnabled true
buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
buildConfigField "boolean", "TIME_CHECK", "false"
Expand Down Expand Up @@ -201,7 +201,7 @@ dependencies {

jarJar 'com.ibm.fhir:fhir-model:4.7.0'

implementation('org.smartregister:opensrp-client-core:4.3.10-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-core:4.3.16-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.github.ybq', module: 'Android-SpinKit'
Expand All @@ -218,7 +218,7 @@ dependencies {
exclude group: 'com.android.support', module: 'appcompat-v7'
}

implementation('org.smartregister:opensrp-client-native-form:2.0.6-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-native-form:2.1.3-r12-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'cardview-v7'
Expand All @@ -229,7 +229,7 @@ dependencies {
}

// implementation(project(':opensrp-tasking')) {
implementation('org.smartregister:opensrp-client-tasking:0.0.3-v17-EUSM-SNAPSHOT') {
implementation('org.smartregister:opensrp-client-tasking:0.0.3-v18-r5-EUSM-SNAPSHOT') {
transitive = true
exclude group: 'org.smartregister', module: 'opensrp-client-core'
exclude group: 'com.ibm.fhir', module: 'fhir-model'
Expand Down
1 change: 1 addition & 0 deletions opensrp-eusm/src/main/assets/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ SYNC_DOWNLOAD_BATCH_SIZE=100
CHOOSE_OPERATIONAL_AREA_FIRST=false
select_plan_then_area=true
allow.offline.login.with.invalid.token=true
ALLOW_MULTIPLE_OPERATIONAL_AREA_SELECTION=true
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ public void setUserLocation(Location userLocation) {
@Override
public void onUserAssignmentRevoked(UserAssignmentDTO userAssignmentDTO) {
PreferencesUtil preferencesUtil = PreferencesUtil.getInstance();
if (userAssignmentDTO.getJurisdictions().contains(preferencesUtil.getCurrentOperationalAreaId())) {

if (userAssignmentDTO.getJurisdictions().containsAll(preferencesUtil.getCurrentOperationalAreaIds())) {
preferencesUtil.setCurrentOperationalArea(null);
}
if (userAssignmentDTO.getPlans().contains(preferencesUtil.getCurrentPlanId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import net.sqlcipher.database.SQLiteDatabase;

import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.smartregister.clientandeventmodel.Event;
import org.smartregister.commonregistry.CommonPersonObjectClient;
Expand Down Expand Up @@ -136,8 +137,8 @@ public boolean isMDA() {

@Override
public String getCurrentLocationId() {
Location currentOperationalArea = AppUtils.getOperationalAreaLocation(PreferencesUtil.getInstance().getCurrentOperationalArea());
return currentOperationalArea == null ? null : currentOperationalArea.getId();
Set<Location> currentOperationalAreas = AppUtils.getOperationalAreaLocations(PreferencesUtil.getInstance().getCurrentOperationalAreas());
return !currentOperationalAreas.isEmpty() ? currentOperationalAreas.stream().filter(location -> location.getId() != null).map(location -> location.getId()).collect(Collectors.joining( PreferencesUtil.OPERATIONAL_AREA_SEPARATOR)) : null;
}

@Override
Expand Down Expand Up @@ -481,6 +482,7 @@ public double getOnClickMaxZoomLevel() {

@Override
public void fetchPlans(String jurisdictionName, BaseDrawerContract.Presenter presenter) {
// TODO: jurisdictionName comma separated
PlanDefinitionRepository planDefinitionRepository = EusmApplication.getInstance().getPlanDefinitionRepository();
Set<PlanDefinition> planDefinitionSet = planDefinitionRepository.findAllPlanDefinitions();
getAppExecutors().mainThread().execute(new Runnable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public static ProductInfoFragment newInstance(Bundle bundle) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
taskDetail = (TaskDetail) getArguments().getSerializable(AppConstants.IntentData.TASK_DETAIL);
// StructureDetail structureDetail = (StructureDetail) getArguments().getSerializable(AppConstants.IntentData.STRUCTURE_DETAIL);
initializeAdapter();
initializePresenter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
import org.smartregister.eusm.util.GeoJsonUtils;
import org.smartregister.tasking.contract.TaskingMapActivityContract;
import org.smartregister.tasking.interactor.TaskingMapInteractor;
import org.smartregister.tasking.util.PreferencesUtil;
import org.smartregister.tasking.util.TaskingConstants;
import org.smartregister.tasking.util.Utils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import timber.log.Timber;

Expand All @@ -35,13 +39,14 @@ public void fetchLocations(String plan, String operationalArea, String point, Bo
appExecutors.diskIO().execute(new Runnable() {
@Override
public void run() {
Location operationalAreaLocation = getOperationalAreaLocation(operationalArea);
Set<Location> operationalAreaLocations = getOperationalAreaLocations(new HashSet<>(Arrays.asList(operationalArea.split(PreferencesUtil.OPERATIONAL_AREA_SEPARATOR))));

JSONObject featureCollection = null;
try {
featureCollection = createFeatureCollection();
if (operationalAreaLocation != null) {
if (!operationalAreaLocations.isEmpty()) {
List<StructureDetail> structureDetails = appStructureRepository
.fetchStructureDetails(null, operationalAreaLocation.getId(), null, true, plan);
.fetchStructureDetails(null, operationalAreaLocations.stream().filter(location -> location.getId() != null).map(location -> location.getId()).collect(Collectors.toSet()), null, true, plan);

if (structureDetails != null && !structureDetails.isEmpty()) {
String features = geoJsonUtils.getGeoJsonFromStructureDetail(structureDetails);
Expand All @@ -55,9 +60,8 @@ public void run() {
appExecutors.mainThread().execute(new Runnable() {
@Override
public void run() {
if (operationalAreaLocation != null) {
operationalAreaId = operationalAreaLocation.getId();
Feature operationalAreaFeature = Feature.fromJson(gson.toJson(operationalAreaLocation));
if (!operationalAreaLocations.isEmpty()) {
Feature operationalAreaFeature = Feature.fromJson(gson.toJson(operationalAreaLocations.stream().findFirst().orElse(null)));
if (locationComponentActive != null) {
getPresenter().onStructuresFetched(finalFeatureCollection, operationalAreaFeature, null, point, locationComponentActive);
} else {
Expand All @@ -72,7 +76,7 @@ public void run() {
});
}

protected Location getOperationalAreaLocation(String operationalArea) {
return AppUtils.getOperationalAreaLocation(operationalArea);
protected Set<Location> getOperationalAreaLocations(Set<String> operationalAreas) {
return AppUtils.getOperationalAreaLocations(operationalAreas);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.smartregister.util.AppExecutors;

import java.util.Collections;
import java.util.concurrent.atomic.AtomicInteger;

import timber.log.Timber;

Expand All @@ -39,13 +38,10 @@ public void saveFlagProblemForm(TaskDetail taskDetail,
String encounterType, JSONObject jsonForm,
StructureDetail structureDetail, ProductInfoActivityContract.InteractorCallback interactorCallback) {

appExecutors.diskIO().execute(new Runnable() {
@Override
public void run() {
getJsonFormUtils().saveImage(jsonForm, AppConstants.EventEntityType.PRODUCT);
saveEventAndInitiateProcessing(encounterType, jsonForm, "", interactorCallback,
AppConstants.EventEntityType.PRODUCT);
}
appExecutors.diskIO().execute(() -> {
getJsonFormUtils().saveImage(jsonForm, AppConstants.EventEntityType.PRODUCT);
saveEventAndInitiateProcessing(encounterType, jsonForm, "", interactorCallback,
AppConstants.EventEntityType.PRODUCT);
});
}

Expand All @@ -56,63 +52,46 @@ public void saveEventAndInitiateProcessing(String encounterType, JSONObject form
try {
Event event = AppUtils.createEventFromJsonForm(form, encounterType, bindType, entityId);
try {
AtomicInteger count = new AtomicInteger(1);
IntentFilter filter = new IntentFilter(TASK_GENERATED_EVENT);
TaskGenerationReceiver taskGenerationReceiver = new TaskGenerationReceiver(task ->
appExecutors.mainThread().execute(() -> returnResponse(interactorCallback, event, true, count.getAndIncrement())),
AppConstants.EncounterType.FLAG_PROBLEM.equals(encounterType) ? 2 : 1);
appExecutors.mainThread().execute(() -> returnResponse(interactorCallback, event, true)));
LocalBroadcastManager.getInstance(EusmApplication.getInstance().getApplicationContext()).registerReceiver(taskGenerationReceiver, filter);

AppUtils.initiateEventProcessing(Collections.singletonList(event.getFormSubmissionId()));
} catch (Exception e) {
Timber.e(e);
returnResponse(interactorCallback, event, false, 0);
returnResponse(interactorCallback, event, false);
}
} catch (JSONException e) {
Timber.e(e);
returnResponse(interactorCallback, null, false, 0);
returnResponse(interactorCallback, null, false);
}
}

@Override
public void markProductAsGood(StructureDetail structureDetail, TaskDetail taskDetail, ProductInfoActivityContract.InteractorCallback callBack,
Activity activity) {
appExecutors.diskIO().execute(new Runnable() {
@Override
public void run() {
JSONObject jsonObject = getJsonFormUtils()
.getFormObjectWithDetails(activity, AppConstants.JsonForm.LOOKS_GOOD, structureDetail, taskDetail);
saveEventAndInitiateProcessing(AppConstants.EncounterType.LOOKS_GOOD, jsonObject,
"", callBack, AppConstants.EventEntityType.PRODUCT);
}
appExecutors.diskIO().execute(() -> {
JSONObject jsonObject = getJsonFormUtils()
.getFormObjectWithDetails(activity, AppConstants.JsonForm.LOOKS_GOOD, structureDetail, taskDetail);
saveEventAndInitiateProcessing(AppConstants.EncounterType.LOOKS_GOOD, jsonObject,
"", callBack, AppConstants.EventEntityType.PRODUCT);
});
}

@Override
public void startFlagProblemForm(StructureDetail structureDetail, TaskDetail taskDetail, String formName, Activity activity,
ProductInfoActivityContract.InteractorCallback interactorCallBack) {
appExecutors.diskIO().execute(new Runnable() {
@Override
public void run() {
JSONObject form = getJsonFormUtils().getFormObjectWithDetails(activity, formName, structureDetail, taskDetail);
appExecutors.mainThread().execute(new Runnable() {
@Override
public void run() {
interactorCallBack.onFlagProblemFormFetched(form);
}
});
}
appExecutors.diskIO().execute(() -> {
JSONObject form = getJsonFormUtils().getFormObjectWithDetails(activity, formName, structureDetail, taskDetail);
appExecutors.mainThread().execute(() -> interactorCallBack.onFlagProblemFormFetched(form));
});
}

private void returnResponse(ProductInfoActivityContract.InteractorCallback interactorCallback,
Event event, boolean status, int callCount) {
Event event, boolean status) {
if (event != null && event.getDetails() != null) {
String encounterType = event.getEventType();
if (AppConstants.EncounterType.FLAG_PROBLEM.equals(encounterType)) {
if (status && callCount < 2) {
return;
}
interactorCallback.onSavedFlagProblemTask(status, event);
} else if (AppConstants.EncounterType.LOOKS_GOOD.equals(encounterType)) {
interactorCallback.onProductMarkedAsGood(status, event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.smartregister.eusm.model;

import org.smartregister.domain.Location;
import org.smartregister.eusm.application.EusmApplication;
import org.smartregister.eusm.domain.StructureDetail;
import org.smartregister.eusm.repository.AppStructureRepository;
import org.smartregister.eusm.util.AppUtils;
import org.smartregister.tasking.util.PreferencesUtil;
import org.smartregister.tasking.util.Utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class StructureRegisterFragmentModel {

Expand All @@ -20,18 +18,18 @@ public StructureRegisterFragmentModel() {
}

public int countOfStructures(String nameFilter) {
Location location = AppUtils.getOperationalAreaLocation(PreferencesUtil.getInstance().getCurrentOperationalArea());
if (location != null) {
return appStructureRepository.countOfStructures(nameFilter, location.getId(), PreferencesUtil.getInstance().getCurrentPlanId());
Set<String> locations = PreferencesUtil.getInstance().getCurrentOperationalAreaIds();
if (!locations.isEmpty()) {
return appStructureRepository.countOfStructures(nameFilter, locations, PreferencesUtil.getInstance().getCurrentPlanId());
} else {
return 0;
}
}

public List<StructureDetail> fetchStructures(int pageNo, String nameFilter) {
Location location = AppUtils.getOperationalAreaLocation(PreferencesUtil.getInstance().getCurrentOperationalArea());
if (location != null) {
return appStructureRepository.fetchStructureDetails(pageNo, location.getId(), nameFilter, PreferencesUtil.getInstance().getCurrentPlanId());
Set<String> locations = PreferencesUtil.getInstance().getCurrentOperationalAreaIds();
if (!locations.isEmpty()) {
return appStructureRepository.fetchStructureDetails(pageNo, locations, nameFilter, PreferencesUtil.getInstance().getCurrentPlanId());
} else {
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,33 @@ public String getEntireTree(List<FormLocation> entireTree) {
List<String> jurisdictionList = planDefinitionSearches.stream().map(PlanDefinitionSearch::getJurisdictionId).collect(Collectors.toList());
LocationRepository locationRepository = drishtiApplication.getContext().getLocationRepository();
List<Location> locationList = locationRepository.getLocationsByIds(jurisdictionList);

List<FormLocation> formLocations = filterLocations(locationList.stream().map(location ->
location.getProperties().getName()
).collect(Collectors.toList()), entireTree);

cleanUpFormLocations(formLocations);
return AssetHandler.javaToJsonString(formLocations,
new TypeToken<List<FormLocation>>() {
}.getType());
}


private void cleanUpFormLocations(List<FormLocation> formLocations) {
if (!formLocations.isEmpty()) {
FormLocation root = formLocations.get(0);
if (root.nodes != null && !root.nodes.isEmpty()) {
Iterator<FormLocation> locationIterable = root.nodes.iterator();
while (locationIterable.hasNext()) {
FormLocation formLocation = locationIterable.next();
if (formLocation.nodes.isEmpty()) {
locationIterable.remove();
}
}
}
}
}


/**
* Filter out district not in the plan
*
Expand All @@ -123,4 +141,6 @@ private List<FormLocation> filterLocations(List<String> filteredIn, List<FormLoc
}
return entireTree;
}

}

Loading

0 comments on commit 9da04c7

Please sign in to comment.