|
@@ -1,15 +1,33 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
import com.diagbot.dto.ConceptDTO;
|
|
|
+import com.diagbot.entity.Concept;
|
|
|
import com.diagbot.entity.LibraryInfo;
|
|
|
+import com.diagbot.entity.Medical;
|
|
|
+import com.diagbot.dto.RelationDTO;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.service.impl.ConceptServiceImpl;
|
|
|
+import com.diagbot.vo.AmendTermVo;
|
|
|
+import com.diagbot.vo.MedicalVo;
|
|
|
import com.diagbot.vo.TermVo;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 术语查询业务层
|
|
|
* @author: Weixuan Huang
|
|
@@ -38,24 +56,297 @@ public class ConceptFacade extends ConceptServiceImpl {
|
|
|
|
|
|
ConceptDTO conceptDTO = getConcept(termvo);
|
|
|
// 获取与医学术语的基本信息
|
|
|
- termvo.setId(conceptDTO.getLibId());
|
|
|
- termvo.setConcept_id(conceptDTO.getId());
|
|
|
- List<LibraryInfo> libraryInfo = libraryinfoFacade.getLibraryInfor(termvo);
|
|
|
- for (LibraryInfo libinfo : libraryInfo) {
|
|
|
- if (libinfo.getIsConcept() != null && libinfo.getIsConcept() == 1) {
|
|
|
- conceptDTO.setName(libinfo.getName());
|
|
|
+ if (conceptDTO != null) {
|
|
|
+ termvo.setId(conceptDTO.getLibId());
|
|
|
+ termvo.setConcept_id(conceptDTO.getId());
|
|
|
+ LibraryInfo libraryInfo = libraryinfoFacade.getLibraryInfor(termvo);
|
|
|
+
|
|
|
+ if (libraryInfo.getIsConcept() != null && libraryInfo.getIsConcept() == 1) {
|
|
|
+ conceptDTO.setName(libraryInfo.getName());
|
|
|
}
|
|
|
+ conceptDTO.setLibraryInfo(libraryInfo);
|
|
|
+
|
|
|
+ // 获取与术语相关的医学知识
|
|
|
+ conceptDTO.setInformation(libraryDetailFacade.getLibraryDetails(termvo));
|
|
|
+ // 获取与术语相关的临床医学信息
|
|
|
+ MedicalVo medicalVo = new MedicalVo();
|
|
|
+ medicalVo.setName(termvo.getTerm());
|
|
|
+ conceptDTO.setMedicalInfo(medicalFacade.getMedicalInfo(medicalVo));
|
|
|
+ // 获取术语的所有上级信息
|
|
|
+ conceptDTO.setRelations(relationFacade.getAllRelation(termvo));
|
|
|
+ }
|
|
|
+
|
|
|
+ return conceptDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新医学术语信息
|
|
|
+ *
|
|
|
+ * @param amendTermVo
|
|
|
+ * @return ConceptDTO
|
|
|
+ */
|
|
|
+ public ConceptDTO upsertConceptInfo(@RequestBody AmendTermVo amendTermVo) {
|
|
|
+ ConceptDTO conceptDTO = new ConceptDTO();
|
|
|
+
|
|
|
+ TermVo termVo = new TermVo();
|
|
|
+ termVo.setTerm(amendTermVo.getConcept());
|
|
|
+
|
|
|
+ // 如果概念术语不存在,添加新术语,然后添加新的概念
|
|
|
+ conceptDTO = getConcept(termVo);
|
|
|
+ if (conceptDTO == null) {
|
|
|
+ AmendTermVo amendconcept = new AmendTermVo();
|
|
|
+ amendconcept.setOldterm(amendTermVo.getOldterm());
|
|
|
+ amendconcept.setNewterm(amendTermVo.getConcept());
|
|
|
+ amendconcept.setConcept("");
|
|
|
+ libraryinfoFacade.upsertLibraryInfo(amendconcept);
|
|
|
+
|
|
|
+ Concept concept = new Concept();
|
|
|
+ int libid = libraryinfoFacade.getLibraryInfor(termVo).getId().intValue();
|
|
|
+ concept.setLibId(libid);
|
|
|
+ this.saveOrUpdate(concept);
|
|
|
+
|
|
|
+ conceptDTO = getConcept(termVo);
|
|
|
}
|
|
|
+
|
|
|
+ amendTermVo.setConcept_id(conceptDTO.getId());
|
|
|
+ LibraryInfo libraryInfo = libraryinfoFacade.upsertLibraryInfo(amendTermVo);
|
|
|
conceptDTO.setLibraryInfo(libraryInfo);
|
|
|
|
|
|
- // 获取与术语相关的医学知识
|
|
|
- conceptDTO.setInformation(libraryDetailFacade.getLibraryDetails(termvo));
|
|
|
- // 获取与术语相关的临床医学信息
|
|
|
- conceptDTO.setMedicalInfo(medicalFacade.getMedicalInfo(termvo));
|
|
|
- // 获取术语的所有上级信息
|
|
|
- conceptDTO.setRelations(relationFacade.getRelation(termvo));
|
|
|
+ conceptDTO = updateConceptInfo(amendTermVo, conceptDTO);
|
|
|
+
|
|
|
+ return conceptDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新或添加医学术语信息
|
|
|
+ *
|
|
|
+ * @param amendTermVo
|
|
|
+ * @param conceptDTO
|
|
|
+ * @return ConceptDTO
|
|
|
+ */
|
|
|
+ public ConceptDTO updateConceptInfo(AmendTermVo amendTermVo, ConceptDTO conceptDTO) {
|
|
|
+
|
|
|
+ libraryDetailFacade.upsertLibraryInfo(amendTermVo);
|
|
|
+ conceptDTO.setInformation(amendTermVo.getInformation());
|
|
|
+
|
|
|
+ medicalFacade.upsertMedicalInfo(amendTermVo);
|
|
|
+ conceptDTO.setMedicalInfo(amendTermVo.getMedicalInfo());
|
|
|
+
|
|
|
+ relationFacade.upsertRelationInfo(amendTermVo);
|
|
|
+ conceptDTO.setRelations(amendTermVo.getRelations());
|
|
|
+
|
|
|
+ return conceptDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从文件批量导入术语信息
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @return ConceptDTO
|
|
|
+ */
|
|
|
+ public ConceptDTO importBatch(MultipartFile file) {
|
|
|
+ ConceptDTO conceptDTO = new ConceptDTO();
|
|
|
+ List<String> messages = new ArrayList<>();
|
|
|
+
|
|
|
+ InputStream inputStream = null;
|
|
|
+ Workbook wb = null;
|
|
|
+
|
|
|
+ AmendTermVo amendTermVo;
|
|
|
+ Medical medical;
|
|
|
+ List<Medical> medlist;
|
|
|
+ RelationDTO relationDTO;
|
|
|
+ List<RelationDTO> rellist;
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (!file.isEmpty()) {
|
|
|
+ inputStream = file.getInputStream();
|
|
|
+
|
|
|
+ if (inputStream.available() > 1024000) {
|
|
|
+ messages.add("术语文件最大支持1MB!");
|
|
|
+ } else {
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ if (fileName.lastIndexOf(".") != -1) {
|
|
|
+ String type = fileName.substring(fileName.lastIndexOf("."));
|
|
|
+ if (type.equals(".xls")) {
|
|
|
+ wb = new HSSFWorkbook(inputStream);
|
|
|
+ } else if (type.equals(".xlsx")) {
|
|
|
+ wb = new XSSFWorkbook(inputStream);
|
|
|
+ }
|
|
|
+ if (wb != null) {
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ int count = 0;
|
|
|
+ String group, category, std_name, name, code, prop;
|
|
|
+ String grp_type = "";
|
|
|
+ String cate_type = "";
|
|
|
+ String std_type = "";
|
|
|
+ for (Row row : sheet) {
|
|
|
+ count++;
|
|
|
+
|
|
|
+ if (row != null) {
|
|
|
+ if (count == 1) {
|
|
|
+ grp_type = row.getCell(0).toString();
|
|
|
+ if (medicalFacade.getTypeInfo(grp_type) == null) {
|
|
|
+ System.out.println("术语类型-'" + grp_type + "'不存在!");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ cate_type = row.getCell(1).toString();
|
|
|
+ if (medicalFacade.getTypeInfo(cate_type) == null) {
|
|
|
+ System.out.println("术语类型-'" + cate_type + "'不存在!");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ std_type = row.getCell(2).toString().replace("标准名称", "");
|
|
|
+ if (medicalFacade.getTypeInfo(std_type) == null) {
|
|
|
+ System.out.println("术语类型-'" + std_type + "'不存在!");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (count > 1) {
|
|
|
+
|
|
|
+ group = (row.getCell(0) == null) ? "" : row.getCell(0).toString();
|
|
|
+ category = (row.getCell(1) == null) ? "" : row.getCell(1).toString();
|
|
|
+ std_name = (row.getCell(2) == null) ? "" : row.getCell(2).toString();
|
|
|
+ name = (row.getCell(3) == null) ? "" : row.getCell(3).toString();
|
|
|
+ code = category + "\"-\"" + std_name;
|
|
|
+ prop = (row.getCell(5) == null) ? "" : row.getCell(5).toString();
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println(group + "\t" + category + "\t" + std_name + "\t" +
|
|
|
+ name + "\t" + code + "\t" + prop);
|
|
|
+
|
|
|
+ // 设置实体
|
|
|
+ amendTermVo = new AmendTermVo();
|
|
|
+ amendTermVo.setConcept(std_name);
|
|
|
+ amendTermVo.setNewterm(name);
|
|
|
+ amendTermVo.setOldterm("");
|
|
|
+
|
|
|
+ medical = new Medical();
|
|
|
+ medical.setName(name);
|
|
|
+ medical.setType(std_type);
|
|
|
+ medical.setStdName(std_name);
|
|
|
+ medical.setCateName(category);
|
|
|
+ medical.setCode(code);
|
|
|
+ medical.setNote(prop);
|
|
|
+ medlist = new ArrayList<>();
|
|
|
+ medlist.add(medical);
|
|
|
+ amendTermVo.setMedicalInfo(medlist);
|
|
|
+
|
|
|
+ this.upsertConceptInfo(amendTermVo);
|
|
|
+ System.out.println(name + ":\t 已入库.");
|
|
|
+
|
|
|
+
|
|
|
+ if (category.length() > 0) {
|
|
|
+ // 设置套餐
|
|
|
+ amendTermVo = new AmendTermVo();
|
|
|
+ amendTermVo.setConcept(category);
|
|
|
+ amendTermVo.setNewterm(category);
|
|
|
+ amendTermVo.setOldterm("");
|
|
|
+
|
|
|
+ medical = new Medical();
|
|
|
+ medical.setName(category);
|
|
|
+ medical.setType(cate_type);
|
|
|
+ medical.setStdName(category);
|
|
|
+ medical.setCateName(group);
|
|
|
+ medical.setCode("");
|
|
|
+ medical.setNote("");
|
|
|
+ medlist = new ArrayList<>();
|
|
|
+ medlist.add(medical);
|
|
|
+ amendTermVo.setMedicalInfo(medlist);
|
|
|
+
|
|
|
+ relationDTO = new RelationDTO();
|
|
|
+ relationDTO.setStartId(getConceptId(std_name));
|
|
|
+ relationDTO.setStartName(std_name);
|
|
|
+ relationDTO.setRelationId(1);
|
|
|
+ relationDTO.setEndId(getConceptId(category));
|
|
|
+ relationDTO.setEndName(category);
|
|
|
+ rellist = new ArrayList<>();
|
|
|
+ rellist.add(relationDTO);
|
|
|
+ amendTermVo.setRelations(rellist);
|
|
|
+
|
|
|
+ this.upsertConceptInfo(amendTermVo);
|
|
|
+
|
|
|
+ System.out.println(category + ":\t 已入库.");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (group.length() > 0) {
|
|
|
+ // 设置大类
|
|
|
+ amendTermVo = new AmendTermVo();
|
|
|
+ amendTermVo.setConcept(group);
|
|
|
+ amendTermVo.setNewterm(group);
|
|
|
+ amendTermVo.setOldterm("");
|
|
|
+
|
|
|
+ medical = new Medical();
|
|
|
+ medical.setName(group);
|
|
|
+ medical.setType(grp_type);
|
|
|
+ medical.setStdName(group);
|
|
|
+ medical.setCateName("");
|
|
|
+ medical.setCode("");
|
|
|
+ medical.setNote("");
|
|
|
+ medlist = new ArrayList<>();
|
|
|
+ medlist.add(medical);
|
|
|
+ amendTermVo.setMedicalInfo(medlist);
|
|
|
+
|
|
|
+ this.upsertConceptInfo(amendTermVo);
|
|
|
+ System.out.println(group + ":\t 已入库.");
|
|
|
+ }
|
|
|
+ // if (count >= 1)
|
|
|
+ // break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println(count + " 条记录添加入库.");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ messages.add("非excel文件无法解析!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ messages.add("未知文件无法解析!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ messages.add("无文件上传!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (IOException ioe) {
|
|
|
+ ioe.printStackTrace();
|
|
|
+ }
|
|
|
+ catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ try {
|
|
|
+
|
|
|
+ if (inputStream != null) {
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
+ if (wb != null) {
|
|
|
+ wb.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return conceptDTO;
|
|
|
}
|
|
|
|
|
|
+ public int getConceptId(String term) {
|
|
|
+ int id = 0;
|
|
|
+ TermVo termVo = new TermVo();
|
|
|
+
|
|
|
+ try {
|
|
|
+ termVo.setTerm(term);
|
|
|
+ ConceptDTO conceptDTO = getConcept(termVo);
|
|
|
+ if (conceptDTO != null) {
|
|
|
+ id = conceptDTO.getId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ return id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|