This commit is contained in:
zhuangyuanke 2024-12-31 17:10:08 +08:00
parent f88b28b243
commit b54fee7a77
2 changed files with 195 additions and 184 deletions

View File

@ -113,29 +113,30 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
return patientInfoMapper.selectPatientInfoList(patientInfo);
}
/**
* @description 患者管理患者档案列表
* @param patientInfo 患者信息查询传输对象
* @return 患者信息集合
* @Author haown
* @Date 2024-08-05 14:46
*/
@DataScope(agencyAlias = "p", userAlias = "p.attending_physician_id")
@Override public List<PatientInfoVo> getPatientList(PatientInfoDto patientInfo) {
List<PatientInfoVo> patientInfoVoList = patientInfoMapper.getPatientList(patientInfo);
return patientInfoVoList;
}
/**
* @param patientInfo 患者信息查询传输对象
* @return 患者信息集合
* @description 患者管理患者档案列表
* @Author haown
* @Date 2024-08-05 14:46
*/
@DataScope(agencyAlias = "p", userAlias = "p.attending_physician_id")
@Override
public List<PatientInfoVo> getPatientList(PatientInfoDto patientInfo) {
List<PatientInfoVo> patientInfoVoList = patientInfoMapper.getPatientList(patientInfo);
return patientInfoVoList;
}
/**
* 查询患者信息列表
*
* @param patientInfo 患者信息
* @return 患者信息
*/
@Override
public List<PatientInfo> selectAllPatientList(PatientInfoDto patientInfo) {
return patientInfoMapper.selectPatientInfoList(patientInfo);
}
/**
* 查询患者信息列表
*
* @param patientInfo 患者信息
* @return 患者信息
*/
@Override
public List<PatientInfo> selectAllPatientList(PatientInfoDto patientInfo) {
return patientInfoMapper.selectPatientInfoList(patientInfo);
}
/**
* 新增患者信息
@ -146,63 +147,63 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
@Override
@Transactional
public PatientInfo insertPatientInfo(PatientInfo patientInfo) {
if (StringUtils.isBlank(patientInfo.getCardNo())) {
throw new ServiceException("请输入身份证号");
}
// 根据身份证号+机构id判断用户信息是否存在
PatientInfoDto patientQuery = new PatientInfoDto();
patientQuery.setCardNo(patientInfo.getCardNo());
patientQuery.setHospitalAgencyId(patientInfo.getHospitalAgencyId());
List<PatientInfo> patientList = patientInfoMapper.selectPatientInfoList(patientQuery);
boolean exist = false;
if(CollectionUtils.isNotEmpty(patientList)) {
PatientInfo patientOld = patientList.get(0);
patientInfo.setId(patientOld.getId());
exist = true;
} else {
patientInfo.setCreateTime(LocalDateTime.now());
patientInfo.setCreateBy(SecurityUtils.getLoginUser().getUser().getNickName());
}
patientInfo.setDelFlag(0);
// 根据身份证号计算性别出生日期
if (patientInfo.getBirthDate() == null) {
patientInfo.setBirthDate(BaseUtil.getBirthday(patientInfo.getCardNo()));
}
if (StringUtils.isBlank(patientInfo.getSex())) {
patientInfo.setSex(BaseUtil.getGender(patientInfo.getCardNo()));
}
// 先根据身份证号查询是否有该居民
ResidentInfo residentQuery = new ResidentInfo();
residentQuery.setCardNo(patientInfo.getCardNo());
List<ResidentInfo> residentList = residentInfoMapper.selectResidentInfoList(residentQuery);
// 身份证号没查到居民通过手机号查询居民
if (CollectionUtils.isEmpty(residentList) && StringUtils.isNotBlank(patientInfo.getPatientPhone())) {
residentQuery.setCardNo(null);
residentQuery.setPatientPhone(patientInfo.getPatientPhone());
residentList = residentInfoMapper.selectResidentInfoList(residentQuery);
}
ResidentInfo residentInfo = new ResidentInfo();
BeanUtils.copyBeanProp(residentInfo, patientInfo);
if (CollectionUtils.isEmpty(residentList)) {
// 新增居民
residentInfoMapper.insertResidentInfo(residentInfo);
patientInfo.setResidentId(residentInfo.getId());
} else {
// 修改居民信息
residentInfo.setId(residentList.get(0).getId());
residentInfoMapper.updateResidentInfo(residentInfo);
patientInfo.setResidentId(residentList.get(0).getId());
}
// 患者来源
if (StringUtils.isBlank(patientInfo.getPatientSource())) {
patientInfo.setPatientSource(PatientSourceEnum.MANAGE_END.name());
}
if (exist) {
patientInfoMapper.updatePatientInfoSelective(patientInfo);
} else {
patientInfoMapper.insertPatientInfo(patientInfo);
}
return patientInfo;
if (StringUtils.isBlank(patientInfo.getCardNo())) {
throw new ServiceException("请输入身份证号");
}
// 根据身份证号+机构id判断用户信息是否存在
PatientInfoDto patientQuery = new PatientInfoDto();
patientQuery.setCardNo(patientInfo.getCardNo());
patientQuery.setHospitalAgencyId(patientInfo.getHospitalAgencyId());
List<PatientInfo> patientList = patientInfoMapper.selectPatientInfoList(patientQuery);
boolean exist = false;
if (CollectionUtils.isNotEmpty(patientList)) {
PatientInfo patientOld = patientList.get(0);
patientInfo.setId(patientOld.getId());
exist = true;
} else {
patientInfo.setCreateTime(LocalDateTime.now());
patientInfo.setCreateBy(SecurityUtils.getLoginUser().getUser().getNickName());
}
patientInfo.setDelFlag(0);
// 根据身份证号计算性别出生日期
if (patientInfo.getBirthDate() == null) {
patientInfo.setBirthDate(BaseUtil.getBirthday(patientInfo.getCardNo()));
}
if (StringUtils.isBlank(patientInfo.getSex())) {
patientInfo.setSex(BaseUtil.getGender(patientInfo.getCardNo()));
}
// 先根据身份证号查询是否有该居民
ResidentInfo residentQuery = new ResidentInfo();
residentQuery.setCardNo(patientInfo.getCardNo());
List<ResidentInfo> residentList = residentInfoMapper.selectResidentInfoList(residentQuery);
// 身份证号没查到居民通过手机号查询居民
if (CollectionUtils.isEmpty(residentList) && StringUtils.isNotBlank(patientInfo.getPatientPhone())) {
residentQuery.setCardNo(null);
residentQuery.setPatientPhone(patientInfo.getPatientPhone());
residentList = residentInfoMapper.selectResidentInfoList(residentQuery);
}
ResidentInfo residentInfo = new ResidentInfo();
BeanUtils.copyBeanProp(residentInfo, patientInfo);
if (CollectionUtils.isEmpty(residentList)) {
// 新增居民
residentInfoMapper.insertResidentInfo(residentInfo);
patientInfo.setResidentId(residentInfo.getId());
} else {
// 修改居民信息
residentInfo.setId(residentList.get(0).getId());
residentInfoMapper.updateResidentInfo(residentInfo);
patientInfo.setResidentId(residentList.get(0).getId());
}
// 患者来源
if (StringUtils.isBlank(patientInfo.getPatientSource())) {
patientInfo.setPatientSource(PatientSourceEnum.MANAGE_END.name());
}
if (exist) {
patientInfoMapper.updatePatientInfoSelective(patientInfo);
} else {
patientInfoMapper.insertPatientInfo(patientInfo);
}
return patientInfo;
}
/**
@ -213,56 +214,57 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
*/
@Override
public PatientInfo updatePatientInfo(PatientInfo patientInfo) {
if (StringUtils.isBlank(patientInfo.getCardNo())) {
throw new ServiceException("请输入身份证号");
}
// 根据身份证号计算性别出生日期
patientInfo.setBirthDate(BaseUtil.getBirthday(patientInfo.getCardNo()));
patientInfo.setSex(BaseUtil.getGender(patientInfo.getCardNo()));
ResidentInfo residentInfo = new ResidentInfo();
if (patientInfo.getResidentId() != null) {
residentInfo = residentInfoMapper.selectResidentInfoById(patientInfo.getResidentId());
BeanUtils.copyBeanProp(residentInfo, patientInfo);
residentInfo.setId(patientInfo.getResidentId());
residentInfoMapper.updateResidentInfo(residentInfo);
} else {
// 先根据身份证号查询是否有该居民
ResidentInfo residentQuery = new ResidentInfo();
residentQuery.setCardNo(patientInfo.getCardNo());
List<ResidentInfo> residentList = residentInfoMapper.selectResidentInfoList(residentQuery);
// 身份证号没查到居民通过手机号查询居民
if (CollectionUtils.isEmpty(residentList) && StringUtils.isNotBlank(patientInfo.getPatientPhone())) {
residentQuery.setCardNo(null);
residentQuery.setPatientPhone(patientInfo.getPatientPhone());
residentList = residentInfoMapper.selectResidentInfoList(residentQuery);
}
if (CollectionUtils.isNotEmpty(residentList)) {
Long residentId = residentList.get(0).getId();
residentInfo = residentList.get(0);
BeanUtils.copyBeanProp(residentInfo, patientInfo);
residentInfo.setId(residentId);
residentInfoMapper.updateResidentInfo(residentInfo);
} else {
BeanUtils.copyBeanProp(residentInfo, patientInfo);
residentInfo.setId(null);
residentInfoMapper.insertResidentInfo(residentInfo);
}
patientInfo.setResidentId(residentInfo.getId());
}
patientInfo.setUpdateBy(SecurityUtils.getLoginUser().getUser().getNickName());
patientInfo.setUpdateTime(LocalDateTime.now());
patientInfo.setDelFlag(0);
patientInfoMapper.updatePatientInfoSelective(patientInfo);
return patientInfo;
if (StringUtils.isBlank(patientInfo.getCardNo())) {
throw new ServiceException("请输入身份证号");
}
// 根据身份证号计算性别出生日期
patientInfo.setBirthDate(BaseUtil.getBirthday(patientInfo.getCardNo()));
patientInfo.setSex(BaseUtil.getGender(patientInfo.getCardNo()));
ResidentInfo residentInfo = new ResidentInfo();
if (patientInfo.getResidentId() != null) {
residentInfo = residentInfoMapper.selectResidentInfoById(patientInfo.getResidentId());
BeanUtils.copyBeanProp(residentInfo, patientInfo);
residentInfo.setId(patientInfo.getResidentId());
residentInfoMapper.updateResidentInfo(residentInfo);
} else {
// 先根据身份证号查询是否有该居民
ResidentInfo residentQuery = new ResidentInfo();
residentQuery.setCardNo(patientInfo.getCardNo());
List<ResidentInfo> residentList = residentInfoMapper.selectResidentInfoList(residentQuery);
// 身份证号没查到居民通过手机号查询居民
if (CollectionUtils.isEmpty(residentList) && StringUtils.isNotBlank(patientInfo.getPatientPhone())) {
residentQuery.setCardNo(null);
residentQuery.setPatientPhone(patientInfo.getPatientPhone());
residentList = residentInfoMapper.selectResidentInfoList(residentQuery);
}
if (CollectionUtils.isNotEmpty(residentList)) {
Long residentId = residentList.get(0).getId();
residentInfo = residentList.get(0);
BeanUtils.copyBeanProp(residentInfo, patientInfo);
residentInfo.setId(residentId);
residentInfoMapper.updateResidentInfo(residentInfo);
} else {
BeanUtils.copyBeanProp(residentInfo, patientInfo);
residentInfo.setId(null);
residentInfoMapper.insertResidentInfo(residentInfo);
}
patientInfo.setResidentId(residentInfo.getId());
}
patientInfo.setUpdateBy(SecurityUtils.getLoginUser().getUser().getNickName());
patientInfo.setUpdateTime(LocalDateTime.now());
patientInfo.setDelFlag(0);
patientInfoMapper.updatePatientInfoSelective(patientInfo);
return patientInfo;
}
@Override public PatientInfo updateBaseInfo(PatientBaseInfoDto patientInfo) {
PatientInfo patientInfo1 = patientInfoMapper.selectPatientInfoById(patientInfo.getId());
BeanUtils.copyBeanProp(patientInfo1, patientInfo);
return updatePatientInfo(patientInfo1);
}
@Override
public PatientInfo updateBaseInfo(PatientBaseInfoDto patientInfo) {
PatientInfo patientInfo1 = patientInfoMapper.selectPatientInfoById(patientInfo.getId());
BeanUtils.copyBeanProp(patientInfo1, patientInfo);
return updatePatientInfo(patientInfo1);
}
/**
/**
* 批量删除患者信息
*
* @param ids 需要删除的患者信息主键
@ -271,55 +273,57 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
@Override
@Transactional(rollbackFor = Exception.class)
public int deletePatientInfoByIds(Long[] ids) {
int flag = 0;
for (Long id : ids) {
PatientInfo patientInfo = patientInfoMapper.selectPatientInfoById(id);
// 查询关联的就诊记录是否已签约
if (patientInfo.getSignPatientRecordId() != null && StringUtils.equals(SignRecordServiceStatusConstants.SERVICE_CENTER, patientInfo.getServiceStatus())) {
SignPatientRecord signPatientRecord = signPatientRecordMapper.selectByPrimaryKey(patientInfo.getSignPatientRecordId());
if (ObjectUtils.isNotEmpty(signPatientRecord) && Objects.equals(patientInfo.getPatientVisitRecordId(), signPatientRecord.getPatientVisitRecordId()) && signPatientRecord.getDelFlag() == 0) {
throw new ServiceException("该居民已签约不能删除该就诊记录!");
}
}
patientVisitRecordService.deletePatientVisitRecordById(patientInfo.getPatientVisitRecordId());
// 根据患者最新一条就诊记录修改患者状态
PatientVisitRecordDto patientVisitRecordDto = new PatientVisitRecordDto();
patientVisitRecordDto.setHospitalAgencyId(patientInfo.getHospitalAgencyId());
patientVisitRecordDto.setPatientId(id);
PatientVisitRecord patientVisitRecord = patientVisitRecordService.getLastRecord(patientVisitRecordDto);
if (ObjectUtils.isEmpty(patientVisitRecord)) {
setVisitInfoNull(patientInfo);
} else {
BeanUtils.copyBeanProp(patientInfo, patientVisitRecord);
patientInfo.setId(id);
patientInfo.setPatientVisitRecordId(patientVisitRecord.getId());
// 设置patientType
patientVisitRecordService.setPatientType(patientInfo, patientVisitRecord);
}
patientInfo.setPatientType(null);
flag += patientInfoMapper.updatePatientInfo(patientInfo);
}
int flag = 0;
for (Long id : ids) {
PatientInfo patientInfo = patientInfoMapper.selectPatientInfoById(id);
// 查询关联的就诊记录是否已签约
if (patientInfo.getSignPatientRecordId() != null && StringUtils.equals(SignRecordServiceStatusConstants.SERVICE_CENTER, patientInfo.getServiceStatus())) {
SignPatientRecord signPatientRecord = signPatientRecordMapper.selectByPrimaryKey(patientInfo.getSignPatientRecordId());
if (ObjectUtils.isNotEmpty(signPatientRecord) && Objects.equals(patientInfo.getPatientVisitRecordId(), signPatientRecord.getPatientVisitRecordId()) && signPatientRecord.getDelFlag() == 0) {
throw new ServiceException("该居民已签约不能删除该就诊记录!");
}
}
patientVisitRecordService.deletePatientVisitRecordById(patientInfo.getPatientVisitRecordId());
// 根据患者最新一条就诊记录修改患者状态
PatientVisitRecordDto patientVisitRecordDto = new PatientVisitRecordDto();
patientVisitRecordDto.setHospitalAgencyId(patientInfo.getHospitalAgencyId());
patientVisitRecordDto.setPatientId(id);
PatientVisitRecord patientVisitRecord = patientVisitRecordService.getLastRecord(patientVisitRecordDto);
if (ObjectUtils.isEmpty(patientVisitRecord)) {
setVisitInfoNull(patientInfo);
} else {
BeanUtils.copyBeanProp(patientInfo, patientVisitRecord);
patientInfo.setId(id);
patientInfo.setPatientVisitRecordId(patientVisitRecord.getId());
// 设置patientType
patientVisitRecordService.setPatientType(patientInfo, patientVisitRecord);
}
patientInfo.setPatientType(null);
flag += patientInfoMapper.updatePatientInfo(patientInfo);
}
return flag;
}
/**
* 设置患者就诊信息为空
* @param patientInfo 患者信息
*/
private void setVisitInfoNull(PatientInfo patientInfo){
patientInfo.setVisitDate(null);
patientInfo.setPatientType(null);
patientInfo.setPatientVisitRecordId(null);
patientInfo.setVisitMethod(null);
patientInfo.setAdmissionTime(null);
patientInfo.setDischargeTime(null);
patientInfo.setAttendingPhysicianId(null);
patientInfo.setAttendingPhysicianName(null);
patientInfo.setResponsibleNurse(null);
patientInfo.setMainDiagnosis(null);
patientInfo.setVisitSerialNumber(null);
patientInfo.setInHospitalNumber(null);
}
/**
* 设置患者就诊信息为空
*
* @param patientInfo 患者信息
*/
private void setVisitInfoNull(PatientInfo patientInfo) {
patientInfo.setVisitDate(null);
patientInfo.setPatientType(null);
patientInfo.setPatientVisitRecordId(null);
patientInfo.setVisitMethod(null);
patientInfo.setAdmissionTime(null);
patientInfo.setDischargeTime(null);
patientInfo.setAttendingPhysicianId(null);
patientInfo.setAttendingPhysicianName(null);
patientInfo.setResponsibleNurse(null);
patientInfo.setMainDiagnosis(null);
patientInfo.setVisitSerialNumber(null);
patientInfo.setInHospitalNumber(null);
}
/**
* 删除患者信息
*
@ -350,7 +354,7 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
}
//如果要导入的数据列表为空直接返回
if (CollectionUtils.isEmpty(list) || list.size() == 0) {
return AjaxResult.error("导入数据列表不能为空!" );
return AjaxResult.error("导入数据列表不能为空!");
}
//如果存在 患者姓名或手机号或科室或就诊日期为空的情况直接返回
List<PatientInfoImport> collect = list.stream().filter(Objects::nonNull).filter(item -> StringUtils.isEmpty(item.getPatientName()) || StringUtils.isEmpty(item.getPatientPhone()) || StringUtils.isEmpty(item.getDeptAlias()) || Objects.isNull(item.getVisitDate())).collect(Collectors.toList());
@ -385,7 +389,7 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
//组装数据
List<PatientInfoImport> patientInfoImportList = new ArrayList<>();
//要导入的居民信息列表
List<PatientInfoImport> patientInfoImportList_forResident = new ArrayList<>();
List<PatientInfoImport> patientInfoImportList_forResident = new ArrayList<>();
for (PatientInfoImport patientInfoImport : distinctCollect) {
//选择自动去除当日重复记录
// if (CollectionUtils.isNotEmpty(residentInfos)) {
@ -485,9 +489,8 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
//设置导入记录ID
item.setPatientInfoImportId(item.getId());
//居民信息去重
if(residentInfos.stream().filter(residentInfo -> residentInfo.getPatientName().equals(item.getPatientName())
&& residentInfo.getPatientPhone().equals(item.getPatientPhone())).collect(Collectors.toSet()).size()==0)
{
if (residentInfos.stream().filter(residentInfo -> residentInfo.getPatientName().equals(item.getPatientName())
&& residentInfo.getPatientPhone().equals(item.getPatientPhone())).collect(Collectors.toSet()).size() == 0) {
patientInfoImportList_forResident.add(item);
}
//如果已存在
@ -498,21 +501,28 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
}
}
);
if(patientInfoImportList_forResident.size()>0) {
if (patientInfoImportList_forResident.size() > 0) {
int residentCount = residentInfoMapper.insertResidentInfoList(patientInfoImportList_forResident);
if (residentCount <= 0) {
log.info("居民表新增失败!");
return AjaxResult.error("居民信息新增失败;");
}
//设置居民ID
patientInfoImportList.forEach(item -> item.setResidentId(item.getId()));
patientInfoImportList_forResident.forEach(item ->
{
patientInfoImportList.stream().filter(item2 -> item2.getPatientName().equals(item.getPatientName())
&& item2.getPatientPhone().equals(item.getPatientPhone())).findFirst().orElse(new PatientInfoImport())
.setResidentId(item.getId());
}
);
}
//endregion
//设置为门诊患者
patientInfoImportList.forEach(item ->
{item.setPatientType(PatientTypeEnum.OUTPATIENT.getInfo());
item.setVisitMethod(VisitMethodConstants.OUTPATIENT_SERVICE);});
{
item.setPatientType(PatientTypeEnum.OUTPATIENT.getInfo());
item.setVisitMethod(VisitMethodConstants.OUTPATIENT_SERVICE);
});
//新增患者表
int i = patientInfoMapper.insertPatientInfoList(patientInfoImportList);
if (i <= 0) {
@ -651,7 +661,8 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
patientInfoImports.forEach(item -> item.setResidentId(item.getId()));
//设置为门诊患者
patientInfoImports.forEach(item ->
{item.setPatientType(PatientTypeEnum.OUTPATIENT.getInfo());
{
item.setPatientType(PatientTypeEnum.OUTPATIENT.getInfo());
item.setVisitMethod(VisitMethodConstants.OUTPATIENT_SERVICE);
});

View File

@ -906,7 +906,7 @@
) values
<foreach item="PatientInfoImport" index="index" collection="list" separator=",">
(
#{PatientInfoImport.id},
#{PatientInfoImport.residentId},
#{PatientInfoImport.patientInfoImportId},
#{PatientInfoImport.visitDate},
#{PatientInfoImport.inHospitalNumber},