From a1c276b16bac39b7f7c24606b2ab1ff716a639a2 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Wed, 19 Aug 2026 15:27:28 +0300 Subject: [PATCH] VIDA 3 attachments implemented --- assets/langs/ar-SA.json | 3 +- assets/langs/en-US.json | 3 +- lib/core/api_consts.dart | 2 + lib/features/lab/lab_repo.dart | 52 ++- lib/features/lab/lab_view_model.dart | 29 ++ .../lab/models/resp_models/lab_result.dart | 375 +++++++++++++++--- ..._lab_result_attachment_response_model.dart | 44 ++ lib/generated/locale_keys.g.dart | 1 + .../lab_result_via_clinic/LabResultList.dart | 4 - .../lab_order_result_item.dart | 73 +++- 10 files changed, 515 insertions(+), 71 deletions(-) create mode 100644 lib/features/lab/models/resp_models/patient_lab_result_attachment_response_model.dart diff --git a/assets/langs/ar-SA.json b/assets/langs/ar-SA.json index c025a030..8c372f0c 100644 --- a/assets/langs/ar-SA.json +++ b/assets/langs/ar-SA.json @@ -1969,5 +1969,6 @@ "hide": "إخفاء", "viewPatientQR": "عرض رمز الاستجابة السريعة للمريض", "patientQR": "رمز الاستجابة السريعة للمريض", - "forText": "عن" + "forText": "عن", + "viewAttachment": "المرفقات" } diff --git a/assets/langs/en-US.json b/assets/langs/en-US.json index 1f006d2c..797c63b3 100644 --- a/assets/langs/en-US.json +++ b/assets/langs/en-US.json @@ -1959,7 +1959,8 @@ "hide": "Hide", "viewPatientQR": "View Patient QR Code", "patientQR": "Patient QR Code", - "forText": "For" + "forText": "For", + "viewAttachment": "Attachments" } diff --git a/lib/core/api_consts.dart b/lib/core/api_consts.dart index 7d3b97d4..2ca3aff0 100644 --- a/lib/core/api_consts.dart +++ b/lib/core/api_consts.dart @@ -1023,6 +1023,8 @@ const DOWNLOAD_PHARMACY_INVOICE_PDF = 'Services/Notifications.svc/REST/DownloadI const GET_APPOINTMENT_PARKING_QR = 'Services/outps.svc/rest/pms_getParkingTicketByAppointmentNo'; +const GET_LAB_RESULT_PDF_ATTACHMENT = 'Services/Patients.svc/REST/GetVidaLabResultAttachment'; + class ApiKeyConstants { static final String googleMapsApiKey = 'AIzaSyB6TERnxIr0yJ3qG4ULBZbu0sAD4tGqtng'; } diff --git a/lib/features/lab/lab_repo.dart b/lib/features/lab/lab_repo.dart index 94679047..5d040538 100644 --- a/lib/features/lab/lab_repo.dart +++ b/lib/features/lab/lab_repo.dart @@ -8,6 +8,7 @@ import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/features/lab/models/resp_models/ai_overview_labresults_by_ai_model.dart'; import 'package:hmg_patient_app_new/features/lab/models/resp_models/patient_lab_order_response_by_ai_model.dart'; import 'package:hmg_patient_app_new/features/lab/models/resp_models/patient_lab_orders_response_model.dart'; +import 'package:hmg_patient_app_new/features/lab/models/resp_models/patient_lab_result_attachment_response_model.dart'; import 'package:hmg_patient_app_new/features/lab/models/resp_models/patient_lab_special_result.dart'; import 'package:hmg_patient_app_new/services/logger_service.dart'; @@ -29,7 +30,10 @@ abstract class LabRepo { Future>> getPatientAiOverViewLabOrders({required int langId, required dynamic payload}); Future>> getPatientAiOverViewLabOrder(var payloa); + Map> groupLabResultsByPackageName(List labResults); + + Future>> getLabResultAttachmentPDF({required LabResult labResult, required int selectedIndex}); } class LabRepoImp implements LabRepo { @@ -57,8 +61,8 @@ class LabRepoImp implements LabRepo { // Group results by package name for (var labResult in labResults) { - String packageName = labResult.PackageName ?? 'Unknown Package'; - + String packageName = labResult.packageName ?? 'Unknown Package'; + if (groupedResults.containsKey(packageName)) { // Package name exists, add to existing list groupedResults[packageName]!.add(labResult); @@ -450,4 +454,48 @@ class LabRepoImp implements LabRepo { return Left(UnknownFailure(e.toString())); } } + + @override + Future>> getLabResultAttachmentPDF({required LabResult labResult, required selectedIndex}) async { + Map mapDevice = { + "ProjectID": labResult.projectID, + "SetupID": labResult.setupID, + "LabAccessionNumber": labResult.accessionNo, + "FileName": labResult.fileNameWithExtension, + "Lang": Utils.appState.isArabic() ? "ar" : "en", + "Internationalization": "false", + "FileHash": Utils.isVidaPlusProject(int.parse(labResult.projectID!)) ? [labResult.uploadedDocuments?[selectedIndex]] : [], + }; + + try { + GenericApiModel? apiResponse; + Failure? failure; + await apiClient.post( + GET_LAB_RESULT_PDF_ATTACHMENT, + body: mapDevice, + onFailure: (error, statusCode, {messageStatus, failureType}) { + failure = failureType; + }, + onSuccess: (response, statusCode, {messageStatus, errorMessage}) { + try { + PatientLabResultPDFAttachmentResponse? labResultAttachmentResponse = PatientLabResultPDFAttachmentResponse.fromJson(response['GetVidaLabAttachment']); + + apiResponse = GenericApiModel( + messageStatus: messageStatus, + statusCode: statusCode, + errorMessage: null, + data: labResultAttachmentResponse.data?.first.base64Content, + ); + } catch (e) { + failure = DataParsingFailure(e.toString()); + } + }, + ); + if (failure != null) return Left(failure!); + if (apiResponse == null) return Left(ServerFailure("Unknown error")); + return Right(apiResponse!); + } catch (e) { + return Left(UnknownFailure(e.toString())); + } + } } diff --git a/lib/features/lab/lab_view_model.dart b/lib/features/lab/lab_view_model.dart index 1c25ef9d..63b64ba0 100644 --- a/lib/features/lab/lab_view_model.dart +++ b/lib/features/lab/lab_view_model.dart @@ -95,6 +95,8 @@ class LabViewModel extends ChangeNotifier { bool isLabAIAnalysisNeedsToBeShown = true; bool isLabResultsHistoryShowMore = false; + String patientLabResultAttachmentPDFBase64 = ""; + LabViewModel({required this.labRepo, required this.errorHandlerService, required this.navigationService}); initLabProvider() { @@ -148,6 +150,8 @@ class LabViewModel extends ChangeNotifier { uniqueTests.clear(); labOrderTests.clear(); uniqueTests = {}; + filteredUniqueTestsList.clear(); + filteredIndexedCharacterForUniqueTest.clear(); patientLabOrdersByClinic.clear(); patientLabOrdersByHospital.clear(); patientLabOrdersViewList.clear(); @@ -230,6 +234,31 @@ class LabViewModel extends ChangeNotifier { ); } + Future getLabResultAttachmentPDF({required LabResult labResult, required selectedIndex, Function(dynamic)? onSuccess, Function(String)? onError}) async { + final result = await labRepo.getLabResultAttachmentPDF(labResult: labResult, selectedIndex: selectedIndex); + + result.fold( + (failure) async => await errorHandlerService.handleError( + failure: failure, + onOkPressed: () { + onError!(failure.message); + }, + ), + (apiResponse) { + if (apiResponse.messageStatus == 2) { + onError!(apiResponse.errorMessage!); + // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); + } else if (apiResponse.messageStatus == 1) { + patientLabResultAttachmentPDFBase64 = apiResponse.data!; + notifyListeners(); + if (onSuccess != null) { + onSuccess(apiResponse); + } + } + }, + ); + } + filterSuggestions() { final List labels = patientLabOrders.expand((order) => order.testDetails ?? []).map((detail) => detail.description).whereType().toList(); _labSuggestionsList = labels.toSet().toList(); diff --git a/lib/features/lab/models/resp_models/lab_result.dart b/lib/features/lab/models/resp_models/lab_result.dart index 78be004a..f5f6f4b9 100644 --- a/lib/features/lab/models/resp_models/lab_result.dart +++ b/lib/features/lab/models/resp_models/lab_result.dart @@ -1,127 +1,236 @@ class LabResult { + String? accessionNo; + String? calculatedResultFlag; + dynamic changeResult; + String? collectedOn; + dynamic criticalHigh; + dynamic criticalLow; String? description; dynamic femaleInterpretativeData; + String? fileNameWithExtension; int? gender; + dynamic genderDesc; + String? header; + dynamic interpretativeData; + String? invoiceType; + bool? isCertificateAllowed; + bool? isLabTestAttachment; + bool? isPregnant; + bool? isVisibleComponent; int? lineItemNo; dynamic maleInterpretativeData; - dynamic notes; + dynamic needMedicalVerificationForAbnResult; + String? notes; + int? orderLineItemNo; + int? orderNo; String? packageID; + String? packageName; + String? packageShortDescription; int? patientID; String? projectID; + String? receivedOn; String? referanceRange; + dynamic referenceHigh; + dynamic referenceLow; + String? registeredOn; + String? reportedOn; + String? resultSymbol; + int? resultTypeID; String? resultValue; + int? resultValueBasedLineItemNo; + String? resultValueFlag; + String? rptTestCode; String? sampleCollectedOn; String? sampleReceivedOn; String? setupID; + int? status; + dynamic statusDesc; + dynamic statusDescription; + String? subHeader; dynamic superVerifiedOn; String? testCode; + int? testID; + String? testShortDescription; String? uOM; + List? uploadedDocuments; String? verifiedOn; - String? verifiedOnDateTime; - String? changeResult; - String? calculatedResultFlag; - String? criticalHigh; - String? referenceHigh; - String? criticalLow; - String? referenceLow; - num? resultTypeID; - String? packageShortDescription; - int? testId; - String? testShortDescription; - String? PackageName; + dynamic verifiedOnDateTime; LabResult( - {this.description, - this.femaleInterpretativeData, - this.gender, - this.lineItemNo, - this.maleInterpretativeData, - this.notes, - this.packageID, - this.patientID, - this.projectID, - this.referanceRange, - this.resultValue, - this.sampleCollectedOn, - this.sampleReceivedOn, + {this.accessionNo, + this.calculatedResultFlag, + this.changeResult, + this.collectedOn, + this.criticalHigh, + this.criticalLow, + this.description, + this.femaleInterpretativeData, + this.fileNameWithExtension, + this.gender, + this.genderDesc, + this.header, + this.interpretativeData, + this.invoiceType, + this.isCertificateAllowed, + this.isLabTestAttachment, + this.isPregnant, + this.isVisibleComponent, + this.lineItemNo, + this.maleInterpretativeData, + this.needMedicalVerificationForAbnResult, + this.notes, + this.orderLineItemNo, + this.orderNo, + this.packageID, + this.packageName, + this.packageShortDescription, + this.patientID, + this.projectID, + this.receivedOn, + this.referanceRange, + this.referenceHigh, + this.referenceLow, + this.registeredOn, + this.reportedOn, + this.resultSymbol, + this.resultTypeID, + this.resultValue, + this.resultValueBasedLineItemNo, + this.resultValueFlag, + this.rptTestCode, + this.sampleCollectedOn, + this.sampleReceivedOn, this.setupID, - this.superVerifiedOn, - this.testCode, - this.uOM, - this.verifiedOn, - this.calculatedResultFlag, - this.verifiedOnDateTime, - this.criticalHigh, - this.referenceHigh, - this.criticalLow, - this.referenceLow, - this.testId, - this.testShortDescription, - this.PackageName - }); + this.status, + this.statusDesc, + this.statusDescription, + this.subHeader, + this.superVerifiedOn, + this.testCode, + this.testID, + this.testShortDescription, + this.uOM, + this.uploadedDocuments, + this.verifiedOn, + this.verifiedOnDateTime}); LabResult.fromJson(Map json) { + accessionNo = json['AccessionNo']; + calculatedResultFlag = json['CalculatedResultFlag']; + changeResult = json['ChangeResult']; + collectedOn = json['CollectedOn']; + criticalHigh = json['CriticalHigh']; + criticalLow = json['CriticalLow']; description = json['Description']; femaleInterpretativeData = json['FemaleInterpretativeData']; + fileNameWithExtension = json['FileNameWithExtension']; gender = json['Gender']; + genderDesc = json['GenderDesc']; + header = json['Header']; + interpretativeData = json['InterpretativeData']; + invoiceType = json['InvoiceType']; + isCertificateAllowed = json['IsCertificateAllowed']; + isLabTestAttachment = json['IsLabTestAttachment']; + isPregnant = json['IsPregnant']; + isVisibleComponent = json['IsVisibleComponent']; lineItemNo = json['LineItemNo']; maleInterpretativeData = json['MaleInterpretativeData']; + needMedicalVerificationForAbnResult = json['NeedMedicalVerificationForAbnResult']; notes = json['Notes']; + orderLineItemNo = json['OrderLineItemNo']; + orderNo = json['OrderNo']; packageID = json['PackageID']; + packageName = json['PackageName']; + packageShortDescription = json['PackageShortDescription']; patientID = json['PatientID']; projectID = json['ProjectID']; + receivedOn = json['ReceivedOn']; referanceRange = json['ReferanceRange']; + referenceHigh = json['ReferenceHigh']; + referenceLow = json['ReferenceLow']; + registeredOn = json['RegisteredOn']; + reportedOn = json['ReportedOn']; + resultSymbol = json['ResultSymbol']; + resultTypeID = json['ResultTypeID']; resultValue = json['ResultValue']; + resultValueBasedLineItemNo = json['ResultValueBasedLineItemNo']; + resultValueFlag = json['ResultValueFlag']; + rptTestCode = json['RptTestCode']; sampleCollectedOn = json['SampleCollectedOn']; sampleReceivedOn = json['SampleReceivedOn']; setupID = json['SetupID']; + status = json['Status']; + statusDesc = json['StatusDesc']; + statusDescription = json['StatusDescription']; + subHeader = json['SubHeader']; superVerifiedOn = json['SuperVerifiedOn']; testCode = json['TestCode']; + testID = json['TestID']; + testShortDescription = json['TestShortDescription']; uOM = json['UOM']; + uploadedDocuments = json['UploadedDocuments'] ?? []; verifiedOn = json['VerifiedOn']; verifiedOnDateTime = json['VerifiedOnDateTime']; - changeResult = json['ChangeResult']; - calculatedResultFlag = json['CalculatedResultFlag']; - criticalHigh = json['CriticalHigh']; - referenceHigh = json['ReferenceHigh']; - criticalLow = json['CriticalLow']; - referenceLow = json['ReferenceLow']; - packageShortDescription = json['PackageShortDescription']; - resultTypeID = json['ResultTypeID']; - testId = json['TestID']; - testShortDescription = json['TestShortDescription']; - PackageName = json['PackageName']; } Map toJson() { final Map data = new Map(); + data['AccessionNo'] = this.accessionNo; + data['CalculatedResultFlag'] = this.calculatedResultFlag; + data['ChangeResult'] = this.changeResult; + data['CollectedOn'] = this.collectedOn; + data['CriticalHigh'] = this.criticalHigh; + data['CriticalLow'] = this.criticalLow; data['Description'] = this.description; data['FemaleInterpretativeData'] = this.femaleInterpretativeData; + data['FileNameWithExtension'] = this.fileNameWithExtension; data['Gender'] = this.gender; + data['GenderDesc'] = this.genderDesc; + data['Header'] = this.header; + data['InterpretativeData'] = this.interpretativeData; + data['InvoiceType'] = this.invoiceType; + data['IsCertificateAllowed'] = this.isCertificateAllowed; + data['IsLabTestAttachment'] = this.isLabTestAttachment; + data['IsPregnant'] = this.isPregnant; + data['IsVisibleComponent'] = this.isVisibleComponent; data['LineItemNo'] = this.lineItemNo; data['MaleInterpretativeData'] = this.maleInterpretativeData; + data['NeedMedicalVerificationForAbnResult'] = this.needMedicalVerificationForAbnResult; data['Notes'] = this.notes; + data['OrderLineItemNo'] = this.orderLineItemNo; + data['OrderNo'] = this.orderNo; data['PackageID'] = this.packageID; + data['PackageName'] = this.packageName; + data['PackageShortDescription'] = this.packageShortDescription; data['PatientID'] = this.patientID; data['ProjectID'] = this.projectID; + data['ReceivedOn'] = this.receivedOn; data['ReferanceRange'] = this.referanceRange; + data['ReferenceHigh'] = this.referenceHigh; + data['ReferenceLow'] = this.referenceLow; + data['RegisteredOn'] = this.registeredOn; + data['ReportedOn'] = this.reportedOn; + data['ResultSymbol'] = this.resultSymbol; + data['ResultTypeID'] = this.resultTypeID; data['ResultValue'] = this.resultValue; + data['ResultValueBasedLineItemNo'] = this.resultValueBasedLineItemNo; + data['ResultValueFlag'] = this.resultValueFlag; + data['RptTestCode'] = this.rptTestCode; data['SampleCollectedOn'] = this.sampleCollectedOn; data['SampleReceivedOn'] = this.sampleReceivedOn; data['SetupID'] = this.setupID; + data['Status'] = this.status; + data['StatusDesc'] = this.statusDesc; + data['StatusDescription'] = this.statusDescription; + data['SubHeader'] = this.subHeader; data['SuperVerifiedOn'] = this.superVerifiedOn; data['TestCode'] = this.testCode; + data['TestID'] = this.testID; + data['TestShortDescription'] = this.testShortDescription; data['UOM'] = this.uOM; + data['UploadedDocuments'] = this.uploadedDocuments; data['VerifiedOn'] = this.verifiedOn; data['VerifiedOnDateTime'] = this.verifiedOnDateTime; - data['ChangeResult'] = this.changeResult; - data['CriticalHigh'] = this.criticalHigh; - data['ReferenceHigh'] = this.referenceHigh; - data['CriticalLow'] = this.criticalLow; - data['ReferenceLow'] = this.referenceLow; - data['TestID'] = this.testId; - data['TestShortDescription'] = this.testShortDescription; - data['PackageName'] = this.PackageName; return data; } @@ -145,3 +254,151 @@ class LabResult { return 'LabOrderResult(flag: $calculatedResultFlag, value: $resultValue, verifiedOn: $verifiedOnDateTime)'; } } + +// class LabResult { +// String? description; +// dynamic femaleInterpretativeData; +// int? gender; +// int? lineItemNo; +// dynamic maleInterpretativeData; +// dynamic notes; +// String? packageID; +// int? patientID; +// String? projectID; +// String? referanceRange; +// String? resultValue; +// String? sampleCollectedOn; +// String? sampleReceivedOn; +// String? setupID; +// dynamic superVerifiedOn; +// String? testCode; +// String? uOM; +// String? verifiedOn; +// String? verifiedOnDateTime; +// String? changeResult; +// String? calculatedResultFlag; +// String? criticalHigh; +// String? referenceHigh; +// String? criticalLow; +// String? referenceLow; +// num? resultTypeID; +// String? packageShortDescription; +// int? testId; +// String? testShortDescription; +// String? PackageName; +// +// LabResult( +// {this.description, +// this.femaleInterpretativeData, +// this.gender, +// this.lineItemNo, +// this.maleInterpretativeData, +// this.notes, +// this.packageID, +// this.patientID, +// this.projectID, +// this.referanceRange, +// this.resultValue, +// this.sampleCollectedOn, +// this.sampleReceivedOn, +// this.setupID, +// this.superVerifiedOn, +// this.testCode, +// this.uOM, +// this.verifiedOn, +// this.calculatedResultFlag, +// this.verifiedOnDateTime, +// this.criticalHigh, +// this.referenceHigh, +// this.criticalLow, +// this.referenceLow, +// this.testId, +// this.testShortDescription, +// this.PackageName +// }); +// +// LabResult.fromJson(Map json) { +// description = json['Description']; +// femaleInterpretativeData = json['FemaleInterpretativeData']; +// gender = json['Gender']; +// lineItemNo = json['LineItemNo']; +// maleInterpretativeData = json['MaleInterpretativeData']; +// notes = json['Notes']; +// packageID = json['PackageID']; +// patientID = json['PatientID']; +// projectID = json['ProjectID']; +// referanceRange = json['ReferanceRange']; +// resultValue = json['ResultValue']; +// sampleCollectedOn = json['SampleCollectedOn']; +// sampleReceivedOn = json['SampleReceivedOn']; +// setupID = json['SetupID']; +// superVerifiedOn = json['SuperVerifiedOn']; +// testCode = json['TestCode']; +// uOM = json['UOM']; +// verifiedOn = json['VerifiedOn']; +// verifiedOnDateTime = json['VerifiedOnDateTime']; +// changeResult = json['ChangeResult']; +// calculatedResultFlag = json['CalculatedResultFlag']; +// criticalHigh = json['CriticalHigh']; +// referenceHigh = json['ReferenceHigh']; +// criticalLow = json['CriticalLow']; +// referenceLow = json['ReferenceLow']; +// packageShortDescription = json['PackageShortDescription']; +// resultTypeID = json['ResultTypeID']; +// testId = json['TestID']; +// testShortDescription = json['TestShortDescription']; +// PackageName = json['PackageName']; +// } +// +// Map toJson() { +// final Map data = new Map(); +// data['Description'] = this.description; +// data['FemaleInterpretativeData'] = this.femaleInterpretativeData; +// data['Gender'] = this.gender; +// data['LineItemNo'] = this.lineItemNo; +// data['MaleInterpretativeData'] = this.maleInterpretativeData; +// data['Notes'] = this.notes; +// data['PackageID'] = this.packageID; +// data['PatientID'] = this.patientID; +// data['ProjectID'] = this.projectID; +// data['ReferanceRange'] = this.referanceRange; +// data['ResultValue'] = this.resultValue; +// data['SampleCollectedOn'] = this.sampleCollectedOn; +// data['SampleReceivedOn'] = this.sampleReceivedOn; +// data['SetupID'] = this.setupID; +// data['SuperVerifiedOn'] = this.superVerifiedOn; +// data['TestCode'] = this.testCode; +// data['UOM'] = this.uOM; +// data['VerifiedOn'] = this.verifiedOn; +// data['VerifiedOnDateTime'] = this.verifiedOnDateTime; +// data['ChangeResult'] = this.changeResult; +// data['CriticalHigh'] = this.criticalHigh; +// data['ReferenceHigh'] = this.referenceHigh; +// data['CriticalLow'] = this.criticalLow; +// data['ReferenceLow'] = this.referenceLow; +// data['TestID'] = this.testId; +// data['TestShortDescription'] = this.testShortDescription; +// data['PackageName'] = this.PackageName; +// return data; +// } +// +// bool checkIfGraphShouldBeDisplayed(){ +// if (resultTypeID == null) return false; +// if (resultTypeID == 6) return false; +// if (referanceRange == null || referanceRange == "" || referanceRange == "\n") return false; +// bool isDigit = RegExp(r"\\d+").hasMatch("$resultValue"); +// if(isDigit) return true; +// try { +// num.parse(resultValue ?? ""); +// } catch (e) { +// return false; +// } +// +// return true; +// } +// +// @override +// String toString() { +// return 'LabOrderResult(flag: $calculatedResultFlag, value: $resultValue, verifiedOn: $verifiedOnDateTime)'; +// } +// } diff --git a/lib/features/lab/models/resp_models/patient_lab_result_attachment_response_model.dart b/lib/features/lab/models/resp_models/patient_lab_result_attachment_response_model.dart new file mode 100644 index 00000000..37601a5b --- /dev/null +++ b/lib/features/lab/models/resp_models/patient_lab_result_attachment_response_model.dart @@ -0,0 +1,44 @@ +class PatientLabResultPDFAttachmentResponse { + List? data; + + PatientLabResultPDFAttachmentResponse({this.data}); + + PatientLabResultPDFAttachmentResponse.fromJson(Map json) { + if (json['data'] != null) { + data = []; + json['data'].forEach((v) { + data!.add(new Data.fromJson(v)); + }); + } + } + + Map toJson() { + final Map data = new Map(); + if (this.data != null) { + data['data'] = this.data!.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class Data { + String? base64Content; + String? fileName; + int? fileSize; + + Data({this.base64Content, this.fileName, this.fileSize}); + + Data.fromJson(Map json) { + base64Content = json['base64Content']; + fileName = json['fileName']; + fileSize = json['fileSize']; + } + + Map toJson() { + final Map data = new Map(); + data['base64Content'] = base64Content; + data['fileName'] = fileName; + data['fileSize'] = fileSize; + return data; + } +} diff --git a/lib/generated/locale_keys.g.dart b/lib/generated/locale_keys.g.dart index 536f3355..5f75d01a 100644 --- a/lib/generated/locale_keys.g.dart +++ b/lib/generated/locale_keys.g.dart @@ -1951,5 +1951,6 @@ abstract class LocaleKeys { static const viewPatientQR = 'viewPatientQR'; static const patientQR = 'patientQR'; static const forText = 'forText'; + static const viewAttachment = 'viewAttachment'; } diff --git a/lib/presentation/lab/lab_result_via_clinic/LabResultList.dart b/lib/presentation/lab/lab_result_via_clinic/LabResultList.dart index 88b9cb6a..934f8337 100644 --- a/lib/presentation/lab/lab_result_via_clinic/LabResultList.dart +++ b/lib/presentation/lab/lab_result_via_clinic/LabResultList.dart @@ -1,8 +1,5 @@ -import 'dart:ui' as ui; - import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; -import 'package:hmg_patient_app_new/core/app_state.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; import 'package:hmg_patient_app_new/features/lab/lab_view_model.dart'; @@ -11,7 +8,6 @@ import 'package:hmg_patient_app_new/presentation/lab/lab_result_via_clinic/lab_o import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:hmg_patient_app_new/widgets/date_range_selector/viewmodel/date_range_view_model.dart'; import 'package:provider/provider.dart'; -import '../../../core/dependencies.dart' show getIt; import '../../../core/utils/size_utils.dart' show ResponsiveExtension; import '../../../generated/locale_keys.g.dart' show LocaleKeys; diff --git a/lib/presentation/lab/lab_result_via_clinic/lab_order_result_item.dart b/lib/presentation/lab/lab_result_via_clinic/lab_order_result_item.dart index 2f6ee667..2c4a7fb9 100644 --- a/lib/presentation/lab/lab_result_via_clinic/lab_order_result_item.dart +++ b/lib/presentation/lab/lab_result_via_clinic/lab_order_result_item.dart @@ -1,5 +1,6 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; +import 'package:get_it/get_it.dart'; import 'package:hmg_patient_app_new/core/app_assets.dart'; import 'package:hmg_patient_app_new/core/app_export.dart'; import 'package:hmg_patient_app_new/core/app_state.dart'; @@ -11,9 +12,12 @@ import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; import 'package:hmg_patient_app_new/features/lab/lab_view_model.dart' show LabViewModel; import 'package:hmg_patient_app_new/features/lab/models/resp_models/lab_result.dart'; import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; +import 'package:hmg_patient_app_new/services/navigation_service.dart'; import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart'; import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart'; +import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart'; +import 'package:open_filex/open_filex.dart'; import 'package:provider/provider.dart'; import 'dart:ui' as ui; @@ -116,9 +120,11 @@ class LabOrderResultItem extends StatelessWidget { SizedBox(height: 12.h), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.end, + mainAxisSize: MainAxisSize.max, children: [ Flexible( - flex: 2, + flex: (tests?.isLabTestAttachment ?? false) ? 1 : 2, child: Visibility( visible: tests?.checkIfGraphShouldBeDisplayed() == true, child: Column( @@ -134,7 +140,7 @@ class LabOrderResultItem extends StatelessWidget { ), ), Flexible( - flex:2, + flex: 2, child: Visibility( visible: tests?.checkIfGraphShouldBeDisplayed() == true, child: CustomButton( @@ -148,14 +154,73 @@ class LabOrderResultItem extends StatelessWidget { backgroundColor: AppColors.infoColor.withAlpha(20), borderColor: AppColors.infoColor.withAlpha(0), textColor: AppColors.infoColor, - fontSize: 14, + fontSize: 13.f, fontWeight: FontWeight.w600, - borderRadius: 12, + borderRadius: 12.r, padding: EdgeInsets.fromLTRB(10, 0, 10, 0), height: 40.h, ), ), ), + if (tests?.isLabTestAttachment ?? false) + Flexible( + flex: 2, + child: Visibility( + visible: tests?.checkIfGraphShouldBeDisplayed() == true, + child: CustomButton( + icon: AppAssets.document, + iconColor: AppColors.primaryRedColor, + iconSize: 16.h, + text: LocaleKeys.viewAttachment.tr(context: context), + onPressed: () async { + if (Utils.isVidaPlusProject(int.parse(tests!.projectID!))) { + } else { + LoaderBottomSheet.showLoader(loadingText: LocaleKeys.generatingReport.tr(context: context)); + await getIt + .get() + .getLabResultAttachmentPDF( + labResult: tests!, + selectedIndex: 0, + onError: (err) { + LoaderBottomSheet.hideLoader(); + showCommonBottomSheetWithoutHeight( + context, + child: Utils.getErrorWidget(loadingText: err), + callBackFunc: () {}, + isFullScreen: false, + isCloseButtonVisible: true, + ); + }) + .then((val) async { + LoaderBottomSheet.hideLoader(); + if (getIt.get().patientLabResultAttachmentPDFBase64.isNotEmpty) { + String path = await Utils.createFileFromString(getIt.get().patientLabResultAttachmentPDFBase64, "pdf"); + try { + OpenFilex.open(path); + } catch (ex) { + showCommonBottomSheetWithoutHeight( + getIt.get().navigatorKey.currentContext!, + child: Utils.getErrorWidget(loadingText: "Cannot open file"), + callBackFunc: () {}, + isFullScreen: false, + isCloseButtonVisible: true, + ); + } + } + }); + } + }, + backgroundColor: AppColors.primaryRedColor.withAlpha(20), + borderColor: AppColors.primaryRedColor.withAlpha(0), + textColor: AppColors.primaryRedColor, + fontSize: 13.f, + fontWeight: FontWeight.w600, + borderRadius: 12.r, + padding: EdgeInsets.fromLTRB(10, 0, 10, 0), + height: 40.h, + ), + ), + ), ], ), ],