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.
408 lines
15 KiB
Dart
408 lines
15 KiB
Dart
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
|
|
import 'package:diplomaticquarterapp/pages/MyAppointments/models/AppointmentType.dart';
|
|
import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/AppointmentCardView.dart';
|
|
import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart';
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
import 'package:diplomaticquarterapp/widgets/others/app_expandable_notifier.dart';
|
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:smart_progress_bar/smart_progress_bar.dart';
|
|
|
|
class MyAppointments extends StatefulWidget {
|
|
List<AppoitmentAllHistoryResultList> appoList = [];
|
|
|
|
List<AppoitmentAllHistoryResultList> bookedAppoList = [];
|
|
List<AppoitmentAllHistoryResultList> confirmedAppoList = [];
|
|
List<AppoitmentAllHistoryResultList> arrivedAppoList = [];
|
|
|
|
List<PatientAppointmentList> _patientBookedAppointmentListHospital = List();
|
|
List<PatientAppointmentList> _patientConfirmedAppointmentListHospital =
|
|
List();
|
|
List<PatientAppointmentList> _patientArrivedAppointmentListHospital = List();
|
|
|
|
@override
|
|
_MyAppointmentsState createState() => _MyAppointmentsState();
|
|
}
|
|
|
|
class _MyAppointmentsState extends State<MyAppointments>
|
|
with SingleTickerProviderStateMixin {
|
|
TabController _tabController;
|
|
|
|
bool isDataLoaded = false;
|
|
|
|
@override
|
|
void initState() {
|
|
_tabController = new TabController(length: 3, vsync: this);
|
|
WidgetsBinding.instance
|
|
.addPostFrameCallback((_) => getPatientAppointmentHistory());
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AppScaffold(
|
|
appBarTitle: TranslationBase.of(context).myAppointments,
|
|
isShowAppBar: true,
|
|
body: Container(
|
|
child: Column(children: [
|
|
TabBar(
|
|
tabs: [
|
|
Tab(text: TranslationBase.of(context).booked),
|
|
Tab(text: TranslationBase.of(context).confirmed),
|
|
Tab(text: TranslationBase.of(context).arrived),
|
|
],
|
|
controller: _tabController,
|
|
),
|
|
Divider(
|
|
color: Colors.grey[600],
|
|
thickness: 0.5,
|
|
),
|
|
Expanded(
|
|
child: new TabBarView(
|
|
physics: NeverScrollableScrollPhysics(),
|
|
children: [
|
|
isDataLoaded ? getBookedAppointments() : Container(),
|
|
isDataLoaded ? getConfirmedAppointments() : Container(),
|
|
isDataLoaded ? getArrivedAppointments() : Container()
|
|
],
|
|
controller: _tabController,
|
|
),
|
|
),
|
|
]),
|
|
),
|
|
);
|
|
}
|
|
|
|
getPatientAppointmentHistory() {
|
|
DoctorsListService service = new DoctorsListService();
|
|
widget.appoList.clear();
|
|
widget.bookedAppoList.clear();
|
|
widget.confirmedAppoList.clear();
|
|
widget.arrivedAppoList.clear();
|
|
service.getPatientAppointmentHistory(false, context).then((res) {
|
|
print(res['AppoimentAllHistoryResultList'].length);
|
|
if (res['MessageStatus'] == 1) {
|
|
setState(() {
|
|
if (res['AppoimentAllHistoryResultList'].length != 0) {
|
|
res['AppoimentAllHistoryResultList'].forEach((v) {
|
|
widget.appoList
|
|
.add(new AppoitmentAllHistoryResultList.fromJson(v));
|
|
});
|
|
sortAppointmentList();
|
|
openAppointmentsTab();
|
|
isDataLoaded = true;
|
|
} else {}
|
|
});
|
|
} else {
|
|
AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
|
|
}
|
|
}).catchError((err) {
|
|
print(err);
|
|
AppToast.showErrorToast(message: err);
|
|
Navigator.of(context).pop();
|
|
}).showProgressBar(
|
|
text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6));
|
|
}
|
|
|
|
bool isConfirmed(AppoitmentAllHistoryResultList appo) {
|
|
return AppointmentType.isConfirmed(appo);
|
|
}
|
|
|
|
bool isArrived(AppoitmentAllHistoryResultList appo) {
|
|
return AppointmentType.isArrived(appo);
|
|
}
|
|
|
|
bool isBooked(AppoitmentAllHistoryResultList appo) {
|
|
return AppointmentType.isBooked(appo);
|
|
}
|
|
|
|
sortAppointmentList() {
|
|
widget.appoList.forEach((v) {
|
|
if (isBooked(v)) {
|
|
widget.bookedAppoList.add(v);
|
|
}
|
|
|
|
if (isConfirmed(v)) {
|
|
widget.confirmedAppoList.add(v);
|
|
}
|
|
|
|
if (isArrived(v)) {
|
|
widget.arrivedAppoList.add(v);
|
|
}
|
|
});
|
|
|
|
widget.bookedAppoList.forEach((element) {
|
|
List<PatientAppointmentList> doctorByHospital =
|
|
widget._patientBookedAppointmentListHospital
|
|
.where(
|
|
(elementClinic) =>
|
|
elementClinic.filterName == element.clinicName,
|
|
)
|
|
.toList();
|
|
|
|
if (doctorByHospital.length != 0) {
|
|
widget
|
|
._patientBookedAppointmentListHospital[widget
|
|
._patientBookedAppointmentListHospital
|
|
.indexOf(doctorByHospital[0])]
|
|
.patientDoctorAppointmentList
|
|
.add(element);
|
|
} else {
|
|
widget._patientBookedAppointmentListHospital.add(PatientAppointmentList(
|
|
filterName: element.clinicName, patientDoctorAppointment: element));
|
|
}
|
|
});
|
|
|
|
widget.confirmedAppoList.forEach((element) {
|
|
List<PatientAppointmentList> doctorByHospital =
|
|
widget._patientConfirmedAppointmentListHospital
|
|
.where(
|
|
(elementClinic) =>
|
|
elementClinic.filterName == element.clinicName,
|
|
)
|
|
.toList();
|
|
|
|
if (doctorByHospital.length != 0) {
|
|
widget
|
|
._patientConfirmedAppointmentListHospital[widget
|
|
._patientConfirmedAppointmentListHospital
|
|
.indexOf(doctorByHospital[0])]
|
|
.patientDoctorAppointmentList
|
|
.add(element);
|
|
} else {
|
|
widget._patientConfirmedAppointmentListHospital.add(
|
|
PatientAppointmentList(
|
|
filterName: element.clinicName,
|
|
patientDoctorAppointment: element));
|
|
}
|
|
});
|
|
|
|
widget.arrivedAppoList.forEach((element) {
|
|
List<PatientAppointmentList> doctorByHospital =
|
|
widget._patientArrivedAppointmentListHospital
|
|
.where(
|
|
(elementClinic) =>
|
|
elementClinic.filterName == element.clinicName,
|
|
)
|
|
.toList();
|
|
|
|
if (doctorByHospital.length != 0) {
|
|
widget
|
|
._patientArrivedAppointmentListHospital[widget
|
|
._patientArrivedAppointmentListHospital
|
|
.indexOf(doctorByHospital[0])]
|
|
.patientDoctorAppointmentList
|
|
.add(element);
|
|
} else {
|
|
widget._patientArrivedAppointmentListHospital.add(
|
|
PatientAppointmentList(
|
|
filterName: element.clinicName,
|
|
patientDoctorAppointment: element));
|
|
}
|
|
});
|
|
}
|
|
|
|
openAppointmentsTab() {
|
|
if (widget._patientBookedAppointmentListHospital.length != 0) {
|
|
_tabController.index = 0;
|
|
} else if (widget._patientConfirmedAppointmentListHospital.length != 0) {
|
|
_tabController.index = 1;
|
|
} else if (widget._patientArrivedAppointmentListHospital.length != 0) {
|
|
_tabController.index = 2;
|
|
return;
|
|
}
|
|
}
|
|
|
|
Widget getBookedAppointments() {
|
|
return Container(
|
|
child: widget.bookedAppoList.length != 0
|
|
? new ListView.builder(
|
|
itemCount: widget.bookedAppoList.length,
|
|
itemBuilder: (context, i) {
|
|
return AppointmentCard(
|
|
appo: widget.bookedAppoList[i],
|
|
onReloadAppointmentHistory: getPatientAppointmentHistory,
|
|
);
|
|
},
|
|
)
|
|
: Container(
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: <Widget>[
|
|
Image.asset(
|
|
"assets/images/new-design/noAppointmentIcon.png"),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(TranslationBase.of(context).noBookedAppointments,
|
|
style: TextStyle(
|
|
fontSize: 16.0,
|
|
)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Container(
|
|
child: widget.bookedAppoList.length != 0
|
|
? SingleChildScrollView(
|
|
physics: BouncingScrollPhysics(),
|
|
child: Column(
|
|
children: <Widget>[
|
|
...List.generate(
|
|
widget._patientBookedAppointmentListHospital.length,
|
|
(index) => AppExpandableNotifier(
|
|
title: widget
|
|
._patientBookedAppointmentListHospital[index]
|
|
.filterName,
|
|
bodyWidget: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: widget
|
|
._patientBookedAppointmentListHospital[index]
|
|
.patientDoctorAppointmentList
|
|
.map((doctor) {
|
|
return AppointmentCard(
|
|
appo: doctor,
|
|
onReloadAppointmentHistory:
|
|
getPatientAppointmentHistory,
|
|
);
|
|
}).toList(),
|
|
)),
|
|
)
|
|
],
|
|
),
|
|
)
|
|
: Container(
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: <Widget>[
|
|
Image.asset(
|
|
"assets/images/new-design/noAppointmentIcon.png"),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text("No Booked Appointments",
|
|
style: TextStyle(
|
|
fontSize: 16.0,
|
|
)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
|
|
))));
|
|
}
|
|
|
|
Widget getConfirmedAppointments() {
|
|
return widget.confirmedAppoList.length != 0
|
|
? Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: SingleChildScrollView(
|
|
physics: BouncingScrollPhysics(),
|
|
child: Column(
|
|
children: <Widget>[
|
|
...List.generate(
|
|
widget._patientConfirmedAppointmentListHospital.length,
|
|
(index) => AppExpandableNotifier(
|
|
title: widget
|
|
._patientConfirmedAppointmentListHospital[index]
|
|
.filterName,
|
|
bodyWidget: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: widget
|
|
._patientConfirmedAppointmentListHospital[index]
|
|
.patientDoctorAppointmentList
|
|
.map((doctor) {
|
|
return AppointmentCard(
|
|
appo: doctor,
|
|
onReloadAppointmentHistory:
|
|
getPatientAppointmentHistory,
|
|
);
|
|
}).toList(),
|
|
)),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: Container(
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: <Widget>[
|
|
Image.asset("assets/images/new-design/noAppointmentIcon.png"),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(TranslationBase.of(context).noConfirmedAppointments ,
|
|
style: TextStyle(
|
|
fontSize: 16.0,
|
|
)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget getArrivedAppointments() {
|
|
return widget.arrivedAppoList.length != 0
|
|
? Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: SingleChildScrollView(
|
|
physics: BouncingScrollPhysics(),
|
|
child: Column(
|
|
children: <Widget>[
|
|
...List.generate(
|
|
widget._patientArrivedAppointmentListHospital.length,
|
|
(index) => AppExpandableNotifier(
|
|
title: widget
|
|
._patientArrivedAppointmentListHospital[index]
|
|
.filterName,
|
|
bodyWidget: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: widget
|
|
._patientArrivedAppointmentListHospital[index]
|
|
.patientDoctorAppointmentList
|
|
.map((doctor) {
|
|
return AppointmentCard(
|
|
appo: doctor,
|
|
onReloadAppointmentHistory:
|
|
getPatientAppointmentHistory,
|
|
);
|
|
}).toList(),
|
|
)),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: Container(
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: <Widget>[
|
|
Image.asset("assets/images/new-design/noAppointmentIcon.png"),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(TranslationBase.of(context).noArrivedAppointments,
|
|
style: TextStyle(
|
|
fontSize: 16.0,
|
|
)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|