优化患者导入功能
This commit is contained in:
parent
b93b519a49
commit
51ccd0d692
@ -108,7 +108,7 @@ token:
|
||||
# 令牌密钥
|
||||
secret: DIweGcEWJTbvo48dnvOMR8GsDW
|
||||
# 令牌有效期(默认30分钟)
|
||||
expireTime: 30
|
||||
expireTime: 120
|
||||
# 请求拦截白名单
|
||||
ant-matchers: /postDischarge/**,/testMobile/**,/postDischargeApplet/**,/api/**,/manage/patientInfoimporttemp/**
|
||||
|
||||
|
||||
@ -131,21 +131,22 @@ public class PatientInfoController extends BaseController {
|
||||
return toAjax(patientInfoService.deletePatientInfoByIds(ids));
|
||||
}
|
||||
|
||||
//isDistinct==1,表示自动去重;==0表示不去重;
|
||||
@ApiOperation("患者信息导入")
|
||||
@PostMapping("/patientUpload")
|
||||
public AjaxResult patientUpload(MultipartFile file, Integer records) throws Exception {
|
||||
public AjaxResult patientUpload(MultipartFile file, Integer isDistinct) throws Exception {
|
||||
//判断excel里面是否有数据/文件格式
|
||||
if (Objects.isNull(file) || StringUtils.isBlank(file.getOriginalFilename())) {
|
||||
return AjaxResult.error("请选择需要导入的文件!");
|
||||
}
|
||||
// 获取文件名
|
||||
String orgName = file.getOriginalFilename();
|
||||
if (!orgName.endsWith(Constants.XLSX) && !orgName.endsWith(Constants.XLS)) {
|
||||
String filename = file.getOriginalFilename();
|
||||
if (!filename.endsWith(Constants.XLSX) && !filename.endsWith(Constants.XLS)) {
|
||||
return AjaxResult.error("导入文件格式不正确,请导入xlsx或xls格式的文件!");
|
||||
}
|
||||
ExcelUtil<PatientInfoImport> util = new ExcelUtil<>(PatientInfoImport.class);
|
||||
List<PatientInfoImport> list = util.importExcel(file.getInputStream());
|
||||
return patientInfoService.patientUpload(list, records, orgName);
|
||||
return patientInfoService.patientUpload(list, isDistinct, filename);
|
||||
}
|
||||
|
||||
@ApiOperation("未识别科室名称导入")
|
||||
|
||||
@ -133,4 +133,10 @@ public class PatientInfoDto extends BaseEntity {
|
||||
/** 年龄 */
|
||||
@ApiModelProperty(value = "年龄")
|
||||
private Integer age;
|
||||
|
||||
@ApiModelProperty(value = "导入流水号")
|
||||
private String sn;
|
||||
|
||||
@ApiModelProperty(value = "导入患者表id")
|
||||
private Integer patientInfoImportId;
|
||||
}
|
||||
|
||||
@ -94,9 +94,11 @@ public interface IPatientInfoService {
|
||||
* 患者导入
|
||||
*
|
||||
* @param list 患者信息结合
|
||||
* isDistinct==1,表示自动去重;==0表示不去重;
|
||||
* filename,附件名称
|
||||
* @return AjaxResult
|
||||
*/
|
||||
AjaxResult patientUpload(List<PatientInfoImport> list,Integer records,String orgName);
|
||||
AjaxResult patientUpload(List<PatientInfoImport> list,Integer isDistinct,String filename);
|
||||
|
||||
/**
|
||||
* 未识别科室名称导入
|
||||
|
||||
@ -331,57 +331,70 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
|
||||
/**
|
||||
* 患者导入
|
||||
*
|
||||
* @param list 患者信息结合
|
||||
* @param list 患者信息集合
|
||||
* isDistinct==1,表示自动去重;==0表示不去重;
|
||||
* fileName,附件名称;
|
||||
* @return AjaxResult
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public AjaxResult patientUpload(List<PatientInfoImport> list, Integer records, String orgName) {
|
||||
if (CollectionUtils.isEmpty(list) || list.size() == 0) {
|
||||
return AjaxResult.error("已完成数据导入!导入成功0条记录,失败" + list.size() + "条记录。失败原因:导入用户数据不能为空!");
|
||||
}
|
||||
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());
|
||||
if (CollectionUtils.isNotEmpty(collect)) {
|
||||
return AjaxResult.error("已完成数据导入!导入成功0条记录,失败" + list.size() + "条记录。失败原因:请填写完整导入信息!");
|
||||
}
|
||||
List<PatientInfoImport> regexPhoneList = list.stream().filter(item -> StringUtils.isNotBlank(item.getPatientPhone())).filter(item -> BooleanUtils.isFalse(regexUtil.regexPhone(item.getPatientPhone()))).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(regexPhoneList)) {
|
||||
return AjaxResult.error(HttpStatus.ERROR_TWO, "已完成数据导入!导入成功0条记录,失败" + list.size() + "条记录。失败原因:手机号号码格式不正确,请重新录入!", regexPhoneList);
|
||||
}
|
||||
//导入重复过滤
|
||||
List<PatientInfoImport> distinctCollect = list.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
//与数据库重复
|
||||
List<PatientInfo> patientInfos = new ArrayList<>();
|
||||
List<ResidentInfo> residentInfos = residentInfoMapper.selectResidentInfoByPhoneList(list);
|
||||
if (Objects.isNull(records) || records == 1) {
|
||||
LocalDate nowDate = LocalDate.now();
|
||||
patientInfos = patientInfoMapper.selectPatientInfoByPatientName(list, nowDate);
|
||||
}
|
||||
//sn
|
||||
String sn = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
||||
public AjaxResult patientUpload(List<PatientInfoImport> list, Integer isDistinct, String fileName) {
|
||||
//登录用户科室信息
|
||||
SysUser sysUser = sysUserMapper.selectUserById(SecurityUtils.getUserId());
|
||||
Agency agency = agencyMapper.selectAgencyById(sysUser.getHospitalAgencyId());
|
||||
if (Objects.isNull(agency) || StringUtils.isEmpty(agency.getNodeType())) {
|
||||
return AjaxResult.error("已完成数据导入!导入成功0条记录,失败" + list.size() + "条记录。失败原因:该账号无所属医院信息,请先添加该账号所属的医院信息!");
|
||||
return AjaxResult.error("该账号无所属医院信息,请先配置该账号所属的医院信息!");
|
||||
}
|
||||
|
||||
//如果要导入的数据列表为空,直接返回
|
||||
if (CollectionUtils.isEmpty(list) || list.size() == 0) {
|
||||
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());
|
||||
if (CollectionUtils.isNotEmpty(collect)) {
|
||||
return AjaxResult.error("用户信息不完整,科室名称、就诊时间、姓名、联系电话均不允许为空,请完善后重试;");
|
||||
}
|
||||
//存在手机号格式不正确的情况,直接返回
|
||||
List<PatientInfoImport> regexPhoneList = list.stream().filter(item -> StringUtils.isNotBlank(item.getPatientPhone())).filter(item -> BooleanUtils.isFalse(regexUtil.regexPhone(item.getPatientPhone()))).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(regexPhoneList)) {
|
||||
return AjaxResult.error(HttpStatus.ERROR_TWO, "部分手机号格式不正确,请修改后重试;", regexPhoneList);
|
||||
}
|
||||
//导入重复过滤,列表内患者信息自去重;
|
||||
List<PatientInfoImport> distinctCollect = list.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
//与数据库重复
|
||||
List<PatientInfo> patientInfos_CurrentDay = new ArrayList<>();
|
||||
List<ResidentInfo> residentInfos = residentInfoMapper.selectResidentInfoByPhoneList(list);
|
||||
//如果要求自动去重(同数据库中 当日已导入患者列表 比对,如果患者姓名和手机号相同,视为重复)
|
||||
if (Objects.isNull(isDistinct) || isDistinct == 1) {
|
||||
LocalDate nowDate = LocalDate.now();
|
||||
//此处实现是跟患者表数据比对,(也可以直接跟已导入患者表数据比对)
|
||||
patientInfos_CurrentDay = patientInfoMapper.selectPatientInfoByPatientName(list, nowDate);
|
||||
}
|
||||
//sn 导入流水号;
|
||||
String sn = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
||||
|
||||
Department department = new Department();
|
||||
department.setHospitalAgencyId(sysUser.getHospitalAgencyId());
|
||||
List<Department> departmentList = departmentMapper.selectDepartmentNameCount(department);
|
||||
|
||||
PatientInfoImportVO patientInfoImportVO = new PatientInfoImportVO();
|
||||
List<DeptAliasVO> deptAliasVOS = new ArrayList<>();
|
||||
//组装数据
|
||||
List<PatientInfoImport> patientInfoImportList = new ArrayList<>();
|
||||
//要导入的居民信息列表
|
||||
List<PatientInfoImport> patientInfoImportList_forResident = new ArrayList<>();
|
||||
for (PatientInfoImport patientInfoImport : distinctCollect) {
|
||||
//选择自动去除当日重复记录
|
||||
if (CollectionUtils.isNotEmpty(residentInfos)) {
|
||||
List<ResidentInfo> collect1 = residentInfos.stream().filter(Objects::nonNull).filter(item -> patientInfoImport.getPatientName().equals(item.getPatientName()) && patientInfoImport.getPatientPhone().equals(item.getPatientPhone())).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(collect1)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(patientInfos) && (Objects.isNull(records) || records == 1)) {
|
||||
List<PatientInfo> collect1 = patientInfos.stream().filter(Objects::nonNull).filter(item -> patientInfoImport.getPatientName().equals(item.getPatientName()) && patientInfoImport.getPatientPhone().equals(item.getPatientPhone())).collect(Collectors.toList());
|
||||
// if (CollectionUtils.isNotEmpty(residentInfos)) {
|
||||
// List<ResidentInfo> collect1 = residentInfos.stream().filter(Objects::nonNull).filter(item -> patientInfoImport.getPatientName().equals(item.getPatientName()) && patientInfoImport.getPatientPhone().equals(item.getPatientPhone())).collect(Collectors.toList());
|
||||
// if (CollectionUtils.isNotEmpty(collect1)) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// 如果当日已有导入,则不再重复导入
|
||||
if (CollectionUtils.isNotEmpty(patientInfos_CurrentDay) && (Objects.isNull(isDistinct) || isDistinct == 1)) {
|
||||
List<PatientInfo> collect1 = patientInfos_CurrentDay.stream().filter(Objects::nonNull).filter(item -> patientInfoImport.getPatientName().equals(item.getPatientName()) && patientInfoImport.getPatientPhone().equals(item.getPatientPhone())).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(collect1)) {
|
||||
continue;
|
||||
}
|
||||
@ -421,12 +434,15 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
|
||||
deptAliasVO.setSn(sn);
|
||||
deptAliasVO.setDeptAlias(patientInfoImport.getDeptAlias());
|
||||
deptAliasVOS.add(deptAliasVO);
|
||||
|
||||
//?????
|
||||
// 20241209 注释掉,没什么用用,zyk 貌似用于下面重复判断
|
||||
patientInfoImportList.add(patientInfoImport);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(patientInfoImportList)) {
|
||||
return AjaxResult.success("已完成数据导入!导入成功0条记录;失败0条记录,重复" + list.size() + "条记录(已自动去重)。");
|
||||
return AjaxResult.success("附件中所有患者记录与今日已导入数据重复,不能重复导入");
|
||||
}
|
||||
//组装返回数据
|
||||
//组装返回科室数据
|
||||
patientInfoImportVO.setSn(sn);
|
||||
patientInfoImportVO.setCount(list.size());
|
||||
if (CollectionUtils.isNotEmpty(departmentList) && departmentList.size() > 0) {
|
||||
@ -436,41 +452,69 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
|
||||
deptAliasVOS = deptAliasVOS.stream().filter(Objects::nonNull).filter(item -> Objects.nonNull(item.getDeptAlias())).distinct().collect(Collectors.toList());
|
||||
patientInfoImportVO.setDeptAliasVOS(deptAliasVOS);
|
||||
}
|
||||
|
||||
//科室名称全符合新增患者表,否则返回数据
|
||||
if (CollectionUtils.isNotEmpty(deptAliasVOS)) {
|
||||
return AjaxResult.error("科室名称不存在", patientInfoImportVO);
|
||||
} else {
|
||||
//新增缓存表
|
||||
int insertCount = patientInfoImportMapper.insertPatientInfoImportList(patientInfoImportList);
|
||||
if (insertCount <= 0) {
|
||||
log.info("缓存表新增失败!");
|
||||
return AjaxResult.error("已完成数据导入!导入成功0条记录,失败" + patientInfoImportVO.getCount() + "条记录。");
|
||||
return AjaxResult.error("数据导入失败!");
|
||||
}
|
||||
//导入记录表
|
||||
//导入记录主表
|
||||
//region 导入记录主表
|
||||
PatientInfoImportMain patientInfoImportMain = new PatientInfoImportMain();
|
||||
patientInfoImportMain.setCreateBy(SecurityUtils.getUsername());
|
||||
patientInfoImportMain.setCreateTime(LocalDateTime.now());
|
||||
patientInfoImportMain.setSn(sn);
|
||||
patientInfoImportMain.setHospitalAgencyId(agency.getId());
|
||||
patientInfoImportMain.setFileName(orgName);
|
||||
patientInfoImportMain.setFileName(fileName);
|
||||
patientInfoImportMain.setHospitalAgencyName(agency.getAgencyName());
|
||||
patientInfoImportMainMapper.insertPatientInfoImportMain(patientInfoImportMain);
|
||||
//科室名称全符合新增患者表,否则返回数据
|
||||
if (CollectionUtils.isNotEmpty(deptAliasVOS)) {
|
||||
return AjaxResult.error("科室名称不存在", patientInfoImportVO);
|
||||
} else {
|
||||
//endregion
|
||||
|
||||
//新增居民表
|
||||
patientInfoImportList.forEach(item -> item.setPatientInfoImportId(item.getId()));
|
||||
int residentCount = residentInfoMapper.insertResidentInfoList(patientInfoImportList);
|
||||
//region 新增居民表
|
||||
patientInfoImportList.forEach(item ->
|
||||
{
|
||||
//设置导入记录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)
|
||||
{
|
||||
patientInfoImportList_forResident.add(item);
|
||||
}
|
||||
//如果已存在
|
||||
else {
|
||||
//设置居民ID
|
||||
item.setResidentId(residentInfos.stream().filter(residentInfo -> residentInfo.getPatientName().equals(item.getPatientName())
|
||||
&& residentInfo.getPatientPhone().equals(item.getPatientPhone())).findFirst().orElse(new ResidentInfo()).getId());
|
||||
}
|
||||
}
|
||||
);
|
||||
if(patientInfoImportList_forResident.size()>0) {
|
||||
int residentCount = residentInfoMapper.insertResidentInfoList(patientInfoImportList_forResident);
|
||||
if (residentCount <= 0) {
|
||||
log.info("居民表新增失败!");
|
||||
return AjaxResult.error("已完成数据导入!导入成功0条记录,失败" + patientInfoImportVO.getCount() + "条记录。");
|
||||
return AjaxResult.error("居民信息新增失败;");
|
||||
}
|
||||
//设置居民ID
|
||||
patientInfoImportList.forEach(item -> item.setResidentId(item.getId()));
|
||||
}
|
||||
//endregion
|
||||
|
||||
//新增患者表
|
||||
int i = patientInfoMapper.insertPatientInfoList(patientInfoImportList);
|
||||
if (i <= 0) {
|
||||
log.info("患者表新增失败!");
|
||||
return AjaxResult.error("已完成数据导入!导入成功0条记录,失败" + patientInfoImportVO.getCount() + "条记录。");
|
||||
return AjaxResult.error("患者信息新增失败;");
|
||||
}
|
||||
patientInfoImportList.forEach(item -> item.setPatientInfoId(item.getId()));
|
||||
//新增就诊记录表
|
||||
//region 新增就诊记录表
|
||||
List<PatientVisitRecord> patientVisitRecords = new ArrayList<>();
|
||||
for (PatientInfoImport patientInfoImport : patientInfoImportList) {
|
||||
PatientVisitRecord patientVisitRecord = new PatientVisitRecord();
|
||||
@ -488,8 +532,9 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
|
||||
int patientVisitRecordCount = patientVisitRecordMapper.insertPatientVisitRecordList(patientVisitRecords);
|
||||
if (patientVisitRecordCount <= 0) {
|
||||
log.info("就诊记录表新增失败!");
|
||||
return AjaxResult.error("已完成数据导入!导入成功0条记录,失败" + patientInfoImportVO.getCount() + "条记录。");
|
||||
return AjaxResult.error("就诊记录新增失败");
|
||||
}
|
||||
//endregion
|
||||
}
|
||||
String msg = "已完成数据导入!导入成功" + patientInfoImportList.size() + "条记录,失败0条记录";
|
||||
if (list.size() != patientInfoImportList.size()) {
|
||||
|
||||
@ -186,8 +186,10 @@ public class SignPatientManageRouteServiceImpl implements ISignPatientManageRout
|
||||
signPatientManageRoute.setTaskCreateType(TaskCreateTypeEnum.MANUAL_CREATE.getInfo());
|
||||
signPatientManageRoute.setCreateBy(SecurityUtils.getUsername());
|
||||
signPatientManageRoute.setCreateTime(LocalDateTime.now());
|
||||
//任务执行类型,批量执行
|
||||
if(StringUtils.isNotBlank(signPatientManageRoute.getImportMainId()))
|
||||
{ signPatientManageRoute.setTaskExcuteType(TaskExcuteTypeEnum.BATCH_TASK.getInfo());}
|
||||
|
||||
int insertRoute = signPatientManageRouteMapper.insertSignPatientManageRoute(signPatientManageRoute);
|
||||
if (insertRoute < 0) {
|
||||
return AjaxResult.error("新增签约患者管理任务路径失败!请联系管理员!");
|
||||
@ -198,16 +200,20 @@ public class SignPatientManageRouteServiceImpl implements ISignPatientManageRout
|
||||
if (Objects.isNull(routeNode) || StringUtils.isBlank(routeNode.getTaskNodeType()) || (" ").equals(routeNode.getTaskNodeType()) || StringUtils.isBlank(routeNode.getRouteNodeName()) || Objects.isNull(routeNode.getRouteNodeDay())) {
|
||||
continue;
|
||||
}
|
||||
//任务执行类型,批量执行
|
||||
if(StringUtils.isNotBlank(signPatientManageRoute.getImportMainId()))
|
||||
{ routeNode.setTaskExcuteType(TaskExcuteTypeEnum.BATCH_TASK.getInfo());}
|
||||
extracted(signPatientManageRoute, signPatientManageRouteNodes, routeNode);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(signPatientManageRouteNodes)) {
|
||||
return AjaxResult.error("创建任务中至少有一个管理任务节点!");
|
||||
}
|
||||
//批量插入任务
|
||||
int insertBatchCount = signPatientManageRouteNodeMapper.insertBatch(signPatientManageRouteNodes);
|
||||
if (insertBatchCount < 0) {
|
||||
return AjaxResult.error("新增签约患者管理任务路径失败!请联系管理员!");
|
||||
}
|
||||
//更新 签约记录的 审核状态为 未审核 zyk 20241204
|
||||
//更新 签约记录的 审核状态为 未审核,适用场景:手动创建任务 zyk 20241204
|
||||
SignPatientRecord signPatientRecord = new SignPatientRecord();
|
||||
signPatientRecord.setRouteCheckStatus(RouteCheckStatusEnum.UNAUDITED.getInfo());
|
||||
|
||||
|
||||
@ -21,6 +21,19 @@ public class PatientInfoVo {
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 导入患者表id
|
||||
*/
|
||||
@ApiModelProperty(value = "导入患者表id")
|
||||
private Long patientInfoImportId;
|
||||
|
||||
/**
|
||||
* 导入流水号
|
||||
*/
|
||||
@ApiModelProperty(value = "导入流水号")
|
||||
private String sn;
|
||||
|
||||
|
||||
/**
|
||||
* 居民信息表id
|
||||
*/
|
||||
|
||||
@ -274,6 +274,12 @@
|
||||
<if test="residentId != null">
|
||||
and p.resident_id = #{residentId}
|
||||
</if>
|
||||
<if test="patientInfoImportId != null">
|
||||
and p.patient_info_import_id = #{patientInfoImportId}
|
||||
</if>
|
||||
<if test="sn != null and sn != ''">
|
||||
and p.sn = #{sn}
|
||||
</if>
|
||||
<if test="patientName != null and patientName != ''">
|
||||
and p.patient_name = #{patientName}
|
||||
</if>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user