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); } - - - - + } }