prescription.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import 'dart:convert';
  2. import 'package:fis_common/logger/logger.dart';
  3. import 'package:fis_jsonrpc/rpc.dart';
  4. import 'package:vitalapp/managers/interfaces/prescription.dart';
  5. import 'package:vitalapp/rpc.dart';
  6. import 'package:vitalapp/store/store.dart';
  7. class PrescriptionManager implements IPrescriptionManager {
  8. PrescriptionManager();
  9. @override
  10. Future<String?> createPrescription({
  11. required String patientCode,
  12. required String prescriptionKey,
  13. String? physicalExamNumber,
  14. String? followUpCode,
  15. String? prescriptionData,
  16. }) async {
  17. try {
  18. CreatePrescriptionRequest request = CreatePrescriptionRequest(
  19. patientCode: patientCode,
  20. physicalExamNumber: physicalExamNumber,
  21. followUpCode: followUpCode,
  22. prescriptionData: prescriptionData,
  23. key: prescriptionKey,
  24. token: Store.user.token,
  25. );
  26. print(jsonEncode(request.toJson()));
  27. logger.i(
  28. "PrescriptionManager updatePrescription request:${jsonEncode(request.toJson())}.",
  29. );
  30. String prescriptionCode =
  31. await rpc.vitalPrescription.createPrescriptionAsync(request);
  32. return prescriptionCode;
  33. } catch (e) {
  34. logger.e("createPrescription error.", e);
  35. return null;
  36. }
  37. }
  38. @override
  39. Future<PrescriptionDTO?> getPrescriptionDetailByFollowAnPatient({
  40. required String patientCode,
  41. String? followUpCode,
  42. }) async {
  43. try {
  44. GetPrescriptionDetailByFollowAnPatientRequest request =
  45. GetPrescriptionDetailByFollowAnPatientRequest(
  46. token: Store.user.token,
  47. followUpCode: followUpCode,
  48. patientCode: patientCode,
  49. );
  50. PrescriptionDTO? prescription = await rpc.vitalPrescription
  51. .getPrescriptionDetailByFollowAnPatientAsync(request);
  52. return prescription;
  53. } catch (e) {
  54. logger.e("getPrescriptionDetailByFollowAnPatient error.", e);
  55. return null;
  56. }
  57. }
  58. @override
  59. Future<List<PrescriptionDTO>?> getPrescriptionPage({
  60. required String patientCode,
  61. String? physicalExamNumber,
  62. String? followUpCode,
  63. }) async {
  64. try {
  65. PrescriptionPageRequest request = PrescriptionPageRequest(
  66. token: Store.user.token,
  67. physicalExamNumber: physicalExamNumber,
  68. followUpCode: followUpCode,
  69. patientCode: patientCode,
  70. pageIndex: 1,
  71. pageSize: 1000,
  72. );
  73. PageCollection<PrescriptionDTO> prescription =
  74. await rpc.vitalPrescription.getPrescriptionPageAsync(request);
  75. return prescription.pageData;
  76. } catch (e) {
  77. logger.e("getPrescriptionPage error.", e);
  78. return null;
  79. }
  80. }
  81. @override
  82. Future<bool?> updatePrescription({
  83. required String patientCode,
  84. required String prescriptionKey,
  85. required String prescriptionCode,
  86. String? physicalExamNumber,
  87. String? followUpCode,
  88. String? prescriptionData,
  89. }) async {
  90. try {
  91. UpdatePrescriptionRequest request = UpdatePrescriptionRequest(
  92. patientCode: patientCode,
  93. physicalExamNumber: physicalExamNumber,
  94. followUpCode: followUpCode,
  95. prescriptionData: prescriptionData,
  96. key: prescriptionKey,
  97. code: prescriptionCode,
  98. token: Store.user.token,
  99. );
  100. logger.i(
  101. "PrescriptionManager updatePrescription request:${jsonEncode(request.toJson())}.",
  102. );
  103. bool result =
  104. await rpc.vitalPrescription.updatePrescriptionAsync(request);
  105. return result;
  106. } catch (e) {
  107. logger.e("createPrescription error.", e);
  108. return null;
  109. }
  110. }
  111. @override
  112. Future<bool?> removePrescription({
  113. required String prescriptionCode,
  114. }) async {
  115. try {
  116. RemovePrescriptionRequest request = RemovePrescriptionRequest(
  117. code: prescriptionCode,
  118. token: Store.user.token,
  119. );
  120. bool result =
  121. await rpc.vitalPrescription.removePrescriptionAsync(request);
  122. return result;
  123. } catch (e) {
  124. logger.e("removePrescription error.", e);
  125. return null;
  126. }
  127. }
  128. }