From 6235755a345c600b0548af534583f1a7a616e077 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Mon, 1 Mar 2021 16:10:13 +0300 Subject: [PATCH 01/21] Add user-practitioner-role in AllSharedPreferences --- .../smartregister/repository/AllSharedPreferences.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java b/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java index 2b083f3bb..dc8371f3f 100644 --- a/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java @@ -33,6 +33,7 @@ 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 SharedPreferences preferences; public AllSharedPreferences(SharedPreferences preferences) { @@ -385,5 +386,14 @@ 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); + } + + public void setUserPractitionerRole(String practitionerRole) { + preferences.edit().putString(USER_PRACTITIONER_ROLE, practitionerRole).commit(); + } } From f64655c20568136f254e808ef7636716d4aabc4a Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Mon, 1 Mar 2021 17:13:57 +0300 Subject: [PATCH 02/21] :arrow-up: Increment core library to 4.2.5.1-GS-PREVIEW-SNAPSHOT --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 08faacff1..ad8e4af73 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=4.2.4-SNAPSHOT +VERSION_NAME=4.2.5.1-GS-PREVIEW-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Core Application From a07e8c56a71ef066ff4d83c6cb6f7be89bf49be7 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Tue, 2 Mar 2021 09:04:12 +0300 Subject: [PATCH 03/21] Fetch user practitioner role during login - Add PractitionerRole and Practitioner models - Fetch practitioners and practitioner roles to map the current user practitioner-role - Save the current user practitioner-role-code in preferences Fixes tasks in https://github.com/OpenSRP/opensrp-client-goldsmith/issues/80 --- .../smartregister/domain/Practitioner.java | 63 +++++++++++++ .../domain/PractitionerRole.java | 70 +++++++++++++++ .../domain/PractitionerRoleCode.java | 21 +++++ .../login/task/RemoteLoginTask.java | 37 ++++++++ .../org/smartregister/service/HTTPAgent.java | 89 +++++++++++++++++++ 5 files changed, 280 insertions(+) create mode 100644 opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java create mode 100644 opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java create mode 100644 opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java diff --git a/opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java b/opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java new file mode 100644 index 000000000..847cffdea --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java @@ -0,0 +1,63 @@ +package org.smartregister.domain; + + +import java.io.Serializable; + +/** + * Created by Ephraim Kigamba - nek.eam@gmail.com on 01-03-2021. + */ +public class Practitioner implements Serializable { + + private static final long serialVersionUID = -8367551045898354954L; + + private String identifier; + + private Boolean active; + + private String name; + + private String userId; + + private String username; + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public Boolean getActive() { + return active; + } + + public void setActive(Boolean active) { + this.active = active; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + +} \ No newline at end of file diff --git a/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java b/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java new file mode 100644 index 000000000..b2415875c --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java @@ -0,0 +1,70 @@ +package org.smartregister.domain; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.gson.annotations.SerializedName; + +/** + * Created by Ephraim Kigamba - nek.eam@gmail.com on 01-03-2021. + */ +public class PractitionerRole implements Serializable { + + private static final long serialVersionUID = -2472589757270251270L; + @JsonProperty + private String identifier; + + @JsonProperty + private Boolean active; + + @JsonProperty + @SerializedName("organization") + private String organizationIdentifier; + + @JsonProperty + @SerializedName("practitioner") + private String practitionerIdentifier; + + @JsonProperty + private PractitionerRoleCode code; + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public Boolean getActive() { + return active; + } + + public void setActive(Boolean active) { + this.active = active; + } + + public String getOrganizationIdentifier() { + return organizationIdentifier; + } + + public void setOrganizationIdentifier(String organizationIdentifier) { + this.organizationIdentifier = organizationIdentifier; + } + + public String getPractitionerIdentifier() { + return practitionerIdentifier; + } + + public void setPractitionerIdentifier(String practitionerIdentifier) { + this.practitionerIdentifier = practitionerIdentifier; + } + + public PractitionerRoleCode getCode() { + return code; + } + + public void setCode(PractitionerRoleCode code) { + this.code = code; + } +} \ No newline at end of file diff --git a/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java b/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java new file mode 100644 index 000000000..5f40b33b8 --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java @@ -0,0 +1,21 @@ +package org.smartregister.domain; + +import java.io.Serializable; + +/** + * Created by Ephraim Kigamba - nek.eam@gmail.com on 01-03-2021. + */ + +public class PractitionerRoleCode implements Serializable { + + private static final long serialVersionUID = 5814439241291810987L; + private String text; + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } +} \ No newline at end of file diff --git a/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java b/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java index df45bee1b..5c258294e 100644 --- a/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java +++ b/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java @@ -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,36 @@ 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())) { + loggedInPractitioner = practitioner; + } + } + + if (loggedInPractitioner != null && practitionerRoles != null) { + + PractitionerRole loggedInPractitionerRole = null; + for (PractitionerRole practitionerRole: practitionerRoles) { + if (loggedInPractitioner.getIdentifier().equals(practitionerRole.getPractitionerIdentifier())) { + loggedInPractitionerRole = practitionerRole; + } + } + + if (loggedInPractitionerRole != null) { + getOpenSRPContext().allSharedPreferences().setUserPractitionerRole(loggedInPractitionerRole.getCode().getText()); + } + } + } + @Override protected void onProgressUpdate(Integer... messageIdentifier) { mLoginView.updateProgressMessage(getOpenSRPContext().applicationContext().getString(messageIdentifier[0])); diff --git a/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java b/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java index fc16d37da..b3740fdfb 100644 --- a/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java +++ b/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java @@ -27,6 +27,8 @@ import org.smartregister.compression.GZIPCompression; import org.smartregister.domain.DownloadStatus; import org.smartregister.domain.LoginResponse; +import org.smartregister.domain.Practitioner; +import org.smartregister.domain.PractitionerRole; import org.smartregister.domain.ProfileImage; import org.smartregister.domain.Response; import org.smartregister.domain.ResponseErrorStatus; @@ -36,6 +38,7 @@ import org.smartregister.security.SecurityHelper; import org.smartregister.ssl.OpensrpSSLHelper; import org.smartregister.util.Utils; +import org.smartregister.view.contract.IView; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -59,7 +62,9 @@ import java.net.URL; import java.net.URLConnection; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import javax.net.ssl.HttpsURLConnection; @@ -105,6 +110,8 @@ public class HTTPAgent { private Gson gson; private static final String DETAILS_URL = "/user-details?anm-id="; + private static final String PRACTITIONER_ROLE_URL = "/rest/practitionerRole"; + private static final String PRACTITIONER_URL = "/rest/practitioner"; public HTTPAgent(Context context, AllSharedPreferences @@ -1017,6 +1024,88 @@ public AccountConfiguration fetchOAuthConfiguration() { return null; } + private void initializeAdapter(Set iviews) { + Set mySet = new HashSet<>(); + + initializeAdapter(mySet); + } + + public Practitioner[] fetchPractitioners() { + + String baseUrl = configuration.dristhiBaseURL(); + + if (baseUrl.endsWith("/")) { + baseUrl = baseUrl.substring(0, baseUrl.length() - 1); + } + + baseUrl = baseUrl + PRACTITIONER_URL; + + HttpURLConnection urlConnection = null; + + InputStream inputStream = null; + try { + + urlConnection = initializeHttp(baseUrl, true); + + int statusCode = urlConnection.getResponseCode(); + if (statusCode == HttpStatus.SC_OK) { + + inputStream = urlConnection.getInputStream(); + + String responseString = IOUtils.toString(inputStream); + + return gson.fromJson(responseString, Practitioner[].class); + } + + } catch (IOException e) { + Timber.e(e); + } finally { + + closeConnection(urlConnection); + closeIOStream(inputStream); + + } + return null; + } + + public PractitionerRole[] fetchPractitionerRoles() { + + String baseUrl = configuration.dristhiBaseURL(); + + if (baseUrl.endsWith("/")) { + baseUrl = baseUrl.substring(0, baseUrl.length() - 1); + } + + baseUrl = baseUrl + PRACTITIONER_ROLE_URL; + + HttpURLConnection urlConnection = null; + + InputStream inputStream = null; + try { + + urlConnection = initializeHttp(baseUrl, true); + + int statusCode = urlConnection.getResponseCode(); + if (statusCode == HttpStatus.SC_OK) { + + inputStream = urlConnection.getInputStream(); + + String responseString = IOUtils.toString(inputStream); + + return gson.fromJson(responseString, PractitionerRole[].class); + } + + } catch (IOException e) { + Timber.e(e); + } finally { + + closeConnection(urlConnection); + closeIOStream(inputStream); + + } + return null; + } + private void closeConnection(HttpURLConnection urlConnection) { if (urlConnection != null) { try { From 550b50b362881cfb58a99d8f7f6e8f18ecb01c6b Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Tue, 2 Mar 2021 10:20:50 +0300 Subject: [PATCH 04/21] :arrow-up: Bump to 4.2.5.5-GS-PREVIEW-SNAPSHOT --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ad8e4af73..eeea62449 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=4.2.5.1-GS-PREVIEW-SNAPSHOT +VERSION_NAME=4.2.5.5-GS-PREVIEW-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Core Application From bcd782cb6fb32e4d710b0db2ffb7de7eaa62d16f Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Thu, 4 Mar 2021 18:58:58 +0300 Subject: [PATCH 05/21] Remove Practioner, PractionerRole & PractitionerRoleCode models --- .../smartregister/domain/Practitioner.java | 63 ----------------- .../domain/PractitionerRole.java | 70 ------------------- .../domain/PractitionerRoleCode.java | 21 ------ 3 files changed, 154 deletions(-) delete mode 100644 opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java delete mode 100644 opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java delete mode 100644 opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java diff --git a/opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java b/opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java deleted file mode 100644 index 847cffdea..000000000 --- a/opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.smartregister.domain; - - -import java.io.Serializable; - -/** - * Created by Ephraim Kigamba - nek.eam@gmail.com on 01-03-2021. - */ -public class Practitioner implements Serializable { - - private static final long serialVersionUID = -8367551045898354954L; - - private String identifier; - - private Boolean active; - - private String name; - - private String userId; - - private String username; - - public String getIdentifier() { - return identifier; - } - - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - public Boolean getActive() { - return active; - } - - public void setActive(Boolean active) { - this.active = active; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - -} \ No newline at end of file diff --git a/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java b/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java deleted file mode 100644 index b2415875c..000000000 --- a/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.smartregister.domain; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.gson.annotations.SerializedName; - -/** - * Created by Ephraim Kigamba - nek.eam@gmail.com on 01-03-2021. - */ -public class PractitionerRole implements Serializable { - - private static final long serialVersionUID = -2472589757270251270L; - @JsonProperty - private String identifier; - - @JsonProperty - private Boolean active; - - @JsonProperty - @SerializedName("organization") - private String organizationIdentifier; - - @JsonProperty - @SerializedName("practitioner") - private String practitionerIdentifier; - - @JsonProperty - private PractitionerRoleCode code; - - public String getIdentifier() { - return identifier; - } - - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - public Boolean getActive() { - return active; - } - - public void setActive(Boolean active) { - this.active = active; - } - - public String getOrganizationIdentifier() { - return organizationIdentifier; - } - - public void setOrganizationIdentifier(String organizationIdentifier) { - this.organizationIdentifier = organizationIdentifier; - } - - public String getPractitionerIdentifier() { - return practitionerIdentifier; - } - - public void setPractitionerIdentifier(String practitionerIdentifier) { - this.practitionerIdentifier = practitionerIdentifier; - } - - public PractitionerRoleCode getCode() { - return code; - } - - public void setCode(PractitionerRoleCode code) { - this.code = code; - } -} \ No newline at end of file diff --git a/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java b/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java deleted file mode 100644 index 5f40b33b8..000000000 --- a/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.smartregister.domain; - -import java.io.Serializable; - -/** - * Created by Ephraim Kigamba - nek.eam@gmail.com on 01-03-2021. - */ - -public class PractitionerRoleCode implements Serializable { - - private static final long serialVersionUID = 5814439241291810987L; - private String text; - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } -} \ No newline at end of file From 3c654d37b2cc01556e56864e488f1ed4a3c21a77 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Thu, 4 Mar 2021 18:59:39 +0300 Subject: [PATCH 06/21] :arrow-up: Update plan-evaluator to version 1.4.0-SNAPSHOT --- opensrp-app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-app/build.gradle b/opensrp-app/build.gradle index 5ff367f1b..d805a9cbe 100644 --- a/opensrp-app/build.gradle +++ b/opensrp-app/build.gradle @@ -232,7 +232,7 @@ dependencies { transitive = true } - implementation 'org.smartregister:opensrp-plan-evaluator:1.2.3-SNAPSHOT' + implementation 'org.smartregister:opensrp-plan-evaluator:1.4.0-SNAPSHOT' implementation 'xerces:xercesImpl:2.12.0' From ce930d8edd80d7fd45dff6b8ebab83fa23fe7d00 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Wed, 10 Mar 2021 17:38:27 +0300 Subject: [PATCH 07/21] Update TaskDao implementations --- .../java/org/smartregister/repository/TaskRepository.java | 7 ++++--- .../java/org/smartregister/repository/dao/TaskDaoImpl.java | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/repository/TaskRepository.java b/opensrp-app/src/main/java/org/smartregister/repository/TaskRepository.java index 90494e117..b9258aff0 100644 --- a/opensrp-app/src/main/java/org/smartregister/repository/TaskRepository.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/TaskRepository.java @@ -689,10 +689,11 @@ public int getUnsyncedCreatedTasksAndTaskStatusCount() { return unsyncedRecordsCount; } + @NonNull - public Set getTasksByJurisdiction(@NonNull String jurisdictionId) { - String query = "SELECT * FROM " + TASK_TABLE + " WHERE " + GROUP_ID + " = ?"; - return getTasks(query, new String[]{jurisdictionId}); + public Set getTasksByJurisdictionAndPlan(@NonNull String jurisdictionId, String planIdentifier) { + String query = "SELECT * FROM " + TASK_TABLE + " WHERE " + GROUP_ID + " = ? AND " + PLAN_ID + " = ?"; + return getTasks(query, new String[]{jurisdictionId, planIdentifier}); } public List getEntityIdsWithDuplicateTasks() { diff --git a/opensrp-app/src/main/java/org/smartregister/repository/dao/TaskDaoImpl.java b/opensrp-app/src/main/java/org/smartregister/repository/dao/TaskDaoImpl.java index a102bcc67..0407f3326 100644 --- a/opensrp-app/src/main/java/org/smartregister/repository/dao/TaskDaoImpl.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/dao/TaskDaoImpl.java @@ -90,8 +90,8 @@ public org.smartregister.domain.Task updateTask(org.smartregister.domain.Task ta } @Override - public List findTasksByJurisdiction(String jurisdiction) { - return getTasksByJurisdiction(jurisdiction) + public List findTasksByJurisdiction(String jurisdiction,String planIdentifier) { + return getTasksByJurisdictionAndPlan(jurisdiction, planIdentifier) .stream() .map(TaskConverter::convertTasktoFihrResource) .collect(Collectors.toList()); From 78f3b3a8bdc687e3fb093778cffcec60370775ee Mon Sep 17 00:00:00 2001 From: Allan O Date: Fri, 12 Mar 2021 21:41:31 +0300 Subject: [PATCH 08/21] :construction: Handle URI Exception --- .../src/main/java/org/smartregister/service/HTTPAgent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java b/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java index 256876f61..799f8a443 100644 --- a/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java +++ b/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java @@ -1062,7 +1062,7 @@ public Practitioner[] fetchPractitioners() { return gson.fromJson(responseString, Practitioner[].class); } - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { Timber.e(e); } finally { @@ -1100,7 +1100,7 @@ public PractitionerRole[] fetchPractitionerRoles() { return gson.fromJson(responseString, PractitionerRole[].class); } - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { Timber.e(e); } finally { From 410457cb2a06cca695977a3287c2798c10b24b05 Mon Sep 17 00:00:00 2001 From: Allan O Date: Sun, 21 Mar 2021 11:51:20 +0300 Subject: [PATCH 09/21] :construction: Add Pratitioner repository --- .../repository/PractitionerRepository.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 opensrp-app/src/main/java/org/smartregister/repository/PractitionerRepository.java diff --git a/opensrp-app/src/main/java/org/smartregister/repository/PractitionerRepository.java b/opensrp-app/src/main/java/org/smartregister/repository/PractitionerRepository.java new file mode 100644 index 000000000..c1ff59bf8 --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/repository/PractitionerRepository.java @@ -0,0 +1,87 @@ +package org.smartregister.repository; + +import android.content.ContentValues; + +import androidx.annotation.NonNull; + +import net.sqlcipher.Cursor; +import net.sqlcipher.database.SQLiteDatabase; + +import org.smartregister.domain.Practitioner; + +import java.util.ArrayList; +import java.util.List; + +import timber.log.Timber; + +public class PractitionerRepository extends BaseRepository { + + + protected static final String ID = "_id"; + protected static final String IS_ACTIVE = "is_active"; + protected static final String NAME = "name"; + protected static final String USER_ID = "user_id"; + protected static final String USERNAME = "username"; + + private static final String PRACTITIONER_TABLE = "practitioner"; + + private static final String CREATE_PRACTITIONER_TABLE = + "CREATE TABLE " + PRACTITIONER_TABLE + " (" + + ID + " VARCHAR NOT NULL PRIMARY KEY," + + IS_ACTIVE + " INTEGER NOT NULL," + + NAME + " VARCHAR NOT NULL," + + USER_ID + " VARCHAR NOT NULL," + + USERNAME + " VARCHAR NOT NULL)"; + + public static void createTable(SQLiteDatabase database) { + database.execSQL(CREATE_PRACTITIONER_TABLE); + } + + public void addOrUpdate(Practitioner practitioner) { + ContentValues contentValues = new ContentValues(); + contentValues.put(ID, practitioner.getIdentifier()); + contentValues.put(IS_ACTIVE, practitioner.getActive()); + contentValues.put(NAME, practitioner.getName()); + contentValues.put(USER_ID, practitioner.getUserId()); + contentValues.put(USERNAME, practitioner.getUsername()); + getWritableDatabase().replace(PRACTITIONER_TABLE, null, contentValues); + + } + + protected Practitioner readCursor(@NonNull Cursor cursor) { + Practitioner practitioner = new Practitioner(); + practitioner.setIdentifier(cursor.getString(cursor.getColumnIndex(ID))); + practitioner.setName(cursor.getString(cursor.getColumnIndex(NAME))); + practitioner.setActive(cursor.getInt(cursor.getColumnIndex(IS_ACTIVE)) > 0); + practitioner.setUserId(cursor.getString(cursor.getColumnIndex(USER_ID))); + practitioner.setUsername(cursor.getString(cursor.getColumnIndex(USERNAME))); + + return practitioner; + } + + + public List getAllPractitioners() { + List practitionerList = new ArrayList<>(); + try (Cursor cursor = getReadableDatabase().rawQuery("SELECT * FROM " + PRACTITIONER_TABLE, + null)) { + while (cursor.moveToNext()) { + practitionerList.add(readCursor(cursor)); + } + } + return practitionerList; + } + + public Practitioner getPractitionerByIdentifier(String identifier) { + Practitioner practitioner = null; + try (Cursor cursor = getReadableDatabase().rawQuery("SELECT * FROM " + PRACTITIONER_TABLE + + " WHERE " + ID + " =?", new String[]{identifier})) { + while (cursor.moveToNext()) { + practitioner = readCursor(cursor); + } + } catch (Exception e) { + Timber.e(e); + } + return practitioner; + } + +} From 695252ab7fa4d43776965b41a4cfd74544c232ce Mon Sep 17 00:00:00 2001 From: Allan O Date: Sun, 21 Mar 2021 11:57:53 +0300 Subject: [PATCH 10/21] :construction: Add Pratitioner sync helper + service --- .../sync/helper/PractitionerSyncHelper.java | 98 +++++++++++++++++++ ...PractitionersByIdAndRoleIntentService.java | 29 ++++++ 2 files changed, 127 insertions(+) create mode 100644 opensrp-app/src/main/java/org/smartregister/sync/helper/PractitionerSyncHelper.java create mode 100644 opensrp-app/src/main/java/org/smartregister/sync/intent/SyncPractitionersByIdAndRoleIntentService.java diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/PractitionerSyncHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/PractitionerSyncHelper.java new file mode 100644 index 000000000..f4540f913 --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/PractitionerSyncHelper.java @@ -0,0 +1,98 @@ +package org.smartregister.sync.helper; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import org.json.JSONException; +import org.json.JSONObject; +import org.smartregister.CoreLibrary; +import org.smartregister.domain.Practitioner; +import org.smartregister.domain.Response; +import org.smartregister.exception.NoHttpResponseException; +import org.smartregister.repository.AllSharedPreferences; +import org.smartregister.repository.PractitionerRepository; +import org.smartregister.service.HTTPAgent; + +import java.text.MessageFormat; +import java.util.List; + +import timber.log.Timber; + +/** + * Created by Allan Onchuru on 20/03/2021 + */ + +public class PractitionerSyncHelper { + + private final PractitionerRepository practitionerRepository; + private HTTPAgent httpAgent; + private Gson gson; + protected static PractitionerSyncHelper instance; + private final AllSharedPreferences allSharedPreferences; + private static final String PRACTITIONER_URL = "/rest/practitioner"; + private static final String PRACTITIONERS_BY_ID_AND_ROLE_URL = PRACTITIONER_URL + "/report-to"; + + public static PractitionerSyncHelper getInstance() { + if (instance == null) { + instance = new PractitionerSyncHelper(CoreLibrary.getInstance().context().getPractitionerRepository()); + } + return instance; + } + + private PractitionerSyncHelper(PractitionerRepository practitionerRepository) { + this.practitionerRepository = practitionerRepository; + this.allSharedPreferences = CoreLibrary.getInstance().context().allSharedPreferences(); + this.httpAgent = CoreLibrary.getInstance().context().getHttpAgent(); + this.gson = new Gson(); + } + + + public void syncPractitionersByIdAndRoleFromServer() { + String practitionerIdentifier = allSharedPreferences.getUserPractitionerRole(); + String code = allSharedPreferences.getUserPractitionerRole(); + try { + String response = syncPractitioners(practitionerIdentifier, code); + List practitioners = gson.fromJson(response, new TypeToken>() { + }.getType()); + for (Practitioner practitioner : practitioners) { + practitionerRepository.addOrUpdate(practitioner); + } + } catch (Exception ex) { + Timber.e(ex); + } + } + + private String syncPractitioners(String practitionerIdentifier, String code) throws JSONException, NoHttpResponseException { + if (httpAgent == null) { + throw new IllegalArgumentException(PRACTITIONERS_BY_ID_AND_ROLE_URL + " HTTPAgent agent is null"); + } + + String baseUrl = getFormattedBaseUrl(); + + JSONObject request = new JSONObject(); + request.put("practitionerIdentifier", practitionerIdentifier); + request.put("code", code); + + Response resp = httpAgent.post( + MessageFormat.format("{0}{1}", + baseUrl, + PRACTITIONERS_BY_ID_AND_ROLE_URL), + request.toString()); + + if (resp.isFailure()) { + throw new NoHttpResponseException(PRACTITIONERS_BY_ID_AND_ROLE_URL + " not data returned"); + } + + return resp.payload().toString(); + } + + public String getFormattedBaseUrl() { + String baseUrl = CoreLibrary.getInstance().context().configuration().dristhiBaseURL(); + String endString = "/"; + if (baseUrl.endsWith(endString)) { + baseUrl = baseUrl.substring(0, baseUrl.lastIndexOf(endString)); + } + return baseUrl; + } + +} diff --git a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncPractitionersByIdAndRoleIntentService.java b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncPractitionersByIdAndRoleIntentService.java new file mode 100644 index 000000000..41f868ffd --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncPractitionersByIdAndRoleIntentService.java @@ -0,0 +1,29 @@ +package org.smartregister.sync.intent; + +import android.content.Intent; + +import org.smartregister.sync.helper.PractitionerSyncHelper; + +import timber.log.Timber; + +public class SyncPractitionersByIdAndRoleIntentService extends BaseSyncIntentService { + + private static final String TAG = SyncPractitionersByIdAndRoleIntentService.class.getCanonicalName(); + + public SyncPractitionersByIdAndRoleIntentService() { + super(TAG); + } + + @Override + protected void onHandleIntent(Intent intent) { + super.onHandleIntent(intent); + + PractitionerSyncHelper practitionerSyncHelper = PractitionerSyncHelper.getInstance(); + + try { + practitionerSyncHelper.syncPractitionersByIdAndRoleFromServer(); + } catch (Exception ex) { + Timber.e(ex); + } + } +} From 75ad239d9b97a2423c70ab4b0ead09a35d5bd23a Mon Sep 17 00:00:00 2001 From: Allan O Date: Sun, 21 Mar 2021 11:58:33 +0300 Subject: [PATCH 11/21] :construction: Add Sync Pratitioner by ID & Role Job --- .../main/java/org/smartregister/Context.java | 9 ++++++++ .../job/SyncPractitionersByIdAndRoleJob.java | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 opensrp-app/src/main/java/org/smartregister/job/SyncPractitionersByIdAndRoleJob.java diff --git a/opensrp-app/src/main/java/org/smartregister/Context.java b/opensrp-app/src/main/java/org/smartregister/Context.java index f5b91566a..e9edee3c0 100755 --- a/opensrp-app/src/main/java/org/smartregister/Context.java +++ b/opensrp-app/src/main/java/org/smartregister/Context.java @@ -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; @@ -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; @@ -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(); diff --git a/opensrp-app/src/main/java/org/smartregister/job/SyncPractitionersByIdAndRoleJob.java b/opensrp-app/src/main/java/org/smartregister/job/SyncPractitionersByIdAndRoleJob.java new file mode 100644 index 000000000..864c33ce5 --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/job/SyncPractitionersByIdAndRoleJob.java @@ -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.SyncPractitionersByIdAndRoleIntentService; + +public class SyncPractitionersByIdAndRoleJob extends BaseJob { + + public static final String TAG = "SyncPractitionersByIdAndRoleJob"; + + @NonNull + @Override + protected Result onRunJob(@NonNull Params params) { + Intent intent = new Intent(getApplicationContext(), SyncPractitionersByIdAndRoleIntentService.class); + getApplicationContext().startService(intent); + return params != null && params.getExtras().getBoolean(AllConstants.INTENT_KEY.TO_RESCHEDULE, false) ? Result.RESCHEDULE : Result.SUCCESS; + } +} From b78bd0fcab0631da44bf72bc34a4cfea95e1c972 Mon Sep 17 00:00:00 2001 From: Allan O Date: Sun, 21 Mar 2021 16:49:25 +0300 Subject: [PATCH 12/21] :construction: Add toolbar color & options hiding functionality --- .../configuration/ToolbarOptions.java | 11 ++++++++++ .../BaseConfigurableRegisterFragment.java | 22 ++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/configuration/ToolbarOptions.java b/opensrp-app/src/main/java/org/smartregister/configuration/ToolbarOptions.java index ff4385b70..d8471c424 100644 --- a/opensrp-app/src/main/java/org/smartregister/configuration/ToolbarOptions.java +++ b/opensrp-app/src/main/java/org/smartregister/configuration/ToolbarOptions.java @@ -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 getHiddenToolOptions() { + return new ArrayList<>(); + } + public DialogOptionModel getDialogOptionModel(); } diff --git a/opensrp-app/src/main/java/org/smartregister/view/fragment/BaseConfigurableRegisterFragment.java b/opensrp-app/src/main/java/org/smartregister/view/fragment/BaseConfigurableRegisterFragment.java index 08389ca0a..c6f76ff5f 100644 --- a/opensrp-app/src/main/java/org/smartregister/view/fragment/BaseConfigurableRegisterFragment.java +++ b/opensrp-app/src/main/java/org/smartregister/view/fragment/BaseConfigurableRegisterFragment.java @@ -34,6 +34,7 @@ import org.smartregister.view.activity.BaseConfigurableRegisterActivity; import org.smartregister.view.activity.BaseRegisterActivity; import org.smartregister.view.contract.BaseRegisterFragmentContract; +import org.smartregister.view.dialog.DialogOptionModel; import org.smartregister.view.dialog.NoMatchDialogFragment; import org.smartregister.view.model.BaseConfigurableRegisterFragmentModel; import org.smartregister.view.presenter.BaseConfigurableRegisterFragmentPresenter; @@ -50,6 +51,7 @@ public class BaseConfigurableRegisterFragment extends BaseRegisterFragment { private static final String DUE_FILTER_TAG = "PRESSED"; + private View navbarContainer; private View dueOnlyLayout; private boolean dueFilterActive = false; private ModuleRegisterQueryProviderContract moduleRegisterQueryProvider; @@ -85,7 +87,7 @@ protected int getLayout() { @Override public void setupViews(View view) { super.setupViews(view); - + navbarContainer = view.findViewById(R.id.register_nav_bar_container); if (toolbarOptions != null && toolbarOptions.isNewToolbarEnabled()) { initializeConfigurableLayoutViews(view); return; @@ -128,7 +130,6 @@ public void setupViews(View view) { titleView.setPadding(0, titleView.getTop(), titleView.getPaddingRight(), titleView.getPaddingBottom()); } - View navbarContainer = view.findViewById(R.id.register_nav_bar_container); navbarContainer.setFocusable(false); View topLeftLayout = view.findViewById(R.id.top_left_layout); @@ -153,6 +154,10 @@ public void setupViews(View view) { } public void initializeConfigurableLayoutViews(View view) { + // Update Toolbar color + if (toolbarOptions.getToolBarColor() > 0) { + navbarContainer.setBackgroundColor(toolbarOptions.getToolBarColor()); + } // Update logo ImageView logo = view.findViewById(R.id.top_left_logo); if (logo != null && toolbarOptions.getLogoResourceId() > 0) { @@ -163,6 +168,15 @@ public void initializeConfigurableLayoutViews(View view) { if (backButton != null) backButton.setOnClickListener(v -> getActivity().finish()); + + // Hide unwanted toolbar options + List hiddenToolbarOptions = toolbarOptions.getHiddenToolOptions(); + if (hiddenToolbarOptions.size() > 0) { + for (int layoutId : hiddenToolbarOptions) { + view.findViewById(layoutId).setVisibility(View.GONE); + } + } + ExtendedFloatingActionButton addClientsFab = view.findViewById(R.id.add_new_client_fab); if (addClientsFab != null) { setupAddClientFab(addClientsFab); @@ -172,7 +186,9 @@ public void initializeConfigurableLayoutViews(View view) { if (registerSelect != null) { registerSelect.setOnClickListener(v -> { if (getActivity() instanceof BaseConfigurableRegisterActivity) { - ((BaseConfigurableRegisterActivity) getActivity()).showFragmentDialog(toolbarOptions.getDialogOptionModel()); + DialogOptionModel dialogOptionModel = toolbarOptions.getDialogOptionModel(); + if (dialogOptionModel != null) + ((BaseConfigurableRegisterActivity) getActivity()).showFragmentDialog(dialogOptionModel); } }); } From 7a79e338f4104455e44af6360301eff520bccca5 Mon Sep 17 00:00:00 2001 From: Allan O Date: Sun, 21 Mar 2021 22:23:11 +0300 Subject: [PATCH 13/21] :construction: Refactor navigation & add bottom nav configs Refactored Toolbar configs to be merged in NavigationOptions --- .../BottomNavigationOptions.java | 10 ++++++++ .../BottomNavigationOptionsModel.java | 11 ++++++++ .../ConfigurableNavigationOptions.java | 9 +++++++ .../ConfigurableBottomNavigationListener.java | 25 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 opensrp-app/src/main/java/org/smartregister/configuration/BottomNavigationOptions.java create mode 100644 opensrp-app/src/main/java/org/smartregister/configuration/BottomNavigationOptionsModel.java create mode 100644 opensrp-app/src/main/java/org/smartregister/configuration/ConfigurableNavigationOptions.java create mode 100644 opensrp-app/src/main/java/org/smartregister/listener/ConfigurableBottomNavigationListener.java diff --git a/opensrp-app/src/main/java/org/smartregister/configuration/BottomNavigationOptions.java b/opensrp-app/src/main/java/org/smartregister/configuration/BottomNavigationOptions.java new file mode 100644 index 000000000..4d25bef70 --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/configuration/BottomNavigationOptions.java @@ -0,0 +1,10 @@ +package org.smartregister.configuration; + +public interface BottomNavigationOptions { + + public int getBottomNavigationLayoutId(); + + public BottomNavigationOptionsModel getBottomNavigationOptionsModel(); + + public int checkedItemId(); +} diff --git a/opensrp-app/src/main/java/org/smartregister/configuration/BottomNavigationOptionsModel.java b/opensrp-app/src/main/java/org/smartregister/configuration/BottomNavigationOptionsModel.java new file mode 100644 index 000000000..5a784bb61 --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/configuration/BottomNavigationOptionsModel.java @@ -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); +} diff --git a/opensrp-app/src/main/java/org/smartregister/configuration/ConfigurableNavigationOptions.java b/opensrp-app/src/main/java/org/smartregister/configuration/ConfigurableNavigationOptions.java new file mode 100644 index 000000000..42b8473b0 --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/configuration/ConfigurableNavigationOptions.java @@ -0,0 +1,9 @@ +package org.smartregister.configuration; + +public interface ConfigurableNavigationOptions { + + public ToolbarOptions getToolbarOptions(); + + public BottomNavigationOptions getBottomNavigationOptions(); + +} diff --git a/opensrp-app/src/main/java/org/smartregister/listener/ConfigurableBottomNavigationListener.java b/opensrp-app/src/main/java/org/smartregister/listener/ConfigurableBottomNavigationListener.java new file mode 100644 index 000000000..dfe8bfb6d --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/listener/ConfigurableBottomNavigationListener.java @@ -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; + } + +} From c85260da909619fcd3889bba489494bb2c8c7dcb Mon Sep 17 00:00:00 2001 From: Allan O Date: Sun, 21 Mar 2021 22:25:42 +0300 Subject: [PATCH 14/21] :recycle: Refactor toolbar & bottom nav Module configs --- .../configuration/ModuleConfiguration.java | 10 +++--- .../listener/BottomNavigationListener.java | 6 ++-- .../BaseConfigurableRegisterActivity.java | 32 ++++++++++++++++--- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/configuration/ModuleConfiguration.java b/opensrp-app/src/main/java/org/smartregister/configuration/ModuleConfiguration.java index 54b716387..6657230f5 100644 --- a/opensrp-app/src/main/java/org/smartregister/configuration/ModuleConfiguration.java +++ b/opensrp-app/src/main/java/org/smartregister/configuration/ModuleConfiguration.java @@ -83,8 +83,8 @@ public String getRegisterTitle() { return builder.registerTitle; } - public Class getToolbarOptions() { - return builder.toolbarOptions; + public Class getNavigationOptions() { + return builder.navigationOptions; } public int getMaxCheckInDurationInMinutes() { @@ -127,7 +127,7 @@ public static class Builder { @NonNull private Class jsonFormActivity; - private Class toolbarOptions; + private Class navigationOptions; private boolean isBottomNavigationEnabled; @@ -163,8 +163,8 @@ public Builder setModuleMetadata(@NonNull ModuleMetadata moduleMetadata) { return this; } - public Builder setToolbarOptions(@Nullable Class toolbarOptions) { - this.toolbarOptions = toolbarOptions; + public Builder setNavigationOptions(@Nullable Class navigationOptions) { + this.navigationOptions = navigationOptions; return this; } diff --git a/opensrp-app/src/main/java/org/smartregister/listener/BottomNavigationListener.java b/opensrp-app/src/main/java/org/smartregister/listener/BottomNavigationListener.java index 842f4f0d2..75be6c185 100644 --- a/opensrp-app/src/main/java/org/smartregister/listener/BottomNavigationListener.java +++ b/opensrp-app/src/main/java/org/smartregister/listener/BottomNavigationListener.java @@ -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; diff --git a/opensrp-app/src/main/java/org/smartregister/view/activity/BaseConfigurableRegisterActivity.java b/opensrp-app/src/main/java/org/smartregister/view/activity/BaseConfigurableRegisterActivity.java index cb0ffc350..bf02e4a12 100644 --- a/opensrp-app/src/main/java/org/smartregister/view/activity/BaseConfigurableRegisterActivity.java +++ b/opensrp-app/src/main/java/org/smartregister/view/activity/BaseConfigurableRegisterActivity.java @@ -18,8 +18,12 @@ import org.smartregister.R; import org.smartregister.client.utils.domain.Form; import org.smartregister.commonregistry.CommonPersonObjectClient; +import org.smartregister.configuration.BottomNavigationOptions; +import org.smartregister.configuration.ConfigurableNavigationOptions; import org.smartregister.configuration.ModuleConfiguration; import org.smartregister.configuration.ModuleMetadata; +import org.smartregister.listener.ConfigurableBottomNavigationListener; +import org.smartregister.util.ConfigurationInstancesHelper; import org.smartregister.util.JsonFormUtils; import org.smartregister.util.Utils; import org.smartregister.view.contract.BaseRegisterContract; @@ -46,12 +50,13 @@ public class BaseConfigurableRegisterActivity extends BaseRegisterActivity { protected String moduleName; protected ModuleConfiguration moduleConfiguration; + private ConfigurableNavigationOptions navigationOptions; @Override protected void onCreate(Bundle savedInstanceState) { moduleName = Utils.extractModuleName(getIntent()); fetchModuleConfiguration(); - + initNavigationOptions(); super.onCreate(savedInstanceState); onStartActivityWithAction(); } @@ -61,6 +66,13 @@ private void fetchModuleConfiguration() { .getModuleConfiguration(getModuleName()); } + private void initNavigationOptions() { + Class navigationOptionsClass = moduleConfiguration.getNavigationOptions(); + if (navigationOptionsClass != null) { + this.navigationOptions = ConfigurationInstancesHelper.newInstance(navigationOptionsClass); + } + } + public String getModuleName() { return moduleName; } @@ -86,12 +98,21 @@ protected void onStartActivityWithAction() { @Override protected void registerBottomNavigation() { try { - View bottomNavGeneralView = findViewById(org.smartregister.R.id.bottom_navigation); - if (bottomNavGeneralView instanceof BottomNavigationView) { - BottomNavigationView bottomNavigationView = (BottomNavigationView) bottomNavGeneralView; - if (!getModuleConfiguration().isBottomNavigationEnabled()) { + if (!getModuleConfiguration().isBottomNavigationEnabled()) { + View bottomNavGeneralView = findViewById(org.smartregister.R.id.bottom_navigation); + if (bottomNavGeneralView instanceof BottomNavigationView) { + BottomNavigationView bottomNavigationView = (BottomNavigationView) bottomNavGeneralView; bottomNavigationView.setVisibility(View.GONE); } + } else { + BottomNavigationOptions bottomNavigationOptions = navigationOptions.getBottomNavigationOptions(); + if (bottomNavigationOptions != null) { + BottomNavigationView bottomNavigationView = findViewById(bottomNavigationOptions.getBottomNavigationLayoutId()); + bottomNavigationView.setOnNavigationItemSelectedListener(new ConfigurableBottomNavigationListener(this, + bottomNavigationOptions.getBottomNavigationOptionsModel())); + bottomNavigationView.getMenu().findItem(bottomNavigationOptions.checkedItemId()).setChecked(true); + bottomNavigationView.setVisibility(View.VISIBLE); + } } } catch (NoSuchFieldError e) { // This error occurs because the ID cannot be found on some client applications because the layout @@ -109,6 +130,7 @@ protected void initializePresenter() { protected BaseRegisterFragment getRegisterFragment() { BaseConfigurableRegisterFragment baseConfigurableRegisterFragment = new BaseConfigurableRegisterFragment(); baseConfigurableRegisterFragment.setModuleConfiguration(getModuleConfiguration()); + baseConfigurableRegisterFragment.setToolbarOptions(navigationOptions.getToolbarOptions()); return baseConfigurableRegisterFragment; } From 14ed73150dfab8deb764ce5cd24d7408138f3d74 Mon Sep 17 00:00:00 2001 From: Allan O Date: Sun, 21 Mar 2021 22:46:41 +0300 Subject: [PATCH 15/21] :construction: Add set fragment toolbar options --- .../view/fragment/BaseConfigurableRegisterFragment.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/view/fragment/BaseConfigurableRegisterFragment.java b/opensrp-app/src/main/java/org/smartregister/view/fragment/BaseConfigurableRegisterFragment.java index c6f76ff5f..9951195e7 100644 --- a/opensrp-app/src/main/java/org/smartregister/view/fragment/BaseConfigurableRegisterFragment.java +++ b/opensrp-app/src/main/java/org/smartregister/view/fragment/BaseConfigurableRegisterFragment.java @@ -61,10 +61,10 @@ public class BaseConfigurableRegisterFragment extends BaseRegisterFragment { public void setModuleConfiguration(@NonNull ModuleConfiguration moduleConfiguration) { moduleRegisterQueryProvider = ConfigurationInstancesHelper.newInstance(moduleConfiguration.getRegisterQueryProvider()); this.moduleConfiguration = moduleConfiguration; - Class toolbarOptionsClass = moduleConfiguration.getToolbarOptions(); - if (toolbarOptionsClass != null) { - this.toolbarOptions = ConfigurationInstancesHelper.newInstance(toolbarOptionsClass); - } + } + + public void setToolbarOptions(ToolbarOptions toolbarOptions) { + this.toolbarOptions = toolbarOptions; } public ModuleConfiguration getModuleConfiguration() { From 867e02927325651ff9d054aa89f9e865677a6d16 Mon Sep 17 00:00:00 2001 From: Allan O Date: Sun, 21 Mar 2021 22:47:57 +0300 Subject: [PATCH 16/21] :construction: Change practitioner ID column to IDENTIFIER --- .../repository/PractitionerRepository.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/repository/PractitionerRepository.java b/opensrp-app/src/main/java/org/smartregister/repository/PractitionerRepository.java index c1ff59bf8..4f85e2a76 100644 --- a/opensrp-app/src/main/java/org/smartregister/repository/PractitionerRepository.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/PractitionerRepository.java @@ -16,8 +16,8 @@ public class PractitionerRepository extends BaseRepository { - protected static final String ID = "_id"; + protected static final String IDENTIFIER = "identifier"; protected static final String IS_ACTIVE = "is_active"; protected static final String NAME = "name"; protected static final String USER_ID = "user_id"; @@ -26,8 +26,9 @@ public class PractitionerRepository extends BaseRepository { private static final String PRACTITIONER_TABLE = "practitioner"; private static final String CREATE_PRACTITIONER_TABLE = - "CREATE TABLE " + PRACTITIONER_TABLE + " (" + + "CREATE TABLE IF NOT EXISTS " + PRACTITIONER_TABLE + " (" + ID + " VARCHAR NOT NULL PRIMARY KEY," + + IDENTIFIER + " VARCHAR NOT NULL PRIMARY KEY," + IS_ACTIVE + " INTEGER NOT NULL," + NAME + " VARCHAR NOT NULL," + USER_ID + " VARCHAR NOT NULL," + @@ -40,6 +41,7 @@ public static void createTable(SQLiteDatabase database) { public void addOrUpdate(Practitioner practitioner) { ContentValues contentValues = new ContentValues(); contentValues.put(ID, practitioner.getIdentifier()); + contentValues.put(IDENTIFIER, practitioner.getIdentifier()); contentValues.put(IS_ACTIVE, practitioner.getActive()); contentValues.put(NAME, practitioner.getName()); contentValues.put(USER_ID, practitioner.getUserId()); @@ -50,7 +52,7 @@ public void addOrUpdate(Practitioner practitioner) { protected Practitioner readCursor(@NonNull Cursor cursor) { Practitioner practitioner = new Practitioner(); - practitioner.setIdentifier(cursor.getString(cursor.getColumnIndex(ID))); + practitioner.setIdentifier(cursor.getString(cursor.getColumnIndex(IDENTIFIER))); practitioner.setName(cursor.getString(cursor.getColumnIndex(NAME))); practitioner.setActive(cursor.getInt(cursor.getColumnIndex(IS_ACTIVE)) > 0); practitioner.setUserId(cursor.getString(cursor.getColumnIndex(USER_ID))); @@ -74,7 +76,7 @@ public List getAllPractitioners() { public Practitioner getPractitionerByIdentifier(String identifier) { Practitioner practitioner = null; try (Cursor cursor = getReadableDatabase().rawQuery("SELECT * FROM " + PRACTITIONER_TABLE + - " WHERE " + ID + " =?", new String[]{identifier})) { + " WHERE " + IDENTIFIER + " =?", new String[]{identifier})) { while (cursor.moveToNext()) { practitioner = readCursor(cursor); } From 7930b1d3a475e27bf4cf2a53ac7e0be900c29ec2 Mon Sep 17 00:00:00 2001 From: Allan O Date: Mon, 22 Mar 2021 12:10:46 +0300 Subject: [PATCH 17/21] :construction: Show bottom nav icons + title --- .../org/smartregister/repository/PractitionerRepository.java | 4 ++-- .../view/activity/BaseConfigurableRegisterActivity.java | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/repository/PractitionerRepository.java b/opensrp-app/src/main/java/org/smartregister/repository/PractitionerRepository.java index 4f85e2a76..01447cfff 100644 --- a/opensrp-app/src/main/java/org/smartregister/repository/PractitionerRepository.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/PractitionerRepository.java @@ -16,7 +16,7 @@ public class PractitionerRepository extends BaseRepository { - protected static final String ID = "_id"; + protected static final String ID = "id"; protected static final String IDENTIFIER = "identifier"; protected static final String IS_ACTIVE = "is_active"; protected static final String NAME = "name"; @@ -28,7 +28,7 @@ public class PractitionerRepository extends BaseRepository { private static final String CREATE_PRACTITIONER_TABLE = "CREATE TABLE IF NOT EXISTS " + PRACTITIONER_TABLE + " (" + ID + " VARCHAR NOT NULL PRIMARY KEY," + - IDENTIFIER + " VARCHAR NOT NULL PRIMARY KEY," + + IDENTIFIER + " VARCHAR NOT NULL," + IS_ACTIVE + " INTEGER NOT NULL," + NAME + " VARCHAR NOT NULL," + USER_ID + " VARCHAR NOT NULL," + diff --git a/opensrp-app/src/main/java/org/smartregister/view/activity/BaseConfigurableRegisterActivity.java b/opensrp-app/src/main/java/org/smartregister/view/activity/BaseConfigurableRegisterActivity.java index bf02e4a12..fffa10ad1 100644 --- a/opensrp-app/src/main/java/org/smartregister/view/activity/BaseConfigurableRegisterActivity.java +++ b/opensrp-app/src/main/java/org/smartregister/view/activity/BaseConfigurableRegisterActivity.java @@ -22,6 +22,7 @@ import org.smartregister.configuration.ConfigurableNavigationOptions; import org.smartregister.configuration.ModuleConfiguration; import org.smartregister.configuration.ModuleMetadata; +import org.smartregister.helper.BottomNavigationHelper; import org.smartregister.listener.ConfigurableBottomNavigationListener; import org.smartregister.util.ConfigurationInstancesHelper; import org.smartregister.util.JsonFormUtils; @@ -110,8 +111,10 @@ protected void registerBottomNavigation() { BottomNavigationView bottomNavigationView = findViewById(bottomNavigationOptions.getBottomNavigationLayoutId()); bottomNavigationView.setOnNavigationItemSelectedListener(new ConfigurableBottomNavigationListener(this, bottomNavigationOptions.getBottomNavigationOptionsModel())); - bottomNavigationView.getMenu().findItem(bottomNavigationOptions.checkedItemId()).setChecked(true); bottomNavigationView.setVisibility(View.VISIBLE); + BottomNavigationHelper bottomNavigationHelper = new BottomNavigationHelper(); + bottomNavigationHelper.disableShiftMode(bottomNavigationView); + bottomNavigationView.getMenu().findItem(bottomNavigationOptions.checkedItemId()).setChecked(true); } } } catch (NoSuchFieldError e) { From 6bfe0d81e717f99ea998a7ce9f2ecc95851d2264 Mon Sep 17 00:00:00 2001 From: Allan O Date: Tue, 23 Mar 2021 11:25:26 +0300 Subject: [PATCH 18/21] :construction: Add practitioner identifier to shared pref --- .../smartregister/login/task/RemoteLoginTask.java | 5 +++-- .../repository/AllSharedPreferences.java | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java b/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java index 5c258294e..6b307aa16 100644 --- a/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java +++ b/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java @@ -178,7 +178,7 @@ protected void fetchUserRole() { } Practitioner loggedInPractitioner = null; - for (Practitioner practitioner: practitioners) { + for (Practitioner practitioner : practitioners) { if (practitioner != null && mUsername.equals(practitioner.getUsername())) { loggedInPractitioner = practitioner; } @@ -187,7 +187,7 @@ protected void fetchUserRole() { if (loggedInPractitioner != null && practitionerRoles != null) { PractitionerRole loggedInPractitionerRole = null; - for (PractitionerRole practitionerRole: practitionerRoles) { + for (PractitionerRole practitionerRole : practitionerRoles) { if (loggedInPractitioner.getIdentifier().equals(practitionerRole.getPractitionerIdentifier())) { loggedInPractitionerRole = practitionerRole; } @@ -195,6 +195,7 @@ protected void fetchUserRole() { if (loggedInPractitionerRole != null) { getOpenSRPContext().allSharedPreferences().setUserPractitionerRole(loggedInPractitionerRole.getCode().getText()); + getOpenSRPContext().allSharedPreferences().setUserPractitionerIdentifier(loggedInPractitionerRole.getIdentifier()); } } } diff --git a/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java b/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java index dc8371f3f..40e196c51 100644 --- a/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java @@ -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; @@ -34,6 +34,7 @@ public class AllSharedPreferences { 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) { @@ -392,8 +393,18 @@ 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_ROLE, identifier).commit(); + + } } From 493dbe42249590e6b76a755b0bbf3263c8829c4c Mon Sep 17 00:00:00 2001 From: Allan O Date: Tue, 23 Mar 2021 13:03:39 +0300 Subject: [PATCH 19/21] :bug: Fix get and set practitioner identifier --- opensrp-app/build.gradle | 6 +++--- .../java/org/smartregister/login/task/RemoteLoginTask.java | 2 +- .../org/smartregister/repository/AllSharedPreferences.java | 2 +- .../smartregister/sync/helper/PractitionerSyncHelper.java | 2 +- .../view/fragment/BaseConfigurableRegisterFragmentTest.java | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/opensrp-app/build.gradle b/opensrp-app/build.gradle index 724d867c7..19b9f4d77 100644 --- a/opensrp-app/build.gradle +++ b/opensrp-app/build.gradle @@ -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' @@ -312,4 +312,4 @@ coveralls { sourceDirs = ["$project.projectDir/src/main/java"] } -apply from: '../maven.gradle' \ No newline at end of file +//apply from: '../maven.gradle' \ No newline at end of file diff --git a/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java b/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java index 6b307aa16..b65378f58 100644 --- a/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java +++ b/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java @@ -195,7 +195,7 @@ protected void fetchUserRole() { if (loggedInPractitionerRole != null) { getOpenSRPContext().allSharedPreferences().setUserPractitionerRole(loggedInPractitionerRole.getCode().getText()); - getOpenSRPContext().allSharedPreferences().setUserPractitionerIdentifier(loggedInPractitionerRole.getIdentifier()); + getOpenSRPContext().allSharedPreferences().setUserPractitionerIdentifier(loggedInPractitionerRole.getPractitionerIdentifier()); } } } diff --git a/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java b/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java index 40e196c51..e96c18fdb 100644 --- a/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java @@ -403,7 +403,7 @@ public void setUserPractitionerRole(String practitionerRole) { } public void setUserPractitionerIdentifier(String identifier) { - preferences.edit().putString(USER_PRACTITIONER_ROLE, identifier).commit(); + preferences.edit().putString(USER_PRACTITIONER_IDENTIFIER, identifier).commit(); } } diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/PractitionerSyncHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/PractitionerSyncHelper.java index f4540f913..7ff47469e 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/PractitionerSyncHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/PractitionerSyncHelper.java @@ -48,7 +48,7 @@ private PractitionerSyncHelper(PractitionerRepository practitionerRepository) { public void syncPractitionersByIdAndRoleFromServer() { - String practitionerIdentifier = allSharedPreferences.getUserPractitionerRole(); + String practitionerIdentifier = allSharedPreferences.getUserPractitionerIdentifier(); String code = allSharedPreferences.getUserPractitionerRole(); try { String response = syncPractitioners(practitionerIdentifier, code); diff --git a/opensrp-app/src/test/java/org/smartregister/view/fragment/BaseConfigurableRegisterFragmentTest.java b/opensrp-app/src/test/java/org/smartregister/view/fragment/BaseConfigurableRegisterFragmentTest.java index d7de4e633..e367b33aa 100644 --- a/opensrp-app/src/test/java/org/smartregister/view/fragment/BaseConfigurableRegisterFragmentTest.java +++ b/opensrp-app/src/test/java/org/smartregister/view/fragment/BaseConfigurableRegisterFragmentTest.java @@ -75,7 +75,7 @@ private void setupModuleConfiguration() { moduleConfiguration = Mockito.mock(ModuleConfiguration.class, Mockito.CALLS_REAL_METHODS); Mockito.doReturn(MockRegisterQueryProvider.class).when(moduleConfiguration).getRegisterQueryProvider(); Mockito.doReturn(FormActivity.class).when(moduleConfiguration).getJsonFormActivity(); - Mockito.doReturn(ToolbarOptions.class).when(moduleConfiguration).getToolbarOptions(); + Mockito.doReturn(ToolbarOptions.class).when(moduleConfiguration).getNavigationOptions(); CoreLibrary.getInstance().addModuleConfiguration(moduleName, moduleConfiguration); } From 898c86037d8363a466d02b4947791a3c73c55ca0 Mon Sep 17 00:00:00 2001 From: Allan O Date: Tue, 23 Mar 2021 13:30:56 +0300 Subject: [PATCH 20/21] :bug: Fix Sync CHW Practitioners --- .../job/SyncPractitionersByIdAndRoleJob.java | 4 ++-- .../sync/helper/PractitionerSyncHelper.java | 22 +++++++++---------- ...ractitionersByIdAndRoleIntentService.java} | 8 +++---- 3 files changed, 16 insertions(+), 18 deletions(-) rename opensrp-app/src/main/java/org/smartregister/sync/intent/{SyncPractitionersByIdAndRoleIntentService.java => SyncChwPractitionersByIdAndRoleIntentService.java} (58%) diff --git a/opensrp-app/src/main/java/org/smartregister/job/SyncPractitionersByIdAndRoleJob.java b/opensrp-app/src/main/java/org/smartregister/job/SyncPractitionersByIdAndRoleJob.java index 864c33ce5..6f5bea030 100644 --- a/opensrp-app/src/main/java/org/smartregister/job/SyncPractitionersByIdAndRoleJob.java +++ b/opensrp-app/src/main/java/org/smartregister/job/SyncPractitionersByIdAndRoleJob.java @@ -5,7 +5,7 @@ import androidx.annotation.NonNull; import org.smartregister.AllConstants; -import org.smartregister.sync.intent.SyncPractitionersByIdAndRoleIntentService; +import org.smartregister.sync.intent.SyncChwPractitionersByIdAndRoleIntentService; public class SyncPractitionersByIdAndRoleJob extends BaseJob { @@ -14,7 +14,7 @@ public class SyncPractitionersByIdAndRoleJob extends BaseJob { @NonNull @Override protected Result onRunJob(@NonNull Params params) { - Intent intent = new Intent(getApplicationContext(), SyncPractitionersByIdAndRoleIntentService.class); + 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; } diff --git a/opensrp-app/src/main/java/org/smartregister/sync/helper/PractitionerSyncHelper.java b/opensrp-app/src/main/java/org/smartregister/sync/helper/PractitionerSyncHelper.java index 7ff47469e..6a90dc2f3 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/helper/PractitionerSyncHelper.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/helper/PractitionerSyncHelper.java @@ -4,7 +4,6 @@ import com.google.gson.reflect.TypeToken; import org.json.JSONException; -import org.json.JSONObject; import org.smartregister.CoreLibrary; import org.smartregister.domain.Practitioner; import org.smartregister.domain.Response; @@ -31,6 +30,9 @@ public class PractitionerSyncHelper { private final AllSharedPreferences allSharedPreferences; private static final String PRACTITIONER_URL = "/rest/practitioner"; private static final String PRACTITIONERS_BY_ID_AND_ROLE_URL = PRACTITIONER_URL + "/report-to"; + private static final String PRACTITIONER_IDENTIFIER = "practitionerIdentifier"; + private static final String PRACTITIONER_ROLE_CODE = "code"; + public static PractitionerSyncHelper getInstance() { if (instance == null) { @@ -47,9 +49,9 @@ private PractitionerSyncHelper(PractitionerRepository practitionerRepository) { } - public void syncPractitionersByIdAndRoleFromServer() { + public void syncChwPractitionersByIdAndRoleFromServer() { String practitionerIdentifier = allSharedPreferences.getUserPractitionerIdentifier(); - String code = allSharedPreferences.getUserPractitionerRole(); + String code = "Community Health Worker"; try { String response = syncPractitioners(practitionerIdentifier, code); List practitioners = gson.fromJson(response, new TypeToken>() { @@ -69,15 +71,11 @@ private String syncPractitioners(String practitionerIdentifier, String code) thr String baseUrl = getFormattedBaseUrl(); - JSONObject request = new JSONObject(); - request.put("practitionerIdentifier", practitionerIdentifier); - request.put("code", code); - - Response resp = httpAgent.post( - MessageFormat.format("{0}{1}", - baseUrl, - PRACTITIONERS_BY_ID_AND_ROLE_URL), - request.toString()); + Response resp = httpAgent.fetch( + MessageFormat.format("{0}{1}{2}", + baseUrl, PRACTITIONERS_BY_ID_AND_ROLE_URL, + "?" + PRACTITIONER_IDENTIFIER + "=" + practitionerIdentifier + + "&" + PRACTITIONER_ROLE_CODE + "=" + code)); if (resp.isFailure()) { throw new NoHttpResponseException(PRACTITIONERS_BY_ID_AND_ROLE_URL + " not data returned"); diff --git a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncPractitionersByIdAndRoleIntentService.java b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncChwPractitionersByIdAndRoleIntentService.java similarity index 58% rename from opensrp-app/src/main/java/org/smartregister/sync/intent/SyncPractitionersByIdAndRoleIntentService.java rename to opensrp-app/src/main/java/org/smartregister/sync/intent/SyncChwPractitionersByIdAndRoleIntentService.java index 41f868ffd..78e828f14 100644 --- a/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncPractitionersByIdAndRoleIntentService.java +++ b/opensrp-app/src/main/java/org/smartregister/sync/intent/SyncChwPractitionersByIdAndRoleIntentService.java @@ -6,11 +6,11 @@ import timber.log.Timber; -public class SyncPractitionersByIdAndRoleIntentService extends BaseSyncIntentService { +public class SyncChwPractitionersByIdAndRoleIntentService extends BaseSyncIntentService { - private static final String TAG = SyncPractitionersByIdAndRoleIntentService.class.getCanonicalName(); + private static final String TAG = SyncChwPractitionersByIdAndRoleIntentService.class.getCanonicalName(); - public SyncPractitionersByIdAndRoleIntentService() { + public SyncChwPractitionersByIdAndRoleIntentService() { super(TAG); } @@ -21,7 +21,7 @@ protected void onHandleIntent(Intent intent) { PractitionerSyncHelper practitionerSyncHelper = PractitionerSyncHelper.getInstance(); try { - practitionerSyncHelper.syncPractitionersByIdAndRoleFromServer(); + practitionerSyncHelper.syncChwPractitionersByIdAndRoleFromServer(); } catch (Exception ex) { Timber.e(ex); } From 64394b8919a9a445f08fe9d79f9dc1b37c977ee5 Mon Sep 17 00:00:00 2001 From: Allan O Date: Tue, 23 Mar 2021 19:32:58 +0300 Subject: [PATCH 21/21] :construction: Add practitionerIdentifier constant --- opensrp-app/src/main/java/org/smartregister/AllConstants.java | 1 + 1 file changed, 1 insertion(+) diff --git a/opensrp-app/src/main/java/org/smartregister/AllConstants.java b/opensrp-app/src/main/java/org/smartregister/AllConstants.java index 8ae63d979..9f3a797e7 100644 --- a/opensrp-app/src/main/java/org/smartregister/AllConstants.java +++ b/opensrp-app/src/main/java/org/smartregister/AllConstants.java @@ -28,6 +28,7 @@ public class AllConstants { public static final String FAMILY = "Family"; public static final String RELATIONSHIPS = "relationships"; public static final String TASK_IDENTIFIER = "taskIdentifier"; + public static final String PRACTITIONER_IDENTIFIER = "practitionerIdentifier"; // Maximum time difference between server and client time in milliseconds