123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:uuid/uuid.dart';
- import 'package:vitalapp/database/db.dart';
- import 'package:vitalapp/database/entities/defines.dart';
- import 'package:vitalapp/database/entities/followup.dart';
- import 'package:vitalapp/store/store.dart';
- class FollowUpServiceMock extends VitalFollowUpService {
- FollowUpServiceMock(super.host);
- @override
- Future<String> createFollowUpAsync(CreateFollowUpRequest request) async {
- final entity = FollowUpEntity();
- final patientCode = Store.user.currentSelectPatientInfo!.code!;
- // 本地先生成一个Code,上传后更新
- final uuid = const Uuid().v4().replaceAll('-', '');
- entity.code = "mock_$uuid";
- entity.isValid = true;
- entity.syncType = OfflineDataSyncType.create;
- entity.userCode = Store.user.userCode!;
- entity.patientCode = patientCode;
- entity.contractDoctor = Store.user.displayName;
- entity.typeKey = request.key!;
- entity.templateCode = request.templateCode!;
- entity.mode = request.followUpMode;
- entity.followUpTime = request.followUpTime!;
- if (request.nextFollowUpTime != null) {
- // TODO: 理论不能为空,但是这个默认值目前没有确定
- entity.nextFollowUpTime = request.nextFollowUpTime!;
- }
- entity.followUpPhtots = request.followUpPhotos!;
- entity.dataJson = request.followUpData!;
- final id = await db.repositories.followUp.insert(entity);
- final success = id > 0;
- if (success) {
- if (entity.typeKey == "GXY") {
- // 统计数量+1
- await db.repositories.patient
- .increaseGxyFollowUpCount(patientCode, Store.user.userCode!);
- } else if (entity.typeKey == "TNB") {
- // 统计数量+1
- await db.repositories.patient
- .increaseTnbFollowUpCount(patientCode, Store.user.userCode!);
- }
- }
- final result = success ? entity.code : "";
- return result;
- }
- @override
- Future<bool> updateFollowUpAsync(UpdateFollowUpRequest request) async {
- FollowUpEntity? entity =
- await db.repositories.followUp.singleByCode(request.code!);
- if (entity == null) {
- entity = FollowUpEntity();
- entity.isValid = true;
- entity.syncType = OfflineDataSyncType.update;
- }
- final patientCode = Store.user.currentSelectPatientInfo!.code!;
- entity.code = request.code!;
- entity.userCode = Store.user.userCode!;
- entity.patientCode = patientCode;
- entity.contractDoctor = Store.user.principalName;
- entity.typeKey = request.key!;
- entity.mode = request.followUpMode!;
- entity.followUpTime = request.followUpTime!;
- if (request.nextFollowUpTime != null) {
- // TODO: 理论不能为空,但是这个默认值目前没有确定
- entity.nextFollowUpTime = request.nextFollowUpTime!;
- }
- entity.followUpPhtots = request.followUpPhotos!;
- entity.dataJson = request.followUpData!;
- int result;
- if (entity.id == -1) {
- result = await db.repositories.followUp.insert(entity);
- if (result > 0) {
- if (entity.typeKey == "GXY") {
- // 统计数量+1
- await db.repositories.patient
- .increaseGxyFollowUpCount(patientCode, Store.user.userCode!);
- } else if (entity.typeKey == "TNB") {
- // 统计数量+1
- await db.repositories.patient
- .increaseTnbFollowUpCount(patientCode, Store.user.userCode!);
- }
- }
- } else {
- result = await db.repositories.followUp.update(entity);
- }
- return result > 0;
- }
- @override
- Future<List<FollowUpRecordDTO>> getFollowUpRecordListAsync(
- GetFollowUpRecordListRequest request) async {
- final entities = await db.repositories.followUp.queryAllListByPatient(
- request.patientCode!,
- Store.user.userCode!,
- request.keys?.first,
- );
- if (entities.isEmpty) {
- return [];
- }
- // 都放一个Record里
- final record = FollowUpRecordDTO();
- final patient = Store.user.currentSelectPatientInfo;
- record.patientName = patient?.patientName ?? "";
- // record.contractedDoctor = patient?.contractedDoctorName ?? "";
- record.contractedDoctor = entities.first.contractDoctor;
- record.followUpRecordDatas = entities
- .map(
- (e) => FollowUpRecordDataDTO(
- code: e.code,
- templateCode: e.templateCode,
- key: e.typeKey,
- followUpDoctor: e.contractDoctor,
- followUpState: FollowUpStateEnum.FollowUpVisit,
- followUpMode: e.mode,
- followUpTime: e.followUpTime,
- nextFollowUpTime: e.nextFollowUpTime,
- followUpPhotos: e.followUpPhtots,
- followUpData: e.dataJson,
- ),
- )
- .toList();
- return [record];
- }
- }
|