From c7bfe24207b809cf57c25a85d19e265a6fc7df20 Mon Sep 17 00:00:00 2001 From: hussam al-habibeh Date: Tue, 29 Dec 2020 14:32:06 +0200 Subject: [PATCH] post procedure --- lib/client/base_app_client.dart | 17 +-- lib/config/config.dart | 2 + .../model/procedure/categories_procedure.dart | 18 +++ lib/core/service/prescription_service.dart | 19 ++- lib/core/service/procedure_service.dart | 32 +++- lib/core/viewModel/procedure_View_model.dart | 28 ++++ .../prescription/prescription_screen.dart | 5 +- lib/screens/procedures/procedure_screen.dart | 144 +++++++++++------- 8 files changed, 192 insertions(+), 73 deletions(-) create mode 100644 lib/core/model/procedure/categories_procedure.dart diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index ed14ecac..46dd9290 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -83,13 +83,12 @@ class BaseAppClient { onFailure('Error While Fetching data', statusCode); } else { var parsed = json.decode(response.body.toString()); - // if (!parsed['IsAuthenticated']) { - // // TODO: return it back when IsAuthenticated work fine in all service - // // await helpers.logout(); - // - // helpers.showErrorToast('Your session expired Please login agian'); - // } else - if (parsed['MessageStatus'] == 1) { + if (!parsed['IsAuthenticated']) { + // TODO: return it back when IsAuthenticated work fine in all service + // await helpers.logout(); + // + // helpers.showErrorToast('Your session expired Please login agian'); + } else if (parsed['MessageStatus'] == 1) { onSuccess(parsed, statusCode); } else { String error = @@ -102,8 +101,8 @@ class BaseAppClient { if (parsed["ValidationErrors"]["ValidationErrors"] != null && parsed["ValidationErrors"]["ValidationErrors"].length != 0) { for (var i = 0; - i < parsed["ValidationErrors"]["ValidationErrors"].length; - i++) { + i < parsed["ValidationErrors"]["ValidationErrors"].length; + i++) { error = error + parsed["ValidationErrors"]["ValidationErrors"][i] ["Messages"][0] + diff --git a/lib/config/config.dart b/lib/config/config.dart index abf451b8..fa184b33 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -122,6 +122,8 @@ const POST_ALLERGY = 'Services/DoctorApplication.svc/REST/PostAllergies'; const POST_HISTORY = 'Services/DoctorApplication.svc/REST/PostHistory'; const POST_CHIEF_COMPLAINT = 'Services/DoctorApplication.svc/REST/PostChiefcomplaint'; +const GET_CATEGORISE_PROCEDURE = + 'Services/DoctorApplication.svc/REST/GetCategories'; var selectedPatientType = 1; diff --git a/lib/core/model/procedure/categories_procedure.dart b/lib/core/model/procedure/categories_procedure.dart new file mode 100644 index 00000000..e7a7fd40 --- /dev/null +++ b/lib/core/model/procedure/categories_procedure.dart @@ -0,0 +1,18 @@ +class CategoriseProcedureModel { + String categoryID; + String categoryName; + + CategoriseProcedureModel({this.categoryID, this.categoryName}); + + CategoriseProcedureModel.fromJson(Map json) { + categoryID = json['CategoryID']; + categoryName = json['CategoryName']; + } + + Map toJson() { + final Map data = new Map(); + data['CategoryID'] = this.categoryID; + data['CategoryName'] = this.categoryName; + return data; + } +} diff --git a/lib/core/service/prescription_service.dart b/lib/core/service/prescription_service.dart index 46b93481..d51fcc3e 100644 --- a/lib/core/service/prescription_service.dart +++ b/lib/core/service/prescription_service.dart @@ -33,13 +33,16 @@ class PrescriptionService extends BaseService { Future postPrescription() async { hasError = false; //_prescriptionList.clear(); - await baseAppClient.post(POST_PRESCRIPTION_LIST, - onSuccess: (dynamic response, int statusCode) { - _prescriptionList - .add(PrescriptionModel.fromJson(response['PrescriptionList'])); - }, onFailure: (String error, int statusCode) { - hasError = true; - super.error = error; - }, body: _postPrescriptionReqModel.toJson()); + await baseAppClient.post( + GET_CATEGORISE_PROCEDURE, + onSuccess: (dynamic response, int statusCode) { + _prescriptionList + .add(PrescriptionModel.fromJson(response['PrescriptionList'])); + }, + onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, + ); } } diff --git a/lib/core/service/procedure_service.dart b/lib/core/service/procedure_service.dart index 4c795baf..fdc18003 100644 --- a/lib/core/service/procedure_service.dart +++ b/lib/core/service/procedure_service.dart @@ -1,12 +1,22 @@ import 'package:doctor_app_flutter/config/config.dart'; +import 'package:doctor_app_flutter/core/model/procedure/categories_procedure.dart'; import 'package:doctor_app_flutter/core/model/procedure/get_procedure_model.dart'; import 'package:doctor_app_flutter/core/model/procedure/get_procedure_req_model.dart'; import 'package:doctor_app_flutter/core/model/procedure/post_procedure_req_model.dart'; import 'package:doctor_app_flutter/core/service/base/base_service.dart'; +import 'package:flutter/foundation.dart'; class ProcedureService extends BaseService { List _procedureList = List(); List get procedureList => _procedureList; + List _categoriesList = List(); + List get categoriesList => _categoriesList; + List procedureslist = List(); + + Procedures t1 = Procedures( + category: '02', + procedure: '02011002', + ); GetProcedureReqModel _getProcedureReqModel = GetProcedureReqModel( clinicId: 0, @@ -34,15 +44,31 @@ class ProcedureService extends BaseService { }, body: _getProcedureReqModel.toJson()); } - Future postProcedure() async { + Future getCategories() async { + hasError = false; + _categoriesList.clear(); + await baseAppClient.post( + GET_CATEGORISE_PROCEDURE, + onSuccess: (dynamic response, int statusCode) { + _categoriesList + .add(CategoriseProcedureModel.fromJson(response['listCategories'])); + }, + onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, + ); + } + + Future postProcedure(PostProcedureReqModel postProcedureReqModel) async { hasError = false; _procedureList.clear(); await baseAppClient.post(POST_PROCEDURE_LIST, onSuccess: (dynamic response, int statusCode) { - _procedureList.add(GetProcedureModel.fromJson(response['ProcedureList'])); + print("Success"); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; - }, body: _postProcedureReqModel.toJson()); + }, body: postProcedureReqModel.toJson()); } } diff --git a/lib/core/viewModel/procedure_View_model.dart b/lib/core/viewModel/procedure_View_model.dart index f65c0b2e..13e18ed3 100644 --- a/lib/core/viewModel/procedure_View_model.dart +++ b/lib/core/viewModel/procedure_View_model.dart @@ -1,5 +1,7 @@ import 'package:doctor_app_flutter/core/enum/viewstate.dart'; +import 'package:doctor_app_flutter/core/model/procedure/categories_procedure.dart'; import 'package:doctor_app_flutter/core/model/procedure/get_procedure_model.dart'; +import 'package:doctor_app_flutter/core/model/procedure/post_procedure_req_model.dart'; import 'package:doctor_app_flutter/core/service/procedure_service.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/locator.dart'; @@ -8,6 +10,8 @@ class ProcedureViewModel extends BaseViewModel { bool hasError = false; ProcedureService _procedureService = locator(); List get procedureList => _procedureService.procedureList; + List get categoriesList => + _procedureService.categoriesList; Future getProcedure() async { hasError = false; @@ -20,4 +24,28 @@ class ProcedureViewModel extends BaseViewModel { } else setState(ViewState.Idle); } + + Future getCategories() async { + hasError = false; + //_insuranceCardService.clearInsuranceCard(); + setState(ViewState.Busy); + await _procedureService.getCategories(); + if (_procedureService.hasError) { + error = _procedureService.error; + setState(ViewState.ErrorLocal); + } else + setState(ViewState.Idle); + } + + Future postProcedure(PostProcedureReqModel postProcedureReqModel) async { + hasError = false; + //_insuranceCardService.clearInsuranceCard(); + setState(ViewState.Busy); + await _procedureService.postProcedure(postProcedureReqModel); + if (_procedureService.hasError) { + error = _procedureService.error; + setState(ViewState.ErrorLocal); + } else + setState(ViewState.Idle); + } } diff --git a/lib/screens/prescription/prescription_screen.dart b/lib/screens/prescription/prescription_screen.dart index 4ccebf39..e29bcefc 100644 --- a/lib/screens/prescription/prescription_screen.dart +++ b/lib/screens/prescription/prescription_screen.dart @@ -76,7 +76,7 @@ class _NewPrescriptionScreenState extends State { fontWeight: FontWeight.bold, ), SizedBox( - width: 20, + width: 5.0, ), AppText( patient.patientId.toString(), @@ -111,7 +111,7 @@ class _NewPrescriptionScreenState extends State { InkWell( onTap: () { addPrescriptionForm(context); - //model.postPrescription(); + model.postPrescription(); }, child: CircleAvatar( radius: 65, @@ -195,6 +195,7 @@ class _NewPrescriptionScreenState extends State { ), onTap: () { addPrescriptionForm(context); + model.postPrescription(); }, ), SizedBox( diff --git a/lib/screens/procedures/procedure_screen.dart b/lib/screens/procedures/procedure_screen.dart index 3af63004..59cf5bdf 100644 --- a/lib/screens/procedures/procedure_screen.dart +++ b/lib/screens/procedures/procedure_screen.dart @@ -1,10 +1,14 @@ +import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/size_config.dart'; +import 'package:doctor_app_flutter/core/enum/viewstate.dart'; +import 'package:doctor_app_flutter/core/model/procedure/post_procedure_req_model.dart'; import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/procedure_View_model.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; +import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/patients/profile/patient_profile_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/Text.dart'; @@ -24,6 +28,7 @@ class ProcedureScreen extends StatefulWidget { class _ProcedureScreenState extends State { int testNum = 1; PatiantInformtion patient; + TextEditingController procedureController = TextEditingController(); @override Widget build(BuildContext context) { final routeArgs = ModalRoute.of(context).settings.arguments as Map; @@ -72,7 +77,7 @@ class _ProcedureScreenState extends State { fontWeight: FontWeight.bold, ), SizedBox( - width: 20, + width: 5.0, ), AppText( patient.patientId.toString(), @@ -376,62 +381,99 @@ class _ProcedureScreenState extends State { } } +postProcedure({ProcedureViewModel model}) async { + model = new ProcedureViewModel(); + PostProcedureReqModel postProcedureReqModel = new PostProcedureReqModel(); + List controls = List(); + List controlsProcedure = List(); + + postProcedureReqModel.appointmentNo = 2016054575; + + postProcedureReqModel.episodeID = 200012166; + postProcedureReqModel.patientMRN = 3120725; + postProcedureReqModel.vidaAuthTokenID = + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxNDg1IiwianRpIjoiZjQ4YTk0OTQtYTczZS00MDI3LWI2MjgtNzc4MjAwMzUyYWEzIiwiZW1haWwiOiJNb2hhbWVkLlJlc3dhbkBjbG91ZHNvbHV0aW9uLXNhLmNvbSIsImlkIjoiMTQ4NSIsIk5hbWUiOiJTSEFLRVJBIFBBUlZFRU4gKFVTRUQgQlkgRVNFUlZJQ0VTKSIsIkVtcGxveWVlSWQiOiIxNDg1IiwiRmFjaWxpdHlHcm91cElkIjoiMDEwMjY2IiwiRmFjaWxpdHlJZCI6IjE1IiwiUGhhcmFtY3lGYWNpbGl0eUlkIjoiNTUiLCJJU19QSEFSTUFDWV9DT05ORUNURUQiOiJUcnVlIiwiRG9jdG9ySWQiOiIxNDg1IiwiU0VTU0lPTklEIjoiMjE1ODUyMTAiLCJDbGluaWNJZCI6IjMiLCJyb2xlIjoiRE9DVE9SUyIsIm5iZiI6MTYwODM2NDU2OCwiZXhwIjoxNjA5MjI4NTY4LCJpYXQiOjE2MDgzNjQ1Njh9.YLbvq5nxPn8o9ZYkcbc5YAX7Jy23Mm0s33oRmE8GHDI'; + + controls.add( + Controls(code: 'Remarks', controlValue: 'Testing'), + ); + controlsProcedure.add( + Procedures(category: "02", procedure: "02011002", controls: controls)); + postProcedureReqModel.procedures = controlsProcedure; + + await model.postProcedure(postProcedureReqModel); + DrAppToastMsg.showSuccesToast('Procedure had been added'); + if (model.state == ViewState.ErrorLocal) { + helpers.showErrorToast(model.error); + } +} + void addSelectedProcedure(context) { + TextEditingController procedureController = TextEditingController(); showModalBottomSheet( context: context, builder: (BuildContext bc) { - return SingleChildScrollView( - child: Container( - height: 490, - child: Padding( - padding: EdgeInsets.all(12.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - AppText( - 'Select Procedure'.toUpperCase(), - fontWeight: FontWeight.w900, - ), - SizedBox( - height: 9.0, - ), - Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Container( - decoration: BoxDecoration( - borderRadius: - BorderRadius.all(Radius.circular(6.0)), - border: Border.all( - width: 1.0, color: HexColor("#CCCCCC"))), - child: AppTextFormField( - labelText: 'Add Delected Procedures'.toUpperCase(), - borderColor: Colors.white, - textInputType: TextInputType.text, - inputFormatter: ONLY_LETTERS, + return BaseView( + //onModelReady: (model) => model.getCategories(), + builder: + (BuildContext context, ProcedureViewModel model, Widget child) => + SingleChildScrollView( + child: Container( + height: 490, + child: Padding( + padding: EdgeInsets.all(12.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AppText( + 'Select Procedure'.toUpperCase(), + fontWeight: FontWeight.w900, + ), + // Text(model.categoriesList[0].categoryName), + SizedBox( + height: 9.0, + ), + Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Container( + decoration: BoxDecoration( + borderRadius: + BorderRadius.all(Radius.circular(6.0)), + border: Border.all( + width: 1.0, color: HexColor("#CCCCCC"))), + child: AppTextFormField( + labelText: 'Add Delected Procedures'.toUpperCase(), + borderColor: Colors.white, + textInputType: TextInputType.text, + inputFormatter: ONLY_LETTERS, + controller: procedureController, + ), ), - ), - SizedBox( - height: 280.0, - ), - Container( - margin: EdgeInsets.all(SizeConfig.widthMultiplier * 5), - child: Wrap( - alignment: WrapAlignment.center, - children: [ - AppButton( - title: TranslationBase.of(context).addMedication, - // onPressed: () { - // Navigator.pop(context); - // prescriptionWarning(context); - // }, - ), - ], + SizedBox( + height: 280.0, + ), + Container( + margin: + EdgeInsets.all(SizeConfig.widthMultiplier * 5), + child: Wrap( + alignment: WrapAlignment.center, + children: [ + AppButton( + title: + TranslationBase.of(context).addMedication, + onPressed: () { + Navigator.pop(context); + postProcedure(); + }, + ), + ], + ), ), - ), - ], - ) - ], + ], + ) + ], + ), ), ), ),