From 2455f48fe1ce68e94fd5dad6e521cd8e6ab3a885 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 15 Aug 2023 10:03:18 +0300 Subject: [PATCH] View medical report done --- lib/config/config.dart | 1 + lib/core/service/medical/reports_service.dart | 30 +++++++++++ .../medical/reports/report_list_widget.dart | 54 +++++++++++++++++-- pubspec.yaml | 2 + 4 files changed, 83 insertions(+), 4 deletions(-) diff --git a/lib/config/config.dart b/lib/config/config.dart index 73b647bf..17840c50 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -184,6 +184,7 @@ var REPORTS = 'Services/Doctors.svc/REST/GetPatientMedicalReportStatusInfo'; var INSERT_REQUEST_FOR_MEDICAL_REPORT = 'Services/Doctors.svc/REST/InsertRequestForMedicalReport'; var SEND_MEDICAL_REPORT_EMAIL = 'Services/Notifications.svc/REST/SendMedicalReportEmail'; var GET_INPATIENT_ADMISSIONS = 'Services/inps.svc/REST/getAdmissionForMedicalReport'; +var GET_MEDICAL_REPORT_PDF = 'Services/inps.svc/REST/getMedicalReportPDF'; ///Rate // var IS_LAST_APPOITMENT_RATED = 'Services/Doctors.svc/REST/IsLastAppoitmentRated'; diff --git a/lib/core/service/medical/reports_service.dart b/lib/core/service/medical/reports_service.dart index f9a0041c..9f8bfb45 100644 --- a/lib/core/service/medical/reports_service.dart +++ b/lib/core/service/medical/reports_service.dart @@ -177,4 +177,34 @@ class ReportsService extends BaseService { }, body: body); return response; } + + Future getMedicalReportPDF(String projectName, String clinicName, String doctorName, String requestDate, String invoiceNo, int projectID, String stamp, String setupID) async { + Map body = new Map(); + body['SetupID'] = setupID; + body['PrintDate'] = requestDate; + body['ProcedureID'] = "05005009"; + body['Reporttype'] = "MEDICAL REPORT"; + body['stamp'] = stamp; + body['To'] = user.emailAddress; + body['DateofBirth'] = user.dateofBirth; + body['PatientIditificationNum'] = user.patientIdentificationNo; + body['PatientMobileNumber'] = user.mobileNumber; + body['PatientName'] = user.firstName + " " + user.lastName; + body['ProjectName'] = projectName; + body['ClinicName'] = clinicName; + body['ProjectID'] = projectID; + body['InvoiceNo'] = invoiceNo; + body['PrintedByName'] = user.firstName + " " + user.lastName; + + dynamic response; + + hasError = false; + await baseAppClient.post(GET_MEDICAL_REPORT_PDF, onSuccess: (dynamic res, int statusCode) { + response = res; + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: body); + return response; + } } diff --git a/lib/pages/medical/reports/report_list_widget.dart b/lib/pages/medical/reports/report_list_widget.dart index 5c62de22..016fad79 100644 --- a/lib/pages/medical/reports/report_list_widget.dart +++ b/lib/pages/medical/reports/report_list_widget.dart @@ -1,3 +1,7 @@ +import 'dart:convert'; +import 'dart:io'; +import 'dart:typed_data'; + import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/core/model/reports/Reports.dart'; import 'package:diplomaticquarterapp/core/service/medical/reports_service.dart'; @@ -14,6 +18,8 @@ import 'package:diplomaticquarterapp/widgets/dialogs/confirm_send_email_dialog.d import 'package:diplomaticquarterapp/widgets/my_rich_text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:open_file/open_file.dart'; +import 'package:path_provider/path_provider.dart'; import 'package:provider/provider.dart'; import 'package:rating_bar/rating_bar.dart'; @@ -111,10 +117,22 @@ class ReportListWidget extends StatelessWidget { if (reportList[index].status == 2) Row( children: [ - Padding( - padding: const EdgeInsets.only(right: 11.0, left: 11.0), - child: Text(TranslationBase.of(context).viewReport, - style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, fontStyle: FontStyle.italic, color: CustomColors.accentColor, letterSpacing: -0.48, height: 18 / 12, decoration: TextDecoration.underline)), + InkWell( + onTap: () { + getMedicalReportPDF(report); + }, + child: Padding( + padding: const EdgeInsets.only(right: 11.0, left: 11.0), + child: Text(TranslationBase.of(context).viewReport, + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + fontStyle: FontStyle.italic, + color: CustomColors.accentColor, + letterSpacing: -0.48, + height: 18 / 12, + decoration: TextDecoration.underline)), + ), ), IconButton( icon: Icon(Icons.email), @@ -155,6 +173,26 @@ class ReportListWidget extends StatelessWidget { ); } + void getMedicalReportPDF(Reports report) { + GifLoaderDialogUtils.showMyDialog(AppGlobal.context); + ReportsService _reportsService = locator(); + _reportsService + .getMedicalReportPDF(report.projectName, report.clinicDescription, report.doctorName, DateUtil.convertDateToString(report.requestDate), report.invoiceNo.toString(), report.projectID, + DateUtil.convertDateToString(report.requestDate), report.setupId) + .then((value) async { + GifLoaderDialogUtils.hideDialog(AppGlobal.context); + try { + String path = await _createFileFromString(value["MedicalReportBase64"], "pdf"); + OpenFile.open(path); + } catch (ex) { + AppToast.showErrorToast(message: "Cannot open file."); + } + }).catchError((err) { + GifLoaderDialogUtils.hideDialog(AppGlobal.context); + print(err); + }); + } + sendReportEmail(Reports report) { GifLoaderDialogUtils.showMyDialog(AppGlobal.context); ReportsService _reportsService = locator(); @@ -169,4 +207,12 @@ class ReportListWidget extends StatelessWidget { print(err); }); } + + Future _createFileFromString(String encodedStr, String ext) async { + Uint8List bytes = base64.decode(encodedStr); + String dir = (await getApplicationDocumentsDirectory()).path; + File file = File("$dir/" + DateTime.now().millisecondsSinceEpoch.toString() + "." + ext); + await file.writeAsBytes(bytes); + return file.path; + } } diff --git a/pubspec.yaml b/pubspec.yaml index c4265c47..c7bbbdf2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -207,6 +207,8 @@ dependencies: sms_otp_auto_verify: ^2.1.0 flutter_ios_voip_kit: ^0.0.5 google_api_availability: ^3.0.1 + open_file: ^3.2.1 + path_provider: ^2.0.8 # flutter_callkit_incoming: ^1.0.3+3 # firebase_core: 1.12.0