diff --git a/lib/pages/BookAppointment/search_result/ResultByClinic.dart b/lib/pages/BookAppointment/search_result/ResultByClinic.dart index 088994cd..15fc79f3 100644 --- a/lib/pages/BookAppointment/search_result/ResultByClinic.dart +++ b/lib/pages/BookAppointment/search_result/ResultByClinic.dart @@ -25,7 +25,7 @@ import '../../../uitl/gif_loader_dialog_utils.dart'; class ResultByClinic extends StatefulWidget { HospitalsModel? selectedValue; - Function(RegionList) onClinicSelected; + Function(RegionList, int?) onClinicSelected; ResultByClinic({super.key, this.selectedValue, required this.onClinicSelected}); @@ -165,7 +165,7 @@ class _ResultByClinicState extends State { ), ).then((value) { if (value is RegionList) { - widget.onClinicSelected(value); + widget.onClinicSelected(value,null); } }); } @@ -202,7 +202,7 @@ class _ResultByClinicState extends State { var lng = await sharedPref.getDouble(USER_LONG); var isLocationEnabled = (lat != null && lat != 0.0) && (lng != null && lng != 0.0); regionHospitalList = await DoctorMapper.sortList(isLocationEnabled, regionHospitalList); - widget.onClinicSelected(regionHospitalList); + widget.onClinicSelected(regionHospitalList, clinicID); setState(() {}); } else { GifLoaderDialogUtils.hideDialog(context); diff --git a/lib/pages/BookAppointment/search_result/ResultByDoctors.dart b/lib/pages/BookAppointment/search_result/ResultByDoctors.dart index f374e97c..bdb74688 100644 --- a/lib/pages/BookAppointment/search_result/ResultByDoctors.dart +++ b/lib/pages/BookAppointment/search_result/ResultByDoctors.dart @@ -1,7 +1,11 @@ +import 'package:auto_size_text/auto_size_text.dart'; +import 'package:diplomaticquarterapp/config/size_config.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart'; import 'package:diplomaticquarterapp/models/Appointments/OBGyneProcedureListResponse.dart'; import 'package:diplomaticquarterapp/pages/BookAppointment/widgets/DoctorView.dart'; +import 'package:diplomaticquarterapp/theme/colors.dart'; +import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/utils_new.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -13,7 +17,10 @@ class ResultByDoctor extends StatefulWidget { final bool isObGyneAppointment; final bool isDoctorNameSearch; final bool isDoctorSearchResult; + final bool showNearestAppointment; + final bool nearestAppointmentDoctors; final OBGyneProcedureListResponse? obGyneProcedureListResponse; + final Function(bool)? refreshDoctorList; ResultByDoctor({ required this.doctorsList, @@ -22,7 +29,10 @@ class ResultByDoctor extends StatefulWidget { required this.isObGyneAppointment, required this.isDoctorNameSearch, required this.isDoctorSearchResult, + this.showNearestAppointment = false, + this.nearestAppointmentDoctors = false, this.obGyneProcedureListResponse, + this.refreshDoctorList }); @override @@ -30,12 +40,53 @@ class ResultByDoctor extends StatefulWidget { } class _ResultByDoctorState extends State { + + bool nearestAppo = false; + + @override + void initState() { + nearestAppo = widget.nearestAppointmentDoctors; + super.initState(); + } @override Widget build(BuildContext context) { - return SizedBox( - child: widget.patientDoctorAppointmentListHospital?.isNotEmpty == true - ? Padding( - padding: const EdgeInsets.all(12.0), + return Column( + children: [ + + Visibility( + visible: widget.showNearestAppointment, + child: Padding( + padding: const EdgeInsets.only(left: 6, right: 6,), + child: Row( + children: [ + Checkbox( + activeColor: CustomColors.accentColor, + value: nearestAppo, + onChanged: (bool? value) { + setState(() { + nearestAppo = value ?? false; + }); + widget.refreshDoctorList?.call(nearestAppo); + }, + ), + AutoSizeText( + TranslationBase.of(context).nearestAppo.trim(), + maxLines: 1, + minFontSize: 10, + style: TextStyle( + fontSize: SizeConfig.textMultiplier! * 1.4, + fontWeight: FontWeight.w600, + letterSpacing: -0.39, + height: 0.8, + ), + ), + // Text(TranslationBase.of(context).nearestAppo, style: TextStyle(fontSize: 14.0, letterSpacing: -0.56)), + ], + ), + ), + ), + widget.patientDoctorAppointmentListHospital?.isNotEmpty == true + ? Expanded( child: ListView.separated( addAutomaticKeepAlives: true, physics: BouncingScrollPhysics(), @@ -50,21 +101,25 @@ class _ResultByDoctorState extends State { itemBuilder: (context, index) { final doctor = widget.patientDoctorAppointmentListHospital![index]; - return DoctorView( - doctor: doctor, - isLiveCareAppointment: widget.isLiveCareAppointment, - isObGyneAppointment: widget.isObGyneAppointment, - isDoctorNameSearch: widget.isDoctorNameSearch, - obGyneProcedureListResponse: widget.obGyneProcedureListResponse, - isShowDate: false, - onTap: () { - context.read().analytics.appointment.book_appointment_select_doctor(appointment_type: 'regular', doctor: doctor); - }); + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 12.0), + child: DoctorView( + doctor: doctor, + isLiveCareAppointment: widget.isLiveCareAppointment, + isObGyneAppointment: widget.isObGyneAppointment, + isDoctorNameSearch: widget.isDoctorNameSearch, + obGyneProcedureListResponse: widget.obGyneProcedureListResponse, + isShowDate: false, + onTap: () { + context.read().analytics.appointment.book_appointment_select_doctor(appointment_type: 'regular', doctor: doctor); + }), + ); }, itemCount: widget.patientDoctorAppointmentListHospital?.length ?? 0, ), ) - : getNoDataWidget(context), + : getNoDataWidget(context), + ], ); } diff --git a/lib/pages/BookAppointment/search_result/SearchResultWithTabForHospital.dart b/lib/pages/BookAppointment/search_result/SearchResultWithTabForHospital.dart index db54904e..4f0e94cd 100644 --- a/lib/pages/BookAppointment/search_result/SearchResultWithTabForHospital.dart +++ b/lib/pages/BookAppointment/search_result/SearchResultWithTabForHospital.dart @@ -9,7 +9,11 @@ import 'package:diplomaticquarterapp/pages/BookAppointment/search_result/ResultB import 'package:diplomaticquarterapp/pages/BookAppointment/search_result/ResultByHospital.dart'; import 'package:diplomaticquarterapp/pages/BookAppointment/search_result/ResultByRegion.dart'; import 'package:diplomaticquarterapp/pages/BookAppointment/widgets/DoctorView.dart'; +import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; +import 'package:diplomaticquarterapp/services/appointment_services/doctor_response_mapper.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/utils_new.dart'; import 'package:diplomaticquarterapp/widgets/others/app_expandable_notifier.dart'; @@ -17,6 +21,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:provider/provider.dart'; +import '../../../config/shared_pref_kay.dart'; +import '../../../core/service/client/base_app_client.dart'; + class SearchResultWithTabForHospital extends StatefulWidget { List doctorsList = []; RegionList patientDoctorAppointmentListHospital; @@ -54,6 +61,8 @@ class _SearchResultWithTabForHospitalState int selectedHospitalIndex = -1; ScrollController scrollController = ScrollController(); RegionList? doctorList; + bool nearestAppointment= false; + int clinicId = -1; @override void initState() { @@ -135,6 +144,8 @@ class _SearchResultWithTabForHospitalState doctorList = null; _currentIndex = 0; changePageViewIndex(0); + nearestAppointment = false; + clinicId = -1; }); }, ), @@ -159,6 +170,9 @@ class _SearchResultWithTabForHospitalState doctorList = null; _currentIndex = 1; changePageViewIndex(1); + nearestAppointment = false; + clinicId = -1; + }); }, ), @@ -183,6 +197,9 @@ class _SearchResultWithTabForHospitalState doctorList = null; _currentIndex = 2; changePageViewIndex(2); + nearestAppointment = false; + clinicId = -1; + }); }, ), @@ -203,9 +220,12 @@ class _SearchResultWithTabForHospitalState : CustomColors.grey2, onTap: () { setState(() { - _currentIndex = 3; doctorList = null; changePageViewIndex(3); + _currentIndex = 3; + nearestAppointment= false; + clinicId = -1; + }); }, ), @@ -350,11 +370,14 @@ class _SearchResultWithTabForHospitalState selectedRegion != '' && selectedHospitalIndex != -1) ? ResultByClinic( - onClinicSelected: (doctorList) { + onClinicSelected: (doctorList, clinicId) { setState(() { + this.nearestAppointment = false; this.doctorList = doctorList; _currentIndex = 4; changePageViewIndex(4); + if(clinicId != null) + this.clinicId = clinicId; }); }, selectedValue: selectedHospital) @@ -384,7 +407,19 @@ class _SearchResultWithTabForHospitalState widget.isLiveCareAppointment, isDoctorSearchResult: widget.isDoctorSearchResult, isObGyneAppointment: widget.isObGyneAppointment, - isDoctorNameSearch: widget.isDoctorNameSearch) + isDoctorNameSearch: widget.isDoctorNameSearch, + showNearestAppointment: clinicId != -1 , + nearestAppointmentDoctors: nearestAppointment, + refreshDoctorList: (isNearestAppointmentChecked){ + setState(() { + // changePageViewIndex(3); + // _currentIndex = 3; + nearestAppointment= false; + }); + callDoctorsSearchAPI(clinicId, isNearestAppointmentChecked); + }, + + ) : SizedBox.shrink(), ], ), @@ -395,6 +430,62 @@ class _SearchResultWithTabForHospitalState ); } + callDoctorsSearchAPI(int clinicID, bool nearestAppointment) { + var isArabic = context.read().isArabic; + int languageID = isArabic ? 1 : 2; + GifLoaderDialogUtils.showMyDialog(context); + List doctorsList = []; + List arr = []; + List arrDistance = []; + List result; + int numAll; + List _patientDoctorAppointmentListHospital = []; + + DoctorsListService service = new DoctorsListService(); + service + .getDoctorsList(clinicID, selectedHospital?.mainProjectID.toString() != "" ? int.parse(selectedHospital?.mainProjectID.toString() ?? "-1") : 0, nearestAppointment, languageID, null) + .then((res) async { + GifLoaderDialogUtils.hideDialog(context); + if (res['MessageStatus'] == 1) { + RegionList regionHospitalList = RegionList(); + + if (res['DoctorList'].length != 0) { + res['DoctorList'].forEach((v) { + doctorsList.add(new DoctorList.fromJson( + v, + )); + }); + + regionHospitalList = await DoctorMapper.getMappedDoctor(doctorsList, isArabic: isArabic); + var lat = await sharedPref.getDouble(USER_LAT); + + var lng = await sharedPref.getDouble(USER_LONG); + var isLocationEnabled = (lat != null && lat != 0.0) && (lng != null && lng != 0.0); + regionHospitalList = await DoctorMapper.sortList(isLocationEnabled, regionHospitalList); + + setState(() { + this.doctorList = regionHospitalList; + _currentIndex = 4; + changePageViewIndex(4); + this.nearestAppointment = nearestAppointment; + }); + } else { + GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: res['ErrorSearchMsg']); + } + + GifLoaderDialogUtils.hideDialog(context); + // navigateToSearchResults(context, doctorsList, _patientDoctorAppointmentListHospital); + } else { + GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: res['ErrorEndUserMessage']); + } + }).catchError((err) { + GifLoaderDialogUtils.hideDialog(context); + print(err); + AppToast.showErrorToast(message: err, localContext: context); + }); + } String getTitle() { switch (_currentIndex) { case 0: