Skip to content

Commit

Permalink
Merge branch 'master' into resource-update
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev authored Sep 7, 2019
2 parents fe33462 + 8afb7c2 commit 61c212f
Show file tree
Hide file tree
Showing 12 changed files with 354 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.smartregister.chw.core.contract.CoreApplication;
import org.smartregister.chw.core.helper.RulesEngineHelper;
import org.smartregister.chw.core.repository.AncRegisterRepository;
import org.smartregister.chw.core.repository.PncRegisterRepository;
import org.smartregister.chw.core.repository.ScheduleRepository;
import org.smartregister.chw.core.repository.WashCheckRepository;
import org.smartregister.chw.core.sync.CoreClientProcessor;
Expand Down Expand Up @@ -44,6 +45,7 @@ public class CoreChwApplication extends DrishtiApplication implements CoreApplic

private static CommonFtsObject commonFtsObject = null;
private static AncRegisterRepository ancRegisterRepository;
private static PncRegisterRepository pncRegisterRepository;
private static TaskRepository taskRepository;
private static PlanDefinitionRepository planDefinitionRepository;
private static WashCheckRepository washCheckRepository;
Expand Down Expand Up @@ -74,6 +76,13 @@ public static AncRegisterRepository ancRegisterRepository() {
return ancRegisterRepository;
}

public static PncRegisterRepository pncRegisterRepository() {
if (pncRegisterRepository == null) {
pncRegisterRepository = new PncRegisterRepository(getInstance().getRepository());
}
return pncRegisterRepository;
}

public static WashCheckRepository getWashCheckRepository() {
if (washCheckRepository == null) {
washCheckRepository = new WashCheckRepository(getInstance().getRepository());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import android.content.Intent;

import org.smartregister.chw.anc.activity.BaseAncMemberProfileActivity;
import org.smartregister.chw.anc.domain.MemberObject;
import org.smartregister.chw.core.R;
import org.smartregister.chw.core.activity.CoreAboveFiveChildProfileActivity;
import org.smartregister.chw.core.activity.CoreChildProfileActivity;
import org.smartregister.chw.core.utils.ChildDBConstants;
import org.smartregister.chw.core.utils.CoreChildUtils;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.pnc.activity.BasePncMemberProfileActivity;
import org.smartregister.commonregistry.CommonPersonObject;
import org.smartregister.commonregistry.CommonPersonObjectClient;
import org.smartregister.configurableviews.model.View;
import org.smartregister.family.fragment.BaseFamilyProfileMemberFragment;
Expand All @@ -22,6 +25,7 @@

import timber.log.Timber;

import static org.smartregister.chw.anc.util.Constants.ANC_MEMBER_OBJECTS.TITLE_VIEW_TEXT;

public abstract class CoreFamilyProfileMemberFragment extends BaseFamilyProfileMemberFragment {

Expand All @@ -47,7 +51,13 @@ public void goToProfileActivity(android.view.View view) {
CommonPersonObjectClient commonPersonObjectClient = (CommonPersonObjectClient) view.getTag();
String entityType = Utils.getValue(commonPersonObjectClient.getColumnmaps(), ChildDBConstants.KEY.ENTITY_TYPE, false);
if (CoreConstants.TABLE_NAME.FAMILY_MEMBER.equals(entityType)) {
goToOtherMemberProfileActivity(commonPersonObjectClient);
if (isAncMember(commonPersonObjectClient.entityId())) {
goToAncProfileActivity(commonPersonObjectClient);
} else if (isPncMember(commonPersonObjectClient.entityId())) {
gotToPncProfileActivity(commonPersonObjectClient);
} else {
goToOtherMemberProfileActivity(commonPersonObjectClient);
}
} else {
goToChildProfileActivity(commonPersonObjectClient);
}
Expand Down Expand Up @@ -82,12 +92,60 @@ public void goToChildProfileActivity(CommonPersonObjectClient patient) {
startActivity(intent);
}

public void goToAncProfileActivity(CommonPersonObjectClient patient) {
patient.getColumnmaps().putAll(getAncCommonPersonObject(patient.entityId()).getColumnmaps());
HashMap<String, String> familyHeadDetails = getAncFamilyHeadNameAndPhone(((BaseFamilyProfileMemberPresenter) presenter).getFamilyHead());
String familyHeadName = "";
String familyHeadPhone = "";
if (familyHeadDetails != null) {
familyHeadName = familyHeadDetails.get(org.smartregister.chw.anc.util.Constants.ANC_MEMBER_OBJECTS.FAMILY_HEAD_NAME);
familyHeadPhone = familyHeadDetails.get(org.smartregister.chw.anc.util.Constants.ANC_MEMBER_OBJECTS.FAMILY_HEAD_PHONE);
}
Intent intent = new Intent(getActivity(), getAncMemberProfileActivityClass());
intent.putExtra(org.smartregister.chw.anc.util.Constants.ANC_MEMBER_OBJECTS.MEMBER_PROFILE_OBJECT, new MemberObject(patient));
intent.putExtra(org.smartregister.chw.anc.util.Constants.ANC_MEMBER_OBJECTS.FAMILY_HEAD_NAME, familyHeadName);
intent.putExtra(org.smartregister.chw.anc.util.Constants.ANC_MEMBER_OBJECTS.FAMILY_HEAD_PHONE, familyHeadPhone);
intent.putExtra(TITLE_VIEW_TEXT, String.format(getString(R.string.return_to_family_name), ""));
startActivity(intent);
}

public void gotToPncProfileActivity(CommonPersonObjectClient patient) {
patient.getColumnmaps().putAll(getPncCommonPersonObject(patient.entityId()).getColumnmaps());
HashMap<String, String> familyHeadDetails = getAncFamilyHeadNameAndPhone(((BaseFamilyProfileMemberPresenter) presenter).getFamilyHead());
String familyHeadName = "";
String familyHeadPhone = "";
if (familyHeadDetails != null) {
familyHeadName = familyHeadDetails.get(org.smartregister.chw.anc.util.Constants.ANC_MEMBER_OBJECTS.FAMILY_HEAD_NAME);
familyHeadPhone = familyHeadDetails.get(org.smartregister.chw.anc.util.Constants.ANC_MEMBER_OBJECTS.FAMILY_HEAD_PHONE);
}
Intent intent = new Intent(getActivity(), getPncMemberProfileActivityClass());
intent.putExtra(org.smartregister.chw.anc.util.Constants.ANC_MEMBER_OBJECTS.MEMBER_PROFILE_OBJECT, new MemberObject(patient));
intent.putExtra(org.smartregister.chw.anc.util.Constants.ANC_MEMBER_OBJECTS.FAMILY_HEAD_NAME, familyHeadName);
intent.putExtra(org.smartregister.chw.anc.util.Constants.ANC_MEMBER_OBJECTS.FAMILY_HEAD_PHONE, familyHeadPhone);
intent.putExtra(TITLE_VIEW_TEXT, String.format(getString(R.string.return_to_family_name), ""));
startActivity(intent);
}

protected abstract Class<?> getFamilyOtherMemberProfileActivityClass();

protected abstract Class<? extends CoreAboveFiveChildProfileActivity> getAboveFiveChildProfileActivityClass();

protected abstract Class<? extends CoreChildProfileActivity> getChildProfileActivityClass();

protected abstract Class<? extends BaseAncMemberProfileActivity> getAncMemberProfileActivityClass();

protected abstract Class<? extends BasePncMemberProfileActivity> getPncMemberProfileActivityClass();

protected abstract boolean isAncMember(String baseEntityId);

protected abstract HashMap<String, String> getAncFamilyHeadNameAndPhone(String baseEntityId);

protected abstract CommonPersonObject getAncCommonPersonObject(String baseEntityId);

protected abstract CommonPersonObject getPncCommonPersonObject(String baseEntityId);

protected abstract boolean isPncMember(String baseEntityId);

@Override
protected abstract void initializePresenter();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public String getFamilyName() {
return familyName;
}

public String getFamilyHeadBaseEntityId() { return familyHead; }

@Override
public void updateFamilyMember(String jsonString) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,30 @@
import org.apache.commons.lang3.tuple.Triple;
import org.json.JSONObject;
import org.smartregister.chw.core.R;
import org.smartregister.chw.core.application.CoreChwApplication;
import org.smartregister.chw.core.contract.CoreChildRegisterContract;
import org.smartregister.chw.core.contract.FamilyProfileExtendedContract;
import org.smartregister.chw.core.domain.FamilyMember;
import org.smartregister.chw.core.interactor.CoreChildRegisterInteractor;
import org.smartregister.chw.core.interactor.CoreFamilyProfileInteractor;
import org.smartregister.chw.core.model.CoreChildProfileModel;
import org.smartregister.chw.core.model.CoreChildRegisterModel;
import org.smartregister.chw.core.repository.AncRegisterRepository;
import org.smartregister.chw.core.repository.PncRegisterRepository;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.core.utils.CoreJsonFormUtils;
import org.smartregister.chw.core.utils.Utils;
import org.smartregister.clientandeventmodel.Client;
import org.smartregister.clientandeventmodel.Event;
import org.smartregister.commonregistry.CommonPersonObject;
import org.smartregister.commonregistry.CommonPersonObjectClient;
import org.smartregister.family.contract.FamilyProfileContract;
import org.smartregister.family.domain.FamilyEventClient;
import org.smartregister.family.presenter.BaseFamilyProfilePresenter;
import org.smartregister.view.LocationPickerView;

import java.lang.ref.WeakReference;
import java.util.HashMap;

import timber.log.Timber;

Expand Down Expand Up @@ -157,4 +162,32 @@ public boolean updatePrimaryCareGiver(Context context, String jsonString, String
}
return res;
}

public boolean isAncMember(String baseEntityId) {
return getAncRegisterRepository().checkIfAncWoman(baseEntityId);
}

public HashMap<String, String> getAncFamilyHeadNameAndPhone(String baseEntityId) {
return getAncRegisterRepository().getFamilyNameAndPhone(baseEntityId);
}

public CommonPersonObject getAncCommonPersonObject(String baseEntityId) {
return getAncRegisterRepository().getAncCommonPersonObject(baseEntityId);
}

public CommonPersonObject getPncCommonPersonObject(String baseEntityId) {
return getPncRegisterRepository().getPncCommonPersonObject(baseEntityId);
}

public boolean isPncMember(String baseEntityId) {
return getPncRegisterRepository().checkIfPncWoman(baseEntityId);
}

private AncRegisterRepository getAncRegisterRepository() {
return CoreChwApplication.ancRegisterRepository();
}

private PncRegisterRepository getPncRegisterRepository() {
return CoreChwApplication.pncRegisterRepository();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

import org.smartregister.chw.anc.util.Constants;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.core.utils.CoreReferralUtils;
import org.smartregister.chw.core.utils.Utils;
import org.smartregister.commonregistry.CommonPersonObject;
import org.smartregister.family.util.DBConstants;
import org.smartregister.repository.BaseRepository;
import org.smartregister.repository.Repository;

import java.util.ArrayList;
import java.util.HashMap;

import timber.log.Timber;
Expand Down Expand Up @@ -155,4 +159,38 @@ public int getAncPncWomenCount(String familyBaseID, String register) {
return 0;

}

public CommonPersonObject getAncCommonPersonObject(String baseEntityId) {
SQLiteDatabase database = getReadableDatabase();
Cursor cursor = null;
CommonPersonObject personObject = null;

ArrayList<String> tablesOfInterestList = new ArrayList<>();
tablesOfInterestList.add(CoreConstants.TABLE_NAME.FAMILY);
tablesOfInterestList.add(CoreConstants.TABLE_NAME.ANC_MEMBER);

// NOTE: Doing this so that we avoid possible bugs when passing/determining the indices for respective tables to be used in the building the query
String[] tablesOfInterest = new String[tablesOfInterestList.size()];
tablesOfInterest = tablesOfInterestList.toArray(tablesOfInterest);

String query = CoreReferralUtils.mainAncDetailsSelect(tablesOfInterest, tablesOfInterestList.indexOf(CoreConstants.TABLE_NAME.FAMILY), tablesOfInterestList.indexOf(CoreConstants.TABLE_NAME.ANC_MEMBER), baseEntityId);
Timber.d("ANC Member CommonPersonObject Query %s", query);

try {
if (database == null) {
return null;
}
cursor = database.rawQuery(query, null);
if (cursor != null && cursor.moveToFirst()) {
personObject = Utils.context().commonrepository(CoreConstants.TABLE_NAME.ANC_MEMBER).readAllcommonforCursorAdapter(cursor);
}
} catch (Exception ex) {
Timber.e(ex);
} finally {
if (cursor != null) {
cursor.close();
}
}
return personObject;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.smartregister.chw.core.repository;

import net.sqlcipher.Cursor;
import net.sqlcipher.database.SQLiteDatabase;

import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.core.utils.CoreReferralUtils;
import org.smartregister.chw.core.utils.Utils;
import org.smartregister.commonregistry.CommonPersonObject;
import org.smartregister.family.util.DBConstants;
import org.smartregister.repository.BaseRepository;
import org.smartregister.repository.Repository;

import timber.log.Timber;

public class PncRegisterRepository extends BaseRepository {

public static final String TABLE_NAME = CoreConstants.TABLE_NAME.PNC_MEMBER;
public static final String BASE_ENTITY_ID = "base_entity_id";
public static final String IS_CLOSED = "is_closed";
public static final String DELIVERY_DATE = "delivery_date";
public static final String LAST_VISIT_DATE = "last_visit_date";
public static final String[] PNC_COUNT_TABLE_COLUMNS = {BASE_ENTITY_ID};

public PncRegisterRepository(Repository repository) {
super(repository);
}

public boolean checkIfPncWoman(String baseEntityId) {
SQLiteDatabase database = getReadableDatabase();
Cursor cursor = null;
try {
if (database == null) {
return false;
}
String selection = DBConstants.KEY.BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE + " AND " +
org.smartregister.chw.anc.util.DBConstants.KEY.IS_CLOSED + " = ? " + COLLATE_NOCASE;
String[] selectionArgs = new String[]{baseEntityId, "0"};
cursor = database.query(CoreConstants.TABLE_NAME.PNC_MEMBER, PNC_COUNT_TABLE_COLUMNS, selection, selectionArgs, null, null, null);
if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) {
return true;
}
} catch (Exception e) {
Timber.e(e);
} finally {
if (cursor != null) {
cursor.close();
}
}
return false;
}

public CommonPersonObject getPncCommonPersonObject(String baseEntityId) {
SQLiteDatabase database = getReadableDatabase();
Cursor cursor = null;
CommonPersonObject personObject = null;
String query = CoreReferralUtils.pncFamilyMemberProfileDetailsSelect(CoreConstants.TABLE_NAME.FAMILY, baseEntityId);
Timber.d("PNC Member CommonPersonObject Query %s", query);

try {
if (database == null) {
return null;
}
cursor = database.rawQuery(query, null);
if (cursor != null && cursor.moveToFirst()) {
personObject = Utils.context().commonrepository(CoreConstants.TABLE_NAME.FAMILY).readAllcommonforCursorAdapter(cursor);
}
} catch (Exception ex) {
Timber.e(ex);
} finally {
if (cursor != null) {
cursor.close();
}
}
return personObject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ public static class JsonAssets {
public static final String NUTRITION_STATUS = "nutrition_status";
public static final String GESTATION_AGE = "gestation_age";
public static final String IS_PROBLEM = "is_problem";
public static final String REFERRAL_CODE = "Referral";


public static class FAMILY_MEMBER {
Expand Down
Loading

0 comments on commit 61c212f

Please sign in to comment.