瀏覽代碼

转化修改

rengb 4 年之前
父節點
當前提交
aada2ddb34

+ 182 - 19
common/src/main/java/com/lantone/common/util/StringUtil.java

@@ -4,7 +4,12 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateUtils;
 
 import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * @Description: 字符串有关帮助类 封装了第三方帮助类
@@ -53,14 +58,16 @@ public class StringUtil {
     }
 
     /**
-     * 判断两个字符串是否相同
+     * 删除字符串中的换行和控制字符
      *
-     * @param arg1
-     * @param arg2
-     * @return
+     * @param str
      */
-    public static boolean equals(String arg1, String arg2) {
-        return StringUtils.equals(arg1, arg2);
+    public static String remove_ctl(String str) {
+        String trim = "";
+        if (StringUtils.isNotEmpty(str)) {
+            trim = str.replaceAll("\r|\n|\r\n|/r/n", "").trim();
+        }
+        return trim;
     }
 
     /**
@@ -73,16 +80,134 @@ public class StringUtil {
         if (isBlank(str)) {
             return str;
         }
-        return str.replaceAll("[\\s\\p{Zs}]", "");
+        return str.replaceAll("[\\s\\p{Zs}]", "").replaceAll(" ", "");
+    }
+
+    /**
+     * 比较两个列表的内容
+     */
+    public static List<String> compareList(List<String> A, List<String> B) {
+        List<String> res = new ArrayList<>();
+
+        for (String i : A) {
+            if (!B.contains(i)) {
+                res.add(i);
+            }
+        }
+
+        for (String j : B) {
+            if (!A.contains(j)) {
+                res.add(j);
+            }
+        }
+
+        return res;
+    }
+
+    /**
+     * 列表A是否包含列表B
+     */
+    public static boolean containList(List<String> A, List<String> B) {
+        boolean res = true;
+
+        try {
+            for (String item : B) {
+                if (!A.contains(item)) {
+                    res = false;
+                    break;
+                }
+            }
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        } finally {
+            return res;
+        }
+    }
+
+    /**
+     * 比较两个字符串集合是否一模一样:个数一样、顺序一样
+     *
+     * @param source
+     * @param target
+     * @return
+     */
+    public static boolean isEqually(List<String> source, List<String> target) {
+        boolean ret = false;
+        if (ListUtil.isNotEmpty(source) && ListUtil.isNotEmpty(target)) {
+            String[] sourceArray = source.toArray(new String[] {});
+            String[] targetArray = target.toArray(new String[] {});
+            ret = Arrays.equals(sourceArray, targetArray);
+        }
+        return ret;
+    }
+
+    /**
+     * 判断字符串是否包含数字
+     *
+     * @param company
+     * @return
+     */
+    public static boolean isContainNumber(String company) {
+        Pattern p = Pattern.compile("[0-9]");
+        Matcher m = p.matcher(company);
+        if (m.find()) {
+            return true;
+        }
+        return false;
     }
 
     /**
-     * 解析时间
+     * 标点符号空格等转逗号分割
+     *
+     * @param content
+     * @return
+     */
+    public static String specialCharComma(String content) {
+        if (StringUtil.isNotBlank(content)) {
+            content = content.replaceAll("(\\d+)|[、,。.;;??]", " ").replaceAll("(\\s+)", ",");
+            if (content.indexOf(",") == 0) {
+                content = content.substring(1);
+            }
+            if (content.lastIndexOf(",") == content.length() - 1) {
+                content = content.substring(0, content.length() - 1);
+            }
+        }
+        return content;
+    }
+
+    /**
+     * 判断两个字符串是否相同
+     *
+     * @param arg1
+     * @param arg2
+     * @return
+     */
+    public static boolean equals(String arg1, String arg2) {
+        return StringUtils.equals(arg1, arg2);
+    }
+
+    /**
+     * 比较两个字符串集合是否内容一样,即A包含B,B包含A,交集为空
+     * 个数、顺序不考虑
+     *
+     * @param source
+     * @param target
+     * @return
+     */
+    //    public static boolean isSameContent(List<String> source, List<String> target) {
+    //        Set<String> sourceSet = Sets.newHashSet(source);
+    //        Set<String> targetSet = Sets.newHashSet(target);
+    //        return Sets.difference(sourceSet, targetSet).isEmpty() && Sets.difference(targetSet, sourceSet).isEmpty();
+    //    }
+
+
+    /**
+     * 根据给定的时间格式解析时间
      *
      * @param datetime
      * @return
      */
-    public static Date parseDateTime(String datetime) {
+    public static Date parseDateTime(String datetime, String[] dateFormats) {
         Date date = null;
         try {
             datetime = remove_ctl(datetime);
@@ -90,27 +215,65 @@ public class StringUtil {
             if (datetime.contains("至")) {
                 datetime = datetime.split("至")[1].replaceAll("[\\u4e00-\\u9fa5]", "");
             }
-
             if (datetime.length() > 0) {
-                date = DateUtils.parseDate(datetime, DateUtil.dateFormats);
+                date = DateUtils.parseDate(datetime, dateFormats);
             }
         } catch (ParseException ex) {
             ex.printStackTrace();
+        } finally {
+            return date;
+        }
+    }
+
+    public static String matRegx(String source, String regex1, String regex2, String val) {
+        if (isNotBlank(source) && isNotBlank(regex1) && isNotBlank(regex2)) {
+            Pattern pattern = Pattern.compile(regex1);
+            Matcher matcher = pattern.matcher(source);
+            if (matcher.find()) {
+                String sce1 = matcher.group();
+                if (isBlank(val) || !sce1.contains(val)) {
+                    String sce2 = sce1.replaceAll(regex2, val);
+                    source = source.replaceAll(sce1, sce2);
+                }
+            }
         }
-        return date;
+        return source;
     }
 
     /**
-     * 删除字符串中的换行和控制字符
+     * 去除字符串两边空白 包含一些特殊空格
      *
-     * @param str
+     * @param msg
+     * @return
      */
-    public static String remove_ctl(String str) {
-        String trim = "";
-        if(StringUtils.isNotEmpty(str)){
-            trim = str.replaceAll("\r|\n|\r\n|/r/n", "").trim();
+    public static String trim(String msg) {
+        if (isNotBlank(msg)) {
+            return org.springframework.util.StringUtils.trimWhitespace(msg).trim();
         }
-        return trim;
+        return msg;
+    }
+
+    /**
+     * 去掉尾部几位符合字符
+     *
+     * @param value
+     * @param regex
+     * @param len
+     * @return
+     */
+    public static String removeWN(String value, String regex, int len) {
+        String ret = value;
+        if (StringUtil.isNotBlank(value) && value.length() >= len) {
+            String endStr = null;
+            for (int i = len; i > 0; i--) {
+                endStr = value.substring(value.length() - len);
+                if (endStr.replaceAll(regex, "").length() == 0) {
+                    ret = value.substring(0, value.length() - len);
+                    break;
+                }
+            }
+        }
+        return ret;
     }
 
 }

+ 1 - 1
structure-center/src/main/java/com/lantone/structure/dto/AnalysisDTO.java

@@ -7,6 +7,6 @@ import java.util.Map;
 @Data
 public class AnalysisDTO {
 
-    private Map<String, Object> result;
+    private Map<String, String> result;
 
 }

+ 12 - 343
structure-center/src/main/java/com/lantone/structure/facade/StructureFacade.java

@@ -1,28 +1,18 @@
 package com.lantone.structure.facade;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONException;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.google.common.collect.ObjectArrays;
-import com.lantone.common.util.FastJsonUtils;
-import com.lantone.common.util.StringUtil;
-import com.lantone.structure.ai.AIAnalyze;
 import com.lantone.structure.client.CRFServiceClient;
 import com.lantone.structure.client.SimilarityServiceClient;
 import com.lantone.structure.dto.AnalysisDTO;
-import com.lantone.structure.model.InputInfo;
-import com.lantone.structure.model.doc.*;
+import com.lantone.structure.facade.tran.CesareanSectionTran;
+import com.lantone.structure.facade.tran.ClinicalBloodTran;
+import com.lantone.structure.facade.tran.RescueTran;
+import com.lantone.structure.facade.tran.StagesSummaryTran;
+import com.lantone.structure.facade.tran.TargetTran;
 import com.lantone.structure.vo.AnalysisVO;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections.map.HashedMap;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.*;
-
 /**
  * @Description:
  * @author: rengb
@@ -38,347 +28,26 @@ public class StructureFacade {
 
 
     public AnalysisDTO analysis(AnalysisVO analysisVO) {
-        InputInfo inputInfo = new InputInfo();
+        AnalysisDTO analysisDTO = new AnalysisDTO();
+        TargetTran targetTran = null;
         switch (analysisVO.getType()) {
             case "剖宫产手术":
-                List<CaesareanSectionDoc> caesareanSectionDocList = new ArrayList<>();
-                CaesareanSectionDoc caesareanSectionDoc = new CaesareanSectionDoc();
-                caesareanSectionDoc.setText(analysisVO.getText());
-                caesareanSectionDocList.add(caesareanSectionDoc);
-                inputInfo.setCaesareanSectionDocs(caesareanSectionDocList);
+                targetTran = new CesareanSectionTran();
                 break;
             case "输血记录":
-                List<ClinicalBloodDoc> clinicalBloodDocList = new ArrayList<>();
-                ClinicalBloodDoc clinicalBloodDoc = new ClinicalBloodDoc();
-                clinicalBloodDoc.setText(analysisVO.getText());
-                clinicalBloodDocList.add(clinicalBloodDoc);
-                inputInfo.setClinicalBloodDocs(clinicalBloodDocList);
+                targetTran = new ClinicalBloodTran();
                 break;
             case "抢救记录":
-                List<RescueDoc> rescueDocList = new ArrayList<>();
-                RescueDoc rescueDoc = new RescueDoc();
-                rescueDoc.setText(analysisVO.getText());
-                rescueDocList.add(rescueDoc);
-                inputInfo.setRescueDocs(rescueDocList);
+                targetTran = new RescueTran();
                 break;
             case "阶段小结":
-                List<StagesSummaryDoc> stagesSummaryDocList = new ArrayList<>();
-                StagesSummaryDoc stagesSummaryDoc = new StagesSummaryDoc();
-                stagesSummaryDoc.setText(analysisVO.getText());
-                stagesSummaryDocList.add(stagesSummaryDoc);
-                inputInfo.setStagesSummaryDocs(stagesSummaryDocList);
+                targetTran = new StagesSummaryTran();
                 break;
             default:
                 break;
         }
-
-        AIAnalyze aiAnalyze = new AIAnalyze(crfServiceClient, similarityServiceClient);
-        try {
-            aiAnalyze.aiProcess(inputInfo);
-        } catch (Exception e) {
-            log.error("AI模型执行错误:" + e.getMessage(), e);
-        }
-
-        //存储映射
-        AnalysisDTO analysisDTO = saveMap(inputInfo, analysisVO);
-        return analysisDTO;
-    }
-
-    public AnalysisDTO saveMap(InputInfo inputInfo, AnalysisVO analysisVO) {
-        Map<String, Object> map = Maps.newHashMap();
-        Map<String, String> retMap = new HashMap<>();
-        Map<String, String> structureMap = new HashMap<>();
-        AnalysisDTO analysisDTO = new AnalysisDTO();
-        Map<String, String> keyContrastMap = Maps.newHashMap();
-        if (analysisVO.getType().equals("剖宫产手术")) {
-            Map<String, Object> jsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(inputInfo.getCaesareanSectionDocs().get(0).getCaesareanSectionLabel()));
-            //添加keyContrastMap数据
-            AddKeyValue(keyContrastMap, sectionKeyContrasts);
-            mapKeyContrastCommon(jsonMap, keyContrastMap, retMap);
-            replaceMapping(retMap,ezSectionMaps,structureMap);
-        } else if (analysisVO.getType().equals("输血记录")) {
-            Map<String, Object> jsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(inputInfo.getClinicalBloodDocs().get(0).getClinicalBloodLabel()));
-            AddKeyValue(keyContrastMap, bloodKeyContrasts);
-            bloodKeyContrastCommon(jsonMap, keyContrastMap, structureMap);
-        } else if (analysisVO.getType().equals("抢救记录")) {
-            Map<String, Object> jsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(inputInfo.getRescueDocs().get(0).getRescueLabel()));
-          //  AddKeyValue(keyContrastMap, rescueContrasts);
-            mapKeyContrastCommon(jsonMap, keyContrastMap, retMap);
-        } else if (analysisVO.getType().equals("阶段小结")) {
-            Map<String, Object> jsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(inputInfo.getStagesSummaryDocs().get(0).getStagesSummaryLabel()));
-            mapKeyContrastCommon(jsonMap, keyContrastMap, retMap);
-        }
-        map.put(analysisVO.getType(), structureMap);
-        analysisDTO.setResult(map);
-
+        analysisDTO.setResult(targetTran.convert(analysisVO.getText()));
         return analysisDTO;
     }
 
-    public void AddKeyValue(Map<String, String> keyContrastMap, List<String> keyContrasts) {
-        for (String keyContrast : keyContrasts) {
-            String[] split = keyContrast.split("=");
-            keyContrastMap.put(split[0], split[1]);
-
-        }
-    }
-
-    private List<String> sectionKeyContrasts = Lists.newArrayList(
-            "bloodPressure=血压情况",
-            "caputSuccedaneum=产瘤",
-            "drugs=手术用药名称",
-            "puerperaCondition=手术时产妇情况",
-            "amnioticFluid=羊水",
-            "diagnosis=诊断名称",
-            "anesthesiaMethod=麻醉方法",
-            "transfusion=输血成分",
-            "newborn=新生儿",
-            "fluidInfusion=补液",
-            "uCAgents=宫缩剂名称",
-            "uterineWallSutures=子宫壁缝合情况",
-            "childbirthConditions=胎盘娩出情况",
-            "uterusConditions=子宫情况",
-            "childbirthWay=胎儿娩出方式",
-            "cordAroundNeck=脐带绕颈",
-            "apgarScores=Apgar评分",
-            "placenta=胎盘",
-            "uterineCavityDispose=宫腔探查处理情况",
-            "cordAroundBody=脐带绕身",
-            "umbilicalCord=脐带",
-            "uterineCavityAbnormity=宫腔探查异常情况描述",
-            "hemorrhage=术中出血",
-            "amnioticFluidCharacter=羊水性状",
-            "quantity=量",
-            "volume=体积",
-            "weight=重量",
-            "extent=长度",
-            "negative=否定",
-            "cylinderNumber=圈数",
-            "usageWardRound=宫缩剂用法",
-            "consumption=宫缩剂用量",
-            "score=分数",
-            "caputSuccedaneumPart=产瘤部位"
-    );
-
-
-    private List<String> bloodKeyContrasts = Lists.newArrayList(
-            "reason=输血原因",
-            "responseType=输血反应类型",
-            "indication=输血指征",
-            "type=输血类型",
-            "startTime=输血开始时间",
-            "endTime=输血结束时间",
-            "当前诊断=死亡诊断",
-            "死亡日期=死亡时间",
-            "初步诊断=入院诊断",
-            "诊治经过=诊疗经过",
-            "现病史- 发病情况=发病情况",
-            "本人姓名=姓名",
-            "病历日期=记录时间",
-            "医生=记录医师"
-    );
-
-    private List<String> rescueContrasts = Lists.newArrayList(
-            "auxiliaryTest=检查/检验项目名称",
-            "interventions=介入物名称",
-            "operations=手术及操作名称",
-            //无对应
-            "drugs=抢救药品",
-            "methods=操作方法",
-            "diagnosis=疾病诊断名称",
-            //无对应
-            "conditions=抢救病情"
-
-
-
-    );
-
-    private List<String> stagesContrasts = Lists.newArrayList(
-
-    );
-
-
-    public void mapKeyContrastCommon(Map sourceMap, Map<String, String> keyContrastMap, Map<String, String> retMap) {
-        Map<String, Object> sourceMap_ = copyMap(sourceMap);
-        for (Map.Entry<String, Object> dateEntry : sourceMap_.entrySet()) {
-            try {
-                Object object = JSON.parse(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
-                if (object instanceof JSONObject) {
-                    Map<String, Object> firstJsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
-                    if (firstJsonMap.size() == 1) {
-                        String key = keyContrastMap.get(dateEntry.getKey());
-                        retMap.put(key, (String) firstJsonMap.get("name"));
-                    } else {
-                        for (Map.Entry<String, Object> firstDateEntry : firstJsonMap.entrySet()) {
-                            Map<String, Object> jsonToMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(firstDateEntry.getValue()));
-                            if (jsonToMap.size() == 1) {
-                                String childKey = keyContrastMap.get(firstDateEntry.getKey());
-                                if (retMap.containsKey(keyContrastMap.get(firstDateEntry.getKey()))) {
-                                    retMap.put(keyContrastMap.get(dateEntry.getKey()) + childKey, (String) jsonToMap.get("name"));
-                                } else {
-                                    retMap.put(childKey, (String) jsonToMap.get("name"));
-                                }
-                            }
-                        }
-                    }
-                } else if (object instanceof JSONArray) {
-                    List<Map<String, Object>> jsonToListMap = FastJsonUtils.getJsonToListMap(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
-                    int count = 1;
-                    StringBuffer sb = new StringBuffer();
-                    for (Map<String, Object> mapList : jsonToListMap) {
-                        for (Map.Entry<String, Object> firstDateEntry : mapList.entrySet()) {
-                            if (firstDateEntry.getKey().equals("name")) {
-                                break;
-                            }
-                            Map<String, Object> jsonToMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(firstDateEntry.getValue()));
-                            if (jsonToMap.size() == 1) {
-                                String childKey = keyContrastMap.get(firstDateEntry.getKey());
-                                if (retMap.containsKey(keyContrastMap.get(firstDateEntry.getKey()))) {
-                                    retMap.put(keyContrastMap.get(dateEntry.getKey()) + childKey, (String) jsonToMap.get("name"));
-                                } else {
-                                    retMap.put(childKey, (String) jsonToMap.get("name"));
-                                }
-                            }
-                        }
-                        sb.append((count++) + "." + mapList.get("name"));
-                    }
-                    retMap.put(keyContrastMap.get(dateEntry.getKey()), sb.toString());
-                }
-
-            } catch (JSONException e) {
-                log.error(keyContrastMap.get(dateEntry.getKey()) + "json为空");
-            }
-        }
-    }
-
-    public void bloodKeyContrastCommon(Map sourceMap, Map<String, String> keyContrastMap, Map<String, String> retMap) {
-        Map<String, Object> sourceMap_ = copyMap(sourceMap);
-        for (Map.Entry<String, Object> dateEntry : sourceMap_.entrySet()) {
-            try {
-                Object object = JSON.parse(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
-                if (object instanceof JSONObject) {
-                    Map<String, Object> firstJsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
-                    if (firstJsonMap.size() == 1) {
-                        String key = keyContrastMap.get(dateEntry.getKey());
-                        retMap.put(key, (String) firstJsonMap.get("name"));
-                    } else {
-                        StringBuffer sbX = new StringBuffer();
-                        for (Map.Entry<String, Object> firstDateEntry : firstJsonMap.entrySet()) {
-                            String beanToJson = FastJsonUtils.getBeanToJson( firstDateEntry.getValue());
-                            if(beanToJson.contains("name")||beanToJson.contains("measurementUnit")){
-                                Map<String, Object> jsonToMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(firstDateEntry.getValue()));
-                                if (jsonToMap.size() == 1) {
-                                    String childKey = keyContrastMap.get(firstDateEntry.getKey());
-                                    if (retMap.containsKey(keyContrastMap.get(firstDateEntry.getKey()))) {
-                                        retMap.put(keyContrastMap.get(dateEntry.getKey()) + childKey, (String) jsonToMap.get("name"));
-                                    } else {
-                                        retMap.put(childKey, (String) jsonToMap.get("name"));
-                                    }
-                                }else{
-                                    for (Map.Entry<String, Object> typeObjectEntry : jsonToMap.entrySet()) {
-                                        Object value = typeObjectEntry.getValue();
-                                        if(value instanceof JSONObject){
-                                            Map<String, Object> objToMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(value));
-                                            sbX.append(objToMap.get("name"));
-                                        }else{
-                                            sbX.append( jsonToMap.get("name"));
-                                        }
-
-                                    }
-                                }
-                            }else{
-                                sbX.append(firstDateEntry.getValue());
-                            }
-                            retMap.put(keyContrastMap.get(dateEntry.getKey()),sbX.toString());
-                        }
-
-                    }
-                } else if (object instanceof JSONArray) {
-                    List<Map<String, Object>> jsonToListMap = FastJsonUtils.getJsonToListMap(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
-                    int count = 1;
-                    StringBuffer sb = new StringBuffer();
-                    if(jsonToListMap.size()==1){
-                        Object name = jsonToListMap.get(0).get("name");
-                        retMap.put(keyContrastMap.get(dateEntry.getKey()),String.valueOf(name));
-                    }else{
-                    for (Map<String, Object> mapList : jsonToListMap) {
-                        for (Map.Entry<String, Object> stringObjectEntry : mapList.entrySet()) {
-                            if(stringObjectEntry.getKey()=="negative"){
-                                Map<String, Object> negativeJsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(stringObjectEntry.getValue()));
-                                Object negativeObject = negativeJsonMap.get("name");
-                                sb.append((count++) + "." +(negativeObject==null? "":negativeObject));
-                            }else if(stringObjectEntry.getKey()=="name"){
-                                sb.append(stringObjectEntry.getValue());
-                            }
-                        }
-                    }
-                        retMap.put(keyContrastMap.get(dateEntry.getKey()), sb.toString());
-                  }
-
-                }
-
-            } catch (JSONException e) {
-                log.error(keyContrastMap.get(dateEntry.getKey()) + "json为空");
-            }
-        }
-    }
-
-    public void replaceMapping(Map sourceMap, List<String> keyContrasts, Map<String, String> retMap) {
-        Map<String, String> sourceMap_ = 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));
-            }
-        }
-    }
-
-    private List<String> ezSectionMaps = Lists.newArrayList(
-            "诊断名称=手术指征",
-            "量=羊水量(mL)",
-            "长度=新生儿出生身长(cm)",
-            "圈数=绕颈身(周)",
-            "宫缩剂用法=宫缩剂使用方法",
-            "手术用药名称=手术用药",
-            "术中出血量=出血量(mL)",
-            "补液量=输液量(mL)",
-            "脐带长度=脐带长度(cm)",
-            "分数=Apgar评分值"
-    );
-
-
-
-    /**
-     * 复制一个map
-     *
-     * @param map
-     * @return
-     */
-    public static Map<String, Object> copyMap(Map<String, Object> map) {
-        if (map == null) {
-            return null;
-        }
-        Map<String, Object> retMap = Maps.newHashMap();
-        map.keySet().forEach(key -> {
-            retMap.put(key, map.get(key));
-        });
-        return retMap;
-    }
-
 }

+ 312 - 0
structure-center/src/main/java/com/lantone/structure/facade/tran/CesareanSectionTran.java

@@ -0,0 +1,312 @@
+package com.lantone.structure.facade.tran;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.lantone.common.util.DateUtil;
+import com.lantone.common.util.ListUtil;
+import com.lantone.common.util.StringUtil;
+import com.lantone.structure.facade.tran.util.CommonAnalysisUtil;
+import com.lantone.structure.model.doc.CaesareanSectionDoc;
+import com.lantone.structure.model.entity.Drug;
+import com.lantone.structure.model.entity.UCAgent;
+import com.lantone.structure.model.label.CaesareanSectionLabel;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @Description:
+ * @author: rengb
+ * @time: 2021/2/2 13:48
+ */
+@Slf4j
+public class CesareanSectionTran extends TargetTran {
+
+    @Override
+    public Map<String, String> convert(String text) {
+        List<CaesareanSectionDoc> caesareanSectionDocList = new ArrayList<>();
+        CaesareanSectionDoc caesareanSectionDoc = new CaesareanSectionDoc();
+        caesareanSectionDoc.setText(text);
+        caesareanSectionDocList.add(caesareanSectionDoc);
+        inputInfo.setCaesareanSectionDocs(caesareanSectionDocList);
+        aiProcess();
+
+        Map<String, String> sourceMap = cutWord(text);
+        insertCrf(sourceMap);
+        return sourceMap;
+    }
+
+    private Map<String, String> cutWord(String text) {
+        Map<String, String> ret = Maps.newHashMap();
+        Map<String, String> sourceMap = Maps.newHashMap();
+        List<String> titles = CommonAnalysisUtil.sortTitles(
+                Lists.newArrayList("手术开始时间", "手术结束时间", "手术日期", "术前诊断", "手术名称", "术中诊断", "手 术 者",
+                        "麻 醉 者", "手术标本", "术中并发症", "术中失血量", "手术经过", "第1次手术"),
+                text
+        );
+        CommonAnalysisUtil.cutByTitles(text, titles, 0, sourceMap);
+        opeTimeHandle(sourceMap, ret);
+        ret.put("术前诊断", sourceMap.get("术前诊断"));
+        ret.put("剖宫产手术过程", sourceMap.get("手术经过"));
+        return ret;
+    }
+
+    private void opeTimeHandle(Map<String, String> sourceMap, Map<String, String> ret) {
+        try {
+            String opeStartTime = sourceMap.get("手术开始时间");
+            String opeEndTime = sourceMap.get("手术结束时间");
+            if (StringUtil.isNotBlank(sourceMap.get("手术日期"))) {
+                String[] arry = sourceMap.get("手术日期").split("-");
+                opeStartTime = arry[0];
+                opeEndTime = arry[1];
+            }
+            ret.put("手术开始日期时间", opeStartTime);
+            ret.put("手术结束日期时间", opeEndTime);
+            ret.put("手术全程时间(min)", (DateUtil.parseDate(opeEndTime, DateUtil.FORMAT_LONG_CN_MI).getTime() - DateUtil.parseDate(opeStartTime, DateUtil.FORMAT_LONG_CN_MI).getTime()) / 60000 + "");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+    }
+
+    private void insertCrf(Map<String, String> sourceMap) {
+        List<CaesareanSectionDoc> caesareanSectionDocs = inputInfo.getCaesareanSectionDocs();
+        if (ListUtil.isEmpty(caesareanSectionDocs)) {
+            return;
+        }
+        CaesareanSectionDoc caesareanSectionDoc = caesareanSectionDocs.get(0);
+        CaesareanSectionLabel caesareanSectionLabel = caesareanSectionDoc != null ? caesareanSectionDoc.getCaesareanSectionLabel() : null;
+        if (caesareanSectionLabel == null) {
+            return;
+        }
+        StringBuffer value = new StringBuffer();
+
+        //手术指征
+        if (ListUtil.isNotEmpty(caesareanSectionLabel.getDiagnosis())) {
+            caesareanSectionLabel.getDiagnosis().stream().filter(i -> i != null && StringUtil.isNotBlank(i.getName())).forEach(i -> {
+                value.append(i.getName()).append(";");
+                ;
+            });
+            sourceMap.put("手术指征", value.toString());
+            value.setLength(0);
+        }
+
+        //麻醉体位
+        if (caesareanSectionLabel.getAnesthesiaMethod() != null) {
+            sourceMap.put("麻醉体位", caesareanSectionLabel.getAnesthesiaMethod().getName());
+        }
+
+        //麻醉效果
+        if (caesareanSectionLabel.getAnestheticEffect() != null) {
+            sourceMap.put("麻醉效果", caesareanSectionLabel.getAnestheticEffect().getName());
+        }
+
+        //子宫情况
+        if (ListUtil.isNotEmpty(caesareanSectionLabel.getUterusConditions())) {
+            caesareanSectionLabel.getUterusConditions().stream().filter(i -> i != null && StringUtil.isNotBlank(i.getName())).forEach(i -> {
+                value.append(i.getName()).append(";");
+                ;
+            });
+            sourceMap.put("子宫情况", value.toString());
+            value.setLength(0);
+        }
+
+        //胎儿娩出方式
+        if (caesareanSectionLabel.getChildbirthWay() != null) {
+            sourceMap.put("胎儿娩出方式", caesareanSectionLabel.getChildbirthWay().getName());
+        }
+
+        //羊水性状
+        //羊水量(mL)
+        if (caesareanSectionLabel.getAmnioticFluid() != null) {
+            if (caesareanSectionLabel.getAmnioticFluid().getAmnioticFluidCharacter() != null) {
+                sourceMap.put("羊水性状", caesareanSectionLabel.getAmnioticFluid().getAmnioticFluidCharacter().getName());
+            }
+            if (caesareanSectionLabel.getAmnioticFluid().getQuantity() != null) {
+                sourceMap.put("羊水量(mL)", caesareanSectionLabel.getAmnioticFluid().getQuantity().getName());
+            }
+        }
+
+        //胎盘娩出情况
+        if (ListUtil.isNotEmpty(caesareanSectionLabel.getChildbirthConditions())) {
+            caesareanSectionLabel.getChildbirthConditions().stream().filter(i -> i != null && StringUtil.isNotBlank(i.getName())).forEach(i -> {
+                value.append(i.getName()).append(";");
+            });
+            sourceMap.put("胎盘娩出情况", value.toString());
+            value.setLength(0);
+        }
+
+        //脐带长度(cm)
+        if (caesareanSectionLabel.getUmbilicalCord() != null) {
+            if (caesareanSectionLabel.getUmbilicalCord().getExtent() != null) {
+                sourceMap.put("脐带长度(cm)", caesareanSectionLabel.getUmbilicalCord().getExtent().getName());
+            }
+        }
+
+        //绕颈身(周)
+        if (caesareanSectionLabel.getCordAroundNeck() != null || caesareanSectionLabel.getCordAroundBody() != null) {
+            String rjValue = "";
+            if (caesareanSectionLabel.getCordAroundNeck() != null) {
+                if (caesareanSectionLabel.getCordAroundNeck().getNegative() != null) {
+                    if (StringUtil.isNotBlank(caesareanSectionLabel.getCordAroundNeck().getNegative().getName())) {
+                        rjValue += caesareanSectionLabel.getCordAroundNeck().getNegative().getName() + "绕颈";
+                    }
+                }
+                if (caesareanSectionLabel.getCordAroundNeck().getCylinderNumber() != null) {
+                    if (StringUtil.isNotBlank(caesareanSectionLabel.getCordAroundNeck().getCylinderNumber().getName())) {
+                        rjValue += caesareanSectionLabel.getCordAroundNeck().getCylinderNumber().getName();
+                    }
+                }
+                rjValue += " ";
+            }
+            if (caesareanSectionLabel.getCordAroundBody() != null) {
+                if (caesareanSectionLabel.getCordAroundBody().getNegative() != null) {
+                    if (StringUtil.isNotBlank(caesareanSectionLabel.getCordAroundBody().getNegative().getName())) {
+                        rjValue += caesareanSectionLabel.getCordAroundBody().getNegative().getName() + "绕身";
+                    }
+                }
+                if (caesareanSectionLabel.getCordAroundBody().getCylinderNumber() != null) {
+                    if (StringUtil.isNotBlank(caesareanSectionLabel.getCordAroundBody().getCylinderNumber().getName())) {
+                        rjValue += caesareanSectionLabel.getCordAroundBody().getCylinderNumber().getName();
+                    }
+                }
+            }
+            sourceMap.put("绕颈身(周)", rjValue.trim());
+        }
+
+        //子宫壁缝合情况
+        if (ListUtil.isNotEmpty(caesareanSectionLabel.getUterineWallSutures())) {
+            caesareanSectionLabel.getUterineWallSutures().stream().filter(i -> i != null && StringUtil.isNotBlank(i.getName())).forEach(i -> {
+                value.append(i.getName()).append(";");
+            });
+            sourceMap.put("子宫壁缝合情况", value.toString());
+            value.setLength(0);
+        }
+
+        //宫缩剂名称
+        //宫缩剂使用方法
+        if (ListUtil.isNotEmpty(caesareanSectionLabel.getUCAgents())) {
+            StringBuffer gsjName = new StringBuffer();
+            StringBuffer gsjMd = new StringBuffer();
+            List<UCAgent> uCAgents = caesareanSectionLabel.getUCAgents().stream()
+                    .filter(i -> i != null && StringUtil.isNotBlank(i.getName()))
+                    .collect(Collectors.toList());
+            uCAgents.forEach(i -> {
+                gsjName.append(i.getName()).append(";");
+                if (i.getConsumption() != null && StringUtil.isNotBlank(i.getConsumption().getName())) {
+                    gsjMd.append(i.getName()).append(" ").append(i.getConsumption().getName()).append(" ");
+                }
+                if (i.getUsageWardRound() != null && StringUtil.isNotBlank(i.getUsageWardRound().getName())) {
+                    gsjMd.append(i.getUsageWardRound().getName());
+                }
+                gsjMd.append(";");
+            });
+            sourceMap.put("宫缩剂名称", gsjName.toString());
+            sourceMap.put("宫缩剂使用方法", gsjMd.toString());
+        }
+
+        //宫腔探查异常情况描述
+        if (ListUtil.isNotEmpty(caesareanSectionLabel.getUterineCavityAbnormity())) {
+            caesareanSectionLabel.getUterineCavityAbnormity().stream().filter(i -> i != null && StringUtil.isNotBlank(i.getName())).forEach(i -> {
+                value.append(i.getName()).append(";");
+                ;
+            });
+            sourceMap.put("宫腔探查异常情况描述", value.toString());
+            value.setLength(0);
+        }
+
+        //宫腔探查处理情况
+        if (ListUtil.isNotEmpty(caesareanSectionLabel.getUterineCavityDispose())) {
+            caesareanSectionLabel.getUterineCavityDispose().stream().filter(i -> i != null && StringUtil.isNotBlank(i.getName())).forEach(i -> {
+                value.append(i.getName()).append(";");
+            });
+            sourceMap.put("宫腔探查处理情况", value.toString());
+            value.setLength(0);
+        }
+
+        //手术时产妇情况
+        if (ListUtil.isNotEmpty(caesareanSectionLabel.getPuerperaCondition())) {
+            caesareanSectionLabel.getPuerperaCondition().stream().filter(i -> i != null && StringUtil.isNotBlank(i.getName())).forEach(i -> {
+                value.append(i.getName()).append(";");
+            });
+            sourceMap.put("手术时产妇情况", value.toString());
+            value.setLength(0);
+        }
+
+        //出血量(mL)
+        if (caesareanSectionLabel.getHemorrhage() != null) {
+            if (caesareanSectionLabel.getHemorrhage().getQuantity() != null) {
+                sourceMap.put("出血量(mL)", caesareanSectionLabel.getHemorrhage().getQuantity().getName());
+            }
+        }
+
+        //输液量(mL)
+        if (caesareanSectionLabel.getFluidInfusion() != null) {
+            if (caesareanSectionLabel.getFluidInfusion().getQuantity() != null) {
+                sourceMap.put("输液量(mL)", caesareanSectionLabel.getFluidInfusion().getQuantity().getName());
+            }
+        }
+
+        //新生儿出生体重(g)
+        //新生儿出生身长(cm)
+        if (caesareanSectionLabel.getNewborn() != null) {
+            if (caesareanSectionLabel.getNewborn().getWeight() != null) {
+                sourceMap.put("新生儿出生体重(g)", caesareanSectionLabel.getNewborn().getWeight().getName());
+            }
+            if (caesareanSectionLabel.getNewborn().getExtent() != null) {
+                sourceMap.put("新生儿出生身长(cm)", caesareanSectionLabel.getNewborn().getExtent().getName());
+            }
+        }
+
+        //Apgar评分值
+        if (ListUtil.isNotEmpty(caesareanSectionLabel.getApgarScores())) {
+            caesareanSectionLabel.getApgarScores().stream().filter(i -> i != null && StringUtil.isNotBlank(i.getName())).forEach(i -> {
+                value.append(i.getName()).append(";");
+            });
+            sourceMap.put("Apgar评分值", value.toString());
+            value.setLength(0);
+        }
+
+        //产瘤大小
+        //产瘤部位
+        if (caesareanSectionLabel.getCaputSuccedaneum() != null) {
+            if (caesareanSectionLabel.getCaputSuccedaneum().getVolume() != null) {
+                sourceMap.put("产瘤大小", caesareanSectionLabel.getCaputSuccedaneum().getVolume().getName());
+            }
+            if (caesareanSectionLabel.getCaputSuccedaneum().getCaputSuccedaneumPart() != null) {
+                sourceMap.put("产瘤部位", caesareanSectionLabel.getCaputSuccedaneum().getCaputSuccedaneumPart().getName());
+            }
+        }
+
+        //手术用药
+        //手术用药量
+        if (ListUtil.isNotEmpty(caesareanSectionLabel.getDrugs())) {
+            StringBuffer drugName = new StringBuffer();
+            StringBuffer consumption = new StringBuffer();
+            List<Drug> drugs = caesareanSectionLabel.getDrugs().stream()
+                    .filter(i -> i != null && StringUtil.isNotBlank(i.getName()))
+                    .collect(Collectors.toList());
+            drugs.forEach(i -> {
+                drugName.append(i.getName()).append(";");
+                if (i.getConsumption() != null && StringUtil.isNotBlank(i.getConsumption().getName())) {
+                    consumption.append(i.getName()).append(" ").append(i.getConsumption().getName());
+                }
+                consumption.append(";");
+            });
+            sourceMap.put("手术用药", drugName.toString());
+            sourceMap.put("手术用药量", consumption.toString());
+        }
+
+        //输血成分
+        //输血量(mL)
+        if (caesareanSectionLabel.getTransfusion() != null) {
+            sourceMap.put("输血成分", caesareanSectionLabel.getTransfusion().getName());
+            if (caesareanSectionLabel.getTransfusion().getQuantity() != null) {
+                sourceMap.put("输血量(mL)", caesareanSectionLabel.getTransfusion().getQuantity().getName());
+            }
+        }
+    }
+
+}

+ 106 - 0
structure-center/src/main/java/com/lantone/structure/facade/tran/ClinicalBloodTran.java

@@ -0,0 +1,106 @@
+package com.lantone.structure.facade.tran;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONException;
+import com.alibaba.fastjson.JSONObject;
+import com.lantone.common.util.FastJsonUtils;
+import com.lantone.structure.model.doc.ClinicalBloodDoc;
+import com.lantone.structure.util.MapUtil;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:
+ * @author: rengb
+ * @time: 2021/2/2 14:16
+ */
+@Slf4j
+public class ClinicalBloodTran extends TargetTran {
+
+    @Override
+    Map<String, String> convert(String text) {
+        List<ClinicalBloodDoc> clinicalBloodDocList = new ArrayList<>();
+        ClinicalBloodDoc clinicalBloodDoc = new ClinicalBloodDoc();
+        clinicalBloodDoc.setText(text);
+        clinicalBloodDocList.add(clinicalBloodDoc);
+        inputInfo.setClinicalBloodDocs(clinicalBloodDocList);
+        return null;
+    }
+
+    public void bloodKeyContrastCommon(Map sourceMap, Map<String, String> keyContrastMap, Map<String, String> retMap) {
+        Map<String, Object> sourceMap_ = MapUtil.copyMap(sourceMap);
+        for (Map.Entry<String, Object> dateEntry : sourceMap_.entrySet()) {
+            try {
+                Object object = JSON.parse(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
+                if (object instanceof JSONObject) {
+                    Map<String, Object> firstJsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
+                    if (firstJsonMap.size() == 1) {
+                        String key = keyContrastMap.get(dateEntry.getKey());
+                        retMap.put(key, (String) firstJsonMap.get("name"));
+                    } else {
+                        StringBuffer sbX = new StringBuffer();
+                        for (Map.Entry<String, Object> firstDateEntry : firstJsonMap.entrySet()) {
+                            String beanToJson = FastJsonUtils.getBeanToJson( firstDateEntry.getValue());
+                            if(beanToJson.contains("name")||beanToJson.contains("measurementUnit")){
+                                Map<String, Object> jsonToMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(firstDateEntry.getValue()));
+                                if (jsonToMap.size() == 1) {
+                                    String childKey = keyContrastMap.get(firstDateEntry.getKey());
+                                    if (retMap.containsKey(keyContrastMap.get(firstDateEntry.getKey()))) {
+                                        retMap.put(keyContrastMap.get(dateEntry.getKey()) + childKey, (String) jsonToMap.get("name"));
+                                    } else {
+                                        retMap.put(childKey, (String) jsonToMap.get("name"));
+                                    }
+                                }else{
+                                    for (Map.Entry<String, Object> typeObjectEntry : jsonToMap.entrySet()) {
+                                        Object value = typeObjectEntry.getValue();
+                                        if(value instanceof JSONObject){
+                                            Map<String, Object> objToMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(value));
+                                            sbX.append(objToMap.get("name"));
+                                        }else{
+                                            sbX.append( jsonToMap.get("name"));
+                                        }
+
+                                    }
+                                }
+                            }else{
+                                sbX.append(firstDateEntry.getValue());
+                            }
+                            retMap.put(keyContrastMap.get(dateEntry.getKey()),sbX.toString());
+                        }
+
+                    }
+                } else if (object instanceof JSONArray) {
+                    List<Map<String, Object>> jsonToListMap = FastJsonUtils.getJsonToListMap(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
+                    int count = 1;
+                    StringBuffer sb = new StringBuffer();
+                    if(jsonToListMap.size()==1){
+                        Object name = jsonToListMap.get(0).get("name");
+                        retMap.put(keyContrastMap.get(dateEntry.getKey()),String.valueOf(name));
+                    }else{
+                        for (Map<String, Object> mapList : jsonToListMap) {
+                            for (Map.Entry<String, Object> stringObjectEntry : mapList.entrySet()) {
+                                if(stringObjectEntry.getKey()=="negative"){
+                                    Map<String, Object> negativeJsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(stringObjectEntry.getValue()));
+                                    Object negativeObject = negativeJsonMap.get("name");
+                                    sb.append((count++) + "." +(negativeObject==null? "":negativeObject));
+                                }else if(stringObjectEntry.getKey()=="name"){
+                                    sb.append(stringObjectEntry.getValue());
+                                }
+                            }
+                        }
+                        retMap.put(keyContrastMap.get(dateEntry.getKey()), sb.toString());
+                    }
+
+                }
+
+            } catch (JSONException e) {
+                log.error(keyContrastMap.get(dateEntry.getKey()) + "json为空");
+            }
+        }
+    }
+
+}

+ 28 - 0
structure-center/src/main/java/com/lantone/structure/facade/tran/RescueTran.java

@@ -0,0 +1,28 @@
+package com.lantone.structure.facade.tran;
+
+import com.lantone.structure.model.doc.RescueDoc;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:
+ * @author: rengb
+ * @time: 2021/2/2 14:14
+ */
+@Slf4j
+public class RescueTran extends TargetTran {
+
+    @Override
+    Map<String, String> convert(String text) {
+        List<RescueDoc> rescueDocList = new ArrayList<>();
+        RescueDoc rescueDoc = new RescueDoc();
+        rescueDoc.setText(text);
+        rescueDocList.add(rescueDoc);
+        inputInfo.setRescueDocs(rescueDocList);
+        return null;
+    }
+
+}

+ 29 - 0
structure-center/src/main/java/com/lantone/structure/facade/tran/StagesSummaryTran.java

@@ -0,0 +1,29 @@
+package com.lantone.structure.facade.tran;
+
+import com.lantone.structure.model.doc.StagesSummaryDoc;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:
+ * @author: rengb
+ * @time: 2021/2/2 14:15
+ */
+@Slf4j
+public class StagesSummaryTran extends TargetTran {
+
+    @Override
+    Map<String, String> convert(String text) {
+        List<StagesSummaryDoc> stagesSummaryDocList = new ArrayList<>();
+        StagesSummaryDoc stagesSummaryDoc = new StagesSummaryDoc();
+        stagesSummaryDoc.setText(text);
+        stagesSummaryDocList.add(stagesSummaryDoc);
+        inputInfo.setStagesSummaryDocs(stagesSummaryDocList);
+
+        return null;
+    }
+
+}

+ 41 - 0
structure-center/src/main/java/com/lantone/structure/facade/tran/TargetTran.java

@@ -0,0 +1,41 @@
+package com.lantone.structure.facade.tran;
+
+import com.lantone.structure.ai.AIAnalyze;
+import com.lantone.structure.client.CRFServiceClient;
+import com.lantone.structure.client.SimilarityServiceClient;
+import com.lantone.structure.model.InputInfo;
+import com.lantone.structure.util.SpringContextUtil;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Map;
+
+/**
+ * @Description:
+ * @author: rengb
+ * @time: 2021/2/2 13:49
+ */
+@Slf4j
+public abstract class TargetTran {
+
+    InputInfo inputInfo;
+    SimilarityServiceClient similarityServiceClient;
+    CRFServiceClient crfServiceClient;
+
+    public abstract Map<String, String> convert(String text);
+
+    public TargetTran() {
+        this.inputInfo = inputInfo;
+        similarityServiceClient = SpringContextUtil.getBean("similarityServiceClient");
+        crfServiceClient = SpringContextUtil.getBean("crfServiceClient");
+    }
+
+    public void aiProcess() {
+        AIAnalyze aiAnalyze = new AIAnalyze(crfServiceClient, similarityServiceClient);
+        try {
+            aiAnalyze.aiProcess(inputInfo);
+        } catch (Exception e) {
+            log.error("AI模型执行错误:" + e.getMessage(), e);
+        }
+    }
+
+}

+ 260 - 0
structure-center/src/main/java/com/lantone/structure/facade/tran/util/CommonAnalysisUtil.java

@@ -0,0 +1,260 @@
+package com.lantone.structure.facade.tran.util;
+
+import com.google.common.collect.Lists;
+import com.lantone.common.util.StringUtil;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @Description :
+ * @Author : HUJING
+ * @Date: 2020/9/10 13:48
+ */
+@Slf4j
+public class CommonAnalysisUtil {
+
+
+    public static void html2StructureMap(List<String> titles, String htmlText, Map<String, String> structureMap) {
+        List<String> sortTitles = sortTitles(titles, htmlText);
+        cutByTitles(htmlText, sortTitles, 0, structureMap);
+    }
+
+
+    /**
+     * 将list中html内容转换成structureMap
+     *
+     * @param titles       文书各标题
+     * @param htmlText     html内容以行的形式存储list
+     * @param structureMap
+     * @return
+     */
+    public void html2StructureMap(List<String> titles, List<String> htmlText, Map<String, String> structureMap) {
+        StringBuffer sb = new StringBuffer();
+        for (String line : htmlText) {
+            String text = line.replaceAll("[   ]", " ");
+            if (text.length() == 0) {
+                continue;
+            }
+            sb.append(text).append("\n");
+        }
+        html2StructureMap(titles, sb.toString(), structureMap);
+    }
+
+    /**
+     * 根据文书各标题截取相应文本,存入structmap中
+     *
+     * @param line         原始文本
+     * @param titles       文书各标题
+     * @param depth        递归深度,也就是titles取值时的下标值
+     * @param structureMap 存储结构化数据
+     */
+    public static void cutByTitles(String line, List<String> titles, int depth, Map<String, String> structureMap) {
+        if (depth > titles.size() || titles.size() == 0) {
+            return;
+        }
+        String beforeTitle = null, title = null, newTitle = null, value = null;
+        beforeTitle = StringUtil.removeBlank(titles.get(Math.max(depth - 1, 0)));
+        title = titles.get(Math.min(depth, titles.size() - 1));
+        if (depth == titles.size()) {
+            /*if (line.contains("\n")) {
+                line = line.split("\n")[0];
+            }
+            */
+            value = line.replace("\n", "");
+            if (StringUtil.isBlank(structureMap.get(beforeTitle))) {
+                structureMap.put(beforeTitle, StringUtil.trim(value));
+            }
+            return;
+        }
+        if (line.contains(title + ":") || line.contains(title + ":")) {
+            if (line.contains(title + ":")) {
+                newTitle = title + ":";
+            } else {
+                newTitle = title + ":";
+            }
+            if (depth > 0) {
+                value = line.substring(0, line.indexOf(newTitle));
+                if (StringUtil.isBlank(structureMap.get(beforeTitle))) {
+                    structureMap.put(beforeTitle, StringUtil.trim(value).replace("\n", ""));
+                }
+            }
+            line = line.substring(line.indexOf(newTitle) + newTitle.length());
+            depth++;
+        } else {
+            titles.remove(depth);
+        }
+        cutByTitles(line, titles, depth, structureMap);
+    }
+
+    /**
+     * 将title根据在文本中的位置排序
+     *
+     * @param titles
+     * @param content
+     * @return
+     */
+    public static List<String> sortTitles(List<String> titles, String content) {
+        Map<Integer, String> titleIndex = new TreeMap<>();
+        int index, index_1, index_2;
+        for (String title : titles) {
+            index_1 = content.indexOf(title + ":");
+            index_2 = content.indexOf(title + ":");
+            index = Math.max(index_1, index_2);
+            if (index != -1) {
+                titleIndex.put(index, title);
+                StringBuffer sb = new StringBuffer(title.length());
+                for (int i = 0; i < title.length(); i++) {
+                    sb.append('*');
+                }
+                content = content.substring(0, index) + sb.toString() + content.substring(index + title.length() + 1);
+                //                content = content.substring(0, index) + content.substring(index + title.length() + 1);
+            }
+        }
+        titles = Lists.newArrayList(titleIndex.values());
+        return titles;
+    }
+
+    /**
+     * 标题没有冒号版本
+     */
+    public static void html2StructureMapNoColon(List<String> titles, String htmlText, Map<String, String> structureMap) {
+        List<String> sortTitlesNoColon = sortTitlesNoColon(titles, htmlText);
+        cutByTitlesNoColon(htmlText, sortTitlesNoColon, 0, structureMap);
+    }
+
+    /**
+     * 标题没有冒号版本
+     */
+    public static void cutByTitlesNoColon(String line, List<String> titles, int depth, Map<String, String> structureMap) {
+        if (depth > titles.size() || titles.size() == 0) {
+            return;
+        }
+        String beforeTitle = null, title = null, newTitle = null, value = null;
+        beforeTitle = StringUtil.removeBlank(titles.get(Math.max(depth - 1, 0)));
+        title = titles.get(Math.min(depth, titles.size() - 1));
+        if (depth == titles.size()) {
+            value = line;
+            value = value.trim();
+            if (value.startsWith(":") || value.startsWith(":")) {
+                value = value.replaceFirst("[::]", "");
+            }
+            if (StringUtil.isBlank(structureMap.get(beforeTitle))) {
+                structureMap.put(beforeTitle, StringUtil.trim(value).replace("\n", ""));
+            }
+            return;
+        }
+        if (line.contains(title)) {
+            newTitle = title;
+            if (depth > 0) {
+                value = line.substring(0, line.indexOf(newTitle));
+                value = value.trim();
+                if (value.startsWith(":") || value.startsWith(":")) {
+                    value = value.replaceFirst("[::]", "");
+                }
+                if (StringUtil.isBlank(structureMap.get(beforeTitle))) {
+                    structureMap.put(beforeTitle, StringUtil.trim(value).replace("\n", ""));
+                }
+            }
+            line = line.substring(line.indexOf(newTitle) + newTitle.length());
+            depth++;
+        } else {
+            titles.remove(depth);
+        }
+        cutByTitlesNoColon(line, titles, depth, structureMap);
+    }
+
+    /**
+     * 标题没有冒号版本
+     */
+    public static List<String> sortTitlesNoColon(List<String> titles, String content) {
+        Map<Integer, String> titleIndex = new TreeMap<>();
+        int index;
+        for (String title : titles) {
+            index = content.indexOf(title);
+            if (index != -1) {
+                titleIndex.put(index, title);
+                content = content.replace(title, "");
+            }
+        }
+        titles = Lists.newArrayList(titleIndex.values());
+        return titles;
+    }
+
+    /**
+     * 抽取文本中的第一个时间
+     *
+     * @param top
+     * @return
+     */
+    public static String extractDate(String top) {
+        Pattern pattern = Pattern.compile("[0-9]{4}[-][0-9]{1,2}[-][0-9]{1,2}([ ][0-9]{1,2}[:][0-9]{1,2}([:][0-9]{1,2})?)?");
+        Matcher matcher = pattern.matcher(top);
+        if (matcher.find()) {
+            return matcher.group(0);
+        } else {
+            Pattern p1 = Pattern.compile("[0-9]{4}年[0-9]+月[0-9]+日[0-9]+时[0-9]+分");
+            Matcher m1 = p1.matcher(top);
+            if (m1.find()) {
+                return m1.group(0);
+            }
+        }
+        return null;
+    }
+
+
+    /**
+     * 若内容中是包含选择框(会诊类型:     急会诊       普通会诊         请院外会诊),特殊处理
+     *
+     * @param structureMap
+     */
+    public static void processType(Map<String, String> structureMap, String title) {
+        if (structureMap.containsKey(title)) {
+            String type = structureMap.get(title);
+            String[] types = type.split(" ");
+            for (String t : types) {
+                if (t.contains("\uF0FE")) {
+                    structureMap.put(title, t.replace("\uF0FE", ""));
+                    break;
+                }
+            }
+        }
+    }
+
+    /**
+     * 若list中其中一个元素包含之后第二个、第三个元素的文本,则把这个元素删除
+     *
+     * @param htmlList
+     */
+    public static void removeRepeat(List<String> htmlList) {
+        List<Integer> index = Lists.newArrayList();
+        if (htmlList.size() < 3) {
+            return;
+        }
+        String str1 = null, str2 = null, str3 = null;
+        for (int i = 0; i < htmlList.size() - 2; i++) {
+            str1 = htmlList.get(i);
+            str2 = htmlList.get(i + 1);
+            str3 = htmlList.get(i + 2);
+            if (str1.contains(str2) && str1.contains(str3)) {
+                index.add(i);
+            }
+        }
+
+        for (int i = 0; i < index.size(); i++) {
+            htmlList.remove(index.get(i) - i);
+        }
+    }
+
+    public static void makeEmpty(Map<String, String> structureMap, String... key) {
+        for (String k : key) {
+            if (structureMap.containsKey(k)) {
+                structureMap.put(k, "");
+            }
+        }
+    }
+}

+ 97 - 0
structure-center/src/main/java/com/lantone/structure/util/MapUtil.java

@@ -0,0 +1,97 @@
+package com.lantone.structure.util;
+
+import com.google.common.collect.Maps;
+import com.lantone.common.util.StringUtil;
+
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @Description: map工具类
+ * @author: gaodm
+ * @time: 2018/9/4 9:24
+ */
+public class MapUtil {
+
+
+    public static Object mapToObject(Map<String, Object> map, Class<?> beanClass) throws Exception {
+        if (map == null) {
+            return null;
+        }
+
+        Object obj = beanClass.newInstance();
+
+        BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
+        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+        for (PropertyDescriptor property : propertyDescriptors) {
+            Method setter = property.getWriteMethod();
+            if (setter != null) {
+                setter.invoke(obj, map.get(property.getName()));
+            }
+        }
+
+        return obj;
+    }
+
+    public static Map<String, Object> objectToMap(Object obj) throws Exception {
+        if (obj == null) {
+            return null;
+        }
+
+        Map<String, Object> map = new HashMap<String, Object>();
+
+        BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
+        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+        for (PropertyDescriptor property : propertyDescriptors) {
+            String key = property.getName();
+            if (key.compareToIgnoreCase("class") == 0) {
+                continue;
+            }
+            Method getter = property.getReadMethod();
+            Object value = getter != null ? getter.invoke(obj) : null;
+            map.put(key, value);
+        }
+        return map;
+    }
+
+    /**
+     * 复制一个map
+     *
+     * @param map
+     * @return
+     */
+    public static Map<String, Object> copyMap(Map<String, Object> map) {
+        if (map == null) {
+            return null;
+        }
+        Map<String, Object> retMap = Maps.newHashMap();
+        map.keySet().forEach(key -> {
+            retMap.put(key, map.get(key));
+        });
+        return retMap;
+    }
+
+    /**
+     * map key同义词赋值
+     *
+     * @param map
+     * @param sourceKey
+     * @param targetKeys
+     */
+    public static void keyAssig(Map<String, String> map, String sourceKey, String... targetKeys) {
+        if (map == null || StringUtil.isBlank(sourceKey) || targetKeys == null || targetKeys.length == 0 || StringUtil.isNotBlank(map.get(sourceKey))) {
+            return;
+        }
+        for (String targetKey : targetKeys) {
+            if (StringUtil.isNotBlank(map.get(targetKey))) {
+                map.put(sourceKey, map.get(targetKey));
+                break;
+            }
+        }
+    }
+
+}