Browse Source

量表结构优化

Zhaops 6 years ago
parent
commit
0ff81c29ad
1 changed files with 46 additions and 30 deletions
  1. 46 30
      graph/src/main/java/org/diagbot/graph/jdbc/Neo4jAPI.java

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

@@ -1841,15 +1841,16 @@ public class Neo4jAPI {
         //分组计算结果
         JSONObject groupCalcJson = new JSONObject();
         JSONObject groupCalcResult = new JSONObject();
-        groupCalcJson.put("value", "");
-        groupCalcJson.put("unit", "");
-        groupCalcJson.put("text", "");
-        groupCalcJson.put("isShow", 0);
+        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",1);
 
         Map<String, Object> calculate = new HashMap<>();
         Map<String, List<Map<String, String>>> nameDetails = new HashMap<>();
@@ -1917,36 +1918,49 @@ public class Neo4jAPI {
                     groupItem.put("groupCalculate", groupCalcJson);
                 }
 
-                JSONObject rows = new JSONObject();
-                JSONArray rowList = new JSONArray();
+                JSONArray rowsList = new JSONArray();
                 if (!groupItem.containsKey("rows") || groupItem.get("rows") == null) {
-                    rows.put("metux", 0);
-                    rows.put("required", 1);
-                    groupItem.put("rows", rows);
+                    groupItem.put("rows", rowsList);
                 } else {
-                    if (JSONObject.parseObject(groupItem.get("rows").toString()).containsKey("row")) {
-                        rowList = JSONArray.parseArray(JSONObject.parseObject(groupItem.get("rows").toString()).get("row").toString());
-                    }
+                    rowsList = JSONArray.parseArray(groupItem.get("rows").toString());
                 }
+
                 Boolean existRow = false;
-                for (int i = 0; i < rowList.size(); i++) {
-                    JSONObject row = rowList.getJSONObject(i);
-                    if (row.containsKey("name") && row.get("name").equals(optionOrIndex)) {
-                        JSONArray details = JSON.parseArray(row.get("details").toString());
-                        if (!"NULL".equals(pacsResult)) {
-                            JSONObject rowDetail = new JSONObject();
-                            rowDetail.put("detailName", pacsResult);
-                            rowDetail.put("score", score2);
-                            rowDetail.put("state", 0);
-                            details.add(rowDetail);
-                            row.put("details", details);
+                for (int j = 0; j < rowsList.size(); j++) {
+                    JSONObject rowJson = rowsList.getJSONObject(j);
+                    JSONArray rowList = new JSONArray();
+                    if (rowJson.containsKey("row")) {
+                        rowList = JSONArray.parseArray(rowJson.get("row").toString());
+                    } else {
+                        rowJson.put("metux", 0);
+                        rowJson.put("required", 1);
+                        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)) {
+                            JSONArray details = JSON.parseArray(row.get("details").toString());
+                            if (!"NULL".equals(pacsResult)) {
+                                JSONObject rowDetail = new JSONObject();
+                                rowDetail.put("detailName", pacsResult);
+                                rowDetail.put("score", score2);
+                                rowDetail.put("state", 0);
+                                details.add(rowDetail);
+                                row.put("details", details);
+                            }
+                            rowsList.remove(j);
+                            rowJson.put("row", rowList);
+                            rowsList.add(rowJson);
+                            existRow = true;
+                            break;
                         }
-                        rows.put("row", rowList);
-                        existRow = true;
-                        break;
                     }
                 }
-                if (rowList.size() == 0 || existRow == false) {
+                if (rowsList.size() == 0 || existRow == false) {
+                    JSONObject rowJson = new JSONObject();
+                    rowJson.put("metux", 0);
+                    rowJson.put("required", 1);
+                    JSONArray rowList = new JSONArray();
                     JSONObject row = new JSONObject();
                     row.put("name", optionOrIndex);
                     row.put("coefficent", 1);
@@ -1962,9 +1976,10 @@ public class Neo4jAPI {
                         row.put("details", details);
                     }
                     rowList.add(row);
-                    rows.put("row", rowList);
+                    rowJson.put("row", rowList);
+                    rowsList.add(rowJson);
                 }
-                groupItem.put("rows", rows);
+                groupItem.put("rows", rowsList);
                 groupList.add(groupItem);
                 threeLevelItems.put("group", groupList);
             }
@@ -1975,8 +1990,9 @@ public class Neo4jAPI {
             calculate.put("range", results);
             calculate.put("formula", "");
             Map<String, String> calcResult = new HashMap<>();
-            calcResult.put("score", "");
+            calcResult.put("value", "");
             calcResult.put("text", "");
+            calcResult.put("unit", "");
             calculate.put("result", calcResult);
             threeLevelItems.put("calculate", calculate);