You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/pages/MyAppointments/widgets/AppointmentActions.dart

700 lines
25 KiB
Dart

import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/core/model/labs/patient_lab_orders.dart';
import 'package:diplomaticquarterapp/core/model/prescriptions/prescription_report_enh.dart';
import 'package:diplomaticquarterapp/core/model/radiology/final_radiology.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
import 'package:diplomaticquarterapp/models/Appointments/appoDetailsButtons.dart';
import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/models/AppointmentType.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/models/ArrivedButtons.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/models/AskDocRequestTypeModel.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/models/BookedButtons.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/models/BookedButtonsAllowCheckIn.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/models/ConfirmedButtons.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/models/ConfirmedButtonsAllowCheckIn.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/PrescriptionReport.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/askDocDialog.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/reminder_dialog.dart';
import 'package:diplomaticquarterapp/pages/feedback/feedback_home_page.dart';
import 'package:diplomaticquarterapp/pages/insurance/insurance_approval_screen.dart';
import 'package:diplomaticquarterapp/pages/medical/labs/laboratory_result_page.dart';
import 'package:diplomaticquarterapp/pages/medical/radiology/radiology_details_page.dart';
import 'package:diplomaticquarterapp/pages/medical/vital_sign/vital_sign_details_screen.dart';
import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart';
import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.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/widgets/data_display/text.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/material.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
class AppointmentActions extends StatefulWidget {
AppoitmentAllHistoryResultList appo;
TabController tabController;
final Function enableFooterButton;
MyInAppBrowser browser;
AppointmentActions(
{@required this.appo,
@required this.tabController,
@required this.enableFooterButton});
@override
_AppointmentActionsState createState() => _AppointmentActionsState();
}
class _AppointmentActionsState extends State<AppointmentActions> {
List<AppoDetailsButton> appoButtonsList = [];
ToDoCountProviderModel toDoProvider;
@override
void initState() {
_getAppointmentActionButtons();
super.initState();
}
@override
Widget build(BuildContext context) {
ProjectViewModel projectViewModel = Provider.of(context);
toDoProvider = Provider.of<ToDoCountProviderModel>(context);
var size = MediaQuery.of(context).size;
final double itemHeight = projectViewModel.isArabic
? ((size.height - kToolbarHeight - 24) * 0.5) / 2
: ((size.height - kToolbarHeight - 24) * 0.45) / 2;
final double itemWidth = size.width / 2;
return Container(
margin: EdgeInsets.all(5.0),
child: CustomScrollView(
primary: false,
physics: NeverScrollableScrollPhysics(),
slivers: <Widget>[
SliverPadding(
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
sliver: SliverGrid.count(
crossAxisCount: 2,
childAspectRatio: (itemWidth / itemHeight),
children: appoButtonsList
.map((e) => GestureDetector(
onTap: () {
_handleButtonClicks(e);
},
child: Container(
margin: EdgeInsets.all(8.0),
padding: EdgeInsets.only(bottom: 4.0),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey[400],
blurRadius: 2.0,
spreadRadius: 0.0)
],
borderRadius: BorderRadius.circular(10),
color: Colors.white),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
margin:
EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0),
child: Texts(
e.title,
color: Color(0xffB8382C),
variant: "overline",
fontSize: SizeConfig.textMultiplier * 2.1,
),
),
Container(
margin:
EdgeInsets.fromLTRB(5.0, 0.0, 5.0, 0.0),
child: Texts(
e.subtitle,
color: Colors.black,
variant: "overline",
fontSize: SizeConfig.textMultiplier * 1.9,
),
),
],
),
),
Container(
alignment: projectViewModel.isArabic
? Alignment.bottomLeft
: Alignment.bottomRight,
margin: projectViewModel.isArabic
? EdgeInsets.fromLTRB(
10.0, 7.0, 0.0, 8.0)
: EdgeInsets.fromLTRB(
0.0, 7.0, 10.0, 8.0),
child: Image.asset(e.icon,
width: 40.0, height: 40.0),
),
],
),
),
))
.toList(),
),
),
],
),
);
}
_handleButtonClicks(AppoDetailsButton) {
print(AppoDetailsButton.caller);
switch (AppoDetailsButton.caller) {
case "openReschedule":
widget.tabController.animateTo((widget.tabController.index + 1) % 2);
setState(() {
print("Reschedule");
widget.enableFooterButton();
});
break;
case "onCancelAppointment":
ConfirmDialog dialog = new ConfirmDialog(
context: context,
confirmMessage: TranslationBase.of(context).cancelAppoMsg,
okText: TranslationBase.of(context).confirm,
cancelText: TranslationBase.of(context).cancel_nocaps,
okFunction: () => {cancelAppointment()},
cancelFunction: () => {});
dialog.showAlertDialog(context);
break;
case "confirmAppointment":
confirmAppointment();
break;
case "navigateToProject":
openMap(double.parse(widget.appo.latitude),
double.parse(widget.appo.longitude));
break;
case "addReminder":
showReminderDialog(widget.appo);
break;
case "goToTodoList":
Navigator.of(context).pop();
break;
case "askDoc":
askYourDoc();
break;
case "radiology":
openAppointmentRadiology();
break;
case "labResult":
openAppointmentLabResults();
break;
case "prescriptions":
openPrescriptionReport();
break;
case "Survey":
rateAppointment();
break;
case "Insurance":
navigateToInsuranceApprovals(widget.appo.appointmentNo);
break;
case "VitalSigns":
navigateToVitalSigns(widget.appo.appointmentNo, widget.appo.projectID);
break;
case "insertComplaint":
navigateToInsertComplaint();
break;
}
}
_getAppointmentActionButtons() {
if (widget.appo != null) {
if (isConfirmed()) {
if (widget.appo.isOnlineCheckedIN) {
_getConfirmedCheckInAppoActionsList();
} else {
_getConfirmedAppoActionsList();
}
} else {
print("isConfirmed Null");
}
if (isBooked()) {
if (widget.appo.isOnlineCheckedIN) {
_getBookedCheckInAppoActionsList();
} else {
_getBookedAppoActionsList();
}
} else {
print("isBooked Null");
}
if (isArrived()) {
if (widget.appo.clinicID == 17) {
_getArrivedInvoiceAppoActionsList();
} else {
_getArrivedAppoActionsList();
}
} else {
print("isArrived Null");
}
} else {
print("Appo Null");
}
}
bool isConfirmed() {
return AppointmentType.isConfirmed(widget.appo);
}
bool isArrived() {
return AppointmentType.isArrived(widget.appo);
}
bool isCheckedIn() {
return widget.appo.isOnlineCheckedIN;
}
bool isBooked() {
return AppointmentType.isBooked(widget.appo);
}
Future<List<AppoDetailsButton>> _getBookedAppoActionsList() async {
print("_getBookedAppoActionsList");
BookedButtons bookedButtons = new BookedButtons();
print(bookedButtons.buttons);
List<AppoDetailsButton> buttonsList = [];
for (var i = 0; i < bookedButtons.buttons.length; i++) {
buttonsList.add(AppoDetailsButton(
title: bookedButtons.buttons[i]['title'],
subtitle: bookedButtons.buttons[i]['subtitle'],
icon: bookedButtons.buttons[i]['icon'],
caller: bookedButtons.buttons[i]['caller'],
));
}
setState(() {
appoButtonsList = buttonsList;
});
}
Future<List<AppoDetailsButton>> _getBookedCheckInAppoActionsList() async {
print("_getBookedCheckInAppoActionsList");
BookedButtonsAllowCheckIn bookedButtonsAllowCheckIn =
new BookedButtonsAllowCheckIn();
print(bookedButtonsAllowCheckIn.buttons);
List<AppoDetailsButton> buttonsList = [];
for (var i = 0; i < bookedButtonsAllowCheckIn.buttons.length; i++) {
buttonsList.add(AppoDetailsButton(
title: bookedButtonsAllowCheckIn.buttons[i]['title'],
subtitle: bookedButtonsAllowCheckIn.buttons[i]['subtitle'],
icon: bookedButtonsAllowCheckIn.buttons[i]['icon'],
caller: bookedButtonsAllowCheckIn.buttons[i]['caller'],
));
}
setState(() {
appoButtonsList = buttonsList;
});
}
Future<List<AppoDetailsButton>> _getConfirmedAppoActionsList() async {
print("_getConfirmedAppoActionsList");
ConfirmedButtons confirmedButtons = new ConfirmedButtons();
print(confirmedButtons.buttons);
List<AppoDetailsButton> buttonsList = [];
for (var i = 0; i < confirmedButtons.buttons.length; i++) {
buttonsList.add(AppoDetailsButton(
title: confirmedButtons.buttons[i]['title'],
subtitle: confirmedButtons.buttons[i]['subtitle'],
icon: confirmedButtons.buttons[i]['icon'],
caller: confirmedButtons.buttons[i]['caller'],
));
}
setState(() {
appoButtonsList = buttonsList;
});
}
Future<List<AppoDetailsButton>> _getConfirmedCheckInAppoActionsList() async {
print("_getConfirmedAllowCheckInAppoActionsList");
ConfirmedButtonsAllowCheckIn confirmedButtonsAllowCheckIn =
new ConfirmedButtonsAllowCheckIn();
print(confirmedButtonsAllowCheckIn.buttons);
List<AppoDetailsButton> buttonsList = [];
for (var i = 0; i < confirmedButtonsAllowCheckIn.buttons.length; i++) {
buttonsList.add(AppoDetailsButton(
title: confirmedButtonsAllowCheckIn.buttons[i]['title'],
subtitle: confirmedButtonsAllowCheckIn.buttons[i]['subtitle'],
icon: confirmedButtonsAllowCheckIn.buttons[i]['icon'],
caller: confirmedButtonsAllowCheckIn.buttons[i]['caller'],
));
}
setState(() {
appoButtonsList = buttonsList;
});
}
Future<List<AppoDetailsButton>> _getArrivedAppoActionsList() async {
print("_getArrivedAppoActionsList");
ArrivedButtons arrivedButtons = new ArrivedButtons();
print(arrivedButtons.buttons);
List<AppoDetailsButton> buttonsList = [];
for (var i = 0; i < arrivedButtons.buttons.length; i++) {
buttonsList.add(AppoDetailsButton(
title: arrivedButtons.buttons[i]['title'],
subtitle: arrivedButtons.buttons[i]['subtitle'],
icon: arrivedButtons.buttons[i]['icon'],
caller: arrivedButtons.buttons[i]['caller'],
));
}
setState(() {
appoButtonsList = buttonsList;
});
}
Future<List<AppoDetailsButton>> _getArrivedInvoiceAppoActionsList() async {
print("_getArrivedInvoiceAppoActionsList");
ArrivedButtons arrivedButtons = new ArrivedButtons();
List<AppoDetailsButton> buttonsList = [];
for (var i = 0; i < arrivedButtons.buttons.length; i++) {
buttonsList.add(AppoDetailsButton(
title: arrivedButtons.buttons[i]['title'],
subtitle: arrivedButtons.buttons[i]['subtitle'],
icon: arrivedButtons.buttons[i]['icon'],
caller: arrivedButtons.buttons[i]['caller'],
));
}
setState(() {
appoButtonsList = buttonsList;
});
}
cancelAppointment() {
ConfirmDialog.closeAlertDialog(context);
GifLoaderDialogUtils.showMyDialog(context);
DoctorsListService service = new DoctorsListService();
service.cancelAppointment(widget.appo, context).then((res) {
GifLoaderDialogUtils.hideDialog(context);
print(res);
if (res['MessageStatus'] == 1) {
getToDoCount();
AppToast.showSuccessToast(message: res['ErrorEndUserMessage']);
Navigator.of(context).pop();
} else {
AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
}
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
print(err);
});
}
getToDoCount() {
toDoProvider.setState(0, true);
ClinicListService service = new ClinicListService();
service.getActiveAppointmentNo(context).then((res) {
print(res['AppointmentActiveNumber']);
if (res['MessageStatus'] == 1) {
toDoProvider.setState(res['AppointmentActiveNumber'], true);
} else {}
}).catchError((err) {
print(err);
});
}
openAppointmentLabResults() {
GifLoaderDialogUtils.showMyDialog(context);
DoctorsListService service = new DoctorsListService();
PatientLabOrders patientLabOrders = new PatientLabOrders();
service
.getPatientLabOrdersByAppoNo(widget.appo.appointmentNo,
widget.appo.projectID, widget.appo.clinicID, context)
.then((res) {
print(res['ListLabResultsByAppNo']);
GifLoaderDialogUtils.hideDialog(context);
if (res['ListLabResultsByAppNo'] != null) {
patientLabOrders.orderNo =
res['ListLabResultsByAppNo'][0]['OrderNo'].toString();
patientLabOrders.invoiceNo =
res['ListLabResultsByAppNo'][0]['InvoiceNo'].toString();
patientLabOrders.clinicID = widget.appo.clinicID;
patientLabOrders.projectID = widget.appo.projectID.toString();
print(patientLabOrders.invoiceNo);
print(patientLabOrders.orderNo);
navigateToLabResults(patientLabOrders);
} else {
AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
}
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
print(err);
AppToast.showErrorToast(message: err);
});
}
openAppointmentRadiology() {
GifLoaderDialogUtils.showMyDialog(context);
DoctorsListService service = new DoctorsListService();
FinalRadiology finalRadiology = new FinalRadiology();
service
.getPatientRadOrders(widget.appo.appointmentNo.toString(), context)
.then((res) {
GifLoaderDialogUtils.hideDialog(context);
if (res['FinalRadiologyList'] != null) {
print(res['FinalRadiologyList']);
finalRadiology =
new FinalRadiology.fromJson(res['FinalRadiologyList'][0]);
print(finalRadiology.reportData);
navigateToRadiologyDetails(finalRadiology);
} else {
AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
}
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
print(err);
AppToast.showErrorToast(message: err);
});
}
openPrescriptionReport() {
GifLoaderDialogUtils.showMyDialog(context);
List<PrescriptionReportEnh> prescriptionReportEnhList = List();
DoctorsListService service = new DoctorsListService();
service.getPatientPrescriptionReports(widget.appo, context).then((res) {
GifLoaderDialogUtils.hideDialog(context);
if (res['ListPRM'].length != 0) {
res['ListPRM'].forEach((report) {
prescriptionReportEnhList.add(PrescriptionReportEnh.fromJson(report));
});
print(prescriptionReportEnhList.length);
navigateToMedicinePrescriptionReport(
prescriptionReportEnhList, res['ListPRM']);
} else {
AppToast.showErrorToast(message: TranslationBase.of(context).noRecords);
}
}).catchError((err) {
print(err);
GifLoaderDialogUtils.hideDialog(context);
AppToast.showErrorToast(message: err);
});
}
Future navigateToMedicinePrescriptionReport(
List<PrescriptionReportEnh> prescriptionReportEnhList,
dynamic listPres) async {
Navigator.push(
context,
FadePage(
page: PrescriptionReportPage(
prescriptionReportEnhList: prescriptionReportEnhList,
listPres: listPres,
appo: widget.appo)));
}
Future navigateToLabResults(PatientLabOrders patientLabOrders) async {
Navigator.push(
context,
FadePage(
page: LaboratoryResultPage(patientLabOrders: patientLabOrders)))
.then((value) {});
}
Future navigateToRadiologyDetails(FinalRadiology finalRadiology) async {
Navigator.push(
context,
FadePage(
page: RadiologyDetailsPage(finalRadiology: finalRadiology)))
.then((value) {});
}
static Future<void> openMap(double latitude, double longitude) async {
String googleUrl =
'https://www.google.com/maps/search/?api=1&query=$latitude,$longitude';
if (await canLaunch(googleUrl)) {
await launch(googleUrl);
} else {
throw 'Could not open the map.';
}
}
showReminderDialog(AppoitmentAllHistoryResultList appo) {
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: ReminderDialog(
eventId: appo.appointmentNo.toString(),
title: "Doctor Appointment",
description: "You have an appointment with " +
appo.doctorTitle +
" " +
appo.doctorNameObj,
startDate: appo.appointmentDate,
endDate: appo.appointmentDate,
location: appo.projectName,
),
),
);
},
transitionDuration: Duration(milliseconds: 500),
barrierDismissible: true,
barrierLabel: '',
context: context,
pageBuilder: (context, animation1, animation2) {});
}
askYourDoc() {
GifLoaderDialogUtils.showMyDialog(context);
DoctorsListService service = new DoctorsListService();
service.isAllowedToAskDoctor(widget.appo.doctorID, context).then((res) {
GifLoaderDialogUtils.hideDialog(context);
print(res['PatientDoctorAppointmentResultList']);
if (res['PatientDoctorAppointmentResultList'].length != 0) {
getCallRequestType();
} else {
AppToast.showErrorToast(
message: TranslationBase.of(context).askDocNotAllowed);
}
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
print(err);
AppToast.showErrorToast(message: err);
});
}
getCallRequestType() {
GifLoaderDialogUtils.showMyDialog(context);
DoctorsListService service = new DoctorsListService();
service.getCallRequestType(context).then((res) {
GifLoaderDialogUtils.hideDialog(context);
List<AskDocRequestType> requestData = new List<AskDocRequestType>();
res['ListReqTypes'].forEach((element) {
requestData.add(new AskDocRequestType.fromJson(element));
});
Future.delayed(const Duration(milliseconds: 400), () {
showAskDocRequestDialog(requestData);
});
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
print(err);
});
}
showAskDocRequestDialog(List<AskDocRequestType> requestData) {
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: AskDocDialog(requestData: requestData),
),
);
},
transitionDuration: Duration(milliseconds: 500),
barrierDismissible: true,
barrierLabel: '',
context: context,
pageBuilder: (context, animation1, animation2) {})
.then((value) {
print("Dialog Closed");
print(value);
if (value != null) {
sendAskDocRequest(value);
}
});
}
sendAskDocRequest(int requestType) {
GifLoaderDialogUtils.showMyDialog(context);
DoctorsListService service = new DoctorsListService();
service
.sendAskDocCallRequest(widget.appo, requestType.toString(), context)
.then((res) {
GifLoaderDialogUtils.hideDialog(context);
if (res['MessageStatus'] == 1) {
AppToast.showSuccessToast(message: "Request Sent Successfully");
} else {
AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
}
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
print(err);
AppToast.showErrorToast(message: err);
});
}
confirmAppointment() {
GifLoaderDialogUtils.showMyDialog(context);
DoctorsListService service = new DoctorsListService();
service
.confirmAppointment(widget.appo.appointmentNo, widget.appo.clinicID,
widget.appo.projectID, widget.appo.isLiveCareAppointment, context)
.then((res) {
GifLoaderDialogUtils.hideDialog(context);
if (res['MessageStatus'] == 1) {
AppToast.showSuccessToast(message: res['ErrorEndUserMessage']);
Navigator.of(context).pop();
} else {
AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
}
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
print(err);
});
}
navigateToInsuranceApprovals(int appoNo) {
Navigator.push(
context, FadePage(page: InsuranceApproval(appointmentNo: appoNo)));
}
navigateToVitalSigns(int appoNo, int projectID) {
Navigator.push(
context,
FadePage(
page: VitalSignDetailsScreen(
appointmentNo: appoNo,
projectID: projectID,
isNotOneAppointment: false,
)));
}
navigateToInsertComplaint() {
Navigator.push(context, FadePage(page: FeedbackHomePage()));
}
rateAppointment() {
widget.browser = new MyInAppBrowser();
widget.browser.openBrowser('http://hmg.com/SitePages/pso.aspx?p=' +
widget.appo.projectID.toString() +
'.' +
widget.appo.appointmentNo.toString() +
'&c=1');
}
}