Skip to content

Commit

Permalink
Merge branch '#20-implement-malaria-follo-up-visit' into apk-release1
Browse files Browse the repository at this point in the history
# Conflicts:
#	opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/domain/MemberObject.java
#	opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/util/DBConstants.java
#	opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java
  • Loading branch information
whoisladleo committed Jul 4, 2019
2 parents f6ba3d6 + 348b97f commit 1379a3e
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 2 deletions.
1 change: 1 addition & 0 deletions opensrp-chw-malaria/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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();
}
}

}


Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions opensrp-chw-malaria/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
<color name="black">#000000</color>
<color name="light_gray">#FAFAFA</color>
<color name="visit_status_ok">@android:color/holo_blue_light</color>

<color name="visit_status_over_due">#D13F3F</color>
</resources>
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

}

0 comments on commit 1379a3e

Please sign in to comment.