followup.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import 'package:fis_jsonrpc/services/followUp.dart';
  2. import 'package:fis_jsonrpc/services/followUp.m.dart';
  3. import 'package:uuid/uuid.dart';
  4. import 'package:vitalapp/database/db.dart';
  5. import 'package:vitalapp/database/entities/defines.dart';
  6. import 'package:vitalapp/database/entities/followup.dart';
  7. import 'package:vitalapp/store/store.dart';
  8. class FollowUpServiceMock extends VitalFollowUpService {
  9. FollowUpServiceMock(super.host);
  10. @override
  11. Future<String> createFollowUpAsync(CreateFollowUpRequest request) async {
  12. final entity = FollowUpEntity();
  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 = Store.user.currentSelectPatientInfo!.code!;
  20. entity.contractDoctor = Store.user.principalName;
  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. // 统计数量+1
  35. await db.repositories.patient
  36. .increaseFollowUpCount(entity.code, Store.user.userCode!);
  37. }
  38. final result = success ? entity.code : "";
  39. return result;
  40. }
  41. @override
  42. Future<bool> updateFollowUpAsync(UpdateFollowUpRequest request) async {
  43. FollowUpEntity? entity =
  44. await db.repositories.followUp.singleByCode(request.code!);
  45. if (entity == null) {
  46. entity = FollowUpEntity();
  47. entity.isValid = true;
  48. entity.syncType = OfflineDataSyncType.update;
  49. }
  50. entity.code = request.code!;
  51. entity.userCode = Store.user.userCode!;
  52. entity.patientCode = Store.user.currentSelectPatientInfo!.code!;
  53. entity.contractDoctor =
  54. Store.user.currentSelectPatientInfo!.contractedDoctorName!;
  55. entity.typeKey = request.key!;
  56. entity.mode = request.followUpMode!;
  57. entity.followUpTime = request.followUpTime!;
  58. entity.nextFollowUpTime = request.nextFollowUpTime!;
  59. entity.followUpPhtots = request.followUpPhotos!;
  60. entity.dataJson = request.followUpData!;
  61. int result;
  62. if (entity.id == 0) {
  63. result = await db.repositories.followUp.insert(entity);
  64. if (result > 0) {
  65. // 统计数量+1
  66. await db.repositories.patient
  67. .increaseFollowUpCount(entity.code, Store.user.userCode!);
  68. }
  69. } else {
  70. result = await db.repositories.followUp.update(entity);
  71. }
  72. return result > 0;
  73. }
  74. @override
  75. Future<List<FollowUpRecordDTO>> getFollowUpRecordListAsync(
  76. GetFollowUpRecordListRequest request) async {
  77. final entities = await db.repositories.followUp
  78. .queryAllListByPatient(request.patientCode!, Store.user.userCode!);
  79. if (entities.isEmpty) {
  80. return [];
  81. }
  82. // 都放一个Record里
  83. final record = FollowUpRecordDTO();
  84. final patient = Store.user.currentSelectPatientInfo;
  85. record.patientName = patient?.patientName ?? "";
  86. // record.contractedDoctor = patient?.contractedDoctorName ?? "";
  87. record.contractedDoctor = entities.first.contractDoctor;
  88. record.followUpRecordDatas = entities
  89. .map(
  90. (e) => FollowUpRecordDataDTO(
  91. code: e.code,
  92. templateCode: e.templateCode,
  93. key: e.typeKey,
  94. followUpDoctor: e.contractDoctor,
  95. followUpState: FollowUpStateEnum.FollowUpVisit,
  96. followUpMode: e.mode,
  97. followUpTime: e.followUpTime,
  98. nextFollowUpTime: e.nextFollowUpTime,
  99. followUpPhotos: e.followUpPhtots,
  100. followUpData: e.dataJson,
  101. ),
  102. )
  103. .toList();
  104. return [record];
  105. }
  106. }