controller.dart 15 KB

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