controller.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import 'dart:convert';
  2. import 'package:ecg_list_view/entitys/resident_model.dart';
  3. import 'package:ecg_list_view/rpc/rpc_bridge.dart';
  4. import 'package:flutter/foundation.dart';
  5. import 'package:get/get.dart';
  6. import 'package:fis_jsonrpc/rpc.dart';
  7. import 'package:fis_common/logger/logger.dart';
  8. import 'package:fis_common/index.dart';
  9. class EcgListController extends GetxController {
  10. RecordProcessStateEnum typeFilter = RecordProcessStateEnum.All;
  11. List<ExamStateEnum>? states;
  12. EcgListController();
  13. //右侧选中的Tab
  14. int selectedTabIndex = 0;
  15. ///展示下级的数据
  16. bool showLowerDatas = false;
  17. /// 表格loading
  18. bool tableLoading = true;
  19. /// 当前表格页数
  20. int currPageIndex = 1;
  21. /// 当前列表选中的
  22. int currectSelected = -1;
  23. DateTime? startTime;
  24. DateTime? endTime;
  25. List<ElectrocardiogramRecord> residentList = [];
  26. List<UserFeatureDTO> userFeatures = [];
  27. /// 列表的总数
  28. int tableCount = 0;
  29. /// 当前检测详情
  30. List<List<String>> tableData = [];
  31. List<ReportDTO> reports = [];
  32. Future<void> getDatas({
  33. int? pageSize = 10,
  34. int? pageIndex = 1,
  35. String? keyword = "",
  36. }) async {
  37. tableLoading = true;
  38. currPageIndex = pageIndex!;
  39. currectSelected = -1;
  40. tableData.clear();
  41. final result = await RPCBridge.ins.rpc.vitalElectrocardiogram
  42. .getElectrocardiogramRecordPageAsync(
  43. ElectrocardiogramRecordPageRequest(
  44. token: RPCBridge.ins.token,
  45. pageSize: pageSize!,
  46. pageIndex: pageIndex,
  47. keyWord: keyword,
  48. startTime: startTime?.toUtc(),
  49. endTime: endTime?.toUtc(),
  50. isQuerySubordinate: showLowerDatas,
  51. states: states,
  52. ),
  53. );
  54. residentList.clear();
  55. residentList = result.pageData ?? [];
  56. tableCount = result.totalCount;
  57. residentList = residentList;
  58. tableLoading = false;
  59. update(["ecg_list"]);
  60. update(["table"]);
  61. update(["table_pagination"]);
  62. }
  63. Future<List<List<String>>> getTableData(String data) async {
  64. if (data.isEmpty) {
  65. return [];
  66. }
  67. var currentDiagnosis = <List<String>>[];
  68. var jsonData = json.decode(data);
  69. List<String> keys = jsonData.keys.toList();
  70. List<DictionaryWithUnitDTO>? dtos = [];
  71. dtos = await RPCBridge.ins.rpc.vitalDictionary
  72. .getDictionaryNameAndUnitByKeysAsync(
  73. GetDictionaryNameAndUnitByKeysRequest(
  74. keys: keys,
  75. token: RPCBridge.ins.token,
  76. ));
  77. for (var key in keys) {
  78. if (key == "ECG_POINT" || key == "ECG_POINT12") {
  79. continue;
  80. }
  81. var dto = dtos.firstWhereOrNull((item) => item.key == key);
  82. if (dto == null) {
  83. continue;
  84. }
  85. final value = jsonData[key].toString();
  86. if (value.isEmpty) {
  87. // 不展示空值
  88. continue;
  89. }
  90. currentDiagnosis.add([
  91. dto.name ?? '',
  92. value,
  93. dto.unit ?? '',
  94. ]);
  95. }
  96. return currentDiagnosis;
  97. }
  98. @override
  99. void onReady() {
  100. super.onReady();
  101. _getOperationPermission();
  102. getDatas();
  103. }
  104. Future<void> onRowTap(int index) async {
  105. currectSelected = index;
  106. var examRecord = residentList[index];
  107. if (examRecord.examData.isNotNullOrEmpty) {
  108. tableData = await getTableData(examRecord.examData!);
  109. }
  110. loadReports();
  111. update(["ecg_list"]);
  112. }
  113. void changeDatas(bool v) {
  114. showLowerDatas = v;
  115. }
  116. void loadCurrentRecordInfo() {
  117. update(["ecg_list"]);
  118. }
  119. Future<void> loadReports() async {
  120. if (currectSelected == -1) {
  121. return;
  122. }
  123. var recordCode = residentList[currectSelected].code;
  124. try {
  125. reports = await RPCBridge.ins.rpc.ultrasoundReport.vitalFindReportsAsync(
  126. FindReportsRequest(
  127. token: RPCBridge.ins.token,
  128. recordCode: recordCode,
  129. ),
  130. );
  131. } catch (e) {
  132. logger.e('EcgListController loadReports ex:$e');
  133. }
  134. update(["ecg_list"]);
  135. }
  136. Future<void> changeTypeFilter(RecordProcessStateEnum value) async {
  137. typeFilter = value;
  138. if (value == RecordProcessStateEnum.All) {
  139. states = null;
  140. } else if (value == RecordProcessStateEnum.Done) {
  141. states = [ExamStateEnum.Reported];
  142. } else {
  143. states = [
  144. ExamStateEnum.Unchecked,
  145. ExamStateEnum.Invalid,
  146. ExamStateEnum.Inspected
  147. ];
  148. }
  149. await getDatas();
  150. update(["ecg_list"]);
  151. }
  152. Future<void> _getOperationPermission() async {
  153. userFeatures = await RPCBridge.ins.rpc.vitalUser
  154. .getOperationPermissionAsync(GetOperationPermissionRequest(
  155. token: RPCBridge.ins.token,
  156. appType: ApplicationTypeEnum.App,
  157. ));
  158. update(["ecg_list"]);
  159. }
  160. // @override
  161. // void onClose() {
  162. // super.onClose();
  163. // }
  164. }