From 65adf0ddb04e4bcee6e74288a5d34481ba0b6963 Mon Sep 17 00:00:00 2001 From: Sagar S Date: Wed, 13 Nov 2019 15:37:06 +0530 Subject: [PATCH] Done minor change for triggering prescription notifications as change into Sync functionality --- .../client/database/dao/SyncDAO.java | 42 ++++++++++++++----- .../client/utilities/NotificationID.java | 15 +++++++ 2 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/io/intelehealth/client/utilities/NotificationID.java diff --git a/app/src/main/java/io/intelehealth/client/database/dao/SyncDAO.java b/app/src/main/java/io/intelehealth/client/database/dao/SyncDAO.java index 06705be81f..bed4fe8b14 100755 --- a/app/src/main/java/io/intelehealth/client/database/dao/SyncDAO.java +++ b/app/src/main/java/io/intelehealth/client/database/dao/SyncDAO.java @@ -4,12 +4,14 @@ import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.crashlytics.android.Crashlytics; import com.google.gson.Gson; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import io.intelehealth.client.R; import io.intelehealth.client.app.AppConstants; @@ -22,6 +24,8 @@ import io.intelehealth.client.models.pushResponseApiCall.PushResponseApiCall; import io.intelehealth.client.services.LastSyncIntentService; import io.intelehealth.client.utilities.Logger; +import io.intelehealth.client.utilities.NotificationID; +import io.intelehealth.client.utilities.NotificationUtils; import io.intelehealth.client.utilities.PatientsFrameJson; import io.intelehealth.client.utilities.SessionManager; import io.intelehealth.client.utilities.exception.DAOException; @@ -107,9 +111,28 @@ public void onResponse(Call call, Response response) { AppConstants.notificationUtils.DownloadDone("sync", "failed synced,You can try again", 1, IntelehealthApplication.getAppContext()); if (response.body().getData() != null) { - triggerVisitNotification(response.body().getData().getVisitDTO()); - } + ArrayList listPatientUUID = new ArrayList(); + List listVisitDTO = new ArrayList<>(); + ArrayList encounterVisitUUID = new ArrayList(); + for (int i = 0; i < response.body().getData().getEncounterDTO().size(); i++) { + if (response.body().getData().getEncounterDTO().get(i) + .getEncounterTypeUuid().equalsIgnoreCase("d7151f82-c1f3-4152-a605-2f9ea7414a79")) { + encounterVisitUUID.add(response.body().getData().getEncounterDTO().get(i).getVisituuid()); + } + } + listVisitDTO.addAll(response.body().getData().getVisitDTO()); + for (int i = 0; i < encounterVisitUUID.size() ; i++) { + for (int j = 0; j < listVisitDTO.size(); j++) { + if (encounterVisitUUID.get(i).equalsIgnoreCase(listVisitDTO.get(j).getUuid())){ + listPatientUUID.add(listVisitDTO.get(j).getPatientuuid()); + } + } + } + if (listPatientUUID.size() > 0) { + triggerVisitNotification(listPatientUUID); + } + } } Logger.logD("End Pull request", "Ended"); @@ -128,19 +151,18 @@ public void onFailure(Call call, Throwable t) { return true; } - private void triggerVisitNotification(List listVisitDTO) { + private void triggerVisitNotification(ArrayList listPatientUUID) { List activePatientList = new ArrayList<>(); getPatients(activePatientList); - List visitDTO = new ArrayList<>(); - visitDTO.addAll(listVisitDTO); - - if (visitDTO != null) { - for (int i = 0; i < visitDTO.size(); i++) { + if (listPatientUUID != null) { + for (int i = 0; i < listPatientUUID.size(); i++) { for (int j = 0; j < activePatientList.size(); j++) { - if (visitDTO.get(i).getPatientuuid().equalsIgnoreCase(activePatientList.get(j).getPatientuuid())) { - AppConstants.notificationUtils.DownloadDone(IntelehealthApplication.getAppContext().getResources().getString(R.string.patient) + " " + activePatientList.get(j).getFirst_name() + " " + activePatientList.get(j).getLast_name(), IntelehealthApplication.getAppContext().getResources().getString(R.string.has_a_new_prescription), 2, IntelehealthApplication.getAppContext()); + if (listPatientUUID.get(i).equalsIgnoreCase(activePatientList.get(j).getPatientuuid())) { + Log.e("GET-ID", "" + NotificationID.getID()); + AppConstants.notificationUtils.DownloadDone(IntelehealthApplication.getAppContext().getResources().getString(R.string.patient) + " " + activePatientList.get(j).getFirst_name() + " " + activePatientList.get(j).getLast_name(), + IntelehealthApplication.getAppContext().getResources().getString(R.string.has_a_new_prescription), NotificationID.getID(), IntelehealthApplication.getAppContext()); } } } diff --git a/app/src/main/java/io/intelehealth/client/utilities/NotificationID.java b/app/src/main/java/io/intelehealth/client/utilities/NotificationID.java new file mode 100644 index 0000000000..ba331932ec --- /dev/null +++ b/app/src/main/java/io/intelehealth/client/utilities/NotificationID.java @@ -0,0 +1,15 @@ +package io.intelehealth.client.utilities; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Created by Sagar Shimpi + * Github - sagarS23 + */ +public class NotificationID { + private final static AtomicInteger c = new AtomicInteger(5); + + public static int getID() { + return c.incrementAndGet(); + } +}