Monthly Reports implemented
parent
255353dd21
commit
ede8844f19
@ -1,3 +1,3 @@
|
||||
add_<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M20.1905 5.77665C20.59 6.15799 20.6047 6.79098 20.2234 7.19048L9.72336 18.1905C9.53745 18.3852 9.28086 18.4968 9.01163 18.4999C8.7424 18.5031 8.48328 18.3975 8.29289 18.2071L4.79289 14.7071C4.40237 14.3166 4.40237 13.6834 4.79289 13.2929C5.18342 12.9024 5.81658 12.9024 6.20711 13.2929L8.98336 16.0692L18.7766 5.80953C19.158 5.41003 19.791 5.39531 20.1905 5.77665Z" fill="white"/>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 537 B After Width: | Height: | Size: 533 B |
@ -0,0 +1,53 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:hmg_patient_app_new/core/api/api_client.dart';
|
||||
import 'package:hmg_patient_app_new/core/api_consts.dart';
|
||||
import 'package:hmg_patient_app_new/core/common_models/generic_api_model.dart';
|
||||
import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart';
|
||||
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
||||
|
||||
abstract class MonthlyReportRepo {
|
||||
Future<Either<Failure, GenericApiModel<dynamic>>> updatePatientHealthSummaryReport({required bool rSummaryReport});
|
||||
}
|
||||
|
||||
class MonthlyReportRepoImp implements MonthlyReportRepo {
|
||||
final ApiClient apiClient;
|
||||
final LoggerService loggerService;
|
||||
|
||||
MonthlyReportRepoImp({required this.loggerService, required this.apiClient});
|
||||
|
||||
@override
|
||||
Future<Either<Failure, GenericApiModel<dynamic>>> updatePatientHealthSummaryReport({required bool rSummaryReport}) async {
|
||||
Map<String, dynamic> mapDevice = {
|
||||
"RSummaryReport": rSummaryReport,
|
||||
};
|
||||
|
||||
try {
|
||||
GenericApiModel<dynamic>? apiResponse;
|
||||
Failure? failure;
|
||||
await apiClient.post(
|
||||
UPDATE_HEALTH_TERMS,
|
||||
body: mapDevice,
|
||||
onFailure: (error, statusCode, {messageStatus, failureType}) {
|
||||
failure = failureType;
|
||||
},
|
||||
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
||||
try {
|
||||
apiResponse = GenericApiModel<dynamic>(
|
||||
messageStatus: messageStatus,
|
||||
statusCode: statusCode,
|
||||
errorMessage: errorMessage,
|
||||
data: response,
|
||||
);
|
||||
} catch (e) {
|
||||
failure = DataParsingFailure(e.toString());
|
||||
}
|
||||
},
|
||||
);
|
||||
if (failure != null) return Left(failure!);
|
||||
if (apiResponse == null) return Left(ServerFailure("Unknown error"));
|
||||
return Right(apiResponse!);
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hmg_patient_app_new/features/monthly_report/monthly_report_repo.dart';
|
||||
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
|
||||
|
||||
class MonthlyReportViewModel extends ChangeNotifier {
|
||||
MonthlyReportRepo monthlyReportRepo;
|
||||
ErrorHandlerService errorHandlerService;
|
||||
|
||||
bool isUpdateHealthSummaryLoading = false;
|
||||
bool isHealthSummaryEnabled = false;
|
||||
|
||||
MonthlyReportViewModel({
|
||||
required this.monthlyReportRepo,
|
||||
required this.errorHandlerService,
|
||||
});
|
||||
|
||||
setHealthSummaryEnabled(bool value) {
|
||||
isHealthSummaryEnabled = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> updatePatientHealthSummaryReport({
|
||||
required bool rSummaryReport,
|
||||
Function(dynamic)? onSuccess,
|
||||
Function(String)? onError,
|
||||
}) async {
|
||||
isUpdateHealthSummaryLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
final result = await monthlyReportRepo.updatePatientHealthSummaryReport(
|
||||
rSummaryReport: rSummaryReport,
|
||||
);
|
||||
|
||||
result.fold(
|
||||
(failure) async {
|
||||
isUpdateHealthSummaryLoading = false;
|
||||
notifyListeners();
|
||||
await errorHandlerService.handleError(failure: failure);
|
||||
if (onError != null) {
|
||||
onError(failure.toString());
|
||||
}
|
||||
},
|
||||
(apiResponse) {
|
||||
isUpdateHealthSummaryLoading = false;
|
||||
if (apiResponse.messageStatus == 2) {
|
||||
notifyListeners();
|
||||
if (onError != null) {
|
||||
onError(apiResponse.errorMessage ?? "Unknown error");
|
||||
}
|
||||
} else if (apiResponse.messageStatus == 1) {
|
||||
// Update the local state on success
|
||||
isHealthSummaryEnabled = rSummaryReport;
|
||||
notifyListeners();
|
||||
if (onSuccess != null) {
|
||||
onSuccess(apiResponse);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue