From 818a1f82052c2447f12607cdb7ea9f38aa338aae Mon Sep 17 00:00:00 2001 From: Haroon Amjad <> Date: Tue, 2 Sep 2025 21:27:43 +0300 Subject: [PATCH] lab result fixes --- .../viewModels/medical/labs_view_model.dart | 36 +++++++++--- .../medical/labs/laboratory_result_page.dart | 58 +++++++++---------- .../LabResult/laboratory_result_widget.dart | 17 +++--- 3 files changed, 66 insertions(+), 45 deletions(-) diff --git a/lib/core/viewModels/medical/labs_view_model.dart b/lib/core/viewModels/medical/labs_view_model.dart index 7a90e45b..7fe12714 100644 --- a/lib/core/viewModels/medical/labs_view_model.dart +++ b/lib/core/viewModels/medical/labs_view_model.dart @@ -87,20 +87,29 @@ class LabsViewModel extends BaseViewModel { List labResultLists = []; - getLaboratoryResult({String? projectID, int? clinicID, String? invoiceNo, String? invoiceType, String? orderNo, String? setupID, bool? isVidaPlus}) async { + getLaboratoryResult({required PatientLabOrders patientLabOrder, String? projectID, int? clinicID, String? invoiceNo, String? invoiceType, String? orderNo, String? setupID, bool? isVidaPlus}) async { setState(ViewState.Busy); await _labsService.getLaboratoryResult(invoiceNo: invoiceNo, invoiceType: invoiceType, orderNo: orderNo, projectID: projectID, clinicID: clinicID, setupID: setupID, isVidaPlus: isVidaPlus); + // await _labsService.getPatientLabResult(patientLabOrder: patientLabOrder, isVidaPlus: isVidaPlus); if (_labsService.hasError) { error = _labsService.error!; - // setState(ViewState.Error); + setState(ViewState.Error); } else { - // setState(ViewState.Idle); + setState(ViewState.Idle); } } getPatientLabResult({required PatientLabOrders patientLabOrder, required bool isVidaPlus, bool isTablet = false}) async { setState(ViewState.Busy); await _labsService.getPatientLabResult(patientLabOrder: patientLabOrder, isVidaPlus: isVidaPlus); + await _labsService.getLaboratoryResult( + invoiceNo: patientLabOrder.invoiceNo, + invoiceType: patientLabOrder.invoiceType, + orderNo: patientLabOrder.orderNo, + projectID: patientLabOrder.projectID, + clinicID: patientLabOrder.clinicID, + setupID: patientLabOrder.setupID, + isVidaPlus: isVidaPlus); if (_labsService.hasError) { error = _labsService.error!; setState(ViewState.Error); @@ -199,7 +208,13 @@ class LabsViewModel extends BaseViewModel { maxYForThreeDots = double.parse(element.resultValue!); } // threePointGraphValue.add(DataPoint( labelValue: counter,value : _labsService.transformValueInRange(double.parse(element.resultValue!), element.calculatedResultFlag??""), label: "${months[dateTime.month-1]} ${dateTime.year}", date: dateTime)); - threePointGraphValue.add(DataPoint( labelValue: counter,value : double.parse(element.resultValue!), actualValue: element.resultValue!,label: formatDateAsMMYY(dateTime), date: dateTime, referenceRangeValue:element.calculatedResultFlag ??"IRR")); + threePointGraphValue.add(DataPoint( + labelValue: counter, + value: double.parse(element.resultValue!), + actualValue: element.resultValue!, + label: formatDateAsMMYY(dateTime), + date: dateTime, + referenceRangeValue: element.calculatedResultFlag ?? "IRR")); counter++; } catch (e) {} }); @@ -217,15 +232,21 @@ class LabsViewModel extends BaseViewModel { completeeGraphValues.clear(); setState(ViewState.Busy); double counter = 1; - threshold = _labsService.getThresholdValue(); + threshold = _labsService.getThresholdValue(); _labsService.labOrdersResultsList.reversed.forEach((element) { try { var dateTime = DateUtil.convertStringToDate(element.verifiedOnDateTime!); - if(double.parse(element.resultValue!)> maxYForCompleteGraph){ + if (double.parse(element.resultValue!) > maxYForCompleteGraph) { maxYForCompleteGraph = double.parse(element.resultValue!); } // completeeGraphValues.add(DataPoint( labelValue: counter,value : _labsService.transformValueInRange(double.parse(element.resultValue!), element.calculatedResultFlag??""), label: "${months[dateTime.month-1]} ${dateTime.year}", date: dateTime)); - completeeGraphValues.add(DataPoint( labelValue: counter,value : double.parse(element.resultValue!), label: formatDateAsMMYY(dateTime), date: dateTime,actualValue: element.resultValue!, referenceRangeValue:element.calculatedResultFlag??"IRR" )); + completeeGraphValues.add(DataPoint( + labelValue: counter, + value: double.parse(element.resultValue!), + label: formatDateAsMMYY(dateTime), + date: dateTime, + actualValue: element.resultValue!, + referenceRangeValue: element.calculatedResultFlag ?? "IRR")); } catch (e) { print("the mapping is having exception $e"); } @@ -242,6 +263,7 @@ class LabsViewModel extends BaseViewModel { String year = date.year.toString().substring(2); return '$month/$year'; } + sendLabReportEmail({PatientLabOrders? patientLabOrder, String? mes, AuthenticatedUser? userObj, required bool isVidaPlus, bool isDownload = false}) async { setState(ViewState.Busy); diff --git a/lib/pages/medical/labs/laboratory_result_page.dart b/lib/pages/medical/labs/laboratory_result_page.dart index 634220ae..f9c9305d 100644 --- a/lib/pages/medical/labs/laboratory_result_page.dart +++ b/lib/pages/medical/labs/laboratory_result_page.dart @@ -24,15 +24,16 @@ class _LaboratoryResultPageState extends State { Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); return BaseView( - onModelReady: (model) => model.getLaboratoryResult( - invoiceNo: widget.patientLabOrders!.invoiceNo, - invoiceType: widget.patientLabOrders!.invoiceType, - clinicID: widget.patientLabOrders!.clinicID, - projectID: widget.patientLabOrders!.projectID, - orderNo: widget.patientLabOrders!.orderNo, - setupID: widget.patientLabOrders!.setupID, - isVidaPlus: Utils.isVidaPlusProject(projectViewModel, int.parse(widget.patientLabOrders!.projectID!)), - ), + onModelReady: (model) {}, + // onModelReady: (model) => model.getLaboratoryResult( + // invoiceNo: widget.patientLabOrders!.invoiceNo, + // invoiceType: widget.patientLabOrders!.invoiceType, + // clinicID: widget.patientLabOrders!.clinicID, + // projectID: widget.patientLabOrders!.projectID, + // orderNo: widget.patientLabOrders!.orderNo, + // setupID: widget.patientLabOrders!.setupID, + // isVidaPlus: Utils.isVidaPlusProject(projectViewModel, int.parse(widget.patientLabOrders!.projectID!)), + // ), builder: (_, model, w) => AppScaffold( isShowAppBar: true, appBarTitle: widget.patientLabOrders!.doctorName!, @@ -45,27 +46,24 @@ class _LaboratoryResultPageState extends State { child: Column( children: [ LaboratoryResultWidget( - onTap: () async { - await model.sendLabReportEmail( - patientLabOrder: widget.patientLabOrders, - mes: TranslationBase.of(context).sendSuc, - userObj: projectViewModel.user, - isVidaPlus: Utils.isVidaPlusProject( - projectViewModel, - int.parse(widget.patientLabOrders!.projectID!), - ), - isDownload: true); - }, - showConfirmMessageDialog: false, - billNo: widget.patientLabOrders!.invoiceNo, - // details: model.patientLabSpecialResult[index].resultDataHTML, - details: model.patientLabSpecialResult.isEmpty - ? null - : getSpecialResults(model), - orderNo: widget.patientLabOrders!.orderNo, - patientLabOrder: widget.patientLabOrders, - labmodel: model - ), + onTap: () async { + await model.sendLabReportEmail( + patientLabOrder: widget.patientLabOrders, + mes: TranslationBase.of(context).sendSuc, + userObj: projectViewModel.user, + isVidaPlus: Utils.isVidaPlusProject( + projectViewModel, + int.parse(widget.patientLabOrders!.projectID!), + ), + isDownload: true); + }, + showConfirmMessageDialog: false, + billNo: widget.patientLabOrders!.invoiceNo, + // details: model.patientLabSpecialResult[index].resultDataHTML, + details: model.patientLabSpecialResult.isEmpty ? null : getSpecialResults(model), + orderNo: widget.patientLabOrders!.orderNo, + patientLabOrder: widget.patientLabOrders, + labmodel: model), ], ), ), diff --git a/lib/widgets/data_display/medical/LabResult/laboratory_result_widget.dart b/lib/widgets/data_display/medical/LabResult/laboratory_result_widget.dart index fae3c671..cdba7c9c 100644 --- a/lib/widgets/data_display/medical/LabResult/laboratory_result_widget.dart +++ b/lib/widgets/data_display/medical/LabResult/laboratory_result_widget.dart @@ -22,7 +22,8 @@ class LaboratoryResultWidget extends StatefulWidget { final bool showConfirmMessageDialog; final LabsViewModel labmodel; - const LaboratoryResultWidget({Key? key, this.onTap, this.billNo, this.details, this.orderNo, this.projectName, this.patientLabOrder, this.showConfirmMessageDialog = true,required this.labmodel}) : super(key: key); + const LaboratoryResultWidget({Key? key, this.onTap, this.billNo, this.details, this.orderNo, this.projectName, this.patientLabOrder, this.showConfirmMessageDialog = true, required this.labmodel}) + : super(key: key); @override _LaboratoryResultWidgetState createState() => _LaboratoryResultWidgetState(); @@ -40,21 +41,20 @@ class _LaboratoryResultWidgetState extends State { super.initState(); this.model = widget.labmodel; - labSpecialResult = widget.details; + // labSpecialResult = widget.details; + labSpecialResult = widget.details ?? "No Data Available"; } - @override void didChangeDependencies() { super.didChangeDependencies(); var oldStateTablateScreenState = isTabletScreen; - isTabletScreen = isTablet(context); - if(isTabletScreen != oldStateTablateScreenState); + isTabletScreen = isTablet(context); + if (isTabletScreen != oldStateTablateScreenState) ; { model?.recalculatePercentage(isTabletScreen); } - } bool isTablet(BuildContext context) { @@ -71,9 +71,10 @@ class _LaboratoryResultWidgetState extends State { onModelReady: (_) { print("the length of in on model Ready ${model?.patientLabSpecialResult.length}"); WidgetsBinding.instance.addPostFrameCallback((_) { - model?.getPatientLabResult(isVidaPlus: Utils.isVidaPlusProject(projectViewModel, int.parse(widget.patientLabOrder!.projectID!)), patientLabOrder: widget.patientLabOrder!, isTablet: isTabletScreen); + model?.getPatientLabResult( + isVidaPlus: Utils.isVidaPlusProject(projectViewModel, int.parse(widget.patientLabOrder!.projectID!)), patientLabOrder: widget.patientLabOrder!, isTablet: isTabletScreen); + labSpecialResult = widget.details ?? "No Data Available"; }); - }, builder: (_, __, w) => NetworkBaseView( baseViewModel: widget.labmodel,