浏览代码

推送高危,判读diag != null

kongwz 6 年之前
父节点
当前提交
1c723f9a86

+ 97 - 0
graph/src/main/java/org/diagbot/graph/jdbc/Neo4jAPI.java

@@ -770,6 +770,103 @@ public class Neo4jAPI {
         }
     }
 
+    /**
+     * 新结构,包含关联词
+     * @param keys
+     * @param webDiag
+     * @return
+     */
+    public Map<String, Map<String,String>> getNewCondition(String[] keys,String webDiag) {
+        Map<String, Map<String,String>> diseaseCondition = new LinkedHashMap<>();
+        List<String> newList = new ArrayList<>();
+        List<String> fildList = new ArrayList<>();
+        List<String> startList = new ArrayList<>();
+        //输出确诊集合
+        Set<String> quezhen = new LinkedHashSet<>();
+        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);
+            logger.info("session 为: " + session);
+            //第一步查询是否有组合的词
+            query = propertiesUtil.getProperty("searchNumColl").replace("startList", fildList.toString());
+            result = session.run(query);
+            while (result.hasNext()) {
+                Record next = result.next();
+                String v = next.get("v").toString();
+                startList.add(v);
+            }
+            newList.addAll(startList);
+            while (newList.size() > 0) {
+                query = propertiesUtil.getProperty("searchNewCondition").replace("newList", newList.toString()).replace("fildList", startList.toString());
+                result = session.run(query);
+                newList.clear();
+                while (result.hasNext()) {
+                    Record record = result.next();
+                    String condition = record.get("condition").toString();
+                    String jundgement = record.get("jundgement").toString();
+                    if ("TRUE".equals(jundgement)) {
+                        newList.add(condition);
+                        startList.add(condition);
+                    }
+                }
+            }
+            //第三步查找确诊
+            query = propertiesUtil.getProperty("searchDis").replace("startList", startList.toString());
+            result = session.run(query);
+            while (result.hasNext()) {
+                Record record = result.next();
+                String quezhenName = record.get("name").toString().replace("\"", "");
+                String conditionType = record.get("relationType").toString().replace("\"", "");
+                if ("确诊".equals(conditionType)) {
+                    quezhen.add(quezhenName);
+                } else if ("拟诊".equals(conditionType)) {
+                    quezhen.add(quezhenName);
+                }
+            }
+            for (String qu : quezhen) {
+                Map<String, String> dis_res = new HashMap<>();
+                dis_res.put("确诊", "");
+//                diseaseCondition.put(qu, JSON.toJSONString(dis_res));
+                diseaseCondition.put(qu,dis_res);
+                logger.info("图谱推出的诊断为: " + qu);
+            }
+            Set<String> queSets = diseaseCondition.keySet();
+            if(webDiag != null && webDiag.trim() != ""){
+                String[] webDiagSplits = webDiag.split(",");
+                String mainDiag = webDiagSplits[0];
+                query = propertiesUtil.getProperty("searchDifferentialDiagnose").replace("mainDis", mainDiag);
+                result = session.run(query);
+                while (result.hasNext()) {
+                    Record record = result.next();
+                    List<Object> coll = record.get("coll").asList();
+                    if(coll != null && coll.size()>0){
+                        for (Object o:coll) {
+                            if(queSets.contains(o.toString().replace("\"",""))){
+                                Map<String, String> stringStringMap = diseaseCondition.get(o.toString().replace("\"", ""));
+                                stringStringMap.put("鉴别诊断","");
+                                diseaseCondition.put(o.toString().replace("\"",""),stringStringMap);
+                            }else {
+                                Map<String, String> diffMap = new HashMap<>();
+                                diffMap.put("鉴别诊断","");
+                                diseaseCondition.put(o.toString().replace("\"",""),diffMap);
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            CloseSession(session);
+            return diseaseCondition;
+        }
+    }
     /**
      * 不良反应推送
      */

+ 21 - 0
graph/src/main/resources/bolt.properties

@@ -42,6 +42,27 @@ where n.name=row\n \
 with distinct m,r\n \
 return m.name as name, labels(m)[0] as label,type(r) as relationType
 
+#\u63A8\u9001\u786E\u8BCA,\u65B0\u7ED3\u6784,\u5305\u542B\u5173\u8054\u8BCD
+#\u67E5\u627E\u8FD9\u4E2A\u8BCD\u5C5E\u4E8E\u54EA\u4E2A\u5E8F\u53F7\u96C6\u5408
+searchNumColl=match(h)-[r:\u5C5E\u4E8E|:\u8BCA\u65AD\u4F9D\u636E]->(c:Condition)\n \
+where h.name in startList\n \
+with c.name as v,count(distinct r)>=c.path as hh\n \
+where hh =true\n \
+return v
+#\u67E5\u627E\u8BCA\u65AD\u4F9D\u636E
+searchNewCondition=with newList as data \n \
+ match (l)-[r:\u8BCA\u65AD\u4F9D\u636E]->(m:Condition)\n \
+where l.name in data \n \
+with m,fildList as data\n \
+match (n)-[r:\u8BCA\u65AD\u4F9D\u636E]->(m:Condition)\n \
+where n.name in data\n \
+return m.name as condition, count(distinct r)>=m.path as jundgement, labels(m)[0] as label\n";
+#\u67E5\u627E\u786E\u8BCA
+searchDis=match (n:Condition)-[r:\u786E\u8BCA|:\u62DF\u8BCA]->(m:Disease)\n \
+where n.name in startList\n \
+with distinct m,r\n \
+return m.name as name, labels(m)[0] as label,type(r) as relationType;
+
 #\u67E5\u627E\u9274\u522B\u8BCA\u65AD\u7684\u8BED\u53E5
 searchDifferentialDiagnose=match(d:Disease)-[r:\u9274\u522B\u8BCA\u65AD]->(h) where d.name='mainDis' return collect(h.name) as coll
 

+ 10 - 7
graphdb/src/main/java/org/diagbot/service/impl/KnowledgeServiceImpl.java

@@ -181,14 +181,17 @@ public class KnowledgeServiceImpl implements KnowledgeService {
 
     @Override
     public Map<String, Object> getHighRiskDisease(SearchData searchData) {
-        String[] splitsDiag = searchData.getDiag().split(",|,|、");
-        List<String> diseaseNameList = Arrays.asList(splitsDiag);
         Map<String, Object> map = new HashMap<>();
-        List<Map<String, Object>> list = baseNodeRepository.getHighRisk(diseaseNameList);
-        for (Map hrmap:list) {
-            String name = hrmap.get("name").toString();
-            String risk = hrmap.get("risk").toString();
-            map.put(name, risk);
+        String diag = searchData.getDiag();
+        if(diag != null && diag != ""){
+            String[] splitsDiag = searchData.getDiag().split(",|,|、");
+            List<String> diseaseNameList = Arrays.asList(splitsDiag);
+            List<Map<String, Object>> list = baseNodeRepository.getHighRisk(diseaseNameList);
+            for (Map hrmap:list) {
+                String name = hrmap.get("name").toString();
+                String risk = hrmap.get("risk").toString();
+                map.put(name, risk);
+            }
         }
         return map;
     }