浏览代码

新结构治疗方案推送

kongwz 5 年之前
父节点
当前提交
1cb212241d

+ 15 - 5
graph-web/src/main/java/org/diagbot/graphWeb/work/GraphCalculate.java

@@ -19,6 +19,7 @@ import javax.servlet.http.HttpServletRequest;
 import java.util.*;
 
 import org.diagbot.nlp.rule.module.PreResult;
+import org.diagbot.nlp.util.Constants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -73,8 +74,10 @@ public class GraphCalculate {
         //计算诊断
         Map<String, Object> condition =null;
         Map<String, Map<String, String>> excludelist = null;
-        if(featureTypeList.contains("2")){
+        starttime = System.currentTimeMillis();
+        if(featureTypeList.contains(Constants.feature_type_diag)){
             condition = neo4jAPI.getNewCondition((String[]) inputList.toArray(new String[inputList.size()]),webDiag );
+            System.out.println("推送诊断消耗:"+(System.currentTimeMillis()-starttime)+"s");
             // 查找需要排除的诊断
             excludelist = neo4jAPI.getExcludeDiag(inputList);
             responseData.setExcludeDiag(Arrays.asList(excludelist.keySet().stream().toArray(String[]::new)));
@@ -127,32 +130,38 @@ public class GraphCalculate {
             }
         }
         logger.info("页面导入的所有化验项为 :" +lisSet);
+        starttime = System.currentTimeMillis();
         //走治疗
-        if (StringUtils.isNotEmpty(diseaseName) && featureTypeList.contains("6")) {
+        if (StringUtils.isNotEmpty(diseaseName) && featureTypeList.contains(Constants.feature_type_treat)) {
             // 查找页面诊断里是否有不良反应
             Map<String, List<String>> disUE = neo4jAPI.getDisUE(diseaseName, diseaseType);
             //根据页面输入内容推出的不良反应集合
             Set<String> ue = neo4jAPI.getUe((String[]) inputList.toArray(new String[inputList.size()]));
             //走平常诊断治疗
-            Map<String, Filnlly> mulDiseaseTreat = neo4jAPI.getMulDiseaseTreat_2(diseaseName,webDiag, diseaseType, diseaseSet,disUE,ue,String.join(",", inputList));
-            responseData.setTreat(mulDiseaseTreat);
+//            Map<String, Filnlly> mulDiseaseTreat = neo4jAPI.getMulDiseaseTreat_2(diseaseName,webDiag, diseaseType, diseaseSet,disUE,ue,String.join(",", inputList));
+            Map<String, Filnlly> mulDiseaseTreat_new = neo4jAPI.getMulDiseaseTreat_new(diseaseName,webDiag, diseaseType, diseaseSet,disUE,ue,String.join(",", inputList));
+            System.out.println("推送治疗消耗:"+(System.currentTimeMillis()-starttime)+"s");
+            responseData.setTreat(mulDiseaseTreat_new);
         }
         //管理评估(慢病才有)
         if (featureTypeList.contains("11") && diseaseType == 1 && diseaseType != null) {
             logger.info("featureTypeList 包含11,走管理评估!!!");
+            starttime = System.currentTimeMillis();
             if(webDiag != null){
                 MangementEvaluation mangementEvaluation = neo4jAPI.pushMe(webDiagList,lis_Result);
+                System.out.println("推送管理评估消耗:"+(System.currentTimeMillis()-starttime)+"s");
                 Map<String, JSONObject> mangementEvaluation1 = mangementEvaluation.getMangementEvaluation();
                 responseData.setManagementEvaluation(mangementEvaluation1);
             }
         }
         //指标推送
         if (featureTypeList.contains("22") ) {
+            starttime = System.currentTimeMillis();
             List<MedicalIndication> idns =new ArrayList<>();
             Set<String> newindSet = new HashSet<>();
             Set<String> newindSet1 = new HashSet<>();
             //查找指标
-            Set<String> indSet = neo4jAPI.getInd((String[]) inputList.toArray(new String[inputList.size()]),sex,age);
+            Set<String> indSet = neo4jAPI.getInd((String[]) inputList.toArray(new String[inputList.size()]),sex,age,webDiagList);
             if(indSet != null && indSet.size()>0){
                 for (String ind:indSet) {
                     if("肾功能不全".equals(ind)){
@@ -193,6 +202,7 @@ public class GraphCalculate {
                     idns.add(medicalIndication);
                 }
             }
+            System.out.println("推送指标消耗:"+(System.currentTimeMillis()-starttime)+"s");
             responseData.setMedicalIndications(idns);
         }
         //诊断推送

+ 165 - 30
graph/src/main/java/org/diagbot/graph/jdbc/Neo4jAPI.java

@@ -874,7 +874,7 @@ public class Neo4jAPI {
     /**
      * 指标推送
      */
-    public Set<String> getInd(String[] keys,String sex,int age) {
+    public Set<String> getInd(String[] keys,String sex,int age,String[] webDiagList) {
         //查找指标推送
         Set<String> indSet = new HashSet<>();
         List<String> newList = new ArrayList<>();
@@ -883,6 +883,10 @@ public class Neo4jAPI {
         for (String fild : keys) {
             fildList.add("\"" + fild.trim() + "\"");
         }
+        for (String diag:webDiagList
+             ) {
+            fildList.add("\"" + diag + "\"");
+        }
         logger.info("根据 " + fildList + " 这些词推送指标!!!");
         Session session = null;
         StatementResult result = null;
@@ -989,34 +993,7 @@ public class Neo4jAPI {
         nf.setMinimumFractionDigits(0);//设置该百分比数字,保留2位小数;
         nf.setRoundingMode(RoundingMode.HALF_UP); //设置满5向上进位,即四舍五入;
         Map<String, String> resultMap = new HashMap<>();
-        String[] diseaseArray = disease.split(",|,|、|;|:|;");
-        List<String> diseaseList = new ArrayList<>();//诊断数组
-        for (int i = 0; i < diseaseArray.length; i++) {
-            diseaseList.add(diseaseArray[i]);
-        }
-        Map<String, ArrayList> diseFilds = new HashMap<>();
-//        for (int i = 0; i < diseaseList.size(); i++) {
-            String[] fildsArray = filds.split(",");
-            ArrayList<String> fildsList = new ArrayList<>();//其他条件数组
-            for (String fild : fildsArray) {
-                fildsList.add("\'" + fild + "\'");
-            }
-            if(disSet != null && disSet.size()>0){
-                for (String yizhen : disSet) {
-                    fildsList.add("\'" + yizhen + "\'");
-                }
-            }
-
-            for (String h : ueSet) {
-                fildsList.add("\'" + h + "\'");
-            }
-           /* for (int j = 0; j < diseaseList.size(); j++) {
-                if (i != j) {
-                    fildsList.add("\'" + diseaseList.get(j) + "\'");
-                }
-            }*/
-
-            diseFilds.put(disName, fildsList);
+        Map<String, ArrayList> diseFilds = getdisFilds(disName, disease, disSet, ueSet, filds);
 //        }
         try {
             session = driver.session(AccessMode.WRITE);
@@ -1210,6 +1187,163 @@ public class Neo4jAPI {
             return diagTreat;
         }
     }
+    public Map<String,Filnlly> getMulDiseaseTreat_new(String disName,String disease, Integer diseaseType, Set<String> disSet, Map<String, List<String>> disUE, Set<String> ueSet, String filds) {
+        Map<String,Filnlly> newTret = new HashMap<>();
+        Session session = null;
+        Map<String, ArrayList> diseFilds = getdisFilds(disName, disease, disSet, ueSet, filds);
+        try{
+            session = driver.session(AccessMode.WRITE);
+            Integer integer = session.writeTransaction(new TransactionWork<Integer>() {
+                @Override
+                public Integer execute(Transaction tx) {
+                    StatementResult result = null;
+                    String query = "";
+                    if(diseFilds != null && diseFilds.size()>0){
+                        for (Map.Entry<String, ArrayList> df : diseFilds.entrySet()) {
+                            //大对象集合
+                            ArrayList<Drugs> drugsList = new ArrayList<Drugs>();
+
+                            Map<String,String> medicaton_ji = new HashMap<>();//药的忌用和慎用集合
+                            Map<String,List<String>> medicatonMap = new LinkedHashMap<>();//全部的药集合
+                            String diseaseName = df.getKey();//疾病
+                            ArrayList value = df.getValue();//其他条件
+                            query = propertiesUtil.getProperty("searchTreat").replace("disName","\'"+diseaseName+"\'").replace("filds",value.toString());
+                            logger.info("查找诊断对应的类和药物,包括类的排序,查找语句为:\n"+query);
+                            result = tx.run(query);
+                            while (result.hasNext()) {
+                                Record record = result.next();
+                                String big = record.get("big").toString().replace("\"", "");
+                                String sub = record.get("sub").toString().replace("\"", "");
+                                String med = record.get("med").toString().replace("\"", "");
+                                String ty = record.get("ty").toString().replace("\"","");
+                                if ("NULL".equals(ty)){
+                                    if(medicatonMap.containsKey(big+"$"+sub)){
+                                        List<String> ml = medicatonMap.get(big + "$" + sub);
+                                        ml.add(med);
+                                        medicatonMap.put(big+"$"+sub,ml);
+                                    }else {
+                                        List<String> ml = new ArrayList<>();
+                                        ml.add(med);
+                                        medicatonMap.put(big+"$"+sub,ml);
+                                    }
+                                }else {
+                                    if(medicaton_ji.containsKey(med)){
+                                        if(medicaton_ji.get(med).equals("慎用") && ty.equals("忌用")){
+                                            medicaton_ji.put(med,"忌用");
+                                        }
+                                    }else {
+                                        medicaton_ji.put(med,ty);
+                                    }
+                                }
+                            }
+                            if(medicatonMap != null && medicatonMap.size()>0){
+                                for (Map.Entry<String,List<String>> fd:medicatonMap.entrySet()) {
+                                    int i = 0;
+                                    String big = "",sub="";
+                                    String big_sub = fd.getKey();//大小类
+                                    List<String> medications = fd.getValue();//药的集合
+                                    String[] splits = big_sub.split("\\$");
+                                    Drugs drugs = new Drugs();
+                                    if(splits[0].equals(splits[1])){
+                                        sub = "";
+                                        big = splits[0];
+                                    }else {
+                                        big = splits[0];
+                                        sub = splits[1];
+                                    }
+                                    LinkedList<Medicition> mes = new LinkedList<>();
+                                    if(medications != null && medications.size()>0){
+                                        for (String m:medications) {
+                                            Medicition medicition = new Medicition();
+                                            medicition.setMedicitionName(m);
+                                            if(medicaton_ji.containsKey(m)){
+                                                String s = medicaton_ji.get(m);
+                                                if(s.equals("忌用")){
+                                                    medicition.setForbidden(2);
+                                                }else {
+                                                    medicition.setForbidden(1);
+                                                }
+                                            }else {
+                                                medicition.setForbidden(0);
+                                            }
+                                            if(i<3){
+                                                medicition.setIsShow(1);
+                                                i++;
+                                            }else {
+                                                medicition.setIsShow(0);
+                                            }
+                                            mes.add(medicition);
+                                        }
+                                    }
+                                    drugs.setBigdrugsName(big);
+                                    drugs.setSubdrugsName(sub);
+                                    drugs.setDrugsForbidden(0);
+                                    drugs.setMedicitionsList(mes);
+                                    drugsList.add(drugs);
+                                }
+                            }
+                            Filnlly filnlly = new Filnlly();
+                            //显示不良反应
+                            if (diseaseType != null && 1 == diseaseType) {
+                                List<String> stringList = disUE.get(diseaseName);
+                                logger.info(diseaseName + "下面有" + stringList + "不良反应");
+                                if (stringList != null && stringList.size() > 0) {
+                                    List<Indicators> indicatorsList1 = new ArrayList<>();
+                                    for (String de : stringList) {
+                                        Indicators indicators1 = getAdverse(ueSet, de);
+                                        logger.info(disSet + "包含  " + de);
+                                        indicatorsList1.add(indicators1);
+                                    }
+                                    filnlly.setAdverseEvent(indicatorsList1);
+                                }
+                            }
+                            filnlly.setTreatment(drugsList);
+                            newTret.put(diseaseName, filnlly);
+                        }
+                    }
+                    return 1;
+                }
+            });
+        }catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            CloseSession(session);
+            return newTret;
+        }
+    }
+
+    /**
+     * 治疗方案,取每个诊断对应的filds
+     * @param disName
+     * @param disease
+     * @param disSet
+     * @param ueSet
+     * @param filds
+     * @return
+     */
+    private Map<String, ArrayList> getdisFilds(String disName, String disease, Set<String> disSet, Set<String> ueSet, String filds) {
+        String[] diseaseArray = disease.split(",|,|、|;|:|;");
+        List<String> diseaseList = new ArrayList<>();//诊断数组
+        for (int i = 0; i < diseaseArray.length; i++) {
+            diseaseList.add(diseaseArray[i]);
+        }
+        Map<String, ArrayList> diseFilds = new HashMap<>();
+        String[] fildsArray = filds.split(",");
+        ArrayList<String> fildsList = new ArrayList<>();//其他条件数组
+        for (String fild : fildsArray) {
+            fildsList.add("\'" + fild + "\'");
+        }
+        if(disSet != null && disSet.size()>0){
+            for (String yizhen : disSet) {
+                fildsList.add("\'" + yizhen + "\'");
+            }
+        }
+        for (String h : ueSet) {
+            fildsList.add("\'" + h + "\'");
+        }
+        diseFilds.put(disName, fildsList);
+        return diseFilds;
+    }
 
     /**
      * 推送指标
@@ -1523,7 +1657,7 @@ public class Neo4jAPI {
                 bigGrad.put("details", gradItemJ);
                 gradItemJson.add(bigGrad);
                 gradeJson.put("rows", gradItemJson);
-                mangementMap.put("疗效评估", curativeJson);
+                mangementMap.put("风险因素评估", curativeJson);
                 mangementMap.put("糖尿病分级管理", gradeJson);
                 mangementEvaluation.setMangementEvaluation(mangementMap);
 //            }
@@ -2267,4 +2401,5 @@ public class Neo4jAPI {
         }
     }
 
+
 }

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

@@ -5,9 +5,9 @@ pass_235 = diagbot@20180822
 
 # neo4j bolt credentials
 #\u7EBF\u4E0A\u4F7F\u7528
-bolt.uri=bolt://192.168.2.233
+bolt.uri=bolt://192.168.3.180
 bolt.user=neo4j
-bolt.passwd=root
+bolt.passwd=123456
 
 
 #\u6D4B\u8BD5\u4F7F\u7528
@@ -22,9 +22,6 @@ match (n)-[r:\u5C5E\u4E8E]->(m)-[r1:\u7EC4\u5408]->(k) \n \
 where n.name= row \n \
 return m.name as condition, count(distinct r)>=m.path as jundgement, labels(m)[0] as label,k.name as standName
 
-searchCollection1=match (n)-[r:\u5C5E\u4E8E]->(m)-[r1:\u7EC4\u5408]->(k) \n \
-where n.name in fildList \n \
-return m.name as condition, count(distinct r)>=m.path as jundgement, labels(m)[0] as label,k.name as standName
 #\u67E5\u627E\u8FD1\u4E49\u8BCD\u7CBE\u534E\u7248
 serchCollect=match (n)-[r:\u8BCA\u65AD\u4F9D\u636E|:\u8FD1\u4E49\u8BCD]->(e) where n.name in fildList return n.name as fild,collect(distinct type(r)) as typeCollect
 #\u67E5\u627E\u80FD\u63A8\u51FA\u8BCA\u65AD\u4F9D\u636E\u7684\u8BCD
@@ -36,14 +33,6 @@ match (n)-[r:\u8BCA\u65AD\u4F9D\u636E]->(m)\n \
 where n.name= row\n \
 return m.name as condition, count(distinct r)>=m.path as jundgement, labels(m)[0] as label
 
-searchCondition1=match (l)-[r:\u8BCA\u65AD\u4F9D\u636E]->(m)\n \
-where l.name in newList\n \
-with m,fildList as data\n \
-match (n)-[r:\u8BCA\u65AD\u4F9D\u636E]->(m)\n \
-where n.name in data\n \
-with m.name as condition, count(distinct r) as sd,m.path as jundgement\n \
-where sd>=jundgement\n \
-return condition
 #\u67E5\u627E\u786E\u8BCA,\u62DF\u8BCA\u7684\u8BED\u53E5
 searchQuezhen=match (n)-[r:\u786E\u8BCA|:\u62DF\u8BCA]->(m:Disease)\n \
 where n.name in fildList\n \
@@ -53,7 +42,8 @@ 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 \
+where (h:Symptom or h:Vital or h:LISResult or h:PACSResult or h:History or h:Other or h:Cause or h:Prognosis or h:PrevailHistory or h:Disease or h:Indicators or h:UntowardEffect) and \
+ h.name in startList\n \
 with c.name as v,count(distinct r)>=c.path as hh\n \
 where hh =true\n \
 return v
@@ -100,12 +90,27 @@ where n.name in fildList\n \
 with distinct m,r\n \
 return m.name as name
 
-#\u67E5\u627E\u4E00\u4E9B\u8BCD\u662F\u5426\u5728\u56FE\u8C31\u4E2D
-searchWords=match(d) where d.name in fildList return distinct d.name as name
 #\u6839\u636E\u75BE\u75C5\u67E5\u627E\u76F8\u5E94\u7684Lis Pacs
 serchLisPacs=unwind disList as row \n \
   match (d:Disease)-[r1:\u63A8\u8350|:\u8868\u73B0]->(m) where d.name=row return  labels(m)[0] as label,m.name as name
 
+# \u65B0\u7ED3\u6784\u6CBB\u7597\u67E5\u8BE2
+searchTreat=match(h:Disease{name:disName})-[r:\u6CBB\u7597\u65B9\u6848]->(t:Treat)-[r2:\u63A8\u8350]->(m:Medicine)-[r1:\u5C5E\u4E8E]->(d:Drugs)\n \
+with t,m,d\n \
+match(t)-[r:\u63A8\u8350]->(m)-[r1:\u5C5E\u4E8E]->(h:Drugs)\n \
+where d.name=h.bigDrugs \n \
+with t,m,d,h\n \
+match(m)<-[R:\u614E\u7528|:\u5FCC\u7528]-(i) where i.name in filds\n \
+return t.name as treat,d.name as big,h.name as sub,m.name as med,type(R) as ty\n \
+order by h.p\n \
+union\n \
+match(h:Disease{name:disName})-[r:\u6CBB\u7597\u65B9\u6848]->(t:Treat)-[r2:\u63A8\u8350]->(m:Medicine)-[r1:\u5C5E\u4E8E]->(d:Drugs)\n \
+with t,m,d\n \
+match(t)-[r:\u63A8\u8350]->(m)-[r1:\u5C5E\u4E8E]->(h:Drugs)\n \
+where d.name=h.bigDrugs and h.p<6 \n \
+return t.name as treat,d.name as big,h.name as sub, m.name as med,null as ty\n \
+order by h.p
+
 #\u66F4\u65B0\u8BCA\u65AD\u4F9D\u636E\u7684path
 updateConditionPath=match (n:Condition)<-[:\u8BCA\u65AD\u4F9D\u636E]-(m) \n \
           with n,\n \