Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add status to vaccine overdue count repo #196

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=5.0.0-SNAPSHOT
VERSION_NAME=5.0.1-SNAPSHOT
VERSION_CODE=3
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Immunization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,12 @@ private static List<Alert> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down Expand Up @@ -95,14 +95,15 @@ 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();

ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String[]> 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());

Expand All @@ -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
Expand Down