Skip to content

Commit

Permalink
Merge 92dc688 into c6fbb40
Browse files Browse the repository at this point in the history
  • Loading branch information
whoisladleo committed Apr 24, 2019
2 parents c6fbb40 + 92dc688 commit a161169
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
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.8-SNAPSHOT
VERSION_NAME=1.4.9-SNAPSHOT
VERSION_CODE=2
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Immunization
Expand Down
2 changes: 1 addition & 1 deletion opensrp-immunization/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@ coveralls {
}


apply from: '../maven.gradle'
apply from: '../maven.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.gson.reflect.TypeToken;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Contract;
import org.joda.time.DateTime;
import org.joda.time.Months;
import org.json.JSONException;
Expand Down Expand Up @@ -85,6 +86,11 @@
*/
public class VaccinatorUtils {
private static final String TAG = "VaccinatorUtils";

private static String vaccines_file = "vaccines.json";
private static String mother_vaccines_file = "mother_vaccines.json";
private static String special_vaccines_file = "special_vaccines.json";
private static String recurring_service_types_file = "recurring_service_types.json";

public static HashMap<String, String> providerDetails() {
org.smartregister.Context context = ImmunizationLibrary.getInstance().context();
Expand Down Expand Up @@ -693,10 +699,21 @@ public static int dpToPx(Context context, float dpValue) {
* @return list of VaccineGroup with the supported vaccines
*/
public static List<VaccineGroup> getSupportedVaccines(@Nullable Context context) {
return getSupportedVaccines(context, null);
}

/**
* Returns a list of VaccineGroup containing a list of supported vaccines
*
* @param context Current valid context to be used
* @param prefix Country prefix
* @return list of VaccineGroup with the supported vaccines
*/
public static List<VaccineGroup> getSupportedVaccines(@Nullable Context context, String prefix) {
Class<List<VaccineGroup>> clazz = (Class) List.class;
Type listType = new TypeToken<List<VaccineGroup>>() {
}.getType();
return ImmunizationLibrary.getInstance().assetJsonToJava("vaccines.json", clazz, listType);
return ImmunizationLibrary.getInstance().assetJsonToJava(getFileName(vaccines_file,prefix), clazz, listType);
}

/**
Expand All @@ -706,17 +723,31 @@ public static List<VaccineGroup> getSupportedVaccines(@Nullable Context context)
* @return list of VaccineGroup with the supported vaccines
*/
public static List<VaccineGroup> getSupportedWomanVaccines(@Nullable Context context) {
return getSupportedWomanVaccines(context, null);
}

/**
* Returns a list of VaccineGroup containing a list of supported woman vaccines
*
* @param context Current valid context to be used
* @return list of VaccineGroup with the supported vaccines
*/
public static List<VaccineGroup> getSupportedWomanVaccines(@Nullable Context context, String prefix) {
Class<List<VaccineGroup>> clazz = (Class) List.class;
Type listType = new TypeToken<List<VaccineGroup>>() {
}.getType();
return ImmunizationLibrary.getInstance().assetJsonToJava("mother_vaccines.json", clazz, listType);
return ImmunizationLibrary.getInstance().assetJsonToJava(getFileName(mother_vaccines_file,prefix), clazz, listType);
}

public static List<org.smartregister.immunization.domain.jsonmapping.Vaccine> getSpecialVaccines(@Nullable Context context) {
return getSpecialVaccines(context, null);
}

public static List<org.smartregister.immunization.domain.jsonmapping.Vaccine> getSpecialVaccines(@Nullable Context context, String prefix) {
Class<List<org.smartregister.immunization.domain.jsonmapping.Vaccine>> clazz = (Class) List.class;
Type listType = new TypeToken<List<org.smartregister.immunization.domain.jsonmapping.Vaccine>>() {
}.getType();
return ImmunizationLibrary.getInstance().assetJsonToJava("special_vaccines.json", clazz, listType);
return ImmunizationLibrary.getInstance().assetJsonToJava(getFileName(special_vaccines_file,prefix), clazz, listType);
}

/**
Expand All @@ -726,7 +757,17 @@ public static List<org.smartregister.immunization.domain.jsonmapping.Vaccine> ge
* @return JSON String with the supported vaccines or NULL if unable to obtain the list
*/
public static String getSupportedRecurringServices(Context context) {
String supportedServicesString = org.smartregister.util.Utils.readAssetContents(context, "recurring_service_types.json");
return getSupportedRecurringServices(context, null);
}

/**
* Returns a JSON String containing a list of supported services
*
* @param context Current valid context to be used
* @return JSON String with the supported vaccines or NULL if unable to obtain the list
*/
public static String getSupportedRecurringServices(Context context, String prefix) {
String supportedServicesString = org.smartregister.util.Utils.readAssetContents(context, getFileName(recurring_service_types_file, prefix));
return supportedServicesString;
}

Expand Down Expand Up @@ -836,4 +877,12 @@ public static String getColorValue(Context cxt, AlertStatus alertStatus) {
return "#" + Integer.toHexString(cxt.getResources().getColor(org.smartregister.immunization.R.color.alert_na)).substring(2);
}
}

public static String getFileName(String fileName, String prefix) {
if(prefix != null) {
return prefix + "_" + fileName;
} else {
return fileName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ public void assertVaccinatorUtilsTest() throws Exception {
Resources resources = Mockito.mock(Resources.class);
PowerMockito.when(ctx.getResources()).thenReturn(resources);
PowerMockito.when(resources.getColor(org.mockito.ArgumentMatchers.anyInt())).thenReturn(magicColor);

//get file name with prefix
Assert.assertEquals(vaccinatorUtils.getFileName("vaccines.json", "tz"), "tz_vaccines.json");

//get file name without prefix
Assert.assertEquals(vaccinatorUtils.getFileName("vaccines.json", null), "vaccines.json");


//get color test for different status
Assert.assertNotNull(vaccinatorUtils.getColorValue(ctx, AlertStatus.upcoming));
Assert.assertNotNull(vaccinatorUtils.getColorValue(ctx, AlertStatus.normal));
Expand Down

0 comments on commit a161169

Please sign in to comment.