Prechádzať zdrojové kódy

量表结构接口添加indexId属性

hujing 6 rokov pred
rodič
commit
b9d4dd2f60

+ 92 - 69
graph/src/main/java/org/diagbot/graph/jdbc/Neo4jAPI.java

@@ -42,9 +42,10 @@ public class Neo4jAPI {
     public Neo4jAPI(Driver driver) {
         this.driver = driver;
     }
-//    public Neo4jAPI() {
-//
-//    }
+    //    public Neo4jAPI() {
+    //
+    //    }
+
     /**
      * 获取所有标签名称
      *
@@ -654,13 +655,13 @@ public class Neo4jAPI {
         for (String fild : keys) {
             fildList.add("\"" + fild.trim() + "\"");
         }
-        logger.info("根据 "+fildList+" 这些词推送图谱诊断!!!");
+        logger.info("根据 " + fildList + " 这些词推送图谱诊断!!!");
         Session session = null;
         StatementResult result = null;
         String query = "";
         try {
             session = driver.session(AccessMode.WRITE);
-            logger.info("session 为: "+session);
+            logger.info("session 为: " + session);
             //第一步查询是否有组合的词
             query = propertiesUtil.getProperty("searchCollection").replace("fildList", fildList.toString());
             result = session.run(query);
@@ -735,7 +736,7 @@ public class Neo4jAPI {
                 Map<String, String> dis_res = new HashMap<>();
                 dis_res.put("确诊", "");
                 diseaseCondition.put(qu, JSON.toJSONString(dis_res));
-                logger.info("图谱推出的诊断为: "+qu);
+                logger.info("图谱推出的诊断为: " + qu);
             }
         } catch (Exception e) {
             e.printStackTrace();
@@ -969,7 +970,7 @@ public class Neo4jAPI {
      * @param filds   //     * @param sign 标志,2是平常诊断的治疗,0是复诊诊断的治疗,1是急诊
      * @return
      */
-    public Map<String, Filnlly> getMulDiseaseTreat_2(String disease,Integer diseaseType,Set<String> disSet, String filds) {
+    public Map<String, Filnlly> getMulDiseaseTreat_2(String disease, Integer diseaseType, Set<String> disSet, String filds) {
         Map<String, Filnlly> diagTreat = new HashMap<>();
         Session session = null;
         NumberFormat nf = NumberFormat.getPercentInstance();
@@ -988,7 +989,7 @@ public class Neo4jAPI {
             for (String fild : fildsArray) {
                 fildsList.add("\'" + fild + "\'");
             }
-            for (String yizhen:disSet) {
+            for (String yizhen : disSet) {
                 fildsList.add("\'" + yizhen + "\'");
             }
             for (int j = 0; j < diseaseList.size(); j++) {
@@ -1164,12 +1165,12 @@ public class Neo4jAPI {
                         }
                         Filnlly filnlly = new Filnlly();
                         //显示不良反应
-                        if(diseaseType !=null && 1 == diseaseType){
+                        if (diseaseType != null && 1 == diseaseType) {
                             List<Indicators> indicatorsList1 = new ArrayList<>();
                             Indicators indicators1 = getAdverse(disSet, "低血糖反应");
-                            logger.info(disSet+"包含  低血糖反应");
+                            logger.info(disSet + "包含  低血糖反应");
                             Indicators indicators2 = getAdverse(disSet, "胃肠道不良反应");
-                            logger.info(disSet+"包含  胃肠道不良反应");
+                            logger.info(disSet + "包含  胃肠道不良反应");
                             indicatorsList1.add(indicators1);
                             indicatorsList1.add(indicators2);
                             filnlly.setAdverseEvent(indicatorsList1);
@@ -1184,11 +1185,12 @@ public class Neo4jAPI {
             e.printStackTrace();
         } finally {
             CloseSession(session);
-//            driver.close();
+            //            driver.close();
             return diagTreat;
         }
     }
-    public Indicators getAdverse(Set<String> dis,String name){
+
+    public Indicators getAdverse(Set<String> dis, String name) {
         List<Detail> detailList1 = new ArrayList<>();
         Indicators indicators1 = new Indicators();
         indicators1.setName(name);
@@ -1199,10 +1201,10 @@ public class Neo4jAPI {
         Detail detail2 = new Detail();
         detail2.setName("是");
         detail2.setValue(0);
-        if(dis.contains(name)){
+        if (dis.contains(name)) {
             detail2.setValue(1);
         }
-        logger.info("有"+name+" 标记为是!!!!");
+        logger.info("有" + name + " 标记为是!!!!");
         Detail detail3 = new Detail();
         detail3.setName("轻度");
         detail3.setValue(0);
@@ -1228,6 +1230,7 @@ public class Neo4jAPI {
         indicators1.setDetails(detailList1);
         return indicators1;
     }
+
     /**
      * 倒推实现
      *
@@ -1812,10 +1815,11 @@ public class Neo4jAPI {
 
     /**
      * 获取量表
+     *
      * @param scaleName
      * @return
      */
-    public Map<String, Object> getScaleCalc2(String[] scaleItems,String scaleName) {
+    public Map<String, Object> getScaleCalc2(String[] scaleItems, String scaleName) {
         Session session = driver.session(AccessMode.READ);
         StatementResult Rset = null;
         Record rec;
@@ -1830,22 +1834,21 @@ public class Neo4jAPI {
 
         try {
             String query = "match (m:Scale)-[r1]->(n1)-[r2]->(n2)-[r3]->(n3)-[r4]->(n4) " +
-                    "WHERE m.name=~'.*"+scaleName+".*' " +
+                    "WHERE m.name=~'.*" + scaleName + ".*' " +
                     "return m.name,m.calc,m.type,m.titleName,n1.name,n1.isShow,r2.mutex as r2mutex,n2.name," +
                     "n2.required as n2required,n3.name as n3name,n3.coefficient as n3coefficient," +
-                    "n3.constant as n3constant,n3.controlType as n3controlType, r4.score as r4score," +
+                    "n3.constant as n3constant,n3.controlType as n3controlType,n3.indexId as n3indexId, r4.score as r4score," +
                     "n4.name as n4name order by toInt(r1.p),toInt(r2.p),toInt(r3.p),toInt(r4.p) " +
                     "union " +
-                    "match (m:Scale)-[r1]->(n1:Method)-[r2]->(n2) WHERE m.name=~'.*"+scaleName+".*' " +
+                    "match (m:Scale)-[r1]->(n1:Method)-[r2]->(n2) WHERE m.name=~'.*" + scaleName + ".*' " +
                     "return m.name,m.calc,m.type,m.titleName,n1.name,n1.isShow,r2.score as r2mutex,n2.name,null as n2required," +
-                    "null as n3name,null as n3coefficient,null as n3constant,null as n3controlType,null as r4score, " +
+                    "null as n3name,null as n3coefficient,null as n3constant,null as n3controlType,null as n3indexId,null as r4score, " +
                     "null as n4name order by toInt(r2.p)";
             Rset = session.run(query);
 
             String calc = "";
             String type = "";
             String group = "";
-            String titleName = "";
             String isShow = "";
             String text = "";
             String mutex = "";
@@ -1853,6 +1856,7 @@ public class Neo4jAPI {
             String coefficient = "";
             String constant = "";
             String controlType = "";
+            String indexId = "";
             String score = "";
             String option = "";
             String index = "";
@@ -1862,7 +1866,6 @@ public class Neo4jAPI {
                 scaleName = rec.get("m.name").toString().replace("\"", "");
                 calc = rec.get("m.calc").toString().replace("\"", "");
                 type = rec.get("m.type").toString().replace("\"", "");
-                titleName = rec.get("m.titleName").toString().replace("\"", "");
                 group = rec.get("n1.name").toString().replace("\"", "");
                 isShow = rec.get("n1.isShow").toString().replace("\"", "");
                 text = rec.get("n2.name").toString().replace("\"", "");
@@ -1872,26 +1875,27 @@ public class Neo4jAPI {
                 coefficient = rec.get("n3coefficient").toString().replace("\"", "");//系数
                 constant = rec.get("n3constant").toString().replace("\"", "");//常数
                 controlType = rec.get("n3controlType").toString().replace("\"", "");
+                indexId = rec.get("n3indexId").toString().replace("\"", "");
                 score = rec.get("r4score").toString().replace("\"", "");
                 option = rec.get("n4name").toString().replace("\"", "");
 
                 //标题
-                List<Object> titles = new ArrayList<>();
-                JSONObject title = new JSONObject();
-                title.put("name", titleName);
-                title.put("column", "name");
-                titles.add(title);
-                title = new JSONObject();
-                title.put("name", "临床症状");
-                title.put("column", "detailName");
-                titles.add(title);
-                title = new JSONObject();
-                title.put("name", "得分");
-                title.put("column", "score");
-                titles.add(title);
-                JSONObject titleJson = new JSONObject();
-                titleJson.put("columns", titles);
-                titleJson.put("isShow", 0);
+                //                List<Object> titles = new ArrayList<>();
+                //                JSONObject title = new JSONObject();
+                //                title.put("name", titleName);
+                //                title.put("column", "name");
+                //                titles.add(title);
+                //                title = new JSONObject();
+                //                title.put("name", "临床症状");
+                //                title.put("column", "detailName");
+                //                titles.add(title);
+                //                title = new JSONObject();
+                //                title.put("name", "得分");
+                //                title.put("column", "score");
+                //                titles.add(title);
+                //                JSONObject titleJson = new JSONObject();
+                //                titleJson.put("columns", titles);
+                //                titleJson.put("isShow", 0);
 
                 //分组计算结果
                 JSONObject groupCalcJson = new JSONObject();
@@ -1900,15 +1904,19 @@ public class Neo4jAPI {
                 groupCalcResult.put("unit", "");
                 groupCalcResult.put("text", "");
                 groupCalcJson.put("result", groupCalcResult);
-                groupCalcJson.put("isShow", 0);
-
-                scaleStructure.put("scaleType", Integer.valueOf(type));
-                scaleStructure.put("scaleName", scaleName);
+                groupCalcJson.put("isShow", Integer.valueOf(isShow));
+                if (!scaleStructure.containsKey("scaleType")) {
+                    scaleStructure.put("scaleType", Integer.valueOf(type));
+                }
+                if (!scaleStructure.containsKey("scaleName")) {
+                    scaleStructure.put("scaleName", scaleName);
+                }
                 if (!scaleStructure.containsKey("group")) {
                     scaleStructure.put("group", new JSONArray());
                 }
-                scaleStructure.put("Calc",Integer.valueOf(calc));
-
+                if (!scaleStructure.containsKey("Calc")) {
+                    scaleStructure.put("Calc", Integer.valueOf(calc));
+                }
                 if (group.contains("计算方法")) {
                     String[] range = mutex.split("~|-");
                     String min = range[0];
@@ -1937,10 +1945,10 @@ public class Neo4jAPI {
                 }
                 if (groupList.size() == 0 || existGroup == false) {
                     groupItem.put("groupName", group);
-                    if (group.equals("感觉损伤")) {
-                        titleJson.put("isShow", Integer.valueOf(isShow));
-                    }
-                    groupItem.put("title", titleJson);
+                    //                    if (group.equals("感觉损伤")) {
+                    //                        titleJson.put("isShow", Integer.valueOf(isShow));
+                    //                    }
+                    //                    groupItem.put("title", titleJson);
                     groupItem.put("groupCalculate", groupCalcJson);
                 }
 
@@ -1951,6 +1959,7 @@ public class Neo4jAPI {
                     rowsList = JSONArray.parseArray(groupItem.get("rows").toString());
                 }
 
+
                 Boolean existRow = false;
                 for (int j = 0; j < rowsList.size(); j++) {
                     JSONObject rowJson = rowsList.getJSONObject(j);
@@ -1960,6 +1969,7 @@ public class Neo4jAPI {
                     } else {
                         rowJson.put("metux", Integer.valueOf(mutex));
                         rowJson.put("required", Integer.valueOf(required));
+                        rowJson.put("indexId", Integer.valueOf(indexId));
                         rowJson.put("row", rowList);
                     }
                     for (int i = 0; i < rowList.size(); i++) {
@@ -1970,23 +1980,31 @@ public class Neo4jAPI {
                                 JSONObject rowDetail = new JSONObject();
                                 rowDetail.put("detailName", option);
                                 rowDetail.put("score", Integer.valueOf(score));
-                                JSONArray scaleItem = (JSONArray) JSONArray.toJSON(scaleItems);
-                                for (int k = 0; k < scaleItem.size(); k++) {
-                                    if (scaleItem.get(k).toString().contains(row.getString("name"))){
-                                        if (scaleItem.get(k).toString().contains(option)){
-                                            rowDetail.put("state", 1);
-                                            scaleItem.remove(k);
-                                            break;
+                                if (scaleItems.length > 0) {
+                                    JSONArray scaleItem = (JSONArray) JSONArray.toJSON(scaleItems);
+                                    for (int k = 0; k < scaleItem.size(); k++) {
+                                        if (scaleItem.get(k).toString().contains(row.getString("name"))) {
+                                            if (scaleItem.get(k).toString().contains(option)) {
+                                                rowDetail.put("state", 1);
+                                                scaleItem.remove(k);
+                                                break;
+                                            }
+                                        } else {
+                                            rowDetail.put("state", 0);
                                         }
                                     }
-                                    else {
-                                        rowDetail.put("state", 0);
-                                    }
+                                } else {
+                                    rowDetail.put("state", 0);
                                 }
                                 details.add(rowDetail);
                                 row.put("details", details);
                             }
                             rowsList.remove(j);
+                            //                            if (Integer.valueOf(mutex) == 0 && Integer.valueOf(rowJson.get("indexId").toString()) == Integer.valueOf(indexId)) {
+                            //                                rowJson.getJSONArray("row").add(row);
+                            //                            } else {
+                            //                                rowJson.put("row", rowList);
+                            //                            }
                             rowJson.put("row", rowList);
                             rowsList.add(rowJson);
                             existRow = true;
@@ -1998,6 +2016,7 @@ public class Neo4jAPI {
                     JSONObject rowJson = new JSONObject();
                     rowJson.put("metux", Integer.valueOf(mutex));
                     rowJson.put("required", Integer.valueOf(required));
+                    rowJson.put("indexId", Integer.valueOf(indexId));
                     JSONArray rowList = new JSONArray();
                     JSONObject row = new JSONObject();
                     row.put("name", index);
@@ -2008,25 +2027,29 @@ public class Neo4jAPI {
                         JSONObject rowDetail = new JSONObject();
                         rowDetail.put("detailName", option);
                         rowDetail.put("score", Integer.valueOf(score));
-                        JSONArray scaleItem = (JSONArray) JSONArray.toJSON(scaleItems);
-                        for (int k = 0; k < scaleItem.size(); k++) {
-                            if (scaleItem.get(k).toString().contains(row.getString("name"))){
-                                if (scaleItem.get(k).toString().contains(option)){
-                                    rowDetail.put("state", 1);
-                                    scaleItem.remove(k);
-                                    break;
+                        if (scaleItems.length > 0) {
+                            JSONArray scaleItem = (JSONArray) JSONArray.toJSON(scaleItems);
+                            for (int k = 0; k < scaleItem.size(); k++) {
+                                if (scaleItem.get(k).toString().contains(row.getString("name"))) {
+                                    if (scaleItem.get(k).toString().contains(option)) {
+                                        rowDetail.put("state", 1);
+                                        scaleItem.remove(k);
+                                        break;
+                                    }
+                                } else {
+                                    rowDetail.put("state", 0);
                                 }
                             }
-                            else {
-                                rowDetail.put("state", 0);
-                            }
+                        } else {
+                            rowDetail.put("state", 0);
                         }
-//                        rowDetail.put("state", 0);
+                        //                        rowDetail.put("state", 0);
                         JSONArray details = new JSONArray();
                         details.add(rowDetail);
                         row.put("details", details);
                     }
                     rowList.add(row);
+
                     rowJson.put("row", rowList);
                     rowsList.add(rowJson);
                 }