You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
6.3 KiB
Dart
163 lines
6.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
|
|
import 'package:hmg_patient_app_new/features/authentication/models/resp_models/authenticated_user_resp_model.dart';
|
|
import 'package:hmg_patient_app_new/features/radiology/radiology_repo.dart';
|
|
import 'package:hmg_patient_app_new/presentation/radiology/radiology_result_page.dart';
|
|
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
|
|
import 'package:hmg_patient_app_new/services/navigation_service.dart';
|
|
import 'package:hmg_patient_app_new/widgets/routes/custom_page_route.dart';
|
|
|
|
import 'models/resp_models/patient_radiology_response_model.dart';
|
|
|
|
class RadiologyViewModel extends ChangeNotifier {
|
|
bool isRadiologyOrdersLoading = false;
|
|
bool isRadiologyPDFReportLoading = false;
|
|
|
|
RadiologyRepo radiologyRepo;
|
|
ErrorHandlerService errorHandlerService;
|
|
NavigationService navigationService;
|
|
|
|
List<PatientRadiologyResponseModel> patientRadiologyOrders = [];
|
|
List<PatientRadiologyResponseModel> filteredRadiologyOrders = [];
|
|
List<PatientRadiologyResponseModel> tempRadiologyOrders = [];
|
|
String radiologyImageURL = "";
|
|
String patientRadiologyReportPDFBase64 = "";
|
|
|
|
late List<String> _radiologySuggestionsList = [];
|
|
|
|
List<String> get radiologySuggestions => _radiologySuggestionsList;
|
|
|
|
late PatientRadiologyResponseModel patientRadiologyOrderByAppointment;
|
|
|
|
RadiologyViewModel({required this.radiologyRepo, required this.errorHandlerService, required this.navigationService});
|
|
|
|
initRadiologyViewModel() {
|
|
patientRadiologyOrders.clear();
|
|
filteredRadiologyOrders.clear();
|
|
isRadiologyOrdersLoading = true;
|
|
isRadiologyPDFReportLoading = true;
|
|
radiologyImageURL = "";
|
|
getPatientRadiologyOrders();
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> getPatientRadiologyOrders({Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
|
final result = await radiologyRepo.getPatientRadiologyOrders();
|
|
|
|
result.fold(
|
|
(failure) async => await errorHandlerService.handleError(failure: failure),
|
|
(apiResponse) {
|
|
if (apiResponse.messageStatus == 2) {
|
|
// dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
|
|
} else if (apiResponse.messageStatus == 1) {
|
|
patientRadiologyOrders = apiResponse.data!;
|
|
filteredRadiologyOrders = List.from(patientRadiologyOrders);
|
|
tempRadiologyOrders = [...patientRadiologyOrders];
|
|
isRadiologyOrdersLoading = false;
|
|
filterSuggestions();
|
|
notifyListeners();
|
|
if (onSuccess != null) {
|
|
onSuccess(apiResponse);
|
|
}
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<void> getPatientRadiologyOrdersByAppointment({required num appointmentNo, required num projectID, Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
|
final result = await radiologyRepo.getPatientRadiologyOrderByAppointment(appointmentNo: appointmentNo, projectID: projectID);
|
|
|
|
result.fold(
|
|
(failure) async => await errorHandlerService.handleError(failure: failure),
|
|
(apiResponse) {
|
|
if (apiResponse.messageStatus == 2) {
|
|
// dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
|
|
} else if (apiResponse.messageStatus == 1) {
|
|
notifyListeners();
|
|
if (apiResponse.data!.isNotEmpty) {
|
|
if (onSuccess != null) {
|
|
onSuccess(apiResponse);
|
|
}
|
|
navigationService.push(
|
|
CustomPageRoute(
|
|
page: RadiologyResultPage(patientRadiologyResponseModel: apiResponse.data!.first),
|
|
),
|
|
);
|
|
} else {
|
|
if (onError != null) {
|
|
onError("No Radiology Orders Found".needTranslation);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<void> getRadiologyImage(
|
|
{required PatientRadiologyResponseModel patientRadiologyResponseModel, Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
|
final result = await radiologyRepo.getRadiologyImage(patientRadiologyResponseModel: patientRadiologyResponseModel);
|
|
|
|
result.fold(
|
|
(failure) async => await errorHandlerService.handleError(failure: failure),
|
|
(apiResponse) {
|
|
if (apiResponse.messageStatus == 2) {
|
|
// dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
|
|
} else if (apiResponse.messageStatus == 1) {
|
|
radiologyImageURL = apiResponse.data!;
|
|
notifyListeners();
|
|
if (onSuccess != null) {
|
|
onSuccess(apiResponse);
|
|
}
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<void> getRadiologyPDF(
|
|
{required PatientRadiologyResponseModel patientRadiologyResponseModel,
|
|
required AuthenticatedUser authenticatedUser,
|
|
Function(dynamic)? onSuccess,
|
|
Function(String)? onError}) async {
|
|
final result =
|
|
await radiologyRepo.getRadiologyReportPDF(patientRadiologyResponseModel: patientRadiologyResponseModel, authenticatedUser: authenticatedUser);
|
|
|
|
result.fold(
|
|
(failure) async => await errorHandlerService.handleError(
|
|
failure: failure,
|
|
onOkPressed: () {
|
|
onError!(failure.message);
|
|
},
|
|
),
|
|
(apiResponse) {
|
|
if (apiResponse.messageStatus == 2) {
|
|
onError!(apiResponse.errorMessage!);
|
|
// dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
|
|
} else if (apiResponse.messageStatus == 1) {
|
|
patientRadiologyReportPDFBase64 = apiResponse.data!;
|
|
isRadiologyPDFReportLoading = false;
|
|
notifyListeners();
|
|
if (onSuccess != null) {
|
|
onSuccess(apiResponse);
|
|
}
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
filterSuggestions() {
|
|
final List<String> labels = patientRadiologyOrders.map((detail) => detail.description).whereType<String>().toList();
|
|
_radiologySuggestionsList = labels.toSet().toList();
|
|
notifyListeners();
|
|
}
|
|
|
|
filterRadiologyReports(String query) {
|
|
if (query.isEmpty) {
|
|
patientRadiologyOrders = tempRadiologyOrders; // reset
|
|
} else {
|
|
filteredRadiologyOrders = filteredRadiologyOrders.where((desc) => desc.description!.toLowerCase().contains(query.toLowerCase())).toList();
|
|
patientRadiologyOrders = filteredRadiologyOrders;
|
|
}
|
|
notifyListeners();
|
|
}
|
|
}
|