Merge pull request 'WD: feature/search_by_region' (#42) from feature/search_by_region into master

Reviewed-on: #42
pull/43/head
Haroon6138 1 month ago
commit 64818c082e

@ -212,7 +212,7 @@ var GET_QR_PARKING = 'Services/SWP.svc/REST/GetQRParkingByID';
//URL to get clinic list //URL to get clinic list
var GET_CLINICS_LIST_URL = "Services/lists.svc/REST/GetClinicCentralized"; var GET_CLINICS_LIST_URL = "Services/lists.svc/REST/GetClinicCentralized";
var GET_CLINICS_LIST_WRT_HOSPITAL_URL = "Services/Lists.svc/REST/GetClinicFromDoctorSchedule"; var GET_CLINICS_LIST_WRT_HOSPITAL_ID_URL = "Services/Lists.svc/REST/GetClinicFromDoctorSchedule";
//URL to get active appointment list //URL to get active appointment list
var GET_ACTIVE_APPOINTMENTS_LIST_URL = "Services/Doctors.svc/Rest/Dr_GetAppointmentActiveNumber"; var GET_ACTIVE_APPOINTMENTS_LIST_URL = "Services/Doctors.svc/Rest/Dr_GetAppointmentActiveNumber";

@ -44,6 +44,9 @@ abstract class BookAppointmentsRepo {
Future<Either<Failure, GenericApiModel<List<HospitalsModel>>>> Future<Either<Failure, GenericApiModel<List<HospitalsModel>>>>
getProjectList(); getProjectList();
Future<Either<Failure, GenericApiModel<List<GetClinicsListResponseModel>>>> getClinicsWithRespectToClinicId(String projectID);
} }
class BookAppointmentsRepoImp implements BookAppointmentsRepo { class BookAppointmentsRepoImp implements BookAppointmentsRepo {
@ -409,4 +412,42 @@ class BookAppointmentsRepoImp implements BookAppointmentsRepo {
return Left(UnknownFailure(e.toString())); return Left(UnknownFailure(e.toString()));
} }
} }
@override
Future<Either<Failure, GenericApiModel<List<GetClinicsListResponseModel>>>> getClinicsWithRespectToClinicId(String projectID) async {
Map<String, dynamic> mapDevice = {"ProjectID": projectID};
try {
GenericApiModel<List<GetClinicsListResponseModel>>? apiResponse;
Failure? failure;
await apiClient.post(
GET_CLINICS_LIST_WRT_HOSPITAL_ID_URL,
body: mapDevice,
onFailure: (error, statusCode, {messageStatus, failureType}) {
failure = failureType;
},
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
try {
final list = response['ListClinic'];
final clinicsList = list.map((item) => GetClinicsListResponseModel.fromJson(item as Map<String, dynamic>)).toList().cast<GetClinicsListResponseModel>();
apiResponse = GenericApiModel<List<GetClinicsListResponseModel>>(
messageStatus: messageStatus,
statusCode: statusCode,
errorMessage: null,
data: clinicsList,
);
} 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()));
}
}
} }

@ -70,6 +70,10 @@ class BookAppointmentsViewModel extends ChangeNotifier {
FacilitySelection currentlySelectedFacility = FacilitySelection.ALL; FacilitySelection currentlySelectedFacility = FacilitySelection.ALL;
bool isRegionListLoading = false; bool isRegionListLoading = false;
///this will be used to call the clinic call when navigating from my REGION SELECTION to book appointment screen
bool shouldLoadSpecificClinic = false;
String? currentlySelectedHospitalFromRegionFlow;
BookAppointmentsViewModel({required this.bookAppointmentsRepo, required this.errorHandlerService, required this.navigationService, required this.myAppointmentsViewModel}); BookAppointmentsViewModel({required this.bookAppointmentsRepo, required this.errorHandlerService, required this.navigationService, required this.myAppointmentsViewModel});
void initializeFilteredList() { void initializeFilteredList() {
@ -109,7 +113,7 @@ class BookAppointmentsViewModel extends ChangeNotifier {
clinicsList.clear(); clinicsList.clear();
} }
isClinicsListLoading = value; isClinicsListLoading = value;
notifyListeners(); // notifyListeners();
} }
setSelectedClinic(GetClinicsListResponseModel clinic) { setSelectedClinic(GetClinicsListResponseModel clinic) {
@ -148,7 +152,18 @@ class BookAppointmentsViewModel extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<void> getClinics({Function(dynamic)? onSuccess, Function(String)? onError}) async { /// this function will decide which clinic api to be called
/// either api for region flow or the select clinic api
Future<void> getClinics() async
{
if(shouldLoadSpecificClinic) {
getRegionSelectedClinics();
} else {
getAllClinics();
}
}
Future<void> getAllClinics({Function(dynamic)? onSuccess, Function(String)? onError}) async {
final result = await bookAppointmentsRepo.getClinics(); final result = await bookAppointmentsRepo.getClinics();
result.fold( result.fold(
@ -173,6 +188,7 @@ class BookAppointmentsViewModel extends ChangeNotifier {
Future<void> getDoctorsList( Future<void> getDoctorsList(
{int projectID = 0, bool isNearest = false, int doctorId = 0, String doctorName = "", isContinueDentalPlan = false, Function(dynamic)? onSuccess, Function(String)? onError}) async { {int projectID = 0, bool isNearest = false, int doctorId = 0, String doctorName = "", isContinueDentalPlan = false, Function(dynamic)? onSuccess, Function(String)? onError}) async {
doctorsList.clear(); doctorsList.clear();
projectID = currentlySelectedHospitalFromRegionFlow != null?int.parse(currentlySelectedHospitalFromRegionFlow!):projectID;
final result = await bookAppointmentsRepo.getDoctorsList(selectedClinic.clinicID ?? 0, projectID, isNearest, doctorId, doctorName); final result = await bookAppointmentsRepo.getDoctorsList(selectedClinic.clinicID ?? 0, projectID, isNearest, doctorId, doctorName);
result.fold( result.fold(
@ -391,6 +407,7 @@ class BookAppointmentsViewModel extends ChangeNotifier {
} }
Future<void> getRegionMappedProjectList() async { Future<void> getRegionMappedProjectList() async {
//todo handle the case in the location is switch on
if(hospitalList != null && hospitalList!.registeredDoctorMap != null && hospitalList!.registeredDoctorMap!.isNotEmpty){ if(hospitalList != null && hospitalList!.registeredDoctorMap != null && hospitalList!.registeredDoctorMap!.isNotEmpty){
filteredHospitalList = hospitalList; filteredHospitalList = hospitalList;
return; return;
@ -469,4 +486,33 @@ class BookAppointmentsViewModel extends ChangeNotifier {
isLocationEnabled().then((value) => isLocationAvaiable = value); isLocationEnabled().then((value) => isLocationAvaiable = value);
return isLocationAvaiable; return isLocationAvaiable;
} }
void setLoadSpecificClinic(bool status) {
shouldLoadSpecificClinic = status;
}
void setProjectID(String? mainProjectID) {
currentlySelectedHospitalFromRegionFlow = mainProjectID;
}
Future<void> getRegionSelectedClinics() async{
final result = await bookAppointmentsRepo.getClinicsWithRespectToClinicId(currentlySelectedHospitalFromRegionFlow??"");
result.fold(
(failure) async => await errorHandlerService.handleError(failure: failure),
(apiResponse) {
if (apiResponse.messageStatus == 2) {
// dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
} else if (apiResponse.messageStatus == 1) {
clinicsList = apiResponse.data!;
isClinicsListLoading = false;
initializeFilteredList();
notifyListeners();
}
},
);
}
void resetFilterList(){
filteredHospitalList = hospitalList;
}
} }

@ -1,4 +1,8 @@
import 'package:flutter/foundation.dart' show ChangeNotifier; import 'package:flutter/foundation.dart' show ChangeNotifier;
import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/doctor_list_api_response.dart';
import 'package:hmg_patient_app_new/presentation/book_appointment/select_clinic_page.dart';
import 'package:hmg_patient_app_new/services/navigation_service.dart';
import 'package:hmg_patient_app_new/widgets/transitions/fade_page.dart';
enum AppointmentViaRegionState { enum AppointmentViaRegionState {
REGION_SELECTION, REGION_SELECTION,
@ -11,9 +15,13 @@ enum AppointmentViaRegionState {
class AppointmentViaRegionViewmodel extends ChangeNotifier { class AppointmentViaRegionViewmodel extends ChangeNotifier {
String? selectedRegionId; String? selectedRegionId;
String? selectedFacilityType; String? selectedFacilityType;
PatientDoctorAppointmentList? selectedHospital;
final NavigationService navigationService;
AppointmentViaRegionState bottomSheetState = AppointmentViaRegionState bottomSheetState =
AppointmentViaRegionState.REGION_SELECTION; AppointmentViaRegionState.REGION_SELECTION;
AppointmentViaRegionViewmodel({required this.navigationService});
void setSelectedRegionId(String? regionId) { void setSelectedRegionId(String? regionId) {
selectedRegionId = regionId; selectedRegionId = regionId;
notifyListeners(); notifyListeners();
@ -29,10 +37,16 @@ class AppointmentViaRegionViewmodel extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
void handleLastStep(){
navigationService.pop();
navigationService.push(FadePage(
page: SelectClinicPage(),
),);
}
void handleBackPress() { void handleBackPress() {
switch (bottomSheetState) { switch (bottomSheetState) {
case AppointmentViaRegionState.REGION_SELECTION: case AppointmentViaRegionState.REGION_SELECTION:
// Do nothing or exit the bottom sheet
break; break;
case AppointmentViaRegionState.TYPE_SELECTION: case AppointmentViaRegionState.TYPE_SELECTION:
setBottomSheetState(AppointmentViaRegionState.REGION_SELECTION); setBottomSheetState(AppointmentViaRegionState.REGION_SELECTION);
@ -41,19 +55,6 @@ class AppointmentViaRegionViewmodel extends ChangeNotifier {
case AppointmentViaRegionState.HOSPITAL_SELECTION: case AppointmentViaRegionState.HOSPITAL_SELECTION:
setBottomSheetState(AppointmentViaRegionState.TYPE_SELECTION); setBottomSheetState(AppointmentViaRegionState.TYPE_SELECTION);
break; break;
// case AppointmentViaRegionState.HOSPITAL_SELECTION:
// case AppointmentViaRegionState.CLINIC_SELECTION:
// setBottomSheetState(AppointmentViaRegionState.TYPE_SELECTION);
// setFacility(null);
// break;
// case AppointmentViaRegionState.DOCTOR_SELECTION:
// if (selectedFacilityType == 'Hospital') {
// setBottomSheetState(AppointmentViaRegionState.HOSPITAL_SELECTION);
// } else if (selectedFacilityType == 'Medical Center') {
// setBottomSheetState(AppointmentViaRegionState.CLINIC_SELECTION);
// }
// break;
default: default:
} }
} }
@ -63,4 +64,8 @@ class AppointmentViaRegionViewmodel extends ChangeNotifier {
setFacility(null); setFacility(null);
setBottomSheetState(AppointmentViaRegionState.REGION_SELECTION); setBottomSheetState(AppointmentViaRegionState.REGION_SELECTION);
} }
void setHospitalModel(PatientDoctorAppointmentList? hospital) {
selectedHospital = hospital;
}
} }

@ -146,7 +146,8 @@ void main() async {
), ),
), ),
ChangeNotifierProvider<AppointmentViaRegionViewmodel>( ChangeNotifierProvider<AppointmentViaRegionViewmodel>(
create: (_) => AppointmentViaRegionViewmodel()) create: (_) =>
AppointmentViaRegionViewmodel(navigationService: getIt()))
], child: MyApp()), ], child: MyApp()),
), ),
); );

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/enums.dart'; import 'package:hmg_patient_app_new/core/enums.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/book_appointments/book_appointments_view_model.dart'; import 'package:hmg_patient_app_new/features/book_appointments/book_appointments_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/appointment_via_region_viewmodel.dart';
import 'package:hmg_patient_app_new/features/my_appointments/models/facility_selection.dart'; import 'package:hmg_patient_app_new/features/my_appointments/models/facility_selection.dart';
@ -76,21 +77,28 @@ class HospitalBottomSheetBody extends StatelessWidget {
SizedBox( SizedBox(
height: MediaQuery.sizeOf(context).height * .4, height: MediaQuery.sizeOf(context).height * .4,
child: ListView.separated( child: ListView.separated(
itemBuilder: (_, index) => HospitalListItem( itemBuilder: (_, index)
hospitalData: regionalViewModel.selectedFacilityType == {
FacilitySelection.HMG.name var hospital = regionalViewModel.selectedFacilityType ==
? appointmentsViewModel FacilitySelection.HMG.name
.filteredHospitalList! ? appointmentsViewModel
.registeredDoctorMap![ .filteredHospitalList!
regionalViewModel.selectedRegionId!]! .registeredDoctorMap![
.hmgDoctorList![index] regionalViewModel.selectedRegionId!]!
: appointmentsViewModel .hmgDoctorList![index]
.filteredHospitalList : appointmentsViewModel
?.registeredDoctorMap?[ .filteredHospitalList
regionalViewModel.selectedRegionId!] ?.registeredDoctorMap?[
?.hmcDoctorList?[index], regionalViewModel.selectedRegionId!]
isLocationEnabled: appointmentsViewModel.getLocationStatus(), ?.hmcDoctorList?[index];
), return HospitalListItem(
hospitalData: hospital,
isLocationEnabled: appointmentsViewModel.getLocationStatus(),
).onPress(() {
regionalViewModel.setHospitalModel(hospital);
regionalViewModel.setBottomSheetState(AppointmentViaRegionState.CLINIC_SELECTION);
regionalViewModel.handleLastStep();
});},
separatorBuilder: (_, __) => SizedBox( separatorBuilder: (_, __) => SizedBox(
height: 16.h, height: 16.h,
), ),

@ -122,6 +122,8 @@ class _BookAppointmentPageState extends State<BookAppointmentPage> {
], ],
).onPress(() { ).onPress(() {
bookAppointmentsViewModel.setIsClinicsListLoading(true); bookAppointmentsViewModel.setIsClinicsListLoading(true);
bookAppointmentsViewModel.setLoadSpecificClinic(false);
bookAppointmentsViewModel.setProjectID(null);
Navigator.of(context).push( Navigator.of(context).push(
FadePage( FadePage(
page: SelectClinicPage(), page: SelectClinicPage(),
@ -194,6 +196,7 @@ class _BookAppointmentPageState extends State<BookAppointmentPage> {
} }
void openRegionListBottomSheet(BuildContext context) { void openRegionListBottomSheet(BuildContext context) {
regionalViewModel.flush();
// AppointmentViaRegionViewmodel? viewmodel = null; // AppointmentViaRegionViewmodel? viewmodel = null;
showCommonBottomSheetWithoutHeight(context, showCommonBottomSheetWithoutHeight(context,
title: "", title: "",
@ -203,7 +206,6 @@ class _BookAppointmentPageState extends State<BookAppointmentPage> {
child: Consumer<AppointmentViaRegionViewmodel>(builder: (_, data, __) { child: Consumer<AppointmentViaRegionViewmodel>(builder: (_, data, __) {
return getRegionalSelectionWidget(data); return getRegionalSelectionWidget(data);
}), callBackFunc: () { }), callBackFunc: () {
regionalViewModel.flush();
}); });
} }
@ -212,11 +214,20 @@ class _BookAppointmentPageState extends State<BookAppointmentPage> {
return RegionBottomSheetBody(); return RegionBottomSheetBody();
} }
if(data.bottomSheetState == AppointmentViaRegionState.TYPE_SELECTION){ if(data.bottomSheetState == AppointmentViaRegionState.TYPE_SELECTION){
bookAppointmentsViewModel.resetFilterList();
return FacilityTypeSelectionWidget(selectedRegion: data.selectedRegionId??"",); return FacilityTypeSelectionWidget(selectedRegion: data.selectedRegionId??"",);
} }
if (data.bottomSheetState == AppointmentViaRegionState.HOSPITAL_SELECTION) { if (data.bottomSheetState == AppointmentViaRegionState.HOSPITAL_SELECTION) {
return HospitalBottomSheetBody(); return HospitalBottomSheetBody();
} else { }
if (data.bottomSheetState == AppointmentViaRegionState.CLINIC_SELECTION) {
// Navigator.of(context).pop();
bookAppointmentsViewModel.setIsClinicsListLoading(true);
bookAppointmentsViewModel.setLoadSpecificClinic(true);
bookAppointmentsViewModel.setProjectID(regionalViewModel.selectedHospital?.hospitalList.first?.mainProjectID.toString());
}
else {
SizedBox.shrink(); SizedBox.shrink();
} }
return SizedBox.shrink(); return SizedBox.shrink();

@ -41,7 +41,6 @@ class AppCustomChipWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print("detected icon: $deleteIcon");
return ChipTheme( return ChipTheme(
data: ChipThemeData( data: ChipThemeData(
padding: EdgeInsets.all(0.0), padding: EdgeInsets.all(0.0),

Loading…
Cancel
Save