|
@@ -1,847 +0,0 @@
|
|
|
-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.DictionaryInfoDTO;
|
|
|
-import com.diagbot.dto.HosRelationNumDTO;
|
|
|
-import com.diagbot.dto.RespDTO;
|
|
|
-import com.diagbot.entity.DrugConfig;
|
|
|
-import com.diagbot.enums.ConceptTypeEnum;
|
|
|
-import com.diagbot.enums.IsDeleteEnum;
|
|
|
-import com.diagbot.exception.CommonErrorCode;
|
|
|
-import com.diagbot.exception.CommonException;
|
|
|
-import com.diagbot.service.DrugConfigService;
|
|
|
-import com.diagbot.util.DateUtil;
|
|
|
-import com.diagbot.util.EntityUtil;
|
|
|
-import com.diagbot.util.ExcelUtils;
|
|
|
-import com.diagbot.util.ListUtil;
|
|
|
-import com.diagbot.util.RespDTOUtil;
|
|
|
-import com.diagbot.util.StringUtil;
|
|
|
-import com.diagbot.util.UserUtils;
|
|
|
-import com.diagbot.vo.ConceptVO;
|
|
|
-import com.diagbot.vo.DrugConfigListVO;
|
|
|
-import com.diagbot.vo.DrugConfigPageVO;
|
|
|
-import com.diagbot.vo.HosRelationNumPageVO;
|
|
|
-import com.diagbot.vo.HospitalIdVO;
|
|
|
-import com.diagbot.vo.IdListVO;
|
|
|
-import com.diagbot.vo.IdVO;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.util.ArrayList;
|
|
|
-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/7/29 15:04
|
|
|
- */
|
|
|
-@Component
|
|
|
-public class DrugConfigFacade {
|
|
|
- @Autowired
|
|
|
- private DrugConfigService drugConfigService;
|
|
|
- @Autowired
|
|
|
- private CdssCoreClient cdssCoreClient;
|
|
|
- @Autowired
|
|
|
- private DictionaryFacade dictionaryFacade;
|
|
|
-
|
|
|
- /**
|
|
|
- * 判断是否已存在
|
|
|
- *
|
|
|
- * @param drugConfig
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Boolean isExistRecord(DrugConfig drugConfig) {
|
|
|
- QueryWrapper<DrugConfig> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("hospital_id", drugConfig.getHospitalId())
|
|
|
- .eq("his_name", drugConfig.getHisName())
|
|
|
- .eq("unique_name", drugConfig.getUniqueName());
|
|
|
- if (StringUtil.isBlank(drugConfig.getForm())) {
|
|
|
- queryWrapper.and(i -> i.isNull("form")
|
|
|
- .or()
|
|
|
- .eq("form", ""));
|
|
|
- } else {
|
|
|
- queryWrapper.eq("form", drugConfig.getForm());
|
|
|
- }
|
|
|
- DrugConfig oldRecord = drugConfigService.getOne(queryWrapper, false);
|
|
|
- if (drugConfig.getId() == null
|
|
|
- && oldRecord != null) {
|
|
|
- throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
- }
|
|
|
- if (drugConfig.getId() != null
|
|
|
- && oldRecord != null
|
|
|
- && !drugConfig.getId().equals(oldRecord.getId())) {
|
|
|
- throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 保存记录-单条
|
|
|
- *
|
|
|
- * @param drugConfig
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Boolean saveOrUpdateRecord(DrugConfig drugConfig) {
|
|
|
- String userId = UserUtils.getCurrentPrincipleID();
|
|
|
- Date now = DateUtil.now();
|
|
|
- drugConfig.setModifier(userId);
|
|
|
- drugConfig.setGmtModified(now);
|
|
|
- QueryWrapper<DrugConfig> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("hospital_id", drugConfig.getHospitalId())
|
|
|
- .eq("his_name", drugConfig.getHisName())
|
|
|
- .eq("unique_name", drugConfig.getUniqueName());
|
|
|
- if (StringUtil.isBlank(drugConfig.getForm())) {
|
|
|
- queryWrapper.and(i -> i.isNull("form")
|
|
|
- .or()
|
|
|
- .eq("form", ""));
|
|
|
- } else {
|
|
|
- queryWrapper.eq("form", drugConfig.getForm());
|
|
|
- }
|
|
|
- DrugConfig oldRecord = drugConfigService.getOne(queryWrapper, false);
|
|
|
- if (drugConfig.getId() == null
|
|
|
- && oldRecord != null) {
|
|
|
- throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
- }
|
|
|
- if (drugConfig.getId() != null
|
|
|
- && oldRecord != null
|
|
|
- && !drugConfig.getId().equals(oldRecord.getId())) {
|
|
|
- throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
- }
|
|
|
- //新增数据
|
|
|
- if (drugConfig.getId() == null) {
|
|
|
- drugConfig.setCreator(userId);
|
|
|
- drugConfig.setGmtCreate(now);
|
|
|
- }
|
|
|
- if (drugConfig.getIsDeleted() == null) {
|
|
|
- drugConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
- }
|
|
|
- drugConfigService.saveOrUpdate(drugConfig);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 保存记录-批量
|
|
|
- *
|
|
|
- * @param drugConfigListVO
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Boolean saveOrUpdateRecords(DrugConfigListVO drugConfigListVO) {
|
|
|
- if (ListUtil.isEmpty(drugConfigListVO.getDrugConfigList())) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- return saveOrUpdateRecords(drugConfigListVO.getDrugConfigList());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 批量保存
|
|
|
- *
|
|
|
- * @param drugConfigList
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Boolean saveOrUpdateRecords(List<DrugConfig> drugConfigList) {
|
|
|
- if (ListUtil.isEmpty(drugConfigList)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- String userId = UserUtils.getCurrentPrincipleID();
|
|
|
- Date now = DateUtil.now();
|
|
|
-
|
|
|
- //数据不完整的不保存
|
|
|
- //过滤外部名称或公表名为空的数据
|
|
|
- drugConfigList = drugConfigList
|
|
|
- .stream()
|
|
|
- .filter(i -> i.getHospitalId() != null)
|
|
|
- .filter(i -> StringUtil.isNotBlank(i.getHisName()))
|
|
|
- .filter(i -> StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- if (ListUtil.isEmpty(drugConfigList)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- Long hospitalId = drugConfigList.get(0).getHospitalId();
|
|
|
-
|
|
|
- List<String> hisNames = drugConfigList
|
|
|
- .stream()
|
|
|
- .map(i -> i.getHisName())
|
|
|
- .collect(Collectors.toList());
|
|
|
- List<String> uniqueNames = drugConfigList
|
|
|
- .stream()
|
|
|
- .map(i -> i.getUniqueName())
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- // 验证数据是否已存在,已存在的先删除
|
|
|
- // 没id的删除重新插入,有id的更新
|
|
|
- List<Long> deleteIds = Lists.newLinkedList();
|
|
|
- Map<String, Map<String, Map<String, List<Long>>>> configMap
|
|
|
- = getConfigMap(hospitalId, hisNames, uniqueNames);
|
|
|
- drugConfigList.forEach(drugConfig -> {
|
|
|
- drugConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
- drugConfig.setModifier(userId);
|
|
|
- drugConfig.setGmtModified(now);
|
|
|
- String form = StringUtil.isBlank(drugConfig.getForm()) ? "" : drugConfig.getForm();
|
|
|
- if (drugConfig.getId() == null) {
|
|
|
- if (configMap.get(drugConfig.getHisName()) != null
|
|
|
- && configMap.get(drugConfig.getHisName()).get(form) != null
|
|
|
- && ListUtil.isNotEmpty(configMap.get(drugConfig.getHisName()).get(form).get(drugConfig.getUniqueName()))) {
|
|
|
- deleteIds.addAll(configMap.get(drugConfig.getHisName()).get(form).get(drugConfig.getUniqueName()));
|
|
|
- }
|
|
|
- drugConfig.setCreator(userId);
|
|
|
- drugConfig.setGmtCreate(now);
|
|
|
- }
|
|
|
- if (drugConfig.getIsDeleted() == null) {
|
|
|
- drugConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- //删除已存在映射关系
|
|
|
- IdListVO idListVO = new IdListVO();
|
|
|
- idListVO.setIds(deleteIds);
|
|
|
- deleteRecords(idListVO);
|
|
|
- drugConfigService.saveOrUpdateBatch(drugConfigList);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除记录-单条
|
|
|
- *
|
|
|
- * @param idVO
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Boolean deleteRecord(IdVO idVO) {
|
|
|
- UpdateWrapper<DrugConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.eq("id", idVO.getId())
|
|
|
- .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
- drugConfigService.removeById(idVO.getId());
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除记录-批量
|
|
|
- *
|
|
|
- * @param idListVO
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Boolean deleteRecords(IdListVO idListVO) {
|
|
|
- if (ListUtil.isEmpty(idListVO.getIds())) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- UpdateWrapper<DrugConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.in("id", idListVO.getIds())
|
|
|
- .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
- drugConfigService.removeByIds(idListVO.getIds());
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 分页查询
|
|
|
- *
|
|
|
- * @param drugConfigPageVO
|
|
|
- * @return
|
|
|
- */
|
|
|
- public IPage<DrugConfig> getPage(DrugConfigPageVO drugConfigPageVO) {
|
|
|
- return drugConfigService.getPage(drugConfigPageVO);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 数据导入
|
|
|
- *
|
|
|
- * @param file
|
|
|
- * @param hospitalIdVO
|
|
|
- */
|
|
|
- public void importExcel(MultipartFile file, HospitalIdVO hospitalIdVO) {
|
|
|
- List<DrugConfig> drugConfigList = ExcelUtils.importExcel(file, 1, 1, DrugConfig.class);
|
|
|
- if (ListUtil.isNotEmpty(drugConfigList)) {
|
|
|
- drugConfigList.forEach(drugConfig -> {
|
|
|
- drugConfig.setHospitalId(hospitalIdVO.getHospitalId());
|
|
|
- });
|
|
|
- importExcelRecords(drugConfigList, hospitalIdVO);
|
|
|
- } else {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "校验失败,导入数据不能为空");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 数据导入
|
|
|
- *
|
|
|
- * @param drugConfigList
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Boolean importExcelRecords(List<DrugConfig> drugConfigList,HospitalIdVO hospitalIdVO) {
|
|
|
- Long hospitalId = hospitalIdVO.getHospitalId();
|
|
|
- String userId = UserUtils.getCurrentPrincipleID();
|
|
|
- Date now = DateUtil.now();
|
|
|
-
|
|
|
- //1、数据完整性校验
|
|
|
- //2、去除前后空格
|
|
|
- //过滤空数据,保留重复数据,方便计行
|
|
|
- drugConfigList = drugConfigList.stream()
|
|
|
- .filter(i -> StringUtil.isNotBlank(i.getHisName())
|
|
|
- || StringUtil.isNotBlank(i.getForm())
|
|
|
- || StringUtil.isNotBlank(i.getUniqueCode())
|
|
|
- || StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (ListUtil.isEmpty(drugConfigList)) {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "校验失败,导入数据不能为空");
|
|
|
- }
|
|
|
- List<String> emptyNumList = Lists.newLinkedList();
|
|
|
- //药品剂型
|
|
|
- List<DictionaryInfoDTO> dicTypeMappingList = dictionaryFacade.getListByGroupType(9);
|
|
|
- List<String> formList = dicTypeMappingList.stream()
|
|
|
- .filter(i -> StringUtil.isNotBlank(i.getName()))
|
|
|
- .map(i -> i.getName())
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- List<String> formErrNumList = Lists.newLinkedList();
|
|
|
- for (int i = 0; i < drugConfigList.size(); i++) {
|
|
|
- if (StringUtil.isBlank(drugConfigList.get(i).getHisName())
|
|
|
- || StringUtil.isBlank(drugConfigList.get(i).getUniqueName())) {
|
|
|
- emptyNumList.add(String.valueOf(i + 3));
|
|
|
- }
|
|
|
- if (StringUtil.isNotBlank(drugConfigList.get(i).getHisName())) {
|
|
|
- drugConfigList.get(i).setHisName(drugConfigList.get(i).getHisName().trim());
|
|
|
- }
|
|
|
- if (StringUtil.isNotBlank(drugConfigList.get(i).getUniqueName())) {
|
|
|
- drugConfigList.get(i).setUniqueName(drugConfigList.get(i).getUniqueName().trim());
|
|
|
- }
|
|
|
- if (StringUtil.isNotBlank(drugConfigList.get(i).getForm())) {
|
|
|
- if (!formList.contains(drugConfigList.get(i).getForm())) {
|
|
|
- formErrNumList.add(String.valueOf(i + 3));
|
|
|
- } else {
|
|
|
- drugConfigList.get(i).setForm(drugConfigList.get(i).getForm().trim());
|
|
|
- }
|
|
|
- }
|
|
|
- if (StringUtil.isNotBlank(drugConfigList.get(i).getUniqueCode())) {
|
|
|
- drugConfigList.get(i).setUniqueCode(drugConfigList.get(i).getUniqueCode().trim());
|
|
|
- } else {
|
|
|
- drugConfigList.get(i).setUniqueCode(null);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (ListUtil.isNotEmpty(emptyNumList)) {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "以下行数(不计入空行)存在不完整数据:"
|
|
|
- + emptyNumList.stream().collect(Collectors.joining("、"))
|
|
|
- + "。导入取消,请修改后再试。\n");
|
|
|
- }
|
|
|
- if (ListUtil.isNotEmpty(formErrNumList)) {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "以下行数(不计入空行)药品剂型与数据库药品剂型不匹配:"
|
|
|
- + formErrNumList.stream().collect(Collectors.joining("、"))
|
|
|
- + "。导入取消,请修改后再试。\n");
|
|
|
- }
|
|
|
-
|
|
|
- List<String> hisNames = drugConfigList
|
|
|
- .stream()
|
|
|
- .map(i -> i.getHisName())
|
|
|
- .collect(Collectors.toList());
|
|
|
- List<String> uniqueNames = drugConfigList
|
|
|
- .stream()
|
|
|
- .map(i -> i.getUniqueName())
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- // 验证数据是否已存在,已存在的先删除
|
|
|
- // 没id的删除重新插入,有id的更新
|
|
|
- List<Long> deleteIds = Lists.newLinkedList();
|
|
|
- Map<String, Map<String, Map<String, List<Long>>>> configMap
|
|
|
- = getConfigMap(Long.valueOf(hospitalId), hisNames, uniqueNames);
|
|
|
- drugConfigList.forEach(drugConfig -> {
|
|
|
- drugConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
- drugConfig.setModifier(userId);
|
|
|
- drugConfig.setGmtModified(now);
|
|
|
- String form = StringUtil.isBlank(drugConfig.getForm()) ? "" : drugConfig.getForm();
|
|
|
- if (drugConfig.getId() == null) {
|
|
|
- if (configMap.get(drugConfig.getHisName()) != null
|
|
|
- && configMap.get(drugConfig.getHisName()).get(form) != null
|
|
|
- && ListUtil.isNotEmpty(configMap.get(drugConfig.getHisName()).get(form).get(drugConfig.getUniqueName()))) {
|
|
|
- deleteIds.addAll(configMap.get(drugConfig.getHisName()).get(form).get(drugConfig.getUniqueName()));
|
|
|
- }
|
|
|
- drugConfig.setCreator(userId);
|
|
|
- drugConfig.setGmtCreate(now);
|
|
|
- }
|
|
|
- if (drugConfig.getIsDeleted() == null) {
|
|
|
- drugConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- //标准术语校验
|
|
|
- /*List<String> errorNumList = Lists.newLinkedList();
|
|
|
- ConceptVO conceptVO = new ConceptVO();
|
|
|
- conceptVO.setNames(uniqueNames);
|
|
|
- conceptVO.setType(ConceptTypeEnum.Drug.getKey());
|
|
|
- RespDTO<List<String>> respDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
- RespDTOUtil.respNGDealCover(respDTO, "标准术语校验失败");
|
|
|
- List<String> names = respDTO.data;
|
|
|
- for (int i = 0; i < drugConfigList.size(); i++) {
|
|
|
- if (!names.contains(drugConfigList.get(i).getUniqueName())) {
|
|
|
- errorNumList.add(String.valueOf(i + 2));
|
|
|
- }
|
|
|
- }
|
|
|
- if (ListUtil.isNotEmpty(errorNumList)) {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
- "以下行数(不计空行)标准术语在数据库中不存在:"
|
|
|
- + errorNumList.stream().collect(Collectors.joining("、"))
|
|
|
- + "。导入取消,请修改后再试。");
|
|
|
- }*/
|
|
|
-
|
|
|
- //重复数据过滤
|
|
|
- drugConfigList = drugConfigList
|
|
|
- .stream()
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- //删除已存在映射关系
|
|
|
- IdListVO idListVO = new IdListVO();
|
|
|
- idListVO.setIds(deleteIds);
|
|
|
- deleteRecords(idListVO);
|
|
|
- drugConfigService.saveOrUpdateBatch(drugConfigList);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取映射关系-公表名
|
|
|
- *
|
|
|
- * @param hospitalId
|
|
|
- * @param hisNames
|
|
|
- * @param uniqueNames
|
|
|
- * @return Map<hisName,Map<form,Map<uniqueName,id>>>
|
|
|
- */
|
|
|
- public Map<String, Map<String,Map<String, List<Long>>>> getConfigMap(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
- Map<String, Map<String, Map<String, List<Long>>>> retMap = new HashMap<>();
|
|
|
- QueryWrapper<DrugConfig> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("hospital_id", hospitalId);
|
|
|
- if (ListUtil.isNotEmpty(hisNames)) {
|
|
|
- queryWrapper.in("his_name", hisNames);
|
|
|
- }
|
|
|
- if (ListUtil.isNotEmpty(uniqueNames)) {
|
|
|
- queryWrapper.in("unique_name", uniqueNames);
|
|
|
- }
|
|
|
- List<DrugConfig> records = drugConfigService.list(queryWrapper);
|
|
|
- if (ListUtil.isEmpty(records)) {
|
|
|
- return retMap;
|
|
|
- }
|
|
|
- Map<String, List<DrugConfig>> hisNameMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
- for (Map.Entry<String, List<DrugConfig>> entry : hisNameMap.entrySet()) {
|
|
|
- if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
- Map<String, Map<String, List<Long>>> formMap = new HashMap<>();
|
|
|
- entry.getValue().forEach(i -> {
|
|
|
- if (StringUtil.isBlank(i.getForm())) {
|
|
|
- i.setForm("");
|
|
|
- }
|
|
|
- });
|
|
|
- Map<String, List<DrugConfig>> subMap
|
|
|
- = EntityUtil.makeEntityListMap(entry.getValue(), "form");
|
|
|
- for (Map.Entry<String, List<DrugConfig>> subEntry : subMap.entrySet()) {
|
|
|
- if (ListUtil.isNotEmpty(subEntry.getValue())) {
|
|
|
- Map<String, List<DrugConfig>> thirdMap = EntityUtil.makeEntityListMap(subEntry.getValue(), "uniqueName");
|
|
|
- Map<String, List<Long>> idMap = new HashMap<>();
|
|
|
- for (Map.Entry<String, List<DrugConfig>> thirdEntry : thirdMap.entrySet()) {
|
|
|
- idMap.put(thirdEntry.getKey(), thirdEntry.getValue().stream().map(i -> i.getId()).distinct().collect(Collectors.toList()));
|
|
|
- }
|
|
|
- formMap.put(subEntry.getKey(), idMap);
|
|
|
- }
|
|
|
- }
|
|
|
- retMap.put(entry.getKey(), formMap);
|
|
|
- }
|
|
|
- }
|
|
|
- return retMap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取映射关系-公表名
|
|
|
- *
|
|
|
- * @param hospitalId
|
|
|
- * @param hisNames
|
|
|
- * @param uniqueNames
|
|
|
- * @return Map<uniqueName,Map<form,Map<hisName,List<id>>>>
|
|
|
- */
|
|
|
- public Map<String, Map<String,Map<String, List<Long>>>> getUniqueFormConfigMap(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
- Map<String, Map<String, Map<String, List<Long>>>> retMap = new HashMap<>();
|
|
|
- QueryWrapper<DrugConfig> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("hospital_id", hospitalId);
|
|
|
- if (ListUtil.isNotEmpty(hisNames)) {
|
|
|
- queryWrapper.in("his_name", hisNames);
|
|
|
- }
|
|
|
- if (ListUtil.isNotEmpty(uniqueNames)) {
|
|
|
- queryWrapper.in("unique_name", uniqueNames);
|
|
|
- }
|
|
|
- List<DrugConfig> records = drugConfigService.list(queryWrapper);
|
|
|
- if (ListUtil.isEmpty(records)) {
|
|
|
- return retMap;
|
|
|
- }
|
|
|
-
|
|
|
- records.forEach(record -> {
|
|
|
- if (StringUtil.isBlank(record.getForm())) {
|
|
|
- record.setForm("");
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- Map<String, List<DrugConfig>> uniqueNameMap = EntityUtil.makeEntityListMap(records, "uniqueName");
|
|
|
- for (Map.Entry<String, List<DrugConfig>> entry : uniqueNameMap.entrySet()) {
|
|
|
- if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
- Map<String, Map<String, List<Long>>> subMap = new HashMap<>();
|
|
|
- Map<String, List<DrugConfig>> hisNameMap
|
|
|
- = EntityUtil.makeEntityListMap(entry.getValue(), "form");
|
|
|
- for (Map.Entry<String, List<DrugConfig>> hisEntry : hisNameMap.entrySet()) {
|
|
|
- if (ListUtil.isNotEmpty(hisEntry.getValue())) {
|
|
|
- Map<String, List<DrugConfig>> thirdMap = EntityUtil.makeEntityListMap(hisEntry.getValue(), "hisName");
|
|
|
- Map<String, List<Long>> idMap = new HashMap<>();
|
|
|
- for (Map.Entry<String, List<DrugConfig>> thirdEntry : thirdMap.entrySet()) {
|
|
|
- idMap.put(thirdEntry.getKey(), thirdEntry.getValue().stream().map(i -> i.getId()).distinct().collect(Collectors.toList()));
|
|
|
- }
|
|
|
- subMap.put(hisEntry.getKey(), idMap);
|
|
|
- }
|
|
|
- }
|
|
|
- retMap.put(entry.getKey(), subMap);
|
|
|
- }
|
|
|
- }
|
|
|
- return retMap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取映射关系-公表名
|
|
|
- *
|
|
|
- * @param hospitalId
|
|
|
- * @param hisNames
|
|
|
- * @param uniqueNames
|
|
|
- * @return Map<uniqueName,Map<hisName,Map<form,List<id>>>>
|
|
|
- */
|
|
|
- public Map<String, Map<String,Map<String, List<Long>>>> getUniqueConfigMap(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
- Map<String, Map<String, Map<String, List<Long>>>> retMap = new HashMap<>();
|
|
|
- QueryWrapper<DrugConfig> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("hospital_id", hospitalId);
|
|
|
- if (ListUtil.isNotEmpty(hisNames)) {
|
|
|
- queryWrapper.in("his_name", hisNames);
|
|
|
- }
|
|
|
- if (ListUtil.isNotEmpty(uniqueNames)) {
|
|
|
- queryWrapper.in("unique_name", uniqueNames);
|
|
|
- }
|
|
|
- List<DrugConfig> records = drugConfigService.list(queryWrapper);
|
|
|
- if (ListUtil.isEmpty(records)) {
|
|
|
- return retMap;
|
|
|
- }
|
|
|
-
|
|
|
- records.forEach(record -> {
|
|
|
- if (StringUtil.isBlank(record.getForm())) {
|
|
|
- record.setForm("");
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- Map<String, List<DrugConfig>> uniqueNameMap = EntityUtil.makeEntityListMap(records, "uniqueName");
|
|
|
- for (Map.Entry<String, List<DrugConfig>> entry : uniqueNameMap.entrySet()) {
|
|
|
- if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
- Map<String, Map<String, List<Long>>> subMap = new HashMap<>();
|
|
|
- Map<String, List<DrugConfig>> hisNameMap
|
|
|
- = EntityUtil.makeEntityListMap(entry.getValue(), "hisName");
|
|
|
- for (Map.Entry<String, List<DrugConfig>> hisEntry : hisNameMap.entrySet()) {
|
|
|
- if (ListUtil.isNotEmpty(hisEntry.getValue())) {
|
|
|
- Map<String, List<DrugConfig>> thirdMap = EntityUtil.makeEntityListMap(hisEntry.getValue(), "form");
|
|
|
- Map<String, List<Long>> idMap = new HashMap<>();
|
|
|
- for (Map.Entry<String, List<DrugConfig>> thirdEntry : thirdMap.entrySet()) {
|
|
|
- idMap.put(thirdEntry.getKey(), thirdEntry.getValue().stream().map(i -> i.getId()).distinct().collect(Collectors.toList()));
|
|
|
- }
|
|
|
- subMap.put(hisEntry.getKey(), idMap);
|
|
|
- }
|
|
|
- }
|
|
|
- retMap.put(entry.getKey(), subMap);
|
|
|
- }
|
|
|
- }
|
|
|
- return retMap;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取映射关系-公表名
|
|
|
- *
|
|
|
- * @param hospitalId
|
|
|
- * @param hisNames
|
|
|
- * @param uniqueNames
|
|
|
- * @return Map<hisName,Map<uniqueName,id>>
|
|
|
- */
|
|
|
- public Map<String, Map<String,Long>> getConfigMapWithoutForm(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
- Map<String, Map<String, Long>> retMap = new HashMap<>();
|
|
|
- QueryWrapper<DrugConfig> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("hospital_id", hospitalId);
|
|
|
- if (ListUtil.isNotEmpty(hisNames)) {
|
|
|
- queryWrapper.in("his_name", hisNames);
|
|
|
- }
|
|
|
- if (ListUtil.isNotEmpty(uniqueNames)) {
|
|
|
- queryWrapper.in("unique_name", uniqueNames);
|
|
|
- }
|
|
|
- List<DrugConfig> records = drugConfigService.list(queryWrapper);
|
|
|
- if (ListUtil.isEmpty(records)) {
|
|
|
- return retMap;
|
|
|
- }
|
|
|
- Map<String, List<DrugConfig>> hisNameMap
|
|
|
- = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
- for (Map.Entry<String, List<DrugConfig>> entry : hisNameMap.entrySet()) {
|
|
|
- if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
- retMap.put(entry.getKey(),
|
|
|
- EntityUtil.makeMapWithKeyValue(entry.getValue(), "uniqueName", "id"));
|
|
|
- }
|
|
|
- }
|
|
|
- return retMap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取映射关系
|
|
|
- * Map<uniqueName,Map<hisName,id>>
|
|
|
- *
|
|
|
- * @param hospitalId
|
|
|
- * @param hisNames
|
|
|
- * @param uniqueNames
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Map<String,Map<String,Long>> getUniqueNameConfigMapWithoutForm(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
- Map<String, Map<String, Long>> retMap = new HashMap<>();
|
|
|
- QueryWrapper<DrugConfig> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("hospital_id", hospitalId);
|
|
|
- if (ListUtil.isNotEmpty(hisNames)) {
|
|
|
- queryWrapper.in("his_name", hisNames);
|
|
|
- }
|
|
|
- if (ListUtil.isNotEmpty(uniqueNames)) {
|
|
|
- queryWrapper.in("unique_name", uniqueNames);
|
|
|
- }
|
|
|
- List<DrugConfig> records = drugConfigService.list(queryWrapper);
|
|
|
- if (ListUtil.isEmpty(records)) {
|
|
|
- return retMap;
|
|
|
- }
|
|
|
- records.forEach(i -> {
|
|
|
- if (StringUtil.isBlank(i.getForm())) {
|
|
|
- i.setForm("");
|
|
|
- }
|
|
|
- });
|
|
|
- Map<String, List<DrugConfig>> uniqueNameMap
|
|
|
- = EntityUtil.makeEntityListMap(records, "uniqueName");
|
|
|
- for (Map.Entry<String, List<DrugConfig>> entry : uniqueNameMap.entrySet()) {
|
|
|
- if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
- retMap.put(entry.getKey(),
|
|
|
- EntityUtil.makeMapWithKeyValue(entry.getValue(), "hisName", "id"));
|
|
|
- }
|
|
|
- }
|
|
|
- return retMap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 数据导出
|
|
|
- *
|
|
|
- * @param response
|
|
|
- * @param hospitalIdVO
|
|
|
- */
|
|
|
- public void exportExcel(HttpServletResponse response, HospitalIdVO hospitalIdVO) {
|
|
|
- QueryWrapper<DrugConfig> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("hospital_id", hospitalIdVO.getHospitalId())
|
|
|
- .orderByDesc("gmt_modified");
|
|
|
- List<DrugConfig> records = drugConfigService.list(queryWrapper);
|
|
|
- String fileName = "药品映射.xls";
|
|
|
- ExcelUtils.exportExcel(records, getFrom(), "sheet1", DrugConfig.class, fileName, response, 12.8f);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 各医院映射关系数列表
|
|
|
- *
|
|
|
- * @param hosRelationNumPageVO
|
|
|
- * @return
|
|
|
- */
|
|
|
- public IPage<HosRelationNumDTO> getRelationNumPage(HosRelationNumPageVO hosRelationNumPageVO) {
|
|
|
- return drugConfigService.getRelationNumPage(hosRelationNumPageVO);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 数据导入模板导出
|
|
|
- *
|
|
|
- * @param response
|
|
|
- */
|
|
|
- public void exportExcelModule(HttpServletResponse response) {
|
|
|
- String fileName = "药品映射模板.xls";
|
|
|
- ExcelUtils.exportExcel(new ArrayList<>(), getFrom(), "sheet1", DrugConfig.class, fileName, response, 12.8f);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 剂型说明
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- private String getFrom() {
|
|
|
- String from = "药品模板——药品剂型填写说明[不填";
|
|
|
- //药品剂型
|
|
|
- List<DictionaryInfoDTO> dicTypeMappingList = dictionaryFacade.getListByGroupType(9);
|
|
|
- List<String> formList = dicTypeMappingList.stream()
|
|
|
- .filter(i -> StringUtil.isNotBlank(i.getName()))
|
|
|
- .map(i -> i.getName())
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (ListUtil.isNotEmpty(formList)) {
|
|
|
- for (String s : formList) {
|
|
|
- if (StringUtil.isNotBlank(s)) {
|
|
|
- from += "、" + s;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- from += "]";
|
|
|
- return from;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 导入数据预匹配
|
|
|
- * @param file
|
|
|
- * @param response
|
|
|
- */
|
|
|
- public void precDataMatch(MultipartFile file,HttpServletResponse response) {
|
|
|
- List<DrugConfig> originList = ExcelUtils.importExcel(file, 1, 1, DrugConfig.class);
|
|
|
- List<DrugConfig> retList = dataProcess(originList);
|
|
|
-
|
|
|
- String fileName = "药品关联数据(预匹配).xls";
|
|
|
- ExcelUtils.exportExcel(retList, getFrom(), "sheet1", DrugConfig.class, fileName, response, 12.8f);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 导入数据验证
|
|
|
- *
|
|
|
- * @param file
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Boolean dataVerify(MultipartFile file) {
|
|
|
- List<DrugConfig> originList = ExcelUtils.importExcel(file, 1, 1, DrugConfig.class);
|
|
|
- List<DrugConfig> retList = dataProcess(originList);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 数据处理
|
|
|
- *
|
|
|
- * @param originList
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<DrugConfig> dataProcess(List<DrugConfig> originList) {
|
|
|
- List<DrugConfig> retList = Lists.newLinkedList();
|
|
|
- List<String> hisNameList = originList.stream().map(i -> i.getHisName()).distinct().collect(Collectors.toList());
|
|
|
- Map<String, List<DrugConfig>> allMap = getAll(hisNameList);
|
|
|
-
|
|
|
- //药品剂型
|
|
|
- List<DictionaryInfoDTO> dicTypeMappingList = dictionaryFacade.getListByGroupType(9);
|
|
|
- List<String> formList = dicTypeMappingList.stream()
|
|
|
- .filter(i -> StringUtil.isNotBlank(i.getName()))
|
|
|
- .map(i -> i.getName())
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- //去除空格
|
|
|
- originList.forEach(item -> {
|
|
|
- item.setHisName(item.getHisName().trim());
|
|
|
- });
|
|
|
-
|
|
|
- //获取标准术语
|
|
|
- List<String> precUniqueName = Lists.newArrayList();
|
|
|
- if (allMap != null) {
|
|
|
- for (Map.Entry<String, List<DrugConfig>> entry : allMap.entrySet()) {
|
|
|
- if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
- precUniqueName.addAll(entry.getValue().stream().map(i -> i.getUniqueName()).collect(Collectors.toList()));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- precUniqueName = precUniqueName.stream().distinct().collect(Collectors.toList());
|
|
|
-
|
|
|
- /*ConceptVO conceptVO = new ConceptVO();
|
|
|
- conceptVO.setNames(precUniqueName);
|
|
|
- conceptVO.setType(ConceptTypeEnum.Drug.getKey());
|
|
|
- RespDTO<List<String>> respDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
- RespDTOUtil.respNGDealCover(respDTO, "标准术语校验失败");
|
|
|
- List<String> uniqueNames = respDTO.data;
|
|
|
- if (ListUtil.isNotEmpty(originList)) {
|
|
|
- for (DrugConfig originItem : originList) {
|
|
|
- if (allMap.containsKey(originItem.getHisName())) {
|
|
|
- List<DrugConfig> items = allMap.get(originItem.getHisName());
|
|
|
- boolean flag = false;
|
|
|
- for (DrugConfig item : items) {
|
|
|
- if (uniqueNames.contains(item.getUniqueName())) {
|
|
|
- if (!formList.contains(item.getForm())) {
|
|
|
- item.setForm("");
|
|
|
- }
|
|
|
- retList.add(item);
|
|
|
- flag = true;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!flag) {
|
|
|
- if (!formList.contains(originItem.getForm())) {
|
|
|
- originItem.setForm("");
|
|
|
- }
|
|
|
- retList.add(originItem);
|
|
|
- }
|
|
|
- } else {
|
|
|
- retList.add(originItem);
|
|
|
- }
|
|
|
- }
|
|
|
- }*/
|
|
|
-
|
|
|
- retList = retList.stream()
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- return retList;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取所有医院映射数据
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Map<String,List<DrugConfig>> getAll(List<String> hisNameList) {
|
|
|
- Map<String, List<DrugConfig>> retMap = new HashMap<>();
|
|
|
- QueryWrapper<DrugConfig> queryWrapper = new QueryWrapper<>();
|
|
|
- if (ListUtil.isNotEmpty(hisNameList)) {
|
|
|
- queryWrapper.in("his_name", hisNameList);
|
|
|
- }
|
|
|
- List<DrugConfig> records = drugConfigService.list(queryWrapper);
|
|
|
- if (ListUtil.isEmpty(records)) {
|
|
|
- return retMap;
|
|
|
- }
|
|
|
- records.forEach(record -> {
|
|
|
- record.setHospitalId(null);
|
|
|
- record.setId(null);
|
|
|
- record.setUniqueCode(StringUtils.isBlank(record.getUniqueCode()) ? "" : record.getUniqueCode());
|
|
|
- record.setForm(StringUtils.isBlank(record.getForm()) ? null : record.getForm());
|
|
|
- });
|
|
|
-
|
|
|
- records = records
|
|
|
- .stream()
|
|
|
- .filter(record -> record.getIsDeleted().equals(IsDeleteEnum.N.getKey()))
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (ListUtil.isEmpty(records)) {
|
|
|
- return retMap;
|
|
|
- }
|
|
|
-
|
|
|
- retMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
-
|
|
|
- return retMap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查找指定医院映射关系
|
|
|
- *
|
|
|
- * @param hospitalId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<DrugConfig> getListByHospitalId(Long hospitalId) {
|
|
|
- QueryWrapper<DrugConfig> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("hospital_id", hospitalId);
|
|
|
- return drugConfigService.list(queryWrapper);
|
|
|
- }
|
|
|
-}
|