123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- import 'dart:convert';
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:flutter/widgets.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/architecture/defines.dart';
- import 'package:vitalapp/architecture/values/features.dart';
- import 'package:vitalapp/consts/diagnosis.dart';
- import 'package:vitalapp/database/entities/defines.dart';
- import 'package:vitalapp/global.dart';
- import 'package:vitalapp/managers/interfaces/dictionary.dart';
- import 'package:vitalapp/managers/interfaces/patient.dart';
- import 'package:vitalapp/managers/interfaces/record_data_cache.dart';
- import 'package:vitalapp/pages/controllers/home_nav_mixin.dart';
- import 'package:vitalapp/store/store.dart';
- import 'state.dart';
- class PatientDetailController extends FControllerBase with HomeNavMixin {
- final state = PatientDetailState();
- final _patientManager = Get.find<IPatientManager>();
- @override
- void onInit() {
- WidgetsBinding.instance.addPostFrameCallback(
- (timeStamp) async {
- loadData();
- if (Store.user.hasFeature(FeatureKeys.RecentTestRecords)) {
- await onReadInfo();
- }
- },
- );
- super.onInit();
- }
- /// 打开信息页
- void gotoInfo() {
- Get.toNamed(
- "/patient/info",
- parameters: {"code": state.code},
- );
- }
- /// 前往随访页
- void gotoFollowUp() {
- Get.toNamed(
- "/check/follow_up",
- parameters: {"patientCode": state.code, "patientName": state.name},
- );
- }
- /// 前往随访记录页
- void gotoFollowUpRecord() {
- Get.toNamed(
- "/check/follow_up_record",
- parameters: {"patientCode": state.code, "patientName": state.name},
- );
- }
- /// 前往健康体检页
- void gotoHealthCheck() {
- Get.toNamed(
- "/check/form",
- parameters: {"patientCode": state.code},
- );
- }
- /// 前往签约页
- void gotoContract() {
- Get.toNamed(
- "/contract/package_list",
- parameters: {"patientCode": state.code},
- );
- }
- /// 前往转诊页
- void gotoReferral() {
- //
- }
- /// 前往健康检测页
- void gotoExam() {
- //
- Get.toNamed(
- "/medical",
- parameters: {"patientCode": state.code},
- );
- }
- /// 前往诊疗记录页
- void gotoExamRecord() {
- //
- Get.toNamed(
- "/medical/records",
- parameters: {"patientCode": state.code},
- );
- }
- ///前往体检记录
- void gotoHealthCheckRecord() {
- Get.toNamed(
- "/check/healthCheckRecord",
- parameters: {"patientCode": state.code},
- );
- }
- void gotoContractRecords() {
- Get.toNamed(
- "/contract/contract_records",
- parameters: {"patientCode": state.code},
- );
- }
- Future<void> loadData() async {
- state.code = Store.user.currentSelectPatientInfo?.code ?? '';
- final dto = Store.user.currentSelectPatientInfo;
- if (dto != null) {
- dto.birthday = dto.birthday!.toLocal();
- state.updateDto(dto);
- }
- }
- Future<bool> setCrowdLabelsAsync(
- List<String> carowLabels, List<String> crowdNames) async {
- final result =
- await _patientManager.setCrowdLabelsAsync(state.code, carowLabels);
- if (result) {
- state.updateCrowd(carowLabels, crowdNames);
- }
- return result;
- }
- /// 读取到最近检测记录的数据
- Future<void> onReadInfo() async {
- var getLastRecords = await Get.find<IRecordDataCacheManager>()
- .getLastRecordByPatientCode(Store.user.currentSelectPatientInfo!.code!);
- var dataJson = jsonDecode(getLastRecords?.dataJson ?? '{}');
- final dictionaryManager = Get.find<IDictionaryManager>();
- var currentDiagnosis = <List<String>>[];
- state.isExistLocalData = [
- OfflineDataSyncState.wait,
- OfflineDataSyncState.fail
- ].contains(getLastRecords?.syncState);
- // this.diagnosisTime = DateFormat("yyyy-MM-dd HH:mm:ss").format(row.diagnosisTime);
- for (var element in dataJson.entries) {
- if (element.value != 'null') {
- List<String> keys = element.value.keys.toList();
- List<DictionaryWithUnitDTO>? dtos = [];
- if (kIsOnline == false) {
- for (var key in keys) {
- dtos.add(DictionaryWithUnitDTO(
- key: key,
- name: DiagnosisTranslator.reportTr(key),
- unit: DiagnosisTranslator.getExamUnit(key),
- ));
- }
- } else {
- List<DictionaryWithUnitDTO>? dictionaryList = await dictionaryManager
- .getDictionaryNameAndUnitByKeysAsync(keys) ??
- [];
- dtos = dictionaryList;
- }
- // var dtos =
- // await dictionaryManager.getDictionaryNameAndUnitByKeysAsync(keys);
- for (var key in keys) {
- if (key == "ECG_POINT") {
- continue;
- }
- DictionaryWithUnitDTO dto =
- dtos.firstWhere((item) => item.key == key);
- currentDiagnosis.add([
- dto.name ?? '',
- element.value[key].toString(),
- dto.unit ?? '',
- ]);
- }
- }
- }
- state.currentDiagnosis = currentDiagnosis;
- }
- }
|