followup.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. final patientCode = Store.user.currentSelectPatientInfo!.code!;
  14. // 本地先生成一个Code,上传后更新
  15. final uuid = const Uuid().v4().replaceAll('-', '');
  16. entity.code = "mock_$uuid";
  17. entity.isValid = true;
  18. entity.syncType = OfflineDataSyncType.create;
  19. entity.userCode = Store.user.userCode!;
  20. entity.patientCode = patientCode;
  21. entity.contractDoctor = Store.user.principalName;
  22. entity.typeKey = request.key!;
  23. entity.templateCode = request.templateCode!;
  24. entity.mode = request.followUpMode;
  25. entity.followUpTime = request.followUpTime!;
  26. if (request.nextFollowUpTime != null) {
  27. // TODO: 理论不能为空,但是这个默认值目前没有确定
  28. entity.nextFollowUpTime = request.nextFollowUpTime!;
  29. }
  30. entity.followUpPhtots = request.followUpPhotos!;
  31. entity.dataJson = request.followUpData!;
  32. final id = await db.repositories.followUp.insert(entity);
  33. final success = id > 0;
  34. if (success) {
  35. // 统计数量+1
  36. await db.repositories.patient.increaseFollowUpCount(patientCode);
  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. final patientCode = Store.user.currentSelectPatientInfo!.code!;
  51. entity.code = request.code!;
  52. entity.userCode = Store.user.userCode!;
  53. entity.patientCode = patientCode;
  54. entity.contractDoctor = Store.user.principalName;
  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.increaseFollowUpCount(patientCode);
  67. }
  68. } else {
  69. result = await db.repositories.followUp.update(entity);
  70. }
  71. return result > 0;
  72. }
  73. @override
  74. Future<List<FollowUpRecordDTO>> getFollowUpRecordListAsync(
  75. GetFollowUpRecordListRequest request) async {
  76. final entities = await db.repositories.followUp
  77. .queryAllListByPatient(request.patientCode!, Store.user.userCode!);
  78. if (entities.isEmpty) {
  79. return [];
  80. }
  81. // 都放一个Record里
  82. final record = FollowUpRecordDTO();
  83. final patient = Store.user.currentSelectPatientInfo;
  84. record.patientName = patient?.patientName ?? "";
  85. // record.contractedDoctor = patient?.contractedDoctorName ?? "";
  86. record.contractedDoctor = entities.first.contractDoctor;
  87. record.followUpRecordDatas = entities
  88. .map(
  89. (e) => FollowUpRecordDataDTO(
  90. code: e.code,
  91. templateCode: e.templateCode,
  92. key: e.typeKey,
  93. followUpDoctor: e.contractDoctor,
  94. followUpState: FollowUpStateEnum.FollowUpVisit,
  95. followUpMode: e.mode,
  96. followUpTime: e.followUpTime,
  97. nextFollowUpTime: e.nextFollowUpTime,
  98. followUpPhotos: e.followUpPhtots,
  99. followUpData: e.dataJson,
  100. ),
  101. )
  102. .toList();
  103. return [record];
  104. }
  105. }