controller.dart 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import 'package:fis_jsonrpc/rpc.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:vitalapp/architecture/defines.dart';
  5. import 'package:vitalapp/architecture/network_connectivity.dart';
  6. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  7. import 'package:vitalapp/architecture/values/features.dart';
  8. import 'package:vitalapp/components/alert_dialog.dart';
  9. import 'package:vitalapp/managers/interfaces/diagnosis.dart';
  10. import 'package:vitalapp/managers/interfaces/models/diagnosis_aggregation_record_model.dart';
  11. import 'package:vitalapp/managers/interfaces/patient.dart';
  12. import 'package:vitalapp/pages/controllers/home_nav_mixin.dart';
  13. import 'package:vitalapp/pages/facial_recognition/index.dart';
  14. import 'package:vitalapp/store/store.dart';
  15. import 'package:fis_common/logger/logger.dart';
  16. import 'state.dart';
  17. class PatientDetailController extends FControllerBase with HomeNavMixin {
  18. final state = PatientDetailState();
  19. final _patientManager = Get.find<IPatientManager>();
  20. @override
  21. void onInit() {
  22. WidgetsBinding.instance.addPostFrameCallback(
  23. (timeStamp) async {
  24. loadData();
  25. if (Store.user.hasFeature(FeatureKeys.RecentTestRecords)) {
  26. await onReadLastRecordInfo();
  27. }
  28. netChecker.onlineChangedEvent.addListener(_onlineChanged);
  29. },
  30. );
  31. super.onInit();
  32. }
  33. void _onlineChanged(_, e) {
  34. state.isOnline = e;
  35. }
  36. /// 打开信息页
  37. void gotoInfo() {
  38. Get.toNamed(
  39. "/patient/info",
  40. parameters: {"code": state.code},
  41. );
  42. }
  43. /// 前往随访页
  44. void gotoFollowUp() {
  45. Get.toNamed(
  46. "/check/follow_up",
  47. parameters: {"patientCode": state.code, "patientName": state.name},
  48. );
  49. }
  50. /// 前往随访记录页
  51. void gotoFollowUpRecord() {
  52. Get.toNamed(
  53. "/check/follow_up_record",
  54. parameters: {"patientCode": state.code, "patientName": state.name},
  55. );
  56. }
  57. /// 前往健康体检页
  58. void gotoHealthCheck() {
  59. Get.toNamed(
  60. "/check/form",
  61. parameters: {"patientCode": state.code},
  62. );
  63. }
  64. /// 前往签约页
  65. void gotoContract() {
  66. Get.toNamed(
  67. "/contract/package_list",
  68. parameters: {"patientCode": state.code},
  69. );
  70. }
  71. /// 前往转诊页
  72. void gotoReferral() {
  73. //
  74. }
  75. /// 前往健康检测页
  76. void gotoExam() {
  77. //
  78. Get.toNamed(
  79. "/medical",
  80. parameters: {"patientCode": state.code},
  81. );
  82. }
  83. /// 前往诊疗记录页
  84. void gotoExamRecord() {
  85. //
  86. Get.toNamed(
  87. "/medical/records",
  88. parameters: {"patientCode": state.code},
  89. );
  90. }
  91. ///前往体检记录
  92. void gotoHealthCheckRecord() {
  93. Get.toNamed(
  94. "/check/healthCheckRecord",
  95. parameters: {"patientCode": state.code},
  96. );
  97. }
  98. void gotoContractRecords() {
  99. Get.toNamed(
  100. "/contract/contract_records",
  101. parameters: {"patientCode": state.code},
  102. );
  103. }
  104. /// 人脸录入
  105. Future<void> queryIsNeedFaceInput() async {
  106. var dto =
  107. await getPatientPhoto(Store.user.currentSelectPatientInfo!.cardNo!);
  108. await onFaceEntryClicked(dto);
  109. Get.back();
  110. }
  111. /// 点击录入人脸
  112. Future<void> onFaceEntryClicked(PatientDTO? dto) async {
  113. bool? result = await Get.to<bool>(
  114. () => FacialRecognitionPage(
  115. mode: FacialRecognitionMode.faceInput,
  116. patientInfo: dto,
  117. ),
  118. );
  119. if (result != null && result) {
  120. loadData();
  121. PromptBox.toast('人脸数据存入成功');
  122. }
  123. }
  124. Future<PatientDTO?> getPatientPhoto(String patientCode) async {
  125. try {
  126. final dto = await _patientManager.getDetail(patientCode);
  127. return dto;
  128. } catch (e) {
  129. return null;
  130. }
  131. }
  132. Future<void> loadData({String code = ''}) async {
  133. PatientDTO? dto;
  134. if (code.isNotEmpty) {
  135. dto = await getPatientPhoto(code);
  136. } else if (Store.user.currentSelectPatientInfo != null &&
  137. Store.user.currentSelectPatientInfo!.code != null) {
  138. dto ??= Store.user.currentSelectPatientInfo;
  139. }
  140. if (dto != null) {
  141. state.code = dto.code ?? '';
  142. dto.birthday = dto.birthday!.toLocal();
  143. state.updateDto(dto);
  144. }
  145. }
  146. Future<bool> setCrowdLabelsAsync(
  147. List<String> carowLabels, List<String> crowdNames) async {
  148. final result =
  149. await _patientManager.setCrowdLabelsAsync(state.code, carowLabels);
  150. if (result) {
  151. state.updateCrowd(carowLabels, crowdNames);
  152. }
  153. return result;
  154. }
  155. /// 读取到最近检测记录的数据
  156. Future<void> onReadLastRecordInfo() async {
  157. try {
  158. if (Store.user.currentSelectPatientInfo?.code != null) {
  159. var diagnosisManager = Get.find<IDiagnosisManager>();
  160. List<DiagnosisAggregationRecordModel> getRecords = [];
  161. var getLastRecords =
  162. await diagnosisManager.getDiagnosisAggregationPageAsync(
  163. Store.user.currentSelectPatientInfo!.code!, 1, 10);
  164. if (getLastRecords != null) {
  165. getRecords.addAll(getLastRecords.pageData ?? []);
  166. logger.i(
  167. 'PatientDetailController onReadLastRecordInfo getLastRecords.length:${getLastRecords.dataCount}.');
  168. } else {
  169. logger.i(
  170. 'PatientDetailController onReadLastRecordInfo no online data available.');
  171. }
  172. var listRecords = await diagnosisManager
  173. .getListByPatientCode(Store.user.currentSelectPatientInfo!.code!);
  174. if (listRecords != null) {
  175. getRecords.addAll(listRecords);
  176. logger.i(
  177. 'PatientDetailController onReadLastRecordInfo listRecords.length:${listRecords.length}.');
  178. } else {
  179. logger.i(
  180. 'PatientDetailController onReadLastRecordInfo no local data available.');
  181. }
  182. if (getRecords.isNotEmpty) {
  183. var lastRecordInfo = getRecords.reduce((curr, next) =>
  184. (curr.diagnosisTime!).isAfter(next.diagnosisTime!) ? curr : next);
  185. state.isExistLocalData = lastRecordInfo.isExistLocalData ?? false;
  186. state.currentDiagnosis = await diagnosisManager
  187. .getTableData(lastRecordInfo, isLastRecord: true);
  188. }
  189. }
  190. } catch (e) {
  191. logger.e('PatientDetailController onReadLastRecordInfo.', e);
  192. }
  193. }
  194. @override
  195. void onClose() {
  196. netChecker.onlineChangedEvent.removeListener(_onlineChanged);
  197. }
  198. }