From 058a6d9e8cc3493bd5cd2d0ea1bc2a40d0981825 Mon Sep 17 00:00:00 2001 From: hussam al-habibeh Date: Mon, 26 Apr 2021 15:00:44 +0300 Subject: [PATCH] sick leave service --- lib/core/model/sick_leave_patient_model.dart | 22 ++- lib/core/service/sickleave_service.dart | 48 +++--- lib/core/viewModel/sick_leave_view_model.dart | 11 ++ lib/screens/sick-leave/add-sickleave.dart | 163 +++++++++--------- 4 files changed, 137 insertions(+), 107 deletions(-) diff --git a/lib/core/model/sick_leave_patient_model.dart b/lib/core/model/sick_leave_patient_model.dart index e0637845..3c78f1ff 100644 --- a/lib/core/model/sick_leave_patient_model.dart +++ b/lib/core/model/sick_leave_patient_model.dart @@ -1,3 +1,5 @@ +import 'package:doctor_app_flutter/widgets/shared/StarRating.dart'; + class SickLeavePatientModel { String setupID; int projectID; @@ -30,8 +32,10 @@ class SickLeavePatientModel { dynamic patientName; String projectName; String qR; - List speciality; + // List speciality; String strRequestDate; + String startDate; + String endDate; SickLeavePatientModel( {this.setupID, @@ -65,11 +69,14 @@ class SickLeavePatientModel { this.patientName, this.projectName, this.qR, - this.speciality, - this.strRequestDate}); + // this.speciality, + this.strRequestDate, + this.startDate, + this.endDate}); SickLeavePatientModel.fromJson(Map json) { setupID = json['SetupID']; + projectID = json['ProjectID']; patientID = json['PatientID']; patientType = json['PatientType']; @@ -100,13 +107,16 @@ class SickLeavePatientModel { patientName = json['PatientName']; projectName = json['ProjectName']; qR = json['QR']; - speciality = json['Speciality'].cast(); + // speciality = json['Speciality'].cast(); strRequestDate = json['StrRequestDate']; + startDate = json['StartDate']; + endDate = json['EndDate']; } Map toJson() { final Map data = new Map(); data['SetupID'] = this.setupID; + data['ProjectID'] = this.projectID; data['PatientID'] = this.patientID; data['PatientType'] = this.patientType; @@ -137,8 +147,10 @@ class SickLeavePatientModel { data['PatientName'] = this.patientName; data['ProjectName'] = this.projectName; data['QR'] = this.qR; - data['Speciality'] = this.speciality; + // data['Speciality'] = this.speciality; data['StrRequestDate'] = this.strRequestDate; + data['StartDate'] = this.startDate; + data['EndDate'] = this.endDate; return data; } } diff --git a/lib/core/service/sickleave_service.dart b/lib/core/service/sickleave_service.dart index bba9b31f..90785a7b 100644 --- a/lib/core/service/sickleave_service.dart +++ b/lib/core/service/sickleave_service.dart @@ -98,13 +98,13 @@ class SickLeaveService extends BaseService { Future getSickLeave(patientMRN) async { hasError = false; - await baseAppClient.post( + await baseAppClient.postPatient( GET_SICK_LEAVE, onSuccess: (dynamic response, int statusCode) { Future.value(response); - _getAllsickLeave.clear(); - response['SickLeavesList']['entityList'].forEach((v) { - _getAllsickLeave.add(GetAllSickLeaveResponse.fromJson(v)); + _getAllsickLeavePatient.clear(); + response['List_SickLeave'].forEach((v) { + _getAllsickLeavePatient.add(SickLeavePatientModel.fromJson(v)); }); }, onFailure: (String error, int statusCode) { @@ -115,26 +115,26 @@ class SickLeaveService extends BaseService { ); } - // Future getSickLeavePatient(patientMRN) async { - // _sickLeavePatientRequestModel = - // SickLeavePatientRequestModel(patientID: patientMRN, patientType: 1); - // hasError = false; - // await baseAppClient.post( - // GET_SICK_LEAVE_PATIENT, - // onSuccess: (dynamic response, int statusCode) { - // Future.value(response); - // _getAllsickLeavePatient.clear(); - // response['List_SickLeave'].forEach((v) { - // _getAllsickLeavePatient.add(SickLeavePatientModel.fromJson(v)); - // }); - // }, - // onFailure: (String error, int statusCode) { - // hasError = true; - // super.error = error; - // }, - // body: _sickLeavePatientRequestModel.toJson(), - // ); - // } + Future getSickLeavePatient(patientMRN) async { + _sickLeavePatientRequestModel = SickLeavePatientRequestModel( + patientID: patientMRN, patientTypeID: 2, patientType: 1); + hasError = false; + await baseAppClient.postPatient( + GET_SICK_LEAVE_PATIENT, + onSuccess: (dynamic response, int statusCode) { + Future.value(response); + _getAllsickLeavePatient.clear(); + response['List_SickLeave'].forEach((v) { + _getAllsickLeavePatient.add(SickLeavePatientModel.fromJson(v)); + }); + }, + onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, + body: _sickLeavePatientRequestModel.toJson(), + ); + } Future getRescheduleLeave() async { hasError = false; diff --git a/lib/core/viewModel/sick_leave_view_model.dart b/lib/core/viewModel/sick_leave_view_model.dart index d959f3aa..f5ddd676 100644 --- a/lib/core/viewModel/sick_leave_view_model.dart +++ b/lib/core/viewModel/sick_leave_view_model.dart @@ -10,6 +10,7 @@ class SickLeaveViewModel extends BaseViewModel { SickLeaveService _sickLeaveService = locator(); get sickLeaveStatistics => _sickLeaveService.sickLeavestatisitics; get getAllSIckLeave => _sickLeaveService.getAllSickLeave; + get getAllSIckLeavePatient => _sickLeaveService.getAllSickLeavePatient; List get allOffTime => _sickLeaveService.getOffTimeList; List get allReasons => _sickLeaveService.getReasons; List get coveringDoctors => _sickLeaveService.coveringDoctorsList; @@ -56,6 +57,16 @@ class SickLeaveViewModel extends BaseViewModel { setState(ViewState.Idle); } + Future getSickLeavePatient(patientMRN) async { + setState(ViewState.Busy); + await _sickLeaveService.getSickLeavePatient(patientMRN); + if (_sickLeaveService.hasError) { + error = _sickLeaveService.error; + setState(ViewState.Error); + } else + setState(ViewState.Idle); + } + Future getRescheduleLeave() async { setState(ViewState.Busy); await _sickLeaveService.getRescheduleLeave(); diff --git a/lib/screens/sick-leave/add-sickleave.dart b/lib/screens/sick-leave/add-sickleave.dart index 7820b16c..444e76bd 100644 --- a/lib/screens/sick-leave/add-sickleave.dart +++ b/lib/screens/sick-leave/add-sickleave.dart @@ -1,4 +1,5 @@ import 'package:doctor_app_flutter/config/size_config.dart'; +import 'package:doctor_app_flutter/core/model/sick_leave_patient_model.dart'; import 'package:doctor_app_flutter/core/viewModel/sick_leave_view_model.dart'; import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/models/sickleave/get_all_sickleave_response.dart'; @@ -22,7 +23,7 @@ class AddSickLeavScreen extends StatelessWidget { patient = routeArgs['patient']; return BaseView( onModelReady: (model) => - model.getSickLeave(patient.patientMRN ?? patient.patientId), + model.getSickLeavePatient(patient.patientMRN ?? patient.patientId), builder: (_, model, w) => AppScaffold( baseViewModel: model, isShowAppBar: true, @@ -102,25 +103,26 @@ class AddSickLeavScreen extends StatelessWidget { ], ) : SizedBox(), - model.getAllSIckLeave.length > 0 + model.getAllSIckLeavePatient.length > 0 ? Column( - children: model.getAllSIckLeave - .map((GetAllSickLeaveResponse item) { + children: model.getAllSIckLeavePatient + .map((SickLeavePatientModel item) { return RoundedContainer( margin: EdgeInsets.all(10), child: Column( children: [ Container( - decoration: BoxDecoration( - border: Border( - left: BorderSide( - color: item.status == 1 - ? Colors.yellow[800] - : item.status == 2 - ? Colors.green - : Colors.black, - width: 5.0, - ))), + // decoration: BoxDecoration( + // border: Border( + // left: BorderSide( + // // color: item.status == 1 + // // ? Colors.yellow[800] + // // : item.status == 2 + // // ? Colors.green + // // : Colors.black, + // color: Colors.red, + // width: 5.0, + // ))), padding: EdgeInsets.all(10), child: Row( mainAxisAlignment: @@ -139,35 +141,37 @@ class AddSickLeavScreen extends StatelessWidget { Container( padding: EdgeInsets.all(3), child: AppText( - item.status == 1 - ? TranslationBase.of( - context) - .hold - : item.status == 2 - ? TranslationBase - .of( - context) - .active - : TranslationBase - .of(context) - .all, + item.doctorName, + // item.status == 1 + // ? TranslationBase.of( + // context) + // .hold + // : item.status == 2 + // ? TranslationBase + // .of( + // context) + // .active + // : TranslationBase + // .of(context) + // .all, fontWeight: FontWeight.bold, - color: item.status == 1 - ? Colors.yellow[800] - : item.status == 2 - ? Colors.green - : Colors.black, + // color: item.status == 1 + // ? Colors.yellow[800] + // : item.status == 2 + // ? Colors.green + // : Colors.black, + color: Colors.red, ), ), Row( children: [ + AppText(TranslationBase + .of(context) + .daysSickleave + + ": "), AppText( - TranslationBase.of( - context) - .daysSickleave), - AppText( - item.noOfDays + item.sickLeaveDays .toString(), fontWeight: FontWeight.bold, @@ -183,52 +187,55 @@ class AddSickLeavScreen extends StatelessWidget { ' ', ), Flexible( - child: AppText( - DateUtils - .convertStringToDateFormat( - item.startDate, - 'dd-MMM-yyyy'), - fontWeight: - FontWeight.bold, - )) + child: AppText( + DateUtils + .convertStringToDateFormat( + item.startDate, + 'dd-MMM-yyyy'), + fontWeight: + FontWeight.bold, + ), + ) ], ), Row( - mainAxisAlignment: - MainAxisAlignment - .spaceBetween, - children: [ - AppText( - item.remarks ?? "", + children: [ + AppText( + TranslationBase.of( + context) + .endDate + + ' ', + ), + Flexible( + child: AppText( + DateUtils + .convertStringToDateFormat( + item.endDate, + 'dd-MMM-yyyy'), + fontWeight: + FontWeight.bold, ), - // (item.status == 1 || - // item.status == 2) - // ? IconButton( - // icon: Image.asset( - // 'assets/images/edit.png'), - // - // // color: Colors.green, //Colors.black, - // onPressed: () => { - // if (item.status == - // 1) - // { - // DrAppToastMsg.showErrorToast( - // TranslationBase.of( - // context) - // .sickleaveonhold) - // } - // else - // { - // openSickLeave( - // context, - // true, - // extendedData: - // item) - // } - // }, - // ) - // : SizedBox() - ]), + ) + ], + ), + Row(children: [ + AppText(TranslationBase.of( + context) + .branch + + ": "), + AppText( + item.projectName ?? "", + ), + ]), + Row(children: [ + AppText(TranslationBase.of( + context) + .clinic + + ": "), + AppText( + item.clinicName ?? "", + ), + ]), ], ), SizedBox(