controller.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. import 'dart:async';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:flutter/foundation.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. /// 仅支持在线模式的菜单路由
  22. static final _onlineOnlyMenuRouteNames = <String>[
  23. "/contract/package_list",
  24. "/check/form",
  25. ];
  26. static Widget _buildImgIcon(String assetName) {
  27. return ClipRect(
  28. child: SizedBox(
  29. height: 34,
  30. child: Image.asset(
  31. "assets/images/home/$assetName",
  32. width: 46,
  33. height: 46,
  34. fit: BoxFit.fitWidth,
  35. ),
  36. ),
  37. );
  38. }
  39. final _patientManager = Get.find<IPatientManager>();
  40. final state = HomeState();
  41. /// 当前选中路由
  42. int currentIndex = -1;
  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. state.currentSelectMenu = name;
  223. NavGotoHelper.goto(name, patientInfo);
  224. }
  225. void initMenus() {
  226. if (Store.user.menuPermissionList?.isNotEmpty ?? false) {
  227. List<HomeMenuItem> menuItems = [];
  228. Store.user.menuPermissionList?.forEach((element) {
  229. for (var item in homeMenuItems) {
  230. if (item.key == element.code) {
  231. menuItems.add(item);
  232. }
  233. }
  234. });
  235. if (!menuItems.any((element) => element.key == "JKJC")) {
  236. state.currentSelectMenu = menuItems.first.routeName;
  237. }
  238. state.menuItems = menuItems;
  239. } else {
  240. // state.menuItems = homeMenuItems;
  241. state.menuItems = [
  242. HomeMenuItem(
  243. key: 'XJDA',
  244. title: "新建档案",
  245. routeName: "/patient/create",
  246. // TODO: 图addHealthRecord.png 不太合适,先层叠这样显示
  247. iconWidget: _PatientAddIconProxyWidget(
  248. baseIcon: _buildImgIcon('healthRecord.png'),
  249. ),
  250. ),
  251. HomeMenuItem(
  252. key: 'JMLB',
  253. title: "居民列表",
  254. routeName: "/patient/list",
  255. iconWidget: _buildImgIcon('patientList.png'),
  256. ),
  257. HomeMenuItem(
  258. key: 'JKDA',
  259. title: "健康档案",
  260. routeName: "/patient/detail",
  261. iconWidget: _buildImgIcon('healthRecord.png'),
  262. ),
  263. HomeMenuItem(
  264. key: 'JKJC',
  265. title: "健康检测",
  266. routeName: "/medical",
  267. iconWidget: _buildImgIcon('diagnosisDisplay.png'),
  268. ),
  269. // HomeMenuItem(
  270. // key: 'SZZX',
  271. // title: "设置中心",
  272. // routeName: "/settings",
  273. // iconData: Icons.settings,
  274. // ),
  275. ];
  276. }
  277. }
  278. void updateMenus() {
  279. if (Store.user.menuPermissionList?.isNotEmpty ?? false) {
  280. List<HomeMenuItem> menuItems = [];
  281. Store.user.menuPermissionList?.forEach((element) {
  282. for (var item in homeMenuItems) {
  283. if (item.key == element.code) {
  284. menuItems.add(item);
  285. }
  286. }
  287. });
  288. // if (kDebugMode && !menuItems.any((element) => element.key == 'FSZD')) {
  289. // menuItems.add(
  290. // HomeMenuItem(
  291. // key: 'FSZD',
  292. // routeName: '/remedicalRecordView',
  293. // title: '分时诊断',
  294. // iconWidget: _PatientAddIconProxyWidget(
  295. // baseIcon: _buildImgIcon('healthRecord.png'),
  296. // ),
  297. // ),
  298. // );
  299. // }
  300. // menuItems.add(homeMenuItems.firstWhere((x) => x.key == "ZYTZ"));
  301. state.menuItems = menuItems;
  302. } else {
  303. // state.menuItems = homeMenuItems;
  304. state.menuItems = [
  305. HomeMenuItem(
  306. key: 'XJDA',
  307. title: "新建档案",
  308. routeName: "/patient/create",
  309. // TODO: 图addHealthRecord.png 不太合适,先层叠这样显示
  310. iconWidget: _PatientAddIconProxyWidget(
  311. baseIcon: _buildImgIcon('healthRecord.png'),
  312. ),
  313. ),
  314. HomeMenuItem(
  315. key: 'JMLB',
  316. title: "居民列表",
  317. routeName: "/patient/list",
  318. iconWidget: _buildImgIcon('patientList.png'),
  319. ),
  320. HomeMenuItem(
  321. key: 'JKDA',
  322. title: "健康档案",
  323. routeName: "/patient/detail",
  324. iconWidget: _buildImgIcon('healthRecord.png'),
  325. ),
  326. HomeMenuItem(
  327. key: 'JKJC',
  328. title: "健康检测",
  329. routeName: "/medical",
  330. iconWidget: _buildImgIcon('diagnosisDisplay.png'),
  331. ),
  332. // HomeMenuItem(
  333. // key: 'SZZX',
  334. // title: "设置中心",
  335. // routeName: "/settings",
  336. // iconData: Icons.settings,
  337. // ),
  338. ];
  339. }
  340. }
  341. void onScanData(String code) async {
  342. print('$code');
  343. RegisterPersonInfoDTO? registerPersonInfo =
  344. await _patientManager.getRegisterPersonInfoByPhysicalExamNumberAsync(
  345. physicalExamNumber: code,
  346. );
  347. PatientDTO? patientInfo = PatientDTO();
  348. if (registerPersonInfo != null &&
  349. registerPersonInfo.physicalExamNumber != null) {
  350. patientInfo.code = registerPersonInfo.code;
  351. patientInfo.patientName = registerPersonInfo.name;
  352. Store.user.currentSelectRegisterPersonInfo = registerPersonInfo;
  353. Store.user.currentSelectPatientInfo = patientInfo;
  354. }
  355. Get.back();
  356. onScanSwitchPage(state.currentSelectMenu);
  357. print(state.currentSelectMenu);
  358. }
  359. void onScanSwitchPage(String routeName) {
  360. switch (routeName) {
  361. case "/electrocardiogram":
  362. Get.dialog(_buildMedical());
  363. return;
  364. }
  365. }
  366. Widget _buildMedical() {
  367. return Scaffold(
  368. appBar: VAppBar(
  369. titleText: "体检心电",
  370. ),
  371. body: Container(
  372. color: Colors.white,
  373. child: Stack(
  374. children: [
  375. Row(
  376. children: [
  377. _buildDeviceImage(DeviceTypes.TWELVEHEART),
  378. _buildMedicalInput(DeviceTypes.TWELVEHEART),
  379. ],
  380. ),
  381. Positioned(
  382. right: 16,
  383. bottom: 16,
  384. child: _buildSaveButton(),
  385. ),
  386. ],
  387. ),
  388. ),
  389. );
  390. }
  391. Widget _buildMedicalInput(String? currentTab) {
  392. return Expanded(
  393. flex: currentTab == DeviceTypes.TWELVEHEART ? 18 : 11,
  394. child: Stack(
  395. children: [
  396. Container(
  397. padding: const EdgeInsets.all(16),
  398. child: Column(
  399. children: [
  400. _buildContent(),
  401. ],
  402. ),
  403. ),
  404. ],
  405. ),
  406. );
  407. }
  408. String _deviceImageUrl(String? currentTab) {
  409. switch (currentTab) {
  410. case DeviceTypes.TEMP:
  411. return 'assets/images/healthCheck/temp.png';
  412. case DeviceTypes.SUGAR:
  413. return 'assets/images/healthCheck/sugar.png';
  414. case DeviceTypes.NIBP:
  415. return 'assets/images/healthCheck/nibp.png';
  416. case DeviceTypes.SPO2:
  417. return 'assets/images/healthCheck/spo2.png';
  418. case DeviceTypes.WEIGHT:
  419. return 'assets/images/healthCheck/bmi.png';
  420. case DeviceTypes.URINE:
  421. return 'assets/images/healthCheck/urine.png';
  422. case DeviceTypes.WAIST:
  423. return 'assets/images/healthCheck/whb.png';
  424. default:
  425. return 'assets/images/exam/normalMeasurementChart.png';
  426. }
  427. }
  428. Widget _buildDeviceImage(String? currentTab) {
  429. if (currentTab == DeviceTypes.TWELVEHEART) {
  430. return const SizedBox();
  431. }
  432. return Expanded(
  433. flex: 7,
  434. child: Container(
  435. alignment: Alignment.topCenter,
  436. margin: const EdgeInsets.all(16).copyWith(top: 10),
  437. child: SizedBox(),
  438. ),
  439. );
  440. }
  441. Widget _buildSaveButton() {
  442. return Obx(() {
  443. if (Store.user.currentSelectRegisterPersonInfo == null) {
  444. return const SizedBox();
  445. }
  446. return FloatingActionButton.extended(
  447. // backgroundColor: Theme.of(context).primaryColor,
  448. onPressed: () {
  449. // advanceDebounce(
  450. // () => controller.createHeart(
  451. // Store.user.currentSelectRegisterPersonInfo?.physicalExamNumber ??
  452. // '',
  453. // 'HEIECG',
  454. // ),
  455. // "createCheckup",
  456. // 1500,
  457. // );
  458. },
  459. label: const SizedBox(
  460. width: 240,
  461. height: 60,
  462. child: Center(
  463. child: Text(
  464. '提交',
  465. style: TextStyle(
  466. fontSize: 26,
  467. color: Colors.white,
  468. ),
  469. ),
  470. ),
  471. ),
  472. );
  473. });
  474. }
  475. Widget _buildContent() {
  476. return const TwelveHeartRate();
  477. }
  478. }
  479. class _PatientAddIconProxyWidget extends StatelessWidget {
  480. final Widget baseIcon;
  481. const _PatientAddIconProxyWidget({
  482. Key? key,
  483. required this.baseIcon,
  484. }) : super(key: key);
  485. @override
  486. Widget build(BuildContext context) {
  487. return Stack(
  488. children: [
  489. baseIcon,
  490. const Positioned(
  491. right: 0,
  492. top: 0,
  493. child: Icon(
  494. Icons.add,
  495. size: 16,
  496. color: Colors.white,
  497. ),
  498. )
  499. ],
  500. );
  501. }
  502. }