Kaynağa Gözat

指标推送从图谱计算获得

kongwz 6 yıl önce
ebeveyn
işleme
3e8084cae9

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

@@ -83,12 +83,15 @@ public class GraphCalculate {
             //查找指标
             Set<String> indSet = neo4jAPI.getInd((String[]) inputList.toArray(new String[inputList.size()]));
             logger.info("featureTypeList 包含22,走指标推送!!!,图谱推出的指标为:" + indSet);
-            List<MedicalIndication> medicalIndicationList = new ArrayList<>();
+            /*List<MedicalIndication> medicalIndicationList = new ArrayList<>();
             MedicalIndication medicalIndication = this.getMedicalIndication(indSet,age,sex);
             if (medicalIndication != null) {
                 medicalIndicationList.add(medicalIndication);
             }
-            responseData.setMedicalIndications(medicalIndicationList);
+            responseData.setMedicalIndications(medicalIndicationList);*/
+            List<MedicalIndication> idn = neo4jAPI.getIdn(indSet, age, sex);
+            responseData.setMedicalIndications(idn);
+
         }
         //诊断推送
         responseData.setDis(featureRates);
@@ -291,7 +294,6 @@ public class GraphCalculate {
             if("F".equals(sex)){
                 womanJson.put("state", 1);
             }
-
             sexList.add(manJson);
             sexList.add(womanJson);
             sexJson.put("details", sexList);
@@ -299,11 +301,6 @@ public class GraphCalculate {
             detailList.add(indicationJsonObject);
             detailList.add(sexJson);
             gongshiJson.put("details", detailList);
-            //            JSONObject resultJson = new JSONObject();
-            //            resultJson.put("value", "");
-            //            resultJson.put("unit", "");
-            //            resultJson.put("text", "");
-            //            gongshiJson.put("result", resultJson);
             medicalIndicationDetail2.setContent(gongshiJson);
             //其他
             MedicalIndicationDetail medicalIndicationDetail3 = new MedicalIndicationDetail();
@@ -334,10 +331,6 @@ public class GraphCalculate {
             result.put("text", "");
             result.put("name", "评估结论");
             resultList.add(result);
-            /*resultJson.put("value", maps.get("value"));
-            resultJson.put("unit", maps.get("unit"));
-            resultJson.put("text", maps.get("text"));
-            gongshiJson.put("result", resultJson);*/
             gongshiJson.put("result", resultList);
             medicalIndicationDetail2.setContent(gongshiJson);
             medicalIndicationDetailList.add(medicalIndicationDetail2);

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

@@ -1269,6 +1269,166 @@ public class Neo4jAPI {
         }
     }
 
+    /**
+     * 推送指标
+     * @param idnSet 指标集
+     * @param age 年龄
+     * @param sex 性别
+     * @return
+     */
+    public List<MedicalIndication> getIdn(Set<String> idnSet,Integer age,String sex){
+        String query="";
+        Session session = null;
+        StatementResult result = null;
+        List<MedicalIndication> medicalIndicationList = new ArrayList<>();
+        if(idnSet !=null && idnSet.size()>0){
+            for (String s:idnSet) {
+                MedicalIndication medicalIndication = new MedicalIndication();
+                List<MedicalIndicationDetail> medicalIndicationDetailList = new ArrayList<>();
+                medicalIndication.setName(s);
+                MedicalIndicationDetail medicalIndicationDetail1 =null;
+                MedicalIndicationDetail medicalIndicationDetail2 =null;
+                MedicalIndicationDetail medicalIndicationDetail3 =null;
+                JSONObject gongshiJson = null;
+                List<JSONObject> detailList =null;
+                List<JSONObject> resultList =null;
+                List<JSONObject> sexList = null;
+                List<JSONObject> shiFouList =null;
+                JSONObject shiFouJson = null;
+                Set<String> results = new HashSet<>();
+                query="match(d:Indicators{name:'"+s+"'})-[r2:内容]->(n:Content) where r2.p=1 \n" +
+                        "return r2.p as sort1 ,n.name as conten,null as sort2,null as item,null as controlType,null as state,null as value,null as uint,null as details\n" +
+                        "union\n" +
+                        "match(d:Indicators{name:'"+s+"'})-[r2:内容]->(n:Content)-[r3:项目]->(i:Item) \n" +
+                        "return r2.p as sort1 ,n.name as conten,r3.p as sort2,i.name as item,i.controlType as controlType,i.state as state,i.value as value,i.uint as uint,i.details as details order by sort1,sort2";
+                session = driver.session(AccessMode.WRITE);
+                result = session.run(query);
+                while (result.hasNext()){
+                    Record next1 = result.next();
+                    int sort1 = next1.get("sort1").asInt();
+                    String conten = next1.get("conten").toString();
+                    String sort2 = next1.get("sort2").toString();
+                    String item = next1.get("item").toString();
+                    String controlType = next1.get("controlType").toString();
+                    String state1 = next1.get("state").toString();
+                    String value = next1.get("value").toString();
+                    String uint = next1.get("uint").toString();
+                    String details = next1.get("details").toString();
+                    System.out.println(sort1+"\t"+conten+"\t"+sort2+"\t"+item+"\t"+controlType+"\t"+value+"\t"+uint+"\t"+details);
+                    if(1==sort1){
+                        if(medicalIndicationDetail1 == null){
+                            medicalIndicationDetail1 = new MedicalIndicationDetail();
+                        }
+                        medicalIndicationDetail1.setType(sort1);
+                        JSONObject liangJson = new JSONObject();
+                        liangJson.put("name", conten.replace("\"",""));
+                        medicalIndicationDetail1.setContent(liangJson);
+                    }
+                    else if(2==sort1){
+                        if(medicalIndicationDetail2 ==null){
+                            medicalIndicationDetail2 = new MedicalIndicationDetail();
+                        }
+                        medicalIndicationDetail2.setType(2);
+                        if(gongshiJson == null){
+                            gongshiJson = new JSONObject();
+                        }
+                        gongshiJson.put("name", conten.replace("\"",""));
+                        if(detailList == null){
+                            detailList = new ArrayList<>();
+                        }
+                        JSONObject ageJsonObject = new JSONObject();
+                        ageJsonObject.put("controlType", Integer.parseInt(controlType));
+                        ageJsonObject.put("name",item.replace("\"","") );
+                        ageJsonObject.put("value", value.replace("\"",""));
+                        ageJsonObject.put("uint", uint.replace("\"",""));
+                        if("年龄".equals(item.replace("\"",""))){
+                            ageJsonObject.put("value", age);
+                        }
+                        if(!"3".equals(controlType)){
+                            ageJsonObject.put("details", details.replace("\"",""));
+                        }else {
+                            String query1="match(i:Item)-[r:详细]->(d:Detail) where i.name="+item+"\n" +
+                                    "return d.name as name,d.state as state,d.value as value order by r.p";
+                            StatementResult run1 = session.run(query1);
+                            if(sexList == null){
+                                sexList = new ArrayList<>();
+                            }
+                            while (run1.hasNext()){
+                                Record next = run1.next();
+                                String name = next.get("name").toString();
+                                int state = next.get("state").asInt();
+                                String value1 = next.get("value").toString();
+                                JSONObject manJson = new JSONObject();
+                                manJson.put("detailName", name.replace("\"",""));
+                                manJson.put("value", value1.replace("\"",""));
+                                manJson.put("state", state);
+                                if( "男".equals(name.replace("\"",""))&&"M".equals(sex)){
+                                    manJson.put("state", 1);
+                                }else if("女".equals(name.replace("\"",""))&&"F".equals(sex)){
+                                    manJson.put("state", 1);
+                                }
+                                sexList.add(manJson);
+                            }
+                            ageJsonObject.put("details", sexList);
+                        }
+                        detailList.add(ageJsonObject);
+                        gongshiJson.put("details", detailList);
+                        if(resultList == null){
+                            resultList = new ArrayList<>();
+                        }
+                        String query2 = "match(c:Content)-[r:结果]->(f:Result) where c.name="+conten+"\n" +
+                                "return f.name as name,f.text as text order by r.p";
+                        StatementResult run1 = session.run(query2);
+                        while (run1.hasNext()){
+                            Record next = run1.next();
+                            String name = next.get("name").toString();
+                            String text = next.get("text").toString();
+                            results.add(name.replace("\"",""));
+                        }
+                    }
+                    else if(3==sort1){
+                        if(medicalIndicationDetail3 ==null){
+                            medicalIndicationDetail3 = new MedicalIndicationDetail();
+                        }
+                        medicalIndicationDetail3.setType(3);
+                        if(shiFouList == null){
+                            shiFouList = new ArrayList<>();
+                        }
+                        if(shiFouJson == null){
+                            shiFouJson = new JSONObject();
+                        }
+                        shiFouJson.put("name", conten.replace("\"",""));
+                        shiFouJson.put("controlType", 0);
+                        JSONObject shiJsonObject = new JSONObject();
+                        shiJsonObject.put("detailName", item.replace("\"",""));
+                        shiJsonObject.put("state", Integer.parseInt(state1));
+                        shiFouList.add(shiJsonObject);
+                        shiFouJson.put("details", shiFouList);
+                        medicalIndicationDetail3.setContent(shiFouJson);
+                    }
+                }
+                for (String re: results
+                        ) {
+                    JSONObject result1 = new JSONObject();
+                    result1.put("name",re);
+                    result1.put("text","");
+                    resultList.add(result1);
+                }
+                gongshiJson.put("result", resultList);
+                medicalIndicationDetail2.setContent(gongshiJson);
+                medicalIndicationDetailList.add(medicalIndicationDetail1);
+                medicalIndicationDetailList.add(medicalIndicationDetail2);
+                medicalIndicationDetailList.add(medicalIndicationDetail3);
+                medicalIndication.setDetails(medicalIndicationDetailList);
+                medicalIndicationList.add(medicalIndication);
+            }
+        }else {
+            medicalIndicationList=null;
+        }
+        CloseSession(session);
+        return medicalIndicationList;
+    }
+
     public Indicators getAdverse(Set<String> dis, String name) {
         List<Detail> detailList1 = new ArrayList<>();
         Indicators indicators1 = new Indicators();