followup.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import 'package:fis_jsonrpc/rpc.dart';
  2. import 'package:uuid/uuid.dart';
  3. import 'package:vitalapp/database/db.dart';
  4. import 'package:vitalapp/database/entities/defines.dart';
  5. import 'package:vitalapp/database/entities/followup.dart';
  6. import 'package:vitalapp/store/store.dart';
  7. class FollowUpServiceMock extends VitalFollowUpService {
  8. FollowUpServiceMock(super.host);
  9. @override
  10. Future<String> createFollowUpAsync(CreateFollowUpRequest request) async {
  11. final entity = FollowUpEntity();
  12. final patientCode = Store.user.currentSelectPatientInfo!.code!;
  13. // 本地先生成一个Code,上传后更新
  14. final uuid = const Uuid().v4().replaceAll('-', '');
  15. entity.code = "mock_$uuid";
  16. entity.isValid = true;
  17. entity.syncType = OfflineDataSyncType.create;
  18. entity.userCode = Store.user.userCode!;
  19. entity.patientCode = patientCode;
  20. entity.contractDoctor = Store.user.displayName;
  21. entity.typeKey = request.key!;
  22. entity.templateCode = request.templateCode!;
  23. entity.mode = request.followUpMode;
  24. entity.followUpTime = request.followUpTime!;
  25. if (request.nextFollowUpTime != null) {
  26. // TODO: 理论不能为空,但是这个默认值目前没有确定
  27. entity.nextFollowUpTime = request.nextFollowUpTime!;
  28. }
  29. entity.followUpPhtots = request.followUpPhotos!;
  30. entity.dataJson = request.followUpData!;
  31. final id = await db.repositories.followUp.insert(entity);
  32. final success = id > 0;
  33. if (success) {
  34. if (entity.typeKey == "GXY") {
  35. // 统计数量+1
  36. await db.repositories.patient
  37. .increaseGxyFollowUpCount(patientCode, Store.user.userCode!);
  38. } else if (entity.typeKey == "TNB") {
  39. // 统计数量+1
  40. await db.repositories.patient
  41. .increaseTnbFollowUpCount(patientCode, Store.user.userCode!);
  42. }
  43. }
  44. final result = success ? entity.code : "";
  45. return result;
  46. }
  47. @override
  48. Future<bool> updateFollowUpAsync(UpdateFollowUpRequest request) async {
  49. FollowUpEntity? entity =
  50. await db.repositories.followUp.singleByCode(request.code!);
  51. if (entity == null) {
  52. entity = FollowUpEntity();
  53. entity.isValid = true;
  54. entity.syncType = OfflineDataSyncType.update;
  55. }
  56. final patientCode = Store.user.currentSelectPatientInfo!.code!;
  57. entity.code = request.code!;
  58. entity.userCode = Store.user.userCode!;
  59. entity.patientCode = patientCode;
  60. entity.contractDoctor = Store.user.principalName;
  61. entity.typeKey = request.key!;
  62. entity.mode = request.followUpMode!;
  63. entity.followUpTime = request.followUpTime!;
  64. if (request.nextFollowUpTime != null) {
  65. // TODO: 理论不能为空,但是这个默认值目前没有确定
  66. entity.nextFollowUpTime = request.nextFollowUpTime!;
  67. }
  68. entity.followUpPhtots = request.followUpPhotos!;
  69. entity.dataJson = request.followUpData!;
  70. int result;
  71. if (entity.id == -1) {
  72. result = await db.repositories.followUp.insert(entity);
  73. if (result > 0) {
  74. if (entity.typeKey == "GXY") {
  75. // 统计数量+1
  76. await db.repositories.patient
  77. .increaseGxyFollowUpCount(patientCode, Store.user.userCode!);
  78. } else if (entity.typeKey == "TNB") {
  79. // 统计数量+1
  80. await db.repositories.patient
  81. .increaseTnbFollowUpCount(patientCode, Store.user.userCode!);
  82. }
  83. }
  84. } else {
  85. result = await db.repositories.followUp.update(entity);
  86. }
  87. return result > 0;
  88. }
  89. @override
  90. Future<List<FollowUpRecordDTO>> getFollowUpRecordListAsync(
  91. GetFollowUpRecordListRequest request) async {
  92. final entities = await db.repositories.followUp.queryAllListByPatient(
  93. request.patientCode!,
  94. Store.user.userCode!,
  95. request.keys?.first,
  96. );
  97. if (entities.isEmpty) {
  98. return [];
  99. }
  100. // 都放一个Record里
  101. final record = FollowUpRecordDTO();
  102. final patient = Store.user.currentSelectPatientInfo;
  103. record.patientName = patient?.patientName ?? "";
  104. // record.contractedDoctor = patient?.contractedDoctorName ?? "";
  105. record.contractedDoctor = entities.first.contractDoctor;
  106. record.followUpRecordDatas = entities
  107. .map(
  108. (e) => FollowUpRecordDataDTO(
  109. code: e.code,
  110. templateCode: e.templateCode,
  111. key: e.typeKey,
  112. followUpDoctor: e.contractDoctor,
  113. followUpState: FollowUpStateEnum.FollowUpVisit,
  114. followUpMode: e.mode,
  115. followUpTime: e.followUpTime,
  116. nextFollowUpTime: e.nextFollowUpTime,
  117. followUpPhotos: e.followUpPhtots,
  118. followUpData: e.dataJson,
  119. ),
  120. )
  121. .toList();
  122. return [record];
  123. }
  124. }