|
|
|
|
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/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/features/lab/models/resp_models/patient_lab_orders_response_model.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/features/lab/models/resp_models/patient_lab_special_result.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
|
|
|
|
|
|
|
|
|
import 'models/resp_models/lab_result.dart' show LabResult;
|
|
|
|
|
|
|
|
|
|
abstract class LabRepo {
|
|
|
|
|
Future<Either<Failure, GenericApiModel<List<PatientLabOrdersResponseModel>>>> getPatientLabOrders();
|
|
|
|
|
Future<Either<Failure, GenericApiModel<List<LabResult>>>> getPatientLabResults(PatientLabOrdersResponseModel laborder, bool isVidaPlus, String procedureName);
|
|
|
|
|
|
|
|
|
|
Future<Either<Failure, GenericApiModel<List<LabResult>>>>
|
|
|
|
|
getPatientLabResultsByHospitals(
|
|
|
|
|
PatientLabOrdersResponseModel laborder, bool isVidaPlus);
|
|
|
|
|
|
|
|
|
|
Future<Either<Failure, GenericApiModel<List<PatientLabSpecialResult>>>>
|
|
|
|
|
getSpecialLabResult(
|
|
|
|
|
PatientLabOrdersResponseModel laborder, bool isVidaPlus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class LabRepoImp implements LabRepo {
|
|
|
|
|
final ApiClient apiClient;
|
|
|
|
|
final LoggerService loggerService;
|
|
|
|
|
|
|
|
|
|
LabRepoImp({required this.loggerService, required this.apiClient});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<Either<Failure, GenericApiModel<List<PatientLabOrdersResponseModel>>>> getPatientLabOrders() async {
|
|
|
|
|
Map<String, dynamic> mapDevice = {};
|
|
|
|
|
try {
|
|
|
|
|
GenericApiModel<List<PatientLabOrdersResponseModel>>? apiResponse;
|
|
|
|
|
Failure? failure;
|
|
|
|
|
await apiClient.post(
|
|
|
|
|
GET_Patient_LAB_ORDERS,
|
|
|
|
|
body: mapDevice,
|
|
|
|
|
onFailure: (error, statusCode, {messageStatus, failureType}) {
|
|
|
|
|
failure = failureType;
|
|
|
|
|
},
|
|
|
|
|
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
|
|
|
|
try {
|
|
|
|
|
final list = response['ListPLO'];
|
|
|
|
|
if (list == null || list.isEmpty) {
|
|
|
|
|
throw Exception("lab list is empty");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final labOrders = list.map((item) => PatientLabOrdersResponseModel.fromJson(item as Map<String, dynamic>)).toList().cast<PatientLabOrdersResponseModel>();
|
|
|
|
|
|
|
|
|
|
apiResponse = GenericApiModel<List<PatientLabOrdersResponseModel>>(
|
|
|
|
|
messageStatus: messageStatus,
|
|
|
|
|
statusCode: statusCode,
|
|
|
|
|
errorMessage: null,
|
|
|
|
|
data: labOrders,
|
|
|
|
|
);
|
|
|
|
|
} 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()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<Either<Failure, GenericApiModel<List<LabResult>>>> getPatientLabResults(
|
|
|
|
|
PatientLabOrdersResponseModel laborder, bool isVidaPlus, String procedureName
|
|
|
|
|
) async {
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> request = Map();
|
|
|
|
|
request['InvoiceNo_VP'] = isVidaPlus ? laborder!.invoiceNo : "0";
|
|
|
|
|
request['InvoiceNo'] = isVidaPlus ? "0" : laborder!.invoiceNo;
|
|
|
|
|
request['OrderNo'] = laborder!.orderNo;
|
|
|
|
|
request['isDentalAllowedBackend'] = false;
|
|
|
|
|
request['SetupID'] = laborder!.setupID;
|
|
|
|
|
request['ProjectID'] = laborder.projectID;
|
|
|
|
|
request['ClinicID'] = laborder.clinicID;
|
|
|
|
|
request['Procedure'] = procedureName;
|
|
|
|
|
try {
|
|
|
|
|
GenericApiModel<List<LabResult>>? apiResponse;
|
|
|
|
|
Failure? failure;
|
|
|
|
|
await apiClient.post(
|
|
|
|
|
GET_Patient_LAB_ORDERS_RESULT,
|
|
|
|
|
body: request,
|
|
|
|
|
onFailure: (error, statusCode, {messageStatus, failureType}) {
|
|
|
|
|
failure = failureType;
|
|
|
|
|
},
|
|
|
|
|
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
|
|
|
|
try {
|
|
|
|
|
final list = response['ListPLR'];
|
|
|
|
|
if (list == null || list.isEmpty) {
|
|
|
|
|
throw Exception("lab list is empty");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final labOrders = list
|
|
|
|
|
.map((item) => LabResult.fromJson(item as Map<String, dynamic>))
|
|
|
|
|
.toList()
|
|
|
|
|
.cast<LabResult>();
|
|
|
|
|
|
|
|
|
|
apiResponse = GenericApiModel<List<LabResult>>(
|
|
|
|
|
messageStatus: messageStatus,
|
|
|
|
|
statusCode: statusCode,
|
|
|
|
|
errorMessage: null,
|
|
|
|
|
data: labOrders,
|
|
|
|
|
);
|
|
|
|
|
} 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()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<Either<Failure, GenericApiModel<List<LabResult>>>>
|
|
|
|
|
getPatientLabResultsByHospitals(
|
|
|
|
|
PatientLabOrdersResponseModel laborder, bool isVidaPlus) async {
|
|
|
|
|
Map<String, dynamic> request = Map();
|
|
|
|
|
request['InvoiceNo_VP'] = isVidaPlus ? laborder!.invoiceNo : "0";
|
|
|
|
|
request['InvoiceNo'] = isVidaPlus ? "0" : laborder!.invoiceNo;
|
|
|
|
|
request['OrderNo'] = laborder!.orderNo;
|
|
|
|
|
request['isDentalAllowedBackend'] = false;
|
|
|
|
|
request['SetupID'] = laborder!.setupID;
|
|
|
|
|
request['ProjectID'] = laborder.projectID;
|
|
|
|
|
request['ClinicID'] = laborder.clinicID;
|
|
|
|
|
try {
|
|
|
|
|
GenericApiModel<List<LabResult>>? apiResponse;
|
|
|
|
|
Failure? failure;
|
|
|
|
|
await apiClient.post(
|
|
|
|
|
GET_Patient_LAB_RESULT,
|
|
|
|
|
body: request,
|
|
|
|
|
onFailure: (error, statusCode, {messageStatus, failureType}) {
|
|
|
|
|
failure = failureType;
|
|
|
|
|
},
|
|
|
|
|
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
|
|
|
|
try {
|
|
|
|
|
final list = response['ListPLR'];
|
|
|
|
|
if (list == null || list.isEmpty) {
|
|
|
|
|
throw Exception("lab list is empty");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final labOrders = list.map((item) => LabResult.fromJson(item as Map<String, dynamic>)).toList().cast<LabResult>();
|
|
|
|
|
|
|
|
|
|
apiResponse = GenericApiModel<List<LabResult>>(
|
|
|
|
|
messageStatus: messageStatus,
|
|
|
|
|
statusCode: statusCode,
|
|
|
|
|
errorMessage: null,
|
|
|
|
|
data: labOrders,
|
|
|
|
|
);
|
|
|
|
|
} 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()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<Either<Failure, GenericApiModel<List<PatientLabSpecialResult>>>>
|
|
|
|
|
getSpecialLabResult(
|
|
|
|
|
PatientLabOrdersResponseModel laborder, bool isVidaPlus) async {
|
|
|
|
|
Map<String, dynamic> request = Map();
|
|
|
|
|
request['InvoiceNo_VP'] = isVidaPlus ? laborder!.invoiceNo : "0";
|
|
|
|
|
request['InvoiceNo'] = isVidaPlus ? "0" : laborder!.invoiceNo;
|
|
|
|
|
request['OrderNo'] = laborder!.orderNo;
|
|
|
|
|
request['isDentalAllowedBackend'] = false;
|
|
|
|
|
request['SetupID'] = laborder!.setupID;
|
|
|
|
|
request['ProjectID'] = laborder.projectID;
|
|
|
|
|
request['ClinicID'] = laborder.clinicID;
|
|
|
|
|
try {
|
|
|
|
|
GenericApiModel<List<PatientLabSpecialResult>>? apiResponse;
|
|
|
|
|
Failure? failure;
|
|
|
|
|
await apiClient.post(
|
|
|
|
|
GET_Patient_LAB_SPECIAL_RESULT,
|
|
|
|
|
body: request,
|
|
|
|
|
onFailure: (error, statusCode, {messageStatus, failureType}) {
|
|
|
|
|
failure = failureType;
|
|
|
|
|
},
|
|
|
|
|
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
|
|
|
|
try {
|
|
|
|
|
final list = response['ListPLSR'];
|
|
|
|
|
if (list == null || list.isEmpty) {
|
|
|
|
|
throw Exception("lab list is empty");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final labOrders = list
|
|
|
|
|
.map((item) => PatientLabSpecialResult.fromJson(
|
|
|
|
|
item as Map<String, dynamic>))
|
|
|
|
|
.toList()
|
|
|
|
|
.cast<PatientLabSpecialResult>();
|
|
|
|
|
|
|
|
|
|
apiResponse = GenericApiModel<List<PatientLabSpecialResult>>(
|
|
|
|
|
messageStatus: messageStatus,
|
|
|
|
|
statusCode: statusCode,
|
|
|
|
|
errorMessage: null,
|
|
|
|
|
data: labOrders,
|
|
|
|
|
);
|
|
|
|
|
} 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()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|