Browse Source

义乌病案首页xml解析修改出参

hujing 4 năm trước cách đây
mục cha
commit
406d1b445f

+ 42 - 16
dbanaly/src/main/java/com/lantone/qc/dbanaly/facade/yiwu/YiWuFirstPageRecordXmlUtil.java

@@ -45,22 +45,27 @@ public class YiWuFirstPageRecordXmlUtil {
             .build();
 
     public static Map<String, Object> process(String xml) {
-        Map<String, String> sourceMap = xmlToMap(xml);
-        Map<String, String> structureMap = mapKeyContrast(sourceMap, keyContrasts);
-        Map<String, Object> structureExtMap = Maps.newHashMap();
-        structureExtMap.putAll(structureMap);
+        Map<String, Object> sourceMap = xmlToMap(xml);
+        Map<String, Object> structureMap = mapKeyContrast(sourceMap, keyContrasts);
         JSONArray leaveDiags = new JSONArray();
         specialProcess(structureMap, leaveDiagMap, leaveDiags);
-        structureExtMap.put("出院诊断", leaveDiags);
+        structureMap.put("出院诊断", leaveDiags);
 
         JSONArray operations = new JSONArray();
         specialProcess(structureMap, operationMap, operations);
-        structureExtMap.put("手术信息", operations);
-        return structureExtMap;
+        structureMap.put("手术信息", operations);
+        if (structureMap.containsKey("ID编号")){
+            Map<String, Object> idMap = (Map<String, Object>) structureMap.get("ID编号");
+            idMap.put("出院诊断", "出院诊断_table3");
+            idMap.put("手术信息", "手术信息_table3");
+            idMap = mapKeyContrast(idMap, keyContrasts);
+            structureMap.put("ID编号",idMap);
+        }
+        return structureMap;
     }
 
-    public static Map<String, String> xmlToMap(String xml) {
-        Map<String, String> map = Maps.newHashMap();
+    public static Map<String, Object> xmlToMap(String xml) {
+        Map<String, Object> map = Maps.newHashMap();
         try {
             Document doc = DocumentHelper.parseText(xml);
             Element root = (Element) doc.selectSingleNode("//XTextDocument/XElements/Element[@xsi:type='XTextBody']/XElements");
@@ -114,7 +119,7 @@ public class YiWuFirstPageRecordXmlUtil {
         return ret;
     }
 
-    public static void xInputField(Map<String, String> map, Element xInputFieldElement, String tablePreTxt) {
+    public static void xInputField(Map<String, Object> map, Element xInputFieldElement, String tablePreTxt) {
         String value = getXInputFieldValue(xInputFieldElement);
         if (value == null) {
             return;
@@ -125,6 +130,17 @@ public class YiWuFirstPageRecordXmlUtil {
                 value = map.get(key) + " " + value;
             }
             map.put(key, value);
+            String id = getXInputFieldId(xInputFieldElement);
+            if (StringUtil.isNotBlank(id)) {
+                if (!map.containsKey("ID编号")) {
+                    Map<String, String> idValue = Maps.newHashMap();
+                    idValue.put(key, id);
+                    map.put("ID编号", idValue);
+                } else {
+                    //id唯一,所以不用做if判断key是否存在
+                    ((Map<String, String>) map.get("ID编号")).put(key, id);
+                }
+            }
         }
     }
 
@@ -184,6 +200,16 @@ public class YiWuFirstPageRecordXmlUtil {
         return value;
     }
 
+    //获取 XInputField 的值
+    private static String getXInputFieldId(Element xInputFieldElement) {
+        String value = "";
+        Element idElement = xInputFieldElement.element("ID");
+        if (idElement != null) {
+            value = idElement.getTextTrim();
+        }
+        return value;
+    }
+
     //获取前面文本信息作为key
     private static String getElementPreVal(Element xInputFieldElement) {
         String ret = "";
@@ -214,13 +240,13 @@ public class YiWuFirstPageRecordXmlUtil {
      * @param keyContrasts
      * @return
      */
-    public static Map<String, String> mapKeyContrast(Map<String, String> sourceMap, List<String> keyContrasts) {
-        Map<String, String> retMap = Maps.newHashMap();
+    public static Map<String, Object> mapKeyContrast(Map<String, Object> sourceMap, List<String> keyContrasts) {
+        Map<String, Object> retMap = Maps.newHashMap();
         mapKeyContrastCommon(sourceMap, keyContrasts, retMap);
         return retMap;
     }
 
-    public static void mapKeyContrastCommon(Map sourceMap, List<String> keyContrasts, Map<String, String> retMap) {
+    public static void mapKeyContrastCommon(Map sourceMap, List<String> keyContrasts, Map<String, Object> retMap) {
         Map<String, String> sourceMap_ = MapUtil.copyMap(sourceMap);
         String[] arry = null;
         String sourceKey = null, targetKey;
@@ -234,7 +260,7 @@ public class YiWuFirstPageRecordXmlUtil {
                 targetKey = arry[1];
             }
             if (StringUtil.isNotBlank(sourceMap_.get(sourceKey))
-                    && (!retMap.containsKey(targetKey) || StringUtil.isBlank(retMap.get(targetKey)))) {
+                    && (!retMap.containsKey(targetKey) || StringUtil.isBlank(retMap.get(targetKey).toString()))) {
                 retMap.put(targetKey, sourceMap_.get(sourceKey));
             }
             removeKey.add(sourceKey);
@@ -256,13 +282,13 @@ public class YiWuFirstPageRecordXmlUtil {
      * @param leaveDiagMap
      * @param array
      */
-    public static void specialProcess(Map<String, String> structureMap, Map<String, String> leaveDiagMap, JSONArray array) {
+    public static void specialProcess(Map<String, Object> structureMap, Map<String, String> leaveDiagMap, JSONArray array) {
         JSONObject object;
         int num = 0;
         try {
             for (Map.Entry<String, String> entry : leaveDiagMap.entrySet()) {
                 if (structureMap.containsKey(entry.getKey())) {
-                    String value = structureMap.get(entry.getKey());
+                    String value = structureMap.get(entry.getKey()).toString();
                     value = removeUseless(value);
                     String[] values = value.split(" ");
                     if (num == 0) {