diff --git a/lib/features/hmg_services/hmg_services_view_model.dart b/lib/features/hmg_services/hmg_services_view_model.dart index f462aedd..9cd7e519 100644 --- a/lib/features/hmg_services/hmg_services_view_model.dart +++ b/lib/features/hmg_services/hmg_services_view_model.dart @@ -899,7 +899,9 @@ class HmgServicesViewModel extends ChangeNotifier { int? projectID, bool forceRefresh = false, }) async { - if (hasVitalSignDataLoaded && transNo == null && projectID == null && !forceRefresh) { + final bool isSpecificQuery = (transNo != null || projectID != null); + + if (!isSpecificQuery && hasVitalSignDataLoaded && !forceRefresh) { if (onSuccess != null) { onSuccess(GenericApiModel>( messageStatus: 1, @@ -908,37 +910,44 @@ class HmgServicesViewModel extends ChangeNotifier { } return; } - isVitalSignLoading = true; - notifyListeners(); + + if (!isSpecificQuery) { + isVitalSignLoading = true; + notifyListeners(); + } final result = await hmgServicesRepo.getPatientVitalSign(transNo, projectID); result.fold( (failure) async { - isVitalSignLoading = false; - notifyListeners(); + if (!isSpecificQuery) { + isVitalSignLoading = false; + notifyListeners(); + } await errorHandlerService.handleError(failure: failure); if (onError != null) { onError(failure.message); } }, (apiResponse) { - isVitalSignLoading = false; - if (apiResponse.messageStatus == 1) { - vitalSignList = apiResponse.data ?? []; - if (transNo == null && projectID == null) { + if (!isSpecificQuery) { + isVitalSignLoading = false; + if (apiResponse.messageStatus == 1) { + vitalSignList = apiResponse.data ?? []; hasVitalSignDataLoaded = true; - } - if (vitalSignList.isNotEmpty) { - getIt.get().setSelectedHeight(vitalSignList.first.heightCm); - getIt.get().setSelectedWeight(vitalSignList.first.weightKg); + if (vitalSignList.isNotEmpty) { + getIt.get().setSelectedHeight(vitalSignList.first.heightCm); + getIt.get().setSelectedWeight(vitalSignList.first.weightKg); + } } notifyListeners(); + } + + if (apiResponse.messageStatus == 1) { if (onSuccess != null) { onSuccess(apiResponse); } } else { - notifyListeners(); if (onError != null) { onError(apiResponse.errorMessage ?? 'Unknown error'); } diff --git a/lib/presentation/appointments/appointment_details_page.dart b/lib/presentation/appointments/appointment_details_page.dart index e384793b..dc147981 100644 --- a/lib/presentation/appointments/appointment_details_page.dart +++ b/lib/presentation/appointments/appointment_details_page.dart @@ -692,7 +692,7 @@ class _AppointmentDetailsPageState extends State { ? (apiResponse.data ?? []) : (apiResponse.data is List ? (apiResponse.data as List) - : hmgServicesVM.vitalSignList); + : []); VitalSignResModel? matchedVitalSign; if (vitalList.isNotEmpty) {