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.
PatientApp-KKUMC/lib/pages/BookAppointment/QRCode.dart

573 lines
23 KiB
Dart

import 'dart:typed_data';
import 'package:barcode_scan2/barcode_scan2.dart';
import 'package:diplomaticquarterapp/analytics/google-analytics.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/core/model/privilege/ProjectDetailListModel.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/locator.dart';
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart';
import 'package:diplomaticquarterapp/models/Appointments/PatientShareResposne.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/models/header_model.dart';
import 'package:diplomaticquarterapp/models/patient_queue_no_response_model.dart';
import 'package:diplomaticquarterapp/pages/landing/landing_page.dart';
import 'package:diplomaticquarterapp/routes.dart';
import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart';
import 'package:diplomaticquarterapp/services/authentication/auth_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/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/location_util.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/custom_text_button.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/widgets/data_display/medical/medical_profile_item.dart';
import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart';
import 'package:diplomaticquarterapp/widgets/new_design/doctor_header.dart';
import 'package:diplomaticquarterapp/widgets/nfc/nfc_reader_sheet.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_nfc_kit/flutter_nfc_kit.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';
class QRCode extends StatefulWidget {
PatientShareResponse patientShareResponse;
AppoitmentAllHistoryResultList appointment;
String appoQR;
AuthenticatedUser authUser;
AppSharedPreferences sharedPref = AppSharedPreferences();
QRCode({@required this.patientShareResponse, @required this.appoQR, @required this.appointment});
@override
_QRCodeState createState() => _QRCodeState();
}
class _QRCodeState extends State<QRCode> {
Uint8List _bytes;
bool _supportsNFC = false;
BuildContext _context;
ProjectViewModel projectViewModel;
LocationUtils locationUtils;
ProjectDetailListModel projectDetailListModel;
final authService = new AuthProvider();
GetPatientQueueNoModel getPatientQueueNoModel;
@override
void initState() {
// TODO: implement initState
// _bytes = base64.decode(widget.appoQR.split(',').last);
widget.authUser = new AuthenticatedUser();
// WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
// startNFCScan();
// });
super.initState();
}
startNFCScan() {
Future.delayed(const Duration(milliseconds: 500), () {
showNfcReader(context, onNcfScan: (String nfcId) {
Future.delayed(const Duration(milliseconds: 100), () {
sendNfcCheckInRequest(nfcId, 1);
locator<GAnalytics>().todoList.to_do_list_nfc(widget.appointment);
});
}, onCancel: () {
// Navigator.of(context).pop();
locator<GAnalytics>().todoList.to_do_list_nfc_cancel(widget.appointment);
});
});
}
startQRCodeScan() async {
String onlineCheckInQRCode = (await BarcodeScanner.scan())?.rawContent;
if (onlineCheckInQRCode != "") {
sendNfcCheckInRequest(onlineCheckInQRCode, 2);
locator<GAnalytics>().todoList.to_do_list_nfc(widget.appointment);
} else {}
}
startLocationCheckIn() async {
GifLoaderDialogUtils.showMyDialog(context);
locationUtils = new LocationUtils(isShowConfirmDialog: true, context: context);
locationUtils.getCurrentLocation(callBack: (value) {
projectDetailListModel = Utils.getProjectDetailObj(projectViewModel, widget.appointment.projectID);
double dist = Utils.distance(value.latitude, value.longitude, double.parse(projectDetailListModel.latitude), double.parse(projectDetailListModel.longitude)).ceilToDouble() * 1000;
print(dist);
if (dist <= projectDetailListModel.geofenceRadius) {
GifLoaderDialogUtils.hideDialog(context);
sendNfcCheckInRequest(projectDetailListModel.checkInQrCode, 3);
} else {
GifLoaderDialogUtils.hideDialog(context);
AppToast.showErrorToast(message: TranslationBase.of(context).locationCheckInError);
}
}, failureCallBack: () {
GifLoaderDialogUtils.hideDialog(context);
});
}
@override
Widget build(BuildContext context) {
projectViewModel = Provider.of(context);
_context = context;
FlutterNfcKit.nfcAvailability.then((value) {
_supportsNFC = (value == NFCAvailability.available);
});
List<Widget> checkInOptionsList = getCheckInOptionsList(context);
return AppScaffold(
appBarTitle: TranslationBase.of(context).onlineCheckIn,
isShowAppBar: true,
showNewAppBar: true,
showNewAppBarTitle: true,
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DoctorHeader(
headerModel: HeaderModel(
widget.appointment.doctorTitle + " " + widget.appointment.doctorNameObj,
widget.appointment.doctorID,
widget.appointment.doctorImageURL,
widget.appointment.doctorSpeciality,
"",
widget.appointment.projectName,
DateUtil.convertStringToDate(widget.appointment.appointmentDate),
widget.appointment.isLiveCareAppointment
? DateUtil.convertStringToDate(widget.appointment.appointmentDate).toString().split(" ")[1].substring(0, 5)
: widget.appointment.startTime.substring(0, 5),
null,
widget.appointment.doctorRate,
widget.appointment.actualDoctorRate,
widget.appointment.noOfPatientsRate,
"",
),
isShowName: true,
isNeedToShowButton: false,
buttonTitle: '',
onTap: () {},
onRatingAndReviewTap: () {},
),
Container(
width: double.infinity,
margin: EdgeInsets.only(top: 15.0, bottom: 10.0, left: 20.0, right: 20.0),
child: Text(TranslationBase.of(context).scanQRHospital,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
letterSpacing: -0.48,
)),
),
mHeight(21),
Padding(
padding: EdgeInsets.only(left: 21, right: 21),
child: GridView.builder(
shrinkWrap: true,
primary: false,
physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, childAspectRatio: 2 / 2, crossAxisSpacing: 12, mainAxisSpacing: 12),
padding: EdgeInsets.zero,
itemCount: checkInOptionsList.length,
itemBuilder: (BuildContext context, int index) {
return checkInOptionsList[index];
},
),
),
],
),
),
// bottomSheet: Container(
// color: CustomColors.appBackgroudGreyColor,
// padding: EdgeInsets.all(21),
// // height: 45.0,
// child: Row(
// children: [
// Expanded(
// flex: 1,
// child: ButtonTheme(
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(10.0),
// ),
// height: 45.0,
// child: CustomTextButton(
// backgroundColor: CustomColors.green,
// elevation: 0,
// onPressed: () {
// startNFCScan();
// },
// child: Text(TranslationBase.of(context).scanNFC,
// style: TextStyle(
// fontSize: 18.0,
// color: Colors.white,
// )),
// ),
// ),
// ),
// ],
// ),
// ),
);
}
List<Widget> getCheckInOptionsList(BuildContext context) {
List<Widget> optionsList = [];
optionsList.add(
InkWell(
onTap: () {
if (projectViewModel.havePrivilege(102)) {
startLocationCheckIn();
}
},
child: MedicalProfileItem(
title: TranslationBase.of(context).checkInViaLocation,
imagePath: 'location.svg',
subTitle: "",
isEnable: projectViewModel.havePrivilege(102),
width: 70.0,
height: 70.0,
),
),
);
optionsList.add(
InkWell(
onTap: () {
if (projectViewModel.havePrivilege(79)) {
startQRCodeScan();
}
},
child: MedicalProfileItem(
title: TranslationBase.of(context).pharmaLiveCareScanQR,
imagePath: 'qr_code.svg',
subTitle: "",
isEnable: projectViewModel.havePrivilege(79),
width: 80.0,
height: 80.0,
),
),
);
optionsList.add(
InkWell(
onTap: () {
if (projectViewModel.havePrivilege(80) && _supportsNFC) {
startNFCScan();
} else {
Utils.showErrorToast(TranslationBase.of(context).NFCNotSupported);
}
},
child: MedicalProfileItem(
title: TranslationBase.of(context).scanNFC,
imagePath: 'contactless.svg',
subTitle: "",
isEnable: projectViewModel.havePrivilege(80),
width: 80.0,
height: 80.0,
),
),
);
return optionsList;
}
showCheckInSuccessBottomModalSheet(String successMessage) {
showModalBottomSheet(
isDismissible: false,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16.0)),
),
clipBehavior: Clip.hardEdge,
context: context,
builder: (context) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Wrap(
children: [
SizedBox(
height: 80,
),
Center(
child: SvgPicture.asset(
"assets/images/new-design/ionic-ios-checkmark-circle.svg",
width: 80,
height: 80,
),
),
SizedBox(
height: 100,
),
Text(
successMessage,
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.64, height: 25 / 16),
),
SizedBox(
height: 80,
),
projectViewModel.getPatientQueueNoModel.data.hasQueue
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
TranslationBase.of(context).queueDetails,
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.64, height: 25 / 16),
),
SizedBox(
height: 40,
),
SizedBox(
width: MediaQuery.of(context).size.width,
height: 110,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
TranslationBase.of(context).approxWaitTime,
maxLines: 1,
style: TextStyle(
fontSize: SizeConfig.textMultiplier * 1.5,
// fontWeight: FontWeight.w600,
letterSpacing: -0.3,
height: 13 / 10,
),
),
Text(
"${projectViewModel.getPatientQueueNoModel.data.approxWaitingTimeMin} ${TranslationBase.of(context).minute}",
// "5 minutes",
maxLines: 1,
style: TextStyle(fontSize: SizeConfig.textMultiplier * 1.5, fontWeight: FontWeight.bold, letterSpacing: -0.3, height: 13 / 10, color: Color(0xFFFBF2E31)),
),
],
),
SizedBox(height: 5),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
TranslationBase.of(context).yourQueue,
maxLines: 1,
style: TextStyle(
fontSize: SizeConfig.textMultiplier * 1.4,
fontWeight: FontWeight.w600,
letterSpacing: -0.3,
height: 13 / 10,
),
),
Text(
projectViewModel.getPatientQueueNoModel.data.queueNo,
// "IMD A-11",
maxLines: 1,
style: TextStyle(fontSize: SizeConfig.textMultiplier * 3.0, fontWeight: FontWeight.bold, letterSpacing: -0.3, height: 13 / 10, color: Color(0xFFFBF2E31)),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
TranslationBase.of(context).currentQueue,
maxLines: 1,
style: TextStyle(
fontSize: SizeConfig.textMultiplier * 1.4,
fontWeight: FontWeight.w600,
letterSpacing: -0.3,
height: 13 / 10,
),
),
Text(
projectViewModel.getPatientQueueNoModel.data.queueNoCurServing.isNotEmpty ? projectViewModel.getPatientQueueNoModel.data.queueNoCurServing : "-",
// "IMD A-07",
maxLines: 1,
style: TextStyle(
fontSize: SizeConfig.textMultiplier * 3.0,
fontWeight: FontWeight.bold,
letterSpacing: -0.3,
height: 13 / 10,
),
),
],
),
],
)
],
),
),
),
],
)
: Container(),
DefaultButton(
TranslationBase.of(context).confirm,
() {
Navigator.pop(context, null);
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => LandingPage()),
(Route<dynamic> route) => false,
);
},
color: Color(0xff359846),
textColor: Colors.white,
),
],
),
);
},
);
}
sendEmail() async {
DoctorsListService service = new DoctorsListService();
if (await widget.sharedPref.getObject(USER_PROFILE) != null) {
var data = AuthenticatedUser.fromJson(await widget.sharedPref.getObject(USER_PROFILE));
setState(() {
widget.authUser = data;
});
}
ConfirmDialog dialog = new ConfirmDialog(
context: context,
confirmMessage: "Send a copy of this QR to the email " + widget.authUser.emailAddress + "?",
okText: TranslationBase.of(context).confirm,
cancelText: TranslationBase.of(context).cancel_nocaps,
okFunction: () {
GifLoaderDialogUtils.showMyDialog(context);
service
.sendAppointmentQREmail(widget.authUser.emailAddress, widget.patientShareResponse.appointmentDate, widget.patientShareResponse.appointmentNo.toString(),
widget.patientShareResponse.doctorNameObj, widget.patientShareResponse.projectName, widget.appoQR, getDoctorSpeciality(widget.patientShareResponse.doctorSpeciality), context)
.then((res) {
GifLoaderDialogUtils.hideDialog(context);
ConfirmDialog.closeAlertDialog(context);
}).catchError((err) {
ConfirmDialog.closeAlertDialog(context);
GifLoaderDialogUtils.hideDialog(context);
AppToast.showErrorToast(message: err);
print(err);
});
},
cancelFunction: () => {});
dialog.showAlertDialog(context);
}
Future navigateToHome(context) async {
Navigator.of(context).pushNamed(HOME);
}
getPatientShare(context, String appointmentNo, int clinicID, int projectID, DoctorList docObject) {}
String getDate(String appoDate) {
var appoDateFormatted = "";
var dateObj = DateUtil.convertStringToDate(appoDate);
setState(() {
appoDateFormatted = DateUtil.getWeekDay(dateObj.weekday) +
", " +
dateObj.day.toString() +
" " +
DateUtil.getMonth(dateObj.month) +
" " +
dateObj.year.toString() +
", " +
dateObj.hour.toString() +
":" +
dateObj.minute.toString() +
":00";
});
return appoDateFormatted;
}
String getDoctorSpeciality(List<String> docSpecial) {
String docSpeciality = "";
if (docSpecial != null && docSpecial.length != 0) {
docSpecial.forEach((v) {
docSpeciality = docSpeciality + v + "\n";
});
}
return docSpeciality;
}
void checkIfPatientHasQueueNumber(String successMessage) {
GifLoaderDialogUtils.showMyDialog(context);
authService
.getPatientQueueNo(projectViewModel.user.patientID, widget.patientShareResponse.projectID, widget.patientShareResponse.clinicID, widget.patientShareResponse.appointmentNo)
.then((value) async {
GifLoaderDialogUtils.hideDialog(context);
setState(() {
if (value != null) {
getPatientQueueNoModel = GetPatientQueueNoModel.fromJson(value);
projectViewModel.setPatientQueueModel(getPatientQueueNoModel);
showCheckInSuccessBottomModalSheet(successMessage);
}
});
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
AppToast.showErrorToast(message: err);
});
}
sendNfcCheckInRequest(String nfcId, int checkInBy) {
GifLoaderDialogUtils.showMyDialog(context);
DoctorsListService service = new DoctorsListService();
service.sendCheckinNfcRequest(widget.patientShareResponse.appointmentNo, nfcId, widget.patientShareResponse.projectID, checkInBy, context).then((res) {
print(res);
GifLoaderDialogUtils.hideDialog(context);
// _showMyDialog(res["SuccessMsg"], this.context);
checkIfPatientHasQueueNumber(res["SuccessMsg"]);
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
print(err);
_showMyDialog(err, this.context);
});
}
Future<void> _showMyDialog(String message, BuildContext context) async {
return showDialog<void>(
context: context,
barrierDismissible: true, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Alert'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text(message),
],
),
),
actions: <Widget>[
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context) => LandingPage()), (Route<dynamic> r) => false);
},
),
],
);
},
);
}
}