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/patient_search_screen.dart

611 lines
30 KiB
Dart

4 years ago
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
import 'package:doctor_app_flutter/models/patient/patient_model.dart';
import 'package:doctor_app_flutter/routes.dart';
import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart';
import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';
import '../../config/config.dart';
import '../../config/size_config.dart';
import '../../lookups/patient_lookup.dart';
import '../../widgets/patients/dynamic_elements.dart';
import '../../widgets/shared/buttons/app_buttons_widget.dart';
import '../../widgets/shared/app_scaffold_widget.dart';
import '../../widgets/shared/app_text_form_field.dart';
import '../../widgets/shared/app_texts_widget.dart';
import '../../widgets/shared/rounded_container_widget.dart';
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
Helpers helpers = Helpers();
// OWNER : Ibrahim albitar
// DATE : 19-04-2020
// DESCRIPTION : Patient Search Screen.
class PatientSearchScreen extends StatefulWidget {
@override
_PatientSearchScreenState createState() => _PatientSearchScreenState();
}
class _PatientSearchScreenState extends State<PatientSearchScreen> {
String _selectedType = '1';
String _selectedLocation = '1';
String error = '';
ProjectViewModel projectsProvider;
String itemText = '';
String itemText2 = '';
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
bool _autoValidate = false;
bool onlyArrived = true;
bool isView = false;
bool isFormSubmitted = false;
FocusNode _nodeText1 = FocusNode();
FocusNode _nodeText2 = FocusNode();
FocusNode _nodeText3 = FocusNode();
var _patientSearchFormValues = PatientModel(
FirstName: "0",
MiddleName: "0",
LastName: "0",
PatientMobileNumber: "0",
PatientIdentificationID: "0",
4 years ago
MobileNo: '0',
PatientID: 0,
From: "0",
To: "0",
LanguageID: 2,
stamp: "2020-03-02T13:56:39.170Z",
IPAdress: "11.11.11.11",
VersionID: 1.2,
Channel: 9,
TokenID: "2Fi7HoIHB0eDyekVa6tCJg==",
SessionID: "5G0yXn0Jnq",
IsLoginForDoctorApp: true,
4 years ago
IdentificationNo: '0',
PatientOutSA: false);
void _validateInputs() async {
setState(() {
isFormSubmitted = true;
});
try {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
4 years ago
if ((_patientSearchFormValues.From == "0" ||
_patientSearchFormValues.To == "0") &&
_selectedType == "7" ||
((_patientSearchFormValues.From == "0" ||
_patientSearchFormValues.To == "0") &&
_selectedType == "6")) {
// helpers.showErrorToast("Please Choose The Dates");
4 years ago
} else {
setState(() {
isFormSubmitted = false;
});
4 years ago
Navigator.of(context).pushNamed(PATIENTS, arguments: {
"patientSearchForm": _patientSearchFormValues,
"selectedType": _selectedType,
"isSearch": true,
4 years ago
"isView": isView
4 years ago
});
}
} else {
setState(() {
_autoValidate = true;
});
}
} catch (err) {
4 years ago
error = err.toString();
}
}
handelCatchErrorCase(err) {
//isLoading = false;
//isError = true;
error = helpers.generateContactAdminMsg(err);
//notifyListeners();
throw err;
}
@override
Widget build(BuildContext context) {
projectsProvider = Provider.of(context);
return GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(new FocusNode());
},
child: AppScaffold(
appBarTitle: TranslationBase.of(context).searchPatient,
isShowAppBar: false,
body: ListView(
children: <Widget>[
RoundedContainer(
child: Column(
children: <Widget>[
Column(
children: <Widget>[
// Container(
// child: Icon(
// DoctorApp.search_patient_1,
// size: 100,
// color: Colors.black,
// ),
// margin: EdgeInsets.only(top: 10),
// ),
// Padding(
// padding: const EdgeInsets.only(top: 12.0),
// child: AppText(
// TranslationBase.of(context)
// .searchPatientImageCaptionTitle
// .toUpperCase(),
// fontWeight: FontWeight.bold,
// fontSize: SizeConfig.heightMultiplier * 2.5,
// ),
// ),
// Padding(
// padding: const EdgeInsets.only(top: 5.0),
// child: AppText(
// TranslationBase.of(context)
// .searchPatientImageCaptionBody,
// fontSize: SizeConfig.heightMultiplier * 2,
// ),
// )
],
),
Container(
padding: EdgeInsets.all(15),
width: SizeConfig.screenWidth * 1,
child: Form(
key: _formKey,
autovalidate: _autoValidate,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 15,
),
if (_selectedType != '7')
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(6.0)),
border: Border.all(
width: 1.0, color: HexColor("#CCCCCC"))),
padding: EdgeInsets.all(10),
child: AppTextFormField(
4 years ago
labelText: TranslationBase.of(context)
.patpatientIDMobilenationalientID,
borderColor: Colors.white,
textInputType: TextInputType.number,
textInputAction: TextInputAction.done,
inputFormatter: ONLY_NUMBERS,
focusNode: _nodeText1,
onSaved: (value) {
4 years ago
if (value != null && value != '') {
if (value.length == 10 &&
(value[0] == '2' || value[0] == '1')) {
_patientSearchFormValues
4 years ago
.IdentificationNo = value;
_patientSearchFormValues.Searchtype = 2;
_patientSearchFormValues.setPatientID = 0;
} else if ((value.length == 10 ||
value.length == 9) &&
4 years ago
((value[0] == '0' && value[1] == '5') ||
value[0] == '5')) {
4 years ago
_patientSearchFormValues.MobileNo = value;
_patientSearchFormValues.Searchtype = 0;
4 years ago
} else {
_patientSearchFormValues.setPatientID =
4 years ago
int.parse(value);
4 years ago
_patientSearchFormValues.Searchtype = 1;
4 years ago
}
}
4 years ago
// else{
// }
// value == null || value == ''
// ? _patientSearchFormValues.setPatientID =
// 0
// : _patientSearchFormValues.setPatientID =
// int.parse(value);
// if (value != null &&
// value.toString().trim().isEmpty) {
// _patientSearchFormValues.setPatientID = 0;
// }
},
),
),
SizedBox(
height: 10,
),
4 years ago
// Row(
// mainAxisAlignment: MainAxisAlignment.end,
// children: [
// InkWell(
// child: this.isView == false
// ? AppText(
// TranslationBase.of(context)
// .searchWithOther,
// color: Colors.red,
// fontWeight: FontWeight.bold,
// )
// : AppText(
// TranslationBase.of(context)
// .hideOtherCriteria,
// color: Colors.red,
// fontWeight: FontWeight.bold),
// onTap: () {
// setState(() {
// this.isView = !this.isView;
// });
// },
// )
// ],
// ),
isView == true
? Column(children: [
SizedBox(
height: 10,
),
Container(
height: 65.0,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 1.0,
style: BorderStyle.solid,
color: HexColor("#CCCCCC")),
borderRadius: BorderRadius.all(
Radius.circular(6.0)),
),
),
width: double.infinity,
child: Padding(
padding: EdgeInsets.only(
top: SizeConfig.widthMultiplier * 0.9,
bottom:
SizeConfig.widthMultiplier * 0.9,
right: SizeConfig.widthMultiplier * 3,
left: SizeConfig.widthMultiplier * 3),
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
// add Expanded to have your dropdown button fill remaining space
child: DropdownButtonHideUnderline(
child: DropdownButton(
isExpanded: true,
value: _selectedType,
iconSize: 25,
elevation: 16,
selectedItemBuilder:
(BuildContext context) {
4 years ago
return PATIENT_TYPE_Des.map(
(item) {
return Row(
mainAxisSize:
MainAxisSize.max,
children: <Widget>[
!projectsProvider.isArabic
? AppText(
item['text'],
fontSize: SizeConfig
.textMultiplier *
2.1,
)
: AppText(
item['text_ar'],
fontSize: SizeConfig
.textMultiplier *
2.1,
),
],
);
}).toList();
},
onChanged: (String newValue) => {
setState(() {
_selectedType = newValue;
selectedPatientType =
int.parse(_selectedType);
})
},
4 years ago
items:
PATIENT_TYPE_Des.map((item) {
!projectsProvider.isArabic
? itemText = item['text']
: itemText =
item['text_ar'];
return DropdownMenuItem(
child: Text(
itemText,
textAlign: TextAlign.end,
),
value: item['val'],
);
}).toList(),
)),
),
],
),
),
),
SizedBox(
height: 10,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(6.0)),
border: Border.all(
width: 1.0,
color: HexColor("#CCCCCC"))),
padding: EdgeInsets.all(10),
child: AppTextFormField(
labelText: TranslationBase.of(context)
.firstName,
borderColor: Colors.white,
onSaved: (value) {
value == null || value == ''
? _patientSearchFormValues
.setFirstName = "0"
: _patientSearchFormValues
.setFirstName = value;
if (value != null &&
value.toString().trim().isEmpty) {
_patientSearchFormValues
.setFirstName = "0";
}
},
// validator: (value) {
// return TextValidator().validateName(value);
// },
inputFormatter: ONLY_LETTERS),
),
SizedBox(
height: 10,
),
4 years ago
if (_selectedType != '7')
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(6.0)),
border: Border.all(
width: 1.0,
color: HexColor("#CCCCCC"))),
padding: EdgeInsets.all(10),
child: AppTextFormField(
labelText: TranslationBase.of(context)
4 years ago
.phoneNumber,
borderColor: Colors.white,
4 years ago
textInputType: TextInputType.number,
textInputAction: TextInputAction.done,
inputFormatter: ONLY_NUMBERS,
focusNode: _nodeText1,
onSaved: (value) {
value == null || value == ''
? _patientSearchFormValues
4 years ago
.setPatientMobileNumber = "0"
: _patientSearchFormValues
4 years ago
.setPatientMobileNumber =
value;
if (value != null &&
value.toString().trim().isEmpty) {
_patientSearchFormValues
4 years ago
.setPatientMobileNumber = "0";
}
},
4 years ago
),
),
SizedBox(
height: 10,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(6.0)),
border: Border.all(
width: 1.0,
color: HexColor("#CCCCCC"))),
padding: EdgeInsets.all(10),
child: AppTextFormField(
labelText: TranslationBase.of(context)
4 years ago
.middleName,
borderColor: Colors.white,
onSaved: (value) {
value == null || value == ''
? _patientSearchFormValues
4 years ago
.setMiddleName = "0"
: _patientSearchFormValues
4 years ago
.setMiddleName = value;
if (value != null &&
value.toString().trim().isEmpty) {
_patientSearchFormValues
4 years ago
.setMiddleName = "0";
}
},
4 years ago
// validator: (value) {
// return TextValidator().validateName(value);
// },
inputFormatter: ONLY_LETTERS),
),
SizedBox(
height: 10,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(6.0)),
border: Border.all(
width: 1.0,
color: HexColor("#CCCCCC"))),
padding: EdgeInsets.all(10),
child: AppTextFormField(
labelText: TranslationBase.of(context)
4 years ago
.lastName,
borderColor: Colors.white,
onSaved: (value) {
value == null || value == ''
? _patientSearchFormValues
4 years ago
.setLastName = "0"
: _patientSearchFormValues
4 years ago
.setLastName = value;
if (value != null &&
4 years ago
value.toString().trim().isEmpty) {
_patientSearchFormValues
4 years ago
.setLastName = "0";
}
4 years ago
},
inputFormatter: ONLY_LETTERS),
),
SizedBox(
height: 10,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(6.0)),
border: Border.all(
width: 1.0,
color: HexColor("#CCCCCC"))),
padding: EdgeInsets.all(10),
child: AppTextFormField(
4 years ago
labelText: TranslationBase.of(context)
.patientID,
borderColor: Colors.white,
textInputType: TextInputType.number,
inputFormatter: ONLY_NUMBERS,
focusNode: _nodeText2,
onSaved: (value) {
value == null || value == ''
? _patientSearchFormValues
.setPatientID = 0
: _patientSearchFormValues
.setPatientID =
int.parse(value);
if (value != null &&
value.trim().toString().isEmpty) {
_patientSearchFormValues
.setPatientID = 0;
}
}),
),
4 years ago
SizedBox(
height: 10,
),
4 years ago
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(6.0)),
border: Border.all(
width: 1.0,
color: HexColor("#CCCCCC"))),
padding: EdgeInsets.all(10),
child: AppTextFormField(
labelText: TranslationBase.of(context)
.patientFile,
borderColor: Colors.white,
textInputType: TextInputType.number,
focusNode: _nodeText3,
inputFormatter: ONLY_NUMBERS,
onSaved: (value) {},
),
),
4 years ago
(!(_selectedType == '2' ||
_selectedType == '4'))
? DynamicElements(
_patientSearchFormValues,
isFormSubmitted)
: SizedBox(
height: 0,
),
SizedBox(
height: 10,
),
Container(
child: Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(6.0)),
border: Border.all(
width: 1.0,
color: HexColor("#CCCCCC"))),
height: 25,
width: 25,
child: Checkbox(
value: onlyArrived,
checkColor: HexColor("#2A930A"),
activeColor: Colors.white,
onChanged: (bool newValue) {
setState(() {
onlyArrived = newValue;
});
}),
),
SizedBox(
width: 12,
),
AppText(
TranslationBase.of(context)
.onlyArrivedPatient,
fontSize:
SizeConfig.textMultiplier * 2),
])),
SizedBox(
height: 10,
),
])
: SizedBox(
height: SizeConfig.screenHeight * .45,
),
],
),
),
),
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
margin: EdgeInsets.all(SizeConfig.widthMultiplier * 5),
child: Wrap(
alignment: WrapAlignment.center,
children: <Widget>[
AppButton(
title: TranslationBase.of(context).search,
onPressed: () {
_validateInputs();
},
),
],
),
),
],
),
],
),
),
);
}
}