Skip to content

Commit

Permalink
Merge pull request #250 from opensrp/allow-booster-vaccine-edit
Browse files Browse the repository at this point in the history
Allow editing of booster vaccines
  • Loading branch information
ellykits authored Aug 25, 2021
2 parents 231a2c9 + 7eb957b commit 970f610
Show file tree
Hide file tree
Showing 41 changed files with 1,053 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run unit tests with Gradle
run: ./gradlew :opensrp-child:jacocoTestReport --stacktrace
run: ./gradlew :opensrp-child:jacocoTestReport --stacktrace -Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"
- name: Generate Javadoc with Gradle
run: ./gradlew javadoc
- name: Upload coverage to Coveralls with Gradle
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=0.6.19-SNAPSHOT
VERSION_NAME=0.7.0-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Child Library
Expand Down
10 changes: 4 additions & 6 deletions opensrp-child/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ allprojects {
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
maven { url "https://dl.bintray.com/ona/rdt-capture" }
maven { url 'https://dl.bintray.com/ibm-watson-health/ibm-fhir-server-releases' }
maven { url 'https://nexus.pentaho.org/content/groups/omni/' }
mavenLocal()
}
}
Expand All @@ -106,8 +105,7 @@ dependencies {

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1'


api('org.smartregister:opensrp-client-core:4.3.16-SNAPSHOT@aar') {
api('org.smartregister:opensrp-client-core:4.3.18-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.github.bmelnychuk', module: 'atv'
exclude group: 'com.google.guava', module: 'guava'
Expand Down Expand Up @@ -172,7 +170,7 @@ dependencies {


implementation 'com.google.guava:guava:29.0-android'
implementation 'id.zelory:compressor:2.1.0'
implementation 'id.zelory:compressor:2.1.1'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
implementation "androidx.constraintlayout:constraintlayout:2.0.0"

Expand Down Expand Up @@ -229,4 +227,4 @@ coveralls {
sourceDirs = ["$project.projectDir/src/main/java"]
}

apply from: '../maven.gradle'
apply from: '../maven.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
import com.vijay.jsonwizard.domain.Form;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Triple;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -49,7 +53,9 @@
import org.smartregister.child.contract.ChildTabbedDetailsContract;
import org.smartregister.child.contract.IChildDetails;
import org.smartregister.child.dao.ChildDao;
import org.smartregister.child.domain.ExtraVaccineUpdateEvent;
import org.smartregister.child.enums.Status;
import org.smartregister.child.event.DynamicVaccineType;
import org.smartregister.child.fragment.BaseChildRegistrationDataFragment;
import org.smartregister.child.fragment.ChildUnderFiveFragment;
import org.smartregister.child.fragment.LostCardDialogFragment;
Expand All @@ -60,11 +66,11 @@
import org.smartregister.child.task.LoadAsyncTask;
import org.smartregister.child.task.SaveAdverseEventTask;
import org.smartregister.child.task.SaveDynamicVaccinesTask;
import org.smartregister.child.task.SaveDynamicVaccinesTask.DynamicVaccineTypes;
import org.smartregister.child.task.SaveRegistrationDetailsTask;
import org.smartregister.child.task.SaveServiceTask;
import org.smartregister.child.task.SaveVaccinesTask;
import org.smartregister.child.task.UndoServiceTask;
import org.smartregister.child.task.UpdateDynamicVaccinesTask;
import org.smartregister.child.task.UpdateOfflineAlertsTask;
import org.smartregister.child.toolbar.ChildDetailsToolbar;
import org.smartregister.child.util.ChildAppProperties;
Expand Down Expand Up @@ -123,7 +129,6 @@
import timber.log.Timber;

import static org.smartregister.clientandeventmodel.DateUtil.getDateFromString;
import static org.smartregister.growthmonitoring.util.AppProperties.Entry;
import static org.smartregister.util.Utils.showToast;

/**
Expand Down Expand Up @@ -157,7 +162,7 @@ public abstract class BaseChildDetailTabbedActivity extends BaseChildActivity
private final List<ServiceHolder> removeServicesList = new ArrayList<>();
private final List<Long> dbKeysForDelete = new ArrayList<>();
private VaccineRepository vaccineRepository;
private List<Map.Entry<String, String>> extraChildVaccines;
private List<Triple<String, String, String>> extraChildVaccines;
private LostCardDialogFragment lostCardDialogFragment;
private ChildTabbedDetailsContract.Presenter presenter;
public final SimpleDateFormat ddMmYyyyDateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH);
Expand All @@ -168,6 +173,8 @@ public abstract class BaseChildDetailTabbedActivity extends BaseChildActivity
public final boolean showBoosterImmunizations = Boolean.parseBoolean(ChildLibrary.getInstance().getProperties()
.getProperty(ChildAppProperties.KEY.SHOW_BOOSTER_IMMUNIZATIONS, "false"));

private final List<ExtraVaccineUpdateEvent> extraVaccineUpdateEvents = new ArrayList<>();

public static void updateOptionsMenu(@NonNull List<Vaccine> vaccineList, @NonNull List<ServiceRecord> serviceRecordList,
@NonNull List<Weight> weightList, @Nullable List<Alert> alertList) {
boolean showVaccineList = false;
Expand Down Expand Up @@ -251,7 +258,7 @@ protected void onCreate(Bundle savedInstanceState) {
childUnderFiveFragment.setExtraVaccines(getExtraChildVaccines());
}
if (showBoosterImmunizations) {
List<Map.Entry<String, String>> boosterImmunizations =
List<Triple<String, String, String>> boosterImmunizations =
ChildDao.getChildExtraVaccines(Constants.Tables.EC_BOOSTER_VACCINES, childDetails.entityId());
childUnderFiveFragment.setBoosterImmunizations(boosterImmunizations);
}
Expand Down Expand Up @@ -355,6 +362,15 @@ protected void processEditedServices() {
//clean up
editImmunizationCacheMap.clear();
dbKeysForDelete.clear();

createExtraVaccineUpdateEvents();

}

protected void createExtraVaccineUpdateEvents() {
if ((showExtraVaccines || showBoosterImmunizations) && !extraVaccineUpdateEvents.isEmpty()) {
Utils.startAsyncTask(new UpdateDynamicVaccinesTask(this, extraVaccineUpdateEvents), null);
}
}

private void setupViewPager(ViewPager viewPager) {
Expand Down Expand Up @@ -434,6 +450,7 @@ public void renderProfileWidget(Map<String, String> childDetails) {
TextView profilename = findViewById(R.id.name);
TextView profileOpenSrpId = findViewById(R.id.idforclient);
TextView profileage = findViewById(R.id.ageforclient);
TextView systemOfRegistration = findViewById(R.id.system_of_registration);
String name = "";
String childId = "";
String dobString;
Expand All @@ -445,6 +462,11 @@ public void renderProfileWidget(Map<String, String> childDetails) {
if (StringUtils.isNotBlank(childId)) {
childId = childId.replace("-", "");
}
String systemOfRegistrationText = Utils.getValue(childDetails,Constants.Client.SYSTEM_OF_REGISTRATION, false);
if(systemOfRegistrationText != null && !systemOfRegistrationText.equals(""))
systemOfRegistration.setText(systemOfRegistrationText);
else
systemOfRegistration.setVisibility(View.GONE);
dobString = Utils.getValue(childDetails, Constants.KEY.DOB, false);
Date dob = Utils.dobStringToDate(dobString);
if (dob != null) {
Expand Down Expand Up @@ -605,6 +627,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}


/**
* This method launches dynamic vaccines form. The form has a list of vaccines selected from the multiselect
* widget plus the date the vaccine(s) were administered.
Expand Down Expand Up @@ -660,10 +683,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Utils.startAsyncTask(new SaveAdverseEventTask(jsonString, locationId, childDetails.entityId(), allSharedPreferences.fetchRegisteredANM(), CoreLibrary.getInstance().context().getEventClientRepository()), null);
break;
case Constants.EventType.DYNAMIC_VACCINES:
Utils.startAsyncTask(new SaveDynamicVaccinesTask(this, jsonString, childDetails.entityId(), DynamicVaccineTypes.PRIVATE_SECTOR_VACCINE), null);
Utils.startAsyncTask(new SaveDynamicVaccinesTask(this, jsonString, childDetails.entityId(), DynamicVaccineType.PRIVATE_SECTOR_VACCINE), null);
break;
case Constants.EventType.BOOSTER_VACCINES:
Utils.startAsyncTask(new SaveDynamicVaccinesTask(this, jsonString, childDetails.entityId(), DynamicVaccineTypes.BOOSTER_IMMUNIZATIONS), null);
Utils.startAsyncTask(new SaveDynamicVaccinesTask(this, jsonString, childDetails.entityId(), DynamicVaccineType.BOOSTER_IMMUNIZATIONS), null);
break;
default:
break;
Expand Down Expand Up @@ -696,6 +719,18 @@ protected void onResume() {
super.onResume();
}

@Override
public void onStart() {
EventBus.getDefault().register(this);
super.onStart();
}

@Override
public void onPause() {
EventBus.getDefault().unregister(this);
super.onPause();
}

@Override
public void setChildDetails(Map<String, String> detailsMap) {
this.detailsMap = detailsMap;
Expand All @@ -709,22 +744,35 @@ protected Class onBackActivity() {
}

@Override
public void onSaveDynamicVaccine(DynamicVaccineTypes dynamicVaccineTypes) {
public void onSaveDynamicVaccine(DynamicVaccineType dynamicVaccineType) {
showProgressDialog();
viewPager.setCurrentItem(1, true);
if (showExtraVaccines && dynamicVaccineTypes == DynamicVaccineTypes.PRIVATE_SECTOR_VACCINE) {
if (showExtraVaccines && dynamicVaccineType == DynamicVaccineType.PRIVATE_SECTOR_VACCINE) {
setExtraChildVaccines(ChildDao.getChildExtraVaccines(Constants.Tables.EC_DYNAMIC_VACCINES, childDetails.entityId()));
childUnderFiveFragment.setExtraVaccines(getExtraChildVaccines());
}
if (showBoosterImmunizations && dynamicVaccineTypes == DynamicVaccineTypes.BOOSTER_IMMUNIZATIONS) {
List<Entry<String, String>> boosterImmunization =
if (showBoosterImmunizations && dynamicVaccineType == DynamicVaccineType.BOOSTER_IMMUNIZATIONS) {
List<Triple<String, String, String>> boosterImmunization =
ChildDao.getChildExtraVaccines(Constants.Tables.EC_BOOSTER_VACCINES, childDetails.entityId());
childUnderFiveFragment.setBoosterImmunizations(boosterImmunization);
}
childUnderFiveFragment.updateExtraVaccinesView(dynamicVaccineTypes);
childUnderFiveFragment.updateExtraVaccinesView(dynamicVaccineType, false);
hideProgressDialog();
}

@Override
synchronized public void onUpdateDynamicVaccine() {
extraVaccineUpdateEvents.clear();
for (DynamicVaccineType dynamicVaccineType : DynamicVaccineType.values()) {
onSaveDynamicVaccine(dynamicVaccineType);
}
}

@Subscribe(threadMode = ThreadMode.MAIN_ORDERED)
public void onVaccineUpdated(ExtraVaccineUpdateEvent extraVaccineUpdateEvent) {
extraVaccineUpdateEvents.add(extraVaccineUpdateEvent);
}

protected void confirmReportDeceased(final String json) {

final AlertDialog builder = new AlertDialog.Builder(this).setCancelable(false).create();
Expand Down Expand Up @@ -1286,11 +1334,11 @@ public void startFormActivity(String formData, Form formParam) {
startActivityForResult(intent, REQUEST_CODE_GET_JSON);
}

public List<Map.Entry<String, String>> getExtraChildVaccines() {
public List<Triple<String, String, String>> getExtraChildVaccines() {
return extraChildVaccines;
}

public void setExtraChildVaccines(List<Map.Entry<String, String>> extraChildVaccines) {
public void setExtraChildVaccines(List<Triple<String, String, String>> extraChildVaccines) {
this.extraChildVaccines = extraChildVaccines;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public abstract class BaseChildImmunizationActivity extends BaseChildActivity
private TextView ageTV;
private TextView nameTV;
private TextView childIdTV;
private TextView systemOfRegistrationTV;
private LinearLayout vaccineGroupCanvasLL;
private LinearLayout profileNamelayout;
private LinearLayout serviceGroupCanvasLL;
Expand Down Expand Up @@ -249,6 +250,7 @@ private void setUpViews() {
profileImageIV = findViewById(R.id.profile_image_iv);
nameTV = findViewById(R.id.name_tv);
childIdTV = findViewById(R.id.child_id_tv);
systemOfRegistrationTV = findViewById(R.id.system_of_registration);
floatingActionButton = findViewById(R.id.fab);
someLayout = findViewById(R.id.content_base_inner);
nextAppointmentDateView = findViewById(R.id.next_appointment_date);
Expand Down Expand Up @@ -403,6 +405,7 @@ public void updateViews() {
((TextView) toolbar.findViewById(R.id.title)).setText(getActivityTitle());//Called differently Fixes weird bug

updateAgeViews();
updateSystemOfRegistration();
updateChildIdViews();
updateNextAppointmentDateView();

Expand Down Expand Up @@ -488,6 +491,12 @@ protected void updateChildIdViews() {
Utils.startAsyncTask(new GetSiblingsTask(childDetails, this), null);
}

private void updateSystemOfRegistration()
{
String systemOfRegistration = org.smartregister.util.Utils.getValue(childDetails.getColumnmaps(), Constants.Client.SYSTEM_OF_REGISTRATION, false);
systemOfRegistrationTV.setText(systemOfRegistration!= null ? systemOfRegistration : "");
}

private void updateNextAppointmentDateView() {
if (registerClickables != null && !TextUtils.isEmpty(registerClickables.getNextAppointmentDate())) {
((View) nextAppointmentDateView.getParent()).setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,64 @@
package org.smartregister.child.dao;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Triple;
import org.smartregister.child.util.Constants;
import org.smartregister.dao.AbstractDao;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ChildDao extends AbstractDao {

public static List<Map.Entry<String, String>> getChildExtraVaccines(String tableName, final Map.Entry<String, String> entry,
String baseEntityColumn, String baseEntityId) {
String query = String.format("SELECT %s,%s FROM %s WHERE %s = '%s'", entry.getKey(), entry.getValue(), tableName,
baseEntityColumn, baseEntityId);
DataMap<Map.Entry<String, String>> dataMap = cursor ->
new AbstractMap.SimpleEntry<>(getCursorValue(cursor, entry.getKey()),
getCursorValue(cursor, entry.getValue()));

List<Map.Entry<String, String>> result = readData(query, dataMap);
if (result == null) return new ArrayList<>();
return result;
}

/**
* Retrieve the selected vaccines that are comma separated and create new list
*
*
* @param tableName
* @param baseEntityId unique id for the client
* @param tableName table's name
* @param entityId unique id for the client (in this case the base_entity_id that is processed from
* events is the form submission id to avoid conflicts with data insertion
* @return a list of selected vaccines with their dates
*/
public static List<Map.Entry<String, String>> getChildExtraVaccines(String tableName, String baseEntityId) {
List<Map.Entry<String, String>> extraVaccines = getChildExtraVaccines(tableName,
new AbstractMap.SimpleEntry<>(Constants.KEY.SELECTED_VACCINES, Constants.KEY.VACCINE_DATE), Constants.KEY.ENTITY_ID, baseEntityId);
List<Map.Entry<String, String>> vaccinesList = new ArrayList<>();
for (Map.Entry<String, String> vaccine : extraVaccines) {
if (StringUtils.isNotBlank(vaccine.getKey()) && StringUtils.isNotBlank(vaccine.getValue())) {
String[] vaccines = vaccine.getKey().split(",");
for (String vac : vaccines) {
vaccinesList.add(new AbstractMap.SimpleEntry<>(vac, vaccine.getValue()));
public static List<Triple<String, String, String>> getChildExtraVaccines(String tableName, String entityId) {
List<Triple<String, String, String>> extraVaccines = getChildExtraVaccines(tableName,
Triple.of(Constants.KEY.BASE_ENTITY_ID, Constants.KEY.SELECTED_VACCINES, Constants.KEY.VACCINE_DATE), entityId);
List<Triple<String, String, String>> vaccinesList = new ArrayList<>();

for (Triple<String, String, String> extraVaccine : extraVaccines) {

String baseEntityId = extraVaccine.getLeft();
String vaccineNames = extraVaccine.getMiddle();
String serviceDate = extraVaccine.getRight();

if (StringUtils.isNotBlank(vaccineNames) && StringUtils.isNotBlank(serviceDate)) {
String[] vaccines = vaccineNames.split(",");
for (String vaccine : vaccines) {

vaccinesList.add(Triple.of(baseEntityId, vaccine, serviceDate));
}
}
}

return vaccinesList;
}

private static List<Triple<String, String, String>> getChildExtraVaccines(String tableName, final Triple<String, String, String> columns, String entityId) {
String query = String.format("SELECT %s, %s, %s FROM %s WHERE %s = '%s' AND is_closed IS 0",
columns.getLeft(), columns.getMiddle(), columns.getRight(), tableName, Constants.KEY.ENTITY_ID, entityId);
DataMap<Triple<String, String, String>> dataMap = cursor ->
Triple.of(getCursorValue(cursor, columns.getLeft()), getCursorValue(cursor, columns.getMiddle()),
getCursorValue(cursor, columns.getRight()));

List<Triple<String, String, String>> result = readData(query, dataMap);
if (result == null) return new ArrayList<>();
return result;
}

/**
* Return list of available recurring services
*
* @return recurring services
*/
public static List<String> getRecurringServiceTypes(){
public static List<String> getRecurringServiceTypes() {
String query = "SELECT DISTINCT type FROM recurring_service_types";

DataMap<String> dataMap = cursor -> getCursorValue(cursor, "type");
Expand Down
Loading

0 comments on commit 970f610

Please sign in to comment.