diff --git a/.tx/config b/.tx/config index 090546b28d..dd4c05afe4 100644 --- a/.tx/config +++ b/.tx/config @@ -6,3 +6,4 @@ file_filter = opensrp-chw-core/src/main/res/values-/strings.xml source_file = opensrp-chw-core/src/main/res/values/strings.xml source_lang = en type = ANDROID + diff --git a/gradle.properties b/gradle.properties index eb3cf14196..6787bf3f6f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.5.22-SNAPSHOT +VERSION_NAME=2.0.7-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Chw Core Library diff --git a/opensrp-chw-core/build.gradle b/opensrp-chw-core/build.gradle index b15c47fe6c..a124bed74f 100644 --- a/opensrp-chw-core/build.gradle +++ b/opensrp-chw-core/build.gradle @@ -125,7 +125,7 @@ dependencies { exclude group: 'xpp3', module: 'xpp3' } - api('org.smartregister:opensrp-client-native-form:1.14.5.5-SNAPSHOT@aar') { + api('org.smartregister:opensrp-client-native-form:1.14.5.5-disable_hwid-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'appcompat-v7' exclude group: 'com.android.support', module: 'cardview-v7' @@ -138,7 +138,7 @@ dependencies { compileOnly 'com.ibm.fhir:fhir-model:4.2.3' - api('org.smartregister:opensrp-client-core:1.15.4-SNAPSHOT@aar') { + api('org.smartregister:opensrp-client-core:4.0.4-SNAPSHOT@aar') { transitive = true exclude group: 'com.github.bmelnychuk', module: 'atv' exclude group: 'com.google.guava', module: 'guava' @@ -149,7 +149,7 @@ dependencies { exclude group: 'com.ibm.fhir', module: 'fhir-model' } implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' api('org.smartregister:opensrp-client-configurable-views:1.1.5-SNAPSHOT@aar') { transitive = true @@ -157,7 +157,7 @@ dependencies { exclude group: 'com.android.support', module: 'appcompat-v7' } - api('org.smartregister:opensrp-client-family:1.3.1-SNAPSHOT@aar') { + api('org.smartregister:opensrp-client-family:2.0.1-SNAPSHOT@aar') { transitive = true exclude group: 'org.smartregister', module: 'opensrp-client-core' exclude group: 'org.smartregister', module: 'opensrp-client-native-form' @@ -190,16 +190,17 @@ dependencies { exclude group: 'com.github.lecho', module: 'hellocharts-android' } - api('org.smartregister:opensrp-client-chw-anc:1.1.2-SNAPSHOT@aar') { + api('org.smartregister:opensrp-client-chw-anc:2.0.0-SNAPSHOT@aar') { transitive = true exclude group: 'org.smartregister', module: 'opensrp-client-core' exclude group: 'com.android.support', module: 'appcompat-v7' exclude group: 'org.smartregister', module: 'opensrp-client-native-form' exclude group: 'org.smartregister', module: 'opensrp-client-configurable-views' exclude group: 'org.smartregister', module: 'opensrp-client-immunization' + exclude group: 'org.smartregister', module: 'opensrp-client-family' } - api('org.smartregister:opensrp-client-chw-pnc:1.0.3-SNAPSHOT@aar') { + api('org.smartregister:opensrp-client-chw-pnc:2.0.0-SNAPSHOT@aar') { transitive = true exclude group: 'org.smartregister', module: 'opensrp-client-chw-anc' exclude group: 'org.smartregister', module: 'opensrp-client-core' @@ -207,6 +208,7 @@ dependencies { exclude group: 'org.smartregister', module: 'opensrp-client-native-form' exclude group: 'org.smartregister', module: 'opensrp-client-configurable-views' exclude group: 'org.smartregister', module: 'opensrp-client-immunization' + exclude group: 'org.smartregister', module: 'opensrp-client-family' } api('org.smartregister:opensrp-client-chw-malaria:1.2.18-SNAPSHOT@aar') { @@ -251,7 +253,7 @@ dependencies { api 'com.evernote:android-job:1.2.6' api 'org.greenrobot:eventbus:3.1.1' - api("org.smartregister:android-p2p-sync:0.3.8-apha1-SNAPSHOT") { + api("org.smartregister:android-p2p-sync:0.3.8-aplha4-SNAPSHOT") { transitive = true exclude group: 'org.smartregister', module: 'opensrp-client-core' exclude group: 'com.android.support', module: 'appcompat-v7' @@ -260,9 +262,7 @@ dependencies { exclude group: 'com.rengwuxian.materialedittext', module: 'library' } - api('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') { - transitive = true - } + api 'com.google.firebase:firebase-crashlytics:17.3.0' androidTestImplementation 'org.mockito:mockito-android:3.0.0' androidTestImplementation 'androidx.test.ext:junit:1.1.2' diff --git a/opensrp-chw-core/src/main/AndroidManifest.xml b/opensrp-chw-core/src/main/AndroidManifest.xml index e5bd024b7c..6d2727ca4d 100644 --- a/opensrp-chw-core/src/main/AndroidManifest.xml +++ b/opensrp-chw-core/src/main/AndroidManifest.xml @@ -6,4 +6,7 @@ + + + \ No newline at end of file diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/BaseReferralTaskViewActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/BaseReferralTaskViewActivity.java index 8361a992b8..2535a1f668 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/BaseReferralTaskViewActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/BaseReferralTaskViewActivity.java @@ -136,7 +136,7 @@ protected void getReferralDetails() { updateProblemDisplay(); String clientAge = (Utils.getTranslatedDate(Utils.getDuration(Utils.getValue(getPersonObjectClient().getColumnmaps(), DBConstants.KEY.DOB, false)), getBaseContext())); clientName.setText(getString(R.string.client_name_age_suffix, name, clientAge)); - referralDate.setText(org.smartregister.chw.core.utils.Utils.dd_MMM_yyyy.format(getTask().getExecutionStartDate().toDate())); + referralDate.setText(org.smartregister.chw.core.utils.Utils.dd_MMM_yyyy.format(getTask().getExecutionPeriod().getStart().toDate())); //For PNC get children belonging to the woman String childrenForPncWoman = getChildrenForPncWoman(getPersonObjectClient().entityId()); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/ChwP2pModeSelectActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/ChwP2pModeSelectActivity.java index babc1be213..db97375a18 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/ChwP2pModeSelectActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/ChwP2pModeSelectActivity.java @@ -1,6 +1,6 @@ package org.smartregister.chw.core.activity; -import android.content.Context; +import android.content.res.Configuration; import android.os.Bundle; import androidx.annotation.Nullable; @@ -17,9 +17,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { } @Override - protected void attachBaseContext(Context base) { + protected void attachBaseContext(android.content.Context base) { // get language from prefs String lang = LangUtils.getLanguage(base.getApplicationContext()); - super.attachBaseContext(LangUtils.setAppLocale(base, lang)); + Configuration newConfiguration = LangUtils.setAppLocale(base, lang); + + super.attachBaseContext(base); + + applyOverrideConfiguration(newConfiguration); } + } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreAllClientsRegisterActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreAllClientsRegisterActivity.java index 10db0ef87c..22a2432327 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreAllClientsRegisterActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreAllClientsRegisterActivity.java @@ -15,6 +15,8 @@ import org.smartregister.opd.presenter.BaseOpdRegisterActivityPresenter; import org.smartregister.view.fragment.BaseRegisterFragment; +import java.util.Map; + public class CoreAllClientsRegisterActivity extends BaseOpdRegisterActivity { @Override @@ -52,6 +54,11 @@ protected void onResumption() { } } + @Override + public void startFormActivity(String s, String s1, Map map) { + // to do + } + @Override public void switchToBaseFragment() { Intent intent = new Intent(this, CoreFamilyRegisterActivity.class); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreAncMemberProfileActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreAncMemberProfileActivity.java index 843c3bfe6f..a9e2e8ee3a 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreAncMemberProfileActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreAncMemberProfileActivity.java @@ -161,7 +161,7 @@ public void onClick(View view) { } private int getMonthsDifference(LocalDate date1, LocalDate date2) { - return Months.monthsBetween( date1.withDayOfMonth(1), date2.withDayOfMonth(1)).getMonths(); + return Months.monthsBetween(date1.withDayOfMonth(1), date2.withDayOfMonth(1)).getMonths(); } private boolean isVisitThisMonth(LocalDate lastVisitDate, LocalDate todayDate) { @@ -260,7 +260,8 @@ public void setupViews() { protected void initializeNotificationReferralRecyclerView() { notificationAndReferralLayout = findViewById(R.id.notification_and_referral_row); notificationAndReferralRecyclerView = findViewById(R.id.notification_and_referral_recycler_view); - notificationAndReferralRecyclerView.setLayoutManager(new LinearLayoutManager(this)); + if (notificationAndReferralRecyclerView != null) + notificationAndReferralRecyclerView.setLayoutManager(new LinearLayoutManager(this)); } @Override diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildHomeVisitActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildHomeVisitActivity.java index 26827d4328..ebcfefde87 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildHomeVisitActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildHomeVisitActivity.java @@ -73,10 +73,12 @@ public void redrawHeader(MemberObject memberObject) { tvTitle.setText(MessageFormat.format("{0}, {1} {2}", memberObject.getFullName(), getDuration(memberObject.getDob()), getString(R.string.home_visit_suffix))); } + /* @Override protected void attachBaseContext(Context base) { // get language from prefs String lang = LangUtils.getLanguage(base.getApplicationContext()); super.attachBaseContext(LangUtils.setAppLocale(base, lang)); } + */ } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildRegisterActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildRegisterActivity.java index c9ec7fe2d0..508211d10a 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildRegisterActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreChildRegisterActivity.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.List; +import java.util.Map; import timber.log.Timber; @@ -86,6 +87,11 @@ protected void onResumption() { } } + @Override + public void startFormActivity(String s, String s1, Map map) { + // code + } + @Override public void startFormActivity(String formName, String entityId, String metaData) { try { @@ -158,6 +164,6 @@ public void openFamilyListView() { @Override public void startRegistration() { - startFormActivity(Utils.metadata().familyRegister.formName, null, null); + startFormActivity(Utils.metadata().familyRegister.formName, null, ""); } } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivity.java index c27ac79f7f..123a289d70 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivity.java @@ -64,7 +64,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - if (requestCode == CoreConstants.RQ_CODE.STORAGE_PERMISIONS && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + if (requestCode == CoreConstants.RQ_CODE.STORAGE_PERMISIONS && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { NavigationMenu navigationMenu = NavigationMenu.getInstance(this, null, null); if (navigationMenu != null) { navigationMenu.startP2PActivity(this); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/DefaultAncMedicalHistoryActivityFlv.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/DefaultAncMedicalHistoryActivityFlv.java index c354ff2e97..991a97288a 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/DefaultAncMedicalHistoryActivityFlv.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/DefaultAncMedicalHistoryActivityFlv.java @@ -25,6 +25,7 @@ public abstract class DefaultAncMedicalHistoryActivityFlv implements CoreAncMedicalHistoryActivity.Flavor { protected LinearLayout linearLayoutAncCard; + protected LinearLayout linearLayoutDeliveryKit; protected LinearLayout linearLayoutHealthFacilityVisit; protected LinearLayout linearLayoutHealthFacilityVisitDetails; protected LayoutInflater inflater; @@ -33,6 +34,7 @@ public abstract class DefaultAncMedicalHistoryActivityFlv implements CoreAncMedi private LinearLayout linearLayoutIPTp, linearLayoutIPTpDetails; private TextView customFontTextViewLastVisit; private TextView customFontTextViewAncCard; + private TextView customFontTextViewDeliveryKit; @Override public View bindViews(Activity activity) { @@ -41,6 +43,7 @@ public View bindViews(Activity activity) { linearLayoutLastVisit = view.findViewById(R.id.linearLayoutLastVisit); linearLayoutAncCard = view.findViewById(R.id.linearLayoutAncCard); + linearLayoutDeliveryKit = view.findViewById(R.id.linearLayoutDeliveryKit); linearLayoutHealthFacilityVisit = view.findViewById(R.id.linearLayoutHealthFacilityVisit); linearLayoutHealthFacilityVisitDetails = view.findViewById(R.id.linearLayoutHealthFacilityVisitDetails); linearLayoutTTImmunization = view.findViewById(R.id.linearLayoutTTImmunization); @@ -49,6 +52,7 @@ public View bindViews(Activity activity) { linearLayoutIPTpDetails = view.findViewById(R.id.linearLayoutIPTpDetails); customFontTextViewLastVisit = view.findViewById(R.id.customFontTextViewLastVisit); customFontTextViewAncCard = view.findViewById(R.id.customFontTextViewAncCard); + customFontTextViewDeliveryKit = view.findViewById(R.id.customFontTextViewDeliveryKit); return view; } @@ -59,6 +63,7 @@ public void processViewData(List visits, Context context) { int days = 0; String has_card = "No"; + String has_delivery_kit = "No"; List> hf_visits = new ArrayList<>(); Map immunizations = new HashMap<>(); Map services = new HashMap<>(); @@ -80,6 +85,15 @@ public void processViewData(List visits, Context context) { } + // delivery kiy + if (has_delivery_kit.equalsIgnoreCase("No")) { + List details = visits.get(x).getVisitDetails().get("delivery_kit"); + if (details != null && StringUtils.isNotBlank(details.get(0).getHumanReadable())) { + has_delivery_kit = details.get(0).getHumanReadable(); + } + + } + String[] hf_params = {"anc_hf_visit_date", "weight", "sys_bp", "dia_bp", "hb_level", "ifa_received", "tests_done"}; extractHFVisit(visits, hf_params, hf_visits, x, context); @@ -91,6 +105,7 @@ public void processViewData(List visits, Context context) { processLastVisit(days, context); processAncCard(has_card, context); + processDeliveryKit(has_delivery_kit, context); processHealthFacilityVisit(hf_visits, context); processTTImmunization(immunizations, context); processIPTp(services, context); @@ -183,6 +198,11 @@ protected void processAncCard(String has_card, Context context) { customFontTextViewAncCard.setText(MessageFormat.format("{0}: {1}", context.getString(R.string.anc_home_visit_anc_card_received), getTranslatedText(context, has_card.toLowerCase()))); } + protected void processDeliveryKit(String has_delivery_kit, Context context) { + linearLayoutDeliveryKit.setVisibility(View.VISIBLE); + customFontTextViewDeliveryKit.setText(MessageFormat.format("{0}: {1}", context.getString(R.string.anc_home_visit_delivery_kit_received), getTranslatedText(context, has_delivery_kit.toLowerCase()))); + } + protected void processHealthFacilityVisit(List> hf_visits, Context context) { if (hf_visits != null && hf_visits.size() > 0) { linearLayoutHealthFacilityVisit.setVisibility(View.VISIBLE); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/DefaultChildMedicalHistoryActivityFlv.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/DefaultChildMedicalHistoryActivityFlv.java index c3da6bda3f..5fe0323c5f 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/DefaultChildMedicalHistoryActivityFlv.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/DefaultChildMedicalHistoryActivityFlv.java @@ -42,9 +42,9 @@ public abstract class DefaultChildMedicalHistoryActivityFlv implements CoreChild protected List visits; protected Map> visitMap = new LinkedHashMap<>(); protected Map> vaccineMap = new LinkedHashMap<>(); - private Context context; + protected Context context; private LinearLayout parentView; - private SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()); + protected SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()); @Override public View bindViews(Activity activity) { @@ -271,7 +271,7 @@ private VisitDetailsFormatter getDewormingFormatter() { }; } - private VisitDetailsFormatter getDieataryFormatter() { + protected VisitDetailsFormatter getDieataryFormatter() { return (title, details, visitDate) -> { String diet_diversity = NCUtils.getText(details); String value = ""; @@ -423,7 +423,7 @@ private void medicalHistory(List medicalHistories, String type, } } - private interface VisitDetailsFormatter { + protected interface VisitDetailsFormatter { String format(String title, List details, Date visitDate); } } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/HIA2ReportsActivity.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/HIA2ReportsActivity.java index 616cb5970b..ad1846e8c2 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/HIA2ReportsActivity.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/activity/HIA2ReportsActivity.java @@ -150,7 +150,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { for (int j = 0; j < fieldsArray.length(); j++) { JSONObject fieldJsonObject = fieldsArray.getJSONObject(j); String key = fieldJsonObject.getString(KEY); - String value = fieldJsonObject.getString(VALUE); + String value = !fieldJsonObject.has(VALUE) ? "" : fieldJsonObject.getString(VALUE); result.put(key, value); } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/adapter/NavigationAdapter.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/adapter/NavigationAdapter.java index 4b8a4cc028..75a5cff0c0 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/adapter/NavigationAdapter.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/adapter/NavigationAdapter.java @@ -11,6 +11,7 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; +import org.apache.commons.lang3.StringUtils; import org.smartregister.chw.core.R; import org.smartregister.chw.core.listener.NavigationListener; import org.smartregister.chw.core.model.NavigationOption; @@ -23,27 +24,25 @@ public class NavigationAdapter extends RecyclerView.Adapter { private List navigationOptionList; - private String selectedView = CoreConstants.DrawerMenu.ALL_FAMILIES; private View.OnClickListener onClickListener; private Context context; private Map registeredActivities; + private NavigationAdapterHost host; - public NavigationAdapter(List navigationOptions, Activity context, Map registeredActivities) { + public NavigationAdapter(List navigationOptions, Activity context, Map registeredActivities, NavigationAdapterHost host) { this.navigationOptionList = navigationOptions; this.context = context; this.onClickListener = new NavigationListener(context, this); this.registeredActivities = registeredActivities; + this.host = host; } public String getSelectedView() { - if (selectedView == null || selectedView.equals("")) - setSelectedView(CoreConstants.DrawerMenu.ALL_FAMILIES); - - return selectedView; + return StringUtils.isBlank(host.getSelectedView()) ? CoreConstants.DrawerMenu.ALL_FAMILIES : host.getSelectedView(); } public void setSelectedView(String selectedView) { - this.selectedView = selectedView; + host.setSelectedView(selectedView); this.notifyDataSetChanged(); } @@ -65,7 +64,7 @@ public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { holder.getView().setTag(model.getMenuTitle()); - if (selectedView != null && selectedView.equals(model.getMenuTitle())) { + if (host.getSelectedView().equals(model.getMenuTitle())) { holder.tvCount.setTextColor(context.getResources().getColor(R.color.navigation_item_selected)); holder.tvName.setTextColor(context.getResources().getColor(R.color.navigation_item_selected)); holder.ivIcon.setImageResource(model.getResourceActiveID()); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/adapter/NavigationAdapterHost.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/adapter/NavigationAdapterHost.java new file mode 100644 index 0000000000..891c011f8e --- /dev/null +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/adapter/NavigationAdapterHost.java @@ -0,0 +1,7 @@ +package org.smartregister.chw.core.adapter; + +public interface NavigationAdapterHost { + String getSelectedView(); + + void setSelectedView(String selectedView); +} diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/application/CoreChwApplication.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/application/CoreChwApplication.java index b9562a6c5e..3513b636e6 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/application/CoreChwApplication.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/application/CoreChwApplication.java @@ -39,8 +39,8 @@ import org.smartregister.repository.UniqueIdRepository; import org.smartregister.sync.ClientProcessorForJava; import org.smartregister.sync.helper.ECSyncHelper; +import org.smartregister.view.activity.BaseLoginActivity; import org.smartregister.view.activity.DrishtiApplication; -import org.smartregister.view.activity.LoginActivity; import java.util.ArrayList; import java.util.List; @@ -63,7 +63,6 @@ public abstract class CoreChwApplication extends DrishtiApplication implements C protected ClientProcessorForJava clientProcessorForJava; private LocationRepository locationRepository; private ECSyncHelper ecSyncHelper; - private String password; private UniqueIdRepository uniqueIdRepository; private HIA2IndicatorsRepository hIA2IndicatorsRepository; private DailyTalliesRepository dailyTalliesRepository; @@ -155,7 +154,7 @@ public void onCreate() { @Override public void logoutCurrentUser() { - Intent intent = new Intent(getApplicationContext(), LoginActivity.class); + Intent intent = new Intent(getApplicationContext(), BaseLoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -164,6 +163,7 @@ public void logoutCurrentUser() { context.userService().logoutSession(); } + /* @Override public String getPassword() { if (password == null) { @@ -172,6 +172,7 @@ public String getPassword() { } return password; } + */ @Override public ClientProcessorForJava getClientProcessor() { diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/contract/CoreMalariaProfileContract.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/contract/CoreMalariaProfileContract.java index bb647bcd81..de2915aaa3 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/contract/CoreMalariaProfileContract.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/contract/CoreMalariaProfileContract.java @@ -4,18 +4,18 @@ import org.smartregister.chw.malaria.contract.MalariaProfileContract; import org.smartregister.repository.AllSharedPreferences; -public class CoreMalariaProfileContract { - public interface View extends MalariaProfileContract.View { +public interface CoreMalariaProfileContract { + interface View extends MalariaProfileContract.View { void startFormActivity(JSONObject formJson); } - public interface Presenter extends MalariaProfileContract.Presenter { + interface Presenter extends MalariaProfileContract.Presenter { void startHfMalariaFollowupForm(); void createHfMalariaFollowupEvent(AllSharedPreferences allSharedPreferences, String jsonString, String entityID) throws Exception; } - public interface Interactor extends MalariaProfileContract.Interactor { + interface Interactor extends MalariaProfileContract.Interactor { void createHfMalariaFollowupEvent(AllSharedPreferences allSharedPreferences, String jsonString, String entityIDd) throws Exception; } } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/custom_views/NavigationMenu.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/custom_views/NavigationMenu.java index f05cb4ddc7..76f4f93d3d 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/custom_views/NavigationMenu.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/custom_views/NavigationMenu.java @@ -32,6 +32,7 @@ import org.smartregister.chw.core.activity.CoreCommunityRespondersRegisterActivity; import org.smartregister.chw.core.activity.CoreStockInventoryReportActivity; import org.smartregister.chw.core.adapter.NavigationAdapter; +import org.smartregister.chw.core.adapter.NavigationAdapterHost; import org.smartregister.chw.core.application.CoreChwApplication; import org.smartregister.chw.core.contract.NavigationContract; import org.smartregister.chw.core.model.NavigationModel; @@ -56,7 +57,7 @@ import timber.log.Timber; -public class NavigationMenu implements NavigationContract.View, SyncStatusBroadcastReceiver.SyncStatusListener, DrawerLayout.DrawerListener { +public class NavigationMenu implements NavigationContract.View, SyncStatusBroadcastReceiver.SyncStatusListener, DrawerLayout.DrawerListener , NavigationAdapterHost { private static NavigationMenu instance; private static WeakReference activityWeakReference; private static CoreChwApplication application; @@ -75,6 +76,7 @@ public class NavigationMenu implements NavigationContract.View, SyncStatusBroadc private NavigationContract.Presenter mPresenter; private View parentView; private Timer timer; + private static String selectedView = CoreConstants.DrawerMenu.ALL_FAMILIES; public static void setupNavigationMenu(CoreChwApplication application, NavigationMenu.Flavour menuFlavor, NavigationModel.Flavor modelFlavor, Map registeredActivities, boolean showDeviceToDeviceSync) { @@ -288,10 +290,7 @@ private void registerNavigation(Activity parentActivity) { if (recyclerView != null) { List navigationOptions = mPresenter.getOptions(); - if (navigationAdapter == null) { - navigationAdapter = new NavigationAdapter(navigationOptions, parentActivity, registeredActivities); - } - + navigationAdapter = new NavigationAdapter(navigationOptions, parentActivity, registeredActivities, this); RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(parentActivity); recyclerView.setLayoutManager(mLayoutManager); recyclerView.setItemAnimator(new DefaultItemAnimator()); @@ -481,6 +480,16 @@ public DrawerLayout getDrawer() { return drawer; } + @Override + public String getSelectedView() { + return NavigationMenu.selectedView; + } + + @Override + public void setSelectedView(String selectedView) { + NavigationMenu.selectedView = selectedView; + } + public static String getChildNavigationCountString(){ return menuFlavor.childNavigationMenuCountString(); } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/dao/ReferralTaskDao.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/dao/ReferralTaskDao.java index 6278bcd186..ac7678cc2b 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/dao/ReferralTaskDao.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/dao/ReferralTaskDao.java @@ -2,19 +2,21 @@ import org.joda.time.DateTime; import org.smartregister.dao.AbstractDao; +import org.smartregister.domain.Period; import org.smartregister.domain.Task; import java.util.List; -public class ReferralTaskDao extends AbstractDao{ +public class ReferralTaskDao extends AbstractDao { /** * This method return a list of referral tasks that were marked as done on Facility and are now * supposed to be dismissed (Completed) by the chw; 3 days after the CHW marked them as done. + * * @return list of referral tasks to be completed */ - public static List getToBeCompletedReferralTasks(){ + public static List getToBeCompletedReferralTasks() { String queryStatement = - "SELECT task.*\n" + + "SELECT task.*\n" + "FROM task\n" + " INNER JOIN ec_referral_dismissal on task._id = ec_referral_dismissal.referral_task\n" + "WHERE (Cast((JulianDay(ec_referral_dismissal.notification_dismissal_date) -\n" + @@ -34,13 +36,17 @@ private static AbstractDao.DataMap mapColumnValuesToTask() { task.setGroupIdentifier(getCursorValue(row, "group_id")); task.setStatus(Task.TaskStatus.valueOf(getCursorValue(row, "status"))); task.setBusinessStatus(getCursorValue(row, "business_status")); - task.setPriority(getCursorIntValue(row, "priority")); + task.setPriority(Task.TaskPriority.valueOf(getCursorValue(row, "priority"))); task.setCode(getCursorValue(row, "code")); task.setDescription(getCursorValue(row, "description")); task.setFocus(getCursorValue(row, "focus")); task.setForEntity(getCursorValue(row, "for")); - task.setExecutionStartDate(new DateTime(getCursorValueAsDate(row, "start"))); - task.setExecutionEndDate(new DateTime(getCursorValueAsDate(row, "end"))); + + Period period = new Period(); + period.setStart(new DateTime(getCursorValueAsDate(row, "start"))); + period.setEnd(new DateTime(getCursorValueAsDate(row, "end"))); + task.setExecutionPeriod(period); + task.setAuthoredOn(new DateTime(getCursorValueAsDate(row, "authored_on"))); task.setLastModified(new DateTime(getCursorValueAsDate(row, "last_modified"))); task.setOwner(getCursorValue(row, "owner")); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/fragment/AddMemberFragment.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/fragment/AddMemberFragment.java index 259de25e7c..3fb5e7d779 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/fragment/AddMemberFragment.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/fragment/AddMemberFragment.java @@ -83,7 +83,7 @@ public void onClick(View v) { ((CoreFamilyProfileActivity) context).startChildForm(CoreConstants.JSON_FORM.getChildRegister(), "", "", ""); dismiss(); } else if (i == R.id.layout_add_other_family_member) { - ((CoreFamilyProfileActivity) context).startFormActivity(CoreConstants.JSON_FORM.getFamilyMemberRegister(), null, null); + ((CoreFamilyProfileActivity) context).startFormActivity(CoreConstants.JSON_FORM.getFamilyMemberRegister(), null, ""); dismiss(); } } catch (Exception e) { diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/fragment/CoreChildRegisterFragment.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/fragment/CoreChildRegisterFragment.java index 86b6d7d341..a3852ce46a 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/fragment/CoreChildRegisterFragment.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/fragment/CoreChildRegisterFragment.java @@ -87,7 +87,7 @@ protected String getDefaultSortQuery() { @Override protected void startRegistration() { - ((CoreChildRegisterActivity) getActivity()).startFormActivity(CoreConstants.JSON_FORM.getChildRegister(), null, null); + ((CoreChildRegisterActivity) getActivity()).startFormActivity(CoreConstants.JSON_FORM.getChildRegister(), null, ""); //getActivity().startFormActivity(Utils.metadata().familyRegister.formName, null, null); } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/ServiceTaskModel.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/ServiceTaskModel.java deleted file mode 100644 index 754ee59b3a..0000000000 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/model/ServiceTaskModel.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.smartregister.chw.core.model; - -import org.smartregister.immunization.domain.ServiceWrapper; - -import java.util.Map; - -public class ServiceTaskModel { - private Map givenServiceMap; - private Map notGivenServiceMap; - - public Map getGivenServiceMap() { - return givenServiceMap; - } - - public void setGivenServiceMap(Map givenServiceMap) { - this.givenServiceMap = givenServiceMap; - } - - public Map getNotGivenServiceMap() { - return notGivenServiceMap; - } - - public void setNotGivenServiceMap(Map notGivenServiceMap) { - this.notGivenServiceMap = notGivenServiceMap; - } -} diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/provider/CoreRegisterProvider.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/provider/CoreRegisterProvider.java index 13a6313a94..4413af6e9b 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/provider/CoreRegisterProvider.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/provider/CoreRegisterProvider.java @@ -91,11 +91,12 @@ private void addImageView(RegisterViewHolder viewHolder, int res_id) { if (iconsLayout.getChildCount() > 3) { TextView counterTextView = (TextView) iconsLayout.getChildAt(iconsLayout.getChildCount() - 1); counterTextView.setText(context.getString(R.string.icons_counter, Integer.parseInt(counterTextView.getText().toString().substring(1)) + 1)); + counterTextView.setTextSize(context.getResources().getDimension(R.dimen.family_register_text_size)); } else if (iconsLayout.getChildCount() == 3) { addCounterTextView(iconsLayout); } else { ImageView imageView = new ImageView(context); - int size = convertDpToPixel(22, context); + int size = (int) context.getResources().getDimension(R.dimen.family_register_image_size);//convertDpToPixel(22, context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.gravity = Gravity.CENTER; imageView.setLayoutParams(layoutParams); @@ -112,7 +113,7 @@ private void addCounterTextView(LinearLayout iconsLayout) { counterTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); counterTextView.setBackground(ContextCompat.getDrawable(context, R.drawable.counter_drawable)); counterTextView.setText(context.getString(R.string.icons_counter, 1)); - int size = convertDpToPixel(34, context); + int size = (int) context.getResources().getDimension(R.dimen.family_register_count_size);//convertDpToPixel(34, context); counterTextView.getLayoutParams().height = size; counterTextView.getLayoutParams().width = size; counterTextView.setGravity(Gravity.CENTER); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/repository/CoreChwRepository.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/repository/CoreChwRepository.java index a956ec3be9..08adecb600 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/repository/CoreChwRepository.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/repository/CoreChwRepository.java @@ -110,6 +110,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { super.onUpgrade(db, oldVersion, newVersion); } + /** @Override public SQLiteDatabase getReadableDatabase() { String pass = CoreChwApplication.getInstance().getPassword(); @@ -119,7 +120,9 @@ public SQLiteDatabase getReadableDatabase() { throw new IllegalStateException("Password is blank"); } } + **/ + /** @Override public SQLiteDatabase getWritableDatabase() { String pass = CoreChwApplication.getInstance().getPassword(); @@ -129,6 +132,7 @@ public SQLiteDatabase getWritableDatabase() { throw new IllegalStateException("Password is blank"); } } + **/ @Override public synchronized SQLiteDatabase getWritableDatabase(String password) { diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/repository/ScheduleRepository.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/repository/ScheduleRepository.java index e8c95192f5..1c599fcf97 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/repository/ScheduleRepository.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/repository/ScheduleRepository.java @@ -5,8 +5,11 @@ import net.sqlcipher.database.SQLiteDatabase; +import org.smartregister.chw.anc.util.DBConstants; +import org.smartregister.chw.core.application.CoreChwApplication; import org.smartregister.chw.core.contract.ScheduleTask; import org.smartregister.chw.core.domain.BaseScheduleTask; +import org.smartregister.chw.core.utils.CoreConstants; import org.smartregister.repository.BaseRepository; import java.text.ParseException; @@ -163,6 +166,21 @@ public void deleteSchedulesByFamilyEntityID(String baseEntityID) { } } + public void deleteFamilyKitSchedule(String baseEntityID) { + try { + getWritableDatabase().execSQL("DELETE from schedule_service where schedule_name = 'FAMILY_KIT' and base_entity_id = '" + baseEntityID + "'"); + } catch (Exception e) { + Timber.e(e); + } + } + + public void closeChildMember(String baseEntityID) { + ContentValues values = new ContentValues(); + values.put("is_closed", 1); + CoreChwApplication.getInstance().getRepository().getWritableDatabase().update(CoreConstants.TABLE_NAME.CHILD, values, + DBConstants.KEY.BASE_ENTITY_ID + " = ? ", new String[]{baseEntityID}); + } + public void deleteScheduleByName(String name) { try { getWritableDatabase().delete(TABLE_NAME, SCHEDULE_NAME + "= ?", new String[]{name}); @@ -259,6 +277,7 @@ private String getDateForDB(Date date) { return sdf.format(date); } + private Date getCursorDate(Cursor c, String column_name) { String val = c.getType(c.getColumnIndex(column_name)) == Cursor.FIELD_TYPE_NULL ? null : c.getString(c.getColumnIndex(column_name)); if (val == null) diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/rule/FamilyKitAlertRule.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/rule/FamilyKitAlertRule.java index 98f30eee20..a8c8df9f8f 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/rule/FamilyKitAlertRule.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/rule/FamilyKitAlertRule.java @@ -2,6 +2,10 @@ import android.content.Context; +import org.joda.time.DateTime; + +import java.util.Date; + //All date formats ISO 8601 yyyy-mm-dd /** @@ -13,6 +17,18 @@ public FamilyKitAlertRule(Context context, long lastVisitDateLong, long dateCrea super(context, lastVisitDateLong, dateCreatedLong); } + public Date getDueDate() { + Date lastDueDate = getLastDueDate(); + if (lastDueDate.getTime() < getFirstDayOfMonth(new Date()).getTime()) { + if (getFirstDayOfMonth(lastVisitDate.toDate()).getTime() < getFirstDayOfMonth(new Date()).getTime()) { + return getFirstDayOfMonth(new DateTime(lastVisitDate.toDate()).plusMonths(1).toDate()); + } + return getFirstDayOfMonth(new Date()); + } else { + return lastDueDate; + } + } + @Override public String getRuleKey() { return "familyKitAlertRule"; diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/rule/FpAlertRule.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/rule/FpAlertRule.java index 95543a54cc..38697a442a 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/rule/FpAlertRule.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/rule/FpAlertRule.java @@ -38,6 +38,7 @@ public void setVisitID(String visitID) { this.visitID = visitID; } + // TODO -> This always returns TRUE? public boolean isCocPopValid(int dueDay, int overdueDate) { if (lastVisitDate != null) { this.dueDate = (new DateTime(this.lastVisitDate)).plusDays(this.pillCycles * 28).minusDays(dueDay); @@ -49,6 +50,7 @@ public boolean isCocPopValid(int dueDay, int overdueDate) { return true; } + // TODO -> This always returns TRUE? public boolean isCondomValid(int dueDay, int overdueDate) { if (lastVisitDate != null) { int monthOfYear = new DateTime(lastVisitDate).getMonthOfYear(); @@ -72,6 +74,7 @@ public boolean isCondomValid(int dueDay, int overdueDate) { return true; } + // TODO -> This always returns TRUE? public boolean isInjectionValid(int dueDay, int overdueDate) { if (lastVisitDate != null) { this.dueDate = new DateTime(lastVisitDate).plusDays(dueDay); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/rule/MonthlyAlertRule.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/rule/MonthlyAlertRule.java index c42a6d51e2..ed5b1d2c1d 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/rule/MonthlyAlertRule.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/rule/MonthlyAlertRule.java @@ -20,7 +20,7 @@ public abstract class MonthlyAlertRule implements ICommonRule { public String visitMonthName; private LocalDate dateCreated; private LocalDate todayDate; - private LocalDate lastVisitDate; + public LocalDate lastVisitDate; private Context context; public MonthlyAlertRule(Context context, long lastVisitDateLong, long dateCreatedLong) { @@ -94,11 +94,11 @@ public boolean isVisitWithinThisMonth() { return (lastVisitDate != null) && isVisitThisMonth(lastVisitDate, todayDate); } - private Date getFirstDayOfMonth(Date refDate) { + public Date getFirstDayOfMonth(Date refDate) { return new DateTime(refDate).withDayOfMonth(1).toDate(); } - protected Date getLastDayOfMonth(Date refDate) { + public Date getLastDayOfMonth(Date refDate) { DateTime first = new DateTime(refDate).withDayOfMonth(1); return first.plusMonths(1).minusDays(1).toDate(); } @@ -117,7 +117,7 @@ public Date getDueDate() { } } - private Date getLastDueDate() { + public Date getLastDueDate() { if (lastVisitDate != null && getFirstDayOfMonth(lastVisitDate.toDate()).getTime() < dateCreated.toDate().getTime()) { return getFirstDayOfMonth(lastVisitDate.toDate()); } else { diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/service/CoreAuthorizationService.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/service/CoreAuthorizationService.java index 6b488a935d..78c736284c 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/service/CoreAuthorizationService.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/service/CoreAuthorizationService.java @@ -26,11 +26,21 @@ public class CoreAuthorizationService implements P2PAuthorizationService { private Map authorizationDetails = new HashMap<>(); + private boolean checkTeamId; + + public CoreAuthorizationService(boolean checkTeamId) { + this.checkTeamId = checkTeamId; + } + + public CoreAuthorizationService() { + this.checkTeamId = true; + } + @Override public void authorizeConnection(@NonNull final Map peerDeviceMap, @NonNull final AuthorizationCallback authorizationCallback) { getAuthorizationDetails(map -> { Object peerDeviceTeamId = peerDeviceMap.get(AllConstants.PeerToPeer.KEY_TEAM_ID); - if (peerDeviceTeamId instanceof String + if (!checkTeamId || peerDeviceTeamId instanceof String && peerDeviceTeamId.equals(map.get(AllConstants.PeerToPeer.KEY_TEAM_ID))) { Object peerDeviceLocationId = peerDeviceMap.get(CoreConstants.PEER_TO_PEER.LOCATION_ID); Object myLocationId = authorizationDetails.get(CoreConstants.PEER_TO_PEER.LOCATION_ID); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/sync/CoreClientProcessor.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/sync/CoreClientProcessor.java index 3896d18f32..967346b17e 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/sync/CoreClientProcessor.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/sync/CoreClientProcessor.java @@ -3,6 +3,8 @@ import android.content.ContentValues; import android.content.Context; +import net.sqlcipher.database.SQLiteDatabase; + import org.apache.commons.lang3.StringUtils; import org.smartregister.chw.anc.util.DBConstants; import org.smartregister.chw.anc.util.NCUtils; @@ -52,6 +54,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -82,7 +85,7 @@ public static void addVaccine(VaccineRepository vaccineRepository, Vaccine vacci } // if its an updated vaccine, delete the previous object - vaccineRepository.deleteVaccine(vaccine.getBaseEntityId(), vaccine.getName()); + //vaccineRepository.deleteVaccine(vaccine.getBaseEntityId(), vaccine.getName()); // Add the vaccine vaccineRepository.add(vaccine); @@ -167,7 +170,7 @@ private Table getServiceTable() { return serviceTable; } - protected void processEvents(ClientClassification clientClassification, Table vaccineTable, Table serviceTable, EventClient eventClient, Event event, String eventType) throws Exception { + public void processEvents(ClientClassification clientClassification, Table vaccineTable, Table serviceTable, EventClient eventClient, Event event, String eventType) throws Exception { switch (eventType) { case VaccineIntentService.EVENT_TYPE: case VaccineIntentService.EVENT_TYPE_OUT_OF_CATCHMENT: @@ -186,9 +189,12 @@ protected void processEvents(ClientClassification clientClassification, Table va processVisitEvent(Utils.processOldEvents(eventClient), CoreConstants.EventType.CHILD_HOME_VISIT); processEvent(eventClient.getEvent(), eventClient.getClient(), clientClassification); break; + case CoreConstants.EventType.FAMILY_KIT: + processVisitEvent(Utils.processOldEvents(eventClient), CoreConstants.EventType.FAMILY_KIT); + processEvent(eventClient.getEvent(), eventClient.getClient(), clientClassification); + break; case CoreConstants.EventType.CHILD_VISIT_NOT_DONE: case CoreConstants.EventType.WASH_CHECK: - case CoreConstants.EventType.FAMILY_KIT: case CoreConstants.EventType.ROUTINE_HOUSEHOLD_VISIT: processVisitEvent(eventClient); processEvent(eventClient.getEvent(), eventClient.getClient(), clientClassification); @@ -237,7 +243,7 @@ protected void processEvents(ClientClassification clientClassification, Table va if (eventClient.getClient() == null) { return; } - processRemoveMember(eventClient.getClient().getBaseEntityId(), event.getEventDate().toDate()); + processRemoveMember(eventClient.getClient().getBaseEntityId(), event); break; case FamilyPlanningConstants.EventType.FAMILY_PLANNING_CHANGE_METHOD: clientProcessByObs(eventClient, clientClassification, event, "reason_stop_fp_chw", "decided_to_change_method"); @@ -278,7 +284,7 @@ protected void processEvents(ClientClassification clientClassification, Table va if (eventClient.getClient() == null) { return; } - processRemoveChild(eventClient.getClient().getBaseEntityId(), event.getEventDate().toDate()); + processRemoveChild(eventClient.getClient().getBaseEntityId(), event); break; case CoreConstants.EventType.CHILD_VACCINE_CARD_RECEIVED: if (eventClient.getClient() == null) { @@ -327,12 +333,15 @@ protected void processEvents(ClientClassification clientClassification, Table va public void processDeleteEvent(Event event) { try { + String formSubmissionId = event.getDetails() == null ? "" : event.getDetails().get("deleted_form_submission_id"); // delete from vaccine table - EventDao.deleteVaccineByFormSubmissionId(event.getFormSubmissionId()); - // delete from visit table - EventDao.deleteVisitByFormSubmissionId(event.getFormSubmissionId()); - // delete from recurring service table - EventDao.deleteServiceByFormSubmissionId(event.getFormSubmissionId()); + if (StringUtils.isNotBlank(formSubmissionId)) { + EventDao.deleteVaccineByFormSubmissionId(formSubmissionId); + // delete from visit table + EventDao.deleteVisitByFormSubmissionId(formSubmissionId); + // delete from recurring service table + EventDao.deleteServiceByFormSubmissionId(formSubmissionId); + } Timber.d("Ending processDeleteEvent: %s", event.getEventId()); } catch (Exception e) { @@ -625,9 +634,32 @@ private void processRemoveFamily(String familyID, Date eventDate) { } } - private void processRemoveMember(String baseEntityId, Date eventDate) { + private SQLiteDatabase getWritableDatabase() { + return CoreChwApplication.getInstance().getRepository().getWritableDatabase(); + } - Date myEventDate = eventDate; + private Map readObs(Event event) { + Map obsMap = new HashMap<>(); + if (event.getObs() != null) { + for (Obs obs : event.getObs()) { + if (obs.getValues().size() > 0) + obsMap.put(obs.getFormSubmissionField(), obs.getValues().get(0).toString()); + } + } + return obsMap; + } + + private Date getDate(Map obsMap, String key) throws ParseException { + String strDod = obsMap.get(key); + if (StringUtils.isBlank(strDod)) return null; + + SimpleDateFormat nfDf = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH); + return nfDf.parse(strDod); + } + + private void processRemoveMember(String baseEntityId, Event event) { + + Date myEventDate = event.getEventDate().toDate(); if (myEventDate == null) { myEventDate = new Date(); } @@ -636,28 +668,40 @@ private void processRemoveMember(String baseEntityId, Date eventDate) { return; } + SimpleDateFormat defaultDf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); + Map obsMap = readObs(event); + AllCommonsRepository commonsRepository = CoreChwApplication.getInstance().getAllCommonsRepository(CoreConstants.TABLE_NAME.FAMILY_MEMBER); if (commonsRepository != null) { ContentValues values = new ContentValues(); - values.put(DBConstants.KEY.DATE_REMOVED, new SimpleDateFormat("yyyy-MM-dd").format(myEventDate)); + values.put(DBConstants.KEY.DATE_REMOVED, defaultDf.format(myEventDate)); values.put("is_closed", 1); - CoreChwApplication.getInstance().getRepository().getWritableDatabase().update(CoreConstants.TABLE_NAME.FAMILY_MEMBER, values, - DBConstants.KEY.BASE_ENTITY_ID + " = ? ", new String[]{baseEntityId}); - // clean fts table - CoreChwApplication.getInstance().getRepository().getWritableDatabase().update(CommonFtsObject.searchTableName(CoreConstants.TABLE_NAME.FAMILY_MEMBER), values, + getWritableDatabase().update(CommonFtsObject.searchTableName(CoreConstants.TABLE_NAME.FAMILY_MEMBER), values, " object_id = ? ", new String[]{baseEntityId}); + + try { + Date dod = getDate(obsMap, "date_died"); + if (dod != null) + values.put(DBConstants.KEY.DOD, defaultDf.format(dod)); + } catch (ParseException e) { + Timber.e(e); + } + + getWritableDatabase().update(CoreConstants.TABLE_NAME.FAMILY_MEMBER, values, + DBConstants.KEY.BASE_ENTITY_ID + " = ? ", new String[]{baseEntityId}); + // Utils.context().commonrepository(CoreConstants.TABLE_NAME.FAMILY_MEMBER).populateSearchValues(baseEntityId, DBConstants.KEY.DATE_REMOVED, new SimpleDateFormat("yyyy-MM-dd").format(eventDate), null); - CoreChwApplication.getInstance().getContext().alertService().deleteOfflineAlerts(baseEntityId); + //CoreChwApplication.getInstance().getContext().alertService().deleteOfflineAlerts(baseEntityId); } } - private void processRemoveChild(String baseEntityId, Date eventDate) { + private void processRemoveChild(String baseEntityId, Event event) { - Date myEventDate = eventDate; + Date myEventDate = event.getEventDate().toDate(); if (myEventDate == null) { myEventDate = new Date(); } @@ -666,22 +710,33 @@ private void processRemoveChild(String baseEntityId, Date eventDate) { return; } + Map obsMap = readObs(event); + SimpleDateFormat defaultDf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); + AllCommonsRepository commonsRepository = CoreChwApplication.getInstance().getAllCommonsRepository(CoreConstants.TABLE_NAME.CHILD); if (commonsRepository != null) { ContentValues values = new ContentValues(); - values.put(DBConstants.KEY.DATE_REMOVED, new SimpleDateFormat("yyyy-MM-dd").format(myEventDate)); + values.put(DBConstants.KEY.DATE_REMOVED, defaultDf.format(myEventDate)); values.put("is_closed", 1); - CoreChwApplication.getInstance().getRepository().getWritableDatabase().update(CoreConstants.TABLE_NAME.CHILD, values, - DBConstants.KEY.BASE_ENTITY_ID + " = ? ", new String[]{baseEntityId}); - // clean fts table - CoreChwApplication.getInstance().getRepository().getWritableDatabase().update(CommonFtsObject.searchTableName(CoreConstants.TABLE_NAME.CHILD), values, + getWritableDatabase().update(CommonFtsObject.searchTableName(CoreConstants.TABLE_NAME.CHILD), values, CommonFtsObject.idColumn + " = ? ", new String[]{baseEntityId}); + try { + Date dod = getDate(obsMap, "date_died"); + if (dod != null) + values.put(DBConstants.KEY.DOD, defaultDf.format(dod)); + } catch (ParseException e) { + Timber.e(e); + } + + getWritableDatabase().update(CoreConstants.TABLE_NAME.CHILD, values, + DBConstants.KEY.BASE_ENTITY_ID + " = ? ", new String[]{baseEntityId}); + // Utils.context().commonrepository(CoreConstants.TABLE_NAME.CHILD).populateSearchValues(baseEntityId, DBConstants.KEY.DATE_REMOVED, new SimpleDateFormat("yyyy-MM-dd").format(eventDate), null); - CoreChwApplication.getInstance().getContext().alertService().deleteOfflineAlerts(baseEntityId); + //CoreChwApplication.getInstance().getContext().alertService().deleteOfflineAlerts(baseEntityId); } } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/sync/intent/CloseExpiredReferralsIntentService.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/sync/intent/CloseExpiredReferralsIntentService.java index 4e743b6ecc..acead92634 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/sync/intent/CloseExpiredReferralsIntentService.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/sync/intent/CloseExpiredReferralsIntentService.java @@ -14,6 +14,7 @@ import org.smartregister.chw.referral.util.DBConstants; import org.smartregister.clientandeventmodel.Event; import org.smartregister.clientandeventmodel.Obs; +import org.smartregister.domain.Period; import org.smartregister.domain.Task; import org.smartregister.family.FamilyLibrary; import org.smartregister.repository.AllSharedPreferences; @@ -247,7 +248,9 @@ private void referralNotYetDoneTask(String taskId, String baseEntityId) { private Task updateCurrentTask(String taskId, String baseEntityId) { Task currentTask = taskRepository.getTaskByIdentifier(taskId); DateTime now = new DateTime(); - currentTask.setExecutionEndDate(now); + Period period = new Period(); + period.setEnd(now); + currentTask.setExecutionPeriod(period); currentTask.setLastModified(now); currentTask.setForEntity(baseEntityId); currentTask.setSyncStatus(BaseRepository.TYPE_Unsynced); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/ChwServiceSchedule.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/ChwServiceSchedule.java index 257e5679e8..f839d7e32a 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/ChwServiceSchedule.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/ChwServiceSchedule.java @@ -164,7 +164,7 @@ private static AlertStatus calculateAlertStatus(DateTime dueDateTime, DateTime e Calendar today = Calendar.getInstance(); standardiseCalendarDate(today); - if (expiredCal.getTimeInMillis() < today.getTimeInMillis()) {// expired + if (expiredCal.getTimeInMillis() <= today.getTimeInMillis()) {// expired return AlertStatus.expired; } else if (dueCal.getTimeInMillis() <= today.getTimeInMillis()) {// Due return AlertStatus.normal; diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreReferralUtils.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreReferralUtils.java index b6fdfb6560..8b7ad7701f 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreReferralUtils.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/CoreReferralUtils.java @@ -19,6 +19,7 @@ import org.smartregister.clientandeventmodel.Event; import org.smartregister.commonregistry.CommonRepository; import org.smartregister.cursoradapter.SmartRegisterQueryBuilder; +import org.smartregister.domain.Period; import org.smartregister.domain.Task; import org.smartregister.family.util.DBConstants; import org.smartregister.location.helper.LocationHelper; @@ -171,13 +172,17 @@ private static void createReferralTask(String baseEntityId, AllSharedPreferences task.setGroupIdentifier(locationHelper.getOpenMrsLocationId(locationHelper.generateDefaultLocationHierarchy(CoreChwApplication.getInstance().getAllowedLocationLevels()).get(0))); task.setStatus(Task.TaskStatus.READY); task.setBusinessStatus(CoreConstants.BUSINESS_STATUS.REFERRED); - task.setPriority(3); + task.setPriority(Task.TaskPriority.ROUTINE); task.setCode(CoreConstants.JsonAssets.REFERRAL_CODE); task.setDescription(referralProblems); task.setFocus(focus); task.setForEntity(baseEntityId); DateTime now = new DateTime(); - task.setExecutionStartDate(now); + + Period period = new Period(); + period.setStart(now); + task.setExecutionPeriod(period); + task.setAuthoredOn(now); task.setLastModified(now); task.setOwner(allSharedPreferences.fetchRegisteredANM()); diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/Utils.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/Utils.java index 3ff6698bf6..f10653415b 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/Utils.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/Utils.java @@ -101,14 +101,29 @@ public abstract class Utils extends org.smartregister.family.util.Utils { public static final SimpleDateFormat yyyy_mm_dd = new SimpleDateFormat("yyyy-mm-dd"); private static List assets; + /** + * Can be replaced with a final constant or direct reference + * @return + */ + @Deprecated public static int getAnCWomanImageResourceIdentifier() { return R.drawable.anc_woman; } + /** + * Can be replaced with a final constant or direct reference + * @return + */ + @Deprecated public static int getPnCWomanImageResourceIdentifier() { return R.drawable.pnc_woman; } + /** + * Can be replaced with a final constant or direct reference + * @return + */ + @Deprecated public static int getMemberImageResourceIdentifier() { return R.mipmap.ic_member; } @@ -154,7 +169,7 @@ public static String firstCharacterUppercase(String str) { } public static String convertToDateFormateString(String timeAsDDMMYYYY, SimpleDateFormat dateFormat) { - SimpleDateFormat sdf = new SimpleDateFormat("dd-mm-yyyy", Locale.getDefault());//12-08-2018 + SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());//12-08-2018 try { Date date = sdf.parse(timeAsDDMMYYYY); return dateFormat.format(date); @@ -229,10 +244,20 @@ public static Bitmap getBitmap(Drawable drawable) { return result; } + /** + * Can be replaced with a final constant or direct reference + * @return + */ + @Deprecated public static int getOverDueProfileImageResourceIDentifier() { return R.color.visit_status_over_due; } + /** + * Can be replaced with a final constant or direct reference + * @return + */ + @Deprecated public static int getDueProfileImageResourceIDentifier() { return R.color.due_profile_blue; } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/VisitVaccineUtil.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/VisitVaccineUtil.java index bc219fe7b8..bcbe1bb825 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/VisitVaccineUtil.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/VisitVaccineUtil.java @@ -53,10 +53,10 @@ public static Map getAllVaccines() { List allVacs = new ArrayList<>(); - List woman = ImmunizationLibrary.getVaccineCacheMap().get("woman").vaccineRepo; + List woman = ImmunizationLibrary.getVaccineCacheMap().get("woman").vaccineRepo; allVacs.addAll(woman); - List child = ImmunizationLibrary.getVaccineCacheMap().get("child").vaccineRepo; + List child = ImmunizationLibrary.getVaccineCacheMap().get("child").vaccineRepo; allVacs.addAll(child); for (VaccineRepo.Vaccine vaccine : allVacs) { @@ -281,6 +281,7 @@ public static List getInMemoryAlerts( try { if (vaccineSchedules != null && vaccineSchedules.containsKey(vaccineCategory)) { for (VaccineSchedule curSchedule : vaccineSchedules.get(vaccineCategory).values()) { + if (curSchedule == null) continue; Alert curAlert = curSchedule.getOfflineAlert(baseEntityId, dob.toDate(), issuedVaccines); if (curAlert != null && curAlert.startDate() != null) { generatedAlerts.add(curAlert); @@ -428,7 +429,7 @@ public static String getVaccineTitle(String name, Context context) { return context.getString(R.string.at_birth); } - return name.replace("Weeks", context.getString(R.string.date_weeks)).toLowerCase() + return name.replace("Weeks", context.getString(R.string.date_weeks)) .replace("Months", context.getString(R.string.date_months)).toLowerCase(); } } diff --git a/opensrp-chw-core/src/main/res/layout/medical_history_details.xml b/opensrp-chw-core/src/main/res/layout/medical_history_details.xml index 2119685a99..97a3d00b2b 100644 --- a/opensrp-chw-core/src/main/res/layout/medical_history_details.xml +++ b/opensrp-chw-core/src/main/res/layout/medical_history_details.xml @@ -14,377 +14,411 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/opensrp-chw-core/src/main/res/values-fr/strings.xml b/opensrp-chw-core/src/main/res/values-fr/strings.xml index c2840b4163..8230c0bda5 100644 --- a/opensrp-chw-core/src/main/res/values-fr/strings.xml +++ b/opensrp-chw-core/src/main/res/values-fr/strings.xml @@ -123,13 +123,15 @@ Secondaire Université Enlever cette personne + Enlever la mère Information d\'enregistrement Enregistrement CPN Confirmation pour paludisme Visite de suivi du paludisme Diagnostic du paludisme Suivi de l\'enfant malade - Corriger enfant %1$s\'s détails + Corriger les détails de bébé %1$s + Enlever bébé %1$s Visite de %1$s faite Référer au centre de santé Mise à jour en cours... @@ -206,6 +208,7 @@ Sélectionner un nouveau chef de ménage %s adultes et %s enfants de moins de 5 ans + Fièvre Jaune Retour à profil de %1$s Depuis %1$s @@ -283,7 +286,8 @@ VISITE CPN A LA FORMATION SANITAIRE Carnet CPN - Td + VAT + Kit de livraison SP dose Analyse urinaire Dépistage VIH @@ -298,7 +302,8 @@ FAF reçu: {0} Examens effectués: {0} Carnet CPN reçu - Td{0} - fait {1} + Kit de livraison reçu + VAT{0} - fait {1} SP dose{0}- fait {1} un deux @@ -375,7 +380,9 @@ ÂG ANNULER Références%s - + G: %s + Enfant: %s + Enfants: %s Aucun numéro de téléphone fourni Signes de danger de la CPN; Symptômes:%s %s, %s @@ -424,9 +431,23 @@ %s dose + {0} (MÈRE) + {0} (BÉBÉ) + Visites CPoN au Centre de Santé + Visites CPoN + Planification Familiale + Carte de vaccination enfant + Immunisations (à la naissance) + Allaitement maternel exclusif + Visite {0}: {} + Carte de vaccination enfant reçu: {0} + Date: {0} + VPO 0: {0} + BCG: {0} + - Vaccinations (%s) \n%s \n%s - Vaccinations (%s) \n%s + Immunisations (%s) (%s) \n%s \n%s + Immunisations (%s) (%s) \n%s Jours @@ -434,6 +455,12 @@ Mois Dernière visite il y a %1$s jours + G: %1$s + Signes de danger: %1$s + Action prise: %1$s + Village: %1$s + Évaluation de la santé ThinkMD + Plan de soins ThinkMD (%1$s) Revenir à tous les clients diff --git a/opensrp-chw-core/src/main/res/values-sw/strings.xml b/opensrp-chw-core/src/main/res/values-sw/strings.xml index c7c4b68592..97cb6d9fa7 100644 --- a/opensrp-chw-core/src/main/res/values-sw/strings.xml +++ b/opensrp-chw-core/src/main/res/values-sw/strings.xml @@ -286,6 +286,7 @@ MAHUDHURIO YA KLINIKI YA WAJAWAZITO KWENYE KITUO CHA KUTOLEA HUDUMA ZA AFYA. Kadi ya kliniki ya mjamzito + Kitanda cha Uwasilishaji CHANJO YA PEPOPUNDA DOZI YA IPTp-SP Kipimo kwenye njia ya mkojo @@ -301,6 +302,7 @@ Amepewa IFA: {0} Vipimo vimefanyika: {0} Kadi ya mama mjamzito imepokelewa + Vifaa vya kujifungua vimepokelewa TT{0} - Imefanyika {1} Dozi ya IPTp-SP {0}- Imefanyika {1} 1 diff --git a/opensrp-chw-core/src/main/res/values/dimens.xml b/opensrp-chw-core/src/main/res/values/dimens.xml index dc47d39350..4052b3bda1 100644 --- a/opensrp-chw-core/src/main/res/values/dimens.xml +++ b/opensrp-chw-core/src/main/res/values/dimens.xml @@ -69,4 +69,7 @@ 8dp 8dp - \ No newline at end of file + 5sp + 22dp + 34dp + \ No newline at end of file diff --git a/opensrp-chw-core/src/main/res/values/strings.xml b/opensrp-chw-core/src/main/res/values/strings.xml index 44a94503ae..30406bd077 100644 --- a/opensrp-chw-core/src/main/res/values/strings.xml +++ b/opensrp-chw-core/src/main/res/values/strings.xml @@ -299,6 +299,7 @@ · ANC HEALTH FACILITY VISITS ANC Card + Delivery Kit TT IMMUNIZATION IPTp-SP DOSE Urine analysis @@ -314,6 +315,7 @@ IFA received: {0} Tests done: {0} ANC card received + Delivery kit received TT{0} - done {1} IPTp-SP dose{0}- done {1} 1 diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreAncMemberProfileActivityTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreAncMemberProfileActivityTest.java index 1da5f91786..37a04dac3d 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreAncMemberProfileActivityTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreAncMemberProfileActivityTest.java @@ -1,22 +1,38 @@ package org.smartregister.chw.core.activity; +import android.view.MenuItem; import android.view.View; +import android.widget.RelativeLayout; +import android.widget.TextView; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.robolectric.Robolectric; import org.robolectric.RuntimeEnvironment; +import org.robolectric.android.controller.ActivityController; import org.robolectric.util.ReflectionHelpers; +import org.smartregister.Context; +import org.smartregister.CoreLibrary; import org.smartregister.chw.anc.domain.MemberObject; +import org.smartregister.chw.core.BaseUnitTest; +import org.smartregister.chw.core.R; +import org.smartregister.chw.core.activity.impl.CoreAncMemberProfileActivityImpl; +import org.smartregister.chw.core.presenter.CoreAncMemberProfilePresenter; +import org.smartregister.chw.core.utils.CoreConstants; +import org.smartregister.domain.AlertStatus; -public class CoreAncMemberProfileActivityTest { +import timber.log.Timber; + +public class CoreAncMemberProfileActivityTest extends BaseUnitTest { private CoreAncMemberProfileActivity activity; - private View viewFamilyRow = new View(RuntimeEnvironment.systemContext); + private ActivityController controller; @Mock private MemberObject memberObject; @@ -24,21 +40,95 @@ public class CoreAncMemberProfileActivityTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); - activity = Mockito.mock(CoreAncMemberProfileActivity.class, Mockito.CALLS_REAL_METHODS); - String baseEntityId = "base-entity-id"; - memberObject.setBaseEntityId(baseEntityId); + + MockitoAnnotations.initMocks(this); + + Context context = Context.getInstance(); + CoreLibrary.init(context); + + //Auto login by default + context.session().start(context.session().lengthInMilliseconds()); + + controller = Robolectric.buildActivity(CoreAncMemberProfileActivityImpl.class).create().start(); + activity = controller.get(); + memberObject = Mockito.mock(MemberObject.class); + memberObject.setBaseEntityId("some-base-entity-id"); + memberObject.setFamilyName("Some Family Name"); + ReflectionHelpers.setField(activity, "memberObject", memberObject); + View viewFamilyRow = new View(RuntimeEnvironment.systemContext); ReflectionHelpers.setField(activity, "view_family_row", viewFamilyRow); } + @After + public void tearDown() { + try { + activity.finish(); + controller.pause().stop().destroy(); //destroy controller if we can + } catch (Exception e) { + Timber.e(e); + } + } + @Test public void registerPresenter() { activity.registerPresenter(); Assert.assertNotNull(activity.ancMemberProfilePresenter()); } + @Test + public void testOnOptionsItemSelected() { + activity = Mockito.spy(activity); + + MenuItem menuItem = Mockito.mock(MenuItem.class); + CoreConstants.JSON_FORM.setLocaleAndAssetManager(activity.getApplicationContext().getResources().getConfiguration().locale, activity.getApplicationContext().getAssets()); + + // back pressed + Mockito.doReturn(android.R.id.home).when(menuItem).getItemId(); + Mockito.doNothing().when(activity).onBackPressed(); + + activity.onOptionsItemSelected(menuItem); + Mockito.verify(activity).onBackPressed(); + + // start form + Mockito.doReturn(R.id.action_anc_member_registration).when(menuItem).getItemId(); + Mockito.doNothing().when(activity).startFormForEdit(Mockito.any(), Mockito.any()); + + activity.onOptionsItemSelected(menuItem); + Mockito.verify(activity).startFormForEdit(Mockito.eq(R.string.edit_member_form_title), Mockito.any()); + + + // start form + Mockito.doReturn(R.id.action_anc_registration).when(menuItem).getItemId(); + Mockito.doNothing().when(activity).startFormForEdit(Mockito.any(), Mockito.any()); + + activity.onOptionsItemSelected(menuItem); + Mockito.verify(activity).startFormForEdit(Mockito.eq(R.string.edit_anc_registration_form_title), Mockito.any()); + + // start form + Mockito.doReturn(R.id.anc_danger_signs_outcome).when(menuItem).getItemId(); + CoreAncMemberProfilePresenter presenter = Mockito.mock(CoreAncMemberProfilePresenter.class); + ReflectionHelpers.setField(activity, "presenter", presenter); + + activity.onOptionsItemSelected(menuItem); + Mockito.verify(presenter).startAncDangerSignsOutcomeForm(memberObject); + } + + @Test + public void testSetFamilyStatus() { + ReflectionHelpers.setField(activity, "rlFamilyServicesDue", Mockito.mock(RelativeLayout.class)); + ReflectionHelpers.setField(activity, "tvFamilyStatus", Mockito.mock(TextView.class)); + + activity.setFamilyStatus(AlertStatus.complete); + Assert.assertFalse(ReflectionHelpers.getField(activity, "hasDueServices")); + + activity.setFamilyStatus(AlertStatus.normal); + Assert.assertTrue(ReflectionHelpers.getField(activity, "hasDueServices")); + } + @Test public void openFamilyLocationStartsAncMemberMapActivity() { + activity = Mockito.spy(activity); activity.openFamilyLocation(); Mockito.verify(activity).startActivity(Mockito.any()); } diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreChildProfileActivityTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreChildProfileActivityTest.java index 1f91d01ba7..7a3b542b74 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreChildProfileActivityTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreChildProfileActivityTest.java @@ -62,10 +62,7 @@ public void setUp() { CoreLibrary.init(context); //Auto login by default - String password = "pwd"; context.session().start(context.session().lengthInMilliseconds()); - context.configuration().getDrishtiApplication().setPassword(password); - context.session().setPassword(password); controller = Robolectric.buildActivity(CoreChildProfileActivity.class).create().start(); activity = controller.get(); @@ -128,6 +125,9 @@ public void testInitializePresenter() { @Test public void testSetUpViews() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + activity.memberObject = memberObject; CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); @@ -280,6 +280,9 @@ public void testSetAge() { @Test public void testSetVisitButtonDueStatusMutatesViewsDesign() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); activity.setupViews(); @@ -295,6 +298,9 @@ public void testSetVisitButtonDueStatusMutatesViewsDesign() { @Test public void testSetVisitButtonOverdueStatus() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); activity.setupViews(); @@ -310,6 +316,9 @@ public void testSetVisitButtonOverdueStatus() { @Test public void testSetVisitNotDoneThisMonth() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); activity.setupViews(); @@ -354,6 +363,9 @@ public void testSetLastVisitRowView() { @Test public void testSetServiceNameDue() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); activity.setupViews(); @@ -372,6 +384,9 @@ public void testSetServiceNameDue() { @Test public void testSetServiceNameOverDue() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); activity.setupViews(); @@ -384,6 +399,9 @@ public void testSetServiceNameOverDue() { @Test public void testSetServiceNameUpcoming() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); activity.setupViews(); @@ -396,6 +414,9 @@ public void testSetServiceNameUpcoming() { @Test public void testSetVisitLessTwentyFourView() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); activity.setupViews(); @@ -413,6 +434,9 @@ public void testSetVisitLessTwentyFourView() { @Test public void testSetVisitAboveTwentyFourView() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); activity.setupViews(); @@ -424,6 +448,9 @@ public void testSetVisitAboveTwentyFourView() { @Test public void testSetFamilyHasNothingDue() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); activity.setupViews(); @@ -436,6 +463,9 @@ public void testSetFamilyHasNothingDue() { @Test public void testSetFamilyHasServiceDueDue() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); activity.setupViews(); @@ -448,6 +478,9 @@ public void testSetFamilyHasServiceDueDue() { @Test public void testSetFamilyHasServiceOverdue() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); activity.setupViews(); @@ -524,6 +557,9 @@ public void testOnJsonProcessed() { @Test public void testonProfileTaskFetched() { activity = Mockito.spy(activity); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_child_profile); + CoreChildProfileContract.Presenter presenter = Mockito.mock(CoreChildProfileContract.Presenter.class); Mockito.doReturn(presenter).when(activity).presenter(); activity.setupViews(); diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreFamilyOtherMemberProfileActivityTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreFamilyOtherMemberProfileActivityTest.java index 8e17350eae..e19bcfb160 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreFamilyOtherMemberProfileActivityTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreFamilyOtherMemberProfileActivityTest.java @@ -23,6 +23,7 @@ import org.smartregister.chw.core.BaseUnitTest; import org.smartregister.chw.core.R; import org.smartregister.chw.core.activity.impl.CoreFamilyOtherMemberProfileActivityImpl; +import org.smartregister.chw.core.presenter.CoreFamilyOtherMemberActivityPresenter; import org.smartregister.chw.core.utils.CoreConstants; import org.smartregister.commonregistry.CommonPersonObjectClient; @@ -45,16 +46,14 @@ public void setUp() { CoreLibrary.init(context); //Auto login by default - String password = "pwd"; context.session().start(context.session().lengthInMilliseconds()); - context.configuration().getDrishtiApplication().setPassword(password); - context.session().setPassword(password); Intent intent = new Intent(); intent.putExtra(CoreConstants.INTENT_KEY.CHILD_COMMON_PERSON, commonPersonObjectClient); controller = Robolectric.buildActivity(CoreFamilyOtherMemberProfileActivityImpl.class, intent).create().start(); activity = controller.get(); + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here } @After @@ -69,7 +68,12 @@ public void tearDown() { @Test public void testSetupViewsInitializesViews() { + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_family_other_member_profile_chw); + + ReflectionHelpers.setField(activity,"presenter", Mockito.mock(CoreFamilyOtherMemberActivityPresenter.class)); activity.setupViews(); + Assert.assertNotNull(ReflectionHelpers.getField(activity, "familyFloatingMenu")); Assert.assertNotNull(ReflectionHelpers.getField(activity, "textViewFamilyHas")); Assert.assertNotNull(ReflectionHelpers.getField(activity, "layoutFamilyHasRow")); @@ -91,6 +95,12 @@ public void testOnCreateOptionsMenuInflatesProfileMenu() { @Test public void settingGenderSetsTranslatedString() { String gender = "Female"; + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_family_other_member_profile_chw); + + ReflectionHelpers.setField(activity,"presenter", Mockito.mock(CoreFamilyOtherMemberActivityPresenter.class)); + activity.setupViews(); + activity.setProfileDetailOne(gender); Assert.assertNotNull(ReflectionHelpers.getField(activity, "detailOneView")); } diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreFamilyProfileActivityTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreFamilyProfileActivityTest.java index c158d46c17..9b3bee3a73 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreFamilyProfileActivityTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreFamilyProfileActivityTest.java @@ -23,6 +23,7 @@ import org.smartregister.chw.core.R; import org.smartregister.chw.core.activity.impl.CoreFamilyProfileActivityTestImpl; import org.smartregister.chw.core.custom_views.FamilyFloatingMenu; +import org.smartregister.chw.core.presenter.CoreFamilyProfilePresenter; import org.smartregister.chw.core.utils.ChildDBConstants; import org.smartregister.chw.core.utils.CoreConstants; import org.smartregister.commonregistry.CommonPersonObjectClient; @@ -46,10 +47,7 @@ public void setUp() { CoreLibrary.init(context); //Auto login by default - String password = "pwd"; context.session().start(context.session().lengthInMilliseconds()); - context.configuration().getDrishtiApplication().setPassword(password); - context.session().setPassword(password); controller = Robolectric.buildActivity(CoreFamilyProfileActivityTestImpl.class).create().start(); activity = controller.get(); @@ -67,7 +65,11 @@ public void tearDown() { @Test public void testSetupViews() { + activity.setTheme(org.smartregister.R.style.AppTheme); //we need this here + activity.setContentView(R.layout.activity_family_profile); + ReflectionHelpers.setField(activity, "presenter", Mockito.mock(CoreFamilyProfilePresenter.class)); activity.setupViews(); + Assert.assertNotNull(ReflectionHelpers.getField(activity, "familyFloatingMenu")); } diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivityTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivityTest.java index 0a5818dc6f..b59c7e889e 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivityTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreFamilyRegisterActivityTest.java @@ -44,10 +44,10 @@ public void setUp() { CoreLibrary.init(context); //Auto login by default - String password = "pwd"; + //String password = "pwd"; context.session().start(context.session().lengthInMilliseconds()); - context.configuration().getDrishtiApplication().setPassword(password); - context.session().setPassword(password); + //context.configuration().getDrishtiApplication().setPassword(password); + //context.session().setPassword(password); controller = Robolectric.buildActivity(CoreFamilyRegisterActivityTestImpl.class, new Intent()).create().start(); activity = controller.get(); diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CorePncMemberProfileActivityTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CorePncMemberProfileActivityTest.java index 6ed39e8229..6fefcaef7e 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CorePncMemberProfileActivityTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CorePncMemberProfileActivityTest.java @@ -47,10 +47,10 @@ public void setUp() { CoreLibrary.init(context); //Auto login by default - String password = "pwd"; + //String password = "pwd"; context.session().start(context.session().lengthInMilliseconds()); - context.configuration().getDrishtiApplication().setPassword(password); - context.session().setPassword(password); + //context.configuration().getDrishtiApplication().setPassword(password); + //context.session().setPassword(password); Intent intent = new Intent(); intent.putExtra("MemberObject", memberObject); diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreStockInventoryItemDetailsReportActivityTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreStockInventoryItemDetailsReportActivityTest.java index 69d0d94504..3ddfd39d4c 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreStockInventoryItemDetailsReportActivityTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreStockInventoryItemDetailsReportActivityTest.java @@ -48,10 +48,10 @@ public void setUp() { CoreLibrary.init(context); //Auto login by default - String password = "pwd"; + //String password = "pwd"; context.session().start(context.session().lengthInMilliseconds()); - context.configuration().getDrishtiApplication().setPassword(password); - context.session().setPassword(password); + //context.configuration().getDrishtiApplication().setPassword(password); + //context.session().setPassword(password); String stockItemName = "Male Condoms"; String providerName = "All-CHWs"; diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreStockInventoryReportActivityTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreStockInventoryReportActivityTest.java index b6e4345cf7..9dd03554bc 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreStockInventoryReportActivityTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/CoreStockInventoryReportActivityTest.java @@ -55,10 +55,7 @@ public void setUp() { year = "2019"; //Auto login by default - String password = "pwd"; context.session().start(context.session().lengthInMilliseconds()); - context.configuration().getDrishtiApplication().setPassword(password); - context.session().setPassword(password); controller = Robolectric.buildActivity(CoreStockInventoryReportActivity.class).create().start(); activity = controller.get(); @@ -101,6 +98,8 @@ public void testReloadRecycler() { getProvider(); List stockUsageItemReportList = activity.getStockUsageItemReportList(stockMonth, stockYear); CoreStockUsageItemAdapter coreStockUsageItemAdapter = new CoreStockUsageItemAdapter(stockUsageItemReportList, activity); + + activity.onCreation(); activity.recyclerView.setAdapter(coreStockUsageItemAdapter); activity.reloadRecycler(selected); diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/impl/CoreAncMemberProfileActivityImpl.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/impl/CoreAncMemberProfileActivityImpl.java new file mode 100644 index 0000000000..ae73659d70 --- /dev/null +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/impl/CoreAncMemberProfileActivityImpl.java @@ -0,0 +1,25 @@ +package org.smartregister.chw.core.activity.impl; + +import org.smartregister.chw.core.activity.CoreAncMemberProfileActivity; +import org.smartregister.domain.Task; + +import java.util.Set; + +import timber.log.Timber; + +public class CoreAncMemberProfileActivityImpl extends CoreAncMemberProfileActivity { + @Override + public void openUpcomingService() { + Timber.v("openUpcomingService"); + } + + @Override + public void openFamilyDueServices() { + Timber.v("openFamilyDueServices"); + } + + @Override + public void setClientTasks(Set taskList) { + Timber.v("setClientTasks"); + } +} diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/impl/CoreFamilyRegisterActivityTestImpl.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/impl/CoreFamilyRegisterActivityTestImpl.java index 15dd3bbebe..485614abfc 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/impl/CoreFamilyRegisterActivityTestImpl.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/impl/CoreFamilyRegisterActivityTestImpl.java @@ -6,6 +6,9 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; + +import timber.log.Timber; public class CoreFamilyRegisterActivityTestImpl extends CoreFamilyRegisterActivity { @Override @@ -13,6 +16,11 @@ protected BaseRegisterFragment getRegisterFragment() { return Mockito.mock(BaseRegisterFragment.class); } + @Override + public void startFormActivity(String s, String s1, Map map) { + Timber.v("startFormActivity stub"); + } + public List getViewIdentifiers() { List result = new ArrayList<>(); result.add("1234"); diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/mock/BaseChwNotificationRegisterMock.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/mock/BaseChwNotificationRegisterMock.java index 4d63f44b68..9334d1d136 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/mock/BaseChwNotificationRegisterMock.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/activity/mock/BaseChwNotificationRegisterMock.java @@ -14,6 +14,9 @@ import java.util.HashMap; import java.util.List; +import java.util.Map; + +import timber.log.Timber; import static org.mockito.Mockito.mock; @@ -40,6 +43,11 @@ protected Fragment[] getOtherFragments() { return new Fragment[0]; } + @Override + public void startFormActivity(String s, String s1, Map map) { + Timber.v("startFormActivity stub"); + } + @Override public void startFormActivity(String formName, String entityId, String metaData) { //mock do nothing diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/application/TestApplication.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/application/TestApplication.java index be4eb2204b..41dc3b9ef0 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/application/TestApplication.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/application/TestApplication.java @@ -4,6 +4,7 @@ import org.robolectric.Robolectric; import org.smartregister.Context; import org.smartregister.CoreLibrary; +import org.smartregister.chw.core.sync.SampleSyncConfiguration; import org.smartregister.chw.pnc.PncLibrary; import org.smartregister.configurableviews.ConfigurableViewsLibrary; import org.smartregister.family.BuildConfig; @@ -27,7 +28,7 @@ public void onCreate() { mInstance = this; context = Context.getInstance(); context.updateApplicationContext(getApplicationContext()); - CoreLibrary.init(context); + CoreLibrary.init(context, new SampleSyncConfiguration()); ConfigurableViewsLibrary.init(context); diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/custom_views/CoreFamilyPlanningFloatingMenuTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/custom_views/CoreFamilyPlanningFloatingMenuTest.java index 86f8a4601e..62fd1dac67 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/custom_views/CoreFamilyPlanningFloatingMenuTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/custom_views/CoreFamilyPlanningFloatingMenuTest.java @@ -1,30 +1,27 @@ package org.smartregister.chw.core.custom_views; +import android.os.Build; import android.view.View; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; import org.smartregister.Context; -import org.smartregister.CoreLibrary; +import org.smartregister.chw.core.application.TestApplication; import org.smartregister.chw.core.listener.OnClickFloatingMenu; -import org.smartregister.commonregistry.CommonRepository; import java.util.ArrayList; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; - +@RunWith(RobolectricTestRunner.class) +@Config(application = TestApplication.class, sdk = Build.VERSION_CODES.P) public class CoreFamilyPlanningFloatingMenuTest { - @Mock - private CommonRepository commonRepository; - - @Mock - private Context context; private CoreFamilyPlanningFloatingMenu coreFamilyPlanningFloatingMenu; @@ -38,9 +35,6 @@ public class CoreFamilyPlanningFloatingMenuTest { public void setUp() { MockitoAnnotations.initMocks(this); coreFamilyPlanningFloatingMenu = Mockito.mock(CoreFamilyPlanningFloatingMenu.class, Mockito.CALLS_REAL_METHODS); - - CoreLibrary.init(context); - when(context.commonrepository(anyString())).thenReturn(commonRepository); Context.bindtypes = new ArrayList<>(); } diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/custom_views/FamilyFloatingMenuTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/custom_views/FamilyFloatingMenuTest.java new file mode 100644 index 0000000000..dff8982fcc --- /dev/null +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/custom_views/FamilyFloatingMenuTest.java @@ -0,0 +1,84 @@ +package org.smartregister.chw.core.custom_views; + +import android.view.View; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.FragmentActivity; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.robolectric.Robolectric; +import org.smartregister.Context; +import org.smartregister.CoreLibrary; +import org.smartregister.chw.core.BaseUnitTest; +import org.smartregister.chw.core.listener.OnClickFloatingMenu; +import org.smartregister.commonregistry.CommonRepository; +import org.smartregister.receiver.SyncStatusBroadcastReceiver; + +import java.util.ArrayList; + +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + +public class FamilyFloatingMenuTest extends BaseUnitTest { + @Mock + private CommonRepository commonRepository; + + @Mock + private Context context; + + private FamilyFloatingMenu familyFloatingMenu; + + @Mock + private View view; + + @Mock + private OnClickFloatingMenu onClickFloatingMenu; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + familyFloatingMenu = Mockito.mock(FamilyFloatingMenu.class, Mockito.CALLS_REAL_METHODS); + + CoreLibrary.init(context); + when(context.commonrepository(anyString())).thenReturn(commonRepository); + FragmentActivity activity = Robolectric.buildActivity(AppCompatActivity.class).create().resume().get(); + Context.bindtypes = new ArrayList<>(); + SyncStatusBroadcastReceiver.init(activity); + + } + + @Test + public void whenSetupViewsAnswered() { + familyFloatingMenu.setClickListener(onClickFloatingMenu); + + ArgumentCaptor captor = ArgumentCaptor.forClass(OnClickFloatingMenu.class); + Mockito.verify(familyFloatingMenu, Mockito.times(1)).setClickListener(captor.capture()); + Assert.assertEquals(captor.getValue(), onClickFloatingMenu); + } + @Test + public void whenOnClickAnswered() { + Mockito.doNothing().when(familyFloatingMenu).onClick(view); + familyFloatingMenu.onClick(view); + + ArgumentCaptor captor = ArgumentCaptor.forClass(View.class); + Mockito.verify(familyFloatingMenu, Mockito.times(1)).onClick(captor.capture()); + Assert.assertEquals(captor.getValue(), view); + } + + @Test + public void whenRedrawAnswered() { + Mockito.doNothing().when(familyFloatingMenu).reDraw(true); + familyFloatingMenu.reDraw(true); + + ArgumentCaptor captor = ArgumentCaptor.forClass(Boolean.class); + Mockito.verify(familyFloatingMenu, Mockito.times(1)).reDraw(captor.capture()); + Assert.assertEquals(captor.getValue(), true); + } + +} diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/dao/FHIRBundleDaoTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/dao/FHIRBundleDaoTest.java index 7bcc0774d2..e5ad9703f4 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/dao/FHIRBundleDaoTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/dao/FHIRBundleDaoTest.java @@ -14,7 +14,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import org.smartregister.CoreLibrary; import org.smartregister.chw.core.utils.Utils; import org.smartregister.thinkmd.model.FHIRBundleModel; @@ -31,8 +30,6 @@ public class FHIRBundleDaoTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); - org.smartregister.Context context = org.smartregister.Context.getInstance(); - CoreLibrary.init(context); } @PrepareForTest({ChildDao.class, Utils.class}) diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/dao/ReferralTaskDaoTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/dao/ReferralTaskDaoTest.java index 928a0ecf0a..ad44236b00 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/dao/ReferralTaskDaoTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/dao/ReferralTaskDaoTest.java @@ -6,11 +6,9 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.mockito.junit.MockitoJUnitRunner; import org.smartregister.domain.Task; import org.smartregister.repository.Repository; @@ -18,7 +16,6 @@ import static org.smartregister.domain.Task.TaskStatus.READY; -@RunWith(MockitoJUnitRunner.class) public class ReferralTaskDaoTest extends ReferralTaskDao { @Mock private Repository repository; @@ -38,7 +35,7 @@ public void testGetToBeCompletedReferralTasks() { MatrixCursor matrixCursor = new MatrixCursor(new String[]{"_id", "plan_id", "group_id", "status", "business_status", "priority", "code", "description", "focus", "for", "start", "end", "authored_on", "last_modified", "owner", "sync_status", "server_version", "structure_id", "reason_reference", "location", "requester"}); - matrixCursor.addRow(new Object[]{"1", "plan", "group", READY, "Complete", 3, "ANC", "referred", "ANC Visit", + matrixCursor.addRow(new Object[]{"1", "plan", "group", READY, "Complete", "ROUTINE", "ANC", "referred", "ANC Visit", "location.properties.uid:415-2342fc", "1589962159596", "1589962159596", "1589962159596", "1589962159596", "chwone", 1, "1566393632423", "structure._id.33efadf1-feda-4861-a979-ff4f7cec9ea7", "assigned to", "2c3a0ebd-f79d-4128-a6d3-5dfbffbd01c8", "chwone"}); diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/implementation/MonthlyAlertRuleImpl.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/implementation/MonthlyAlertRuleImpl.java new file mode 100644 index 0000000000..d1f28454f3 --- /dev/null +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/implementation/MonthlyAlertRuleImpl.java @@ -0,0 +1,17 @@ +package org.smartregister.chw.core.implementation; + +import android.content.Context; + +import org.smartregister.chw.core.rule.MonthlyAlertRule; + +public class MonthlyAlertRuleImpl extends MonthlyAlertRule { + + public MonthlyAlertRuleImpl(Context context, long lastVisitDateLong, long dateCreatedLong) { + super(context, lastVisitDateLong, dateCreatedLong); + } + + @Override + public String getRuleKey() { + return null; + } +} diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/presenter/CoreChildRegisterFragmentPresenterTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/presenter/CoreChildRegisterFragmentPresenterTest.java new file mode 100644 index 0000000000..b0b2d2e410 --- /dev/null +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/presenter/CoreChildRegisterFragmentPresenterTest.java @@ -0,0 +1,83 @@ +package org.smartregister.chw.core.presenter; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.robolectric.util.ReflectionHelpers; +import org.smartregister.chw.core.contract.CoreChildRegisterFragmentContract; +import org.smartregister.configurableviews.model.Field; +import org.smartregister.configurableviews.model.RegisterConfiguration; +import org.smartregister.configurableviews.model.View; +import org.smartregister.configurableviews.model.ViewConfiguration; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class CoreChildRegisterFragmentPresenterTest { + + @Mock + private CoreChildRegisterFragmentContract.View view; + + @Mock + private CoreChildRegisterFragmentContract.Model model; + + private CoreChildRegisterFragmentPresenter presenter; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + presenter = Mockito.mock(CoreChildRegisterFragmentPresenter.class, Mockito.CALLS_REAL_METHODS); + ReflectionHelpers.setField(presenter, "viewReference", new WeakReference<>(view)); + ReflectionHelpers.setField(presenter, "model", model); + ReflectionHelpers.setField(presenter, "viewConfigurationIdentifier", "12345"); + } + + @Test + public void testProcessViewConfigurations() { + ViewConfiguration viewConfiguration = Mockito.mock(ViewConfiguration.class); + Mockito.doReturn(viewConfiguration).when(model).getViewConfiguration("12345"); + + Set changes = new HashSet<>(); + Mockito.doReturn(changes).when(model).getRegisterActiveColumns("12345"); + Mockito.doReturn(Mockito.mock(RegisterConfiguration.class)).when(viewConfiguration).getMetadata(); + + presenter.processViewConfigurations(); + Assert.assertEquals(ReflectionHelpers.getField(presenter, "visibleColumns"), changes); + } + + @Test + public void testInitializeQueries() { + presenter.initializeQueries("sample"); + Mockito.verify(view).initializeQueryParams(Mockito.any(), Mockito.any(), Mockito.any()); + Mockito.verify(view).initializeAdapter(Mockito.any()); + Mockito.verify(view).countExecute(); + Mockito.verify(view).filterandSortInInitializeQueries(); + } + + @Test + public void testUpdateSortAndFilter() { + List filterList = new ArrayList<>(); + Field sortField = Mockito.mock(Field.class); + presenter.updateSortAndFilter(filterList, sortField); + Mockito.verify(view).updateFilterAndFilterStatus(Mockito.any(), Mockito.any()); + } + + @Test + public void testGetMainCondition() { + String condition = " ec_child.date_removed is null AND ((( julianday('now') - julianday(ec_child.dob))/365.25) <5) and (( ifnull(ec_child.entry_point,'') <> 'PNC' ) or (ifnull(ec_child.entry_point,'') = 'PNC' and ( date(ec_child.dob, '+28 days') <= date() and ((SELECT is_closed FROM ec_family_member WHERE base_entity_id = ec_child.mother_entity_id ) = 0))) or (ifnull(ec_child.entry_point,'') = 'PNC' and (SELECT is_closed FROM ec_family_member WHERE base_entity_id = ec_child.mother_entity_id ) = 1)) and ((( julianday('now') - julianday(ec_child.dob))/365.25) < 5) "; + Assert.assertEquals(condition, presenter.getMainCondition()); + } + + @Test + public void testGetMainConditionWithTable() { + String condition = " tableName.date_removed is null AND ((( julianday('now') - julianday(ec_child.tableName.dob))/365.25) <5) and (( ifnull(ec_child.tableName.entry_point,'') <> 'PNC' ) or (ifnull(ec_child.tableName.entry_point,'') = 'PNC' and ( date(ec_child.tableName.dob, '+28 days') <= date() and ((SELECT is_closed FROM ec_family_member WHERE base_entity_id = ec_child.tableName.mother_entity_id ) = 0))) or (ifnull(ec_child.entry_point,'') = 'PNC' and (SELECT is_closed FROM ec_family_member WHERE base_entity_id = ec_child.mother_entity_id ) = 1)) and ((( julianday('now') - julianday(ec_child.tableName.dob))/365.25) < 5) "; + String tableName = "tableName"; + Assert.assertEquals(condition, presenter.getMainCondition(tableName)); + } +} diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/presenter/CoreFamilyRemoveMemberPresenterTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/presenter/CoreFamilyRemoveMemberPresenterTest.java new file mode 100644 index 0000000000..cdbc3e86ba --- /dev/null +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/presenter/CoreFamilyRemoveMemberPresenterTest.java @@ -0,0 +1,126 @@ +package org.smartregister.chw.core.presenter; + +import org.json.JSONObject; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.rule.PowerMockRule; +import org.robolectric.util.ReflectionHelpers; +import org.smartregister.chw.core.contract.FamilyRemoveMemberContract; +import org.smartregister.commonregistry.CommonPersonObjectClient; +import org.smartregister.family.util.DBConstants; +import org.smartregister.opd.utils.OpdDbConstants; + +import java.lang.ref.WeakReference; +import java.util.HashMap; + + +@PrepareForTest(CoreFamilyRemoveMemberPresenter.class) +public class CoreFamilyRemoveMemberPresenterTest { + + @Rule + public PowerMockRule rule = new PowerMockRule(); + + @Mock + private FamilyRemoveMemberContract.View view; + + @Mock + private FamilyRemoveMemberContract.Interactor interactor; + + @Mock + private FamilyRemoveMemberContract.Model model; + + private CoreFamilyRemoveMemberPresenter removeMemberPresenter; + + private CommonPersonObjectClient commonPersonClient; + + private HashMap columnMaps; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + removeMemberPresenter = Mockito.mock(CoreFamilyRemoveMemberPresenter.class, Mockito.CALLS_REAL_METHODS); + ReflectionHelpers.setField(removeMemberPresenter, "viewReference", new WeakReference<>(view)); + ReflectionHelpers.setField(removeMemberPresenter, "interactor", interactor); + ReflectionHelpers.setField(removeMemberPresenter, "model", model); + ReflectionHelpers.setField(removeMemberPresenter, "familyHead", "family-head-entity-id"); + ReflectionHelpers.setField(removeMemberPresenter, "primaryCaregiver", "primary-care-giver"); + ReflectionHelpers.setField(removeMemberPresenter, "familyBaseEntityId", "family-entity-id"); + + commonPersonClient = new CommonPersonObjectClient("test-case-id", new HashMap<>(), "test"); + columnMaps = new HashMap<>(); + + commonPersonClient.setColumnmaps(columnMaps); + } + + @Test + public void removeMemberStartsRemoveMemberForm() throws Exception { + columnMaps.put(DBConstants.KEY.BASE_ENTITY_ID, ""); + columnMaps.put(OpdDbConstants.KEY.REGISTER_TYPE, ""); + CoreFamilyRemoveMemberPresenter presenterSpy = PowerMockito.spy(removeMemberPresenter); + PowerMockito.doNothing().when(presenterSpy, "startRemoveMemberForm", ArgumentMatchers.any(CommonPersonObjectClient.class)); + Assert.assertNotNull(commonPersonClient); + presenterSpy.removeMember(commonPersonClient); + PowerMockito.verifyPrivate(presenterSpy).invoke("startRemoveMemberForm", ArgumentMatchers.any(CommonPersonObjectClient.class)); + } + + + @Test + public void removeFamilyHeadInvokesProcessFamilyMember() { + columnMaps.put(DBConstants.KEY.BASE_ENTITY_ID, "family-head-entity-id"); + columnMaps.put(OpdDbConstants.KEY.REGISTER_TYPE, ""); + + removeMemberPresenter.removeMember(commonPersonClient); + Mockito.verify(interactor, Mockito.times(1)).processFamilyMember( + ArgumentMatchers.eq("family-entity-id"), + ArgumentMatchers.any(CommonPersonObjectClient.class), + ArgumentMatchers.any(CoreFamilyRemoveMemberPresenter.class)); + } + + @Test + public void removeEveryoneStartsRemovalForm() { + JSONObject form = Mockito.mock(JSONObject.class); + Mockito.when(model.prepareFamilyRemovalForm( + ArgumentMatchers.eq("family-entity-id"), + ArgumentMatchers.eq("family-name"), + ArgumentMatchers.eq("family-details"))).thenReturn(form); + removeMemberPresenter.removeEveryone("family-name", "family-details"); + Mockito.verify(view, Mockito.times(1)).startJsonActivity(form); + } + + @Test + public void familyRemovedExecutesViewEveryoneRemoved(){ + removeMemberPresenter.onFamilyRemoved(false); + Mockito.verify(view, Mockito.times(0)).onEveryoneRemoved(); + removeMemberPresenter.onFamilyRemoved(true); + Mockito.verify(view, Mockito.times(1)).onEveryoneRemoved(); + } + + @Test + public void memberRemovedExecutesViewOnMemberRemoved(){ + removeMemberPresenter.memberRemoved("test-removal"); + Mockito.verify(view, Mockito.times(1)).onMemberRemoved("test-removal"); + } + + @Test + public void getMainConditionReturnsCorrectString() { + String mainCondition = String.format(" %s = '%s' and %s is null and %s is null ", + DBConstants.KEY.OBJECT_RELATIONAL_ID, "family-entity-id", + DBConstants.KEY.DATE_REMOVED, + DBConstants.KEY.DOD); + Assert.assertEquals(mainCondition, removeMemberPresenter.getMainCondition()); + } + + @Test + public void getDefaultSortQueryReturnsCorrectString() { + String defaultSortQuery = String.format(" %s ASC ", DBConstants.KEY.DOB); + Assert.assertEquals(defaultSortQuery, removeMemberPresenter.getDefaultSortQuery()); + } +} diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/rule/FpAlertRuleTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/rule/FpAlertRuleTest.java new file mode 100644 index 0000000000..7db64cce5d --- /dev/null +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/rule/FpAlertRuleTest.java @@ -0,0 +1,123 @@ +package org.smartregister.chw.core.rule; + +import org.joda.time.DateTime; +import org.joda.time.LocalDate; +import org.joda.time.LocalTime; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.robolectric.util.ReflectionHelpers; +import org.smartregister.chw.core.BaseRobolectricTest; +import org.smartregister.chw.core.utils.CoreConstants; +import org.smartregister.chw.fp.util.FamilyPlanningConstants; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class FpAlertRuleTest extends BaseRobolectricTest { + + private FpAlertRule fpAlertRule; + private DateTime lastVisitDate; + private DateTime dueDate; + private DateTime expiryDate; + private DateTime overDueDate; + + @Before + public void setUp() throws ParseException { + Date fpDate = new SimpleDateFormat("dd-MM-yyyy").parse("17-11-2020"); + Date lastVisit = new SimpleDateFormat("dd-MM-yyyy").parse("17-10-2020"); + fpAlertRule = new FpAlertRule(fpDate, lastVisit, 10, FamilyPlanningConstants.DBConstants.FP_COC); + ReflectionHelpers.setField(fpAlertRule, "visitID", "test-visit-id"); + } + + + @Test + public void canGetVisitId() { + Assert.assertEquals("test-visit-id", fpAlertRule.getVisitID()); + } + + + @Test + public void canGetIfFemaleSterilizationFollowUpOneValid() { + ReflectionHelpers.setField(fpAlertRule, "fpDifference", 5); + Assert.assertFalse(fpAlertRule.isFemaleSterilizationFollowUpOneValid(10, 15, 20)); + Assert.assertTrue(fpAlertRule.isFemaleSterilizationFollowUpOneValid(2, 6, 10)); + } + + @Test + public void buttonStatusDoneIfVisitBeforeExpiry() { + lastVisitDate = LocalDate.now().toDateTime(LocalTime.MIDNIGHT); + dueDate = LocalDate.now().minusDays(5).toDateTime(LocalTime.MIDNIGHT); + expiryDate = LocalDate.now().plusDays(10).toDateTime(LocalTime.MIDNIGHT); + + ReflectionHelpers.setField(fpAlertRule, "dueDate", dueDate); + ReflectionHelpers.setField(fpAlertRule, "expiryDate", expiryDate); + ReflectionHelpers.setField(fpAlertRule, "lastVisitDate", lastVisitDate); + Assert.assertEquals(CoreConstants.VISIT_STATE.VISIT_DONE, fpAlertRule.getButtonStatus()); + } + + @Test + public void buttonStatusDueIfVisitBeforeOverdue() { + lastVisitDate = LocalDate.now().minusDays(10).toDateTime(LocalTime.MIDNIGHT); + dueDate = LocalDate.now().minusDays(5).toDateTime(LocalTime.MIDNIGHT); + overDueDate = LocalDate.now().plusDays(10).toDateTime(LocalTime.MIDNIGHT); + + ReflectionHelpers.setField(fpAlertRule, "dueDate", dueDate); + ReflectionHelpers.setField(fpAlertRule, "overDueDate", overDueDate); + ReflectionHelpers.setField(fpAlertRule, "lastVisitDate", lastVisitDate); + Assert.assertEquals(CoreConstants.VISIT_STATE.DUE, fpAlertRule.getButtonStatus()); + } + + + @Test + public void buttonStatusOverDueIfVisitAfterOverdue() { + lastVisitDate = LocalDate.now().minusDays(10).toDateTime(LocalTime.MIDNIGHT); + dueDate = LocalDate.now().minusDays(5).toDateTime(LocalTime.MIDNIGHT); + overDueDate = LocalDate.now().minusDays(1).toDateTime(LocalTime.MIDNIGHT); + expiryDate = LocalDate.now().plusDays(10).toDateTime(LocalTime.MIDNIGHT); + + ReflectionHelpers.setField(fpAlertRule, "dueDate", dueDate); + ReflectionHelpers.setField(fpAlertRule, "expiryDate", expiryDate); + ReflectionHelpers.setField(fpAlertRule, "overDueDate", overDueDate); + ReflectionHelpers.setField(fpAlertRule, "lastVisitDate", lastVisitDate); + Assert.assertEquals(CoreConstants.VISIT_STATE.OVERDUE, fpAlertRule.getButtonStatus()); + } + + + @Test + public void buttonStatusNotDueIfDateBeforeDueAndExpiry() { + lastVisitDate = LocalDate.now().toDateTime(LocalTime.MIDNIGHT); + dueDate = LocalDate.now().plusDays(10).toDateTime(LocalTime.MIDNIGHT); + expiryDate = LocalDate.now().plusDays(20).toDateTime(LocalTime.MIDNIGHT); + + ReflectionHelpers.setField(fpAlertRule, "dueDate", dueDate); + ReflectionHelpers.setField(fpAlertRule, "expiryDate", expiryDate); + ReflectionHelpers.setField(fpAlertRule, "lastVisitDate", lastVisitDate); + Assert.assertEquals(CoreConstants.VISIT_STATE.NOT_DUE_YET, fpAlertRule.getButtonStatus()); + } + + + @Test + public void canGetDueDate() { + dueDate = LocalDate.now().plusDays(10).toDateTime(LocalTime.MIDNIGHT); + ReflectionHelpers.setField(fpAlertRule, "dueDate", dueDate); + Assert.assertEquals(dueDate.toDate(), fpAlertRule.getDueDate()); + } + + @Test + public void canGetOverdueDate() { + overDueDate = LocalDate.now().minusDays(1).toDateTime(LocalTime.MIDNIGHT); + ReflectionHelpers.setField(fpAlertRule, "overDueDate", overDueDate); + Assert.assertEquals(overDueDate.toDate(), fpAlertRule.getOverDueDate()); + } + + @Test + public void canGetExpiryDate() { + expiryDate = LocalDate.now().plusDays(10).toDateTime(LocalTime.MIDNIGHT); + ReflectionHelpers.setField(fpAlertRule, "expiryDate", expiryDate); + Assert.assertEquals(expiryDate.toDate(), fpAlertRule.getExpiryDate()); + } + + +} \ No newline at end of file diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/rule/MonthlyAlertRuleTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/rule/MonthlyAlertRuleTest.java new file mode 100644 index 0000000000..7343911805 --- /dev/null +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/rule/MonthlyAlertRuleTest.java @@ -0,0 +1,60 @@ +package org.smartregister.chw.core.rule; + +import android.content.Context; + +import org.joda.time.DateTime; +import org.joda.time.LocalDate; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.powermock.reflect.Whitebox; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.util.ReflectionHelpers; +import org.smartregister.chw.core.BaseRobolectricTest; +import org.smartregister.chw.core.implementation.MonthlyAlertRuleImpl; + +import java.util.Date; + + +/** + * Created by Qazi Abubakar + */ + +public class MonthlyAlertRuleTest extends BaseRobolectricTest { + + private MonthlyAlertRule monthlyAlertRule; + + @Before + public void setUp() { + Context context = RuntimeEnvironment.application; + monthlyAlertRule = new MonthlyAlertRuleImpl(context, new Date().getTime(), new Date().getTime()); + } + + @Test + public void lastDueDateIs1stIfLastVisitEarlierThanCreated() throws Exception { + Date firstDayOfThisMonth = LocalDate.now().withDayOfMonth(1).toDate(); + LocalDate dateCreated = LocalDate.fromDateFields(firstDayOfThisMonth).plusWeeks(2); + LocalDate lastVisitDate = LocalDate.fromDateFields(firstDayOfThisMonth).plusWeeks(1); + + ReflectionHelpers.setField(monthlyAlertRule, "dateCreated", dateCreated); + ReflectionHelpers.setField(monthlyAlertRule, "lastVisitDate", lastVisitDate); + + Assert.assertEquals(firstDayOfThisMonth, Whitebox.invokeMethod(monthlyAlertRule, "getLastDueDate")); + } + + @Test + public void testGetLastDayOfMonth(){ + DateTime first = new DateTime(new Date()).withDayOfMonth(1); + Date lastDate = first.plusMonths(1).minusDays(1).toDate(); + Assert.assertNotEquals(first.toDate(), monthlyAlertRule.getLastDayOfMonth(new Date())); + Assert.assertEquals(lastDate.toString(), monthlyAlertRule.getLastDayOfMonth(new Date()).toString()); + } + + @Test + public void testGetFirstDayOfMonth(){ + DateTime first = new DateTime(new Date()).withDayOfMonth(1); + Date lastDate = first.plusMonths(1).minusDays(1).toDate(); + Assert.assertEquals(first.toDate(), monthlyAlertRule.getFirstDayOfMonth(new Date())); + Assert.assertNotEquals(lastDate, monthlyAlertRule.getFirstDayOfMonth(new Date())); + } +} diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/sync/CoreClientProcessorTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/sync/CoreClientProcessorTest.java new file mode 100644 index 0000000000..fe6c3094e8 --- /dev/null +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/sync/CoreClientProcessorTest.java @@ -0,0 +1,58 @@ +package org.smartregister.chw.core.sync; + +import android.content.Context; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.smartregister.chw.core.BaseUnitTest; +import org.smartregister.domain.Client; +import org.smartregister.domain.Event; +import org.smartregister.domain.db.EventClient; +import org.smartregister.immunization.domain.Vaccine; +import org.smartregister.immunization.repository.VaccineRepository; + +import java.util.ArrayList; +import java.util.List; + +public class CoreClientProcessorTest extends BaseUnitTest { + + @Mock + private Context context; + + @Mock + private VaccineRepository vaccineRepository; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testAddVaccine() { + Vaccine vaccine = new Vaccine(); + vaccine.setName("MEASLES 1"); + + CoreClientProcessor.addVaccine(vaccineRepository, vaccine); + Mockito.verify(vaccineRepository).add(vaccine); + Mockito.verify(vaccineRepository).updateFtsSearch(Mockito.any()); + } + + @Test + public void testProcessClient() throws Exception { + CoreClientProcessor processor = Mockito.spy(new CoreClientProcessor(context)); + Mockito.doNothing().when(processor).processEvents(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); + + List eventClients = new ArrayList<>(); + Event event = new Event(); + event.setEventType("Remove Family"); + EventClient eventClient = new EventClient(event, Mockito.mock(Client.class)); + eventClients.add(eventClient); + eventClients.add(eventClient); + + processor.processClient(eventClients); + Mockito.verify(processor, Mockito.times(2)).processEvents(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); + } +} diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/sync/SampleSyncConfiguration.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/sync/SampleSyncConfiguration.java new file mode 100644 index 0000000000..88330b0a51 --- /dev/null +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/sync/SampleSyncConfiguration.java @@ -0,0 +1,74 @@ +package org.smartregister.chw.core.sync; + +import org.smartregister.SyncConfiguration; +import org.smartregister.SyncFilter; +import org.smartregister.view.activity.BaseLoginActivity; + +import java.util.List; + +public class SampleSyncConfiguration extends SyncConfiguration { + @Override + public int getSyncMaxRetries() { + return 0; + } + + @Override + public SyncFilter getSyncFilterParam() { + return SyncFilter.LOCATION_ID; + } + + @Override + public String getSyncFilterValue() { + return "12324"; + } + + @Override + public int getUniqueIdSource() { + return 0; + } + + @Override + public int getUniqueIdBatchSize() { + return 0; + } + + @Override + public int getUniqueIdInitialBatchSize() { + return 0; + } + + @Override + public SyncFilter getEncryptionParam() { + return SyncFilter.LOCATION_ID; + } + + @Override + public boolean updateClientDetailsTable() { + return false; + } + + @Override + public List getSynchronizedLocationTags() { + return null; + } + + @Override + public String getTopAllowedLocationLevel() { + return null; + } + + @Override + public String getOauthClientId() { + return null; + } + + @Override + public String getOauthClientSecret() { + return null; + } + + @Override + public Class getAuthenticationActivity() { + return null; + } +} diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/utils/CoreConstantsTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/utils/CoreConstantsTest.java index e4faad3005..f5da123102 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/utils/CoreConstantsTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/utils/CoreConstantsTest.java @@ -1,18 +1,34 @@ package org.smartregister.chw.core.utils; +import android.content.res.AssetManager; import android.os.Build; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; +import org.robolectric.util.ReflectionHelpers; +import org.smartregister.chw.core.application.CoreChwApplication; import org.smartregister.chw.core.application.TestApplication; +import java.util.Locale; + @RunWith(RobolectricTestRunner.class) @Config(application = TestApplication.class, sdk = Build.VERSION_CODES.P) public class CoreConstantsTest { + @Mock + private CoreConstants.JSON_FORM jsonForm; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + @Test public void getUnifiedReferralForms() { Assert.assertEquals(CoreConstants.JSON_FORM.getAncUnifiedReferralForm(), "referrals/anc_referral_form"); @@ -33,6 +49,51 @@ public void getMenuType() { Assert.assertEquals(CoreConstants.MenuType.ChangePrimaryCare, "ChangePrimaryCare"); } + @Test + public void testGetFamilyKit() { + Locale locale = CoreChwApplication.getInstance().getResources().getConfiguration().locale; + AssetManager assetManager = CoreChwApplication.getInstance().getAssets(); + ReflectionHelpers.setField(jsonForm, "assetManager", assetManager); + ReflectionHelpers.setField(jsonForm, "locale", locale); + Assert.assertEquals(Utils.getLocalForm("family_kit", locale, assetManager), CoreConstants.JSON_FORM.getFamilyKit()); + } + + @Test + public void testGetWashCheck() { + Locale locale = CoreChwApplication.getInstance().getResources().getConfiguration().locale; + AssetManager assetManager = CoreChwApplication.getInstance().getAssets(); + ReflectionHelpers.setField(jsonForm, "assetManager", assetManager); + ReflectionHelpers.setField(jsonForm, "locale", locale); + Assert.assertEquals(Utils.getLocalForm("wash_check", locale, assetManager), CoreConstants.JSON_FORM.getWashCheck()); + } + + @Test + public void testGetFamilyRegister() { + Locale locale = CoreChwApplication.getInstance().getResources().getConfiguration().locale; + AssetManager assetManager = CoreChwApplication.getInstance().getAssets(); + ReflectionHelpers.setField(jsonForm, "assetManager", assetManager); + ReflectionHelpers.setField(jsonForm, "locale", locale); + Assert.assertEquals(Utils.getLocalForm("family_register", locale, assetManager), CoreConstants.JSON_FORM.getFamilyRegister()); + } + + @Test + public void testGetFamilyMemberRegister() { + Locale locale = CoreChwApplication.getInstance().getResources().getConfiguration().locale; + AssetManager assetManager = CoreChwApplication.getInstance().getAssets(); + ReflectionHelpers.setField(jsonForm, "assetManager", assetManager); + ReflectionHelpers.setField(jsonForm, "locale", locale); + Assert.assertEquals(Utils.getLocalForm("family_member_register", locale, assetManager), CoreConstants.JSON_FORM.getFamilyMemberRegister()); + } + + @Test + public void testGetChildRegister() { + Locale locale = CoreChwApplication.getInstance().getResources().getConfiguration().locale; + AssetManager assetManager = CoreChwApplication.getInstance().getAssets(); + ReflectionHelpers.setField(jsonForm, "assetManager", assetManager); + ReflectionHelpers.setField(jsonForm, "locale", locale); + Assert.assertEquals(Utils.getLocalForm("child_enrollment", locale, assetManager), CoreConstants.JSON_FORM.getChildRegister()); + } + @Test public void testGetStockUsageForm() { Assert.assertEquals("stock_usage_report", CoreConstants.JSON_FORM.getStockUsageForm()); diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/utils/UtilsTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/utils/UtilsTest.java index 8c31ae1fb5..3193c58536 100644 --- a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/utils/UtilsTest.java +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/utils/UtilsTest.java @@ -16,6 +16,7 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; +import org.smartregister.chw.core.R; import org.smartregister.chw.core.application.CoreChwApplication; import org.smartregister.chw.core.application.TestApplication; import org.smartregister.chw.referral.domain.MemberObject; @@ -50,6 +51,70 @@ public void setUp() { MockitoAnnotations.initMocks(this); } + @Test + public void testGetAnCWomanImageResourceIdentifier() { + Assert.assertEquals(R.drawable.anc_woman, Utils.getAnCWomanImageResourceIdentifier()); + } + + @Test + public void testGetPnCWomanImageResourceIdentifier() { + Assert.assertEquals(R.drawable.pnc_woman, Utils.getPnCWomanImageResourceIdentifier()); + } + + @Test + public void testGetMemberImageResourceIdentifier() { + Assert.assertEquals(R.mipmap.ic_member, Utils.getMemberImageResourceIdentifier()); + } + + @Test + public void testGetYesNoAsLanguageSpecific() { + Assert.assertEquals(context.getString(R.string.yes), Utils.getYesNoAsLanguageSpecific(context, "Yes")); + Assert.assertEquals(context.getString(R.string.yes), Utils.getYesNoAsLanguageSpecific(context, "YES")); + Assert.assertEquals("", Utils.getYesNoAsLanguageSpecific(context, "")); + Assert.assertEquals(context.getString(R.string.no), Utils.getYesNoAsLanguageSpecific(context, "No")); + Assert.assertEquals(context.getString(R.string.no), Utils.getYesNoAsLanguageSpecific(context, "NO")); + Assert.assertEquals("other", Utils.getYesNoAsLanguageSpecific(context, "other")); + } + + @Test + public void testFirstCharacterUppercase() { + Assert.assertEquals(Utils.firstCharacterUppercase(" "), " "); + Assert.assertEquals(Utils.firstCharacterUppercase(""), ""); + Assert.assertEquals(Utils.firstCharacterUppercase("mike"), "Mike"); + Assert.assertEquals(Utils.firstCharacterUppercase("s"), "S"); + Assert.assertEquals(Utils.firstCharacterUppercase("kevin hart"), "Kevin hart"); + } + + @Test + public void testConvertToDateFormateString() { + Assert.assertEquals("2018-08-12", Utils.convertToDateFormateString("12-08-2018", new SimpleDateFormat("yyyy-MM-dd"))); + Assert.assertEquals("", Utils.convertToDateFormateString("me", new SimpleDateFormat("yyyy-MM-dd"))); + } + + @Test + public void testGetOverDueProfileImageResourceIDentifier() { + Assert.assertEquals(R.color.visit_status_over_due, Utils.getOverDueProfileImageResourceIDentifier()); + } + + @Test + public void testGetDueProfileImageResourceIDentifier() { + Assert.assertEquals(R.color.due_profile_blue, Utils.getDueProfileImageResourceIDentifier()); + } + + /* + public void testProcessOldEvents(){ + Gson gson = new Gson(); + String oldIllnessInfo = "{\"identifiers\":{},\"baseEntityId\":\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\",\"locationId\":\"402ecf03-af72-4c93-b099-e1ce327d815b\",\"eventDate\":\"2019-08-30T22:21:26.660Z\",\"eventType\":\"Child Home Visit\",\"formSubmissionId\":\"2735394b-b799-4cd0-9d2b-6d84d34448d9\",\"providerId\":\"chaone\",\"duration\":0,\"obs\":[{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"home_visit_id\",\"parentCode\":\"\",\"values\":[\"6f28e369-0db3-44a1-a61f-5b907a98f13e\"],\"set\":[],\"formSubmissionField\":\"home_visit_id\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"last_home_visit\",\"parentCode\":\"\",\"values\":[\"1567174886622\"],\"set\":[],\"formSubmissionField\":\"last_home_visit\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"singleVaccine\",\"parentCode\":\"\",\"values\":[\"{\\\"singleVaccinesGiven\\\":[]}\"],\"set\":[],\"formSubmissionField\":\"singleVaccine\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"groupVaccine\",\"parentCode\":\"\",\"values\":[\"{\\\"groupVaccinesGiven\\\":[]}\"],\"set\":[],\"formSubmissionField\":\"groupVaccine\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"vaccineNotGiven\",\"parentCode\":\"\",\"values\":[\"{\\\"vaccineNotGiven\\\":[]}\"],\"set\":[],\"formSubmissionField\":\"vaccineNotGiven\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"service\",\"parentCode\":\"\",\"values\":[\"{\\\"Vitamin A\\\":{\\\"alert\\\":{\\\"caseID\\\":\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\",\\\"completionDate\\\":null,\\\"expiryDate\\\":\\\"2019-09-23\\\",\\\"offline\\\":true,\\\"scheduleName\\\":\\\"Vitamin A1\\\",\\\"startDate\\\":\\\"2015-03-23\\\",\\\"status\\\":\\\"normal\\\",\\\"visitCode\\\":\\\"vitamina1\\\"},\\\"color\\\":null,\\\"createdAt\\\":null,\\\"dbKey\\\":1,\\\"defaultName\\\":\\\"Vitamin A\\\",\\\"dob\\\":\\\"2014-09-23T08:00:00.000+08:00\\\",\\\"gender\\\":\\\"Male\\\",\\\"id\\\":\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\",\\\"patientName\\\":\\\"Doudou Balde\\\",\\\"patientNumber\\\":\\\"\\\",\\\"photo\\\":{\\\"filePath\\\":null,\\\"resourceId\\\":2131230828},\\\"previousVaccineId\\\":null,\\\"serviceType\\\":{\\\"dateEntity\\\":\\\"encounter\\\",\\\"dateEntityId\\\":\\\"encounter_date\\\",\\\"expiryOffset\\\":\\\"+5y\\\",\\\"id\\\":13,\\\"milestoneOffset\\\":\\\"[+6m]\\\",\\\"name\\\":\\\"Vitamin A1\\\",\\\"preOffset\\\":\\\"+6m\\\",\\\"prerequisite\\\":\\\"dob\\\",\\\"serviceGroup\\\":\\\"child\\\",\\\"serviceLogic\\\":\\\"\\\",\\\"serviceNameEntity\\\":\\\"concept\\\",\\\"serviceNameEntityId\\\":\\\"86339AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\",\\\"type\\\":\\\"Vitamin A\\\",\\\"units\\\":null,\\\"updatedAt\\\":1566980540710},\\\"status\\\":\\\"due\\\",\\\"synced\\\":false,\\\"today\\\":false,\\\"updatedVaccineDate\\\":\\\"2019-08-30T22:20:42.718+08:00\\\",\\\"vaccineDate\\\":\\\"2015-03-23T00:00:00.000+08:00\\\",\\\"value\\\":null}}\"],\"set\":[],\"formSubmissionField\":\"service\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"serviceNotGiven\",\"parentCode\":\"\",\"values\":[\"{\\\"Deworming\\\":{\\\"alert\\\":{\\\"caseID\\\":\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\",\\\"completionDate\\\":null,\\\"expiryDate\\\":\\\"2019-09-23\\\",\\\"offline\\\":true,\\\"scheduleName\\\":\\\"Deworming 1\\\",\\\"startDate\\\":\\\"2015-09-23\\\",\\\"status\\\":\\\"normal\\\",\\\"visitCode\\\":\\\"deworming1\\\"},\\\"color\\\":null,\\\"createdAt\\\":null,\\\"dbKey\\\":null,\\\"defaultName\\\":\\\"Deworming\\\",\\\"dob\\\":\\\"2014-09-23T08:00:00.000+08:00\\\",\\\"gender\\\":\\\"Male\\\",\\\"id\\\":\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\",\\\"patientName\\\":\\\"Doudou Balde\\\",\\\"patientNumber\\\":\\\"\\\",\\\"photo\\\":{\\\"filePath\\\":null,\\\"resourceId\\\":2131230828},\\\"previousVaccineId\\\":null,\\\"serviceType\\\":{\\\"dateEntity\\\":\\\"encounter\\\",\\\"dateEntityId\\\":\\\"encounter_date\\\",\\\"expiryOffset\\\":\\\"+5y\\\",\\\"id\\\":22,\\\"milestoneOffset\\\":\\\"[+1y]\\\",\\\"name\\\":\\\"Deworming 1\\\",\\\"preOffset\\\":\\\"+1y\\\",\\\"prerequisite\\\":\\\"dob\\\",\\\"serviceGroup\\\":\\\"child\\\",\\\"serviceLogic\\\":\\\"\\\",\\\"serviceNameEntity\\\":\\\"concept\\\",\\\"serviceNameEntityId\\\":\\\"159922AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\",\\\"type\\\":\\\"Deworming\\\",\\\"units\\\":null,\\\"updatedAt\\\":1566980540721},\\\"status\\\":\\\"due\\\",\\\"synced\\\":false,\\\"today\\\":false,\\\"updatedVaccineDate\\\":null,\\\"vaccineDate\\\":\\\"2015-09-23T00:00:00.000+08:00\\\",\\\"value\\\":null}}\"],\"set\":[],\"formSubmissionField\":\"serviceNotGiven\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"birth_certificate\",\"parentCode\":\"\",\"values\":[\"{\\\"birtCert\\\":\\\"{\\\\\\\"count\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"encounter_type\\\\\\\":\\\\\\\"Birth Certification\\\\\\\",\\\\\\\"entity_id\\\\\\\":\\\\\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\\\\\",\\\\\\\"metadata\\\\\\\":{\\\\\\\"start\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"start\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163137AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"2019-08-30 22:20:17\\\\\\\"},\\\\\\\"end\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"end\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"2019-08-30 22:20:38\\\\\\\"},\\\\\\\"today\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"encounter\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"encounter_date\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"30-08-2019\\\\\\\"},\\\\\\\"deviceid\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"deviceid\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163149AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"865959046137007\\\\\\\"},\\\\\\\"subscriberid\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"subscriberid\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163150AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"460031208673496\\\\\\\"},\\\\\\\"simserial\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"simserial\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163151AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"89860314107971674978\\\\\\\"},\\\\\\\"phonenumber\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"phonenumber\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163152AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"\\\\\\\"},\\\\\\\"encounter_location\\\\\\\":\\\\\\\"\\\\\\\"},\\\\\\\"step1\\\\\\\":{\\\\\\\"title\\\\\\\":\\\\\\\"Birth Certification\\\\\\\",\\\\\\\"fields\\\\\\\":[{\\\\\\\"key\\\\\\\":\\\\\\\"birth_cert\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"165406AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"select one\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"spinner\\\\\\\",\\\\\\\"hint\\\\\\\":\\\\\\\"Does the child have a birth certificate?\\\\\\\",\\\\\\\"values\\\\\\\":[\\\\\\\"Yes\\\\\\\",\\\\\\\"No\\\\\\\"],\\\\\\\"openmrs_choice_ids\\\\\\\":{\\\\\\\"Yes\\\\\\\":\\\\\\\"1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"No\\\\\\\":\\\\\\\"1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\"},\\\\\\\"v_required\\\\\\\":{\\\\\\\"value\\\\\\\":true,\\\\\\\"err\\\\\\\":\\\\\\\"Please select option\\\\\\\"},\\\\\\\"step\\\\\\\":\\\\\\\"step1\\\\\\\",\\\\\\\"is-rule-check\\\\\\\":true,\\\\\\\"value\\\\\\\":\\\\\\\"Yes\\\\\\\"},{\\\\\\\"key\\\\\\\":\\\\\\\"birth_cert_issue_date\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"164129AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"date_picker\\\\\\\",\\\\\\\"hint\\\\\\\":\\\\\\\"Birth certificate issuance date\\\\\\\",\\\\\\\"expanded\\\\\\\":false,\\\\\\\"max_date\\\\\\\":\\\\\\\"today\\\\\\\",\\\\\\\"min_date\\\\\\\":\\\\\\\"today-1802d\\\\\\\",\\\\\\\"v_required\\\\\\\":{\\\\\\\"value\\\\\\\":\\\\\\\"true\\\\\\\",\\\\\\\"err\\\\\\\":\\\\\\\"Please enter Birth certificate issuance date\\\\\\\"},\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":true,\\\\\\\"value\\\\\\\":\\\\\\\"30-08-2019\\\\\\\"},{\\\\\\\"key\\\\\\\":\\\\\\\"birth_cert_num\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"162052AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"text\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"edit_text\\\\\\\",\\\\\\\"hint\\\\\\\":\\\\\\\"Birth certificate number\\\\\\\",\\\\\\\"v_required\\\\\\\":{\\\\\\\"value\\\\\\\":\\\\\\\"true\\\\\\\",\\\\\\\"err\\\\\\\":\\\\\\\"Please enter number\\\\\\\"},\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":true,\\\\\\\"value\\\\\\\":\\\\\\\"20150901\\\\\\\"},{\\\\\\\"key\\\\\\\":\\\\\\\"birth_notification\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"165405AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"select one\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"spinner\\\\\\\",\\\\\\\"hint\\\\\\\":\\\\\\\"Was the birth notification done?\\\\\\\",\\\\\\\"values\\\\\\\":[\\\\\\\"Yes\\\\\\\",\\\\\\\"No\\\\\\\"],\\\\\\\"openmrs_choice_ids\\\\\\\":{\\\\\\\"Yes\\\\\\\":\\\\\\\"1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"No\\\\\\\":\\\\\\\"1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\"},\\\\\\\"v_required\\\\\\\":{\\\\\\\"value\\\\\\\":false,\\\\\\\"err\\\\\\\":\\\\\\\"Please select option\\\\\\\"},\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":false,\\\\\\\"step\\\\\\\":\\\\\\\"step1\\\\\\\",\\\\\\\"is-rule-check\\\\\\\":true},{\\\\\\\"key\\\\\\\":\\\\\\\"birthinstroductions\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"label\\\\\\\",\\\\\\\"text\\\\\\\":\\\\\\\"Ask to see the birth notification and instruct the caregiver to register the birth at County Health.\\\\\\\",\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":false},{\\\\\\\"key\\\\\\\":\\\\\\\"caregiverinstroductions\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"label\\\\\\\",\\\\\\\"text\\\\\\\":\\\\\\\"Instruct the caregiver to have the birth registered at County Health.\\\\\\\",\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":false}]}}\\\"}\"],\"set\":[],\"formSubmissionField\":\"birth_certificate\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"illness_information\",\"parentCode\":\"\",\"values\":[\"{}\"],\"set\":[],\"formSubmissionField\":\"illness_information\",\"humanReadableValues\":[]}],\"entityType\":\"ec_child\",\"version\":1567174886660,\"teamId\":\"d9eb010a-6d03-4bf8-b57a-b488dedd6f51\",\"team\":\"Clinic A Team\",\"dateCreated\":\"2019-08-30T14:21:50.258Z\",\"serverVersion\":1567174910258,\"clientApplicationVersion\":1,\"clientDatabaseVersion\":9,\"type\":\"Event\",\"id\":\"2e2601e9-e612-4eb5-9ca2-0ea19829fac2\",\"revision\":\"v1\"}"; + String oldServiceEvent = "{\"identifiers\":{},\"baseEntityId\":\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\",\"locationId\":\"402ecf03-af72-4c93-b099-e1ce327d815b\",\"eventDate\":\"2019-08-30T22:21:26.660Z\",\"eventType\":\"Child Home Visit\",\"formSubmissionId\":\"2735394b-b799-4cd0-9d2b-6d84d34448d9\",\"providerId\":\"chaone\",\"duration\":0,\"obs\":[{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"home_visit_id\",\"parentCode\":\"\",\"values\":[\"6f28e369-0db3-44a1-a61f-5b907a98f13e\"],\"set\":[],\"formSubmissionField\":\"home_visit_id\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"last_home_visit\",\"parentCode\":\"\",\"values\":[\"1567174886622\"],\"set\":[],\"formSubmissionField\":\"last_home_visit\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"singleVaccine\",\"parentCode\":\"\",\"values\":[\"{\\\"singleVaccinesGiven\\\":[]}\"],\"set\":[],\"formSubmissionField\":\"singleVaccine\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"groupVaccine\",\"parentCode\":\"\",\"values\":[\"{\\\"groupVaccinesGiven\\\":[]}\"],\"set\":[],\"formSubmissionField\":\"groupVaccine\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"vaccineNotGiven\",\"parentCode\":\"\",\"values\":[\"{\\\"vaccineNotGiven\\\":[]}\"],\"set\":[],\"formSubmissionField\":\"vaccineNotGiven\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"service\",\"parentCode\":\"\",\"values\":[\"{\\\"Vitamin A\\\":{\\\"alert\\\":{\\\"caseID\\\":\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\",\\\"completionDate\\\":null,\\\"expiryDate\\\":\\\"2019-09-23\\\",\\\"offline\\\":true,\\\"scheduleName\\\":\\\"Vitamin A1\\\",\\\"startDate\\\":\\\"2015-03-23\\\",\\\"status\\\":\\\"normal\\\",\\\"visitCode\\\":\\\"vitamina1\\\"},\\\"color\\\":null,\\\"createdAt\\\":null,\\\"dbKey\\\":1,\\\"defaultName\\\":\\\"Vitamin A\\\",\\\"dob\\\":\\\"2014-09-23T08:00:00.000+08:00\\\",\\\"gender\\\":\\\"Male\\\",\\\"id\\\":\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\",\\\"patientName\\\":\\\"Doudou Balde\\\",\\\"patientNumber\\\":\\\"\\\",\\\"photo\\\":{\\\"filePath\\\":null,\\\"resourceId\\\":2131230828},\\\"previousVaccineId\\\":null,\\\"serviceType\\\":{\\\"dateEntity\\\":\\\"encounter\\\",\\\"dateEntityId\\\":\\\"encounter_date\\\",\\\"expiryOffset\\\":\\\"+5y\\\",\\\"id\\\":13,\\\"milestoneOffset\\\":\\\"[+6m]\\\",\\\"name\\\":\\\"Vitamin A1\\\",\\\"preOffset\\\":\\\"+6m\\\",\\\"prerequisite\\\":\\\"dob\\\",\\\"serviceGroup\\\":\\\"child\\\",\\\"serviceLogic\\\":\\\"\\\",\\\"serviceNameEntity\\\":\\\"concept\\\",\\\"serviceNameEntityId\\\":\\\"86339AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\",\\\"type\\\":\\\"Vitamin A\\\",\\\"units\\\":null,\\\"updatedAt\\\":1566980540710},\\\"status\\\":\\\"due\\\",\\\"synced\\\":false,\\\"today\\\":false,\\\"updatedVaccineDate\\\":\\\"2019-08-30T22:20:42.718+08:00\\\",\\\"vaccineDate\\\":\\\"2015-03-23T00:00:00.000+08:00\\\",\\\"value\\\":null}}\"],\"set\":[],\"formSubmissionField\":\"service\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"serviceNotGiven\",\"parentCode\":\"\",\"values\":[\"{\\\"Deworming\\\":{\\\"alert\\\":{\\\"caseID\\\":\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\",\\\"completionDate\\\":null,\\\"expiryDate\\\":\\\"2019-09-23\\\",\\\"offline\\\":true,\\\"scheduleName\\\":\\\"Deworming 1\\\",\\\"startDate\\\":\\\"2015-09-23\\\",\\\"status\\\":\\\"normal\\\",\\\"visitCode\\\":\\\"deworming1\\\"},\\\"color\\\":null,\\\"createdAt\\\":null,\\\"dbKey\\\":null,\\\"defaultName\\\":\\\"Deworming\\\",\\\"dob\\\":\\\"2014-09-23T08:00:00.000+08:00\\\",\\\"gender\\\":\\\"Male\\\",\\\"id\\\":\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\",\\\"patientName\\\":\\\"Doudou Balde\\\",\\\"patientNumber\\\":\\\"\\\",\\\"photo\\\":{\\\"filePath\\\":null,\\\"resourceId\\\":2131230828},\\\"previousVaccineId\\\":null,\\\"serviceType\\\":{\\\"dateEntity\\\":\\\"encounter\\\",\\\"dateEntityId\\\":\\\"encounter_date\\\",\\\"expiryOffset\\\":\\\"+5y\\\",\\\"id\\\":22,\\\"milestoneOffset\\\":\\\"[+1y]\\\",\\\"name\\\":\\\"Deworming 1\\\",\\\"preOffset\\\":\\\"+1y\\\",\\\"prerequisite\\\":\\\"dob\\\",\\\"serviceGroup\\\":\\\"child\\\",\\\"serviceLogic\\\":\\\"\\\",\\\"serviceNameEntity\\\":\\\"concept\\\",\\\"serviceNameEntityId\\\":\\\"159922AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\",\\\"type\\\":\\\"Deworming\\\",\\\"units\\\":null,\\\"updatedAt\\\":1566980540721},\\\"status\\\":\\\"due\\\",\\\"synced\\\":false,\\\"today\\\":false,\\\"updatedVaccineDate\\\":null,\\\"vaccineDate\\\":\\\"2015-09-23T00:00:00.000+08:00\\\",\\\"value\\\":null}}\"],\"set\":[],\"formSubmissionField\":\"serviceNotGiven\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"birth_certificate\",\"parentCode\":\"\",\"values\":[\"{\\\"birtCert\\\":\\\"{\\\\\\\"count\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"encounter_type\\\\\\\":\\\\\\\"Birth Certification\\\\\\\",\\\\\\\"entity_id\\\\\\\":\\\\\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\\\\\",\\\\\\\"metadata\\\\\\\":{\\\\\\\"start\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"start\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163137AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"2019-08-30 22:20:17\\\\\\\"},\\\\\\\"end\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"end\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"2019-08-30 22:20:38\\\\\\\"},\\\\\\\"today\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"encounter\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"encounter_date\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"30-08-2019\\\\\\\"},\\\\\\\"deviceid\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"deviceid\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163149AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"865959046137007\\\\\\\"},\\\\\\\"subscriberid\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"subscriberid\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163150AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"460031208673496\\\\\\\"},\\\\\\\"simserial\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"simserial\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163151AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"89860314107971674978\\\\\\\"},\\\\\\\"phonenumber\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"phonenumber\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163152AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"\\\\\\\"},\\\\\\\"encounter_location\\\\\\\":\\\\\\\"\\\\\\\"},\\\\\\\"step1\\\\\\\":{\\\\\\\"title\\\\\\\":\\\\\\\"Birth Certification\\\\\\\",\\\\\\\"fields\\\\\\\":[{\\\\\\\"key\\\\\\\":\\\\\\\"birth_cert\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"165406AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"select one\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"spinner\\\\\\\",\\\\\\\"hint\\\\\\\":\\\\\\\"Does the child have a birth certificate?\\\\\\\",\\\\\\\"values\\\\\\\":[\\\\\\\"Yes\\\\\\\",\\\\\\\"No\\\\\\\"],\\\\\\\"openmrs_choice_ids\\\\\\\":{\\\\\\\"Yes\\\\\\\":\\\\\\\"1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"No\\\\\\\":\\\\\\\"1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\"},\\\\\\\"v_required\\\\\\\":{\\\\\\\"value\\\\\\\":true,\\\\\\\"err\\\\\\\":\\\\\\\"Please select option\\\\\\\"},\\\\\\\"step\\\\\\\":\\\\\\\"step1\\\\\\\",\\\\\\\"is-rule-check\\\\\\\":true,\\\\\\\"value\\\\\\\":\\\\\\\"Yes\\\\\\\"},{\\\\\\\"key\\\\\\\":\\\\\\\"birth_cert_issue_date\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"164129AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"date_picker\\\\\\\",\\\\\\\"hint\\\\\\\":\\\\\\\"Birth certificate issuance date\\\\\\\",\\\\\\\"expanded\\\\\\\":false,\\\\\\\"max_date\\\\\\\":\\\\\\\"today\\\\\\\",\\\\\\\"min_date\\\\\\\":\\\\\\\"today-1802d\\\\\\\",\\\\\\\"v_required\\\\\\\":{\\\\\\\"value\\\\\\\":\\\\\\\"true\\\\\\\",\\\\\\\"err\\\\\\\":\\\\\\\"Please enter Birth certificate issuance date\\\\\\\"},\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":true,\\\\\\\"value\\\\\\\":\\\\\\\"30-08-2019\\\\\\\"},{\\\\\\\"key\\\\\\\":\\\\\\\"birth_cert_num\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"162052AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"text\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"edit_text\\\\\\\",\\\\\\\"hint\\\\\\\":\\\\\\\"Birth certificate number\\\\\\\",\\\\\\\"v_required\\\\\\\":{\\\\\\\"value\\\\\\\":\\\\\\\"true\\\\\\\",\\\\\\\"err\\\\\\\":\\\\\\\"Please enter number\\\\\\\"},\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":true,\\\\\\\"value\\\\\\\":\\\\\\\"20150901\\\\\\\"},{\\\\\\\"key\\\\\\\":\\\\\\\"birth_notification\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"165405AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"select one\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"spinner\\\\\\\",\\\\\\\"hint\\\\\\\":\\\\\\\"Was the birth notification done?\\\\\\\",\\\\\\\"values\\\\\\\":[\\\\\\\"Yes\\\\\\\",\\\\\\\"No\\\\\\\"],\\\\\\\"openmrs_choice_ids\\\\\\\":{\\\\\\\"Yes\\\\\\\":\\\\\\\"1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"No\\\\\\\":\\\\\\\"1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\"},\\\\\\\"v_required\\\\\\\":{\\\\\\\"value\\\\\\\":false,\\\\\\\"err\\\\\\\":\\\\\\\"Please select option\\\\\\\"},\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":false,\\\\\\\"step\\\\\\\":\\\\\\\"step1\\\\\\\",\\\\\\\"is-rule-check\\\\\\\":true},{\\\\\\\"key\\\\\\\":\\\\\\\"birthinstroductions\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"label\\\\\\\",\\\\\\\"text\\\\\\\":\\\\\\\"Ask to see the birth notification and instruct the caregiver to register the birth at County Health.\\\\\\\",\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":false},{\\\\\\\"key\\\\\\\":\\\\\\\"caregiverinstroductions\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"label\\\\\\\",\\\\\\\"text\\\\\\\":\\\\\\\"Instruct the caregiver to have the birth registered at County Health.\\\\\\\",\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":false}]}}\\\"}\"],\"set\":[],\"formSubmissionField\":\"birth_certificate\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"illness_information\",\"parentCode\":\"\",\"values\":[\"{}\"],\"set\":[],\"formSubmissionField\":\"illness_information\",\"humanReadableValues\":[]}],\"entityType\":\"ec_child\",\"version\":1567174886660,\"teamId\":\"d9eb010a-6d03-4bf8-b57a-b488dedd6f51\",\"team\":\"Clinic A Team\",\"dateCreated\":\"2019-08-30T14:21:50.258Z\",\"serverVersion\":1567174910258,\"clientApplicationVersion\":1,\"clientDatabaseVersion\":9,\"type\":\"Event\",\"id\":\"2e2601e9-e612-4eb5-9ca2-0ea19829fac2\",\"revision\":\"v1\"}"; + String oldBirthCertEvent = "{\"identifiers\":{},\"baseEntityId\":\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\",\"locationId\":\"402ecf03-af72-4c93-b099-e1ce327d815b\",\"eventDate\":\"2019-08-30T22:21:26.660Z\",\"eventType\":\"Child Home Visit\",\"formSubmissionId\":\"2735394b-b799-4cd0-9d2b-6d84d34448d9\",\"providerId\":\"chaone\",\"duration\":0,\"obs\":[{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"home_visit_id\",\"parentCode\":\"\",\"values\":[\"6f28e369-0db3-44a1-a61f-5b907a98f13e\"],\"set\":[],\"formSubmissionField\":\"home_visit_id\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"last_home_visit\",\"parentCode\":\"\",\"values\":[\"1567174886622\"],\"set\":[],\"formSubmissionField\":\"last_home_visit\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"singleVaccine\",\"parentCode\":\"\",\"values\":[\"{\\\"singleVaccinesGiven\\\":[]}\"],\"set\":[],\"formSubmissionField\":\"singleVaccine\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"groupVaccine\",\"parentCode\":\"\",\"values\":[\"{\\\"groupVaccinesGiven\\\":[]}\"],\"set\":[],\"formSubmissionField\":\"groupVaccine\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"vaccineNotGiven\",\"parentCode\":\"\",\"values\":[\"{\\\"vaccineNotGiven\\\":[]}\"],\"set\":[],\"formSubmissionField\":\"vaccineNotGiven\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"service\",\"parentCode\":\"\",\"values\":[\"{\\\"Vitamin A\\\":{\\\"alert\\\":{\\\"caseID\\\":\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\",\\\"completionDate\\\":null,\\\"expiryDate\\\":\\\"2019-09-23\\\",\\\"offline\\\":true,\\\"scheduleName\\\":\\\"Vitamin A1\\\",\\\"startDate\\\":\\\"2015-03-23\\\",\\\"status\\\":\\\"normal\\\",\\\"visitCode\\\":\\\"vitamina1\\\"},\\\"color\\\":null,\\\"createdAt\\\":null,\\\"dbKey\\\":1,\\\"defaultName\\\":\\\"Vitamin A\\\",\\\"dob\\\":\\\"2014-09-23T08:00:00.000+08:00\\\",\\\"gender\\\":\\\"Male\\\",\\\"id\\\":\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\",\\\"patientName\\\":\\\"Doudou Balde\\\",\\\"patientNumber\\\":\\\"\\\",\\\"photo\\\":{\\\"filePath\\\":null,\\\"resourceId\\\":2131230828},\\\"previousVaccineId\\\":null,\\\"serviceType\\\":{\\\"dateEntity\\\":\\\"encounter\\\",\\\"dateEntityId\\\":\\\"encounter_date\\\",\\\"expiryOffset\\\":\\\"+5y\\\",\\\"id\\\":13,\\\"milestoneOffset\\\":\\\"[+6m]\\\",\\\"name\\\":\\\"Vitamin A1\\\",\\\"preOffset\\\":\\\"+6m\\\",\\\"prerequisite\\\":\\\"dob\\\",\\\"serviceGroup\\\":\\\"child\\\",\\\"serviceLogic\\\":\\\"\\\",\\\"serviceNameEntity\\\":\\\"concept\\\",\\\"serviceNameEntityId\\\":\\\"86339AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\",\\\"type\\\":\\\"Vitamin A\\\",\\\"units\\\":null,\\\"updatedAt\\\":1566980540710},\\\"status\\\":\\\"due\\\",\\\"synced\\\":false,\\\"today\\\":false,\\\"updatedVaccineDate\\\":\\\"2019-08-30T22:20:42.718+08:00\\\",\\\"vaccineDate\\\":\\\"2015-03-23T00:00:00.000+08:00\\\",\\\"value\\\":null}}\"],\"set\":[],\"formSubmissionField\":\"service\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"serviceNotGiven\",\"parentCode\":\"\",\"values\":[\"{\\\"Deworming\\\":{\\\"alert\\\":{\\\"caseID\\\":\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\",\\\"completionDate\\\":null,\\\"expiryDate\\\":\\\"2019-09-23\\\",\\\"offline\\\":true,\\\"scheduleName\\\":\\\"Deworming 1\\\",\\\"startDate\\\":\\\"2015-09-23\\\",\\\"status\\\":\\\"normal\\\",\\\"visitCode\\\":\\\"deworming1\\\"},\\\"color\\\":null,\\\"createdAt\\\":null,\\\"dbKey\\\":null,\\\"defaultName\\\":\\\"Deworming\\\",\\\"dob\\\":\\\"2014-09-23T08:00:00.000+08:00\\\",\\\"gender\\\":\\\"Male\\\",\\\"id\\\":\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\",\\\"patientName\\\":\\\"Doudou Balde\\\",\\\"patientNumber\\\":\\\"\\\",\\\"photo\\\":{\\\"filePath\\\":null,\\\"resourceId\\\":2131230828},\\\"previousVaccineId\\\":null,\\\"serviceType\\\":{\\\"dateEntity\\\":\\\"encounter\\\",\\\"dateEntityId\\\":\\\"encounter_date\\\",\\\"expiryOffset\\\":\\\"+5y\\\",\\\"id\\\":22,\\\"milestoneOffset\\\":\\\"[+1y]\\\",\\\"name\\\":\\\"Deworming 1\\\",\\\"preOffset\\\":\\\"+1y\\\",\\\"prerequisite\\\":\\\"dob\\\",\\\"serviceGroup\\\":\\\"child\\\",\\\"serviceLogic\\\":\\\"\\\",\\\"serviceNameEntity\\\":\\\"concept\\\",\\\"serviceNameEntityId\\\":\\\"159922AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\",\\\"type\\\":\\\"Deworming\\\",\\\"units\\\":null,\\\"updatedAt\\\":1566980540721},\\\"status\\\":\\\"due\\\",\\\"synced\\\":false,\\\"today\\\":false,\\\"updatedVaccineDate\\\":null,\\\"vaccineDate\\\":\\\"2015-09-23T00:00:00.000+08:00\\\",\\\"value\\\":null}}\"],\"set\":[],\"formSubmissionField\":\"serviceNotGiven\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"birth_certificate\",\"parentCode\":\"\",\"values\":[\"{\\\"birtCert\\\":\\\"{\\\\\\\"count\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"encounter_type\\\\\\\":\\\\\\\"Birth Certification\\\\\\\",\\\\\\\"entity_id\\\\\\\":\\\\\\\"d0da64ab-ab8c-4cd8-ab18-e2661009e436\\\\\\\",\\\\\\\"metadata\\\\\\\":{\\\\\\\"start\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"start\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163137AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"2019-08-30 22:20:17\\\\\\\"},\\\\\\\"end\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"end\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"2019-08-30 22:20:38\\\\\\\"},\\\\\\\"today\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"encounter\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"encounter_date\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"30-08-2019\\\\\\\"},\\\\\\\"deviceid\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"deviceid\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163149AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"865959046137007\\\\\\\"},\\\\\\\"subscriberid\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"subscriberid\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163150AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"460031208673496\\\\\\\"},\\\\\\\"simserial\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"simserial\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163151AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"89860314107971674978\\\\\\\"},\\\\\\\"phonenumber\\\\\\\":{\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"phonenumber\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"163152AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"\\\\\\\"},\\\\\\\"encounter_location\\\\\\\":\\\\\\\"\\\\\\\"},\\\\\\\"step1\\\\\\\":{\\\\\\\"title\\\\\\\":\\\\\\\"Birth Certification\\\\\\\",\\\\\\\"fields\\\\\\\":[{\\\\\\\"key\\\\\\\":\\\\\\\"birth_cert\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"165406AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"select one\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"spinner\\\\\\\",\\\\\\\"hint\\\\\\\":\\\\\\\"Does the child have a birth certificate?\\\\\\\",\\\\\\\"values\\\\\\\":[\\\\\\\"Yes\\\\\\\",\\\\\\\"No\\\\\\\"],\\\\\\\"openmrs_choice_ids\\\\\\\":{\\\\\\\"Yes\\\\\\\":\\\\\\\"1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"No\\\\\\\":\\\\\\\"1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\"},\\\\\\\"v_required\\\\\\\":{\\\\\\\"value\\\\\\\":true,\\\\\\\"err\\\\\\\":\\\\\\\"Please select option\\\\\\\"},\\\\\\\"step\\\\\\\":\\\\\\\"step1\\\\\\\",\\\\\\\"is-rule-check\\\\\\\":true,\\\\\\\"value\\\\\\\":\\\\\\\"Yes\\\\\\\"},{\\\\\\\"key\\\\\\\":\\\\\\\"birth_cert_issue_date\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"164129AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"date_picker\\\\\\\",\\\\\\\"hint\\\\\\\":\\\\\\\"Birth certificate issuance date\\\\\\\",\\\\\\\"expanded\\\\\\\":false,\\\\\\\"max_date\\\\\\\":\\\\\\\"today\\\\\\\",\\\\\\\"min_date\\\\\\\":\\\\\\\"today-1802d\\\\\\\",\\\\\\\"v_required\\\\\\\":{\\\\\\\"value\\\\\\\":\\\\\\\"true\\\\\\\",\\\\\\\"err\\\\\\\":\\\\\\\"Please enter Birth certificate issuance date\\\\\\\"},\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":true,\\\\\\\"value\\\\\\\":\\\\\\\"30-08-2019\\\\\\\"},{\\\\\\\"key\\\\\\\":\\\\\\\"birth_cert_num\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"162052AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"text\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"edit_text\\\\\\\",\\\\\\\"hint\\\\\\\":\\\\\\\"Birth certificate number\\\\\\\",\\\\\\\"v_required\\\\\\\":{\\\\\\\"value\\\\\\\":\\\\\\\"true\\\\\\\",\\\\\\\"err\\\\\\\":\\\\\\\"Please enter number\\\\\\\"},\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":true,\\\\\\\"value\\\\\\\":\\\\\\\"20150901\\\\\\\"},{\\\\\\\"key\\\\\\\":\\\\\\\"birth_notification\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"concept\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"165405AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"openmrs_data_type\\\\\\\":\\\\\\\"select one\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"spinner\\\\\\\",\\\\\\\"hint\\\\\\\":\\\\\\\"Was the birth notification done?\\\\\\\",\\\\\\\"values\\\\\\\":[\\\\\\\"Yes\\\\\\\",\\\\\\\"No\\\\\\\"],\\\\\\\"openmrs_choice_ids\\\\\\\":{\\\\\\\"Yes\\\\\\\":\\\\\\\"1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\",\\\\\\\"No\\\\\\\":\\\\\\\"1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\\\\\"},\\\\\\\"v_required\\\\\\\":{\\\\\\\"value\\\\\\\":false,\\\\\\\"err\\\\\\\":\\\\\\\"Please select option\\\\\\\"},\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":false,\\\\\\\"step\\\\\\\":\\\\\\\"step1\\\\\\\",\\\\\\\"is-rule-check\\\\\\\":true},{\\\\\\\"key\\\\\\\":\\\\\\\"birthinstroductions\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"label\\\\\\\",\\\\\\\"text\\\\\\\":\\\\\\\"Ask to see the birth notification and instruct the caregiver to register the birth at County Health.\\\\\\\",\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":false},{\\\\\\\"key\\\\\\\":\\\\\\\"caregiverinstroductions\\\\\\\",\\\\\\\"openmrs_entity_parent\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"openmrs_entity_id\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"label\\\\\\\",\\\\\\\"text\\\\\\\":\\\\\\\"Instruct the caregiver to have the birth registered at County Health.\\\\\\\",\\\\\\\"relevance\\\\\\\":{\\\\\\\"rules-engine\\\\\\\":{\\\\\\\"ex-rules\\\\\\\":{\\\\\\\"rules-file\\\\\\\":\\\\\\\"birth_certification.yml\\\\\\\"}}},\\\\\\\"is_visible\\\\\\\":false}]}}\\\"}\"],\"set\":[],\"formSubmissionField\":\"birth_certificate\",\"humanReadableValues\":[]},{\"fieldType\":\"formsubmissionField\",\"fieldDataType\":\"text\",\"fieldCode\":\"illness_information\",\"parentCode\":\"\",\"values\":[\"{}\"],\"set\":[],\"formSubmissionField\":\"illness_information\",\"humanReadableValues\":[]}],\"entityType\":\"ec_child\",\"version\":1567174886660,\"teamId\":\"d9eb010a-6d03-4bf8-b57a-b488dedd6f51\",\"team\":\"Clinic A Team\",\"dateCreated\":\"2019-08-30T14:21:50.258Z\",\"serverVersion\":1567174910258,\"clientApplicationVersion\":1,\"clientDatabaseVersion\":9,\"type\":\"Event\",\"id\":\"2e2601e9-e612-4eb5-9ca2-0ea19829fac2\",\"revision\":\"v1\"}"; + + Event event = gson.fromJson(oldIllnessInfo, Event.class); + EventClient eventClient = new EventClient(event,new Client("12345")); + List result = Utils.processOldEvents(eventClient); + Assert.assertEquals(result.size(),1); + } + */ + @Test public void canConvertReferralToANCMemberObject() { client = new CommonPersonObjectClient("case1", details, "test user"); diff --git a/sample/build.gradle b/sample/build.gradle index efa3539057..fc1f311ea2 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -97,6 +97,25 @@ android { } } + // avoid errors with message 'Duplicate files copied in APK ...' + packagingOptions { + exclude 'META-INF/DEPENDENCIES.txt' + exclude 'META-INF/LICENSE.txt' + exclude 'META-INF/NOTICE.txt' + exclude 'META-INF/NOTICE' + exclude 'META-INF/NOTICE.md' + exclude 'META-INF/LICENSE' + exclude 'META-INF/LICENSE.md' + exclude 'META-INF/DEPENDENCIES' + exclude 'META-INF/notice.txt' + exclude 'META-INF/license.txt' + exclude 'META-INF/dependencies.txt' + exclude 'META-INF/LGPL2.1' + exclude 'LICENSE.txt' + exclude 'META-INF/LICENSE.md' + exclude 'META-INF/NOTICE.md' + } + lintOptions { checkReleaseBuilds false abortOnError false diff --git a/sample/src/main/java/org/smartregister/chw/hf/activity/FamilyRegisterActivity.java b/sample/src/main/java/org/smartregister/chw/hf/activity/FamilyRegisterActivity.java index 80889f8b5c..4492577f93 100644 --- a/sample/src/main/java/org/smartregister/chw/hf/activity/FamilyRegisterActivity.java +++ b/sample/src/main/java/org/smartregister/chw/hf/activity/FamilyRegisterActivity.java @@ -18,6 +18,8 @@ import org.smartregister.helper.BottomNavigationHelper; import org.smartregister.view.fragment.BaseRegisterFragment; +import java.util.Map; + public class FamilyRegisterActivity extends CoreFamilyRegisterActivity { public static void registerBottomNavigation(BottomNavigationHelper bottomNavigationHelper, @@ -68,4 +70,9 @@ protected void onCreate(Bundle savedInstanceState) { protected BaseRegisterFragment getRegisterFragment() { return new FamilyRegisterFragment(); } + + @Override + public void startFormActivity(String s, String s1, Map map) { + + } } diff --git a/sample/src/main/java/org/smartregister/chw/hf/activity/ReferralRegisterActivity.java b/sample/src/main/java/org/smartregister/chw/hf/activity/ReferralRegisterActivity.java index ded102b2fc..e46792c894 100644 --- a/sample/src/main/java/org/smartregister/chw/hf/activity/ReferralRegisterActivity.java +++ b/sample/src/main/java/org/smartregister/chw/hf/activity/ReferralRegisterActivity.java @@ -6,6 +6,8 @@ import org.smartregister.helper.BottomNavigationHelper; import org.smartregister.view.fragment.BaseRegisterFragment; +import java.util.Map; + public class ReferralRegisterActivity extends BaseReferralRegister { @Override @@ -23,6 +25,11 @@ protected BaseRegisterFragment getRegisterFragment() { return new ReferralRegisterFragment(); } + @Override + public void startFormActivity(String s, String s1, Map map) { + + } + @Override protected void registerBottomNavigation() { bottomNavigationHelper = new BottomNavigationHelper(); diff --git a/sample/src/main/java/org/smartregister/chw/hf/activity/UpdatesRegisterActivity.java b/sample/src/main/java/org/smartregister/chw/hf/activity/UpdatesRegisterActivity.java index 42decd757e..6f9a1d427a 100644 --- a/sample/src/main/java/org/smartregister/chw/hf/activity/UpdatesRegisterActivity.java +++ b/sample/src/main/java/org/smartregister/chw/hf/activity/UpdatesRegisterActivity.java @@ -12,6 +12,7 @@ import org.smartregister.view.fragment.BaseRegisterFragment; import java.util.List; +import java.util.Map; public class UpdatesRegisterActivity extends BaseChwNotificationRegister { @@ -35,6 +36,11 @@ protected Fragment[] getOtherFragments() { return new Fragment[0]; } + @Override + public void startFormActivity(String s, String s1, Map map) { + + } + @Override public void startFormActivity(String formName, String entityId, String metaData) { //Overridden not needed diff --git a/sample/src/main/java/org/smartregister/chw/hf/custom_view/HfNavigationMenu.java b/sample/src/main/java/org/smartregister/chw/hf/custom_view/HfNavigationMenu.java index f04abb0fcd..eea0bd358c 100644 --- a/sample/src/main/java/org/smartregister/chw/hf/custom_view/HfNavigationMenu.java +++ b/sample/src/main/java/org/smartregister/chw/hf/custom_view/HfNavigationMenu.java @@ -47,6 +47,16 @@ public Intent getServiceReportIntent(Activity activity) { return new Intent(activity, HIA2ReportsActivity.class); } + @Override + public String childNavigationMenuCountString() { + return null; + } + + @Override + public Intent getHIA2ReportActivityIntent(Activity activity) { + return null; + } + @Override public boolean hasCommunityResponders() { return false; diff --git a/sample/src/main/java/org/smartregister/chw/hf/sync/HfSyncConfiguration.java b/sample/src/main/java/org/smartregister/chw/hf/sync/HfSyncConfiguration.java index 871ebba529..df6db12616 100644 --- a/sample/src/main/java/org/smartregister/chw/hf/sync/HfSyncConfiguration.java +++ b/sample/src/main/java/org/smartregister/chw/hf/sync/HfSyncConfiguration.java @@ -5,6 +5,7 @@ import org.smartregister.SyncFilter; import org.smartregister.chw.core.utils.Utils; import org.smartregister.chw.hf.BuildConfig; +import org.smartregister.view.activity.BaseLoginActivity; import java.util.Collections; import java.util.List; @@ -67,4 +68,19 @@ public List getSynchronizedLocationTags() { public String getTopAllowedLocationLevel() { return ""; } + + @Override + public String getOauthClientId() { + return null; + } + + @Override + public String getOauthClientSecret() { + return null; + } + + @Override + public Class getAuthenticationActivity() { + return null; + } }