Browse Source

ItemMetaConverter

melon.yin 2 years ago
parent
commit
fd1ebe30f6

File diff suppressed because it is too large
+ 0 - 0
assets/items.json


+ 2 - 6
lib/interfaces/process/items/item_metas.dart

@@ -12,10 +12,7 @@ class ItemMeta {
   String briefAnnotation;
 
   /// 测量类型
-  String? measureType;
-
-  /// 组合测量方法
-  String? multiMethod;
+  String measureType;
 
   /// 计算输出元信息
   List<ItemOutputMeta> outputs;
@@ -25,11 +22,10 @@ class ItemMeta {
 
   ItemMeta(
     this.name, {
-    this.measureType,
+    required this.measureType,
     required this.description,
     required this.outputs,
     this.briefAnnotation = '',
-    this.multiMethod,
     this.childItems = const [],
   });
 

+ 18 - 3
lib/interfaces/process/items/types.dart

@@ -16,21 +16,36 @@ class MeasureTypes {
   /// 面积
   static const String Area = "Area";
 
-  /// 体积
-  static const String Volume = "Volume";
-
   /// 角度
   static const String Angle = "Angle";
 
   /// 椭圆测面积周长
   static const String AreaPerimeterEllipse = "AreaPerimeterEllipse";
 
+  /* Volume */
+
+  /// 体积
+  static const String Volume = "Volume";
+
   /// 椭圆测体积
   static const String VolumeEllipse = "VolumeEllipse";
 
+  /// 单线体积
+  static const String VolumeOneDistance = "VolumeOneDistance";
+
+  /// 二线体积
+  static const String VolumeTwoDistance = "VolumeTwoDistance";
+
+  /// 三线体积
+  static const String VolumeThreeDistance = "VolumeThreeDistance";
+
+  /* 面积周长 */
+
   /// 折线多边型测面积周长
   static const String AreaPerimeterPolyline = "AreaPerimeterPolyline";
 
+  /* AI */
+
   /// 前壁
   static const String AntCCA_IMT = "Ant.CCA IMT";
 

+ 57 - 0
lib/item_create_test.dart

@@ -0,0 +1,57 @@
+import 'dart:convert';
+
+import 'package:fis_jsonrpc/services/remedical.m.dart';
+import 'package:fis_measure/interfaces/process/items/types.dart';
+import 'package:fis_measure/process/items/item_meta_convert.dart';
+import 'package:flutter/services.dart';
+
+class ItemCreateTest {
+  // ignore: non_constant_identifier_names
+  static List<String> C_Working_Items = [
+    // "Distance",
+    // "Depth",
+    // "Perimeter",
+    // "Area",
+    "Volume",
+    // "Angle",
+    // "%Stenosis",
+    // "A/B Ratio",
+    // "AP",
+    // "Thyroid Vol.(L)",
+    // "Thyroid Vol.(R)",
+    // "Renal Vol.(L)",
+  ];
+
+  // ignore: non_constant_identifier_names
+  static List<String> C_Working_Types = [
+    MeasureTypes.Distance,
+    // MeasureTypes.Depth,
+    // MeasureTypes.Perimeter,
+    // MeasureTypes.Area,
+    // MeasureTypes.Angle,
+    // MeasureTypes.VolumeThreeDistance,
+    // MeasureTypes.AreaPerimeterEllipse,
+    // MeasureTypes.AreaPerimeterPolyline,
+    // MeasureTypes.Volume,
+  ];
+  void run() async {
+    final txt = await rootBundle.loadString('assets/items.json');
+    final mapList = jsonDecode(txt) as List<dynamic>;
+    final workingMaps =
+        mapList.where((e) => C_Working_Items.contains(e['Name']));
+    // mapList.where((e) => C_Working_Items.contains(e['MeasureTypeName']));
+    for (var map in workingMaps) {
+      final dto = ItemMetaDTO.fromJson(map);
+      // final hasMulti =
+      //     dto.multiMethodItems != null && dto.multiMethodItems!.isNotEmpty;
+      // final hasChild =
+      //     dto.methodChildItems != null && dto.methodChildItems!.isNotEmpty;
+      // if (!hasMulti && !hasChild) {
+      //   final meta = ItemMetaConverter(dto).output();
+      //   print(meta.name);
+      // }
+      final meta = ItemMetaConverter(dto).output();
+      print(meta.name);
+    }
+  }
+}

+ 3 - 1
lib/main.dart

@@ -10,6 +10,7 @@ import 'package:flutter/material.dart';
 import 'package:get/get.dart';
 import 'package:fis_i18n/i18n.dart';
 
+import 'item_create_test.dart';
 import 'third_vid_test.dart';
 
 void main() async {
@@ -67,7 +68,8 @@ class _MyHomePageState extends State<MyHomePage> {
           children: <Widget>[
             ElevatedButton(
               onPressed: () {
-                ThirdPartVidTest().run();
+                // ThirdPartVidTest().run();
+                ItemCreateTest().run();
               },
               child: const Text("Test 3rd vid"),
             ),

+ 4 - 5
lib/process/items/factory.dart

@@ -38,8 +38,8 @@ class MeasureItemFactory {
     _itemCreatorMap[key] = creator;
   }
 
-  MeasureItemCreator? _findCreator(String typeName, [String? suffix]) {
-    final key = _buildKey(typeName, suffix);
+  MeasureItemCreator? _findCreator(String typeName) {
+    final key = typeName; //_buildKey(typeName, suffix);
     if (_itemCreatorMap.containsKey(key)) {
       return _itemCreatorMap[key];
     }
@@ -56,10 +56,9 @@ class MeasureItemFactory {
   ///
   /// [parent] 父项
   static MeasureItem? createItem(ItemMeta meta, [IMeasureItem? parent]) {
-    if (meta.measureType == null || meta.measureType!.isEmpty) return null;
+    if (meta.measureType.isEmpty) return null;
 
-    final creator =
-        _singleton._findCreator(meta.measureType!, meta.multiMethod);
+    final creator = _singleton._findCreator(meta.measureType);
     if (creator == null) return null;
 
     final item = creator.call(meta, parent);

+ 88 - 0
lib/process/items/item_meta_convert.dart

@@ -0,0 +1,88 @@
+import 'package:fis_jsonrpc/services/remedical.m.dart';
+import 'package:fis_measure/interfaces/process/items/item_metas.dart';
+import 'package:vid/us/vid_us_unit.dart';
+
+class ItemMetaConverter {
+  ItemMetaConverter(this.dto);
+
+  final ItemMetaDTO dto;
+
+  late String _measureType = dto.measureTypeName!;
+
+  late final List<ItemOutputMeta> _outputs;
+  late final List<ItemMeta> _childItems = [];
+
+  /// 输出测量项元
+  ItemMeta output() {
+    if (dto.multiMethodItems != null && dto.multiMethodItems!.isNotEmpty) {
+      _loadMulti();
+    } else if (dto.methodChildItems != null &&
+        dto.methodChildItems!.isNotEmpty) {
+      _loadCombo();
+    } else {
+      _loadSimple();
+    }
+    _outputs = _convetOutputsFromCalc(dto.calculator!);
+
+    final meta = ItemMeta(
+      dto.name!,
+      measureType: _measureType,
+      description: dto.description!,
+      briefAnnotation: dto.briefAnnotation ?? '',
+      outputs: _outputs,
+      childItems: _childItems,
+    );
+
+    return meta;
+  }
+
+  /// 简单测量
+  void _loadSimple() {
+    //
+  }
+
+  /// 组合测量
+  void _loadCombo() {
+    for (var child in dto.methodChildItems!) {
+      _childItems.add(_convertChildItem(child));
+    }
+  }
+
+  /// 多测量方法
+  void _loadMulti() {
+    final workingItem = dto.multiMethodItems!.firstWhere((e) => e.isWorking);
+    _measureType = workingItem.measureTypeName!;
+
+    if (workingItem.childItems != null && workingItem.childItems!.isNotEmpty) {
+      for (var child in workingItem.childItems!) {
+        _childItems.add(_convertChildItem(child));
+      }
+    }
+  }
+
+  static ItemMeta _convertChildItem(ChildItemMetaDTO c) {
+    return ItemMeta(
+      c.name!,
+      measureType: c.measureTypeName!,
+      description: c.description!,
+      outputs: _convetOutputsFromCalc(c.calculator!),
+      childItems: [],
+    );
+  }
+
+  static List<ItemOutputMeta> _convetOutputsFromCalc(
+      CalculatorMetaDTO calcDto) {
+    return calcDto.availableOutputs!
+        .where((e) => e.isWorking == true)
+        .map((e) => _convetOutputFromDto(e))
+        .toList();
+  }
+
+  static ItemOutputMeta _convetOutputFromDto(OutputItemMetaDTO o) {
+    return ItemOutputMeta(
+      o.name!,
+      o.description!,
+      VidUsUnitMap.getUnit(o.unit),
+    );
+  }
+}

+ 1 - 1
lib/process/primitives/combos/lwh_straightline.dart

@@ -57,7 +57,7 @@ class LWHStraightLine extends TopMeasureItem<LWHStraightlineFeature> {
   void onCancelingOnce() {}
 
   static LWHStraightLine createVolume(ItemMeta meta, [IMeasureItem? parent]) {
-    if (meta.measureType != MeasureTypes.Volume || meta.multiMethod != "LWH") {
+    if (meta.measureType != MeasureTypes.VolumeThreeDistance) {
       throw ArgumentError();
     }
     var lwh = LWHStraightLine(meta);

+ 2 - 2
lib/process/workspace/application.dart

@@ -438,6 +438,7 @@ class Application implements IApplication {
       final childBuild = (String name) {
         return ItemMeta(
           name,
+          measureType: "LWHStraight",
           description: name,
           outputs: [
             ItemOutputMeta("Distance", "Distance", VidUsUnit.cm),
@@ -446,13 +447,12 @@ class Application implements IApplication {
       };
       activeMeasureItem = MeasureItemFactory.createItem(
         ItemMeta(
-          MeasureTypes.Volume,
+          MeasureTypes.VolumeThreeDistance,
           measureType: MeasureTypes.Volume,
           description: MeasureTypes.Volume,
           outputs: [
             ItemOutputMeta("Volume", "Volume", VidUsUnit.cm3),
           ],
-          multiMethod: "LWH",
           childItems: [
             childBuild("L"),
             childBuild("W"),

+ 2 - 2
lib/view/measure/measure_tool.dart

@@ -108,10 +108,10 @@ class LeftSiderSelectMeasureState extends FState<LeftSiderSelectMeasure> {
             childItemMetas.add(
               ItemMeta(
                 element.name ?? '',
+                measureType: element.measureTypeName!,
                 description: element.description ?? '',
                 outputs: itemOutputMeta,
                 childItems: childItemMetas,
-                multiMethod: multiMethod,
               ),
             );
           }
@@ -119,10 +119,10 @@ class LeftSiderSelectMeasureState extends FState<LeftSiderSelectMeasure> {
         itemMetaList.add(
           ItemMeta(
             element.name ?? '',
+            measureType: element.measureTypeName!,
             description: element.description ?? '',
             outputs: itemOutputMeta,
             childItems: childItemMetas,
-            multiMethod: multiMethod,
           ),
         );
       }

+ 2 - 3
lib/view/measure/measure_tools_title.dart

@@ -69,7 +69,6 @@ class _LeftMeasureToolsState extends State<LeftMeasureTools> {
         if (element.multiMethodItems?.isNotEmpty ?? false) {
           ChildItemMetaDTO? itemMeta = element.multiMethodItems!
               .firstWhereOrNull((element) => element.isWorking == true);
-          multiMethod = itemMeta?.name ?? '';
           List<ChildItemMetaDTO> childItems = itemMeta?.childItems ?? [];
 
           /// 组合测量项部分
@@ -77,10 +76,10 @@ class _LeftMeasureToolsState extends State<LeftMeasureTools> {
             childItemMetas.add(
               ItemMeta(
                 element.name ?? '',
+                measureType: element.measureTypeName!,
                 description: element.description ?? '',
                 outputs: itemOutputMeta,
                 childItems: childItemMetas,
-                multiMethod: multiMethod,
               ),
             );
           }
@@ -88,10 +87,10 @@ class _LeftMeasureToolsState extends State<LeftMeasureTools> {
         itemMetaList.add(
           ItemMeta(
             element.name ?? '',
+            measureType: element.measureTypeName!,
             description: element.description ?? '',
             outputs: itemOutputMeta,
             childItems: childItemMetas,
-            multiMethod: multiMethod,
           ),
         );
       }

+ 1 - 0
lib/view/mobile_view/mobile_right_panel/mobile_measure_tool.dart

@@ -85,6 +85,7 @@ class _MobileMeasureSelector extends LeftSiderSelectMeasureState {
           changeItem(
             ItemMeta(
               "None",
+              measureType: "None",
               description: "None",
               outputs: [
                 ItemOutputMeta("None", "None", VidUsUnit.cm2),

+ 7 - 7
pubspec.lock

@@ -21,7 +21,7 @@ packages:
       name: asn1lib
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.1.0"
+    version: "1.1.1"
   async:
     dependency: transitive
     description:
@@ -149,8 +149,8 @@ packages:
     dependency: "direct main"
     description:
       path: "."
-      ref: "0d8e47b"
-      resolved-ref: "0d8e47bf872a5c99f88c88fe3e805312fdddcfdb"
+      ref: "06b2cae"
+      resolved-ref: "06b2cae73b8bc11e399497d6b9d4491933a80d8c"
       url: "http://git.ius.plus:88/Project-Wing/fis_lib_jsonrpc.git"
     source: git
     version: "0.0.1"
@@ -446,7 +446,7 @@ packages:
       name: plugin_platform_interface
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "2.1.2"
+    version: "2.1.3"
   pointer_interceptor:
     dependency: transitive
     description:
@@ -460,7 +460,7 @@ packages:
       name: pointycastle
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "3.6.1"
+    version: "3.6.2"
   process:
     dependency: transitive
     description:
@@ -521,7 +521,7 @@ packages:
       name: synchronized
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "3.0.0+2"
+    version: "3.0.0+3"
   term_glyph:
     dependency: transitive
     description:
@@ -649,7 +649,7 @@ packages:
       name: webview_flutter_platform_interface
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.9.2"
+    version: "1.9.3"
   webview_flutter_wkwebview:
     dependency: transitive
     description:

+ 2 - 2
pubspec.yaml

@@ -96,7 +96,7 @@ dependency_overrides:
   fis_jsonrpc:
     git:
       url: http://git.ius.plus:88/Project-Wing/fis_lib_jsonrpc.git
-      ref: 0d8e47b
+      ref: 06b2cae
   fis_lib_business_components:
     git:
       url: http://git.ius.plus/bakamaka.guan/fis_lib_business_components.git
@@ -104,7 +104,7 @@ dependency_overrides:
   fis_lib_qrcode:
     git:
       url: http://git.ius.plus/jimmy.jiang/fis_lib_qrcode.git
-      ref: f7fd36ad46    
+      ref: f7fd36ad46
 dev_dependencies:
   flutter_test:
     sdk: flutter

Some files were not shown because too many files changed in this diff