controller.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import 'dart:convert';
  2. import 'package:fis_jsonrpc/services/diagnosis.m.dart';
  3. import 'package:get/get.dart';
  4. import 'package:vitalapp/architecture/defines.dart';
  5. import 'package:vitalapp/managers/interfaces/diagnosis.dart';
  6. import 'package:vitalapp/managers/interfaces/dictionary.dart';
  7. import 'package:vitalapp/pages/medical/records/state.dart';
  8. class MedicalRecordsController extends FControllerBase {
  9. final state = MedicalRecordsState();
  10. final _diagnosisManager = Get.find<IDiagnosisManager>();
  11. final _dictionaryManager = Get.find<IDictionaryManager>();
  12. late String patientCode;
  13. @override
  14. void onReady() {
  15. super.onReady();
  16. final p = Get.parameters;
  17. patientCode = p['patientCode'] ?? "";
  18. _loadData();
  19. }
  20. _loadData() async {
  21. try {
  22. var result =
  23. await _diagnosisManager.getDiagnosisAggregationPageAsync(patientCode);
  24. if (result != null) {
  25. state.updateDto(result);
  26. }
  27. } catch (e) {}
  28. }
  29. Future<List<List<String>>> getTableData(
  30. DiagnosisAggregationRecord dto) async {
  31. var currentDiagnosis = <List<String>>[];
  32. var index = 1;
  33. // this.diagnosisTime = DateFormat("yyyy-MM-dd HH:mm:ss").format(row.diagnosisTime);
  34. for (var element in dto.diagnosisAggregationData!) {
  35. if (element.diagnosisData != "null") {
  36. var jsonData = json.decode(element.diagnosisData!);
  37. List<String> keys = jsonData.keys.toList();
  38. var dtos =
  39. await _dictionaryManager.getDictionaryNameAndUnitByKeysAsync(keys);
  40. for (var key in keys) {
  41. var dto = dtos?.firstWhere((item) => item.key == key);
  42. currentDiagnosis.add([
  43. (index++).toString(),
  44. dto?.name ?? '',
  45. jsonData[key],
  46. dto?.unit ?? '',
  47. ]);
  48. }
  49. }
  50. }
  51. return currentDiagnosis;
  52. }
  53. }