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.
doctor_app_flutter/lib/screens/patients/patients_screen.dart

637 lines
28 KiB
Dart

/*
5 years ago
*@author: Amjad Amireh Merge to Elham rababah
*@Date:27/4/2020
*@param:
5 years ago
*@return:PatientsScreen
*@desc:
5 years ago
*/
import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/models/patient/patient_model.dart';
import 'package:doctor_app_flutter/models/patient/topten_users_res_model.dart';
5 years ago
import 'package:doctor_app_flutter/providers/patients_provider.dart';
import 'package:doctor_app_flutter/routes.dart';
4 years ago
import 'package:doctor_app_flutter/widgets/patients/profile/profile_medical_info_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/card_with_bgNew_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart';
import 'package:doctor_app_flutter/widgets/shared/errors/dr_app_embedded_error.dart';
import 'package:doctor_app_flutter/widgets/shared/profile_image_widget.dart';
import 'package:flutter/material.dart';
5 years ago
import 'package:provider/provider.dart';
4 years ago
import 'package:flutter_svg/flutter_svg.dart';
5 years ago
import '../../config/size_config.dart';
import 'package:hexcolor/hexcolor.dart';
import '../../widgets/shared/app_scaffold_widget.dart';
import '../../widgets/shared/card_with_bg_widget.dart';
5 years ago
import 'package:doctor_app_flutter/config/config.dart';
class PatientsScreen extends StatefulWidget {
@override
_PatientsScreenState createState() => _PatientsScreenState();
}
class _PatientsScreenState extends State<PatientsScreen> {
List<dynamic> litems;
List parsed;
List date;
List unfilterDate;
Color sideColor = Colors.black;
List<PatiantInformtion> responseModelList;
List<PatiantInformtion> responseModelList2;
4 years ago
final String url = "assets/images/";
final String avatarMale = "user_male.svg"; //'working_male.svg';//'user.svg';
final String avatarFemale = 'user_female.svg';
4 years ago
final String assetName = 'assets/image.svg';
// List<String> _locations = ['Today', 'Old Date', 'YESTERDAY'];
List<String> _locations = ['All','Today', 'Tomorrow', 'Next Week'];
int _activeLocation = 0;
5 years ago
bool _isInit = true;
String patientType;
String patientTypetitle;
var _isLoading = false;
5 years ago
bool _isError = true;
String error = "";
5 years ago
final _controller = TextEditingController();
PatientModel patient;
PatientsProvider patientsProv;
5 years ago
@override
void didChangeDependencies() {
final routeArgs = ModalRoute.of(context).settings.arguments as Map;
patient = routeArgs['patientSearchForm'];
patientType = routeArgs['selectedType'];
patientTypetitle = SERVICES_PATIANT_HEADER[int.parse(patientType)];
5 years ago
print(patientType);
5 years ago
if (_isInit) {
PatientsProvider patientsProv = Provider.of<PatientsProvider>(context);
setState(() {
_isLoading = true;
_isError = false;
5 years ago
error = "";
});
5 years ago
patientsProv.getPatientList(patient, patientType).then((res) {
setState(() {
_isLoading = false;
if (res['MessageStatus'] == 1) {
int val2 = int.parse(patientType);
litems = res[SERVICES_PATIANT2[val2]];
parsed = litems;
responseModelList = new ModelResponse.fromJson(parsed).list;
responseModelList2 = responseModelList;
_isError = false;
} else {
_isError = true;
error = res['ErrorEndUserMessage'] ?? res['ErrorMessage'];
}
5 years ago
});
}).catchError((error) {
print(error);
5 years ago
setState(() {
_isError = true;
_isLoading = false;
5 years ago
this.error = helpers.generateContactAdminMsg(error);
});
5 years ago
});
}
5 years ago
_isInit = false;
5 years ago
super.didChangeDependencies();
}
/*
*@author: Amjad Amireh
*@Date:2/5/2020
*@param:
*@return:PatientsScreen Search textbox filter
*@desc:
*/
searchData(String str) {
this.responseModelList = this.responseModelList2;
var strExist = str.length > 0 ? true : false;
if (strExist) {
List<PatiantInformtion> filterData = [];
for (var i = 0; i < responseModelList2.length; i++) {
String firstName = responseModelList[i].firstName.toUpperCase();
String lastName = responseModelList[i].lastName.toUpperCase();
if (firstName.contains(str.toUpperCase()) ||
lastName.contains(str.toUpperCase())) {
filterData.add(responseModelList[i]);
}
}
setState(() {
this.responseModelList = filterData;
});
} else {
setState(() {
this.responseModelList = this.responseModelList2;
});
}
}
/*
*@author: Amjad Amireh
*@Date:5/5/2020
*@param:
*@return:Convert time from Milesecond to date with time
*@desc:
*/
convertDate(String str) {
String timeConvert;
const start = "/Date(";
const end = "+0300)";
final startIndex = str.indexOf(start);
final endIndex = str.indexOf(end, startIndex + start.length);
var date = new DateTime.fromMillisecondsSinceEpoch(
int.parse(str.substring(startIndex + start.length, endIndex)));
String newDateformat = date.year.toString() +
"/" +
date.month.toString().padLeft(2, '0') +
"/" +
date.day.toString().padLeft(2, '0') +
" " +
"-" +
" " +
date.hour.toString().padLeft(2, '0') +
":" +
date.minute.toString().toString().padLeft(2, '0');
return newDateformat.toString();
}
/*
*@author: Amjad Amireh
*@Date:5/5/2020
*@param:
*@return:Convert time from Milesecond to date
*@desc:
*/
convertDateFormat(String str) {
String timeConvert;
const start = "/Date(";
const end = "+0300)";
final startIndex = str.indexOf(start);
final endIndex = str.indexOf(end, startIndex + start.length);
var date = new DateTime.fromMillisecondsSinceEpoch(
int.parse(str.substring(startIndex + start.length, endIndex)));
String newDate = date.year.toString() +
"-" +
date.month.toString().padLeft(2, '0') +
"-" +
date.day.toString().padLeft(2, '0');
return newDate.toString();
}
convertDateFormat2(String str) {
String timeConvert;
const start = "/Date(";
const end = "+0300)";
final startIndex = str.indexOf(start);
final endIndex = str.indexOf(end, startIndex + start.length);
var date = new DateTime.fromMillisecondsSinceEpoch(
int.parse(str.substring(startIndex + start.length, endIndex)));
String newDate = date.year.toString() +
"/" +
date.month.toString().padLeft(2, '0') +
"/" +
date.day.toString().padLeft(2, '0');
return newDate.toString();
}
filterBooking(String str) {
this.responseModelList = this.responseModelList2;
var strExist = str.length > 0 ? true : false;
if (true) {
List<PatiantInformtion> filterDate = [];
for (var i = 0; i < responseModelList2.length; i++) {
String patiantAppointment =
convertDateFormat(responseModelList[i].appointmentDate);
String dateAppointment = checkDate(patiantAppointment);
if (dateAppointment.contains(str)) {
filterDate.add(responseModelList[i]);
}
}
setState(() {
this.responseModelList = filterDate;
});
} else {
setState(() {
this.responseModelList = this.responseModelList2;
});
}
}
String checkDate(String dateString) {
DateTime checkedTime = DateTime.parse(dateString);
DateTime currentTime = DateTime.now();
if ((currentTime.year == checkedTime.year) &&
(currentTime.month == checkedTime.month) &&
(currentTime.day == checkedTime.day)) {
return "Today";
} else if ((currentTime.year == checkedTime.year) &&
(currentTime.month == checkedTime.month)) {
if ((currentTime.day - checkedTime.day) == 1) {
return "YESTERDAY";
} else if ((currentTime.day - checkedTime.day) == -1) {
return "Tomorrow";
}
if ((currentTime.day - checkedTime.day) <= -2) {
return "Next Week";
} else {
return "All";
}
}
return "All";
}
/*
*@author: Amjad Amireh Modified New design
*@Date:21/5/2020
*@param:
*@return:PatientsScreen
*@desc:
*/
@override
Widget build(BuildContext context) {
PatientsProvider patientsProv = Provider.of<PatientsProvider>(context);
return AppScaffold(
5 years ago
appBarTitle: patientTypetitle,
body: _isLoading
? DrAppCircularProgressIndeicator()
: _isError
? DrAppEmbeddedError(error: error)
: litems == null
? DrAppEmbeddedError(error: 'You don\'t have any patient')
: Container(
child: ListView(
scrollDirection: Axis.vertical,
children: <Widget>[
Container(
child: litems == null
? Column(
children: <Widget>[
Container(
child: Center(
child: Padding(
padding: const EdgeInsets.fromLTRB(
0, 0, 0, 0), //250
child:
DrAppCircularProgressIndeicator(),
)),
),
],
)
: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context)
.size
.height *
0.03),
child: SERVICES_PATIANT2[
int.parse(patientType)] ==
"List_MyOutPatient"
? _locationBar(context)
: Container(),
),
SizedBox(height: 10.0),
Container(
width: SizeConfig.screenWidth * 0.9,
child: TextField(
controller: _controller,
onChanged: (String str) {
this.searchData(str);
},
decoration: buildInputDecoration(
context, 'Search '),
),
),
SizedBox(
height: 10.0,
),
Container(
//===============
decoration: BoxDecoration(
color: Color(0Xffffffff),
borderRadius:
BorderRadius.circular(20)),
//================
margin:
EdgeInsets.fromLTRB(15, 0, 15, 0),
child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
children: responseModelList
.map((PatiantInformtion item) {
return Container(
decoration: myBoxDecoration(),
child: InkWell(
child: CardWithBgWidgetNew(
//CardWithBgWidget(
widget: Column(
children: <Widget>[
Container(
// decoration: myBoxDecoration(),
child: Row(
children: <Widget>[
Column(
mainAxisAlignment:
MainAxisAlignment
.start,
children:
item.genderDescription ==
"Male"
? [
SvgPicture.asset(
url + avatarMale,
height: 80.0,
width: 80.0,
semanticsLabel: 'Male Logo')
]
: [
SvgPicture.asset(
url + avatarFemale,
height: 80.0,
width: 80.0,
semanticsLabel: 'Female Logo')
],
),
SizedBox(
width: 10,
),
Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
children: <
Widget>[
AppText(
item.firstName +
" " +
item.lastName,
fontSize: 2.0 *
SizeConfig
.textMultiplier,
fontWeight:
FontWeight
.bold,
backGroundcolor:
Colors
.white,
),
SizedBox(
height: 8,
),
AppText(
"File Number:" +
item.patientId
.toString(),
fontSize: 2.0 *
SizeConfig
.textMultiplier,
fontWeight:
FontWeight
.bold,
backGroundcolor:
Colors
.white,
),
// SizedBox(
// height: 8,
// ),
AppText(
"Age:" +
item.age
.toString(),
fontSize: 2.0 *
SizeConfig
.textMultiplier,
fontWeight:
FontWeight
.bold,
backGroundcolor:
Colors
.white,
),
SizedBox(
height: 8,
),
SERVICES_PATIANT2[
int.parse(patientType)] ==
"List_MyOutPatient"
? Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <
Widget>[
Container(
height:
20,
width:
80,
decoration:
BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Hexcolor("#20A169"),
),
child:
AppText(
item.startTime,
color: Colors.white,
fontSize: 2 * SizeConfig.textMultiplier,
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
),
),
SizedBox(
width:
60,
),
Container(
child:
AppText(
convertDateFormat2(item.appointmentDate.toString()),
fontSize: 2.0 * SizeConfig.textMultiplier,
fontWeight: FontWeight.bold,
),
)
],
)
: AppText(
item.nationalityName,
fontSize:
2.5 *
SizeConfig.textMultiplier,
),
],
),
// Divider(color: Colors.grey)
],
),
),
// Divider(color: Colors.grey)
],
),
),
onTap: () {
Navigator.of(context)
.pushNamed(
PATIENTS_PROFILE,
arguments: {
"patient": item
});
},
),
);
}).toList(),
),
),
],
5 years ago
),
)
],
),
),
);
}
5 years ago
InputDecoration buildInputDecoration(BuildContext context, hint) {
5 years ago
return InputDecoration(
prefixIcon: Icon(Icons.search, color: Colors.red),
5 years ago
filled: true,
fillColor: Colors.white,
hintText: hint,
hintStyle: TextStyle(fontSize: 2 * SizeConfig.textMultiplier),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(20)),
borderSide: BorderSide(color: Hexcolor('#CCCCCC')),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(50.0)),
borderSide: BorderSide(color: Colors.grey), //),
5 years ago
));
}
Widget _locationBar(BuildContext _context) {
return Container(
5 years ago
height: MediaQuery.of(context).size.height * 0.065,
width: SizeConfig.screenWidth * 0.9,
5 years ago
decoration: BoxDecoration(
color: Color(0Xffffffff), borderRadius: BorderRadius.circular(20)),
5 years ago
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: _locations.map((item) {
bool _isActive = _locations[_activeLocation] == item ? true : false;
return Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
5 years ago
InkWell(
child: Center(
child: Container(
height: 40,
width: 90,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: _isActive ? Hexcolor("#B8382B") : Colors.white,
),
child: Center(
child: Text(
item,
style: TextStyle(
fontSize: 12,
color: _isActive
? Colors.white
: Colors.black, //Colors.black,
// backgroundColor:_isActive
// ? Hexcolor("#B8382B")
// : Colors.white,//sideColor,
fontWeight: FontWeight.bold,
),
),
)),
),
5 years ago
onTap: () {
print(_locations.indexOf(item));
filterBooking(item.toString());
setState(() {
_activeLocation = _locations.indexOf(item);
});
}),
_isActive
? Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white),
alignment: Alignment.center,
5 years ago
height: 3,
width: 90,
5 years ago
)
: Container()
]);
}).toList(),
),
);
}
myBoxDecoration() {
return BoxDecoration(
border: Border(
bottom: BorderSide(
// <--- top side
color: Colors.grey,
width: 1.0,
),
),
);
}
}