|
@@ -15,15 +15,16 @@ import com.lantone.qc.dbanaly.facade.yiwu.enums.RHEnum;
|
|
|
import com.lantone.qc.dbanaly.facade.yiwu.enums.SexEnum;
|
|
|
import com.lantone.qc.dbanaly.facade.yiwu.util.MapUtil;
|
|
|
import com.lantone.qc.dbanaly.facade.yiwu.util.YWDateUtils;
|
|
|
+import com.lantone.qc.pub.Content;
|
|
|
+import com.lantone.qc.pub.util.FastJsonUtils;
|
|
|
+import com.lantone.qc.pub.util.FileUtil;
|
|
|
import com.lantone.qc.pub.util.StringUtil;
|
|
|
import org.dom4j.Document;
|
|
|
import org.dom4j.DocumentHelper;
|
|
|
import org.dom4j.Element;
|
|
|
+import springfox.documentation.spring.web.json.Json;
|
|
|
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @Description: xml解析工具
|
|
@@ -55,8 +56,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);
|
|
@@ -72,9 +73,9 @@ public class YiWuFirstPageRecordXmlUtil {
|
|
|
}
|
|
|
|
|
|
//新生儿年龄处理
|
|
|
- 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();
|
|
|
if (StringUtil.isNotBlank(text) && text.contains("年龄 Value1") && text.contains("新生儿出生体重克")) {
|
|
|
String substring = text.substring(text.indexOf("年龄 Value1"), text.indexOf("新生儿出生体重克"));
|
|
|
String[] split = substring.split(",");
|
|
@@ -90,13 +91,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);
|
|
@@ -105,21 +108,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);
|
|
|
});
|
|
|
}
|
|
|
});
|
|
@@ -128,6 +137,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();
|
|
@@ -138,6 +148,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 -> {
|
|
@@ -148,7 +174,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;
|
|
@@ -160,12 +186,34 @@ 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 的键
|
|
|
private static String getXInputFieldKey(Element xInputFieldElement, String tablePreTxt) {
|
|
|
String key = null;
|
|
|
- String[] elementNames = { "Name", "BackgroundText", "ToolTip" };
|
|
|
+ String[] elementNames = {"Name", "BackgroundText", "ToolTip"};
|
|
|
for (String elementName : elementNames) {
|
|
|
key = xInputFieldElement.elementTextTrim(elementName);
|
|
|
if (StringUtil.isNotBlank(key)) {
|
|
@@ -252,13 +300,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;
|
|
@@ -272,7 +320,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);
|
|
@@ -294,13 +342,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) {
|
|
@@ -311,7 +359,7 @@ public class YiWuFirstPageRecordXmlUtil {
|
|
|
}
|
|
|
} else {
|
|
|
boolean flag = false;
|
|
|
- if ("诊断类型".equals(entry.getKey()) && values[0].contains("诊断")) {
|
|
|
+ if ("诊断类型".equals(entry.getKey()) && values[0].contains("诊断") && array.size() > 0) {
|
|
|
array.getJSONObject(0).put("诊断类别", values[0].replace(":", ""));
|
|
|
flag = true;
|
|
|
}
|
|
@@ -341,13 +389,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\\lantone\\Desktop\\病案首页xml解析问题\\病案首页xml解析问题\\出院诊断和实习医师未解析成功.xml");
|
|
|
+// String xml = "";
|
|
|
Map<String, Object> ret = process(xml);
|
|
|
+ String iDs = ret.get("IDs").toString();
|
|
|
+ ret.put("IDs", FastJsonUtils.getJsonToBean(iDs, Object.class));
|
|
|
System.out.println(ret);
|
|
|
}
|
|
|
|
|
@@ -459,7 +510,9 @@ public class YiWuFirstPageRecordXmlUtil {
|
|
|
"科主任222=科主任",
|
|
|
"实习医师=实习医师",
|
|
|
"国籍=国籍",
|
|
|
- "工作单位邮政编码=工作单位邮编"
|
|
|
+ "工作单位邮政编码=工作单位邮编",
|
|
|
+ "进修医师=进修医师",
|
|
|
+ "出院主要诊断=出院诊断"
|
|
|
);
|
|
|
|
|
|
public static Map<String, Object> processToValue(Map<String, Object> map) {
|