controller.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import 'dart:io';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:get/get.dart';
  4. import 'package:path_provider/path_provider.dart';
  5. import 'package:vitalapp/architecture/storage/text_storage.dart';
  6. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  7. import 'package:vitalapp/global.dart';
  8. import 'package:vitalapp/managers/interfaces/exam.dart';
  9. import 'package:vitalapp/pages/check/examination/state.dart';
  10. import 'package:vitalapp/pages/check/models/form.dart';
  11. class ExaminationController extends GetxController {
  12. ExaminationController({
  13. required this.patientCode,
  14. required this.batchNumber,
  15. });
  16. String patientCode;
  17. final _examManager = Get.find<IExamManager>();
  18. final state = ExaminationState();
  19. String batchNumber;
  20. _initData() {
  21. update(["examination"]);
  22. // getBatchNumber();
  23. }
  24. // Future<void> getBatchNumber() async {
  25. // var cachedBatchNumber = await readCachedBatchNumber();
  26. // if (cachedBatchNumber != null) {
  27. // batchNumber = cachedBatchNumber;
  28. // } else {
  29. // await saveCachedBatchNumber();
  30. // }
  31. // }
  32. // Future<bool?> saveCachedBatchNumber() async {
  33. // batchNumber = const Uuid().v4().replaceAll('-', '');
  34. // TextStorage cachedRecord = TextStorage(
  35. // fileName: 'batchNumber',
  36. // directory: "patient/$patientCode",
  37. // );
  38. // return cachedRecord.save(batchNumber ?? "");
  39. // }
  40. Future<String?> readCachedBatchNumber() async {
  41. TextStorage cachedRecord = TextStorage(
  42. fileName: 'batchNumber',
  43. directory: "patient/$patientCode",
  44. );
  45. return cachedRecord.read();
  46. }
  47. List<MenuItem> menuList = [
  48. MenuItem(label: "一般状况", value: 'ZZYBZK'),
  49. MenuItem(label: "辅助检查", value: 'FZJC'),
  50. MenuItem(label: "生活方式", value: 'SHFS'),
  51. MenuItem(label: "脏器及查体", value: 'ZQCT'),
  52. MenuItem(label: "现存主要健康问题", value: 'XCZYWT'),
  53. MenuItem(label: "住院及用药情况", value: 'ZYYYFMYGHYFJZS'),
  54. MenuItem(label: "健康评价及指导", value: 'JKPJJZD'),
  55. ];
  56. Future<void> createOrUpdateExam(key, templateCode, data, isMuanual) async {
  57. if (!kIsOnline) {
  58. // TODO: 暂不支持离线体检
  59. PromptBox.toast("请检查网络连接");
  60. return;
  61. }
  62. TextStorage template = TextStorage(
  63. fileName: key,
  64. directory: "patient/$patientCode/exam",
  65. );
  66. if (!isMuanual) {
  67. final cachedData = await template.read();
  68. if (cachedData == data) {
  69. // 无改动
  70. return;
  71. }
  72. }
  73. var result = await _examManager.createExam(CreateExamRequest(
  74. key: key,
  75. patientCode: patientCode,
  76. templateCode: templateCode,
  77. examData: data,
  78. batchNumber: batchNumber,
  79. ));
  80. if (result ?? false) {
  81. try {
  82. await template.save(data);
  83. PromptBox.toast('保存成功');
  84. } catch (err) {
  85. PromptBox.toast('保存失败');
  86. }
  87. }
  88. }
  89. /// 检查数据是否为空
  90. Future<bool> checkExamEmpty() async {
  91. try {
  92. final root = await getExternalStorageDirectory();
  93. final dir = Directory("${root!.path}/patient/$patientCode/exam");
  94. if (await dir.exists()) {
  95. final files = dir.listSync();
  96. return files.isEmpty;
  97. } else {
  98. return true;
  99. }
  100. } catch (e) {
  101. return false;
  102. }
  103. }
  104. // Future<void> deleteCached() async {
  105. // saveCachedBatchNumber();
  106. // TextStorage template = TextStorage(
  107. // fileName: '',
  108. // directory: "patient/$patientCode/exam",
  109. // );
  110. // final result = await template.deleteDirectory();
  111. // if (result) {
  112. // PromptBox.toast('本轮体检已结束');
  113. // Get.back();
  114. // }
  115. // }
  116. @override
  117. void onReady() {
  118. _initData();
  119. super.onReady();
  120. }
  121. }