|
|
|
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
|
|
|
|
import 'package:diplomaticquarterapp/core/model/er/PatientER.dart';
|
|
|
|
import 'package:diplomaticquarterapp/core/model/hospitals/hospitals_model.dart';
|
|
|
|
import 'package:diplomaticquarterapp/core/viewModels/er/am_request_view_model.dart';
|
|
|
|
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
|
|
|
|
import 'package:diplomaticquarterapp/pages/Blood/dialogs/SelectHospitalDialog.dart';
|
|
|
|
import 'package:diplomaticquarterapp/pages/ErService/widgets/AppointmentCard.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/ProgressDialog.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
|
|
import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
|
|
|
|
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
|
|
|
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
|
|
import 'package:diplomaticquarterapp/widgets/pickupLocation/PickupLocationFromMap.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
import 'package:geolocator/geolocator.dart';
|
|
|
|
import 'package:google_maps_place_picker/google_maps_place_picker.dart';
|
|
|
|
import '../AvailableAppointmentsPage.dart';
|
|
|
|
|
|
|
|
enum HaveAppointment { YES, NO }
|
|
|
|
|
|
|
|
class PickupLocation extends StatefulWidget {
|
|
|
|
final Function changeCurrentTab;
|
|
|
|
final PatientER patientER;
|
|
|
|
final AmRequestViewModel amRequestViewModel;
|
|
|
|
|
|
|
|
PickupLocation(
|
|
|
|
{Key key,
|
|
|
|
this.changeCurrentTab,
|
|
|
|
this.patientER,
|
|
|
|
this.amRequestViewModel});
|
|
|
|
|
|
|
|
@override
|
|
|
|
_PickupLocationState createState() => _PickupLocationState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PickupLocationState extends State<PickupLocation> {
|
|
|
|
bool _isInsideHome = false;
|
|
|
|
HaveAppointment _haveAppointment = HaveAppointment.NO;
|
|
|
|
double _latitude;
|
|
|
|
double _longitude;
|
|
|
|
AppoitmentAllHistoryResultList myAppointment;
|
|
|
|
HospitalsModel _selectedHospital;
|
|
|
|
PickResult _result;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_getCurrentLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
_getCurrentLocation() async {
|
|
|
|
await getLastKnownPosition().then((value) {
|
|
|
|
_latitude = value.latitude;
|
|
|
|
_longitude = value.longitude;
|
|
|
|
}).catchError((e) {
|
|
|
|
_longitude = 0;
|
|
|
|
_latitude = 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return AppScaffold(
|
|
|
|
isShowAppBar: false,
|
|
|
|
isShowDecPage: false,
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
child: Container(
|
|
|
|
margin: EdgeInsets.only(left: 12, right: 12),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
if (widget.patientER.direction == 1)
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Texts(TranslationBase.of(context).pickupLocation),
|
|
|
|
SizedBox(
|
|
|
|
height: 15,
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => PickupLocationFromMap(
|
|
|
|
latitude: _latitude,
|
|
|
|
longitude: _longitude,
|
|
|
|
onPick: (value) {
|
|
|
|
setState(() {
|
|
|
|
_result = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(12),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.rectangle,
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
border: Border.all(color: Colors.grey, width: 0.5),
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Expanded(child: Texts(getSelectFromMapName(context))),
|
|
|
|
Icon(
|
|
|
|
FontAwesomeIcons.mapMarkerAlt,
|
|
|
|
size: 24,
|
|
|
|
color: Colors.black,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
Texts(TranslationBase.of(context).pickupSpot),
|
|
|
|
SizedBox(
|
|
|
|
height: 5,
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
_isInsideHome = !_isInsideHome;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.rectangle,
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
border: Border.all(color: Colors.grey, width: 0.5),
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
child: ListTile(
|
|
|
|
title: Texts(TranslationBase.of(context).insideHome),
|
|
|
|
leading: Checkbox(
|
|
|
|
value: _isInsideHome,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_isInsideHome = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
Texts(TranslationBase.of(context).haveAppo),
|
|
|
|
SizedBox(
|
|
|
|
height: 5,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
if (myAppointment == null) {
|
|
|
|
getAppointment();
|
|
|
|
setState(() {
|
|
|
|
_haveAppointment = HaveAppointment.YES;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.rectangle,
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
border:
|
|
|
|
Border.all(color: Colors.grey, width: 0.5),
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
child: ListTile(
|
|
|
|
title: Texts(TranslationBase.of(context).yes),
|
|
|
|
leading: Radio(
|
|
|
|
value: HaveAppointment.YES,
|
|
|
|
groupValue: _haveAppointment,
|
|
|
|
onChanged: (value) {
|
|
|
|
if (myAppointment == null) {
|
|
|
|
getAppointment();
|
|
|
|
setState(() {
|
|
|
|
_haveAppointment = value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
_haveAppointment = HaveAppointment.NO;
|
|
|
|
myAppointment = null;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.rectangle,
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
border:
|
|
|
|
Border.all(color: Colors.grey, width: 0.5),
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
child: ListTile(
|
|
|
|
title: Texts(TranslationBase.of(context).no),
|
|
|
|
leading: Radio(
|
|
|
|
value: HaveAppointment.NO,
|
|
|
|
groupValue: _haveAppointment,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_haveAppointment = value;
|
|
|
|
myAppointment = null;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
if (myAppointment != null)
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
AppointmentCard(
|
|
|
|
appointment: myAppointment,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
Texts(TranslationBase.of(context).dropoffLocation),
|
|
|
|
SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
confirmSelectHospitalDialog(
|
|
|
|
widget.amRequestViewModel.hospitals);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(12),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.rectangle,
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
border: Border.all(color: Colors.grey, width: 0.5),
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Texts(getHospitalName(
|
|
|
|
TranslationBase.of(context).pickupLocation)),
|
|
|
|
Icon(
|
|
|
|
Icons.arrow_drop_down,
|
|
|
|
size: 24,
|
|
|
|
color: Colors.black,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
if (widget.patientER.direction == 0)
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Texts(TranslationBase.of(context).pickupLocation),
|
|
|
|
SizedBox(
|
|
|
|
height: 15,
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
confirmSelectHospitalDialog(
|
|
|
|
widget.amRequestViewModel.hospitals);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(12),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.rectangle,
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
border: Border.all(color: Colors.grey, width: 0.5),
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Texts(getHospitalName(
|
|
|
|
TranslationBase.of(context).pickupLocation)),
|
|
|
|
Icon(
|
|
|
|
Icons.arrow_drop_down,
|
|
|
|
size: 24,
|
|
|
|
color: Colors.black,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
Texts(TranslationBase.of(context).dropoffLocation),
|
|
|
|
SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => PickupLocationFromMap(
|
|
|
|
latitude: _latitude,
|
|
|
|
longitude: _longitude,
|
|
|
|
onPick: (value) {
|
|
|
|
setState(() {
|
|
|
|
_result = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(12),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.rectangle,
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
border: Border.all(color: Colors.grey, width: 0.5),
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Expanded(child: Texts(getSelectFromMapName(context))),
|
|
|
|
Icon(
|
|
|
|
FontAwesomeIcons.mapMarkerAlt,
|
|
|
|
size: 24,
|
|
|
|
color: Colors.black,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 45,
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
bottomSheet: Container(
|
|
|
|
padding: EdgeInsets.all(15),
|
|
|
|
width: double.maxFinite,
|
|
|
|
height: 90,
|
|
|
|
child: SecondaryButton(
|
|
|
|
color: Colors.grey[800],
|
|
|
|
textColor: Colors.white,
|
|
|
|
onTap: () {
|
|
|
|
if (_result == null || _selectedHospital == null)
|
|
|
|
AppToast.showErrorToast(
|
|
|
|
message: TranslationBase.of(context).selectAll);
|
|
|
|
else
|
|
|
|
setState(() {
|
|
|
|
widget.patientER.pickupSpot = _isInsideHome ? 1 : 0;
|
|
|
|
if (widget.patientER.direction == 0) {
|
|
|
|
widget.patientER.pickupLocationLattitude =
|
|
|
|
_result.geometry.location.lat.toString();
|
|
|
|
widget.patientER.pickupLocationLongitude =
|
|
|
|
_result.geometry.location.lng.toString();
|
|
|
|
widget.patientER.dropoffLocationLattitude =
|
|
|
|
_selectedHospital.latitude;
|
|
|
|
widget.patientER.dropoffLocationLongitude =
|
|
|
|
_selectedHospital.longitude;
|
|
|
|
} else {
|
|
|
|
widget.patientER.pickupLocationLattitude =
|
|
|
|
_selectedHospital.latitude;
|
|
|
|
widget.patientER.pickupLocationLongitude =
|
|
|
|
_selectedHospital.longitude;
|
|
|
|
widget.patientER.dropoffLocationLattitude =
|
|
|
|
_result.geometry.location.lat.toString();
|
|
|
|
widget.patientER.dropoffLocationLongitude =
|
|
|
|
_result.geometry.location.lng.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
widget.patientER.latitude =
|
|
|
|
widget.patientER.pickupLocationLattitude;
|
|
|
|
widget.patientER.longitude =
|
|
|
|
widget.patientER.pickupLocationLongitude;
|
|
|
|
widget.patientER.dropoffLocationName =
|
|
|
|
_selectedHospital.name;
|
|
|
|
widget.patientER.createdBy =
|
|
|
|
widget.amRequestViewModel.user.patientID;
|
|
|
|
widget.patientER.isOutPatient =
|
|
|
|
widget.amRequestViewModel.user.outSA;
|
|
|
|
widget.patientER.patientIdentificationID = widget
|
|
|
|
.amRequestViewModel.user.patientIdentificationNo;
|
|
|
|
widget.patientER.pickupDateTime =
|
|
|
|
DateUtil.convertDateToStringLocation(DateTime.now());
|
|
|
|
widget.patientER.pickupLocationName =
|
|
|
|
_result.formattedAddress;
|
|
|
|
widget.patientER.projectID =
|
|
|
|
widget.amRequestViewModel.user.projectID;
|
|
|
|
widget.patientER.requesterFileNo =
|
|
|
|
widget.amRequestViewModel.user.patientID;
|
|
|
|
widget.patientER.requesterIsOutSA = false;
|
|
|
|
widget.patientER.lineItemNo = 0;
|
|
|
|
widget.patientER.requesterMobileNo =
|
|
|
|
widget.amRequestViewModel.user.mobileNumber;
|
|
|
|
|
|
|
|
if (_haveAppointment == HaveAppointment.YES) {
|
|
|
|
widget.patientER.appointmentNo =
|
|
|
|
myAppointment.appointmentNo.toString();
|
|
|
|
widget.patientER.appointmentClinicName =
|
|
|
|
myAppointment.clinicName;
|
|
|
|
widget.patientER.appointmentDoctorName =
|
|
|
|
myAppointment.doctorNameObj;
|
|
|
|
widget.patientER.appointmentBranch =
|
|
|
|
myAppointment.projectName;
|
|
|
|
widget.patientER.appointmentTime =
|
|
|
|
myAppointment.appointmentDate;
|
|
|
|
widget.patientER.haveAppointment = true;
|
|
|
|
} else {
|
|
|
|
widget.patientER.appointmentNo = "0";
|
|
|
|
widget.patientER.appointmentClinicName = null;
|
|
|
|
widget.patientER.appointmentDoctorName = null;
|
|
|
|
widget.patientER.appointmentBranch = null;
|
|
|
|
widget.patientER.appointmentTime = null;
|
|
|
|
widget.patientER.haveAppointment = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
widget.patientER.pickupSpot = _isInsideHome ? 1 : 0;
|
|
|
|
widget.changeCurrentTab(2);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
label: TranslationBase.of(context).next,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void confirmSelectHospitalDialog(List<HospitalsModel> hospitals) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
child: SelectHospitalDialog(
|
|
|
|
hospitals: hospitals,
|
|
|
|
selectedHospital: _selectedHospital,
|
|
|
|
onValueSelected: (value) {
|
|
|
|
setState(() {
|
|
|
|
_selectedHospital = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
String getHospitalName(String title) {
|
|
|
|
return _selectedHospital == null ? title : _selectedHospital.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
String getSelectFromMapName(context) {
|
|
|
|
return _result != null
|
|
|
|
? _result.formattedAddress
|
|
|
|
: TranslationBase.of(context).selectMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
getAppointment() {
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
widget.amRequestViewModel.getAppointmentHistory().then((value) {
|
|
|
|
if (widget.amRequestViewModel.state == ViewState.Error ||
|
|
|
|
widget.amRequestViewModel.state == ViewState.ErrorLocal) {
|
|
|
|
AppToast.showErrorToast(message: widget.amRequestViewModel.error);
|
|
|
|
} else if (widget
|
|
|
|
.amRequestViewModel.appoitmentAllHistoryResultList.length >
|
|
|
|
0) {
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => AvailableAppointmentsPage(
|
|
|
|
appointmentsAllHistoryList:
|
|
|
|
widget.amRequestViewModel.appoitmentAllHistoryResultList,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
).then((value) {
|
|
|
|
if (value != null)
|
|
|
|
setState(() {
|
|
|
|
myAppointment = value;
|
|
|
|
});
|
|
|
|
else {
|
|
|
|
ProgressDialogUtil.hideProgressDialog(context);
|
|
|
|
setState(() {
|
|
|
|
_haveAppointment = HaveAppointment.NO;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
setState(() {
|
|
|
|
_haveAppointment = HaveAppointment.NO;
|
|
|
|
});
|
|
|
|
AppToast.showErrorToast(
|
|
|
|
message: TranslationBase.of(context).noAppointment);
|
|
|
|
}
|
|
|
|
}).catchError((e) {
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
AppToast.showErrorToast(message: e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|