package com.smartor.service.impl;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.common.core.redis.RedisCache;
|
import com.ruoyi.common.exception.base.BaseException;
|
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DtoConversionUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.smartor.domain.*;
|
import com.smartor.mapper.BaseTagMapper;
|
import com.smartor.mapper.PatArchiveMapper;
|
import com.smartor.mapper.PatArchivetagMapper;
|
import com.smartor.mapper.ServiceSubtaskMapper;
|
import com.smartor.service.IPatArchiveService;
|
import com.smartor.service.IPatMedInhospService;
|
import com.smartor.service.IPatMedOuthospService;
|
import com.smartor.service.IPatMedPhysicalService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
import org.apache.poi.ss.usermodel.DataFormatter;
|
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import java.io.FileOutputStream;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.Executors;
|
import java.util.stream.Collectors;
|
|
/**
|
* 患者档案Service业务层处理
|
*
|
* @author smartor
|
* @date 2023-03-04
|
*/
|
@Slf4j
|
@Service
|
public class PatArchiveServiceImpl implements IPatArchiveService {
|
@Autowired
|
private PatArchiveMapper patArchiveMapper;
|
|
@Autowired
|
private ServiceSubtaskMapper serviceSubtaskMapper;
|
|
@Autowired
|
private BaseTagMapper baseTagMapper;
|
|
@Autowired
|
private PatArchivetagMapper patArchivetagMapper;
|
|
@Autowired
|
private IPatMedInhospService patMedInhospService;
|
|
@Autowired
|
private IPatMedOuthospService patMedOuthospService;
|
|
@Autowired
|
private IPatMedPhysicalService patMedPhysicalService;
|
|
@Autowired
|
private RedisCache redisCache;
|
|
|
/**
|
* 查询患者档案
|
*
|
* @param patid 患者档案主键
|
* @return 患者档案
|
*/
|
@Override
|
public PatArchive selectPatArchiveByPatid(Long patid) {
|
return patArchiveMapper.selectPatArchiveByPatid(patid);
|
}
|
|
/**
|
* 查询患者档案列表
|
*
|
* @param patArchive 患者档案
|
* @return 患者档案
|
*/
|
@Override
|
public List<PatArchive> selectPatArchiveList(PatArchive patArchive) {
|
return patArchiveMapper.selectPatArchiveList(patArchive);
|
}
|
|
|
/**
|
* 新增患者档案
|
*
|
* @param patArchive 患者档案
|
* @return 结果
|
*/
|
@Transactional(rollbackFor = Exception.class)
|
@Override
|
public Integer insertPatArchive(PatArchive patArchive) {
|
patArchive.setCreateTime(DateUtils.getNowDate());
|
patArchiveMapper.insertPatArchiveSingle(patArchive);
|
return patArchive.getId().intValue();
|
}
|
|
@Transactional(rollbackFor = Exception.class)
|
@Override
|
public Boolean update(PatArchive patArchive) {
|
int i = patArchiveMapper.updatePatArchive(patArchive);
|
if (i != 1) {
|
return false;
|
} else {
|
ServiceSubtask serviceSubtask = new ServiceSubtask();
|
serviceSubtask.setPatid(patArchive.getId());
|
serviceSubtask.setSendname(patArchive.getName());
|
serviceSubtask.setPhone(patArchive.getTelcode());
|
serviceSubtask.setSex(patArchive.getSex());
|
serviceSubtask.setAge(patArchive.getAge());
|
serviceSubtask.setSfzh(patArchive.getIdcardno());
|
serviceSubtask.setAddr(patArchive.getPlaceOfResidence());
|
serviceSubtaskMapper.updateServiceSubtaskByPatId(serviceSubtask);
|
}
|
return true;
|
}
|
|
/**
|
* 新增或修改患者档信息
|
*
|
* @param patArchiveVO 新增或修改患者档信息
|
* @return 结果
|
*/
|
@Transactional(rollbackFor = Exception.class)
|
@Override
|
public Boolean saveOrUpdatePatInfo(PatArchiveVO patArchiveVO) {
|
//通过isoperation来判断是否新增
|
PatArchive patArchive = DtoConversionUtils.sourceToTarget(patArchiveVO, PatArchive.class);
|
if (patArchiveVO.getIsoperation() != null && patArchiveVO.getIsoperation() == 1 || patArchiveVO.getId() == null) {
|
//新增
|
List<PatArchive> patArchives = new ArrayList<>();
|
patArchive.setUpdateTime(DateUtils.getNowDate());
|
patArchives.add(patArchive);
|
patArchiveMapper.insertPatArchive(patArchives);
|
} else if (patArchiveVO.getIsoperation() != null && patArchiveVO.getIsoperation() == 2 || patArchiveVO.getId() != null) {
|
//修改
|
patArchiveVO.setIsoperation(2);
|
patArchiveMapper.updatePatArchive(patArchive);
|
if (StringUtils.isNotEmpty(patArchive.getNotrequiredFlag()) && patArchive.getNotrequiredFlag().equals("1")) {
|
//不需要服务了,需要通过patid和sendstate=2或者sendstate=1去查询一下,service_subtask里是否有正在执行的任务,有的话,立即停了
|
ServiceSubtaskVO serviceSubtaskVO = new ServiceSubtaskVO();
|
serviceSubtaskVO.setPatid(patArchive.getId());
|
serviceSubtaskVO.setSendstate(2L);
|
List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
|
serviceSubtaskVO.setSendstate(1L);
|
List<ServiceSubtask> serviceSubtaskList1 = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
|
if (CollectionUtils.isNotEmpty(serviceSubtaskList)) {
|
if (CollectionUtils.isNotEmpty(serviceSubtaskList1)) serviceSubtaskList.addAll(serviceSubtaskList1);
|
} else {
|
if (CollectionUtils.isNotEmpty(serviceSubtaskList1)) serviceSubtaskList = serviceSubtaskList1;
|
}
|
//去redis中,查询是否有subid,有的话移除cache-exist
|
if (CollectionUtils.isNotEmpty(serviceSubtaskList)) {
|
for (ServiceSubtask serviceSubtask : serviceSubtaskList) {
|
log.error("需要移除的subId为:{}", serviceSubtask.getId().toString());
|
serviceSubtaskMapper.deleteServiceSubtaskById(serviceSubtask.getId());
|
redisCache.removeElementFromList("cache-exist", serviceSubtask.getId().toString());
|
redisCache.removeElementFromList("cache-0", serviceSubtask.getId().toString());
|
redisCache.removeElementFromList("cache-1", serviceSubtask.getId().toString());
|
redisCache.removeElementFromList("cache-2", serviceSubtask.getId().toString());
|
redisCache.removeElementFromList("cache-3", serviceSubtask.getId().toString());
|
redisCache.removeElementFromList("cache-4", serviceSubtask.getId().toString());
|
}
|
}
|
}
|
}
|
|
if (CollectionUtils.isNotEmpty(patArchiveVO.getTagList())) {
|
//处理标签(新增、删除)
|
for (PatArchivetag patArchivetag : patArchiveVO.getTagList()) {
|
patArchivetag.setGuid(patArchiveVO.getGuid());
|
patArchivetag.setOrgid(patArchiveVO.getOrgid());
|
if (patArchivetag.getIsoperation() != null && patArchivetag.getIsoperation() == 1 || patArchivetag.getIsoperation() == null && patArchiveVO.getIsoperation() == 1) {
|
//判断一下base_tag里是不是存在,如果不存在,先新增
|
BaseTag baseTag = new BaseTag();
|
baseTag.setTagname(patArchivetag.getTagname().trim());
|
List<BaseTag> baseTags = baseTagMapper.selectBaseTagListByTagname(baseTag);
|
if (CollectionUtils.isEmpty(baseTags)) {
|
//先给放到未分类中
|
baseTag.setTagcategoryid(6L);
|
baseTag.setOrgid(patArchiveVO.getOrgid());
|
baseTag.setDelFlag("0");
|
baseTag.setUpdateTime(new Date());
|
baseTag.setCreateTime(new Date());
|
baseTagMapper.insertBaseTag(baseTag);
|
patArchivetag.setTagid(baseTag.getTagid());
|
} else {
|
patArchivetag.setTagid(baseTags.get(0).getTagid());
|
}
|
//新增
|
patArchivetag.setUpdateBy(null);
|
patArchivetag.setCreateTime(new Date());
|
patArchivetag.setPatid(patArchive.getId());
|
patArchivetagMapper.insertPatArchivetag(patArchivetag);
|
} else if (patArchivetag.getIsoperation() != null && patArchivetag.getIsoperation() == 3 || patArchivetag.getIsoperation() == null && patArchiveVO.getIsoperation() == 3) {
|
patArchivetag.setDelFlag("1");
|
//删除
|
log.info("标签的id为:{}", patArchivetag.getTagid());
|
patArchivetagMapper.deletePatArchivetagById(patArchivetag);
|
}
|
}
|
|
}
|
return true;
|
}
|
|
/**
|
* 批量删除患者档案
|
*
|
* @param patids 需要删除的患者档案主键
|
* @return 结果
|
*/
|
@Override
|
public int deletePatArchiveByPatids(Long[] patids) {
|
return patArchiveMapper.deletePatArchiveByPatids(patids);
|
}
|
|
/**
|
* 删除患者档案信息
|
*
|
* @param patid 患者档案主键
|
* @return 结果
|
*/
|
@Override
|
public int deletePatArchiveByPatid(Long patid) {
|
return patArchiveMapper.deletePatArchiveByPatid(patid);
|
}
|
|
/**
|
* 获取患者信息
|
*
|
* @param patArchiveReq
|
* @return
|
*/
|
@Override
|
public List<PatArchiveOthreInfo> getPatientInfo(PatArchiveReq patArchiveReq) {
|
if (CollectionUtils.isEmpty(patArchiveReq.getLeavehospitaldistrictcodes()) || patArchiveReq.getLeavehospitaldistrictcodes().size() == 0) {
|
patArchiveReq.setLeavehospitaldistrictcodes(null);
|
}
|
if (CollectionUtils.isEmpty(patArchiveReq.getLeaveldeptcodes()) || patArchiveReq.getLeaveldeptcodes().size() == 0) {
|
patArchiveReq.setLeaveldeptcodes(null);
|
}
|
|
List<PatArchiveOthreInfo> patArchiveList = new ArrayList<>();
|
if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 1) {
|
// 查看住院 1 查看门诊 2 查看体检 3
|
List<PatArchiveOthreInfo> patArchives1 = patArchiveMapper.selectPatArchiveInfoByInhosp(patArchiveReq);
|
if (CollectionUtils.isNotEmpty(patArchives1)) {
|
patArchiveList.addAll(patArchives1);
|
}
|
} else if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 2) {
|
// 查看住院 1 查看门诊 2 查看体检 3
|
List<PatArchiveOthreInfo> patArchives2 = patArchiveMapper.selectPatArchiveInfoByOuthosp(patArchiveReq);
|
if (CollectionUtils.isNotEmpty(patArchives2)) {
|
patArchiveList.addAll(patArchives2);
|
}
|
} else if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 3) {
|
// 查看住院 1 查看门诊 2 查看体检 3
|
List<PatArchiveOthreInfo> patArchives3 = patArchiveMapper.selectPatArchiveInfoByPhysical(patArchiveReq);
|
if (CollectionUtils.isNotEmpty(patArchives3)) {
|
patArchiveList.addAll(patArchives3);
|
}
|
}
|
|
return patArchiveList;
|
}
|
|
|
@Override
|
@Transactional
|
public PatUpInfoVO importFilehandle(SysUser user, String tags, MultipartFile file) {
|
System.out.println("start : " + System.currentTimeMillis() / 1000);
|
PatUpInfoVO patUpInfoVO = new PatUpInfoVO();
|
//需要处理的总行数
|
int lastRowNum = 0;
|
|
final List<PatArchive> errorpatArchiveList = new ArrayList<>();
|
//创建线程池
|
ExecutorService pool = Executors.newFixedThreadPool(10);
|
try {
|
Workbook workbook = new XSSFWorkbook(file.getInputStream());
|
Sheet sheet = workbook.getSheetAt(0);
|
|
//获取文件里的总行数
|
lastRowNum = sheet.getLastRowNum();
|
//将文件里的数据分成10份
|
int partsize = lastRowNum / 10;
|
for (int i = 0; i < 10; i++) {
|
int start = i * partsize + 1;
|
int end = (i + 1) * partsize;
|
|
pool.execute(new Runnable() {
|
@Override
|
public void run() {
|
for (int j = start; j <= end; j++) {
|
List<PatArchive> patArchives = new ArrayList<>();
|
String name = Thread.currentThread().getName();
|
Row row = sheet.getRow(j);
|
//如果行为空,进行下一次循环
|
if (ObjectUtils.isEmpty(row)) {
|
continue;
|
}
|
PatArchive patArchive = new PatArchive();
|
if (ObjectUtils.isEmpty(row.getCell(6)) || StringUtils.isEmpty(row.getCell(6).toString())) {
|
addRemark("证件号码为空", patArchive);
|
} else {
|
patArchive.setIdcardno(row.getCell(6).toString());
|
//根据身份证,先去患者管理表里看看有没有这个人,如果有这个人,也不需要插入患者表
|
// (这一块查询会影响整体的速度,需要优化)
|
List<PatArchive> patArchiveList1 = patArchiveMapper.selectPatArchiveList(patArchive);
|
if (patArchiveList1.size() > 0) {
|
patArchive.setRemark("该患者已存在");
|
}
|
}
|
|
//判断姓名是否为空
|
if (Objects.isNull(row.getCell(0)) || StringUtils.isEmpty(row.getCell(0).toString())) {
|
addRemark("姓名为空", patArchive);
|
} else {
|
patArchive.setName(row.getCell(0).toString());
|
}
|
|
//判断性别是否为空
|
if (ObjectUtils.isEmpty(row.getCell(1)) || StringUtils.isEmpty(row.getCell(1).toString())) {
|
addRemark("性别为空", patArchive);
|
} else {
|
patArchive.setSex(row.getCell(1).toString().equals("男") ? 1L : 2L);
|
}
|
|
//判断证件类型是否为空
|
if (ObjectUtils.isEmpty(row.getCell(2)) || StringUtils.isEmpty(row.getCell(2).toString())) {
|
addRemark("证件类型为空", patArchive);
|
} else {
|
patArchive.setIdcardtype(row.getCell(2).toString());
|
}
|
|
//判断籍贯是否为空
|
if (ObjectUtils.isEmpty(row.getCell(3)) || StringUtils.isEmpty(row.getCell(3).toString())) {
|
patArchive.setNativePlace(null);
|
} else {
|
patArchive.setNativePlace(row.getCell(3).toString());
|
}
|
|
//判断居住地是否为空
|
if (ObjectUtils.isEmpty(row.getCell(4)) || StringUtils.isEmpty(row.getCell(4).toString())) {
|
patArchive.setPlaceOfResidence(null);
|
} else {
|
patArchive.setPlaceOfResidence(row.getCell(4).toString());
|
}
|
|
//判断居住地是否为空
|
if (ObjectUtils.isEmpty(row.getCell(5)) || StringUtils.isEmpty(row.getCell(5).toString())) {
|
patArchive.setBirthplace(null);
|
} else {
|
patArchive.setBirthplace(row.getCell(5).toString());
|
}
|
|
//判断出生日期是否为空
|
if (ObjectUtils.isEmpty(row.getCell(7)) || StringUtils.isEmpty(row.getCell(7).toString())) {
|
// addRemark("出生日期为空", patArchive);
|
patArchive.setBirthdate(null);
|
} else {
|
//格式转换,转成日期
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
Date javaDate = new Date();
|
if (row.getCell(7).getCellType().toString().equals("NUMERIC")) {
|
javaDate = HSSFDateUtil.getJavaDate(row.getCell(7).getNumericCellValue());
|
} else {
|
try {
|
javaDate = dateFormat.parse(row.getCell(7).toString());
|
} catch (ParseException e) {
|
e.printStackTrace();
|
}
|
}
|
dateFormat.format(javaDate);
|
patArchive.setBirthdate(javaDate);
|
}
|
|
//判断年龄是否为空
|
if (ObjectUtils.isEmpty(row.getCell(8)) || StringUtils.isEmpty(row.getCell(8).toString())) {
|
patArchive.setAge(null);
|
} else {
|
patArchive.setAge(Long.valueOf(row.getCell(8).toString()));
|
}
|
|
//判断本人联系是否为空,和长度是否正确
|
if (ObjectUtils.isEmpty(row.getCell(12)) || StringUtils.isEmpty(row.getCell(12).toString())) {
|
addRemark("本人联系电话为空", patArchive);
|
} else {
|
//格式转换,转成文本
|
if (row.getCell(12).getCellType().toString().equals("NUMERIC")) {
|
String cellData = String.valueOf((long) row.getCell(12).getNumericCellValue());
|
patArchive.setTelcode(cellData);
|
} else {
|
DataFormatter dataFormatter = new DataFormatter();
|
String cellValue = dataFormatter.formatCellValue(row.getCell(12));
|
patArchive.setTelcode(cellValue);
|
}
|
}
|
|
//判断亲属联系方式是否为空,长度是否正确
|
if (ObjectUtils.isEmpty(row.getCell(13)) || StringUtils.isEmpty(row.getCell(13).toString())) {
|
// addRemark("亲属联系方式为空", patArchive);
|
patArchive.setRelativetelcode(null);
|
} else {
|
//格式转换,转成文本
|
if (row.getCell(13).getCellType().toString().equals("NUMERIC")) {
|
String cellData = String.valueOf((long) row.getCell(13).getNumericCellValue());
|
patArchive.setRelativetelcode(cellData);
|
} else {
|
DataFormatter dataFormatter = new DataFormatter();
|
String cellValue = dataFormatter.formatCellValue(row.getCell(13));
|
patArchive.setRelativetelcode(cellValue);
|
}
|
}
|
//判断民族是否为空
|
if (ObjectUtils.isEmpty(row.getCell(14)) || StringUtils.isEmpty(row.getCell(14).toString())) {
|
patArchive.setNation(null);
|
} else {
|
patArchive.setNation(row.getCell(14).toString());
|
}
|
|
//患都标签是否为空
|
if (ObjectUtils.isEmpty(row.getCell(17)) || StringUtils.isEmpty(row.getCell(17).toString())) {
|
patArchive.setTag(tags);
|
} else {
|
if (StringUtils.isNotEmpty(tags)) {
|
patArchive.setTag(row.getCell(17).toString() + "," + tags);
|
} else {
|
patArchive.setTag(row.getCell(17).toString());
|
}
|
}
|
|
//判断备注是否为空
|
if (!StringUtils.isEmpty(patArchive.getRemark())) {
|
//如果备注字段不为空,说有该患者填写有问题
|
errorpatArchiveList.add(patArchive);
|
continue;
|
}
|
|
patArchive.setUploadTime(new Date());
|
patArchive.setIsupload(0L);
|
//往患者表里新增,并获取到新增ID
|
patArchive.setOrgid(user.getOrgid());
|
patArchives.add(patArchive);
|
int i1 = patArchiveMapper.insertPatArchive(patArchives);
|
|
// // 根据标签名查询出标签信息
|
// String s = patArchive.getTag();
|
// String[] split = s.split(",");
|
// for (String tagName : split) {
|
// BaseTag baseTag = new BaseTag();
|
// baseTag.setTagname(tagName);
|
// List<BaseTag> baseTags = baseTagMapper.selectBaseTagList(baseTag);
|
//
|
// //如果该标签为空,现标签管理没有出现过的新标签时,自动将标签添加到"标签管理"未分类“中。编辑人为导入账号
|
// if (CollectionUtils.isEmpty(baseTags)) {
|
// baseTag = new BaseTag();
|
// baseTag.setTagcategoryid(1L);
|
// baseTag.setTagname(tagName);
|
// baseTag.setOrgid(user.getDeptId().toString());
|
// baseTag.setDelFlag("0");
|
// baseTag.setCreateBy(user.getUserName());
|
// baseTag.setCreateTime(new Date());
|
// baseTag.setCreateBy(user.getUserName());
|
// baseTag.setCreateTime(new Date());
|
// baseTagMapper.insertBaseTag(baseTag);
|
// } else {
|
// baseTag = baseTags.get(0);
|
// }
|
//
|
// // 新增患者档案标签
|
// PatArchivetag patArchivetag = DtoConversionUtils.sourceToTarget(baseTag, PatArchivetag.class);
|
// patArchivetag.setUpdateBy(user.getUserName());
|
// patArchivetag.setCreateTime(new Date());
|
// patArchivetag.setPatid(patArchive.getPatid());
|
// patArchivetagMapper.insertPatArchivetag(patArchivetag);
|
// }
|
|
patArchives.clear();
|
}
|
}
|
});
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
pool.shutdown();
|
Boolean aa = true;
|
d:
|
while (aa) {
|
boolean terminated = pool.isTerminated();
|
if (terminated) {
|
aa = false;
|
continue d;
|
}
|
}
|
|
if (errorpatArchiveList.size() != 0) {
|
patUpInfoVO.setSuccessNum(lastRowNum - errorpatArchiveList.size());
|
patUpInfoVO.setFailNum(errorpatArchiveList.size());
|
} else {
|
patUpInfoVO.setSuccessNum(lastRowNum == 0 ? 0 : lastRowNum);
|
patUpInfoVO.setFailNum(0);
|
}
|
patUpInfoVO.setPatArchiveList(errorpatArchiveList);
|
return patUpInfoVO;
|
}
|
|
@Override
|
public String exportErrPatInfo(List<PatArchive> patArchiveList) {
|
// 创建工作簿和工作表
|
Workbook workbook = new XSSFWorkbook();
|
Sheet sheet = workbook.createSheet("Sheet1");
|
// 创建行和单元格,并设置单元格的值
|
Row row = sheet.createRow(0);
|
getdata(row, null, true);
|
|
for (int i = 0; i < patArchiveList.size(); i++) {
|
row = sheet.createRow(i + 1);
|
getdata(row, patArchiveList.get(i), false);
|
}
|
// 保存工作簿到文件
|
FileOutputStream outputStream = null;
|
try {
|
outputStream = new FileOutputStream("患者错误信息.xlsx");
|
workbook.write(outputStream);
|
outputStream.close();
|
workbook.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
return "导出失败";
|
}
|
return "导出成功";
|
}
|
|
@Override
|
public List<PatArchive> patInfoByContion(PatArchiveReq patArchive) {
|
List<PatArchive> patArchives = new ArrayList<>();
|
|
//根据条件获取患者信息
|
// List<PatArchive> patArchiveList = patArchiveMapper.patInfoByContion(patArchive);
|
List<PatArchiveOthreInfo> patArchiveList = new ArrayList<>();
|
|
if (patArchive.getEndtime() != null) {
|
//出院时间只有住院才有
|
patArchive.setAllhosp(1L);
|
}
|
|
if (patArchive.getAllhosp() != null && patArchive.getAllhosp() == 0) {
|
List<PatArchiveOthreInfo> patArchives0 = patArchiveMapper.selectPatArchiveInfoByAllhosp(patArchive);
|
if (CollectionUtils.isNotEmpty(patArchives0)) {
|
patArchiveList.addAll(patArchives0);
|
}
|
} else if (patArchive.getAllhosp() != null && patArchive.getAllhosp() == 1) {
|
List<PatArchiveOthreInfo> patArchives1 = patArchiveMapper.selectPatArchiveInfoByInhosp(patArchive);
|
if (CollectionUtils.isNotEmpty(patArchives1)) {
|
patArchiveList.addAll(patArchives1);
|
}
|
} else if (patArchive.getAllhosp() != null && patArchive.getAllhosp() == 2) {
|
List<PatArchiveOthreInfo> patArchives2 = patArchiveMapper.selectPatArchiveInfoByOuthosp(patArchive);
|
if (CollectionUtils.isNotEmpty(patArchives2)) {
|
patArchiveList.addAll(patArchives2);
|
}
|
} else if (patArchive.getAllhosp() != null && patArchive.getAllhosp() == 3) {
|
List<PatArchiveOthreInfo> patArchives3 = patArchiveMapper.selectPatArchiveInfoByPhysical(patArchive);
|
if (CollectionUtils.isNotEmpty(patArchives3)) {
|
patArchiveList.addAll(patArchives3);
|
}
|
}
|
|
//根据患者ID进行分组
|
Map<Long, List<PatArchiveOthreInfo>> listMap = patArchiveList.stream().collect(Collectors.groupingBy(PatArchiveOthreInfo::getId));
|
|
//对数据进行封装
|
for (List<PatArchiveOthreInfo> list : listMap.values()) {
|
PatArchive patArchive1 = new PatArchive();
|
Set<PatArchivetag> stringList = new HashSet<>();
|
for (int i = 0; i < list.size(); i++) {
|
if (i == 0) {
|
patArchive1 = DtoConversionUtils.sourceToTarget(list.get(0), PatArchive.class);
|
//将标签置空,不空也没有问题
|
patArchive1.setTag("");
|
}
|
//将查出的tag,放到patArchive1里的TagList中
|
PatArchivetag patArchivetag = new PatArchivetag();
|
patArchivetag.setTagname(list.get(i).getTag());
|
patArchivetag.setTagid(list.get(i).getTagid());
|
stringList.add(patArchivetag);
|
}
|
patArchive1.setTagList(stringList.stream().collect(Collectors.toList()));
|
patArchives.add(patArchive1);
|
}
|
|
return patArchives;
|
}
|
|
@Override
|
public List<PatArchivetagAndPatientInfo> patTagByContion(List<Long> tagids) {
|
List<PatArchivetagAndPatientInfo> patArchivetagAndPatientInfos = new ArrayList<>();
|
if (tagids.size() > 0) {
|
for (int i = 0; i < tagids.size(); i++) {
|
PatArchivetag patArchivetag = new PatArchivetag();
|
patArchivetag.setTagid(tagids.get(i));
|
//获取患者patid
|
List<PatArchivetag> patArchivetags1 = patArchivetagMapper.selectPatArchivetagAndBaseTagList(patArchivetag);
|
for (int j = 0; j < patArchivetags1.size(); j++) {
|
PatArchivetagAndPatientInfo patArchivetagAndPatientInfo = DtoConversionUtils.sourceToTarget(patArchivetags1.get(j), PatArchivetagAndPatientInfo.class);
|
PatArchive patArchive = new PatArchive();
|
patArchive.setId(patArchivetagAndPatientInfo.getPatid());
|
List<PatArchive> patArchiveList = patArchiveMapper.selectPatArchiveList(patArchive);
|
patArchivetagAndPatientInfo.setPatNum(patArchiveList.size());
|
// patArchivetagAndPatientInfo.setPatArchives(patArchiveList);
|
patArchivetagAndPatientInfos.add(patArchivetagAndPatientInfo);
|
}
|
}
|
} else {
|
PatArchivetag patArchivetag = new PatArchivetag();
|
//获取患者patid
|
List<PatArchivetag> patArchivetags1 = patArchivetagMapper.selectPatArchivetagAndBaseTagList(patArchivetag);
|
for (int j = 0; j < patArchivetags1.size(); j++) {
|
PatArchivetagAndPatientInfo patArchivetagAndPatientInfo = DtoConversionUtils.sourceToTarget(patArchivetags1.get(j), PatArchivetagAndPatientInfo.class);
|
PatArchive patArchive = new PatArchive();
|
patArchive.setId(patArchivetagAndPatientInfo.getPatid());
|
List<PatArchive> patArchiveList = patArchiveMapper.selectPatArchiveList(patArchive);
|
// patArchivetagAndPatientInfo.setPatArchives(patArchiveList);
|
patArchivetagAndPatientInfo.setPatNum(patArchiveList.size());
|
patArchivetagAndPatientInfos.add(patArchivetagAndPatientInfo);
|
}
|
}
|
return patArchivetagAndPatientInfos;
|
}
|
|
@Override
|
public List<PatArchivetagAndPatientInfo> patInfoByTag(List<Long> tagids) {
|
|
|
return null;
|
}
|
|
@Override
|
public List<Object> getUserTreatmentInfo(String pid, String type) {
|
if (StringUtils.isEmpty(pid) || StringUtils.isEmpty(type)) {
|
throw new BaseException("入参为空,请检查入参");
|
}
|
List<Object> objectList = new ArrayList<>();
|
|
//通过患者获取门诊信息
|
PatMedInhosp patMedInhosp = new PatMedInhosp();
|
patMedInhosp.setInhospno(pid);
|
List<PatMedInhosp> patMedInhosps = patMedInhospService.selectPatMedInhospList(patMedInhosp);
|
objectList.addAll(patMedInhosps);
|
|
|
return null;
|
}
|
|
private void getdata(Row row, PatArchive patArchive, Boolean head) {
|
if (head) {
|
row.createCell(0).setCellValue("姓名");
|
row.createCell(1).setCellValue("性别");
|
row.createCell(2).setCellValue("证件类型");
|
row.createCell(3).setCellValue("证件号码");
|
row.createCell(4).setCellValue("出生日期");
|
row.createCell(5).setCellValue("本人联系方式");
|
row.createCell(6).setCellValue("亲属联系方式");
|
row.createCell(7).setCellValue("患者标签");
|
row.createCell(8).setCellValue("错误原因");
|
} else {
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
row.createCell(0).setCellValue(patArchive.getName());
|
row.createCell(1).setCellValue(patArchive.getSex() == 1 ? "男" : "女");
|
row.createCell(2).setCellValue(patArchive.getIdcardtype());
|
row.createCell(3).setCellValue(patArchive.getIdcardno());
|
if (ObjectUtils.isNotEmpty(patArchive.getBirthdate())) {
|
row.createCell(4).setCellValue(simpleDateFormat.format(patArchive.getBirthdate()).toString());
|
}
|
row.createCell(5).setCellValue(patArchive.getTelcode());
|
row.createCell(6).setCellValue(patArchive.getRelativetelcode());
|
row.createCell(7).setCellValue(patArchive.getTag());
|
row.createCell(8).setCellValue(patArchive.getRemark());
|
|
|
}
|
|
}
|
|
public void addRemark(String info, PatArchive patArchive) {
|
if (StringUtils.isNotEmpty(patArchive.getRemark()) == true) {
|
patArchive.setRemark(patArchive.getRemark() + "," + info);
|
} else {
|
patArchive.setRemark(info);
|
}
|
}
|
|
/**
|
* 获取患者信息(去重)
|
*
|
* @param patArchiveReq
|
* @return
|
*/
|
@Override
|
public List<PatArchiveOthreInfo> getPatientInfoQC(PatArchiveReq patArchiveReq) {
|
if (CollectionUtils.isEmpty(patArchiveReq.getLeavehospitaldistrictcodes()) || patArchiveReq.getLeavehospitaldistrictcodes().size() == 0) {
|
patArchiveReq.setLeavehospitaldistrictcodes(null);
|
}
|
if (CollectionUtils.isEmpty(patArchiveReq.getLeaveldeptcodes()) || patArchiveReq.getLeaveldeptcodes().size() == 0) {
|
patArchiveReq.setLeaveldeptcodes(null);
|
}
|
|
List<PatArchiveOthreInfo> patArchiveList = new ArrayList<>();
|
if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 1) {
|
// 查看住院 1 查看门诊 2 查看体检 3
|
List<PatArchiveOthreInfo> patArchives1 = patArchiveMapper.selectPatArchiveInfoByInhospQC(patArchiveReq);
|
if (CollectionUtils.isNotEmpty(patArchives1)) {
|
patArchiveList.addAll(patArchives1);
|
}
|
} else if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 2) {
|
// 查看住院 1 查看门诊 2 查看体检 3
|
List<PatArchiveOthreInfo> patArchives2 = patArchiveMapper.selectPatArchiveInfoByOuthospQC(patArchiveReq);
|
if (CollectionUtils.isNotEmpty(patArchives2)) {
|
patArchiveList.addAll(patArchives2);
|
}
|
} else if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 3) {
|
// 查看住院 1 查看门诊 2 查看体检 3
|
List<PatArchiveOthreInfo> patArchives3 = patArchiveMapper.selectPatArchiveInfoByPhysicalQC(patArchiveReq);
|
if (CollectionUtils.isNotEmpty(patArchives3)) {
|
patArchiveList.addAll(patArchives3);
|
}
|
}
|
|
return patArchiveList;
|
}
|
}
|