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

Monthly tallies sync #126

Merged
merged 5 commits into from
Dec 15, 2020
Merged
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
4 changes: 2 additions & 2 deletions opensrp-chw-hf/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {
buildConfigField "String", 'opensrp_url_debug', '"https://boresha-afya-stage.smartregister.org/opensrp/"'
// buildConfigField "String", 'opensrp_url_debug', '"https://ba-unified-stage.smartregister.org/opensrp/"'
buildConfigField "boolean", 'SUPPORT_QR', 'true'
buildConfigField "int", "DATABASE_VERSION", '9'
buildConfigField "int", "DATABASE_VERSION", '11'
buildConfigField "int", "DATA_SYNC_DURATION_MINUTES", '15'
buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
buildConfigField "boolean", "TIME_CHECK", "false"
Expand Down Expand Up @@ -147,7 +147,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation('org.smartregister:opensrp-client-chw-core:1.5.22-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-chw-core:1.5.23-SNAPSHOT@aar') {
// implementation(project(":opensrp-chw-core")) {
transitive = true
exclude group: 'com.android.support', module: 'appcompat-v7'
Expand Down
8 changes: 8 additions & 0 deletions opensrp-chw-hf/src/main/assets/ec_client_fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@
"json_mapping": {
"field": "attributes.dateRemoved"
}
},
{
"column_name": "event_date",
"type": "Event",
"json_mapping": {
"field": "eventDate",
"event_type": "Family Registration"
}
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.smartregister.chw.core.loggers.CrashlyticsTree;
import org.smartregister.chw.core.provider.CoreAllClientsRegisterQueryProvider;
import org.smartregister.chw.core.service.CoreAuthorizationService;
import org.smartregister.chw.core.utils.ChildDBConstants;
import org.smartregister.chw.core.utils.ChwDBConstants;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.core.utils.FormUtils;
import org.smartregister.chw.fp.FpLibrary;
Expand All @@ -43,10 +45,12 @@
import org.smartregister.chw.hf.sync.HfSyncConfiguration;
import org.smartregister.chw.malaria.MalariaLibrary;
import org.smartregister.chw.pnc.PncLibrary;
import org.smartregister.commonregistry.CommonFtsObject;
import org.smartregister.configurableviews.ConfigurableViewsLibrary;
import org.smartregister.configurableviews.helper.JsonSpecHelper;
import org.smartregister.family.FamilyLibrary;
import org.smartregister.family.domain.FamilyMetadata;
import org.smartregister.family.util.DBConstants;
import org.smartregister.immunization.ImmunizationLibrary;
import org.smartregister.location.helper.LocationHelper;
import org.smartregister.opd.OpdLibrary;
Expand All @@ -69,6 +73,7 @@
import timber.log.Timber;

public class HealthFacilityApplication extends CoreChwApplication implements CoreApplication {
private CommonFtsObject commonFtsObject;

@Override
public FamilyMetadata getMetadata() {
Expand Down Expand Up @@ -132,6 +137,23 @@ public TaskRepository getTaskRepository() {
return taskRepository;
}

public CommonFtsObject getCommonFtsObject() {
if (commonFtsObject == null) {

String[] tables = getFTSTables();

Map<String, String[]> searchMap = getFTSSearchMap();
Map<String, String[]> sortMap = getFTSSortMap();

commonFtsObject = new CommonFtsObject(tables);
for (String ftsTable : commonFtsObject.getTables()) {
commonFtsObject.updateSearchFields(ftsTable, searchMap.get(ftsTable));
commonFtsObject.updateSortFields(ftsTable, sortMap.get(ftsTable));
}
}
return commonFtsObject;
}

@Override
public void onCreate() {
super.onCreate();
Expand All @@ -140,6 +162,7 @@ public void onCreate() {
context = Context.getInstance();
context.updateApplicationContext(getApplicationContext());
context.updateCommonFtsObject(createCommonFtsObject());
context.updateCommonFtsObject(getCommonFtsObject());

//init Job Manager
SyncStatusBroadcastReceiver.init(this);
Expand Down Expand Up @@ -220,4 +243,44 @@ public void logoutCurrentUser() {
public boolean getChildFlavorUtil(){
return true;
}

public String[] getFTSTables() {
return new String[]{CoreConstants.TABLE_NAME.FAMILY, CoreConstants.TABLE_NAME.FAMILY_MEMBER, CoreConstants.TABLE_NAME.CHILD};
}

public Map<String, String[]> getFTSSearchMap() {
Map<String, String[]> map = new HashMap<>();
map.put(CoreConstants.TABLE_NAME.FAMILY, new String[]{
DBConstants.KEY.BASE_ENTITY_ID, DBConstants.KEY.VILLAGE_TOWN, DBConstants.KEY.FIRST_NAME,
DBConstants.KEY.LAST_NAME, DBConstants.KEY.UNIQUE_ID, ChwDBConstants.NEAREST_HEALTH_FACILITY
});

map.put(CoreConstants.TABLE_NAME.FAMILY_MEMBER, new String[]{
DBConstants.KEY.BASE_ENTITY_ID, DBConstants.KEY.FIRST_NAME, DBConstants.KEY.MIDDLE_NAME,
DBConstants.KEY.LAST_NAME, DBConstants.KEY.UNIQUE_ID, ChildDBConstants.KEY.ENTRY_POINT, DBConstants.KEY.DOB, DBConstants.KEY.DATE_REMOVED
});

map.put(CoreConstants.TABLE_NAME.CHILD, new String[]{
DBConstants.KEY.BASE_ENTITY_ID, DBConstants.KEY.FIRST_NAME, DBConstants.KEY.MIDDLE_NAME,
DBConstants.KEY.LAST_NAME, DBConstants.KEY.UNIQUE_ID, ChildDBConstants.KEY.ENTRY_POINT, DBConstants.KEY.DOB, DBConstants.KEY.DATE_REMOVED
});
return map;
}

public Map<String, String[]> getFTSSortMap() {
Map<String, String[]> map = new HashMap<>();
map.put(CoreConstants.TABLE_NAME.FAMILY, new String[]{DBConstants.KEY.LAST_INTERACTED_WITH, DBConstants.KEY.DATE_REMOVED,
DBConstants.KEY.FAMILY_HEAD, DBConstants.KEY.PRIMARY_CAREGIVER, DBConstants.KEY.ENTITY_TYPE,
CoreConstants.DB_CONSTANTS.DETAILS
});

map.put(CoreConstants.TABLE_NAME.FAMILY_MEMBER, new String[]{DBConstants.KEY.DOB, DBConstants.KEY.DOD,
DBConstants.KEY.LAST_INTERACTED_WITH, DBConstants.KEY.DATE_REMOVED, DBConstants.KEY.RELATIONAL_ID
});

map.put(CoreConstants.TABLE_NAME.CHILD, new String[]{ChildDBConstants.KEY.LAST_HOME_VISIT, ChildDBConstants.KEY.VISIT_NOT_DONE, DBConstants.KEY
.LAST_INTERACTED_WITH, ChildDBConstants.KEY.DATE_CREATED, DBConstants.KEY.DATE_REMOVED, DBConstants.KEY.DOB, ChildDBConstants.KEY.ENTRY_POINT
});
return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
Expand All @@ -15,6 +17,7 @@
import org.smartregister.chw.core.activity.CoreFamilyRemoveMemberActivity;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.fp.dao.FpDao;
import org.smartregister.chw.hf.R;
import org.smartregister.chw.hf.fragment.FamilyProfileMemberFragment;
import org.smartregister.chw.hf.model.FamilyProfileModel;
import org.smartregister.chw.hf.presenter.FamilyProfilePresenter;
Expand All @@ -26,6 +29,9 @@
import java.util.HashMap;

public class FamilyProfileActivity extends CoreFamilyProfileActivity {
private TextView tvEventDate;
private TextView tvInterpunct;


@Override
public boolean onCreateOptionsMenu(Menu menu) {
Expand All @@ -48,6 +54,19 @@ protected void refreshList(Fragment fragment) {
}
}
}
@Override
protected void setupViews() {
super.setupViews();
tvEventDate = findViewById(R.id.textview_event_date);
tvInterpunct = findViewById(R.id.interpunct);
}

@Override
public void setEventDate(String eventDate) {
tvEventDate.setVisibility(View.VISIBLE);
tvInterpunct.setVisibility(View.VISIBLE);
tvEventDate.setText(String.format(this.getString(R.string.created), eventDate));
}

@Override
protected Class<? extends CoreFamilyRemoveMemberActivity> getFamilyRemoveMemberClass() {
Expand Down Expand Up @@ -159,9 +178,4 @@ private void setupMenuOptions(Menu menu) {
public FamilyProfilePresenter getFamilyProfilePresenter() {
return (FamilyProfilePresenter) presenter;
}

@Override
public void setEventDate(String s) {
// do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.smartregister.chw.core.application.CoreChwApplication;
import org.smartregister.chw.core.repository.CoreChwRepository;
import org.smartregister.chw.core.repository.StockUsageReportRepository;
import org.smartregister.chw.core.utils.ChwDBConstants;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.hf.BuildConfig;
import org.smartregister.chw.hf.dao.FamilyDao;
Expand Down Expand Up @@ -65,6 +66,10 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
upgradeToVersion8(db);
case 9:
upgradeToVersion9(db);
case 10:
upgradeToVersion10(db);
case 11:
upgradeToVersion11(db);
default:
break;
}
Expand Down Expand Up @@ -197,4 +202,32 @@ private void upgradeToVersion9(SQLiteDatabase db) {
Timber.e(ex, "Problems adding sync location ids");
}
}

private static void upgradeToVersion10(SQLiteDatabase db) {
try {
db.execSQL("ALTER TABLE ec_family ADD COLUMN event_date VARCHAR; ");
// add missing columns
} catch (Exception e) {
Timber.e(e, "upgradeToVersion10 ");
}

try {
db.execSQL("UPDATE ec_family SET event_date = (select min(eventDate) from event where event.baseEntityId = ec_family.base_entity_id and event.eventType = 'Family Registration') where event_date is null;");
} catch (Exception e) {
Timber.e(e, "upgradeToVersion10 ");
}

}

private static void upgradeToVersion11(SQLiteDatabase db) {
try {
List<String> columns = new ArrayList<>();
columns.add(DBConstants.KEY.VILLAGE_TOWN);
columns.add(ChwDBConstants.NEAREST_HEALTH_FACILITY);
DatabaseMigrationUtils.addFieldsToFTSTable(db, CoreChwApplication.createCommonFtsObject(), CoreConstants.TABLE_NAME.FAMILY, columns);

} catch (Exception e) {
Timber.e(e, "upgradeToVersion11 ");
}
}
}
Loading