patient_ext.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/store/store.dart';
  6. class PatientExtensionServiceMock extends VitalPatientExtensionService {
  7. PatientExtensionServiceMock(String host) : super(host);
  8. @override
  9. Future<String> createPatientExtensionAsync(
  10. CreatePatientExtensionRequest request) async {
  11. final entity = await db.repositories.patient
  12. .singleByCodeWithUserCode(request.patientCode!, Store.user.userCode!);
  13. if (entity == null) {
  14. return "";
  15. } // 本地先生成一个Code,上传后更新
  16. final uuid = const Uuid().v4().replaceAll('-', '');
  17. entity.extCode = "mock_$uuid";
  18. entity.extJson = request.extensionData;
  19. entity.syncState = OfflineDataSyncState.wait;
  20. // entity.extSyncState = OfflineDataSyncState.wait;
  21. entity.overallSyncState = OfflineDataSyncState.wait;
  22. final rows = await db.repositories.patient.update(entity);
  23. if (rows > 0) {
  24. final uuid = const Uuid().v4().replaceAll('-', '');
  25. return "mock_$uuid";
  26. }
  27. return "";
  28. }
  29. @override
  30. Future<bool> updatePatientExtensionAsync(
  31. UpdatePatientExtensionRequest request) async {
  32. final entity = await db.repositories.patient
  33. .singleByCodeWithUserCode(request.patientCode!, Store.user.userCode!);
  34. if (entity == null) {
  35. return false;
  36. }
  37. entity.extJson = request.extensionData;
  38. entity.syncState = OfflineDataSyncState.wait;
  39. entity.overallSyncState = OfflineDataSyncState.wait;
  40. final rows = await db.repositories.patient.update(entity);
  41. return rows > 0;
  42. }
  43. @override
  44. Future<PatientExtensionDTO> getPatientExtensionDetailByCodeAndKeyAsync(
  45. GetPatientExtensionByCodeAndKeyRequest request) async {
  46. final entity = await db.repositories.patient
  47. .singleByCodeWithUserCode(request.patientCode!, Store.user.userCode!);
  48. if (entity == null) {
  49. throw NullThrownError();
  50. }
  51. final dto = PatientExtensionDTO(
  52. code: entity.extCode,
  53. key: "PatientHealthInfo",
  54. extensionData: entity.extJson,
  55. );
  56. return dto;
  57. }
  58. }