ORDER ALTERED FOR THE SORTED LIST #397

Merged
Haroon6138 merged 4 commits from CLINIC_ORDER_CHANGE into master 2 days ago

1
.gitignore vendored

@ -43,3 +43,4 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release
/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

@ -12,6 +12,7 @@ class DoctorMapper{
for (var element in doctorList) {
String? region = element.getRegionName(isArabic);
String? regionEng = element.getRegionName(false);
if (region == null) continue;
var regionDoctorList = regionList.registeredDoctorMap?.putIfAbsent(region, () => PatientDoctorAppointmentListByRegion());
@ -33,6 +34,8 @@ class DoctorMapper{
var newAppointment = PatientDoctorAppointmentList(
filterName:
element.getProjectCompleteNameWithLocale(isArabic: isArabic),
filterNameEng:
element.getProjectCompleteNameWithLocale(isArabic: false),
distanceInKMs: element.projectDistanceInKiloMeters.toString(),
projectTopName: element.projectTopName,
projectBottomName: element.projectBottomName,
@ -82,6 +85,7 @@ class DoctorMapper{
regionDoctorList?.hmgSize = regionDoctorList.hmgDoctorList?.length ?? 0;
regionList.registeredDoctorMap?[region] = regionDoctorList;
regionList.regionNameMap?[regionEng??""] = region;
}
return regionList;
@ -110,10 +114,19 @@ class DoctorMapper{
}
List<String>? keys = unsorted.registeredDoctorMap?.keys.toList();
keys?.sort();
final keys = unsorted.registeredDoctorMap?.keys.toList() ?? [];
if (keys.isEmpty) return unsorted;
keys.sort((a, b) {
final priorityA = _getRegionSortPriority(a);
final priorityB = _getRegionSortPriority(b);
if (priorityA != priorityB) return priorityA.compareTo(priorityB);
final aValue = a.toLowerCase();
final bValue = b.toLowerCase();
return aValue.compareTo(bValue);
});
if (keys == null) return unsorted;
Map<String, PatientDoctorAppointmentListByRegion> sortedMap = {};
for (var key in keys) {
sortedMap[key] = unsorted.registeredDoctorMap![key]!;
@ -122,6 +135,25 @@ class DoctorMapper{
return unsorted;
}
static int _getRegionSortPriority(String regionKey) {
final key = regionKey.trim().toLowerCase();
if (key.isEmpty) return 999;
if (key.startsWith('c') || key.contains('وسط') || key.contains('الوسط') || key.contains('المنطقة الوسطى')) {
return 0;
}
if (key.startsWith('w') || key.contains('غرب') || key.contains('الغربي') || key.contains('الغربية')) {
return 1;
}
if (key.startsWith('e') || key.contains('شرق') || key.contains('الشرقي') || key.contains('الشرقية')) {
return 2;
}
if (key.startsWith("u") || key.contains('الإمارات') || key.contains('امارات')) {
return 3;
}
return 999;
}
static Future<RegionList> getMappedHospitals(
List<HospitalsModel> hospitalList, {
bool isArabic = false, double lat = 0.0,double lng = 0.0
@ -129,6 +161,7 @@ class DoctorMapper{
final regionList = RegionList();
for (final hospital in hospitalList) {
final region = hospital.getRegionName(isArabic);
final regionEng = hospital.getRegionName(false);
if (region == null) continue;
final regionData = regionList.registeredDoctorMap?.putIfAbsent(
@ -152,6 +185,7 @@ class DoctorMapper{
} else {
final newEntry = PatientDoctorAppointmentList(
filterName: hospital.name,
filterNameEng: hospital.getName(false),
distanceInKMs: hospital.distanceInKilometers?.toString(),
projectTopName: hospital.name,
projectBottomName: hospital.name,
@ -196,6 +230,7 @@ class DoctorMapper{
regionData?.hmcSize = regionData.hmcDoctorList?.length ?? 0;
regionData?.hmgSize = regionData.hmgDoctorList?.length ?? 0;
regionList.registeredDoctorMap?[region] = regionData;
regionList.regionNameMap?[regionEng??""] = region;
}
return regionList;

@ -1,4 +1,3 @@
import 'package:hmg_patient_app_new/features/book_appointments/models/resp_models/doctors_list_response_model.dart';
import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/hospital_model.dart' show HospitalsModel;
@ -236,6 +235,7 @@ class DoctorList {
class PatientDoctorAppointmentList {
String? filterName = "";
String? filterNameEng = "";
String? distanceInKMs = "";
List<DoctorsListResponseModel>? patientDoctorAppointmentList = [];
String? projectTopName = "";
@ -245,12 +245,14 @@ class PatientDoctorAppointmentList {
PatientDoctorAppointmentList(
{this.filterName,
this.filterNameEng,
this.distanceInKMs,
this.projectTopName,
this.projectBottomName,
DoctorsListResponseModel? patientDoctorAppointment,
HospitalsModel? model,
this.isHMC = false}) {
filterNameEng ??= filterName;
if (model != null) {
hospitalList.add(model);
}
@ -272,4 +274,5 @@ class PatientDoctorAppointmentListByRegion {
class RegionList {
Map<String, PatientDoctorAppointmentListByRegion?>? registeredDoctorMap = {};
Map<String, String>? regionNameMap = {};
}

@ -94,7 +94,7 @@ dependencies:
image_picker_android: ^0.8.13+16
image_picker_platform_interface: ^2.10.0
location: ^8.0.1
location: ^10.0.2
gms_check: ^1.0.4
huawei_location: ^6.14.2+301
huawei_health: ^6.15.0+300

Loading…
Cancel
Save