Lab report PDF implementation contd.

pull/83/head
haroon amjad 3 weeks ago
parent a2310e1447
commit 1e08394ba1

@ -160,7 +160,7 @@ class ApiClientImp implements ApiClient {
// body['VersionID'] = ApiConsts.appVersionID.toString(); // body['VersionID'] = ApiConsts.appVersionID.toString();
if (!isExternal) { if (!isExternal) {
body['VersionID'] = "50.0"; body['VersionID'] = "19.1";
body['Channel'] = ApiConsts.appChannelId.toString(); body['Channel'] = ApiConsts.appChannelId.toString();
body['IPAdress'] = ApiConsts.appIpAddress; body['IPAdress'] = ApiConsts.appIpAddress;
body['generalid'] = ApiConsts.appGeneralId; body['generalid'] = ApiConsts.appGeneralId;
@ -174,7 +174,7 @@ class ApiClientImp implements ApiClient {
} }
// body['TokenID'] = "@dm!n"; // body['TokenID'] = "@dm!n";
// body['PatientID'] = 4772172; // body['PatientID'] = 3966014;
// body['PatientTypeID'] = 1; // body['PatientTypeID'] = 1;
// //
// body['PatientOutSA'] = 0; // body['PatientOutSA'] = 0;

@ -13,13 +13,12 @@ abstract class LabRepo {
Future<Either<Failure, GenericApiModel<List<PatientLabOrdersResponseModel>>>> getPatientLabOrders(); Future<Either<Failure, GenericApiModel<List<PatientLabOrdersResponseModel>>>> getPatientLabOrders();
Future<Either<Failure, GenericApiModel<List<LabResult>>>> getPatientLabResults(PatientLabOrdersResponseModel laborder, bool isVidaPlus, String procedureName); Future<Either<Failure, GenericApiModel<List<LabResult>>>> getPatientLabResults(PatientLabOrdersResponseModel laborder, bool isVidaPlus, String procedureName);
Future<Either<Failure, GenericApiModel<List<LabResult>>>> Future<Either<Failure, GenericApiModel<List<LabResult>>>> getPatientLabResultsByHospitals(PatientLabOrdersResponseModel laborder, bool isVidaPlus);
getPatientLabResultsByHospitals(
PatientLabOrdersResponseModel laborder, bool isVidaPlus); Future<Either<Failure, GenericApiModel<List<PatientLabSpecialResult>>>> getSpecialLabResult(PatientLabOrdersResponseModel laborder, bool isVidaPlus);
Future<Either<Failure, GenericApiModel<String>>> getLabResultReportPDF({required PatientLabOrdersResponseModel labOrder});
Future<Either<Failure, GenericApiModel<List<PatientLabSpecialResult>>>>
getSpecialLabResult(
PatientLabOrdersResponseModel laborder, bool isVidaPlus);
} }
class LabRepoImp implements LabRepo { class LabRepoImp implements LabRepo {
@ -223,4 +222,10 @@ class LabRepoImp implements LabRepo {
return Left(UnknownFailure(e.toString())); return Left(UnknownFailure(e.toString()));
} }
} }
@override
Future<Either<Failure, GenericApiModel<String>>> getLabResultReportPDF({required PatientLabOrdersResponseModel labOrder}) async {
// TODO: implement getLabResultReportPDF
throw UnimplementedError();
}
} }

@ -3,6 +3,7 @@ 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/exceptions/api_failure.dart';
import 'package:hmg_patient_app_new/core/common_models/generic_api_model.dart'; import 'package:hmg_patient_app_new/core/common_models/generic_api_model.dart';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/features/prescriptions/models/resp_models/patient_prescriptions_response_model.dart'; import 'package:hmg_patient_app_new/features/prescriptions/models/resp_models/patient_prescriptions_response_model.dart';
import 'package:hmg_patient_app_new/features/prescriptions/models/resp_models/prescription_detail_response_model.dart'; import 'package:hmg_patient_app_new/features/prescriptions/models/resp_models/prescription_detail_response_model.dart';
import 'package:hmg_patient_app_new/services/logger_service.dart'; import 'package:hmg_patient_app_new/services/logger_service.dart';
@ -13,6 +14,8 @@ abstract class PrescriptionsRepo {
Future<Either<Failure, GenericApiModel<List<PrescriptionDetailResponseModel>>>> getPatientPrescriptionDetails({required PatientPrescriptionsResponseModel prescriptionsResponseModel}); Future<Either<Failure, GenericApiModel<List<PrescriptionDetailResponseModel>>>> getPatientPrescriptionDetails({required PatientPrescriptionsResponseModel prescriptionsResponseModel});
Future<Either<Failure, GenericApiModel<dynamic>>> getPrescriptionInstructionsPDF({required PatientPrescriptionsResponseModel prescriptionsResponseModel}); Future<Either<Failure, GenericApiModel<dynamic>>> getPrescriptionInstructionsPDF({required PatientPrescriptionsResponseModel prescriptionsResponseModel});
Future<Either<Failure, GenericApiModel<dynamic>>> getPrescriptionPDF({required PatientPrescriptionsResponseModel prescriptionsResponseModel, required List<PrescriptionDetailResponseModel> prescriptionDetailsList});
} }
class PrescriptionsRepoImp implements PrescriptionsRepo { class PrescriptionsRepoImp implements PrescriptionsRepo {
@ -153,4 +156,54 @@ class PrescriptionsRepoImp implements PrescriptionsRepo {
return Left(UnknownFailure(e.toString())); return Left(UnknownFailure(e.toString()));
} }
} }
@override
Future<Either<Failure, GenericApiModel>> getPrescriptionPDF({required PatientPrescriptionsResponseModel prescriptionsResponseModel, required List<PrescriptionDetailResponseModel> prescriptionDetailsList}) async {
Map<String, dynamic> mapDevice = {
"AppointmentDate": prescriptionsResponseModel.appointmentDate,
"ClinicName": prescriptionsResponseModel.clinicDescription,
"DoctorName": prescriptionsResponseModel.doctorName,
"ProjectID": prescriptionsResponseModel.projectID,
"DoctorID": prescriptionsResponseModel.doctorID,
"ClinicID": prescriptionsResponseModel.clinicID,
"DateofBirth": Utils.appState.getAuthenticatedUser()!.dateofBirth,
"ListPrescriptions": prescriptionDetailsList,
"PatientIditificationNum": Utils.appState.getAuthenticatedUser()!.patientIdentificationNo,
"PatientMobileNumber": Utils.appState.getAuthenticatedUser()!.mobileNumber,
"PatientName": "${Utils.appState.getAuthenticatedUser()!.firstName!} ${Utils.appState.getAuthenticatedUser()!.lastName!}",
"To": Utils.appState.getAuthenticatedUser()!.emailAddress,
"SetupID": prescriptionsResponseModel.setupID,
"IsDownload": true,
};
try {
GenericApiModel<dynamic>? apiResponse;
Failure? failure;
await apiClient.post(
SEND_PRESCRIPTION_EMAIL,
body: mapDevice,
onFailure: (error, statusCode, {messageStatus, failureType}) {
failure = failureType;
},
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
try {
final prescriptionPDFData = response["Base64Data"];
apiResponse = GenericApiModel<dynamic>(
messageStatus: messageStatus,
statusCode: statusCode,
errorMessage: null,
data: prescriptionPDFData,
);
} 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()));
}
}
} }

@ -25,6 +25,8 @@ class PrescriptionsViewModel extends ChangeNotifier {
String prescriptionInstructionsPDFLink = ""; String prescriptionInstructionsPDFLink = "";
String prescriptionPDFBase64Data = "";
PrescriptionsViewModel({required this.prescriptionsRepo, required this.errorHandlerService}); PrescriptionsViewModel({required this.prescriptionsRepo, required this.errorHandlerService});
initPrescriptionsViewModel() { initPrescriptionsViewModel() {
@ -150,4 +152,25 @@ class PrescriptionsViewModel extends ChangeNotifier {
}, },
); );
} }
Future<void> getPrescriptionPDFBase64(PatientPrescriptionsResponseModel prescriptionsResponseModel, {Function(dynamic)? onSuccess, Function(String)? onError}) async {
final result = await prescriptionsRepo.getPrescriptionPDF(prescriptionsResponseModel: prescriptionsResponseModel, prescriptionDetailsList: prescriptionDetailsList);
result.fold(
(failure) async {
onError!(failure.message);
},
(apiResponse) {
if (apiResponse.messageStatus == 2) {
onError!(apiResponse.errorMessage!);
} else if (apiResponse.messageStatus == 1) {
prescriptionPDFBase64Data = apiResponse.data;
notifyListeners();
if (onSuccess != null) {
onSuccess(apiResponse);
}
}
},
);
}
} }

@ -2,6 +2,7 @@ import 'package:easy_localization/easy_localization.dart'
show tr, StringTranslateExtension; show tr, StringTranslateExtension;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.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/size_utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.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/extensions/widget_extensions.dart';
@ -12,58 +13,119 @@ import 'package:hmg_patient_app_new/presentation/lab/lab_result_via_hospital/Lab
import 'package:hmg_patient_app_new/presentation/lab/lab_result_via_hospital/lab_order_specialResult.dart'; import 'package:hmg_patient_app_new/presentation/lab/lab_result_via_hospital/lab_order_specialResult.dart';
import 'package:hmg_patient_app_new/theme/colors.dart'; 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/appbar/collapsing_list_view.dart';
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class LabResultByHospitals extends StatelessWidget { class LabResultByHospitals extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CollapsingListView( return Scaffold(
title: LocaleKeys.labResults.tr(), backgroundColor: AppColors.bgScaffoldColor,
child: SingleChildScrollView( body: Column(
child: Column( children: [
spacing: 8.h, Expanded(
crossAxisAlignment: CrossAxisAlignment.start, child: CollapsingListView(
children: [ title: LocaleKeys.labResults.tr(),
Selector<LabViewModel, bool>( child: SingleChildScrollView(
selector: (_, model) => model.isLabResultByHospitalLoading, child: Column(
builder: (_, isLoading, __) { spacing: 8.h,
if (isLoading) { crossAxisAlignment: CrossAxisAlignment.start,
return Column( children: [
children: [ Selector<LabViewModel, bool>(
LabResultItemView( selector: (_, model) => model.isLabResultByHospitalLoading,
onTap: () {}, builder: (_, isLoading, __) {
labOrder: null, if (isLoading) {
index: 0, return Column(
isLoading: true, children: [
), LabResultItemView(
LabResultItemView( onTap: () {},
onTap: () {}, labOrder: null,
labOrder: null, index: 0,
index: 0, isLoading: true,
isLoading: true, ),
), LabResultItemView(
LabResultItemView( onTap: () {},
onTap: () {}, labOrder: null,
labOrder: null, index: 0,
index: 0, isLoading: true,
isLoading: true, ),
), LabResultItemView(
LabResultItemView( onTap: () {},
onTap: () {}, labOrder: null,
labOrder: null, index: 0,
index: 0, isLoading: true,
isLoading: true, ),
), LabResultItemView(
], onTap: () {},
); labOrder: null,
} else { index: 0,
return LabResultList(); isLoading: true,
} ),
}, ],
), );
LabOrderSpecialResult() } else {
], return LabResultList();
).paddingAll(24.h), }
)); },
),
LabOrderSpecialResult()
],
).paddingAll(24.h),
)),
),
Container(
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
color: AppColors.whiteColor,
borderRadius: 24.h,
hasShadow: true,
),
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,
// );
// }
// }
// });
},
backgroundColor: AppColors.successColor,
borderColor: AppColors.successColor,
textColor: AppColors.whiteColor,
fontSize: 16,
fontWeight: FontWeight.w500,
borderRadius: 12,
padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
height: 45.h,
icon: AppAssets.download,
iconColor: AppColors.whiteColor,
iconSize: 20.h,
).paddingSymmetrical(24.h, 24.h),
),
],
),
);
} }
} }

@ -77,6 +77,7 @@ class PatientSickLeaveCard extends StatelessWidget {
AppCustomChipWidget( AppCustomChipWidget(
icon: AppAssets.doctor_calendar_icon, icon: AppAssets.doctor_calendar_icon,
labelText: DateUtil.formatDateToDate(DateUtil.convertStringToDate(patientSickLeavesResponseModel.appointmentDate), false), labelText: DateUtil.formatDateToDate(DateUtil.convertStringToDate(patientSickLeavesResponseModel.appointmentDate), false),
labelPadding: EdgeInsetsDirectional.only(start: -4.h, end: 8.h),
).toShimmer2(isShow: isLoading), ).toShimmer2(isShow: isLoading),
AppCustomChipWidget(labelText: isLoading ? "Pending Activation" : patientSickLeavesResponseModel.clinicName!).toShimmer2(isShow: isLoading), AppCustomChipWidget(labelText: isLoading ? "Pending Activation" : patientSickLeavesResponseModel.clinicName!).toShimmer2(isShow: isLoading),
], ],

@ -22,6 +22,7 @@ import 'package:hmg_patient_app_new/widgets/chip/app_custom_chip_widget.dart';
import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.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:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart';
import 'package:hmg_patient_app_new/widgets/shimmer/movies_shimmer_widget.dart'; import 'package:hmg_patient_app_new/widgets/shimmer/movies_shimmer_widget.dart';
import 'package:open_filex/open_filex.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
@ -127,6 +128,7 @@ class _PrescriptionDetailPageState extends State<PrescriptionDetailPage> {
AppCustomChipWidget( AppCustomChipWidget(
icon: AppAssets.doctor_calendar_icon, icon: AppAssets.doctor_calendar_icon,
labelText: DateUtil.formatDateToDate(DateUtil.convertStringToDate(widget.prescriptionsResponseModel.appointmentDate), false), labelText: DateUtil.formatDateToDate(DateUtil.convertStringToDate(widget.prescriptionsResponseModel.appointmentDate), false),
labelPadding: EdgeInsetsDirectional.only(start: -4.h, end: 8.h),
), ),
AppCustomChipWidget( AppCustomChipWidget(
labelText: widget.prescriptionsResponseModel.clinicDescription!, labelText: widget.prescriptionsResponseModel.clinicDescription!,
@ -141,6 +143,41 @@ class _PrescriptionDetailPageState extends State<PrescriptionDetailPage> {
), ),
], ],
), ),
SizedBox(height: 16.h),
CustomButton(
text: "Download Prescription".needTranslation,
onPressed: () async {
LoaderBottomSheet.showLoader();
await prescriptionVM.getPrescriptionPDFBase64(widget.prescriptionsResponseModel).then((val) async {
LoaderBottomSheet.hideLoader();
if (prescriptionVM.prescriptionPDFBase64Data.isNotEmpty) {
String path = await Utils.createFileFromString(prescriptionVM.prescriptionPDFBase64Data, "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.withValues(alpha: 0.15),
borderColor: AppColors.successColor.withValues(alpha: 0.01),
textColor: AppColors.successColor,
fontSize: 14,
fontWeight: FontWeight.w500,
borderRadius: 12,
padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
height: 40.h,
icon: AppAssets.download,
iconColor: AppColors.successColor,
iconSize: 14.h,
),
], ],
), ),
), ),

@ -68,7 +68,7 @@ class _RadiologyResultPageState extends State<RadiologyResultPage> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
SizedBox(height: 16.h), SizedBox(height: 16.h),
widget.patientRadiologyResponseModel.description!.toText16(isBold: true), // widget.patientRadiologyResponseModel.description!.toText16(isBold: true),
SizedBox(height: 8.h), SizedBox(height: 8.h),
widget.patientRadiologyResponseModel.reportData!.trim().toText12(isBold: true, color: AppColors.textColorLight), widget.patientRadiologyResponseModel.reportData!.trim().toText12(isBold: true, color: AppColors.textColorLight),
SizedBox(height: 16.h), SizedBox(height: 16.h),

Loading…
Cancel
Save