diff --git a/gradle.properties b/gradle.properties index cb1b6b0c..519714d5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=4.0.7-SNAPSHOT +VERSION_NAME=4.0.8-ALPHA1-SNAPSHOT VERSION_CODE=3 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Immunization diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/domain/VaccineSchedule.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/domain/VaccineSchedule.java index 9696db9e..d9bc0196 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/domain/VaccineSchedule.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/domain/VaccineSchedule.java @@ -115,7 +115,6 @@ private static VaccineSchedule getVaccineSchedule(String vaccineName, String vac VaccineRepo.Vaccine vaccine = VaccineRepo.getVaccine(vaccineName, vaccineCategory); - if (vaccine != null) { ArrayList conditions = new ArrayList<>(); if (schedule.conditions != null) { @@ -151,7 +150,6 @@ public static List updateOfflineAlerts(String baseEntityId, DateTime dob List newAlerts = updateOfflineAlertsAndReturnNewAlertList(baseEntityId, dob, vaccineCategory); List notInNew = getAlertsNotInNew(newAlerts); return notInNew; - } catch (Exception e) { Timber.e(VaccineSchedule.class.getName(), e.toString(), e); return new ArrayList<>(); @@ -199,7 +197,6 @@ public static List updateOfflineAlertsAndReturnAffectedVaccineNames(Stri * @param vaccineCategory */ private static List updateOfflineAlertsAndReturnNewAlertList(String baseEntityId, DateTime dob, String vaccineCategory) { - List newAlerts = new ArrayList<>(); try { VaccineRepository vaccineRepository = ImmunizationLibrary.getInstance().vaccineRepository(); @@ -228,10 +225,12 @@ private static List updateOfflineAlertsAndReturnNewAlertList(String baseE newAlerts.add(curAlert); alertService.updateFtsSearch(curAlert, true); - if (!isAnyVaccineUrgent && AlertStatus.urgent.equals(curAlert.status())) { + if (!isAnyVaccineUrgent && (AlertStatus.urgent.equals(curAlert.status()) + || AlertStatus.normal.equals(curAlert.status()))) { try { isAnyVaccineUrgent = true; - ImmunizationLibrary.getInstance().getVaccineOverdueCountRepository().upsert(baseEntityId); + ImmunizationLibrary.getInstance().getVaccineOverdueCountRepository() + .upsert(baseEntityId, curAlert.status().value()); } catch (Exception e) { Timber.e(e); } @@ -250,8 +249,7 @@ private static List updateOfflineAlertsAndReturnNewAlertList(String baseE alertService.create(newAlerts); } - } catch ( - Exception e) { + } catch (Exception e) { Timber.e(VaccineSchedule.class.getName(), e.toString(), e); } @@ -358,8 +356,7 @@ public static void setVaccineSchedules(HashMap issuedVaccines) { + public Alert getOfflineAlert(String baseEntityId, Date dateOfBirth, List issuedVaccines) { Alert defaultAlert = null; // Check if all conditions pass @@ -384,14 +381,15 @@ public Alert getOfflineAlert(String baseEntityId, Date dateOfBirth, } if (alertStatus != null) { - - Alert offlineAlert = new Alert(baseEntityId, + Alert offlineAlert = new Alert( + baseEntityId, vaccine.display(), vaccine.name().toLowerCase(Locale.ENGLISH).replace(" ", ""), alertStatus, dueDate == null ? null : DateUtil.yyyyMMdd.format(dueDate), expiryDate == null ? null : DateUtil.yyyyMMdd.format(expiryDate), - true); + true + ); return offlineAlert; } @@ -400,7 +398,6 @@ public Alert getOfflineAlert(String baseEntityId, Date dateOfBirth, } protected boolean isVaccineIssued(String currentVaccine, List issuedVaccines) { - for (Vaccine vaccine : issuedVaccines) { if (currentVaccine.equalsIgnoreCase(vaccine.getName().replaceAll(" ", ""))) { return true; diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineOverdueCountRepository.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineOverdueCountRepository.java index b8ac29d2..d59775d4 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineOverdueCountRepository.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineOverdueCountRepository.java @@ -13,16 +13,18 @@ public class VaccineOverdueCountRepository extends BaseRepository { public static final String TABLE_NAME = "vaccine_overdue_count"; + public static final String STATUS = "status"; public static final String CREATE_TABLE_SQL = "CREATE TABLE " + TABLE_NAME + "(" + VaccineRepository.BASE_ENTITY_ID + " VARCHAR NOT NULL," + "UNIQUE(" + VaccineRepository.BASE_ENTITY_ID + ") ON CONFLICT REPLACE)"; - + public static final String ADD_STATUS_COLUMN = "ALTER TABLE " + TABLE_NAME + " ADD " + STATUS + " VARCHAR;"; @VisibleForTesting - protected static final String UPDATE_QUERY_SQL = "INSERT INTO " + TABLE_NAME + "(base_entity_id) values ( ? ) ON conflict(base_entity_id) do nothing;"; + protected static final String UPDATE_QUERY_SQL = "INSERT OR REPLACE INTO " + TABLE_NAME + "(base_entity_id, status) values ( ? , ? );"; public static void createTable(@NonNull SQLiteDatabase database) { database.execSQL(CREATE_TABLE_SQL); + database.execSQL(ADD_STATUS_COLUMN); } /** @@ -40,9 +42,9 @@ public int getOverdueCount(String countQuerySQL) { * * @param baseEntityId the entity id of client */ - public void upsert(String baseEntityId) { + public void upsert(String baseEntityId, String status) { try { - getWritableDatabase().execSQL(UPDATE_QUERY_SQL, new String[]{baseEntityId}); + getWritableDatabase().execSQL(UPDATE_QUERY_SQL, new String[]{baseEntityId, status}); } catch (Exception e) { Timber.e(e); } diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/service/intent/RecurringIntentService.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/service/intent/RecurringIntentService.java index bf13111f..1121cda9 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/service/intent/RecurringIntentService.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/service/intent/RecurringIntentService.java @@ -16,6 +16,7 @@ import java.text.SimpleDateFormat; import java.util.List; +import java.util.Locale; import timber.log.Timber; @@ -74,7 +75,10 @@ protected void onHandleIntent(Intent intent) { if (!serviceRecordList.isEmpty()) { for (ServiceRecord serviceRecord : serviceRecordList) { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat( + "yyyy-MM-dd", + Locale.getDefault().toString().startsWith("ar") ? Locale.ENGLISH : Locale.getDefault() + ); String formattedDate = simpleDateFormat.format(serviceRecord.getDate()); ServiceType serviceType = recurringServiceTypeRepository.find(serviceRecord.getRecurringServiceId()); diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/view/ServiceCard.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/view/ServiceCard.java index aab6ce51..a28a4947 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/view/ServiceCard.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/view/ServiceCard.java @@ -32,8 +32,9 @@ */ public class ServiceCard extends LinearLayout { - private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yy"); - private static final SimpleDateFormat SHORT_DATE_FORMAT = new SimpleDateFormat("dd/MM"); + + private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yy", Locale.ENGLISH); + private static final SimpleDateFormat SHORT_DATE_FORMAT = new SimpleDateFormat("dd/MM", Locale.ENGLISH); private Context context; private ImageView statusIV; private TextView nameTV; diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/view/VaccineGroup.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/view/VaccineGroup.java index 698cd3e6..e055933b 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/view/VaccineGroup.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/view/VaccineGroup.java @@ -30,6 +30,7 @@ import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.concurrent.TimeUnit; /** @@ -67,18 +68,22 @@ private void init(Context context) { this.context = context; LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); layoutInflater.inflate(R.layout.view_vaccine_group, this, true).setFilterTouchesWhenObscured(true); - ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT); + ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams( + LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ); setLayoutParams(layoutParams); - READABLE_DATE_FORMAT = new SimpleDateFormat("dd MMMM, yyyy"); + READABLE_DATE_FORMAT = new SimpleDateFormat( + "dd MMMM, yyyy", + Locale.getDefault().toString().startsWith("ar") ? Locale.ENGLISH : Locale.getDefault() + ); nameTV = findViewById(R.id.name_tv); vaccinesGV = findViewById(R.id.vaccines_gv); vaccinesGV.setExpanded(true); recordAllTV = findViewById(R.id.record_all_tv); recordAllTV.setOnClickListener(this); - } public VaccineGroup(Context context, AttributeSet attrs) { diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineOverdueCountRepositoryTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineOverdueCountRepositoryTest.java index 3696aa5b..7e23990b 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineOverdueCountRepositoryTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineOverdueCountRepositoryTest.java @@ -39,12 +39,12 @@ public void testCreateTableExecutesCorrectSQLQuery() { VaccineOverdueCountRepository.createTable(sqliteDatabase); - Mockito.verify(sqliteDatabase).execSQL(stringArgumentCaptor.capture()); + Mockito.verify(sqliteDatabase, Mockito.times(2)).execSQL(stringArgumentCaptor.capture()); String sQLExecuted = stringArgumentCaptor.getValue(); Assert.assertNotNull(sQLExecuted); - Assert.assertEquals(VaccineOverdueCountRepository.CREATE_TABLE_SQL, sQLExecuted); + Assert.assertEquals(VaccineOverdueCountRepository.ADD_STATUS_COLUMN, sQLExecuted); } @@ -95,6 +95,7 @@ public void testGetOverdueCountReturnsZeroIfCursorNull() { @Test public void testUpsertExecuteCorrectUpdateAndInsertQuery() { String TEST_BASE_ENTIY_ID = "test-id"; + String STATUS = "urgent"; Mockito.doNothing().when(sqliteDatabase).execSQL(ArgumentMatchers.anyString(), ArgumentMatchers.any(String[].class)); Mockito.doReturn(sqliteDatabase).when(overdueCountRepository).getWritableDatabase(); @@ -102,7 +103,7 @@ public void testUpsertExecuteCorrectUpdateAndInsertQuery() { ArgumentCaptor stringArgumentCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor stringArrayArgumentCaptor = ArgumentCaptor.forClass(String[].class); - overdueCountRepository.upsert(TEST_BASE_ENTIY_ID); + overdueCountRepository.upsert(TEST_BASE_ENTIY_ID, STATUS); Mockito.verify(sqliteDatabase).execSQL(stringArgumentCaptor.capture(), stringArrayArgumentCaptor.capture()); @@ -113,8 +114,9 @@ public void testUpsertExecuteCorrectUpdateAndInsertQuery() { String[] resultParameters = stringArrayArgumentCaptor.getValue(); Assert.assertNotNull(resultParameters); - Assert.assertEquals(1, resultParameters.length); + Assert.assertEquals(2, resultParameters.length); Assert.assertEquals(TEST_BASE_ENTIY_ID, resultParameters[0]); + Assert.assertEquals(STATUS, resultParameters[1]); } @Test diff --git a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java index d8a77d8c..8a025b78 100644 --- a/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java +++ b/sample/src/main/java/org/smartregister/immunization/sample/DetailActivity.java @@ -59,6 +59,7 @@ import java.util.Date; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; /** @@ -74,7 +75,10 @@ public class DetailActivity extends AppCompatActivity implements VaccinationActi public static Gender gender; public static final String EXTRA_CHILD_DETAILS = "child_details"; - public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy"); + public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat( + "dd-MM-yyyy", + Locale.getDefault().toString().startsWith("ar") ? Locale.ENGLISH : Locale.getDefault() + ); private ImmunizationFragment immunizationFragment; public CommonPersonObjectClient getChildDetails() { diff --git a/sample/src/main/java/org/smartregister/immunization/sample/util/SampleUtil.java b/sample/src/main/java/org/smartregister/immunization/sample/util/SampleUtil.java index ea98e883..7be0085b 100644 --- a/sample/src/main/java/org/smartregister/immunization/sample/util/SampleUtil.java +++ b/sample/src/main/java/org/smartregister/immunization/sample/util/SampleUtil.java @@ -4,13 +4,17 @@ import java.text.SimpleDateFormat; import java.util.HashMap; +import java.util.Locale; import java.util.Random; /** * Created by keyman on 01/08/2017. */ public class SampleUtil { - public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy"); + public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat( + "dd/MM/yyyy", + Locale.getDefault().toString().startsWith("ar") ? Locale.ENGLISH : Locale.getDefault() + ); public static final String ENTITY_ID = "1"; public static final String DOB_STRING = "2018-06-01T00:00:00.000Z";