diagnosis.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import 'package:vital_local_database/core/index.dart';
  2. import 'package:vitalapp/database/db.dart';
  3. import 'package:vitalapp/database/entities/defines.dart';
  4. import 'package:vitalapp/database/entities/diagnosis.dart';
  5. import 'interfaces/diagnosis.dart';
  6. class DiagnosisRepository
  7. extends BaseDbRepository<DiagnosisEntity, DiagnosisColumnsDefine>
  8. implements IDiagnosisRepository {
  9. DiagnosisRepository(super.database);
  10. @override
  11. DiagnosisEntity createEntityInstance() => DiagnosisEntity();
  12. @override
  13. Future<List<DiagnosisEntity>> getListByPatientCode(
  14. String patientCode, {
  15. OfflineDataSyncState? syncState,
  16. required String userCode,
  17. }) async {
  18. final query = queryable.where((x) {
  19. final List<IDbColumnCondition> arr = [];
  20. arr.add(x.isValid.equals(true));
  21. arr.add(x.patientCode.equals(patientCode));
  22. arr.add(x.userCode.equals(userCode));
  23. ///添加用户code
  24. if (syncState != null) {
  25. arr.add(x.syncState.equals(syncState));
  26. }
  27. return arr;
  28. });
  29. final list =
  30. await query.orderBy((x) => x.createTime, DbOrderByType.desc).toList();
  31. return list;
  32. }
  33. @override
  34. Future<int> getNotUploadedCountByPatientCode(
  35. String patientCode,
  36. String userCode,
  37. ) async {
  38. final query = queryable.where((x) {
  39. final List<IDbColumnCondition> arr = [];
  40. arr.add(x.isValid.equals(true));
  41. arr.add(x.patientCode.equals(patientCode));
  42. arr.add(x.syncState.notEquals(OfflineDataSyncState.success));
  43. arr.add(x.userCode.equals(userCode)); //添加用户code
  44. return arr;
  45. });
  46. final listCount = await query.count();
  47. return listCount;
  48. }
  49. @override
  50. Future<List<DiagnosisEntity>> getNotUploadedListByPatientCode(
  51. String patientCode,
  52. String userCode,
  53. ) async {
  54. final query = queryable.where((x) {
  55. final List<IDbColumnCondition> arr = [];
  56. arr.add(x.isValid.equals(true));
  57. arr.add(x.patientCode.equals(patientCode));
  58. arr.add(x.userCode.equals(userCode)); //添加用户code
  59. arr.add(x.syncState.notEquals(OfflineDataSyncState.success));
  60. return arr;
  61. });
  62. final list =
  63. await query.orderBy((x) => x.createTime, DbOrderByType.desc).toList();
  64. return list;
  65. }
  66. }