1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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/store/store.dart';
- class PatientExtensionServiceMock extends VitalPatientExtensionService {
- PatientExtensionServiceMock(String host) : super(host);
- @override
- Future<String> createPatientExtensionAsync(
- CreatePatientExtensionRequest request) async {
- final entity = await db.repositories.patient
- .singleByCodeWithUserCode(request.patientCode!, Store.user.userCode!);
- if (entity == null) {
- return "";
- } // 本地先生成一个Code,上传后更新
- final uuid = const Uuid().v4().replaceAll('-', '');
- entity.extCode = "mock_$uuid";
- entity.extJson = request.extensionData;
- entity.syncState = OfflineDataSyncState.wait;
- // entity.extSyncState = OfflineDataSyncState.wait;
- entity.overallSyncState = OfflineDataSyncState.wait;
- final rows = await db.repositories.patient.update(entity);
- if (rows > 0) {
- final uuid = const Uuid().v4().replaceAll('-', '');
- return "mock_$uuid";
- }
- return "";
- }
- @override
- Future<bool> updatePatientExtensionAsync(
- UpdatePatientExtensionRequest request) async {
- final entity = await db.repositories.patient
- .singleByCodeWithUserCode(request.patientCode!, Store.user.userCode!);
- if (entity == null) {
- return false;
- }
- entity.extJson = request.extensionData;
- entity.syncState = OfflineDataSyncState.wait;
- entity.overallSyncState = OfflineDataSyncState.wait;
- final rows = await db.repositories.patient.update(entity);
- return rows > 0;
- }
- @override
- Future<PatientExtensionDTO> getPatientExtensionDetailByCodeAndKeyAsync(
- GetPatientExtensionByCodeAndKeyRequest request) async {
- final entity = await db.repositories.patient
- .singleByCodeWithUserCode(request.patientCode!, Store.user.userCode!);
- if (entity == null) {
- throw NullThrownError();
- }
- final dto = PatientExtensionDTO(
- code: entity.extCode,
- key: "PatientHealthInfo",
- extensionData: entity.extJson,
- );
- return dto;
- }
- }
|