lab report download implemented

pull/83/head
haroon amjad 3 weeks ago
parent e1ac77855c
commit 5e1a7652be

@ -160,7 +160,7 @@ class ApiClientImp implements ApiClient {
// body['VersionID'] = ApiConsts.appVersionID.toString();
if (!isExternal) {
body['VersionID'] = "19.1";
body['VersionID'] = "50.0";
body['Channel'] = ApiConsts.appChannelId.toString();
body['IPAdress'] = ApiConsts.appIpAddress;
body['generalid'] = ApiConsts.appGeneralId;

@ -3,6 +3,8 @@ import 'package:hmg_patient_app_new/core/api_consts.dart';
import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart';
import 'package:hmg_patient_app_new/core/common_models/generic_api_model.dart';
import 'package:dartz/dartz.dart';
import 'package:hmg_patient_app_new/core/utils/date_util.dart';
import 'package:hmg_patient_app_new/core/utils/utils.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_special_result.dart';
import 'package:hmg_patient_app_new/services/logger_service.dart';
@ -225,7 +227,55 @@ class LabRepoImp implements LabRepo {
@override
Future<Either<Failure, GenericApiModel<String>>> getLabResultReportPDF({required PatientLabOrdersResponseModel labOrder}) async {
// TODO: implement getLabResultReportPDF
throw UnimplementedError();
Map<String, dynamic> mapDevice = {
"InvoiceNo": Utils.isVidaPlusProject(int.parse(labOrder.projectID!)) ? "0" : labOrder.invoiceNo,
"InvoiceNo_VP": Utils.isVidaPlusProject(int.parse(labOrder.projectID!)) ? labOrder.invoiceNo : "0",
// "LineItemNo": labOrder.invoiceLineItemNo,
// "InvoiceLineItemNo": labOrder.invoiceLineItemNo,
"ProjectID": labOrder.projectID!,
"DoctorID": labOrder.doctorID!,
"OrderNo": labOrder.orderNo!,
"InvoiceType": labOrder.invoiceType!,
"SetupID": labOrder.setupID!,
"IsDownload": true,
'ClinicName': labOrder.clinicDescription,
'DateofBirth': Utils.appState.getAuthenticatedUser()!.dateofBirth,
'DoctorName': labOrder.doctorName,
'OrderDate': '${DateUtil.convertStringToDate(labOrder.orderDate!).year}-${DateUtil.convertStringToDate(labOrder.orderDate!).month}-${DateUtil.convertStringToDate(labOrder.orderDate!).day}',
'PatientIditificationNum': Utils.appState.getAuthenticatedUser()!.patientIdentificationNo,
'PatientMobileNumber': Utils.appState.getAuthenticatedUser()!.mobileNumber,
'PatientName': "${Utils.appState.getAuthenticatedUser()!.firstName!} ${Utils.appState.getAuthenticatedUser()!.lastName!}",
'ProjectName': labOrder.projectName,
"To": Utils.appState.getAuthenticatedUser()!.emailAddress
};
try {
GenericApiModel<String>? apiResponse;
Failure? failure;
await apiClient.post(
Utils.isVidaPlusProject(int.parse(labOrder.projectID!)) ? SEND_LAB_RESULT_EMAIL : SEND_LAB_RESULT_EMAIL_NEW,
body: mapDevice,
onFailure: (error, statusCode, {messageStatus, failureType}) {
failure = failureType;
},
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
try {
apiResponse = GenericApiModel<String>(
messageStatus: messageStatus,
statusCode: statusCode,
errorMessage: null,
data: response["PdfContent"],
);
} 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()));
}
}
}

@ -36,6 +36,7 @@ class LabViewModel extends ChangeNotifier {
List<PatientLabOrdersResponseModel> tempLabOrdersList = [];
String labSpecialResult = "";
List<String> labOrderTests = [];
String patientLabResultReportPDFBase64 = "";
PatientLabOrdersResponseModel? currentlySelectedPatientOrder;
@ -130,6 +131,31 @@ class LabViewModel extends ChangeNotifier {
);
}
Future<void> getLabResultReportPDF({required PatientLabOrdersResponseModel labOrder, Function(dynamic)? onSuccess, Function(String)? onError}) async {
final result = await labRepo.getLabResultReportPDF(labOrder: labOrder);
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) {
patientLabResultReportPDFBase64 = apiResponse.data!;
notifyListeners();
if (onSuccess != null) {
onSuccess(apiResponse);
}
}
},
);
}
filterSuggestions() {
final List<String> labels = patientLabOrders
.expand((order) => order.testDetails!)

@ -155,10 +155,10 @@ class PatientLabOrdersResponseModel {
status = json['Status'];
statusDesc = json['StatusDesc'];
strOrderDate = json['StrOrderDate'];
if (json['TestDetails'] != dynamic) {
if (json['TestDetails'] != null) {
testDetails = <TestDetails>[];
json['TestDetails'].forEach((v) {
testDetails!.add(new TestDetails.fromJson(v));
testDetails!.add(TestDetails.fromJson(v));
});
}
}

File diff suppressed because one or more lines are too long

@ -4,9 +4,11 @@ import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/core/utils/utils.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';
import 'package:hmg_patient_app_new/features/lab/models/resp_models/patient_lab_orders_response_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/lab/lab_result_item_view.dart';
import 'package:hmg_patient_app_new/presentation/lab/lab_result_via_hospital/LabResultList.dart';
@ -14,12 +16,20 @@ import 'package:hmg_patient_app_new/presentation/lab/lab_result_via_hospital/lab
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.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';
class LabResultByHospitals extends StatelessWidget {
LabResultByHospitals({required this.labOrder, Key? key});
late LabViewModel labViewModel;
PatientLabOrdersResponseModel labOrder;
@override
Widget build(BuildContext context) {
labViewModel = Provider.of<LabViewModel>(context, listen: false);
return Scaffold(
backgroundColor: AppColors.bgScaffoldColor,
body: Column(
@ -83,33 +93,37 @@ class LabResultByHospitals extends StatelessWidget {
child: CustomButton(
text: "Download report".needTranslation,
onPressed: () async {
// LoaderBottomSheet.showLoader();
// await radiologyViewModel.getRadiologyPDF(patientRadiologyResponseModel: widget.patientRadiologyResponseModel, authenticatedUser: _appState.getAuthenticatedUser()!, onError: (err) {
// LoaderBottomSheet.hideLoader();
// showCommonBottomSheetWithoutHeight(
// context,
// child: Utils.getErrorWidget(loadingText: err),
// callBackFunc: () {},
// isFullScreen: false,
// isCloseButtonVisible: true,
// );
// }).then((val) async {
// LoaderBottomSheet.hideLoader();
// if (radiologyViewModel.patientRadiologyReportPDFBase64.isNotEmpty) {
// String path = await Utils.createFileFromString(radiologyViewModel.patientRadiologyReportPDFBase64, "pdf");
// try {
// OpenFilex.open(path);
// } catch (ex) {
// showCommonBottomSheetWithoutHeight(
// context,
// child: Utils.getErrorWidget(loadingText: "Cannot open file".needTranslation),
// callBackFunc: () {},
// isFullScreen: false,
// isCloseButtonVisible: true,
// );
// }
// }
// });
LoaderBottomSheet.showLoader(loadingText: "Generating report, Please wait...".needTranslation);
await labViewModel
.getLabResultReportPDF(
labOrder: labOrder,
onError: (err) {
LoaderBottomSheet.hideLoader();
showCommonBottomSheetWithoutHeight(
context,
child: Utils.getErrorWidget(loadingText: err),
callBackFunc: () {},
isFullScreen: false,
isCloseButtonVisible: true,
);
})
.then((val) async {
LoaderBottomSheet.hideLoader();
if (labViewModel.patientLabResultReportPDFBase64.isNotEmpty) {
String path = await Utils.createFileFromString(labViewModel.patientLabResultReportPDFBase64, "pdf");
try {
OpenFilex.open(path);
} catch (ex) {
showCommonBottomSheetWithoutHeight(
context,
child: Utils.getErrorWidget(loadingText: "Cannot open file".needTranslation),
callBackFunc: () {},
isFullScreen: false,
isCloseButtonVisible: true,
);
}
}
});
},
backgroundColor: AppColors.successColor,
borderColor: AppColors.successColor,

Loading…
Cancel
Save