Skip to content

Commit

Permalink
Merge branch 'master' into flavor-nigeria-dcis
Browse files Browse the repository at this point in the history
  • Loading branch information
zzainulabidin committed Oct 5, 2021
2 parents ec21818 + 6b9146b commit b58d650
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 33 deletions.
18 changes: 12 additions & 6 deletions opensrp-chw/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ android {
togo {
dimension = 'baseDimension'
applicationIdSuffix ".togo"
versionCode 23
versionName "1.2.5"
versionCode 26
versionName "1.2.7"
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '1000'
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '500'
buildConfigField "String", 'opensrp_url', '"https://wcaro-tg.smartregister.org/opensrp/"'
Expand All @@ -322,20 +322,24 @@ android {
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"National", "Regional" , "District" , "Formation sanitaire", "Supervisor", "Village"}'
buildConfigField "String", 'DEFAULT_LOCATION_DEBUG', '"Village"'
buildConfigField "String", 'DEFAULT_LOCATION', '"Village"'
buildConfigField "int", "DATABASE_VERSION", '20'
buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '10'
buildConfigField "int", "MAX_READ_TIMEOUT", '10'
buildConfigField "int", "DATABASE_VERSION", '21'
}
liberia {
dimension = 'baseDimension'
versionCode 6
versionName "0.1.12"
buildConfigField "String", 'opensrp_url', '"https://wcaro-liberia.smartregister.org/opensrp/"'
versionCode 7
versionName "1.0.0"
buildConfigField "String", 'opensrp_url', '"https://wcaro-lr.smartregister.org/opensrp/"'
buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/liberia/"'
buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-stage.smartregister.org/opensrp/"'
buildConfigField "String[]", "LOCATION_HIERACHY", '{"Clinic" , "CHSS" , "CHA"}'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"Country" , "County" , "District", "Clinics", "CHSS", "Village"}'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS_DEBUG", '{"Clinic" , "CHSS" , "CHA"}'
buildConfigField "String", 'DEFAULT_LOCATION', '"Village"'
buildConfigField "String", 'DEFAULT_LOCATION_DEBUG', '"CHA"'
buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '5'
buildConfigField "int", "MAX_READ_TIMEOUT", '5'
buildConfigField "int", "DATABASE_VERSION", '7'
}
lmh {
Expand Down Expand Up @@ -397,6 +401,8 @@ dependencies {
//For viewing PDFs in the app
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'

implementation 'com.github.lecho:hellocharts-android:v1.5.8@aar'

testImplementation "org.koin:koin-test:2.0.1"
testImplementation 'junit:junit:4.13'
testImplementation 'org.mockito:mockito-core:3.1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
package org.smartregister.chw.sync;

import org.smartregister.chw.dao.EventDao;
import org.smartregister.sync.intent.SyncIntentService;

public class ChwSyncIntentService extends SyncIntentService {

@Override
protected void handleSync() {
// fetch the last downloaded serverVersion before any unsyced data
Long serverVersion = EventDao.getMinimumVerifiedServerVersion();
if (serverVersion != null)
org.smartregister.util.Utils.getAllSharedPreferences().saveLastSyncDate(serverVersion);

// flag all contentious events as unsynced
EventDao.markEventsForReUpload();
super.handleSync();
}

@Override
public int getEventPullLimit() {
return 1000;
}

@Override
protected Integer getEventBatchSize(){
return 250;
}
return 50;
} // Should this be configurable?
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package org.smartregister.chw.application;

public class ChwApplicationFlv extends DefaultChwApplicationFlv {
@Override
public boolean showChildrenUnderFiveAndGirlsAgeNineToEleven() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.smartregister.chw.repository;

import static org.smartregister.repository.BaseRepository.TYPE_Synced;
import static org.smartregister.repository.BaseRepository.TYPE_Valid;

import android.content.Context;
import android.database.Cursor;

import net.sqlcipher.database.SQLiteDatabase;

import org.apache.commons.lang3.StringUtils;
import org.joda.time.format.DateTimeFormat;
import org.json.JSONObject;
import org.smartregister.chw.anc.AncLibrary;
Expand Down Expand Up @@ -51,6 +55,9 @@

public class ChwRepositoryFlv {

private static final String EVENT_ID = "id";
private static final String _ID = "_id";

public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, int newVersion) {
Timber.w(ChwRepository.class.getName(),
"Upgrading database from version " + oldVersion + " to "
Expand Down Expand Up @@ -109,21 +116,16 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion,
case 20:
upgradeToVersion20(db);
break;
case 21:
upgradeToVersion21(db);
break;
default:
break;
}
upgradeTo++;
}
}

private static void upgradeToVersion20(SQLiteDatabase db) {
try {
db.execSQL("ALTER TABLE ec_family_member ADD COLUMN marital_status VARCHAR;");
} catch (Exception e) {
Timber.e(e, "upgradeToVersion20");
}
}

private static void upgradeToVersion2(Context context, SQLiteDatabase db) {
try {
db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_EVENT_ID_COL);
Expand Down Expand Up @@ -336,6 +338,7 @@ private static List<Event> readEvents(Cursor cursor) {
while (!cursor.isAfterLast()) {
String json = cursor.getString(cursor.getColumnIndex("json"));
Event event = syncHelper.convert(new JSONObject(json), Event.class);
event.setEventId(getEventId(json));
events.add(event);
cursor.moveToNext();
}
Expand All @@ -348,6 +351,24 @@ private static List<Event> readEvents(Cursor cursor) {
return events;
}

private static String getEventId(String jsonString) {
JSONObject jsonObject;
String eventId = null;
if (StringUtils.isNotEmpty(jsonString)) {
try {
jsonObject = new JSONObject(jsonString);
if (jsonObject.has(EVENT_ID)) {
eventId = jsonObject.getString(EVENT_ID);
}else if (jsonObject.has(_ID)) {
eventId = jsonObject.getString(_ID);
}
} catch (Exception ex) {
Timber.e(ex);
}
}
return eventId;
}

private static void processHFNextVisitDateObs(List<Event> events, SQLiteDatabase sqLiteDatabase) {
// Save missing PNC Health Facility visit (next visit) details
for (Event event : events) {
Expand Down Expand Up @@ -420,17 +441,17 @@ private static void upgradeToVersion17(SQLiteDatabase db) {
Timber.e(e, "upgradeToVersion17");
}
}

private static void upgradeToVersion18(SQLiteDatabase db) {
try {
ReportingLibrary reportingLibraryInstance = ReportingLibrary.getInstance();
initializeIndicatorDefinitions(reportingLibraryInstance, db);
} catch (Exception e){
} catch (Exception e) {
Timber.e(e, "upgradeToVersion18");
}
}
private static void upgradeToVersion19(Context context, SQLiteDatabase db) {

private static void upgradeToVersion19(Context context, SQLiteDatabase db) {
try {
db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_IS_VOIDED_COL);
db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_IS_VOIDED_COL_INDEX);
Expand All @@ -440,4 +461,42 @@ private static void upgradeToVersion19(Context context, SQLiteDatabase db) {
Timber.e(e);
}
}

private static void upgradeToVersion20(SQLiteDatabase db) {
try {
db.execSQL("ALTER TABLE ec_family_member ADD COLUMN marital_status VARCHAR;");
} catch (Exception e) {
Timber.e(e, "upgradeToVersion20");
}
}

private static void upgradeToVersion21(SQLiteDatabase db) {
List<Event> events = new ArrayList<>();
String eventTableName = EventClientRepository.Table.event.name();
String eventIdCol = EventClientRepository.event_column.eventId.name();
String eventSyncStatusCol = EventClientRepository.event_column.syncStatus.name();
String eventValidCol = EventClientRepository.event_column.validationStatus.name();
String jsonCol = EventClientRepository.event_column.json.name();
String formSubmissionCol = EventClientRepository.event_column.formSubmissionId.name();

Cursor cursor;
String selection = eventIdCol + " IS NULL AND " + eventValidCol + " = ?";
try {
cursor = db.query(eventTableName, new String[]{jsonCol},
selection, new String[]{TYPE_Valid}, null, null, null);
events = readEvents(cursor);
} catch (Exception ex) {
Timber.e(ex);
}
String updateSQL;
for (Event event : events) {
updateSQL = String.format("UPDATE %s SET %s = '%s', %s = '%s' WHERE %s = '%s';", eventTableName,
eventIdCol, event.getEventId(), eventSyncStatusCol, TYPE_Synced, formSubmissionCol, event.getFormSubmissionId());
try {
db.execSQL(updateSQL);
} catch (Exception e) {
Timber.e(e, "upgradeToVersion21 ");
}
}
}
}

0 comments on commit b58d650

Please sign in to comment.