follow_up.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import 'package:fis_common/event/event_type.dart';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:vitalapp/database/db.dart';
  5. import 'package:vitalapp/database/entities/defines.dart';
  6. import 'package:vitalapp/managers/interfaces/follow_up.dart';
  7. import 'package:vitalapp/rpc.dart';
  8. import 'package:vitalapp/store/store.dart';
  9. import 'package:fis_common/logger/logger.dart';
  10. class FollowUpManager implements IFollowUpManager {
  11. @override
  12. Future<String> createFollowUp(CreateFollowUpRequest examRequest) async {
  13. try {
  14. examRequest.token = Store.user.token;
  15. final examCode = await rpc.vitalFollowUp.createFollowUpAsync(
  16. examRequest,
  17. );
  18. return examCode;
  19. } catch (e) {
  20. logger.e("FollowUpManager createFollowUp error.", e);
  21. return '';
  22. }
  23. }
  24. @override
  25. Future<bool?> updateFollowUp(UpdateFollowUpRequest followRequest) async {
  26. try {
  27. followRequest.token = Store.user.token;
  28. final result = await rpc.vitalFollowUp.updateFollowUpAsync(
  29. followRequest,
  30. );
  31. return result;
  32. } catch (e) {
  33. logger.e("FollowUpManager updateFollowUp error.", e);
  34. return null;
  35. }
  36. }
  37. @override
  38. Future<bool> removeFollowUpAsync(String code, String key) async {
  39. try {
  40. final result = await rpc.vitalFollowUp.removeFollowUpAsync(
  41. RemoveFollowUpRequest(
  42. key: key,
  43. code: code,
  44. token: Store.user.token,
  45. ),
  46. );
  47. return result;
  48. } catch (e) {
  49. logger.e("FollowUpManager removeFollowUpAsync error.", e);
  50. }
  51. return false;
  52. }
  53. @override
  54. Future<List<FollowUpDTO>?> getFollowUpPage(
  55. FollowUpPageRequest followUpPageRequest) async {
  56. try {
  57. followUpPageRequest.token = Store.user.token;
  58. final result = await rpc.vitalFollowUp.getFollowUpPageAsync(
  59. followUpPageRequest,
  60. );
  61. return result.pageData;
  62. } catch (e) {
  63. logger.e("FollowUpManager getFollowUpPage error.", e);
  64. return null;
  65. }
  66. }
  67. @override
  68. Future<List<FollowUpRecordDTO>?> getFollowUpRecordList(
  69. List<String> keys, String patientCode) async {
  70. try {
  71. var request = GetFollowUpRecordListRequest(
  72. keys: keys,
  73. patientCode: patientCode,
  74. token: Store.user.token,
  75. );
  76. final result =
  77. await rpc.vitalFollowUp.getFollowUpRecordListAsync(request);
  78. return result;
  79. } catch (e) {
  80. return null;
  81. }
  82. }
  83. @override
  84. Future<List<FollowUpRecordDTO>?> getFollowUpRecordListByYearAsync(
  85. GetFollowUpRecordListByYearRequest
  86. followUpRecordListByYearRequest) async {
  87. try {
  88. followUpRecordListByYearRequest.token = Store.user.token;
  89. final result = await rpc.vitalFollowUp
  90. .getFollowUpRecordListByYearAsync(followUpRecordListByYearRequest);
  91. return result;
  92. } catch (e) {
  93. return null;
  94. }
  95. }
  96. Future<List<FollowUpRecordDTO>> getPatientNotUploadedRecordList(
  97. String patientCode, String key) async {
  98. final entities = await db.repositories.followUp.queryable
  99. .where(
  100. (x) => [
  101. x.isValid.equals(true),
  102. x.userCode.equals(Store.user.userCode),
  103. x.patientCode.equals(patientCode),
  104. x.typeKey.equals(key),
  105. x.syncState.notEquals(OfflineDataSyncState.success),
  106. ],
  107. )
  108. .toList();
  109. if (entities.isEmpty) {
  110. return [];
  111. }
  112. // 都放一个Record里
  113. final record = FollowUpRecordDTO();
  114. final patient = Store.user.currentSelectPatientInfo;
  115. record.patientName = patient?.patientName ?? "";
  116. // record.contractedDoctor = patient?.contractedDoctorName ?? "";
  117. record.contractedDoctor = entities.first.contractDoctor;
  118. record.followUpRecordDatas = entities
  119. .map(
  120. (e) => FollowUpRecordDataDTO(
  121. code: e.code,
  122. templateCode: e.templateCode,
  123. key: e.typeKey,
  124. followUpDoctor: e.contractDoctor,
  125. followUpState: FollowUpStateEnum.FollowUpVisit,
  126. followUpMode: e.mode,
  127. followUpTime: e.followUpTime,
  128. nextFollowUpTime: e.nextFollowUpTime,
  129. followUpPhotos: e.followUpPhtots,
  130. followUpData: e.dataJson,
  131. ),
  132. )
  133. .toList();
  134. return [record];
  135. }
  136. MaterialColor followUpStateColors(FollowUpStateEnum state) {
  137. switch (state) {
  138. case FollowUpStateEnum.NoFollowUp:
  139. return Colors.grey;
  140. case FollowUpStateEnum.Cancelled:
  141. return Colors.red;
  142. case FollowUpStateEnum.FollowUpVisit:
  143. return Colors.green;
  144. default:
  145. return Colors.blue;
  146. }
  147. }
  148. String getFollowUpMode(FollowUpModeEnum? modeEnum) {
  149. switch (modeEnum) {
  150. case FollowUpModeEnum.Outpatient:
  151. return "门诊";
  152. case FollowUpModeEnum.Phone:
  153. return "电话";
  154. case FollowUpModeEnum.Visit:
  155. return "上门";
  156. default:
  157. return "";
  158. }
  159. }
  160. String followUpStateTransition(FollowUpStateEnum state) {
  161. switch (state) {
  162. case FollowUpStateEnum.NoFollowUp:
  163. return "未随访";
  164. case FollowUpStateEnum.FollowUpVisit:
  165. return "已随访";
  166. case FollowUpStateEnum.Cancelled:
  167. return "已作废";
  168. default:
  169. return "";
  170. }
  171. }
  172. final FEventHandler<String> onFollowMedicalData = FEventHandler<String>();
  173. }