-
Notifications
You must be signed in to change notification settings - Fork 41
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
base: add-reconfigurable-registers-and-profiles
Are you sure you want to change the base?
Changes from 22 commits
6235755
f64655c
a07e8c5
550b50b
bcd782c
3c654d3
ce930d8
4e3d6aa
78f3b3a
5139517
410457c
695252a
75ad239
b78bd0f
7a79e33
c85260d
14ed731
867e029
7930b1d
6bfe0d8
493dbe4
898c860
64394b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -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 |
---|---|---|
@@ -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 |
---|---|---|
|
@@ -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; | ||
|
@@ -140,6 +142,11 @@ protected LoginResponse doInBackground(Void... params) { | |
} | ||
|
||
} | ||
|
||
// Save the registered ANM | ||
getOpenSRPContext().allSharedPreferences().updateANMUserName(mUsername); | ||
|
||
fetchUserRole(); | ||
} else { | ||
if (response.getAccountError() != null && response.getAccountError().getError() != null) { | ||
return LoginResponse.valueOf(response.getAccountError().getError().toUpperCase(Locale.ENGLISH)); | ||
|
@@ -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())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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])); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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) { | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
||
} | ||
} | ||
|
There was a problem hiding this comment.
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