diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivity.java index c50974b705..b5dc801495 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivity.java @@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils; import org.smartregister.chw.core.custom_views.NavigationMenu; +import org.smartregister.chw.core.model.CoreFamilyRegisterModel; import org.smartregister.chw.core.utils.CoreConstants; import org.smartregister.family.activity.BaseFamilyRegisterActivity; import org.smartregister.family.model.BaseFamilyRegisterModel; @@ -32,7 +33,7 @@ protected void onCreate(Bundle savedInstanceState) { @Override protected void initializePresenter() { - presenter = new BaseFamilyRegisterPresenter(this, new BaseFamilyRegisterModel()); + presenter = new BaseFamilyRegisterPresenter(this, new CoreFamilyRegisterModel()); } @Override diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/CoreFamilyProfileModel.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/CoreFamilyProfileModel.java index 1ccd6b2915..a5e0471226 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/CoreFamilyProfileModel.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/CoreFamilyProfileModel.java @@ -1,9 +1,22 @@ package org.smartregister.chw.core.model; +import com.vijay.jsonwizard.constants.JsonFormConstants; + +import org.json.JSONObject; +import org.smartregister.chw.core.application.CoreChwApplication; +import org.smartregister.chw.core.utils.CoreJsonFormUtils; import org.smartregister.family.model.BaseFamilyProfileModel; public abstract class CoreFamilyProfileModel extends BaseFamilyProfileModel { + public CoreFamilyProfileModel(String familyName) { super(familyName); } + + @Override + public JSONObject getFormAsJson(String formName, String entityId, String currentLocationId) throws Exception { + JSONObject form = super.getFormAsJson(formName, entityId, currentLocationId); + CoreJsonFormUtils.populateLocationsTree(form, JsonFormConstants.STEP1, CoreChwApplication.getInstance().getAllowedLocationLevels(), "nearest_facility"); + return form; + } } \ No newline at end of file diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/CoreFamilyRegisterModel.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/CoreFamilyRegisterModel.java new file mode 100644 index 0000000000..98ffe1a833 --- /dev/null +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/CoreFamilyRegisterModel.java @@ -0,0 +1,19 @@ +package org.smartregister.chw.core.model; + +import com.vijay.jsonwizard.constants.JsonFormConstants; + +import org.json.JSONObject; +import org.smartregister.chw.core.application.CoreChwApplication; +import org.smartregister.chw.core.utils.CoreJsonFormUtils; +import org.smartregister.family.model.BaseFamilyRegisterModel; + +public class CoreFamilyRegisterModel extends BaseFamilyRegisterModel { + + @Override + public JSONObject getFormAsJson(String formName, String entityId, String currentLocationId) throws Exception { + JSONObject form = super.getFormAsJson(formName, entityId, currentLocationId); + CoreJsonFormUtils.populateLocationsTree(form, JsonFormConstants.STEP1, CoreChwApplication.getInstance().getAllowedLocationLevels(), "nearest_facility"); + return form; + } + +} diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/presenter/CoreFamilyProfilePresenter.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/presenter/CoreFamilyProfilePresenter.java index 7ec3f8803c..1747acf535 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/presenter/CoreFamilyProfilePresenter.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/presenter/CoreFamilyProfilePresenter.java @@ -3,6 +3,8 @@ import android.content.Context; import android.util.Pair; +import com.vijay.jsonwizard.constants.JsonFormConstants; + import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Triple; import org.json.JSONObject; @@ -70,6 +72,7 @@ public FamilyProfileExtendedContract.View getView() { @Override public void startFormForEdit(CommonPersonObjectClient client) { JSONObject form = CoreJsonFormUtils.getAutoPopulatedJsonEditFormString(CoreConstants.JSON_FORM.getFamilyDetailsRegister(), getView().getApplicationContext(), client, Utils.metadata().familyRegister.updateEventType); + CoreJsonFormUtils.populateLocationsTree(form, JsonFormConstants.STEP1, CoreChwApplication.getInstance().getAllowedLocationLevels(), "nearest_facility"); try { getView().startFormActivity(form); } catch (Exception e) { diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreJsonFormUtils.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreJsonFormUtils.java index b912cb1e12..5a35091df0 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreJsonFormUtils.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreJsonFormUtils.java @@ -6,6 +6,7 @@ import android.text.TextUtils; import android.util.Pair; +import com.google.common.reflect.TypeToken; import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.domain.Form; @@ -27,6 +28,7 @@ import org.smartregister.commonregistry.CommonPersonObjectClient; import org.smartregister.domain.Photo; import org.smartregister.domain.ProfileImage; +import org.smartregister.domain.form.FormLocation; import org.smartregister.domain.tag.FormTag; import org.smartregister.family.FamilyLibrary; import org.smartregister.family.util.Constants; @@ -867,4 +869,37 @@ public static HashMap getEducationLevels(Context context) { return educationLevels; } + public static void populateLocationsTree(JSONObject form, String stepName, + ArrayList healthFacilities, String locationTree) { + try { + JSONArray questions = form.getJSONObject(stepName).getJSONArray(JsonFormConstants.FIELDS); + healthFacilities.add(0, "Country"); + healthFacilities.add(1, "Region"); + healthFacilities.add(2, "District"); + List defaultFacility = LocationHelper.getInstance().generateDefaultLocationHierarchy(healthFacilities); + List upToFacilities = LocationHelper.getInstance().generateLocationHierarchyTree(false, healthFacilities); + + String defaultFacilityString = AssetHandler.javaToJsonString(defaultFacility, + new TypeToken>() { + }.getType()); + + String upToFacilitiesString = AssetHandler.javaToJsonString(upToFacilities, + new TypeToken>() { + }.getType()); + + for (int i = 0; i < questions.length(); i++) { + if (questions.getJSONObject(i).getString(JsonFormConstants.KEY).equals(locationTree)) { + if (StringUtils.isNotBlank(upToFacilitiesString)) { + questions.getJSONObject(i).put(JsonFormConstants.TREE, new JSONArray(upToFacilitiesString)); + } + if (StringUtils.isNotBlank(defaultFacilityString)) { + questions.getJSONObject(i).put(JsonFormConstants.DEFAULT, defaultFacilityString); + } + } + } + } catch (Exception e) { + Timber.e(e); + } + } + } diff --git a/opensrp-chw-hf/build.gradle b/opensrp-chw-hf/build.gradle index 79a5e6ab54..f061cfd902 100644 --- a/opensrp-chw-hf/build.gradle +++ b/opensrp-chw-hf/build.gradle @@ -31,7 +31,7 @@ android { minSdkVersion 18 targetSdkVersion 28 versionCode 1 - versionName "1.2.3" + versionName "1.2.4" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true buildConfigField "String", 'opensrp_url', '"https://boresha-afya.smartregister.org/opensrp/"' @@ -63,7 +63,7 @@ android { buildConfigField "int", "REPORT_INDICATOR_GENERATION_MINUTES", '15' buildConfigField "int", "HOME_VISIT_MINUTES", '60' buildConfigField "boolean", 'SUPPORT_REPORT', 'false' - buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"Ward" , "Health Facility"}' + buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"Ward" , "Health Facility", "Village", "Village Sublocations"}' buildConfigField "String", 'DEFAULT_LOCATION', '"Health Facility"' } diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index fea28bac20..0dd647bb60 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -123,12 +123,12 @@ android { dimension = 'baseDimension' applicationIdSuffix ".ba" versionCode 1 - versionName "1.0.0" + versionName "1.0.1" buildConfigField "String", 'opensrp_url', '"https://boresha-afya.smartregister.org/opensrp/"' buildConfigField "String", 'opensrp_url_debug', '"https://boresha-afya-stage.smartregister.org/opensrp/"' - buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"Ward" , "Health Facility"}' + buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"Ward" , "Health Facility", "Village", "Village Sublocations"}' buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS_DEBUG", '{"MOH Jhpiego Facility Name" , "Village"}' - buildConfigField "String", 'DEFAULT_LOCATION', '"Health Facility"' + buildConfigField "String", 'DEFAULT_LOCATION', '"Village Sublocations"' buildConfigField "String", 'DEFAULT_LOCATION_DEBUG', '"Village"' buildConfigField "boolean", 'SUPPORT_QR', 'true' buildConfigField "boolean", 'SUPPORT_REPORT', 'false'