From 0dd258fbae7d612226a8225d8ecb6c6f8e601a19 Mon Sep 17 00:00:00 2001 From: liu Date: Thu, 22 Feb 2024 13:16:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9F=A5=E8=AF=86=E5=9B=BE?= =?UTF-8?q?=E8=B0=B1,=E4=BD=BF=E7=94=A8nebula=E4=BD=9C=E4=B8=BA=E7=9F=A5?= =?UTF-8?q?=E8=AF=86=E5=9B=BE=E8=B0=B1=E7=9A=84=E5=AD=98=E5=82=A8=E5=92=8C?= =?UTF-8?q?=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GraphNebulaController.java | 16 ++- .../domain/AllergyHistoryVertex.java | 2 +- .../domain/AncillaryResultVertex.java | 2 +- .../supervision/domain/AncillaryVertex.java | 2 +- .../supervision/domain/DiagnosisVertex.java | 2 +- .../domain/FamilyHistoryVertex.java | 2 +- .../domain/IllnessHistoryVertex.java | 2 +- .../domain/MarriageChildHistoryVertex.java | 2 +- .../supervision/domain/MedicalRecVertex.java | 2 +- .../domain/OperationHistoryVertex.java | 2 +- .../com/supervision/domain/PatientVertex.java | 2 +- .../domain/PersonalHistoryVertex.java | 2 +- .../domain/PhysicalResultVertex.java | 2 +- .../supervision/domain/PhysicalVertex.java | 2 +- .../domain/PreviousHistoryVertex.java | 2 +- .../domain/ProcessMedicalVertex.java | 2 +- .../supervision/domain/SelfDescVertex.java | 2 +- .../domain/SinglePropertyEdge.java | 2 +- .../supervision/domain/SymptomsVertex.java | 2 +- .../domain/TreatmentPlanVertex.java | 2 +- .../java/com/supervision/enums/TagEnum.java | 64 +++++++++ .../service/GraphNebulaService.java | 7 +- .../service/impl/GraphNebulaServiceImpl.java | 134 +++++++++++++++--- .../main/java/com/supervision/vo/EdgeVO.java | 17 +++ .../main/java/com/supervision/vo/GraphVO.java | 17 +++ .../main/java/com/supervision/vo/NodeVO.java | 24 ++++ .../java/com/supervision/vo/TreeGraphVO.java | 7 + .../java/com/supervision/vo/TreeNodeVO.java | 30 ++++ .../src/main/resources/virtual-patient.nGQL | 40 +++--- 29 files changed, 331 insertions(+), 63 deletions(-) create mode 100644 virtual-patient-graph/src/main/java/com/supervision/enums/TagEnum.java create mode 100644 virtual-patient-graph/src/main/java/com/supervision/vo/EdgeVO.java create mode 100644 virtual-patient-graph/src/main/java/com/supervision/vo/GraphVO.java create mode 100644 virtual-patient-graph/src/main/java/com/supervision/vo/NodeVO.java create mode 100644 virtual-patient-graph/src/main/java/com/supervision/vo/TreeGraphVO.java create mode 100644 virtual-patient-graph/src/main/java/com/supervision/vo/TreeNodeVO.java diff --git a/virtual-patient-graph/src/main/java/com/supervision/controller/GraphNebulaController.java b/virtual-patient-graph/src/main/java/com/supervision/controller/GraphNebulaController.java index 4f2df5d5..6abfb6d2 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/controller/GraphNebulaController.java +++ b/virtual-patient-graph/src/main/java/com/supervision/controller/GraphNebulaController.java @@ -1,9 +1,11 @@ package com.supervision.controller; import com.supervision.service.GraphNebulaService; +import com.supervision.vo.GraphVO; +import com.supervision.vo.TreeNodeVO; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; -import org.nebula.contrib.ngbatis.models.data.NgSubgraph; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -16,15 +18,25 @@ public class GraphNebulaController { private final GraphNebulaService graphNebulaService; + @ApiOperation("创建图谱") @GetMapping("createGraph") public void createGraph(String processId) { graphNebulaService.creatGraphByNebula(processId); } + + @ApiOperation("查询图谱") @GetMapping("queryGraph") - public List> queryGraph(String processId) { + public GraphVO queryGraph(String processId) { return graphNebulaService.queryGraph(processId); } + @ApiOperation("查询树形结构图") + @GetMapping("queryTreeGraph") + public List queryTreeGraph(String processId) { + return graphNebulaService.queryTreeGraph(processId); + } + + } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/AllergyHistoryVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/AllergyHistoryVertex.java index 3608ef10..4443f3fe 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/AllergyHistoryVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/AllergyHistoryVertex.java @@ -16,6 +16,6 @@ public class AllergyHistoryVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/AncillaryResultVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/AncillaryResultVertex.java index fed7ec66..3c50de5d 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/AncillaryResultVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/AncillaryResultVertex.java @@ -15,5 +15,5 @@ public class AncillaryResultVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/AncillaryVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/AncillaryVertex.java index 66eeee5a..8a1f13aa 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/AncillaryVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/AncillaryVertex.java @@ -15,5 +15,5 @@ public class AncillaryVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/DiagnosisVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/DiagnosisVertex.java index 1641a155..e01a8233 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/DiagnosisVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/DiagnosisVertex.java @@ -15,5 +15,5 @@ public class DiagnosisVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/FamilyHistoryVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/FamilyHistoryVertex.java index ee4659e5..f045ad5a 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/FamilyHistoryVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/FamilyHistoryVertex.java @@ -15,5 +15,5 @@ public class FamilyHistoryVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/IllnessHistoryVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/IllnessHistoryVertex.java index 7b8adcc4..cad34ec7 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/IllnessHistoryVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/IllnessHistoryVertex.java @@ -15,5 +15,5 @@ public class IllnessHistoryVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/MarriageChildHistoryVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/MarriageChildHistoryVertex.java index 9e3f9f21..1862c7a8 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/MarriageChildHistoryVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/MarriageChildHistoryVertex.java @@ -15,5 +15,5 @@ public class MarriageChildHistoryVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/MedicalRecVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/MedicalRecVertex.java index 6a03223c..5ee8d585 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/MedicalRecVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/MedicalRecVertex.java @@ -12,6 +12,6 @@ public class MedicalRecVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/OperationHistoryVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/OperationHistoryVertex.java index d63b4c7e..e018b498 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/OperationHistoryVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/OperationHistoryVertex.java @@ -15,5 +15,5 @@ public class OperationHistoryVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/PatientVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/PatientVertex.java index cbbcb02d..8d6eae16 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/PatientVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/PatientVertex.java @@ -14,6 +14,6 @@ public class PatientVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/PersonalHistoryVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/PersonalHistoryVertex.java index d392747b..a0419409 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/PersonalHistoryVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/PersonalHistoryVertex.java @@ -15,5 +15,5 @@ public class PersonalHistoryVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/PhysicalResultVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/PhysicalResultVertex.java index 246a4f9f..20849007 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/PhysicalResultVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/PhysicalResultVertex.java @@ -15,5 +15,5 @@ public class PhysicalResultVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/PhysicalVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/PhysicalVertex.java index 82fa6a39..35ab71e4 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/PhysicalVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/PhysicalVertex.java @@ -15,5 +15,5 @@ public class PhysicalVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/PreviousHistoryVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/PreviousHistoryVertex.java index 13fafb10..2c699542 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/PreviousHistoryVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/PreviousHistoryVertex.java @@ -15,5 +15,5 @@ public class PreviousHistoryVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/ProcessMedicalVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/ProcessMedicalVertex.java index 11048d67..0d7bef92 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/ProcessMedicalVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/ProcessMedicalVertex.java @@ -12,5 +12,5 @@ public class ProcessMedicalVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/SelfDescVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/SelfDescVertex.java index 9620e94f..4d353ecc 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/SelfDescVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/SelfDescVertex.java @@ -12,5 +12,5 @@ public class SelfDescVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/SinglePropertyEdge.java b/virtual-patient-graph/src/main/java/com/supervision/domain/SinglePropertyEdge.java index e8b27ffd..fe12ac74 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/SinglePropertyEdge.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/SinglePropertyEdge.java @@ -16,5 +16,5 @@ import javax.persistence.Table; public class SinglePropertyEdge { - private String name; + private String edgeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/SymptomsVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/SymptomsVertex.java index 0402c53d..d1a8657d 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/SymptomsVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/SymptomsVertex.java @@ -15,5 +15,5 @@ public class SymptomsVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/domain/TreatmentPlanVertex.java b/virtual-patient-graph/src/main/java/com/supervision/domain/TreatmentPlanVertex.java index 1a0ee35e..56aaf7bb 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/domain/TreatmentPlanVertex.java +++ b/virtual-patient-graph/src/main/java/com/supervision/domain/TreatmentPlanVertex.java @@ -15,5 +15,5 @@ public class TreatmentPlanVertex { @Id private String id; - private String name; + private String nodeValue; } diff --git a/virtual-patient-graph/src/main/java/com/supervision/enums/TagEnum.java b/virtual-patient-graph/src/main/java/com/supervision/enums/TagEnum.java new file mode 100644 index 00000000..08006acc --- /dev/null +++ b/virtual-patient-graph/src/main/java/com/supervision/enums/TagEnum.java @@ -0,0 +1,64 @@ +package com.supervision.enums; + +public enum TagEnum { + medical_rec("病例", 1, "#00B8F5"), + + process_medical("电子病历", 2, "#00B8F5"), + + self_desc("主诉", 3, "#00B8F5"), + + previous_history("既往病史", 3, "#00B8F5"), + + illness_history("现病史", 3, "#00B8F5"), + + personal_history("个人史", 3, "#00B8F5"), + + allergy_history("过敏史", 3, "#00B8F5"), + + family_history("家族史", 3, "#00B8F5"), + + marriage_child_history("婚育史", 3, "#00B8F5"), + + operation_history("手术史", 3, "#00B8F5"), + + symptoms("症状", 2, "#00B8F5"), + + patient("患者信息", 2, "#00B8F5"), + + physical("体格检查", 2, "#00B8F5"), + + physical_result("体格检查结果", 2, "#00B8F5"), + + ancillary("辅助检查", 2, "#00B8F5"), + + ancillary_result("辅助检查结果", 2, "#00B8F5"), + + treatment_plan("处置计划", 2, "#00B8F5"), + + diagnosis("诊断", 2, "#00B8F5"); + + private final String type; + + private final Integer level; + + private final String colour; + + TagEnum(String type, Integer level, String colour) { + this.type = type; + this.level = level; + this.colour = colour; + + } + + public String getType() { + return type; + } + + public Integer getLevel() { + return level; + } + + public String getColour() { + return colour; + } +} diff --git a/virtual-patient-graph/src/main/java/com/supervision/service/GraphNebulaService.java b/virtual-patient-graph/src/main/java/com/supervision/service/GraphNebulaService.java index efb2edfc..0891d658 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/service/GraphNebulaService.java +++ b/virtual-patient-graph/src/main/java/com/supervision/service/GraphNebulaService.java @@ -1,6 +1,7 @@ package com.supervision.service; -import org.nebula.contrib.ngbatis.models.data.NgSubgraph; +import com.supervision.vo.GraphVO; +import com.supervision.vo.TreeNodeVO; import java.util.List; @@ -8,6 +9,8 @@ public interface GraphNebulaService { void creatGraphByNebula(String processId); - List> queryGraph(String processId); + GraphVO queryGraph(String processId); + + List queryTreeGraph(String processId); } diff --git a/virtual-patient-graph/src/main/java/com/supervision/service/impl/GraphNebulaServiceImpl.java b/virtual-patient-graph/src/main/java/com/supervision/service/impl/GraphNebulaServiceImpl.java index 0713f01e..bafce50c 100644 --- a/virtual-patient-graph/src/main/java/com/supervision/service/impl/GraphNebulaServiceImpl.java +++ b/virtual-patient-graph/src/main/java/com/supervision/service/impl/GraphNebulaServiceImpl.java @@ -1,5 +1,7 @@ package com.supervision.service.impl; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.NumberUtil; @@ -7,20 +9,26 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.supervision.dao.*; import com.supervision.domain.*; +import com.supervision.enums.TagEnum; import com.supervision.exception.BusinessException; import com.supervision.model.Process; import com.supervision.model.*; import com.supervision.service.*; +import com.supervision.vo.EdgeVO; +import com.supervision.vo.GraphVO; +import com.supervision.vo.NodeVO; +import com.supervision.vo.TreeNodeVO; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.nebula.contrib.ngbatis.models.data.NgEdge; import org.nebula.contrib.ngbatis.models.data.NgSubgraph; +import org.nebula.contrib.ngbatis.models.data.NgVertex; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; @Slf4j @Service @@ -78,21 +86,21 @@ public class GraphNebulaServiceImpl implements GraphNebulaService { // 首先创建一个病历 MedicalRecVertex medicalRecVertex = new MedicalRecVertex(); - medicalRecVertex.setName((disposalMethod == 0 ? "门诊" : "住院") + "(" + DateUtil.format(process.getCreateTime(), "yyyy-MM-dd") + ")"); + medicalRecVertex.setNodeValue((disposalMethod == 0 ? "门诊" : "住院") + "(" + DateUtil.format(process.getCreateTime(), "yyyy-MM-dd") + ")"); medicalRecDao.insert(medicalRecVertex); log.info("病历图谱ID:{}", medicalRecVertex.getId()); // 根据processId找到电子病历 ProcessMedical processMedical = processMedicalService.lambdaQuery().eq(ProcessMedical::getProcessId, processId).oneOpt().orElseThrow(() -> new BusinessException("未找到电子病历")); ProcessMedicalVertex processMedicalVertex = new ProcessMedicalVertex(); - processMedicalVertex.setName("病历(" + DateUtil.format(processMedical.getCreateTime(), "yyyy-MM-dd") + ")"); + processMedicalVertex.setNodeValue("病历(" + DateUtil.format(processMedical.getCreateTime(), "yyyy-MM-dd") + ")"); processMedicalDao.insert(processMedicalVertex); medicalRecDao.insertEdge(medicalRecVertex, new NoPropertyEdge(), processMedicalVertex); // 创建主诉节点 if (StrUtil.isNotBlank(processMedical.getPatientSelfDesc())) { SelfDescVertex selfDescVertex = new SelfDescVertex(); - selfDescVertex.setName("主诉:" + processMedical.getPatientSelfDesc()); + selfDescVertex.setNodeValue(processMedical.getPatientSelfDesc()); selfDescDao.insert(selfDescVertex); // 保存节点之间的关系 processMedicalDao.insertEdge(processMedicalVertex, new NoPropertyEdge(), selfDescVertex); @@ -100,7 +108,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService { // 创建现病史节点 if (StrUtil.isNotBlank(processMedical.getIllnessHistory())) { IllnessHistoryVertex illnessHistoryVertex = new IllnessHistoryVertex(); - illnessHistoryVertex.setName("现病史:" + processMedical.getIllnessHistory()); + illnessHistoryVertex.setNodeValue(processMedical.getIllnessHistory()); illnessHistoryDao.insert(illnessHistoryVertex); // 保存节点之间的关系 processMedicalDao.insertEdge(processMedicalVertex, new NoPropertyEdge(), illnessHistoryVertex); @@ -108,7 +116,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService { // 创建个人史节点 if (StrUtil.isNotBlank(processMedical.getPersonalHistory())) { PersonalHistoryVertex personalHistoryVertex = new PersonalHistoryVertex(); - personalHistoryVertex.setName("个人史:" + processMedical.getPersonalHistory()); + personalHistoryVertex.setNodeValue(processMedical.getPersonalHistory()); personalHistoryDao.insert(personalHistoryVertex); // 保存节点之间的关系 processMedicalDao.insertEdge(processMedicalVertex, new NoPropertyEdge(), personalHistoryVertex); @@ -116,7 +124,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService { // 创建过敏史节点 if (ObjectUtil.isNotEmpty(processMedical.getAllergyHistoryFlag()) && 1 == processMedical.getAllergyHistoryFlag() && StrUtil.isNotBlank(processMedical.getAllergyHistory())) { AllergyHistoryVertex allergyHistoryVertex = new AllergyHistoryVertex(); - allergyHistoryVertex.setName("过敏史:" + processMedical.getAllergyHistory()); + allergyHistoryVertex.setNodeValue(processMedical.getAllergyHistory()); allergyHistoryDao.insert(allergyHistoryVertex); // 保存节点之间的关系 processMedicalDao.insertEdge(processMedicalVertex, new NoPropertyEdge(), allergyHistoryVertex); @@ -124,7 +132,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService { // 创建既往史节点 if (ObjectUtil.isNotEmpty(processMedical.getPreviousHistoryFlag()) && 1 == processMedical.getPreviousHistoryFlag() && StrUtil.isNotBlank(processMedical.getPreviousHistory())) { PreviousHistoryVertex previousHistoryVertex = new PreviousHistoryVertex(); - previousHistoryVertex.setName("既往史:" + processMedical.getPreviousHistory()); + previousHistoryVertex.setNodeValue(processMedical.getPreviousHistory()); previousHistoryDao.insert(previousHistoryVertex); // 保存节点之间的关系 processMedicalDao.insertEdge(processMedicalVertex, new NoPropertyEdge(), previousHistoryVertex); @@ -132,7 +140,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService { // 创建家族史节点 if (ObjectUtil.isNotEmpty(processMedical.getFamilyHistoryFlag()) && 1 == processMedical.getFamilyHistoryFlag() && StrUtil.isNotBlank(processMedical.getFamilyHistory())) { FamilyHistoryVertex familyHistoryVertex = new FamilyHistoryVertex(); - familyHistoryVertex.setName("家族史:" + processMedical.getFamilyHistory()); + familyHistoryVertex.setNodeValue(processMedical.getFamilyHistory()); familyHistoryDao.insert(familyHistoryVertex); // 保存节点之间的关系 processMedicalDao.insertEdge(processMedicalVertex, new NoPropertyEdge(), familyHistoryVertex); @@ -140,7 +148,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService { // 创建手术史节点 if (ObjectUtil.isNotEmpty(processMedical.getOperationHistory()) && 1 == processMedical.getOperationHistoryFlag() && StrUtil.isNotBlank(processMedical.getOperationHistory())) { OperationHistoryVertex operationHistoryVertex = new OperationHistoryVertex(); - operationHistoryVertex.setName("手术史:" + processMedical.getOperationHistory()); + operationHistoryVertex.setNodeValue(processMedical.getOperationHistory()); operationHistoryDao.insert(operationHistoryVertex); // 保存节点之间的关系 processMedicalDao.insertEdge(processMedicalVertex, new NoPropertyEdge(), operationHistoryVertex); @@ -148,7 +156,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService { // 创建患者节点 MedicalRec medicalRec = Optional.ofNullable(medicalRecService.getById(process.getMedicalRecId())).orElseThrow(() -> new BusinessException("未找到病历")); PatientVertex patientVertex = new PatientVertex(); - patientVertex.setName("患者:" + medicalRec.getPatientName()); + patientVertex.setNodeValue(medicalRec.getPatientName()); patientDao.insert(patientVertex); processMedicalDao.insertEdge(medicalRecVertex, new NoPropertyEdge(), patientVertex); @@ -165,7 +173,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService { } if (ObjectUtil.isNotEmpty(tool)) { PhysicalVertex physicalVertex = new PhysicalVertex(); - physicalVertex.setName("体格检查:" + tool.getToolName() + (location != null ? ("-" + location.getLocationName()) : "")); + physicalVertex.setNodeValue(tool.getToolName() + (location != null ? ("-" + location.getLocationName()) : "")); physicalDao.insert(physicalVertex); processMedicalDao.insertEdge(medicalRecVertex, new NoPropertyEdge(), physicalVertex); // 如果是证实诊断依据,添加到证实诊断依据里面去 @@ -183,13 +191,13 @@ public class GraphNebulaServiceImpl implements GraphNebulaService { ConfigAncillaryItem configAncillaryItem = configAncillaryItemService.getById(diagnosisAncillaryRecord.getItemId()); if (ObjectUtil.isNotEmpty(configAncillaryItem)) { AncillaryVertex ancillaryVertex = new AncillaryVertex(); - ancillaryVertex.setName("辅助检查:" + configAncillaryItem.getItemName()); + ancillaryVertex.setNodeValue(configAncillaryItem.getItemName()); ancillaryDao.insert(ancillaryVertex); // 保存病历和辅助检查连线 medicalRecDao.insertEdge(medicalRecVertex, new NoPropertyEdge(), ancillaryVertex); // 结果节点 AncillaryResultVertex ancillaryResultVertex = new AncillaryResultVertex(); - ancillaryResultVertex.setName(diagnosisAncillaryRecord.getResult()); + ancillaryResultVertex.setNodeValue(diagnosisAncillaryRecord.getResult()); ancillaryResultDao.insert(ancillaryResultVertex); // 保存检查结果连线 ancillaryDao.insertEdge(ancillaryVertex, new SinglePropertyEdge("结果"), ancillaryResultVertex); @@ -207,7 +215,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService { Disease disease = diseaseService.getById(diagnosisPrimary.getPrimaryDiagnosisId()); if (ObjectUtil.isNotEmpty(disease)) { DiagnosisVertex diagnosisVertex = new DiagnosisVertex(); - diagnosisVertex.setName("诊断:" + disease.getDiseaseNameAlias()); + diagnosisVertex.setNodeValue(disease.getDiseaseNameAlias()); diagnosisDao.insert(diagnosisVertex); diagnosisDao.insertEdge(medicalRecVertex, new SinglePropertyEdge("诊断"), diagnosisVertex); diagnosisMap.put(diagnosisPrimary.getId(), diagnosisVertex); @@ -237,10 +245,96 @@ public class GraphNebulaServiceImpl implements GraphNebulaService { @Override - public List> queryGraph(String processId) { + public GraphVO queryGraph(String processId) { Process process = Optional.ofNullable(processService.getById(processId)).orElseThrow(() -> new BusinessException("未找到对应的问诊流程")); - return medicalRecDao.selectSubgraph(process.getGraphId()); + List> subgraphList = medicalRecDao.selectSubgraph(process.getGraphId()); + + List nodeList = new ArrayList<>(); + List edgeList = new ArrayList<>(); + for (NgSubgraph subgraph : subgraphList) { + // 首先构建点 + List> vertexes = subgraph.getVertexes(); + for (NgVertex vertex : vertexes) { + NodeVO nodeVO = new NodeVO(); + String vid = vertex.getVid(); + nodeVO.setId(vid); + Map properties = vertex.getProperties(); + for (Map.Entry entry : properties.entrySet()) { + String key = entry.getKey(); + TagEnum tagEnum = TagEnum.valueOf(key); + if (ObjectUtil.isNotEmpty(tagEnum)) { + nodeVO.setNodeType(tagEnum.name()); + nodeVO.setNodeDesc(tagEnum.getType()); + nodeVO.setNodeColour(tagEnum.getColour()); + nodeVO.setNodeLevel(tagEnum.getLevel()); + } + Object value = entry.getValue(); + if (value instanceof Map) { + Map map = (Map) value; + Object nodeValue = map.get("nodeValue"); + if (ObjectUtil.isNotEmpty(nodeValue)) { + nodeVO.setNodeValue(String.valueOf(nodeValue)); + } + map.forEach((k, v) -> { + if (ObjectUtil.isNotEmpty(k)) { + nodeVO.getParams().put(String.valueOf(k), v); + } + }); + } + } + nodeList.add(nodeVO); + } + // 构建边 + List> edges = subgraph.getEdges(); + for (NgEdge edge : edges) { + EdgeVO edgeVO = new EdgeVO(); + edgeVO.setSource(edge.getSrcID()); + edgeVO.setTarget(edge.getDstID()); + Map properties = edge.getProperties(); + Object nameObject = properties.get("edgeValue"); + if (ObjectUtil.isNotEmpty(nameObject)) { + edgeVO.setName(String.valueOf(nameObject)); + } + edgeVO.setParams(properties); + edgeList.add(edgeVO); + } + } + return new GraphVO(nodeList, edgeList); + } + + @Override + public List queryTreeGraph(String processId) { + GraphVO graphVO = queryGraph(processId); + List treeNodeList = graphVO.getNodes().stream().map(node -> BeanUtil.toBean(node, TreeNodeVO.class)).collect(Collectors.toList()); + // 首先找到第一级节点 + List firstNodeList = treeNodeList.stream().filter(node -> node.getNodeLevel() == 1).collect(Collectors.toList()); + if (CollUtil.isEmpty(firstNodeList)) { + return null; + } + // treeNodeList转换为map,key为节点ID,value为节点对象 + Map treeNodeMap = treeNodeList.stream().collect(Collectors.toMap(TreeNodeVO::getId, Function.identity())); + for (TreeNodeVO nodeVO : firstNodeList) { + recursionBuildTree(nodeVO, treeNodeMap, graphVO.getEdges()); + } + return firstNodeList; } + private void recursionBuildTree(TreeNodeVO preNode, Map treeNodeMap, List edgeList) { + // 通过preNode的ID找到所有的子节点 + List childNode = new ArrayList<>(); + for (EdgeVO edgeVO : edgeList) { + if (StrUtil.equals(edgeVO.getSource(), preNode.getId())) { + TreeNodeVO treeNodeVO = treeNodeMap.get(edgeVO.getTarget()); + if (ObjectUtil.isNotEmpty(treeNodeVO)) { + childNode.add(treeNodeVO); + } + ; + } + } + preNode.setChildNodeList(childNode); + for (TreeNodeVO treeNodeVO : childNode) { + recursionBuildTree(treeNodeVO, treeNodeMap, edgeList); + } + } } diff --git a/virtual-patient-graph/src/main/java/com/supervision/vo/EdgeVO.java b/virtual-patient-graph/src/main/java/com/supervision/vo/EdgeVO.java new file mode 100644 index 00000000..9411fbe8 --- /dev/null +++ b/virtual-patient-graph/src/main/java/com/supervision/vo/EdgeVO.java @@ -0,0 +1,17 @@ +package com.supervision.vo; + +import lombok.Data; + +import java.util.Map; + +@Data +public class EdgeVO { + + private String source; + + private String target; + + private String name; + + private Map params; +} diff --git a/virtual-patient-graph/src/main/java/com/supervision/vo/GraphVO.java b/virtual-patient-graph/src/main/java/com/supervision/vo/GraphVO.java new file mode 100644 index 00000000..0139923d --- /dev/null +++ b/virtual-patient-graph/src/main/java/com/supervision/vo/GraphVO.java @@ -0,0 +1,17 @@ +package com.supervision.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class GraphVO { + + private List nodes; + + private List edges; +} diff --git a/virtual-patient-graph/src/main/java/com/supervision/vo/NodeVO.java b/virtual-patient-graph/src/main/java/com/supervision/vo/NodeVO.java new file mode 100644 index 00000000..dad5f842 --- /dev/null +++ b/virtual-patient-graph/src/main/java/com/supervision/vo/NodeVO.java @@ -0,0 +1,24 @@ +package com.supervision.vo; + +import lombok.Data; + +import java.util.LinkedHashMap; +import java.util.Map; + +@Data +public class NodeVO { + + private String id; + + private String nodeValue; + + private String nodeColour; + + private Integer nodeLevel; + + private String nodeType; + + private String nodeDesc; + + private Map params = new LinkedHashMap<>(); +} diff --git a/virtual-patient-graph/src/main/java/com/supervision/vo/TreeGraphVO.java b/virtual-patient-graph/src/main/java/com/supervision/vo/TreeGraphVO.java new file mode 100644 index 00000000..380ca1dc --- /dev/null +++ b/virtual-patient-graph/src/main/java/com/supervision/vo/TreeGraphVO.java @@ -0,0 +1,7 @@ +package com.supervision.vo; + +import lombok.Data; + +@Data +public class TreeGraphVO { +} diff --git a/virtual-patient-graph/src/main/java/com/supervision/vo/TreeNodeVO.java b/virtual-patient-graph/src/main/java/com/supervision/vo/TreeNodeVO.java new file mode 100644 index 00000000..e81127a1 --- /dev/null +++ b/virtual-patient-graph/src/main/java/com/supervision/vo/TreeNodeVO.java @@ -0,0 +1,30 @@ +package com.supervision.vo; + +import lombok.Data; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +@Data +public class TreeNodeVO { + + private String id; + + private String nodeValue; + + private String nodeColour; + + private Integer nodeLevel; + + private String nodeType; + + private String nodeDesc; + + private Map params = new LinkedHashMap<>(); + + /** + * 子节点 + */ + private List childNodeList; +} diff --git a/virtual-patient-graph/src/main/resources/virtual-patient.nGQL b/virtual-patient-graph/src/main/resources/virtual-patient.nGQL index 7b7c088c..09512f1d 100644 --- a/virtual-patient-graph/src/main/resources/virtual-patient.nGQL +++ b/virtual-patient-graph/src/main/resources/virtual-patient.nGQL @@ -5,49 +5,49 @@ CREATE SPACE IF NOT EXISTS virtual_patient (vid_type=FIXED_STRING(64)) comment= USE virtual_patient; // 切换图空间 // 创建病历节点 -CREATE TAG IF NOT EXISTS medical_rec(name String); +CREATE TAG IF NOT EXISTS medical_rec(nodeValue string); // 创建电子病历节点 -CREATE TAG IF NOT EXISTS process_medical(name string); +CREATE TAG IF NOT EXISTS process_medical(nodeValue string); // 创建主诉节点 -CREATE TAG IF NOT EXISTS self_desc(name string); +CREATE TAG IF NOT EXISTS self_desc(nodeValue string); // 创建既往病史节点 -CREATE TAG IF NOT EXISTS previous_history(name string); +CREATE TAG IF NOT EXISTS previous_history(nodeValue string); // 创建现病史节点 -CREATE TAG IF NOT EXISTS illness_history(name string); +CREATE TAG IF NOT EXISTS illness_history(nodeValue string); // 创建个人史节点 -CREATE TAG IF NOT EXISTS personal_history(name string); +CREATE TAG IF NOT EXISTS personal_history(nodeValue string); // 创建过敏史节点 -CREATE TAG IF NOT EXISTS allergy_history(name string); +CREATE TAG IF NOT EXISTS allergy_history(nodeValue string); // 创建家族史节点 -CREATE TAG IF NOT EXISTS family_history(name string); +CREATE TAG IF NOT EXISTS family_history(nodeValue string); // 创建婚育史节点 -CREATE TAG IF NOT EXISTS marriage_child_history(name string); +CREATE TAG IF NOT EXISTS marriage_child_history(nodeValue string); // 创建手术史节点 -CREATE TAG IF NOT EXISTS operation_history(name string); +CREATE TAG IF NOT EXISTS operation_history(nodeValue string); // 创建症状节点 -CREATE TAG IF NOT EXISTS symptoms(name string); +CREATE TAG IF NOT EXISTS symptoms(nodeValue string); // 创建患者信息节点 -CREATE TAG IF NOT EXISTS patient(name string); +CREATE TAG IF NOT EXISTS patient(nodeValue string); // 创建体格检查节点 -CREATE TAG IF NOT EXISTS physical(name string); +CREATE TAG IF NOT EXISTS physical(nodeValue string); // 创建体格检查结果节点 -CREATE TAG IF NOT EXISTS physical_result(name string); +CREATE TAG IF NOT EXISTS physical_result(nodeValue string); // 创建辅助检查节点 -CREATE TAG IF NOT EXISTS ancillary(name string); +CREATE TAG IF NOT EXISTS ancillary(nodeValue string); // 创建辅助检查结果节点 -CREATE TAG IF NOT EXISTS ancillary_result(name string); +CREATE TAG IF NOT EXISTS ancillary_result(nodeValue string); // 创建处置节点 -CREATE TAG IF NOT EXISTS treatment_plan(name string); +CREATE TAG IF NOT EXISTS treatment_plan(nodeValue string); // 创建诊断(疾病)节点 -CREATE TAG IF NOT EXISTS diagnosis(name string); +CREATE TAG IF NOT EXISTS diagnosis(nodeValue string); // 创建无属性的边 CREATE EDGE IF NOT EXISTS no_property_edge(); // 创建单个属性的边 -CREATE EDGE IF NOT EXISTS single_property_edge(name string); +CREATE EDGE IF NOT EXISTS single_property_edge(edgeValue string); // 创建病历索引 -CREATE TAG INDEX medical_rec_index ON medical_rec (name(64)) +CREATE TAG INDEX medical_rec_index ON medical_rec (nodeValue(64))