@ -77,33 +77,33 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
@Override
public String creatGraphByNebula ( String processId ) {
Process process = Optional . ofNullable ( processService . getById ( processId ) ) . orElseThrow ( ( ) - > new BusinessException ( " 未找到流程,创建图谱失败 ") ) ;
Process process = Optional . ofNullable ( processService . getById ( processId ) ) . orElseThrow ( ( ) - > new BusinessException ( " Workflow not found, failed to create map ") ) ;
// 根据processId找到对应的诊疗计划,如果没有找到,说明治疗流程未完成,诊断失败
List < TreatmentPlanRecord > treatmentPlanRecordList = treatmentPlanRecordService . lambdaQuery ( ) . eq ( TreatmentPlanRecord : : getProcessId , processId ) . list ( ) ;
Integer disposalMethod = treatmentPlanRecordList . stream ( ) . findAny ( ) . orElse ( new TreatmentPlanRecord ( ) ) . getDisposalMethod ( ) ;
MedicalRec medicalRec = Optional . ofNullable ( medicalRecService . getById ( process . getMedicalRecId ( ) ) ) . orElseThrow ( ( ) - > new BusinessException ( " 未找到病历 ") ) ;
MedicalRec medicalRec = Optional . ofNullable ( medicalRecService . getById ( process . getMedicalRecId ( ) ) ) . orElseThrow ( ( ) - > new BusinessException ( " Medical records not found ") ) ;
// 首先创建一个病历
MedicalRecVertex medicalRecVertex = new MedicalRecVertex ( ) ;
// 格式:患者名称-门诊/住院(时间)
// 如果没有填写治疗计划,默认为门诊
medicalRecVertex . setNodeValue ( ( ObjectUtil . isEmpty ( disposalMethod ) | | disposalMethod = = 0 ? " 门诊" : "住院 ") + "-" + medicalRec . getPatientName ( ) + "(" + DateUtil . format ( process . getCreateTime ( ) , "yyyy-MM-dd" ) + ")" ) ;
medicalRecVertex . setNodeValue ( ( ObjectUtil . isEmpty ( disposalMethod ) | | disposalMethod = = 0 ? " Outpatient" : "Hospitalization ") + "-" + medicalRec . getPatientName ( ) + "(" + 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 ( " 未找到电子病历 ") ) ;
ProcessMedical processMedical = processMedicalService . lambdaQuery ( ) . eq ( ProcessMedical : : getProcessId , processId ) . oneOpt ( ) . orElseThrow ( ( ) - > new BusinessException ( " Medical records not found ") ) ;
ProcessMedicalVertex processMedicalVertex = new ProcessMedicalVertex ( ) ;
processMedicalVertex . setNodeValue ( " 病历 (" + DateUtil . format ( processMedical . getCreateTime ( ) , "yyyy-MM-dd" ) + ")" ) ;
processMedicalVertex . setNodeValue ( " medical record (" + DateUtil . format ( processMedical . getCreateTime ( ) , "yyyy-MM-dd" ) + ")" ) ;
processMedicalDao . insert ( processMedicalVertex ) ;
medicalRecDao . insertEdge ( medicalRecVertex , new SinglePropertyEdge ( " 电子病历 ") , processMedicalVertex ) ;
medicalRecDao . insertEdge ( medicalRecVertex , new SinglePropertyEdge ( " Electronic Health Record ") , processMedicalVertex ) ;
// 创建主诉节点
if ( StrUtil . isNotBlank ( processMedical . getPatientSelfDesc ( ) ) ) {
SelfDescVertex selfDescVertex = new SelfDescVertex ( ) ;
selfDescVertex . setNodeValue ( processMedical . getPatientSelfDesc ( ) ) ;
selfDescDao . insert ( selfDescVertex ) ;
// 保存节点之间的关系
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " 主诉 ") , selfDescVertex ) ;
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " Chief Complaint ") , selfDescVertex ) ;
}
// 创建现病史节点
if ( StrUtil . isNotBlank ( processMedical . getIllnessHistory ( ) ) ) {
@ -111,7 +111,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
illnessHistoryVertex . setNodeValue ( processMedical . getIllnessHistory ( ) ) ;
illnessHistoryDao . insert ( illnessHistoryVertex ) ;
// 保存节点之间的关系
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " 现病史 ") , illnessHistoryVertex ) ;
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " Current Medical History ") , illnessHistoryVertex ) ;
}
// 创建个人史节点
if ( StrUtil . isNotBlank ( processMedical . getPersonalHistory ( ) ) ) {
@ -119,7 +119,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
personalHistoryVertex . setNodeValue ( processMedical . getPersonalHistory ( ) ) ;
personalHistoryDao . insert ( personalHistoryVertex ) ;
// 保存节点之间的关系
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " 个人史 ") , personalHistoryVertex ) ;
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " Past Medical History ") , personalHistoryVertex ) ;
}
// 创建过敏史节点
if ( ObjectUtil . isNotEmpty ( processMedical . getAllergyHistoryFlag ( ) ) & & 1 = = processMedical . getAllergyHistoryFlag ( ) & & StrUtil . isNotBlank ( processMedical . getAllergyHistory ( ) ) ) {
@ -127,7 +127,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
allergyHistoryVertex . setNodeValue ( processMedical . getAllergyHistory ( ) ) ;
allergyHistoryDao . insert ( allergyHistoryVertex ) ;
// 保存节点之间的关系
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " 过敏史 ") , allergyHistoryVertex ) ;
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " allergy history ") , allergyHistoryVertex ) ;
}
// 创建既往史节点
if ( ObjectUtil . isNotEmpty ( processMedical . getPreviousHistoryFlag ( ) ) & & 1 = = processMedical . getPreviousHistoryFlag ( ) & & StrUtil . isNotBlank ( processMedical . getPreviousHistory ( ) ) ) {
@ -135,7 +135,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
previousHistoryVertex . setNodeValue ( processMedical . getPreviousHistory ( ) ) ;
previousHistoryDao . insert ( previousHistoryVertex ) ;
// 保存节点之间的关系
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " 既往史 ") , previousHistoryVertex ) ;
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " Past Medical History ") , previousHistoryVertex ) ;
}
// 创建家族史节点
if ( ObjectUtil . isNotEmpty ( processMedical . getFamilyHistoryFlag ( ) ) & & 1 = = processMedical . getFamilyHistoryFlag ( ) & & StrUtil . isNotBlank ( processMedical . getFamilyHistory ( ) ) ) {
@ -143,7 +143,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
familyHistoryVertex . setNodeValue ( processMedical . getFamilyHistory ( ) ) ;
familyHistoryDao . insert ( familyHistoryVertex ) ;
// 保存节点之间的关系
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " 家族史 ") , familyHistoryVertex ) ;
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " Family history ") , familyHistoryVertex ) ;
}
// 创建手术史节点
if ( ObjectUtil . isNotEmpty ( processMedical . getOperationHistory ( ) ) & & 1 = = processMedical . getOperationHistoryFlag ( ) & & StrUtil . isNotBlank ( processMedical . getOperationHistory ( ) ) ) {
@ -151,7 +151,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
operationHistoryVertex . setNodeValue ( processMedical . getOperationHistory ( ) ) ;
operationHistoryDao . insert ( operationHistoryVertex ) ;
// 保存节点之间的关系
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " 手术史 ") , operationHistoryVertex ) ;
processMedicalDao . insertEdge ( processMedicalVertex , new SinglePropertyEdge ( " Surgical History ") , operationHistoryVertex ) ;
}
@ -169,12 +169,12 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
PhysicalVertex physicalVertex = new PhysicalVertex ( ) ;
physicalVertex . setNodeValue ( tool . getToolName ( ) + ( location ! = null ? ( "-" + location . getLocationName ( ) ) : "" ) ) ;
physicalDao . insert ( physicalVertex ) ;
processMedicalDao . insertEdge ( medicalRecVertex , new SinglePropertyEdge ( " 体格检查 ") , physicalVertex ) ;
processMedicalDao . insertEdge ( medicalRecVertex , new SinglePropertyEdge ( " physical examination ") , physicalVertex ) ;
// 获取查询结果,增加到结果节点中
PhysicalResultVertex physicalResultVertex = new PhysicalResultVertex ( ) ;
physicalResultVertex . setNodeValue ( StrUtil . blankToDefault ( physicalRecord . getResult ( ) , " 无相关资讯 ") ) ;
physicalResultVertex . setNodeValue ( StrUtil . blankToDefault ( physicalRecord . getResult ( ) , " No relevant information ") ) ;
physicalResultDao . insert ( physicalResultVertex ) ;
physicalResultDao . insertEdge ( physicalVertex , new SinglePropertyEdge ( " 结果 ") , physicalResultVertex ) ;
physicalResultDao . insertEdge ( physicalVertex , new SinglePropertyEdge ( " result ") , physicalResultVertex ) ;
// 如果是证实诊断依据,添加到证实诊断依据里面去
if ( NumberUtil . equals ( 1 , physicalRecord . getBasisConfirmFlag ( ) ) ) {
physicalConfirmMap . put ( physicalRecord . getId ( ) , physicalVertex ) ;
@ -192,13 +192,13 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
ancillaryVertex . setNodeValue ( configAncillaryItem . getItemName ( ) ) ;
ancillaryDao . insert ( ancillaryVertex ) ;
// 保存病历和辅助检查连线
medicalRecDao . insertEdge ( medicalRecVertex , new SinglePropertyEdge ( " 辅助检查 ") , ancillaryVertex ) ;
medicalRecDao . insertEdge ( medicalRecVertex , new SinglePropertyEdge ( " Auxiliary examination ") , ancillaryVertex ) ;
// 结果节点
AncillaryResultVertex ancillaryResultVertex = new AncillaryResultVertex ( ) ;
ancillaryResultVertex . setNodeValue ( StrUtil . blankToDefault ( diagnosisAncillaryRecord . getResult ( ) , " 无相关资讯 ") ) ;
ancillaryResultVertex . setNodeValue ( StrUtil . blankToDefault ( diagnosisAncillaryRecord . getResult ( ) , " No relevant information ") ) ;
ancillaryResultDao . insert ( ancillaryResultVertex ) ;
// 保存检查结果连线
ancillaryDao . insertEdge ( ancillaryVertex , new SinglePropertyEdge ( " 结果 ") , ancillaryResultVertex ) ;
ancillaryDao . insertEdge ( ancillaryVertex , new SinglePropertyEdge ( " Results ") , ancillaryResultVertex ) ;
// 如果是证实诊断依据,添加到证实诊断依据里面去
if ( NumberUtil . equals ( 1 , diagnosisAncillaryRecord . getBasisConfirmFlag ( ) ) ) {
ancillaryConfirmMap . put ( diagnosisAncillaryRecord . getId ( ) , ancillaryVertex ) ;
@ -215,7 +215,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
DiagnosisVertex diagnosisVertex = new DiagnosisVertex ( ) ;
diagnosisVertex . setNodeValue ( disease . getDiseaseNameAlias ( ) ) ;
diagnosisDao . insert ( diagnosisVertex ) ;
diagnosisDao . insertEdge ( medicalRecVertex , new SinglePropertyEdge ( " 诊断 ") , diagnosisVertex ) ;
diagnosisDao . insertEdge ( medicalRecVertex , new SinglePropertyEdge ( " Diagnosis ") , diagnosisVertex ) ;
diagnosisMap . put ( diagnosisPrimary . getId ( ) , diagnosisVertex ) ;
}
}
@ -228,12 +228,12 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
// 如果疾病诊断不为空,则根据relationId,查询对应的体格检查节点
PhysicalVertex physicalVertex = physicalConfirmMap . get ( relation . getRelationId ( ) ) ;
if ( ObjectUtil . isNotEmpty ( physicalVertex ) ) {
physicalDao . insertEdge ( diagnosisVertex , new SinglePropertyEdge ( " 依据 ") , physicalVertex ) ;
physicalDao . insertEdge ( diagnosisVertex , new SinglePropertyEdge ( " based on ") , physicalVertex ) ;
}
// 再尝试找辅助检查
AncillaryVertex ancillaryVertex = ancillaryConfirmMap . get ( relation . getRelationId ( ) ) ;
if ( ObjectUtil . isNotEmpty ( ancillaryVertex ) ) {
ancillaryDao . insertEdge ( diagnosisVertex , new SinglePropertyEdge ( " 依据 ") , ancillaryVertex ) ;
ancillaryDao . insertEdge ( diagnosisVertex , new SinglePropertyEdge ( " based on ") , ancillaryVertex ) ;
}
}
}
@ -245,7 +245,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
@Override
public GraphVO queryGraph ( String processId , Integer level ) {
Process process = Optional . ofNullable ( processService . getById ( processId ) ) . orElseThrow ( ( ) - > new BusinessException ( " 未找到对应的问诊流程 ") ) ;
Process process = Optional . ofNullable ( processService . getById ( processId ) ) . orElseThrow ( ( ) - > new BusinessException ( " Corresponding consultation process not found ") ) ;
// 如果图谱ID为空,则创建图谱
if ( StrUtil . isEmpty ( process . getGraphId ( ) ) ) {
String graphId = creatGraphByNebula ( processId ) ;