Special result attachments handled

CR-20974-PDF-Results-In-Lab
haroon amjad 1 month ago
parent e0eabb38d7
commit 3f00dec522

@ -20,6 +20,7 @@ import 'package:hmg_patient_app_new/features/lab/models/resp_models/ai_overview_
import 'package:hmg_patient_app_new/features/lab/models/resp_models/lab_result.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_special_result.dart';
import 'package:hmg_patient_app_new/generated/codegen_loader.g.dart';
import 'package:hmg_patient_app_new/presentation/lab/lab_result_via_clinic/LabResultByClinic.dart';
import 'package:hmg_patient_app_new/presentation/lab/lab_results/lab_result_details.dart';
@ -51,6 +52,7 @@ class LabViewModel extends ChangeNotifier {
List<PatientLabOrdersResponseModel> patientLabOrders = [];
List<PatientLabOrdersResponseModel> filteredLabOrders = [];
List<PatientLabOrdersResponseModel> tempLabOrdersList = [];
String labSpecialResult = "";
List<String> labOrderTests = [];
String patientLabResultReportPDFBase64 = "";
@ -66,7 +68,9 @@ class LabViewModel extends ChangeNotifier {
// Flat list for UI compatibility
List<LabResult> mainLabResultsByHospitalsList = [];
List<PatientLabSpecialResult> patientSpecialLabResultsList = [];
// Grouped map by package name for efficient lookups
Map<String, List<LabResult>> mainLabResultsByPackageName = {};
@ -591,6 +595,7 @@ class LabViewModel extends ChangeNotifier {
Future<void> getPatientSpecialResult(PatientLabOrdersResponseModel laborder) async {
isSpecialResultsLoading = true;
labSpecialResult = "";
patientSpecialLabResultsList.clear();
notifyListeners();
final result = await labRepo.getSpecialLabResult(
laborder,
@ -614,6 +619,7 @@ class LabViewModel extends ChangeNotifier {
});
labSpecialResult = htmlbuffer.toString();
patientSpecialLabResultsList = apiResponse.data ?? [];
notifyListeners();
}
@ -1072,4 +1078,80 @@ class LabViewModel extends ChangeNotifier {
isCloseButtonVisible: true,
);
}
void openSpecialLabResultsAttachmentSheet({required PatientLabSpecialResult specialLabResult, required projectID, required setupID}) {
LabResult labResult = LabResult(
projectID: projectID,
setupID: setupID,
accessionNo: specialLabResult.accessionNo,
uploadedDocuments: specialLabResult.uploadedDocuments,
fileNameWithExtensionList: specialLabResult.fileNameWithExtensionList,
);
showCommonBottomSheetWithoutHeight(
getIt.get<NavigationService>().navigatorKey.currentContext!,
title: LocaleKeys.selectAttachment.tr(),
child: (Utils.isVidaPlusProject(int.parse(projectID)) ? (specialLabResult.uploadedDocuments ?? []).isNotEmpty : (specialLabResult.fileNameWithExtensionList ?? []).isNotEmpty)
? Column(
children: [
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: Utils.isVidaPlusProject(int.parse(projectID)) ? (specialLabResult.uploadedDocuments ?? []).length : (specialLabResult.fileNameWithExtensionList ?? []).length,
itemBuilder: (context, index) {
return Padding(
padding: EdgeInsets.only(right: 12.h, bottom: 12.h),
child:
"${Utils.isVidaPlusProject(int.parse(projectID)) ? specialLabResult.uploadedDocuments![index].fileName : specialLabResult.fileNameWithExtensionList![index].fileNameWithExtension}"
.toText16(color: AppColors.primaryRedColor, isBold: true, isUnderLine: true),
).onPress(() {
LoaderBottomSheet.showLoader();
getLabResultAttachmentPDF(
labResult: labResult,
selectedIndex: index,
onError: (err) {
LoaderBottomSheet.hideLoader();
showCommonBottomSheetWithoutHeight(
context,
child: Utils.getErrorWidget(loadingText: err),
callBackFunc: () {},
isFullScreen: false,
isCloseButtonVisible: true,
);
}).then((val) async {
Navigator.pop(context);
if (getIt.get<LabViewModel>().patientLabResultAttachmentPDFBase64.isNotEmpty) {
String path = await Utils.createFileFromString(getIt.get<LabViewModel>().patientLabResultAttachmentPDFBase64, "pdf");
try {
OpenFilex.open(path);
} catch (ex) {
showCommonBottomSheetWithoutHeight(
getIt.get<NavigationService>().navigatorKey.currentContext!,
child: Utils.getErrorWidget(loadingText: "Cannot open file"),
callBackFunc: () {},
isFullScreen: false,
isCloseButtonVisible: true,
);
}
} else {
showCommonBottomSheetWithoutHeight(
getIt.get<NavigationService>().navigatorKey.currentContext!,
child: Utils.getErrorWidget(loadingText: "Attachment not available"),
callBackFunc: () {},
isFullScreen: false,
isCloseButtonVisible: true,
);
}
});
});
},
),
],
)
: Utils.getErrorWidget(loadingText: "No attachments found"),
callBackFunc: () {},
isFullScreen: false,
isCloseButtonVisible: true,
);
}
}

@ -53,9 +53,9 @@ class LabResult {
String? testShortDescription;
String? uOM;
List<LabResultAttachment>? uploadedDocuments;
List<FileNameWithExtensionList>? fileNameWithExtensionList;
String? verifiedOn;
dynamic verifiedOnDateTime;
List<FileNameWithExtensionList>? fileNameWithExtensionList;
LabResult(
{this.accessionNo,
@ -112,6 +112,7 @@ class LabResult {
this.testShortDescription,
this.uOM,
this.uploadedDocuments,
this.fileNameWithExtensionList,
this.verifiedOn,
this.verifiedOnDateTime});

@ -1,23 +1,50 @@
import 'package:hmg_patient_app_new/features/lab/models/resp_models/lab_result.dart';
class PatientLabSpecialResult {
String? invoiceNo;
String? accessionNo;
String? moduleID;
String? resultData;
String? resultDataHTML;
bool? isLabTestAttachment;
dynamic resultDataTxt;
List<LabResultAttachment>? uploadedDocuments;
List<FileNameWithExtensionList>? fileNameWithExtensionList;
PatientLabSpecialResult(
{this.invoiceNo,
this.moduleID,
this.resultData,
this.resultDataHTML,
this.resultDataTxt});
this.accessionNo,
this.resultData,
this.resultDataHTML,
this.isLabTestAttachment,
this.resultDataTxt,
this.uploadedDocuments,
this.fileNameWithExtensionList,
});
PatientLabSpecialResult.fromJson(Map<String, dynamic> json) {
invoiceNo = json['InvoiceNo'];
accessionNo = json['AccessionNo'];
moduleID = json['ModuleID'];
resultData = json['ResultData'];
resultDataHTML = json['ResultDataHTML'];
isLabTestAttachment = json['IsLabTestAttachment'];
resultDataTxt = json['ResultDataTxt'];
if (json['UploadedDocuments'] != null) {
uploadedDocuments = <LabResultAttachment>[];
json['UploadedDocuments'].forEach((v) {
uploadedDocuments!.add(LabResultAttachment.fromJson(v));
});
}
if (json['FileNameWithExtensionList'] != null) {
fileNameWithExtensionList = <FileNameWithExtensionList>[];
json['FileNameWithExtensionList'].forEach((v) {
fileNameWithExtensionList!.add(FileNameWithExtensionList.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {

File diff suppressed because one or more lines are too long

@ -131,7 +131,7 @@ class LabResultByClinic extends StatelessWidget {
}
},
),
LabOrderSpecialResult(),
LabOrderSpecialResult(projectID: labOrder.projectID ?? "0", setupID: labOrder.setupID ?? ""),
],
).paddingAll(24.h),
)),

@ -1,16 +1,22 @@
import 'package:easy_localization/easy_localization.dart';
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/dependencies.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/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/lab/lab_view_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
import 'package:provider/provider.dart';
class LabOrderSpecialResult extends StatelessWidget {
const LabOrderSpecialResult({super.key});
String projectID;
String setupID;
LabOrderSpecialResult({super.key, required this.projectID, required this.setupID});
@override
Widget build(BuildContext context) {
@ -64,7 +70,6 @@ class LabOrderSpecialResult extends StatelessWidget {
.tr()
.toText14(isBold: true)
.toShimmer2(isShow: isLoading),
data.isEmpty
? LocaleKeys.noSpecialResult
.tr()
@ -72,8 +77,26 @@ class LabOrderSpecialResult extends StatelessWidget {
isBold: true,
color: AppColors.textColorLight)
.toShimmer2(isShow: isLoading)
: HtmlWidget(data).toShimmer2(isShow: isLoading)
: HtmlWidget(data).toShimmer2(isShow: isLoading),
CustomButton(
icon: AppAssets.document,
iconColor: AppColors.primaryRedColor,
iconSize: 16.h,
text: LocaleKeys.viewAttachment.tr(context: context),
onPressed: () async {
getIt
.get<LabViewModel>()
.openSpecialLabResultsAttachmentSheet(specialLabResult: getIt.get<LabViewModel>().patientSpecialLabResultsList.first, projectID: projectID, setupID: setupID);
},
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,
),
//
],
),

Loading…
Cancel
Save