| | |
| | | package com.smartor.service.impl; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.smartor.domain.BaseTag; |
| | | import com.smartor.domain.PatArchivetag; |
| | | import com.smartor.domain.PatUpInfoVO; |
| | | import com.smartor.mapper.BaseTagMapper; |
| | | import com.smartor.mapper.PatArchivetagMapper; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.smartor.mapper.PatArchiveMapper; |
| | | import com.smartor.domain.PatArchive; |
| | | import com.smartor.service.IPatArchiveService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * 患者档案Service业务层处理 |
| | | * |
| | | * |
| | | * @author smartor |
| | | * @date 2023-03-04 |
| | | */ |
| | | @Service |
| | | public class PatArchiveServiceImpl implements IPatArchiveService |
| | | { |
| | | public class PatArchiveServiceImpl implements IPatArchiveService { |
| | | @Autowired |
| | | private PatArchiveMapper patArchiveMapper; |
| | | |
| | | @Autowired |
| | | private BaseTagMapper baseTagMapper; |
| | | |
| | | @Autowired |
| | | private PatArchivetagMapper patArchivetagMapper; |
| | | |
| | | |
| | | /** |
| | | * 查询患者档案 |
| | | * |
| | | * |
| | | * @param patid 患者档案主键 |
| | | * @return 患者档案 |
| | | */ |
| | | @Override |
| | | public PatArchive selectPatArchiveByPatid(Long patid) |
| | | { |
| | | public PatArchive selectPatArchiveByPatid(Long patid) { |
| | | return patArchiveMapper.selectPatArchiveByPatid(patid); |
| | | } |
| | | |
| | | /** |
| | | * 查询患者档案列表 |
| | | * |
| | | * |
| | | * @param patArchive 患者档案 |
| | | * @return 患者档案 |
| | | */ |
| | | @Override |
| | | public List<PatArchive> selectPatArchiveList(PatArchive patArchive) |
| | | { |
| | | public List<PatArchive> selectPatArchiveList(PatArchive patArchive) { |
| | | return patArchiveMapper.selectPatArchiveList(patArchive); |
| | | } |
| | | |
| | | /** |
| | | * 新增患者档案 |
| | | * |
| | | * |
| | | * @param patArchive 患者档案 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertPatArchive(PatArchive patArchive) |
| | | { |
| | | public int insertPatArchive(PatArchive patArchive) { |
| | | patArchive.setCreateTime(DateUtils.getNowDate()); |
| | | return patArchiveMapper.insertPatArchive(patArchive); |
| | | } |
| | | |
| | | /** |
| | | * 修改患者档案 |
| | | * |
| | | * |
| | | * @param patArchive 患者档案 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updatePatArchive(PatArchive patArchive) |
| | | { |
| | | public int updatePatArchive(PatArchive patArchive) { |
| | | patArchive.setUpdateTime(DateUtils.getNowDate()); |
| | | return patArchiveMapper.updatePatArchive(patArchive); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除患者档案 |
| | | * |
| | | * |
| | | * @param patids 需要删除的患者档案主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deletePatArchiveByPatids(Long[] patids) |
| | | { |
| | | public int deletePatArchiveByPatids(Long[] patids) { |
| | | return patArchiveMapper.deletePatArchiveByPatids(patids); |
| | | } |
| | | |
| | | /** |
| | | * 删除患者档案信息 |
| | | * |
| | | * |
| | | * @param patid 患者档案主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deletePatArchiveByPatid(Long patid) |
| | | { |
| | | public int deletePatArchiveByPatid(Long patid) { |
| | | return patArchiveMapper.deletePatArchiveByPatid(patid); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public PatUpInfoVO fileHandle(String username, MultipartFile file) { |
| | | PatUpInfoVO patUpInfoVO = new PatUpInfoVO(); |
| | | Integer successNum = 0; |
| | | Integer failNum = 0; |
| | | |
| | | List<PatArchive> errorpatArchiveList = new ArrayList<>(); |
| | | try { |
| | | Workbook workbook = new XSSFWorkbook(file.getInputStream()); |
| | | Sheet sheet = workbook.getSheetAt(0); |
| | | |
| | | for (int i = sheet.getFirstRowNum() + 1; i < sheet.getLastRowNum(); i++) { |
| | | Row row = sheet.getRow(i); |
| | | //如果行为空,进行下一次循环 |
| | | if (ObjectUtils.isEmpty(row)) { |
| | | continue; |
| | | } |
| | | PatArchive patArchive = new PatArchive(); |
| | | if (ObjectUtils.isEmpty(row.getCell(3))) { |
| | | patArchive.setRemark("身份证号为空"); |
| | | } else { |
| | | patArchive.setIccardno(row.getCell(3).toString()); |
| | | //根据身份证,先去患者管理表里看看有没有这个人,如果有这个人,也不需要插入患者表 |
| | | List<PatArchive> patArchiveList1 = patArchiveMapper.selectPatArchiveList(patArchive); |
| | | if (patArchiveList1.size() > 0) { |
| | | patArchive.setRemark("该患者已存在"); |
| | | } |
| | | } |
| | | |
| | | //判断姓名是否为空 |
| | | if (ObjectUtils.isEmpty(row.getCell(0))) { |
| | | patArchive.setRemark(patArchive.getRemark() + "," + "姓名为空"); |
| | | errorpatArchiveList.add(patArchive); |
| | | } else { |
| | | patArchive.setName(row.getCell(0).toString()); |
| | | } |
| | | |
| | | //判断性别是否为空 |
| | | |
| | | if (ObjectUtils.isEmpty(row.getCell(1))) { |
| | | patArchive.setRemark(patArchive.getRemark() + "," + "性别为空"); |
| | | } else { |
| | | patArchive.setSex(row.getCell(1).toString().equals("男") ? 1L : 2L); |
| | | } |
| | | |
| | | //判断证件类型是否为空 |
| | | if (ObjectUtils.isEmpty(row.getCell(2))) { |
| | | patArchive.setRemark("证件类型为空"); |
| | | } else { |
| | | patArchive.setIccardtype(row.getCell(2).toString()); |
| | | } |
| | | |
| | | //判断出生日期是否为空 |
| | | if (ObjectUtils.isEmpty(row.getCell(4))) { |
| | | patArchive.setRemark("出生日期为空"); |
| | | } else { |
| | | //格式转换,转成日期 |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); |
| | | Date javaDate = new Date(); |
| | | if (row.getCell(4).getCellType().toString().equals("NUMERIC")) { |
| | | javaDate = HSSFDateUtil.getJavaDate(row.getCell(4).getNumericCellValue()); |
| | | } else { |
| | | javaDate = new Date(row.getCell(4).toString()); |
| | | } |
| | | dateFormat.format(javaDate); |
| | | patArchive.setBirthdate(javaDate); |
| | | } |
| | | |
| | | //判断本人联系是否为空,和长度是否正确 |
| | | if (ObjectUtils.isEmpty(row.getCell(5))) { |
| | | patArchive.setRemark("本人联系电话为空"); |
| | | } else { |
| | | //格式转换,转成文本 |
| | | if (row.getCell(5).getCellType().toString().equals("NUMERIC")) { |
| | | String cellData = String.valueOf((long) row.getCell(5).getNumericCellValue()); |
| | | patArchive.setTelcode(cellData); |
| | | } else { |
| | | DataFormatter dataFormatter = new DataFormatter(); |
| | | String cellValue = dataFormatter.formatCellValue(row.getCell(5)); |
| | | patArchive.setTelcode(cellValue); |
| | | } |
| | | } |
| | | |
| | | //判断亲属联系方式是否为空,长度是否正确 |
| | | if (ObjectUtils.isEmpty(row.getCell(6))) { |
| | | patArchive.setRemark("本人联系电话为空"); |
| | | } else { |
| | | //格式转换,转成文本 |
| | | if (row.getCell(6).getCellType().toString().equals("NUMERIC")) { |
| | | String cellData = String.valueOf((long) row.getCell(6).getNumericCellValue()); |
| | | patArchive.setRelativetelcode(cellData); |
| | | } else { |
| | | DataFormatter dataFormatter = new DataFormatter(); |
| | | String cellValue = dataFormatter.formatCellValue(row.getCell(6)); |
| | | patArchive.setRelativetelcode(cellValue); |
| | | } |
| | | } |
| | | |
| | | //患都标签是否为空 |
| | | if (ObjectUtils.isEmpty(row.getCell(7))) { |
| | | patArchive.setRemark("患者标签为空"); |
| | | } |
| | | |
| | | //判断备注是否为空 |
| | | if (!StringUtils.isEmpty(patArchive.getRemark())) { |
| | | //如果备注字段不为空,说有该患者填写有问题 |
| | | errorpatArchiveList.add(patArchive); |
| | | failNum = failNum + 1; |
| | | continue; |
| | | } |
| | | |
| | | //往患者表里新增,并获取到新增ID |
| | | patArchiveMapper.insertPatArchive(patArchive); |
| | | |
| | | //根据标签名查询出标签信息 |
| | | BaseTag baseTag = new BaseTag(); |
| | | baseTag.setTagname(row.getCell(7).toString()); |
| | | List<BaseTag> baseTags = baseTagMapper.selectBaseTagList(baseTag); |
| | | BaseTag baseTag1 = baseTags.get(0); |
| | | |
| | | // 新增患者档案标签 |
| | | PatArchivetag patArchivetag = DtoConversionUtils.sourceToTarget(baseTag1, PatArchivetag.class); |
| | | patArchivetag.setUpdateBy(username); |
| | | patArchivetag.setCreateTime(new Date()); |
| | | patArchivetag.setPatid(patArchive.getPatid()); |
| | | patArchivetagMapper.insertPatArchivetag(patArchivetag); |
| | | successNum = successNum + 1; |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | patUpInfoVO.setFailNum(failNum); |
| | | patUpInfoVO.setSuccessNum(successNum); |
| | | patUpInfoVO.setPatArchiveList(errorpatArchiveList); |
| | | return patUpInfoVO; |
| | | } |
| | | |
| | | } |
| | | |