Skip to content

Commit

Permalink
Merge pull request #151 from OpenSRP/customizations-unicef-angola
Browse files Browse the repository at this point in the history
Customizations for UNICEF Angola
  • Loading branch information
hamza-vd authored Dec 4, 2020
2 parents 387914f + 96994da commit 92cdd80
Show file tree
Hide file tree
Showing 16 changed files with 411 additions and 23 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ To use this approach, the file name should contain the name of the category as t

Note that you can have any number of underscores and the filename must end in __vaccines.json_ . By default, only **Child** and **Woman** category vaccines are supported by the library

## Overdue status indication

The current default background indication color for overdue vaccines is red and due is blue. Setting the following property to `true` will disable the indication colors for overdue and due vaccines and will be shown with only white background color.

```
hide.overdue.vaccine.status=true
```

## Gotcha's when using the library

1. Vaccine schedule not changing after changing the `vaccines.json` file!
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=3.0.0-SNAPSHOT
VERSION_NAME=3.0.1-SNAPSHOT
VERSION_CODE=2
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Immunization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ public boolean isExpiredVaccineCardRed() {
return getProperties().isTrue(IMConstants.APP_PROPERTIES.EXPIRED_CARD_AS_RED);
}

public boolean hideOverdueVaccineStatus() {
return getProperties().hasProperty(IMConstants.APP_PROPERTIES.HIDE_OVERDUE_VACCINE_STATUS) && instance.getProperties().getPropertyBoolean(IMConstants.APP_PROPERTIES.HIDE_OVERDUE_VACCINE_STATUS);
}

public long getVaccineSyncTime() {
if (vaccineSyncTime == -1) {
setVaccineSyncTime(BuildConfig.VACCINE_SYNC_TIME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class APP_PROPERTIES {
public static final String VACCINE_EXPIRED_ENTRY_ALLOW = "vaccine.expired.entry.allow";
public static final String VACCINE_REQUISITE_DATE_CONSTRAINT_ENABLED = "vaccine.requisite.date.constraint.enabled";
public static final String EXPIRED_CARD_AS_RED = "vaccine.expired.red";
public static final String HIDE_OVERDUE_VACCINE_STATUS = "hide.overdue.vaccine.status";
public static final String VACCINE_SYNC_IMMEDIATE = "vaccine.sync.immediate";
public static final String NOVEL_OUT_OF_CATCHMENT = "novel.out.of.catchment";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ private static void processVaccineGroup(VaccineGroup vaccineGroup, String catego
if (vaccineGroup.id.equals("Birth") && category.equals(IMConstants.VACCINE_TYPE.CHILD)) {
List<Vaccine> vaccinesList = VaccinatorUtils.getSpecialVaccines(ImmunizationLibrary.getInstance().context().applicationContext());

for (Vaccine vaccine : vaccinesList) {
if (vaccineGroup.vaccines == null) {
vaccineGroup.vaccines = new ArrayList<>();
}
if (vaccinesList != null)
for (Vaccine vaccine : vaccinesList) {
if (vaccineGroup.vaccines == null) {
vaccineGroup.vaccines = new ArrayList<>();
}

vaccineGroup.vaccines.add(vaccine);
}
vaccineGroup.vaccines.add(vaccine);
}
}

for (Vaccine vaccine : vaccineGroup.vaccines) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ private void updateStateUi() {

case DUE:
setBackgroundResource(R.drawable.vaccine_card_background_white);
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_blue);
if (ImmunizationLibrary.getInstance().hideOverdueVaccineStatus()) {
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_white);
} else {
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_blue);
}
undoB.setVisibility(INVISIBLE);
nameTV.setVisibility(VISIBLE);
nameTV.setText(getVaccineName());
Expand Down Expand Up @@ -212,7 +216,11 @@ private void updateStateUi() {

case OVERDUE:
setBackgroundResource(R.drawable.vaccine_card_background_white);
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_red);
if (ImmunizationLibrary.getInstance().hideOverdueVaccineStatus()) {
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_white);
} else {
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_red);
}
undoB.setVisibility(INVISIBLE);
nameTV.setVisibility(VISIBLE);
nameTV.setText(getVaccineName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.joda.time.DateTime;
import org.smartregister.domain.Alert;
import org.smartregister.immunization.ImmunizationLibrary;
import org.smartregister.immunization.R;
import org.smartregister.immunization.domain.ServiceWrapper;
import org.smartregister.immunization.domain.State;
Expand Down Expand Up @@ -176,11 +177,16 @@ private void updateStateUi() {
setVisibility(VISIBLE);
break;
case DUE:
setBackgroundResource(R.drawable.vaccine_card_background_blue);
if (ImmunizationLibrary.getInstance().hideOverdueVaccineStatus()) {
setBackgroundResource(R.drawable.vaccine_card_background_white);
nameTV.setTextColor(context.getResources().getColor(R.color.silver));
} else {
setBackgroundResource(R.drawable.vaccine_card_background_blue);
nameTV.setTextColor(context.getResources().getColor(android.R.color.white));
}
statusIV.setVisibility(GONE);
undoB.setVisibility(GONE);
nameTV.setVisibility(VISIBLE);
nameTV.setTextColor(context.getResources().getColor(android.R.color.white));
nameTV.setText(String.format(context.getString(R.string.record_), getServiceName()));
break;
case DONE_CAN_BE_UNDONE:
Expand All @@ -206,11 +212,16 @@ private void updateStateUi() {
nameTV.setText(getServiceName() + " - " + DATE_FORMAT.format(getDateDone()));
break;
case OVERDUE:
setBackgroundResource(R.drawable.vaccine_card_background_red);
if (ImmunizationLibrary.getInstance().hideOverdueVaccineStatus()) {
setBackgroundResource(R.drawable.vaccine_card_background_white);
nameTV.setTextColor(context.getResources().getColor(R.color.silver));
} else {
setBackgroundResource(R.drawable.vaccine_card_background_red);
nameTV.setTextColor(context.getResources().getColor(android.R.color.white));
}
statusIV.setVisibility(GONE);
undoB.setVisibility(GONE);
nameTV.setVisibility(VISIBLE);
nameTV.setTextColor(context.getResources().getColor(android.R.color.white));
String serviceName = getServiceName();
if (getDateDue() != null) {
nameTV.setText(String.format(context.getString(R.string.record_due_),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.joda.time.DateTime;
import org.smartregister.domain.Alert;
import org.smartregister.immunization.ImmunizationLibrary;
import org.smartregister.immunization.R;
import org.smartregister.immunization.domain.ServiceWrapper;
import org.smartregister.immunization.domain.State;
Expand Down Expand Up @@ -186,7 +187,11 @@ private void updateStateUi() {
break;
case DUE:
setBackgroundResource(R.drawable.vaccine_card_background_white);
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_blue);
if (ImmunizationLibrary.getInstance().hideOverdueVaccineStatus()) {
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_white);
} else {
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_blue);
}
undoB.setVisibility(INVISIBLE);
nameTV.setVisibility(VISIBLE);
nameTV.setText(getVaccineName());
Expand Down Expand Up @@ -218,7 +223,11 @@ private void updateStateUi() {
break;
case OVERDUE:
setBackgroundResource(R.drawable.vaccine_card_background_white);
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_red);
if (ImmunizationLibrary.getInstance().hideOverdueVaccineStatus()) {
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_white);
} else {
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_red);
}
undoB.setVisibility(INVISIBLE);
nameTV.setVisibility(VISIBLE);
nameTV.setText(getVaccineName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,16 @@ private void updateStateUi() {
nameTV.setText(getVaccineName());
break;
case DUE:
setBackgroundResource(R.drawable.vaccine_card_background_blue);
if (ImmunizationLibrary.getInstance().hideOverdueVaccineStatus()) {
setBackgroundResource(R.drawable.vaccine_card_background_white);
nameTV.setTextColor(context.getResources().getColor(R.color.silver));
} else {
setBackgroundResource(R.drawable.vaccine_card_background_blue);
nameTV.setTextColor(context.getResources().getColor(android.R.color.white));
}
statusIV.setVisibility(GONE);
undoB.setVisibility(GONE);
nameTV.setVisibility(VISIBLE);
nameTV.setTextColor(context.getResources().getColor(android.R.color.white));
String vaccineName = getVaccineName();
nameTV.setText(String.format(context.getString(R.string.record_), vaccineName));
if (vaccineName.toLowerCase().contains("measles") || vaccineName.toLowerCase().contains("mr")) {
Expand Down Expand Up @@ -220,11 +225,16 @@ private void updateStateUi() {

break;
case OVERDUE:
setBackgroundResource(R.drawable.vaccine_card_background_red);
if (ImmunizationLibrary.getInstance().hideOverdueVaccineStatus()) {
setBackgroundResource(R.drawable.vaccine_card_background_white);
nameTV.setTextColor(context.getResources().getColor(R.color.silver));
} else {
setBackgroundResource(R.drawable.vaccine_card_background_red);
nameTV.setTextColor(context.getResources().getColor(android.R.color.white));
}
statusIV.setVisibility(GONE);
undoB.setVisibility(GONE);
nameTV.setVisibility(VISIBLE);
nameTV.setTextColor(context.getResources().getColor(android.R.color.white));
String vName = getVaccineName();
nameTV.setText(String.format(context.getString(R.string.record_due_),
vName, DATE_FORMAT.format(getDateDue())));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners android:radius="3dp" />
<gradient
android:angle="0"
android:endColor="@color/vaccine_grey_bg_end"
android:startColor="@color/vaccine_grey_bg_st" />
<stroke
android:width="0.5dp"
android:color="@color/vaccine_grey_bg_stk" />
</shape>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.smartregister.CoreLibrary;
import org.smartregister.immunization.BaseUnitTest;
import org.smartregister.immunization.R;
import org.smartregister.immunization.customshadows.FontTextViewShadow;
Expand Down Expand Up @@ -46,7 +45,6 @@ public class UndoServiceDialogFragmentTest extends BaseUnitTest {
public void setUp() {

org.mockito.MockitoAnnotations.initMocks(this);
CoreLibrary.init(context_);

Mockito.doReturn(properties).when(context_).getAppProperties();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.smartregister.immunization.view;

import android.widget.Button;

import org.joda.time.DateTime;
import org.json.JSONObject;
import org.junit.Assert;
Expand All @@ -11,6 +13,7 @@
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.powermock.reflect.Whitebox;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
Expand All @@ -20,6 +23,7 @@
import org.smartregister.domain.Event;
import org.smartregister.immunization.BaseUnitTest;
import org.smartregister.immunization.ImmunizationLibrary;
import org.smartregister.immunization.R;
import org.smartregister.immunization.customshadows.FontTextViewShadow;
import org.smartregister.immunization.domain.State;
import org.smartregister.immunization.domain.Vaccine;
Expand Down Expand Up @@ -48,6 +52,8 @@ public class ImmunizationRowCardTest extends BaseUnitTest {
public PowerMockRule rule = new PowerMockRule();
private ImmunizationRowCard view;

private ImmunizationLibrary immunizationLibrary;

@Before
public void setUp() throws Exception {
org.mockito.MockitoAnnotations.initMocks(this);
Expand All @@ -63,7 +69,7 @@ public void setUp() throws Exception {
event.setDateCreated(new DateTime());

PowerMockito.mockStatic(ImmunizationLibrary.class);
ImmunizationLibrary immunizationLibrary = Mockito.mock(ImmunizationLibrary.class);
immunizationLibrary = Mockito.mock(ImmunizationLibrary.class);
VaccineRepository vaccineRepository = Mockito.mock(VaccineRepository.class);
ImmunizationLibrary.init(Mockito.mock(org.smartregister.Context.class), Mockito.mock(Repository.class),
Mockito.mock(CommonFtsObject.class), 0, 0);
Expand Down Expand Up @@ -163,4 +169,67 @@ public void assertgetStateCallsUpdateStateReturnsWrapperState() throws Exception
Assert.assertEquals(view.getState(), State.DONE_CAN_BE_UNDONE);
}

@Test
public void testHideVaccineOverdueRowCardColor() {
PowerMockito.when(immunizationLibrary.hideOverdueVaccineStatus()).thenReturn(true);

Alert alert = new Alert("", "", "", AlertStatus.urgent, "", "");
VaccineWrapper wrapper = new VaccineWrapper();
wrapper.setSynced(true);
wrapper.setStatus(magicDue);
wrapper.setAlert(alert);
wrapper.setName(magicMR);
wrapper.setVaccineDate(new DateTime());

ImmunizationRowCard rowCard = Mockito.spy(view);
Button statusIV = Mockito.mock(Button.class);
Whitebox.setInternalState(rowCard, "statusIV", statusIV);
rowCard.setVaccineWrapper(wrapper);

Mockito.verify(statusIV).setBackgroundResource(R.drawable.vaccine_card_background_white);

alert = new Alert("", "", "", AlertStatus.normal, "", "");
wrapper.setSynced(true);
wrapper.setStatus(magicDue);
wrapper.setAlert(alert);
wrapper.setName(magicMR);
wrapper.setVaccineDate(new DateTime());
wrapper.setDbKey(0L);
rowCard.setVaccineWrapper(wrapper);

Mockito.verify(statusIV, Mockito.times(2)).setBackgroundResource(R.drawable.vaccine_card_background_white);

}

@Test
public void testShowVaccineOverdueRowCardColor() {
PowerMockito.when(immunizationLibrary.hideOverdueVaccineStatus()).thenReturn(false);

Alert alert = new Alert("", "", "", AlertStatus.urgent, "", "");
VaccineWrapper wrapper = new VaccineWrapper();
wrapper.setSynced(true);
wrapper.setStatus(magicDue);
wrapper.setAlert(alert);
wrapper.setName(magicMR);
wrapper.setVaccineDate(new DateTime());

ImmunizationRowCard rowCard = Mockito.spy(view);
Button statusIV = Mockito.mock(Button.class);
Whitebox.setInternalState(rowCard, "statusIV", statusIV);
rowCard.setVaccineWrapper(wrapper);

Mockito.verify(statusIV).setBackgroundResource(R.drawable.vaccine_card_background_red);

alert = new Alert("", "", "", AlertStatus.normal, "", "");
wrapper.setSynced(true);
wrapper.setStatus(magicDue);
wrapper.setAlert(alert);
wrapper.setName(magicMR);
wrapper.setVaccineDate(new DateTime());
wrapper.setDbKey(0L);
rowCard.setVaccineWrapper(wrapper);

Mockito.verify(statusIV).setBackgroundResource(R.drawable.vaccine_card_background_blue);
}

}
Loading

0 comments on commit 92cdd80

Please sign in to comment.