|
@@ -6,6 +6,9 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.diagbot.entity.node.LIS;
|
|
|
import org.diagbot.entity.node.Symptom;
|
|
|
import org.diagbot.mapper.KnowledgeMapper;
|
|
|
+import org.diagbot.pub.Label;
|
|
|
+import org.diagbot.pub.Type;
|
|
|
+import org.diagbot.pub.jdbc.MysqlJdbc;
|
|
|
import org.diagbot.service.KnowledgeService;
|
|
|
import org.diagbot.vo.*;
|
|
|
import org.diagbot.entity.node.Disease;
|
|
@@ -24,12 +27,16 @@ import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.Statement;
|
|
|
import java.text.NumberFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
@Service
|
|
|
-public class KnowledgeServiceImpl implements KnowledgeService {
|
|
|
+public class KnowledgeServiceImpl implements KnowledgeService {
|
|
|
Logger logger = LoggerFactory.getLogger(KnowledgeServiceImpl.class);
|
|
|
@Autowired
|
|
|
private SymptomRepository symptomRepository;
|
|
@@ -49,7 +56,14 @@ public class KnowledgeServiceImpl implements KnowledgeService {
|
|
|
private List<BaseNode> baseNodes;
|
|
|
|
|
|
private Pageable pageable;
|
|
|
-
|
|
|
+ private Connection conn = null;
|
|
|
+ private MysqlJdbc nlpJdbc = new MysqlJdbc("root", "lantone", "jdbc:mysql://192.168.2.236:3306/med?useSSL=false&useUnicode=true&characterEncoding=UTF-8");
|
|
|
+ public Connection getConn(){
|
|
|
+ if(conn == null){
|
|
|
+ conn = nlpJdbc.connect();
|
|
|
+ }
|
|
|
+ return conn;
|
|
|
+ }
|
|
|
/**
|
|
|
* 处理症状节点相关的申请
|
|
|
*/
|
|
@@ -378,7 +392,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
|
|
|
@Override
|
|
|
public Map<String, List<FeatureRate>> getLisPacs(SearchData searchData) {
|
|
|
String[] featureArray = StringUtils.split(searchData.getFeatureType(), ",");
|
|
|
- List<String> featureList = Arrays.asList(featureArray);
|
|
|
+ List<String> featureList = Arrays.asList(searchData.getFeatureTypes());
|
|
|
Map<String, List<FeatureRate>> lisPacsFeature = new HashMap<>();
|
|
|
String webDiag = searchData.getDiag();
|
|
|
List<String> webDiagList = null;
|
|
@@ -1398,6 +1412,361 @@ public class KnowledgeServiceImpl implements KnowledgeService {
|
|
|
return indicators1;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新图谱
|
|
|
+ * @param singleDisease
|
|
|
+ * @return
|
|
|
+ * 类型(1:症状,2:体征,3:化验,4:辅检,5:鉴别诊断,6:病史,7:诱因,8:病程,9:其他,91:确诊,92:拟诊,93:警惕)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public RespDTO updateNeoDisease(NeoParamVO singleDisease) {
|
|
|
+ RespDTO respDTO = new RespDTO();
|
|
|
+ respDTO.data=true;
|
|
|
+ respDTO.code="1";
|
|
|
+ Integer disId = singleDisease.getDisId();
|
|
|
+ String disName = this.getDisName(disId);
|
|
|
+ if(StringUtils.isNotEmpty(disName)){
|
|
|
+ diseaseRepository.mergeDis(disName,disId,0);
|
|
|
+ }else {
|
|
|
+ respDTO.code="0";
|
|
|
+ respDTO.msg="在数据库中没有找个这个疾病!!!";
|
|
|
+ }
|
|
|
+ //获取每个诊断依据的全部数据
|
|
|
+ List<Map<String, String>> allData = this.getAllData(disId);
|
|
|
+ //获取拟诊,确诊,警惕组合
|
|
|
+ Map<String, List<String>> allNiQueZhenCollection = this.getAllNiQueZhenCollection(disId);
|
|
|
+ this.saveNiQue2Neo(allData,allNiQueZhenCollection,disName,disId);
|
|
|
+ this.saveData2Neo4j(allData,disId,disName);
|
|
|
+
|
|
|
+ System.out.println();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return respDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 把一个完整的诊断依据封装到list中,list中存的是map,一行一个map
|
|
|
+ * @param disId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Map<String,String>> getAllData(Integer disId){
|
|
|
+ List<Map<String,String>> contentList = new ArrayList<>();
|
|
|
+ conn = this.getConn();
|
|
|
+ Statement st = null;
|
|
|
+ ResultSet rs = null;
|
|
|
+ try {
|
|
|
+ String type, code ,standard,relation,result,formula,name;
|
|
|
+ String sql = "SELECT diagnose_id,dis_name,`type`,`code`,standard,relation,result,formula FROM `kl_diagnose_detail` where diagnose_id = "+disId+"";
|
|
|
+ st = conn.createStatement();
|
|
|
+ rs = st.executeQuery(sql);
|
|
|
+ while (rs.next()){
|
|
|
+ Map<String,String> content = new HashMap<>();
|
|
|
+ type = rs.getString(3);
|
|
|
+ code = rs.getString("code");
|
|
|
+ standard = rs.getString("standard");
|
|
|
+ relation = rs.getString("relation");
|
|
|
+ result = rs.getString("result");
|
|
|
+ formula = rs.getString("formula");
|
|
|
+ name = Type.getName(Integer.parseInt(type));
|
|
|
+ content.put("type",type);
|
|
|
+ content.put("typeName",name);
|
|
|
+ content.put("code",code);
|
|
|
+ content.put("standard",standard);
|
|
|
+ content.put("relation",relation);
|
|
|
+ content.put("result",result);
|
|
|
+ content.put("formula",formula);
|
|
|
+ contentList.add(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ rs.close();
|
|
|
+ st.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return contentList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取一个诊断依据的确诊,拟诊,警惕集合
|
|
|
+ * @param disId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String,List<String>> getAllNiQueZhenCollection(Integer disId) {
|
|
|
+ Map<String,List<String>> queNiMap = new HashMap<>();
|
|
|
+ conn = this.getConn();
|
|
|
+ Statement st = null;
|
|
|
+ ResultSet rs = null;
|
|
|
+ List<String> queList = new ArrayList<>();
|
|
|
+ List<String> niList = new ArrayList<>();
|
|
|
+ List<String> highList = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ String type, formula, label,name;
|
|
|
+ String sql = "SELECT type,formula FROM `kl_diagnose_detail` where diagnose_id = "+disId+" and type in (91,92,93)";
|
|
|
+ st = conn.createStatement();
|
|
|
+ rs = st.executeQuery(sql);
|
|
|
+ while (rs.next()) {
|
|
|
+ type = rs.getString(1);
|
|
|
+ formula = rs.getString(2);
|
|
|
+ name = Type.getName(Integer.parseInt(type));
|
|
|
+ if("拟诊".equals(name)){
|
|
|
+ niList.add(formula);
|
|
|
+ }else if("确诊".equals(name)){
|
|
|
+ queList.add(formula);
|
|
|
+ }else if("警惕".equals(name)){
|
|
|
+ highList.add(formula);
|
|
|
+ }
|
|
|
+ if(queList != null){
|
|
|
+ for (String que:queList) {
|
|
|
+ if(que.contains("拟诊")){
|
|
|
+ for (String ni:niList
|
|
|
+ ) {
|
|
|
+ String newNi = que.replaceAll("拟诊", ni);
|
|
|
+ queList.add(newNi);
|
|
|
+ }
|
|
|
+ queList.remove(que);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ queNiMap.put("拟诊",niList);
|
|
|
+ queNiMap.put("确诊",queList);
|
|
|
+ queNiMap.put("警惕",highList);
|
|
|
+
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ rs.close();
|
|
|
+ st.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return queNiMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取疾病名
|
|
|
+ * @param disId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getDisName(Integer disId){
|
|
|
+ Statement st = null;
|
|
|
+ ResultSet rs = null;
|
|
|
+ conn = this.getConn();
|
|
|
+ String name="";
|
|
|
+ try {
|
|
|
+ String sql = "SELECT dis_name FROM `kl_diagnose_detail` where diagnose_id = "+disId+"";
|
|
|
+ st = conn.createStatement();
|
|
|
+ rs = st.executeQuery(sql);
|
|
|
+ while (rs.next()) {
|
|
|
+ name = rs.getString(1);
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ rs.close();
|
|
|
+ st.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 把确诊,拟诊,警惕存入图谱
|
|
|
+ */
|
|
|
+ public void saveNiQue2Neo(List<Map<String, String>> allData,Map<String, List<String>> allNiQueZhenCollection,String disName,Integer disId){
|
|
|
+ List<String> stringList =null;
|
|
|
+ String[] types = {"确诊","拟诊","警惕"};
|
|
|
+ Integer path = 1;
|
|
|
+ String[] nisplits;
|
|
|
+ for (String type:types) {
|
|
|
+ if("确诊".equals(type)){
|
|
|
+ stringList = allNiQueZhenCollection.get(type);
|
|
|
+ if(stringList != null){
|
|
|
+ for(int i =0;i<stringList.size();i++){
|
|
|
+ nisplits = stringList.get(i).split("\\+");
|
|
|
+ path = nisplits.length;
|
|
|
+ diseaseRepository.mergeCondition(disName+"-"+type+"组块"+(i+1),path);
|
|
|
+ diseaseRepository.mergeQueNiHigh(disName+"-"+type+"组块"+(i+1),disId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if("拟诊".equals(type)){
|
|
|
+ stringList = allNiQueZhenCollection.get(type);
|
|
|
+ if(stringList != null){
|
|
|
+ for(int i =0;i<stringList.size();i++){
|
|
|
+ nisplits = stringList.get(i).split("\\+");
|
|
|
+ path = nisplits.length;
|
|
|
+ diseaseRepository.mergeCondition(disName+"-"+type+"组块"+(i+1),path);
|
|
|
+ diseaseRepository.mergeNiHigh(disName+"-"+type+"组块"+(i+1),disId);
|
|
|
+ this.splitConditionContent(nisplits,disName,disName+"-"+type+"组块"+(i+1),allData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if("警惕".equals(type)){
|
|
|
+ stringList = allNiQueZhenCollection.get(type);
|
|
|
+ if(stringList != null){
|
|
|
+ for(int i =0;i<stringList.size();i++){
|
|
|
+ nisplits = stringList.get(i).split("\\+");
|
|
|
+ path = nisplits.length;
|
|
|
+ diseaseRepository.mergeCondition(disName+"-"+type+"组块"+(i+1),path);
|
|
|
+ diseaseRepository.mergeHigh(disName+"-"+type+"组块"+(i+1),disId);
|
|
|
+ this.splitConditionContent(nisplits,disName,disName+"-"+type+"组块"+(i+1),allData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理任几
|
|
|
+ * @param nisplits
|
|
|
+ * @param disName
|
|
|
+ * @param startNode
|
|
|
+ * @param allData
|
|
|
+ */
|
|
|
+ public void splitConditionContent(String[] nisplits,String disName,String startNode,List<Map<String, String>> allData){
|
|
|
+ Integer path = 1;
|
|
|
+ String rel = "";
|
|
|
+ for (String ni:nisplits) {
|
|
|
+ if(ni.contains("/")){
|
|
|
+ if(ni.contains("任一")){
|
|
|
+ path = 1;
|
|
|
+ rel = "任一";
|
|
|
+ }else if(ni.contains("任二")){
|
|
|
+ path = 2;
|
|
|
+ rel = "任二";
|
|
|
+ }else if(ni.contains("任三")){
|
|
|
+ path = 3;
|
|
|
+ rel = "任三";
|
|
|
+ }else if(ni.contains("任四")){
|
|
|
+ path = 4;
|
|
|
+ rel = "任四";
|
|
|
+ }else if(ni.contains("任五")){
|
|
|
+ path = 5;
|
|
|
+ rel = "任五";
|
|
|
+ }else {
|
|
|
+ path = 1;
|
|
|
+ rel = "任一";
|
|
|
+ }
|
|
|
+ diseaseRepository.mergeRenCondition(disName+ni,path,rel);
|
|
|
+ diseaseRepository.mergeRenCondition(disName+ni,startNode);
|
|
|
+ //获取这个任几集合的数字集合
|
|
|
+ List<String> numList = this.getNumList(ni);
|
|
|
+ if(numList != null && numList.size()>0){
|
|
|
+ for (String num:numList
|
|
|
+ ) {
|
|
|
+ this.processDetailNum(disName,num,disName+ni,allData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ this.processDetailNum(disName,ni,disName+ni,allData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取任几集合的code列表
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> getNumList(String renCondition){
|
|
|
+ List<String> numList = new ArrayList<>();
|
|
|
+ String[] numSplits = renCondition.split("/");
|
|
|
+ if(numSplits.length>0){
|
|
|
+ for (int i=0;i<numSplits.length;i++){
|
|
|
+ if(i == 0){
|
|
|
+ numList.add(numSplits[i].replaceAll("\\(",""));
|
|
|
+ }else if(i == numSplits.length-1){
|
|
|
+ String numSplit = numSplits[i];
|
|
|
+ int i1 = numSplit.indexOf(")");
|
|
|
+ System.out.println(numSplit+"\t"+i1);
|
|
|
+ numList.add(numSplits[i].substring(0,numSplits[i].indexOf(")")));
|
|
|
+ }else {
|
|
|
+ numList.add(numSplits[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return numList;
|
|
|
+ }
|
|
|
+ public void processDetailNum(String disName,String num,String renCondition,List<Map<String, String>> allData){
|
|
|
+ String[] types = {"化验","辅检","排除条件"};
|
|
|
+ for (Map<String, String> row:allData) {
|
|
|
+ String code = row.get("code");//编码
|
|
|
+ String type = row.get("type");//类型
|
|
|
+ String typeName = row.get("typeName");//类型对应的中文名
|
|
|
+ String relation = row.get("relation");//关联词
|
|
|
+ String result = row.get("result");//结果
|
|
|
+ if(num.equals(code)){
|
|
|
+ if(Arrays.asList(types).indexOf(typeName) <0){
|
|
|
+ diseaseRepository.mergeNUMCondition(disName+code);
|
|
|
+ diseaseRepository.mergeNUMCondition(disName+code,renCondition);
|
|
|
+ }else if("化验".equals(typeName) && !"".equals(result)){
|
|
|
+ diseaseRepository.mergeNUMCondition(disName+code);
|
|
|
+ diseaseRepository.mergeNUMCondition(disName+code,renCondition);
|
|
|
+ }else if("辅检".equals(typeName) && !"".equals(relation)){
|
|
|
+ diseaseRepository.mergeNUMCondition(disName+code);
|
|
|
+ diseaseRepository.mergeNUMCondition(disName+code,renCondition);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存完整的诊断依据入知识图谱
|
|
|
+ * @param allData
|
|
|
+ * @param disId
|
|
|
+ * @param disName
|
|
|
+ */
|
|
|
+ public void saveData2Neo4j(List<Map<String, String>> allData,Integer disId,String disName){
|
|
|
+// Map<String, Map<String, String>> standard_info_synonym_map = NlpCache.standard_info_synonym_map;
|
|
|
+ for (Map<String,String> row:allData) {
|
|
|
+ String code = row.get("code");//编码
|
|
|
+ String type = row.get("type");//类型
|
|
|
+ String typeName = row.get("typeName");//类型对应的中文名
|
|
|
+ String standard = row.get("standard");//标准词
|
|
|
+ String relation = row.get("relation");//关联词
|
|
|
+ String result = row.get("result");//结果
|
|
|
+ if(StringUtils.isNotEmpty(type)){
|
|
|
+ if(!"3".equals(type) && !"4".equals(type) && !"5".equals(type)){
|
|
|
+ //添加词语之前,要找标准词
|
|
|
+ //添加standard
|
|
|
+ diseaseRepository.mergeStandard(Label.getLabel(type),standard);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 在图谱中删除诊断依据
|
|
|
+ * @param singleDisease
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Integer deleteNeoDisease(NeoParamVO singleDisease) {
|
|
|
+ Integer disId = singleDisease.getDisId();
|
|
|
+ if(disId != null){
|
|
|
+ diseaseRepository.deleteRelation1(disId);
|
|
|
+ diseaseRepository.deleteRelation2(disId);
|
|
|
+ diseaseRepository.deleteRelation3(disId);
|
|
|
+ diseaseRepository.deleteRelation4(disId);
|
|
|
+ diseaseRepository.deleteRelation5(disId);
|
|
|
+ diseaseRepository.deleteRelation6(disId);
|
|
|
+ diseaseRepository.deleteRelation7(disId);
|
|
|
+ diseaseRepository.deleteRelation8(disId);
|
|
|
+ diseaseRepository.deleteRelation9(disId);
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<Map<String, Object>> getRecommendItem(QueryVo queryVo) {
|
|
|
List<Map<String, Object>> list = relationRepository.getRecommendItem(queryVo.getDiseaselist());
|