浏览代码

修改量表结构接口,将之前写死的参数修改成图谱中的字段

hujing 6 年之前
父节点
当前提交
661d3cfc4b

+ 117 - 120
graph/src/main/java/org/diagbot/graph/jdbc/Neo4jAPI.java

@@ -1671,31 +1671,15 @@ public class Neo4jAPI {
         threeLevelItems.put("scaleType", "");
 
         try {
-            String query = "match (m:Scale)-[r1]->(n1)-[r2]->(n2)-[r3]->(n3)-[r4]->(n4) " +
-                    "WHERE m.name=~'.*"+scaleName+".*' " +
-                    "return m.name,m.calc,m.type,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," +
-                    "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+".*' " +
-                    "return m.name,m.calc,m.type,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 n4name";
+            String query = "match (m:Scale)-[r1]->(n1)-[r2]->(n2)-[r3]->(n3) WHERE m.name=~'.*" + scaleName + ".*' " +
+                    "return n1.name, n1.method, r1.score, n2.name, r2.score,n2.type, r2.p,n3.name as n3name,r3.score as r3score, r3.p as r3p, n3.type as n3type order by toInt(r2.p),n2.type " +
+                    "union match (m:Scale)-[r1]->(n1)-[r2]->(n2)  WHERE m.name=~'.*" + scaleName + ".*' return n1.name,n1.method, r1.score,n2.name,r2.score,n2.type,r2.p, null as n3name, null as r3score, null as r3p, null as n3type order by toInt(r2.p),n2.type";
 
             Rset = session.run(query);
 
             String name = "";
-            String calc = "";
-            String type = "";
-            String isShow = "";
-            String mutex = "";
-            String required = "";
-            String coefficient = "";
-            String constant = "";
-            String controlType = "";
             String method = "";
-            String index = "";
+            String optionOrIndex = "";
             String pacsResult = "";
             String score1 = "";
             String score2 = "";
@@ -1707,7 +1691,7 @@ public class Neo4jAPI {
                 name = rec.get("n1.name").toString().replace("\"", "");
                 method = rec.get("n1.method").toString().replace("\"", "");
                 //轻度 右拇指振动觉
-                index = rec.get("n2.name").toString().replace("\"", "");
+                optionOrIndex = rec.get("n2.name").toString().replace("\"", "");
                 //正常 异常
                 pacsResult = rec.get("n3name").toString().replace("\"", "");
                 //range区间
@@ -1725,7 +1709,7 @@ public class Neo4jAPI {
                     result = new TreeMap<>();
                     result.put("min", min);
                     result.put("max", max);
-                    result.put("text", index);
+                    result.put("text", optionOrIndex);
                     result.put("priority", priority);
                     results.add(result);
                 }
@@ -1745,7 +1729,7 @@ public class Neo4jAPI {
                 threeLevelItems.put("title", titles);
 
                 if ("NULL".equals(method) && !"NULL".equals(pacsResult)) {
-                    index = index + "_" + priority;
+                    optionOrIndex = optionOrIndex + "_" + priority;
 
                     Map<String, String> detailInfo = new LinkedHashMap<>();
                     detailInfo.put("detailName", pacsResult);
@@ -1753,11 +1737,11 @@ public class Neo4jAPI {
                     detailInfo.put("state", "0");
                     detailInfo.put("priority", priority);
 
-                    if (nameDetails.containsKey(index)) {
-                        nameDetails.get(index).add(detailInfo);
+                    if (nameDetails.containsKey(optionOrIndex)) {
+                        nameDetails.get(optionOrIndex).add(detailInfo);
                     } else {
-                        nameDetails.put(index, new ArrayList<>());
-                        nameDetails.get(index).add(detailInfo);
+                        nameDetails.put(optionOrIndex, new ArrayList<>());
+                        nameDetails.get(optionOrIndex).add(detailInfo);
                     }
                 }
             }
@@ -1837,86 +1821,102 @@ public class Neo4jAPI {
         Record rec;
         scaleName = scaleName.toUpperCase();
 
-        Map<String, Object> threeLevelItems = new LinkedHashMap<>();
-        //<<=44,0>
-
+        Map<String, Object> scaleStructure = new LinkedHashMap<>();
         Map<String, Object> result = null;
-        Map<String, Object> title = new LinkedHashMap<>();
-        List<Map<String, Object>> results = new ArrayList<>();
 
-        //标题
-        List<Object> titles = new ArrayList<>();
-        title.put("name", "临床体格检查");
-        title.put("column", "name");
-        titles.add(title);
-        title = new LinkedHashMap<>();
-        title.put("name", "临床症状");
-        title.put("column", "detailName");
-        titles.add(title);
-        title = new LinkedHashMap<>();
-        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();
-        JSONObject groupCalcResult = new JSONObject();
-        groupCalcResult.put("value", "");
-        groupCalcResult.put("unit", "");
-        groupCalcResult.put("text", "");
-        groupCalcJson.put("result", groupCalcResult);
-        groupCalcJson.put("isShow", 0);
-
-        threeLevelItems.put("scaleType", 1);
-        threeLevelItems.put("scaleName", scaleName);
-        threeLevelItems.put("group", new JSONArray());
-        threeLevelItems.put("noCalc",0);
+        List<Map<String, Object>> results = new ArrayList<>();
 
         Map<String, Object> calculate = new HashMap<>();
-        Map<String, List<Map<String, String>>> nameDetails = new HashMap<>();
 
         try {
-            String query = "match (m:Scale)-[r1]->(n1)-[r2]->(n2)-[r3]->(n3) WHERE m.name=~'.*" + scaleName + ".*' return n1.name, n1.method, r1.score, n2.name, r2.score,n2.type, r2.p,n3.name as n3name,r3.score as r3score, r3.p as r3p, n3.type as n3type order by toInt(r1.p), toInt(r2.p),n2.type,toInt(r3.p) \n" +
-                    "union match (m:Scale)-[r1]->(n1)-[r2]->(n2)  WHERE m.name=~'.*" + scaleName + ".*' return n1.name,n1.method, r1.score,n2.name,r2.score,n2.type,r2.p, null as n3name, null as r3score, null as r3p, null as n3type order by toInt(r1.p), toInt(r2.p), n2.type";
-
+            String query = "match (m:Scale)-[r1]->(n1)-[r2]->(n2)-[r3]->(n3)-[r4]->(n4) " +
+                    "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," +
+                    "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+".*' " +
+                    "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 n4name order by toInt(r2.p)";
             Rset = session.run(query);
 
-            String name = "";
-            String method = "";
-            String optionOrIndex = "";
-            String pacsResult = "";
-            String score1 = "";
-            String score2 = "";
-            String priority = "";
+            String calc = "";
+            String type = "";
+            String group = "";
+            String titleName = "";
+            String isShow = "";
+            String text = "";
+            String mutex = "";
+            String required = "";
+            String coefficient = "";
+            String constant = "";
+            String controlType = "";
+            String score = "";
+            String option = "";
+            String index = "";
 
             while (Rset.hasNext()) {
                 rec = Rset.next();
-                //分组名称
-                name = rec.get("n1.name").toString().replace("\"", "");
-                method = rec.get("n1.method").toString().replace("\"", "");
-                //项目名称
-                optionOrIndex = rec.get("n2.name").toString().replace("\"", "");
-                //指标结果
-                pacsResult = rec.get("n3name").toString().replace("\"", "");
-                //range区间
-                score1 = rec.get("r2.score").toString().replace("\"", "");
-                //得分
-                score2 = rec.get("r3score").toString().replace("\"", "");
-                //权重(排序)
-                priority = rec.get("r2.p").toString().replace("\"", "");
+                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("\"", "");
+                mutex = rec.get("r2mutex").toString().replace("\"", "");
+                required = rec.get("n2required").toString().replace("\"", "");
+                index = rec.get("n3name").toString().replaceAll("(\"|_)", "");
+                coefficient = rec.get("n3coefficient").toString().replace("\"", "");//系数
+                constant = rec.get("n3constant").toString().replace("\"", "");//常数
+                controlType = rec.get("n3controlType").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);
+
+                //分组计算结果
+                JSONObject groupCalcJson = new JSONObject();
+                JSONObject groupCalcResult = new JSONObject();
+                groupCalcResult.put("value", "");
+                groupCalcResult.put("unit", "");
+                groupCalcResult.put("text", "");
+                groupCalcJson.put("result", groupCalcResult);
+                groupCalcJson.put("isShow", 0);
+
+                scaleStructure.put("scaleType", Integer.valueOf(type));
+                scaleStructure.put("scaleName", scaleName);
+                if (!scaleStructure.containsKey("group")) {
+                    scaleStructure.put("group", new JSONArray());
+                }
+                scaleStructure.put("Calc",Integer.valueOf(calc));
 
-                if (name.contains("计算方法")) {
-                    String[] score = score1.split("~|-");
-                    String min = score[0];
-                    String max = score[1];
+                if (group.contains("计算方法")) {
+                    String[] range = mutex.split("~|-");
+                    String min = range[0];
+                    String max = range[1];
                     result = new TreeMap<>();
                     result.put("min", min);
                     result.put("max", max);
-                    result.put("text", optionOrIndex);
-                    result.put("priority", priority);
+                    result.put("text", text);
                     results.add(result);
                     continue;
                 }
@@ -1924,10 +1924,10 @@ public class Neo4jAPI {
                 //分组匹配
                 JSONObject groupItem = new JSONObject();
                 Boolean existGroup = false;
-                JSONArray groupList = (JSONArray) threeLevelItems.get("group");
+                JSONArray groupList = (JSONArray) scaleStructure.get("group");
                 if (groupList.size() > 0) {
                     for (int i = 0; i < groupList.size(); i++) {
-                        if (groupList.getJSONObject(i).containsKey("groupName") && groupList.getJSONObject(i).get("groupName").equals(name)) {
+                        if (groupList.getJSONObject(i).containsKey("groupName") && groupList.getJSONObject(i).get("groupName").equals(group)) {
                             groupItem = groupList.getJSONObject(i);
                             groupList.remove(i);
                             existGroup = true;
@@ -1936,9 +1936,9 @@ public class Neo4jAPI {
                     }
                 }
                 if (groupList.size() == 0 || existGroup == false) {
-                    groupItem.put("groupName", name);
-                    if (name.equals("感觉损伤")) {
-                        titleJson.put("isShow", 0);
+                    groupItem.put("groupName", group);
+                    if (group.equals("感觉损伤")) {
+                        titleJson.put("isShow", Integer.valueOf(isShow));
                     }
                     groupItem.put("title", titleJson);
                     groupItem.put("groupCalculate", groupCalcJson);
@@ -1958,22 +1958,22 @@ public class Neo4jAPI {
                     if (rowJson.containsKey("row")) {
                         rowList = JSONArray.parseArray(rowJson.get("row").toString());
                     } else {
-                        rowJson.put("metux", 0);
-                        rowJson.put("required", 1);
+                        rowJson.put("metux", Integer.valueOf(mutex));
+                        rowJson.put("required", Integer.valueOf(required));
                         rowJson.put("row", rowList);
                     }
                     for (int i = 0; i < rowList.size(); i++) {
                         JSONObject row = rowList.getJSONObject(i);
-                        if (row.containsKey("name") && row.get("name").equals(optionOrIndex)) {
+                        if (row.containsKey("name") && row.get("name").equals(index)) {
                             JSONArray details = JSON.parseArray(row.get("details").toString());
-                            if (!"NULL".equals(pacsResult)) {
+                            if (!"NULL".equals(option)) {
                                 JSONObject rowDetail = new JSONObject();
-                                rowDetail.put("detailName", pacsResult);
-                                rowDetail.put("score", score2);
+                                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(pacsResult)){
+                                        if (scaleItem.get(k).toString().contains(option)){
                                             rowDetail.put("state", 1);
                                             scaleItem.remove(k);
                                             break;
@@ -1996,22 +1996,22 @@ public class Neo4jAPI {
                 }
                 if (rowsList.size() == 0 || existRow == false) {
                     JSONObject rowJson = new JSONObject();
-                    rowJson.put("metux", 0);
-                    rowJson.put("required", 1);
+                    rowJson.put("metux", Integer.valueOf(mutex));
+                    rowJson.put("required", Integer.valueOf(required));
                     JSONArray rowList = new JSONArray();
                     JSONObject row = new JSONObject();
-                    row.put("name", optionOrIndex);
-                    row.put("coefficent", 1);
-                    row.put("constant", 0);
-                    row.put("controlType", 0);
-                    if (!"NULL".equals(pacsResult)) {
+                    row.put("name", index);
+                    row.put("coefficient", Integer.valueOf(coefficient));
+                    row.put("constant", Integer.valueOf(constant));
+                    row.put("controlType", Integer.valueOf(controlType));
+                    if (!"NULL".equals(option)) {
                         JSONObject rowDetail = new JSONObject();
-                        rowDetail.put("detailName", pacsResult);
-                        rowDetail.put("score", score2);
+                        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(pacsResult)){
+                                if (scaleItem.get(k).toString().contains(option)){
                                     rowDetail.put("state", 1);
                                     scaleItem.remove(k);
                                     break;
@@ -2032,12 +2032,9 @@ public class Neo4jAPI {
                 }
                 groupItem.put("rows", rowsList);
                 groupList.add(groupItem);
-                threeLevelItems.put("group", groupList);
+                scaleStructure.put("group", groupList);
             }
 
-            for (Map<String, Object> resMap : results) {
-                resMap.remove("priority");
-            }
             calculate.put("range", results);
             calculate.put("formula", "");
             Map<String, String> calcResult = new HashMap<>();
@@ -2045,14 +2042,14 @@ public class Neo4jAPI {
             calcResult.put("text", "");
             calcResult.put("unit", "");
             calculate.put("result", calcResult);
-            threeLevelItems.put("calculate", calculate);
+            scaleStructure.put("calculate", calculate);
 
         } catch (Exception ex) {
             ex.printStackTrace();
             System.out.println("返回带得分需要计算的量表时出了问题!---->getScaleCalc");
         } finally {
             CloseSession(session);
-            return threeLevelItems;
+            return scaleStructure;
         }
     }
 

+ 2 - 2
push-web/src/main/java/org/diagbot/push/controller/GraphController.java

@@ -95,8 +95,8 @@ public class GraphController extends BaseController {
     @RequestMapping(value = "/scale", method = RequestMethod.POST)
     @ResponseBody
     public Map<String, Object> scale(HttpServletRequest request, @RequestBody SearchData searchData) throws Exception {
-//        Driver driver = DriverManager.newDrive("192.168.2.233", "neo4j", "root");
-        Driver driver = DriverManager.newDrive();
+        Driver driver = DriverManager.newDrive("192.168.2.233", "neo4j", "root");
+//        Driver driver = DriverManager.newDrive();
         Neo4jAPI neo4jAPI = new Neo4jAPI(driver);
         Set<String> inputs = searchData.getInputs().keySet();
         String[] input = inputs.toArray(new String[inputs.size()]);