import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/models/LiveCare/ERAppointmentFeesResponse.dart';
import 'package:diplomaticquarterapp/models/LiveCare/LiveCareClinicsListResponse.dart';
import 'package:diplomaticquarterapp/models/LiveCare/LiveCareScheduleClinicsListResponse.dart';
import 'package:diplomaticquarterapp/pages/BookAppointment/SearchResults.dart';
import 'package:diplomaticquarterapp/pages/ToDoList/payment_method_select.dart';
import 'package:diplomaticquarterapp/pages/livecare/livecare_home.dart';
import 'package:diplomaticquarterapp/pages/livecare/livecare_scheduling/schedule_clinic_card.dart';
import 'package:diplomaticquarterapp/pages/livecare/livecare_type_select.dart';
import 'package:diplomaticquarterapp/pages/livecare/widgets/LiveCareInfoDialog.dart';
import 'package:diplomaticquarterapp/pages/livecare/widgets/LiveCarePaymentDialog.dart';
import 'package:diplomaticquarterapp/pages/livecare/widgets/clinic_card.dart';
import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart';
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
import 'package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart';
import 'package:diplomaticquarterapp/theme/colors.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.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.dart';
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart';
import 'package:diplomaticquarterapp/widgets/in_app_browser/InAppBrowser.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../live_care_payment_page.dart';

class ClinicList extends StatefulWidget {
  final Function getLiveCareHistory;

  ClinicList({@required this.getLiveCareHistory});

  @override
  _clinic_listState createState() => _clinic_listState();
}

class _clinic_listState extends State<ClinicList> {
  int currentSelectedIndex = 0;
  LiveCareClinicsListResponse liveCareClinicsListResponse;

  List<PatientERGetClinicsList> liveCareOnlineClinicsListResponse;
  List<PatientERGetClinicsList> liveCareOfflineClinicsListResponse;

  LiveCareScheduleClinicsListResponse liveCareScheduleClinicsListResponse;

  bool isDataLoaded = false;
  var languageID;
  var currentSelectedLiveCareType;

  int selectedClinicID = 1;
  String selectedClinicName = "-";

  AppSharedPreferences sharedPref = AppSharedPreferences();

  AuthenticatedUser authUser;
  AuthProvider authProvider = new AuthProvider();

  MyInAppBrowser browser;

  String liveCareClinicIDs;

  @override
  void initState() {
    liveCareClinicsListResponse = new LiveCareClinicsListResponse();

    liveCareOnlineClinicsListResponse = new List();
    liveCareOfflineClinicsListResponse = new List();

    liveCareScheduleClinicsListResponse = new LiveCareScheduleClinicsListResponse();

    WidgetsBinding.instance.addPostFrameCallback((_) {
      if (LiveCareHome.isLiveCareTypeSelected != true) {
        openLiveCareSelectionDialog();
      } else {
        setState(() {
          currentSelectedLiveCareType = "immediate";
          getLiveCareClinicsList();
        });
      }
    });

    getLanguageID();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: currentSelectedLiveCareType == "immediate" ? getLiveCareImmediateClinicList() : getLiveCareScheduleClinicList(),
    );
  }

  void startLiveCare() {
    bool isError = false;
    LiveCareService service = new LiveCareService();
    GifLoaderDialogUtils.showMyDialog(context);
    ERAppointmentFeesResponse erAppointmentFeesResponse = new ERAppointmentFeesResponse();
    service.getERAppointmentFees(selectedClinicID, context).then((res) {
      GifLoaderDialogUtils.hideDialog(context);
      if (res['HasAppointment'] == true) {
        isError = true;
        showLiveCareCancelDialog(res['ErrorEndUserMessage'], res);
      } else {
        erAppointmentFeesResponse = ERAppointmentFeesResponse.fromJson(res);
        isError = false;
      }
      if (!isError) getERAppointmentTime(erAppointmentFeesResponse.getERAppointmentFeesList);
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      print(err);
      isError = true;
      AppToast.showErrorToast(message: err);
    });
  }

  showLiveCareCancelDialog(String msg, res) {
    ConfirmDialog dialog = new ConfirmDialog(
        context: context,
        confirmMessage: msg,
        okText: TranslationBase.of(context).confirm,
        cancelText: TranslationBase.of(context).cancel_nocaps,
        okFunction: () => {cancelAppointment(res)},
        cancelFunction: () => {});
    dialog.showAlertDialog(context);
  }

  cancelAppointment(res) {
    AppoitmentAllHistoryResultList appo = AppoitmentAllHistoryResultList();
    appo.clinicID = res['ClinicID'];
    appo.doctorID = res['DoctorID'];
    appo.endTime = res['EndTime'];
    appo.projectID = res['ProjectID'];
    appo.startTime = res['StrAppointmentDate'];
    appo.appointmentNo = res['AppointmentID'];
    appo.isLiveCareAppointment = true;
    appo.originalClinicID = 0;
    appo.originalProjectID = res['ProjectID'];
    appo.appointmentDate = res['AppointmentDate'];

    ConfirmDialog.closeAlertDialog(context);
    GifLoaderDialogUtils.showMyDialog(context);
    DoctorsListService service = new DoctorsListService();
    service.cancelAppointment(appo, context).then((res) {
      GifLoaderDialogUtils.hideDialog(context);
      print(res);
      if (res['MessageStatus'] == 1) {
        AppToast.showSuccessToast(message: res['ErrorEndUserMessage']);
        startLiveCare();
      } else {
        AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
      }
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      AppToast.showErrorToast(message: err);
      print(err);
    });
  }

  getERAppointmentTime(GetERAppointmentFeesList getERAppointmentFeesList) {
    LiveCareService service = new LiveCareService();
    GifLoaderDialogUtils.showMyDialog(context);
    service.getERAppointmentTime(selectedClinicID, context).then((res) {
      GifLoaderDialogUtils.hideDialog(context);
      showLiveCarePaymentDialog(getERAppointmentFeesList, res['WatingtimeInteger']);
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      print(err);
      AppToast.showErrorToast(message: err);
    });
  }

  showLiveCarePaymentDialog(GetERAppointmentFeesList getERAppointmentFeesList, int waitingTime) {
    navigateTo(context, LiveCarePatmentPage(getERAppointmentFeesList: getERAppointmentFeesList, waitingTime: waitingTime, clinicName: selectedClinicName)).then(
      (value) {
        if (value) {
          if (getERAppointmentFeesList.total == "0" || getERAppointmentFeesList.total == "0.0") {
            showLiveCareInfoDialog(getERAppointmentFeesList);
          } else {
            navigateToPaymentMethod(getERAppointmentFeesList, context);
          }
        }
      },
    );
    // showGeneralDialog(
    //         barrierColor: Colors.black.withOpacity(0.5),
    //         transitionBuilder: (context, a1, a2, widget) {
    //           final curvedValue = Curves.easeInOutBack.transform(a1.value) - 1.0;
    //           return Transform(
    //             transform: Matrix4.translationValues(0.0, curvedValue * 200, 0.0),
    //             child: Opacity(
    //               opacity: a1.value,
    //               child: LiveCarePaymentDialog(getERAppointmentFeesList: getERAppointmentFeesList, waitingTime: waitingTime, clinicName: selectedClinicName),
    //             ),
    //           );
    //         },
    //         transitionDuration: Duration(milliseconds: 500),
    //         barrierDismissible: true,
    //         barrierLabel: '',
    //         context: context,
    //         pageBuilder: (context, animation1, animation2) {})
    //     .then((value) {
    //   if (value) {
    //     if (getERAppointmentFeesList.total == "0" || getERAppointmentFeesList.total == "0.0") {
    //       showLiveCareInfoDialog(getERAppointmentFeesList);
    //     } else {
    //       navigateToPaymentMethod(getERAppointmentFeesList, context);
    //     }
    //   }
    // });
  }

  showLiveCareInfoDialog(GetERAppointmentFeesList getERAppointmentFeesList) async {
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      setState(() {
        authUser = data;
      });
    }

    showGeneralDialog(
            barrierColor: Colors.black.withOpacity(0.5),
            transitionBuilder: (context, a1, a2, widget) {
              final curvedValue = Curves.easeInOutBack.transform(a1.value) - 1.0;
              return Transform(
                transform: Matrix4.translationValues(0.0, curvedValue * 200, 0.0),
                child: Opacity(
                  opacity: a1.value,
                  child: LiveCareInfoDialog(),
                ),
              );
            },
            transitionDuration: Duration(milliseconds: 500),
            barrierDismissible: true,
            barrierLabel: '',
            context: context,
            pageBuilder: (context, animation1, animation2) {})
        .then((value) {
      if (value) {
        if (getERAppointmentFeesList.total == "0" || getERAppointmentFeesList.total == "0.0") {
          addNewCallForPatientER(authUser.patientID.toString() + "" + DateTime.now().millisecondsSinceEpoch.toString());
        } else {
          navigateToPaymentMethod(getERAppointmentFeesList, context);
        }
      }
    });
  }

  Future navigateToPaymentMethod(GetERAppointmentFeesList getERAppointmentFeesList, context) async {
    AppoitmentAllHistoryResultList appo = new AppoitmentAllHistoryResultList();

    appo.clinicID = selectedClinicID;
    appo.appointmentNo = DateTime.now().millisecondsSinceEpoch;
    appo.projectID = 12;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      setState(() {
        authUser = data;
      });
    }

    Navigator.push(context, FadePage(page: PaymentMethod(onSelectedMethod: (String metohd) {
      setState(() {});
    }))).then((value) {
      print(value);
      if (value != null) {
        openPayment(value, authUser, double.parse(getERAppointmentFeesList.total), appo);
      }
    });
  }

  openPayment(String paymentMethod, AuthenticatedUser authenticatedUser, double amount, AppoitmentAllHistoryResultList appo) {
    browser = new MyInAppBrowser(onExitCallback: onBrowserExit, appo: appo, onLoadStartCallback: onBrowserLoadStart, context: context);

    browser.openPaymentBrowser(amount, "LiveCare Payment", Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo), "12", authenticatedUser.emailAddress, paymentMethod,
        authenticatedUser.patientType, authenticatedUser.firstName, authenticatedUser.patientID, authenticatedUser, browser, false, "4", selectedClinicID.toString());
  }

  onBrowserLoadStart(String url) {
    print("onBrowserLoadStart");
    print(url);

    MyInAppBrowser.successURLS.forEach((element) {
      if (url.contains(element)) {
        if (browser.isOpened()) browser.close();
        MyInAppBrowser.isPaymentDone = true;
        return;
      }
    });

    MyInAppBrowser.errorURLS.forEach((element) {
      if (url.contains(element)) {
        if (browser.isOpened()) browser.close();
        MyInAppBrowser.isPaymentDone = false;
        return;
      }
    });
  }

  onBrowserExit(AppoitmentAllHistoryResultList appo, bool isPaymentMade) {
    print("onBrowserExit Called!!!!");
    if (isPaymentMade) checkPaymentStatus(appo);
  }

  checkPaymentStatus(AppoitmentAllHistoryResultList appo) {
    DoctorsListService service = new DoctorsListService();
    GifLoaderDialogUtils.showMyDialog(context);
    service.checkPaymentStatus(Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo), context).then((res) {
      GifLoaderDialogUtils.hideDialog(context);
      print("Printing Payment Status Reponse!!!!");
      print(res);
      String paymentInfo = res['Response_Message'];
      if (paymentInfo == 'Success') {
        addNewCallForPatientER(Utils.getAppointmentTransID(appo.projectID, appo.clinicID, appo.appointmentNo));
      } else {
        AppToast.showErrorToast(message: res['Response_Message']);
      }
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      AppToast.showErrorToast(message: err);
      print(err);
    });
  }

  addNewCallForPatientER(String clientRequestID) {
    LiveCareService service = new LiveCareService();
    GifLoaderDialogUtils.showMyDialog(context);
    service.addNewCallForPatientER(selectedClinicID, clientRequestID, context).then((res) {
      GifLoaderDialogUtils.hideDialog(context);
      AppToast.showSuccessToast(message: "New Call has been added successfully");
      widget.getLiveCareHistory();
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      AppToast.showErrorToast(message: err);
      print(err);
    });
  }

  getLanguageID() async {
    languageID = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
  }

  getLiveCareClinicsList() {
    isDataLoaded = false;
    LiveCareService service = new LiveCareService();
    GifLoaderDialogUtils.showMyDialog(context);
    service.getLivecareClinics(context).then((res) {
      GifLoaderDialogUtils.hideDialog(context);
      print(res['PatientER_GetClinicsList'].length);
      if (res['MessageStatus'] == 1) {
        setState(() {
          liveCareOnlineClinicsListResponse.clear();
          liveCareClinicsListResponse = LiveCareClinicsListResponse.fromJson(res);

          liveCareClinicsListResponse.patientERGetClinicsList.forEach((clinic) {
            if (clinic.isOnline == 1) {
              liveCareOnlineClinicsListResponse.add(clinic);
            } else {
              liveCareOfflineClinicsListResponse.add(clinic);
            }
          });

          selectedClinicID = liveCareClinicsListResponse.patientERGetClinicsList[0].serviceID;
          selectedClinicName = liveCareClinicsListResponse.patientERGetClinicsList[0].serviceName;
          isDataLoaded = true;
        });
      } else {
        isDataLoaded = true;
        AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
      }
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      // AppToast.showErrorToast(message: err);
      print(err);
    });
  }

  getLiveCareScheduleClinicsList() {
    isDataLoaded = false;
    LiveCareService service = new LiveCareService();
    GifLoaderDialogUtils.showMyDialog(context);
    service.getLiveCareScheduledClinics(context).then((res) {
      GifLoaderDialogUtils.hideDialog(context);
      print(res['ClinicsHaveScheduleList'].length);
      if (res['MessageStatus'] == 1) {
        setState(() {
          liveCareScheduleClinicsListResponse = LiveCareScheduleClinicsListResponse.fromJson(res);
          selectedClinicID = liveCareScheduleClinicsListResponse.clinicsHaveScheduleList[0].serviceID;
          selectedClinicName = liveCareScheduleClinicsListResponse.clinicsHaveScheduleList[0].clinicDesc;
          isDataLoaded = true;
        });
      } else {
        isDataLoaded = true;
        AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
      }
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      AppToast.showErrorToast(message: err);
      print(err);
    });
  }

  openLiveCareSelectionDialog() async {
    liveCareClinicIDs = await sharedPref.getString(LIVECARE_CLINIC_DATA);
    if (liveCareClinicIDs != null) {
      selectedClinicID = int.parse(liveCareClinicIDs.split("-")[2]);
      setState(() {
        currentSelectedLiveCareType = "immediate";
      });
      getLiveCareClinicsList();
      startLiveCare();
    } else {
      Navigator.of(context)
          .push(new MaterialPageRoute<String>(
              builder: (BuildContext context) {
                return LiveCareTypeSelect();
              },
              fullscreenDialog: true))
          .then((value) {
        if (value == null) {
          Navigator.pop(context);
        } else {
          print(value);
          if (value == "immediate") {
            setState(() {
              LiveCareHome.isLiveCareTypeSelected = true;
              currentSelectedLiveCareType = "immediate";
            });
            getLiveCareClinicsList();
          }
          if (value == "schedule") {
            setState(() {
              LiveCareHome.isLiveCareTypeSelected = true;
              currentSelectedLiveCareType = "schedule";
            });
            getLiveCareScheduleClinicsList();
          }
        }
      });
    }
  }

  Widget getLiveCareScheduleClinicList() {
    return Column(
      children: <Widget>[
        isDataLoaded
            ? Expanded(
              child: Container(
                  child: liveCareScheduleClinicsListResponse.clinicsHaveScheduleList.length > 0
                      ? Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            mHeight(10),
                            ListView.builder(
                              scrollDirection: Axis.vertical,
                              shrinkWrap: true,
                              physics: ScrollPhysics(),
                              padding: EdgeInsets.all(0.0),
                              itemCount: liveCareScheduleClinicsListResponse.clinicsHaveScheduleList.length,
                              itemBuilder: (context, index) {
                                return InkWell(
                                  onTap: () {
                                    updateSelectedScheduleIndex(liveCareScheduleClinicsListResponse.clinicsHaveScheduleList[index]);
                                  },
                                  child: ScheduleClinicCard(
                                    isSelected: selectedClinicID == liveCareScheduleClinicsListResponse.clinicsHaveScheduleList[index].serviceID ? true : false,
                                    clinicsHaveScheduleList: liveCareScheduleClinicsListResponse.clinicsHaveScheduleList[index],
                                    languageID: languageID,
                                  ),
                                );
                              },
                            ),
                            Container(
                              height: 10.0,
                            ),
                          ],
                        )
                      : getNoDataWidget(context),
                ),
            )
            : Container(),
        isDataLoaded
            ? Container(
              width: double.infinity,
         color: Colors.white,
              padding: EdgeInsets.all(12),
              child: ButtonTheme(
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(10.0),
                ),
                minWidth: MediaQuery.of(context).size.width * 0.7,
                height: 45.0,
                child: RaisedButton(
                  color: CustomColors.accentColor,
                  textColor: Colors.white,
                  elevation: 0,
                  disabledTextColor: Colors.white,
                  disabledColor: new Color(0xFFbcc2c4),
                  onPressed: startScheduleLiveCare,
                  child: Text(TranslationBase.of(context).start, style: TextStyle(fontSize: 18.0)),
                ),
              ),
            )
            : Container(),
      ],
    );
  }

  Widget getLiveCareImmediateClinicList() {
    return Column(
      children: <Widget>[
        isDataLoaded
            ? Expanded(
                child: Container(
                  child: SingleChildScrollView(
                      child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      ListView.builder(
                        scrollDirection: Axis.vertical,
                        shrinkWrap: true,
                        physics: ScrollPhysics(),
                        padding: const EdgeInsets.only(top: 16.0),
                        itemCount: liveCareOnlineClinicsListResponse.length,
                        itemBuilder: (context, index) {
                          return InkWell(
                            onTap: () {
                              updateSelectedIndex(liveCareOnlineClinicsListResponse[index]);
                            },
                            child: ClinicCard(
                              isSelected: selectedClinicID == liveCareOnlineClinicsListResponse[index].serviceID ? true : false,
                              patientERGetClinicsList: liveCareOnlineClinicsListResponse[index],
                              languageID: languageID,
                            ),
                          );
                        },
                      ),
                      // Container(
                      //   margin: EdgeInsets.all(15.0),
                      //   child: Text(TranslationBase.of(context).offlineClinics, style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold)),
                      // ),
                      ListView.builder(
                        scrollDirection: Axis.vertical,
                        shrinkWrap: true,
                        physics: ScrollPhysics(),
                        padding: EdgeInsets.all(0.0),
                        itemCount: liveCareOfflineClinicsListResponse.length,
                        itemBuilder: (context, index) {
                          return ClinicCard(
                            isSelected: selectedClinicID == liveCareOfflineClinicsListResponse[index].serviceID ? true : false,
                            patientERGetClinicsList: liveCareOfflineClinicsListResponse[index],
                            languageID: languageID,
                          );
                        },
                      ),
                      Container(
                        height: 10.0,
                      ),
                    ],
                  )),
                ),
              )
            : Container(),
        isDataLoaded
            ? Container(
                color: Colors.white,
                width: double.infinity,
                padding: EdgeInsets.all(16),
                child: DefaultButton(
                  TranslationBase.of(context).start,
                  () {
                    startLiveCare();
                  },
                ),
              )
            : Container(),
      ],
    );
  }

  void startScheduleLiveCare() {
    List<DoctorList> doctorsList = [];
    LiveCareService service = new LiveCareService();
    GifLoaderDialogUtils.showMyDialog(context);
    List<PatientDoctorAppointmentList> _patientDoctorAppointmentListHospital = List();
    service.getLiveCareScheduledDoctorList(context, selectedClinicID).then((res) {
      GifLoaderDialogUtils.hideDialog(context);
      if (res['MessageStatus'] == 1) {
        setState(() {
          if (res['DoctorByClinicIDList'].length != 0) {
            res['DoctorByClinicIDList'].forEach((v) {
              doctorsList.add(new DoctorList.fromJson(v));
            });

            doctorsList.forEach((element) {
              List<PatientDoctorAppointmentList> doctorByHospital = _patientDoctorAppointmentListHospital
                  .where(
                    (elementClinic) => elementClinic.filterName == element.projectName,
                  )
                  .toList();

              if (doctorByHospital.length != 0) {
                _patientDoctorAppointmentListHospital[_patientDoctorAppointmentListHospital.indexOf(doctorByHospital[0])].patientDoctorAppointmentList.add(element);
              } else {
                _patientDoctorAppointmentListHospital
                    .add(PatientDoctorAppointmentList(filterName: element.projectName, distanceInKMs: element.projectDistanceInKiloMeters.toString(), patientDoctorAppointment: element));
              }
            });
          } else {}
        });
        this.sharedPref.setBool(IS_LIVECARE_APPOINTMENT, true);
        navigateToSearchResults(context, doctorsList, _patientDoctorAppointmentListHospital);
      } else {}
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      AppToast.showErrorToast(message: err);
      print(err);
    });
  }

  Future navigateToSearchResults(context, List<DoctorList> docList, List<PatientDoctorAppointmentList> patientDoctorAppointmentListHospital) async {
    Navigator.push(context, FadePage(page: SearchResults(doctorsList: docList, isLiveCareAppointment: false, patientDoctorAppointmentListHospital: patientDoctorAppointmentListHospital)));
  }

  updateSelectedIndex(PatientERGetClinicsList patientERGetClinicsList) {
    setState(() {
      selectedClinicID = patientERGetClinicsList.serviceID;
      selectedClinicName = patientERGetClinicsList.serviceName;
    });
  }

  updateSelectedScheduleIndex(ClinicsHaveScheduleList patientERGetClinicsList) {
    setState(() {
      selectedClinicID = patientERGetClinicsList.serviceID;
      selectedClinicName = patientERGetClinicsList.clinicDesc;
    });
  }
}
