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/register_patient/RegisterSearchPatientPage.dart

317 lines
13 KiB
Dart

import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/model/PatientRegistration/CheckPatientForRegistrationModel.dart';
import 'package:doctor_app_flutter/core/model/PatientRegistration/GetPatientInfoRequestModel.dart';
import 'package:doctor_app_flutter/core/model/PatientRegistration/PatientRegistrationModel.dart';
import 'package:doctor_app_flutter/core/viewModel/PatientRegistrationViewModel.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/util/date-utils.dart';
import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/dialogs/dailog-list-select.dart';
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart';
import 'package:flutter/material.dart';
class RegisterSearchPatientPage extends StatefulWidget {
final Function changePageViewIndex;
const RegisterSearchPatientPage({Key key, this.changePageViewIndex})
: super(key: key);
@override
_RegisterSearchPatientPageState createState() =>
_RegisterSearchPatientPageState();
}
class _RegisterSearchPatientPageState extends State<RegisterSearchPatientPage> {
String countryError;
dynamic _selectedCountry;
TextEditingController _phoneController = TextEditingController();
TextEditingController _phoneCode = TextEditingController(text: "966");
String phoneError;
TextEditingController _idController = TextEditingController();
String idError;
DateTime _birthDate;
String birthdateError;
@override
Widget build(BuildContext context) {
final screenSize = MediaQuery.of(context).size;
return BaseView<PatientRegistrationViewModel>(
builder: (_, model, w) => AppScaffold(
baseViewModel: model,
isShowAppBar: false,
body: Column(
children: [
Expanded(
child: Container(
width: double.infinity,
margin: EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppText(
"Please enter mobile number or Identification number",
fontFamily: 'Poppins',
fontSize: SizeConfig.textMultiplier * 2.2,
fontWeight: FontWeight.w800,
),
SizedBox(
height: 10,
),
AppTextFieldCustom(
height: screenSize.height * 0.075,
hintText: "Country",
isTextFieldHasSuffix: true,
validationError: countryError,
dropDownText: _selectedCountry != null
? _selectedCountry['nameEn']
: "Saudi Arabia",
enabled: false,
/*onClick: model.dietTypesList != null && model.dietTypesList.length > 0
? () {
openListDialogField('nameEn', 'id', model.dietTypesList, (selectedValue) {
setState(() {
_selectedCountry = selectedValue;
});
});
}
: () async {
GifLoaderDialogUtils.showMyDialog(context);
await model
.getDietTypes(patient.patientId)
.then((_) => GifLoaderDialogUtils.hideDialog(context));
if (model.state == ViewState.Idle && model.dietTypesList.length > 0) {
openListDialogField('nameEn', 'id', model.dietTypesList, (selectedValue) {
setState(() {
_selectedCountry = selectedValue;
});
});
} else if (model.state == ViewState.ErrorLocal) {
DrAppToastMsg.showErrorToast(model.error);
} else {
DrAppToastMsg.showErrorToast("Empty List");
}
},*/
),
SizedBox(
height: 10,
),
Row(
children: [
Container(
width: MediaQuery.of(context).size.width * 0.3,
child: AppTextFieldCustom(
height: screenSize.height * 0.075,
hintText: "Code",
inputType: TextInputType.phone,
controller: _phoneCode,
validationError: phoneError,
),
),
Expanded(
child: Container(
// width: MediaQuery.of(context).size.width*0.7,
child: AppTextFieldCustom(
height: screenSize.height * 0.075,
hintText: "Phone Number",
inputType: TextInputType.phone,
controller: _phoneController,
validationError: phoneError,
),
),
),
],
),
SizedBox(
height: 10,
),
AppTextFieldCustom(
height: screenSize.height * 0.075,
hintText: "ID Number",
inputType: TextInputType.phone,
controller: _idController,
validationError: idError,
),
SizedBox(
height: 12,
),
AppText(
"Calender",
fontSize: SizeConfig.textMultiplier * 1.8,
fontWeight: FontWeight.w800,
),
SizedBox(
height: 10,
),
AppTextFieldCustom(
height: screenSize.height * 0.075,
hintText: "Birthdate",
dropDownText: _birthDate != null
? "${AppDateUtils.convertStringToDateFormat(_birthDate.toString(), "yyyy/MM/dd")}"
: null,
enabled: false,
isTextFieldHasSuffix: true,
validationError: birthdateError,
suffixIcon: IconButton(
icon: Icon(
Icons.calendar_today,
color: Colors.black,
),
onPressed: null,
),
onClick: () {
if (_birthDate == null) {
_birthDate = DateTime.now();
}
_selectDate(context, _birthDate, (picked) {
setState(() {
_birthDate = picked;
});
});
},
),
],
),
),
),
),
],
),
bottomSheet: Container(
height: 60,
margin: EdgeInsets.symmetric(vertical: 16, horizontal: 16),
child: Row(
children: [
Expanded(
child: Container(
child: AppButton(
title: TranslationBase.of(context).cancel,
hasBorder: true,
vPadding: 12,
hPadding: 8,
borderColor: Color(0xFFeaeaea),
color: Color(0xFFeaeaea),
fontColor: Colors.black,
fontSize: 2.2,
onPressed: () {
Navigator.of(context).pop();
},
),
),
),
SizedBox(
width: 8,
),
Expanded(
child: Container(
child: AppButton(
title: TranslationBase.of(context).next,
hasBorder: true,
vPadding: 12,
hPadding: 8,
borderColor: Color(0xFFB8382B),
color: Color(0xFFB8382B),
fontColor: Colors.white,
fontSize: 2.0,
onPressed: () async {
GifLoaderDialogUtils.showMyDialog(context);
CheckPatientForRegistrationModel
checkPatientForRegistrationModel =
CheckPatientForRegistrationModel(
patientIdentificationID:
int.parse(_idController.text),
patientMobileNumber:
int.parse(_phoneController.text),
zipCode: _phoneCode.text,
isHijri: 0,
patientID: 0,
isRegister: false,
isDentalAllowedBackend: false,
patientOutSA: 0,
generalid: GENERAL_ID,
dOB:
"${AppDateUtils.convertStringToDateFormat(_birthDate.toString(), "yyyy/MM/dd")}");
await model.checkPatientForRegistration(
checkPatientForRegistrationModel);
GetPatientInfoRequestModel getPatientInfoRequestModel =
GetPatientInfoRequestModel(
//TODO Elham* this return the static to dynamic
patientIdentificationID:"1062938285", //_idController.text,
isHijri: 0,
isDentalAllowedBackend: false,
patientOutSA: 0,
generalid: GENERAL_ID,
sessionID: null,
dOB:"31/07/1988",//"${AppDateUtils.convertStringToDateFormat(_birthDate.toString(), "dd/MM/yyyy")}"
);
await model.getPatientInfo(getPatientInfoRequestModel);
if (model.state == ViewState.ErrorLocal) {
Helpers.showErrorToast(model.error);
} else {
widget.changePageViewIndex(1);
}
GifLoaderDialogUtils.hideDialog(context);
},
),
),
),
],
),
),
),
);
}
Future _selectDate(BuildContext context, DateTime dateTime,
Function(DateTime picked) updateDate) async {
final DateTime picked = await showDatePicker(
context: context,
initialDate: dateTime,
firstDate: DateTime(DateTime.now().year - 150),
lastDate: DateTime(DateTime.now().year + 150),
initialEntryMode: DatePickerEntryMode.calendar,
);
if (picked != null && picked != dateTime) {
updateDate(picked);
}
}
void openListDialogField(String attributeName, String attributeValueId,
List<dynamic> list, Function(dynamic selectedValue) okFunction) {
ListSelectDialog dialog = ListSelectDialog(
list: list,
attributeName: attributeName,
attributeValueId: attributeValueId,
usingSearch: true,
okText: TranslationBase.of(context).ok,
okFunction: (selectedValue) {
okFunction(selectedValue);
},
);
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return dialog;
},
);
}
}