diff --git a/opensrp-chw-malaria/build.gradle b/opensrp-chw-malaria/build.gradle index a3ec19e..f4d368c 100644 --- a/opensrp-chw-malaria/build.gradle +++ b/opensrp-chw-malaria/build.gradle @@ -111,6 +111,7 @@ dependencies { testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.+' + testImplementation 'org.robolectric:robolectric:3.8' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java index e1d9611..8f07507 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java @@ -20,11 +20,18 @@ import org.smartregister.malaria.R; import org.smartregister.view.activity.BaseProfileActivity; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + public class BaseMalariaProfileActivity extends BaseProfileActivity implements MalariaProfileContract.View { protected MemberObject MEMBER_OBJECT; private BaseMalariaProfilePresenter profilePresenter; - private TextView textViewName, textViewGender, textViewLocation, textViewUniqueID; + private TextView textViewName, textViewGender, textViewLocation, textViewUniqueID, textViewRecordMalaria; + private View recordMalariaView; + private View.OnClickListener onClickListener; public static void startProfileActivity(Activity activity, MemberObject memberObject) { Intent intent = new Intent(activity, BaseMalariaProfileActivity.class); @@ -60,6 +67,11 @@ public void onClick(View v) { textViewGender = findViewById(R.id.textview_gender); textViewLocation = findViewById(R.id.textview_address); textViewUniqueID = findViewById(R.id.textview_id); + recordMalariaView = findViewById(R.id.record_visit_malaria); + + textViewRecordMalaria = findViewById(R.id.textview_record_malaria); + textViewRecordMalaria.setOnClickListener(onClickListener); + MEMBER_OBJECT = (MemberObject) getIntent().getSerializableExtra(Constants.MALARIA_MEMBER_OBJECT.MEMBER_OBJECT); @@ -78,6 +90,19 @@ public void setProfileViewWithData() { textViewGender.setText(MEMBER_OBJECT.getGender()); textViewLocation.setText(MEMBER_OBJECT.getAddress()); textViewUniqueID.setText(MEMBER_OBJECT.getUniqueId()); + + if (MEMBER_OBJECT.getMalariaTestDate() != null) { + try { + Date date = + new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).parse((MEMBER_OBJECT.getMalariaTestDate())); + int malaria_test_date_processed = new Period(new DateTime(date), new DateTime()).getDays(); + profilePresenter.recordMalariaButton(malaria_test_date_processed, + textViewRecordMalaria, recordMalariaView,this); + } catch (ParseException e) { + e.printStackTrace(); + } + } + } @@ -98,8 +123,11 @@ protected void fetchProfileData() { @Override public void onClick(View view) { - if (view.getId() == R.id.title_layout) { + int id = view.getId(); + if (id == R.id.title_layout) { onBackPressed(); + } else if (id == R.id.textview_record_malaria) { + profilePresenter.recordMalariaFollowUp(this); } } diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/domain/MemberObject.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/domain/MemberObject.java index 47250b0..c8de17c 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/domain/MemberObject.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/domain/MemberObject.java @@ -13,6 +13,19 @@ public class MemberObject implements Serializable { private String gender; private String uniqueId; private String age; + private String relationalid; + private String details; + private boolean isClosed; + private String dateChwMalariaTest; + private String feverMalariaChw; + private String feverDuration; + private String dateHfMalariaTest; + private String malariaTestDate; + private String malariaTreat; + private String famLlin; + private String llin2Days; + private String llinCondition; + private String malariaEduChw; private String baseEntityId; private String relationalId; private String primaryCareGiver; @@ -32,6 +45,19 @@ public MemberObject(CommonPersonObjectClient client) { primaryCareGiver = client.getColumnmaps().get(DBConstants.KEY.PRIMARY_CARE_GIVER); familyHead = client.getColumnmaps().get(DBConstants.KEY.FAMILY_HEAD); familyBaseEntityId = client.getColumnmaps().get(DBConstants.KEY.FAMILY_BASE_ENTITY_ID); + relationalid = client.getColumnmaps().get(DBConstants.KEY.RELATIONALID); + details = client.getColumnmaps().get(DBConstants.KEY.DETAILS); + isClosed = Boolean.parseBoolean(client.getColumnmaps().get(DBConstants.KEY.IS_CLOSED)); + dateChwMalariaTest = client.getColumnmaps().get(DBConstants.KEY.DATE_CHW_MALARIA_TEST); + feverMalariaChw = client.getColumnmaps().get(DBConstants.KEY.FEVER_MALARIA_CHW); + feverDuration = client.getColumnmaps().get(DBConstants.KEY.FEVER_DURATION); + dateHfMalariaTest = client.getColumnmaps().get(DBConstants.KEY.DATE_HF_MALARIA_TEST); + malariaTestDate = client.getColumnmaps().get(DBConstants.KEY.MALARIA_TEST_DATE); + malariaTreat = client.getColumnmaps().get(DBConstants.KEY.MALARIA_TREAT); + famLlin = client.getColumnmaps().get(DBConstants.KEY.FAM_LLIN); + llin2Days = client.getColumnmaps().get(DBConstants.KEY.LLIN_2DAYS); + llinCondition = client.getColumnmaps().get(DBConstants.KEY.LLIN_CONDITION); + malariaEduChw = client.getColumnmaps().get(DBConstants.KEY.MALARIA_EDU_CHW); } public String getFirstName() { return firstName; @@ -89,6 +115,110 @@ public void setUniqueId(String uniqueId) { this.uniqueId = uniqueId; } + public String getRelationalid() { + return relationalid; + } + + public void setRelationalid(String relationalid) { + this.relationalid = relationalid; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + public boolean getIsClosed() { + return isClosed; + } + + public void setIsClosed(boolean isClosed) { + this.isClosed = isClosed; + } + + public String getDateChwMalariaTest() { + return dateChwMalariaTest; + } + + public void setDateChwMalariaTest(String dateChwMalariaTest) { + this.dateChwMalariaTest = dateChwMalariaTest; + } + + public String getFeverMalariaChw() { + return feverMalariaChw; + } + + public void setFeverMalariaChw(String feverMalariaChw) { + this.feverMalariaChw = feverMalariaChw; + } + + public String getFeverDuration() { + return feverDuration; + } + + public void setFeverDuration(String feverDuration) { + this.feverDuration = feverDuration; + } + + public String getDateHfMalariaTest() { + return dateHfMalariaTest; + } + + public void setDateHfMalariaTest(String dateHfMalariaTest) { + this.dateHfMalariaTest = dateHfMalariaTest; + } + + public String getMalariaTestDate() { + return malariaTestDate; + } + + public void setMalariaTestDate(String malariaTestDate) { + this.malariaTestDate = malariaTestDate; + } + + public String getMalariaTreat() { + return malariaTreat; + } + + public void setMalariaTreat(String malariaTreat) { + this.malariaTreat = malariaTreat; + } + + public String getFamLlin() { + return famLlin; + } + + public void setFamLlin(String famLlin) { + this.famLlin = famLlin; + } + + public String getLlin2Days() { + return llin2Days; + } + + public void setLlin2Days(String llin2Days) { + this.llin2Days = llin2Days; + } + + public String getLlinCondition() { + return llinCondition; + } + + public void setLlinCondition(String llinCondition) { + this.llinCondition = llinCondition; + } + + public String getMalariaEduChw() { + return malariaEduChw; + } + + public void setMalariaEduChw(String malariaEduChw) { + this.malariaEduChw = malariaEduChw; + } + public String getBaseEntityId() { return baseEntityId; } diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java index 0bde527..d9ecbb1 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java @@ -1,9 +1,13 @@ package org.smartregister.chw.malaria.presenter; import android.content.Context; +import android.support.v4.content.ContextCompat; +import android.view.View; +import android.widget.Toast; import org.smartregister.chw.malaria.contract.MalariaProfileContract; import org.smartregister.chw.malaria.domain.MemberObject; +import org.smartregister.malaria.R; public class BaseMalariaProfilePresenter { @@ -31,4 +35,39 @@ public void fillProfileData(MemberObject memberObject) { view.setProfileViewWithData(); } } + + public void recordMalariaButton(int days_from_malaria_test_date, View view, + View viewContainer, Context context) { + if(days_from_malaria_test_date >= 7 && days_from_malaria_test_date < 10) { + changeViewColor(view, context, R.color.due_profile_blue); + toggleViewVisibility(viewContainer, true); + + } else if (days_from_malaria_test_date >= 10){ + changeViewColor(view, context, R.color.visit_status_over_due); + toggleViewVisibility(viewContainer, true); + } + toggleViewVisibility(viewContainer, false); + } + + + public void recordMalariaFollowUp(Context context) { + //call the form from this function + Toast.makeText(context, "Record Malaria", Toast.LENGTH_SHORT).show(); + } + + public void changeViewColor(View view, Context context, int color) { + view.setBackgroundColor(ContextCompat.getColor(context, + color)); + + } + + private void toggleViewVisibility(View view, Boolean show) { + if(show) { + view.setVisibility(View.VISIBLE); + } else { + view.setVisibility(View.GONE); + } + + } + } diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/util/DBConstants.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/util/DBConstants.java index f3ec49e..6c33332 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/util/DBConstants.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/util/DBConstants.java @@ -18,6 +18,20 @@ public final class KEY { public static final String VILLAGE_TOWN = "village_town"; public static final String DATE_REMOVED = "date_removed"; public static final String GENDER = "gender"; + public static final String RELATIONALID = "relationalid"; + public static final String DETAILS = "details"; + public static final String IS_CLOSED = "is_closed"; + public static final String DATE_CHW_MALARIA_TEST = "date_chw_malaria_test"; + public static final String FEVER_MALARIA_CHW = "fever_malaria_chw"; + public static final String FEVER_DURATION = "fever_duration"; + public static final String MALARIA_RESULTS = "malaria_results"; + public static final String DATE_HF_MALARIA_TEST = "date_hf_malaria_test"; + public static final String MALARIA_TEST_DATE = "malaria_test_date"; + public static final String MALARIA_TREAT = "malaria_treat"; + public static final String FAM_LLIN = "fam_llin"; + public static final String LLIN_2DAYS = "llin_2days"; + public static final String LLIN_CONDITION = "llin_condition"; + public static final String MALARIA_EDU_CHW = "malaria_edu_chw"; public static final String RELATIONAL_ID = "relational_id"; public static final String FAMILY_HEAD = "family_head"; public static final String PRIMARY_CARE_GIVER = "primary_caregiver"; diff --git a/opensrp-chw-malaria/src/main/res/values/colors.xml b/opensrp-chw-malaria/src/main/res/values/colors.xml index 6dd30b3..37f0001 100644 --- a/opensrp-chw-malaria/src/main/res/values/colors.xml +++ b/opensrp-chw-malaria/src/main/res/values/colors.xml @@ -23,4 +23,6 @@ #000000 #FAFAFA @android:color/holo_blue_light + + #D13F3F diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java index d17c277..1196a32 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java @@ -1,11 +1,16 @@ package org.smartregister.presenter; +import android.content.Context; +import android.widget.TextView; + import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; + import org.smartregister.chw.malaria.contract.MalariaProfileContract; import org.smartregister.chw.malaria.domain.MemberObject; import org.smartregister.chw.malaria.presenter.BaseMalariaProfilePresenter; +import org.smartregister.malaria.R; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -14,15 +19,30 @@ public class BaseMalariaProfilePresenterTest { @Mock private MalariaProfileContract.View view = Mockito.mock(MalariaProfileContract.View.class); + @Mock + private TextView androidView = Mockito.mock(TextView.class); + private TextView androidView2 = Mockito.mock(TextView.class); + @Mock private BaseMalariaProfilePresenter profilePresenter = Mockito.mock(BaseMalariaProfilePresenter.class); @Mock private MemberObject memberObject = Mockito.mock(MemberObject.class); + @Mock + private Context context = Mockito.mock(Context.class); + @Test public void fillProfileDataDoesntCallsSetProfileViewWithDataIfMemberObjectEmpty() { profilePresenter.fillProfileData(memberObject); verify(view, never()).setProfileViewWithData(); } + + @Test + public void malariaTestDatePeriodIsNotBetweenSevenAndTenAndNotGreaterThanTen() { + profilePresenter.recordMalariaButton(4, androidView, androidView2, context); + verify(profilePresenter, never()).changeViewColor(androidView, context, + R.color.due_profile_blue); + } + }