Browse Source

调整随访Mock

Melon 1 year ago
parent
commit
761c2c1f93

+ 11 - 0
lib/database/db.dart

@@ -1,3 +1,4 @@
+import 'package:flutter/foundation.dart';
 import 'package:vital_local_database/index.dart';
 import 'package:vitalapp/database/db_patch/v1.dart';
 import 'package:vitalapp/database/entities/diagnosis.dart';
@@ -6,6 +7,7 @@ import 'package:vitalapp/database/entities/patient.dart';
 import 'package:vitalapp/database/repositories/followup.dart';
 import 'package:vitalapp/database/repositories/interfaces/followup.dart';
 import 'db_patch/v2.dart';
+import 'entities/exam.dart';
 import 'repositories/interfaces/diagnosis.dart';
 import 'repositories/interfaces/exam.dart';
 import 'repositories/interfaces/exam_batch.dart';
@@ -33,12 +35,21 @@ class VitalDatabaseAccessor
   /// 初始化
   Future<void> init() async {
     _database = await _connection.open();
+    if (kDebugMode) {
+      await _debugBatch();
+    }
     await checkAndUpgradeDatabaseVersion();
     _store.regRepository<IPatientRepository>(PatientRepository(database));
     _store.regRepository<IDiagnosisRepository>(DiagnosisRepository(database));
     _store.regRepository<IFollowUpRepository>(FollowUpRepository(database));
   }
 
+  Future<void> _debugBatch() async {
+    // TODO: 此处仅限开发调试时临时执行,提交前请清除!!!!
+    database.execute("DROP TABLE ${FollowUpEntity().tableName};");
+    database.execute("DROP TABLE ${ExamEntity().tableName};");
+  }
+
   ///检查本地数据库版本,以判断是否需要升级
   Future<void> checkAndUpgradeDatabaseVersion() async {
     var originalVersion = await database.getVersion();

+ 21 - 0
lib/database/entities/followup.dart

@@ -14,11 +14,14 @@ class FollowUpEntity extends SyncableEntity<FollowUpEntity> {
       '"code" VARCHAR(100) NOT NULL,'
       '"userCode" VARCHAR(100) NOT NULL,'
       '"patientCode" VARCHAR(100) NOT NULL,'
+      '"contractDoctor" VARCHAR(100) NOT NULL,'
       '"typeKey" VARCHAR(100) NOT NULL,'
       '"templateCode" VARCHAR(100) NOT NULL,'
       '"dataJson" TEXT NOT NULL,'
       '"mode" INTEGER NOT NULL,'
       '"followUpTime" DATETIME NOT NULL,'
+      '"nextFollowUpTime" DATETIME NOT NULL,'
+      '"followUpPhtots" TEXT NOT NULL,'
       '"syncType" INTEGER NOT NULL,'
       '"syncState" INTEGER NOT NULL,'
       '"createTime" DATETIME NOT NULL,'
@@ -36,6 +39,9 @@ class FollowUpEntity extends SyncableEntity<FollowUpEntity> {
   /// 居民档案编码
   String patientCode = '';
 
+  /// 签约医生
+  String contractDoctor = '';
+
   /// 分类Key
   String typeKey = '';
 
@@ -48,13 +54,24 @@ class FollowUpEntity extends SyncableEntity<FollowUpEntity> {
   /// 随访时间
   DateTime followUpTime = DateTime(1900, 1, 1);
 
+  /// 下次随访时间
+  DateTime nextFollowUpTime = DateTime(1900, 1, 1);
+
+  /// 随访照片
+  List<String> followUpPhtots = [];
+
   @override
   Map<String, dynamic> toJson() {
     final map = super.toJson();
     map['patientCode'] = patientCode;
+    map['contractDoctor'] = contractDoctor;
+    map['typeKey'] = typeKey;
     map['templateCode'] = templateCode;
     map['mode'] = mode.index;
     map['followUpTime'] = f2d_DateTime(followUpTime);
+    map['nextFollowUpTime'] = f2d_DateTime(nextFollowUpTime);
+    // 符号 `|` 分隔
+    map['followUpPhtots'] = followUpPhtots.join('|');
     return map;
   }
 
@@ -62,9 +79,13 @@ class FollowUpEntity extends SyncableEntity<FollowUpEntity> {
   FollowUpEntity fromJson(Map<String, dynamic> map) {
     super.fromJson(map);
     patientCode = map['patientCode'];
+    contractDoctor = map['contractDoctor'];
+    typeKey = map['typeKey'];
     templateCode = map['templateCode'];
     mode = FollowUpModeEnum.values[map["mode"]];
     followUpTime = d2f_DateTime(map['followUpTime']);
+    nextFollowUpTime = d2f_DateTime(map['nextFollowUpTime']);
+    followUpPhtots = (map['followUpPhtots'] as String).split('|');
     return this;
   }
 }

+ 1 - 6
lib/mock/services/exam.dart

@@ -6,16 +6,11 @@ class ExamServiceMock extends VitalExamService {
 
   @override
   Future<String> createExamAsync(CreateExamRequest request) {
+    // 同步Server,新增&更新都走这个接口
     // TODO: implement createExamAsync
     return super.createExamAsync(request);
   }
 
-  @override
-  Future<bool> updateExamAsync(UpdateExamRequest request) {
-    // TODO: implement updateExamAsync
-    return super.updateExamAsync(request);
-  }
-
   @override
   Future<List<ExamRecordDTO>> getExamRecordListAsync(
       GetExamRecordListRequest request) {

+ 39 - 25
lib/mock/services/followup.dart

@@ -1,6 +1,3 @@
-import 'dart:convert';
-
-import 'package:fis_jsonrpc/services/analyzeConfig.m.dart';
 import 'package:fis_jsonrpc/services/followUp.dart';
 import 'package:fis_jsonrpc/services/followUp.m.dart';
 import 'package:uuid/uuid.dart';
@@ -20,11 +17,15 @@ class FollowUpServiceMock extends VitalFollowUpService {
     entity.syncType = OfflineDataSyncType.create;
     entity.userCode = Store.user.userCode!;
     entity.patientCode = Store.user.currentSelectPatientInfo!.code!;
+    entity.contractDoctor =
+        Store.user.currentSelectPatientInfo!.contractedDoctorName!;
     entity.typeKey = request.key!;
     entity.templateCode = request.templateCode!;
     entity.mode = request.followUpMode;
     entity.followUpTime = request.followUpTime!;
-    entity.dataJson = jsonEncode(request); // 完整缓存请求
+    entity.nextFollowUpTime = request.nextFollowUpTime!;
+    entity.followUpPhtots = request.followUpPhotos!;
+    entity.dataJson = request.followUpData!;
 
     final id = await db.repositories.followUp.insert(entity);
     final result = id > 0 ? entity.code : "";
@@ -39,27 +40,18 @@ class FollowUpServiceMock extends VitalFollowUpService {
       entity = FollowUpEntity();
       entity.isValid = true;
       entity.syncType = OfflineDataSyncType.update;
-      entity.dataJson = jsonEncode(request);
-    } else {
-      if (entity.syncType == OfflineDataSyncType.create) {
-        final jsonMap = jsonDecode(entity.dataJson);
-        // 创建类型里含有templateCode,不能丢了
-        final createReq = CreateFollowUpRequest.fromJson(jsonMap);
-        createReq.followUpMode = request.followUpMode!;
-        createReq.followUpTime = request.followUpTime;
-        createReq.nextFollowUpTime = request.nextFollowUpTime;
-        createReq.followUpPhotos = request.followUpPhotos;
-        createReq.followUpData = request.followUpData;
-      } else {
-        entity.dataJson = jsonEncode(request);
-      }
     }
-
     entity.code = request.code!;
     entity.userCode = Store.user.userCode!;
     entity.patientCode = Store.user.currentSelectPatientInfo!.code!;
+    entity.contractDoctor =
+        Store.user.currentSelectPatientInfo!.contractedDoctorName!;
     entity.typeKey = request.key!;
+    entity.mode = request.followUpMode!;
     entity.followUpTime = request.followUpTime!;
+    entity.nextFollowUpTime = request.nextFollowUpTime!;
+    entity.followUpPhtots = request.followUpPhotos!;
+    entity.dataJson = request.followUpData!;
 
     int result;
     if (entity.id == 0) {
@@ -75,11 +67,33 @@ class FollowUpServiceMock extends VitalFollowUpService {
       GetFollowUpRecordListRequest request) async {
     final entities = await db.repositories.followUp
         .queryPatientAllList(request.patientCode!, Store.user.userCode!);
-    final list = entities.map((e) {
-      final dto = FollowUpRecordDTO();
-// dto.birthday
-      return dto;
-    }).toList();
-    return list;
+    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];
   }
 }