From a42f06c9ffe327524b58748dcb278f764e8fbcb5 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Tue, 9 Jun 2020 15:25:43 +0300 Subject: [PATCH 1/7] modify hospital provider to make it call app base --- lib/client/base_app_client.dart | 26 +++++++++++++++++++------- lib/config/config.dart | 8 ++++++-- lib/providers/hospital_provider.dart | 25 +++++++++++++++++-------- lib/screens/auth/login_screen.dart | 4 +++- lib/widgets/auth/login_form.dart | 18 ++++++++++++++---- 5 files changed, 59 insertions(+), 22 deletions(-) diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index 0d57b9dd..f23acf57 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -4,9 +4,16 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/interceptor/http_interceptor.dart'; import 'package:doctor_app_flutter/models/doctor_profile_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:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; import 'package:http/http.dart'; +DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); +Helpers helpers = new Helpers(); + /* *@author: Mohammad Aljammal *@Date:28/5/2020 @@ -34,12 +41,14 @@ class BaseAppClient { try { Map profile = await sharedPref.getObj(DOCTOR_PROFILE); String token = await sharedPref.getString(TOKEN); - DoctorProfileModel doctorProfile = DoctorProfileModel.fromJson(profile); - body['DoctorID'] = doctorProfile.doctorID; - body['EditedBy'] = doctorProfile.doctorID; - body['ProjectID'] = doctorProfile.projectID; - body['ClinicID'] = doctorProfile.clinicID; - body['TokenID'] = token; + if (profile != null) { + DoctorProfileModel doctorProfile = DoctorProfileModel.fromJson(profile); + body['DoctorID'] = doctorProfile?.doctorID; + body['EditedBy'] = doctorProfile?.doctorID; + body['ProjectID'] = doctorProfile?.projectID; + body['ClinicID'] = doctorProfile?.clinicID; + } + body['TokenID'] = token ?? ''; body['LanguageID'] = LANGUAGE_ID; body['stamp'] = STAMP; body['IPAdress'] = IP_ADDRESS; @@ -56,7 +65,10 @@ class BaseAppClient { onFailure('Error While Fetching data', statusCode); } else { var parsed = json.decode(response.body.toString()); - if (parsed['MessageStatus'] == 1) { + if (!parsed['IsAuthenticated']) { + Navigator.of(AppGlobal.CONTEX).pushNamed(LOGIN); + helpers.showErrorToast('Your session expired Please login agian'); + } else if (parsed['MessageStatus'] == 1) { onSuccess(parsed, statusCode); } else { onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], diff --git a/lib/config/config.dart b/lib/config/config.dart index 886430ad..b1cb4682 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -2,8 +2,8 @@ const MAX_SMALL_SCREEN = 660; const ONLY_NUMBERS = "[0-9]"; const ONLY_LETTERS = "[a-zA-Z]"; const ONLY_DATE = "[0-9/]"; - const BASE_URL = 'https://hmgwebservices.com/Services/'; -//const BASE_URL = 'https://uat.hmgwebservices.com/Services/'; +// const BASE_URL = 'https://hmgwebservices.com/Services/'; +const BASE_URL = 'https://uat.hmgwebservices.com/Services/'; const PHARMACY_ITEMS_URL = "Lists.svc/REST/GetPharmcyItems_Region"; const PHARMACY_LIST_URL = "Patients.svc/REST/GetPharmcyList"; const PATIENT_PROGRESS_NOTE_URL = "DoctorApplication.svc/REST/GetProgressNoteForInPatient"; @@ -64,3 +64,7 @@ const PATIENT_OUT_SA = false; /// Timer Info const TIMER_MIN =10; +class AppGlobal{ +static var CONTEX; +} + diff --git a/lib/providers/hospital_provider.dart b/lib/providers/hospital_provider.dart index abf758a2..834b3889 100644 --- a/lib/providers/hospital_provider.dart +++ b/lib/providers/hospital_provider.dart @@ -1,11 +1,11 @@ import 'dart:convert'; import 'package:doctor_app_flutter/client/app_client.dart'; +import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/config/config.dart'; import 'package:flutter/cupertino.dart'; class HospitalProvider with ChangeNotifier { - Future getProjectsList() async { const url = GET_PROJECTS; var info = { @@ -18,12 +18,21 @@ class HospitalProvider with ChangeNotifier { "SessionID": "i1UJwCTSqt", "IsLoginForDoctorApp": true }; - try { - final response = await AppClient.post(url, body: json.encode(info)); - return Future.value(json.decode(response.body)); - } catch (error) { - throw error; - // print('error'); - } + // try { + // final response = await AppClient.post(url, body: json.encode(info)); + // return Future.value(json.decode(response.body)); + // } catch (error) { + // throw error; + // // print('error'); + // } + + await BaseAppClient.post(url, + onSuccess: ( response, statusCode) { + return Future.value(response); + }, + onFailure: (String error, int statusCode) { + throw error; + }, + body: info); } } diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 8b25d21d..2d43a048 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:doctor_app_flutter/config/config.dart'; import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -11,8 +12,8 @@ import '../../widgets/auth/login_form.dart'; import '../../widgets/shared/app_scaffold_widget.dart'; import '../../widgets/shared/dr_app_circular_progress_Indeicator.dart'; -DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); +DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); class Loginsreen extends StatefulWidget { @override _LoginsreenState createState() => _LoginsreenState(); @@ -55,6 +56,7 @@ class _LoginsreenState extends State { @override Widget build(BuildContext context) { + AppGlobal.CONTEX = context; getSharedPref(); return AppScaffold( isLoading: _isLoading, diff --git a/lib/widgets/auth/login_form.dart b/lib/widgets/auth/login_form.dart index b93bfafa..ba6c9a02 100644 --- a/lib/widgets/auth/login_form.dart +++ b/lib/widgets/auth/login_form.dart @@ -36,7 +36,7 @@ class _LoginFormState extends State { String _platformImei = 'Unknown'; String uniqueId = "Unknown"; var projectsList = []; - + bool _isInit = true; FocusNode focusPass; FocusNode focusProject; @@ -54,6 +54,19 @@ class _LoginFormState extends State { void initState() { super.initState(); initPlatformState(); + + + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + if (_isInit) { + if (projectsList.length == 0) { + getProjectsList(); + } + } + _isInit = false; } @override @@ -61,9 +74,6 @@ class _LoginFormState extends State { final focusPass = FocusNode(); final focusProject = FocusNode(); - if (projectsList.length == 0) { - getProjectsList(); - } AuthProvider authProv = Provider.of(context); return Form( From 02216b497cd89af687596df63204e93100186cba Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Tue, 9 Jun 2020 15:47:59 +0300 Subject: [PATCH 2/7] delete http intercceptor --- lib/client/app_client.dart | 12 +-- lib/client/base_app_client.dart | 11 ++- lib/interceptor/http_interceptor.dart | 65 ------------- lib/providers/patients_provider.dart | 127 ++++++++++++-------------- 4 files changed, 69 insertions(+), 146 deletions(-) delete mode 100644 lib/interceptor/http_interceptor.dart diff --git a/lib/client/app_client.dart b/lib/client/app_client.dart index 68c4fb8b..215b2714 100644 --- a/lib/client/app_client.dart +++ b/lib/client/app_client.dart @@ -1,6 +1,5 @@ import 'package:doctor_app_flutter/config/config.dart'; -import 'package:doctor_app_flutter/interceptor/http_interceptor.dart'; -import 'package:http/http.dart'; +import 'package:http/http.dart' as http; // OWNER : Ibrahim albitar // DATE : 22-04-2020 @@ -8,11 +7,12 @@ import 'package:http/http.dart'; class AppClient { - static Client client = HttpInterceptor().getClient(); - - static Future post(dynamic path, {dynamic body}) async { + static Future post(dynamic path, {dynamic body}) async { String _fullUrl = BASE_URL + path; - final response = await client.post(_fullUrl, body: body); + final response = await http.post(_fullUrl, body: body, headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }); return response; } } \ No newline at end of file diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index f23acf57..39b3c683 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -2,14 +2,13 @@ import 'dart:convert'; import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; -import 'package:doctor_app_flutter/interceptor/http_interceptor.dart'; import 'package:doctor_app_flutter/models/doctor_profile_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:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:http/http.dart'; +import 'package:http/http.dart' as http; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); Helpers helpers = new Helpers(); @@ -29,7 +28,6 @@ Helpers helpers = new Helpers(); body: null); * */ class BaseAppClient { - static Client client = HttpInterceptor().getClient(); static post( String endPoint, { @@ -59,7 +57,12 @@ class BaseAppClient { body['PatientOutSA'] = PATIENT_OUT_SA; if (await Helpers.checkConnection()) { - final response = await client.post(url, body: json.encode(body)); + final response = await http.post(url, + body: json.encode(body), + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }); final int statusCode = response.statusCode; if (statusCode < 200 || statusCode >= 400 || json == null) { onFailure('Error While Fetching data', statusCode); diff --git a/lib/interceptor/http_interceptor.dart b/lib/interceptor/http_interceptor.dart deleted file mode 100644 index 4d0f9c33..00000000 --- a/lib/interceptor/http_interceptor.dart +++ /dev/null @@ -1,65 +0,0 @@ -import 'dart:convert'; - -import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; -import 'package:doctor_app_flutter/providers/auth_provider.dart'; -import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; -import 'package:http/http.dart'; -import 'package:http_interceptor/http_interceptor.dart'; - -import '../providers/auth_provider.dart'; -import '../util/dr_app_shared_pref.dart'; - -DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); -List publicUrls = [ - LOGIN_URL, - SELECT_DEVICE_IMEI, - MEMBER_CHECK_ACTIVATION_CODE_NEW, - SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE -]; - -class HttpInterceptor extends InterceptorContract { - - Client getClient(){ - return HttpClientWithInterceptor.build(interceptors: [this]); -} - - Future interceptRequest({RequestData data}) async { - print('RequestData ${data.body}'); - print('RequestData ${data.url}'); - try { - data.headers["Content-Type"] = "application/json"; - data.headers["Accept"] = "application/json"; - // if (publicUrls.contains(data.url)) { - // var loggedUserInfo = await sharedPref.getObj('loggedUser'); - // var token = await sharedPref.getString(TOKEN); - // // print("token"+token); - // // print('loggedUserInfo${loggedUserInfo["LogInTokenID"]}'); - // // // the sevices handel the token in differat name so I ask to be change - // // // we must change the imple - // var body = json.decode(data.body); - // body['LogInTokenID']=token; - // data.body = json.encode(body); - - // // data.body['LogInTokenID'] = ''; - // } else { - // if (data.body['LogInTokenID']) { - // data.body['LogInTokenID'] = ''; - // } - // if (data.body['TokenID']) { - // data.body['TokenID'] = ''; - // } - // } - } catch (e) { - print(e); - } - - // print('data.body${data.body}'); - return data; - } - - @override - Future interceptResponse({ResponseData data}) async { - // print('ResponseData ${data.body}'); - return data; - } -} diff --git a/lib/providers/patients_provider.dart b/lib/providers/patients_provider.dart index e93c2ceb..e2e6c061 100644 --- a/lib/providers/patients_provider.dart +++ b/lib/providers/patients_provider.dart @@ -17,12 +17,9 @@ import 'package:doctor_app_flutter/models/patient/radiology_res_model.dart'; import 'package:doctor_app_flutter/models/patient/refer_to_doctor_request.dart'; import 'package:doctor_app_flutter/models/prescription_report.dart'; import 'package:flutter/cupertino.dart'; -import 'package:http/http.dart'; -import 'package:http_interceptor/http_client_with_interceptor.dart'; import '../client/app_client.dart'; import '../config/config.dart'; -import '../interceptor/http_interceptor.dart'; import '../models/patient/lab_orders_res_model.dart'; import '../models/patient/patiant_info_model.dart'; import '../models/patient/patient_model.dart'; @@ -67,52 +64,46 @@ class PatientsProvider with ChangeNotifier { ClinicByProjectIdRequest(); ReferToDoctorRequest _referToDoctorRequest = ReferToDoctorRequest(); - Client client = - HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]); + PatiantInformtion _selectedPatient; Future getPatientList(PatientModel patient, patientType) async { - /* const url = - BASE_URL+'DoctorApplication.svc/REST/GetMyInPatient';*/ - int val = int.parse(patientType); - //**********Modify url by amjad amireh for patiant type********* final url = BASE_URL + "DoctorApplication.svc/REST/" + SERVICES_PATIANT[val]; - // print("a===========$url=======a"); try { - final response = await client.post(url, - body: json.encode({ - "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(json.decode(response.body)); + await BaseAppClient.post(url, + onSuccess: (dynamic response, int statusCode) { + return Future.value(response); + }, onFailure: (String error, int statusCode) { + throw 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 + }); } catch (err) { - throw err; + handelCatchErrorCase(error); } } @@ -239,7 +230,7 @@ class PatientsProvider with ChangeNotifier { try { if (await Helpers.checkConnection()) { final response = - await AppClient.post(GET_PRESCRIPTION, body: json.encode(patient)); + await AppClient.post(GET_PRESCRIPTION, body: json.encode(patient)); final int statusCode = response.statusCode; isLoading = false; @@ -302,22 +293,20 @@ class PatientsProvider with ChangeNotifier { } } - getPrescriptionReport(prescriptionReqModel) async{ + getPrescriptionReport(prescriptionReqModel) async { prescriptionReport = []; isLoading = true; isError = false; error = ""; notifyListeners(); - await BaseAppClient.post( - 'Patients.svc/REST/GetPrescriptionReport', + await BaseAppClient.post('Patients.svc/REST/GetPrescriptionReport', onSuccess: (dynamic response, int statusCode) { - response['ListPRM'].forEach((v) { - prescriptionReport - .add(PrescriptionReport.fromJson(v)); - }); - isError = false; - isLoading = false; - }, onFailure: (String error, int statusCode) { + response['ListPRM'].forEach((v) { + prescriptionReport.add(PrescriptionReport.fromJson(v)); + }); + isError = false; + isLoading = false; + }, onFailure: (String error, int statusCode) { isError = true; isLoading = false; this.error = error; @@ -661,31 +650,27 @@ class PatientsProvider with ChangeNotifier { final int statusCode = response.statusCode; isLoading = false; - if (statusCode < 200 || statusCode >= 400 || json == null) { - isError = true; - error = 'Error While Fetching data'; + if (statusCode < 200 || statusCode >= 400 || json == null) { + isError = true; + error = 'Error While Fetching data'; + } else { + var res = json.decode(response.body); + print('$res'); + if (res['MessageStatus'] == 1) { + patientProgressNoteList = res['List_GetPregressNoteForInPatient']; } else { - var res = json.decode(response.body); - print('$res'); - if (res['MessageStatus'] == 1) { - patientProgressNoteList = res['List_GetPregressNoteForInPatient']; - } else { - isError = true; - error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; - } + isError = true; + error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; } - } else { - isLoading = false; - isError = true; - error = 'Please Check The Internet Connection'; } - notifyListeners(); - } catch (err) { - handelCatchErrorCase(err); + } else { + isLoading = false; + isError = true; + error = 'Please Check The Internet Connection'; } + notifyListeners(); + } catch (err) { + handelCatchErrorCase(err); } - - - - + } } From 334150894a46cd528a26c233ae07f819da6c8557 Mon Sep 17 00:00:00 2001 From: Mohammad ALjammal Date: Tue, 9 Jun 2020 17:31:07 +0300 Subject: [PATCH 3/7] Change http call to BaseAppClient --- lib/client/base_app_client.dart | 5 +- lib/providers/hospital_provider.dart | 7 - lib/providers/medicine_provider.dart | 75 ++----- lib/providers/patients_provider.dart | 305 ++++++++------------------- 4 files changed, 109 insertions(+), 283 deletions(-) diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index 39b3c683..124e361e 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -20,6 +20,7 @@ Helpers helpers = new Helpers(); *@return: *@desc: */ + ///Example /* await BaseAppClient.post('', @@ -28,7 +29,6 @@ Helpers helpers = new Helpers(); body: null); * */ class BaseAppClient { - static post( String endPoint, { Map body, @@ -44,7 +44,8 @@ class BaseAppClient { body['DoctorID'] = doctorProfile?.doctorID; body['EditedBy'] = doctorProfile?.doctorID; body['ProjectID'] = doctorProfile?.projectID; - body['ClinicID'] = doctorProfile?.clinicID; + if (!body.containsKey('ClinicID')) + body['ClinicID'] = doctorProfile?.clinicID; } body['TokenID'] = token ?? ''; body['LanguageID'] = LANGUAGE_ID; diff --git a/lib/providers/hospital_provider.dart b/lib/providers/hospital_provider.dart index 834b3889..8c22ae0b 100644 --- a/lib/providers/hospital_provider.dart +++ b/lib/providers/hospital_provider.dart @@ -18,13 +18,6 @@ class HospitalProvider with ChangeNotifier { "SessionID": "i1UJwCTSqt", "IsLoginForDoctorApp": true }; - // try { - // final response = await AppClient.post(url, body: json.encode(info)); - // return Future.value(json.decode(response.body)); - // } catch (error) { - // throw error; - // // print('error'); - // } await BaseAppClient.post(url, onSuccess: ( response, statusCode) { diff --git a/lib/providers/medicine_provider.dart b/lib/providers/medicine_provider.dart index a0d8f4ed..0f8734f4 100644 --- a/lib/providers/medicine_provider.dart +++ b/lib/providers/medicine_provider.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:doctor_app_flutter/client/app_client.dart'; +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/models/pharmacies_List_request_model.dart'; @@ -11,47 +12,32 @@ import 'package:flutter/cupertino.dart'; class MedicineProvider with ChangeNotifier { DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); - + var pharmacyItemsList = []; var pharmaciesList = []; bool isFinished = true; bool hasError = false; String errorMsg = ''; - PharmaciesItemsRequestModel _itemsRequestModel =PharmaciesItemsRequestModel(); + PharmaciesItemsRequestModel _itemsRequestModel = + PharmaciesItemsRequestModel(); PharmaciesListRequestModel _listRequestModel = PharmaciesListRequestModel(); Future getMedicineItem(String itemName) async { resetDefaultValues(); try { - if (await Helpers.checkConnection()) { - _itemsRequestModel.pHRItemName = itemName; - - final response = await AppClient.post(PHARMACY_ITEMS_URL, - body: json.encode(_itemsRequestModel.toJson())); - final int statusCode = response.statusCode; + _itemsRequestModel.pHRItemName = itemName; + await BaseAppClient.post(PHARMACY_ITEMS_URL, + onSuccess: (dynamic response, int statusCode) { + pharmacyItemsList = response['ListPharmcy_Region']; + hasError = false; isFinished = true; - if (statusCode < 200 || statusCode >= 400 || json == null) { - isFinished = true; - hasError = true; - errorMsg = 'Error While Fetching data'; - } else { - var parsed = json.decode(response.body.toString()); - if (parsed['MessageStatus'] == 1) { - pharmacyItemsList = parsed['ListPharmcy_Region']; - hasError = false; - isFinished = true; - errorMsg = "Done"; - } else { - hasError = true; - errorMsg = parsed['ErrorMessage'] ?? parsed['ErrorEndUserMessage']; - } - } - } else { + errorMsg = "Done"; + }, onFailure: (String error, int statusCode) { isFinished = true; hasError = true; - errorMsg = 'Please Check The Internet Connection'; - } + errorMsg = error; + }, body: _itemsRequestModel.toJson()); notifyListeners(); } catch (error) { throw error; @@ -61,37 +47,20 @@ class MedicineProvider with ChangeNotifier { } Future getPharmaciesList(int itemId) async { - String token = await sharedPref.getString(TOKEN); resetDefaultValues(); try { - if (await Helpers.checkConnection()) { - _listRequestModel.itemID = itemId; - _listRequestModel.tokenID = token; - final response = await AppClient.post(PHARMACY_LIST_URL, - body: json.encode(_listRequestModel.toJson())); - final int statusCode = response.statusCode; + _listRequestModel.itemID = itemId; + await BaseAppClient.post(PHARMACY_LIST_URL, + onSuccess: (dynamic response, int statusCode) { + pharmaciesList = response['PharmList']; + hasError = false; isFinished = true; - if (statusCode < 200 || statusCode >= 400 || json == null) { - isFinished = true; - hasError = true; - errorMsg = 'Error While Fetching data'; - } else { - var parsed = json.decode(response.body.toString()); - if (parsed['MessageStatus'] == 1) { - pharmaciesList = parsed['PharmList']; - hasError = false; - isFinished = true; - errorMsg = "Done"; - } else { - hasError = true; - errorMsg = parsed['ErrorMessage'] ?? parsed['ErrorEndUserMessage']; - } - } - } else { + errorMsg = "Done"; + }, onFailure: (String error, int statusCode) { isFinished = true; hasError = true; - errorMsg = 'Please Check The Internet Connection'; - } + errorMsg = error; + }, body: _listRequestModel.toJson()); notifyListeners(); } catch (error) { throw error; diff --git a/lib/providers/patients_provider.dart b/lib/providers/patients_provider.dart index e2e6c061..ca88a5b7 100644 --- a/lib/providers/patients_provider.dart +++ b/lib/providers/patients_provider.dart @@ -71,11 +71,8 @@ class PatientsProvider with ChangeNotifier { Future getPatientList(PatientModel patient, patientType) async { int val = int.parse(patientType); - final url = - BASE_URL + "DoctorApplication.svc/REST/" + SERVICES_PATIANT[val]; - try { - await BaseAppClient.post(url, + await BaseAppClient.post( SERVICES_PATIANT[val], onSuccess: (dynamic response, int statusCode) { return Future.value(response); }, onFailure: (String error, int statusCode) { @@ -125,21 +122,10 @@ class PatientsProvider with ChangeNotifier { setBasicData(); try { - if (await Helpers.checkConnection()) { - final response = await AppClient.post(GET_PATIENT_VITAL_SIGN, - body: json.encode(patient)); - final int statusCode = response.statusCode; - isLoading = false; - - if (statusCode < 200 || statusCode >= 400 || json == null) { - isError = true; - error = 'Error While Fetching data'; - } else { - var res = json.decode(response.body); - print('$res'); - if (res['MessageStatus'] == 1) { + await BaseAppClient.post(GET_PATIENT_VITAL_SIGN, + onSuccess: (dynamic response, int statusCode) { patientVitalSignList = []; - res['List_DoctorPatientVitalSign'].forEach((v) { + response['List_DoctorPatientVitalSign'].forEach((v) { patientVitalSignList.add(new VitalSignResModel.fromJson(v)); }); @@ -157,16 +143,13 @@ class PatientsProvider with ChangeNotifier { .add(patientVitalSignOrderdSubListTemp[x]); } } - } else { + }, + onFailure: (String error, int statusCode) { + isLoading = false; isError = true; - error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; - } - } - } else { - isLoading = false; - isError = true; - error = 'Please Check The Internet Connection'; - } + this.error = error; + }, + body: patient); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -185,33 +168,19 @@ class PatientsProvider with ChangeNotifier { setBasicData(); try { - if (await Helpers.checkConnection()) { - final response = await AppClient.post(GET_PATIENT_LAB_OREDERS, - body: json.encode(patient)); - final int statusCode = response.statusCode; - isLoading = false; - - if (statusCode < 200 || statusCode >= 400 || json == null) { - isError = true; - error = 'Error While Fetching data'; - } else { - var res = json.decode(response.body); - print('$res'); - if (res['MessageStatus'] == 1) { + await BaseAppClient.post(GET_PATIENT_LAB_OREDERS, + onSuccess: (dynamic response, int statusCode) { patientLabResultOrdersList = []; - res['List_GetLabOreders'].forEach((v) { + response['List_GetLabOreders'].forEach((v) { patientLabResultOrdersList.add(new LabOrdersResModel.fromJson(v)); }); - } else { + }, + onFailure: (String error, int statusCode) { + isLoading = false; isError = true; - error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; - } - } - } else { - isLoading = false; - isError = true; - error = 'Please Check The Internet Connection'; - } + this.error = error; + }, + body: patient); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -226,36 +195,21 @@ class PatientsProvider with ChangeNotifier { */ getOutPatientPrescriptions(patient) async { setBasicData(); - try { - if (await Helpers.checkConnection()) { - final response = - await AppClient.post(GET_PRESCRIPTION, body: json.encode(patient)); - final int statusCode = response.statusCode; - isLoading = false; - - if (statusCode < 200 || statusCode >= 400 || json == null) { - isError = true; - error = 'Error While Fetching data'; - } else { - var res = json.decode(response.body); - print('$res'); - if (res['MessageStatus'] == 1) { + await BaseAppClient.post(GET_PRESCRIPTION, + onSuccess: (dynamic response, int statusCode) { patientPrescriptionsList = []; - res['PatientPrescriptionList'].forEach((v) { + response['PatientPrescriptionList'].forEach((v) { patientPrescriptionsList .add(new PrescriptionResModel.fromJson(v)); }); - } else { + }, + onFailure: (String error, int statusCode) { + isLoading = false; isError = true; - error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; - } - } - } else { - isLoading = false; - isError = true; - error = 'Please Check The Internet Connection'; - } + this.error = error; + }, + body: patient); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -339,33 +293,20 @@ class PatientsProvider with ChangeNotifier { // notifyListeners(); setBasicData(); try { - if (await Helpers.checkConnection()) { - final response = - await AppClient.post(GET_RADIOLOGY, body: json.encode(patient)); - final int statusCode = response.statusCode; - isLoading = false; - if (statusCode < 200 || statusCode >= 400 || json == null) { - isError = true; - error = 'Error While Fetching data'; - } else { - var res = json.decode(response.body); - print('$res'); - if (res['MessageStatus'] == 1) { + await BaseAppClient.post(GET_RADIOLOGY, + onSuccess: (dynamic response, int statusCode) { patientRadiologyList = []; - res['List_GetRadOreders'].forEach((v) { + response['List_GetRadOreders'].forEach((v) { patientRadiologyList.add(new RadiologyResModel.fromJson(v)); }); - } else { + }, + onFailure: (String error, int statusCode) { + isLoading = false; isError = true; - error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; - } - } - } else { - isLoading = false; - isError = true; - error = 'Please Check The Internet Connection'; - } + this.error = error; + }, + body: patient); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -399,31 +340,16 @@ class PatientsProvider with ChangeNotifier { getPatientInsuranceApprovals(patient) async { setBasicData(); try { - if (await Helpers.checkConnection()) { - final response = await AppClient.post(PATIENT_INSURANCE_APPROVALS_URL, - body: json.encode(patient)); - final int statusCode = response.statusCode; - isLoading = false; - - if (statusCode < 200 || statusCode >= 400 || json == null) { - isError = true; - error = 'Error While Fetching data'; - } else { - var res = json.decode(response.body); - print('$res'); - if (res['MessageStatus'] == 1) { - //patientRadiologyList = []; - insuranceApporvalsList = res['List_ApprovalMain_InPatient']; - } else { + await BaseAppClient.post(PATIENT_INSURANCE_APPROVALS_URL, + onSuccess: (dynamic response, int statusCode) { + insuranceApporvalsList = response['List_ApprovalMain_InPatient']; + }, + onFailure: (String error, int statusCode) { + isLoading = false; isError = true; - error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; - } - } - } else { - isLoading = false; - isError = true; - error = 'Please Check The Internet Connection'; - } + this.error = error; + }, + body: patient); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -437,30 +363,17 @@ class PatientsProvider with ChangeNotifier { getPatientProgressNote(patient) async { setBasicData(); try { - if (await Helpers.checkConnection()) { - final response = await AppClient.post(PATIENT_PROGRESS_NOTE_URL, - body: json.encode(patient)); - final int statusCode = response.statusCode; - isLoading = false; - if (statusCode < 200 || statusCode >= 400 || json == null) { - isError = true; - error = 'Error While Fetching data'; - } else { - var res = json.decode(response.body); - print('$res'); - if (res['MessageStatus'] == 1) { - patientProgressNoteList = res['List_GetPregressNoteForInPatient']; - } else { + await BaseAppClient.post(PATIENT_PROGRESS_NOTE_URL, + onSuccess: (dynamic response, int statusCode) { + patientProgressNoteList = response['List_GetPregressNoteForInPatient']; + }, + onFailure: (String error, int statusCode) { + isLoading = false; isError = true; - error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; - } - } - } else { - isLoading = false; - isError = true; - error = 'Please Check The Internet Connection'; - } + this.error = error; + }, + body: patient); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -472,38 +385,19 @@ class PatientsProvider with ChangeNotifier { *@desc: getDoctorsList */ getDoctorsList(String clinicId) async { - String token = await sharedPref.getString(TOKEN); - int projectID = await sharedPref.getInt(PROJECT_ID); setBasicData(); try { - if (await Helpers.checkConnection()) { - _doctorsByClinicIdRequest.projectID = projectID; - _doctorsByClinicIdRequest.clinicID = clinicId; - _doctorsByClinicIdRequest.tokenID = token; - - final response = await AppClient.post(PATIENT_GET_DOCTOR_BY_CLINIC_URL, - body: json.encode(_doctorsByClinicIdRequest)); - final int statusCode = response.statusCode; - isLoading = false; - - if (statusCode < 200 || statusCode >= 400 || json == null) { - isError = true; - error = 'Error While Fetching data'; - } else { - var res = json.decode(response.body); - print('$res'); - if (res['MessageStatus'] == 1) { - doctorsList = res['List_Doctors_All']; - } else { + _doctorsByClinicIdRequest.clinicID = clinicId; + await BaseAppClient.post(PATIENT_GET_DOCTOR_BY_CLINIC_URL, + onSuccess: (dynamic response, int statusCode) { + doctorsList = response['List_Doctors_All']; + }, + onFailure: (String error, int statusCode) { + isLoading = false; isError = true; - error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; - } - } - } else { - isLoading = false; - isError = true; - error = 'Please Check The Internet Connection'; - } + this.error = error; + }, + body: _doctorsByClinicIdRequest.toJson()); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -521,37 +415,19 @@ class PatientsProvider with ChangeNotifier { *@desc: getClinicsList */ getClinicsList() async { - String token = await sharedPref.getString(TOKEN); setBasicData(); try { - if (await Helpers.checkConnection()) { - int projectID = await sharedPref.getInt(PROJECT_ID); - _clinicByProjectIdRequest.projectID = projectID; - _clinicByProjectIdRequest.tokenID = token; - final response = await AppClient.post(PATIENT_GET_CLINIC_BY_PROJECT_URL, - body: json.encode(_clinicByProjectIdRequest)); - final int statusCode = response.statusCode; - isLoading = false; - - if (statusCode < 200 || statusCode >= 400 || json == null) { - isError = true; - error = 'Error While Fetching data'; - } else { - var res = json.decode(response.body); - print('$res'); - if (res['MessageStatus'] == 1) { - clinicsList = res['List_Clinic_All']; - } else { + await BaseAppClient.post(PATIENT_GET_CLINIC_BY_PROJECT_URL, + onSuccess: (dynamic response, int statusCode) { + clinicsList = response['List_Clinic_All']; + }, + onFailure: (String error, int statusCode) { + isLoading = false; isError = true; - error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; - } - } - } else { - isLoading = false; - isError = true; - error = 'Please Check The Internet Connection'; - } + this.error = error; + }, + body: _clinicByProjectIdRequest.toJson()); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -573,30 +449,17 @@ class PatientsProvider with ChangeNotifier { String token = await sharedPref.getString(TOKEN); setBasicData(); try { - if (await Helpers.checkConnection()) { - _referralFrequencyRequest.tokenID = token; - final response = await AppClient.post(PATIENT_GET_LIST_REFERAL_URL, - body: json.encode(_referralFrequencyRequest)); - final int statusCode = response.statusCode; - isLoading = false; - if (statusCode < 200 || statusCode >= 400 || json == null) { - isError = true; - error = 'Error While Fetching data'; - } else { - var res = json.decode(response.body); - print('$res'); - if (res['MessageStatus'] == 1) { - referalFrequancyList = res['list_STPReferralFrequency']; - } else { + + await BaseAppClient.post(PATIENT_GET_LIST_REFERAL_URL, + onSuccess: (dynamic response, int statusCode) { + referalFrequancyList = response['list_STPReferralFrequency']; + }, + onFailure: (String error, int statusCode) { + isLoading = false; isError = true; - error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; - } - } - } else { - isLoading = false; - isError = true; - error = 'Please Check The Internet Connection'; - } + this.error = error; + }, + body: _referralFrequencyRequest.toJson()); notifyListeners(); } catch (err) { handelCatchErrorCase(err); From eb09cda2a187573e9d473c33ccf2b9b23f7249a3 Mon Sep 17 00:00:00 2001 From: Mohammad ALjammal Date: Wed, 10 Jun 2020 11:04:53 +0300 Subject: [PATCH 4/7] fix issues in patients provider --- lib/client/base_app_client.dart | 2 +- lib/config/config.dart | 4 +-- lib/providers/patients_provider.dart | 45 +++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index 124e361e..031c70ac 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -57,7 +57,7 @@ class BaseAppClient { body['IsLoginForDoctorApp'] = IS_LOGIN_FOR_DOCTOR_APP; body['PatientOutSA'] = PATIENT_OUT_SA; - if (await Helpers.checkConnection()) { + if (await Helpers.checkConnection()) { final response = await http.post(url, body: json.encode(body), headers: { diff --git a/lib/config/config.dart b/lib/config/config.dart index 6e75ccf2..e80acab5 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -2,8 +2,8 @@ const MAX_SMALL_SCREEN = 660; const ONLY_NUMBERS = "[0-9]"; const ONLY_LETTERS = "[a-zA-Z]"; const ONLY_DATE = "[0-9/]"; -// const BASE_URL = 'https://hmgwebservices.com/Services/'; -const BASE_URL = 'https://uat.hmgwebservices.com/Services/'; + const BASE_URL = 'https://hmgwebservices.com/Services/'; +//const BASE_URL = 'https://uat.hmgwebservices.com/Services/'; const PHARMACY_ITEMS_URL = "Lists.svc/REST/GetPharmcyItems_Region"; const PHARMACY_LIST_URL = "Patients.svc/REST/GetPharmcyList"; const PATIENT_PROGRESS_NOTE_URL = "DoctorApplication.svc/REST/GetProgressNoteForInPatient"; diff --git a/lib/providers/patients_provider.dart b/lib/providers/patients_provider.dart index ca88a5b7..0770ad47 100644 --- a/lib/providers/patients_provider.dart +++ b/lib/providers/patients_provider.dart @@ -68,14 +68,15 @@ class PatientsProvider with ChangeNotifier { PatiantInformtion _selectedPatient; - Future getPatientList(PatientModel patient, patientType) async { + getPatientList(PatientModel patient, patientType) async { int val = int.parse(patientType); try { - await BaseAppClient.post( SERVICES_PATIANT[val], - onSuccess: (dynamic response, int statusCode) { - return Future.value(response); - }, onFailure: (String error, int statusCode) { + var localResponse ; + await BaseAppClient.post( 'DoctorApplication.svc/REST/'+SERVICES_PATIANT[val], + onSuccess: (dynamic response, int statusCode) async{ + localResponse = response; + }, onFailure: (String error, int statusCode) async{ throw error; }, body: { "ProjectID": patient.ProjectID, @@ -99,9 +100,12 @@ class PatientsProvider with ChangeNotifier { "IsLoginForDoctorApp": patient.IsLoginForDoctorApp, "PatientOutSA": patient.PatientOutSA }); + + return localResponse; } catch (err) { handelCatchErrorCase(error); } + } setBasicData() { @@ -138,11 +142,15 @@ class PatientsProvider with ChangeNotifier { a.vitalSignDate.microsecondsSinceEpoch; }); patientVitalSignOrderdSubList.clear(); - for (int x = 0; x < 20; x++) { + int length = patientVitalSignOrderdSubListTemp.length >= 20 ? 20 : patientVitalSignOrderdSubListTemp.length; + for (int x = 0; x < length; x++) { patientVitalSignOrderdSubList .add(patientVitalSignOrderdSubListTemp[x]); } } + isLoading = false; + isError = false; + this.error = ''; }, onFailure: (String error, int statusCode) { isLoading = false; @@ -174,6 +182,9 @@ class PatientsProvider with ChangeNotifier { response['List_GetLabOreders'].forEach((v) { patientLabResultOrdersList.add(new LabOrdersResModel.fromJson(v)); }); + isLoading = false; + isError = false; + this.error = ''; }, onFailure: (String error, int statusCode) { isLoading = false; @@ -203,6 +214,9 @@ class PatientsProvider with ChangeNotifier { patientPrescriptionsList .add(new PrescriptionResModel.fromJson(v)); }); + isLoading = false; + isError = false; + this.error = ''; }, onFailure: (String error, int statusCode) { isLoading = false; @@ -300,6 +314,9 @@ class PatientsProvider with ChangeNotifier { response['List_GetRadOreders'].forEach((v) { patientRadiologyList.add(new RadiologyResModel.fromJson(v)); }); + isLoading = false; + isError = false; + this.error = ''; }, onFailure: (String error, int statusCode) { isLoading = false; @@ -343,6 +360,9 @@ class PatientsProvider with ChangeNotifier { await BaseAppClient.post(PATIENT_INSURANCE_APPROVALS_URL, onSuccess: (dynamic response, int statusCode) { insuranceApporvalsList = response['List_ApprovalMain_InPatient']; + isLoading = false; + isError = false; + this.error = ''; }, onFailure: (String error, int statusCode) { isLoading = false; @@ -367,6 +387,9 @@ class PatientsProvider with ChangeNotifier { await BaseAppClient.post(PATIENT_PROGRESS_NOTE_URL, onSuccess: (dynamic response, int statusCode) { patientProgressNoteList = response['List_GetPregressNoteForInPatient']; + isLoading = false; + isError = false; + this.error = ''; }, onFailure: (String error, int statusCode) { isLoading = false; @@ -391,6 +414,9 @@ class PatientsProvider with ChangeNotifier { 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; @@ -421,6 +447,9 @@ class PatientsProvider with ChangeNotifier { 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; @@ -446,13 +475,15 @@ class PatientsProvider with ChangeNotifier { *@desc: getReferralFrequancyList */ getReferralFrequancyList() async { - String token = await sharedPref.getString(TOKEN); 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; From e6b99adc806807233f3ecf59564d245a38ce885a Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Wed, 10 Jun 2020 11:20:47 +0300 Subject: [PATCH 5/7] change calling serivce to base app client --- lib/providers/auth_provider.dart | 120 +++++++++++++-------- lib/providers/hospital_provider.dart | 18 +--- lib/widgets/auth/verfiy_account.dart | 4 +- lib/widgets/auth/verification_methods.dart | 2 +- 4 files changed, 81 insertions(+), 63 deletions(-) diff --git a/lib/providers/auth_provider.dart b/lib/providers/auth_provider.dart index af93c837..f362442d 100644 --- a/lib/providers/auth_provider.dart +++ b/lib/providers/auth_provider.dart @@ -1,86 +1,108 @@ -import 'dart:convert'; -import 'package:doctor_app_flutter/client/app_client.dart'; +import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:flutter/cupertino.dart'; + import '../models/user_model.dart'; -const LOGIN_URL = - 'Sentry.svc/REST/MemberLogIN_New'; -const INSERT_DEVICE_IMEI = - 'Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI'; +const LOGIN_URL = 'Sentry.svc/REST/MemberLogIN_New'; +const INSERT_DEVICE_IMEI = 'Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI'; const SELECT_DEVICE_IMEI = 'Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI'; const SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE = 'Sentry.svc/REST/DoctorApplication_SendActivationCodebyOTPNotificationType'; -const MEMBER_CHECK_ACTIVATION_CODE_NEW ='Sentry.svc/REST/MemberCheckActivationCode_New'; +const MEMBER_CHECK_ACTIVATION_CODE_NEW = + 'Sentry.svc/REST/MemberCheckActivationCode_New'; const GET_DOC_PROFILES = 'Doctors.svc/REST/GetDocProfiles'; -class AuthProvider with ChangeNotifier { - Future login(UserModel userInfo) async { - const url = LOGIN_URL; +class AuthProvider with ChangeNotifier { + Future login(UserModel userInfo) async { try { - final response = await AppClient.post(url, - body: json.encode({ - "UserID": userInfo.UserID, - "Password": userInfo.Password, - "ProjectID": userInfo.ProjectID, - "LanguageID": userInfo.LanguageID, - "IPAdress": userInfo.IPAdress, - "VersionID": userInfo.VersionID, - "Channel": userInfo.Channel, - "SessionID": userInfo.SessionID - })); - return Future.value(json.decode(response.body)); + dynamic localRes; + + await BaseAppClient.post(LOGIN_URL, + onSuccess: (dynamic response, int statusCode) { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }, body: { + "UserID": userInfo.UserID, + "Password": userInfo.Password, + "ProjectID": userInfo.ProjectID, + "LanguageID": userInfo.LanguageID, + "IPAdress": userInfo.IPAdress, + "VersionID": userInfo.VersionID, + "Channel": userInfo.Channel, + "SessionID": userInfo.SessionID + }); + + return Future.value(localRes); } catch (error) { print(error); throw error; } } - Future insertDeviceImei(imei) async { - const url = INSERT_DEVICE_IMEI; - + Future insertDeviceImei(imei) async { try { - final response = await AppClient.post(url, body: json.encode(imei)); - return Future.value(json.decode(response.body)); + dynamic localRes; + + await BaseAppClient.post(INSERT_DEVICE_IMEI, + onSuccess: (dynamic response, int statusCode) { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }, body: imei); + return Future.value(localRes); } catch (error) { print(error); throw error; } } - Future selectDeviceImei(imei) async { - const url = SELECT_DEVICE_IMEI; - + Future selectDeviceImei(imei) async { try { - final response = await AppClient.post(url, body: json.encode(imei)); - return Future.value(json.decode(response.body)); + dynamic localRes; + await BaseAppClient.post(SELECT_DEVICE_IMEI, + onSuccess: (dynamic response, int statusCode) { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }, body: imei); + return Future.value(localRes); } catch (error) { print(error); throw error; } } - Future sendActivationCodeByOtpNotificationType( + Future sendActivationCodeByOtpNotificationType( activationCodeModel) async { - const url = SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE; - try { - final response = await AppClient.post(url, body: json.encode(activationCodeModel)); - return Future.value(json.decode(response.body)); + var localRes; + await BaseAppClient.post(SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE, + onSuccess: (dynamic response, int statusCode) { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }, body: activationCodeModel); + return Future.value(localRes); } catch (error) { print(error); throw error; } } - Future memberCheckActivationCodeNew(activationCodeModel) async { - const url = MEMBER_CHECK_ACTIVATION_CODE_NEW; - + Future memberCheckActivationCodeNew(activationCodeModel) async { try { - final response = await AppClient.post(url, body: json.encode(activationCodeModel)); - return Future.value(json.decode(response.body)); + dynamic localRes; + await BaseAppClient.post(MEMBER_CHECK_ACTIVATION_CODE_NEW, + onSuccess: (dynamic response, int statusCode) { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }, body: activationCodeModel); + return Future.value(localRes); } catch (error) { print(error); throw error; @@ -94,12 +116,16 @@ class AuthProvider with ChangeNotifier { *@return:Future *@desc: getDocProfiles */ - Future getDocProfiles(docInfo) async { - const url = GET_DOC_PROFILES; - + Future getDocProfiles(docInfo) async { try { - final response = await AppClient.post(url, body: json.encode(docInfo)); - return Future.value(json.decode(response.body)); + dynamic localRes; + await BaseAppClient.post(GET_DOC_PROFILES, + onSuccess: (dynamic response, int statusCode) { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }, body: docInfo); + return Future.value(localRes); } catch (error) { print(error); throw error; diff --git a/lib/providers/hospital_provider.dart b/lib/providers/hospital_provider.dart index 834b3889..262d258e 100644 --- a/lib/providers/hospital_provider.dart +++ b/lib/providers/hospital_provider.dart @@ -1,6 +1,3 @@ -import 'dart:convert'; - -import 'package:doctor_app_flutter/client/app_client.dart'; import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/config/config.dart'; import 'package:flutter/cupertino.dart'; @@ -18,21 +15,16 @@ class HospitalProvider with ChangeNotifier { "SessionID": "i1UJwCTSqt", "IsLoginForDoctorApp": true }; - // try { - // final response = await AppClient.post(url, body: json.encode(info)); - // return Future.value(json.decode(response.body)); - // } catch (error) { - // throw error; - // // print('error'); - // } - + dynamic localRes ; await BaseAppClient.post(url, - onSuccess: ( response, statusCode) { - return Future.value(response); + onSuccess: ( response, statusCode) async { + localRes= response; }, onFailure: (String error, int statusCode) { throw error; }, body: info); + return Future.value(localRes); + } } diff --git a/lib/widgets/auth/verfiy_account.dart b/lib/widgets/auth/verfiy_account.dart index feae82ce..c72b0c10 100644 --- a/lib/widgets/auth/verfiy_account.dart +++ b/lib/widgets/auth/verfiy_account.dart @@ -322,7 +322,7 @@ class _VerifyAccountState extends State { verifyAccountFormValue['digit4']; print(activationCode); int projectID = await sharedPref.getInt(PROJECT_ID); - Map model = { + Map model = { "activationCode": activationCode, "DoctorID": _loggedUser['DoctorID'], "LogInTokenID": _loggedUser['LogInTokenID'], @@ -421,7 +421,7 @@ class _VerifyAccountState extends State { projectID: clinicInfo.projectID, tokenID: '', languageID: 2); - authProv.getDocProfiles(docInfo).then((res) { + authProv.getDocProfiles(docInfo.toJson()).then((res) { if (res['MessageStatus'] == 1) { print("DoctorProfileList ${res['DoctorProfileList'][0]}"); loginProcessCompleted(res['DoctorProfileList'][0], changeLoadingStata); diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index 3a7fa482..af72b092 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -255,7 +255,7 @@ class _VerificationMethodsState extends State { if (oTPSendType == 1 || oTPSendType == 2) { widget.changeLoadingStata(true); - Map model = { + Map model = { "LogInTokenID": _loggedUser['LogInTokenID'], "Channel": 9, "MobileNumber": _loggedUser['MobileNumber'], From 3e05a58dd7ce7dc18b45d0d5a98050f5fc1d0bd1 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Wed, 10 Jun 2020 11:38:09 +0300 Subject: [PATCH 6/7] delete app client --- lib/client/app_client.dart | 18 -- lib/config/config.dart | 4 +- lib/providers/medicine_provider.dart | 8 +- lib/providers/patients_provider.dart | 321 ++++++++++++--------------- 4 files changed, 145 insertions(+), 206 deletions(-) delete mode 100644 lib/client/app_client.dart diff --git a/lib/client/app_client.dart b/lib/client/app_client.dart deleted file mode 100644 index 215b2714..00000000 --- a/lib/client/app_client.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:doctor_app_flutter/config/config.dart'; -import 'package:http/http.dart' as http; - -// OWNER : Ibrahim albitar -// DATE : 22-04-2020 -// DESCRIPTION : Custom App client to pin base url for all srvices - -class AppClient { - - static Future post(dynamic path, {dynamic body}) async { - String _fullUrl = BASE_URL + path; - final response = await http.post(_fullUrl, body: body, headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json' - }); - return response; - } -} \ No newline at end of file diff --git a/lib/config/config.dart b/lib/config/config.dart index e80acab5..f6849172 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -2,8 +2,8 @@ const MAX_SMALL_SCREEN = 660; const ONLY_NUMBERS = "[0-9]"; const ONLY_LETTERS = "[a-zA-Z]"; const ONLY_DATE = "[0-9/]"; - const BASE_URL = 'https://hmgwebservices.com/Services/'; -//const BASE_URL = 'https://uat.hmgwebservices.com/Services/'; + // const BASE_URL = 'https://hmgwebservices.com/Services/'; +const BASE_URL = 'https://uat.hmgwebservices.com/Services/'; const PHARMACY_ITEMS_URL = "Lists.svc/REST/GetPharmcyItems_Region"; const PHARMACY_LIST_URL = "Patients.svc/REST/GetPharmcyList"; const PATIENT_PROGRESS_NOTE_URL = "DoctorApplication.svc/REST/GetProgressNoteForInPatient"; diff --git a/lib/providers/medicine_provider.dart b/lib/providers/medicine_provider.dart index 0f8734f4..1f432531 100644 --- a/lib/providers/medicine_provider.dart +++ b/lib/providers/medicine_provider.dart @@ -1,15 +1,11 @@ -import 'dart:convert'; - -import 'package:doctor_app_flutter/client/app_client.dart'; 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/models/pharmacies_List_request_model.dart'; import 'package:doctor_app_flutter/models/pharmacies_items_request_model.dart'; -import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; -import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:flutter/cupertino.dart'; +import '.../../../util/dr_app_shared_pref.dart'; + class MedicineProvider with ChangeNotifier { DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); diff --git a/lib/providers/patients_provider.dart b/lib/providers/patients_provider.dart index 0770ad47..2984398e 100644 --- a/lib/providers/patients_provider.dart +++ b/lib/providers/patients_provider.dart @@ -1,6 +1,3 @@ -import 'dart:convert'; - -import 'package:doctor_app_flutter/client/app_client.dart'; import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/models/doctor_profile_model.dart'; @@ -18,7 +15,6 @@ import 'package:doctor_app_flutter/models/patient/refer_to_doctor_request.dart'; import 'package:doctor_app_flutter/models/prescription_report.dart'; import 'package:flutter/cupertino.dart'; -import '../client/app_client.dart'; import '../config/config.dart'; import '../models/patient/lab_orders_res_model.dart'; import '../models/patient/patiant_info_model.dart'; @@ -64,19 +60,18 @@ class PatientsProvider with ChangeNotifier { ClinicByProjectIdRequest(); ReferToDoctorRequest _referToDoctorRequest = ReferToDoctorRequest(); - - PatiantInformtion _selectedPatient; getPatientList(PatientModel patient, patientType) async { int val = int.parse(patientType); try { - var localResponse ; - await BaseAppClient.post( 'DoctorApplication.svc/REST/'+SERVICES_PATIANT[val], - onSuccess: (dynamic response, int statusCode) async{ - localResponse = response; - }, onFailure: (String error, int statusCode) async{ + var localResponse; + await BaseAppClient.post( + 'DoctorApplication.svc/REST/' + SERVICES_PATIANT[val], + onSuccess: (dynamic response, int statusCode) async { + localResponse = response; + }, onFailure: (String error, int statusCode) async { throw error; }, body: { "ProjectID": patient.ProjectID, @@ -105,7 +100,6 @@ class PatientsProvider with ChangeNotifier { } catch (err) { handelCatchErrorCase(error); } - } setBasicData() { @@ -128,36 +122,36 @@ class PatientsProvider with ChangeNotifier { try { await BaseAppClient.post(GET_PATIENT_VITAL_SIGN, onSuccess: (dynamic response, int statusCode) { - patientVitalSignList = []; - response['List_DoctorPatientVitalSign'].forEach((v) { - patientVitalSignList.add(new VitalSignResModel.fromJson(v)); - }); - - if (patientVitalSignList.length > 0) { - List patientVitalSignOrderdSubListTemp = []; - patientVitalSignOrderdSubListTemp = patientVitalSignList; - patientVitalSignOrderdSubListTemp - .sort((VitalSignResModel a, VitalSignResModel b) { - return b.vitalSignDate.microsecondsSinceEpoch - - a.vitalSignDate.microsecondsSinceEpoch; - }); - patientVitalSignOrderdSubList.clear(); - int length = patientVitalSignOrderdSubListTemp.length >= 20 ? 20 : patientVitalSignOrderdSubListTemp.length; - for (int x = 0; x < length; x++) { - patientVitalSignOrderdSubList - .add(patientVitalSignOrderdSubListTemp[x]); - } - } - isLoading = false; - isError = false; - this.error = ''; - }, - onFailure: (String error, int statusCode) { - isLoading = false; - isError = true; - this.error = error; - }, - body: patient); + patientVitalSignList = []; + response['List_DoctorPatientVitalSign'].forEach((v) { + patientVitalSignList.add(new VitalSignResModel.fromJson(v)); + }); + + if (patientVitalSignList.length > 0) { + List patientVitalSignOrderdSubListTemp = []; + patientVitalSignOrderdSubListTemp = patientVitalSignList; + patientVitalSignOrderdSubListTemp + .sort((VitalSignResModel a, VitalSignResModel b) { + return b.vitalSignDate.microsecondsSinceEpoch - + a.vitalSignDate.microsecondsSinceEpoch; + }); + patientVitalSignOrderdSubList.clear(); + int length = patientVitalSignOrderdSubListTemp.length >= 20 + ? 20 + : patientVitalSignOrderdSubListTemp.length; + for (int x = 0; x < length; x++) { + patientVitalSignOrderdSubList + .add(patientVitalSignOrderdSubListTemp[x]); + } + } + isLoading = false; + isError = false; + this.error = ''; + }, onFailure: (String error, int statusCode) { + isLoading = false; + isError = true; + this.error = error; + }, body: patient); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -178,20 +172,18 @@ class PatientsProvider with ChangeNotifier { try { await BaseAppClient.post(GET_PATIENT_LAB_OREDERS, onSuccess: (dynamic response, int statusCode) { - patientLabResultOrdersList = []; - response['List_GetLabOreders'].forEach((v) { - patientLabResultOrdersList.add(new LabOrdersResModel.fromJson(v)); - }); - isLoading = false; - isError = false; - this.error = ''; - }, - onFailure: (String error, int statusCode) { - isLoading = false; - isError = true; - this.error = error; - }, - body: patient); + patientLabResultOrdersList = []; + response['List_GetLabOreders'].forEach((v) { + patientLabResultOrdersList.add(new LabOrdersResModel.fromJson(v)); + }); + isLoading = false; + isError = false; + this.error = ''; + }, onFailure: (String error, int statusCode) { + isLoading = false; + isError = true; + this.error = error; + }, body: patient); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -209,21 +201,18 @@ class PatientsProvider with ChangeNotifier { try { await BaseAppClient.post(GET_PRESCRIPTION, onSuccess: (dynamic response, int statusCode) { - patientPrescriptionsList = []; - response['PatientPrescriptionList'].forEach((v) { - patientPrescriptionsList - .add(new PrescriptionResModel.fromJson(v)); - }); - isLoading = false; - isError = false; - this.error = ''; - }, - onFailure: (String error, int statusCode) { - isLoading = false; - isError = true; - this.error = error; - }, - body: patient); + patientPrescriptionsList = []; + response['PatientPrescriptionList'].forEach((v) { + patientPrescriptionsList.add(new PrescriptionResModel.fromJson(v)); + }); + isLoading = false; + isError = false; + this.error = ''; + }, onFailure: (String error, int statusCode) { + isLoading = false; + isError = true; + this.error = error; + }, body: patient); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -307,23 +296,20 @@ class PatientsProvider with ChangeNotifier { // notifyListeners(); setBasicData(); try { - await BaseAppClient.post(GET_RADIOLOGY, onSuccess: (dynamic response, int statusCode) { - patientRadiologyList = []; - response['List_GetRadOreders'].forEach((v) { - patientRadiologyList.add(new RadiologyResModel.fromJson(v)); - }); - isLoading = false; - isError = false; - this.error = ''; - }, - onFailure: (String error, int statusCode) { - isLoading = false; - isError = true; - this.error = error; - }, - body: patient); + patientRadiologyList = []; + response['List_GetRadOreders'].forEach((v) { + patientRadiologyList.add(new RadiologyResModel.fromJson(v)); + }); + isLoading = false; + isError = false; + this.error = ''; + }, onFailure: (String error, int statusCode) { + isLoading = false; + isError = true; + this.error = error; + }, body: patient); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -359,17 +345,15 @@ class PatientsProvider with ChangeNotifier { try { await BaseAppClient.post(PATIENT_INSURANCE_APPROVALS_URL, onSuccess: (dynamic response, int statusCode) { - insuranceApporvalsList = response['List_ApprovalMain_InPatient']; - isLoading = false; - isError = false; - this.error = ''; - }, - onFailure: (String error, int statusCode) { - isLoading = false; - isError = true; - this.error = error; - }, - body: patient); + insuranceApporvalsList = response['List_ApprovalMain_InPatient']; + isLoading = false; + isError = false; + this.error = ''; + }, onFailure: (String error, int statusCode) { + isLoading = false; + isError = true; + this.error = error; + }, body: patient); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -383,20 +367,17 @@ class PatientsProvider with ChangeNotifier { getPatientProgressNote(patient) async { setBasicData(); try { - await BaseAppClient.post(PATIENT_PROGRESS_NOTE_URL, onSuccess: (dynamic response, int statusCode) { - patientProgressNoteList = response['List_GetPregressNoteForInPatient']; - isLoading = false; - isError = false; - this.error = ''; - }, - onFailure: (String error, int statusCode) { - isLoading = false; - isError = true; - this.error = error; - }, - body: patient); + patientProgressNoteList = response['List_GetPregressNoteForInPatient']; + isLoading = false; + isError = false; + this.error = ''; + }, onFailure: (String error, int statusCode) { + isLoading = false; + isError = true; + this.error = error; + }, body: patient); notifyListeners(); } catch (err) { handelCatchErrorCase(err); @@ -413,17 +394,15 @@ class PatientsProvider with ChangeNotifier { _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()); + 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); @@ -443,20 +422,17 @@ class PatientsProvider with ChangeNotifier { 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()); + 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); @@ -477,20 +453,17 @@ class PatientsProvider with ChangeNotifier { 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()); + 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); @@ -523,45 +496,33 @@ class PatientsProvider with ChangeNotifier { int clinicId = doctorProfile.clinicID; setBasicData(); try { - if (await Helpers.checkConnection()) { - // _referToDoctorRequest.tokenID = token; - // _referToDoctorRequest.admissionNo = admissionNo; - // _referToDoctorRequest.projectID = projectID; - // _referToDoctorRequest.tokenID = token; - // _referToDoctorRequest.extension = extension; - // _referToDoctorRequest.frequency = selectedReferralFrequancyID; - // _referToDoctorRequest.patientID = - // _referToDoctorRequest.priority = - // _referToDoctorRequest.referralClinic = - // _referToDoctorRequest.referralDoctor = - // _referToDoctorRequest.referringDoctorRemarks = - // _referToDoctorRequest.roomID = - // _referToDoctorRequest.referringClinic = - // _referToDoctorRequest.referringDoctor = - - final response = await AppClient.post(PATIENT_REFER_TO_DOCTOR_URL, - body: json.encode(_referralFrequencyRequest)); - final int statusCode = response.statusCode; + // _referToDoctorRequest.tokenID = token; + // _referToDoctorRequest.admissionNo = admissionNo; + // _referToDoctorRequest.projectID = projectID; + // _referToDoctorRequest.tokenID = token; + // _referToDoctorRequest.extension = extension; + // _referToDoctorRequest.frequency = selectedReferralFrequancyID; + // _referToDoctorRequest.patientID = + // _referToDoctorRequest.priority = + // _referToDoctorRequest.referralClinic = + // _referToDoctorRequest.referralDoctor = + // _referToDoctorRequest.referringDoctorRemarks = + // _referToDoctorRequest.roomID = + // _referToDoctorRequest.referringClinic = + // _referToDoctorRequest.referringDoctor = + + await BaseAppClient.post(PATIENT_REFER_TO_DOCTOR_URL, + onSuccess: (dynamic response, int statusCode) { + patientProgressNoteList = response['List_GetPregressNoteForInPatient']; isLoading = false; - - if (statusCode < 200 || statusCode >= 400 || json == null) { - isError = true; - error = 'Error While Fetching data'; - } else { - var res = json.decode(response.body); - print('$res'); - if (res['MessageStatus'] == 1) { - patientProgressNoteList = res['List_GetPregressNoteForInPatient']; - } else { - isError = true; - error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; - } - } - } else { + isError = false; + this.error = ''; + }, onFailure: (String error, int statusCode) { isLoading = false; isError = true; - error = 'Please Check The Internet Connection'; - } + this.error = error; + }, body: _referralFrequencyRequest.toJson()); + notifyListeners(); } catch (err) { handelCatchErrorCase(err); From 9b065036aedfd4e87e000638d7af6359236f0db5 Mon Sep 17 00:00:00 2001 From: Mohammad ALjammal Date: Thu, 11 Jun 2020 09:24:10 +0300 Subject: [PATCH 7/7] fix issues in get patients service --- lib/client/base_app_client.dart | 9 +++- lib/config/config.dart | 6 +-- lib/providers/patients_provider.dart | 22 +++++----- lib/screens/QR_reader_screen.dart | 14 ++++-- lib/screens/doctor/my_schedule_screen.dart | 3 +- .../patients/patients_list_screen.dart | 4 ++ lib/screens/patients/patients_screen.dart | 3 +- .../profile/radiology/radiology_screen.dart | 4 -- .../doctor/my_referral_patient_widget.dart | 44 +++++++++++-------- .../patients/profile/large_avatar.dart | 12 ++--- 10 files changed, 74 insertions(+), 47 deletions(-) diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index 031c70ac..93ca0690 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -9,6 +9,8 @@ import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; +import 'package:http_interceptor/http_methods.dart'; +import 'package:http_interceptor/models/request_data.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); Helpers helpers = new Helpers(); @@ -36,6 +38,9 @@ class BaseAppClient { Function(String error, int statusCode) onFailure, }) async { String url = BASE_URL + endPoint; + RequestData data = RequestData(body: body,baseUrl: url,method: Method.POST); + + try { Map profile = await sharedPref.getObj(DOCTOR_PROFILE); String token = await sharedPref.getString(TOKEN); @@ -44,7 +49,7 @@ class BaseAppClient { body['DoctorID'] = doctorProfile?.doctorID; body['EditedBy'] = doctorProfile?.doctorID; body['ProjectID'] = doctorProfile?.projectID; - if (!body.containsKey('ClinicID')) + // if (!body.containsKey('ClinicID')) body['ClinicID'] = doctorProfile?.clinicID; } body['TokenID'] = token ?? ''; @@ -56,6 +61,8 @@ class BaseAppClient { body['SessionID'] = SESSION_ID; body['IsLoginForDoctorApp'] = IS_LOGIN_FOR_DOCTOR_APP; body['PatientOutSA'] = PATIENT_OUT_SA; + print("URL : $url"); + print("Body : ${json.encode(body)}"); if (await Helpers.checkConnection()) { final response = await http.post(url, diff --git a/lib/config/config.dart b/lib/config/config.dart index f6849172..5f902f2f 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -2,8 +2,8 @@ const MAX_SMALL_SCREEN = 660; const ONLY_NUMBERS = "[0-9]"; const ONLY_LETTERS = "[a-zA-Z]"; const ONLY_DATE = "[0-9/]"; - // const BASE_URL = 'https://hmgwebservices.com/Services/'; -const BASE_URL = 'https://uat.hmgwebservices.com/Services/'; +const BASE_URL = 'https://hmgwebservices.com/Services/'; +//const BASE_URL = 'https://uat.hmgwebservices.com/Services/'; const PHARMACY_ITEMS_URL = "Lists.svc/REST/GetPharmcyItems_Region"; const PHARMACY_LIST_URL = "Patients.svc/REST/GetPharmcyList"; const PATIENT_PROGRESS_NOTE_URL = "DoctorApplication.svc/REST/GetProgressNoteForInPatient"; @@ -23,7 +23,7 @@ const GET_RADIOLOGY = 'DoctorApplication.svc/REST/GetPatientRadResult'; var selectedPatientType = 0; -//*********change value to decode json from Dropdown ************ +//*********change value to decode json from Dropdown ************1 var SERVICES_PATIANT = [ "GetMyOutPatient", "GetMyInPatient", diff --git a/lib/providers/patients_provider.dart b/lib/providers/patients_provider.dart index 2984398e..3aebd306 100644 --- a/lib/providers/patients_provider.dart +++ b/lib/providers/patients_provider.dart @@ -62,17 +62,16 @@ class PatientsProvider with ChangeNotifier { PatiantInformtion _selectedPatient; - getPatientList(PatientModel patient, patientType) async { + Future getPatientList(PatientModel patient, patientType) async { int val = int.parse(patientType); try { - var localResponse; - await BaseAppClient.post( - 'DoctorApplication.svc/REST/' + SERVICES_PATIANT[val], - onSuccess: (dynamic response, int statusCode) async { - localResponse = response; - }, onFailure: (String error, int statusCode) async { - throw error; + dynamic localRes; + await BaseAppClient.post('DoctorApplication.svc/REST/' + SERVICES_PATIANT[val], + onSuccess: (dynamic response, int statusCode) { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; }, body: { "ProjectID": patient.ProjectID, "ClinicID": patient.ClinicID, @@ -96,9 +95,10 @@ class PatientsProvider with ChangeNotifier { "PatientOutSA": patient.PatientOutSA }); - return localResponse; - } catch (err) { - handelCatchErrorCase(error); + return Future.value(localRes); + } catch (error) { + print(error); + throw error; } } diff --git a/lib/screens/QR_reader_screen.dart b/lib/screens/QR_reader_screen.dart index bbbe327a..80d9332d 100644 --- a/lib/screens/QR_reader_screen.dart +++ b/lib/screens/QR_reader_screen.dart @@ -7,6 +7,7 @@ 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/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'; @@ -159,9 +160,9 @@ DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); } else { setState(() { isError = true; - error = 'No patient'; isLoading = false; }); + DrAppToastMsg.showErrorToast('No patient'); } break; case "1": @@ -176,20 +177,27 @@ DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); }); } else { setState(() { - error = 'No patient'; isError = true; isLoading = false; }); + DrAppToastMsg.showErrorToast('No patient'); break; } } } else { setState(() { - error = response['ErrorEndUserMessage'] ?? response['ErrorMessage'] ; isLoading = false; isError = true; }); + DrAppToastMsg.showErrorToast(response['ErrorEndUserMessage'] ?? response['ErrorMessage']); + } + }).catchError((error){ + setState(() { + isLoading = false; + }); + helpers.showErrorToast(error); + //DrAppToastMsg.showErrorToast(error); }); } // } diff --git a/lib/screens/doctor/my_schedule_screen.dart b/lib/screens/doctor/my_schedule_screen.dart index f7b9d444..cd0f94a3 100644 --- a/lib/screens/doctor/my_schedule_screen.dart +++ b/lib/screens/doctor/my_schedule_screen.dart @@ -15,7 +15,8 @@ class MyScheduleScreen extends StatelessWidget { @override Widget build(BuildContext context) { scheduleProvider = Provider.of(context); - return Scaffold( + return AppScaffold( + appBarTitle: TranslationBase.of(context).mySchedule, body: scheduleProvider.isLoading ? DrAppCircularProgressIndeicator() : scheduleProvider.isError diff --git a/lib/screens/patients/patients_list_screen.dart b/lib/screens/patients/patients_list_screen.dart index 6d0b97a8..150de5df 100644 --- a/lib/screens/patients/patients_list_screen.dart +++ b/lib/screens/patients/patients_list_screen.dart @@ -33,6 +33,10 @@ class _PatientsListScreenState extends State { print(res); }).catchError((error) { print(error); + setState(() { + _isLoading = false; + _hasError = error; + }); }); } _isInit = false; diff --git a/lib/screens/patients/patients_screen.dart b/lib/screens/patients/patients_screen.dart index 1128832f..a5142dce 100644 --- a/lib/screens/patients/patients_screen.dart +++ b/lib/screens/patients/patients_screen.dart @@ -104,7 +104,8 @@ class _PatientsScreenState extends State { }).catchError((error) { setState(() { _isError = true; - this.error = helpers.generateContactAdminMsg(error); + _isLoading = false; + this.error = error; }); }); } diff --git a/lib/screens/patients/profile/radiology/radiology_screen.dart b/lib/screens/patients/profile/radiology/radiology_screen.dart index 1ddf944e..5d232d3a 100644 --- a/lib/screens/patients/profile/radiology/radiology_screen.dart +++ b/lib/screens/patients/profile/radiology/radiology_screen.dart @@ -132,10 +132,6 @@ class _RadiologyScreenState extends State { url: patientsProv .patientRadiologyList[index] .doctorImageURL, - name: patientsProv - .patientLabResultOrdersList[ - index] - .doctorName, ), Expanded( child: Padding( diff --git a/lib/widgets/doctor/my_referral_patient_widget.dart b/lib/widgets/doctor/my_referral_patient_widget.dart index 02d3f10a..67db51fa 100644 --- a/lib/widgets/doctor/my_referral_patient_widget.dart +++ b/lib/widgets/doctor/my_referral_patient_widget.dart @@ -42,24 +42,26 @@ class _MyReferralPatientWidgetState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - AppText( - '${widget.myReferralPatientModel.firstName} ${widget.myReferralPatientModel.lastName}', - fontSize: 2.5 * SizeConfig.textMultiplier, - fontWeight: FontWeight.bold, - ), - InkWell( - onTap: () { - setState(() { - _showDetails = !_showDetails; - }); - }, - child: Icon(_showDetails - ? Icons.keyboard_arrow_up - : Icons.keyboard_arrow_down)), - ], + InkWell( + onTap: () { + setState(() { + _showDetails = !_showDetails; + }); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + AppText( + '${widget.myReferralPatientModel.firstName} ${widget.myReferralPatientModel.lastName}', + fontSize: 2.5 * SizeConfig.textMultiplier, + fontWeight: FontWeight.bold, + ), + Icon(_showDetails + ? Icons.keyboard_arrow_up + : Icons.keyboard_arrow_down), + + ], + ), ), !_showDetails ? Container() @@ -87,6 +89,7 @@ class _MyReferralPatientWidgetState extends State { 1.7 * SizeConfig.textMultiplier, fontWeight: FontWeight.bold, ), + SizedBox(height: 5,), AppText( '${widget.myReferralPatientModel.referringDoctor}', fontSize: @@ -108,6 +111,7 @@ class _MyReferralPatientWidgetState extends State { 1.7 * SizeConfig.textMultiplier, fontWeight: FontWeight.bold, ), + SizedBox(height: 5,), AppText( widget.myReferralPatientModel .referringClinicDescription, @@ -135,6 +139,7 @@ class _MyReferralPatientWidgetState extends State { 1.7 * SizeConfig.textMultiplier, fontWeight: FontWeight.bold, ), + SizedBox(height: 5,), AppText( '${widget.myReferralPatientModel.referringClinicDescription}', fontSize: @@ -157,6 +162,7 @@ class _MyReferralPatientWidgetState extends State { 1.7 * SizeConfig.textMultiplier, fontWeight: FontWeight.bold, ), + SizedBox(height: 5,), AppText( widget.myReferralPatientModel .frequencyDescription, @@ -184,6 +190,7 @@ class _MyReferralPatientWidgetState extends State { 1.7 * SizeConfig.textMultiplier, fontWeight: FontWeight.bold, ), + SizedBox(height: 5,), AppText( '${widget.myReferralPatientModel.priorityDescription}', fontSize: @@ -206,6 +213,7 @@ class _MyReferralPatientWidgetState extends State { 1.7 * SizeConfig.textMultiplier, fontWeight: FontWeight.bold, ), + SizedBox(height: 5,), AppText( Helpers.getDateFormatted(widget .myReferralPatientModel diff --git a/lib/widgets/patients/profile/large_avatar.dart b/lib/widgets/patients/profile/large_avatar.dart index 54cbcb30..3b70f393 100644 --- a/lib/widgets/patients/profile/large_avatar.dart +++ b/lib/widgets/patients/profile/large_avatar.dart @@ -35,25 +35,27 @@ class LargeAvatar extends StatelessWidget { ), ), ); - } else if (name == null || name.isEmpty) { + } else if (name != null || name.isNotEmpty) { return Center( child: AppText( - 'DR', + name[0].toUpperCase(), color: Colors.white, + fontSize: 18, + fontWeight: FontWeight.bold, )); } else { return Center( child: AppText( - name[0].toUpperCase(), + 'DR', color: Colors.white, - fontSize: 18, - fontWeight: FontWeight.bold, )); } } @override Widget build(BuildContext context) { + var vlr = name; + var asd; return InkWell( onTap: disableProfileView ? null