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 Given by Default ANM Column #188

Open
wants to merge 4 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=4.0.5-SNAPSHOT
VERSION_NAME=4.0.8-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 @@ -28,6 +28,7 @@ public class Vaccine {
private Integer outOfCatchment;
private Integer outreach;
private Date createdAt;
private Integer givenByDefaultANM;

public Vaccine() {
}
Expand Down Expand Up @@ -118,6 +119,30 @@ public Vaccine(Long id, String baseEntityId, String programClientId, String name
this.outreach = outreach;
}

public Vaccine(Long id, String baseEntityId, String programClientId, String name, Integer
calculation, Date date, String anmId, String locationId, String syncStatus, String
hia2Status, Long updatedAt, String eventId, String formSubmissionId, Integer
outOfCatchment, Date createdAt, Integer isVoided,Integer outreach, Integer givenByDEfaultANM) {
this.id = id;
this.baseEntityId = baseEntityId;
this.programClientId = programClientId;
this.name = name;
this.calculation = calculation;
this.date = date;
this.anmId = anmId;
this.locationId = locationId;
this.syncStatus = syncStatus;
this.hia2Status = hia2Status;
this.updatedAt = updatedAt;
this.eventId = eventId;
this.formSubmissionId = formSubmissionId;
this.outOfCatchment = outOfCatchment;
this.createdAt = createdAt;
this.isVoided = isVoided;
this.outreach = outreach;
this.givenByDefaultANM = givenByDEfaultANM;
}

public Long getId() {
return id;
}
Expand Down Expand Up @@ -286,4 +311,12 @@ public Integer getOutreach() {
public void setOutreach(Integer outreach) {
this.outreach = outreach;
}

public Integer getGivenByDefaultANM() {
return givenByDefaultANM;
}

public void setGivenByDefaultANM(Integer givenByDEfaultANM) {
this.givenByDefaultANM = givenByDEfaultANM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public class VaccineRepository extends BaseRepository {
public static final String CREATED_AT = "created_at";
public static final String TEAM_ID = "team_id";
public static final String TEAM = "team";
public static final String[] VACCINE_TABLE_COLUMNS = {ID_COLUMN, BASE_ENTITY_ID, PROGRAM_CLIENT_ID, NAME, CALCULATION, DATE, ANMID, LOCATION_ID, CHILD_LOCATION_ID, TEAM, TEAM_ID, SYNC_STATUS, HIA2_STATUS, UPDATED_AT_COLUMN, EVENT_ID, FORMSUBMISSION_ID, OUT_OF_AREA, IS_VOIDED, CREATED_AT,OUTREACH};
public static final String GIVEN_BY_DEFAULT_ANM = "given_by_default_anm";
public static final String[] VACCINE_TABLE_COLUMNS = {ID_COLUMN, BASE_ENTITY_ID, PROGRAM_CLIENT_ID, NAME, CALCULATION, DATE, ANMID, LOCATION_ID, CHILD_LOCATION_ID, TEAM, TEAM_ID, SYNC_STATUS, HIA2_STATUS, UPDATED_AT_COLUMN, EVENT_ID, FORMSUBMISSION_ID, OUT_OF_AREA, IS_VOIDED, CREATED_AT,OUTREACH, GIVEN_BY_DEFAULT_ANM} ;
public static final String UPDATE_TABLE_ADD_EVENT_ID_COL = "ALTER TABLE " + VACCINE_TABLE_NAME + " ADD COLUMN " + EVENT_ID + " VARCHAR;";
public static final String EVENT_ID_INDEX = "CREATE INDEX " + VACCINE_TABLE_NAME + "_" + EVENT_ID + "_index ON " + VACCINE_TABLE_NAME + "(" + EVENT_ID + " COLLATE NOCASE);";
public static final String UPDATE_TABLE_ADD_FORMSUBMISSION_ID_COL = "ALTER TABLE " + VACCINE_TABLE_NAME + " ADD COLUMN " + FORMSUBMISSION_ID + " VARCHAR;";
Expand All @@ -67,6 +68,9 @@ public class VaccineRepository extends BaseRepository {
private static final String VACCINE_SQL = "CREATE TABLE vaccines (_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,base_entity_id VARCHAR NOT NULL,program_client_id VARCHAR NULL,name VARCHAR NOT NULL,calculation INTEGER,date DATETIME NOT NULL,anmid VARCHAR NULL,location_id VARCHAR NULL,sync_status VARCHAR, updated_at INTEGER NULL, UNIQUE(base_entity_id, program_client_id, name) ON CONFLICT IGNORE)";
private static final String BASE_ENTITY_ID_INDEX = "CREATE INDEX " + VACCINE_TABLE_NAME + "_" + BASE_ENTITY_ID + "_index ON " + VACCINE_TABLE_NAME + "(" + BASE_ENTITY_ID + " COLLATE NOCASE);";
private static final String UPDATED_AT_INDEX = "CREATE INDEX " + VACCINE_TABLE_NAME + "_" + UPDATED_AT_COLUMN + "_index ON " + VACCINE_TABLE_NAME + "(" + UPDATED_AT_COLUMN + ");";
public static final String UPDATE_TABLE_ADD_GIVEN_BY_DEFAULT_ANM_COL = "ALTER TABLE " + VACCINE_TABLE_NAME + " ADD COLUMN " + GIVEN_BY_DEFAULT_ANM + " INTEGER;";
public static final String UPDATE_TABLE_ADD_GIVEN_BY_DEFAULT_ANM_COL_INDEX = "CREATE INDEX " + VACCINE_TABLE_NAME + "_" + GIVEN_BY_DEFAULT_ANM + "_index ON " + VACCINE_TABLE_NAME + "(" + GIVEN_BY_DEFAULT_ANM + " COLLATE NOCASE);";

public static String HIA2_Within = "Within";
public static String HIA2_Overdue = "Overdue";

Expand Down Expand Up @@ -111,6 +115,9 @@ public void add(Vaccine vaccine) {

vaccine.setHia2Status(null);

if (vaccine.getGivenByDefaultANM() == null)
vaccine.setGivenByDefaultANM(1);

if (StringUtils.isBlank(vaccine.getSyncStatus())) {
vaccine.setSyncStatus(TYPE_Unsynced);
}
Expand Down Expand Up @@ -193,6 +200,7 @@ private ContentValues createValuesFor(Vaccine vaccine) {
values.put(OUTREACH, vaccine.getOutreach());
values.put(CREATED_AT,
vaccine.getCreatedAt() != null ? EventClientRepository.dateFormat.format(vaccine.getCreatedAt()) : null);
values.put(GIVEN_BY_DEFAULT_ANM, vaccine.getGivenByDefaultANM());
return values;
}

Expand Down Expand Up @@ -288,14 +296,15 @@ public List<Vaccine> readAllVaccines(Cursor cursor) {
vaccine.setTeam(cursor.getString(cursor.getColumnIndex(TEAM)));
vaccine.setTeamId(cursor.getString(cursor.getColumnIndex(TEAM_ID)));
vaccine.setChildLocationId(cursor.getString(cursor.getColumnIndex(CHILD_LOCATION_ID)));
vaccine.setGivenByDefaultANM(cursor.getInt(cursor.getColumnIndex(GIVEN_BY_DEFAULT_ANM)));

vaccines.add(vaccine);

cursor.moveToNext();
}
}
} catch (Exception e) {

e.printStackTrace();
} finally {
cursor.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public void assertDefaultConstructorsCreateNonNullObjectOnInstantiation() {
ANMID, LOCATIONID, SYNCSTATUS, HIA2STATUS, 0l, EVENTID, FORMSUBMISSIONID, 0));
junit.framework.Assert.assertNotNull(new Vaccine(0l, BASEENTITYID, PROGRAMCLIENTID, NAME, 0, new Date(),
ANMID, LOCATIONID, SYNCSTATUS, HIA2STATUS, 0l, EVENTID, FORMSUBMISSIONID, 0, new Date(), 1));

junit.framework.Assert.assertNotNull(new Vaccine(0l, BASEENTITYID, PROGRAMCLIENTID, NAME, 0, new Date(),
ANMID, LOCATIONID, SYNCSTATUS, HIA2STATUS, 0l, EVENTID, FORMSUBMISSIONID, 0, new Date(), 1,1));
junit.framework.Assert.assertNotNull(new Vaccine(0l, BASEENTITYID, PROGRAMCLIENTID, NAME, 0, new Date(),
ANMID, LOCATIONID, SYNCSTATUS, HIA2STATUS, 0l, EVENTID, FORMSUBMISSIONID, 0, new Date(), 1,1, 1));
}

@Test
Expand Down Expand Up @@ -127,8 +128,12 @@ public void assetTestallgettersandsetters() {

vaccine.setOutreach(1);
Assert.assertEquals(1,vaccine.getOutreach().intValue());

vaccine.setProgramClientId(PROGRAMCLIENTID);
junit.framework.Assert.assertEquals(PROGRAMCLIENTID, vaccine.getProgramClientId());

vaccine.setGivenByDefaultANM(1);
junit.framework.Assert.assertEquals(1, vaccine.getGivenByDefaultANM().intValue());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,12 @@ public void testReadAllReturnsListOfVaccines() {
VaccineRepository.TEAM_ID,
VaccineRepository.CHILD_LOCATION_ID,
VaccineRepository.IS_VOIDED,
VaccineRepository.OUTREACH
VaccineRepository.OUTREACH,
VaccineRepository.GIVEN_BY_DEFAULT_ANM
};

MatrixCursor cursor = new MatrixCursor(columns);
cursor.addRow(new Object[]{1l, "", "", magicName, magic10, magicTime, "", "", "", "", 1l, "", "", 1, magicTime, "", "", "", 1, 1});
cursor.addRow(new Object[]{1l, "", "", magicName, magic10, magicTime, "", "", "", "", 1l, "", "", 1, magicTime, "", "", "", 1, 1, 0});

List<Vaccine> vaccines = vaccineRepository.readAllVaccines(cursor);
Assert.assertFalse(vaccines.isEmpty());
Expand Down Expand Up @@ -374,10 +375,10 @@ public void testFindByBaseEntityIdAndVaccineNameInvokesDBQueryAndReturnsCorrectV
VaccineRepository.LOCATION_ID, VaccineRepository.SYNC_STATUS, VaccineRepository.HIA2_STATUS,
VaccineRepository.CREATED_AT, VaccineRepository.UPDATED_AT_COLUMN, VaccineRepository.EVENT_ID,
VaccineRepository.FORMSUBMISSION_ID, VaccineRepository.OUT_OF_AREA, VaccineRepository.IS_VOIDED, VaccineRepository.OUTREACH,
VaccineRepository.TEAM, VaccineRepository.TEAM_ID, VaccineRepository.CHILD_LOCATION_ID
VaccineRepository.TEAM, VaccineRepository.TEAM_ID, VaccineRepository.CHILD_LOCATION_ID, VaccineRepository.GIVEN_BY_DEFAULT_ANM
};
MatrixCursor cursor = new MatrixCursor(columns);
cursor.addRow(new Object[]{1l, "", "", magicName, magic10, magicTime, "", "", "", "", magicDate, 1l, "", "", 1, 0, 0, team, teamId, ""});
cursor.addRow(new Object[]{1l, "", "", magicName, magic10, magicTime, "", "", "", "", magicDate, 1l, "", "", 1, 0, 0, team, teamId, "", 0});

Mockito.when(
sqliteDatabase.query(
Expand Down
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ android {
}

debug {
buildConfigField "int", "DATABASE_VERSION", '6'
buildConfigField "int", "DATABASE_VERSION", '7'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
break;
case 6:
upgradeToVersion6(db);
case 7:
upgradeToVersion7(db);
default:
break;
}
Expand Down Expand Up @@ -218,4 +220,15 @@ private void upgradeToVersion6(SQLiteDatabase db)
}
}

private void upgradeToVersion7(SQLiteDatabase db) {
try {
db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_GIVEN_BY_DEFAULT_ANM_COL);
db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_GIVEN_BY_DEFAULT_ANM_COL_INDEX);

} catch (Exception e) {
Log.e(TAG, "upgradeToVersion7 " + Log.getStackTraceString(e));
}
}


}