Pārlūkot izejas kodu

Merge remote-tracking branch 'origin/push-grade' into push-test

kongwz 5 gadi atpakaļ
vecāks
revīzija
9ae2c3ca54

+ 11 - 0
bigdata-web/src/main/java/org/diagbot/bigdata/common/ApplicationCacheUtil.java

@@ -33,6 +33,7 @@ public class ApplicationCacheUtil {
     public static Map<String, List<Map<String, String>>> kl_result_mapping_standword_map = null;
     // 规则
     public static Map<String, List<Rule>> rule_filter_map = null;
+    public static Map<String, List<Rule>> kl_rule_filter_map = null;
 
 
     public static Map<String, Map<String, String>> getStandard_info_synonym_map() {
@@ -255,6 +256,16 @@ public class ApplicationCacheUtil {
         }
     }
 
+    public static void create_kl_rule_filter_map() {
+        kl_rule_filter_map = new HashMap<>();
+
+        Configuration configuration = new DefaultConfig();
+        List<String> fileContents = configuration.readFileContents("bigdata_rule_filter.dict");
+        for (String line:fileContents) {
+            String[] content = line.split("\\|");
+        }
+    }
+
     public static void setProterty(Lexeme lexeme) {
         for (String featureType : lexeme.getProperty().split(",")) {
             switch (featureType) {

+ 35 - 0
common-push/src/main/java/org/diagbot/common/push/cache/CacheFileManager.java

@@ -5,6 +5,7 @@ import org.diagbot.pub.utils.PropertiesUtil;
 import org.diagbot.pub.utils.security.EncrypDES;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.util.StringUtils;
 
 import java.io.File;
 import java.io.FileWriter;
@@ -351,6 +352,40 @@ public class CacheFileManager {
                 fw.write("\n");
             }
             fw.close();
+
+            //规则过滤信息
+            sql = "SELECT idx_name, set_name, set_status, min_value, max_value, standard_value, " +
+                    " , unit, concept_text, crisis_status, remind FROM kl_rule_new ";
+            st = conn.createStatement();
+            rs = st.executeQuery(sql);
+            fw = new FileWriter(path + "bigdata_rule_filter.dict");
+            String r10;
+            while (rs.next()) {
+                r1 = rs.getString(1);
+                r2 = rs.getString(2);
+                r3 = rs.getString(3);
+                r4 = rs.getString(4);
+                r5 = rs.getString(5);
+                r6 = rs.getString(6);
+                r7 = rs.getString(7);
+                r8 = rs.getString(8);
+                r9 = rs.getString(9);
+                r10 = rs.getString(10);
+                r1 = StringUtils.isEmpty(r1)?"":r1;
+                r2 = StringUtils.isEmpty(r1)?"":r2;
+                r3 = StringUtils.isEmpty(r1)?"":r3;
+                r4 = StringUtils.isEmpty(r1)?"":r4;
+                r5 = StringUtils.isEmpty(r1)?"":r5;
+                r6 = StringUtils.isEmpty(r1)?"":r6;
+                r7 = StringUtils.isEmpty(r1)?"":r7;
+                r8 = StringUtils.isEmpty(r1)?"":r8;
+                r9 = StringUtils.isEmpty(r1)?"":r9;
+                r10 = StringUtils.isEmpty(r1)?"":r10;
+                fw.write(encrypDES.encrytor(r1+ "|" + r2 + "|" + r3 + "|" + r4 + "|" + r5
+                        + "|" + r6 + "|" + r7 + "|" + r8 + "|" + r9 + "|" + r10));
+                fw.write("\n");
+            }
+            fw.close();
         } catch (IOException ioe) {
             ioe.printStackTrace();
         } catch (SQLException sqle) {

+ 79 - 0
common-push/src/main/java/org/diagbot/common/push/filter/PreResult.java

@@ -0,0 +1,79 @@
+package org.diagbot.common.push.filter;
+
+/**
+ * Created by louhr on 2019/8/31.
+ */
+public class PreResult {
+    private String detailName;
+    private String uniqueName;
+    private Double maxValue;
+    private Double minValue;
+    private String name;
+    private String otherValue;
+    private String units;
+    private Double value;
+
+    public String getDetailName() {
+        return detailName;
+    }
+
+    public void setDetailName(String detailName) {
+        this.detailName = detailName;
+    }
+
+    public String getUniqueName() {
+        return uniqueName;
+    }
+
+    public void setUniqueName(String uniqueName) {
+        this.uniqueName = uniqueName;
+    }
+
+    public Double getMaxValue() {
+        return maxValue;
+    }
+
+    public void setMaxValue(Double maxValue) {
+        this.maxValue = maxValue;
+    }
+
+    public Double getMinValue() {
+        return minValue;
+    }
+
+    public void setMinValue(Double minValue) {
+        this.minValue = minValue;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getOtherValue() {
+        return otherValue;
+    }
+
+    public void setOtherValue(String otherValue) {
+        this.otherValue = otherValue;
+    }
+
+    public String getUnits() {
+        return units;
+    }
+
+    public void setUnits(String units) {
+        this.units = units;
+    }
+
+    public Double getValue() {
+        return value;
+    }
+
+    public void setValue(Double value) {
+        this.value = value;
+    }
+}

+ 45 - 0
common-push/src/main/java/org/diagbot/common/push/filter/PretreatmentFilter.java

@@ -0,0 +1,45 @@
+package org.diagbot.common.push.filter;
+
+
+import org.diagbot.common.push.filter.pretreat.Pretreatment;
+import org.diagbot.common.push.filter.pretreat.PretreatmentSymptom;
+import org.diagbot.common.push.filter.pretreat.PretreatmentVital;
+import org.diagbot.common.work.SearchData;
+import org.springframework.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PretreatmentFilter {
+    public void crisisFilter(SearchData searchData) throws java.io.IOException {
+        //将数值类型内容全部转换为标准术语  依据kl_rule提供规则
+
+        List<PreResult> allPreResultList = new ArrayList<>();
+        //症状数据
+        if (!StringUtils.isEmpty(searchData.getSymptom())) {
+            searchData.setSymptom(add2PreResultList(new PretreatmentSymptom(), searchData.getSymptom(), allPreResultList));
+        }
+        //体征数据
+        if (!StringUtils.isEmpty(searchData.getVital())) {
+            searchData.setVital(add2PreResultList(new PretreatmentVital(), searchData.getVital(), allPreResultList));
+        }
+        //lis文本非结构化数据
+        if (!StringUtils.isEmpty(searchData.getLis())) {
+            searchData.setLis(add2PreResultList(new PretreatmentVital(), searchData.getLis(), allPreResultList));
+        }
+        //pacs数据
+        if (!StringUtils.isEmpty(searchData.getPacs())) {
+            searchData.setPacs(add2PreResultList(new PretreatmentVital(), searchData.getPacs(), allPreResultList));
+        }
+    }
+
+    private String add2PreResultList(Pretreatment pretreatment, String content, List<PreResult> allPreResultList) throws java.io.IOException {
+        List<PreResult> preResultList = pretreatment.analyze(content);
+        if (preResultList != null) {
+            allPreResultList.addAll(preResultList);
+
+
+        }
+        return content;
+    }
+}

+ 88 - 0
common-push/src/main/java/org/diagbot/common/push/filter/pretreat/Pretreatment.java

@@ -0,0 +1,88 @@
+package org.diagbot.common.push.filter.pretreat;
+
+import org.diagbot.common.push.filter.PreResult;
+import org.diagbot.nlp.participle.ParticipleUtil;
+import org.diagbot.nlp.participle.word.Lexeme;
+import org.diagbot.nlp.participle.word.LexemePath;
+import org.diagbot.nlp.util.NegativeEnum;
+import org.diagbot.nlp.util.NlpUtil;
+import org.springframework.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by louhr on 2019/8/31.
+ */
+public abstract class Pretreatment {
+    protected NegativeEnum[] nees_time_and_unit = new NegativeEnum[]{NegativeEnum.EVENT_TIME, NegativeEnum.UNIT};
+
+    protected int cursor = 0;
+
+    public abstract List<PreResult> analyze(String content) throws java.io.IOException;
+
+    abstract PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index);
+
+    protected List<PreResult> analyzeDefault(String content) throws java.io.IOException{
+        LexemePath<Lexeme> lexemes = ParticipleUtil.participle(content);
+
+        List<PreResult> preResultList = new ArrayList<>();
+        for (int i = 0; i < lexemes.size(); i++) {
+            Lexeme l = lexemes.get(i);
+            if (NlpUtil.isFeature(l.getProperty(), nees_time_and_unit)) {
+                PreResult result = data2Object(lexemes, l, i, l.getProperty());
+                if (result != null) {
+                    preResultList.add(result);
+                }
+            }
+        }
+        return preResultList;
+    }
+
+    protected PreResult data2Object(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index, String property) {
+        if (index < 2) {
+            return null;
+        }
+        return createPreResult(lexemes, lexeme, index);
+    }
+
+    public PreResult createDefaultPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        double value = findNumberValue(lexemes, lexeme, index);
+        if (value == -1) return null;
+        //继续往前找本体
+        String text = findBodyValue(lexemes, lexeme, index);
+        if (StringUtils.isEmpty(text)) {
+            return null;
+        }
+        PreResult result = new PreResult();
+        result.setValue(value);
+        result.setUnits(lexeme.getText());
+        result.setDetailName(text);
+        return result;
+    }
+
+    protected double findNumberValue(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        if (index < 1) return -1;
+        cursor = index - 1;
+        Lexeme leftLexeme = lexemes.get(cursor);
+        if ("×".equals(leftLexeme.getText())) {
+            if  (cursor <= 0) return -1;
+            cursor--;
+            leftLexeme = lexemes.get(cursor);
+        }
+        if (NlpUtil.isNumberString(leftLexeme)) {
+            return NlpUtil.numberText2value(leftLexeme);
+        }
+        return -1;
+    }
+
+    protected String findBodyValue(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        if (cursor > 0) cursor--;
+        Lexeme leftLexeme = lexemes.get(cursor);
+        if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[]{NegativeEnum.VITAL_INDEX,
+                NegativeEnum.VITAL_INDEX_VALUE, NegativeEnum.VITAL_RESULT, NegativeEnum.SYMPTOM})) {
+            return leftLexeme.getText();
+        }
+        return null;
+    }
+}

+ 41 - 0
common-push/src/main/java/org/diagbot/common/push/filter/pretreat/PretreatmentLis.java

@@ -0,0 +1,41 @@
+package org.diagbot.common.push.filter.pretreat;
+
+import org.diagbot.common.push.filter.PreResult;
+import org.diagbot.nlp.participle.word.Lexeme;
+import org.diagbot.nlp.participle.word.LexemePath;
+import org.diagbot.nlp.util.NegativeEnum;
+import org.diagbot.nlp.util.NlpUtil;
+import org.springframework.util.StringUtils;
+
+import java.util.List;
+
+public class PretreatmentLis extends Pretreatment {
+    public List<PreResult> analyze(String content) throws java.io.IOException{
+        return super.analyzeDefault(content);
+    }
+
+    public PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        PreResult result = new PreResult();
+        double value = findNumberValue(lexemes, lexeme, index);
+        if (value == -1) return null;
+        //继续往前找化验明细项
+        if (cursor > 0) cursor--;
+        Lexeme leftLexeme = lexemes.get(cursor);
+        if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[]{NegativeEnum.LIS_NAME})) {
+            result.setDetailName(leftLexeme.getText());
+        } else {
+            return null;
+        }
+        //查找化验套餐
+        int position = cursor - 1;
+        while (position > -1) {
+            leftLexeme = lexemes.get(position);
+            if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[]{NegativeEnum.LIS_TYPE})) {
+                result.setName(leftLexeme.getText());
+                break;
+            }
+            position--;
+        }
+        return result;
+    }
+}

+ 17 - 0
common-push/src/main/java/org/diagbot/common/push/filter/pretreat/PretreatmentSymptom.java

@@ -0,0 +1,17 @@
+package org.diagbot.common.push.filter.pretreat;
+
+import org.diagbot.common.push.filter.PreResult;
+import org.diagbot.nlp.participle.word.Lexeme;
+import org.diagbot.nlp.participle.word.LexemePath;
+
+import java.util.List;
+
+public class PretreatmentSymptom extends Pretreatment {
+    public List<PreResult> analyze(String content) throws java.io.IOException{
+        return super.analyzeDefault(content);
+    }
+
+    public PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        return super.createDefaultPreResult(lexemes, lexeme, index);
+    }
+}

+ 17 - 0
common-push/src/main/java/org/diagbot/common/push/filter/pretreat/PretreatmentVital.java

@@ -0,0 +1,17 @@
+package org.diagbot.common.push.filter.pretreat;
+
+import org.diagbot.common.push.filter.PreResult;
+import org.diagbot.nlp.participle.word.Lexeme;
+import org.diagbot.nlp.participle.word.LexemePath;
+
+import java.util.List;
+
+public class PretreatmentVital extends Pretreatment {
+    public List<PreResult> analyze(String content) throws java.io.IOException{
+        return super.analyzeDefault(content);
+    }
+
+    public PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        return super.createDefaultPreResult(lexemes, lexeme, index);
+    }
+}

+ 40 - 4
graph-web/src/main/java/org/diagbot/graphWeb/work/GraphCalculate.java

@@ -47,8 +47,7 @@ public class GraphCalculate {
         int age = searchData.getAge();
         String sex = searchData.getSex();
         logger.info("前端传来的年龄为 :"+age+" 前端传来的性别为 :"+sex);
-        //获取缓存
-//        Map<String, String> lexionCache = CacheUtil.getLexionCache();
+
         Map<String, Map<String, String>> sexAgeCache = CacheUtil.getSexAgeCache();
         Map<String, Map<String, String>> inputs = searchData.getGraphInputs();
         Set<String> ss = new HashSet<>();
@@ -152,16 +151,20 @@ public class GraphCalculate {
                 responseData.setManagementEvaluation(mangementEvaluation1);
             }
         }
-
+        String pacsOrder = searchData.getPacsOrder();
         //指标推送
         if (featureTypeList.contains("22") ) {
+            List<MedicalIndication> pacsMi = getPacsMi(pacsOrder, inputList,webDiag);
             //查找指标
             Set<String> indSet = neo4jAPI.getInd((String[]) inputList.toArray(new String[inputList.size()]));
             logger.info("featureTypeList 包含22,走指标推送!!!,图谱推出的指标为:" + indSet);
             if(indSet.contains("肾功能不全")){
                 List<MedicalIndication> idn = neo4jAPI.getIdn(indSet, age, sex);
-                responseData.setMedicalIndications(idn);
+                pacsMi.addAll(idn);
+                responseData.setMedicalIndications(pacsMi);
             }
+            responseData.setMedicalIndications(pacsMi);
+
         }
 
         //诊断推送
@@ -171,6 +174,39 @@ public class GraphCalculate {
         System.out.println("Total takes: " + (System.currentTimeMillis()-starttime)/1000d + 's');
         return responseData;
     }
+    public List<MedicalIndication> getPacsMi(String pacsOrder,List<String> inputList,String webDiag){
+        if(StringUtils.isNotEmpty(webDiag)){
+            String[] webDiagsplits = webDiag.split(",|,|、|;|:|;");
+            for (String wd:webDiagsplits
+                 ) {
+                inputList.add(wd);
+            }
+        }
+
+        List<MedicalIndication> pacsMi = new ArrayList<>();
+        Map<String, String> newInd = neo4jAPI.getNewInd((String[]) inputList.toArray(new String[inputList.size()]));
+        if(StringUtils.isNotEmpty(pacsOrder)){
+            String[] pacsOrders = pacsOrder.split(",|,");
+            for (String pacs:pacsOrders) {
+                if(newInd.containsKey(pacs)){
+                    String causes = newInd.get(pacs);
+                    MedicalIndication m = new MedicalIndication();
+                    List<MedicalIndicationDetail> mds = new ArrayList<>();
+                    MedicalIndicationDetail medicalIndicationDetail = new MedicalIndicationDetail();
+                    medicalIndicationDetail.setType(4);
+                    JSONObject jsonObject = new JSONObject();
+                    jsonObject.put("name", causes);
+                    jsonObject.put("controlType",2);
+                    medicalIndicationDetail.setContent(jsonObject);
+                    mds.add(medicalIndicationDetail);
+                    m.setName("不建议做:"+pacs);
+                    m.setDetails(mds);
+                    pacsMi.add(m);
+                }
+            }
+        }
+        return pacsMi;
+    }
 //    诊断过滤
     public void filterDis(List<FeatureRate> graphFeatureRates,String sex,Integer age) throws Exception {
         if(neo4jAPI == null){

+ 48 - 1
graph/src/main/java/org/diagbot/graph/jdbc/Neo4jAPI.java

@@ -1146,7 +1146,54 @@ public class Neo4jAPI {
         }
     }
 
-
+    /**
+     * 指标推送,检查预警
+     */
+    public Map<String,String> getNewInd(String[] keys) {
+        //查找指标推送
+        Map<String ,String> indMap = new HashMap<>();
+        List<String> fildList = new ArrayList<>();
+        for (String fild : keys) {
+            fildList.add("\"" + fild.trim() + "\"");
+        }
+        logger.info("根据 " + fildList + " 这些词推送指标!!!");
+        Session session = null;
+        StatementResult result = null;
+        String query = "";
+        try {
+            session = driver.session(AccessMode.WRITE);
+            //第一步查询输入的词所在number
+            query = "match(t:Temporary)-[r:属于]->(n:NewCondition)-[r1:诊断依据]->(n1:NewCondition)-[r2:拟诊]->(n2:NewIndicators) \n" +
+                    "where t.name in "+fildList+" return n2.name as name";
+            System.out.println(query);
+            result = session.run(query);
+            while (result.hasNext()) {
+                Record record = result.next();
+                String newIndName = record.get("name").toString();
+                StringBuffer s = new StringBuffer();
+                query = "match(n2:NewIndicators)-[r:表现]->(t:Temporary) where n2.name="+newIndName+" return collect(t.name) as names";
+                StatementResult sr = session.run(query);
+                while (sr.hasNext()){
+                    Record next = sr.next();
+                    List<Object> names = next.get("names").asList();
+                    if(names.size()>0){
+                        for (Object o:names) {
+
+                            if(fildList.indexOf("\""+o.toString()+"\"") >= 0){
+                                s.append(o.toString().replace("\"", ""));
+                            }
+                        }
+                    }
+                }
+                indMap.put(newIndName.replace("\"", ""),s.toString());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            CloseSession(session);
+            return indMap;
+        }
+    }
     /**
      * 多疾病下治疗方案
      *

+ 2 - 2
graph/src/main/resources/bolt.properties

@@ -5,7 +5,7 @@ pass_235 = diagbot@20180822
 
 # neo4j bolt credentials
 #\u7EBF\u4E0A\u4F7F\u7528
-bolt.uri=bolt://192.168.2.232
+bolt.uri=bolt://192.168.2.234
 bolt.user=neo4j
 bolt.passwd=root
 
@@ -87,7 +87,7 @@ searchDifferentialDiagnose=match(d:Disease)-[r:\u9274\u522B\u8BCA\u65AD]->(h) wh
 searchEmergency=match(d:Disease) where d.name in disList return d.name as emDis,d.emergency as em
 
 #\u67E5\u627E\u6307\u6807\u7684\u8BED\u53E5
-searchIndication=match (n:Condition)-[r:\u786E\u8BCA|:\u62DF\u8BCA]->(m:Indicators)\n \
+    searchIndication=match (n:Condition)-[r:\u786E\u8BCA|:\u62DF\u8BCA]->(m:Indicators)\n \
 where n.name in fildList\n \
 with distinct m,r\n \
 return m.name as name

+ 2 - 2
graphdb/src/main/resources/application.yml

@@ -6,14 +6,14 @@ spring:
     active: local
   data:
     neo4j:
-      uri: bolt://192.168.2.232:7687
+      uri: bolt://192.168.2.234:7687
       username: neo4j
       password: root
 
 # 驱动配置信息
   datasource:
     driver-class-name: org.neo4j.jdbc.Driver
-    url: jdbc:neo4j:http://192.168.2.232:7474
+    url: jdbc:neo4j:http://192.168.2.234:7474
     username: neo4j
     password: root
     #定义初始连接数

+ 40 - 1
nlp/src/main/java/org/diagbot/nlp/util/NlpUtil.java

@@ -2,7 +2,7 @@ package org.diagbot.nlp.util;
 
 import org.diagbot.nlp.participle.word.Lexeme;
 
-import java.util.Arrays;
+import java.util.*;
 
 /**
  * @Auther: fyeman
@@ -11,6 +11,20 @@ import java.util.Arrays;
  */
 public class NlpUtil {
 
+    private static List numtextList = new ArrayList(Arrays.asList("数", "多", "半", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"));
+    private static  Map<String, String> numtextMap = new HashMap<String, String>(){{
+        put("一","1");
+        put("二","2");
+        put("三","3");
+        put("四","4");
+        put("五","5");
+        put("六","6");
+        put("七","7");
+        put("八","8");
+        put("九","9");
+        put("十","10");
+    }};
+
     public static String[] extendsSymbol(String[] origin, String[] extend_symbols) {
         String[] symbols = new String[origin.length + extend_symbols.length];
         System.arraycopy(origin, 0, symbols, 0, origin.length);
@@ -33,6 +47,31 @@ public class NlpUtil {
         return false;
     }
 
+    public static double numberText2value(Lexeme l) {
+        double value = 0.0;
+        if (numtextList.contains(l.getText())) {
+            if ("数".equals(l.getText()) || "多".equals(l.getText())) {     //数年直接按5年处理
+                value = 5;
+            } else if ("半".equals(l.getText())) {
+                value = 0.5;
+            } else {
+                value = Double.valueOf(numtextMap.get(l.getText()));
+            }
+        } else {
+            try {
+                value = Double.valueOf(l.getText());
+            } catch (Exception nfe) {
+                if (l.getText().indexOf("-") > -1) {
+                    try {
+                        value = Double.valueOf(l.getText().split("-")[0]);
+                    } catch (Exception e) {
+                    }
+                }
+            }
+        }
+        return value;
+    }
+
     public static boolean isFeature(String property, NegativeEnum[] features) {
         if (property == null) {
             return false;