From d9b6e9fed8d7c824f33a98ca6433667ccb485fd8 Mon Sep 17 00:00:00 2001 From: Sultan khan Date: Sat, 18 Apr 2026 10:37:30 +0300 Subject: [PATCH] fixes and updates --- lib/core/utils/calender_utils_new.dart | 20 ++++--- .../appointment_details_page.dart | 2 +- .../emergency_services/nearest_er_page.dart | 29 +++++++++++ .../habib_wallet/habib_wallet_page.dart | 52 +++++++++---------- .../possible_conditions_screen.dart | 19 +++++++ lib/widgets/appbar/collapsing_list_view.dart | 8 ++- 6 files changed, 90 insertions(+), 40 deletions(-) diff --git a/lib/core/utils/calender_utils_new.dart b/lib/core/utils/calender_utils_new.dart index 441214b5..59c0e170 100644 --- a/lib/core/utils/calender_utils_new.dart +++ b/lib/core/utils/calender_utils_new.dart @@ -131,13 +131,17 @@ class CalenderUtilsNew { print("the frequency is $frequencyNumber"); frequencyNumber ??= 2; //Some time frequency number is null so by default will be 2 int interval = calculateIntervalAsPerFrequency(frequencyNumber); - // int remainingDays = days - (Jiffy.parseFromDateTime(DateTime.now()).diff(Jiffy.parseFromDateTime(DateUtil.convertStringToDate(orderDate)), unit: Unit.day) as int); - Duration difference = (actualDate.difference(DateUtil.convertStringToDate(orderDate))); - int remainingDays = 5; - // if (remainingDays.isNegative) { - // onFailure?.call("Prescription date has been already passed you can not add a reminder for this prescription."); - // return false; - // } + + // Calculate remaining days based on prescription days and order date + DateTime orderDateTime = DateUtil.convertStringToDate(orderDate); + int daysSinceOrder = DateTime.now().difference(orderDateTime).inDays; + int remainingDays = days - daysSinceOrder; + + // Validate that prescription is still active + if (remainingDays <= 0) { + onFailure?.call("Prescription date has already passed. You cannot add a reminder for this prescription."); + return false; + } bool statusOfOperation = false; @@ -156,7 +160,7 @@ class CalenderUtilsNew { actualDate = actualDate.add(Duration(hours: interval)); // if (actualDate.difference(currentDay).inDays == 1) break; } - // actualDate = actualDate.add(Duration(days: 1)); + actualDate = actualDate.add(Duration(days: 1)); } return statusOfOperation; diff --git a/lib/presentation/appointments/appointment_details_page.dart b/lib/presentation/appointments/appointment_details_page.dart index 6720befb..974c6019 100644 --- a/lib/presentation/appointments/appointment_details_page.dart +++ b/lib/presentation/appointments/appointment_details_page.dart @@ -262,7 +262,7 @@ class _AppointmentDetailsPageState extends State { Expanded( child: CollapsingListView( title: LocaleKeys.appointmentDetails.tr(context: context), - report: AppointmentType.isArrived(widget.patientAppointmentHistoryResponseModel) || widget.patientAppointmentHistoryResponseModel.isLiveCareAppointment! || widget.patientAppointmentHistoryResponseModel.isClinicReBookingAllowed! ==false || widget.patientAppointmentHistoryResponseModel.isActiveDoctor! == false + report: AppointmentType.isArrived(widget.patientAppointmentHistoryResponseModel) && widget.patientAppointmentHistoryResponseModel.isLiveCareAppointment==false && widget.patientAppointmentHistoryResponseModel.isClinicReBookingAllowed! ==true && widget.patientAppointmentHistoryResponseModel.isActiveDoctor! == true ? () { contactUsViewModel.setSelectedFeedbackType(FeedbackType(id: 1, nameEN: "Complaint for appointment", nameAR: 'شكوى على موعد')); contactUsViewModel.setPatientFeedbackSelectedAppointment(widget.patientAppointmentHistoryResponseModel); diff --git a/lib/presentation/emergency_services/nearest_er_page.dart b/lib/presentation/emergency_services/nearest_er_page.dart index 97e601d5..9eaaa5c7 100644 --- a/lib/presentation/emergency_services/nearest_er_page.dart +++ b/lib/presentation/emergency_services/nearest_er_page.dart @@ -2,6 +2,7 @@ import 'package:easy_localization/easy_localization.dart' show tr, StringTransla import 'package:flutter/material.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; import 'package:hmg_patient_app_new/core/app_assets.dart'; +import 'package:hmg_patient_app_new/core/location_util.dart'; import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; @@ -27,6 +28,34 @@ class _NearestErPageState extends State { final TextEditingController searchText = TextEditingController(); final Debouncer debouncer = Debouncer(milliseconds: 500); + @override + void initState() { + super.initState(); + _checkLocationAndFetchER(); + } + + void _checkLocationAndFetchER() { + final emergencyServicesViewModel = context.read(); + + // Check if location utils is available and get location with permission check + if (emergencyServicesViewModel.locationUtils != null) { + emergencyServicesViewModel.locationUtils!.getLocation( + isShowConfirmDialog: true, + onSuccess: (position) { + // Location permission granted and location received + emergencyServicesViewModel.getNearestER(); + }, + onFailure: () { + // Location permission denied or failed, still fetch ER list without location sorting + emergencyServicesViewModel.getNearestER(); + }, + ); + } else { + // No location utils available, just fetch the ER list + emergencyServicesViewModel.getNearestER(); + } + } + @override void dispose() { debouncer.dispose(); diff --git a/lib/presentation/habib_wallet/habib_wallet_page.dart b/lib/presentation/habib_wallet/habib_wallet_page.dart index fd5d17a1..c21e7a62 100644 --- a/lib/presentation/habib_wallet/habib_wallet_page.dart +++ b/lib/presentation/habib_wallet/habib_wallet_page.dart @@ -86,9 +86,7 @@ class _HabibWalletState extends State { SizedBox(height: 4.h), Consumer(builder: (context, habibWalletVM, child) { return Utils.getPaymentAmountWithSymbol2( - num.parse( - NumberFormat.decimalPattern().format(habibWalletVM.habibWalletAmount), - ), + habibWalletVM.habibWalletAmount, textColor: Colors.white, iconColor: Colors.white, iconSize: 16, @@ -104,28 +102,30 @@ class _HabibWalletState extends State { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - CustomButton( - height: 40.h, - icon: AppAssets.recharge_icon, - iconSize: 24.w, - backgroundColor: AppColors.infoColor, - textColor: Colors.white, - text: LocaleKeys.recharge.tr(context: context), - borderWidth: 0.w, - fontWeight: FontWeight.w600, - borderColor: Colors.transparent, - padding: EdgeInsets.fromLTRB(4, 0, 12, 0), - fontSize: 14.f, - onPressed: () { - Navigator.of(context) - .push(CustomPageRoute( - page: RechargeWalletPage(), - )) - .then((val) { - habibWalletVM.initHabibWalletProvider(); - habibWalletVM.getPatientBalanceAmount(); - }); - }, + Flexible( + child: CustomButton( + height: 40.h, + icon: AppAssets.recharge_icon, + iconSize: 24.w, + backgroundColor: AppColors.infoColor, + textColor: Colors.white, + text: LocaleKeys.recharge.tr(context: context), + borderWidth: 0.w, + fontWeight: FontWeight.w600, + borderColor: Colors.transparent, + padding: EdgeInsets.fromLTRB(4, 0, 12, 0), + fontSize: 14.f, + onPressed: () { + Navigator.of(context) + .push(CustomPageRoute( + page: RechargeWalletPage(), + )) + .then((val) { + habibWalletVM.initHabibWalletProvider(); + habibWalletVM.getPatientBalanceAmount(); + }); + }, + ), ), ], ), @@ -147,7 +147,7 @@ class _HabibWalletState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded(child: habibWalletVM.habibWalletBalanceList[index].projectDescription!.toText16(isBold: true, color: AppColors.textColor)), - Utils.getPaymentAmountWithSymbol2(num.parse(NumberFormat.decimalPattern().format(habibWalletVM.habibWalletBalanceList[index].patientAdvanceBalanceAmount!)), + Utils.getPaymentAmountWithSymbol2(habibWalletVM.habibWalletBalanceList[index].patientAdvanceBalanceAmount!, //did the changes because of negative value textColor: AppColors.textColor, iconColor: AppColors.textColor, iconSize: 18.h, isExpanded: false, fontSize: 28.f, fontWeight: FontWeight.w600, letterSpacing: -1), ], ).paddingSymmetrical(0, 12.h); diff --git a/lib/presentation/symptoms_checker/possible_conditions_screen.dart b/lib/presentation/symptoms_checker/possible_conditions_screen.dart index 1902cf72..01f0dc39 100644 --- a/lib/presentation/symptoms_checker/possible_conditions_screen.dart +++ b/lib/presentation/symptoms_checker/possible_conditions_screen.dart @@ -18,6 +18,7 @@ import 'package:hmg_patient_app_new/features/symptoms_checker/symptoms_checker_v import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; import 'package:hmg_patient_app_new/presentation/appointments/widgets/faculity_selection/facility_type_selection_widget.dart'; import 'package:hmg_patient_app_new/presentation/appointments/widgets/region_bottomsheet/region_list_widget.dart'; +import 'package:hmg_patient_app_new/presentation/emergency_services/nearest_er_page.dart'; import 'package:hmg_patient_app_new/presentation/symptoms_checker/widgets/condition_card.dart'; import 'package:hmg_patient_app_new/services/dialog_service.dart'; import 'package:hmg_patient_app_new/services/navigation_service.dart'; @@ -92,10 +93,28 @@ class PossibleConditionsPage extends StatelessWidget { separatorBuilder: (context, index) => SizedBox(height: 16.h), itemBuilder: (context, index) { final condition = conditions[index]; + // Create temporary card to access severity enum + final conditionCard = ConditionCard( + condition: condition, + symptoms: symptoms, + ); + return ConditionCard( condition: condition, symptoms: symptoms, onActionPressed: () { + // Check if condition is Emergency - redirect to Nearest ER page + if (conditionCard.severityEnum == PossibleConditionsSeverityEnum.emergency) { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => NearestErPage(), + ), + ); + return; + } + + // For non-emergency cases, continue with normal booking flow LoaderBottomSheet.showLoader(); symptomsCheckerViewModel.getClinicConditionsFromCategory( categoryName: (condition.conditionDetails!.category!.name) ?? "Other", diff --git a/lib/widgets/appbar/collapsing_list_view.dart b/lib/widgets/appbar/collapsing_list_view.dart index d641cb77..805fa677 100644 --- a/lib/widgets/appbar/collapsing_list_view.dart +++ b/lib/widgets/appbar/collapsing_list_view.dart @@ -140,12 +140,10 @@ class CollapsingListView extends StatelessWidget { // trailing: trailing, // ), ), - SliverList( - delegate: SliverChildBuilderDelegate( - (context, index) => child, - childCount: 1, + if (child != null) + SliverToBoxAdapter( + child: child!, ), - ), ], ).expanded, if (bottomChild != null) bottomChild! -- 2.30.2