From 3797db386aec872e0150a25642761523813148b3 Mon Sep 17 00:00:00 2001 From: Allan Date: Fri, 3 May 2019 11:00:42 +0300 Subject: [PATCH 01/19] Add Reporting library dependency in CHW --- opensrp-chw/build.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 650d6cbee7..ea16bc2c42 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -149,6 +149,12 @@ dependencies { exclude group: 'com.android.support', module: 'appcompat-v7' } + implementation('org.smartregister:opensrp-client-reporting:1.0.1-SNAPSHOT@aar') { + transitive = true + exclude group: 'org.smartregister', module: 'opensrp-client-core' + exclude group: 'com.android.support', module: 'appcompat-v7' + } + implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.support:recyclerview-v7:28.0.0' From ddcc88e3a9387063f801c0ccc3f5ce838de5237c Mon Sep 17 00:00:00 2001 From: Allan Date: Fri, 3 May 2019 11:16:00 +0300 Subject: [PATCH 02/19] Initialize reporting library --- .../chw/application/ChwApplication.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwApplication.java b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwApplication.java index a7c442cd5d..9820a12245 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwApplication.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwApplication.java @@ -38,6 +38,7 @@ import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.location.helper.LocationHelper; import org.smartregister.receiver.SyncStatusBroadcastReceiver; +import org.smartregister.reporting.ReportingLibrary; import org.smartregister.repository.AllSharedPreferences; import org.smartregister.repository.Repository; import org.smartregister.sync.ClientProcessorForJava; @@ -65,6 +66,10 @@ public class ChwApplication extends DrishtiApplication { private RulesEngineHelper rulesEngineHelper; + private String indicatorsConfigFile = "config/indicator-definitions.yml"; + private String indicatorDataInitialisedPref = "INDICATOR_DATA_INITIALISED"; + private String appVersionCodePref = "APP_VERSION_CODE"; + public static synchronized ChwApplication getInstance() { return (ChwApplication) mInstance; } @@ -139,6 +144,19 @@ public void onCreate() { // init json helper this.jsonSpecHelper = new JsonSpecHelper(this); + // Init Reporting library + ReportingLibrary.init(context, getRepository(), null, BuildConfig.VERSION_CODE, BuildConfig.DATABASE_VERSION); + ReportingLibrary reportingLibraryInstance = ReportingLibrary.getInstance(); + // Check if indicator data initialised + boolean indicatorDataInitialised = Boolean.parseBoolean(reportingLibraryInstance.getContext() + .allSharedPreferences().getPreference(indicatorDataInitialisedPref)); + boolean isUpdated = checkIfAppUpdated(); + if (!indicatorDataInitialised || isUpdated) { + reportingLibraryInstance.initIndicatorData(indicatorsConfigFile); // This will persist the data in the DB + reportingLibraryInstance.getContext().allSharedPreferences().savePreference(indicatorDataInitialisedPref, "true"); + reportingLibraryInstance.getContext().allSharedPreferences().savePreference(appVersionCodePref, String.valueOf(BuildConfig.VERSION_CODE)); + } + //init Job Manager JobManager.create(this).addJobCreator(new ChwJobCreator()); @@ -160,6 +178,15 @@ public void onCreate() { saveLanguage(Locale.FRENCH.getLanguage()); } + private boolean checkIfAppUpdated() { + String savedAppVersion = ReportingLibrary.getInstance().getContext().allSharedPreferences().getPreference(appVersionCodePref); + if (savedAppVersion.isEmpty()) { + return true; + } else { + int savedVersion = Integer.parseInt(savedAppVersion); + return (BuildConfig.VERSION_CODE > savedVersion); + } + } private void saveLanguage(String language) { AllSharedPreferences allSharedPreferences = ChwApplication.getInstance().getContext().allSharedPreferences(); From 994712ea224dd2e65d21b026b180415c51c12b4a Mon Sep 17 00:00:00 2001 From: Allan Date: Fri, 3 May 2019 12:00:02 +0300 Subject: [PATCH 03/19] Add indicators yaml config file --- opensrp-chw/src/main/assets/config/indicator-definitions.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 opensrp-chw/src/main/assets/config/indicator-definitions.yml diff --git a/opensrp-chw/src/main/assets/config/indicator-definitions.yml b/opensrp-chw/src/main/assets/config/indicator-definitions.yml new file mode 100644 index 0000000000..11c7972e5d --- /dev/null +++ b/opensrp-chw/src/main/assets/config/indicator-definitions.yml @@ -0,0 +1,4 @@ +indicators: + - key: "CHW_001" + description: "Total U5 children" + indicatorQuery: "select count(distinct baseEntityId) from event where eventType = 'Child Registration' and eventDate = '%s'" \ No newline at end of file From 3faf32a16bbbf4a5e5ca4ccbf5ee4a06cffe102c Mon Sep 17 00:00:00 2001 From: Allan Date: Mon, 6 May 2019 12:21:29 +0300 Subject: [PATCH 04/19] Move initialise Reporting tables and indicators to ChwRepository class --- opensrp-chw/build.gradle | 2 +- .../chw/application/ChwApplication.java | 24 ---------- .../chw/repository/ChwRepository.java | 47 ++++++++++++++++--- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index ea16bc2c42..6c9bd8add1 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -149,7 +149,7 @@ dependencies { exclude group: 'com.android.support', module: 'appcompat-v7' } - implementation('org.smartregister:opensrp-client-reporting:1.0.1-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-reporting:1.0.5-SNAPSHOT@aar') { transitive = true exclude group: 'org.smartregister', module: 'opensrp-client-core' exclude group: 'com.android.support', module: 'appcompat-v7' diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwApplication.java b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwApplication.java index 9820a12245..ece24ababb 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwApplication.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwApplication.java @@ -66,10 +66,6 @@ public class ChwApplication extends DrishtiApplication { private RulesEngineHelper rulesEngineHelper; - private String indicatorsConfigFile = "config/indicator-definitions.yml"; - private String indicatorDataInitialisedPref = "INDICATOR_DATA_INITIALISED"; - private String appVersionCodePref = "APP_VERSION_CODE"; - public static synchronized ChwApplication getInstance() { return (ChwApplication) mInstance; } @@ -146,16 +142,6 @@ public void onCreate() { // Init Reporting library ReportingLibrary.init(context, getRepository(), null, BuildConfig.VERSION_CODE, BuildConfig.DATABASE_VERSION); - ReportingLibrary reportingLibraryInstance = ReportingLibrary.getInstance(); - // Check if indicator data initialised - boolean indicatorDataInitialised = Boolean.parseBoolean(reportingLibraryInstance.getContext() - .allSharedPreferences().getPreference(indicatorDataInitialisedPref)); - boolean isUpdated = checkIfAppUpdated(); - if (!indicatorDataInitialised || isUpdated) { - reportingLibraryInstance.initIndicatorData(indicatorsConfigFile); // This will persist the data in the DB - reportingLibraryInstance.getContext().allSharedPreferences().savePreference(indicatorDataInitialisedPref, "true"); - reportingLibraryInstance.getContext().allSharedPreferences().savePreference(appVersionCodePref, String.valueOf(BuildConfig.VERSION_CODE)); - } //init Job Manager JobManager.create(this).addJobCreator(new ChwJobCreator()); @@ -178,16 +164,6 @@ public void onCreate() { saveLanguage(Locale.FRENCH.getLanguage()); } - private boolean checkIfAppUpdated() { - String savedAppVersion = ReportingLibrary.getInstance().getContext().allSharedPreferences().getPreference(appVersionCodePref); - if (savedAppVersion.isEmpty()) { - return true; - } else { - int savedVersion = Integer.parseInt(savedAppVersion); - return (BuildConfig.VERSION_CODE > savedVersion); - } - } - private void saveLanguage(String language) { AllSharedPreferences allSharedPreferences = ChwApplication.getInstance().getContext().allSharedPreferences(); allSharedPreferences.saveLanguagePreference(language); diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/repository/ChwRepository.java b/opensrp-chw/src/main/java/org/smartregister/chw/repository/ChwRepository.java index 1e5ecfb81e..4e55a1e4ea 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/repository/ChwRepository.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/repository/ChwRepository.java @@ -20,6 +20,10 @@ import org.smartregister.immunization.repository.VaccineRepository; import org.smartregister.immunization.repository.VaccineTypeRepository; import org.smartregister.immunization.util.IMDatabaseUtils; +import org.smartregister.reporting.ReportingLibrary; +import org.smartregister.reporting.repository.DailyIndicatorCountRepository; +import org.smartregister.reporting.repository.IndicatorQueryRepository; +import org.smartregister.reporting.repository.IndicatorRepository; import org.smartregister.repository.AlertRepository; import org.smartregister.repository.EventClientRepository; import org.smartregister.repository.Repository; @@ -35,6 +39,9 @@ public class ChwRepository extends Repository { protected SQLiteDatabase readableDatabase; protected SQLiteDatabase writableDatabase; private Context context; + private String indicatorsConfigFile = "config/indicator-definitions.yml"; + private String indicatorDataInitialisedPref = "INDICATOR_DATA_INITIALISED"; + private String appVersionCodePref = "APP_VERSION_CODE"; public ChwRepository(Context context, org.smartregister.Context openSRPContext) { super(context, AllConstants.DATABASE_NAME, BuildConfig.DATABASE_VERSION, openSRPContext.session(), ChwApplication.createCommonFtsObject(), openSRPContext.sharedRepositoriesArray()); @@ -57,13 +64,28 @@ public void onCreate(SQLiteDatabase database) { RecurringServiceTypeRepository.createTable(database); RecurringServiceRecordRepository.createTable(database); + + IndicatorRepository.createTable(database); + IndicatorQueryRepository.createTable(database); + DailyIndicatorCountRepository.createTable(database); + //onUpgrade(database, 1, 2); RecurringServiceTypeRepository recurringServiceTypeRepository = ImmunizationLibrary.getInstance().recurringServiceTypeRepository(); IMDatabaseUtils.populateRecurringServices(context, database, recurringServiceTypeRepository); - onUpgrade(database, 1, BuildConfig.DATABASE_VERSION); + ReportingLibrary reportingLibraryInstance = ReportingLibrary.getInstance(); + // Check if indicator data initialised + boolean indicatorDataInitialised = Boolean.parseBoolean(reportingLibraryInstance.getContext() + .allSharedPreferences().getPreference(indicatorDataInitialisedPref)); + boolean isUpdated = checkIfAppUpdated(); + if (!indicatorDataInitialised || isUpdated) { + reportingLibraryInstance.initIndicatorData(indicatorsConfigFile, database); // This will persist the data in the DB + reportingLibraryInstance.getContext().allSharedPreferences().savePreference(indicatorDataInitialisedPref, "true"); + reportingLibraryInstance.getContext().allSharedPreferences().savePreference(appVersionCodePref, String.valueOf(BuildConfig.VERSION_CODE)); + } + } @Override @@ -103,9 +125,9 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { @Override public SQLiteDatabase getReadableDatabase() { String pass = ChwApplication.getInstance().getPassword(); - if(StringUtils.isNotBlank(pass)){ + if (StringUtils.isNotBlank(pass)) { return getReadableDatabase(pass); - }else{ + } else { throw new IllegalStateException("Password is blank"); } } @@ -113,9 +135,9 @@ public SQLiteDatabase getReadableDatabase() { @Override public SQLiteDatabase getWritableDatabase() { String pass = ChwApplication.getInstance().getPassword(); - if(StringUtils.isNotBlank(pass)){ + if (StringUtils.isNotBlank(pass)) { return getWritableDatabase(pass); - }else{ + } else { throw new IllegalStateException("Password is blank"); } } @@ -160,6 +182,16 @@ public synchronized void close() { super.close(); } + private boolean checkIfAppUpdated() { + String savedAppVersion = ReportingLibrary.getInstance().getContext().allSharedPreferences().getPreference(appVersionCodePref); + if (savedAppVersion.isEmpty()) { + return true; + } else { + int savedVersion = Integer.parseInt(savedAppVersion); + return (BuildConfig.VERSION_CODE > savedVersion); + } + } + private void upgradeToVersion2(SQLiteDatabase db) { try { db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_EVENT_ID_COL); @@ -229,8 +261,8 @@ private void upgradeToVersion5(SQLiteDatabase db) { private void upgradeToVersion6(SQLiteDatabase db) { try { - if(BuildConfig.BUILD_COUNTRY == Country.TANZANIA){ - for (String query: RepositoryUtils.UPGRADE_V6) { + if (BuildConfig.BUILD_COUNTRY == Country.TANZANIA) { + for (String query : RepositoryUtils.UPGRADE_V6) { db.execSQL(query); } } @@ -238,6 +270,7 @@ private void upgradeToVersion6(SQLiteDatabase db) { Log.e(TAG, "upgradeToVersion6 " + Log.getStackTraceString(e)); } } + private void upgradeToVersion7(SQLiteDatabase db) { try { db.execSQL(HomeVisitRepository.UPDATE_TABLE_ADD_VACCINE_NOT_GIVEN); From ce022a9fed619c5a2949c2c6b1f418170f1718fd Mon Sep 17 00:00:00 2001 From: mahmud6390 Date: Mon, 6 May 2019 16:27:29 +0600 Subject: [PATCH 05/19] https://github.com/OpenSRP/opensrp-client-chw/issues/334 due status not handle in previous --- .../fragment/FamilyProfileDueFragment.java | 12 +++- .../chw/task/UpdateServiceTask.java | 2 +- .../chw/util/ChwServiceSchedule.java | 60 ++++++++++--------- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/fragment/FamilyProfileDueFragment.java b/opensrp-chw/src/main/java/org/smartregister/chw/fragment/FamilyProfileDueFragment.java index dec409afee..2334c1945e 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/fragment/FamilyProfileDueFragment.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/fragment/FamilyProfileDueFragment.java @@ -55,13 +55,19 @@ public void initializeAdapter(Set> doInBackground(Void... voids) { String dobString = Utils.getValue(childDetails.getColumnmaps(), "dob", false); if (!TextUtils.isEmpty(dobString)) { DateTime dateTime = new DateTime(dobString); - VaccineSchedule.updateOfflineAlerts(childDetails.entityId(), dateTime, "child"); + // VaccineSchedule.updateOfflineAlerts(childDetails.entityId(), dateTime, "child"); ChwServiceSchedule.updateOfflineAlerts(childDetails.entityId(), dateTime); } diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/util/ChwServiceSchedule.java b/opensrp-chw/src/main/java/org/smartregister/chw/util/ChwServiceSchedule.java index 865bdbcda2..071173f85d 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/util/ChwServiceSchedule.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/util/ChwServiceSchedule.java @@ -25,6 +25,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import timber.log.Timber; + /** * Created by Keyman on 26/05/2017. */ @@ -69,8 +71,6 @@ public static void updateOfflineAlerts(String type, String baseEntityId, DateTim String[] alertArray = VaccinateActionUtils.allAlertNames(serviceTypes); - List newAlerts = new ArrayList<>(); - // Get all the administered services List issuedServices = recurringServiceRecordRepository.findByEntityId(baseEntityId); alertService.deleteOfflineAlerts(baseEntityId, alertArray); @@ -80,14 +80,15 @@ public static void updateOfflineAlerts(String type, String baseEntityId, DateTim for (ServiceType serviceType : serviceTypes) { Alert curAlert = getOfflineAlert(serviceType, issuedServices, baseEntityId, dob); - if (curAlert == null) { - break; - } else { +// if (curAlert == null ) { +// break; +// } else { // Check if the current alert already exists for the entityId boolean exists = false; for (Alert curExistingAlert : existingAlerts) { - if (curExistingAlert.scheduleName().equalsIgnoreCase(curAlert.scheduleName()) - && curExistingAlert.caseId().equalsIgnoreCase(curAlert.caseId())) { + if (curAlert!=null && curExistingAlert.scheduleName().equalsIgnoreCase(curAlert.scheduleName()) + && curExistingAlert.caseId().equalsIgnoreCase(curAlert.caseId())) + { exists = true; break; } @@ -96,7 +97,8 @@ public static void updateOfflineAlerts(String type, String baseEntityId, DateTim // Check if service is already given if (!exists) { for (ServiceRecord serviceRecord : issuedServices) { - if (curAlert.scheduleName().equalsIgnoreCase(serviceRecord.getName()) || curAlert.visitCode().equalsIgnoreCase(serviceRecord.getName())) { + if (curAlert!=null && curAlert.scheduleName().equalsIgnoreCase(serviceRecord.getName()) + || curAlert!=null && curAlert.visitCode().equalsIgnoreCase(serviceRecord.getName())) { exists = true; break; } @@ -105,10 +107,12 @@ public static void updateOfflineAlerts(String type, String baseEntityId, DateTim if (!exists) { // Insert alert into table - newAlerts.add(curAlert); - alertService.create(curAlert); + if(curAlert!=null && !curAlert.status().value().equalsIgnoreCase(AlertStatus.expired.value())){ + alertService.create(curAlert); + } + } - } + //} } } catch (Exception e) { @@ -139,34 +143,32 @@ public static Alert getOfflineAlert(final ServiceType serviceType, final List Date: Mon, 6 May 2019 16:58:06 +0600 Subject: [PATCH 06/19] remove unused code and adding unit test. --- .../chw/util/ChwServiceSchedule.java | 91 ------------------- .../chw/util/ChwServiceScheduleTest.java | 39 ++++++++ 2 files changed, 39 insertions(+), 91 deletions(-) create mode 100644 opensrp-chw/src/test/java/org/smartregister/chw/util/ChwServiceScheduleTest.java diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/util/ChwServiceSchedule.java b/opensrp-chw/src/main/java/org/smartregister/chw/util/ChwServiceSchedule.java index 071173f85d..37a779ddd8 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/util/ChwServiceSchedule.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/util/ChwServiceSchedule.java @@ -3,28 +3,20 @@ import android.util.Log; import org.joda.time.DateTime; -import org.json.JSONException; -import org.json.JSONObject; import org.smartregister.clientandeventmodel.DateUtil; import org.smartregister.domain.Alert; import org.smartregister.domain.AlertStatus; import org.smartregister.immunization.ImmunizationLibrary; import org.smartregister.immunization.domain.ServiceRecord; -import org.smartregister.immunization.domain.ServiceTrigger; import org.smartregister.immunization.domain.ServiceType; import org.smartregister.immunization.repository.RecurringServiceRecordRepository; import org.smartregister.immunization.repository.RecurringServiceTypeRepository; import org.smartregister.immunization.util.VaccinateActionUtils; import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.service.AlertService; - -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import timber.log.Timber; /** @@ -33,22 +25,6 @@ public class ChwServiceSchedule { - private final ServiceTrigger dueTrigger; - private final ServiceTrigger expiryTrigger; - - - public static ChwServiceSchedule getServiceSchedule(JSONObject schedule) - throws JSONException { - ServiceTrigger dueTrigger = ServiceTrigger.init(schedule.getJSONObject("due")); - ServiceTrigger expiryTrigger = ServiceTrigger.init(schedule.optJSONObject("expiry")); - return new ChwServiceSchedule(dueTrigger, expiryTrigger); - } - - public ChwServiceSchedule(ServiceTrigger dueTrigger, ServiceTrigger expiryTrigger) { - this.dueTrigger = dueTrigger; - this.expiryTrigger = expiryTrigger; - } - public static void updateOfflineAlerts(String baseEntityId, DateTime dob) { RecurringServiceTypeRepository recurringServiceTypeRepository = ImmunizationLibrary.getInstance().recurringServiceTypeRepository(); List types = recurringServiceTypeRepository.fetchTypes(); @@ -178,72 +154,5 @@ public static void standardiseCalendarDate(Calendar calendarDate) { calendarDate.set(Calendar.MILLISECOND, 0); } - public static DateTime standardiseDateTime(DateTime dateTime) { - if (dateTime != null) { - return dateTime.withTime(0, 0, 0, 0); - } - return null; - } - - public ServiceTrigger getDueTrigger() { - return dueTrigger; - } - - public ServiceTrigger getExpiryTrigger() { - return expiryTrigger; - } - - public static DateTime addOffsetToDateTime(DateTime dateTime, List offsets) { - DateTime afterOffset = dateTime; - if (dateTime != null && offsets != null && !offsets.isEmpty()) { - for (String offset : offsets) { - afterOffset = addOffsetToDateTime(afterOffset, offset); - } - } - return afterOffset; - } - - public static DateTime addOffsetToDateTime(DateTime dateTime, String offset) { - try { - DateTime afterOffset = dateTime; - if (dateTime != null && offset != null) { - String offsetAfterReplace = offset.replace(" ", "").toLowerCase(); - Pattern p1 = Pattern.compile("([-+]{1})(.*)"); - Matcher m1 = p1.matcher(offsetAfterReplace); - if (m1.find()) { - String comparitorString = m1.group(1); - String valueString = m1.group(2); - - int comparitor = 1; - if ("-".equals(comparitorString)) { - comparitor = -1; - } - - String[] values = valueString.split(","); - for (int i = 0; i < values.length; i++) { - Pattern p2 = Pattern.compile("(\\d+)([dwmy]{1})"); - Matcher m2 = p2.matcher(values[i]); - - if (m2.find()) { - int curValue = comparitor * Integer.parseInt(m2.group(1)); - String fieldString = m2.group(2); - if ("d".endsWith(fieldString)) { - afterOffset = afterOffset.plusDays(curValue); - } else if ("m".equals(fieldString)) { - afterOffset = afterOffset.plusMonths(curValue); - } else if ("y".equals(fieldString)) { - afterOffset = afterOffset.plusYears(curValue); - } - } - } - } - } - - return afterOffset; - } catch (Exception e) { - Log.e(ChwServiceSchedule.class.getName(), e.toString(), e); - return dateTime; - } - } } diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/util/ChwServiceScheduleTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/util/ChwServiceScheduleTest.java new file mode 100644 index 0000000000..27da833ed9 --- /dev/null +++ b/opensrp-chw/src/test/java/org/smartregister/chw/util/ChwServiceScheduleTest.java @@ -0,0 +1,39 @@ +package org.smartregister.chw.util; + +import org.joda.time.DateTime; +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.powermock.reflect.Whitebox; +import org.smartregister.chw.BaseUnitTest; +import org.smartregister.domain.AlertStatus; + +public class ChwServiceScheduleTest extends BaseUnitTest { + + @Mock + private ChwServiceSchedule chwServiceSchedule; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + chwServiceSchedule = new ChwServiceSchedule(); + } + + @Test + public void calculateAlertStatusNormalExpiryDateSame() throws Exception{ + DateTime dueDateTime = new DateTime(); + DateTime expiryDateTime = new DateTime(); + AlertStatus alertStatus = Whitebox.invokeMethod(chwServiceSchedule,"calculateAlertStatus",dueDateTime,expiryDateTime); + Assert.assertEquals("normal",alertStatus.value()); + } + @Test + public void calculateAlertStatusExpiredExpiryDateTesterday() throws Exception{ + DateTime dueDateTime = new DateTime(); + DateTime expiryDateTime = new DateTime( 1556880664000L); + AlertStatus alertStatus = Whitebox.invokeMethod(chwServiceSchedule,"calculateAlertStatus",dueDateTime,expiryDateTime); + Assert.assertEquals("expired",alertStatus.value()); + } +} From bfcf0b5f8187c3ff7b6837a0bb54a55a01407e52 Mon Sep 17 00:00:00 2001 From: mahmud6390 Date: Mon, 6 May 2019 17:16:46 +0600 Subject: [PATCH 07/19] https://github.com/OpenSRP/opensrp-client-chw/issues/346 before next datatfetch view refresh --- .../org/smartregister/chw/activity/ChildProfileActivity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/activity/ChildProfileActivity.java b/opensrp-chw/src/main/java/org/smartregister/chw/activity/ChildProfileActivity.java index 55dfd453ec..fb4df93410 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/activity/ChildProfileActivity.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/activity/ChildProfileActivity.java @@ -490,6 +490,8 @@ public void updateImmunizationData() { handler.postDelayed(new Runnable() { @Override public void run() { + layoutMostDueOverdue.setVisibility(View.GONE); + viewMostDueRow.setVisibility(View.GONE); presenter().fetchVisitStatus(childBaseEntityId); presenter().fetchUpcomingServiceAndFamilyDue(childBaseEntityId); presenter().updateChildCommonPerson(childBaseEntityId); From 1a3e2b1f119222ab5478cb6f0aa0651059a3f639 Mon Sep 17 00:00:00 2001 From: Allan Date: Mon, 6 May 2019 15:13:34 +0300 Subject: [PATCH 08/19] Schedule IndicatorGeneratingJob --- opensrp-chw/build.gradle | 2 +- .../org/smartregister/chw/interactor/LoginInteractor.java | 4 ++++ .../main/java/org/smartregister/chw/job/ChwJobCreator.java | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 6c9bd8add1..afe0148506 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -149,7 +149,7 @@ dependencies { exclude group: 'com.android.support', module: 'appcompat-v7' } - implementation('org.smartregister:opensrp-client-reporting:1.0.5-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-reporting:1.0.6-SNAPSHOT@aar') { transitive = true exclude group: 'org.smartregister', module: 'opensrp-client-core' exclude group: 'com.android.support', module: 'appcompat-v7' diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/interactor/LoginInteractor.java b/opensrp-chw/src/main/java/org/smartregister/chw/interactor/LoginInteractor.java index c3ab3ee033..d60ede7e6f 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/interactor/LoginInteractor.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/interactor/LoginInteractor.java @@ -6,6 +6,7 @@ import org.smartregister.job.PullUniqueIdsServiceJob; import org.smartregister.job.SyncServiceJob; import org.smartregister.login.interactor.BaseLoginInteractor; +import org.smartregister.reporting.job.RecurringIndicatorGeneratingJob; import org.smartregister.view.contract.BaseLoginContract; import java.util.concurrent.TimeUnit; @@ -29,6 +30,9 @@ protected void scheduleJobsPeriodically() { PullUniqueIdsServiceJob.scheduleJob(PullUniqueIdsServiceJob.TAG, TimeUnit.MINUTES.toMillis(BuildConfig.PULL_UNIQUE_IDS_MINUTES), getFlexValue (BuildConfig.PULL_UNIQUE_IDS_MINUTES)); + RecurringIndicatorGeneratingJob.scheduleJob(RecurringIndicatorGeneratingJob.TAG, + TimeUnit.MINUTES.toMillis(org.smartregister.reporting.BuildConfig.REPORT_INDICATOR_GENERATION_MINUTES), TimeUnit.MINUTES.toMillis(1)); + } @Override diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/job/ChwJobCreator.java b/opensrp-chw/src/main/java/org/smartregister/chw/job/ChwJobCreator.java index cef7da3b26..a53dbd09cc 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/job/ChwJobCreator.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/job/ChwJobCreator.java @@ -13,6 +13,7 @@ import org.smartregister.job.PullUniqueIdsServiceJob; import org.smartregister.job.SyncServiceJob; import org.smartregister.job.ValidateSyncDataServiceJob; +import org.smartregister.reporting.job.RecurringIndicatorGeneratingJob; /** * Created by keyman on 27/11/2018. @@ -34,6 +35,8 @@ public Job create(@NonNull String tag) { return new VaccineRecurringServiceJob(); case ImageUploadServiceJob.TAG: return new ImageUploadServiceJob(); + case RecurringIndicatorGeneratingJob.TAG: + return new RecurringIndicatorGeneratingJob(); default: Log.d(ChwJobCreator.class.getCanonicalName(), "Looks like you tried to create a job " + tag + " that is not declared in the Anc Job Creator"); return null; From 87cbc714065cddb07ef34666ec130b620a160323 Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Mon, 6 May 2019 16:53:57 +0300 Subject: [PATCH 09/19] Fixed Breaking Tests and Codacy Errors --- .../chw/util/ChwServiceSchedule.java | 56 +++++++++---------- .../FamilyProfileDueFragmentTest.java | 3 + 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/util/ChwServiceSchedule.java b/opensrp-chw/src/main/java/org/smartregister/chw/util/ChwServiceSchedule.java index 37a779ddd8..c07215868b 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/util/ChwServiceSchedule.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/util/ChwServiceSchedule.java @@ -14,9 +14,11 @@ import org.smartregister.immunization.util.VaccinateActionUtils; import org.smartregister.immunization.util.VaccinatorUtils; import org.smartregister.service.AlertService; + import java.util.Calendar; import java.util.Date; import java.util.List; + import timber.log.Timber; /** @@ -59,35 +61,31 @@ public static void updateOfflineAlerts(String type, String baseEntityId, DateTim // if (curAlert == null ) { // break; // } else { - // Check if the current alert already exists for the entityId - boolean exists = false; - for (Alert curExistingAlert : existingAlerts) { - if (curAlert!=null && curExistingAlert.scheduleName().equalsIgnoreCase(curAlert.scheduleName()) - && curExistingAlert.caseId().equalsIgnoreCase(curAlert.caseId())) - { - exists = true; - break; - } + // Check if the current alert already exists for the entityId + boolean exists = false; + for (Alert curExistingAlert : existingAlerts) { + if (curAlert != null && curExistingAlert.scheduleName().equalsIgnoreCase(curAlert.scheduleName()) + && curExistingAlert.caseId().equalsIgnoreCase(curAlert.caseId())) { + exists = true; + break; } + } - // Check if service is already given - if (!exists) { - for (ServiceRecord serviceRecord : issuedServices) { - if (curAlert!=null && curAlert.scheduleName().equalsIgnoreCase(serviceRecord.getName()) - || curAlert!=null && curAlert.visitCode().equalsIgnoreCase(serviceRecord.getName())) { - exists = true; - break; - } + // Check if service is already given + if (!exists) { + for (ServiceRecord serviceRecord : issuedServices) { + if (curAlert != null && curAlert.scheduleName().equalsIgnoreCase(serviceRecord.getName()) + || curAlert != null && curAlert.visitCode().equalsIgnoreCase(serviceRecord.getName())) { + exists = true; + break; } } + } - if (!exists) { - // Insert alert into table - if(curAlert!=null && !curAlert.status().value().equalsIgnoreCase(AlertStatus.expired.value())){ - alertService.create(curAlert); - } - - } + // Insert alert into table + if (!exists && curAlert != null && !curAlert.status().value().equalsIgnoreCase(AlertStatus.expired.value())) { + alertService.create(curAlert); + } //} } @@ -104,7 +102,7 @@ public static Alert getOfflineAlert(final ServiceType serviceType, final List Date: Tue, 7 May 2019 18:00:09 +0300 Subject: [PATCH 10/19] Updated the words and the due state graphic --- opensrp-chw/src/main/res/layout/fragment_profile_due.xml | 4 ++-- opensrp-chw/src/main/res/values/strings.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/opensrp-chw/src/main/res/layout/fragment_profile_due.xml b/opensrp-chw/src/main/res/layout/fragment_profile_due.xml index 46fcd41120..633ae50f83 100644 --- a/opensrp-chw/src/main/res/layout/fragment_profile_due.xml +++ b/opensrp-chw/src/main/res/layout/fragment_profile_due.xml @@ -63,8 +63,8 @@ diff --git a/opensrp-chw/src/main/res/values/strings.xml b/opensrp-chw/src/main/res/values/strings.xml index bc673bf4b3..a8bbadf603 100644 --- a/opensrp-chw/src/main/res/values/strings.xml +++ b/opensrp-chw/src/main/res/values/strings.xml @@ -239,8 +239,8 @@ October November December - No Services are due - When a service becomes due for a family member, it shows up here. + No services are due + When a service becomes due for a family member, it will show up here. None Primary From efd078b8236bd76eba255670c538bf9cc9291852 Mon Sep 17 00:00:00 2001 From: Allan Date: Wed, 8 May 2019 11:51:31 +0300 Subject: [PATCH 11/19] Test that the reporting library instance is initialised when application starts --- .../chw/application/ChwApplicationTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 opensrp-chw/src/test/java/org/smartregister/chw/application/ChwApplicationTest.java diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/application/ChwApplicationTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/application/ChwApplicationTest.java new file mode 100644 index 0000000000..1393dc90d4 --- /dev/null +++ b/opensrp-chw/src/test/java/org/smartregister/chw/application/ChwApplicationTest.java @@ -0,0 +1,14 @@ +package org.smartregister.chw.application; + +import org.junit.Assert; +import org.junit.Test; +import org.smartregister.chw.BaseUnitTest; +import org.smartregister.reporting.ReportingLibrary; + +public class ChwApplicationTest extends BaseUnitTest { + + @Test + public void reportingLibraryIsInitialisedOnStart() { + Assert.assertNotNull(ReportingLibrary.getInstance()); + } +} From d51e4cf720a1634260f425c943bd19969494bb4d Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Wed, 8 May 2019 16:29:47 +0300 Subject: [PATCH 12/19] Issue #346 updated the proper records pending --- .../smartregister/chw/util/ChildDBConstants.java | 7 ++++++- .../chw/util/ChwServiceScheduleTest.java | 16 ++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/util/ChildDBConstants.java b/opensrp-chw/src/main/java/org/smartregister/chw/util/ChildDBConstants.java index 49342c3643..1c5532c194 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/util/ChildDBConstants.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/util/ChildDBConstants.java @@ -43,7 +43,12 @@ public static String childAgeLimitFilter(String tableName) { } public static String childDueFilter() { - return " ((" + ChildDBConstants.KEY.LAST_HOME_VISIT + " is null OR ((" + ChildDBConstants.KEY.LAST_HOME_VISIT + "/1000) > strftime('%s',datetime('now','start of month')))) AND ((" + ChildDBConstants.KEY.VISIT_NOT_DONE + " is null OR " + ChildDBConstants.KEY.VISIT_NOT_DONE + " = '0') OR ((" + ChildDBConstants.KEY.VISIT_NOT_DONE + "/1000) > strftime('%s',datetime('now','start of month'))))) "; + return "(( " + + "IFNULL(STRFTIME('%Y%m%d%H%M%S', datetime((" + KEY.LAST_HOME_VISIT + ")/1000,'unixepoch')),0) " + + "< STRFTIME('%Y%m%d%H%M%S', datetime('now','start of month')) " + + "AND IFNULL(STRFTIME('%Y%m%d%H%M%S', datetime((" + KEY.VISIT_NOT_DONE + ")/1000,'unixepoch')),0) " + + "< STRFTIME('%Y%m%d%H%M%S', datetime('now','start of month')) " + + " ))"; } public static String childMainFilter(String mainCondition, String mainMemberCondition, String filters, String sort, int limit, int offset) { diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/util/ChwServiceScheduleTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/util/ChwServiceScheduleTest.java index 27da833ed9..fc0e9c2952 100644 --- a/opensrp-chw/src/test/java/org/smartregister/chw/util/ChwServiceScheduleTest.java +++ b/opensrp-chw/src/test/java/org/smartregister/chw/util/ChwServiceScheduleTest.java @@ -5,7 +5,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.powermock.reflect.Whitebox; import org.smartregister.chw.BaseUnitTest; @@ -23,17 +22,18 @@ public void setUp() { } @Test - public void calculateAlertStatusNormalExpiryDateSame() throws Exception{ + public void calculateAlertStatusNormalExpiryDateSame() throws Exception { DateTime dueDateTime = new DateTime(); DateTime expiryDateTime = new DateTime(); - AlertStatus alertStatus = Whitebox.invokeMethod(chwServiceSchedule,"calculateAlertStatus",dueDateTime,expiryDateTime); - Assert.assertEquals("normal",alertStatus.value()); + AlertStatus alertStatus = Whitebox.invokeMethod(chwServiceSchedule, "calculateAlertStatus", dueDateTime, expiryDateTime); + Assert.assertEquals("normal", alertStatus.value()); } + @Test - public void calculateAlertStatusExpiredExpiryDateTesterday() throws Exception{ + public void calculateAlertStatusExpiredExpiryDateTesterday() throws Exception { DateTime dueDateTime = new DateTime(); - DateTime expiryDateTime = new DateTime( 1556880664000L); - AlertStatus alertStatus = Whitebox.invokeMethod(chwServiceSchedule,"calculateAlertStatus",dueDateTime,expiryDateTime); - Assert.assertEquals("expired",alertStatus.value()); + DateTime expiryDateTime = new DateTime(1556880664000L); + AlertStatus alertStatus = Whitebox.invokeMethod(chwServiceSchedule, "calculateAlertStatus", dueDateTime, expiryDateTime); + Assert.assertEquals("expired", alertStatus.value()); } } From 17c56e1634eb36755d6c9f938b96430f245b1e95 Mon Sep 17 00:00:00 2001 From: Allan Date: Wed, 8 May 2019 16:32:59 +0300 Subject: [PATCH 13/19] Add LoginInteractorTest for scheduling jobs periodically Test that jobs are scheduled when scheduleJobsPeriodically() is called --- .../chw/interactor/LoginInteractorTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 opensrp-chw/src/test/java/org/smartregister/chw/interactor/LoginInteractorTest.java diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/interactor/LoginInteractorTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/interactor/LoginInteractorTest.java new file mode 100644 index 0000000000..842ec75c24 --- /dev/null +++ b/opensrp-chw/src/test/java/org/smartregister/chw/interactor/LoginInteractorTest.java @@ -0,0 +1,58 @@ +package org.smartregister.chw.interactor; + +import android.content.Context; + +import com.evernote.android.job.Job; +import com.evernote.android.job.JobCreator; +import com.evernote.android.job.JobManager; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +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.PowerMockRunner; +import org.smartregister.chw.job.ChwJobCreator; +import org.smartregister.chw.presenter.LoginPresenter; +import org.smartregister.job.BaseJob; +import org.smartregister.reporting.job.RecurringIndicatorGeneratingJob; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({BaseJob.class, JobManager.class}) +public class LoginInteractorTest { + + private LoginInteractor loginInteractor; + + @Mock + Context context; + + @Mock + private LoginPresenter loginPresenter; + + @Mock + private JobCreator jobCreator; + + @Mock + private JobManager jobManager; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + loginInteractor = new LoginInteractor(loginPresenter); + } + + @Test + public void jobsAreScheduledOnScheduleJobsPeriodically() { + PowerMockito.mockStatic(BaseJob.class); + PowerMockito.mockStatic(JobManager.class); + PowerMockito.when(JobManager.create(context)).thenReturn(jobManager); + jobManager.addJobCreator(jobCreator); + loginInteractor.scheduleJobsPeriodically(); + PowerMockito.verifyStatic(Mockito.times(5)); + BaseJob.scheduleJob(ArgumentMatchers.anyString(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong()); + } +} From 1deea989c9d44d2d0b7ac447a35540b3bdc09ed2 Mon Sep 17 00:00:00 2001 From: Allan Date: Wed, 8 May 2019 16:49:31 +0300 Subject: [PATCH 14/19] Fix codacy issues in LoginInteractorTest --- .../smartregister/chw/interactor/LoginInteractorTest.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/interactor/LoginInteractorTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/interactor/LoginInteractorTest.java index 842ec75c24..83f81df90d 100644 --- a/opensrp-chw/src/test/java/org/smartregister/chw/interactor/LoginInteractorTest.java +++ b/opensrp-chw/src/test/java/org/smartregister/chw/interactor/LoginInteractorTest.java @@ -2,7 +2,6 @@ import android.content.Context; -import com.evernote.android.job.Job; import com.evernote.android.job.JobCreator; import com.evernote.android.job.JobManager; @@ -16,10 +15,8 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import org.smartregister.chw.job.ChwJobCreator; import org.smartregister.chw.presenter.LoginPresenter; import org.smartregister.job.BaseJob; -import org.smartregister.reporting.job.RecurringIndicatorGeneratingJob; @RunWith(PowerMockRunner.class) @PrepareForTest({BaseJob.class, JobManager.class}) @@ -28,7 +25,7 @@ public class LoginInteractorTest { private LoginInteractor loginInteractor; @Mock - Context context; + private Context context; @Mock private LoginPresenter loginPresenter; @@ -52,7 +49,7 @@ public void jobsAreScheduledOnScheduleJobsPeriodically() { PowerMockito.when(JobManager.create(context)).thenReturn(jobManager); jobManager.addJobCreator(jobCreator); loginInteractor.scheduleJobsPeriodically(); - PowerMockito.verifyStatic(Mockito.times(5)); + PowerMockito.verifyStatic(BaseJob.class, Mockito.times(5)); BaseJob.scheduleJob(ArgumentMatchers.anyString(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong()); } } From 12f68843198cc8a6ade2cec772cbc50ac7d0274b Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Wed, 8 May 2019 17:36:28 +0300 Subject: [PATCH 15/19] #338 remove duplicate profile --- .../org/smartregister/chw/activity/MedicalHistoryActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/activity/MedicalHistoryActivity.java b/opensrp-chw/src/main/java/org/smartregister/chw/activity/MedicalHistoryActivity.java index 67462a0f33..8b89a19c83 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/activity/MedicalHistoryActivity.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/activity/MedicalHistoryActivity.java @@ -122,7 +122,7 @@ private void parseBundleANdUpdateView() { if (TextUtils.isEmpty(name)) { textViewTitle.setVisibility(View.GONE); } else { - textViewTitle.setText(getString(R.string.medical_title, name + "'s profile")); + textViewTitle.setText(getString(R.string.medical_title, name)); } textViewLastVisit.setText(getString(R.string.medical_last_visit, Utils.firstCharacterUppercase(lastVisitDays))); initializePresenter(); From 1d4f4db1b32300fdb19c797f24c7e158adcf32f5 Mon Sep 17 00:00:00 2001 From: Allan Date: Thu, 9 May 2019 11:19:40 +0300 Subject: [PATCH 16/19] Add verification statement in LoginInteractorTest Try and fix codacy requirement to have something asserted in test --- .../org/smartregister/chw/interactor/LoginInteractorTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/interactor/LoginInteractorTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/interactor/LoginInteractorTest.java index 83f81df90d..88d815a7c2 100644 --- a/opensrp-chw/src/test/java/org/smartregister/chw/interactor/LoginInteractorTest.java +++ b/opensrp-chw/src/test/java/org/smartregister/chw/interactor/LoginInteractorTest.java @@ -12,6 +12,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.mockito.internal.verification.VerificationModeFactory; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -51,5 +52,6 @@ public void jobsAreScheduledOnScheduleJobsPeriodically() { loginInteractor.scheduleJobsPeriodically(); PowerMockito.verifyStatic(BaseJob.class, Mockito.times(5)); BaseJob.scheduleJob(ArgumentMatchers.anyString(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong()); + PowerMockito.verifyNoMoreInteractions(BaseJob.class); } } From cdebb11f1de6df98f2edaa0f0cd81fd0326d3513 Mon Sep 17 00:00:00 2001 From: mahmud6390 Date: Thu, 9 May 2019 14:44:38 +0600 Subject: [PATCH 17/19] travis fix --- .../chw/presenter/ChildRegisterFragmentPresenterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/presenter/ChildRegisterFragmentPresenterTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/presenter/ChildRegisterFragmentPresenterTest.java index bbbf3ac80f..848dd5a710 100644 --- a/opensrp-chw/src/test/java/org/smartregister/chw/presenter/ChildRegisterFragmentPresenterTest.java +++ b/opensrp-chw/src/test/java/org/smartregister/chw/presenter/ChildRegisterFragmentPresenterTest.java @@ -45,7 +45,7 @@ public void testDefaultSortQuery() { @Test public void testDueAndFilterCondition() { - Assert.assertEquals(" date_removed is null AND (( strftime('%Y','now') - strftime('%Y',dob))<5) AND ((last_home_visit is null OR ((last_home_visit/1000) > strftime('%s',datetime('now','start of month')))) AND ((visit_not_done is null OR visit_not_done = '0') OR ((visit_not_done/1000) > strftime('%s',datetime('now','start of month'))))) ", presenter.getDueFilterCondition()); + Assert.assertEquals(" date_removed is null AND (( strftime('%Y','now') - strftime('%Y',dob))<5) AND (( IFNULL(STRFTIME('%Y%m%d%H%M%S', datetime((last_home_visit)/1000,'unixepoch')),0) < STRFTIME('%Y%m%d%H%M%S', datetime('now','start of month')) AND IFNULL(STRFTIME('%Y%m%d%H%M%S', datetime((visit_not_done)/1000,'unixepoch')),0) < STRFTIME('%Y%m%d%H%M%S', datetime('now','start of month')) ))", presenter.getDueFilterCondition()); } } From 64dd580f2097699feb7f203ac4a2f969015bbf40 Mon Sep 17 00:00:00 2001 From: Allan Date: Thu, 9 May 2019 16:03:38 +0300 Subject: [PATCH 18/19] Add Children (0-11 months) who died in the last year indicator --- .../src/main/assets/config/indicator-definitions.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/opensrp-chw/src/main/assets/config/indicator-definitions.yml b/opensrp-chw/src/main/assets/config/indicator-definitions.yml index 11c7972e5d..d25319ebdb 100644 --- a/opensrp-chw/src/main/assets/config/indicator-definitions.yml +++ b/opensrp-chw/src/main/assets/config/indicator-definitions.yml @@ -1,4 +1,9 @@ indicators: - key: "CHW_001" description: "Total U5 children" - indicatorQuery: "select count(distinct baseEntityId) from event where eventType = 'Child Registration' and eventDate = '%s'" \ No newline at end of file + indicatorQuery: "select count(distinct baseEntityId) from event where eventType = 'Child Registration' and eventDate = '%s'" + + - key: "CHW_002" + description: "Children (0-11 months) who died in the last year" + indicatorQuery: "select count(distinct event.baseEntityId) from event where eventType = 'Remove Child Under 5' and eventDate = '%s' and event.baseEntityId in (select ec_child.base_entity_id + from ec_child where date(ec_child.dob) >= date('now', '-11 month') and date(ec_child.dod) >= date('now', '-12 month'))" From 4dca1b9945b9b47147ab935cc90c4df06ea1a716 Mon Sep 17 00:00:00 2001 From: Allan Date: Thu, 9 May 2019 17:50:57 +0300 Subject: [PATCH 19/19] Add Children (12-59 months) who died in the last year indicator --- opensrp-chw/src/main/assets/config/indicator-definitions.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/opensrp-chw/src/main/assets/config/indicator-definitions.yml b/opensrp-chw/src/main/assets/config/indicator-definitions.yml index d25319ebdb..8616b9b863 100644 --- a/opensrp-chw/src/main/assets/config/indicator-definitions.yml +++ b/opensrp-chw/src/main/assets/config/indicator-definitions.yml @@ -7,3 +7,8 @@ indicators: description: "Children (0-11 months) who died in the last year" indicatorQuery: "select count(distinct event.baseEntityId) from event where eventType = 'Remove Child Under 5' and eventDate = '%s' and event.baseEntityId in (select ec_child.base_entity_id from ec_child where date(ec_child.dob) >= date('now', '-11 month') and date(ec_child.dod) >= date('now', '-12 month'))" + + - key: "CHW_003" + description: "Children (12-59 months) who died in the last year" + indicatorQuery: "select count(distinct event.baseEntityId) from event where eventType = 'Remove Child Under 5' and eventDate = '%s' and event.baseEntityId in (select ec_child.base_entity_id + from ec_child where date(ec_child.dob) >= date('now', '-60 month') and date(ec_child.dob) < date('now', '-11 month') and date(ec_child.dod) >= date('now', '-12 month'))" \ No newline at end of file