浏览代码

Merge branch 'master' into innerDevelop

zhoutg 4 年之前
父节点
当前提交
47aa561921

+ 10 - 2
src/main/java/com/diagbot/dto/NeoEntityDTO.java

@@ -3,6 +3,8 @@ package com.diagbot.dto;
 
 import lombok.Data;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -18,8 +20,14 @@ public class NeoEntityDTO {
     private String name;
 
     // 实体标签
-    private List<String> labels;
+    private List<String> labels = new ArrayList<>();
 
     // 实体属性
-    private Map<String, String> property;
+    private Map<String, String> property = new HashMap<>();
+
+    // 实体属性列表
+    private List<Map<String, Object>> nodes = new ArrayList<>();
+
+    // 返回信息
+    private String msg;
 }

+ 39 - 0
src/main/java/com/diagbot/dto/NeoRelationDTO.java

@@ -0,0 +1,39 @@
+package com.diagbot.dto;
+
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @description: 图谱关系内容
+ * @author: Mark
+ * @time: 2020/8/27 18:34
+ */
+@Data
+public class NeoRelationDTO {
+
+    // 起始实体名称
+    private String startname;
+
+    // 起始实体标签
+    private String startlabel;
+
+    // 关系名称
+    private String relname;
+
+    // 关系属性
+    private Map<String, String> property = new HashMap<>();
+
+    // 终点实体名称
+    private String endname;
+
+    // 终点实体标签
+    private String endlabel;
+
+    // 返回信息
+    private String msg;
+}

+ 2 - 2
src/main/java/com/diagbot/entity/node/LisName.java

@@ -28,8 +28,8 @@ public class LisName extends BaseNode  {
 	@Property(name = "范围")
 	private Integer range;
 
-	@Property(name = "静态知识")
-	private String knowledge;
+//	@Property(name = "静态知识")
+//	private String knowledge;
 
 	@Relationship(type = "实验室检查名称相关实验室检查代码", direction = Relationship.OUTGOING)
 	private Set<LisNameLisCode> lisNameliscodes = new HashSet<>();

+ 494 - 84
src/main/java/com/diagbot/facade/EntityFacade.java

@@ -1,16 +1,17 @@
 package com.diagbot.facade;
 
 import com.diagbot.dto.NeoEntityDTO;
-import com.diagbot.entity.node.Symptom;
+import com.diagbot.dto.NeoRelationDTO;
+import com.diagbot.entity.node.*;
 import com.diagbot.entity.node.base.BaseNode;
 import com.diagbot.repository.*;
-//import com.diagbot.util.GenericNode;
+import com.diagbot.util.BeanMapUtils;
+import com.diagbot.util.GenericNode;
 import com.diagbot.util.StringUtil;
 import com.diagbot.vo.*;
 
-import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Component;
 
 import java.io.BufferedReader;
@@ -25,6 +26,7 @@ import java.util.*;
  * @time: 2018/8/6 9:11
  */
 @Component
+@Slf4j
 public class EntityFacade {
 
     @Autowired
@@ -34,11 +36,45 @@ public class EntityFacade {
     SymptomNameRepository symptomNameRepository;
 
     @Autowired
-    LisNameRepository lisRepository;
+    VitalRepository vitalRepository;
+
+    @Autowired
+    DeptRepository deptRepository;
+
+    @Autowired
+    LisNameRepository lisNameRepository;
 
     @Autowired
     LisSetRepository lisSetRepository;
 
+    @Autowired
+    YiBaoDiseaseNameRepository icdDiseaseRepository;
+
+    @Autowired
+    PacsNameRepository pacsNameRepository;
+
+    @Autowired
+    PacsSubNameRepository pacsSubNameRepository;
+
+    @Autowired
+    GroupRepository groupRepository;
+
+    @Autowired
+    MedicineRepository medicineRepository;
+
+    @Autowired
+    YiBaoOperationNameRepository operationRepository;
+
+    @Autowired
+    TransfusionRemindRepository transfusionRemindRepository;
+
+    @Autowired
+    LisCriticalRepository lisCriticalRepository;
+
+    @Autowired
+    LisAliasRepository lisAliasRepository;
+
+
 
     public List<String> getLabels() {
         List<String> labels = baseNodeRepository.getLabels();
@@ -47,24 +83,209 @@ public class EntityFacade {
     }
 
 
-    public List<BaseNode> getNodes(KgQueryVO kgQueryVO) {
-
-        List<BaseNode> baseNodes = new ArrayList<>();
+    /**
+     * 查询节点信息
+     * @param kgQueryVO
+     * @return
+     */
+    public List<Map<String, Object>> getNodes(KgQueryVO kgQueryVO) {
 
         String label = kgQueryVO.getStartLabel().trim();
         String name = kgQueryVO.getStartName();
 
+        List<Map<String, Object>> baseNodes = getNodeList(label, name);
+        baseNodes = GenericNode.removeRelation(baseNodes);
+
+        return baseNodes;
+    }
+
+
+    /**
+     * 更新节点信息
+     * @param neoEntityVO
+     * @return
+     */
+    public NeoEntityDTO updateNeoNode(NeoEntityVO neoEntityVO) {
+
+        String name = neoEntityVO.getName();
+        String label = neoEntityVO.getLabel();
+        String newname = neoEntityVO.getNewname();
+        String newlabel = neoEntityVO.getNewlabel();
+        String user = neoEntityVO.getUser();
+        EntityProp entityProp = neoEntityVO.getEntityProp();
+
+        NeoEntityDTO neoEntityDTO = new NeoEntityDTO();
+        neoEntityDTO.getLabels().add(label);
+        neoEntityDTO.setName(name);
+
+        List<Map<String, Object>> nodes = getNodeList(label, name);
+
+        // 查找到一个原有节点
+        if (nodes.size()==1) {
+            List<Map<String, Object>> newnodes = getNodeList(newlabel, newname);
+            // 查找到待修改的新节点
+            if (newnodes.size()>0) {
+                neoEntityDTO.setMsg("有" + nodes.size() + "个同名的新节点已存在");
+            }
+            else {
+                updateNode(label, name, newlabel, newname, entityProp, nodes.get(0));
+                neoEntityDTO.setMsg(build_node_msg(user, label, name, newlabel, newname));
+            }
+        }
+        // 查找到多个原有节点
+        else if (nodes.size()>1) {
+            neoEntityDTO.setNodes(nodes);
+            neoEntityDTO.setMsg("有"+nodes.size()+"个重复信息的节点");
+        }
+
+
+        return  neoEntityDTO;
+    }
+
+
+
+    /**
+     * 删除节点信息
+     * @param neoEntityVO
+     * @return
+     */
+    public NeoEntityDTO deleteNeoNode(NeoEntityVO neoEntityVO) {
+
+        String name = neoEntityVO.getName();
+        String label = neoEntityVO.getLabel();
+        String user = neoEntityVO.getUser();
+
+        NeoEntityDTO neoEntityDTO = new NeoEntityDTO();
+        neoEntityDTO.setName(name);
+        neoEntityDTO.getLabels().add(label);
+
+        List<Map<String, Object>> nodes = getNodeList(label, name);
+
+        // 查找到一个原有节点
+        if (nodes.size()==1) {
+            removeNode(label, name, nodes.get(0));
+            neoEntityDTO.setMsg(remove_node_msg(user, label, name));
+        }
+        // 查找到多个原有节点
+        else if (nodes.size()>1) {
+            neoEntityDTO.setMsg("有"+nodes.size()+"个重复信息的节点");
+        }
+        // 找不到节点
+        else if (nodes.size()==0) {
+            neoEntityDTO.setMsg("此节点不存在");
+        }
+
+        return  neoEntityDTO;
+    }
+
+
+    /**
+     * 删除关系信息
+     */
+    public NeoRelationDTO deleteNeoRelation(NeoRelationVO neoRelationVO) {
+        return updateNeoRelation(neoRelationVO, 0);
+    }
+
+
+    /**
+     * 更新关系信息
+     * @param neoRelationVO
+     * @return
+     */
+    public NeoRelationDTO updateNeoRelation(NeoRelationVO neoRelationVO, Integer status) {
+
+        String s_name = neoRelationVO.getStartname();
+        String s_label = neoRelationVO.getStartlabel();
+        String relname = neoRelationVO.getRelname();
+        String e_name = neoRelationVO.getEndname();
+        String e_label = neoRelationVO.getEndabel();
+        String user = neoRelationVO.getUser();
+        Map<String, String> props = neoRelationVO.getProperty();
+
+        NeoRelationDTO neoRelationDTO = new NeoRelationDTO();
+        neoRelationDTO.setStartname(s_name);
+        neoRelationDTO.setStartlabel(s_label);
+        neoRelationDTO.setEndname(e_name);
+        neoRelationDTO.setEndlabel(e_label);
+
+        List<Map<String, Object>> s_nodes = getNodeList(s_label, s_name);
+        List<Map<String, Object>> e_nodes = getNodeList(e_label, e_name);
+
+        if (s_nodes.size()!=1) {
+            if (s_nodes.size()>0) {
+                neoRelationDTO.setMsg("有" + s_nodes.size() + "个名为\"" + s_name + "\"的起始节点已存在");
+            }
+            else if (s_nodes.size()==0) {
+                neoRelationDTO.setMsg("节点" + s_name + "(" + s_label+ ")不存在");            }
+        }
+        else if (e_nodes.size()!=1) {
+            if (e_nodes.size()>0) {
+                neoRelationDTO.setMsg("有" + e_nodes.size() + "个名为\"" + e_name + "\"的终点节点已存在");
+            }
+            else if (e_nodes.size()==0) {
+                neoRelationDTO.setMsg("节点" + e_name + "(" + e_label+ ")不存在");            }
+        }
+        else {
+            Map<String, Object> s_node = s_nodes.get(0);
+            Map<String, Object> e_node = e_nodes.get(0);
+
+            List<?> e_nd_list = getEndNodeList(s_label, s_name, relname);
+
+            if (inlist(e_nd_list, e_node)) {
+                if (null!=status && status == 0) {
+                    updateRelation(s_label, s_node, relname, status, e_name);
+                    neoRelationDTO.setMsg(build_relation_msg(user, s_label, s_name, e_label, e_name, relname));
+                }
+            }
+        }
+
+
+        return  neoRelationDTO;
+    }
+
+
+
+    public List<Map<String, Object>> getNodeList(String label, String name) {
+
+        List<Map<String, Object>> baseNodes = new ArrayList<>();
+
+        GenericNode<?> gNode = new GenericNode<>();
+        List<?> nodes = new ArrayList<>();
+
         try {
             if (StringUtil.isNotBlank(label) && StringUtil.isNotBlank(name)) {
                 if (Constants.node_Labels.contains(label)) {
                     switch (label) {
                         case "症状":
-                            List<Symptom> symptoms = symptomNameRepository.findByNameIs(name);
-//                            GenericNode<Symptom> sNodes = new GenericNode<>();
-//                            baseNodes = sNodes.fillNodeTree(symptoms);
+                            nodes = symptomNameRepository.findByNameIs(name);
+                            gNode = new GenericNode<Symptom>();
+                            break;
+                        case "体征":
+                            nodes = vitalRepository.findByNameIs(name);
+                            gNode = new GenericNode<Vital>();
+                            break;
+                        case "禁忌人群":
+                            nodes = groupRepository.findByNameIs(name);
+                            gNode = new GenericNode<Group>();
+                            break;
+                        case "实验室检查名称":
+                            nodes = lisNameRepository.findByNameIs(name);
+                            gNode = new GenericNode<Lis>();
+                            break;
+                        case "实验室检查别名":
+                            nodes = lisAliasRepository.findByNameIs(name);
+                            gNode = new GenericNode<>();
+                            break;
+                        case "实验室检查套餐名":
+                            nodes = lisSetRepository.findByNameIs(name);
+                            gNode = new GenericNode<Vital>();
+                            break;
+                        case "实验室检查危急值":
+                            nodes = lisCriticalRepository.findByNameIs(name);
+                            gNode = new GenericNode<Vital>();
                             break;
                     }
-
+                    baseNodes = gNode.fillNodeTree(nodes);
                 }
             }
         }
@@ -77,114 +298,303 @@ public class EntityFacade {
     }
 
 
+    public List<?> getEndNodeList(String s_label, String s_name, String relname) {
 
-    public NeoEntityDTO updateNeoNode(NeoEntityVO neoEntityVO) {
+        BaseNode baseNode;
+        List<?> baseNodes = new ArrayList<>();
 
-        List<String> keys;
-        String name = neoEntityVO.getName();
-        List<String> labels = neoEntityVO.getLabels();
-        Map<String, String> props = neoEntityVO.getProperty();
+        try {
+            if (StringUtil.isNotBlank(s_label)) {
+                switch (s_label) {
+                    case "辅助检查名称":
+                        PacsNameNode pacsNameNode = new PacsNameNode();
+                        baseNode = pacsNameRepository.findByNameIs(s_name).get(0);
+                        baseNodes = pacsNameNode.getNodesbyRelation((PacsName)baseNode, relname);
+                        break;
+                    case "实验室检查名称":
+                        LisNameNode lisNameNode = new LisNameNode();
+                        baseNode = lisNameRepository.findByNameIs(s_name).get(0);
+                        baseNodes = lisNameNode.getNodesbyRelation((LisName)baseNode, relname);
+                        break;
+                        /*
+                    case "实验室检查别名":
+                        nodes = lisAliasRepository.findByNameIs(name);
+                        gNode = new GenericNode<>();
+                        break;
+                        */
+                    case "实验室检查套餐名":
+                        LisSetNode lisSetNode = new LisSetNode();
+                        baseNode = lisSetRepository.findByNameIs(s_name).get(0);
+                        baseNodes = lisSetNode.getNodesbyRelation((LisSet)baseNode, relname);
+                        break;
+                        /*
+                    case "实验室检查危急值":
+                        nodes = lisCriticalRepository.findByNameIs(name);
+                        gNode = new GenericNode<Vital>();
+                        break;
+                        */
+                }
+//                baseNodes = gNode.fillNodeTree(nodes);
+            }
+        }
+        catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        finally {
+            return baseNodes;
+        }
+    }
 
-        NeoEntityDTO neoEntityDTO = new NeoEntityDTO();
 
-        Map<String, String> map = getMapping("node_mapping");
 
-        String label = labels.get(0);
-        if (null!=map.get(label)) {
-            String clsname = map.get(label);
+    public Map<String, String> updateNode(String label, String name, String newlabel, String newname,
+                                          EntityProp entityProp, Map<String, Object> nodeinfo) {
 
-            switch (clsname) {
-                case "LisName":
-                    LisNameNode lisNode = new LisNameNode();
-                    keys = getKeys(baseNodeRepository.getLisNameKeys(), "name");
-                    neoEntityDTO = lisNode.updateEntity(name, props, keys, lisRepository);
-                    break;
-                case "LisSet":
-                    LisSetNode lisPackNode = new LisSetNode();
-                    keys = getKeys(baseNodeRepository.getLisSetKeys(), "name");
-                    neoEntityDTO = lisPackNode.updateEntity(name, props, keys, lisSetRepository);
-                    break;
+        Map<String, String> node = new HashMap<>();
+
+        try {
+            long nd_id = Long.valueOf(nodeinfo.get("id").toString());
+            nodeinfo.remove("id");
+            nodeinfo = updateNodeInfo(nodeinfo, entityProp);
+
+            // 更新节点标签
+            if (StringUtil.isNotBlank(newlabel)) {
+                if (!newname.equals(name)) {
+                    name = newname;
+                }
+                createNewNode(newlabel, nodeinfo);
+            }
+            // 更新节点名称
+            else if (StringUtil.isNotBlank(newname) && !newname.equals(name)) {
+                name = newname;
+                nodeinfo.put("name", name);
+                createNewNode(label, nodeinfo);
             }
 
-            neoEntityDTO.setLabels(labels);
+            DeactivateNode(nd_id, label, nodeinfo);
+
+            node.put(name, label);
+        }
+        catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        finally {
+            return node;
         }
 
-        return  neoEntityDTO;
     }
 
 
-    /**
-     * 获取图谱节点类型到节点类名的静态映射
-     * @param fname
-     * @return
-     */
-    private Map<String, String> getMapping(String fname) {
-        Map<String, String> mapping = new HashMap<>();
+
+    public Map<String, Object> updateNodeInfo(Map<String, Object> nodeinfo, EntityProp entityProp) {
+
+        if (StringUtil.isNotBlank(entityProp.getVitalname())) {
+            nodeinfo.put("vitalname", entityProp.getVitalname());
+        }
+
+        if (null!=entityProp.getMinval()) {
+            nodeinfo.put("minval", entityProp.getMinval());
+        }
+
+        if (null!=entityProp.getMaxval()) {
+            nodeinfo.put("maxval", entityProp.getMaxval());
+        }
+
+        if (null!=entityProp.getUnit()) {
+            nodeinfo.put("unit", entityProp.getUnit());
+        }
+
+        if (null!=entityProp.getRange()) {
+            nodeinfo.put("range", entityProp.getRange());
+        }
+
+        if (StringUtil.isNotBlank(entityProp.getPycode())) {
+            nodeinfo.put("pycode", entityProp.getPycode());
+        }
+
+        if (StringUtil.isNotBlank(entityProp.getKnowledge())) {
+            nodeinfo.put("knowledge", entityProp.getKnowledge());
+        }
+
+        if (null!=entityProp.getIs_kl()) {
+            nodeinfo.put("is_kl", entityProp.getIs_kl());
+        }
+
+        return nodeinfo;
+    }
+
+
+
+    public Map<String, String> removeNode(String label, String name, Map<String, Object> nodeinfo) {
+
+        Map<String, String> node = new HashMap<>();
+
         try {
+            long nd_id = Long.valueOf(nodeinfo.get("id").toString());
 
-            ClassPathResource classPathResource = new ClassPathResource(fname);
+            DeactivateNode(nd_id, label, nodeinfo);
 
-            File file = classPathResource.getFile();
-            BufferedReader br = new BufferedReader(new FileReader(file));
-            String line;
-            String[] pair;
-            while ((line=br.readLine())!=null) {
-                if (line.contains(":")) {
-                    pair = line.split(":");
-                    mapping.put(pair[0].trim(), pair[1].trim());
-                }
-            }
+            node.put(name, label);
         }
-        catch (IOException ioe) {
-            ioe.printStackTrace();
+        catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        finally {
+            return node;
         }
 
-        return mapping;
     }
 
 
-    /**
-     * 获取节点的属性列表
-     * @param keylist
-     * @param exclude
-     * @return
-     */
-    private List<String> getKeys(List<List<String>> keylist, String exclude) {
-        List<String> finalkeys = new ArrayList<>();
 
-        for (List<String> keys : keylist) {
-            for (String key : keys) {
-                if (!key.equals(exclude) && !finalkeys.contains(key)) {
-                    finalkeys.add(key);
-                }
+    public void createNewNode(String label, Map<String, Object> nodeinfo) {
+        saveNode(label, nodeinfo);
+    }
+
+
+
+    public void DeactivateNode(Long id, String label, Map<String, Object> nodeinfo) {
+        nodeinfo.put("id", id);
+        nodeinfo.put("status", 0);
+        saveNode(label, nodeinfo);
+    }
+
+
+    public void saveNode(String label, Map<String, Object> nodeinfo) {
+        try {
+            switch (label) {
+                case "症状":
+                    Symptom symptom = BeanMapUtils.mapToBean(nodeinfo, Symptom.class);
+                    symptomNameRepository.save(symptom);
+                    break;
+                case "体征":
+                    Vital vital = BeanMapUtils.mapToBean(nodeinfo, Vital.class);
+                    vitalRepository.save(vital);
+                    break;
+                case "实验室检查名称":
+                    LisName lisName = BeanMapUtils.mapToBean(nodeinfo, LisName.class);
+                    lisNameRepository.save(lisName);
+                    break;
+                case "实验室检查别名":
+                    LisAlias lisAlias = BeanMapUtils.mapToBean(nodeinfo, LisAlias.class);
+                    lisAliasRepository.save(lisAlias);
+                    break;
+                case "实验室检查套餐名":
+                    LisSet lisSet = BeanMapUtils.mapToBean(nodeinfo, LisSet.class);
+                    lisSetRepository.save(lisSet);
+                    break;
+                case "实验室检查危急值":
+                    break;
+                case "辅助检查名称":
+                    PacsName pacsName = BeanMapUtils.mapToBean(nodeinfo, PacsName.class);
+                    pacsNameRepository.save(pacsName);
+                    break;
+                case "辅助检查子项目名称":
+                    PacsSubName pacsSubName = BeanMapUtils.mapToBean(nodeinfo, PacsSubName.class);
+                    pacsSubNameRepository.save(pacsSubName);
+                    break;
+
             }
         }
-
-        return finalkeys;
+        catch (Exception ex) {
+            ex.printStackTrace();
+        }
     }
 
 
-    /**
-     * 删除节点
-     * @param neoEntityVO
-     * @return
-     */
-    public int deleteNeoNode(NeoEntityVO neoEntityVO) {
-        int cnt = 0;
+
+    public boolean inlist(List<?> nodelist, Map<String, Object> node) {
+
+        boolean isin = false;
+        String key = "name";
 
         try {
-            if (null != neoEntityVO.getID()) {
-                long id = neoEntityVO.getID();
-                BaseNode node = baseNodeRepository.findById(id);
-                cnt = 1;
-//                baseNodeRepository.delete(node);
+            for (Object nd : nodelist) {
+                Map<String, Object> nd_map = BeanMapUtils.beanToMap(nd);
+                String nd_map_name = nd_map.get(key).toString();
+                String node_name = node.get(key).toString();
+                if (nd_map_name.equals(node_name)) {
+                    isin = true;
+                    break;
+                }
             }
+
         }
         catch (Exception ex) {
             ex.printStackTrace();
         }
         finally {
-            return cnt;
+            return isin;
+        }
+
+    }
+
+
+
+    public void updateRelation(String s_label, Map<String, Object> s_node, String relname, Integer status, String e_name) {
+        try {
+            switch (s_label) {
+                case "辅助检查名称":
+                    PacsName pacsName = BeanMapUtils.mapToBean(s_node, PacsName.class);
+                    PacsNameNode pacsNameNode = new PacsNameNode();
+                    pacsNameNode.updateRelation(pacsName, relname, status, e_name, pacsNameRepository);
+                    break;
+                case "实验室检查名称":
+                    LisName lisName = BeanMapUtils.mapToBean(s_node, LisName.class);
+                    LisNameNode lisNameNode = new LisNameNode();
+                    lisNameNode.updateRelation(lisName, relname, status, e_name, lisNameRepository);
+                    break;
+                case "实验室检查套餐名":
+                    LisSet lisSet = BeanMapUtils.mapToBean(s_node, LisSet.class);
+                    LisSetNode lisSetNode = new LisSetNode();
+                    lisSetNode.updateRelation(lisSet, relname, status, e_name, lisSetRepository);
+                    break;
+            }
+        }
+        catch (Exception ex) {
+            ex.printStackTrace();
         }
     }
+
+
+
+    public String build_node_msg(String user, String label, String name, String newlbl, String newname) {
+        String msg = "\n";
+
+        msg += "操作用户:\t" + user + "\n";
+        msg += "初始节点:\t" + name + "(" + label + ")\n";
+        msg += "更新为:\t" + newname + "(" + newlbl + ")\n";
+
+        log.error(msg);
+
+        return msg;
+    }
+
+
+    public String remove_node_msg(String user, String label, String name) {
+        String msg = "\n";
+
+        msg += "操作用户:\t" + user + "\n";
+        msg += "初始节点:\t" + name + "(" + label + ")\n";
+        msg += "更新状态为:\t删除\n";
+
+        log.error(msg);
+
+        return msg;
+    }
+
+
+    public String build_relation_msg(String user, String s_label, String s_name, String e_label, String e_name, String relname) {
+        String msg = "\n";
+
+        msg += "操作用户:\t" + user + "\n";
+        msg += "起始节点:\t" + s_name + "(" + s_label + ")\n";
+        msg += "终止节点:\t" + e_name + "(" + e_label + ")\n";
+        msg += "删除关系名称为:\t" + relname + "\n";
+
+        log.error(msg);
+
+        return msg;
+    }
+
 }

+ 54 - 0
src/main/java/com/diagbot/model/ai/process/EntityProcessLis.java

@@ -3,6 +3,7 @@ package com.diagbot.model.ai.process;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.diagbot.model.ai.model.EntityEnum;
+import com.diagbot.model.ai.model.Lemma;
 import com.diagbot.model.entity.Lis;
 import com.diagbot.model.entity.LisValue;
 import com.diagbot.model.entity.PD;
@@ -16,6 +17,7 @@ import java.util.Map;
 import java.util.stream.Collectors;
 
 public class EntityProcessLis extends EntityProcess {
+
     public List<Lis> extractEntity(JSONObject outputs) {
         List<Lis> lises = new ArrayList<>();
         Lis lis = null;
@@ -71,9 +73,61 @@ public class EntityProcessLis extends EntityProcess {
             }
             lises.add(lis);
         }
+
+        /**
+         * 读取实验室检查带结果的化验,将套餐和明细都置成实验室检查名称,主要用来解决套餐和明细同一个名字只写一次的问题
+         */
+        List<Lemma> lisLemmas = createEntityTree(outputs, EntityEnum.LABORATORY.toString());
+        for (Lemma lemma : lisLemmas) {
+            if (lemma.isHaveChildren()) {
+                List<Lemma> sonLemma = lemma.getRelationLemmas();
+                for (Lemma leSon : sonLemma) {
+                    if (leSon.getId() > lemma.getId()) {
+                        if (leSon.getProperty().equals(EntityEnum.LABORATORY_VALUE.toString())) {
+                            Lis lisBean = new Lis();
+                            lisBean.setName(lemma.getText());
+                            lisBean.setBigItem(generateLisValue(lemma.getText())); // 套餐
+                            lisBean.setLisValue(generateLisValue(leSon.getText())); // 结果
+                            lisBean.setPd(generatePd(leSon.getText())); // 结果结构化
+                            lises.add(lisBean);
+                            break;
+                        }
+                    }
+                }
+            }
+        }
         return lises;
     }
 
+    /**
+     * 生成PD实体类型
+     *
+     * @param value
+     * @return
+     */
+    public PD generatePd(String value) {
+        PD pd = new PD();
+        String[] val_unit = new String[2];
+        if (value.trim().length() > 0) {
+            val_unit = extract_digit_new(value);
+        }
+        pd.setValue(val_unit[0]);
+        pd.setUnit(val_unit[1]);
+        return pd;
+    }
+
+    /**
+     * 生成化验bean类型
+     *
+     * @param name
+     * @return
+     */
+    public LisValue generateLisValue(String name) {
+        LisValue lisValue = new LisValue();
+        lisValue.setName(name);
+        return lisValue;
+    }
+
     private Map<String,List<String>> processLisoutputs(JSONObject outputs){
         JSONObject annotation = outputs.getJSONObject("annotation");
         JSONArray entitys = annotation.getJSONArray("T");

+ 21 - 0
src/main/java/com/diagbot/repository/GroupRepository.java

@@ -0,0 +1,21 @@
+package com.diagbot.repository;
+
+import com.diagbot.entity.node.Group;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.neo4j.annotation.Query;
+import org.springframework.data.neo4j.repository.Neo4jRepository;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+
+public interface GroupRepository extends Neo4jRepository<Group, Long> {
+
+    List<Group> findByNameContaining(String name);
+
+    List<Group> findByNameIs(String name);
+
+    List<Group> findByNameIn(List<String> names);
+
+}

+ 60 - 5
src/main/java/com/diagbot/repository/LisSetNode.java

@@ -11,11 +11,8 @@ import com.diagbot.entity.relationship.LisSetGroup;
 import com.diagbot.util.ListUtil;
 import com.diagbot.util.NeoUtil;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
+import java.util.stream.Collectors;
 
 public class LisSetNode {
 
@@ -268,5 +265,63 @@ public class LisSetNode {
 		return neoEntityDTO;
 	}
 
+
+
+	/**
+	 * 根据关系名查询对应节点
+	 */
+	public List<?> getNodesbyRelation(LisSet lisSet, String relname) {
+		List<?> nodelist =  new ArrayList<>();
+
+		try {
+			switch (relname) {
+				case "实验室检查套餐名禁忌性别":
+					nodelist = Arrays.asList(lisSet.getLisSetgender().getGender());
+					break;
+				case "实验室检查套餐名禁忌禁忌人群":
+					nodelist = lisSet.getLisSetGroups().stream().map(x -> x.getGroup()).collect(Collectors.toList());
+					break;
+			}
+		}
+		catch (Exception ex) {
+			ex.printStackTrace();
+		}
+		finally {
+			return nodelist;
+		}
+	}
+
+
+	/**
+	 * 更新关系状态属性
+	 */
+	public void updateRelation(LisSet lisSet, String relname, Integer status, String e_name, LisSetRepository lisSetRepository) {
+
+		try {
+			switch (relname) {
+				case "实验室检查名称禁忌性别":
+					lisSet.getLisSetgender().setStatus(status);
+					lisSetRepository.save(lisSet);
+					break;
+				case "实验室检查名称禁忌禁忌人群":
+					lisSet.getLisSetGroups().stream().filter(x -> x.getGroup().getName()==e_name)
+							.collect(Collectors.toList()).stream().forEach(y -> y.setStatus(status));
+					lisSetRepository.save(lisSet);
+					break;
+//				case "实验室检查名称相关实验室检查套餐名":
+//					lisSet.getLisnamelisSet().stream().filter(x -> x.getLisSet().getName()==e_name).
+//							collect(Collectors.toList()).stream().forEach(y -> y.setStatus(status));
+//					lisSetRepository.save(lisSet);
+//					break;
+			}
+		}
+		catch (Exception ex) {
+			ex.printStackTrace();
+		}
+		finally {
+
+		}
+	}
+
 }
 

+ 39 - 0
src/main/java/com/diagbot/vo/EntityProp.java

@@ -0,0 +1,39 @@
+package com.diagbot.vo;
+
+import lombok.Data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @Description: 图谱实体属性入参
+ * @Author:Mark
+ * @time: 2020/11/05 9:38
+ */
+@Data
+public class EntityProp {
+    // 体征指标
+    private String vitalname;
+
+    // 最小值
+    private Double minval;
+
+    // 最大值
+    private Double maxval;
+
+    // 单位
+    private String unit;
+
+    // 范围
+    private Integer range;
+
+    // 拼音编码
+    private String pycode;
+
+    // 静态知识
+    private String knowledge;
+
+    // 静态知识标识, 0:没有静态知识, 1:有静态知识
+    private Integer is_kl;
+
+}

+ 11 - 5
src/main/java/com/diagbot/vo/NeoEntityVO.java

@@ -14,13 +14,19 @@ import java.util.Map;
  */
 @Data
 public class NeoEntityVO {
+    // 用户名
+    private String user;
     // 节点ID
-    private Integer ID;
+    private Long ID;
+    // 节点标签
+    private String label;
     // 节点名称
     private String name;
-    // 节点标签
-    private List<String> labels;
-    // 节点属性
-    private Map<String, String> property = new HashMap<>();
+    // 节点更新标签
+    private String newlabel;
+    // 节点更新名称
+    private String newname;
+    // 节点更新属性
+    private EntityProp entityProp;
 
 }

+ 32 - 0
src/main/java/com/diagbot/vo/NeoRelationVO.java

@@ -0,0 +1,32 @@
+package com.diagbot.vo;
+
+import lombok.Data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @Description: 图谱修改入参
+ * @Author:Mark
+ * @time: 2020/8/28 9:34
+ */
+@Data
+public class NeoRelationVO {
+    // 操作用户
+    private String user;
+    // 节点ID
+    private Long ID;
+    // 起始节点标签
+    private String startlabel;
+    // 起始节点名称
+    private String startname;
+    // 关系名称
+    private String relname;
+    // 终点节点标签
+    private String endabel;
+    // 终点节点名称
+    private String endname;
+    // 关系更新属性
+    private Map<String, String> property = new HashMap<>();
+
+}

+ 11 - 3
src/main/java/com/diagbot/web/EntityController.java

@@ -1,10 +1,12 @@
 package com.diagbot.web;
 
 import com.diagbot.dto.NeoEntityDTO;
+import com.diagbot.dto.NeoRelationDTO;
 import com.diagbot.entity.node.base.BaseNode;
 import com.diagbot.facade.EntityFacade;
 import com.diagbot.vo.KgQueryVO;
 import com.diagbot.vo.NeoEntityVO;
+import com.diagbot.vo.NeoRelationVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 
@@ -12,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -38,20 +41,25 @@ public class EntityController {
 
     @ApiOperation(value = "实体查询API", notes = "")
     @PostMapping("/getNode")
-    public List<BaseNode> getNodes(@RequestBody KgQueryVO kgQueryVO) {
+    public List<Map<String, Object>> getNodes(@RequestBody KgQueryVO kgQueryVO) {
         return entityFacade.getNodes(kgQueryVO);
     }
 
     @ApiOperation(value = "实体更新API", notes = "")
     @PostMapping("/updateNode")
     public NeoEntityDTO updateNode(@RequestBody NeoEntityVO neoEntityVO) {
-
         return entityFacade.updateNeoNode(neoEntityVO);
     }
 
+    @ApiOperation(value = "关系删除API", notes = "")
+    @PostMapping("/removeRelation")
+    public NeoRelationDTO removeRelation(@RequestBody NeoRelationVO neoRelationVO) {
+        return entityFacade.deleteNeoRelation(neoRelationVO);
+    }
+
     @ApiOperation(value = "实体删除API", notes = "")
     @PostMapping("/deleteNode")
-    public int deleteNode(@RequestBody NeoEntityVO neoEntityVO) {
+    public NeoEntityDTO deleteNode(@RequestBody NeoEntityVO neoEntityVO) {
         return entityFacade.deleteNeoNode(neoEntityVO);
     }