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

Implement sync task with events #49

Merged
merged 23 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
73bd02e
Update server url
ellykits Jan 24, 2020
8fd5043
Update version code to 5
ellykits Jan 24, 2020
f7f4122
Updated syncConfiguration to enable sync by teamId
cozej4 Feb 6, 2020
43d6f83
Updated dependencies and associated code refactore
cozej4 Feb 12, 2020
8a38950
Merge branch 'master' into unified-hf
ellykits Feb 17, 2020
c2e8dc3
code refactoring
cozej4 Feb 18, 2020
97020ac
Merged changes from master
cozej4 Feb 18, 2020
d0f05ee
Code refactoring
cozej4 Feb 18, 2020
5f0af49
Merge branch 'unified-hf' of github.com:OpenSRP/opensrp-client-chw-hf…
ellykits Feb 20, 2020
9d7e59d
Sync missing clients and events after syncing tasks
ellykits Feb 26, 2020
cd021ed
Implement sync task with event and clients
ellykits Feb 28, 2020
940d965
Fix app crash when loading child profile
ellykits Feb 28, 2020
d897a44
Merge branch 'unified-hf' into implement-sync-task-with-events
ellykits Mar 2, 2020
41cc046
Update client-core and chw-core versions
ellykits Mar 3, 2020
00859a7
Update chw-core to version 1.1.49
ellykits Mar 6, 2020
7893633
Update chw-core version to 1.1.50
ellykits Mar 6, 2020
218db37
Updated save of closeReferral Event to save the event with locationId…
cozej4 Mar 10, 2020
200dccc
Code refactoring
cozej4 Mar 10, 2020
480a29f
Merge changes from remote branch
ellykits Mar 11, 2020
1a5418d
Updated opensrp debug url
cozej4 Mar 18, 2020
a92c185
fixed debug url
cozej4 Mar 18, 2020
6958e83
fixed debug url
cozej4 Mar 18, 2020
7684f2f
Update FACILITY_LEVEL build config to use list
ellykits Mar 19, 2020
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
19 changes: 11 additions & 8 deletions opensrp-chw-hf/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ android {
applicationId "org.smartregister.chw.hf"
minSdkVersion 18
targetSdkVersion 28
versionCode 4
versionName "1.2.6"
versionCode 5
versionName "1.2.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
buildConfigField "String", 'opensrp_url', '"https://boresha-afya.smartregister.org/opensrp/"'
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", '5'
buildConfigField "int", "DATA_SYNC_DURATION_MINUTES", '15'
Expand Down Expand Up @@ -65,7 +66,8 @@ android {
buildConfigField "boolean", 'SUPPORT_REPORT', 'false'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"Ward" , "Health Facility", "Village", "Village Sublocations"}'
buildConfigField "String[]", "LOCATION_HIERACHY", '{"Country","Region","District","Ward" , "Health Facility", "Village", "Village Sublocations"}'
buildConfigField "String", 'DEFAULT_LOCATION', '"Health Facility"'
buildConfigField "String", 'DEFAULT_LOCATION', '"Facility"'
buildConfigField "String[]", 'FACILITY_LEVEL', '{"Facility"}'
}

debug {
Expand All @@ -80,9 +82,10 @@ android {
buildConfigField "int", "REPORT_INDICATOR_GENERATION_MINUTES", '15'
buildConfigField "int", "HOME_VISIT_MINUTES", '60'
buildConfigField "boolean", 'SUPPORT_REPORT', 'false'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"MOH Jhpiego Facility Name" , "Village"}'
buildConfigField "String[]", "LOCATION_HIERACHY", '{"Country","Region","District","Ward" , "Health Facility", "Village", "Village Sublocations"}'
buildConfigField "String", 'DEFAULT_LOCATION', '"Village"'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"Ward" , "Council", "Facility", "Health Facility", "Village", "Village Sublocations"}'
buildConfigField "String[]", "LOCATION_HIERACHY", '{"Country","Region","District","Ward" ,"Council", "Facility", "Health Facility", "Village", "Village Sublocations"}'
buildConfigField "String", 'DEFAULT_LOCATION', '"Facility"'
buildConfigField "String[]", 'FACILITY_LEVEL', '{"Facility", "MOH Jhpiego Facility Name"}'
testCoverageEnabled true
}
}
Expand Down Expand Up @@ -115,7 +118,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation ('org.smartregister:opensrp-client-chw-core:1.1.40-SNAPSHOT@aar') {
implementation ('org.smartregister:opensrp-client-chw-core:1.1.50-SNAPSHOT@aar') {
transitive = true
exclude group: 'org.smartregister', module: 'opensrp-client-native-form'
exclude group: 'org.smartregister', module: 'opensrp-client-chw-referral'
Expand All @@ -129,7 +132,7 @@ dependencies {
exclude group: 'com.google.guava', module: 'guava'
}

implementation ('org.smartregister:opensrp-client-native-form:1.7.17-SNAPSHOT@aar') {
implementation ('org.smartregister:opensrp-client-native-form:1.7.23-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.android.support', module: 'recyclerview-v7'
exclude group: 'com.android.support', module: 'appcompat-v7'
Expand Down
1 change: 1 addition & 0 deletions opensrp-chw-hf/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
<service android:name="org.smartregister.sync.intent.LocationIntentService" />
<service android:name="org.smartregister.chw.hf.sync.intent.HfSyncTaskIntentService" />
<service android:name="org.smartregister.sync.intent.PlanIntentService" />
<service android:name="org.smartregister.chw.core.sync.intent.SyncClientEventsPerTaskIntentService" />

<uses-library
android:name="org.apache.http.legacy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.smartregister.family.util.Utils;

import java.util.Date;
import java.util.Map;
import java.util.Set;

import timber.log.Timber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private void saveCloseReferralEvent() {
.withFormSubmissionId(JsonFormUtils.generateRandomUUIDString())
.withEntityType(CoreConstants.TABLE_NAME.CLOSE_REFERRAL)
.withProviderId(sharedPreferences.fetchRegisteredANM())
.withLocationId(sharedPreferences.fetchDefaultLocalityId(sharedPreferences.fetchRegisteredANM()))
.withLocationId(getTask().getLocation())
.withTeamId(sharedPreferences.fetchDefaultTeamId(sharedPreferences.fetchRegisteredANM()))
.withTeam(sharedPreferences.fetchDefaultTeam(sharedPreferences.fetchRegisteredANM()))
.withClientDatabaseVersion(BuildConfig.DATABASE_VERSION)
Expand All @@ -404,6 +404,9 @@ private void saveCloseReferralEvent() {

org.smartregister.chw.hf.utils.JsonFormUtils.tagSyncMetadata(Utils.context().allSharedPreferences(), baseEvent);// tag docs

//setting the location uuid of the referral initiator so that to allow the event to sync back to the chw app since it sync data by location.
baseEvent.setLocationId(getTask().getLocation());

JSONObject eventJson = new JSONObject(JsonFormUtils.gson.toJson(baseEvent));
syncHelper.addEvent(getBaseEntityId(), eventJson);
long lastSyncTimeStamp = HealthFacilityApplication.getInstance().getContext().allSharedPreferences().fetchLastUpdatedAtDate(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ protected void scheduleJobsPeriodically() {
HomeVisitServiceJob.scheduleJob(HomeVisitServiceJob.TAG, TimeUnit.MINUTES.toMinutes(
BuildConfig.HOME_VISIT_MINUTES), getFlexValue(BuildConfig.HOME_VISIT_MINUTES));

/*PlanIntentServiceJob.scheduleJob(PlanIntentServiceJob.TAG, TimeUnit.MINUTES.toMinutes(
BuildConfig.DATA_SYNC_DURATION_MINUTES), getFlexValue(BuildConfig.DATA_SYNC_DURATION_MINUTES));*/

SyncTaskServiceJob.scheduleJob(SyncTaskServiceJob.TAG, TimeUnit.MINUTES.toMinutes(
BuildConfig.DATA_SYNC_DURATION_MINUTES), getFlexValue(BuildConfig.DATA_SYNC_DURATION_MINUTES));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.evernote.android.job.Job;
import com.evernote.android.job.JobCreator;

import org.smartregister.chw.core.job.SyncTaskWithClientEventsServiceJob;
import org.smartregister.chw.core.job.VaccineRecurringServiceJob;
import org.smartregister.chw.core.sync.intent.SyncClientEventsPerTaskIntentService;
import org.smartregister.chw.hf.sync.intent.HfSyncTaskIntentService;
import org.smartregister.job.ExtendedSyncServiceJob;
import org.smartregister.job.ImageUploadServiceJob;
Expand Down Expand Up @@ -46,6 +48,8 @@ public Job create(@NonNull String tag) {
return new SyncTaskServiceJob(HfSyncTaskIntentService.class);
case PlanIntentServiceJob.TAG:
return new PlanIntentServiceJob();
case SyncTaskWithClientEventsServiceJob.TAG:
return new SyncTaskWithClientEventsServiceJob(SyncClientEventsPerTaskIntentService.class);
default:
Timber.d("Please create job and specify the right job tag");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import net.sqlcipher.Cursor;

import org.smartregister.chw.core.repository.ChwTaskRepository;
import org.smartregister.chw.core.utils.ChwDBConstants;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.domain.Task;
import org.smartregister.repository.Repository;
import org.smartregister.repository.TaskNotesRepository;
import org.smartregister.repository.TaskRepository;

import timber.log.Timber;

public class HfTaskRepository extends TaskRepository {
public class HfTaskRepository extends ChwTaskRepository {

public HfTaskRepository(TaskNotesRepository taskNotesRepository) {
super(taskNotesRepository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

import org.smartregister.SyncConfiguration;
import org.smartregister.SyncFilter;
import org.smartregister.chw.core.utils.Utils;
import org.smartregister.chw.hf.BuildConfig;

import java.util.Collections;
import java.util.List;

/**
* @author Elly Nerdstone
*/
Expand All @@ -17,12 +19,13 @@ public int getSyncMaxRetries() {

@Override
public SyncFilter getSyncFilterParam() {
return SyncFilter.LOCATION;
return SyncFilter.TEAM_ID;
}

@Override
public String getSyncFilterValue() {
return Utils.getSyncFilterValue();
String providerId = org.smartregister.Context.getInstance().allSharedPreferences().fetchRegisteredANM();
return org.smartregister.Context.getInstance().allSharedPreferences().fetchDefaultTeamId(providerId);
}

@Override
Expand Down Expand Up @@ -54,4 +57,14 @@ public SyncFilter getEncryptionParam() {
public boolean updateClientDetailsTable() {
return false;
}

@Override
public List<String> getSynchronizedLocationTags() {
return Collections.emptyList();
}

@Override
public String getTopAllowedLocationLevel() {
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import org.smartregister.CoreLibrary;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.hf.HealthFacilityApplication;
import org.smartregister.chw.hf.BuildConfig;
import org.smartregister.location.helper.LocationHelper;
import org.smartregister.repository.TaskRepository;
import org.smartregister.sync.helper.TaskServiceHelper;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;

public class HfTaskServiceHelper extends TaskServiceHelper {

protected static HfTaskServiceHelper instance;

public HfTaskServiceHelper(TaskRepository taskRepository) {
Expand All @@ -29,12 +31,12 @@ public static HfTaskServiceHelper getInstance() {
@Override
protected List<String> getLocationIds() {
LocationHelper locationHelper = LocationHelper.getInstance();
ArrayList<String> allowedLevels = HealthFacilityApplication.getInstance().getAllowedLocationLevels();
ArrayList<String> allowedLevels = new ArrayList<>(Arrays.asList(BuildConfig.FACILITY_LEVEL));
List<String> locations = new ArrayList<>();
if (allowedLevels != null) {
List<String> locationIds = locationHelper.generateDefaultLocationHierarchy(allowedLevels);
if (locationIds != null) {
locations.add(locationHelper.getOpenMrsLocationId(locationIds.get(0)));
List<String> locationIds = locationHelper.generateDefaultLocationHierarchy(allowedLevels);
if (locationIds != null) {
for (String locationName : locationIds) {
locations.add(locationHelper.getOpenMrsLocationId(locationName));
}
}
return locations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Intent;

import org.smartregister.chw.core.job.SyncTaskWithClientEventsServiceJob;
import org.smartregister.chw.hf.sync.helper.HfTaskServiceHelper;
import org.smartregister.sync.intent.SyncTaskIntentService;

Expand All @@ -10,5 +11,6 @@ public class HfSyncTaskIntentService extends SyncTaskIntentService {
protected void onHandleIntent(Intent intent) {
HfTaskServiceHelper taskServiceHelper = HfTaskServiceHelper.getInstance();
taskServiceHelper.syncTasks();
SyncTaskWithClientEventsServiceJob.scheduleJobImmediately(SyncTaskWithClientEventsServiceJob.TAG);
}
}
65 changes: 61 additions & 4 deletions opensrp-chw-hf/src/main/res/layout/content_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_arrow_forward_ios" />
android:src="@drawable/row_goto" />

<org.smartregister.view.customcontrols.CustomFontTextView
android:id="@+id/textview_last_vist_day"
Expand Down Expand Up @@ -109,7 +109,7 @@
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_arrow_forward_ios" />
android:src="@drawable/row_goto" />

<org.smartregister.view.customcontrols.CustomFontTextView
android:id="@+id/textview_name_due"
Expand Down Expand Up @@ -147,14 +147,71 @@
android:visibility="gone" />

<RelativeLayout
android:id="@+id/family_has_row"
android:id="@+id/sick_visit_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/view_most_due_overdue_row"
android:background="@drawable/list_item_background_selctor"
android:padding="20dp"
android:visibility="gone">

<ImageView
android:id="@+id/sick_visit_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="@drawable/rowicon_sickchild" />

<ImageView
android:id="@+id/sick_visit_arrow_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/row_goto" />

<org.smartregister.view.customcontrols.CustomFontTextView
android:id="@+id/textview_sick_visit_has"
style="@style/CustomFontTextViewStyle.ListView.Normal.MultipleLines"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/sick_visit_image"
android:gravity="center_horizontal"
android:text="@string/sick_visit_on"
android:textColor="@android:color/black" />

<org.smartregister.view.customcontrols.CustomFontTextView
android:id="@+id/text_view_sick_visit_profile"
style="@style/CustomFontTextViewStyle.ListView.Normal.MultipleLines"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textview_sick_visit_has"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/sick_visit_image"
android:text="@string/view_sick_visits"
android:textColor="@android:color/darker_gray" />

</RelativeLayout>

<View
android:id="@+id/view_sick_visit_row"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_below="@+id/sick_visit_row"
android:background="@color/light_grey"
android:visibility="gone" />

<RelativeLayout
android:id="@+id/family_has_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/view_sick_visit_row"
android:background="@drawable/list_item_background_selctor"
android:padding="20dp"
android:visibility="gone">

<ImageView
android:id="@+id/family_image"
android:layout_width="wrap_content"
Expand All @@ -169,7 +226,7 @@
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_arrow_forward_ios" />
android:src="@drawable/row_goto" />

<org.smartregister.view.customcontrols.CustomFontTextView
android:id="@+id/textview_family_has"
Expand Down