controller.dart 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import 'dart:convert';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/widgets.dart';
  5. import 'package:get/get.dart';
  6. import 'package:vitalapp/architecture/defines.dart';
  7. import 'package:vitalapp/architecture/network_connectivity.dart';
  8. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  9. import 'package:vitalapp/architecture/values/features.dart';
  10. import 'package:vitalapp/components/alert_dialog.dart';
  11. import 'package:vitalapp/consts/diagnosis.dart';
  12. import 'package:vitalapp/database/entities/defines.dart';
  13. import 'package:vitalapp/global.dart';
  14. import 'package:vitalapp/managers/interfaces/diagnosis.dart';
  15. import 'package:vitalapp/managers/interfaces/dictionary.dart';
  16. import 'package:vitalapp/managers/interfaces/models/diagnosis_aggregation_record_model.dart';
  17. import 'package:vitalapp/managers/interfaces/patient.dart';
  18. import 'package:vitalapp/managers/interfaces/record_data_cache.dart';
  19. import 'package:vitalapp/pages/controllers/home_nav_mixin.dart';
  20. import 'package:vitalapp/pages/facial_recognition/index.dart';
  21. import 'package:vitalapp/store/store.dart';
  22. import 'state.dart';
  23. class PatientDetailController extends FControllerBase with HomeNavMixin {
  24. final state = PatientDetailState();
  25. final _patientManager = Get.find<IPatientManager>();
  26. @override
  27. void onInit() {
  28. WidgetsBinding.instance.addPostFrameCallback(
  29. (timeStamp) async {
  30. loadData();
  31. if (Store.user.hasFeature(FeatureKeys.RecentTestRecords)) {
  32. await onReadLastRecordInfo();
  33. }
  34. netChecker.onlineChangedEvent.addListener(_onlineChanged);
  35. },
  36. );
  37. super.onInit();
  38. }
  39. void _onlineChanged(_, e) {
  40. state.isOnline = e;
  41. }
  42. /// 打开信息页
  43. void gotoInfo() {
  44. Get.toNamed(
  45. "/patient/info",
  46. parameters: {"code": state.code},
  47. );
  48. }
  49. /// 前往随访页
  50. void gotoFollowUp() {
  51. Get.toNamed(
  52. "/check/follow_up",
  53. parameters: {"patientCode": state.code, "patientName": state.name},
  54. );
  55. }
  56. /// 前往随访记录页
  57. void gotoFollowUpRecord() {
  58. Get.toNamed(
  59. "/check/follow_up_record",
  60. parameters: {"patientCode": state.code, "patientName": state.name},
  61. );
  62. }
  63. /// 前往健康体检页
  64. void gotoHealthCheck() {
  65. Get.toNamed(
  66. "/check/form",
  67. parameters: {"patientCode": state.code},
  68. );
  69. }
  70. /// 前往签约页
  71. void gotoContract() {
  72. Get.toNamed(
  73. "/contract/package_list",
  74. parameters: {"patientCode": state.code},
  75. );
  76. }
  77. /// 前往转诊页
  78. void gotoReferral() {
  79. //
  80. }
  81. /// 前往健康检测页
  82. void gotoExam() {
  83. //
  84. Get.toNamed(
  85. "/medical",
  86. parameters: {"patientCode": state.code},
  87. );
  88. }
  89. /// 前往诊疗记录页
  90. void gotoExamRecord() {
  91. //
  92. Get.toNamed(
  93. "/medical/records",
  94. parameters: {"patientCode": state.code},
  95. );
  96. }
  97. ///前往体检记录
  98. void gotoHealthCheckRecord() {
  99. Get.toNamed(
  100. "/check/healthCheckRecord",
  101. parameters: {"patientCode": state.code},
  102. );
  103. }
  104. void gotoContractRecords() {
  105. Get.toNamed(
  106. "/contract/contract_records",
  107. parameters: {"patientCode": state.code},
  108. );
  109. }
  110. /// 询问是否需要人脸录入
  111. Future<void> queryIsNeedFaceInput() async {
  112. /// 拥有人脸权限并且不是身份证扫码建档
  113. if (Store.user.hasFeature(FeatureKeys.FaceRecognition) && state.isOnline) {
  114. var dto =
  115. await getPatientPhoto(Store.user.currentSelectPatientInfo!.cardNo!);
  116. String? photoUrl = dto?.photos != null ? dto?.photos![0] : "";
  117. if (photoUrl!.isNotEmpty) {
  118. await Get.dialog(VAlertDialog(
  119. contentPadding: const EdgeInsets.fromLTRB(20, 1, 20, 1),
  120. title: '提示',
  121. content: Container(
  122. margin: const EdgeInsets.only(bottom: 20),
  123. child: Column(
  124. mainAxisSize: MainAxisSize.min,
  125. children: [
  126. Image.network(photoUrl,
  127. width: 300, height: 220, fit: BoxFit.cover,
  128. loadingBuilder: (context, child, progress) {
  129. if (progress == null ||
  130. progress.cumulativeBytesLoaded ==
  131. progress.expectedTotalBytes) {
  132. return Image.network(
  133. photoUrl,
  134. width: 300,
  135. height: 220,
  136. fit: BoxFit.cover,
  137. );
  138. }
  139. return const CircularProgressIndicator(
  140. color: Colors.blueAccent);
  141. }),
  142. const Text("该居民已采集过人脸,是否重新采集?",
  143. style: TextStyle(fontSize: 20),
  144. textAlign: TextAlign.center),
  145. ],
  146. ),
  147. ),
  148. confirmLabel: '重新采集',
  149. cancelLabel: '跳过',
  150. showCancel: true,
  151. onConfirm: () async {
  152. await onFaceEntryClicked(dto);
  153. Get.back();
  154. },
  155. onCanceled: () {
  156. Get.back();
  157. },
  158. ));
  159. } else {
  160. await Get.dialog(VAlertDialog(
  161. contentPadding: const EdgeInsets.fromLTRB(20, 1, 20, 1),
  162. title: '提示',
  163. content: Container(
  164. margin: const EdgeInsets.only(bottom: 20),
  165. child: const Text(
  166. '采集人像,完成后可以使用人脸识别功能',
  167. style: TextStyle(fontSize: 20),
  168. textAlign: TextAlign.center,
  169. ),
  170. ),
  171. confirmLabel: '采集',
  172. cancelLabel: '暂不采集',
  173. showCancel: true,
  174. onConfirm: () async {
  175. await onFaceEntryClicked(dto);
  176. Get.back();
  177. },
  178. onCanceled: () {
  179. Get.back();
  180. },
  181. ));
  182. }
  183. }
  184. }
  185. /// 点击录入人脸
  186. Future<void> onFaceEntryClicked(PatientDTO? dto) async {
  187. bool? result = await Get.to<bool>(
  188. () => FacialRecognitionPage(
  189. mode: FacialRecognitionMode.faceInput,
  190. patientInfo: dto,
  191. ),
  192. );
  193. if (result != null && result) {
  194. loadData();
  195. PromptBox.toast('人脸数据存入成功');
  196. }
  197. }
  198. Future<PatientDTO?> getPatientPhoto(String patientCode) async {
  199. try {
  200. final dto = await _patientManager.getDetail(patientCode);
  201. return dto;
  202. } catch (e) {
  203. return null;
  204. }
  205. }
  206. Future<void> loadData() async {
  207. state.code = Store.user.currentSelectPatientInfo?.code ?? '';
  208. var dto = await getPatientPhoto(Store.user.currentSelectPatientInfo!.code!);
  209. dto ??= Store.user.currentSelectPatientInfo;
  210. if (dto != null) {
  211. dto.birthday = dto.birthday!.toLocal();
  212. state.updateDto(dto);
  213. }
  214. }
  215. Future<bool> setCrowdLabelsAsync(
  216. List<String> carowLabels, List<String> crowdNames) async {
  217. final result =
  218. await _patientManager.setCrowdLabelsAsync(state.code, carowLabels);
  219. if (result) {
  220. state.updateCrowd(carowLabels, crowdNames);
  221. }
  222. return result;
  223. }
  224. /// 读取到最近检测记录的数据
  225. Future<void> onReadLastRecordInfo() async {
  226. if (Store.user.currentSelectPatientInfo?.code != null) {
  227. var diagnosisManager = Get.find<IDiagnosisManager>();
  228. List<DiagnosisAggregationRecordModel> getRecords = [];
  229. var getLastRecords =
  230. await diagnosisManager.getDiagnosisAggregationPageAsync(
  231. Store.user.currentSelectPatientInfo!.code!, 1, 10);
  232. getRecords.addAll(getLastRecords?.pageData ?? []);
  233. var listRecords = await diagnosisManager
  234. .getListByPatientCode(Store.user.currentSelectPatientInfo!.code!);
  235. getRecords.addAll(listRecords ?? []);
  236. if (getRecords.isNotEmpty) {
  237. var lastRecordInfo = getRecords.reduce((curr, next) =>
  238. (curr.diagnosisTime!).isAfter(next.diagnosisTime!) ? curr : next);
  239. state.isExistLocalData = lastRecordInfo.isExistLocalData ?? false;
  240. state.currentDiagnosis =
  241. await diagnosisManager.getTableData(lastRecordInfo);
  242. }
  243. }
  244. }
  245. @override
  246. void onClose() {
  247. netChecker.onlineChangedEvent.removeListener(_onlineChanged);
  248. }
  249. }