Skip to content

Commit

Permalink
Merge eb4c92e into 83b3eca
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Sep 16, 2020
2 parents 83b3eca + eb4c92e commit 1a82fe1
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 52 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,6 @@ vaccine.requisite.date.constraint.enabled=true
1. Vaccine schedule not changing after changing the `vaccines.json` file!

Some of the vaccine configurations are not dependent on change done to the `vaccines.json`, in this case you should check the current configuration [here](https://github.com/OpenSRP/opensrp-client-immunization/blob/67a15611b53c55e111a0b7bff4f32a02c27b2920/opensrp-immunization/src/main/java/org/smartregister/immunization/db/VaccineRepo.java#L37)
and come-up with the correct configuration. Next step is to add the custom configuration to library. You should loop through the configurations array from `VaccineRepo.Vaccine[] ImmunizationLibrary.getInstance().getVaccines()` and add
modify the properties of the vaccine enum to whatever you need. You should then use `ImmunizationLibrary.getInstance().setVaccines(VaccineRepo.Vaccine[])`
and come-up with the correct configuration. Next step is to add the custom configuration to library. You should loop through the configurations array from `VaccineRepo.Vaccine[] ImmunizationLibrary.getInstance().getVaccines(category)` and add
modify the properties of the vaccine enum to whatever you need. You should then use `ImmunizationLibrary.getInstance().setVaccines(VaccineRepo.Vaccine[], category)`
to re-set all the vaccine configs using the configurations array you retrieved.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=1.4.48-SNAPSHOT
VERSION_NAME=2.0.0-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 @@ -49,7 +49,7 @@ public class ImmunizationLibrary {

public static List<String> COMBINED_VACCINES = new ArrayList<>();
public static Map<String, String> COMBINED_VACCINES_MAP = new HashMap<>();
private Map<String, String> conditionalVaccinesMap = new HashMap<>();
private Map<String, String> conditionalVaccinesMap = new HashMap<>();
private String currentConditionalVaccine;

private long vaccineSyncTime = -1;
Expand Down Expand Up @@ -169,12 +169,21 @@ public AppProperties getProperties() {
return ImmunizationLibrary.getInstance().context().getAppProperties();
}

public void setVaccines(VaccineRepo.Vaccine[] vaccines) {
this.vaccineCacheMap.get(IMConstants.VACCINE_TYPE.CHILD).vaccines = vaccines;
/**
* @param vaccines the vaccines repo enum values
* @param category the category the vaccines are for e.g. CHILD, WOMAN
*/
public void setVaccines(VaccineRepo.Vaccine[] vaccines, String category) {
this.vaccineCacheMap.get(category).vaccines = vaccines;
}

public VaccineRepo.Vaccine[] getVaccines() {
return this.vaccineCacheMap.get(IMConstants.VACCINE_TYPE.CHILD).vaccines;
/**
* @param category the category of the vaccines to be retrieved
* returns an array of the vaccines from the specified category
*/
public VaccineRepo.Vaccine[]
getVaccines(String category) {
return this.vaccineCacheMap.get(category).vaccines;
}

public boolean isAllowExpiredVaccineEntry() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
import org.smartregister.immunization.ImmunizationLibrary;

import java.util.ArrayList;
import java.util.List;

public class VaccineRepo {

public static ArrayList<Vaccine> getVaccines(String category) {
public static List<Vaccine> getVaccines(String category) {
return getVaccines(category, false);
}

public static ArrayList<Vaccine> getVaccines(String category, boolean useDefault) {
public static List<Vaccine> getVaccines(String category, boolean useDefault) {
ArrayList<Vaccine> vl = new ArrayList<>();
Vaccine[] vaccines = useDefault ? Vaccine.values() : ImmunizationLibrary.getInstance().getVaccines();
Vaccine[] vaccines = useDefault ? Vaccine.values() : ImmunizationLibrary.getInstance().getVaccines(category);
for (Vaccine v : vaccines) {
if (v.category().equalsIgnoreCase(category.trim())) {
vl.add(v);
Expand All @@ -22,10 +23,9 @@ public static ArrayList<Vaccine> getVaccines(String category, boolean useDefault
}

public static Vaccine getVaccine(String name, String category) {
Vaccine[] vaccines = ImmunizationLibrary.getInstance().getVaccines();
Vaccine[] vaccines = ImmunizationLibrary.getInstance().getVaccines(category);
for (Vaccine curVaccine : vaccines) {
if (curVaccine.display.equalsIgnoreCase(name)
&& curVaccine.category.equalsIgnoreCase(category)) {
if (curVaccine.display.equalsIgnoreCase(name)) {
return curVaccine;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,31 +301,17 @@ public static String[] allAlertNames(String category) {
if (category == null) {
return null;
}
if ("child".equals(category)) {

ArrayList<VaccineRepo.Vaccine> vaccines = VaccineRepo.getVaccines("child");
List<String> names = new ArrayList<>();

for (VaccineRepo.Vaccine vaccine : vaccines) {
names.add(vaccine.display());
names.add(vaccine.name());
}
List<VaccineRepo.Vaccine> vaccines = VaccineRepo.getVaccines(category);
List<String> names = new ArrayList<>();

return names.toArray(new String[names.size()]);
for (VaccineRepo.Vaccine vaccine : vaccines) {
names.add(vaccine.display());
names.add(vaccine.name());
}
if ("woman".equals(category)) {

ArrayList<VaccineRepo.Vaccine> vaccines = VaccineRepo.getVaccines("woman");
List<String> names = new ArrayList<>();

for (VaccineRepo.Vaccine vaccine : vaccines) {
names.add(vaccine.display());
names.add(vaccine.name());
}
return names.toArray(new String[names.size()]);

return names.toArray(new String[names.size()]);
}
return null;
}

public static String[] allAlertNames(Collection<List<ServiceType>> typeList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public static List<Map<String, Object>> generateScheduleList(String category, Da
boolean m2Given = false;
boolean oGiven = false;
try {
ArrayList<Vaccine> vl = VaccineRepo.getVaccines(category);
List<Vaccine> vl = VaccineRepo.getVaccines(category);
for (Vaccine v : vl) {
Map<String, Object> m = new HashMap<>();
Date recDate = received.get(v.display().toLowerCase(Locale.ENGLISH));
Expand Down Expand Up @@ -931,7 +931,7 @@ public static List<VaccineGroup> getSupportedVaccines(@Nullable Context context,
ImmunizationLibrary immunizationLibrary = ImmunizationLibrary.getInstance();
Map<String, String> conditionalVaccinesMap = immunizationLibrary.getConditionalVaccinesMap();
if (!conditionalVaccinesMap.isEmpty() && immunizationLibrary.getCurrentConditionalVaccine() != null) {
return getVaccineGroupsFromVaccineConfigFile(context, getFileName(conditionalVaccinesMap.get(immunizationLibrary.getCurrentConditionalVaccine()), prefix));
return getVaccineGroupsFromVaccineConfigFile(context, getFileName(conditionalVaccinesMap.get(immunizationLibrary.getCurrentConditionalVaccine()), prefix));
}
return getVaccineGroupsFromVaccineConfigFile(context, getFileName(vaccines_file, prefix));
}
Expand Down Expand Up @@ -1178,8 +1178,9 @@ private static Matcher getPrefixSymbolMatcher(String offset) {
* This method is used to return minimum and maximum date as a pair for a vaccine that has a
* prerequisite. Example if you have IPV2 vaccine that depends on IPV1. We want to set the minimum
* date for IPV2 to be the date IPV1 was administered.
*
* @param vaccineWrappers Current vaccine(s) to be administered
* @param issuedVaccines Requisite vaccine(s) that were administered earlier
* @param issuedVaccines Requisite vaccine(s) that were administered earlier
* @return a pair of minimum and maximum date respectively
*/
public static Pair<Calendar, Calendar> getVaccineMinimumAndMaximumDate(List<VaccineWrapper> vaccineWrappers, List<org.smartregister.immunization.domain.Vaccine> issuedVaccines) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.smartregister.immunization.customshadows.FontTextViewShadow;
import org.smartregister.immunization.db.VaccineRepo;
import org.smartregister.immunization.repository.VaccineRepository;
import org.smartregister.immunization.util.IMConstants;
import org.smartregister.service.AlertService;
import org.smartregister.util.AppProperties;

Expand All @@ -23,7 +24,7 @@

@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, shadows = {FontTextViewShadow.class}, sdk = Build.VERSION_CODES.O_MR1)
@Config(shadows = {FontTextViewShadow.class}, sdk = Build.VERSION_CODES.O_MR1)
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*", "javax.xml.*", "org.xml.sax.*"
, "org.w3c.dom.*", "org.springframework.context.*", "org.apache.log4j.*", "com.android.internal.policy.*"
, "org.xmlpull.v1.*"})
Expand All @@ -44,7 +45,10 @@ public void mockImmunizationLibrary(@NonNull ImmunizationLibrary immunizationLib
PowerMockito.when(ImmunizationLibrary.getInstance()).thenReturn(immunizationLibrary);
PowerMockito.when(ImmunizationLibrary.getInstance().context()).thenReturn(context);
PowerMockito.when(ImmunizationLibrary.getInstance().vaccineRepository()).thenReturn(vaccineRepository);
PowerMockito.when(ImmunizationLibrary.getInstance().getVaccines()).thenReturn(VaccineRepo.Vaccine.values());

PowerMockito.when(ImmunizationLibrary.getInstance().getVaccines(IMConstants.VACCINE_TYPE.CHILD)).thenReturn(VaccineRepo.Vaccine.values());
PowerMockito.when(ImmunizationLibrary.getInstance().getVaccines(IMConstants.VACCINE_TYPE.WOMAN)).thenReturn(VaccineRepo.Vaccine.values());

PowerMockito.when(ImmunizationLibrary.getInstance().vaccineRepository().findByEntityId(org.mockito.ArgumentMatchers.anyString())).thenReturn(null);
PowerMockito.when(ImmunizationLibrary.getInstance().context().alertService()).thenReturn(alertService);
PowerMockito.when(ImmunizationLibrary.getInstance().getProperties()).thenReturn(appProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.smartregister.immunization.domain.jsonmapping.Condition;
import org.smartregister.immunization.domain.jsonmapping.VaccineGroup;
import org.smartregister.immunization.repository.VaccineRepository;
import org.smartregister.immunization.util.IMConstants;
import org.smartregister.service.AlertService;
import org.smartregister.util.AppProperties;
import org.smartregister.util.JsonFormUtils;
Expand Down Expand Up @@ -63,7 +64,7 @@ public class VaccineScheduleTest extends BaseUnitTest {
public void setUp() {
MockitoAnnotations.initMocks(this);

Mockito.doReturn(VaccineRepo.Vaccine.values()).when(immunizationLibrary).getVaccines();
Mockito.doReturn(VaccineRepo.Vaccine.values()).when(immunizationLibrary).getVaccines(IMConstants.VACCINE_TYPE.CHILD);
}

@Test
Expand Down Expand Up @@ -108,10 +109,9 @@ public void assertInitAndInitVaccineWithTestData() {
mockImmunizationLibrary();

VaccineSchedule.init(vaccines, specialVaccines, magicChild);
VaccineSchedule.init(vaccines, specialVaccines, "");
Assert.assertNotNull(VaccineSchedule.getVaccineSchedule(magicChild, magicOPV0));
Assert.assertNull(VaccineSchedule.getVaccineSchedule("", ""));
//vaccine cnodition test
//vaccine condition test
Condition object = new Condition();
object.type = "";
Assert.assertNull(VaccineCondition.init("", object));
Expand Down Expand Up @@ -152,7 +152,6 @@ public void testVaccineOrCondition() throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

VaccineSchedule.init(vaccines, specialVaccines, "child");
VaccineSchedule.init(vaccines, specialVaccines, "");

List<Vaccine> list = new ArrayList<>();
list.add(new Vaccine(0l, VaccineTest.BASEENTITYID, VaccineTest.PROGRAMCLIENTID, "MCV 1", 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.smartregister.immunization.ImmunizationLibrary;
import org.smartregister.immunization.db.VaccineRepo;
import org.smartregister.immunization.domain.jsonmapping.Due;
import org.smartregister.immunization.util.IMConstants;
import org.smartregister.util.JsonFormUtils;

import java.util.Calendar;
Expand Down Expand Up @@ -50,7 +51,7 @@ public void assertInitReturnsNonNullTriggers() {

PowerMockito.mockStatic(ImmunizationLibrary.class);
PowerMockito.when(ImmunizationLibrary.getInstance()).thenReturn(immunizationLibrary);
PowerMockito.when(immunizationLibrary.getVaccines()).thenReturn(new VaccineRepo.Vaccine[]{VaccineRepo.Vaccine.opv0, VaccineRepo.Vaccine.opv1, VaccineRepo.Vaccine.bcg});
PowerMockito.when(immunizationLibrary.getVaccines(IMConstants.VACCINE_TYPE.CHILD)).thenReturn(new VaccineRepo.Vaccine[]{VaccineRepo.Vaccine.opv0, VaccineRepo.Vaccine.opv1, VaccineRepo.Vaccine.bcg});
VaccineTrigger vaccineTrigger = VaccineTrigger.init(CHILD, data2);
Assert.assertNotNull(vaccineTrigger);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.smartregister.immunization.domain.VaccineWrapper;
import org.smartregister.immunization.fragment.mock.DrishtiApplicationShadow;
import org.smartregister.immunization.fragment.mock.VaccinationDialogFragmentTestActivity;
import org.smartregister.immunization.util.IMConstants;
import org.smartregister.util.AppProperties;

import java.util.ArrayList;
Expand Down Expand Up @@ -58,7 +59,7 @@ public void setUp() {
ImmunizationLibrary immunizationLibrary = Mockito.mock(ImmunizationLibrary.class);
ReflectionHelpers.setStaticField(ImmunizationLibrary.class, "instance", immunizationLibrary);

Mockito.doReturn(VaccineRepo.Vaccine.values()).when(immunizationLibrary).getVaccines();
Mockito.doReturn(VaccineRepo.Vaccine.values()).when(immunizationLibrary).getVaccines(IMConstants.VACCINE_TYPE.CHILD);
Mockito.doReturn(properties).when(immunizationLibrary).getProperties();

activity = Robolectric.buildActivity(VaccinationDialogFragmentTestActivity.class).create().start().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.smartregister.immunization.domain.jsonmapping.VaccineGroup;
import org.smartregister.immunization.fragment.mock.DrishtiApplicationShadow;
import org.smartregister.immunization.fragment.mock.VaccinationEditDialogFragmentTestActivity;
import org.smartregister.immunization.util.IMConstants;
import org.smartregister.util.AppProperties;
import org.smartregister.util.JsonFormUtils;

Expand Down Expand Up @@ -79,7 +80,7 @@ public void setUp() {
PowerMockito.when(ImmunizationLibrary.getInstance().context()).thenReturn(context);
Mockito.doReturn(properties).when(immunizationLibrary).getProperties();

Mockito.doReturn(VaccineRepo.Vaccine.values()).when(immunizationLibrary).getVaccines();
Mockito.doReturn(VaccineRepo.Vaccine.values()).when(immunizationLibrary).getVaccines(IMConstants.VACCINE_TYPE.CHILD);

activity = Robolectric.buildActivity(VaccinationEditDialogFragmentTestActivity.class).create().start().get();
activity.setContentView(R.layout.service_dialog_view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class VaccineSchedulesUpdateIntentServiceTest {
public VaccineSchedulesUpdateIntentService vaccineScheduleUpdateIntentService;

@Before
public void setUp() throws Exception {
public void setUp() {
vaccineScheduleUpdateIntentService = Mockito.spy(new VaccineSchedulesUpdateIntentService());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.smartregister.immunization.domain.VaccineWrapper;
import org.smartregister.immunization.domain.jsonmapping.VaccineGroup;
import org.smartregister.immunization.repository.VaccineRepository;
import org.smartregister.immunization.util.IMConstants;
import org.smartregister.immunization.util.VaccinateActionUtils;
import org.smartregister.immunization.util.VaccinatorUtils;
import org.smartregister.repository.AlertRepository;
Expand Down Expand Up @@ -94,7 +95,7 @@ public void setUp() {
Assert.assertNotNull(vaccinateActionUtils);

mockImmunizationLibrary(immunizationLibrary, context, vaccineRepository, alertService, appProperties);
Mockito.doReturn(VaccineRepo.Vaccine.values()).when(immunizationLibrary).getVaccines();
Mockito.doReturn(VaccineRepo.Vaccine.values()).when(immunizationLibrary).getVaccines(IMConstants.VACCINE_TYPE.CHILD);
}

@Test
Expand Down Expand Up @@ -188,7 +189,8 @@ public void assertAllAlertNamesTestReturnsAlertForACategory() {
Assert.assertNotNull(womanVaccines);
Assert.assertEquals(womanVaccines.length, 10);

Assert.assertNull(VaccinateActionUtils.allAlertNames(magicNULL));
String NULL_CATEGORY = null;
Assert.assertNull(VaccinateActionUtils.allAlertNames(NULL_CATEGORY));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.smartregister.immunization.sample.BuildConfig;
import org.smartregister.immunization.sample.repository.SampleRepository;
import org.smartregister.immunization.sample.util.VaccineDuplicate;
import org.smartregister.immunization.util.IMConstants;
import org.smartregister.immunization.util.VaccinatorUtils;
import org.smartregister.repository.Repository;
import org.smartregister.view.activity.DrishtiApplication;
Expand Down Expand Up @@ -48,12 +49,12 @@ public void onCreate() {
}

private void updateHardcodedVaccineDefinition() {
VaccineRepo.Vaccine[] vaccines = ImmunizationLibrary.getInstance().getVaccines();
VaccineRepo.Vaccine[] vaccines = ImmunizationLibrary.getInstance().getVaccines(IMConstants.VACCINE_TYPE.CHILD);

HashMap<String, VaccineDuplicate> replacementVaccines = new HashMap<>();
replacementVaccines.put("MR 2", new VaccineDuplicate("MR 2", VaccineRepo.Vaccine.mr1, -1, 548, 183, "child"));

for (VaccineRepo.Vaccine vaccine: vaccines) {
for (VaccineRepo.Vaccine vaccine : vaccines) {
if (replacementVaccines.containsKey(vaccine.display())) {
VaccineDuplicate vaccineDuplicate = replacementVaccines.get(vaccine.display());

Expand All @@ -65,7 +66,7 @@ private void updateHardcodedVaccineDefinition() {
}
}

ImmunizationLibrary.getInstance().setVaccines(vaccines);
ImmunizationLibrary.getInstance().setVaccines(vaccines, IMConstants.VACCINE_TYPE.CHILD);
}

public static synchronized SampleApplication getInstance() {
Expand Down

0 comments on commit 1a82fe1

Please sign in to comment.