controller.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. import 'dart:async';
  2. import 'package:fis_common/js_plateform/js_platform.dart';
  3. import 'package:fis_jsonrpc/rpc.dart';
  4. import 'package:flutter/material.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/components/appbar.dart';
  10. import 'package:vitalapp/global.dart';
  11. import 'package:vitalapp/helper/goto_helper.dart';
  12. import 'package:vitalapp/managers/interfaces/account.dart';
  13. import 'package:vitalapp/managers/interfaces/patient.dart';
  14. import 'package:vitalapp/pages/controllers/home_nav_mixin.dart';
  15. import 'package:vitalapp/pages/home/models/menu.dart';
  16. import 'package:vitalapp/pages/medical/widgets/twelve_ecg.dart';
  17. import 'package:vitalapp/store/store.dart';
  18. import 'package:vnote_device_plugin/consts/types.dart';
  19. import 'state.dart';
  20. class HomeController extends FControllerBase with HomeNavMixin {
  21. static const String _windowName = "Main";
  22. /// 仅支持在线模式的菜单路由
  23. static final _onlineOnlyMenuRouteNames = <String>[
  24. "/contract/package_list",
  25. "/check/form",
  26. ];
  27. static Widget _buildImgIcon(String assetName) {
  28. return ClipRect(
  29. child: SizedBox(
  30. height: 34,
  31. child: Image.asset(
  32. "assets/images/home/$assetName",
  33. width: 46,
  34. height: 46,
  35. fit: BoxFit.fitWidth,
  36. ),
  37. ),
  38. );
  39. }
  40. final _patientManager = Get.find<IPatientManager>();
  41. final state = HomeState();
  42. /// 当前选中路由
  43. int currentIndex = -1;
  44. List<HomeMenuItem> homeMenuItems = [
  45. HomeMenuItem(
  46. key: 'ZY',
  47. title: "主页",
  48. routeName: "/dashboard",
  49. iconData: Icons.home_outlined,
  50. ),
  51. HomeMenuItem(
  52. key: 'XJDA',
  53. title: "新建档案",
  54. routeName: "/patient/create",
  55. // TODO: 图addHealthRecord.png 不太合适,先层叠这样显示
  56. iconWidget: _PatientAddIconProxyWidget(
  57. baseIcon: _buildImgIcon('healthRecord.png'),
  58. ),
  59. ),
  60. HomeMenuItem(
  61. key: 'JKDA',
  62. title: "健康档案",
  63. routeName: "/patient/detail",
  64. iconWidget: _buildImgIcon('healthRecord.png'),
  65. ),
  66. HomeMenuItem(
  67. key: 'JMLB',
  68. title: "居民列表",
  69. routeName: "/patient/list",
  70. iconWidget: _buildImgIcon('patientList.png'),
  71. ),
  72. HomeMenuItem(
  73. key: 'YSQY',
  74. title: "医生签约",
  75. routeName: "/contract/package_list",
  76. iconWidget: _buildImgIcon('doctorSigning.png'),
  77. ),
  78. HomeMenuItem(
  79. key: 'JKTJ',
  80. title: "健康体检",
  81. routeName: "/check/form",
  82. iconWidget: _buildImgIcon('healthCheckup.png'),
  83. ),
  84. HomeMenuItem(
  85. key: 'RQSF',
  86. title: "人群随访",
  87. routeName: "/check/follow_up",
  88. iconWidget: _buildImgIcon('populationFollowUp.png'),
  89. ),
  90. HomeMenuItem(
  91. key: 'JKJC',
  92. title: "健康检测",
  93. routeName: "/medical",
  94. iconWidget: _buildImgIcon('diagnosisDisplay.png'),
  95. isSelected: true,
  96. ),
  97. HomeMenuItem(
  98. title: "中医体质",
  99. routeName: "/TraditionalChineseMedicineConstitution",
  100. key: "ZYTZ",
  101. iconWidget: _buildImgIcon("medicineConstitution.png"),
  102. isSelected: true,
  103. ),
  104. HomeMenuItem(
  105. key: 'TJDJ',
  106. title: "体检列表",
  107. routeName: "/registrationList",
  108. iconWidget: _PatientAddIconProxyWidget(
  109. baseIcon: _buildImgIcon('healthRecord.png'),
  110. ),
  111. ),
  112. HomeMenuItem(
  113. key: 'TJYY',
  114. title: "预约管理",
  115. routeName: "/appointment",
  116. iconWidget: _PatientAddIconProxyWidget(
  117. baseIcon: _buildImgIcon('diagnosisDisplay.png'),
  118. ),
  119. ),
  120. HomeMenuItem(
  121. key: 'TJJCJC',
  122. title: "基础检查",
  123. routeName: "/basicCheck",
  124. iconWidget: _PatientAddIconProxyWidget(
  125. baseIcon: _buildImgIcon('patientList.png'),
  126. ),
  127. ),
  128. HomeMenuItem(
  129. key: 'TJXD',
  130. title: "心电",
  131. routeName: "/electrocardiogram",
  132. iconWidget: _PatientAddIconProxyWidget(
  133. baseIcon: _buildImgIcon('populationFollowUp.png'),
  134. ),
  135. ),
  136. HomeMenuItem(
  137. key: 'TJNY',
  138. title: "尿常规",
  139. routeName: "/ncg",
  140. iconWidget: _PatientAddIconProxyWidget(
  141. baseIcon: _buildImgIcon('populationFollowUp.png'),
  142. ),
  143. ),
  144. HomeMenuItem(
  145. key: 'TJXCG',
  146. title: "血常规",
  147. routeName: "/bloodTest",
  148. iconWidget: _PatientAddIconProxyWidget(
  149. baseIcon: _buildImgIcon('populationFollowUp.png'),
  150. ),
  151. ),
  152. HomeMenuItem(
  153. key: 'TJSH',
  154. title: "生化",
  155. routeName: "/biochemistryTest",
  156. iconWidget: _PatientAddIconProxyWidget(
  157. baseIcon: _buildImgIcon('populationFollowUp.png'),
  158. ),
  159. ),
  160. // HomeMenuItem(
  161. // key: 'SZZX',
  162. // title: "设置中心",
  163. // routeName: "/settings",
  164. // iconData: Icons.settings,
  165. // ),
  166. HomeMenuItem(
  167. key: 'TJCS',
  168. routeName: '/remedicalRecordView',
  169. title: '超声',
  170. iconWidget: _PatientAddIconProxyWidget(
  171. baseIcon: _buildImgIcon('populationFollowUp.png'),
  172. ),
  173. ),
  174. // HomeMenuItem(
  175. // key: 'YCBG',
  176. // routeName: '/remedicalRecordView',
  177. // title: '异常报告',
  178. // iconWidget: _PatientAddIconProxyWidget(
  179. // baseIcon: _buildImgIcon('populationFollowUp.png'),
  180. // ),
  181. // ),
  182. ];
  183. /// 登出
  184. Future<void> logOut() async {
  185. final result = await Get.find<IAccountManager>().logout();
  186. if (result) {
  187. Get.offAllNamed("/login");
  188. }
  189. }
  190. // Future<void> changeMedical() async {
  191. // try {
  192. // Get.offAllNamed("/medical", id: 1001);
  193. // } catch (e) {}
  194. // }
  195. void onlineChanged(_, bool isOnline) {
  196. state.isOnline = isOnline;
  197. }
  198. @override
  199. void onInit() {
  200. initMenus();
  201. super.onInit();
  202. }
  203. initAddListener() {
  204. netChecker.onlineChangedEvent.addListener(onlineChanged);
  205. }
  206. netCheckerRemoveListener() {
  207. netChecker.onlineChangedEvent.removeListener(onlineChanged);
  208. }
  209. /// 切换活动菜单
  210. void switchActiveMenu(HomeMenuItem data) async {
  211. if (!kIsOnline) {
  212. // 无网络时,根据仅在线支持的菜单名单判断,进行阻断和提示
  213. if (_onlineOnlyMenuRouteNames.contains(data.routeName)) {
  214. PromptBox.toast("请检查网络连接");
  215. return;
  216. }
  217. }
  218. if (state.currentSelectMenu != data.routeName) {
  219. switchNavByName(data.routeName);
  220. }
  221. }
  222. void switchNavByName(String name, [Map? patientInfo]) {
  223. if (Store.user.currentSelectPatientInfo == null) {
  224. /// 有些路由跳转之前需要判断有没有选择居民
  225. if (["/patient/detail"].contains(name)) {
  226. PromptBox.toast("当前未选择居民,请先选择居民后再操作。");
  227. return;
  228. }
  229. }
  230. state.currentSelectMenu = name;
  231. NavGotoHelper.goto(name, patientInfo);
  232. }
  233. void initMenus() {
  234. if (Store.user.menuPermissionList?.isNotEmpty ?? false) {
  235. List<HomeMenuItem> menuItems = [];
  236. Store.user.menuPermissionList?.forEach((element) {
  237. for (var item in homeMenuItems) {
  238. if (item.key == element.code) {
  239. menuItems.add(item);
  240. }
  241. }
  242. });
  243. if (!menuItems.any((element) => element.key == "JKJC")) {
  244. state.currentSelectMenu = menuItems.first.routeName;
  245. }
  246. state.menuItems = menuItems;
  247. } else {
  248. // state.menuItems = homeMenuItems;
  249. state.menuItems = [
  250. HomeMenuItem(
  251. key: 'XJDA',
  252. title: "新建档案",
  253. routeName: "/patient/create",
  254. // TODO: 图addHealthRecord.png 不太合适,先层叠这样显示
  255. iconWidget: _PatientAddIconProxyWidget(
  256. baseIcon: _buildImgIcon('healthRecord.png'),
  257. ),
  258. ),
  259. HomeMenuItem(
  260. key: 'JMLB',
  261. title: "居民列表",
  262. routeName: "/patient/list",
  263. iconWidget: _buildImgIcon('patientList.png'),
  264. ),
  265. HomeMenuItem(
  266. key: 'JKDA',
  267. title: "健康档案",
  268. routeName: "/patient/detail",
  269. iconWidget: _buildImgIcon('healthRecord.png'),
  270. ),
  271. HomeMenuItem(
  272. key: 'JKJC',
  273. title: "健康检测",
  274. routeName: "/medical",
  275. iconWidget: _buildImgIcon('diagnosisDisplay.png'),
  276. ),
  277. ];
  278. }
  279. }
  280. void updateMenus() {
  281. if (Store.user.menuPermissionList?.isNotEmpty ?? false) {
  282. List<HomeMenuItem> menuItems = [];
  283. Store.user.menuPermissionList?.forEach((element) {
  284. for (var item in homeMenuItems) {
  285. if (item.key == element.code) {
  286. menuItems.add(item);
  287. }
  288. }
  289. });
  290. state.menuItems = menuItems;
  291. } else {
  292. state.menuItems = [
  293. HomeMenuItem(
  294. key: 'XJDA',
  295. title: "新建档案",
  296. routeName: "/patient/create",
  297. // TODO: 图addHealthRecord.png 不太合适,先层叠这样显示
  298. iconWidget: _PatientAddIconProxyWidget(
  299. baseIcon: _buildImgIcon('healthRecord.png'),
  300. ),
  301. ),
  302. HomeMenuItem(
  303. key: 'JMLB',
  304. title: "居民列表",
  305. routeName: "/patient/list",
  306. iconWidget: _buildImgIcon('patientList.png'),
  307. ),
  308. HomeMenuItem(
  309. key: 'JKDA',
  310. title: "健康档案",
  311. routeName: "/patient/detail",
  312. iconWidget: _buildImgIcon('healthRecord.png'),
  313. ),
  314. HomeMenuItem(
  315. key: 'JKJC',
  316. title: "健康检测",
  317. routeName: "/medical",
  318. iconWidget: _buildImgIcon('diagnosisDisplay.png'),
  319. ),
  320. // HomeMenuItem(
  321. // key: 'SZZX',
  322. // title: "设置中心",
  323. // routeName: "/settings",
  324. // iconData: Icons.settings,
  325. // ),
  326. ];
  327. }
  328. }
  329. void onScanData(String code) async {
  330. print('$code');
  331. RegisterPersonInfoDTO? registerPersonInfo =
  332. await _patientManager.getRegisterPersonInfoByPhysicalExamNumberAsync(
  333. physicalExamNumber: code,
  334. );
  335. PatientDTO? patientInfo = PatientDTO();
  336. if (registerPersonInfo != null &&
  337. registerPersonInfo.physicalExamNumber != null) {
  338. patientInfo.code = registerPersonInfo.code;
  339. patientInfo.patientName = registerPersonInfo.name;
  340. Store.user.currentSelectRegisterPersonInfo = registerPersonInfo;
  341. Store.user.currentSelectPatientInfo = patientInfo;
  342. }
  343. Get.back();
  344. onScanSwitchPage(state.currentSelectMenu);
  345. print(state.currentSelectMenu);
  346. }
  347. void onScanSwitchPage(String routeName) {
  348. switch (routeName) {
  349. case "/electrocardiogram":
  350. Get.dialog(_buildMedical());
  351. return;
  352. }
  353. }
  354. Widget _buildMedical() {
  355. return Scaffold(
  356. appBar: VAppBar(
  357. titleText: "体检心电",
  358. ),
  359. body: Container(
  360. color: Colors.white,
  361. child: Stack(
  362. children: [
  363. Row(
  364. children: [
  365. _buildDeviceImage(DeviceTypes.TWELVEHEART),
  366. _buildMedicalInput(DeviceTypes.TWELVEHEART),
  367. ],
  368. ),
  369. Positioned(
  370. right: 16,
  371. bottom: 16,
  372. child: _buildSaveButton(),
  373. ),
  374. ],
  375. ),
  376. ),
  377. );
  378. }
  379. Widget _buildMedicalInput(String? currentTab) {
  380. return Expanded(
  381. flex: currentTab == DeviceTypes.TWELVEHEART ? 18 : 11,
  382. child: Stack(
  383. children: [
  384. Container(
  385. padding: const EdgeInsets.all(16),
  386. child: Column(
  387. children: [
  388. _buildContent(),
  389. ],
  390. ),
  391. ),
  392. ],
  393. ),
  394. );
  395. }
  396. String _deviceImageUrl(String? currentTab) {
  397. switch (currentTab) {
  398. case DeviceTypes.TEMP:
  399. return 'assets/images/healthCheck/temp.png';
  400. case DeviceTypes.SUGAR:
  401. return 'assets/images/healthCheck/sugar.png';
  402. case DeviceTypes.NIBP:
  403. return 'assets/images/healthCheck/nibp.png';
  404. case DeviceTypes.SPO2:
  405. return 'assets/images/healthCheck/spo2.png';
  406. case DeviceTypes.WEIGHT:
  407. return 'assets/images/healthCheck/bmi.png';
  408. case DeviceTypes.URINE:
  409. return 'assets/images/healthCheck/urine.png';
  410. case DeviceTypes.WAIST:
  411. return 'assets/images/healthCheck/whb.png';
  412. default:
  413. return 'assets/images/exam/normalMeasurementChart.png';
  414. }
  415. }
  416. Widget _buildDeviceImage(String? currentTab) {
  417. if (currentTab == DeviceTypes.TWELVEHEART) {
  418. return const SizedBox();
  419. }
  420. return Expanded(
  421. flex: 7,
  422. child: Container(
  423. alignment: Alignment.topCenter,
  424. margin: const EdgeInsets.all(16).copyWith(top: 10),
  425. child: SizedBox(),
  426. ),
  427. );
  428. }
  429. Widget _buildSaveButton() {
  430. return Obx(() {
  431. if (Store.user.currentSelectRegisterPersonInfo == null) {
  432. return const SizedBox();
  433. }
  434. return FloatingActionButton.extended(
  435. // backgroundColor: Theme.of(context).primaryColor,
  436. onPressed: () {
  437. // advanceDebounce(
  438. // () => controller.createHeart(
  439. // Store.user.currentSelectRegisterPersonInfo?.physicalExamNumber ??
  440. // '',
  441. // 'HEIECG',
  442. // ),
  443. // "createCheckup",
  444. // 1500,
  445. // );
  446. },
  447. label: const SizedBox(
  448. width: 240,
  449. height: 60,
  450. child: Center(
  451. child: Text(
  452. '提交',
  453. style: TextStyle(
  454. fontSize: 26,
  455. color: Colors.white,
  456. ),
  457. ),
  458. ),
  459. ),
  460. );
  461. });
  462. }
  463. Widget _buildContent() {
  464. return const TwelveHeartRate();
  465. }
  466. ///开启拖拽
  467. Future<void> onStartDrag() async {
  468. JSPlateForm.beginWindowDrag(_windowName);
  469. }
  470. ///结束拖拽
  471. Future<void> onEndDrag() async {
  472. JSPlateForm.endWindowDrag(_windowName);
  473. }
  474. ///最小化
  475. Future<void> onMinimize() async {
  476. JSPlateForm.minimizeWindow(_windowName);
  477. }
  478. ///最大化
  479. Future<void> onMaximize() async {
  480. JSPlateForm.maximizeWindow(_windowName);
  481. }
  482. ///关闭
  483. Future<void> onWindowClose() async {
  484. JSPlateForm.closeWindow(_windowName);
  485. }
  486. }
  487. class _PatientAddIconProxyWidget extends StatelessWidget {
  488. final Widget baseIcon;
  489. const _PatientAddIconProxyWidget({
  490. Key? key,
  491. required this.baseIcon,
  492. }) : super(key: key);
  493. @override
  494. Widget build(BuildContext context) {
  495. return Stack(
  496. children: [
  497. baseIcon,
  498. const Positioned(
  499. right: 0,
  500. top: 0,
  501. child: Icon(
  502. Icons.add,
  503. size: 16,
  504. color: Colors.white,
  505. ),
  506. )
  507. ],
  508. );
  509. }
  510. }