controller.dart 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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/global.dart';
  8. import 'package:vitalapp/managers/interfaces/diagnosis.dart';
  9. import 'package:vitalapp/managers/interfaces/patient.dart';
  10. import 'package:vitalapp/pages/controllers/home_nav_mixin.dart';
  11. import 'package:vitalapp/pages/facial_recognition/index.dart';
  12. import 'package:vitalapp/store/store.dart';
  13. import 'package:fis_common/logger/logger.dart';
  14. import 'state.dart';
  15. class PatientDetailController extends FControllerBase with HomeNavMixin {
  16. final state = PatientDetailState();
  17. final _patientManager = Get.find<IPatientManager>();
  18. @override
  19. void onInit() {
  20. WidgetsBinding.instance.addPostFrameCallback(
  21. (timeStamp) async {
  22. await loadData();
  23. netChecker.onlineChangedEvent.addListener(_onlineChanged);
  24. },
  25. );
  26. super.onInit();
  27. }
  28. void _onlineChanged(_, e) {
  29. state.isOnline = e;
  30. }
  31. /// 打开信息页
  32. void gotoInfo() {
  33. Get.toNamed(
  34. "/patient/info",
  35. parameters: {"code": state.code},
  36. );
  37. }
  38. /// 打开精神障碍信息补充表
  39. void gotoMentalDisorderInfo() {
  40. Get.toNamed(
  41. "/patient/mental_disorder_info",
  42. parameters: {"code": state.code},
  43. );
  44. }
  45. /// 前往随访页
  46. void gotoFollowUp() {
  47. Get.toNamed(
  48. "/check/follow_up",
  49. parameters: {"patientCode": state.code, "patientName": state.name},
  50. );
  51. }
  52. /// 前往随访记录页
  53. void gotoFollowUpRecord() {
  54. Get.toNamed(
  55. "/check/follow_up_record",
  56. parameters: {"patientCode": state.code, "patientName": state.name},
  57. );
  58. }
  59. /// 前往高血压记录页面
  60. void gotoHypertensionRecord() {
  61. Get.toNamed(
  62. "/check/follow_up_record/hypertension",
  63. parameters: {"patientCode": state.code, "patientName": state.name},
  64. );
  65. }
  66. /// 前往糖尿病记录页面
  67. void gotoDiabetesRecord() {
  68. Get.toNamed(
  69. "/check/follow_up_record/diabetes",
  70. );
  71. }
  72. ///前往严重精神障碍记录页面
  73. void gotoMentalDisorderRecord() {
  74. Get.toNamed(
  75. "/check/follow_up_record/mentalDisorder",
  76. );
  77. }
  78. ///check/follow_up_record/tuberculosis
  79. ///前往严重精神障碍记录页面
  80. void gototuberculosisRecord() {
  81. Get.toNamed(
  82. "check/follow_up_record/tuberculosis",
  83. );
  84. }
  85. /// 前往健康体检页
  86. void gotoHealthCheck() {
  87. Get.toNamed(
  88. "/check/form",
  89. parameters: {"patientCode": state.code},
  90. );
  91. }
  92. /// 前往签约页
  93. void gotoContract() {
  94. Get.toNamed(
  95. "/contract/package_list",
  96. parameters: {"patientCode": state.code},
  97. );
  98. }
  99. /// 前往转诊页
  100. void gotoReferral() {
  101. //
  102. }
  103. /// 前往健康检测页
  104. void gotoExam() {
  105. //
  106. Get.toNamed(
  107. "/medical",
  108. parameters: {"patientCode": state.code},
  109. );
  110. }
  111. /// 前往诊疗记录页
  112. void gotoExamRecord() {
  113. //
  114. Get.toNamed(
  115. "/medical/records",
  116. parameters: {"patientCode": state.code},
  117. );
  118. }
  119. ///前往体检记录
  120. void gotoHealthCheckRecord() {
  121. if (!kIsOnline) {
  122. PromptBox.toast("请检查网络连接");
  123. return;
  124. }
  125. Get.toNamed(
  126. "/check/healthCheckRecord",
  127. parameters: {"patientCode": state.code},
  128. );
  129. }
  130. /// 前往签约记录页
  131. void gotoContractRecords() async {
  132. await Get.toNamed(
  133. "/contract/contract_records",
  134. parameters: {"patientCode": state.code},
  135. );
  136. loadData();
  137. }
  138. ///前往中医体质记录
  139. void gotoTraditionalChineseMedicineConsitutionRecord() {
  140. Get.toNamed(
  141. "/TraditionalChineseMedicineConsitutionRecord",
  142. parameters: {"key": "LNRZYYJKGLFWJL"},
  143. );
  144. }
  145. ///前往自理能力评估记录页面
  146. void gotoSelfCareAbilityAssessment() {
  147. Get.toNamed(
  148. '/SelfCareAbilityAssessmentRecord',
  149. parameters: {"Key": "LNRZLNLPG"},
  150. );
  151. }
  152. void gotoMaternalHealthManagement() {
  153. Get.toNamed(
  154. '/MaternalHealthManagement',
  155. parameters: {"Key": "MaternalHealthManagement"},
  156. );
  157. }
  158. void gotoChildHealth() {
  159. Get.toNamed(
  160. "/check/follow_up_record/children",
  161. parameters: {"patientCode": state.code, "patientName": state.name},
  162. );
  163. }
  164. /// 人脸录入
  165. Future<void> queryIsNeedFaceInput() async {
  166. var dto = await getPatientDto(Store.user.currentSelectPatientInfo!.cardNo!);
  167. await onFaceEntryClicked(dto);
  168. Get.back();
  169. }
  170. /// 点击录入人脸
  171. Future<void> onFaceEntryClicked(PatientDTO? dto) async {
  172. bool? result = await Get.to<bool>(
  173. () => FacialRecognitionPage(
  174. mode: FacialRecognitionMode.faceInput,
  175. patientInfo: dto,
  176. ),
  177. );
  178. if (result != null && result) {
  179. await loadData();
  180. PromptBox.toast('人脸数据存入成功');
  181. }
  182. }
  183. Future<PatientDTO?> getPatientDto(String patientCode) async {
  184. try {
  185. final dto = await _patientManager.getDetail(patientCode);
  186. return dto;
  187. } catch (e) {
  188. return null;
  189. }
  190. }
  191. Future<void> updatePatient() async {
  192. try {
  193. final dto = await _patientManager.getDetail(state.dto.code!);
  194. if (dto == null) {
  195. return;
  196. }
  197. UpdatePatientRequest2 request = UpdatePatientRequest2(
  198. token: Store.user.token,
  199. code: dto.code,
  200. patientName: dto.patientName,
  201. phone: dto.phone,
  202. emergencyName: dto.emergencyName,
  203. emergencyPhone: dto.emergencyPhone,
  204. cardNo: dto.cardNo,
  205. nationality: dto.nationality,
  206. birthday: dto.birthday,
  207. cardType: dto.cardType,
  208. patientGender: dto.patientGender,
  209. patientAddress: dto.patientAddress,
  210. crowdLabels: _patientManager.crowdLabelsConvert(state.labels),
  211. permanentResidenceAddress: dto.permanentResidenceAddress,
  212. );
  213. _patientManager.updatePatientAsync(request);
  214. } catch (e) {
  215. logger.e("PatientDetailController updatePatient:${e}");
  216. }
  217. }
  218. Future<void> loadData({String code = ''}) async {
  219. PatientDTO? dto;
  220. if (code.isNotEmpty) {
  221. dto = await getPatientDto(code);
  222. } else if (Store.user.currentSelectPatientInfo != null &&
  223. Store.user.currentSelectPatientInfo!.code != null) {
  224. dto = await getPatientDto(Store.user.currentSelectPatientInfo!.code!);
  225. // if (kDebugMode && (dto!.crowdLabels?.isEmpty ?? true)) {
  226. // dto.crowdLabels = ["RQFL_LNR", "CJJB_GXY_Suspected", "CJJB_TNB"];
  227. // }
  228. } else if (Store.user.currentSelectPatientInfo != null &&
  229. Store.user.currentSelectPatientInfo!.cardNo != null) {
  230. dto = await getPatientDto(Store.user.currentSelectPatientInfo!.cardNo!);
  231. }
  232. if (dto != null) {
  233. state.code = dto.code ?? '';
  234. dto.birthday = dto.birthday!.toLocal();
  235. state.updateDto(dto);
  236. } else if (state.dto.phone == "UNLOAD") {
  237. state.dto.phone = "";
  238. state.updateDto(state.dto);
  239. }
  240. }
  241. Future<bool> setCrowdLabelsAsync(
  242. List<String> carowLabels, List<String> crowdNames) async {
  243. final result =
  244. await _patientManager.setCrowdLabelsAsync(state.code, carowLabels);
  245. if (result) {
  246. state.updateCrowd(carowLabels, crowdNames);
  247. }
  248. return result;
  249. }
  250. IDiagnosisManager _diagnosisManager = Get.find<IDiagnosisManager>();
  251. /// 读取到最近检测记录的数据
  252. Future<void> onReadLastRecordInfo() async {
  253. try {
  254. var lastRecordInfo = await _diagnosisManager.getLastRecordInfo();
  255. if (lastRecordInfo != null) {
  256. state.isExistLocalData = lastRecordInfo.isExistLocalData ?? false;
  257. state.currentDiagnosis = await _diagnosisManager
  258. .getTableData(lastRecordInfo, isLastRecord: true);
  259. } else {
  260. state.currentDiagnosis = [];
  261. }
  262. } catch (e) {
  263. logger.e('PatientDetailController onReadLastRecordInfo.', e);
  264. }
  265. }
  266. @override
  267. void onClose() {
  268. netChecker.onlineChangedEvent.removeListener(_onlineChanged);
  269. }
  270. }