import 'dart:io';

import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
import 'package:diplomaticquarterapp/models/Appointments/DoctorProfile.dart';
import 'package:diplomaticquarterapp/models/Appointments/PatientShareResposne.dart';
import 'package:diplomaticquarterapp/models/Appointments/doctor_pre_post_image.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/models/Request.dart';
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:flutter/cupertino.dart';


class DoctorsListService extends BaseService {
  AppSharedPreferences sharedPref = AppSharedPreferences();
  AppGlobal appGlobal = new AppGlobal();

  AuthenticatedUser authUser = new AuthenticatedUser();
  AuthProvider authProvider = new AuthProvider();

  double lat;
  double long;
  String deviceToken;
  String tokenID;

  Future<Map> getDoctorsList(
      int clinicID, int projectID, bool isNearest, BuildContext context,
      {doctorId, doctorName, isContinueDentalPlan = false}) async {
    Map<String, dynamic> request;

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

    if (await this.sharedPref.getDouble(USER_LAT) != null &&
        await this.sharedPref.getDouble(USER_LONG) != null) {
      lat = await this.sharedPref.getDouble(USER_LAT);
      long = await this.sharedPref.getDouble(USER_LONG);
    }

    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": "10.20.10.20",
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "generalid": 'Cs2020@2016\$2958',
      "PatientOutSA": authProvider.isLogin ? authUser.outSA : 0,
      "TokenID": "",
      "DeviceTypeID": req.DeviceTypeID,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "ClinicID": clinicID,
      "ProjectID": projectID,
      "DoctorName": doctorName, //!= null ? doctorId : 0,
      "ContinueDentalPlan": isContinueDentalPlan,
      "IsSearchAppointmnetByClinicID": isContinueDentalPlan ? false : true,
      "PatientID": authUser.patientID != null ? authUser.patientID : 0,
      "gender": authUser.gender != null ? authUser.gender : 0,
      "age": authUser.age != null ? authUser.age : 0,
      "IsGetNearAppointment": false,
      "SearchForVoiceCommand":
          doctorId != null && doctorId.length > 0 ? true : false,
      "DoctorIDsList": doctorId,
      "Latitude": lat != null ? lat.toString() : 0,
      "Longitude": long != null ? long.toString() : 0,
      "isDentalAllowedBackend": isContinueDentalPlan,
      "IsGetNearAppointment": isNearest,
      if (isNearest)
        "SelectedDate": DateUtil.convertDateToString(DateTime.now()),
      "License": true
    };

    dynamic localRes;

    await baseAppClient.post(GET_DOCTORS_LIST_URL,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getDoctorsListByName(String docName, BuildContext context) async {
    Map<String, dynamic> request;

    double lat;
    double long;

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

    if (await this.sharedPref.getDouble(USER_LAT) != null &&
        await this.sharedPref.getDouble(USER_LONG) != null) {
      lat = await this.sharedPref.getDouble(USER_LAT);
      long = await this.sharedPref.getDouble(USER_LONG);
    }

    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": "10.20.10.20",
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "generalid": 'Cs2020@2016\$2958',
      "PatientOutSA": authProvider.isLogin ? authUser.outSA : false,
      "TokenID": "",
      "DeviceTypeID": req.DeviceTypeID,
      "SessionID": null,
      "ClinicID": 0,
      "ProjectID": 0,
      "ContinueDentalPlan": false,
      "IsSearchAppointmnetByClinicID": false,
      "DoctorName": docName,
      "PatientID": authUser.patientID != null ? authUser.patientID : 0,
      "gender": authUser.gender != null ? authUser.gender : 0,
      "age": authUser.age != null ? authUser.age : 0,
      "IsGetNearAppointment": false,
      "Latitude": lat,
      "Longitude": long,
      "License": true
    };

    dynamic localRes;

    await baseAppClient.post(GET_DOCTORS_LIST_URL,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getDoctorsProfile(
      int docID, int clinicID, int projectID, context) async {
    Map<String, dynamic> request;
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": "10.20.10.20",
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "generalid": 'Cs2020@2016\$2958',
      "PatientOutSA": authUser.outSA ?? false,
      "TokenID": "",
      "DeviceTypeID": req.DeviceTypeID,
      "SessionID": null,
      "doctorID": docID,
      "ClinicID": clinicID,
      "PatientID": 0,
      "License": true,
      "IsRegistered": true,
      "ProjectID": projectID,
      "isDentalAllowedBackend": false
    };

    dynamic localRes;

    await baseAppClient.post(GET_DOCTOR_PROFILE,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getDoctorsRating(int docID, context) async {
    Map<String, dynamic> request;
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": "10.20.10.20",
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "generalid": 'Cs2020@2016\$2958',
      "PatientOutSA": authUser.outSA,
      "TokenID": "",
      "DeviceTypeID": req.DeviceTypeID,
      "SessionID": null,
      "doctorID": docID,
      "PatientID": 0,
      "License": true,
      "IsRegistered": true,
      "isDentalAllowedBackend": false
    };

    dynamic localRes;

    await baseAppClient.post(GET_DOCTOR_RATING_NOTES,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<DoctorPrePostImages> getDoctorPrePostImages(
      DoctorProfileList doctorProfile, context) async {
    Map<String, dynamic> request;
    request = {
      "PatientOutSA": authUser.outSA ?? 0,
      "isDentalAllowedBackend": false,
      "DoctorID": doctorProfile.doctorID,
      "ClinicID": doctorProfile.clinicID,
      "ProjectID": doctorProfile.projectID
    };

    var images = DoctorPrePostImages();
    await baseAppClient.post(GET_DOCTOR_PRE_POST_IMAGES,
        onSuccess: (response, statusCode) async {
      var list = response['DoctorPrePostImagesList'];
      if (list is List && list.length > 0) {
        list.forEach((j) {
          var image = DoctorPrePostImageModel.fromJson(j);
          if (image.imageType == 1) images.pre = image;
          if (image.imageType == 2) images.post = image;
        });
      }
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(images);
  }

  Future<Map> getDoctorsRatingDetails(int docID, context) async {
    Map<String, dynamic> request;
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": "10.20.10.20",
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "generalid": 'Cs2020@2016\$2958',
      "PatientOutSA": authUser.outSA,
      "TokenID": "",
      "DeviceTypeID": req.DeviceTypeID,
      "SessionID": null,
      "DoctorID": docID,
      "PatientID": 0,
      "License": true,
      "IsRegistered": true,
      "isDentalAllowedBackend": false
    };

    dynamic localRes;

    await baseAppClient.post(GET_DOCTOR_RATING_DETAILS,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getDoctorFreeSlots(
      int docID, int clinicID, int projectID, BuildContext context) async {
    Map<String, dynamic> request;
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "DoctorID": docID,
      "IsBookingForLiveCare": 0,
      "ClinicID": clinicID,
      "ProjectID": projectID,
      "OriginalClinicID": clinicID,
      "days": 0,
      "isReschadual": false,
      "VersionID": req.VersionID,
      "Channel": 3,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": "10.20.10.20",
      "generalid": "Cs2020@2016\$2958",
      "PatientOutSA": authUser.outSA,
      "SessionID": null,
      "isDentalAllowedBackend": false,
      "DeviceTypeID": 1
    };

    dynamic localRes;

    await baseAppClient.post(GET_DOCTOR_FREE_SLOTS,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getDoctorScheduledFreeSlots(int docID, int clinicID,
      int projectID, int serviceID, BuildContext context) async {
    Map<String, dynamic> request;
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "DoctorID": docID,
      "IsBookingForLiveCare": 1,
      "ClinicID": clinicID,
      "ProjectID": projectID,
      "OriginalClinicID": clinicID,
      "ServiceID": serviceID,
      "days": 50,
      "isReschadual": false,
      "VersionID": req.VersionID,
      "Channel": 3,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": "10.20.10.20",
      "generalid": "Cs2020@2016\$2958",
      "PatientOutSA": authUser.outSA,
      "SessionID": null,
      "isDentalAllowedBackend": false,
      "DeviceTypeID": 1
    };

    dynamic localRes;

    await baseAppClient.post(GET_LIVECARE_SCHEDULE_DOCTOR_TIME_SLOTS,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> insertAppointment(int docID, int clinicID, int projectID,
      String selectedTime, String selectedDate, BuildContext context,
      [String procedureID]) async {
    Map<String, dynamic> request;

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

    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "IsForLiveCare": false,
      "ProjectID": projectID,
      "ClinicID": clinicID,
      "DoctorID": docID,
      "StartTime": selectedTime,
      "SelectedTime": selectedTime,
      "EndTime": selectedTime,
      "ProcedureID": procedureID,
      "InitialSlotDuration": 0,
      "StrAppointmentDate": selectedDate,
      "IsVirtual": false,
      "DeviceType": Platform.isIOS ? 'iOS' : 'Android',
      "BookedBy": 102,
      "VisitType": 1,
      "VisitFor": 1,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(INSERT_SPECIFIC_APPOINTMENT,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> insertLiveCareScheduleAppointment(
      int docID,
      int clinicID,
      int projectID,
      int serviceID,
      String selectedTime,
      String selectedDate,
      BuildContext context) async {
    Map<String, dynamic> request;

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

    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "IsForLiveCare": true,
      "ProjectID": projectID,
      "ClinicID": clinicID,
      "DoctorID": docID,
      "ServiceID": serviceID,
      "StartTime": selectedTime,
      "SelectedTime": selectedTime,
      "EndTime": selectedTime,
      "InitialSlotDuration": 0,
      "StrAppointmentDate": selectedDate,
      "IsVirtual": false,
      "DeviceType": Platform.isIOS ? 'iOS' : 'Android',
      "BookedBy": 102,
      "VisitType": 1,
      "VisitFor": 1,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(INSERT_LIVECARE_SCHEDULE_APPOINTMENT,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientShare(
      String appoID, int clinicID, int projectID, BuildContext context) async {
    Map<String, dynamic> request;

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

    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();

    request = {
      "ProjectID": projectID,
      "ClinicID": clinicID,
      "AppointmentNo": appoID,
      "IsActiveAppointment": true,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(GET_PATIENT_SHARE,
        onSuccess: (response, statusCode) async {
      localRes = response['OnlineCheckInAppointments'][0];
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getLiveCareAppointmentPatientShare(
      String appoID, int clinicID, int projectID, BuildContext context) async {
    Map<String, dynamic> request;

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

    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();

    request = {
      "ProjectID": projectID,
      "ClinicID": clinicID,
      "AppointmentNo": appoID,
      "IsActiveAppointment": true,
      "IsForLiveCare": true,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(GET_PATIENT_SHARE_LIVECARE,
        onSuccess: (response, statusCode) async {
      localRes = response['OnlineCheckInAppointments'][0];
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientAppointmentHistory(
      bool isActiveAppointment, BuildContext context) async {
    Map<String, dynamic> request;

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

    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();

    request = {
      "IsActiveAppointment": isActiveAppointment,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": 0,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(GET_PATIENT_APPOINTMENT_HISTORY,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientAppointmentCurfewHistory(
      bool isActiveAppointment) async {
    Map<String, dynamic> request;
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();

    request = {
      "IsActiveAppointment": isActiveAppointment,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": 0,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": 1231755,
      "TokenID": "@dm!n",
      "PatientTypeID": 1,
      "PatientType": 1
    };

    dynamic localRes;

    await baseAppClient.post(GET_PATIENT_APPOINTMENT_CURFEW_HISTORY,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> confirmAppointment(int appoNo, int clinicID, int projectID,
      bool isLiveCare, BuildContext context) async {
    Map<String, dynamic> request;

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

    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();

    request = {
      "AppointmentNumber": appoNo,
      "IsLiveCareAppointment": isLiveCare,
      "ClinicID": clinicID,
      "ProjectID": projectID,
      "ConfirmationBy": 102,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": 0,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(CONFIRM_APPOINTMENT,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> insertVIDARequest(int appoNo, int clinicID, int projectID,
      int serviceID, int docID, BuildContext context) async {
    Map<String, dynamic> request;

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

    deviceToken = await sharedPref.getString(PUSH_TOKEN);

    if (await this.sharedPref.getDouble(USER_LAT) != null &&
        await this.sharedPref.getDouble(USER_LONG) != null) {
      lat = await this.sharedPref.getDouble(USER_LAT);
      long = await this.sharedPref.getDouble(USER_LONG);
    }

    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();

    request = {
      "AppointmentNo": appoNo,
      "ClinicID": clinicID,
      "ProjectID": projectID,
      "ServiceID": serviceID,
      "AcceptedBy": docID,
      "DeviceToken": deviceToken,
      "Latitude": lat,
      "Longitude": long,
      "DeviceType": req.DeviceType,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(INSERT_VIDA_REQUEST,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> cancelAppointment(
      AppoitmentAllHistoryResultList appo, BuildContext context) async {
    Map<String, dynamic> request;

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

    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();

    request = {
      "AppointmentID": appo.appointmentNo,
      "ClinicID": appo.clinicID,
      "ProjectID": appo.projectID,
      "EndTime": appo.endTime,
      "StartTime": appo.startTime,
      "DoctorID": appo.doctorID,
      "IsForLiveCare": appo.isLiveCareAppointment,
      "OriginalClinicID": appo.originalClinicID,
      "OriginalProjectID": appo.originalProjectID,
      "StrAppointmentDate": DateUtil.getDateFormatted(appo.appointmentDate),
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(CANCEL_APPOINTMENT,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> generateAppointmentQR(
      PatientShareResponse patientShareResponse, BuildContext context) async {
    Map<String, dynamic> request;

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

    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();

    request = {
      "AppointmentNo": patientShareResponse.appointmentNo,
      "ClinicID": patientShareResponse.clinicID,
      "ProjectID": patientShareResponse.projectID,
      "IsFollowup": patientShareResponse.isFollowup,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(GENERATE_QR_APPOINTMENT,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> sendAppointmentQREmail(
      String to,
      String appoDate,
      String appoNo,
      String docName,
      String projName,
      String QR,
      String speciality,
      BuildContext context) async {
    Map<String, dynamic> request;

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

    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();

    request = {
      "AppointmentNo": appoNo,
      "AppointmentDate": appoDate,
      "DoctorName": docName,
      "ProjectName": projName,
      "QR": QR,
      "Speciality": speciality,
      "To": to,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(EMAIL_QR_APPOINTMENT,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> checkPaymentStatus(
      String transactionID, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "ClientRequestID": transactionID,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };
    dynamic localRes;
    await baseAppClient.post(CHECK_PAYMENT_STATUS,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> addAdvancedNumberRequest(
      String advanceNumber,
      String paymentReference,
      dynamic appointmentID,
      BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "AdvanceNumber": advanceNumber,
      "PaymentReferenceNumber": paymentReference,
      "AppointmentID": appointmentID,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };
    dynamic localRes;
    await baseAppClient.post(ADD_ADVANCE_NUMBER_REQUEST,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> addVIDARequest(String advanceNumber, String paymentReference,
      dynamic apptData, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "AdvanceNumber": advanceNumber,
      "PaymentReferenceNumber": paymentReference,
      "AppointmentNo": apptData.AppointmentNo,
      "AcceptedBy": apptData.DoctorID,
      "ServiceID": apptData.ServiceID,
      "ProjectID": apptData.ProjectID,
      "ClinicID": apptData.ClinicID,
      "ClientRequestID": Utils.getAppointmentTransID(
          apptData.ProjectID, apptData.ClinicID, apptData.AppointmentNo),
      "AppointmentDate": apptData.AppointmentDate,
      "DeviceType": Platform.isIOS ? "iOS" : "Android",
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    // request.DeviceToken = this.cs.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false);
    // request.Latitude = this.cs.sharedService.getSharedData('userLat', false);
    // request.Longitude = this.cs.sharedService.getSharedData('userLong', false);
    // request.ServiceID = apptData.ServiceID;
    // request.ProjectID = apptData.ProjectID;
    // request.ClinicID = apptData.ClinicID;
    // request.ClientRequestID = AppointmentModel.getAppointmentTransID(apptData);
    // request.AppointmentDate = apptData.AppointmentDate;
    // request.DeviceType = this.getDeviceType();
    // request.VoipToken = this.platform.is('ios') ? this.cs.sharedService.getSharedData(AuthenticationService.APNS_TOKEN, false) : "";
    dynamic localRes;
    await baseAppClient.post(ADD_VIDA_REQUEST,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> isAllowedToAskDoctor(int docID, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "IsForAskYourDoctor": true,
      "DoctorID": docID,
      "Top": 25,
      "beforeDays": 15,
      "exludType": 4,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(IS_ALLOW_ASK_DOCTOR,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getCallRequestType(BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(GET_CALL_REQUEST_TYPE,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> sendAskDocCallRequest(AppoitmentAllHistoryResultList appo,
      String requestType, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();

    request = {
      "ProjectID": appo.projectID,
      "SetupID": appo.setupID,
      "DoctorID": appo.doctorID,
      "RequestType": requestType,
      "RequestTypeID": requestType,
      "PatientMobileNumber": authUser.mobileNumber,
      "IsMessageSent": false,
      "RequestDate":
          DateUtil.getYearMonthDayHourMinSecDateFormatted(DateTime.now())
              .split(" ")[0],
      "RequestTime":
          DateUtil.getYearMonthDayHourMinSecDateFormatted(DateTime.now())
              .split(" ")[1],
      "Remarks": "",
      "Status": 1,
      "CreatedBy": 102,
      "CreatedOn":
          DateUtil.getYearMonthDayHourMinSecDateFormatted(DateTime.now())
              .split(" ")[0],
      "EditedBy": 102,
      "EditedOn":
          DateUtil.getYearMonthDayHourMinSecDateFormatted(DateTime.now())
              .split(" ")[0],
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(SEND_CALL_REQUEST,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientRadOrders(String appoNo, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "AppointmentNo": appoNo,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(GET_PATIENT_ORDERS,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientLabOrdersByAppoNo(dynamic appoNo, dynamic projID,
      dynamic clinicID, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "AppointmentNo": appoNo,
      "ProjectID": projID,
      "ClinicID": clinicID,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(GET_PATIENT_LAB_ORDERS_BY_APPOINTMENT,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientPrescriptionReports(
      AppoitmentAllHistoryResultList appo, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "AppointmentNo": appo.appointmentNo,
      "ClinicID": appo.clinicID,
      "ProjectID": appo.projectID,
      "EpisodeID": appo.episodeID,
      "VersionID": req.VersionID,
      "SetupID": appo.setupID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(GET_PRESCRIPTION_REPORT_ENH,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> sendPrescriptionEmail(String appoDate, String setupId,
      dynamic prescriptionReportEnhList, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "AppointmentDate": appoDate,
      "DateofBirth": authUser.dateofBirth,
      "ListPrescriptions": prescriptionReportEnhList,
      "PatientIditificationNum": authUser.patientIdentificationNo,
      "PatientMobileNumber": authUser.mobileNumber,
      "PatientName": authUser.firstName + " " + authUser.lastName,
      "To": authUser.emailAddress,
      "SetupID": setupId,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(SEND_PRESCRIPTION_EMAIL,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> createAdvancePayment(
      AppoitmentAllHistoryResultList appo,
      String projectID,
      double payedAmount,
      String paymentReference,
      String paymentMethodName,
      BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "ProjectID": projectID,
      "OnlineCheckInAppointment": {
        "AppointmentNo": appo != null ? appo.appointmentNo.toString() : "0",
        "PaymentMethodName": paymentMethodName,
        "PaymentAmount": payedAmount == 0 ? "0" : payedAmount.toString(),
        "PaymentDate": payedAmount == 0
            ? ""
            : "/Date(" +
                DateTime.now().millisecondsSinceEpoch.toString() +
                ")/",
        "PaymentReferenceNumber": payedAmount == 0 ? "" : paymentReference,
        "ProjectID": appo != null ? appo.projectID.toString() : projectID,
        "PatientID": authUser.patientID,
        "ClinicID": appo != null ? appo.clinicID : "0",
        "UserID": authUser.patientID,
        "Status": authUser.patientType
      },
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };
    dynamic localRes;
    await baseAppClient.post(CREATE_ADVANCE_PAYMENT,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> HIS_createAdvancePayment(
      AppoitmentAllHistoryResultList appo,
      String projectID,
      double payedAmount,
      String paymentReference,
      String paymentMethodName,
      dynamic patientType,
      String patientName,
      dynamic patientID,
      BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();

    request = {
      "CustName": patientName,
      "CustID": patientID,
      "SetupID": "010266",
      "ProjectID": projectID,
      "PatientID": patientID,
      "AccountID": patientID,
      "PaymentAmount": payedAmount,
      "NationalityID": null,
      "DepositorName": authUser.firstName + " " + authUser.lastName,
      "CreatedBy": 3,
      "PaymentMethodName": paymentMethodName,
      "PaymentReference": paymentReference,
      "PaymentMethod": paymentMethodName,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "TokenID": "@dm!n",
      "PatientTypeID": patientType,
      "PatientType": patientType
    };
    dynamic localRes;
    await baseAppClient.post(HIS_CREATE_ADVANCE_PAYMENT,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientHealthDataStats(
      int medCategoryId, int medCategoryStsId, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(
          await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    var languageID =
        await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
    Request req = appGlobal.getPublicRequest();
    request = {
      "MedCategoryID": medCategoryId,
      "MedGetStsID": medCategoryStsId,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": languageID == 'ar' ? 1 : 2,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "TokenID": "@dm!n",
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };
    dynamic localRes;
    await baseAppClient.post(GET_PATIENT_HEALTH_STATS,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> sendCheckinNfcRequest(int appointmentNo, String nfcCode,
      int projectId, BuildContext context) async {
    Map<String, dynamic> request;

    request = {
      "AppointmentNo": appointmentNo,
      "NFC_Code": nfcCode,
      "ProjectID": projectId,
    };
    dynamic localRes;
    await baseAppClient.post(SEND_CHECK_IN_NFC_REQUEST,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> checkIfHasDentalPlan(int projectID, BuildContext context) async {
    Map<String, dynamic> request;

    request = {
      "ProjectID": projectID,
    };
    dynamic localRes;
    await baseAppClient.post(HAS_DENTAL_PLAN,
        onSuccess: (response, statusCode) async {
          localRes = response;
        }, onFailure: (String error, int statusCode) {
          throw error;
        }, body: request);
    return Future.value(localRes);
  }

}
