|
@@ -0,0 +1,349 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.diagbot.client.CdssCoreClient;
|
|
|
+import com.diagbot.dto.ConceptDetailDTO;
|
|
|
+import com.diagbot.dto.ConceptInfoDTO;
|
|
|
+import com.diagbot.dto.DictionaryInfoDTO;
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.dto.StaticKnowledgeIndexDTO;
|
|
|
+import com.diagbot.entity.ConceptDetail;
|
|
|
+import com.diagbot.entity.ConceptInfo;
|
|
|
+import com.diagbot.enums.ConceptTypeEnum;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.service.ConceptDetailService;
|
|
|
+import com.diagbot.service.impl.ConceptInfoServiceImpl;
|
|
|
+import com.diagbot.util.BeanUtil;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.RespDTOUtil;
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
+import com.diagbot.util.UserUtils;
|
|
|
+import com.diagbot.vo.ChangeStatusVO;
|
|
|
+import com.diagbot.vo.ConceptInfoPageVO;
|
|
|
+import com.diagbot.vo.ConceptInfoVO;
|
|
|
+import com.diagbot.vo.IdVO;
|
|
|
+import com.diagbot.vo.StaticKnowledgeIndexVO;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @Author:zhaops
|
|
|
+ * @time: 2020/8/19 14:17
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class ConceptInfoFacade extends ConceptInfoServiceImpl {
|
|
|
+ @Autowired
|
|
|
+ private CdssCoreClient cdssCoreClient;
|
|
|
+ @Autowired
|
|
|
+ private DictionaryFacade dictionaryFacade;
|
|
|
+ @Autowired
|
|
|
+ private ConceptDetailFacade conceptDetailFacade;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("conceptDetailServiceImpl")
|
|
|
+ private ConceptDetailService conceptDetailService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回不带静态知识的检索结果
|
|
|
+ *
|
|
|
+ * @param staticKnowledgeIndexVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<StaticKnowledgeIndexDTO> staticKnowledgeIndexWithoutInfo(StaticKnowledgeIndexVO staticKnowledgeIndexVO) {
|
|
|
+ List<StaticKnowledgeIndexDTO> staticKnowledgeIndexDTOList = staticKnowledgeIndex(staticKnowledgeIndexVO);
|
|
|
+ //过滤没有静态知识的检索结果
|
|
|
+ staticKnowledgeIndexDTOList = staticKnowledgeIndexDTOList
|
|
|
+ .stream()
|
|
|
+ .filter(i -> i.getHasInfomation().equals(0)
|
|
|
+ && i.getHasNotice().equals(0)
|
|
|
+ && i.getHasClinicalPathway().equals(0))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return staticKnowledgeIndexDTOList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 医学知识(静态信息)检索
|
|
|
+ *
|
|
|
+ * @param staticKnowledgeIndexVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<StaticKnowledgeIndexDTO> staticKnowledgeIndex(StaticKnowledgeIndexVO staticKnowledgeIndexVO) {
|
|
|
+ List<StaticKnowledgeIndexDTO> retList = Lists.newLinkedList();
|
|
|
+ //静态知识检索顺序
|
|
|
+ List<DictionaryInfoDTO> dicStaticIndexList = dictionaryFacade.getListByGroupType(7);
|
|
|
+ //页面术语类型和图谱映射
|
|
|
+ List<DictionaryInfoDTO> dicTypeMappingList = dictionaryFacade.getListByGroupType(8);
|
|
|
+
|
|
|
+ List<StaticKnowledgeIndexDTO> staticKnowledgeIndexDTOList = Lists.newLinkedList();
|
|
|
+ RespDTO<List<StaticKnowledgeIndexDTO>> respDTO = cdssCoreClient.staticKnowledgeIndex(staticKnowledgeIndexVO);
|
|
|
+ RespDTOUtil.respNGDealCover(respDTO, "检索失败");
|
|
|
+ staticKnowledgeIndexDTOList = respDTO.data;
|
|
|
+ if (ListUtil.isNotEmpty(staticKnowledgeIndexDTOList)) {
|
|
|
+ //typeName转换
|
|
|
+ staticKnowledgeIndexDTOList.forEach(item -> {
|
|
|
+ item.setTypeName(convertTypeName(item.getTypeName(), 2, dicTypeMappingList));
|
|
|
+ });
|
|
|
+ //是否有静态知识
|
|
|
+ List<String> conNameList = staticKnowledgeIndexDTOList
|
|
|
+ .stream()
|
|
|
+ .map(i -> i.getName())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ QueryWrapper<ConceptInfo> conceptInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ conceptInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("name", conNameList);
|
|
|
+ List<ConceptInfo> conceptInfoList = this.list(conceptInfoQueryWrapper);
|
|
|
+ if (ListUtil.isNotEmpty(conceptInfoList)) {
|
|
|
+ //typeName转换
|
|
|
+ conceptInfoList.forEach(item -> {
|
|
|
+ item.setType(convertTypeName(item.getType(), 2, dicTypeMappingList));
|
|
|
+ });
|
|
|
+ Map<String, ConceptInfo> infoMap
|
|
|
+ = EntityUtil.makeEntityMapByKeys(conceptInfoList, "_", "name", "type");
|
|
|
+ for (StaticKnowledgeIndexDTO item : staticKnowledgeIndexDTOList) {
|
|
|
+ if (infoMap.containsKey(item.getName() + "_" + item.getTypeName())) {
|
|
|
+ item.setId(infoMap.get(item.getName() + "_" + item.getTypeName()).getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Long> conceptIdList = conceptInfoList.stream()
|
|
|
+ .map(i -> i.getId())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (ListUtil.isNotEmpty(conceptIdList)) {
|
|
|
+ QueryWrapper<ConceptDetail> conceptDetailQueryWrapper = new QueryWrapper<>();
|
|
|
+ conceptDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("concept_id", conceptIdList);
|
|
|
+ List<ConceptDetail> conceptDetailList = conceptDetailFacade.list(conceptDetailQueryWrapper);
|
|
|
+ Map<Long, List<ConceptDetail>> detailMap
|
|
|
+ = EntityUtil.makeEntityListMap(conceptDetailList, "conceptId");
|
|
|
+ for (StaticKnowledgeIndexDTO item : staticKnowledgeIndexDTOList) {
|
|
|
+ if (item.getId() == null
|
|
|
+ || !detailMap.containsKey(item.getId())) {
|
|
|
+ item.setHasInfomation(0);
|
|
|
+ item.setHasClinicalPathway(0);
|
|
|
+ item.setHasNotice((0));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (ConceptDetail detail : detailMap.get(item.getId())) {
|
|
|
+ List<String> contentTypeList = Arrays.asList(detail.getContentType().split(","));
|
|
|
+ if (contentTypeList.contains("1")) {
|
|
|
+ item.setHasInfomation(1);
|
|
|
+ }
|
|
|
+ if (contentTypeList.contains("2")) {
|
|
|
+ item.setHasNotice(1);
|
|
|
+ }
|
|
|
+ if (contentTypeList.contains("3")) {
|
|
|
+ item.setHasClinicalPathway(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //排序
|
|
|
+ Map<String, List<StaticKnowledgeIndexDTO>> map
|
|
|
+ = EntityUtil.makeEntityListMap(staticKnowledgeIndexDTOList, "typeName");
|
|
|
+ for (DictionaryInfoDTO dic : dicStaticIndexList) {
|
|
|
+ if (dic.getName().equals("检验")) {
|
|
|
+ if (map.containsKey("检验套餐")) {
|
|
|
+ retList.addAll(map.get("检验套餐"));
|
|
|
+ }
|
|
|
+ if (map.containsKey("检验明细")) {
|
|
|
+ retList.addAll(map.get("检验明细"));
|
|
|
+ }
|
|
|
+ } else if (map.containsKey(dic.getName())) {
|
|
|
+ retList.addAll(map.get(dic.getName()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面术语类型和图谱标签名称相互转换
|
|
|
+ *
|
|
|
+ * @param typeName
|
|
|
+ * @param flag 1-页面术语类型转图谱标签名称,2- 图谱标签名称转页面术语类型
|
|
|
+ * @param dicList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String convertTypeName(String typeName, Integer flag, List<DictionaryInfoDTO> dicList) {
|
|
|
+ if (ListUtil.isNotEmpty(dicList)) {
|
|
|
+ Map<String, String> nameValMap = new HashMap<>();
|
|
|
+ if (flag.equals(1)) {
|
|
|
+ nameValMap = EntityUtil.makeMapWithKeyValue(dicList, "name", "val");
|
|
|
+ } else if (flag.equals(2)) {
|
|
|
+ nameValMap = EntityUtil.makeMapWithKeyValue(dicList, "val", "name");
|
|
|
+ }
|
|
|
+ if (nameValMap.containsKey(typeName)) {
|
|
|
+ return nameValMap.get(typeName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return typeName;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表
|
|
|
+ *
|
|
|
+ * @param conceptInfoPageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<ConceptInfoDTO> getPage(ConceptInfoPageVO conceptInfoPageVO) {
|
|
|
+ List<DictionaryInfoDTO> dicList = dictionaryFacade.getListByGroupType(8);
|
|
|
+ if (StringUtil.isNotBlank(conceptInfoPageVO.getType())) {
|
|
|
+ String typeName
|
|
|
+ = convertTypeName(ConceptTypeEnum.getName(Integer.valueOf(conceptInfoPageVO.getType())), 1, dicList);
|
|
|
+ conceptInfoPageVO.setTypeName(typeName);
|
|
|
+ }
|
|
|
+ IPage<ConceptInfoDTO> page = super.getPage(conceptInfoPageVO);
|
|
|
+ List<ConceptInfoDTO> records = page.getRecords();
|
|
|
+ if (ListUtil.isNotEmpty(records)) {
|
|
|
+ records.forEach(record -> {
|
|
|
+ record.setTypeName(convertTypeName(record.getTypeName(), 2, dicList));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ page.setRecords(records);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录(新增or修改)
|
|
|
+ *
|
|
|
+ * @param conceptInfoVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecord(ConceptInfoVO conceptInfoVO) {
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ List<DictionaryInfoDTO> dicList = dictionaryFacade.getListByGroupType(8);
|
|
|
+ //术语类型转换
|
|
|
+ String typeName = convertTypeName(ConceptTypeEnum.getName(Integer.valueOf(conceptInfoVO.getType())), 1, dicList);
|
|
|
+ conceptInfoVO.setTypeName(typeName);
|
|
|
+ if (conceptInfoVO.getId() == null) {
|
|
|
+ QueryWrapper<ConceptInfo> conceptInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ conceptInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("name", conceptInfoVO.getName())
|
|
|
+ .eq("type", typeName);
|
|
|
+ ConceptInfo conceptInfo = this.getOne(conceptInfoQueryWrapper, false);
|
|
|
+ //术语不存在,保存术语信息
|
|
|
+ if (conceptInfo == null) {
|
|
|
+ conceptInfo = new ConceptInfo();
|
|
|
+ BeanUtil.copyProperties(conceptInfoVO, conceptInfo);
|
|
|
+ conceptInfo.setType(typeName);
|
|
|
+ conceptInfo.setCreator(userId);
|
|
|
+ conceptInfo.setGmtCreate(now);
|
|
|
+ conceptInfo.setModifier(userId);
|
|
|
+ conceptInfo.setGmtModified(now);
|
|
|
+ this.save(conceptInfo);
|
|
|
+ }
|
|
|
+ conceptInfoVO.setId(conceptInfo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除已有静态信息
|
|
|
+ QueryWrapper<ConceptDetail> conceptDetailQueryWrapper = new QueryWrapper<>();
|
|
|
+ conceptDetailQueryWrapper.eq("concept_id", conceptInfoVO.getId());
|
|
|
+ conceptDetailFacade.remove(conceptDetailQueryWrapper);
|
|
|
+ //插入新的静态信息
|
|
|
+ List<ConceptDetail> conceptDetailList = Lists.newLinkedList();
|
|
|
+ if (ListUtil.isNotEmpty(conceptInfoVO.getDetails())) {
|
|
|
+ conceptInfoVO.getDetails().forEach(detail -> {
|
|
|
+ ConceptDetail conceptDetail = new ConceptDetail();
|
|
|
+ BeanUtil.copyProperties(detail, conceptDetail);
|
|
|
+ conceptDetail.setConceptId(conceptInfoVO.getId());
|
|
|
+ conceptDetail.setCreator(userId);
|
|
|
+ conceptDetail.setGmtCreate(now);
|
|
|
+ conceptDetail.setModifier(userId);
|
|
|
+ conceptDetail.setGmtModified(now);
|
|
|
+ conceptDetailList.add(conceptDetail);
|
|
|
+ });
|
|
|
+ conceptDetailService.saveBatch(conceptDetailList);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 启用禁用
|
|
|
+ *
|
|
|
+ * @param changeStatusVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean changeStatus(ChangeStatusVO changeStatusVO) {
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ UpdateWrapper<ConceptDetail> conceptDetailUpdateWrapper = new UpdateWrapper<>();
|
|
|
+ conceptDetailUpdateWrapper.eq("concept_id", changeStatusVO.getId())
|
|
|
+ .set("gmt_modified", now)
|
|
|
+ .set("modifier", userId)
|
|
|
+ .set("is_deleted", changeStatusVO.getIsDeleted());
|
|
|
+ conceptDetailService.update(conceptDetailUpdateWrapper);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否已存在
|
|
|
+ *
|
|
|
+ * @param conceptInfoVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean isExist(ConceptInfoVO conceptInfoVO) {
|
|
|
+ List<DictionaryInfoDTO> dicList = dictionaryFacade.getListByGroupType(8);
|
|
|
+ //术语类型转换
|
|
|
+ String typeName = convertTypeName(ConceptTypeEnum.getName(Integer.valueOf(conceptInfoVO.getType())), 1, dicList);
|
|
|
+ conceptInfoVO.setTypeName(typeName);
|
|
|
+ QueryWrapper<ConceptInfo> conceptInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ conceptInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("name", conceptInfoVO.getName())
|
|
|
+ .eq("type", typeName);
|
|
|
+ ConceptInfo conceptInfo = this.getOne(conceptInfoQueryWrapper, false);
|
|
|
+ if (conceptInfo == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ QueryWrapper<ConceptDetail> conceptDetailQueryWrapper = new QueryWrapper<>();
|
|
|
+ conceptDetailQueryWrapper.eq("concept_id", conceptInfo.getId());
|
|
|
+ List<ConceptDetail> conceptDetailList = conceptDetailService.list(conceptDetailQueryWrapper);
|
|
|
+ if (ListUtil.isEmpty(conceptDetailList)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据术语id获取静态信息
|
|
|
+ *
|
|
|
+ * @param idVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ConceptInfoDTO getRecordById(IdVO idVO) {
|
|
|
+ ConceptInfoDTO conceptInfoDTO = new ConceptInfoDTO();
|
|
|
+ ConceptInfo conceptInfo = this.getById(idVO.getId());
|
|
|
+ if (conceptInfo == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ BeanUtil.copyProperties(conceptInfo, conceptInfoDTO);
|
|
|
+ QueryWrapper<ConceptDetail> conceptDetailQueryWrapper = new QueryWrapper<>();
|
|
|
+ conceptDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("concept_id", idVO.getId())
|
|
|
+ .orderByAsc("order_no");
|
|
|
+ List<ConceptDetail> conceptDetailList = conceptDetailFacade.list(conceptDetailQueryWrapper);
|
|
|
+ if (ListUtil.isNotEmpty(conceptDetailList)) {
|
|
|
+ List<ConceptDetailDTO> details = BeanUtil.listCopyTo(conceptDetailList, ConceptDetailDTO.class);
|
|
|
+ conceptInfoDTO.setDetails(details);
|
|
|
+ //启用状态、修改人、修改时间为明细的内容
|
|
|
+ conceptInfoDTO.setModifier(conceptDetailList.get(0).getModifier());
|
|
|
+ conceptInfoDTO.setGmtModified(conceptDetailList.get(0).getGmtModified());
|
|
|
+ conceptInfoDTO.setIsDeleted(conceptDetailList.get(0).getIsDeleted());
|
|
|
+ }
|
|
|
+ return conceptInfoDTO;
|
|
|
+ }
|
|
|
+}
|