contract.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import 'package:fis_jsonrpc/rpc.dart';
  2. import 'package:vitalapp/managers/interfaces/contract.dart';
  3. import 'package:vitalapp/rpc.dart';
  4. import 'package:vitalapp/store/store.dart';
  5. class ContractManager implements IContractManager {
  6. @override
  7. Future<String?> createContractRecordAsync(
  8. CreateContractRecordRequest request) async {
  9. try {
  10. request.token = Store.user.token;
  11. final result =
  12. await rpc.contractRecord.createContractRecordAsync(request);
  13. return result;
  14. } catch (e) {
  15. // logger.e("PatientManager create patient error.", e);
  16. return null;
  17. }
  18. }
  19. @override
  20. Future<PageCollection<ContractRecordDTO>?>
  21. getContractRecordPageByPatientCodeAsync(String patientCode) async {
  22. try {
  23. final result = await rpc.contractRecord
  24. .getContractRecordPageByPatientCodeAsync(
  25. GetContractRecordPageByPatientCodeRequest(
  26. patientCode: patientCode,
  27. token: Store.user.token,
  28. pageSize: 20,
  29. pageIndex: 1));
  30. return result;
  31. } catch (e) {
  32. return null;
  33. }
  34. }
  35. @override
  36. Future<PageCollection<ContractRecordDTO>?>
  37. getContractRecordPageAsync() async {
  38. try {
  39. final result = await rpc.contractRecord.getContractRecordPageAsync(
  40. ContractRecordPageRequest(
  41. token: Store.user.token, pageSize: 20, pageIndex: 1));
  42. return result;
  43. } catch (e) {
  44. return null;
  45. }
  46. }
  47. @override
  48. Future<ContractRecordDTO?> getContractRecordDetailAsync(
  49. String patientCode) async {
  50. try {
  51. var request = GetContractRecordRequest(
  52. code: patientCode,
  53. token: Store.user.token,
  54. );
  55. final result =
  56. await rpc.contractRecord.getContractRecordDetailAsync(request);
  57. return result;
  58. } catch (e) {
  59. return null;
  60. }
  61. }
  62. @override
  63. Future<bool> updateContractRecordStateAsync(
  64. String? code, ContractStateEnum? contractState, String? reason) async {
  65. try {
  66. var request = UpdateContractRecordStateRequest(
  67. code: code,
  68. contractState: contractState,
  69. reason: reason,
  70. token: Store.user.token,
  71. );
  72. final result =
  73. await rpc.contractRecord.updateContractRecordStateAsync(request);
  74. return result;
  75. } catch (e) {}
  76. return false;
  77. }
  78. @override
  79. Future<bool> removeContractRecordAsync(String code) async {
  80. try {
  81. var request = RemoveContractRecordRequest(
  82. code: code,
  83. token: Store.user.token,
  84. );
  85. final result =
  86. await rpc.contractRecord.removeContractRecordAsync(request);
  87. return result;
  88. } catch (e) {}
  89. return false;
  90. }
  91. @override
  92. Future<String> renewalContractRecordAsync(String code) async {
  93. try {
  94. var request = RenewalContractRecordRequest(
  95. token: Store.user.token,
  96. code: code,
  97. serviceStartDate: DateTime.now(),
  98. serviceEndDate: DateTime.now().add(const Duration(days: 365)),
  99. );
  100. final result =
  101. await rpc.contractRecord.renewalContractRecordAsync(request);
  102. return result;
  103. } catch (e) {}
  104. return "";
  105. }
  106. }