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

Washcheck migration #2112

Open
wants to merge 2 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 build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ allprojects {
maven { url "https://cloudant.github.io/cloudant-sync-eap/repository" }
maven { url 'https://maven.fabric.io/public' }
maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
maven { url 'https://nexus.pentaho.org/content/groups/omni/' }
// maven { url 'https://nexus.pentaho.org/content/groups/omni/' }
maven {
url 'https://dl.bintray.com/ibm-watson-health/ibm-fhir-server-releases'
content {
Expand Down
4 changes: 2 additions & 2 deletions opensrp-chw/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ android {
versionName "1.0.8"
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '10000'
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '10000'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '1'
buildConfigField "String", 'opensrp_url', '"https://boresha-afya.smartregister.org/opensrp/"'
buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/ba/"'
buildConfigField "String", 'opensrp_url_debug', '"https://boresha-afya-stage.smartregister.org/opensrp/"'
Expand Down Expand Up @@ -286,7 +286,7 @@ android {
buildConfigField "String", 'DEFAULT_LOCATION', '"VILLAGE/COMMUNAUTE"'
buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '5'
buildConfigField "int", "MAX_READ_TIMEOUT", '5'
buildConfigField "int", "DATABASE_VERSION", '12'
buildConfigField "int", "DATABASE_VERSION", '13'
}
guinea {
dimension = 'baseDimension'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion,
case 23:
upgradeToVersion23(context, db);
break;
case 24:
upgradeToVersion24(db);

default:
break;
}
Expand Down Expand Up @@ -371,4 +374,8 @@ private static void upgradeToVersion23(Context context, SQLiteDatabase db) {
}
}

private static void upgradeToVersion24(SQLiteDatabase db) {
RepositoryUtils.reprocessWashCheckVisits(db);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion,
case 15:
upgradeToVersion15(db);
break;
case 16:
upgradeToVersion16(db);
break;
default:
break;
}
Expand Down Expand Up @@ -214,6 +217,10 @@ private static void upgradeToVersion15(SQLiteDatabase db) {
RepositoryUtils.updateNullEventIds(db);
}

private static void upgradeToVersion16(SQLiteDatabase db) {
RepositoryUtils.reprocessWashCheckVisits(db);
}

private static void initializeIndicatorDefinitions(ReportingLibrary reportingLibrary, SQLiteDatabase sqLiteDatabase) {
String childIndicatorsConfigFile = "config/child-reporting-indicator-definitions.yml";
String ancIndicatorConfigFile = "config/anc-reporting-indicator-definitions.yml";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion,
case 12:
upgradeToVersion12(db);
break;
case 13:
upgradeToVersion13(db);
default:
break;
}
Expand Down Expand Up @@ -165,4 +167,8 @@ private static void upgradeToVersion11(SQLiteDatabase db) {
private static void upgradeToVersion12(SQLiteDatabase db) {
RepositoryUtils.updateNullEventIds(db);
}

private static void upgradeToVersion13(SQLiteDatabase db) {
RepositoryUtils.reprocessWashCheckVisits(db);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion,
case 8:
upgradeToVersion8(db);
break;
case 9:
upgradeToVersion9(db);
default:
break;
}
Expand Down Expand Up @@ -158,5 +160,9 @@ private static void upgradeToVersion7(SQLiteDatabase db) {
}
}

private static void upgradeToVersion9(SQLiteDatabase db) {
RepositoryUtils.reprocessWashCheckVisits(db);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion,
case 8:
upgradeToVersion8(db);
break;
case 9:
upgradeToVersion9(db);
default:
break;
}
Expand Down Expand Up @@ -152,6 +154,10 @@ private static void upgradeToVersion7(SQLiteDatabase db) {
}

private static void upgradeToVersion8(SQLiteDatabase db) {
RepositoryUtils.updateNullEventIds(db);
RepositoryUtils.updateNullEventIds(db);
}

private static void upgradeToVersion9(SQLiteDatabase db) {
RepositoryUtils.reprocessWashCheckVisits(db);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion,
case 7:
upgradeToVersion7(db);
break;
case 8:
upgradeToVersion8(db);
default:
break;
}
Expand Down Expand Up @@ -146,4 +148,8 @@ private static void upgradeToVersion7(SQLiteDatabase db) {
Timber.e(e, "upgradeToVersion7");
}
}

private static void upgradeToVersion8(SQLiteDatabase db) {
RepositoryUtils.reprocessWashCheckVisits(db);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.smartregister.chw.util;

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

import android.database.Cursor;

import net.sqlcipher.database.SQLiteDatabase;

import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.smartregister.chw.anc.util.NCUtils;
import org.smartregister.chw.application.ChwApplication;
import org.smartregister.chw.core.application.CoreChwApplication;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.dao.WashCheckDao;
import org.smartregister.domain.Event;
import org.smartregister.domain.db.EventClient;
import org.smartregister.family.util.DBConstants;
import org.smartregister.repository.EventClientRepository;
import org.smartregister.sync.helper.ECSyncHelper;
Expand All @@ -22,6 +23,9 @@

import timber.log.Timber;

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

public interface RepositoryUtils {

String EVENT_ID = "id";
Expand Down Expand Up @@ -114,7 +118,7 @@ static List<Event> readEvents(Cursor cursor) {
return events;
}

static String getEventId(String jsonString) {
static String getEventId(String jsonString) {
JSONObject jsonObject;
String eventId = null;
if (StringUtils.isNotEmpty(jsonString)) {
Expand All @@ -132,4 +136,38 @@ static String getEventId(String jsonString) {
return eventId;
}


static void reprocessWashCheckVisits(SQLiteDatabase db) {
try {
// add all the wash check tasks to the visit table // will assist the event
List<String> wash_visits = WashCheckDao.getAllWashCheckVisits(db);
for (String visit_id : wash_visits) {
db.execSQL("delete from visits where visit_id = '" + visit_id + "'");
db.execSQL("delete from visit_details where visit_id = '" + visit_id + "'");
}

// reprocess all wash check events
List<EventClient> eventClients = WashCheckDao.getWashCheckEvents(db);
for (EventClient eventClient : eventClients) {
if (eventClient == null) continue;

NCUtils.processHomeVisit(eventClient); // save locally
}

// add missing columns to the DB
List<String> columns = new ArrayList<>();
columns.add(ChildDBConstants.KEY.RELATIONAL_ID);
DatabaseMigrationUtils.addFieldsToFTSTable(db, CoreChwApplication.createCommonFtsObject(), CoreConstants.TABLE_NAME.FAMILY_MEMBER, columns);

// add missing columns
List<String> child_columns = new ArrayList<>();
child_columns.add(DBConstants.KEY.DOB);
child_columns.add(DBConstants.KEY.DATE_REMOVED);
DatabaseMigrationUtils.addFieldsToFTSTable(db, CoreChwApplication.createCommonFtsObject(), CoreConstants.TABLE_NAME.CHILD, child_columns);

} catch (Exception e) {
Timber.e(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.smartregister.chw.core.utils.ChildDBConstants;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.dao.ChwPNCDao;
import org.smartregister.chw.dao.WashCheckDao;
import org.smartregister.chw.domain.PNCHealthFacilityVisitSummary;
import org.smartregister.chw.util.Constants;
import org.smartregister.chw.util.PNCVisitUtil;
Expand All @@ -28,7 +27,6 @@
import org.smartregister.domain.Event;
import org.smartregister.domain.db.Column;
import org.smartregister.domain.db.EventClient;
import org.smartregister.family.util.DBConstants;
import org.smartregister.immunization.repository.RecurringServiceRecordRepository;
import org.smartregister.immunization.repository.RecurringServiceTypeRepository;
import org.smartregister.immunization.repository.VaccineRepository;
Expand Down Expand Up @@ -232,36 +230,7 @@ private static void upgradeToVersion10(SQLiteDatabase db) {
}

private static void upgradeToVersion11(SQLiteDatabase db) {
try {
// add all the wash check tasks to the visit table // will assist the event
List<String> wash_visits = WashCheckDao.getAllWashCheckVisits(db);
for (String visit_id : wash_visits) {
db.execSQL("delete from visits where visit_id = '" + visit_id + "'");
db.execSQL("delete from visit_details where visit_id = '" + visit_id + "'");
}

// reprocess all wash check events
List<EventClient> eventClients = WashCheckDao.getWashCheckEvents(db);
for (EventClient eventClient : eventClients) {
if (eventClient == null) continue;

NCUtils.processHomeVisit(eventClient); // save locally
}

// add missing columns to the DB
List<String> columns = new ArrayList<>();
columns.add(ChildDBConstants.KEY.RELATIONAL_ID);
DatabaseMigrationUtils.addFieldsToFTSTable(db, CoreChwApplication.createCommonFtsObject(), CoreConstants.TABLE_NAME.FAMILY_MEMBER, columns);

// add missing columns
List<String> child_columns = new ArrayList<>();
child_columns.add(DBConstants.KEY.DOB);
child_columns.add(DBConstants.KEY.DATE_REMOVED);
DatabaseMigrationUtils.addFieldsToFTSTable(db, CoreChwApplication.createCommonFtsObject(), CoreConstants.TABLE_NAME.CHILD, child_columns);

} catch (Exception e) {
Timber.e(e);
}
RepositoryUtils.reprocessWashCheckVisits(db);
}

private static void upgradeToVersion12(SQLiteDatabase db, int oldDbVersion) {
Expand Down