view.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. import 'package:fis_jsonrpc/rpc.dart';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import 'package:intl/intl.dart';
  6. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  7. import 'package:vitalapp/components/alert_dialog.dart';
  8. import 'package:vitalapp/components/appbar.dart';
  9. import 'package:vitalapp/components/button.dart';
  10. import 'package:vitalapp/components/qr_code_with_logo/qr_code_with_logo.dart';
  11. import 'package:vitalapp/consts/styles.dart';
  12. import 'package:vitalapp/database/entities/defines.dart';
  13. import 'package:vitalapp/pages/check/follow_up/widgets/follow_up_from.dart';
  14. import 'package:vitalapp/pages/check/follow_up_record/controller.dart';
  15. import 'package:vitalapp/pages/check/maternal_health_management/widgets/delete_follow_up_record_button.dart';
  16. import 'package:vitalapp/pages/check/prescription/prescription_form_keys.dart';
  17. import 'package:vitalapp/pages/check/tuberculosis_management_record/widget/FormSelectDialog.dart';
  18. import 'package:vitalapp/pages/check/widgets/configurable_card.dart';
  19. import 'package:vitalapp/pages/medical/controller.dart';
  20. import 'package:vitalapp/pages/patient/list/widgets/status.dart';
  21. import 'package:vitalapp/pages/widgets/record_common_item.dart';
  22. class TuberculosisManagementView extends GetView<FollowUpRecordController> {
  23. const TuberculosisManagementView({
  24. Key? key,
  25. required this.followUpType,
  26. }) : super(key: key);
  27. final String followUpType;
  28. @override
  29. Widget build(BuildContext context) {
  30. return GetBuilder(
  31. init: FollowUpRecordController(
  32. followUpType: followUpType,
  33. ),
  34. builder: (_) {
  35. return Scaffold(
  36. backgroundColor: const Color.fromRGBO(238, 238, 238, 1),
  37. appBar: VAppBar(
  38. titleWidget: Text('肺结核患者随访管理'),
  39. actions: [
  40. IconButton(
  41. onPressed: () {
  42. Get.dialog(FormSelectDialog(onConfirm: (type) {
  43. String key = "FollowUpTuberculosisFirstRecord";
  44. switch (type) {
  45. case 1:
  46. key = "FollowUpTuberculosisFirstRecord";
  47. break;
  48. case 2:
  49. key = "FollowUpTuberculosisRecord";
  50. break;
  51. case 3:
  52. key = "FollowUpTuberculosisResultRecord";
  53. break;
  54. }
  55. _changePage(key);
  56. Get.back();
  57. }));
  58. },
  59. icon: Icon(
  60. Icons.add,
  61. size: 48,
  62. ),
  63. ),
  64. SizedBox(
  65. width: 8,
  66. ),
  67. ],
  68. ),
  69. body: Stack(
  70. children: [
  71. Row(
  72. mainAxisAlignment: MainAxisAlignment.start,
  73. crossAxisAlignment: CrossAxisAlignment.start,
  74. children: [
  75. _buildDiagram(),
  76. _buildListView(),
  77. ],
  78. ),
  79. ],
  80. ),
  81. );
  82. });
  83. }
  84. void _changePage(String key) async {
  85. /// TODO BAKA 急需求 后面改掉
  86. await Get.put(MedicalController());
  87. controller.followUpController.state.followUpTime = DateTime.now();
  88. controller.followUpController.state.nextFollowUpTime = null;
  89. controller.followUpController.state.followUpMode =
  90. FollowUpModeEnum.Outpatient;
  91. controller.followUpController.state.followUpPhoto = '';
  92. await Get.to(
  93. ConfigurableCard(
  94. cardKey: key,
  95. callBack: (key, templateCode, data, prescriptionKey) async {
  96. final result = await controller.followUpController.createFollowUp(
  97. key, templateCode, data, prescriptionKey.toString());
  98. return result;
  99. },
  100. followUpWidget: FollowUpFrom(
  101. cardKey: key,
  102. ),
  103. ),
  104. transition: Transition.rightToLeft,
  105. );
  106. await controller.getFollowUpRecordList();
  107. await Get.find<MedicalController>().initRecordDataState();
  108. await Get.delete<MedicalController>();
  109. }
  110. Widget _buildDiagram() {
  111. return Expanded(
  112. flex: 1,
  113. child: Padding(
  114. padding: const EdgeInsets.all(16.0).copyWith(right: 0),
  115. child: Container(
  116. // color: Colors.white,
  117. padding: const EdgeInsets.all(16),
  118. decoration: BoxDecoration(
  119. color: Colors.white,
  120. border: Border.all(
  121. color: Colors.white,
  122. ),
  123. borderRadius: GlobalStyles.borderRadius,
  124. ),
  125. child: Image.asset(
  126. 'assets/images/exam/normalMeasurementChart.png',
  127. height: double.infinity,
  128. fit: BoxFit.fitWidth,
  129. ),
  130. ),
  131. ),
  132. );
  133. }
  134. Widget _buildListView() {
  135. return Expanded(
  136. flex: 2,
  137. child: Padding(
  138. padding: const EdgeInsets.all(16),
  139. child: RefreshIndicator(
  140. child: Obx(
  141. () {
  142. final list = controller.state.followUpDTOList;
  143. final children = <Widget>[];
  144. for (var i = 0; i < list.length; i++) {
  145. final dto = list[i];
  146. final offlineSyncArr = controller.offlineSyncTemp[i];
  147. final records = dto.followUpRecordDatas;
  148. if (records == null) {
  149. continue;
  150. }
  151. for (var j = 0; j < records.length; j++) {
  152. final data = records[j];
  153. OfflineDataSyncState? offlineSyncState;
  154. offlineSyncState = kIsWeb ? null : offlineSyncArr[j];
  155. children.add(
  156. _followUpRecordCard(
  157. index: j,
  158. dto: dto,
  159. dataDto: data,
  160. syncState: offlineSyncState,
  161. ),
  162. );
  163. }
  164. }
  165. return list.isEmpty
  166. ? Container(
  167. margin: const EdgeInsets.only(top: 80),
  168. child: Column(
  169. children: [
  170. Center(
  171. child: Image.asset(
  172. "assets/images/no_data.png",
  173. width: 300,
  174. height: 300,
  175. fit: BoxFit.cover,
  176. ),
  177. ),
  178. const Text(
  179. "暂无数据,先看看别的吧",
  180. style: TextStyle(fontSize: 18),
  181. ),
  182. ],
  183. ),
  184. )
  185. : GridView(
  186. gridDelegate:
  187. const SliverGridDelegateWithFixedCrossAxisCount(
  188. crossAxisCount: 1,
  189. mainAxisSpacing: 16,
  190. crossAxisSpacing: 20,
  191. childAspectRatio: 900 / 180,
  192. ),
  193. children: children,
  194. );
  195. },
  196. ),
  197. onRefresh: () async {}),
  198. ),
  199. );
  200. }
  201. }
  202. // ignore: camel_case_types
  203. class _followUpRecordCard extends StatelessWidget {
  204. final FollowUpRecordDTO dto;
  205. final FollowUpRecordDataDTO dataDto;
  206. final int index;
  207. final OfflineDataSyncState? syncState; // TODO temp
  208. _followUpRecordCard({
  209. required this.dto,
  210. required this.dataDto,
  211. required this.index,
  212. this.syncState,
  213. });
  214. final controller = Get.find<FollowUpRecordController>();
  215. @override
  216. Widget build(BuildContext context) {
  217. final body = Stack(
  218. children: [
  219. Row(
  220. children: [
  221. Expanded(
  222. flex: 10,
  223. child: Container(
  224. padding: const EdgeInsets.symmetric(
  225. horizontal: 30,
  226. vertical: 12,
  227. ),
  228. child: Column(
  229. crossAxisAlignment: CrossAxisAlignment.start,
  230. children: [
  231. const SizedBox(
  232. height: 8,
  233. ),
  234. LayoutBuilder(builder: (context, c) {
  235. final width = c.maxWidth - 100;
  236. return SizedBox(
  237. width: width,
  238. child: _buildBaseInfoRow(),
  239. );
  240. }),
  241. const SizedBox(
  242. height: 20,
  243. ),
  244. Wrap(
  245. alignment: WrapAlignment.start,
  246. spacing: 20,
  247. runSpacing: 8,
  248. children: [
  249. SizedBox(
  250. width: 300,
  251. child: RecordCommonItem(
  252. itemName: '姓名',
  253. itemValue: dto.patientName ?? "",
  254. fontSize: 18,
  255. ),
  256. ),
  257. RecordCommonItem(
  258. itemName: '随访类型',
  259. itemValue:
  260. controller.getFollowUpMode(dataDto.followUpMode),
  261. fontSize: 18,
  262. ),
  263. ],
  264. ),
  265. const SizedBox(
  266. height: 20,
  267. ),
  268. Wrap(
  269. alignment: WrapAlignment.start,
  270. spacing: 20,
  271. runSpacing: 8,
  272. children: [
  273. SizedBox(
  274. width: 300,
  275. child: RecordCommonItem(
  276. itemName: '随访医生',
  277. itemValue: dataDto.followUpDoctor ?? "",
  278. fontSize: 18,
  279. ),
  280. ),
  281. RecordCommonItem(
  282. itemName: '随访时间',
  283. itemValue: dataDto.followUpTime != null
  284. ? DateFormat("yyyy-MM-dd")
  285. .format(dataDto.followUpTime!.toLocal())
  286. : "",
  287. fontSize: 18,
  288. ),
  289. ],
  290. )
  291. ],
  292. ),
  293. ),
  294. ),
  295. // Expanded(
  296. // child: IconButton(
  297. // onPressed: () {
  298. // controller.toCheckPage(dataDto, isCreateFromOldDto: true);
  299. // },
  300. // icon: Icon(
  301. // Icons.add,
  302. // size: 56,
  303. // color: Colors.grey.shade400,
  304. // ),
  305. // ),
  306. // )
  307. ],
  308. ),
  309. Positioned(
  310. top: 16,
  311. right: 0,
  312. child: _FollowUpRecordSignStatusTag(
  313. dataDto: dataDto,
  314. ),
  315. ),
  316. // if(dataDto)
  317. Positioned(
  318. top: 16,
  319. right: 100,
  320. child: _OfflineSyncTag(syncState: syncState),
  321. ),
  322. // Positioned(
  323. // bottom: 16,
  324. // right: 12,
  325. // child: IconButton(
  326. // icon: Icon(
  327. // Icons.edit,
  328. // size: 26,
  329. // color: Theme.of(context).primaryColor,
  330. // ),
  331. // onPressed: () {
  332. // controller.toCheckPage(dataDto); //跳转到随访页面
  333. // },
  334. // ),
  335. // ),
  336. Positioned(
  337. bottom: 0,
  338. right: 0,
  339. child: DeleteFollowUpRecordButton(dataDto.code!, dataDto.key!, () {
  340. controller.getFollowUpRecordList();
  341. }),
  342. ),
  343. if (![
  344. "FollowUpTuberculosisFirstRecord",
  345. "FollowUpTuberculosisResultRecord"
  346. ].contains(dataDto.key))
  347. Positioned(
  348. bottom: 16,
  349. right: 180,
  350. child: _buildShareButton(),
  351. ),
  352. Positioned(
  353. bottom: 16,
  354. right: 60,
  355. child: _buildCopyAddButton(dataDto),
  356. ),
  357. ],
  358. );
  359. return Material(
  360. borderRadius: GlobalStyles.borderRadius,
  361. child: Ink(
  362. decoration: BoxDecoration(
  363. color: Colors.white,
  364. borderRadius: GlobalStyles.borderRadius,
  365. ),
  366. child: InkWell(
  367. borderRadius: GlobalStyles.borderRadius,
  368. onTap: () {
  369. // controller.toFollowUpDetailPage(index, dto);
  370. controller.toCheckPage(dataDto); //跳转到随访页面
  371. },
  372. child: body,
  373. ),
  374. ),
  375. );
  376. }
  377. Widget _buildBaseInfoRow() {
  378. return SizedBox(
  379. child: RecordCommonItem(
  380. itemName: '随访名称',
  381. itemValue: controller.getFollowUpValueByKey(dataDto.key ?? ""),
  382. fontSize: 20,
  383. ),
  384. );
  385. }
  386. Widget _buildShareButton() {
  387. return Container(
  388. width: 120,
  389. height: 50,
  390. alignment: Alignment.bottomRight,
  391. child: VButton(
  392. onTap: () async {
  393. // 1111
  394. Map<String, dynamic> preview =
  395. await controller.sharePrescription(dataDto);
  396. const designWidth = 1280.0; // 设计尺寸宽度:1280
  397. final width = Get.width;
  398. final scale = width / designWidth; // 计算缩放比例
  399. if (preview["previewUrl"] == "" || preview["previewUrl"] == null) {
  400. PromptBox.toast("暂无处方");
  401. return;
  402. }
  403. Get.dialog(
  404. VAlertDialog(
  405. title: "分享处方",
  406. width: width * 0.4 / scale,
  407. content: _buildQrcode(preview),
  408. ),
  409. );
  410. },
  411. label: "分享",
  412. ),
  413. );
  414. }
  415. Widget _buildCopyAddButton(FollowUpRecordDataDTO dataDto) {
  416. return Container(
  417. width: 100,
  418. height: 50,
  419. alignment: Alignment.bottomRight,
  420. child: VButton(
  421. onTap: () {
  422. controller.toCheckPage(dataDto, isCreateFromOldDto: true);
  423. },
  424. label: "复制新增",
  425. ),
  426. );
  427. }
  428. ///二维码
  429. Widget _buildQrcode(Map<String, dynamic> qr) {
  430. return VQRCodeWithLogo(
  431. qr["previewUrl"],
  432. codeStatement: PrescriptionFormKeys.AllFormKeys[qr["key"]],
  433. operationStatement: "复制链接",
  434. size: 200,
  435. operationSuccessCallback: () {
  436. PromptBox.toast("复制成功");
  437. },
  438. );
  439. }
  440. }
  441. // ignore: camel_case_types
  442. class _FollowUpRecordSignStatusTag extends StatelessWidget {
  443. final FollowUpRecordDataDTO dataDto;
  444. _FollowUpRecordSignStatusTag({required this.dataDto});
  445. final controller = Get.find<FollowUpRecordController>();
  446. @override
  447. Widget build(BuildContext context) {
  448. return Container(
  449. alignment: Alignment.centerRight,
  450. width: 120,
  451. child: StatusLabel(
  452. title: controller.followUpStateTransition(dataDto.followUpState),
  453. color: controller.followUpStateColors(dataDto.followUpState),
  454. ),
  455. );
  456. }
  457. }
  458. class _OfflineSyncTag extends StatelessWidget {
  459. final OfflineDataSyncState? syncState;
  460. const _OfflineSyncTag({required this.syncState});
  461. @override
  462. Widget build(BuildContext context) {
  463. if (syncState == null || syncState == OfflineDataSyncState.success) {
  464. return const SizedBox();
  465. }
  466. return Container(
  467. height: 30,
  468. alignment: Alignment.center,
  469. padding: const EdgeInsets.symmetric(horizontal: 16),
  470. decoration: BoxDecoration(
  471. borderRadius: BorderRadius.circular(16),
  472. color: Colors.red,
  473. ),
  474. child: Text(
  475. syncState!.getDescription(),
  476. style: const TextStyle(color: Colors.white, fontSize: 14),
  477. ),
  478. );
  479. }
  480. }