item_meta_convert.dart 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import 'package:fis_jsonrpc/services/remedical.m.dart';
  2. import 'package:fis_measure/interfaces/process/items/item_metas.dart';
  3. import 'package:fis_measure/interfaces/process/items/terms.dart';
  4. import 'package:vid/us/vid_us_unit.dart';
  5. class ItemMetaConverter {
  6. ItemMetaConverter(this.dto);
  7. final ItemMetaDTO dto;
  8. late String _measureType = dto.measureTypeName!;
  9. late final List<ItemOutputMeta> _outputs;
  10. late final List<ItemMeta> _childItems = [];
  11. /// 输出测量项元
  12. ItemMeta output() {
  13. if (dto.multiMethodItems != null && dto.multiMethodItems!.isNotEmpty) {
  14. _loadMulti();
  15. } else if (dto.methodChildItems != null &&
  16. dto.methodChildItems!.isNotEmpty) {
  17. _loadCombo();
  18. } else {
  19. _loadSimple();
  20. }
  21. if (dto.name == "LV Study") {
  22. print("!!!!");
  23. }
  24. _outputs = _convetOutputsFromCalc(dto.calculator!);
  25. final meta = ItemMeta(
  26. dto.name!,
  27. measureType: _measureType,
  28. description: dto.description!,
  29. briefAnnotation: dto.briefAnnotation ?? '',
  30. outputs: _outputs,
  31. childItems: _childItems,
  32. );
  33. return meta;
  34. }
  35. /// 简单测量
  36. void _loadSimple() {
  37. //
  38. }
  39. /// 组合测量
  40. void _loadCombo() {
  41. for (var child in dto.methodChildItems!) {
  42. _childItems.add(_convertChildItem(child));
  43. }
  44. }
  45. /// 多测量方法
  46. void _loadMulti() {
  47. final workingItem = dto.multiMethodItems!.firstWhere((e) => e.isWorking);
  48. _measureType = workingItem.measureTypeName!;
  49. if (workingItem.childItems != null && workingItem.childItems!.isNotEmpty) {
  50. for (var child in workingItem.childItems!) {
  51. _childItems.add(_convertChildItem(child));
  52. }
  53. }
  54. }
  55. static ItemMeta _convertChildItem(ChildItemMetaDTO c) {
  56. ChildItemMetaDTO dto = c;
  57. if (c.childItems != null && c.childItems!.isNotEmpty) {
  58. final child = c.childItems!.firstWhere((e) => e.isWorking);
  59. dto = child;
  60. }
  61. return ItemMeta(
  62. c.name!,
  63. measureType: dto.measureTypeName!,
  64. description: c.description ?? c.name!,
  65. outputs: _convetOutputsFromCalc(dto.calculator!),
  66. childItems: [],
  67. );
  68. }
  69. static List<ItemOutputMeta> _convetOutputsFromCalc(
  70. CalculatorMetaDTO calcDto) {
  71. final outputs = calcDto.availableOutputs!
  72. .where((e) => e.isWorking == true)
  73. .map((e) => _convetOutputFromDto(e))
  74. .toList();
  75. if (outputs.isEmpty) {
  76. //TODO: wait remove
  77. return [_convetOutputFromDto(calcDto.availableOutputs!.first)];
  78. }
  79. return outputs;
  80. }
  81. static ItemOutputMeta _convetOutputFromDto(OutputItemMetaDTO o) {
  82. return ItemOutputMeta(
  83. o.name!,
  84. o.description!,
  85. VidUsUnitMap.getUnit(o.unit),
  86. );
  87. }
  88. }