import 'package:vital_local_database/index.dart'; import 'package:vitalapp/database/entities/followup.dart'; import 'interfaces/followup.dart'; class FollowUpRepository extends BaseDbRepository implements IFollowUpRepository { FollowUpRepository(super.database); @override FollowUpEntity createEntityInstance() => FollowUpEntity(); @override Future singleByCode(String code) async { final entity = await queryable .where((x) => [ x.isValid.equals(true), x.code.equals(code), ]) .first(); return entity; } @override Future> queryAllListByPatient( String patientCode, String userCode, [ String? followUpKey, ]) async { final query = queryable.where( (x) => [ x.isValid.equals(true), x.userCode.equals(userCode), x.patientCode.equals(patientCode), if (followUpKey != null) x.typeKey.equals(followUpKey), ], ); final list = await query .orderBy((x) => x.followUpTime, DbOrderByType.desc) // 按随访时间倒序 .toList(); return list; } @override Future> queryPagedListByPatient( String patientCode, String userCode, int pageIndex, { int pageSize = 50, }) async { final offset = pageSize * (pageIndex - 1); var query = queryable.where( (x) => [ x.isValid.equals(true), x.userCode.equals(userCode), x.patientCode.equals(patientCode), ], ); final count = await query.count(); final list = await query .orderBy((x) => x.followUpTime, DbOrderByType.desc) // 按随访时间倒序 .offset(offset) .limit(pageSize) .toList(); final result = DbPagedList( data: list, totalCount: count, pageIndex: pageIndex, pageSize: pageSize, ); return result; } }