|
@@ -1,6 +1,7 @@
|
|
|
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.IndexBatchDTO;
|
|
@@ -24,8 +25,10 @@ import com.diagbot.enums.IsDeleteEnum;
|
|
|
import com.diagbot.enums.MatchSourceEnum;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.MappingConfigService;
|
|
|
import com.diagbot.service.impl.MappingConfigServiceImpl;
|
|
|
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;
|
|
@@ -33,20 +36,27 @@ import com.diagbot.util.StringUtil;
|
|
|
import com.diagbot.util.SysUserUtils;
|
|
|
import com.diagbot.vo.ConceptVO;
|
|
|
import com.diagbot.vo.FilterVO;
|
|
|
+import com.diagbot.vo.IdListVO;
|
|
|
+import com.diagbot.vo.IdVO;
|
|
|
import com.diagbot.vo.MappingConfigPageVO;
|
|
|
+import com.diagbot.vo.MappingConfigVO;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
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.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -56,8 +66,14 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Component
|
|
|
public class MappingConfigFacade extends MappingConfigServiceImpl {
|
|
|
+
|
|
|
+ private static Pattern pattern = Pattern.compile("\\s*|\t|\r|\n");
|
|
|
+
|
|
|
@Autowired
|
|
|
private CdssCoreClient cdssCoreClient;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("mappingConfigServiceImpl")
|
|
|
+ private MappingConfigService mappingConfigService;
|
|
|
|
|
|
/**
|
|
|
* 分页查询
|
|
@@ -111,41 +127,12 @@ public class MappingConfigFacade extends MappingConfigServiceImpl {
|
|
|
|
|
|
//todo conceptId转标准词
|
|
|
List<MappingConfigWrapper> records = page.getRecords();
|
|
|
- ConceptVO conceptVO = new ConceptVO();
|
|
|
- List<Long> ids = Lists.newArrayList();
|
|
|
- ids.addAll(records.stream().map(MappingConfigWrapper::getConceptId).collect(Collectors.toList()));
|
|
|
- ids.addAll(records.stream().filter(i -> i.getFormConceptId() != null)
|
|
|
- .map(MappingConfigWrapper::getFormConceptId).collect(Collectors.toList()));
|
|
|
- conceptVO.setIds(ids);
|
|
|
- RespDTO<List<IndexBatchDTO>> resultRespDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
- if (RespDTOUtil.respIsOK(resultRespDTO) && ListUtil.isNotEmpty(resultRespDTO.data)) {
|
|
|
- Map<Long, String> conceptMap
|
|
|
- = resultRespDTO.data.stream().collect(Collectors.toMap(IndexBatchDTO::getId, IndexBatchDTO::getName));
|
|
|
- for (MappingConfigWrapper record : records) {
|
|
|
- if (conceptMap.containsKey(record.getConceptId())) {
|
|
|
- record.setUniqueName(conceptMap.get(record.getConceptId()));
|
|
|
- }
|
|
|
- if (record.getFormConceptId() != null && conceptMap.containsKey(record.getFormConceptId())) {
|
|
|
- record.setForm(conceptMap.get(record.getFormConceptId()));
|
|
|
- }
|
|
|
- }
|
|
|
- page.setRecords(records);
|
|
|
- }
|
|
|
+ records = addNames(records);
|
|
|
+ page.setRecords(records);
|
|
|
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 导入模板下载
|
|
|
- *
|
|
|
- * @param response
|
|
|
- */
|
|
|
- public void exportExcelModule(HttpServletResponse response, Integer type) {
|
|
|
- if (type == null) {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入数据类型:1-化验、3-辅检、4-诊断、5-药品、6-手术和操作、7-科室、8-输血、10-量表、11-护理、12-中医诊断、13-中医证候、14-麻醉");
|
|
|
- }
|
|
|
- exportExcel(response, new ArrayList<>(), type, "导入模板");
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 导出文件
|
|
@@ -175,7 +162,7 @@ public class MappingConfigFacade extends MappingConfigServiceImpl {
|
|
|
case 5:
|
|
|
fileName = "药品" + fileName;
|
|
|
List<DrugConfig> drugConfigList = BeanUtil.listCopyTo(list, DrugConfig.class);
|
|
|
- ExcelUtils.exportExcel(drugConfigList, null, "sheet1", DrugConfig.class, fileName, response, 12.8f);
|
|
|
+ ExcelUtils.exportExcel(drugConfigList, getForm(), "sheet1", DrugConfig.class, fileName, response, 12.8f);
|
|
|
break;
|
|
|
case 6:
|
|
|
fileName = "手术和操作" + fileName;
|
|
@@ -223,16 +210,57 @@ public class MappingConfigFacade extends MappingConfigServiceImpl {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 导入数据预匹配
|
|
|
+ * 剂型说明
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getForm() {
|
|
|
+ String form = "药品模板——药品剂型填写说明[不填";
|
|
|
+ //药品剂型
|
|
|
+ ConceptVO conceptVO = new ConceptVO();
|
|
|
+ conceptVO.setSource(MatchSourceEnum.StandWord.getKey());
|
|
|
+ conceptVO.setType(ConceptTypeEnum.Form.getKey());
|
|
|
+ RespDTO<List<IndexBatchDTO>> respDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
+ if (RespDTOUtil.respIsOK(respDTO)) {
|
|
|
+ String formList = respDTO.data.stream()
|
|
|
+ .map(i -> i.getName())
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.joining("、"));
|
|
|
+ if (StringUtil.isNotBlank(formList)) {
|
|
|
+ form += "、" + formList;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ form += "]";
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入模板下载
|
|
|
*
|
|
|
- * @param file
|
|
|
- * @param type
|
|
|
* @param response
|
|
|
*/
|
|
|
- public void precDataMatch(MultipartFile file, Integer type, HttpServletResponse response) {
|
|
|
- List<MappingConfigWrapper> originList = readImportData(file, type);
|
|
|
- List<MappingConfigWrapper> retList = dataProcess(originList, type);
|
|
|
- exportExcel(response, retList, type, "关联数据(预匹配)");
|
|
|
+ public void exportExcelModule(HttpServletResponse response, MappingConfigVO mappingConfigVO) {
|
|
|
+ exportExcel(response, new ArrayList<>(), mappingConfigVO.getType(), "导入模板");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ public void exportExcel(HttpServletResponse response, MappingConfigVO mappingConfigVO) {
|
|
|
+ if (mappingConfigVO.getHospitalId() == null) {
|
|
|
+ mappingConfigVO.setHospitalId(Long.valueOf(SysUserUtils.getCurrentHospitalID()));
|
|
|
+ }
|
|
|
+ QueryWrapper<MappingConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", mappingConfigVO.getHospitalId())
|
|
|
+ .eq("type", mappingConfigVO.getType())
|
|
|
+ .orderByDesc("gmt_modified");
|
|
|
+ List<MappingConfig> records = this.list(queryWrapper);
|
|
|
+ List<MappingConfigWrapper> exportList = BeanUtil.listCopyTo(records, MappingConfigWrapper.class);
|
|
|
+ exportList = addNames(exportList);
|
|
|
+ exportExcel(response, exportList, mappingConfigVO.getType(), "映射");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -300,12 +328,25 @@ public class MappingConfigFacade extends MappingConfigServiceImpl {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 数据处理
|
|
|
+ * 导入数据预匹配
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @param type
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ public void precDataMatch(MultipartFile file, Integer type, HttpServletResponse response) {
|
|
|
+ List<MappingConfigWrapper> originList = readImportData(file, type);
|
|
|
+ List<MappingConfigWrapper> retList = precDataProcess(originList, type);
|
|
|
+ exportExcel(response, retList, type, "关联数据(预匹配)");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 预匹配数据处理
|
|
|
*
|
|
|
* @param originList
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<MappingConfigWrapper> dataProcess(List<MappingConfigWrapper> originList, Integer type) {
|
|
|
+ public List<MappingConfigWrapper> precDataProcess(List<MappingConfigWrapper> originList, Integer type) {
|
|
|
List<MappingConfigWrapper> retList = Lists.newLinkedList();
|
|
|
List<MappingConfigWrapper> dataList = Lists.newLinkedList();
|
|
|
List<MappingConfigWrapper> standardList = Lists.newLinkedList();
|
|
@@ -550,9 +591,491 @@ public class MappingConfigFacade extends MappingConfigServiceImpl {
|
|
|
} else {
|
|
|
retList = BeanUtil.listCopyTo(codeList, MappingConfigWrapper.class);
|
|
|
}
|
|
|
+
|
|
|
+ for (MappingConfigWrapper item : retList) {
|
|
|
+ if (item.getIsMatch() == null) {
|
|
|
+ item.setIsMatch(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
return retList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 数据导入
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @param hospitalId
|
|
|
+ * @param type
|
|
|
+ */
|
|
|
+ public void importExcel(MultipartFile file, Long hospitalId, Integer type, String userId) {
|
|
|
+ if (hospitalId == null) {
|
|
|
+ hospitalId = Long.valueOf(SysUserUtils.getCurrentHospitalID());
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(userId)) {
|
|
|
+ userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
+ }
|
|
|
+ List<MappingConfigWrapper> originList = readImportData(file, type);
|
|
|
+ if (ListUtil.isEmpty(originList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "校验失败,导入数据不能为空");
|
|
|
+ }
|
|
|
+ importDataProcess(originList, hospitalId, type, userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入数据处理
|
|
|
+ *
|
|
|
+ * @param originList
|
|
|
+ * @param hospitalId
|
|
|
+ * @param type
|
|
|
+ */
|
|
|
+ public boolean importDataProcess(List<MappingConfigWrapper> originList, Long hospitalId, Integer type, String userId) {
|
|
|
+ List<MappingConfigWrapper> tempList = Lists.newLinkedList();
|
|
|
+
|
|
|
+ Date now = DateUtil.now();
|
|
|
+
|
|
|
+ //过滤空数据,保留重复数据,方便计行
|
|
|
+ //去除空格、回车、换行符、制表符
|
|
|
+ originList = originList.stream()
|
|
|
+ .filter(MappingConfigWrapper::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (ListUtil.isEmpty(originList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "校验失败,导入数据不能为空");
|
|
|
+ }
|
|
|
+ List<Integer> emptyNumList = Lists.newLinkedList();
|
|
|
+ Integer rowId = 1;
|
|
|
+ for (MappingConfigWrapper item : originList) {
|
|
|
+ if (StringUtil.isBlank(item.getHisName())) {
|
|
|
+ if (type.equals(ConceptTypeEnum.Drug.getKey())) {
|
|
|
+ emptyNumList.add(rowId + 2);
|
|
|
+ } else {
|
|
|
+ emptyNumList.add(rowId + 1);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ item.setHisName(pattern.matcher(item.getHisName()).replaceAll(""));
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(item.getHisCode())) {
|
|
|
+ item.setHisCode(pattern.matcher(item.getHisCode()).replaceAll(""));
|
|
|
+ } else {
|
|
|
+ item.setHisCode("");
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(item.getHisDetailName())) {
|
|
|
+ item.setHisDetailName(pattern.matcher(item.getHisDetailName()).replaceAll(""));
|
|
|
+ } else {
|
|
|
+ item.setHisDetailName("");
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(item.getUniqueName())) {
|
|
|
+ item.setUniqueName(pattern.matcher(item.getUniqueName()).replaceAll(""));
|
|
|
+ item.setIsMatch(1);
|
|
|
+ } else {
|
|
|
+ item.setUniqueName("");
|
|
|
+ item.setIsMatch(0);
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(item.getForm())) {
|
|
|
+ item.setForm(pattern.matcher(item.getForm()).replaceAll(""));
|
|
|
+ } else {
|
|
|
+ item.setForm("");
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(item.getCode())) {
|
|
|
+ item.setCode(pattern.matcher(item.getCode()).replaceAll(""));
|
|
|
+ } else {
|
|
|
+ item.setCode("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //医院术语名称不允许为空
|
|
|
+ if (ListUtil.isNotEmpty(emptyNumList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "以下行数(不计入空行)存在不完整数据:"
|
|
|
+ + emptyNumList.stream().map(Object::toString)
|
|
|
+ .collect(Collectors.joining("、"))
|
|
|
+ + "。导入取消,请修改后再试。\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> hisNames = originList
|
|
|
+ .stream()
|
|
|
+ .map(i -> i.getHisName())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ originList = originList.stream().distinct().collect(Collectors.toList());
|
|
|
+ List<MappingConfigWrapper> matchList
|
|
|
+ = originList.stream().filter(i -> StringUtil.isNotBlank(i.getUniqueName())).collect(Collectors.toList());
|
|
|
+ Map<String, List<MappingConfigWrapper>> matchMap
|
|
|
+ = matchList.stream().collect(Collectors.groupingBy(i -> i.getHisName() + "_"
|
|
|
+ + i.getHisCode() + "_"
|
|
|
+ + i.getHisDetailName()));
|
|
|
+ Map<String, List<MappingConfigWrapper>> fullMatchMap = matchList.stream()
|
|
|
+ .collect(Collectors.groupingBy(i -> i.getHisName() + "_"
|
|
|
+ + i.getHisCode() + "_"
|
|
|
+ + i.getHisDetailName() + "_"
|
|
|
+ + i.getUniqueName() + "_"
|
|
|
+ + i.getForm()));
|
|
|
+ List<MappingConfigWrapper> unMatchList
|
|
|
+ = originList.stream().filter(i -> StringUtil.isBlank(i.getUniqueName())).collect(Collectors.toList());
|
|
|
+ Map<String, List<MappingConfigWrapper>> unMatchMap
|
|
|
+ = unMatchList.stream().collect(Collectors.groupingBy(i -> i.getHisName() + "_"
|
|
|
+ + i.getHisCode() + "_"
|
|
|
+ + i.getHisDetailName()));
|
|
|
+ Iterator<MappingConfigWrapper> it = unMatchList.iterator();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ MappingConfigWrapper item = it.next();
|
|
|
+ String matchKey = item.getHisName() + "_"
|
|
|
+ + item.getHisCode() + "_"
|
|
|
+ + item.getHisDetailName();
|
|
|
+ if (matchMap.containsKey(matchKey)) {
|
|
|
+ it.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tempList.addAll(matchList);
|
|
|
+ tempList.addAll(unMatchList);
|
|
|
+
|
|
|
+ // 验证数据是否已存在,已存在的先删除
|
|
|
+ // 没id的删除重新插入,有id的更新
|
|
|
+ synchronized (this) {
|
|
|
+ List<Long> deleteIds = Lists.newLinkedList();
|
|
|
+ List<MappingConfig> existList = this.list(new QueryWrapper<MappingConfig>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", hospitalId)
|
|
|
+ .eq("type", type)
|
|
|
+ .in("his_name", hisNames));
|
|
|
+
|
|
|
+ if (ListUtil.isEmpty(existList)) {
|
|
|
+ List<MappingConfigWrapper> existWrapperList = BeanUtil.listCopyTo(existList, MappingConfigWrapper.class);
|
|
|
+ existWrapperList = addNames(existWrapperList);
|
|
|
+ for (MappingConfigWrapper item : existWrapperList) {
|
|
|
+ if (StringUtil.isBlank(item.getHisDetailName())) {
|
|
|
+ item.setHisDetailName("");
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(item.getUniqueName())) {
|
|
|
+ item.getUniqueName();
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(item.getForm())) {
|
|
|
+ item.setForm("");
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(item.getHisCode())) {
|
|
|
+ item.setHisCode("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<MappingConfigWrapper> db_matchList
|
|
|
+ = existWrapperList.stream().filter(i -> i.getIsMatch().equals(1)).collect(Collectors.toList());
|
|
|
+ Map<String, List<MappingConfigWrapper>> db_matchMap
|
|
|
+ = db_matchList.stream().collect(Collectors.groupingBy(i -> i.getHisName() + "_"
|
|
|
+ + i.getHisCode() + "_"
|
|
|
+ + i.getHisDetailName()));
|
|
|
+ List<MappingConfigWrapper> db_unMatchList
|
|
|
+ = existWrapperList.stream().filter(i -> i.getIsMatch().equals(0)).collect(Collectors.toList());
|
|
|
+ Map<String, List<MappingConfigWrapper>> db_unMatchMap
|
|
|
+ = db_unMatchList.stream().collect(Collectors.groupingBy(i -> i.getHisName() + "_"
|
|
|
+ + i.getHisCode() + "_"
|
|
|
+ + i.getHisDetailName()));
|
|
|
+
|
|
|
+ for (MappingConfigWrapper item : db_matchList) {
|
|
|
+ String matchKey = item.getHisName() + "_"
|
|
|
+ + item.getHisCode() + "_"
|
|
|
+ + item.getHisDetailName() + "_"
|
|
|
+ + item.getUniqueName() + "_"
|
|
|
+ + item.getForm();
|
|
|
+ if (fullMatchMap.containsKey(matchKey)) {
|
|
|
+ deleteIds.add(item.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (MappingConfigWrapper item : db_unMatchList) {
|
|
|
+ String matchKey = item.getHisName() + "_"
|
|
|
+ + item.getHisCode() + "_"
|
|
|
+ + item.getHisDetailName();
|
|
|
+ if (matchMap.containsKey(matchKey)
|
|
|
+ || db_matchMap.containsKey(matchKey)
|
|
|
+ || unMatchMap.containsKey(matchKey)) {
|
|
|
+ deleteIds.add(item.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //标准术语校验
|
|
|
+ ConceptVO conceptVO = new ConceptVO();
|
|
|
+ conceptVO.setSource(MatchSourceEnum.StandWord.getKey());
|
|
|
+ if (type.equals(ConceptTypeEnum.LisPack.getKey())) {
|
|
|
+ conceptVO.setType(ConceptTypeEnum.LisPack.getKey());
|
|
|
+ conceptVO.setNames(tempList.stream()
|
|
|
+ .filter(i -> StringUtil.isBlank(i.getHisDetailName())
|
|
|
+ && StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
+ .map(MappingConfigWrapper::getUniqueName)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ RespDTO<List<IndexBatchDTO>> respDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
+ RespDTOUtil.respNGDealCover(respDTO, "标准术语校验失败");
|
|
|
+ Map<String, List<Long>> packMap = respDTO.data.stream()
|
|
|
+ .collect(Collectors.groupingBy(IndexBatchDTO::getName,
|
|
|
+ Collectors.mapping(IndexBatchDTO::getId, Collectors.toList())));
|
|
|
+ conceptVO.setType(ConceptTypeEnum.Lis.getKey());
|
|
|
+ conceptVO.setNames(tempList.stream()
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getHisDetailName())
|
|
|
+ && StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
+ .map(MappingConfigWrapper::getUniqueName)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ respDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
+ RespDTOUtil.respNGDealCover(respDTO, "标准术语校验失败");
|
|
|
+ Map<String, List<Long>> lisMap = respDTO.data.stream()
|
|
|
+ .collect(Collectors.groupingBy(IndexBatchDTO::getName,
|
|
|
+ Collectors.mapping(IndexBatchDTO::getId, Collectors.toList())));
|
|
|
+
|
|
|
+ for (MappingConfigWrapper item : tempList) {
|
|
|
+ if (StringUtil.isBlank(item.getUniqueName())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(item.getHisDetailName())) {
|
|
|
+ if (packMap.containsKey(item.getUniqueName())) {
|
|
|
+ item.setConceptId(packMap.get(item.getUniqueName()).get(0));
|
|
|
+ item.setIsMatch(1);
|
|
|
+ } else {
|
|
|
+ item.setIsMatch(0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (lisMap.containsKey(item.getUniqueName())) {
|
|
|
+ item.setConceptId(lisMap.get(item.getUniqueName()).get(0));
|
|
|
+ item.setIsMatch(1);
|
|
|
+ } else {
|
|
|
+ item.setIsMatch(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ conceptVO.setType(type);
|
|
|
+ conceptVO.setNames(tempList.stream()
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
+ .map(MappingConfigWrapper::getUniqueName)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ RespDTO<List<IndexBatchDTO>> respDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
+ if (RespDTOUtil.respIsOK(respDTO)) {
|
|
|
+ Map<String, List<Long>> map = respDTO.data.stream()
|
|
|
+ .collect(Collectors.groupingBy(IndexBatchDTO::getName,
|
|
|
+ Collectors.mapping(IndexBatchDTO::getId, Collectors.toList())));
|
|
|
+ for (MappingConfigWrapper item : tempList) {
|
|
|
+ if (StringUtil.isBlank(item.getUniqueName())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (map.containsKey(item.getUniqueName())) {
|
|
|
+ item.setConceptId(map.get(item.getUniqueName()).get(0));
|
|
|
+ item.setIsMatch(1);
|
|
|
+ } else {
|
|
|
+ item.setIsMatch(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //剂型校验
|
|
|
+ if (type.equals(ConceptTypeEnum.Drug)) {
|
|
|
+ conceptVO.setType(ConceptTypeEnum.Form.getKey());
|
|
|
+ conceptVO.setNames(tempList.stream()
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getForm()))
|
|
|
+ .map(MappingConfigWrapper::getForm)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ RespDTO<List<IndexBatchDTO>> respDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
+ if (RespDTOUtil.respIsOK(respDTO)) {
|
|
|
+ Map<String, List<Long>> formMap = respDTO.data.stream()
|
|
|
+ .collect(Collectors.groupingBy(IndexBatchDTO::getName,
|
|
|
+ Collectors.mapping(IndexBatchDTO::getId, Collectors.toList())));
|
|
|
+ for (MappingConfigWrapper item : tempList) {
|
|
|
+ if (StringUtil.isBlank(item.getForm())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (formMap.containsKey(item.getForm())) {
|
|
|
+ item.setFormConceptId(formMap.get(item.getForm()).get(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //重复数据过滤
|
|
|
+ tempList = tempList
|
|
|
+ .stream()
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (MappingConfigWrapper item : tempList) {
|
|
|
+ item.setCreator(userId);
|
|
|
+ item.setGmtCreate(now);
|
|
|
+ item.setModifier(userId);
|
|
|
+ item.setGmtModified(now);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除已存在映射关系
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
+ deleteRecords(idListVO);
|
|
|
+ List<MappingConfig> saveList = BeanUtil.listCopyTo(tempList, MappingConfig.class);
|
|
|
+ mappingConfigService.saveOrUpdateBatch(saveList);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录-单条
|
|
|
+ *
|
|
|
+ * @param idVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteRecord(IdVO idVO) {
|
|
|
+ UpdateWrapper<MappingConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("id", idVO.getId())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
+ mappingConfigService.removeById(idVO.getId());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录-批量
|
|
|
+ *
|
|
|
+ * @param idListVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteRecords(IdListVO idListVO) {
|
|
|
+ if (ListUtil.isEmpty(idListVO.getIds())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ UpdateWrapper<MappingConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.in("id", idListVO.getIds())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
+ mappingConfigService.removeByIds(idListVO.getIds());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取记录-单条
|
|
|
+ *
|
|
|
+ * @param idVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public MappingConfigWrapper getRecord(IdVO idVO) {
|
|
|
+ MappingConfig item = this.getById(idVO.getId());
|
|
|
+ MappingConfigWrapper itemWrapper = new MappingConfigWrapper();
|
|
|
+ BeanUtils.copyProperties(item, itemWrapper);
|
|
|
+ List<MappingConfigWrapper> retList = Lists.newArrayList();
|
|
|
+ retList.add(itemWrapper);
|
|
|
+ addNames(retList);
|
|
|
+
|
|
|
+ return retList.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否已存在
|
|
|
+ *
|
|
|
+ * @param mappingConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean isExistRecord(MappingConfig mappingConfig) {
|
|
|
+ if (mappingConfig.getType() == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入请输入术语类型:1-化验、3-辅检、4-诊断、5-药品、6-手术和操作、7-科室、8-输血、10-量表、11-护理、12-中医诊断、13-中医证候、14-麻醉");
|
|
|
+ }
|
|
|
+ if (mappingConfig.getHospitalId() == null) {
|
|
|
+ mappingConfig.setHospitalId(Long.valueOf(SysUserUtils.getCurrentHospitalID()));
|
|
|
+ }
|
|
|
+ QueryWrapper<MappingConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", mappingConfig.getHospitalId())
|
|
|
+ .eq("type", mappingConfig.getType())
|
|
|
+ .eq("his_name", mappingConfig.getHisName())
|
|
|
+ .eq("concept_id", mappingConfig.getConceptId());
|
|
|
+ if (StringUtil.isBlank(mappingConfig.getHisDetailName())) {
|
|
|
+ queryWrapper.and(i -> i.isNull("his_detail_name")
|
|
|
+ .or()
|
|
|
+ .eq("his_detail_name", ""));
|
|
|
+ } else {
|
|
|
+ queryWrapper
|
|
|
+ .eq("his_detail_name", mappingConfig.getHisDetailName());
|
|
|
+ }
|
|
|
+ if (mappingConfig.getFormConceptId() != null) {
|
|
|
+ queryWrapper.eq("form_concept_id", mappingConfig.getFormConceptId());
|
|
|
+ }
|
|
|
+ MappingConfig oldRecord = this.getOne(queryWrapper, false);
|
|
|
+ if (mappingConfig.getId() == null
|
|
|
+ && oldRecord != null) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
+ }
|
|
|
+ if (mappingConfig.getId() != null
|
|
|
+ && oldRecord != null
|
|
|
+ && !mappingConfig.getId().equals(oldRecord.getId())) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录-单条
|
|
|
+ *
|
|
|
+ * @param mappingConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecord(MappingConfig mappingConfig) {
|
|
|
+ if (mappingConfig.getType() == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入请输入术语类型:1-化验、3-辅检、4-诊断、5-药品、6-手术和操作、7-科室、8-输血、10-量表、11-护理、12-中医诊断、13-中医证候、14-麻醉");
|
|
|
+ }
|
|
|
+ if (mappingConfig.getHospitalId() == null) {
|
|
|
+ mappingConfig.setHospitalId(Long.valueOf(SysUserUtils.getCurrentHospitalID()));
|
|
|
+ }
|
|
|
+ String userId = "";
|
|
|
+ if (StringUtil.isBlank(mappingConfig.getModifier())) {
|
|
|
+ userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
+ }
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ mappingConfig.setModifier(userId);
|
|
|
+ mappingConfig.setGmtModified(now);
|
|
|
+ QueryWrapper<MappingConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", mappingConfig.getHospitalId())
|
|
|
+ .eq("type", mappingConfig.getType())
|
|
|
+ .eq("his_name", mappingConfig.getHisName())
|
|
|
+ .eq("concept_id", mappingConfig.getConceptId());
|
|
|
+ if (StringUtil.isBlank(mappingConfig.getHisDetailName())) {
|
|
|
+ queryWrapper.and(i -> i.isNull("his_detail_name")
|
|
|
+ .or()
|
|
|
+ .eq("his_detail_name", ""));
|
|
|
+ } else {
|
|
|
+ queryWrapper.eq("his_detail_name", mappingConfig.getHisDetailName());
|
|
|
+ }
|
|
|
+ MappingConfig oldRecord = this.getOne(queryWrapper, false);
|
|
|
+ if (mappingConfig.getId() == null
|
|
|
+ && oldRecord != null) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
+ }
|
|
|
+ if (mappingConfig.getId() != null
|
|
|
+ && oldRecord != null
|
|
|
+ && !mappingConfig.getId().equals(oldRecord.getId())) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
+ }
|
|
|
+ //新增数据
|
|
|
+ if (mappingConfig.getId() == null) {
|
|
|
+ mappingConfig.setCreator(userId);
|
|
|
+ mappingConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (mappingConfig.getIsDeleted() == null) {
|
|
|
+ mappingConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除未匹配的关系
|
|
|
+ QueryWrapper<MappingConfig> qwUnMaptch = new QueryWrapper<>();
|
|
|
+ qwUnMaptch.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", mappingConfig.getHospitalId())
|
|
|
+ .eq("type", mappingConfig.getType())
|
|
|
+ .eq("his_name", mappingConfig.getHisName())
|
|
|
+ .eq("concept_id", null);
|
|
|
+ if (StringUtil.isBlank(mappingConfig.getHisDetailName())) {
|
|
|
+ qwUnMaptch.and(i -> i.isNull("his_detail_name")
|
|
|
+ .or()
|
|
|
+ .eq("his_detail_name", ""));
|
|
|
+ } else {
|
|
|
+ qwUnMaptch.eq("his_detail_name", mappingConfig.getHisDetailName());
|
|
|
+ }
|
|
|
+ this.remove(qwUnMaptch);
|
|
|
+
|
|
|
+ this.saveOrUpdate(mappingConfig);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 根据医院名称分组-返回id
|
|
|
*
|
|
@@ -673,4 +1196,45 @@ public class MappingConfigFacade extends MappingConfigServiceImpl {
|
|
|
}
|
|
|
return retMap;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回结果添加标准术语,药品剂型
|
|
|
+ *
|
|
|
+ * @param list
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<MappingConfigWrapper> addNames(List<MappingConfigWrapper> list) {
|
|
|
+ if (ListUtil.isEmpty(list)) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> ids = Lists.newArrayList();
|
|
|
+ ids.addAll(list.stream()
|
|
|
+ .filter(i -> i.getConceptId() != null)
|
|
|
+ .map(MappingConfigWrapper::getConceptId)
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ ids.addAll(list.stream()
|
|
|
+ .filter(i -> i.getFormConceptId() != null)
|
|
|
+ .map(MappingConfigWrapper::getFormConceptId)
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+
|
|
|
+ ConceptVO conceptVO = new ConceptVO();
|
|
|
+ conceptVO.setSource(-1);
|
|
|
+ conceptVO.setIds(ids);
|
|
|
+ RespDTO<List<IndexBatchDTO>> respDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
+ if (RespDTOUtil.respIsOK(respDTO)) {
|
|
|
+ Map<Long, IndexBatchDTO> conceptMap
|
|
|
+ = respDTO.data.stream().collect(Collectors.toMap(IndexBatchDTO::getId, v -> v));
|
|
|
+ for (MappingConfigWrapper record : list) {
|
|
|
+ if (record.getConceptId() != null && conceptMap.containsKey(record.getConceptId())) {
|
|
|
+ record.setUniqueName(conceptMap.get(record.getConceptId()).getName());
|
|
|
+ record.setCode(conceptMap.get(record.getConceptId()).getCode());
|
|
|
+ }
|
|
|
+ if (record.getFormConceptId() != null && conceptMap.containsKey(record.getFormConceptId())) {
|
|
|
+ record.setForm(conceptMap.get(record.getFormConceptId()).getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|