From 4780a3b5f656130e7cde21a8b50a9e19a88b327d Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Wed, 1 Nov 2023 12:02:30 +0300 Subject: [PATCH] Blood Donation CR implementation contd. --- lib/config/config.dart | 2 +- .../blood_donation_free_slots_response.dart | 25 ++ .../blood_donation_book_appointment.dart | 288 +++++++++++++++++- 3 files changed, 302 insertions(+), 13 deletions(-) create mode 100644 lib/core/model/blooddonation/blood_donation_free_slots_response.dart diff --git a/lib/config/config.dart b/lib/config/config.dart index 60e5e9c4..b207f4ff 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -337,7 +337,7 @@ var UPDATE_COVID_QUESTIONNAIRE = 'Services/Doctors.svc/REST/COVID19_Questionnari var CHANNEL = 3; var GENERAL_ID = 'Cs2020@2016\$2958'; var IP_ADDRESS = '10.20.10.20'; -var VERSION_ID = 11.1; +var VERSION_ID = 30.1; var SETUP_ID = '91877'; var LANGUAGE = 2; // var PATIENT_OUT_SA = 0; diff --git a/lib/core/model/blooddonation/blood_donation_free_slots_response.dart b/lib/core/model/blooddonation/blood_donation_free_slots_response.dart new file mode 100644 index 00000000..5c46cab1 --- /dev/null +++ b/lib/core/model/blooddonation/blood_donation_free_slots_response.dart @@ -0,0 +1,25 @@ +class BloodDonationFreeSlotsResponseModel { + int clinicID; + int doctorID; + String freeTimeSlots; + int projectID; + + BloodDonationFreeSlotsResponseModel( + {this.clinicID, this.doctorID, this.freeTimeSlots, this.projectID}); + + BloodDonationFreeSlotsResponseModel.fromJson(Map json) { + clinicID = json['ClinicID']; + doctorID = json['DoctorID']; + freeTimeSlots = json['FreeTimeSlots']; + projectID = json['ProjectID']; + } + + Map toJson() { + final Map data = new Map(); + data['ClinicID'] = this.clinicID; + data['DoctorID'] = this.doctorID; + data['FreeTimeSlots'] = this.freeTimeSlots; + data['ProjectID'] = this.projectID; + return data; + } +} diff --git a/lib/pages/Blood/blood_donation_book_appointment.dart b/lib/pages/Blood/blood_donation_book_appointment.dart index 0f89db89..bbfe3272 100644 --- a/lib/pages/Blood/blood_donation_book_appointment.dart +++ b/lib/pages/Blood/blood_donation_book_appointment.dart @@ -1,28 +1,78 @@ +import 'package:diplomaticquarterapp/core/model/blooddonation/blood_donation_free_slots_response.dart'; import 'package:diplomaticquarterapp/core/model/blooddonation/blood_donation_projects_list_response.dart'; import 'package:diplomaticquarterapp/core/service/blood/blood_donation_service.dart'; +import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; +import 'package:diplomaticquarterapp/models/Appointments/FreeSlot.dart'; +import 'package:diplomaticquarterapp/models/Appointments/timeSlot.dart'; +import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/uitl/date_uitl.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/buttons/custom_text_button.dart'; import 'package:diplomaticquarterapp/widgets/dialogs/radio_selection_dialog.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; +import 'package:provider/provider.dart'; +import 'package:syncfusion_flutter_calendar/calendar.dart'; import '../AlHabibMedicalService/h2o/h20_setting.dart'; class BloodDonationBookAppointment extends StatefulWidget { const BloodDonationBookAppointment(); + static bool areSlotsAvailable = false; + static DateTime selectedAppoDateTime; + static String selectedDate; + static String selectedTime; + @override State createState() => _BloodDonationBookAppointmentState(); } -class _BloodDonationBookAppointmentState extends State { +class _BloodDonationBookAppointmentState extends State with TickerProviderStateMixin { + Map _events; + AnimationController _animationController; + CalendarController _calendarController; + List bloodDonationProjectsListResponse = []; int _selectedProjectID = 0; + int _clinicID = 0; + int _doctorID = 0; + + List docFreeSlots = []; + List dayEvents = []; + + var selectedDate = ""; + dynamic selectedDateJSON; + dynamic jsonFreeSlots; + + int selectedButtonIndex = 0; + + List bloodDonationFreeSlotsResponse = []; + + ProjectViewModel projectViewModel; + ScrollController _scrollController; @override void initState() { + final _selectedDay = DateTime.now(); super.initState(); + + _events = { + _selectedDay: ['Event A0'] + }; + + _scrollController = new ScrollController(); + + _calendarController = CalendarController(); + _animationController = AnimationController( + vsync: this, + duration: const Duration(milliseconds: 50), + ); + WidgetsBinding.instance.addPostFrameCallback((_) { getBloodDonationProjectsList(); }); @@ -30,6 +80,7 @@ class _BloodDonationBookAppointmentState extends State list = []; - bloodDonationProjectsListResponse.forEach((element) { list.add(RadioSelectionDialogModel(element.projectName, element.projectID)); }); - showDialog( context: context, builder: (cxt) => RadioSelectionDialog( @@ -64,6 +114,44 @@ class _BloodDonationBookAppointmentState extends State { + setState(() => {_clinicID = bloodDonationFreeSlotsResponse[0].clinicID, _doctorID = bloodDonationFreeSlotsResponse[0].doctorID, _events.clear(), _events = value}) + }); + } else { + AppToast.showErrorToast(message: res["ErrorEndUserMessage"]); + } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); print(err); }); } + openTimeSlotsPickerForDate(DateTime dateStart, List freeSlots) { + dayEvents.clear(); + DateTime dateStartObj = new DateTime(dateStart.year, dateStart.month, dateStart.day, 0, 0, 0, 0, 0); + + freeSlots.forEach((v) { + if (v.start == dateStartObj) dayEvents.add(v); + }); + + setState(() { + if (dayEvents.length != 0) { + BloodDonationBookAppointment.areSlotsAvailable = true; + selectedButtonIndex = 0; + BloodDonationBookAppointment.selectedTime = dayEvents[selectedButtonIndex].isoTime; + } else + BloodDonationBookAppointment.areSlotsAvailable = false; + }); + } + + Future> _getJSONSlots() async { + Map _eventsParsed; + List slotsList = []; + DateTime date; + final DateFormat formatter = DateFormat('HH:mm'); + final DateFormat dateFormatter = DateFormat('yyyy-MM-dd'); + for (var i = 0; i < bloodDonationFreeSlotsResponse.length; i++) { + date = DateUtil.convertStringToDate(bloodDonationFreeSlotsResponse[i].freeTimeSlots); + slotsList.add(FreeSlot(date, ['slot'])); + docFreeSlots.add(TimeSlot(isoTime: formatter.format(date), start: new DateTime(date.year, date.month, date.day, 0, 0, 0, 0), end: date)); + } + _eventsParsed = Map.fromIterable(slotsList, key: (e) => e.slot, value: (e) => e.event); + setState(() { + BloodDonationBookAppointment.selectedDate = dateFormatter.format(DateUtil.convertStringToDate(bloodDonationFreeSlotsResponse[0].freeTimeSlots)); + selectedDate = DateUtil.getMonthDayYearDateFormatted(DateUtil.convertStringToDate(bloodDonationFreeSlotsResponse[0].freeTimeSlots)); + selectedDateJSON = bloodDonationFreeSlotsResponse[0].freeTimeSlots; + }); + openTimeSlotsPickerForDate(DateUtil.convertStringToDate(selectedDateJSON), docFreeSlots); + _calendarController.selectedDate = DateUtil.convertStringToDate(selectedDateJSON); + return _eventsParsed; + } + getBloodDonationProjectsList() { BloodDonationService service = new BloodDonationService(); GifLoaderDialogUtils.showMyDialog(context); @@ -110,4 +314,64 @@ class _BloodDonationBookAppointmentState extends State _getDataSource() { + final List meetings = []; + _events.forEach((key, value) { + final DateTime startTime = DateTime(key.year, key.month, key.day, 9, 0, 0); + final DateTime endTime = startTime.add(const Duration(minutes: 20)); + meetings.add(Meeting("", startTime, endTime, CustomColors.green, false)); + }); + return meetings; + } +} + +class MeetingDataSource extends CalendarDataSource { + MeetingDataSource(List source) { + appointments = source; + } + + @override + DateTime getStartTime(int index) { + return _getMeetingData(index).from; + } + + @override + DateTime getEndTime(int index) { + return _getMeetingData(index).to; + } + + @override + String getSubject(int index) { + return _getMeetingData(index).eventName; + } + + @override + Color getColor(int index) { + return _getMeetingData(index).background; + } + + @override + bool isAllDay(int index) { + return _getMeetingData(index).isAllDay; + } + + Meeting _getMeetingData(int index) { + final dynamic meeting = appointments[index]; + Meeting meetingData; + if (meeting is Meeting) { + meetingData = meeting; + } + return meetingData; + } +} + +class Meeting { + Meeting(this.eventName, this.from, this.to, this.background, this.isAllDay); + + String eventName; + DateTime from; + DateTime to; + Color background; + bool isAllDay; }