Skip to content

Commit

Permalink
Merge branch 'crvs-dev' of github.com:opensrp/opensrp-client-chw into…
Browse files Browse the repository at this point in the history
… crvs-dev
  • Loading branch information
allan-on committed Aug 5, 2021
2 parents 8314c6d + ce917cb commit a305972
Show file tree
Hide file tree
Showing 89 changed files with 965 additions and 1,550 deletions.
3 changes: 2 additions & 1 deletion opensrp-chw/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ android {
versionName "1.0.0"
buildConfigField "String", 'opensrp_url', '"https://wcaro-td.smartregister.org/opensrp/"'
buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/chad/"'
buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-stage.smartregister.org/opensrp/"'
// buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-stage.smartregister.org/opensrp/"'
buildConfigField "String", 'opensrp_url_debug', '"https://crvs.labs.smartregister.org/opensrp/"'
buildConfigField "String[]", "LOCATION_HIERACHY", '{"Country" , "Province" , "Health District","Health Facility","Village","Clinic" , "CHSS" , "CHA"}'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"Health District","Health Facility","Village"}'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS_DEBUG", '{"Clinic" , "CHSS" , "CHA"}'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.smartregister.chw.activity;

import android.content.Intent;
import android.view.View;
import org.json.JSONObject;
import org.smartregister.chw.anc.util.Constants;
import org.smartregister.chw.core.activity.CoreBirthNotificationRegisterActivity;
Expand All @@ -21,6 +22,7 @@ protected void registerBottomNavigation() {
bottomNavigationHelper = new BottomNavigationHelper();
bottomNavigationView = findViewById(org.smartregister.R.id.bottom_navigation);
FamilyRegisterActivity.registerBottomNavigation(bottomNavigationHelper, bottomNavigationView, this);
bottomNavigationView.setVisibility(View.GONE);
}

@Override
Expand All @@ -35,6 +37,7 @@ protected void onActivityResultExtended(int requestCode, int resultCode, Intent
// process the form
try {
String jsonString = data.getStringExtra(Constants.JSON_FORM_EXTRA.JSON);
assert jsonString != null;
JSONObject form = new JSONObject(jsonString);
String baseEnityId = form.optString(Constants.JSON_FORM_EXTRA.ENTITY_TYPE);
String encounter_type = form.optString(Constants.JSON_FORM_EXTRA.ENCOUNTER_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ protected void registerBottomNavigation() {
bottomNavigationView.getMenu().removeItem(org.smartregister.chw.core.R.id.action_library);

bottomNavigationView.inflateMenu(org.smartregister.chw.core.R.menu.bottom_nav_family_menu);

bottomNavigationHelper.disableShiftMode(bottomNavigationView);

CoreBottomNavigationListener childBottomNavigationListener = new CoreBottomNavigationListener(this);
bottomNavigationView.setOnNavigationItemSelectedListener(childBottomNavigationListener);

}
}

Expand Down Expand Up @@ -122,6 +119,7 @@ protected void onActivityResultExtended(int requestCode, int resultCode, Intent
String jsonString = data.getStringExtra(Constants.JSON_FORM_EXTRA.JSON);
Timber.d("JSONResult : %s", jsonString);

assert jsonString != null;
JSONObject form = new JSONObject(jsonString);
if (form.getString(JsonFormUtils.ENCOUNTER_TYPE).equals(Utils.metadata().familyRegister.registerEventType)
|| form.getString(JsonFormUtils.ENCOUNTER_TYPE).equals(CoreConstants.EventType.CHILD_REGISTRATION)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.smartregister.chw.activity;

import android.content.Intent;
import android.view.View;
import org.json.JSONObject;
import org.smartregister.chw.anc.util.Constants;
import org.smartregister.chw.core.contract.CoreChildRegisterContract;
Expand All @@ -20,6 +21,7 @@ protected void registerBottomNavigation() {
bottomNavigationHelper = new BottomNavigationHelper();
bottomNavigationView = findViewById(org.smartregister.R.id.bottom_navigation);
FamilyRegisterActivity.registerBottomNavigation(bottomNavigationHelper, bottomNavigationView, this);
bottomNavigationView.setVisibility(View.GONE);
}

@Override
Expand All @@ -34,6 +36,7 @@ protected void onActivityResultExtended(int requestCode, int resultCode, Intent
// process the form
try {
String jsonString = data.getStringExtra(Constants.JSON_FORM_EXTRA.JSON);
assert jsonString != null;
JSONObject form = new JSONObject(jsonString);
String baseEnityId = form.optString(Constants.JSON_FORM_EXTRA.ENTITY_TYPE);
String encounter_type = form.optString(Constants.JSON_FORM_EXTRA.ENCOUNTER_TYPE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package org.smartregister.chw.activity;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.os.Bundle;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import org.json.JSONArray;
import org.json.JSONObject;
import org.smartregister.chw.application.ChwApplication;
import org.smartregister.chw.core.activity.CoreFamilyRegisterActivity;
import org.smartregister.chw.core.application.CoreChwApplication;
import org.smartregister.chw.core.custom_views.NavigationMenu;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.core.utils.CoreJsonFormUtils;
import org.smartregister.chw.fragment.DeadClientsFragment;
import org.smartregister.chw.listener.ChwBottomNavigationListener;
Expand All @@ -27,15 +25,19 @@
import org.smartregister.view.fragment.BaseRegisterFragment;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import timber.log.Timber;
import static org.smartregister.chw.core.utils.FormUtils.getFormUtils;
import static org.smartregister.chw.util.CrvsConstants.BASE_ENTITY_ID;
import static org.smartregister.chw.util.CrvsConstants.CLIENT_TYPE;
import static org.smartregister.chw.util.CrvsConstants.DEATH_CERTIFICATE_ISSUE_DATE;
import static org.smartregister.chw.util.CrvsConstants.DEATH_FORM;
import static org.smartregister.chw.util.CrvsConstants.DEATH_MEMBER_FORM;
import static org.smartregister.chw.util.CrvsConstants.DOB;
import static org.smartregister.chw.util.CrvsConstants.HAS_DEATH_CERTIFICATE;
import static org.smartregister.chw.util.CrvsConstants.MIN_DATE;
import static org.smartregister.chw.util.CrvsConstants.RECEIVED_DEATH_CERTIFICATE;
import static org.smartregister.chw.util.DateUtils.changeDateFormat;

public class DeadClientsUpdateActivity extends CoreFamilyRegisterActivity {

Expand Down Expand Up @@ -76,6 +78,17 @@ public void startAncDangerSignsOutcomeForm() {
Map<String, String> valueMap = new HashMap<>();
valueMap.put(HAS_DEATH_CERTIFICATE, death_cert);
valueMap.put(DEATH_CERTIFICATE_ISSUE_DATE, death_cert_issue_date);

try {
JSONObject stepOne = formJsonObject.getJSONObject(JsonFormUtils.STEP1);
JSONArray jsonArray = stepOne.getJSONArray(JsonFormUtils.FIELDS);
JSONObject min_date = CoreJsonFormUtils.getFieldJSONObject(jsonArray, DEATH_CERTIFICATE_ISSUE_DATE);
assert min_date != null;
min_date.put(MIN_DATE, changeDateFormat(Objects.requireNonNull(getIntent().getStringExtra(DOB))));
} catch (Exception e) {
Timber.e(e);
}

CoreJsonFormUtils.populateJsonForm(formJsonObject, valueMap);
JsonFormUtilsFlv.startFormActivity(DeadClientsUpdateActivity.this, formJsonObject, DEATH_FORM);
} catch (Exception e) {
Expand All @@ -98,6 +111,7 @@ protected void onActivityResultExtended(int requestCode, int resultCode, Intent
if (requestCode == JsonFormUtils.REQUEST_CODE_GET_JSON && resultCode == RESULT_OK) {
try {
String jsonString = data.getStringExtra(org.smartregister.family.util.Constants.JSON_FORM_EXTRA.JSON);
assert jsonString != null;
JSONObject form = new JSONObject(jsonString);

if (form.getString(JsonFormUtils.ENCOUNTER_TYPE).equals(CrvsConstants.REMOVE_FAMILY_MEMBER)
Expand All @@ -119,26 +133,53 @@ protected void onActivityResultExtended(int requestCode, int resultCode, Intent
private void updateDeathCertificate(AllCommonsRepository childCommonsRepository, AllCommonsRepository familyCommonsRepository, String jsonString) {
try {
JSONObject jsonObject = new JSONObject(jsonString);
JSONObject stepOne = jsonObject.getJSONObject("step1");
JSONArray fields = stepOne.getJSONArray("fields");
JSONObject stepOne = jsonObject.getJSONObject(CrvsConstants.STEP1);
JSONArray fields = stepOne.getJSONArray(CrvsConstants.FIELDS);

JSONObject has_death_certificate = fields.getJSONObject(1);
JSONObject death_certificate_issue_date = fields.getJSONObject(2);
JSONObject certificateNumber = fields.getJSONObject(3);

String hasCertificate = has_death_certificate.getString("value");
String issueDate = death_certificate_issue_date.getString("value");

if (getIntent().getStringExtra(CLIENT_TYPE).equals("child")) {
String tableName = "ec_child";
String sql = "UPDATE "+tableName+" SET received_death_certificate = ?, death_certificate_issue_date = ? WHERE id = ?";
String[] selectionArgs = {hasCertificate, issueDate, getIntent().getStringExtra(BASE_ENTITY_ID).toLowerCase()};
childCommonsRepository.customQuery(sql, selectionArgs, tableName);
} else {
String tableName = "ec_family_member";
String sql = "UPDATE "+tableName+" SET received_death_certificate = ?, death_certificate_issue_date = ? WHERE id = ?";
String[] selectionArgs = {hasCertificate, issueDate, getIntent().getStringExtra(BASE_ENTITY_ID).toLowerCase()};
familyCommonsRepository.customQuery(sql, selectionArgs, tableName);
String issueDate;
if (hasCertificate.equalsIgnoreCase(CrvsConstants.YES)) {
issueDate = death_certificate_issue_date.getString("value");
}else {
issueDate = "";
}

if (Objects.requireNonNull(getIntent().getStringExtra(CLIENT_TYPE)).equalsIgnoreCase(CrvsConstants.CHILD)) {
String tableName = CoreConstants.TABLE_NAME.CHILD;
if (!issueDate.equals("")) {
String sql = "UPDATE " + tableName + " SET received_death_certificate = ?, death_certificate_issue_date = ? WHERE id = ?";
String[] selectionArgs = {hasCertificate, issueDate, Objects.requireNonNull(getIntent().getStringExtra(BASE_ENTITY_ID)).toLowerCase()};
childCommonsRepository.customQuery(sql, selectionArgs, tableName);
}else {
String sql = "UPDATE " + tableName + " SET received_death_certificate = ? WHERE id = ?";
String[] selectionArgs = {hasCertificate, Objects.requireNonNull(getIntent().getStringExtra(BASE_ENTITY_ID)).toLowerCase()};
childCommonsRepository.customQuery(sql, selectionArgs, tableName);
}
} else if (Objects.requireNonNull(getIntent().getStringExtra(CLIENT_TYPE)).equalsIgnoreCase(CrvsConstants.STILL)) {
String tableName = CoreConstants.TABLE_NAME.FAMILY_MEMBER;
if (!issueDate.equals("")) {
String sql = "UPDATE " + tableName + " SET received_death_certificate = ?, death_certificate_issue_date = ? WHERE id = ?";
String[] selectionArgs = {hasCertificate, issueDate, Objects.requireNonNull(getIntent().getStringExtra(BASE_ENTITY_ID)).toLowerCase()};
familyCommonsRepository.customQuery(sql, selectionArgs, tableName);
}else {
String sql = "UPDATE " + tableName + " SET received_death_certificate = ? WHERE id = ?";
String[] selectionArgs = {hasCertificate, Objects.requireNonNull(getIntent().getStringExtra(BASE_ENTITY_ID)).toLowerCase()};
familyCommonsRepository.customQuery(sql, selectionArgs, tableName);
}
} else if (Objects.requireNonNull(getIntent().getStringExtra(CLIENT_TYPE)).equalsIgnoreCase(CrvsConstants.OUT_OF_AREA)) {
String tableName = CrvsConstants.TABLE_OUT_OF_AREA_DEATH;
if (!issueDate.equals("")) {
String sql = "UPDATE " + tableName + " SET received_death_certificate = ?, death_certificate_issue_date = ? WHERE id = ?";
String[] selectionArgs = {hasCertificate, issueDate, Objects.requireNonNull(getIntent().getStringExtra(BASE_ENTITY_ID)).toLowerCase()};
familyCommonsRepository.customQuery(sql, selectionArgs, tableName);
}else {
String sql = "UPDATE " + tableName + " SET received_death_certificate = ? WHERE id = ?";
String[] selectionArgs = {hasCertificate, Objects.requireNonNull(getIntent().getStringExtra(BASE_ENTITY_ID)).toLowerCase()};
familyCommonsRepository.customQuery(sql, selectionArgs, tableName);
}
}
startActivity(new Intent(this, DeadClientsActivity.class));
finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.fragment.app.Fragment;

import com.vijay.jsonwizard.constants.JsonFormConstants;
import com.vijay.jsonwizard.domain.Form;

import org.json.JSONObject;
import org.smartregister.AllConstants;
import org.smartregister.chw.anc.util.Constants;
Expand All @@ -26,8 +23,7 @@
import org.smartregister.helper.BottomNavigationHelper;
import org.smartregister.view.activity.BaseRegisterActivity;
import org.smartregister.view.fragment.BaseRegisterFragment;

import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand All @@ -47,11 +43,10 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
protected void registerBottomNavigation() {

bottomNavigationHelper = new BottomNavigationHelper();
bottomNavigationView = findViewById(org.smartregister.R.id.bottom_navigation);

FamilyRegisterActivity.registerBottomNavigation(bottomNavigationHelper, bottomNavigationView, this);
bottomNavigationView.setVisibility(View.GONE);
}

@Override
Expand Down Expand Up @@ -117,6 +112,7 @@ protected void onActivityResultExtended(int requestCode, int resultCode, Intent
// process the form
try {
String jsonString = data.getStringExtra(Constants.JSON_FORM_EXTRA.JSON);
assert jsonString != null;
JSONObject form = new JSONObject(jsonString);
String baseEnityId = form.optString(Constants.JSON_FORM_EXTRA.ENTITY_TYPE);
String encounter_type = form.optString(Constants.JSON_FORM_EXTRA.ENCOUNTER_TYPE);
Expand All @@ -131,7 +127,7 @@ protected void onActivityResultExtended(int requestCode, int resultCode, Intent

@Override
public List<String> getViewIdentifiers() {
return Arrays.asList(Utils.metadata().familyRegister.config);
return Collections.singletonList(Utils.metadata().familyRegister.config);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package org.smartregister.chw.activity;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.os.Bundle;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import org.json.JSONArray;
import org.json.JSONObject;
import org.smartregister.chw.anc.AncLibrary;
import org.smartregister.chw.application.ChwApplication;
import org.smartregister.chw.core.custom_views.NavigationMenu;
import org.smartregister.chw.core.utils.CoreJsonFormUtils;
import org.smartregister.chw.fragment.DeadClientsFragment;
import org.smartregister.chw.fragment.OutOfAreaFragment;
import org.smartregister.chw.listener.ChwBottomNavigationListener;
import org.smartregister.chw.util.JsonFormUtilsFlv;
import org.smartregister.chw.util.Utils;
import org.smartregister.commonregistry.AllCommonsRepository;
import org.smartregister.commonregistry.CommonPersonObject;
import org.smartregister.family.util.JsonFormUtils;
import org.smartregister.helper.BottomNavigationHelper;
Expand All @@ -25,8 +22,6 @@
import java.util.Map;
import timber.log.Timber;
import static org.smartregister.chw.core.utils.FormUtils.getFormUtils;
import static org.smartregister.chw.util.CrvsConstants.BASE_ENTITY_ID;
import static org.smartregister.chw.util.CrvsConstants.CLIENT_TYPE;
import static org.smartregister.chw.util.CrvsConstants.OUT_OF_AREA_BIRTH;
import static org.smartregister.chw.util.CrvsConstants.OUT_OF_AREA_CHILD_FORM;
import static org.smartregister.chw.util.CrvsConstants.OUT_OF_AREA_ENCOUNTER_TYPE;
Expand Down Expand Up @@ -75,7 +70,7 @@ public void startAncDangerSignsOutcomeForm() {

@Override
protected BaseRegisterFragment getRegisterFragment() {
return new DeadClientsFragment();
return new OutOfAreaFragment();
}

@Override
Expand All @@ -88,15 +83,9 @@ protected void onActivityResultExtended(int requestCode, int resultCode, Intent
if (requestCode == JsonFormUtils.REQUEST_CODE_GET_JSON && resultCode == RESULT_OK) {
try {
String jsonString = data.getStringExtra(org.smartregister.family.util.Constants.JSON_FORM_EXTRA.JSON);
assert jsonString != null;
JSONObject form = new JSONObject(jsonString);

ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", jsonString);
clipboard.setPrimaryClip(clip);

String openSRPId = AncLibrary.getInstance().getUniqueIdRepository().getNextUniqueId().getOpenmrsId();


if (form.getString(JsonFormUtils.ENCOUNTER_TYPE).equals(OUT_OF_AREA_ENCOUNTER_TYPE)
) {
presenter().saveOutOfAreaForm(jsonString, false);
Expand All @@ -109,35 +98,4 @@ protected void onActivityResultExtended(int requestCode, int resultCode, Intent
}
}

private void updateDeathCertificate(AllCommonsRepository childCommonsRepository, AllCommonsRepository familyCommonsRepository, String jsonString) {
try {
JSONObject jsonObject = new JSONObject(jsonString);
JSONObject stepOne = jsonObject.getJSONObject("step1");
JSONArray fields = stepOne.getJSONArray("fields");

JSONObject has_death_certificate = fields.getJSONObject(1);
JSONObject death_certificate_issue_date = fields.getJSONObject(2);
JSONObject certificateNumber = fields.getJSONObject(3);

String hasCertificate = has_death_certificate.getString("value");
String issueDate = death_certificate_issue_date.getString("value");

if (getIntent().getStringExtra(CLIENT_TYPE).equals("child")) {
String tableName = "ec_child";
String sql = "UPDATE "+tableName+" SET received_death_certificate = ?, death_certificate_issue_date = ? WHERE id = ?";
String[] selectionArgs = {hasCertificate, issueDate, getIntent().getStringExtra(BASE_ENTITY_ID).toLowerCase()};
childCommonsRepository.customQuery(sql, selectionArgs, tableName);
} else {
String tableName = "ec_family_member";
String sql = "UPDATE "+tableName+" SET received_death_certificate = ?, death_certificate_issue_date = ? WHERE id = ?";
String[] selectionArgs = {hasCertificate, issueDate, getIntent().getStringExtra(BASE_ENTITY_ID).toLowerCase()};
familyCommonsRepository.customQuery(sql, selectionArgs, tableName);
}
startActivity(new Intent(this, DeadClientsActivity.class));
finish();

} catch (Exception e) {
Timber.e(e);
}
}
}
Loading

0 comments on commit a305972

Please sign in to comment.