Quellcode durchsuchen

1.添加恩泽输血记录解析添加key映射
2.恩泽xml解析工具添加key映射方法

hujing vor 4 Jahren
Ursprung
Commit
5f2e7e3df9

+ 17 - 9
trans/src/main/java/com/lantone/qc/trans/beilun/util/ez/EzClinicalBloodAnalysis.java

@@ -1,8 +1,10 @@
 package com.lantone.qc.trans.beilun.util.ez;
 
+import com.google.common.collect.Lists;
 import com.lantone.qc.trans.beilun.util.ez.util.EzXmlUtil;
 import lombok.extern.slf4j.Slf4j;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -16,18 +18,24 @@ public class EzClinicalBloodAnalysis implements EzAnalysis {
     @Override
     public Map<String, String> analysis(String xml) throws Exception {
         Map<String, String> map = EzXmlUtil.analysis(xml);
+        Map<String, String> structureMap = EzXmlUtil.mapKeyContrast(map, keyContrasts);
         return map;
     }
+
     /**
      * 目前能解析字段:
-     *  全文本
-     *  诊断
-     *  检验结果
-     *  血型
-     *  输注量
-     *  输血开始时间
-     *  输血日期end
-     *  输血结束时间
-     *  输血指征
+     * 全文本
+     * 诊断
+     * 检验结果
+     * 血型
+     * 输注量
+     * 输血开始时间
+     * 输血日期end
+     * 输血结束时间
+     * 输血指征
      */
+    private static List<String> keyContrasts = Lists.newArrayList(
+            "输注量=输血量(mL)",
+            "血型=ABO血型代码"
+    );
 }

+ 43 - 0
trans/src/main/java/com/lantone/qc/trans/beilun/util/ez/util/EzXmlUtil.java

@@ -1,6 +1,7 @@
 package com.lantone.qc.trans.beilun.util.ez.util;
 
 import com.google.common.collect.Maps;
+import com.lantone.qc.dbanaly.facade.yiwu.util.MapUtil;
 import com.lantone.qc.pub.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.dom4j.Attribute;
@@ -9,8 +10,10 @@ import org.dom4j.DocumentHelper;
 import org.dom4j.Element;
 import org.dom4j.Node;
 
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * @Description:
@@ -101,4 +104,44 @@ public class EzXmlUtil {
             return "";
         }
     }
+
+    /**
+     * 根据给定key映射
+     *
+     * @param sourceMap
+     * @param keyContrasts
+     * @return
+     */
+    public static Map<String, String> mapKeyContrast(Map<String, String> sourceMap, List<String> keyContrasts) {
+        Map<String, String> retMap = Maps.newHashMap();
+        mapKeyContrastCommon(sourceMap, keyContrasts, retMap);
+        return retMap;
+    }
+
+    public static void mapKeyContrastCommon(Map sourceMap, List<String> keyContrasts, Map<String, String> retMap) {
+        Map<String, String> sourceMap_ = MapUtil.copyMap(sourceMap);
+        String[] arry = null;
+        String sourceKey = null, targetKey;
+        Set<String> removeKey = new HashSet<>();
+        for (String keyContrast : keyContrasts) {
+            arry = keyContrast.split("=");
+            sourceKey = arry[0];
+            if (arry.length == 1) {
+                targetKey = arry[0];
+            } else {
+                targetKey = arry[1];
+            }
+            if (StringUtil.isNotBlank(sourceMap_.get(sourceKey))
+                    && (!retMap.containsKey(targetKey) || StringUtil.isBlank(retMap.get(targetKey)))) {
+                retMap.put(targetKey, sourceMap_.get(sourceKey));
+            }
+            removeKey.add(sourceKey);
+        }
+        Set<String> keySet = retMap.keySet();
+        for (String key : sourceMap_.keySet()) {
+            if (!keySet.contains(key) && !removeKey.contains(key)) { // 如果之前已放过key就不用放了
+                retMap.put(key, sourceMap_.get(key));
+            }
+        }
+    }
 }