浏览代码

慢病指标

kongwz 6 年之前
父节点
当前提交
533f65c8d0

+ 22 - 13
graph-web/src/main/java/org/diagbot/graphWeb/work/GraphCalculate.java

@@ -39,6 +39,9 @@ public class GraphCalculate {
         Map<String, Map<String, String>> inputs = searchData.getInputs();
         Set<String> ss = inputs.keySet();
         logger.info("从分词系统接收到的词 :" + ss);
+        String[] featureTypes = searchData.getFeatureType().split(",");
+        List<String> featureTypeList = Arrays.asList(featureTypes);
+        logger.info("featureTypeList : " + featureTypeList);
         inputList.addAll(ss);
         //        Driver driver = DriverManager.newDrive("192.168.2.232", "neo4j", "root");
         Neo4jAPI neo4jAPI = new Neo4jAPI(DriverManager.newDrive());
@@ -47,8 +50,7 @@ public class GraphCalculate {
         Map<String, String> condition = neo4jAPI.getCondition((String[]) inputList.toArray(new String[inputList.size()]));
         List<FeatureRate> featureRates = new ArrayList<>();
         for (Map.Entry<String, String> d : condition.entrySet()) {
-            if (!"低血糖反应".equals(d.getKey()) && !"胃肠道不良反应".equals(d.getKey())
-                    && !"肾功能不全".equals(d.getKey())) {
+            if (!"低血糖反应".equals(d.getKey()) && !"胃肠道不良反应".equals(d.getKey())) {
                 FeatureRate featureRate = new FeatureRate();
                 featureRate.setFeatureName(d.getKey());
                 featureRate.setExtraProperty("");
@@ -59,9 +61,6 @@ public class GraphCalculate {
         }
         String webDiag = searchData.getDiag();
         Set<String> diseaseSet = condition.keySet();
-        String[] featureTypes = searchData.getFeatureType().split(",");
-        List<String> featureTypeList = Arrays.asList(featureTypes);
-        logger.info("featureTypeList : " + featureTypeList);
         logger.info("diseaseSet :" + diseaseSet);
         Integer diseaseType = searchData.getDisType();
         //走治疗
@@ -77,11 +76,15 @@ public class GraphCalculate {
             Map<String, JSONObject> mangementEvaluation1 = mangementEvaluation.getMangementEvaluation();
             responseData.setManagementEvaluation(mangementEvaluation1);
         }
+        int age = searchData.getAge();
+        String sex = searchData.getSex();
         //指标推送
-        if (featureTypeList.contains("22") && diseaseSet != null && diseaseSet.size() > 0) {
-            logger.info("featureTypeList 包含22,走指标推送!!!,图谱推出的诊断为:" + diseaseSet);
+        if (featureTypeList.contains("22") ) {
+            //查找指标
+            Set<String> indSet = neo4jAPI.getInd((String[]) inputList.toArray(new String[inputList.size()]));
+            logger.info("featureTypeList 包含22,走指标推送!!!,图谱推出的指标为:" + indSet);
             List<MedicalIndication> medicalIndicationList = new ArrayList<>();
-            MedicalIndication medicalIndication = this.getMedicalIndication(diseaseSet);
+            MedicalIndication medicalIndication = this.getMedicalIndication(indSet,age,sex);
             if (medicalIndication != null) {
                 medicalIndicationList.add(medicalIndication);
             }
@@ -234,12 +237,12 @@ public class GraphCalculate {
     /**
      * 量表和指标
      *
-     * @param diseaseSet
+     * @param idnSet
      * @return
      */
-    public MedicalIndication getMedicalIndication(Set diseaseSet) throws Exception {
+    public MedicalIndication getMedicalIndication(Set idnSet,Integer age,String sex) throws Exception {
         MedicalIndication medicalIndication = new MedicalIndication();
-        if (diseaseSet.contains("肾功能不全")) {
+        if (idnSet.contains("肾功能不全")) {
             logger.info("diseaseSet中包含肾功能不全");
             //推送指标
             medicalIndication.setName("肾功能不全");
@@ -259,7 +262,7 @@ public class GraphCalculate {
             JSONObject ageJsonObject = new JSONObject();
             ageJsonObject.put("controlType", 2);
             ageJsonObject.put("name", "年龄");
-            ageJsonObject.put("value", "");
+            ageJsonObject.put("value", age);
             ageJsonObject.put("uint", "");
             ageJsonObject.put("details", new ArrayList<>());
             JSONObject indicationJsonObject = new JSONObject();
@@ -278,10 +281,16 @@ public class GraphCalculate {
             manJson.put("detailName", "男");
             manJson.put("value", 1);
             manJson.put("state", 0);
+            if(manJson.get("detailName").equals(sex)){
+                manJson.put("state", 1);
+            }
             JSONObject womanJson = new JSONObject();
             womanJson.put("detailName", "女");
             womanJson.put("value", 1.018);
-            womanJson.put("state", 1);
+            womanJson.put("state", 0);
+            if(womanJson.get("detailName").equals(sex)){
+                womanJson.put("state", 1);
+            }
             sexList.add(manJson);
             sexList.add(womanJson);
             sexJson.put("details", sexList);

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

@@ -738,6 +738,15 @@ public class Neo4jAPI {
                 diseaseCondition.put(qu, JSON.toJSONString(dis_res));
                 logger.info("图谱推出的诊断为: " + qu);
             }
+            //查找指标推送
+            Set<String> indSet = new HashSet<>();
+            query = propertiesUtil.getProperty("searchIndication").replace("fildList", fildList.toString());
+            result = session.run(query);
+            while (result.hasNext()) {
+                Record record = result.next();
+                String indName = record.get("name").toString().replace("\"", "");
+                indSet.add(indName);
+            }
         } catch (Exception e) {
             e.printStackTrace();
         } finally {
@@ -745,6 +754,76 @@ public class Neo4jAPI {
             return diseaseCondition;
         }
     }
+    /**
+     * 指标推送
+     */
+    public Set<String> getInd(String[] keys){
+        //查找指标推送
+        Set<String> indSet = new HashSet<>();
+        List<String> newList = new ArrayList<>();
+        ArrayList<String> fildList = 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("serchCollect").replace("fildList", fildList.toString());
+            result = session.run(query);
+            while (result.hasNext()) {
+                Record record = result.next();
+                String fild = record.get("fild").toString();
+                List<Object> typeCollect = record.get("typeCollect").asList();
+                //如果不包含诊断依据就找它的同义词,否则就要这个词
+                if ("近义词".equals(typeCollect.get(0)) && typeCollect.size() == 1) {
+                    query = "match(l)-[r:近义词]->(h) where l.name=" + fild + " return h.name as js";
+                    StatementResult jinyiResult = session.run(query);
+                    while (jinyiResult.hasNext()) {
+                        Record next = jinyiResult.next();
+                        String js = next.get("js").toString();
+                        fildList.remove(fild);
+                        fildList.add(js);
+                    }
+                }
+            }
+            newList.addAll(fildList);
+            int i = 0;
+            while (newList.size() > 0) {
+                i++;
+                query = propertiesUtil.getProperty("searchCondition").replace("newList", newList.toString()).replace("fildList", fildList.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();
+                    String label = record.get("label").toString();
+                    if ("TRUE".equals(jundgement)) {
+                        newList.add(condition);
+                        fildList.add(condition);
+                    }
+                }
+            }
+            query = propertiesUtil.getProperty("searchIndication").replace("fildList", fildList.toString());
+            result = session.run(query);
+            while (result.hasNext()) {
+                Record record = result.next();
+                String indName = record.get("name").toString().replace("\"", "");
+                indSet.add(indName);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            CloseSession(session);
+            return indSet;
+        }
+    }
 
     /**
      * 新的诊断逻辑

+ 8 - 1
graph/src/main/resources/bolt.properties

@@ -37,7 +37,14 @@ where n.name= row\n \
 return m.name as condition, count(distinct r)>=m.path as jundgement, labels(m)[0] as label
 #\u67E5\u627E\u786E\u8BCA,\u62DF\u8BCA\u7684\u8BED\u53E5
 searchQuezhen=with fildList  as data unwind data as row\n \
-match (n)-[r:\u786E\u8BCA|:\u62DF\u8BCA]->(m)\n \
+match (n)-[r:\u786E\u8BCA|:\u62DF\u8BCA]->(m:Disease)\n \
+where n.name=row\n \
+with distinct m,r\n \
+return m.name as name, labels(m)[0] as label,type(r) as relationType
+
+#\u67E5\u627E\u6307\u6807\u7684\u8BED\u53E5
+searchIndication=with fildList  as data unwind data as row\n \
+match (n)-[r:\u786E\u8BCA|:\u62DF\u8BCA]->(m:Indicators)\n \
 where n.name=row\n \
 with distinct m,r\n \
 return m.name as name, labels(m)[0] as label,type(r) as relationType