diff --git a/lib/config/config.dart b/lib/config/config.dart index 355e58eb..47bb9809 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -186,6 +186,9 @@ const GET_PAtIENTS_INSURANCE_APPROVALS = "Services/Patients.svc/REST/GetApprovalStatus"; const SEARCH_BOT = 'HabibiChatBotApi/BotInterface/GetVoiceCommandResponse'; +const GET_VACCINATIONS_ITEMS = "/Services/ERP.svc/REST/GET_VACCINATIONS_ITEMS"; +const GET_VACCINATION_ONHAND = "/Services/ERP.svc/REST/GET_VACCINATION_ONHAND"; + const GET_PATIENT_SICK_LEAVE = 'Services/Patients.svc/REST/GetPatientSickLeave'; const SendSickLeaveEmail = 'Services/Notifications.svc/REST/SendSickLeaveEmail'; diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 7a4f0acb..0cb3fa2b 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -227,6 +227,7 @@ const Map> localizedValues = { 'ar': 'مسح فوق رمز الاستجابة السريعة للتحقق في الجهاز في المستشفى' }, "sendEmail": {"en": "Send Email", "ar": "ارسال نسخة"}, + "EmailSentSuccessfully": {"en": "Email Sent Successfully", "ar": "تم إرسال البريد الإلكتروني بنجاح"}, "close": {"en": "Close", "ar": "مغلق"}, "booked": {"en": "Booked", "ar": "محجوز"}, "confirmed": {"en": "Confirmed", "ar": "مؤكد"}, @@ -458,4 +459,6 @@ const Map> localizedValues = { "Save":{"en":"Save","ar":"حفظ "}, "UserAgreement":{"en":"User Agreement","ar":"اتفاقية الخصوصية "}, "UpdateSuccessfully":{"en":"Update Successfully","ar":"تم التحديث بنجاح"}, + "CHECK_VACCINE_AVAILABILITY":{"en":"CHECK VACCINE AVAILABILITY","ar":"تحقق من توافر اللقاح"}, + "MyVaccinesAvailability":{"en":"MyVaccinesAvailability","ar":"توفر لقاحي"}, }; diff --git a/lib/core/model/vaccine/vaccination_item.dart b/lib/core/model/vaccine/vaccination_item.dart new file mode 100644 index 00000000..0009ea7d --- /dev/null +++ b/lib/core/model/vaccine/vaccination_item.dart @@ -0,0 +1,18 @@ +class VaccinationItem { + String dESCRIPTION; + String iTEMCODE; + + VaccinationItem({this.dESCRIPTION, this.iTEMCODE}); + + VaccinationItem.fromJson(Map json) { + dESCRIPTION = json['DESCRIPTION']; + iTEMCODE = json['ITEM_CODE']; + } + + Map toJson() { + final Map data = new Map(); + data['DESCRIPTION'] = this.dESCRIPTION; + data['ITEM_CODE'] = this.iTEMCODE; + return data; + } +} diff --git a/lib/core/model/vaccine/vaccination_on_hand.dart b/lib/core/model/vaccine/vaccination_on_hand.dart new file mode 100644 index 00000000..daf3e886 --- /dev/null +++ b/lib/core/model/vaccine/vaccination_on_hand.dart @@ -0,0 +1,44 @@ +class VaccinationOnHand { + int distanceInKilometers; + int iTEMONHAND; + bool isThereItems; + String oRGANIZATIONCODE; + String oRGANIZATIONNAME; + String projectAlias; + int projectID; + String projectName; + + VaccinationOnHand( + {this.distanceInKilometers, + this.iTEMONHAND, + this.isThereItems, + this.oRGANIZATIONCODE, + this.oRGANIZATIONNAME, + this.projectAlias, + this.projectID, + this.projectName}); + + VaccinationOnHand.fromJson(Map json) { + distanceInKilometers = json['DistanceInKilometers']; + iTEMONHAND = json['ITEM_ONHAND']; + isThereItems = json['IsThereItems']; + oRGANIZATIONCODE = json['ORGANIZATION_CODE']; + oRGANIZATIONNAME = json['ORGANIZATION_NAME']; + projectAlias = json['ProjectAlias']; + projectID = json['ProjectID']; + projectName = json['ProjectName']; + } + + Map toJson() { + final Map data = new Map(); + data['DistanceInKilometers'] = this.distanceInKilometers; + data['ITEM_ONHAND'] = this.iTEMONHAND; + data['IsThereItems'] = this.isThereItems; + data['ORGANIZATION_CODE'] = this.oRGANIZATIONCODE; + data['ORGANIZATION_NAME'] = this.oRGANIZATIONNAME; + data['ProjectAlias'] = this.projectAlias; + data['ProjectID'] = this.projectID; + data['ProjectName'] = this.projectName; + return data; + } +} diff --git a/lib/core/service/vaccine_service.dart b/lib/core/service/vaccine_service.dart index 9904b838..297909a4 100644 --- a/lib/core/service/vaccine_service.dart +++ b/lib/core/service/vaccine_service.dart @@ -1,9 +1,13 @@ import 'package:diplomaticquarterapp/config/config.dart'; +import 'package:diplomaticquarterapp/core/model/vaccine/vaccination_item.dart'; +import 'package:diplomaticquarterapp/core/model/vaccine/vaccination_on_hand.dart'; import 'package:diplomaticquarterapp/core/service/base_service.dart'; import 'package:diplomaticquarterapp/core/model/vaccine/my_vaccine.dart'; class VaccineService extends BaseService { List _vaccineList = List(); + List vaccinationItemList = List(); + List vaccinationOnHandList = List(); List get vaccineList => _vaccineList; @@ -25,24 +29,47 @@ class VaccineService extends BaseService { } Future sendEmail() async { - Map body = Map(); body['ListVaccines'] = vaccineList.map((v) => v.toJson()).toList(); - body['ListVaccines'] = user.emailAddress; + body['To'] = user.emailAddress; body['DateofBirth'] = user.dateofBirth; body['PatientIditificationNum'] = user.patientIdentificationNo; body['PatientMobileNumber'] = user.mobileNumber; - body['PatientName'] = user.firstName + " "+ user.lastName; + body['PatientName'] = user.firstName + " " + user.lastName; hasError = false; - await baseAppClient.post(GET_VACCINES, - onSuccess: (dynamic response, int statusCode) { + await baseAppClient.post(GET_VACCINES_EMAIL, + onSuccess: (dynamic response, int statusCode) {}, + onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: body); + } - }, onFailure: (String error, int statusCode) { - hasError = true; - super.error = error; - }, body: body); + Future getMyVaccinationItem() async { + await baseAppClient.post(GET_VACCINATIONS_ITEMS, + onSuccess: (dynamic response, int statusCode) { + response['GetVaccinationsList'].forEach((item) { + vaccinationItemList.add(VaccinationItem.fromJson(item)); + }); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: Map()); + } + Future getMyVaccinationOnHand({String pItemCode}) async { + Map body = Map(); + body['P_ITEM_CODE'] = pItemCode; + await baseAppClient.post(GET_VACCINATION_ONHAND, + onSuccess: (dynamic response, int statusCode) { + response['GetVaccinationOnHandList'].forEach((item) { + vaccinationOnHandList.add(VaccinationOnHand.fromJson(item)); + }); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: body); } } diff --git a/lib/core/viewModels/vaccine_view_model.dart b/lib/core/viewModels/vaccine_view_model.dart index 233a945f..9f8dfecf 100644 --- a/lib/core/viewModels/vaccine_view_model.dart +++ b/lib/core/viewModels/vaccine_view_model.dart @@ -1,3 +1,4 @@ +import 'package:diplomaticquarterapp/core/model/vaccine/vaccination_item.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'base_view_model.dart'; @@ -12,10 +13,11 @@ class VaccineViewModel extends BaseViewModel { VaccineService _vaccineService = locator(); List get vaccineList => _vaccineService.vaccineList; + List get vaccinationItemList => _vaccineService.vaccinationItemList; + Future getVaccine() async { hasError = false; - //_insuranceCardService.clearInsuranceCard(); setState(ViewState.Busy); await _vaccineService.getMyVaccine(); if (_vaccineService.hasError) { @@ -25,6 +27,28 @@ class VaccineViewModel extends BaseViewModel { setState(ViewState.Idle); } + Future getMyVaccinationItem() async { + hasError = false; + setState(ViewState.Busy); + await _vaccineService.getMyVaccinationItem(); + if (_vaccineService.hasError) { + error = _vaccineService.error; + setState(ViewState.Error); + } else + setState(ViewState.Idle); + } + + Future getMyVaccinationOnHand({String pItemCode}) async { + hasError = false; + setState(ViewState.Busy); + await _vaccineService.getMyVaccinationOnHand(pItemCode: pItemCode); + if (_vaccineService.hasError) { + error = _vaccineService.error; + setState(ViewState.ErrorLocal); + } else + setState(ViewState.Idle); + } + Future sendEmail({String message}) async { hasError = false; setState(ViewState.BusyLocal); diff --git a/lib/pages/vaccine/my_vaccines_item_screen.dart b/lib/pages/vaccine/my_vaccines_item_screen.dart new file mode 100644 index 00000000..33ef5975 --- /dev/null +++ b/lib/pages/vaccine/my_vaccines_item_screen.dart @@ -0,0 +1,78 @@ +import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; +import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; +import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; +import 'package:flutter/material.dart'; +import 'package:diplomaticquarterapp/config/size_config.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:provider/provider.dart'; +import '../base/base_view.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:diplomaticquarterapp/core/viewModels/vaccine_view_model.dart'; +import 'package:diplomaticquarterapp/widgets/others/rounded_container.dart'; +import 'package:popup_box/popup_box.dart'; + +class MyVaccinesItemPage extends StatefulWidget { + @override + _MyVaccinesItemPageState createState() => _MyVaccinesItemPageState(); +} + +class _MyVaccinesItemPageState extends State { + @override + Widget build(BuildContext context) { + ProjectViewModel projectViewModel = Provider.of(context); + return BaseView( + onModelReady: (model) => model.getMyVaccinationItem(), + builder: (BuildContext context, VaccineViewModel model, Widget child) => + AppScaffold( + isShowAppBar: true, + appBarTitle: TranslationBase.of(context).myVaccinesAvailability, + baseViewModel: model, + body: Container( + margin: EdgeInsets.only( + left: SizeConfig.screenWidth * 0.004, + right: SizeConfig.screenWidth * 0.004, + top: SizeConfig.screenWidth * 0.04, + ), + child: ListView.builder( + itemCount: model.vaccinationItemList.length, + itemBuilder: (context, index) => InkWell( + onTap: () async { + await model.getMyVaccinationOnHand( + pItemCode: model.vaccinationItemList[index].iTEMCODE); + if (model.hasError) { + AppToast.showErrorToast(message: model.error); + } else { + //TODO show dialog + + } + }, + child: Container( + margin: EdgeInsets.all(5), + padding: EdgeInsets.all(10), + decoration: BoxDecoration( + shape: BoxShape.rectangle, + borderRadius: BorderRadius.circular(7), + color: Colors.white, + ), + child: Row( + children: [ + Expanded( + child: Texts( + model.vaccinationItemList[index].dESCRIPTION)), + Icon(projectViewModel.isArabic + ? Icons.arrow_forward_ios + : Icons.arrow_back_ios) + ], + ), + ), + ), + ), + ), + ), + ); + } +} diff --git a/lib/pages/vaccine/my_vaccines_screen.dart b/lib/pages/vaccine/my_vaccines_screen.dart index c825884c..02d67cac 100644 --- a/lib/pages/vaccine/my_vaccines_screen.dart +++ b/lib/pages/vaccine/my_vaccines_screen.dart @@ -1,5 +1,8 @@ +import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; +import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; +import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; import 'package:flutter/cupertino.dart'; @@ -9,6 +12,8 @@ import 'package:diplomaticquarterapp/core/viewModels/vaccine_view_model.dart'; import 'package:diplomaticquarterapp/widgets/others/rounded_container.dart'; import 'package:popup_box/popup_box.dart'; +import 'my_vaccines_item_screen.dart'; + class MyVaccines extends StatefulWidget { @override _MyVaccinesState createState() => _MyVaccinesState(); @@ -21,193 +26,174 @@ class _MyVaccinesState extends State { onModelReady: (model) => model.getVaccine(), builder: (BuildContext context, VaccineViewModel model, Widget child) => AppScaffold( - isShowAppBar: true, - appBarTitle: 'My Vaccines', - baseViewModel: model, - body: Container( - margin: EdgeInsets.only( - left: SizeConfig.screenWidth * 0.004, - right: SizeConfig.screenWidth * 0.004, - top: SizeConfig.screenWidth * 0.04, - ), - child: Column( - children: [ - RoundedContainer( - backgroundColor: Colors.white, - child: ExpansionTile( - title: Container( - height: 65.0, - child: Text('2018'), - ), - children: [ - Container( - child: ListView.builder( - scrollDirection: Axis.vertical, - shrinkWrap: true, - itemCount: model.vaccineList == null - ? 0 - : model.vaccineList.length, - itemBuilder: (BuildContext context, int index) { - return Column( - children: [ - RoundedContainer( - child: Column( + isShowAppBar: true, + appBarTitle: TranslationBase.of(context).myVaccines, + baseViewModel: model, + body: Container( + margin: EdgeInsets.only( + left: SizeConfig.screenWidth * 0.004, + right: SizeConfig.screenWidth * 0.004, + top: SizeConfig.screenWidth * 0.04, + ), + child: Column( + children: [ + RoundedContainer( + backgroundColor: Colors.white, + child: ExpansionTile( + title: Container( + height: 65.0, + child: Text('2018'), + ), + children: [ + Container( + child: ListView.builder( + scrollDirection: Axis.vertical, + shrinkWrap: true, + itemCount: model.vaccineList == null + ? 0 + : model.vaccineList.length, + itemBuilder: (BuildContext context, int index) { + return Column( + children: [ + RoundedContainer( + child: Column( + children: [ + Row( children: [ - Row( - children: [ - Expanded( - child: Column( - children: [ - Padding( - padding: EdgeInsets.symmetric( - horizontal: 20.0, - vertical: 20.0), - child: Image.network( - model.vaccineList[index] - .doctorImageURL, - height: SizeConfig + Expanded( + child: Column( + children: [ + Padding( + padding: EdgeInsets.symmetric( + horizontal: 20.0, + vertical: 20.0), + child: Image.network( + model.vaccineList[index] + .doctorImageURL, + height: SizeConfig .imageSizeMultiplier * - 23, - width: SizeConfig + 23, + width: SizeConfig .imageSizeMultiplier * - 20, - fit: BoxFit.fill, - ), - ), - ], + 20, + fit: BoxFit.fill, + ), ), - flex: 2, - ), - Expanded( - child: Container( - child: Column( - crossAxisAlignment: + ], + ), + flex: 2, + ), + Expanded( + child: Container( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - model.vaccineList[index] + children: [ + Text( + model.vaccineList[index] .doctorTitle + - model.vaccineList[index] - .doctorName, - style: TextStyle( - fontWeight: FontWeight.w900, - fontSize: 16.6, - ), - ), - SpaceBetweenTexts(space: 7.0), - Text( model.vaccineList[index] - .projectName, - style: TextStyle( - fontSize: 17.0, - letterSpacing: 0.5, - ), - ), - SpaceBetweenTexts(space: 7.0), - Text( - model.vaccineList[index] - .vaccineName, - style: TextStyle( - fontSize: 17.0, - ), - ), - SpaceBetweenTexts(space: 7.0), - Text( - 'Date Taken ' + - convertDateFormat(model - .vaccineList[index] - .invoiceDate), - style: - TextStyle(fontSize: 17.0), - ), - ], + .doctorName, + style: TextStyle( + fontWeight: + FontWeight.w900, + fontSize: 16.6, + ), ), - ), - flex: 5, + SizedBox(height: 7.0), + Text( + model.vaccineList[index] + .projectName, + style: TextStyle( + fontSize: 17.0, + letterSpacing: 0.5, + ), + ), + SizedBox(height: 7.0), + Text( + model.vaccineList[index] + .vaccineName, + style: TextStyle( + fontSize: 17.0, + ), + ), + SizedBox(height: 7.0), + Text( + 'Date Taken ' + + convertDateFormat(model + .vaccineList[index] + .invoiceDate), + style: TextStyle( + fontSize: 17.0), + ), + ], ), - ], + ), + flex: 5, ), ], ), - ), - ], - ); - }), - ) - ], - ), - ), - // SpaceBetweenTexts(space: 165.0), - - ], - ), - - ), - bottomSheet: Container( - color: Theme.of(context).scaffoldBackgroundColor, - padding: EdgeInsets.all(12), - height: MediaQuery.of(context).size.height *0.25, - width: double.infinity, - child: Column( - children: [ - Divider(height: 2,thickness: 1,), - SizedBox(height: 6,), - Container( - width: double.infinity, - // height: 80.0, - child: Button( - label: 'CHECK VACCINE AVAILABILITY', - backgroundColor: Color(0xff9EA3A4), - ), - ), - Container( - width: double.infinity, - // height: 80.0, - child: SecondaryButton( - label: 'SEND EMAIL', - color: Color(0xffF62426), - textColor: Colors.white, - disabled: model.vaccineList.length==0, - onTap: () async { - await PopupBox.showPopupBox( - context: context, - button: MaterialButton( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(3), - ), - color: Colors.white, - child: Text( - 'CANCEL', - style: TextStyle(fontSize: 16.5), - ), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - willDisplayWidget: Column( - children: [ - Text( - 'Conform \nSend a copy of this report to the email' + - model.vaccineList[0].doctorName, - style: TextStyle( - fontSize: 20, - color: Colors.black26, - fontWeight: FontWeight.w900), - ), - SizedBox( - height: 30.0, + ], + ), ), ], - )); - }, - ), - ), - ], + ); + }), + ) + ], + ), + ), + // SpaceBetweenTexts(space: 165.0), + ], + ), + ), + bottomSheet: Container( + color: Theme.of(context).scaffoldBackgroundColor, + padding: EdgeInsets.all(12), + height: MediaQuery.of(context).size.height * 0.25, + width: double.infinity, + child: Column( + children: [ + Divider( + height: 2, + thickness: 1, + ), + SizedBox( + height: 6, + ), + Container( + width: double.infinity, + // height: 80.0, + child: Button( + label: TranslationBase.of(context).checkVaccineAvailability, + backgroundColor: Color(0xff9EA3A4), + onTap: () => + Navigator.push(context, FadePage(page: MyVaccinesItemPage())), + ), + ), + Container( + width: double.infinity, + // height: 80.0, + child: SecondaryButton( + label: TranslationBase.of(context).sendEmail, + color: Color(0xffF62426), + textColor: Colors.white, + disabled: model.vaccineList.length == 0, + loading: model.state == ViewState.BusyLocal, + onTap: () async { + model.sendEmail( + message: + TranslationBase.of(context).emailSentSuccessfully); + }, + ), ), - ), + ], ), + ), + ), ); } + convertDateFormat(String Date) { const start = "/Date("; const end = "+0300)"; @@ -225,18 +211,4 @@ class _MyVaccinesState extends State { return newDate.toString(); } - - -} - -class SpaceBetweenTexts extends StatelessWidget { - final double space; - SpaceBetweenTexts({this.space}); - - @override - Widget build(BuildContext context) { - return SizedBox( - height: space, - ); - } } diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index 8bc0fb6f..f8ead077 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -529,6 +529,9 @@ class TranslationBase { String get save => localizedValues['Save'][locale.languageCode]; String get userAgreement => localizedValues['UserAgreement'][locale.languageCode]; String get updateSuccessfully => localizedValues['UpdateSuccessfully'][locale.languageCode]; + String get emailSentSuccessfully => localizedValues['EmailSentSuccessfully'][locale.languageCode]; + String get checkVaccineAvailability => localizedValues['CHECK_VACCINE_AVAILABILITY'][locale.languageCode]; + String get myVaccinesAvailability => localizedValues['MyVaccinesAvailability'][locale.languageCode]; } class TranslationBaseDelegate extends LocalizationsDelegate {