search lab order updated.

pull/14/head
Sultan khan 2 months ago
parent 3cafc16d50
commit ac17202b7a

@ -11,7 +11,8 @@ class LabViewModel extends ChangeNotifier {
ErrorHandlerService errorHandlerService;
List<PatientLabOrdersResponseModel> patientLabOrders = [];
List<PatientLabOrdersResponseModel> filteredLabOrders = [];
List<PatientLabOrdersResponseModel> tempLabOrdersList = [];
late List<String> _labSuggestionsList = [];
List<String> get labSuggestions => _labSuggestionsList;
@ -20,6 +21,7 @@ class LabViewModel extends ChangeNotifier {
initLabProvider() {
patientLabOrders.clear();
filteredLabOrders.clear();
isLabOrdersLoading = true;
isLabResultsLoading = true;
getPatientLabOrders();
@ -36,6 +38,8 @@ class LabViewModel extends ChangeNotifier {
// dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
} else if (apiResponse.messageStatus == 1) {
patientLabOrders = apiResponse.data!;
filteredLabOrders = List.from(patientLabOrders);
tempLabOrdersList = apiResponse.data!;
isLabOrdersLoading = false;
isLabResultsLoading = false;
filterSuggestions();
@ -48,14 +52,27 @@ class LabViewModel extends ChangeNotifier {
);
}
filterSuggestions(){
filterSuggestions() {
final List<String> labels = patientLabOrders
.expand((order) => order.testDetails!) // flatten testDetails
.map((detail) => detail.description) // pick description
.whereType<String>() // remove nulls if any
.expand((order) => order.testDetails!)
.map((detail) => detail.description)
.whereType<String>()
.toList();
_labSuggestionsList = labels.toSet().toList(); // remove duplicates by converting to a set and back to a list
_labSuggestionsList = labels.toSet().toList();
notifyListeners();
}
filterLabReports(String query) {
if (query.isEmpty) {
filteredLabOrders = List.from(patientLabOrders); // reset
} else {
filteredLabOrders = patientLabOrders.where((order) {
final descriptions = order.testDetails?.map((d) => d.description?.toLowerCase()).toList() ?? [];
return descriptions.any((desc) => desc != null && desc.contains(query.toLowerCase()));
}).toList();
patientLabOrders = filteredLabOrders;
}
notifyListeners();
}
}

@ -63,7 +63,7 @@ class _InsuranceHomePageState extends State<InsuranceHomePage> {
onPressed: () {
insuranceVM.setIsInsuranceHistoryLoading(true);
showCommonBottomSheet(context,
child: InsuranceHistory(), callBackFunc: () {}, title: "", height: ResponsiveExtension.screenHeight * 0.5, isCloseButtonVisible: false, isFullScreen: false);
child: InsuranceHistory(), title: "", height: ResponsiveExtension.screenHeight * 0.5, isCloseButtonVisible: false, isFullScreen: false);
},
backgroundColor: AppColors.primaryRedColor.withOpacity(0.1),
borderColor: AppColors.primaryRedColor.withOpacity(0.0),

@ -4,6 +4,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/enums.dart';
import 'package:hmg_patient_app_new/core/utils/date_util.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
@ -15,6 +16,7 @@ import 'package:hmg_patient_app_new/features/lab/lab_view_model.dart';
import 'package:hmg_patient_app_new/presentation/lab/search_lab_report.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/chip/custom_chip_widget.dart';
import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart';
import 'package:hmg_patient_app_new/widgets/shimmer/movies_shimmer_widget.dart';
import 'package:provider/provider.dart';
@ -30,7 +32,7 @@ class _LabOrdersPageState extends State<LabOrdersPage> {
late LabViewModel labProvider;
List<List<TestDetails>?> labSuggestions = [];
int? expandedIndex;
String? selectedFilterText='';
@override
void initState() {
scheduleMicrotask(() {
@ -66,7 +68,10 @@ class _LabOrdersPageState extends State<LabOrdersPage> {
}else {
showCommonBottomSheet(context, child: SearchLabResultsContent(labSuggestionsList: model.labSuggestions),
callBackFunc: () {},
callBackFunc: (value) {
selectedFilterText = value;
model.filterLabReports(value!);
},
title: LocaleKeys.searchLabReport.tr(),
height: ResponsiveExtension.screenHeight,
isCloseButtonVisible: true);
@ -77,6 +82,8 @@ class _LabOrdersPageState extends State<LabOrdersPage> {
// Build Tab Bar
SizedBox(height: 16.h),
// Expandable list
selectedFilterText!.isNotEmpty ? CustomChipWidget(chipText: selectedFilterText!, chipType: ChipTypeEnum.alert, isSelected: true, ) : SizedBox(),
ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
@ -275,13 +282,6 @@ class _LabOrdersPageState extends State<LabOrdersPage> {
return "";
}
}
getLabSuggestions(LabViewModel model) {
if(model.patientLabOrders.isEmpty){
return [];
}
return model.patientLabOrders.map((m) => m.testDetails).toList();
}
}

@ -7,7 +7,7 @@ import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
void showCommonBottomSheet(BuildContext context,
{required Widget child, required VoidCallback callBackFunc, String? title, required double height, bool isCloseButtonVisible = true, bool isFullScreen = true}) {
{required Widget child, Function(String?)? callBackFunc, String? title, required double height, bool isCloseButtonVisible = true, bool isFullScreen = true}) {
showModalBottomSheet<String>(
sheetAnimationStyle: AnimationStyle(
duration: Duration(milliseconds: 500), // Custom animation duration
@ -29,7 +29,9 @@ void showCommonBottomSheet(BuildContext context,
),
);
}).then((value) {
callBackFunc();
if(value != null) {
callBackFunc!(value);
}
});
}
@ -63,12 +65,14 @@ class ButtonSheetContent extends StatelessWidget {
// Close button
isCloseButtonVisible && isFullScreen
? Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
? Column(children: [
SizedBox(height: 40.h,),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16,),
child: Utils.buildSvgWithAssets(icon: AppAssets.closeBottomNav, width: 32, height: 32).onPress(() {
Navigator.of(context).pop();
}),
)
)])
: SizedBox(),
isFullScreen

Loading…
Cancel
Save