diff --git a/lib/core/api_consts.dart b/lib/core/api_consts.dart index fe0b4d5..4acf486 100644 --- a/lib/core/api_consts.dart +++ b/lib/core/api_consts.dart @@ -151,6 +151,7 @@ var GET_FINDUS_REQUEST = 'Services/Lists.svc/REST/Get_HMG_Locations'; ///LiveChat var GET_LIVECHAT_REQUEST = 'Services/Patients.svc/REST/GetPatientICProjects'; +var GET_LIVECHAT_REQUEST_ID = 'Services/Patients.svc/REST/Patient_ICChatRequest_Insert'; ///babyInformation var GET_BABYINFORMATION_REQUEST = 'Services/Community.svc/REST/GetBabyByUserID'; @@ -661,7 +662,7 @@ var GET_PRESCRIPTION_INSTRUCTIONS_PDF = 'Services/ChatBot_Service.svc/REST/Chatb class ApiConsts { static const maxSmallScreen = 660; - static AppEnvironmentTypeEnum appEnvironmentType = AppEnvironmentTypeEnum.uat; + static AppEnvironmentTypeEnum appEnvironmentType = AppEnvironmentTypeEnum.prod; // static String baseUrl = 'https://uat.hmgwebservices.com/'; // HIS API URL UAT diff --git a/lib/core/dependencies.dart b/lib/core/dependencies.dart index bfbccfc..bdcc818 100644 --- a/lib/core/dependencies.dart +++ b/lib/core/dependencies.dart @@ -35,6 +35,7 @@ import 'package:hmg_patient_app_new/features/medical_file/medical_file_repo.dart import 'package:hmg_patient_app_new/features/medical_file/medical_file_view_model.dart'; import 'package:hmg_patient_app_new/features/monthly_report/monthly_report_repo.dart'; import 'package:hmg_patient_app_new/features/monthly_report/monthly_report_view_model.dart'; +import 'package:hmg_patient_app_new/features/monthly_reports/monthly_reports_repo.dart'; import 'package:hmg_patient_app_new/features/my_appointments/appointment_rating_view_model.dart'; import 'package:hmg_patient_app_new/features/my_appointments/appointment_via_region_viewmodel.dart'; import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_repo.dart'; @@ -162,13 +163,13 @@ class AppDependencies { ),); getIt.registerLazySingleton(() => MonthlyReportsRepoImp(loggerService: getIt(), apiClient: getIt())); getIt.registerLazySingleton(() => QrParkingRepoImp(loggerService: getIt(), apiClient: getIt())); - getIt.registerFactory( - () => QrParkingViewModel( - qrParkingRepo: getIt(), - errorHandlerService: getIt(), - cacheService: getIt(), - ), - ); + // getIt.registerFactory( + // () => QrParkingViewModel( + // qrParkingRepo: getIt(), + // errorHandlerService: getIt(), + // cacheService: getIt(), + // ), + // ); // ViewModels // Global/shared VMs → LazySingleton diff --git a/lib/features/contact_us/contact_us_repo.dart b/lib/features/contact_us/contact_us_repo.dart index 3e96f91..5b9057b 100644 --- a/lib/features/contact_us/contact_us_repo.dart +++ b/lib/features/contact_us/contact_us_repo.dart @@ -14,6 +14,8 @@ abstract class ContactUsRepo { Future>>> getLiveChatProjectsList(); + Future>> getChatRequestID({required String name, required String mobileNo, required String workGroup}); + Future>> insertCOCItem({required RequestInsertCOCItem requestInsertCOCItem, PatientAppointmentHistoryResponseModel? patientSelectedAppointment}); } @@ -97,6 +99,45 @@ class ContactUsRepoImp implements ContactUsRepo { } } + @override + Future>> getChatRequestID({required String name, required String mobileNo, required String workGroup}) async { + Map body = {}; + body['Name'] = name; + body['MobileNo'] = mobileNo; + body['WorkGroup'] = workGroup; + + try { + GenericApiModel? apiResponse; + Failure? failure; + await apiClient.post( + GET_LIVECHAT_REQUEST_ID, + body: body, + onFailure: (error, statusCode, {messageStatus, failureType}) { + failure = failureType; + }, + onSuccess: (response, statusCode, {messageStatus, errorMessage}) { + try { + final requestId = response['RequestId'] as String; + + apiResponse = GenericApiModel( + messageStatus: messageStatus, + statusCode: statusCode, + errorMessage: null, + data: requestId, + ); + } catch (e) { + failure = DataParsingFailure(e.toString()); + } + }, + ); + if (failure != null) return Left(failure!); + if (apiResponse == null) return Left(ServerFailure("Unknown error")); + return Right(apiResponse!); + } catch (e) { + return Left(UnknownFailure(e.toString())); + } + } + @override Future>> insertCOCItem({required RequestInsertCOCItem requestInsertCOCItem, PatientAppointmentHistoryResponseModel? patientSelectedAppointment}) async { final Map body = requestInsertCOCItem.toJson(); diff --git a/lib/features/contact_us/contact_us_view_model.dart b/lib/features/contact_us/contact_us_view_model.dart index 1185700..1029802 100644 --- a/lib/features/contact_us/contact_us_view_model.dart +++ b/lib/features/contact_us/contact_us_view_model.dart @@ -29,6 +29,8 @@ class ContactUsViewModel extends ChangeNotifier { int selectedLiveChatProjectIndex = -1; + String? chatRequestID; + List feedbackAttachmentList = []; PatientAppointmentHistoryResponseModel? patientFeedbackSelectedAppointment; @@ -153,6 +155,32 @@ class ContactUsViewModel extends ChangeNotifier { ); } + Future getChatRequestID({required String name, required String mobileNo, required String workGroup, Function(dynamic)? onSuccess, Function(String)? onError}) async { + final result = await contactUsRepo.getChatRequestID(name: name, mobileNo: mobileNo, workGroup: workGroup); + + result.fold( + (failure) async { + await errorHandlerService.handleError(failure: failure); + if (onError != null) { + onError(failure.toString()); + } + }, + (apiResponse) { + if (apiResponse.messageStatus == 2) { + if (onError != null) { + onError(apiResponse.errorMessage ?? 'Unknown error'); + } + } else if (apiResponse.messageStatus == 1) { + chatRequestID = apiResponse.data; + notifyListeners(); + if (onSuccess != null) { + onSuccess(apiResponse); + } + } + }, + ); + } + Future insertCOCItem({required String subject, required String message, Function(dynamic)? onSuccess, Function(String)? onError}) async { RequestInsertCOCItem requestInsertCOCItem = RequestInsertCOCItem(); requestInsertCOCItem.attachment = feedbackAttachmentList.isNotEmpty ? feedbackAttachmentList.first : ""; diff --git a/lib/features/hmg_services/hmg_services_repo.dart b/lib/features/hmg_services/hmg_services_repo.dart index 85e6018..e4b9a03 100644 --- a/lib/features/hmg_services/hmg_services_repo.dart +++ b/lib/features/hmg_services/hmg_services_repo.dart @@ -940,7 +940,16 @@ class HmgServicesRepoImp implements HmgServicesRepo { for (var vitalSignJson in vitalSignsList) { if (vitalSignJson is Map) { - vitalSignList.add(VitalSignResModel.fromJson(vitalSignJson)); + final vitalSign = VitalSignResModel.fromJson(vitalSignJson); + + // Only add records where BOTH height AND weight are greater than 0 + final hasValidWeight = _isValidValue(vitalSign.weightKg); + final hasValidHeight = _isValidValue(vitalSign.heightCm); + + // Only add if both height and weight are valid (> 0) + if (hasValidWeight && hasValidHeight) { + vitalSignList.add(vitalSign); + } } } } @@ -967,5 +976,22 @@ class HmgServicesRepoImp implements HmgServicesRepo { } } + /// Helper method to check if a value is valid (greater than 0) + bool _isValidValue(dynamic value) { + if (value == null) return false; + + if (value is num) { + return value > 0; + } + + if (value is String) { + if (value.trim().isEmpty) return false; + final parsed = double.tryParse(value); + return parsed != null && parsed > 0; + } + + return false; + } + } diff --git a/lib/presentation/contact_us/live_chat_page.dart b/lib/presentation/contact_us/live_chat_page.dart index 7cbdee3..3602c98 100644 --- a/lib/presentation/contact_us/live_chat_page.dart +++ b/lib/presentation/contact_us/live_chat_page.dart @@ -130,9 +130,13 @@ class LiveChatPage extends StatelessWidget { ).paddingSymmetrical(16.h, 16.h), ).onPress(() { contactUsVM.setSelectedLiveChatProjectIndex(index); - chatURL = - "https://chat.hmg.com/Index.aspx?Name=${appState.getAuthenticatedUser()!.firstName}&PatientID=${appState.getAuthenticatedUser()!.patientId}&MobileNo=${appState.getAuthenticatedUser()!.mobileNumber}&Language=${appState.isArabic() ? 'ar' : 'en'}&WorkGroup=${contactUsVM.liveChatProjectsList[index].value}"; - debugPrint("Chat URL: $chatURL"); + _getChatRequestID( + context, + contactUsVM, + name: appState.getAuthenticatedUser()!.firstName ?? '', + mobileNo: appState.getAuthenticatedUser()!.mobileNumber ?? '', + workGroup: contactUsVM.liveChatProjectsList[index].value ?? '', + ); }), ).paddingSymmetrical(24.h, 0.h), ), @@ -155,8 +159,14 @@ class LiveChatPage extends StatelessWidget { child: CustomButton( text: LocaleKeys.liveChat.tr(context: context), onPressed: () async { - Uri uri = Uri.parse(chatURL); - launchUrl(uri, mode: LaunchMode.platformDefault, webOnlyWindowName: ""); + if (contactUsVM.chatRequestID != null) { + chatURL = "https://chat.hmg.com/Index.aspx?RequestedId=${contactUsVM.chatRequestID}"; + debugPrint("Chat URL: $chatURL"); + Uri uri = Uri.parse(chatURL); + launchUrl(uri, mode: LaunchMode.platformDefault, webOnlyWindowName: ""); + } else { + debugPrint("Chat Request ID is null"); + } }, backgroundColor: contactUsVM.selectedLiveChatProjectIndex == -1 ? AppColors.greyColor : AppColors.primaryRedColor, borderColor: contactUsVM.selectedLiveChatProjectIndex == -1 ? AppColors.greyColor : AppColors.primaryRedColor, @@ -173,4 +183,20 @@ class LiveChatPage extends StatelessWidget { }), ); } + + void _getChatRequestID(BuildContext context, ContactUsViewModel contactUsVM, {required String name, required String mobileNo, required String workGroup}) { + contactUsVM.getChatRequestID( + name: name, + mobileNo: mobileNo, + workGroup: workGroup, + onSuccess: (response) { + debugPrint("Chat Request ID received: ${contactUsVM.chatRequestID}"); + chatURL = "https://chat.hmg.com/Index.aspx?RequestedId=${contactUsVM.chatRequestID}"; + debugPrint("Chat URL: $chatURL"); + }, + onError: (error) { + debugPrint("Error getting chat request ID: $error"); + }, + ); + } } diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart index 059969c..d183d02 100644 --- a/lib/routes/app_routes.dart +++ b/lib/routes/app_routes.dart @@ -85,7 +85,8 @@ class AppRoutes { static const String addHealthTrackerEntryPage = '/addHealthTrackerEntryPage'; static const String healthTrackerDetailPage = '/healthTrackerDetailPage'; - static Map get routes => { + static Map get routes => + { initialRoute: (context) => SplashPage(), loginScreen: (context) => LoginScreen(), landingScreen: (context) => LandingNavigation(), @@ -116,27 +117,37 @@ class AppRoutes { healthTrackersPage: (context) => HealthTrackersPage(), vitalSign: (context) => VitalSignPage(), addHealthTrackerEntryPage: (context) { - final args = ModalRoute.of(context)?.settings.arguments as HealthTrackerTypeEnum?; + final args = ModalRoute + .of(context) + ?.settings + .arguments as HealthTrackerTypeEnum?; return AddHealthTrackerEntryPage( trackerType: args ?? HealthTrackerTypeEnum.bloodSugar, ); }, healthTrackerDetailPage: (context) { - final args = ModalRoute.of(context)?.settings.arguments as HealthTrackerTypeEnum?; + final args = ModalRoute + .of(context) + ?.settings + .arguments as HealthTrackerTypeEnum?; return HealthTrackerDetailPage( trackerType: args ?? HealthTrackerTypeEnum.bloodSugar, ); - - monthlyReports: (context) => ChangeNotifierProvider( - create: (_) => MonthlyReportsViewModel( - monthlyReportsRepo: getIt(), - errorHandlerService: getIt(), + }, + monthlyReports: (context) => + ChangeNotifierProvider( + create: (_) => + MonthlyReportsViewModel( + monthlyReportsRepo: getIt(), + errorHandlerService: getIt(), + ), + child: const MonthlyReportsPage(), ), - child: const MonthlyReportsPage(), - ), + qrParking: (context) => ChangeNotifierProvider( create: (_) => getIt(), child: const ParkingPage(), - }, - }; + ) + }; + }