diff --git a/lib/config/config.dart b/lib/config/config.dart index 6c4da7b1..6afcb64f 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -27,7 +27,8 @@ const PATIENT_GET_CLINIC_BY_PROJECT_URL = const PROJECT_GET_INFO = "Services/DoctorApplication.svc/REST/GetProjectInfo"; const GET_CLINICS = "Services/DoctorApplication.svc/REST/GetClinics"; -//const GET_PROJECTS = 'Services/Lists.svc/REST/GetProjectForDoctorAPP'; +const GET_REFERRAL_FACILITIES = 'Services/DoctorApplication.svc/REST/GetReferralFacilities'; + const GET_PROJECTS = 'Services/DoctorApplication.svc/REST/GetProjectInfo'; const GET_PATIENT_VITAL_SIGN = diff --git a/lib/core/service/patient-doctor-referral-service.dart b/lib/core/service/patient-doctor-referral-service.dart index 813fef35..3136b549 100644 --- a/lib/core/service/patient-doctor-referral-service.dart +++ b/lib/core/service/patient-doctor-referral-service.dart @@ -49,6 +49,20 @@ class PatientReferralService extends LookupService { }, body: info); } + Future getReferralFacilities() async { + hasError = false; + + Map body = Map(); + body['isSameBranch'] = false; + + await baseAppClient.post(GET_REFERRAL_FACILITIES, onSuccess: (response, statusCode) async { + projectsList = response['ProjectInfo']; + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: body); + } + Future getProjectInfo(int projectId) async { Map body = Map(); body['ProjectID'] = projectId; diff --git a/lib/core/viewModel/patient-referral-viewmodel.dart b/lib/core/viewModel/patient-referral-viewmodel.dart index 5771d1db..00ef09f6 100644 --- a/lib/core/viewModel/patient-referral-viewmodel.dart +++ b/lib/core/viewModel/patient-referral-viewmodel.dart @@ -62,7 +62,7 @@ class PatientReferralViewModel extends BaseViewModel { Future getBranches() async { setState(ViewState.BusyLocal); - await _referralPatientService.getProjectsList(); + await _referralPatientService.getReferralFacilities(); if (_referralPatientService.hasError) { error = _referralPatientService.error; setState(ViewState.Error); @@ -77,7 +77,7 @@ class PatientReferralViewModel extends BaseViewModel { await _referralPatientService.getProjectInfo(projectId); if (_referralPatientService.hasError) { error = _referralPatientService.error; - setState(ViewState.Error); + setState(ViewState.ErrorLocal); } else setState(ViewState.Idle); } @@ -87,7 +87,7 @@ class PatientReferralViewModel extends BaseViewModel { await _referralPatientService.getDoctorsList(clinicId); if (_referralPatientService.hasError) { error = _referralPatientService.error; - setState(ViewState.Error); + setState(ViewState.ErrorLocal); } else setState(ViewState.Idle); } diff --git a/lib/screens/patients/profile/referral/refer-patient-screen.dart b/lib/screens/patients/profile/referral/refer-patient-screen.dart index b2a71f4b..6f053089 100644 --- a/lib/screens/patients/profile/referral/refer-patient-screen.dart +++ b/lib/screens/patients/profile/referral/refer-patient-screen.dart @@ -1,4 +1,5 @@ import 'package:doctor_app_flutter/config/config.dart'; +import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/viewModel/patient-referral-viewmodel.dart'; import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; @@ -177,15 +178,18 @@ class _PatientMakeReferralScreenState extends State { _selectedBranch = null; _selectedClinic = null; _selectedDoctor = null; - model.getDoctorBranch().then((value) { + model.getDoctorBranch().then((value) async { _selectedBranch = value; if (_referTo['id'] == 1) { GifLoaderDialogUtils.showMyDialog(context); - model + await model .getClinics(_selectedBranch['facilityId']) .then((_) => GifLoaderDialogUtils.hideDialog( context)); + if (model.state == ViewState.ErrorLocal) { + DrAppToastMsg.showErrorToast(model.error); + } } }); }); @@ -226,15 +230,18 @@ class _PatientMakeReferralScreenState extends State { attributeValueId: 'facilityId', okText: TranslationBase.of(context).ok, okFunction: (selectedValue) { - setState(() { + setState(() async { _selectedBranch = selectedValue; _selectedClinic = null; _selectedDoctor = null; GifLoaderDialogUtils.showMyDialog(context); - model + await model .getClinics(_selectedBranch['facilityId']) .then((_) => GifLoaderDialogUtils.hideDialog(context)); + if (model.state == ViewState.ErrorLocal) { + DrAppToastMsg.showErrorToast(model.error); + } }); }, ); @@ -277,15 +284,18 @@ class _PatientMakeReferralScreenState extends State { TranslationBase.of(context).clinicSearch, okText: TranslationBase.of(context).ok, okFunction: (selectedValue) { - setState(() { + setState(() async { _selectedDoctor = null; _selectedClinic = selectedValue; GifLoaderDialogUtils.showMyDialog(context); - model + await model .getClinicDoctors( _selectedClinic['ClinicID'].toString()) .then((_) => GifLoaderDialogUtils.hideDialog(context)); + if (model.state == ViewState.ErrorLocal) { + DrAppToastMsg.showErrorToast(model.error); + } }); }, );