Browse Source

恩泽修改

rengb 4 years ago
parent
commit
3ada5e1da4

+ 184 - 0
trans/src/main/java/com/lantone/qc/trans/beilun/util/ez/EzXmlAnalysis.java

@@ -0,0 +1,184 @@
+package com.lantone.qc.trans.beilun.util.ez;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.lantone.qc.pub.util.StringUtil;
+import com.lantone.qc.trans.beilun.util.CommonAnalysisUtil;
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.Node;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @Description:
+ * @author: rengb
+ * @time: 2020/9/24 11:28
+ */
+public class EzXmlAnalysis {
+
+    public static Map<String, String> analysis(String deptName, String xml) throws Exception {
+        if (deptName.equals("小儿外科")) {
+            return analysisEk(deptName, xml);
+        }
+        return null;
+    }
+
+    public static Map<String, String> analysisEk(String deptName, String xml) throws Exception {
+        Map<String, String> map = Maps.newLinkedHashMap();
+        Document doc = DocumentHelper.parseText(xml);
+        Element rootElement = doc.getRootElement();
+        jbxxInsertMap(rootElement, map);
+        tgjcInsertMap(rootElement, map);
+        fzjcInsertMap(rootElement, map);
+        zkjcInsertMap(rootElement, map);
+        disInsertMap(rootElement, map);
+        otherInsertMap(rootElement, map);
+        return map;
+    }
+
+    //其他信息
+    public static void otherInsertMap(Element rootElement, Map<String, String> map) {
+        List<String> titles = Lists.newArrayList(
+                "主诉", "现病史", "既往史", "手术史", "输血史", "过敏史", "个人史", "预防接种史", "家族史", "婚育史", "月经史"
+        );
+
+        String rootText = elementTxt(rootElement);
+        titles = CommonAnalysisUtil.sortTitles(titles, rootText);
+        CommonAnalysisUtil.cutByTitles(rootText, titles, 0, map);
+    }
+
+    public static void disInsertMap(Element rootElement, Map<String, String> map) {
+        Node cbzdNode = rootElement.selectSingleNode("section[@name='初步诊断']");
+        if (cbzdNode != null) {
+            rootElement.remove(cbzdNode);
+        }
+        Node disNode = rootElement.selectSingleNode("section[@name='诊断']");
+        if (disNode != null) {
+            String disText = elementTxt(disNode);
+            List<String> titles = CommonAnalysisUtil.sortTitles(Lists.newArrayList("初步诊断", "补充诊断", "修正诊断", "出院诊断"), disText);
+            CommonAnalysisUtil.cutByTitles(disText, titles, 0, map);
+            titles.forEach(title -> {
+                disExt(map, title);
+            });
+            rootElement.remove(disNode);
+        }
+    }
+
+    //诊断特殊处理
+    public static void disExt(Map<String, String> map, String key) {
+        String disMessage = map.get(key);
+        String sign = null;
+        String signTime = null;
+        int signIndex = 0;
+        if (StringUtil.isNotBlank(disMessage)) {
+            Pattern pattern = Pattern.compile("[0-9]+[年/-][0-9]+[月/-][0-9]+[日]{0,}");
+            Matcher matcher = pattern.matcher(disMessage);
+            if (matcher.find()) {
+                signTime = matcher.group();
+                disMessage = disMessage.substring(0, matcher.start());
+            }
+
+            signIndex = disMessage.indexOf("医师签名");
+            if (signIndex > -1) {
+                sign = disMessage.substring(signIndex).replace("医师签名", "").replaceAll("[::]", "");
+                disMessage = disMessage.substring(0, signIndex);
+            }
+            map.put(key, disMessage);
+            if (StringUtil.isNotBlank(sign)) {
+                map.put(key + "签名", sign);
+            }
+            if (StringUtil.isNotBlank(signTime)) {
+                map.put(key + "签名日期", signTime);
+            }
+        }
+    }
+
+    //辅助检查
+    public static void fzjcInsertMap(Element rootElement, Map<String, String> map) {
+        Node fzjcNode = rootElement.selectSingleNode("section[@name='辅助检查']");
+        if (fzjcNode != null) {
+            map.put("辅助检查", elementTxt(fzjcNode).replaceFirst("辅助检查", ""));
+            rootElement.remove(fzjcNode);
+        }
+    }
+
+    // 专科检查
+    public static void zkjcInsertMap(Element rootElement, Map<String, String> map) {
+        Node zkjcNode = rootElement.selectSingleNode("section[@name='专科检查']");
+        if (zkjcNode != null) {
+            map.put("专科检查", elementTxt(zkjcNode).replaceFirst("专科检查", ""));
+            rootElement.remove(zkjcNode);
+        }
+    }
+
+    //基本信息
+    public static void jbxxInsertMap(Element rootElement, Map<String, String> map) {
+        Node jbxxNode = rootElement.selectSingleNode("section[@name='基本信息']");
+        if (jbxxNode != null) {
+            ((List<Element>) jbxxNode.selectNodes("fieldelem")).forEach(i -> {
+                elementInsertMap(i, map);
+            });
+            rootElement.remove(jbxxNode);
+        }
+    }
+
+    //体格检查
+    public static void tgjcInsertMap(Element rootElement, Map<String, String> map) {
+        Node tgjcNode = rootElement.selectSingleNode("section[@name='体格检查']");
+        if (tgjcNode != null) {
+            Node smtzNode = tgjcNode.selectSingleNode("section[@name='生命体征']");
+            if (smtzNode != null) {
+                ((List<Element>) smtzNode.selectNodes("fieldelem")).forEach(i -> {
+                    elementInsertMap(i, map);
+                });
+            }
+            ((List<Element>) tgjcNode.selectNodes("section[@name!='生命体征']")).forEach(i -> {
+                elementInsertMap(i, map);
+            });
+            rootElement.remove(tgjcNode);
+        }
+    }
+
+    public static String elementTxt(Node node) {
+        if (node != null) {
+            return StringUtil.removeBlank(node.getStringValue());
+        } else {
+            return "";
+        }
+    }
+
+    public static void elementInsertMap(Element element, Map<String, String> map) {
+        if (element == null || map == null) {
+            return;
+        }
+        String key = null;
+        List<Element> elements = element.elements();
+        if (elements.size() > 0 && (key = isKey(elementTxt(elements.get(0)))) != null) {
+            element.remove(elements.get(0));
+        } else {
+            key = element.attributeValue("name");
+        }
+        if (StringUtil.isNotBlank(key)) {
+            map.put(key, elementTxt(element));
+        }
+    }
+
+    public static String isKey(String key) {
+        if (StringUtil.isBlank(key)) {
+            return null;
+        }
+        key = StringUtil.removeBlank(key);
+        Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]+[::]");
+        if (pattern.matcher(key).matches()) {
+            return key.substring(0, key.length() - 1);
+        } else {
+            return null;
+        }
+    }
+
+}