controller.dart 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import 'dart:convert';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:flutter/widgets.dart';
  4. import 'package:get/get.dart';
  5. import 'package:vitalapp/architecture/defines.dart';
  6. import 'package:vitalapp/architecture/values/features.dart';
  7. import 'package:vitalapp/consts/diagnosis.dart';
  8. import 'package:vitalapp/database/entities/defines.dart';
  9. import 'package:vitalapp/global.dart';
  10. import 'package:vitalapp/managers/interfaces/dictionary.dart';
  11. import 'package:vitalapp/managers/interfaces/patient.dart';
  12. import 'package:vitalapp/managers/interfaces/record_data_cache.dart';
  13. import 'package:vitalapp/pages/controllers/home_nav_mixin.dart';
  14. import 'package:vitalapp/store/store.dart';
  15. import 'state.dart';
  16. class PatientDetailController extends FControllerBase with HomeNavMixin {
  17. final state = PatientDetailState();
  18. final _patientManager = Get.find<IPatientManager>();
  19. @override
  20. void onInit() {
  21. WidgetsBinding.instance.addPostFrameCallback(
  22. (timeStamp) async {
  23. loadData();
  24. if (Store.user.hasFeature(FeatureKeys.RecentTestRecords)) {
  25. await onReadInfo();
  26. }
  27. },
  28. );
  29. super.onInit();
  30. }
  31. /// 打开信息页
  32. void gotoInfo() {
  33. Get.toNamed(
  34. "/patient/info",
  35. parameters: {"code": state.code},
  36. );
  37. }
  38. /// 前往随访页
  39. void gotoFollowUp() {
  40. Get.toNamed(
  41. "/check/follow_up",
  42. parameters: {"patientCode": state.code, "patientName": state.name},
  43. );
  44. }
  45. /// 前往随访记录页
  46. void gotoFollowUpRecord() {
  47. Get.toNamed(
  48. "/check/follow_up_record",
  49. parameters: {"patientCode": state.code, "patientName": state.name},
  50. );
  51. }
  52. /// 前往健康体检页
  53. void gotoHealthCheck() {
  54. Get.toNamed(
  55. "/check/form",
  56. parameters: {"patientCode": state.code},
  57. );
  58. }
  59. /// 前往签约页
  60. void gotoContract() {
  61. Get.toNamed(
  62. "/contract/package_list",
  63. parameters: {"patientCode": state.code},
  64. );
  65. }
  66. /// 前往转诊页
  67. void gotoReferral() {
  68. //
  69. }
  70. /// 前往健康检测页
  71. void gotoExam() {
  72. //
  73. Get.toNamed(
  74. "/medical",
  75. parameters: {"patientCode": state.code},
  76. );
  77. }
  78. /// 前往诊疗记录页
  79. void gotoExamRecord() {
  80. //
  81. Get.toNamed(
  82. "/medical/records",
  83. parameters: {"patientCode": state.code},
  84. );
  85. }
  86. ///前往体检记录
  87. void gotoHealthCheckRecord() {
  88. Get.toNamed(
  89. "/check/healthCheckRecord",
  90. parameters: {"patientCode": state.code},
  91. );
  92. }
  93. void gotoContractRecords() {
  94. Get.toNamed(
  95. "/contract/contract_records",
  96. parameters: {"patientCode": state.code},
  97. );
  98. }
  99. Future<void> loadData() async {
  100. state.code = Store.user.currentSelectPatientInfo?.code ?? '';
  101. final dto = Store.user.currentSelectPatientInfo;
  102. if (dto != null) {
  103. dto.birthday = dto.birthday!.toLocal();
  104. state.updateDto(dto);
  105. }
  106. }
  107. Future<bool> setCrowdLabelsAsync(
  108. List<String> carowLabels, List<String> crowdNames) async {
  109. final result =
  110. await _patientManager.setCrowdLabelsAsync(state.code, carowLabels);
  111. if (result) {
  112. state.updateCrowd(carowLabels, crowdNames);
  113. }
  114. return result;
  115. }
  116. /// 读取到最近检测记录的数据
  117. Future<void> onReadInfo() async {
  118. var getLastRecords = await Get.find<IRecordDataCacheManager>()
  119. .getLastRecordByPatientCode(Store.user.currentSelectPatientInfo!.code!);
  120. var dataJson = jsonDecode(getLastRecords?.dataJson ?? '{}');
  121. final dictionaryManager = Get.find<IDictionaryManager>();
  122. var currentDiagnosis = <List<String>>[];
  123. state.isExistLocalData = [
  124. OfflineDataSyncState.wait,
  125. OfflineDataSyncState.fail
  126. ].contains(getLastRecords?.syncState);
  127. // this.diagnosisTime = DateFormat("yyyy-MM-dd HH:mm:ss").format(row.diagnosisTime);
  128. for (var element in dataJson.entries) {
  129. if (element.value != 'null') {
  130. List<String> keys = element.value.keys.toList();
  131. List<DictionaryWithUnitDTO>? dtos = [];
  132. if (kIsOnline == false) {
  133. for (var key in keys) {
  134. dtos.add(DictionaryWithUnitDTO(
  135. key: key,
  136. name: DiagnosisTranslator.reportTr(key),
  137. unit: DiagnosisTranslator.getExamUnit(key),
  138. ));
  139. }
  140. } else {
  141. List<DictionaryWithUnitDTO>? dictionaryList = await dictionaryManager
  142. .getDictionaryNameAndUnitByKeysAsync(keys) ??
  143. [];
  144. dtos = dictionaryList;
  145. }
  146. // var dtos =
  147. // await dictionaryManager.getDictionaryNameAndUnitByKeysAsync(keys);
  148. for (var key in keys) {
  149. if (key == "ECG_POINT") {
  150. continue;
  151. }
  152. DictionaryWithUnitDTO dto =
  153. dtos.firstWhere((item) => item.key == key);
  154. currentDiagnosis.add([
  155. dto.name ?? '',
  156. element.value[key].toString(),
  157. dto.unit ?? '',
  158. ]);
  159. }
  160. }
  161. }
  162. state.currentDiagnosis = currentDiagnosis;
  163. }
  164. }