diff --git a/lib/core/service/patient/LiveCarePatientServices.dart b/lib/core/service/patient/LiveCarePatientServices.dart index 05b73393..b8712a9b 100644 --- a/lib/core/service/patient/LiveCarePatientServices.dart +++ b/lib/core/service/patient/LiveCarePatientServices.dart @@ -74,7 +74,7 @@ class LiveCarePatientServices extends BaseService { }, body: startCallReq.toJson(), isLiveCare: _isLive); } - Future endCallWithCharge(int vcID) async { + Future endCallWithCharge(int vcID, String altServiceList) async { hasError = false; await baseAppClient.post(END_CALL_WITH_CHARGE, onSuccess: (dynamic response, int statusCode) { @@ -84,7 +84,7 @@ class LiveCarePatientServices extends BaseService { super.error = error; }, body: { "VC_ID": vcID, - "generalid": "Cs2020@2016\$2958", + "AltServiceList": altServiceList, }, isLiveCare: _isLive); } diff --git a/lib/core/viewModel/LiveCarePatientViewModel.dart b/lib/core/viewModel/LiveCarePatientViewModel.dart index a64552aa..032c7a07 100644 --- a/lib/core/viewModel/LiveCarePatientViewModel.dart +++ b/lib/core/viewModel/LiveCarePatientViewModel.dart @@ -20,7 +20,8 @@ class LiveCarePatientViewModel extends BaseViewModel { StartCallRes get startCallRes => _liveCarePatientServices.startCallRes; - List get alternativeServicesList => _liveCarePatientServices.alternativeServicesList; + List get alternativeServicesList => + _liveCarePatientServices.alternativeServicesList; DashboardService _dashboardService = locator(); @@ -94,9 +95,22 @@ class LiveCarePatientViewModel extends BaseViewModel { } } - Future endCallWithCharge(int vcID) async { + setSelectedCheckboxValues(AlternativeService service, bool isSelected) { + int index = alternativeServicesList.indexOf(service); + if (index != -1) alternativeServicesList[index].isSelected = isSelected; + notifyListeners(); + } + + Future endCallWithCharge(int vcID, bool isConfirmed) async { setState(ViewState.BusyLocal); - await _liveCarePatientServices.endCallWithCharge(vcID); + + String selectedServicesString = ""; + if (isConfirmed) { + selectedServicesString = getSelectedAlternativeServices(); + } + + await _liveCarePatientServices.endCallWithCharge( + vcID, selectedServicesString); if (_liveCarePatientServices.hasError) { error = _liveCarePatientServices.error; setState(ViewState.ErrorLocal); @@ -106,25 +120,35 @@ class LiveCarePatientViewModel extends BaseViewModel { } } - Future transferToAdmin(int vcID, String notes) async { + String getSelectedAlternativeServices() { + List selectedServices = List(); + for (AlternativeService service in alternativeServicesList) { + if (service.isSelected) { + selectedServices.add(service.serviceID); + } + } + return selectedServices.toString(); + } + + Future getAlternativeServices(int vcID) async { setState(ViewState.BusyLocal); - await _liveCarePatientServices.transferToAdmin(vcID, notes); + await _liveCarePatientServices.getAlternativeServices(vcID); if (_liveCarePatientServices.hasError) { error = _liveCarePatientServices.error; setState(ViewState.ErrorLocal); } else { - await getPendingPatientERForDoctorApp(); setState(ViewState.Idle); } } - Future getAlternativeServices(int vcID) async { + Future transferToAdmin(int vcID, String notes) async { setState(ViewState.BusyLocal); - await _liveCarePatientServices.getAlternativeServices(vcID); + await _liveCarePatientServices.transferToAdmin(vcID, notes); if (_liveCarePatientServices.hasError) { error = _liveCarePatientServices.error; setState(ViewState.ErrorLocal); } else { + await getPendingPatientERForDoctorApp(); setState(ViewState.Idle); } } @@ -154,9 +178,7 @@ class LiveCarePatientViewModel extends BaseViewModel { } } - // AlternativeServicesList demoServicesList = AlternativeServicesList(); - - setDemoData(){ + setDemoData() { alternativeServicesList.clear(); alternativeServicesList.add( AlternativeService(serviceID: 1, serviceName: "Medicine Home Delivery"), @@ -194,12 +216,4 @@ class LiveCarePatientViewModel extends BaseViewModel { AlternativeService(serviceID: 11, serviceName: "GASTRIC TUBE CHANGE"), ); } - - setSelected(AlternativeService service, bool isSelected) { - int index = alternativeServicesList.indexOf(service); - if(index !=-1) - alternativeServicesList[index].isSelected = isSelected; - notifyListeners(); - } - } diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index d079a477..85ea3506 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -1,19 +1,14 @@ -import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/patient_muse/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; -import 'package:doctor_app_flutter/models/dashboard/dashboard_model.dart'; -import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; -import 'package:doctor_app_flutter/models/patient/patient_model.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/screens/home/dashboard_slider-item-widget.dart'; import 'package:doctor_app_flutter/screens/home/dashboard_swipe_widget.dart'; import 'package:doctor_app_flutter/screens/home/home_patient_card.dart'; -import 'package:doctor_app_flutter/screens/live_care/TestScreen.dart'; import 'package:doctor_app_flutter/screens/live_care/live_care_patient_screen.dart'; import 'package:doctor_app_flutter/screens/medicine/medicine_search_screen.dart'; import 'package:doctor_app_flutter/screens/patients/PatientsInPatientScreen.dart'; @@ -22,7 +17,6 @@ import 'package:doctor_app_flutter/screens/patients/patient_search/patient_searc import 'package:doctor_app_flutter/screens/patients/profile/referral/patient_referral_screen.dart'; import 'package:doctor_app_flutter/util/date-utils.dart'; import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart'; -import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/patients/profile/profile-welcome-widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; @@ -342,7 +336,6 @@ class _HomeScreenState extends State { context, FadePage( page: LiveCarePatientScreen(), - // page: TestScreen(), ), ); }, diff --git a/lib/screens/live_care/TestScreen.dart b/lib/screens/live_care/TestScreen.dart deleted file mode 100644 index 974f2351..00000000 --- a/lib/screens/live_care/TestScreen.dart +++ /dev/null @@ -1,136 +0,0 @@ -import 'package:doctor_app_flutter/config/size_config.dart'; -import 'package:doctor_app_flutter/core/model/live_care/AlternativeServicesList.dart'; -import 'package:doctor_app_flutter/core/viewModel/LiveCarePatientViewModel.dart'; -import 'package:doctor_app_flutter/screens/base/base_view.dart'; -import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; -import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; -import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; -import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; - -class TestScreen extends StatefulWidget { - @override - _TestScreenState createState() => _TestScreenState(); -} - -class _TestScreenState extends State { - @override - Widget build(BuildContext context) { - return BaseView( - onModelReady: (model) => model.setDemoData(), - builder: (_, model, w) => AppScaffold( - baseViewModel: model, - appBarTitle: TranslationBase.of(context).patientProfile, - backgroundColor: Theme.of(context).scaffoldBackgroundColor, - isShowAppBar: false, - body: Container( - child: Center( - child: AppButton( - fontWeight: FontWeight.w700, - color: Colors.red[600], - title: "open dialog", //TranslationBase.of(context).close, - onPressed: () { - showAlternativesDialog(context, model, () { - model.alternativeServicesList.map((e) => () { - if (e.isSelected) { - print(e.serviceName); - } - }); - Navigator.of(context).pop(); - }); - }, - ), - ), - ), - ), - ); - } - - showAlternativesDialog(BuildContext context, LiveCarePatientViewModel model, Function okFunction) { - return showDialog( - context: context, - barrierDismissible: false, // user must tap button! - builder: (_) { - return Container( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - AlertDialog( - title: null, - content: Container( - height: MediaQuery.of(context).size.height / 2, - child: CheckBoxListWidget(model: model,), - ), - actions: [ - AppButton( - onPressed: (){ - okFunction(); - }, - title: TranslationBase.of(context).noteConfirm, - fontColor: Colors.white, - color: Colors.green[600], - ), - AppButton( - onPressed: () { - Navigator.of(context).pop(); - }, - title: TranslationBase.of(context).cancel, - fontColor: Colors.white, - color: Colors.red[600], - ), - ], - ), - ], - ), - ); - }); - } -} - -class CheckBoxListWidget extends StatefulWidget { - final LiveCarePatientViewModel model; - const CheckBoxListWidget({ - Key key, this.model, - }) : super(key: key); - - @override - _CheckBoxListState createState() => _CheckBoxListState(); -} - -class _CheckBoxListState extends State { - @override - Widget build(BuildContext context) { - return SingleChildScrollView( - child: Column( - children: [ - ...widget.model - .alternativeServicesList - .map( - (element) => Container( - child: CheckboxListTile( - title: AppText( - element.serviceName, - fontWeight: FontWeight.normal, - fontSize: SizeConfig.textMultiplier * 2.2, - ), - value: element.isSelected, - onChanged: (newValue) { - setState(() { - widget.model.setSelected( - element, newValue); - }); - }, - activeColor: Color(0xFFD02127), - controlAffinity: - ListTileControlAffinity.leading, - contentPadding: EdgeInsets.all(0), - ), - ), - ) - .toList() - ], - ), - ); - } -} diff --git a/lib/screens/live_care/end_call_screen.dart b/lib/screens/live_care/end_call_screen.dart index 22f31188..ee1a036d 100644 --- a/lib/screens/live_care/end_call_screen.dart +++ b/lib/screens/live_care/end_call_screen.dart @@ -1,4 +1,5 @@ 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/viewModel/LiveCarePatientViewModel.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; @@ -51,41 +52,48 @@ class _EndCallScreenState extends State { GifLoaderDialogUtils.showMyDialog(context); await liveCareModel .startCall(isReCall: false, vCID: widget.patient.vcId) - .then((value) async{ + .then((value) async { await liveCareModel.getDoctorProfile(); GifLoaderDialogUtils.hideDialog(context); if (liveCareModel.state == ViewState.ErrorLocal) { DrAppToastMsg.showErrorToast(liveCareModel.error); - }else - await VideoChannel.openVideoCallScreen( - kToken: liveCareModel.startCallRes.openTokenID, - kSessionId: liveCareModel.startCallRes.openSessionID, - kApiKey: '46209962', - vcId: widget.patient.vcId, - tokenID: await liveCareModel.getToken(), - generalId: GENERAL_ID, - doctorId: liveCareModel.doctorProfile.doctorID, - onFailure: (String error) { - DrAppToastMsg.showErrorToast(error); - }, - onCallEnd: () async{ - GifLoaderDialogUtils.showMyDialog(context); - GifLoaderDialogUtils.showMyDialog(context); - await liveCareModel.endCall(widget.patient.vcId, false,); - GifLoaderDialogUtils.hideDialog(context); - if (liveCareModel.state == ViewState.ErrorLocal) { - DrAppToastMsg.showErrorToast(liveCareModel.error); - } - }, - onCallNotRespond: (SessionStatusModel sessionStatusModel) async{ - GifLoaderDialogUtils.showMyDialog(context); - GifLoaderDialogUtils.showMyDialog(context); - await liveCareModel.endCall(widget.patient.vcId, sessionStatusModel.sessionStatus == 3,); - GifLoaderDialogUtils.hideDialog(context); - if (liveCareModel.state == ViewState.ErrorLocal) { - DrAppToastMsg.showErrorToast(liveCareModel.error); - } - }); + } else + await VideoChannel.openVideoCallScreen( + kToken: liveCareModel.startCallRes.openTokenID, + kSessionId: liveCareModel.startCallRes.openSessionID, + kApiKey: '46209962', + vcId: widget.patient.vcId, + tokenID: await liveCareModel.getToken(), + generalId: GENERAL_ID, + doctorId: liveCareModel.doctorProfile.doctorID, + onFailure: (String error) { + DrAppToastMsg.showErrorToast(error); + }, + onCallEnd: () async { + GifLoaderDialogUtils.showMyDialog(context); + GifLoaderDialogUtils.showMyDialog(context); + await liveCareModel.endCall( + widget.patient.vcId, + false, + ); + GifLoaderDialogUtils.hideDialog(context); + if (liveCareModel.state == ViewState.ErrorLocal) { + DrAppToastMsg.showErrorToast(liveCareModel.error); + } + }, + onCallNotRespond: + (SessionStatusModel sessionStatusModel) async { + GifLoaderDialogUtils.showMyDialog(context); + GifLoaderDialogUtils.showMyDialog(context); + await liveCareModel.endCall( + widget.patient.vcId, + sessionStatusModel.sessionStatus == 3, + ); + GifLoaderDialogUtils.hideDialog(context); + if (liveCareModel.state == ViewState.ErrorLocal) { + DrAppToastMsg.showErrorToast(liveCareModel.error); + } + }); }); GifLoaderDialogUtils.hideDialog(context); if (liveCareModel.state == ViewState.ErrorLocal) { @@ -103,14 +111,23 @@ class _EndCallScreenState extends State { () async { Navigator.of(context).pop(); GifLoaderDialogUtils.showMyDialog(context); - await liveCareModel.endCallWithCharge(widget.patient.vcId); + await liveCareModel.getAlternativeServices(widget.patient.vcId); GifLoaderDialogUtils.hideDialog(context); if (liveCareModel.state == ViewState.ErrorLocal) { DrAppToastMsg.showErrorToast(liveCareModel.error); } else { - // todo mosa add new service - Navigator.of(context).pop(); - Navigator.of(context).pop(); + showAlternativesDialog(context, liveCareModel, (bool isConfirmed) async { + GifLoaderDialogUtils.showMyDialog(context); + await liveCareModel.endCallWithCharge(widget.patient.vcId, isConfirmed); + GifLoaderDialogUtils.hideDialog(context); + if (liveCareModel.state == ViewState.ErrorLocal) { + DrAppToastMsg.showErrorToast(liveCareModel.error); + } else { + DrAppToastMsg.showSuccesToast("You successfully completed call with charge"); + Navigator.of(context).pop(); + Navigator.of(context).pop(); + } + }); } }); }, isDartIcon: true, dartIcon: DoctorApp.end_consultaion), @@ -247,7 +264,7 @@ class _EndCallScreenState extends State { fontWeight: FontWeight.w700, color: Colors.red[600], title: "Close", //TranslationBase.of(context).close, - onPressed: () { + onPressed: () { Navigator.of(context).pop(); }, ), @@ -263,4 +280,96 @@ class _EndCallScreenState extends State { ), ); } + + showAlternativesDialog(BuildContext context, LiveCarePatientViewModel model, + Function(bool) okFunction) { + return showDialog( + context: context, + barrierDismissible: false, // user must tap button! + builder: (_) { + return Container( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + AlertDialog( + title: null, + content: Container( + height: MediaQuery.of(context).size.height / 2, + child: CheckBoxListWidget( + model: model, + ), + ), + actions: [ + AppButton( + onPressed: (){ + Navigator.of(context).pop(); + okFunction(true); + }, + title: TranslationBase.of(context).noteConfirm, + fontColor: Colors.white, + color: Colors.green[600], + ), + AppButton( + onPressed: () { + Navigator.of(context).pop(); + okFunction(false); + }, + title: TranslationBase.of(context).cancel, + fontColor: Colors.white, + color: Colors.red[600], + ), + ], + ), + ], + ), + ); + }); + } +} + +class CheckBoxListWidget extends StatefulWidget { + final LiveCarePatientViewModel model; + + const CheckBoxListWidget({ + Key key, + this.model, + }) : super(key: key); + + @override + _CheckBoxListState createState() => _CheckBoxListState(); +} + +class _CheckBoxListState extends State { + @override + Widget build(BuildContext context) { + return SingleChildScrollView( + child: Column( + children: [ + ...widget.model.alternativeServicesList + .map( + (element) => Container( + child: CheckboxListTile( + title: AppText( + element.serviceName, + fontWeight: FontWeight.normal, + fontSize: SizeConfig.textMultiplier * 2.2, + ), + value: element.isSelected, + onChanged: (newValue) { + setState(() { + widget.model + .setSelectedCheckboxValues(element, newValue); + }); + }, + activeColor: Color(0xFFD02127), + controlAffinity: ListTileControlAffinity.leading, + contentPadding: EdgeInsets.all(0), + ), + ), + ) + .toList() + ], + ), + ); + } } diff --git a/lib/screens/live_care/live-care_transfer_to_admin.dart b/lib/screens/live_care/live-care_transfer_to_admin.dart index c5bcf304..2d0fb7d7 100644 --- a/lib/screens/live_care/live-care_transfer_to_admin.dart +++ b/lib/screens/live_care/live-care_transfer_to_admin.dart @@ -120,11 +120,12 @@ class _LivaCareTransferToAdminState extends State { () async { Navigator.of(context).pop(); GifLoaderDialogUtils.showMyDialog(context); - model.endCallWithCharge(widget.patient.vcId); + model.transferToAdmin(widget.patient.vcId, noteController.text); GifLoaderDialogUtils.hideDialog(context); if (model.state == ViewState.ErrorLocal) { DrAppToastMsg.showErrorToast(model.error); } else { + DrAppToastMsg.showSuccesToast("You successfully transfer to admin"); Navigator.of(context).pop(); Navigator.of(context).pop(); Navigator.of(context).pop();