data_convert.dart 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import 'dart:convert';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:get/get.dart';
  4. import 'interfaces/data_convert.dart';
  5. import 'interfaces/dictionary.dart';
  6. class DataConvertManager implements IDataConvertManager {
  7. @override
  8. String heartRateConversion(int heartRate) {
  9. if (heartRate < 60) {
  10. return "心率过低";
  11. } else if (heartRate > 100) {
  12. return "心率过快";
  13. }
  14. return "心率值未见异常";
  15. }
  16. @override
  17. Future<List<List<String>>> getTableData(String data) async {
  18. var currentDiagnosis = <List<String>>[];
  19. if (data.isEmpty) {
  20. return currentDiagnosis;
  21. }
  22. var jsonData = json.decode(data);
  23. List<String> keys = jsonData.keys.toList();
  24. List<DictionaryWithUnitDTO>? dtos = [];
  25. dtos = await Get.find<IDictionaryManager>()
  26. .getDictionaryNameAndUnitByKeysAsync(keys) ??
  27. [];
  28. for (var key in keys) {
  29. if (key == "ECG_POINT" ||
  30. key == "ECG_POINT12" ||
  31. key == "HealthGuidance") {
  32. continue;
  33. }
  34. var dto = dtos.firstWhereOrNull((item) => item.key == key);
  35. if (dto == null) {
  36. continue;
  37. }
  38. final value = jsonData[key].toString();
  39. if (value.isEmpty) {
  40. // 不展示空值
  41. continue;
  42. }
  43. currentDiagnosis.add([
  44. dto.name ?? '',
  45. value,
  46. dto.unit ?? '',
  47. ]);
  48. }
  49. return currentDiagnosis;
  50. }
  51. }