|
|
|
|
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/features/radiology/models/resp_models/patient_radiology_response_model.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
|
|
|
|
|
|
|
|
|
abstract class RadiologyRepo {
|
|
|
|
|
Future<Either<Failure, GenericApiModel<List<PatientRadiologyResponseModel>>>> getPatientRadiologyOrders({required String patientId});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RadiologyRepoImp implements RadiologyRepo {
|
|
|
|
|
final ApiClient apiClient;
|
|
|
|
|
final LoggerService loggerService;
|
|
|
|
|
|
|
|
|
|
RadiologyRepoImp({required this.loggerService, required this.apiClient});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<Either<Failure, GenericApiModel<List<PatientRadiologyResponseModel>>>> getPatientRadiologyOrders({required String patientId}) async {
|
|
|
|
|
Map<String, dynamic> mapDevice = {};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
GenericApiModel<List<PatientRadiologyResponseModel>>? apiResponse;
|
|
|
|
|
Failure? failure;
|
|
|
|
|
await apiClient.post(
|
|
|
|
|
GET_PATIENT_ORDERS,
|
|
|
|
|
body: mapDevice,
|
|
|
|
|
onFailure: (error, statusCode, {messageStatus, failureType}) {
|
|
|
|
|
failure = failureType;
|
|
|
|
|
},
|
|
|
|
|
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
|
|
|
|
final radOrders;
|
|
|
|
|
try {
|
|
|
|
|
if (response['FinalRadiologyList'] != null && response['FinalRadiologyList'].length != 0) {
|
|
|
|
|
final list = response['FinalRadiologyList'];
|
|
|
|
|
radOrders = list.map((item) => PatientRadiologyResponseModel.fromJson(item as Map<String, dynamic>)).toList().cast<PatientRadiologyResponseModel>();
|
|
|
|
|
} else {
|
|
|
|
|
final list = response['FinalRadiologyListAPI'];
|
|
|
|
|
radOrders = list.map((item) => PatientRadiologyResponseModel.fromJson(item as Map<String, dynamic>)).toList().cast<PatientRadiologyResponseModel>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
apiResponse = GenericApiModel<List<PatientRadiologyResponseModel>>(
|
|
|
|
|
messageStatus: messageStatus,
|
|
|
|
|
statusCode: statusCode,
|
|
|
|
|
errorMessage: null,
|
|
|
|
|
data: radOrders,
|
|
|
|
|
);
|
|
|
|
|
} 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()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|