import 'dart:convert'; import 'package:fis_common/logger/logger.dart'; import 'package:fis_jsonrpc/rpc.dart'; import 'package:vitalapp/managers/interfaces/prescription.dart'; import 'package:vitalapp/rpc.dart'; import 'package:vitalapp/store/store.dart'; class PrescriptionManager implements IPrescriptionManager { PrescriptionManager(); @override Future createPrescription({ required String patientCode, required String prescriptionKey, String? physicalExamNumber, String? followUpCode, String? prescriptionData, }) async { try { CreatePrescriptionRequest request = CreatePrescriptionRequest( patientCode: patientCode, physicalExamNumber: physicalExamNumber, followUpCode: followUpCode, prescriptionData: prescriptionData, key: prescriptionKey, token: Store.user.token, ); print(jsonEncode(request.toJson())); logger.i( "PrescriptionManager updatePrescription request:${jsonEncode(request.toJson())}.", ); String prescriptionCode = await rpc.vitalPrescription.createPrescriptionAsync(request); return prescriptionCode; } catch (e) { logger.e("createPrescription error.", e); return null; } } @override Future getPrescriptionDetailByFollowAnPatient({ required String patientCode, String? followUpCode, }) async { try { GetPrescriptionDetailByFollowAnPatientRequest request = GetPrescriptionDetailByFollowAnPatientRequest( token: Store.user.token, followUpCode: followUpCode, patientCode: patientCode, ); PrescriptionDTO? prescription = await rpc.vitalPrescription .getPrescriptionDetailByFollowAnPatientAsync(request); return prescription; } catch (e) { logger.e("getPrescriptionDetailByFollowAnPatient error.", e); return null; } } @override Future?> getPrescriptionPage({ required String patientCode, String? physicalExamNumber, String? followUpCode, }) async { try { PrescriptionPageRequest request = PrescriptionPageRequest( token: Store.user.token, physicalExamNumber: physicalExamNumber, followUpCode: followUpCode, patientCode: patientCode, pageIndex: 1, pageSize: 1000, ); PageCollection prescription = await rpc.vitalPrescription.getPrescriptionPageAsync(request); return prescription.pageData; } catch (e) { logger.e("getPrescriptionPage error.", e); return null; } } @override Future updatePrescription({ required String patientCode, required String prescriptionKey, required String prescriptionCode, String? physicalExamNumber, String? followUpCode, String? prescriptionData, }) async { try { UpdatePrescriptionRequest request = UpdatePrescriptionRequest( patientCode: patientCode, physicalExamNumber: physicalExamNumber, followUpCode: followUpCode, prescriptionData: prescriptionData, key: prescriptionKey, code: prescriptionCode, token: Store.user.token, ); logger.i( "PrescriptionManager updatePrescription request:${jsonEncode(request.toJson())}.", ); bool result = await rpc.vitalPrescription.updatePrescriptionAsync(request); return result; } catch (e) { logger.e("createPrescription error.", e); return null; } } @override Future removePrescription({ required String prescriptionCode, }) async { try { RemovePrescriptionRequest request = RemovePrescriptionRequest( code: prescriptionCode, token: Store.user.token, ); bool result = await rpc.vitalPrescription.removePrescriptionAsync(request); return result; } catch (e) { logger.e("removePrescription error.", e); return null; } } }