neo4j集成
parent
ec95a8e1b8
commit
9178a036fb
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.supervision</groupId>
|
||||
<artifactId>virtual-patient</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>virtual-patient-graph</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.supervision</groupId>
|
||||
<artifactId>virtual-patient-model</artifactId>
|
||||
<version>${version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.supervision</groupId>
|
||||
<artifactId>virtual-patient-common</artifactId>
|
||||
<version>${version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-neo4j</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,19 @@
|
||||
package com.supervision;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan(basePackages = {"com.supervision.**.mapper"})
|
||||
@EnableNeo4jRepositories("com.**.repo")
|
||||
public class VirtualPatientGraphApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(VirtualPatientGraphApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.supervision.config;
|
||||
|
||||
import org.neo4j.driver.AuthTokens;
|
||||
import org.neo4j.driver.Driver;
|
||||
import org.neo4j.driver.GraphDatabase;
|
||||
|
||||
import org.neo4j.ogm.session.SessionFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class Neo4jConfig {
|
||||
|
||||
@Value("${spring.data.neo4j.uri}")
|
||||
private String uri;
|
||||
|
||||
@Value("${spring.data.neo4j.username}")
|
||||
private String username;
|
||||
|
||||
@Value("${spring.data.neo4j.password}")
|
||||
private String password;
|
||||
|
||||
@Bean
|
||||
public Driver driver() {
|
||||
// 创建驱动器实例
|
||||
return GraphDatabase.driver(uri, AuthTokens.basic(username, password));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.supervision.controller;
|
||||
|
||||
|
||||
import com.supervision.node.DiseaseNode;
|
||||
import com.supervision.repo.DiseaseRepository;
|
||||
import com.supervision.service.GraphService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("graph")
|
||||
@RequiredArgsConstructor
|
||||
public class GraphController {
|
||||
|
||||
|
||||
private final GraphService graphService;
|
||||
|
||||
@GetMapping("createGraph")
|
||||
public void createGraph(String processId) {
|
||||
graphService.createGraph(processId);
|
||||
}
|
||||
|
||||
@GetMapping("queryGraph")
|
||||
public Object queryGraph(String processId){
|
||||
return graphService.queryGraph(processId);
|
||||
}
|
||||
|
||||
@GetMapping("deleteNode")
|
||||
public void deleteNode() {
|
||||
graphService.deleteNode();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.supervision.node;
|
||||
|
||||
import lombok.Data;
|
||||
import org.neo4j.ogm.annotation.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@NodeEntity("辅助检查")
|
||||
@Data
|
||||
public class AncillaryNode {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Property("辅助检查名称")
|
||||
private String ancillaryName;
|
||||
|
||||
@Relationship("诊断依据")
|
||||
private Set<DiseaseNode> diseaseNodeSet;
|
||||
|
||||
public AncillaryNode(String ancillaryName) {
|
||||
this.ancillaryName = ancillaryName;
|
||||
this.diseaseNodeSet = new HashSet<>();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.supervision.node;
|
||||
|
||||
import lombok.Data;
|
||||
import org.neo4j.ogm.annotation.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@NodeEntity("疾病分类名称")
|
||||
public class DiseaseNode {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Property("疾病名称")
|
||||
private String diseaseName;
|
||||
|
||||
public DiseaseNode(String diseaseName) {
|
||||
this.diseaseName = diseaseName;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.supervision.node;
|
||||
|
||||
import lombok.Data;
|
||||
import org.neo4j.ogm.annotation.NodeEntity;
|
||||
import org.neo4j.ogm.annotation.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@NodeEntity("处置计划")
|
||||
@Data
|
||||
public class DisposalMethodNode {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Property("处置计划类型")
|
||||
private String disposalMethod;
|
||||
|
||||
@Relationship("处置措施")
|
||||
private Set<TreatmentPlanNode> treatmentPlanNodeSet;
|
||||
|
||||
public DisposalMethodNode(String disposalMethod) {
|
||||
this.disposalMethod = disposalMethod;
|
||||
treatmentPlanNodeSet = new HashSet<>();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.supervision.node;
|
||||
|
||||
import lombok.Data;
|
||||
import org.neo4j.ogm.annotation.*;
|
||||
|
||||
|
||||
@NodeEntity("药品")
|
||||
@Data
|
||||
public class DrugNode {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Property("药品名称")
|
||||
private String drugName;
|
||||
|
||||
public DrugNode(String drugName) {
|
||||
this.drugName = drugName;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.supervision.node;
|
||||
|
||||
import lombok.Data;
|
||||
import org.neo4j.ogm.annotation.*;
|
||||
|
||||
@NodeEntity("知识库")
|
||||
@Data
|
||||
public class KnowledgeBaseNode {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Property("知识库")
|
||||
private String diseaseName;
|
||||
|
||||
public KnowledgeBaseNode(String diseaseName) {
|
||||
this.diseaseName = diseaseName;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.supervision.node;
|
||||
|
||||
import lombok.Data;
|
||||
import org.neo4j.ogm.annotation.*;
|
||||
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@NodeEntity("体格检查结果")
|
||||
public class PhysicalNode {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
|
||||
@Property("检查工具")
|
||||
private String toolName;
|
||||
|
||||
@Relationship("所属工具")
|
||||
private Set<PhysicalToolNode> physicalToolNodeSet;
|
||||
|
||||
@Relationship("诊断依据")
|
||||
private Set<DiseaseNode> diseaseNodeSet;
|
||||
|
||||
public PhysicalNode(String toolName) {
|
||||
this.toolName = toolName;
|
||||
this.physicalToolNodeSet = new HashSet<>();
|
||||
this.diseaseNodeSet = new HashSet<>();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.supervision.node;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.neo4j.ogm.annotation.*;
|
||||
|
||||
@Data
|
||||
@NodeEntity("体格检查工具")
|
||||
public class PhysicalToolNode {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Property("体格检查工具名称")
|
||||
private String name;
|
||||
|
||||
public PhysicalToolNode(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.supervision.node;
|
||||
|
||||
import lombok.Data;
|
||||
import org.neo4j.ogm.annotation.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@NodeEntity("问诊实例")
|
||||
public class ProcessNode {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Property("实例号")
|
||||
private String processNo;
|
||||
|
||||
@Relationship(type = "问诊")
|
||||
private Set<KnowledgeBaseNode> knowledgeBaseNodeSet;
|
||||
|
||||
@Relationship(type = "诊断")
|
||||
private Set<PhysicalNode> physicalNodeSet;
|
||||
|
||||
@Relationship(type = "诊断")
|
||||
private Set<AncillaryNode> ancillaryNodeSet;
|
||||
|
||||
@Relationship(type = "处置计划")
|
||||
private DisposalMethodNode disposalMethodNode;
|
||||
|
||||
@Relationship(type = "排除诊断")
|
||||
private Set<DiseaseNode> excludeDiagnosisNodeSet;
|
||||
|
||||
@Relationship(type = "最终诊断")
|
||||
private Set<DiseaseNode> finalDiagnosisNodeSet;
|
||||
|
||||
public ProcessNode(String processNo) {
|
||||
this.processNo = processNo;
|
||||
knowledgeBaseNodeSet = new HashSet<>();
|
||||
physicalNodeSet = new HashSet<>();
|
||||
ancillaryNodeSet = new HashSet<>();
|
||||
excludeDiagnosisNodeSet = new HashSet<>();
|
||||
finalDiagnosisNodeSet = new HashSet<>();
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.supervision.node;
|
||||
|
||||
import lombok.Data;
|
||||
import org.neo4j.ogm.annotation.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@NodeEntity("处置措施")
|
||||
public class TreatmentPlanNode {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Property("处置计划")
|
||||
private String treatmentPlanName;
|
||||
|
||||
@Relationship("所属药品")
|
||||
private Set<DrugNode> drugNodeSet;
|
||||
|
||||
public TreatmentPlanNode(String treatmentPlanName) {
|
||||
this.treatmentPlanName = treatmentPlanName;
|
||||
drugNodeSet = new HashSet<>();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.supervision.repo;
|
||||
|
||||
import com.supervision.node.AncillaryNode;
|
||||
import org.springframework.data.neo4j.repository.Neo4jRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface AncillaryRepository extends Neo4jRepository<AncillaryNode, Long> {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.supervision.repo;
|
||||
|
||||
import com.supervision.node.DiseaseNode;
|
||||
import org.springframework.data.neo4j.repository.Neo4jRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface DiseaseRepository extends Neo4jRepository<DiseaseNode, Long> {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.supervision.repo;
|
||||
|
||||
import com.supervision.node.DiseaseNode;
|
||||
import com.supervision.node.KnowledgeBaseNode;
|
||||
import org.springframework.data.neo4j.repository.Neo4jRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface KnowledgeRepository extends Neo4jRepository<KnowledgeBaseNode, Long> {
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.supervision.repo;
|
||||
|
||||
import com.supervision.node.AncillaryNode;
|
||||
import com.supervision.node.PhysicalNode;
|
||||
import org.springframework.data.neo4j.repository.Neo4jRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PhysicalRepository extends Neo4jRepository<PhysicalNode, Long> {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.supervision.repo;
|
||||
|
||||
import com.supervision.node.KnowledgeBaseNode;
|
||||
import com.supervision.node.PhysicalToolNode;
|
||||
import org.springframework.data.neo4j.repository.Neo4jRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PhysicalToolRepository extends Neo4jRepository<PhysicalToolNode, Long> {
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.supervision.repo;
|
||||
|
||||
import com.supervision.node.ProcessNode;
|
||||
import org.springframework.data.neo4j.repository.Neo4jRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ProcessRepository extends Neo4jRepository<ProcessNode, Long> {
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.supervision.repo;
|
||||
|
||||
import com.supervision.node.ProcessNode;
|
||||
import com.supervision.node.TreatmentPlanNode;
|
||||
import org.springframework.data.neo4j.repository.Neo4jRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface TreatmentPlanRepository extends Neo4jRepository<TreatmentPlanNode, Long> {
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.supervision.service;
|
||||
|
||||
public interface GraphService {
|
||||
|
||||
void createGraph(String processId);
|
||||
|
||||
void deleteNode();
|
||||
|
||||
Object queryGraph(String process);
|
||||
}
|
@ -0,0 +1,274 @@
|
||||
package com.supervision.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.supervision.exception.BusinessException;
|
||||
import com.supervision.model.Process;
|
||||
import com.supervision.model.*;
|
||||
import com.supervision.node.*;
|
||||
import com.supervision.repo.*;
|
||||
import com.supervision.service.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.neo4j.driver.Driver;
|
||||
import org.neo4j.driver.Record;
|
||||
import org.neo4j.driver.Result;
|
||||
import org.neo4j.driver.Session;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class GraphServiceImpl implements GraphService {
|
||||
|
||||
private final DiseaseService diseaseService;
|
||||
|
||||
private final MedicalRecService medicalRecService;
|
||||
|
||||
private final ProcessMedicalService processMedicalService;
|
||||
|
||||
private final ConfigPhysicalToolService configPhysicalToolService;
|
||||
|
||||
private final ConfigPhysicalLocationService configPhysicalLocationService;
|
||||
|
||||
private final ConfigAncillaryItemService configAncillaryItemService;
|
||||
|
||||
private final DiagnosisAncillaryRecordService diagnosisAncillaryRecordService;
|
||||
|
||||
private final DiagnosisPhysicalRecordService diagnosisPhysicalRecordService;
|
||||
|
||||
private final DiagnosisPrimaryRelationService relationService;
|
||||
|
||||
private final DiagnosisPrimaryService diagnosisPrimaryService;
|
||||
|
||||
private final DiseasePhysicalService diseasePhysicalService;
|
||||
|
||||
private final DiseaseAncillaryService diseaseAncillaryService;
|
||||
|
||||
private final ProcessService processService;
|
||||
|
||||
private final TreatmentPlanRecordService treatmentPlanRecordService;
|
||||
|
||||
private final ConfigTreatmentPlanService configTreatmentPlanService;
|
||||
|
||||
private final ConfigDrugService configDrugService;
|
||||
|
||||
private final DiseaseRepository diseaseRepository;
|
||||
|
||||
private final AncillaryRepository ancillaryRepository;
|
||||
|
||||
private final PhysicalRepository physicalRepository;
|
||||
|
||||
private final ProcessRepository processRepository;
|
||||
|
||||
private final KnowledgeRepository knowledgeRepository;
|
||||
|
||||
private final PhysicalToolRepository physicalToolRepository;
|
||||
|
||||
private final TreatmentPlanRepository treatmentPlanRepository;
|
||||
|
||||
private final Driver driver;
|
||||
|
||||
|
||||
@Override
|
||||
public void createGraph(String processId) {
|
||||
Process process = Optional.ofNullable(processService.getById(processId)).orElseThrow(() -> new BusinessException("未找到流程"));
|
||||
ProcessNode processNode = new ProcessNode("问诊实例" + process.getProcessNo());
|
||||
// 生成知识库的关联关系
|
||||
createKnowledge(processId, process, processNode);
|
||||
// 找到process关联的所有初步诊断
|
||||
Map<String, DiseaseNode> diseaseNodeMap = new HashMap<>();
|
||||
List<DiagnosisPrimary> diagnosisPrimaryList = diagnosisPrimaryService.lambdaQuery().eq(DiagnosisPrimary::getProcessId, processId).list();
|
||||
if (CollUtil.isNotEmpty(diagnosisPrimaryList)) {
|
||||
Set<String> diseaseIdSet = diagnosisPrimaryList.stream().map(DiagnosisPrimary::getPrimaryDiagnosisId).collect(Collectors.toSet());
|
||||
List<Disease> diseases = diseaseService.listByIds(diseaseIdSet);
|
||||
for (Disease disease : diseases) {
|
||||
DiseaseNode diseaseNode = new DiseaseNode(disease.getDiseaseNameAlias());
|
||||
diseaseRepository.save(diseaseNode);
|
||||
diseaseNodeMap.put(disease.getId(), diseaseNode);
|
||||
}
|
||||
|
||||
}
|
||||
// 体格检查结果
|
||||
createPhysical(processId, processNode, diseaseNodeMap);
|
||||
// 辅助检查结果
|
||||
createAncillary(processId, processNode, diseaseNodeMap);
|
||||
// 生成处置项
|
||||
createTreatment(processId, processNode);
|
||||
for (DiagnosisPrimary diagnosisPrimary : diagnosisPrimaryList) {
|
||||
// 生成最终诊断和排除诊断
|
||||
if (ObjectUtil.isNotEmpty(diagnosisPrimary.getExcludeFlag())) {
|
||||
if (1 == diagnosisPrimary.getExcludeFlag()) {
|
||||
Optional.ofNullable(diseaseNodeMap.get(diagnosisPrimary.getPrimaryDiagnosisId())).ifPresent(diseaseNode -> {
|
||||
processNode.getFinalDiagnosisNodeSet().add(diseaseNode);
|
||||
});
|
||||
}
|
||||
if (0 == diagnosisPrimary.getExcludeFlag()) {
|
||||
Optional.ofNullable(diseaseNodeMap.get(diagnosisPrimary.getPrimaryDiagnosisId())).ifPresent(diseaseNode -> {
|
||||
processNode.getExcludeDiagnosisNodeSet().add(diseaseNode);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
processRepository.save(processNode);
|
||||
|
||||
}
|
||||
|
||||
private void createTreatment(String processId, ProcessNode processNode) {
|
||||
|
||||
|
||||
List<TreatmentPlanRecord> treatmentPlanRecordList = treatmentPlanRecordService.lambdaQuery().eq(TreatmentPlanRecord::getProcessId, processId).list();
|
||||
// 生成处置计划
|
||||
treatmentPlanRecordList.stream().findAny().ifPresent(record -> {
|
||||
if (ObjectUtil.isNotEmpty(record.getDisposalMethod())) {
|
||||
DisposalMethodNode disposalMethodNode = new DisposalMethodNode(1 == record.getDisposalMethod() ? "住院治疗" : "门诊治疗");
|
||||
processNode.setDisposalMethodNode(disposalMethodNode);
|
||||
// 首先生成非药品的
|
||||
treatmentPlanRecordList.stream().filter(e -> StrUtil.isNotBlank(e.getTreatmentPlanId())).forEach(e -> {
|
||||
Optional.ofNullable(configTreatmentPlanService.getById(e.getTreatmentPlanId())).ifPresent(relation -> {
|
||||
TreatmentPlanNode treatmentPlanNode = new TreatmentPlanNode(relation.getDisposalPlan() + "," + relation.getFirstMeasures());
|
||||
disposalMethodNode.getTreatmentPlanNodeSet().add(treatmentPlanNode);
|
||||
});
|
||||
});
|
||||
// 生成药品的
|
||||
List<TreatmentPlanRecord> drugRecordList = treatmentPlanRecordList.stream().filter(e -> StrUtil.isBlank(e.getTreatmentPlanId()) && StrUtil.isNotBlank(e.getDrugId())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(drugRecordList)) {
|
||||
TreatmentPlanNode treatmentPlanNode = new TreatmentPlanNode("药品");
|
||||
disposalMethodNode.getTreatmentPlanNodeSet().add(treatmentPlanNode);
|
||||
for (TreatmentPlanRecord drugRecord : drugRecordList) {
|
||||
Optional.ofNullable(configDrugService.getById(drugRecord.getDrugId())).ifPresent(configDrug -> {
|
||||
DrugNode drugNode = new DrugNode(configDrug.getDrugName());
|
||||
treatmentPlanNode.getDrugNodeSet().add(drugNode);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 辅助检查
|
||||
*
|
||||
* @param processId 实例ID
|
||||
* @param processNode 实例节点
|
||||
* @param diseaseMap 疾病集合
|
||||
*/
|
||||
private void createAncillary(String processId, ProcessNode processNode, Map<String, DiseaseNode> diseaseMap) {
|
||||
List<DiagnosisAncillaryRecord> diagnosisAncillaryRecordList = diagnosisAncillaryRecordService.lambdaQuery().eq(DiagnosisAncillaryRecord::getProcessId, processId).list();
|
||||
for (DiagnosisAncillaryRecord diagnosisAncillaryRecord : diagnosisAncillaryRecordList) {
|
||||
Optional.ofNullable(configAncillaryItemService.getById(diagnosisAncillaryRecord.getAncillaryId())).ifPresent(ancillaryItem -> {
|
||||
Optional.ofNullable(diseaseAncillaryService.getById(diagnosisAncillaryRecord.getAncillaryId())).ifPresent(diseaseAncillary -> {
|
||||
// 根据预期诊断结果判断
|
||||
String expectedDiagnosisResult = (ObjectUtil.isNotNull(diseaseAncillary.getExpectedDiagnosisResult()) && 1 == diseaseAncillary.getExpectedDiagnosisResult()) ? "异常" : "正常";
|
||||
AncillaryNode ancillaryNode = new AncillaryNode(ancillaryItem.getItemName() + ":" + expectedDiagnosisResult);
|
||||
// 诊断依据
|
||||
Optional<DiagnosisPrimaryRelation> relationOptional = relationService.lambdaQuery().eq(DiagnosisPrimaryRelation::getRelationId, diagnosisAncillaryRecord.getId()).oneOpt();
|
||||
if (relationOptional.isPresent()) {
|
||||
DiagnosisPrimaryRelation primaryRelation = relationOptional.get();
|
||||
Optional<DiagnosisPrimary> primaryOptional = Optional.ofNullable(diagnosisPrimaryService.getById(primaryRelation.getPrimaryId()));
|
||||
primaryOptional.flatMap(diagnosisPrimary -> Optional.ofNullable(diseaseMap.get(diagnosisPrimary.getPrimaryDiagnosisId()))).ifPresent(diseaseNode -> {
|
||||
ancillaryNode.getDiseaseNodeSet().add(diseaseNode);
|
||||
});
|
||||
}
|
||||
processNode.getAncillaryNodeSet().add(ancillaryNode);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void createPhysical(String processId, ProcessNode processNode, Map<String, DiseaseNode> diseaseMap) {
|
||||
List<DiagnosisPhysicalRecord> physicalRecordList = diagnosisPhysicalRecordService.lambdaQuery().eq(DiagnosisPhysicalRecord::getProcessId, processId).list();
|
||||
|
||||
for (DiagnosisPhysicalRecord diagnosisPhysicalRecord : physicalRecordList) {
|
||||
Optional.ofNullable(diseasePhysicalService.getById(diagnosisPhysicalRecord.getPhysicalId())).ifPresent(diseasePhysical -> {
|
||||
// 构建工具
|
||||
if (StrUtil.isNotBlank(diagnosisPhysicalRecord.getToolId())) {
|
||||
Optional.ofNullable(configPhysicalToolService.getById(diagnosisPhysicalRecord.getToolId())).ifPresent(tool -> {
|
||||
PhysicalNode physicalNode = new PhysicalNode(tool.getToolName());
|
||||
// 构建所属位置
|
||||
if (StrUtil.isNotBlank(diagnosisPhysicalRecord.getLocationId())) {
|
||||
Optional<ConfigPhysicalLocation> locationOptional = Optional.ofNullable(configPhysicalLocationService.getById(diagnosisPhysicalRecord.getLocationId()));
|
||||
locationOptional.ifPresent(configPhysicalTool -> {
|
||||
// 根据是否有异常值,如果有异常结果,认为是异常
|
||||
String expectedDiagnosisResult = ObjectUtil.isNotEmpty(diseasePhysical.getResult()) ? "正常" : "异常";
|
||||
PhysicalToolNode physicalToolNode = new PhysicalToolNode(configPhysicalTool.getLocationName() + ":" + expectedDiagnosisResult);
|
||||
physicalNode.getPhysicalToolNodeSet().add(physicalToolNode);
|
||||
});
|
||||
}
|
||||
// 找到关联的初步诊断
|
||||
List<DiagnosisPrimaryRelation> diagnosisPrimaryRelationList = relationService.lambdaQuery().eq(DiagnosisPrimaryRelation::getRelationId, diagnosisPhysicalRecord.getId()).list();
|
||||
for (DiagnosisPrimaryRelation primaryRelation : diagnosisPrimaryRelationList) {
|
||||
Optional<DiagnosisPrimary> primaryOptional = Optional.ofNullable(diagnosisPrimaryService.getById(primaryRelation.getPrimaryId()));
|
||||
primaryOptional.flatMap(diagnosisPrimary -> Optional.ofNullable(diseaseMap.get(diagnosisPrimary.getPrimaryDiagnosisId()))).ifPresent(diseaseNode -> physicalNode.getDiseaseNodeSet().add(diseaseNode));
|
||||
}
|
||||
processNode.getPhysicalNodeSet().add(physicalNode);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void createKnowledge(String processId, Process process, ProcessNode processNode) {
|
||||
// 查询主诉作为知识库
|
||||
Optional<MedicalRec> medicalRecOptional = Optional.ofNullable(medicalRecService.getById(process.getMedicalRecId()));
|
||||
if (medicalRecOptional.isPresent()) {
|
||||
MedicalRec medicalRec = medicalRecOptional.get();
|
||||
KnowledgeBaseNode knowledgeBaseNode = new KnowledgeBaseNode(medicalRec.getSymptoms());
|
||||
processNode.getKnowledgeBaseNodeSet().add(knowledgeBaseNode);
|
||||
}
|
||||
// 个人史作为知识库
|
||||
Optional<ProcessMedical> processMedicalOptional = processMedicalService.lambdaQuery().eq(ProcessMedical::getProcessId, processId).oneOpt();
|
||||
if (processMedicalOptional.isPresent()) {
|
||||
ProcessMedical processMedical = processMedicalOptional.get();
|
||||
if (ObjectUtil.isNotEmpty(processMedical.getFamilyHistoryFlag()) && 1 == processMedical.getFamilyHistoryFlag()
|
||||
&& StrUtil.isNotBlank(processMedical.getFamilyHistory())) {
|
||||
KnowledgeBaseNode knowledgeBaseNode = new KnowledgeBaseNode("家族史:" + processMedical.getFamilyHistory());
|
||||
processNode.getKnowledgeBaseNodeSet().add(knowledgeBaseNode);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(processMedical.getAllergyHistoryFlag()) && 1 == processMedical.getAllergyHistoryFlag()
|
||||
&& StrUtil.isNotBlank(processMedical.getAllergyHistory())) {
|
||||
KnowledgeBaseNode knowledgeBaseNode = new KnowledgeBaseNode("过敏史:" + processMedical.getPersonalHistory());
|
||||
processNode.getKnowledgeBaseNodeSet().add(knowledgeBaseNode);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(processMedical.getPreviousHistoryFlag()) && 1 == processMedical.getPreviousHistoryFlag()
|
||||
&& StrUtil.isNotBlank(processMedical.getPreviousHistory())) {
|
||||
KnowledgeBaseNode knowledgeBaseNode = new KnowledgeBaseNode("既往史:" + processMedical.getPreviousHistory());
|
||||
processNode.getKnowledgeBaseNodeSet().add(knowledgeBaseNode);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(processMedical.getOperationHistoryFlag()) && 1 == processMedical.getOperationHistoryFlag()
|
||||
&& StrUtil.isNotBlank(processMedical.getOperationHistory())) {
|
||||
KnowledgeBaseNode knowledgeBaseNode = new KnowledgeBaseNode("手术史:" + processMedical.getOperationHistory());
|
||||
processNode.getKnowledgeBaseNodeSet().add(knowledgeBaseNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteNode() {
|
||||
diseaseRepository.deleteAll();
|
||||
ancillaryRepository.deleteAll();
|
||||
physicalRepository.deleteAll();
|
||||
processRepository.deleteAll();
|
||||
knowledgeRepository.deleteAll();
|
||||
physicalToolRepository.deleteAll();
|
||||
treatmentPlanRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object queryGraph(String processId) {
|
||||
try (Session session = driver.session()) {
|
||||
Result result = session.run("MATCH (n) RETURN n LIMIT 25");
|
||||
List<Record> list = result.list();
|
||||
return JSONUtil.toJsonStr(list);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
Binary file not shown.
Loading…
Reference in New Issue