|
@@ -0,0 +1,377 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.diagbot.client.CdssCoreClient;
|
|
|
+import com.diagbot.dto.ExportCommonStaticTestDTO;
|
|
|
+import com.diagbot.dto.ExportCommonTestDTO;
|
|
|
+import com.diagbot.dto.ExportLisStaticTestDTO;
|
|
|
+import com.diagbot.dto.ExportLisTestDTO;
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.entity.ConceptInfo;
|
|
|
+import com.diagbot.entity.DiseaseConfig;
|
|
|
+import com.diagbot.entity.DrugConfig;
|
|
|
+import com.diagbot.entity.LisConfig;
|
|
|
+import com.diagbot.entity.OperationConfig;
|
|
|
+import com.diagbot.entity.PacsConfig;
|
|
|
+import com.diagbot.entity.ResultStaticInfo;
|
|
|
+import com.diagbot.entity.ResultStaticKnowledge;
|
|
|
+import com.diagbot.entity.TransfusionConfig;
|
|
|
+import com.diagbot.entity.node.LisName;
|
|
|
+import com.diagbot.entity.relationship.LisNameLisSet;
|
|
|
+import com.diagbot.enums.ConceptTypeEnum;
|
|
|
+import com.diagbot.enums.GraphLabelEnum;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.repository.LisNameRepository;
|
|
|
+import com.diagbot.service.ResultStaticInfoService;
|
|
|
+import com.diagbot.service.ResultStaticKnowledgeService;
|
|
|
+import com.diagbot.service.impl.ResultStaticKnowledgeServiceImpl;
|
|
|
+import com.diagbot.util.BeanUtil;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.ExcelUtils;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.RespDTOUtil;
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
+import com.diagbot.vo.ConceptVO;
|
|
|
+import com.diagbot.vo.ResultStaticPageVO;
|
|
|
+import com.diagbot.vo.StaticKnowledgeTestVO;
|
|
|
+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 org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @Author:zhaops
|
|
|
+ * @time: 2021/1/21 15:20
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class ResultStaticKnowledgeFacade extends ResultStaticKnowledgeServiceImpl {
|
|
|
+ @Autowired
|
|
|
+ private CdssCoreClient cdssCoreClient;
|
|
|
+ @Autowired
|
|
|
+ private ConceptInfoFacade conceptInfoFacade;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LisConfigFacade lisConfigFacade;
|
|
|
+ @Autowired
|
|
|
+ private PacsConfigFacade pacsConfigFacade;
|
|
|
+ @Autowired
|
|
|
+ private DrugConfigFacade drugConfigFacade;
|
|
|
+ @Autowired
|
|
|
+ private DiseaseConfigFacade diseaseConfigFacade;
|
|
|
+ @Autowired
|
|
|
+ private OperationConfigFacade operationConfigFacade;
|
|
|
+ @Autowired
|
|
|
+ private TransfusionConfigFacade transfusionConfigFacade;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LisNameRepository lisNameRepository;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("resultStaticKnowledgeServiceImpl")
|
|
|
+ private ResultStaticKnowledgeService resultStaticKnowledgeService;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("resultStaticInfoServiceImpl")
|
|
|
+ private ResultStaticInfoService resultStaticInfoService;
|
|
|
+
|
|
|
+
|
|
|
+ public Boolean allTest(StaticKnowledgeTestVO testVO) {
|
|
|
+ Long hospitalId = testVO.getHospitalId();
|
|
|
+ List<LisConfig> lisConfigList = lisConfigFacade.getListByHospitalId(hospitalId);
|
|
|
+ List<PacsConfig> pacsConfigList = pacsConfigFacade.getListByHospitalId(hospitalId);
|
|
|
+ List<DrugConfig> drugConfigList = drugConfigFacade.getListByHospitalId(hospitalId);
|
|
|
+ List<DiseaseConfig> diseaseConfigList = diseaseConfigFacade.getListByHospitalId(hospitalId);
|
|
|
+ List<OperationConfig> operationConfigList = operationConfigFacade.getListByHospitalId(hospitalId);
|
|
|
+ List<TransfusionConfig> transfusionConfigList = transfusionConfigFacade.getListByHospitalId(hospitalId);
|
|
|
+ Map<String, Map<String, Map<String, List<Long>>>> lisConfigMap = lisConfigFacade.getUniqueConfigMap(hospitalId, null, null);
|
|
|
+ Map<String, Map<String, List<Long>>> pacsConfigMap = pacsConfigFacade.getUniqueConfigMap(hospitalId, null, null);
|
|
|
+ Map<String, Map<String, Map<String, List<Long>>>> drugConfigMap = drugConfigFacade.getUniqueConfigMap(hospitalId, null, null);
|
|
|
+ Map<String, Map<String, List<Long>>> diseaseConfigMap = diseaseConfigFacade.getUniqueConfigMap(hospitalId, null, null);
|
|
|
+ Map<String, Map<String, List<Long>>> operationConfigMap = operationConfigFacade.getUniqueConfigMap(hospitalId, null, null);
|
|
|
+ Map<String, Map<String, List<Long>>> transfusionConfigMap = transfusionConfigFacade.getUniqueConfigMap(hospitalId, null, null);
|
|
|
+
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 化验静态知识测试
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @param testVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean lisTest(MultipartFile file, StaticKnowledgeTestVO testVO) {
|
|
|
+ List<ResultStaticKnowledge> saveList = Lists.newLinkedList();
|
|
|
+ //从Excel读取数据
|
|
|
+ List<LisConfig> lisConfigList = ExcelUtils.importExcel(file, 0, 1, LisConfig.class);
|
|
|
+
|
|
|
+ Long hospitalId = testVO.getHospitalId();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+
|
|
|
+ //1、数据完整性校验
|
|
|
+ //2、去除前后空格
|
|
|
+ //过滤空数据,保留重复数据,方便计行
|
|
|
+ lisConfigList = lisConfigList.stream()
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getHisName())
|
|
|
+ || StringUtil.isNotBlank(i.getHisDetailName())
|
|
|
+ || StringUtil.isNotBlank(i.getUniqueCode())
|
|
|
+ || StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (ListUtil.isEmpty(lisConfigList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "校验失败,测试数据不能为空");
|
|
|
+ }
|
|
|
+ //数据预处理
|
|
|
+ List<String> emptyNumList = Lists.newLinkedList();
|
|
|
+ for (int i = 0; i < lisConfigList.size(); i++) {
|
|
|
+ if (StringUtil.isBlank(lisConfigList.get(i).getHisName())
|
|
|
+ || StringUtil.isBlank(lisConfigList.get(i).getUniqueName())) {
|
|
|
+ emptyNumList.add(String.valueOf(i + 2));
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(lisConfigList.get(i).getHisName())) {
|
|
|
+ lisConfigList.get(i).setHisName(lisConfigList.get(i).getHisName().trim());
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(lisConfigList.get(i).getHisDetailName())) {
|
|
|
+ lisConfigList.get(i).setHisDetailName(lisConfigList.get(i).getHisDetailName().trim());
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(lisConfigList.get(i).getUniqueName())) {
|
|
|
+ lisConfigList.get(i).setUniqueName(lisConfigList.get(i).getUniqueName().trim());
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(lisConfigList.get(i).getUniqueCode())) {
|
|
|
+ lisConfigList.get(i).setUniqueCode(lisConfigList.get(i).getUniqueCode().trim());
|
|
|
+ } else {
|
|
|
+ lisConfigList.get(i).setUniqueCode(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ListUtil.isNotEmpty(emptyNumList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "以下行数(不计入空行)存在不完整数据:"
|
|
|
+ + emptyNumList.stream().collect(Collectors.joining("、"))
|
|
|
+ + "。测试取消,请修改后再试。\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ //重复数据过滤
|
|
|
+ lisConfigList = lisConfigList
|
|
|
+ .stream()
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (ListUtil.isEmpty(lisConfigList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "校验失败,测试数据不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ //标准术语查询
|
|
|
+ List<String> uniqueNames = lisConfigList
|
|
|
+ .stream()
|
|
|
+ .map(i -> i.getUniqueName())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ ConceptVO conceptVO = new ConceptVO();
|
|
|
+ conceptVO.setNames(uniqueNames);
|
|
|
+ conceptVO.setType(ConceptTypeEnum.LisPack.getKey());
|
|
|
+ RespDTO<List<String>> respLisPackDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
+ RespDTOUtil.respNGDealCover(respLisPackDTO, "标准术语校验失败");
|
|
|
+ List<String> lisPackNames = respLisPackDTO.data;
|
|
|
+ conceptVO.setType(ConceptTypeEnum.Lis.getKey());
|
|
|
+ RespDTO<List<String>> respLisDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
+ RespDTOUtil.respNGDealCover(respLisDTO, "标准术语校验失败");
|
|
|
+ List<String> lisNames = respLisDTO.data;
|
|
|
+
|
|
|
+
|
|
|
+ // 已存在数据
|
|
|
+ Map<String, Map<String, Map<String, List<Long>>>> hisConfigMap = lisConfigFacade.getConfigMap(Long.valueOf(hospitalId), null, null);
|
|
|
+ Map<String, Map<String, Map<String, List<Long>>>> uniqueConfigMap = lisConfigFacade.getUniqueConfigMap(hospitalId, null, null);
|
|
|
+
|
|
|
+ //静态知识
|
|
|
+ List<ConceptInfo> infoList = conceptInfoFacade.getAllConceptInfo();
|
|
|
+ if (ListUtil.isEmpty(infoList)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ List<String> lisStaticNames = infoList.stream()
|
|
|
+ .filter(i -> i.getType().equals(GraphLabelEnum.LisName.getName()))
|
|
|
+ .map(i -> i.getName())
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<String> lisPackStaticNames = infoList.stream()
|
|
|
+ .filter(i -> i.getType().equals(GraphLabelEnum.LisSet.getName()))
|
|
|
+ .map(i -> i.getName())
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (LisConfig config : lisConfigList) {
|
|
|
+ ResultStaticKnowledge result = new ResultStaticKnowledge();
|
|
|
+ result.setGmtCreate(now);
|
|
|
+ result.setGmtModified(now);
|
|
|
+ result.setMessage("");
|
|
|
+ result.setHisName(config.getHisName());
|
|
|
+ result.setHisDetailName(config.getHisDetailName());
|
|
|
+ result.setName(config.getUniqueName());
|
|
|
+
|
|
|
+ //映射关系是否已存在
|
|
|
+ if (hisConfigMap.containsKey(result.getHisName()) &&
|
|
|
+ hisConfigMap.get(result.getHisName()).containsKey(result.getHisDetailName())
|
|
|
+ && hisConfigMap.get(result.getHisName()).get(result.getHisDetailName()).keySet().contains(result.getName())) {
|
|
|
+ if (lisPackNames.contains(result.getName()) || lisNames.contains(result.getName())) {
|
|
|
+ result.setHasStandName(1);
|
|
|
+ } else {
|
|
|
+ result.setHasStandName(0);
|
|
|
+ result.setMessage("标准术语不存在;");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result.setHasStandName(0);
|
|
|
+ result.setMessage(result.getMessage() + "映射关系不存在;");
|
|
|
+ }
|
|
|
+
|
|
|
+ //静态知识是否存在
|
|
|
+ if (lisStaticNames.contains(result.getName())
|
|
|
+ || lisPackStaticNames.contains(result.getName())) {
|
|
|
+ result.setHasStaticKnowledge(1);
|
|
|
+ } else {
|
|
|
+ //查找上级静态知识是否存在
|
|
|
+ List<LisName> lisNameList = lisNameRepository.findByNameIs(result.getName());
|
|
|
+ if (ListUtil.isEmpty(lisNameList)) {
|
|
|
+ result.setHasStaticKnowledge(0);
|
|
|
+ result.setMessage(result.getMessage() + "缺少静态知识;");
|
|
|
+ } else {
|
|
|
+ lisNameList.forEach(lisName -> {
|
|
|
+ Boolean isExist = false;
|
|
|
+ Set<LisNameLisSet> lisNameLisSetSet = lisName.getLisNamelissets();
|
|
|
+ if (lisNameLisSetSet != null && lisNameLisSetSet.size() > 0) {
|
|
|
+ List<String> lisPacks = lisNameLisSetSet.stream().map(i -> i.getLisSet()).collect(Collectors.toList())
|
|
|
+ .stream().map(i -> i.getName()).sorted().collect(Collectors.toList());
|
|
|
+ for (String lisPack : lisPacks) {
|
|
|
+ if (lisPackNames.contains(lisPack)) {
|
|
|
+ isExist = true;
|
|
|
+ result.setMessage(result.getMessage() + "取上级(" + lisPack + ")静态知识;");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isExist) {
|
|
|
+ result.setHasStaticKnowledge(1);
|
|
|
+ } else {
|
|
|
+ result.setHasStaticKnowledge(0);
|
|
|
+ result.setMessage(result.getMessage() + "缺少静态知识;");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ saveList.add(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存
|
|
|
+ saveResult(saveList, testVO);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存静态知识测试结果
|
|
|
+ *
|
|
|
+ * @param list
|
|
|
+ * @param testVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveResult(List<ResultStaticKnowledge> list, StaticKnowledgeTestVO testVO) {
|
|
|
+ Date now = new Date();
|
|
|
+ Integer totleNum = list.size();
|
|
|
+ Integer unMappingNum = list.stream().filter(i -> i.getHasStandName().equals(0)).collect(Collectors.toList()).size();
|
|
|
+ Integer withoutKnowledgeNum = list.stream().filter(i -> i.getHasStaticKnowledge().equals(0)).collect(Collectors.toList()).size();
|
|
|
+ QueryWrapper<ResultStaticInfo> resultStaticInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ resultStaticInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", testVO.getHospitalId())
|
|
|
+ .eq("case_no", testVO.getCaseNo());
|
|
|
+ ResultStaticInfo resultInfo = resultStaticInfoService.getOne(resultStaticInfoQueryWrapper, false);
|
|
|
+ if (resultInfo == null) {
|
|
|
+ resultInfo = new ResultStaticInfo();
|
|
|
+ resultInfo.setHospitalId(testVO.getHospitalId());
|
|
|
+ resultInfo.setCaseNo(testVO.getCaseNo());
|
|
|
+ resultInfo.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ resultInfo.setGmtModified(now);
|
|
|
+ resultInfo.setTotleNum(totleNum);
|
|
|
+ resultInfo.setUnMappingNum(unMappingNum);
|
|
|
+ resultInfo.setWithoutKnowledgeNum(withoutKnowledgeNum);
|
|
|
+ resultStaticInfoService.saveOrUpdate(resultInfo);
|
|
|
+
|
|
|
+ QueryWrapper<ResultStaticKnowledge> resultStaticKnowledgeQueryWrapper = new QueryWrapper<>();
|
|
|
+ resultStaticKnowledgeQueryWrapper.eq("result_id", resultInfo.getId());
|
|
|
+ resultStaticKnowledgeService.remove(resultStaticKnowledgeQueryWrapper);
|
|
|
+
|
|
|
+ for (ResultStaticKnowledge result : list) {
|
|
|
+ result.setType(testVO.getType());
|
|
|
+ result.setResultId(resultInfo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ resultStaticKnowledgeService.saveOrUpdateBatch(list);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //region --------------------------导出------------------------------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param resultStaticPageVO
|
|
|
+ */
|
|
|
+ public void exportLisExcel(HttpServletResponse response, ResultStaticPageVO resultStaticPageVO) {
|
|
|
+ resultStaticPageVO.setSize(-1L);
|
|
|
+ IPage<ResultStaticKnowledge> page = this.getPage(resultStaticPageVO);
|
|
|
+ String fileName = "检验映射测试结果导出.xls";
|
|
|
+ List<ExportLisTestDTO> records = BeanUtil.listCopyTo(page.getRecords(), ExportLisTestDTO.class);
|
|
|
+ ExcelUtils.exportExcel(records, null, "sheet1", ExportLisTestDTO.class, fileName, response, 12.8f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param resultStaticPageVO
|
|
|
+ */
|
|
|
+ public void exportLisStaticExcel(HttpServletResponse response, ResultStaticPageVO resultStaticPageVO) {
|
|
|
+ resultStaticPageVO.setSize(-1L);
|
|
|
+ IPage<ResultStaticKnowledge> page = this.getPage(resultStaticPageVO);
|
|
|
+ String fileName = "检验静态知识测试结果导出.xls";
|
|
|
+ List<ExportLisStaticTestDTO> records = BeanUtil.listCopyTo(page.getRecords(), ExportLisStaticTestDTO.class);
|
|
|
+ ExcelUtils.exportExcel(records, null, "sheet1", ExportLisStaticTestDTO.class, fileName, response, 12.8f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param resultStaticPageVO
|
|
|
+ */
|
|
|
+ public void exportCommonExcel(HttpServletResponse response, ResultStaticPageVO resultStaticPageVO) {
|
|
|
+ resultStaticPageVO.setSize(-1L);
|
|
|
+ IPage<ResultStaticKnowledge> page = this.getPage(resultStaticPageVO);
|
|
|
+ String fileName = "通用映射测试结果导出.xls";
|
|
|
+ List<ExportCommonTestDTO> records = BeanUtil.listCopyTo(page.getRecords(), ExportCommonTestDTO.class);
|
|
|
+ ExcelUtils.exportExcel(records, null, "sheet1", ExportCommonTestDTO.class, fileName, response, 12.8f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param resultStaticPageVO
|
|
|
+ */
|
|
|
+ public void exportCommonStaticExcel(HttpServletResponse response, ResultStaticPageVO resultStaticPageVO) {
|
|
|
+ resultStaticPageVO.setSize(-1L);
|
|
|
+ IPage<ResultStaticKnowledge> page = this.getPage(resultStaticPageVO);
|
|
|
+ String fileName = "通用静态知识测试结果导出.xls";
|
|
|
+ List<ExportCommonStaticTestDTO> records = BeanUtil.listCopyTo(page.getRecords(), ExportCommonStaticTestDTO.class);
|
|
|
+ ExcelUtils.exportExcel(records, null, "sheet1", ExportCommonStaticTestDTO.class, fileName, response, 12.8f);
|
|
|
+ }
|
|
|
+
|
|
|
+ //endregion --------------------------导出------------------------------
|
|
|
+}
|