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

Sync practitioners of a role to device #769

Open
wants to merge 23 commits into
base: add-reconfigurable-registers-and-profiles
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6235755
Add user-practitioner-role in AllSharedPreferences
ekigamba Mar 1, 2021
f64655c
:arrow-up: Increment core library to 4.2.5.1-GS-PREVIEW-SNAPSHOT
ekigamba Mar 1, 2021
a07e8c5
Fetch user practitioner role during login
ekigamba Mar 2, 2021
550b50b
:arrow-up: Bump to 4.2.5.5-GS-PREVIEW-SNAPSHOT
ekigamba Mar 2, 2021
bcd782c
Remove Practioner, PractionerRole & PractitionerRoleCode models
ekigamba Mar 4, 2021
3c654d3
:arrow-up: Update plan-evaluator to version 1.4.0-SNAPSHOT
ekigamba Mar 4, 2021
ce930d8
Update TaskDao implementations
ekigamba Mar 10, 2021
4e3d6aa
Merge branch 'add-reconfigurable-registers-and-profiles' of github.co…
allan-on Mar 12, 2021
78f3b3a
:construction: Handle URI Exception
allan-on Mar 12, 2021
5139517
Merge branch 'add-practitioner-role-in-preference' into sync-practiti…
allan-on Mar 20, 2021
410457c
:construction: Add Pratitioner repository
allan-on Mar 21, 2021
695252a
:construction: Add Pratitioner sync helper + service
allan-on Mar 21, 2021
75ad239
:construction: Add Sync Pratitioner by ID & Role Job
allan-on Mar 21, 2021
b78bd0f
:construction: Add toolbar color & options hiding functionality
allan-on Mar 21, 2021
7a79e33
:construction: Refactor navigation & add bottom nav configs
allan-on Mar 21, 2021
c85260d
:recycle: Refactor toolbar & bottom nav Module configs
allan-on Mar 21, 2021
14ed731
:construction: Add set fragment toolbar options
allan-on Mar 21, 2021
867e029
:construction: Change practitioner ID column to IDENTIFIER
allan-on Mar 21, 2021
7930b1d
:construction: Show bottom nav icons + title
allan-on Mar 22, 2021
6bfe0d8
:construction: Add practitioner identifier to shared pref
allan-on Mar 23, 2021
493dbe4
:bug: Fix get and set practitioner identifier
allan-on Mar 23, 2021
898c860
:bug: Fix Sync CHW Practitioners
allan-on Mar 23, 2021
64394b8
:construction: Add practitionerIdentifier constant
allan-on Mar 23, 2021
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.2.13-gs.1-SNAPSHOT
VERSION_NAME=4.2.13-gs.2-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Core Application
Expand Down
8 changes: 4 additions & 4 deletions opensrp-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ android {
//applicationId "org.smartregister"
minSdkVersion androidMinSdkVersion
targetSdkVersion androidTargetSdkVersion
versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME
/*versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME*/
testInstrumentationRunner "android.test.InstrumentationTestRunner"
buildConfigField "long", "BUILD_TIMESTAMP", System.currentTimeMillis() + "L"
buildConfigField "int", "DB_ENCRYPTION_VERSION", '1'
Expand Down Expand Up @@ -230,7 +230,7 @@ dependencies {
transitive = true
}

implementation 'org.smartregister:opensrp-plan-evaluator:1.3.1-SNAPSHOT'
implementation 'org.smartregister:opensrp-plan-evaluator:1.4.0-SNAPSHOT'

implementation 'xerces:xercesImpl:2.12.0'

Expand Down Expand Up @@ -312,4 +312,4 @@ coveralls {
sourceDirs = ["$project.projectDir/src/main/java"]
}

apply from: '../maven.gradle'
//apply from: '../maven.gradle'
9 changes: 9 additions & 0 deletions opensrp-app/src/main/java/org/smartregister/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.smartregister.repository.ManifestRepository;
import org.smartregister.repository.MotherRepository;
import org.smartregister.repository.PlanDefinitionRepository;
import org.smartregister.repository.PractitionerRepository;
import org.smartregister.repository.ReportRepository;
import org.smartregister.repository.ServiceProvidedRepository;
import org.smartregister.repository.SettingsRepository;
Expand Down Expand Up @@ -227,6 +228,7 @@ public class Context {
private AppProperties appProperties;
private LocationTagRepository locationTagRepository;
private ManifestRepository manifestRepository;
private PractitionerRepository practitionerRepository;
private ClientFormRepository clientFormRepository;
private ClientRelationshipRepository clientRelationshipRepository;

Expand Down Expand Up @@ -1245,6 +1247,13 @@ public ClientFormRepository getClientFormRepository() {
return clientFormRepository;
}

public PractitionerRepository getPractitionerRepository() {
if (practitionerRepository == null) {
practitionerRepository = new PractitionerRepository();
}
return practitionerRepository;
}

public ClientRelationshipRepository getClientRelationshipRepository() {
if (clientRelationshipRepository == null) {
clientRelationshipRepository = new ClientRelationshipRepository();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.smartregister.configuration;

public interface BottomNavigationOptions {

public int getBottomNavigationLayoutId();

public BottomNavigationOptionsModel getBottomNavigationOptionsModel();

public int checkedItemId();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.smartregister.configuration;

import android.app.Activity;
import android.view.MenuItem;

import androidx.annotation.NonNull;

public interface BottomNavigationOptionsModel {

void onBottomOptionSelection(Activity activity, @NonNull MenuItem menuItem);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.smartregister.configuration;

public interface ConfigurableNavigationOptions {

public ToolbarOptions getToolbarOptions();

public BottomNavigationOptions getBottomNavigationOptions();

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public String getRegisterTitle() {
return builder.registerTitle;
}

public Class<? extends ToolbarOptions> getToolbarOptions() {
return builder.toolbarOptions;
public Class<? extends ConfigurableNavigationOptions> getNavigationOptions() {
return builder.navigationOptions;
}

public int getMaxCheckInDurationInMinutes() {
Expand Down Expand Up @@ -127,7 +127,7 @@ public static class Builder {
@NonNull
private Class<? extends ClientFormContract.View> jsonFormActivity;

private Class<? extends ToolbarOptions> toolbarOptions;
private Class<? extends ConfigurableNavigationOptions> navigationOptions;

private boolean isBottomNavigationEnabled;

Expand Down Expand Up @@ -163,8 +163,8 @@ public Builder setModuleMetadata(@NonNull ModuleMetadata moduleMetadata) {
return this;
}

public Builder setToolbarOptions(@Nullable Class<? extends ToolbarOptions> toolbarOptions) {
this.toolbarOptions = toolbarOptions;
public Builder setNavigationOptions(@Nullable Class<? extends ConfigurableNavigationOptions> navigationOptions) {
this.navigationOptions = navigationOptions;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@

import org.smartregister.view.dialog.DialogOptionModel;

import java.util.ArrayList;
import java.util.List;

public interface ToolbarOptions {

public int getLogoResourceId();

default int getToolBarColor() {
return 0;
}

public int getFabTextStringResource();

public boolean isFabEnabled();

public boolean isNewToolbarEnabled();

default List<Integer> getHiddenToolOptions() {
return new ArrayList<>();
}

public DialogOptionModel getDialogOptionModel();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.smartregister.job;

import android.content.Intent;

import androidx.annotation.NonNull;

import org.smartregister.AllConstants;
import org.smartregister.sync.intent.SyncChwPractitionersByIdAndRoleIntentService;

public class SyncPractitionersByIdAndRoleJob extends BaseJob {

public static final String TAG = "SyncPractitionersByIdAndRoleJob";

@NonNull
@Override
protected Result onRunJob(@NonNull Params params) {
Intent intent = new Intent(getApplicationContext(), SyncChwPractitionersByIdAndRoleIntentService.class);
getApplicationContext().startService(intent);
return params != null && params.getExtras().getBoolean(AllConstants.INTENT_KEY.TO_RESCHEDULE, false) ? Result.RESCHEDULE : Result.SUCCESS;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.smartregister.listener;

import android.app.Activity;
import android.view.MenuItem;

import androidx.annotation.NonNull;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import android.view.MenuItem;

import org.smartregister.R;
import org.smartregister.view.activity.BaseRegisterActivity;

public class BottomNavigationListener implements BottomNavigationView.OnNavigationItemSelectedListener {
private Activity context;
protected Activity context;

public BottomNavigationListener(Activity context) {
this.context = context;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.smartregister.listener;

import android.app.Activity;
import android.view.MenuItem;

import androidx.annotation.NonNull;

import org.smartregister.configuration.BottomNavigationOptionsModel;

public class ConfigurableBottomNavigationListener extends BottomNavigationListener {

private BottomNavigationOptionsModel bottomNavigationOptionsModel;

public ConfigurableBottomNavigationListener(Activity context, BottomNavigationOptionsModel model) {
super(context);
this.bottomNavigationOptionsModel = model;
}

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
bottomNavigationOptionsModel.onBottomOptionSelection(context, menuItem);
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.smartregister.account.AccountHelper;
import org.smartregister.account.AccountResponse;
import org.smartregister.domain.LoginResponse;
import org.smartregister.domain.Practitioner;
import org.smartregister.domain.PractitionerRole;
import org.smartregister.domain.jsonmapping.User;
import org.smartregister.event.Listener;
import org.smartregister.sync.helper.SyncSettingsServiceHelper;
Expand Down Expand Up @@ -140,6 +142,11 @@ protected LoginResponse doInBackground(Void... params) {
}

}

// Save the registered ANM
getOpenSRPContext().allSharedPreferences().updateANMUserName(mUsername);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this call required here (maybe it is)?

It is also invoked at a later time once the authentication is successful, afterLoginCheck listener fires and this line is executed


fetchUserRole();
} else {
if (response.getAccountError() != null && response.getAccountError().getError() != null) {
return LoginResponse.valueOf(response.getAccountError().getError().toUpperCase(Locale.ENGLISH));
Expand All @@ -162,6 +169,37 @@ protected LoginResponse doInBackground(Void... params) {
return loginResponse;
}

protected void fetchUserRole() {
Practitioner[] practitioners = getOpenSRPContext().httpAgent().fetchPractitioners();
PractitionerRole[] practitionerRoles = getOpenSRPContext().httpAgent().fetchPractitionerRoles();

if (practitioners == null) {
return;
}

Practitioner loggedInPractitioner = null;
for (Practitioner practitioner : practitioners) {
if (practitioner != null && mUsername.equals(practitioner.getUsername())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this condition is satisfied, is it OK to break out of the loop for efficiency ?

loggedInPractitioner = practitioner;
}
}

if (loggedInPractitioner != null && practitionerRoles != null) {

PractitionerRole loggedInPractitionerRole = null;
for (PractitionerRole practitionerRole : practitionerRoles) {
if (loggedInPractitioner.getIdentifier().equals(practitionerRole.getPractitionerIdentifier())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this condition is satisfied, is it OK to break out of the loop for efficiency ?

loggedInPractitionerRole = practitionerRole;
}
}

if (loggedInPractitionerRole != null) {
getOpenSRPContext().allSharedPreferences().setUserPractitionerRole(loggedInPractitionerRole.getCode().getText());
getOpenSRPContext().allSharedPreferences().setUserPractitionerIdentifier(loggedInPractitionerRole.getPractitionerIdentifier());
}
}
}

@Override
protected void onProgressUpdate(Integer... messageIdentifier) {
mLoginView.updateProgressMessage(getOpenSRPContext().applicationContext().getString(messageIdentifier[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import android.content.SharedPreferences;

import androidx.annotation.Nullable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.apache.commons.lang3.StringUtils;
import org.smartregister.AllConstants;
Expand Down Expand Up @@ -33,6 +33,8 @@ public class AllSharedPreferences {
public static final String FORMS_VERSION = "FORMS_VERSION";
private static final String ENCRYPTED_PASSPHRASE_KEY = "ENCRYPTED_PASSPHRASE_KEY";
private static final String DB_ENCRYPTION_VERSION = "DB_ENCRYPTION_VERSION";
private static final String USER_PRACTITIONER_ROLE = "USER_PRACTITIONER_ROLE";
private static final String USER_PRACTITIONER_IDENTIFIER = "USER_PRACTITIONER_IDENTIFIER";
private SharedPreferences preferences;

public AllSharedPreferences(SharedPreferences preferences) {
Expand Down Expand Up @@ -385,5 +387,24 @@ public int getDBEncryptionVersion() {
public void setDBEncryptionVersion(int encryptionVersion) {
preferences.edit().putInt(DB_ENCRYPTION_VERSION, encryptionVersion).commit();
}

@Nullable
public String getUserPractitionerRole() {
return preferences.getString(USER_PRACTITIONER_ROLE, null);
}

@Nullable
public String getUserPractitionerIdentifier() {
return preferences.getString(USER_PRACTITIONER_IDENTIFIER, null);
}

public void setUserPractitionerRole(String practitionerRole) {
preferences.edit().putString(USER_PRACTITIONER_ROLE, practitionerRole).commit();
}

public void setUserPractitionerIdentifier(String identifier) {
preferences.edit().putString(USER_PRACTITIONER_IDENTIFIER, identifier).commit();
Comment on lines +392 to +406
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenSRP supports multi tenancy on the same device where two user accounts can be active without requiring a data clearing or a fresh installation. Should then the preference keys here have the +username suffix like other user-dependent preference keys?


}
}

Loading