|
@@ -1,5 +1,6 @@
|
|
|
package com.diagbot.util;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.diagbot.enums.data.*;
|
|
@@ -10,10 +11,7 @@ import org.dom4j.Document;
|
|
|
import org.dom4j.DocumentHelper;
|
|
|
import org.dom4j.Element;
|
|
|
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @Description: xml解析工具
|
|
@@ -45,8 +43,8 @@ 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> sourceMap = xmlToMap(xml);
|
|
|
+ Map<String, Object> structureMap = mapKeyContrast(sourceMap, keyContrasts);
|
|
|
newbornAge(structureMap);
|
|
|
Map<String, Object> structureExtMap = Maps.newHashMap();
|
|
|
structureExtMap.putAll(structureMap);
|
|
@@ -57,14 +55,14 @@ public class YiWuFirstPageRecordXmlUtil {
|
|
|
JSONArray operations = new JSONArray();
|
|
|
specialProcess(structureMap, operationMap, operations);
|
|
|
structureExtMap.put("手术信息", operations);
|
|
|
-// structureExtMap = processToValue(structureExtMap);
|
|
|
+ structureExtMap = processToValue(structureExtMap);
|
|
|
return structureExtMap;
|
|
|
}
|
|
|
|
|
|
//新生儿年龄处理
|
|
|
- public static void newbornAge(Map<String, String> structureMap) {
|
|
|
+ public static void newbornAge(Map<String, Object> structureMap) {
|
|
|
if (structureMap != null && structureMap.size() > 0) {
|
|
|
- String text = structureMap.get("原始文本");
|
|
|
+ String text = structureMap.get("原始文本").toString();
|
|
|
boolean containsAgeText = text.contains("年龄 Value1") ? true : text.contains("年龄Value1");
|
|
|
boolean containsWeightText = text.contains("新生儿出生体重");
|
|
|
if (StringUtil.isNotBlank(text) && containsAgeText && containsWeightText) {
|
|
@@ -92,13 +90,15 @@ public class YiWuFirstPageRecordXmlUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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();
|
|
|
+ Map<String, Object> IDsMap = Maps.newHashMap();
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
try {
|
|
|
Document doc = DocumentHelper.parseText(xml);
|
|
|
Element root = (Element) doc.selectSingleNode("//XTextDocument/XElements/Element[@xsi:type='XTextBody']/XElements");
|
|
|
findElement(root, "XInputField").forEach(i -> {
|
|
|
- xInputField(map, i, null);
|
|
|
+ xInputField(map, i, null,IDsMap);
|
|
|
});
|
|
|
findElement(root, "XTextTable").forEach(tableElement -> {
|
|
|
String tablePreTxt = getElementPreVal(tableElement);
|
|
@@ -107,21 +107,27 @@ public class YiWuFirstPageRecordXmlUtil {
|
|
|
List<Element> xTextTable = findElement(cellElement.element("XElements"), "XTextTable");
|
|
|
if (xTextTable.size() > 0) {
|
|
|
xTextTable.forEach(stableElement -> {
|
|
|
+ Element idElement = stableElement.element("ID");
|
|
|
+ String textTrim = "";
|
|
|
+ if (idElement != null) {
|
|
|
+ textTrim = idElement.getTextTrim();
|
|
|
+ }
|
|
|
+ list.add(textTrim);
|
|
|
String stablePreTxt = getElementPreVal(stableElement);
|
|
|
findElement(stableElement.element("XElements"), "XTextTableRow").forEach(srowElement -> {
|
|
|
findElement(srowElement.element("XElements"), "XTextTableCell").forEach(scellElement -> {
|
|
|
findElement(scellElement.element("XElements"), "XInputField").forEach(xInputFieldElement -> {
|
|
|
- xInputField(map, xInputFieldElement, stablePreTxt);
|
|
|
+ xInputField(map, xInputFieldElement, stablePreTxt, IDsMap);
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
} else {
|
|
|
findElement(cellElement.element("XElements"), "XInputField").forEach(xInputFieldElement -> {
|
|
|
- xInputField(map, xInputFieldElement, tablePreTxt);
|
|
|
+ xInputField(map, xInputFieldElement, tablePreTxt, IDsMap);
|
|
|
});
|
|
|
findElement(cellElement.element("XElements"), "XTextRadioBox").forEach(xTextRadioBoxElement -> {
|
|
|
- xInputField(map, xTextRadioBoxElement, tablePreTxt);
|
|
|
+ xInputField(map, xTextRadioBoxElement, tablePreTxt, IDsMap);
|
|
|
});
|
|
|
}
|
|
|
});
|
|
@@ -130,6 +136,7 @@ public class YiWuFirstPageRecordXmlUtil {
|
|
|
Element bodyTextElement = (Element) doc.selectSingleNode("//XTextDocument/BodyText");
|
|
|
String bodyText = bodyTextElement.getText();
|
|
|
map.put("原始文本", bodyText);
|
|
|
+ saveLocationID(map, IDsMap, list);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
map.clear();
|
|
@@ -140,6 +147,22 @@ public class YiWuFirstPageRecordXmlUtil {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ //存储定位ID
|
|
|
+ public static void saveLocationID(Map<String, Object> map, Map<String, Object> IDsMap, List<String> list) {
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ Map<String, Object> structureMap = mapKeyContrast(IDsMap, keyContrasts);
|
|
|
+ if (list.size() > 2) {
|
|
|
+ object.put("诊断", list.get(0));
|
|
|
+ object.put("手术", list.get(1));
|
|
|
+ object.put("重症监护", list.get(2));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map.Entry<String, Object> entry : structureMap.entrySet()) {
|
|
|
+ object.put(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+ map.put("IDs", object);
|
|
|
+ }
|
|
|
+
|
|
|
public static List<Element> findElement(Element element, String attual) {
|
|
|
List<Element> ret = Lists.newArrayList();
|
|
|
((List<Element>) (element.elements())).forEach(i -> {
|
|
@@ -150,7 +173,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, Map<String, Object> IDsMap) {
|
|
|
String value = getXInputFieldValue(xInputFieldElement);
|
|
|
if (value == null) {
|
|
|
return;
|
|
@@ -162,6 +185,28 @@ public class YiWuFirstPageRecordXmlUtil {
|
|
|
}
|
|
|
map.put(key, value);
|
|
|
}
|
|
|
+ Boolean flag = getID(xInputFieldElement, tablePreTxt, IDsMap);
|
|
|
+ if (flag) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Boolean getID(Element xInputFieldElement, String tablePreTxt, Map<String, Object> IDsMap) {
|
|
|
+ String id = "";
|
|
|
+ Element idValueElement = xInputFieldElement.element("ID");
|
|
|
+ Element checkedElement = xInputFieldElement.element("Checked");
|
|
|
+ Element checkedValueElement = xInputFieldElement.element("CheckedValue");
|
|
|
+ if (idValueElement != null) {
|
|
|
+ id = idValueElement.getTextTrim();
|
|
|
+ }
|
|
|
+ String key = getXInputFieldKey(xInputFieldElement, tablePreTxt);
|
|
|
+ if (StringUtil.isNotBlank(key)) {
|
|
|
+ IDsMap.put(key, id);
|
|
|
+ if (checkedElement != null && checkedValueElement != null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
//获取 XInputField 的键
|
|
@@ -254,13 +299,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;
|
|
@@ -274,7 +319,7 @@ public class YiWuFirstPageRecordXmlUtil {
|
|
|
targetKey = arry[1];
|
|
|
}
|
|
|
if (StringUtil.isNotBlank(sourceMap_.get(sourceKey))
|
|
|
- && (!retMap.containsKey(targetKey) || StringUtil.isBlank(retMap.get(targetKey)))) {
|
|
|
+ && (!retMap.containsKey(targetKey) || retMap.get(targetKey) != null)) {
|
|
|
retMap.put(targetKey, sourceMap_.get(sourceKey));
|
|
|
}
|
|
|
removeKey.add(sourceKey);
|
|
@@ -296,13 +341,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) {
|
|
@@ -343,13 +388,16 @@ public class YiWuFirstPageRecordXmlUtil {
|
|
|
while (value.endsWith(" -") || value.endsWith(" -")) {
|
|
|
value = value.substring(0, value.length() - 2);
|
|
|
}
|
|
|
- return value;
|
|
|
+ return value.replace(" -", "");
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
// xmlToMap(FileUtil.fileRead("C:\\Users\\Administrator\\Desktop\\义务\\jiexi\\n5.xml"));
|
|
|
- String xml = "";
|
|
|
+ String xml = FileUtil.fileRead("C:\\Users\\zhangzw\\Desktop\\病案首页xml解析问题\\完整手术解析参考.xml");;
|
|
|
Map<String, Object> ret = process(xml);
|
|
|
+// JSONObject jsonObject = (JSONObject) ret.get("IDs");
|
|
|
+ String jsonStr = JSONObject.toJSONString(ret.get("IDs"));
|
|
|
+ System.out.println(jsonStr);
|
|
|
System.out.println(ret);
|
|
|
}
|
|
|
|