From 243097b8e0bf2f63e9860bfdb74488fcd52d6d71 Mon Sep 17 00:00:00 2001 From: Kaveri Date: Mon, 3 Jun 2024 10:33:18 +0530 Subject: [PATCH 1/3] Visit upload time attribute sent --- .../VisitSummaryActivity.java | 13 +++++++- .../database/dao/VisitAttributeListDAO.java | 32 +++++++++++++++++++ .../app/utilities/DateAndTimeUtils.java | 6 ++-- .../app/utilities/UuidDictionary.java | 1 + 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/intelehealth/app/activities/visitSummaryActivity/VisitSummaryActivity.java b/app/src/main/java/org/intelehealth/app/activities/visitSummaryActivity/VisitSummaryActivity.java index 11a5fac550..53f617745e 100644 --- a/app/src/main/java/org/intelehealth/app/activities/visitSummaryActivity/VisitSummaryActivity.java +++ b/app/src/main/java/org/intelehealth/app/activities/visitSummaryActivity/VisitSummaryActivity.java @@ -1098,7 +1098,16 @@ public void onClick(View view) { e.printStackTrace(); Log.d("Update_Special_Visit", "Update_Special_Visit: " + isUpdateVisitDone); } - + String uploadTime = AppConstants.dateAndTimeUtils.getVisitUploadDateTime(); + VisitAttributeListDAO upload_time_attributes = new VisitAttributeListDAO(); + boolean isUpdateUploadTimeDone = false; + try { + if (!isVisitSpecialityExists) { + isUpdateUploadTimeDone = upload_time_attributes.insertVisitAttributesUploadTime(visitUUID, uploadTime); + } + } catch (DAOException exception) { + exception.printStackTrace(); + } if (isVisitSpecialityExists) { speciality_spinner.setEnabled(false); @@ -5092,6 +5101,8 @@ public void onResponse(Call call, Response respo @Override public void onFailure(Call call, Throwable t) { + t.printStackTrace(); + Log.d(TAG, "onFailure: t :: "+t.getLocalizedMessage()); Log.v("onFailure", t.getMessage()); } }); diff --git a/app/src/main/java/org/intelehealth/app/database/dao/VisitAttributeListDAO.java b/app/src/main/java/org/intelehealth/app/database/dao/VisitAttributeListDAO.java index 0768cf49e9..326ab276ed 100644 --- a/app/src/main/java/org/intelehealth/app/database/dao/VisitAttributeListDAO.java +++ b/app/src/main/java/org/intelehealth/app/database/dao/VisitAttributeListDAO.java @@ -11,6 +11,7 @@ import org.intelehealth.app.app.AppConstants; import org.intelehealth.app.models.dto.VisitAttributeDTO; +import org.intelehealth.app.utilities.UuidDictionary; import org.intelehealth.app.utilities.exception.DAOException; /** @@ -158,4 +159,35 @@ public String getVisitID(String visitUUID) { db.endTransaction(); return visit_id; } + + public boolean insertVisitAttributesUploadTime(String visitUuid, String uploadTime) throws DAOException { + boolean isInserted = false; + + SQLiteDatabase db = AppConstants.inteleHealthDatabaseHelper.getWriteDb(); + db.beginTransaction(); + ContentValues values = new ContentValues(); + try { + values.put("uuid", UUID.randomUUID().toString()); //as per patient attributes uuid generation. + values.put("visit_uuid", visitUuid); + values.put("value", uploadTime); + values.put("visit_attribute_type_uuid", UuidDictionary.ATTRIBUTE_TIME_OF_UPLOAD_BUTTON_CLICK); + values.put("voided", "0"); + values.put("sync", "0"); + + long count = db.insertWithOnConflict("tbl_visit_attribute", null, values, SQLiteDatabase.CONFLICT_REPLACE); + if (count != -1) { + isInserted = true; + } + + db.setTransactionSuccessful(); + } catch (SQLException e) { + isInserted = false; + throw new DAOException(e.getMessage(), e); + } finally { + db.endTransaction(); + } + + Log.d("isInserted", "isInserted: " + isInserted); + return isInserted; + } } \ No newline at end of file diff --git a/app/src/main/java/org/intelehealth/app/utilities/DateAndTimeUtils.java b/app/src/main/java/org/intelehealth/app/utilities/DateAndTimeUtils.java index dc3223f405..1b7ccc2d6a 100644 --- a/app/src/main/java/org/intelehealth/app/utilities/DateAndTimeUtils.java +++ b/app/src/main/java/org/intelehealth/app/utilities/DateAndTimeUtils.java @@ -414,6 +414,8 @@ public static String minus_MinutesAgo(String timeStamp, int minute) throws Parse return df.format(new Date(time - FIVE_MINS_IN_MILLIS)); } - - + public String getVisitUploadDateTime() { + DateFormat date = new SimpleDateFormat("dd MMM yyyy HH:mm:ss", Locale.ENGLISH); + return date.format(new Date()); + } } diff --git a/app/src/main/java/org/intelehealth/app/utilities/UuidDictionary.java b/app/src/main/java/org/intelehealth/app/utilities/UuidDictionary.java index 41b0c49c6e..e461d65f53 100644 --- a/app/src/main/java/org/intelehealth/app/utilities/UuidDictionary.java +++ b/app/src/main/java/org/intelehealth/app/utilities/UuidDictionary.java @@ -89,5 +89,6 @@ public class UuidDictionary { public static final String BILL_PRICE_TOTAL_CHOLESTEROL_ID = "9d2f0fcc-538f-11e6-9cfe-86f436325720"; public static final String BILL_PRICE_BP_ID = "dd51ab03-12ef-43cb-9aef-2ec93a989816"; public static final String BILL_NUM = "9fa03f61-8083-4cce-bbc0-d5f752a8ee7b"; + public static final String ATTRIBUTE_TIME_OF_UPLOAD_BUTTON_CLICK = "9fa03f61-8083-4cce-bbc0-d5f752a8ee7b"; } From db7810c4cd106d3c40a09d9995a3d318afd14e21 Mon Sep 17 00:00:00 2001 From: Kaveri Date: Tue, 4 Jun 2024 15:39:07 +0530 Subject: [PATCH 2/3] NAS-338 issue resolved NAS-321 completed --- .../VisitSummaryActivity.java | 40 +++++++++---------- .../app/appointment/model/CancelRequest.java | 14 +++++++ .../database/dao/VisitAttributeListDAO.java | 10 +++-- .../app/database/dao/VisitsDAO.java | 5 +-- .../app/utilities/UuidDictionary.java | 3 +- 5 files changed, 43 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/org/intelehealth/app/activities/visitSummaryActivity/VisitSummaryActivity.java b/app/src/main/java/org/intelehealth/app/activities/visitSummaryActivity/VisitSummaryActivity.java index 53f617745e..867bb2e1d2 100644 --- a/app/src/main/java/org/intelehealth/app/activities/visitSummaryActivity/VisitSummaryActivity.java +++ b/app/src/main/java/org/intelehealth/app/activities/visitSummaryActivity/VisitSummaryActivity.java @@ -5,6 +5,7 @@ import static org.intelehealth.app.utilities.UuidDictionary.ENCOUNTER_ROLE; import static org.intelehealth.app.utilities.UuidDictionary.ENCOUNTER_VISIT_NOTE; import static org.intelehealth.app.utilities.UuidDictionary.FOLLOW_UP_VISIT; +import static org.intelehealth.app.utilities.UuidDictionary.VISIT_SPECIALITY; import android.app.DatePickerDialog; import android.app.Dialog; @@ -384,7 +385,7 @@ public class VisitSummaryActivity extends AppCompatActivity /*implements Printer private PrinterInterface curPrinterInterface = null; IntelehealthApplication application;*/ - private void collectChatConnectionInfoFromFirebase() { + private void collectChatConnectionInfoFromFirebase() { FirebaseDatabase database = FirebaseDatabase.getInstance(AppConstants.getFirebaseRTDBUrl()); DatabaseReference chatDatabaseReference = database.getReference(AppConstants.getFirebaseRTDBRootRefForTextChatConnInfo() + "/" + visitUuid); chatDatabaseReference.addValueEventListener(new ValueEventListener() { @@ -469,7 +470,7 @@ public void registerBroadcastReceiverDynamically() { public void registerDownloadPrescription() { IntentFilter filter = new IntentFilter(); filter.addAction("downloadprescription"); - ContextCompat.registerReceiver(this,downloadPrescriptionService, filter,ContextCompat.RECEIVER_NOT_EXPORTED); + ContextCompat.registerReceiver(this, downloadPrescriptionService, filter, ContextCompat.RECEIVER_NOT_EXPORTED); } @@ -931,7 +932,7 @@ public void onClick(DialogInterface dialog, int which) { List items = providerAttributeLIstDAO.getAllValues(); items.remove("All"); Log.d("specc", "spec: " + visitUuid); - String special_value = visitAttributeListDAO.getVisitAttributesList_specificVisit(visitUuid); + String special_value = visitAttributeListDAO.getVisitAttributesList_specificVisit(visitUuid, VISIT_SPECIALITY); //Hashmap to List add all value ArrayAdapter stringArrayAdapter; @@ -945,6 +946,7 @@ public void onClick(DialogInterface dialog, int which) { speciality_spinner.setAdapter(stringArrayAdapter); } + Log.d(TAG, "onCreate: special_value : " + special_value); if (special_value != null) { int spinner_position = stringArrayAdapter.getPosition(special_value); speciality_spinner.setSelection(spinner_position); @@ -2017,9 +2019,8 @@ public void onClick(View v) { String remark = fuData.substring(fuData.indexOf(",")); showFollowupRescheduleDialog(remark); Log.d(TAG, "reschedule btn: " + remark); - } - else { // ie. 08-08-2023 - // followupDate = fuData; + } else { // ie. 08-08-2023 + // followupDate = fuData; showFollowupRescheduleDialog(null); } Log.d(TAG, "reschedule btn: " + followupDate); @@ -2095,10 +2096,7 @@ else if (et_date.getText().toString().trim().isEmpty() && !et_reason.getText().t else if (!et_date.getText().toString().trim().isEmpty() && et_reason.getText().toString().trim().isEmpty()) { et_reason.requestFocus(); et_reason.setError(context.getString(R.string.error_field_required)); - } - - - else { // ie. date is not empty ie. user has selected the date from the date picker. + } else { // ie. date is not empty ie. user has selected the date from the date picker. et_date.setError(null); et_reason.setError(null); @@ -2106,7 +2104,7 @@ else if (!et_date.getText().toString().trim().isEmpty() && et_reason.getText().t String reasonValue = et_reason.getText().toString().trim(); if (remark != null) - followupValue = followupValue + remark; // ie. 08-08-2023, Remark: abc + followupValue = followupValue + remark; // ie. 08-08-2023, Remark: abc Log.d(TAG, "showFollowupRescheduleDialog: " + followupValue); try { @@ -2180,8 +2178,7 @@ private void update_insertIntoDb_PushFollowupValues(String followupValue, String encounterTIME_MINUS_ONE_MINUTE = formatDateFromOnetoAnother (visitendDate, "MMM dd, yyyy hh:mm:ss a", "yyyy-MM-dd'T'HH:mm:ss.SSSZ"); encounterTIME_MINUS_ONE_MINUTE = minus_MinutesAgo(encounterTIME_MINUS_ONE_MINUTE, 1); // ie. minus 1mins. - } - else { + } else { encounterTIME_MINUS_ONE_MINUTE = AppConstants.dateAndTimeUtils.currentDateTime(); } @@ -2334,6 +2331,7 @@ private boolean speciality_row_exist_check(String uuid) { /** * starting chat activity here + * * @param view */ public void startTextChat(View view) { @@ -4203,8 +4201,7 @@ private void parseData(String concept_id, String value) { String fuData = followUpDateTextView.getText().toString().trim(); if (!fuData.isEmpty() && (fuData.contains(",") || !fuData.contains("Remark"))) { // ie. date is present and this can we changed too. followupRescheduleBtn.setVisibility(View.VISIBLE); - } - else + } else followupRescheduleBtn.setVisibility(View.GONE); } @@ -4306,7 +4303,7 @@ public void callBroadcastReceiver() { if (!isReceiverRegistered) { IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); receiver = new NetworkChangeReceiver(); - ContextCompat.registerReceiver(this,receiver, filter,ContextCompat.RECEIVER_NOT_EXPORTED); + ContextCompat.registerReceiver(this, receiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED); isReceiverRegistered = true; } } @@ -4797,7 +4794,7 @@ public void downloadPrescriptionDefault() { protected void onStart() { registerDownloadPrescription(); callBroadcastReceiver(); - ContextCompat.registerReceiver(this,(mMessageReceiver), new IntentFilter(FILTER),ContextCompat.RECEIVER_NOT_EXPORTED); + ContextCompat.registerReceiver(this, (mMessageReceiver), new IntentFilter(FILTER), ContextCompat.RECEIVER_NOT_EXPORTED); super.onStart(); } @@ -5078,6 +5075,8 @@ public void onClick(DialogInterface dialogInterface, int i) { CancelRequest request = new CancelRequest(); request.setVisitUuid(mAppointmentDetailsResponse.getData().getVisitUuid()); request.setId(mAppointmentDetailsResponse.getData().getId()); + request.setHwUUID(mAppointmentDetailsResponse.getData().getUserUuid()); + Log.d(TAG, "onClick: CancelRequest : " + new Gson().toJson(request)); String baseurl = "https://" + sessionManager.getServerUrl() + ":3004"; ApiClientAppointment.getInstance(baseurl).getApi().cancelAppointment(request).enqueue(new Callback() { @Override @@ -5102,7 +5101,7 @@ public void onResponse(Call call, Response respo @Override public void onFailure(Call call, Throwable t) { t.printStackTrace(); - Log.d(TAG, "onFailure: t :: "+t.getLocalizedMessage()); + Log.d(TAG, "onFailure: t :: " + t.getLocalizedMessage()); Log.v("onFailure", t.getMessage()); } }); @@ -5346,11 +5345,10 @@ private String sms_prescription() { if (advice_doctor__.indexOf("Start") != -1 || advice_doctor__.lastIndexOf(("Doctor_") + 9) != -1) { String advice_split = new StringBuilder(advice_doctor__).delete(advice_doctor__.indexOf("Start"), advice_doctor__.lastIndexOf("Doctor_") + 9).toString(); - advice_web = stringToWeb(advice_split.replace("\n\n", "\n")); //showing advice here... + advice_web = stringToWeb(advice_split.replace("\n\n", "\n")); //showing advice here... advice_web = advice_web.replace(Node.big_bullet, "- "); Log.d("Hyperlink", "hyper_print: " + advice_web); //gets called when clicked on button of print button - } - else { + } else { advice_web = stringToWeb(advice_doctor__.replace("\n\n", "\n")); //showing advice here... advice_web = advice_web.replace(Node.big_bullet, "- "); Log.d("Hyperlink", "hyper_print: " + advice_web); //gets called when clicked on button of print button diff --git a/app/src/main/java/org/intelehealth/app/appointment/model/CancelRequest.java b/app/src/main/java/org/intelehealth/app/appointment/model/CancelRequest.java index ca5fb0952f..60dfb085b4 100644 --- a/app/src/main/java/org/intelehealth/app/appointment/model/CancelRequest.java +++ b/app/src/main/java/org/intelehealth/app/appointment/model/CancelRequest.java @@ -5,6 +5,17 @@ import java.io.Serializable; public class CancelRequest implements Serializable { + public int getId() { + return id; + } + + public String getHwUUID() { + return hwUUID; + } + + public void setHwUUID(String hwUUID) { + this.hwUUID = hwUUID; + } @SerializedName("id") private int id; @@ -12,6 +23,9 @@ public class CancelRequest implements Serializable { @SerializedName("visitUuid") private String visitUuid; + @SerializedName("hwUUID") + private String hwUUID; + public String getVisitUuid() { return visitUuid; diff --git a/app/src/main/java/org/intelehealth/app/database/dao/VisitAttributeListDAO.java b/app/src/main/java/org/intelehealth/app/database/dao/VisitAttributeListDAO.java index 326ab276ed..2a1d65ef98 100644 --- a/app/src/main/java/org/intelehealth/app/database/dao/VisitAttributeListDAO.java +++ b/app/src/main/java/org/intelehealth/app/database/dao/VisitAttributeListDAO.java @@ -82,15 +82,17 @@ private boolean createVisitAttributeList(VisitAttributeDTO visitDTO, SQLiteDatab return isCreated; } - public String getVisitAttributesList_specificVisit(String VISITUUID) { + public String getVisitAttributesList_specificVisit(String VISITUUID, String visit_attribute_type_uuid) { String isValue = ""; Log.d("specc", "spec_fun: " + VISITUUID); SQLiteDatabase db = AppConstants.inteleHealthDatabaseHelper.getWritableDatabase(); db.beginTransaction(); - Cursor cursor = db.rawQuery("SELECT value FROM tbl_visit_attribute WHERE visit_uuid = ?", - new String[]{VISITUUID}); - + /* Cursor cursor = db.rawQuery("SELECT value FROM tbl_visit_attribute WHERE visit_uuid = ?", + new String[]{VISITUUID});*/ + Cursor cursor = db.rawQuery("SELECT value FROM tbl_visit_attribute WHERE visit_uuid = ? and " + + "visit_attribute_type_uuid = ? and voided = 0", + new String[]{VISITUUID, visit_attribute_type_uuid}); if (cursor.getCount() != 0) { while (cursor.moveToNext()) { isValue = cursor.getString(cursor.getColumnIndexOrThrow("value")); diff --git a/app/src/main/java/org/intelehealth/app/database/dao/VisitsDAO.java b/app/src/main/java/org/intelehealth/app/database/dao/VisitsDAO.java index 5720e11907..b01a98c599 100644 --- a/app/src/main/java/org/intelehealth/app/database/dao/VisitsDAO.java +++ b/app/src/main/java/org/intelehealth/app/database/dao/VisitsDAO.java @@ -279,7 +279,6 @@ public List unsyncedVisits() { private List fetchVisitAttr_Speciality(String visit_uuid) { List list = new ArrayList<>(); - VisitAttribute_Speciality speciality = new VisitAttribute_Speciality(); SQLiteDatabase db = AppConstants.inteleHealthDatabaseHelper.getWriteDb(); db.beginTransaction(); @@ -288,7 +287,7 @@ private List fetchVisitAttr_Speciality(String visit_u if (cursor.getCount() != 0) { while (cursor.moveToNext()) { - + VisitAttribute_Speciality speciality = new VisitAttribute_Speciality(); speciality.setUuid(cursor.getString(cursor.getColumnIndexOrThrow("uuid"))); speciality.setAttributeType(cursor.getString(cursor.getColumnIndexOrThrow("visit_attribute_type_uuid"))); speciality.setValue(cursor.getString(cursor.getColumnIndexOrThrow("value"))); @@ -324,7 +323,7 @@ public List getAllVisits() { idCursor.close(); db.setTransactionSuccessful(); db.endTransaction(); - // db.close(); // NAS-172: no need to close db instance this causes the issue of Sqlite object being closed - Prajwal. + // db.close(); // NAS-172: no need to close db instance this causes the issue of Sqlite object being closed - Prajwal. return visitDTOList; } diff --git a/app/src/main/java/org/intelehealth/app/utilities/UuidDictionary.java b/app/src/main/java/org/intelehealth/app/utilities/UuidDictionary.java index e461d65f53..268b8520a6 100644 --- a/app/src/main/java/org/intelehealth/app/utilities/UuidDictionary.java +++ b/app/src/main/java/org/intelehealth/app/utilities/UuidDictionary.java @@ -89,6 +89,7 @@ public class UuidDictionary { public static final String BILL_PRICE_TOTAL_CHOLESTEROL_ID = "9d2f0fcc-538f-11e6-9cfe-86f436325720"; public static final String BILL_PRICE_BP_ID = "dd51ab03-12ef-43cb-9aef-2ec93a989816"; public static final String BILL_NUM = "9fa03f61-8083-4cce-bbc0-d5f752a8ee7b"; - public static final String ATTRIBUTE_TIME_OF_UPLOAD_BUTTON_CLICK = "9fa03f61-8083-4cce-bbc0-d5f752a8ee7b"; + public static final String ATTRIBUTE_TIME_OF_UPLOAD_BUTTON_CLICK = "ce364c8a-4cb7-4a3b-929e-6311ddcadc01"; + public static final String VISIT_SPECIALITY = "3f296939-c6d3-4d2e-b8ca-d7f4bfd42c2d"; } From bcf9c68c3802f78faadbe1b61358c8ff69428069 Mon Sep 17 00:00:00 2001 From: Kaveri Date: Wed, 12 Jun 2024 15:34:38 +0530 Subject: [PATCH 3/3] NAS-357 related changes --- .../app/app/IntelehealthApplication.java | 8 +++- .../intelehealth/app/shared/BaseActivity.java | 13 ++++-- .../app/utilities/NotificationUtils.java | 42 ++++++++++++++++++ .../receiver/FCMNotificationReceiver.kt | 43 ++++++++++++------- .../klivekit/model/ChatMessage.java | 11 +++++ 5 files changed, 96 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/org/intelehealth/app/app/IntelehealthApplication.java b/app/src/main/java/org/intelehealth/app/app/IntelehealthApplication.java index 8bb5abe587..5e0d8c5175 100644 --- a/app/src/main/java/org/intelehealth/app/app/IntelehealthApplication.java +++ b/app/src/main/java/org/intelehealth/app/app/IntelehealthApplication.java @@ -37,6 +37,7 @@ import io.reactivex.plugins.RxJavaPlugins; import okhttp3.Dispatcher; import okhttp3.OkHttpClient; + import com.rt.printerlibrary.printer.RTPrinter; //Extend Application class with MultiDexApplication for multidex support @@ -65,9 +66,11 @@ public static String getAndroidId() { private static IntelehealthApplication sIntelehealthApplication; public String refreshedFCMTokenID = ""; public String webrtcTempCallId = ""; + public static IntelehealthApplication getInstance() { return sIntelehealthApplication; } + private final SocketManager socketManager = SocketManager.getInstance(); @@ -88,7 +91,7 @@ public void onCreate() { // keeping the base url in one singleton object for using in apprtc module // Initialize - // EzdxBT.initialize(getApplicationContext()); + // EzdxBT.initialize(getApplicationContext()); configureCrashReporting(); RxJavaPlugins.setErrorHandler(throwable -> { @@ -122,6 +125,9 @@ public void onCreate() { } initSocketConnection(); registerActivityLifecycleCallbacks(this); + if (BuildConfig.DEBUG) { + Timber.plant(Timber.DebugTree()); + } } private void configureCrashReporting() { diff --git a/app/src/main/java/org/intelehealth/app/shared/BaseActivity.java b/app/src/main/java/org/intelehealth/app/shared/BaseActivity.java index e65eb333ea..fde6e024e4 100644 --- a/app/src/main/java/org/intelehealth/app/shared/BaseActivity.java +++ b/app/src/main/java/org/intelehealth/app/shared/BaseActivity.java @@ -1,6 +1,9 @@ package org.intelehealth.app.shared; +import static org.intelehealth.app.utilities.NotificationUtils.saveChatInfoLog; + import android.os.Bundle; +import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -11,6 +14,7 @@ import org.intelehealth.app.database.dao.ProviderDAO; import org.intelehealth.app.database.dao.RTCConnectionDAO; import org.intelehealth.app.models.dto.RTCConnectionDTO; +import org.intelehealth.app.utilities.NotificationUtils; import org.intelehealth.app.utilities.exception.DAOException; import org.intelehealth.app.webrtc.activity.NASChatActivity; import org.intelehealth.app.webrtc.notification.AppNotification; @@ -36,7 +40,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { @Override public void showNotification(@NonNull ChatMessage chatMessage) { - RtcArgs args = new RtcArgs(); + NotificationUtils.sendChatNotification(this, chatMessage); + /* RtcArgs args = new RtcArgs(); args.setPatientName(chatMessage.getPatientName()); args.setPatientId(chatMessage.getPatientId()); args.setVisitId(chatMessage.getVisitId()); @@ -53,16 +58,16 @@ public void showNotification(@NonNull ChatMessage chatMessage) { saveChatInfoLog(args.getVisitId(), args.getDoctorUuid()); } catch (DAOException e) { throw new RuntimeException(e); - } + }*/ } - private void saveChatInfoLog(String visitId, String doctorId) throws DAOException { + /* private void saveChatInfoLog(String visitId, String doctorId) throws DAOException { RTCConnectionDTO rtcDto = new RTCConnectionDTO(); rtcDto.setUuid(UUID.randomUUID().toString()); rtcDto.setVisitUUID(visitId); rtcDto.setConnectionInfo(doctorId); new RTCConnectionDAO().insert(rtcDto); - } + }*/ @Override public void saveTheDoctor(@NonNull ChatMessage chatMessage) { diff --git a/app/src/main/java/org/intelehealth/app/utilities/NotificationUtils.java b/app/src/main/java/org/intelehealth/app/utilities/NotificationUtils.java index cbfbbbc0c6..8d4713d6a1 100644 --- a/app/src/main/java/org/intelehealth/app/utilities/NotificationUtils.java +++ b/app/src/main/java/org/intelehealth/app/utilities/NotificationUtils.java @@ -6,10 +6,21 @@ import android.app.PendingIntent; import android.content.Context; import android.os.Build; +import android.util.Log; import androidx.core.app.NotificationCompat; import org.intelehealth.app.R; +import org.intelehealth.app.database.dao.ProviderDAO; +import org.intelehealth.app.database.dao.RTCConnectionDAO; +import org.intelehealth.app.models.dto.RTCConnectionDTO; +import org.intelehealth.app.utilities.exception.DAOException; +import org.intelehealth.app.webrtc.activity.NASChatActivity; +import org.intelehealth.app.webrtc.notification.AppNotification; +import org.intelehealth.klivekit.model.ChatMessage; +import org.intelehealth.klivekit.model.RtcArgs; + +import java.util.UUID; public class NotificationUtils { @@ -135,4 +146,35 @@ public static int getPendingIntentFlag() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT : PendingIntent.FLAG_UPDATE_CURRENT; } + + public static void sendChatNotification(Context context, ChatMessage chatMessage){ + RtcArgs args = new RtcArgs(); + args.setPatientName(chatMessage.getPatientName()); + args.setPatientId(chatMessage.getPatientId()); + args.setVisitId(chatMessage.getVisitId()); + args.setNurseId(chatMessage.getToUser()); + args.setDoctorUuid(chatMessage.getFromUser()); + try { + String title = new ProviderDAO().getProviderName(args.getDoctorUuid()); + new AppNotification.Builder(context) + .title(title) + .body(chatMessage.getMessage()) + .pendingIntent(NASChatActivity.getPendingIntent(context, args)) + .send(); + + saveChatInfoLog(args.getVisitId(), args.getDoctorUuid()); + } catch (DAOException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + + } + public static void saveChatInfoLog(String visitId, String doctorId) throws DAOException { + RTCConnectionDTO rtcDto = new RTCConnectionDTO(); + rtcDto.setUuid(UUID.randomUUID().toString()); + rtcDto.setVisitUUID(visitId); + rtcDto.setConnectionInfo(doctorId); + new RTCConnectionDAO().insert(rtcDto); + } + } diff --git a/app/src/main/java/org/intelehealth/app/webrtc/receiver/FCMNotificationReceiver.kt b/app/src/main/java/org/intelehealth/app/webrtc/receiver/FCMNotificationReceiver.kt index b1cae004ae..b8d632084c 100644 --- a/app/src/main/java/org/intelehealth/app/webrtc/receiver/FCMNotificationReceiver.kt +++ b/app/src/main/java/org/intelehealth/app/webrtc/receiver/FCMNotificationReceiver.kt @@ -3,6 +3,7 @@ package org.intelehealth.app.webrtc.receiver import android.app.PendingIntent import android.content.Context import android.content.Intent +import android.util.Log import com.github.ajalt.timberkt.Timber import com.google.firebase.messaging.RemoteMessage import com.google.gson.Gson @@ -20,7 +21,11 @@ import org.intelehealth.klivekit.call.utils.CallHandlerUtils import org.intelehealth.klivekit.call.utils.CallMode import org.intelehealth.klivekit.call.utils.CallType import org.intelehealth.klivekit.call.utils.IntentUtils +import org.intelehealth.klivekit.chat.model.ChatMessageModel +import org.intelehealth.klivekit.chat.utils.MySharedPreferences +import org.intelehealth.klivekit.model.ChatMessage import org.intelehealth.klivekit.model.RtcArgs +import org.intelehealth.klivekit.socket.SocketManager import org.intelehealth.klivekit.utils.extensions.fromJson /** @@ -30,11 +35,13 @@ import org.intelehealth.klivekit.utils.extensions.fromJson **/ class FCMNotificationReceiver : FcmBroadcastReceiver() { override fun onMessageReceived( - context: Context?, - notification: RemoteMessage.Notification?, - data: HashMap + context: Context?, + notification: RemoteMessage.Notification?, + data: HashMap ) { - Timber.tag(TAG).d("onMessageReceived: ") + Timber.tag(TAG).d("onMessageReceived: data : ${Gson().toJson(data)}") + Timber.tag(TAG).d("onMessageReceived: notification : ${Gson().toJson(notification)}") + val sessionManager = SessionManager(context) if (sessionManager.isLogout) return context?.let { @@ -47,13 +54,13 @@ class FCMNotificationReceiver : FcmBroadcastReceiver() { socketUrl = IntelehealthApplication.getInstance().socketUrl PatientsDAO().getPatientName(roomId).apply { patientName = "" - if(isNotEmpty()){ + if (isNotEmpty()) { patientName = get(0).name } } }.also { arg -> - Timber.tag(TAG).d("onMessageReceived: $arg") + Timber.tag(TAG).d("lllonMessageReceived: $arg") if (isAppInForeground()) { arg.callMode = CallMode.INCOMING CallHandlerUtils.saveIncomingCall(context, arg) @@ -62,6 +69,10 @@ class FCMNotificationReceiver : FcmBroadcastReceiver() { CallHandlerUtils.operateIncomingCall(it, arg) } } + } else if (data.containsKey("actionType") && data["actionType"].equals("TEXT_CHAT")) { + Gson().fromJson(Gson().toJson(data)).apply { + NotificationUtils.sendChatNotification(context, this); + } } else { parseMessage(notification, context) } @@ -96,19 +107,19 @@ class FCMNotificationReceiver : FcmBroadcastReceiver() { val notificationIntent = Intent(context, HomeActivity::class.java) notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) val pendingIntent = PendingIntent.getActivity( - context, - 0, - notificationIntent, - NotificationUtils.getPendingIntentFlag() + context, + 0, + notificationIntent, + NotificationUtils.getPendingIntentFlag() ) FcmNotification.Builder(context) - .channelName("EKAL") - .title(messageTitle ?: "Ekal") - .content(messageBody ?: "") - .smallIcon(R.mipmap.ic_launcher) - .contentIntent(pendingIntent) - .build().startNotify() + .channelName("EKAL") + .title(messageTitle ?: "Ekal") + .content(messageBody ?: "") + .smallIcon(R.mipmap.ic_launcher) + .contentIntent(pendingIntent) + .build().startNotify() // val channelId = "CHANNEL_ID" // val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) diff --git a/klivekit/src/main/java/org/intelehealth/klivekit/model/ChatMessage.java b/klivekit/src/main/java/org/intelehealth/klivekit/model/ChatMessage.java index 1c1955de2d..beb6162d60 100644 --- a/klivekit/src/main/java/org/intelehealth/klivekit/model/ChatMessage.java +++ b/klivekit/src/main/java/org/intelehealth/klivekit/model/ChatMessage.java @@ -221,4 +221,15 @@ public String getOpenMrsId() { public void setOpenMrsId(String openMrsId) { this.openMrsId = openMrsId; } + + @SerializedName("title") + private String title; + + @SerializedName("body") + private String body; + + @SerializedName("actionType") + private String actionType; + + }