diff --git a/lib/core/service/patient_service.dart b/lib/core/service/patient_service.dart index d1ec45ce..b16753f5 100644 --- a/lib/core/service/patient_service.dart +++ b/lib/core/service/patient_service.dart @@ -1,5 +1,8 @@ +import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/config/config.dart'; +import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/core/service/base/base_service.dart'; +import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; import 'package:doctor_app_flutter/models/doctor/request_schedule.dart'; import 'package:doctor_app_flutter/models/patient/get_clinic_by_project_id_request.dart'; import 'package:doctor_app_flutter/models/patient/get_doctor_by_clinic_id_request.dart'; @@ -7,6 +10,7 @@ import 'package:doctor_app_flutter/models/patient/get_list_stp_referral_frequenc import 'package:doctor_app_flutter/models/patient/lab_orders/lab_orders_res_model.dart'; import 'package:doctor_app_flutter/models/patient/lab_result/lab_result.dart'; import 'package:doctor_app_flutter/models/patient/lab_result/lab_result_req_model.dart'; +import 'package:doctor_app_flutter/models/patient/patient_model.dart'; import 'package:doctor_app_flutter/models/patient/prescription/prescription_report.dart'; import 'package:doctor_app_flutter/models/patient/prescription/prescription_report_for_in_patient.dart'; import 'package:doctor_app_flutter/models/patient/prescription/prescription_res_model.dart'; @@ -42,22 +46,33 @@ class PatientService extends BaseService { List get prescriptionReport => _prescriptionReport; List _labResultList = []; + List get labResultList => _labResultList; // TODO: replace var with model var _patientProgressNoteList = []; + get patientProgressNoteList => _patientProgressNoteList; // TODO: replace var with model var _insuranceApporvalsList = []; + get insuranceApporvalsList => _insuranceApporvalsList; // TODO: replace var with model - var doctorsList = []; + var _doctorsList = []; + + get doctorsList => _doctorsList; + // TODO: replace var with model - var clinicsList = []; + var _clinicsList = []; + + get clinicsList => _clinicsList; + // TODO: replace var with model - var referalFrequancyList = []; + var _referalFrequancyList = []; + + get referalFrequancyList => _referalFrequancyList; DoctorsByClinicIdRequest _doctorsByClinicIdRequest = DoctorsByClinicIdRequest(); @@ -69,6 +84,47 @@ class PatientService extends BaseService { RequestSchedule _requestSchedule = RequestSchedule(); + Future getPatientList(PatientModel patient, patientType) async { + hasError = false; + int val = int.parse(patientType); + + dynamic localRes; + await baseAppClient.post( + GET_PATIENT + SERVICES_PATIANT[val], + onSuccess: (dynamic response, int statusCode) { + localRes = response; + }, + onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, + body: { + "ProjectID": patient.ProjectID, + "ClinicID": patient.ClinicID, + "DoctorID": patient.DoctorID, + "FirstName": patient.FirstName, + "MiddleName": patient.MiddleName, + "LastName": patient.LastName, + "PatientMobileNumber": patient.PatientMobileNumber, + "PatientIdentificationID": patient.PatientIdentificationID, + "PatientID": patient.PatientID, + "From": patient.From, + "To": patient.To, + "LanguageID": patient.LanguageID, + "stamp": patient.stamp, + "IPAdress": patient.IPAdress, + "VersionID": patient.VersionID, + "Channel": patient.Channel, + "TokenID": patient.TokenID, + "SessionID": patient.SessionID, + "IsLoginForDoctorApp": patient.IsLoginForDoctorApp, + "PatientOutSA": patient.PatientOutSA + }, + ); + + return Future.value(localRes); + } + Future getPatientVitalSign(patient) async { hasError = false; await baseAppClient.post( @@ -219,6 +275,7 @@ class PatientService extends BaseService { body: requestLabResult.toJson(), ); } + Future getPatientInsuranceApprovals(patient) async { hasError = false; @@ -227,7 +284,6 @@ class PatientService extends BaseService { onSuccess: (dynamic response, int statusCode) { _insuranceApporvalsList = []; _insuranceApporvalsList = response['List_ApprovalMain_InPatient']; - }, onFailure: (String error, int statusCode) { hasError = true; @@ -236,6 +292,7 @@ class PatientService extends BaseService { body: patient, ); } + Future getPatientProgressNote(patient) async { hasError = false; @@ -244,7 +301,6 @@ class PatientService extends BaseService { onSuccess: (dynamic response, int statusCode) { _patientProgressNoteList = []; _patientProgressNoteList = response['List_GetPregressNoteForInPatient']; - }, onFailure: (String error, int statusCode) { hasError = true; @@ -253,4 +309,104 @@ class PatientService extends BaseService { body: patient, ); } + + + Future getClinicsList() async { + hasError = false; + + await baseAppClient.post( + PATIENT_GET_CLINIC_BY_PROJECT_URL, + onSuccess: (dynamic response, int statusCode) { + _clinicsList = []; + _clinicsList = response['List_Clinic_All']; + }, + onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, + body: _clinicByProjectIdRequest.toJson(), + ); + } + + + Future getReferralFrequancyList() async { + hasError = false; + + await baseAppClient.post( + PATIENT_GET_LIST_REFERAL_URL, + onSuccess: (dynamic response, int statusCode) { + _referalFrequancyList = []; + _referalFrequancyList = response['list_STPReferralFrequency']; + }, + onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, + body: _referralFrequencyRequest.toJson(), + ); + } + + Future getDoctorsList(String clinicId) async { + hasError = false; + _doctorsByClinicIdRequest.clinicID = clinicId; + await baseAppClient.post( + PATIENT_GET_DOCTOR_BY_CLINIC_URL, + onSuccess: (dynamic response, int statusCode) { + _doctorsList = []; + _doctorsList = response['List_Doctors_All']; + }, + onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, + body: _doctorsByClinicIdRequest.toJson(), + ); + } + + + // TODO send the total model insted of each parameter + Future referToDoctor({String selectedDoctorID, + String selectedClinicID, + int admissionNo, + String extension, + String priority, + String frequency, + String referringDoctorRemarks, + int patientID, + int patientTypeID, + String roomID, + int projectID}) async { + hasError = false; + // TODO Change it to use it when we implement authentication user + Map profile = await sharedPref.getObj(DOCTOR_PROFILE); + DoctorProfileModel doctorProfile = new DoctorProfileModel.fromJson(profile); + int doctorID = doctorProfile.doctorID; + int clinicId = doctorProfile.clinicID; + _referToDoctorRequest = ReferToDoctorRequest( + projectID: projectID, + admissionNo: admissionNo, + roomID: roomID, + referralClinic: selectedClinicID.toString(), + referralDoctor: selectedDoctorID.toString(), + createdBy: doctorID, + editedBy: doctorID, + patientID: patientID, + patientTypeID: patientTypeID, + referringClinic: clinicId, + referringDoctor: doctorID, + referringDoctorRemarks: referringDoctorRemarks, + priority: priority, + frequency: frequency, + extension: extension, + ); + await baseAppClient.post( + PATIENT_PROGRESS_NOTE_URL, + onSuccess: (dynamic response, int statusCode) {}, + onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, + body: _referToDoctorRequest.toJson(), + ); + } } diff --git a/lib/core/viewModel/patient_view_model.dart b/lib/core/viewModel/patient_view_model.dart index f4b67dbc..f39a3d48 100644 --- a/lib/core/viewModel/patient_view_model.dart +++ b/lib/core/viewModel/patient_view_model.dart @@ -2,6 +2,7 @@ import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/service/patient_service.dart'; import 'package:doctor_app_flutter/models/patient/lab_orders/lab_orders_res_model.dart'; import 'package:doctor_app_flutter/models/patient/lab_result/lab_result.dart'; +import 'package:doctor_app_flutter/models/patient/patient_model.dart'; import 'package:doctor_app_flutter/models/patient/prescription/prescription_report.dart'; import 'package:doctor_app_flutter/models/patient/prescription/prescription_report_for_in_patient.dart'; import 'package:doctor_app_flutter/models/patient/prescription/prescription_res_model.dart'; @@ -36,9 +37,33 @@ class PatientViewModel extends BaseViewModel { _patientService.patientRadiologyList; List get labResultList => _patientService.labResultList; + get insuranceApporvalsList => _patientService.insuranceApporvalsList; + get patientProgressNoteList => _patientService.patientProgressNoteList; + get clinicsList => _patientService.clinicsList; + get doctorsList => _patientService.doctorsList; + + get referalFrequancyList => _patientService.referalFrequancyList; + Future getPatientList(PatientModel patient, patientType, + {bool isBusyLocal = false}) async { + if(isBusyLocal) { + setState(ViewState.BusyLocal); + } else { + setState(ViewState.Busy); + } + return _patientService.getPatientList(patient, patientType); + if (_patientService.hasError) { + error = _patientService.error; + if(isBusyLocal) { + setState(ViewState.ErrorLocal); + } else { + setState(ViewState.Error); + } } else + setState(ViewState.Idle); + } + Future getPatientVitalSign(patient) async { setState(ViewState.Busy); await _patientService.getPatientVitalSign(patient); @@ -108,7 +133,8 @@ class PatientViewModel extends BaseViewModel { } else setState(ViewState.Idle); } - Future getPatientInsuranceApprovals(patient) async{ + + Future getPatientInsuranceApprovals(patient) async { setState(ViewState.Busy); await _patientService.getPatientInsuranceApprovals(patient); if (_patientService.hasError) { @@ -117,7 +143,8 @@ class PatientViewModel extends BaseViewModel { } else setState(ViewState.Idle); } - Future getPatientProgressNote(patient) async{ + + Future getPatientProgressNote(patient) async { setState(ViewState.Busy); await _patientService.getPatientProgressNote(patient); if (_patientService.hasError) { @@ -126,4 +153,92 @@ class PatientViewModel extends BaseViewModel { } else setState(ViewState.Idle); } + + Future getClinicsList() async { + setState(ViewState.Busy); + await _patientService.getClinicsList(); + if (_patientService.hasError) { + error = _patientService.error; + setState(ViewState.Error); + } else { + { + await getReferralFrequancyList(); + setState(ViewState.Idle); + } + } + } + Future getDoctorsList(String clinicId) async { + setState(ViewState.BusyLocal); + await _patientService.getDoctorsList(clinicId); + if (_patientService.hasError) { + error = _patientService.error; + setState(ViewState.ErrorLocal); + } else { + { + await getReferralFrequancyList(); + setState(ViewState.Idle); + } + } + } + + List getDoctorNameList() { + var doctorNamelist = + _patientService.doctorsList.map((value) => value['DoctorName'].toString()).toList(); + return doctorNamelist; + } + + List getClinicNameList() { + var clinicsNameslist = _patientService.clinicsList + .map((value) => value['ClinicDescription'].toString()) + .toList(); + return clinicsNameslist; + } + Future getReferralFrequancyList() async { + setState(ViewState.Busy); + await _patientService.getReferralFrequancyList(); + if (_patientService.hasError) { + error = _patientService.error; + setState(ViewState.Error); + } else + setState(ViewState.Idle); + } + + List getReferralNamesList() { + var referralNamesList = _patientService.referalFrequancyList + .map((value) => value['Description'].toString()) + .toList(); + return referralNamesList; + } + + Future referToDoctor( + {String selectedDoctorID, + String selectedClinicID, + int admissionNo, + String extension, + String priority, + String frequency, + String referringDoctorRemarks, + int patientID, + int patientTypeID, + String roomID, + int projectID}) async { + setState(ViewState.BusyLocal); + await _patientService.referToDoctor( + selectedClinicID: selectedClinicID, + selectedDoctorID: selectedDoctorID, + admissionNo: admissionNo, + extension: extension, + priority: priority, + frequency: frequency, + referringDoctorRemarks: referringDoctorRemarks, + patientID: patientID, + patientTypeID: patientTypeID, + roomID: roomID, + projectID: projectID); + if (_patientService.hasError) { + error = _patientService.error; + setState(ViewState.ErrorLocal); + } else + setState(ViewState.Idle); + } } diff --git a/lib/providers/patients_provider.dart b/lib/providers/patients_provider.dart index 52bdb2e6..a562790c 100644 --- a/lib/providers/patients_provider.dart +++ b/lib/providers/patients_provider.dart @@ -128,155 +128,155 @@ class PatientsProvider with ChangeNotifier { throw err; } - /*@author: ibrahem albitar - *@Date:3/6/2020 - *@desc: getDoctorsList - */ - getDoctorsList(String clinicId) async { - setBasicData(); - try { - _doctorsByClinicIdRequest.clinicID = clinicId; - await baseAppClient.post(PATIENT_GET_DOCTOR_BY_CLINIC_URL, - onSuccess: (dynamic response, int statusCode) { - doctorsList = response['List_Doctors_All']; - isLoading = false; - isError = false; - this.error = ''; - }, onFailure: (String error, int statusCode) { - isLoading = false; - isError = true; - this.error = error; - }, body: _doctorsByClinicIdRequest.toJson()); - notifyListeners(); - } catch (err) { - handelCatchErrorCase(err); - } - } - - List getDoctorNameList() { - var doctorNamelist = - doctorsList.map((value) => value['DoctorName'].toString()).toList(); - return doctorNamelist; - } - - /*@author: ibrahem albitar - *@Date:3/6/2020 - *@desc: getClinicsList - */ - getClinicsList() async { - setBasicData(); - try { - await baseAppClient.post(PATIENT_GET_CLINIC_BY_PROJECT_URL, - onSuccess: (dynamic response, int statusCode) { - clinicsList = response['List_Clinic_All']; - isLoading = false; - isError = false; - this.error = ''; - }, onFailure: (String error, int statusCode) { - isLoading = false; - isError = true; - this.error = error; - }, body: _clinicByProjectIdRequest.toJson()); - notifyListeners(); - } catch (err) { - handelCatchErrorCase(err); - } - } - - List getClinicNameList() { - var clinicsNameslist = clinicsList - .map((value) => value['ClinicDescription'].toString()) - .toList(); - return clinicsNameslist; - } - - /*@author: ibrahem albitar - *@Date:3/6/2020 - *@desc: getReferralFrequancyList - */ - getReferralFrequancyList() async { - setBasicData(); - try { - await baseAppClient.post(PATIENT_GET_LIST_REFERAL_URL, - onSuccess: (dynamic response, int statusCode) { - referalFrequancyList = response['list_STPReferralFrequency']; - isLoading = false; - isError = false; - this.error = ''; - }, onFailure: (String error, int statusCode) { - isLoading = false; - isError = true; - this.error = error; - }, body: _referralFrequencyRequest.toJson()); - notifyListeners(); - } catch (err) { - handelCatchErrorCase(err); - } - } - - List getReferralNamesList() { - var referralNamesList = referalFrequancyList - .map((value) => value['Description'].toString()) - .toList(); - return referralNamesList; - } + // /*@author: ibrahem albitar + // *@Date:3/6/2020 + // *@desc: getDoctorsList + // */ + // getDoctorsList(String clinicId) async { + // setBasicData(); + // try { + // _doctorsByClinicIdRequest.clinicID = clinicId; + // await baseAppClient.post(PATIENT_GET_DOCTOR_BY_CLINIC_URL, + // onSuccess: (dynamic response, int statusCode) { + // doctorsList = response['List_Doctors_All']; + // isLoading = false; + // isError = false; + // this.error = ''; + // }, onFailure: (String error, int statusCode) { + // isLoading = false; + // isError = true; + // this.error = error; + // }, body: _doctorsByClinicIdRequest.toJson()); + // notifyListeners(); + // } catch (err) { + // handelCatchErrorCase(err); + // } + // } + // + // List getDoctorNameList() { + // var doctorNamelist = + // doctorsList.map((value) => value['DoctorName'].toString()).toList(); + // return doctorNamelist; + // } + // + // /*@author: ibrahem albitar + // *@Date:3/6/2020 + // *@desc: getClinicsList + // */ + // getClinicsList() async { + // setBasicData(); + // try { + // await baseAppClient.post(PATIENT_GET_CLINIC_BY_PROJECT_URL, + // onSuccess: (dynamic response, int statusCode) { + // clinicsList = response['List_Clinic_All']; + // isLoading = false; + // isError = false; + // this.error = ''; + // }, onFailure: (String error, int statusCode) { + // isLoading = false; + // isError = true; + // this.error = error; + // }, body: _clinicByProjectIdRequest.toJson()); + // notifyListeners(); + // } catch (err) { + // handelCatchErrorCase(err); + // } + // } + // + // List getClinicNameList() { + // var clinicsNameslist = clinicsList + // .map((value) => value['ClinicDescription'].toString()) + // .toList(); + // return clinicsNameslist; + // } + // + // /*@author: ibrahem albitar + // *@Date:3/6/2020 + // *@desc: getReferralFrequancyList + // */ + // getReferralFrequancyList() async { + // setBasicData(); + // try { + // await baseAppClient.post(PATIENT_GET_LIST_REFERAL_URL, + // onSuccess: (dynamic response, int statusCode) { + // referalFrequancyList = response['list_STPReferralFrequency']; + // isLoading = false; + // isError = false; + // this.error = ''; + // }, onFailure: (String error, int statusCode) { + // isLoading = false; + // isError = true; + // this.error = error; + // }, body: _referralFrequencyRequest.toJson()); + // notifyListeners(); + // } catch (err) { + // handelCatchErrorCase(err); + // } + // } + // + // List getReferralNamesList() { + // var referralNamesList = referalFrequancyList + // .map((value) => value['Description'].toString()) + // .toList(); + // return referralNamesList; + // } /*@author: ibrahem albitar *@Date:3/6/2020 *@desc: referToDoctor */ - referToDoctor(context, - {String selectedDoctorID, - String selectedClinicID, - int admissionNo, - String extension, - String priority, - String frequency, - String referringDoctorRemarks, - int patientID, - int patientTypeID, - String roomID, - int projectID}) async { - setBasicData(); - try { - String token = await sharedPref.getString(TOKEN); - Map profile = await sharedPref.getObj(DOCTOR_PROFILE); - DoctorProfileModel doctorProfile = - new DoctorProfileModel.fromJson(profile); - int doctorID = doctorProfile.doctorID; - int clinicId = doctorProfile.clinicID; - _referToDoctorRequest = ReferToDoctorRequest( - projectID: projectID, - admissionNo: admissionNo, - roomID: roomID, - referralClinic: selectedClinicID.toString(), - referralDoctor: selectedDoctorID.toString(), - createdBy: doctorID, - editedBy: doctorID, - patientID: patientID, - patientTypeID: patientTypeID, - referringClinic: clinicId, - referringDoctor: doctorID, - referringDoctorRemarks: referringDoctorRemarks, - priority: priority, - frequency: frequency, - extension: extension, - tokenID: token); - await baseAppClient.post(PATIENT_REFER_TO_DOCTOR_URL, - onSuccess: (dynamic response, int statusCode) { - // print('Done : \n $res'); - Navigator.pop(context); - }, - onFailure: (String error, int statusCode) { - isLoading = false; - isError = true; - this.error = error; - }, - body: _referToDoctorRequest.toJson()); - notifyListeners(); - - } catch (err) { - handelCatchErrorCase(err); - } - } + // referToDoctor(context, + // {String selectedDoctorID, + // String selectedClinicID, + // int admissionNo, + // String extension, + // String priority, + // String frequency, + // String referringDoctorRemarks, + // int patientID, + // int patientTypeID, + // String roomID, + // int projectID}) async { + // setBasicData(); + // try { + // String token = await sharedPref.getString(TOKEN); + // Map profile = await sharedPref.getObj(DOCTOR_PROFILE); + // DoctorProfileModel doctorProfile = + // new DoctorProfileModel.fromJson(profile); + // int doctorID = doctorProfile.doctorID; + // int clinicId = doctorProfile.clinicID; + // _referToDoctorRequest = ReferToDoctorRequest( + // projectID: projectID, + // admissionNo: admissionNo, + // roomID: roomID, + // referralClinic: selectedClinicID.toString(), + // referralDoctor: selectedDoctorID.toString(), + // createdBy: doctorID, + // editedBy: doctorID, + // patientID: patientID, + // patientTypeID: patientTypeID, + // referringClinic: clinicId, + // referringDoctor: doctorID, + // referringDoctorRemarks: referringDoctorRemarks, + // priority: priority, + // frequency: frequency, + // extension: extension, + // tokenID: token); + // await baseAppClient.post(PATIENT_REFER_TO_DOCTOR_URL, + // onSuccess: (dynamic response, int statusCode) { + // // print('Done : \n $res'); + // Navigator.pop(context); + // }, + // onFailure: (String error, int statusCode) { + // isLoading = false; + // isError = true; + // this.error = error; + // }, + // body: _referToDoctorRequest.toJson()); + // notifyListeners(); + // + // } catch (err) { + // handelCatchErrorCase(err); + // } + // } } diff --git a/lib/screens/QR_reader_screen.dart b/lib/screens/QR_reader_screen.dart index 28c6702a..627f5f31 100644 --- a/lib/screens/QR_reader_screen.dart +++ b/lib/screens/QR_reader_screen.dart @@ -1,23 +1,23 @@ import 'package:barcode_scan/platform_wrapper.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/config/size_config.dart'; -import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/patient_view_model.dart'; 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'; import 'package:doctor_app_flutter/providers/patients_provider.dart'; import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart'; +import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/shared/app_button.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/card_with_bg_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import '../routes.dart'; +import 'base/base_view.dart'; class QrReaderScreen extends StatefulWidget { @override @@ -55,18 +55,22 @@ class _QrReaderScreenState extends State { @override Widget build(BuildContext context) { - return AppScaffold( - appBarTitle: TranslationBase.of(context).qr+ TranslationBase.of(context).reader, - body: Center( - child: Container( - margin: EdgeInsets.only(top: SizeConfig.realScreenHeight / 7), - child: FractionallySizedBox( - widthFactor: 0.9, - child: ListView( - children: [ - AppText( - TranslationBase.of(context).startScanning, - fontSize: 18, + return BaseView( + onModelReady: (model) => model.getClinicsList(), + builder: (_, model, w) => AppScaffold( + baseViewModel: model, + appBarTitle: + TranslationBase.of(context).qr + TranslationBase.of(context).reader, + body: Center( + child: Container( + margin: EdgeInsets.only(top: SizeConfig.realScreenHeight / 7), + child: FractionallySizedBox( + widthFactor: 0.9, + child: ListView( + children: [ + AppText( + TranslationBase.of(context).startScanning, + fontSize: 18, fontWeight: FontWeight.bold, textAlign: TextAlign.center, ), @@ -89,7 +93,7 @@ class _QrReaderScreenState extends State { ), Button( onTap: () { - _scanQrAndGetPatient(context); + _scanQrAndGetPatient(context, model); }, title: TranslationBase.of(context).scanQr, loading: isLoading, @@ -111,20 +115,22 @@ class _QrReaderScreenState extends State { error ?? TranslationBase.of(context) .errorMessage, - color: Theme.of(context).errorColor)), + color: Theme + .of(context) + .errorColor)), ], ), - ) + ) : Container(), - ], + ], + ), + ), + ), ), - ), - ), - ), - ); + ),); } - _scanQrAndGetPatient(BuildContext context) async { + _scanQrAndGetPatient(BuildContext context, PatientViewModel model) async { /// When give qr we will change this method to get data /// var result = await BarcodeScanner.scan(); /// int patientID = get from qr result @@ -148,8 +154,8 @@ class _QrReaderScreenState extends State { // Provider.of(context, listen: false); patient.PatientID = 8808; patient.TokenID = token; - Provider.of(context, listen: false) - .getPatientList(patient, "1") + model + .getPatientList(patient, "1", isBusyLocal: true) .then((response) { if (response['MessageStatus'] == 1) { switch (patientType) { diff --git a/lib/screens/patients/profile/refer_patient_screen.dart b/lib/screens/patients/profile/refer_patient_screen.dart index 790088bc..49e8ca77 100644 --- a/lib/screens/patients/profile/refer_patient_screen.dart +++ b/lib/screens/patients/profile/refer_patient_screen.dart @@ -1,5 +1,8 @@ import 'package:doctor_app_flutter/config/config.dart'; +import 'package:doctor_app_flutter/core/viewModel/patient_view_model.dart'; import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; +import 'package:doctor_app_flutter/screens/base/base_view.dart'; +import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/shared/app_buttons_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_text_form_field.dart'; @@ -8,7 +11,6 @@ import 'package:doctor_app_flutter/widgets/shared/rounded_container_widget.dart' import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:intl/intl.dart'; -import 'package:provider/provider.dart'; import '../../../config/size_config.dart'; import '../../../providers/patients_provider.dart'; @@ -16,7 +18,6 @@ import '../../../util/dr_app_shared_pref.dart'; import '../../../util/extenstions.dart'; import '../../../widgets/shared/app_scaffold_widget.dart'; import '../../../widgets/shared/app_texts_widget.dart'; -import '../../../widgets/shared/dr_app_circular_progress_Indeicator.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); @@ -34,7 +35,6 @@ class ReferPatientScreen extends StatefulWidget { } class _ReferPatientState extends State { - PatientsProvider patientsProv; var doctorsList; final _remarksController = TextEditingController(); final _extController = TextEditingController(); @@ -51,46 +51,32 @@ class _ReferPatientState extends State { int _activePriority = 1; - FocusNode myFocusNode; - - @override - void didChangeDependencies() { - super.didChangeDependencies(); - if (_isInit) { - myFocusNode = FocusNode(); - doctorsList = null; - patientsProv = Provider.of(context); - patientsProv.getClinicsList(); - patientsProv.getReferralFrequancyList(); - } - _isInit = false; - } + FocusNode myFocusNode = FocusNode(); @override Widget build(BuildContext context) { - return AppScaffold( - appBarTitle: TranslationBase.of(context).myReferralPatient, - body: patientsProv.isLoading - ? DrAppCircularProgressIndeicator() - : patientsProv.isError - ? DrAppEmbeddedError(error: patientsProv.error) - : patientsProv.clinicsList == null - ? DrAppEmbeddedError(error: 'Something Wrong!') - : SingleChildScrollView( - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - AppText( - TranslationBase.of(context).clinic, - fontSize: 18, - fontWeight: FontWeight.bold, - marginLeft: 15, - marginTop: 15, - ), - RoundedContainer( - margin: 10, - showBorder: true, + return BaseView( + onModelReady: (model) => model.getClinicsList(), + builder: (_, model, w) => AppScaffold( + baseViewModel: model, + appBarTitle: TranslationBase.of(context).myReferralPatient, + body: model.clinicsList == null + ? DrAppEmbeddedError(error: 'Something Wrong!') + : SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AppText( + TranslationBase.of(context).clinic, + fontSize: 18, + fontWeight: FontWeight.bold, + marginLeft: 15, + marginTop: 15, + ), + RoundedContainer( + margin: 10, + showBorder: true, raduis: 30, borderColor: Color(0xff707070), width: double.infinity, @@ -112,7 +98,7 @@ class _ReferPatientState extends State { elevation: 16, selectedItemBuilder: (BuildContext context) { - return patientsProv + return model .getClinicNameList() .map((item) { return Row( @@ -132,7 +118,7 @@ class _ReferPatientState extends State { setState(() { _selectedDoctor = null; _selectedClinic = newValue; - var clinicInfo = patientsProv + var clinicInfo = model .clinicsList .where((i) => i['ClinicDescription'] @@ -144,10 +130,10 @@ class _ReferPatientState extends State { clinicId = clinicInfo[0]['ClinicID'] .toString(); - patientsProv.getDoctorsList(clinicId); + model.getDoctorsList(clinicId); }) }, - items: patientsProv + items: model .getClinicNameList() .map((item) { return DropdownMenuItem( @@ -197,7 +183,7 @@ class _ReferPatientState extends State { elevation: 16, selectedItemBuilder: (BuildContext context) { - return patientsProv + return model .getDoctorNameList() .map((item) { return Row( @@ -217,7 +203,7 @@ class _ReferPatientState extends State { setState(() { _selectedDoctor = newValue; doctorsList = - patientsProv.doctorsList; + model.doctorsList; var doctorInfo = doctorsList .where((i) => i['DoctorName'] @@ -228,7 +214,7 @@ class _ReferPatientState extends State { .toString(); }) }, - items: patientsProv + items: model .getDoctorNameList() .map((item) { return DropdownMenuItem( @@ -311,7 +297,7 @@ class _ReferPatientState extends State { elevation: 16, selectedItemBuilder: (BuildContext context) { - return patientsProv + return model .getReferralNamesList() .map((item) { return Row( @@ -330,7 +316,7 @@ class _ReferPatientState extends State { onChanged: (newValue) => { setState(() { _selectedReferralFrequancy = newValue; - var freqInfo = patientsProv + var freqInfo = model .referalFrequancyList .singleWhere((i) => i[ 'Description'] @@ -342,7 +328,7 @@ class _ReferPatientState extends State { myFocusNode.requestFocus(); }) }, - items: patientsProv + items: model .getReferralNamesList() .map((item) { return DropdownMenuItem( @@ -391,16 +377,21 @@ class _ReferPatientState extends State { ), // TODO replace AppButton with secondary button and add loading AppButton( - title: TranslationBase.of(context).send, + title: TranslationBase + .of(context) + .send, color: Color(PRIMARY_COLOR), - onPressed: () => {referToDoctor(context)}, + onPressed: () => + { + referToDoctor(context, model) + }, ) ], )) - ], - ), - ), - ); + ], + ), + ), + ),); } Widget priorityBar(BuildContext _context) { @@ -489,25 +480,37 @@ class _ReferPatientState extends State { return time; } - void referToDoctor(context) { + referToDoctor(BuildContext context, PatientViewModel model) async { if (!validation()) { return; } - final routeArgs = ModalRoute.of(context).settings.arguments as Map; + final routeArgs = ModalRoute + .of(context) + .settings + .arguments as Map; PatiantInformtion patient = routeArgs['patient']; - patientsProv.referToDoctor(context, - extension: _extController.value.text, - admissionNo: int.parse(patient.admissionNo), - referringDoctorRemarks: _remarksController.value.text, - frequency: freqId, - patientID: patient.patientId, - patientTypeID: patient.patientType, - priority: (_activePriority + 1).toString(), - roomID: patient.roomId, - selectedClinicID: clinicId.toString(), - selectedDoctorID: doctorId.toString(), - projectID: patient.projectId); + + try { + await model.referToDoctor( + extension: _extController.value.text, + admissionNo: int.parse(patient.admissionNo), + referringDoctorRemarks: _remarksController.value.text, + frequency: freqId, + patientID: patient.patientId, + patientTypeID: patient.patientType, + priority: (_activePriority + 1).toString(), + roomID: patient.roomId, + selectedClinicID: clinicId.toString(), + selectedDoctorID: doctorId.toString(), + projectID: patient.projectId); + // TODO: Add Translation + DrAppToastMsg.showSuccesToast( + 'Reply Successfully'); + Navigator.pop(context); + } catch (e) { + DrAppToastMsg.showErrorToast(e); + } } bool validation() {