From 3a79ddb4885d4252e507b7030dd12fb69884dc68 Mon Sep 17 00:00:00 2001 From: hussam al-habibeh Date: Thu, 3 Sep 2020 11:24:33 +0300 Subject: [PATCH] vaccine service --- lib/config/config.dart | 4 +- lib/core/model/vaccine/my_vaccine.dart | 91 +++++ lib/core/service/vaccine_service.dart | 43 +++ lib/core/viewModels/vaccine_view_model.dart | 25 ++ lib/locator.dart | 5 +- lib/pages/medical/medical_profile_page.dart | 29 +- lib/pages/vaccine/my_vaccines_screen.dart | 361 ++++++++++++++++++++ pubspec.yaml | 8 + 8 files changed, 558 insertions(+), 8 deletions(-) create mode 100644 lib/core/model/vaccine/my_vaccine.dart create mode 100644 lib/core/service/vaccine_service.dart create mode 100644 lib/core/viewModels/vaccine_view_model.dart create mode 100644 lib/pages/vaccine/my_vaccines_screen.dart diff --git a/lib/config/config.dart b/lib/config/config.dart index a7cb621b..fd7de7bf 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -52,7 +52,7 @@ const GENERAL_ID = 'Cs2020@2016\$2958'; const IP_ADDRESS = '10.20.10.20'; const VERSION_ID = 5.5; const SETUP_ID = '91877'; -const LANGUAGE = 1; +const LANGUAGE = 2; const PATIENT_OUT_SA = 0; const SESSION_ID = 'TMRhVmkGhOsvamErw'; const IS_DENTAL_ALLOWED_BACKEND = false; @@ -67,6 +67,8 @@ const GET_PAtIENTS_INSURANCE = "/Patients.svc/REST/Get_PatientInsuranceDetails"; const GET_PAtIENTS_INSURANCE_UPDATED = "/Patients.svc/REST/PatientER_GetPatientInsuranceCardUpdateHistory"; const GET_PAtIENTS_INSURANCE_APPROVALS = "/Patients.svc/REST/GetApprovalStatus"; +const GET_VACCINES = "/Patients.svc/REST/GetDoneVaccinesByPatientID"; +const GET_VACCINES_EMAIL = "/Notifications.svc/REST/SendVaccinesEmail"; class AppGlobal { static var context; diff --git a/lib/core/model/vaccine/my_vaccine.dart b/lib/core/model/vaccine/my_vaccine.dart new file mode 100644 index 00000000..ac6e2e19 --- /dev/null +++ b/lib/core/model/vaccine/my_vaccine.dart @@ -0,0 +1,91 @@ +class VaccineModel { + String to; + String from; + double versionID; + int channel; + int languageID; + String iPAdress; + String generalid; + int patientOutSA; + String sessionID; + bool isDentalAllowedBackend; + int deviceTypeID; + int patientID; + String tokenID; + int patientTypeID; + int patientType; + String invoiceDate; + String doctorImageURL; + String doctorName; + String doctorTitle; + String projectName; + String vaccineName; + + VaccineModel({ + this.to, + this.from, + this.versionID, + this.channel, + this.languageID, + this.iPAdress, + this.generalid, + this.patientOutSA, + this.sessionID, + this.isDentalAllowedBackend, + this.deviceTypeID, + this.patientID, + this.tokenID, + this.patientTypeID, + this.patientType, + this.invoiceDate, + this.doctorImageURL, + this.doctorName, + this.doctorTitle, + this.projectName, + this.vaccineName, + }); + + VaccineModel.fromJson(Map json) { + vaccineName = json['VaccineName']; + projectName = json['ProjectName']; + doctorTitle = json['DoctorTitle']; + doctorName = json['DoctorName']; + doctorImageURL = json['DoctorImageURL']; + invoiceDate = json['InvoiceDate']; + to = json['To']; + from = json['From']; + versionID = json['VersionID']; + channel = json['Channel']; + languageID = json['LanguageID']; + iPAdress = json['IPAdress']; + generalid = json['generalid']; + patientOutSA = json['PatientOutSA']; + sessionID = json['SessionID']; + isDentalAllowedBackend = json['isDentalAllowedBackend']; + deviceTypeID = json['DeviceTypeID']; + patientID = json['PatientID']; + tokenID = json['TokenID']; + patientTypeID = json['PatientTypeID']; + patientType = json['PatientType']; + } + + Map toJson() { + final Map data = new Map(); + data['To'] = this.to; + data['From'] = this.from; + data['VersionID'] = this.versionID; + data['Channel'] = this.channel; + data['LanguageID'] = this.languageID; + data['IPAdress'] = this.iPAdress; + data['generalid'] = this.generalid; + data['PatientOutSA'] = this.patientOutSA; + data['SessionID'] = this.sessionID; + data['isDentalAllowedBackend'] = this.isDentalAllowedBackend; + data['DeviceTypeID'] = this.deviceTypeID; + data['PatientID'] = this.patientID; + data['TokenID'] = this.tokenID; + data['PatientTypeID'] = this.patientTypeID; + data['PatientType'] = this.patientType; + return data; + } +} diff --git a/lib/core/service/vaccine_service.dart b/lib/core/service/vaccine_service.dart new file mode 100644 index 00000000..189e26d8 --- /dev/null +++ b/lib/core/service/vaccine_service.dart @@ -0,0 +1,43 @@ +import 'package:diplomaticquarterapp/config/config.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 get vaccineList => _vaccineList; + + VaccineModel _vaccineModel = VaccineModel( + to: "0", + from: "0", + channel: 3, + deviceTypeID: 2, + generalid: "Cs2020@2016\$2958", + iPAdress: "10.20.10.20", + isDentalAllowedBackend: false, + languageID: 2, + patientID: 1231755, + patientOutSA: 0, + patientType: 1, + patientTypeID: 1, + sessionID: "uoKFXSLUwEaHYPwKZNA", + tokenID: "@dm!n", + versionID: 5.5, + ); + + Future getMyVaccine() async { + hasError = false; + _vaccineList.clear(); + await baseAppClient.post(GET_VACCINES, + onSuccess: (dynamic response, int statusCode) { + response['List_DoneVaccines'].forEach((item) { + _vaccineList.add(VaccineModel.fromJson(item)); + }); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: _vaccineModel.toJson()); + } + + Future sendEmail() async {} +} diff --git a/lib/core/viewModels/vaccine_view_model.dart b/lib/core/viewModels/vaccine_view_model.dart new file mode 100644 index 00000000..a3b6c057 --- /dev/null +++ b/lib/core/viewModels/vaccine_view_model.dart @@ -0,0 +1,25 @@ +import 'base_view_model.dart'; +import '../../locator.dart'; +import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; +import 'package:diplomaticquarterapp/core/model/vaccine/my_vaccine.dart'; +import 'package:diplomaticquarterapp/core/service/vaccine_service.dart'; + +class VaccineViewModel extends BaseViewModel { + bool hasError = false; + + VaccineService _vaccineService = locator(); + + List get vaccineList => _vaccineService.vaccineList; + + Future getVaccine() async { + hasError = false; + //_insuranceCardService.clearInsuranceCard(); + setState(ViewState.Busy); + await _vaccineService.getMyVaccine(); + if (_vaccineService.hasError) { + error = _vaccineService.error; + setState(ViewState.ErrorLocal); + } else + setState(ViewState.Idle); + } +} diff --git a/lib/locator.dart b/lib/locator.dart index 5806ca70..c56abbd7 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -17,6 +17,8 @@ import 'core/viewModels/pharmacies_view_model.dart'; import 'core/service/pharmacies_service.dart'; import 'core/service/insurance_service.dart'; import 'core/viewModels/insurance_card_View_model.dart'; +import 'core/viewModels/vaccine_view_model.dart'; +import 'core/service/vaccine_service.dart'; GetIt locator = GetIt.instance; @@ -31,6 +33,7 @@ void setupLocator() { locator.registerLazySingleton(() => RadiologyService()); locator.registerLazySingleton(() => FeedbackService()); locator.registerLazySingleton(() => InsuranceCardService()); + locator.registerFactory(() => VaccineService()); /// View Model locator.registerFactory(() => HospitalViewModel()); @@ -40,6 +43,6 @@ void setupLocator() { locator.registerFactory(() => LabsViewModel()); locator.registerFactory(() => RadiologyViewModel()); locator.registerFactory(() => FeedbackViewModel()); - + locator.registerFactory(() => VaccineViewModel()); locator.registerFactory(() => InsuranceViewModel()); } diff --git a/lib/pages/medical/medical_profile_page.dart b/lib/pages/medical/medical_profile_page.dart index 53c09727..f570750a 100644 --- a/lib/pages/medical/medical_profile_page.dart +++ b/lib/pages/medical/medical_profile_page.dart @@ -1,5 +1,5 @@ import 'dart:math'; - +import 'package:diplomaticquarterapp/pages/vaccine/my_vaccines_screen.dart'; import 'package:diplomaticquarterapp/pages/medical/prescriptions/prescriptions_home_page.dart'; import 'package:diplomaticquarterapp/pages/medical/radiology/radiology_home_page.dart'; import 'package:diplomaticquarterapp/widgets/data_display/medical/medical_profile_item.dart'; @@ -170,12 +170,11 @@ class _MedicalProfilePageState extends State { subTitle: 'Card', ), ), - ), Expanded( + ), + Expanded( flex: 1, child: InkWell( - onTap: () { - - }, + onTap: () {}, child: MedicalProfileItem( title: 'new', imagePath: 'insurance_card_icon.png', @@ -184,7 +183,25 @@ class _MedicalProfilePageState extends State { ), ) ], - ) + ), + Row( + children: [ + Expanded( + flex: 1, + child: InkWell( + onTap: () { + Navigator.push( + context, FadePage(page: MyVaccines())); + }, + child: MedicalProfileItem( + title: 'Vaccines', + imagePath: 'insurance_card_icon.png', + subTitle: 'Card', + ), + ), + ), + ], + ), ], ), ), diff --git a/lib/pages/vaccine/my_vaccines_screen.dart b/lib/pages/vaccine/my_vaccines_screen.dart new file mode 100644 index 00000000..cfb0415f --- /dev/null +++ b/lib/pages/vaccine/my_vaccines_screen.dart @@ -0,0 +1,361 @@ +import 'dart:typed_data'; +import 'dart:convert'; +import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; +import 'package:flutter/material.dart'; +import 'package:diplomaticquarterapp/config/size_config.dart'; +import 'package:flutter/cupertino.dart'; +import '../base/base_view.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; +import 'package:diplomaticquarterapp/core/viewModels/vaccine_view_model.dart'; +import 'package:diplomaticquarterapp/widgets/others/rounded_container.dart'; +import 'package:flutter_email_sender/flutter_email_sender.dart'; +import 'package:popup_box/popup_box.dart'; + +class MyVaccines extends StatefulWidget { + @override + _MyVaccinesState createState() => _MyVaccinesState(); +} + +class _MyVaccinesState extends State { + @override + Widget build(BuildContext context) { + return BaseView( + 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( + children: [ + Row( + children: [ + 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 + .imageSizeMultiplier * + 20, + fit: BoxFit.fill, + ), + ), + ], + ), + Container( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + 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), + ), + ], + ), + ), + ], + ), + ], + ), + ), + ], + ); + }), + ) + ], + ), + ), + SpaceBetweenTexts(space: 165.0), + Flexible( + child: Container( + width: 350.0, + height: 80.0, + child: Button( + label: 'CHECK VACCINE AVAILABILITY', + backgroundColor: Color(0xff9EA3A4), + ), + ), + ), + Flexible( + child: Container( + width: 350.0, + height: 80.0, + child: Button( + label: 'SEND EMAIL', + backgroundColor: Color(0xffF62426), + onTap: () async { + await PopupBox.showPopupBox( + context: context, + button: MaterialButton( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20), + ), + 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, + ), + ], + )); + }, + ), + ), + ), + ], + ), + +// child: ListView.builder( +// itemCount: model.vaccineList == null ? 0 : model.vaccineList.length, +// itemBuilder: (BuildContext context, int index) { +// return Column( +// children: [ +// RoundedContainer( +// backgroundColor: Colors.white, +// child: Column( +// children: [ +// ExpansionTile( +// title: Container( +// height: 60.0, +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// Texts('2018'), +// ], +// ), +// ), +// children: [ +// Column( +// children: [ +// Row( +// children: [ +// Column( +// children: [ +// Padding( +// padding: EdgeInsets.symmetric( +// horizontal: 20.0, vertical: 20.0), +// child: Container( +// child: Image.network( +// model.vaccineList[index] +// .doctorImageURL, +// height: SizeConfig +// .imageSizeMultiplier * +// 23, +// width: SizeConfig +// .imageSizeMultiplier * +// 20, +// fit: BoxFit.fill, +// colorBlendMode: +// BlendMode.hardLight, +// ), +// ), +// ) +// ], +// ), +// Container( +// child: Column( +// mainAxisAlignment: +// MainAxisAlignment.start, +// crossAxisAlignment: +// CrossAxisAlignment.start, +// children: [ +// Text( +// model.vaccineList[index] +// .doctorTitle + +// model.vaccineList[index] +// .doctorName, +// style: TextStyle( +// fontWeight: FontWeight.w900, +// fontSize: 17.5), +// ), +// Text( +// model +// .vaccineList[index].projectName, +// style: TextStyle( +// fontSize: 19.0, +// letterSpacing: 0.3, +// color: Colors.grey, +// fontWeight: FontWeight.bold), +// ), +// Text( +// model +// .vaccineList[index].vaccineName, +// style: TextStyle( +// fontSize: 19.0, +// color: Colors.grey, +// fontWeight: FontWeight.bold), +// ), +// Text( +// 'Date Taken ' + +// convertDateFormat(model +// .vaccineList[index] +// .invoiceDate), +// style: TextStyle( +// fontSize: 19.0, +// color: Colors.grey, +// fontWeight: FontWeight.bold), +// ), +// ], +// ), +// ), +// ], +// ), +// ], +// ), +// ], +// ), +// ], +// ), +// ), +// Container( +// width: 300, +// child: Button( +// label: 'CHECK VACCINE AVAILABILITY', +// backgroundColor: Color(0xff9EA3A4), +// ), +// ), +// Container( +// width: 300, +// child: Button( +// label: 'SEND EMAIL', +// backgroundColor: Color(0xff9EA3A4), +// ), +// ), +// ], +// ); +// }, +// ), + ), + ), + ); + } + + convertDateFormat(String Date) { + const start = "/Date("; + const end = "+0300)"; + + final startIndex = Date.indexOf(start); + final endIndex = Date.indexOf(end, startIndex + start.length); + + var date = new DateTime.fromMillisecondsSinceEpoch( + int.parse(Date.substring(startIndex + start.length, endIndex))); + String newDate = date.year.toString() + + "-" + + date.month.toString().padLeft(2, '0') + + "-" + + date.day.toString().padLeft(2, '0'); + + return newDate.toString(); + } + + emailSender() async { + final Email email = Email( + body: 'Email body', + subject: 'Email subject', + recipients: ['example@example.com'], + cc: ['cc@example.com'], + bcc: ['bcc@example.com'], + attachmentPaths: ['/path/to/attachment.zip'], + isHTML: false, + ); + + await FlutterEmailSender.send(email); + } +} + +class SpaceBetweenTexts extends StatelessWidget { + final double space; + SpaceBetweenTexts({this.space}); + + @override + Widget build(BuildContext context) { + return SizedBox( + height: space, + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index e2735c4f..c6bf3b03 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -83,6 +83,14 @@ dependencies: #hijri hijri: ^2.0.3 + #Email Sender + flutter_email_sender: ^3.0.1 + + #Popup_window + popup_box: ^0.1.0 + + +