|
|
|
|
@ -3,6 +3,7 @@ import 'package:hmg_patient_app_new/core/api_consts.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/common_models/generic_api_model.dart';
|
|
|
|
|
import 'package:dartz/dartz.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/features/prescriptions/models/resp_models/patient_prescriptions_response_model.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/features/prescriptions/models/resp_models/prescription_detail_response_model.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
|
|
|
|
@ -13,6 +14,8 @@ abstract class PrescriptionsRepo {
|
|
|
|
|
Future<Either<Failure, GenericApiModel<List<PrescriptionDetailResponseModel>>>> getPatientPrescriptionDetails({required PatientPrescriptionsResponseModel prescriptionsResponseModel});
|
|
|
|
|
|
|
|
|
|
Future<Either<Failure, GenericApiModel<dynamic>>> getPrescriptionInstructionsPDF({required PatientPrescriptionsResponseModel prescriptionsResponseModel});
|
|
|
|
|
|
|
|
|
|
Future<Either<Failure, GenericApiModel<dynamic>>> getPrescriptionPDF({required PatientPrescriptionsResponseModel prescriptionsResponseModel, required List<PrescriptionDetailResponseModel> prescriptionDetailsList});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PrescriptionsRepoImp implements PrescriptionsRepo {
|
|
|
|
|
@ -153,4 +156,54 @@ class PrescriptionsRepoImp implements PrescriptionsRepo {
|
|
|
|
|
return Left(UnknownFailure(e.toString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<Either<Failure, GenericApiModel>> getPrescriptionPDF({required PatientPrescriptionsResponseModel prescriptionsResponseModel, required List<PrescriptionDetailResponseModel> prescriptionDetailsList}) async {
|
|
|
|
|
Map<String, dynamic> mapDevice = {
|
|
|
|
|
"AppointmentDate": prescriptionsResponseModel.appointmentDate,
|
|
|
|
|
"ClinicName": prescriptionsResponseModel.clinicDescription,
|
|
|
|
|
"DoctorName": prescriptionsResponseModel.doctorName,
|
|
|
|
|
"ProjectID": prescriptionsResponseModel.projectID,
|
|
|
|
|
"DoctorID": prescriptionsResponseModel.doctorID,
|
|
|
|
|
"ClinicID": prescriptionsResponseModel.clinicID,
|
|
|
|
|
"DateofBirth": Utils.appState.getAuthenticatedUser()!.dateofBirth,
|
|
|
|
|
"ListPrescriptions": prescriptionDetailsList,
|
|
|
|
|
"PatientIditificationNum": Utils.appState.getAuthenticatedUser()!.patientIdentificationNo,
|
|
|
|
|
"PatientMobileNumber": Utils.appState.getAuthenticatedUser()!.mobileNumber,
|
|
|
|
|
"PatientName": "${Utils.appState.getAuthenticatedUser()!.firstName!} ${Utils.appState.getAuthenticatedUser()!.lastName!}",
|
|
|
|
|
"To": Utils.appState.getAuthenticatedUser()!.emailAddress,
|
|
|
|
|
"SetupID": prescriptionsResponseModel.setupID,
|
|
|
|
|
"IsDownload": true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
GenericApiModel<dynamic>? apiResponse;
|
|
|
|
|
Failure? failure;
|
|
|
|
|
await apiClient.post(
|
|
|
|
|
SEND_PRESCRIPTION_EMAIL,
|
|
|
|
|
body: mapDevice,
|
|
|
|
|
onFailure: (error, statusCode, {messageStatus, failureType}) {
|
|
|
|
|
failure = failureType;
|
|
|
|
|
},
|
|
|
|
|
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
|
|
|
|
try {
|
|
|
|
|
final prescriptionPDFData = response["Base64Data"];
|
|
|
|
|
apiResponse = GenericApiModel<dynamic>(
|
|
|
|
|
messageStatus: messageStatus,
|
|
|
|
|
statusCode: statusCode,
|
|
|
|
|
errorMessage: null,
|
|
|
|
|
data: prescriptionPDFData,
|
|
|
|
|
);
|
|
|
|
|
} 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()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|