123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- import 'dart:convert';
- import 'package:ecg_list_view/entitys/resident_model.dart';
- import 'package:ecg_list_view/rpc/rpc_bridge.dart';
- import 'package:flutter/foundation.dart';
- import 'package:get/get.dart';
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:fis_common/logger/logger.dart';
- import 'package:fis_common/index.dart';
- class EcgListController extends GetxController {
- RecordProcessStateEnum typeFilter = RecordProcessStateEnum.All;
- List<ExamStateEnum>? states;
- EcgListController();
- //右侧选中的Tab
- int selectedTabIndex = 0;
- ///展示下级的数据
- bool showLowerDatas = false;
- /// 表格loading
- bool tableLoading = true;
- /// 当前表格页数
- int currPageIndex = 1;
- /// 当前列表选中的
- int currectSelected = -1;
- DateTime? startTime;
- DateTime? endTime;
- List<ElectrocardiogramRecord> residentList = [];
- List<UserFeatureDTO> userFeatures = [];
- /// 列表的总数
- int tableCount = 0;
- /// 当前检测详情
- List<List<String>> tableData = [];
- List<ReportDTO> reports = [];
- Future<void> getDatas({
- int? pageSize = 10,
- int? pageIndex = 1,
- String? keyword = "",
- }) async {
- tableLoading = true;
- currPageIndex = pageIndex!;
- currectSelected = -1;
- tableData.clear();
- final result = await RPCBridge.ins.rpc.vitalElectrocardiogram
- .getElectrocardiogramRecordPageAsync(
- ElectrocardiogramRecordPageRequest(
- token: RPCBridge.ins.token,
- pageSize: pageSize!,
- pageIndex: pageIndex,
- keyWord: keyword,
- startTime: startTime?.toUtc(),
- endTime: endTime?.toUtc(),
- isQuerySubordinate: showLowerDatas,
- states: states,
- ),
- );
- residentList.clear();
- residentList = result.pageData ?? [];
- tableCount = result.totalCount;
- residentList = residentList;
- tableLoading = false;
- update(["ecg_list"]);
- update(["table"]);
- update(["table_pagination"]);
- }
- Future<List<List<String>>> getTableData(String data) async {
- if (data.isEmpty) {
- return [];
- }
- var currentDiagnosis = <List<String>>[];
- var jsonData = json.decode(data);
- List<String> keys = jsonData.keys.toList();
- List<DictionaryWithUnitDTO>? dtos = [];
- dtos = await RPCBridge.ins.rpc.vitalDictionary
- .getDictionaryNameAndUnitByKeysAsync(
- GetDictionaryNameAndUnitByKeysRequest(
- keys: keys,
- token: RPCBridge.ins.token,
- ));
- for (var key in keys) {
- if (key == "ECG_POINT" || key == "ECG_POINT12") {
- continue;
- }
- var dto = dtos.firstWhereOrNull((item) => item.key == key);
- if (dto == null) {
- continue;
- }
- final value = jsonData[key].toString();
- if (value.isEmpty) {
- // 不展示空值
- continue;
- }
- currentDiagnosis.add([
- dto.name ?? '',
- value,
- dto.unit ?? '',
- ]);
- }
- return currentDiagnosis;
- }
- @override
- void onReady() {
- super.onReady();
- _getOperationPermission();
- getDatas();
- }
- Future<void> onRowTap(int index) async {
- currectSelected = index;
- var examRecord = residentList[index];
- if (examRecord.examData.isNotNullOrEmpty) {
- tableData = await getTableData(examRecord.examData!);
- }
- loadReports();
- update(["ecg_list"]);
- }
- void changeDatas(bool v) {
- showLowerDatas = v;
- }
- void loadCurrentRecordInfo() {
- update(["ecg_list"]);
- }
- Future<void> loadReports() async {
- if (currectSelected == -1) {
- return;
- }
- var recordCode = residentList[currectSelected].code;
- try {
- reports = await RPCBridge.ins.rpc.ultrasoundReport.vitalFindReportsAsync(
- FindReportsRequest(
- token: RPCBridge.ins.token,
- recordCode: recordCode,
- ),
- );
- } catch (e) {
- logger.e('EcgListController loadReports ex:$e');
- }
- update(["ecg_list"]);
- }
- Future<void> changeTypeFilter(RecordProcessStateEnum value) async {
- typeFilter = value;
- if (value == RecordProcessStateEnum.All) {
- states = null;
- } else if (value == RecordProcessStateEnum.Done) {
- states = [ExamStateEnum.Reported];
- } else {
- states = [
- ExamStateEnum.Unchecked,
- ExamStateEnum.Invalid,
- ExamStateEnum.Inspected
- ];
- }
- await getDatas();
- update(["ecg_list"]);
- }
- Future<void> _getOperationPermission() async {
- userFeatures = await RPCBridge.ins.rpc.vitalUser
- .getOperationPermissionAsync(GetOperationPermissionRequest(
- token: RPCBridge.ins.token,
- appType: ApplicationTypeEnum.App,
- ));
- update(["ecg_list"]);
- }
- // @override
- // void onClose() {
- // super.onClose();
- // }
- }
|