From 51ccd0d692d1afaf1cd69380d2ad024fb2d3faa0 Mon Sep 17 00:00:00 2001 From: zhuangyuanke Date: Mon, 9 Dec 2024 17:03:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=82=A3=E8=80=85=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 2 +- .../patientinfo/PatientInfoController.java | 9 +- .../dto/patientinfo/PatientInfoDto.java | 6 + .../patientinfo/IPatientInfoService.java | 4 +- .../impl/PatientInfoServiceImpl.java | 163 +++++++++++------- .../SignPatientManageRouteServiceImpl.java | 8 +- .../manage/vo/patientinfo/PatientInfoVo.java | 13 ++ .../manage/patientinfo/PatientInfoMapper.xml | 6 + 8 files changed, 145 insertions(+), 66 deletions(-) diff --git a/postdischarge-admin/src/main/resources/application.yml b/postdischarge-admin/src/main/resources/application.yml index 2c1ef904..d57513f4 100644 --- a/postdischarge-admin/src/main/resources/application.yml +++ b/postdischarge-admin/src/main/resources/application.yml @@ -108,7 +108,7 @@ token: # 令牌密钥 secret: DIweGcEWJTbvo48dnvOMR8GsDW # 令牌有效期(默认30分钟) - expireTime: 30 + expireTime: 120 # 请求拦截白名单 ant-matchers: /postDischarge/**,/testMobile/**,/postDischargeApplet/**,/api/**,/manage/patientInfoimporttemp/** diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/controller/patientinfo/PatientInfoController.java b/postdischarge-manage/src/main/java/com/xinelu/manage/controller/patientinfo/PatientInfoController.java index 8eb2d4d8..6e08fb32 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/controller/patientinfo/PatientInfoController.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/controller/patientinfo/PatientInfoController.java @@ -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 util = new ExcelUtil<>(PatientInfoImport.class); List list = util.importExcel(file.getInputStream()); - return patientInfoService.patientUpload(list, records, orgName); + return patientInfoService.patientUpload(list, isDistinct, filename); } @ApiOperation("未识别科室名称导入") diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/dto/patientinfo/PatientInfoDto.java b/postdischarge-manage/src/main/java/com/xinelu/manage/dto/patientinfo/PatientInfoDto.java index a5e44313..e6270d92 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/dto/patientinfo/PatientInfoDto.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/dto/patientinfo/PatientInfoDto.java @@ -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; } diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfo/IPatientInfoService.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfo/IPatientInfoService.java index 46b7777e..c37c669a 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfo/IPatientInfoService.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfo/IPatientInfoService.java @@ -94,9 +94,11 @@ public interface IPatientInfoService { * 患者导入 * * @param list 患者信息结合 + * isDistinct==1,表示自动去重;==0表示不去重; + * filename,附件名称 * @return AjaxResult */ - AjaxResult patientUpload(List list,Integer records,String orgName); + AjaxResult patientUpload(List list,Integer isDistinct,String filename); /** * 未识别科室名称导入 diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfo/impl/PatientInfoServiceImpl.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfo/impl/PatientInfoServiceImpl.java index 2f70c86d..041e34d8 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfo/impl/PatientInfoServiceImpl.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfo/impl/PatientInfoServiceImpl.java @@ -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 list, Integer records, String orgName) { - if (CollectionUtils.isEmpty(list) || list.size() == 0) { - return AjaxResult.error("已完成数据导入!导入成功0条记录,失败" + list.size() + "条记录。失败原因:导入用户数据不能为空!"); - } - List 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 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 distinctCollect = list.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList()); - //与数据库重复 - List patientInfos = new ArrayList<>(); - List 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 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 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 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 distinctCollect = list.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList()); + //与数据库重复 + List patientInfos_CurrentDay = new ArrayList<>(); + List 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 departmentList = departmentMapper.selectDepartmentNameCount(department); + PatientInfoImportVO patientInfoImportVO = new PatientInfoImportVO(); List deptAliasVOS = new ArrayList<>(); //组装数据 List patientInfoImportList = new ArrayList<>(); + //要导入的居民信息列表 + List patientInfoImportList_forResident = new ArrayList<>(); for (PatientInfoImport patientInfoImport : distinctCollect) { //选择自动去除当日重复记录 - if (CollectionUtils.isNotEmpty(residentInfos)) { - List 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 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 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 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); } - //新增缓存表 - int insertCount = patientInfoImportMapper.insertPatientInfoImportList(patientInfoImportList); - if (insertCount <= 0) { - log.info("缓存表新增失败!"); - return AjaxResult.error("已完成数据导入!导入成功0条记录,失败" + patientInfoImportVO.getCount() + "条记录。"); - } - //导入记录表 - PatientInfoImportMain patientInfoImportMain = new PatientInfoImportMain(); - patientInfoImportMain.setCreateBy(SecurityUtils.getUsername()); - patientInfoImportMain.setCreateTime(LocalDateTime.now()); - patientInfoImportMain.setSn(sn); - patientInfoImportMain.setHospitalAgencyId(agency.getId()); - patientInfoImportMain.setFileName(orgName); - patientInfoImportMain.setHospitalAgencyName(agency.getAgencyName()); - patientInfoImportMainMapper.insertPatientInfoImportMain(patientInfoImportMain); + //科室名称全符合新增患者表,否则返回数据 if (CollectionUtils.isNotEmpty(deptAliasVOS)) { return AjaxResult.error("科室名称不存在", patientInfoImportVO); } else { - //新增居民表 - patientInfoImportList.forEach(item -> item.setPatientInfoImportId(item.getId())); - int residentCount = residentInfoMapper.insertResidentInfoList(patientInfoImportList); - if (residentCount <= 0) { - log.info("居民表新增失败!"); - return AjaxResult.error("已完成数据导入!导入成功0条记录,失败" + patientInfoImportVO.getCount() + "条记录。"); + //新增缓存表 + int insertCount = patientInfoImportMapper.insertPatientInfoImportList(patientInfoImportList); + if (insertCount <= 0) { + log.info("缓存表新增失败!"); + return AjaxResult.error("数据导入失败!"); } - patientInfoImportList.forEach(item -> item.setResidentId(item.getId())); + //导入记录主表 + //region 导入记录主表 + PatientInfoImportMain patientInfoImportMain = new PatientInfoImportMain(); + patientInfoImportMain.setCreateBy(SecurityUtils.getUsername()); + patientInfoImportMain.setCreateTime(LocalDateTime.now()); + patientInfoImportMain.setSn(sn); + patientInfoImportMain.setHospitalAgencyId(agency.getId()); + patientInfoImportMain.setFileName(fileName); + patientInfoImportMain.setHospitalAgencyName(agency.getAgencyName()); + patientInfoImportMainMapper.insertPatientInfoImportMain(patientInfoImportMain); + //endregion + + //新增居民表 + //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("居民信息新增失败;"); + } + //设置居民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 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()) { diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/signpatientmanageroute/impl/SignPatientManageRouteServiceImpl.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/signpatientmanageroute/impl/SignPatientManageRouteServiceImpl.java index 73fb4432..31507486 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/service/signpatientmanageroute/impl/SignPatientManageRouteServiceImpl.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/signpatientmanageroute/impl/SignPatientManageRouteServiceImpl.java @@ -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()); diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/vo/patientinfo/PatientInfoVo.java b/postdischarge-manage/src/main/java/com/xinelu/manage/vo/patientinfo/PatientInfoVo.java index 4a0b9d8c..72f8589a 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/vo/patientinfo/PatientInfoVo.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/vo/patientinfo/PatientInfoVo.java @@ -21,6 +21,19 @@ public class PatientInfoVo { */ private Long id; + /** + * 导入患者表id + */ + @ApiModelProperty(value = "导入患者表id") + private Long patientInfoImportId; + + /** + * 导入流水号 + */ + @ApiModelProperty(value = "导入流水号") + private String sn; + + /** * 居民信息表id */ diff --git a/postdischarge-manage/src/main/resources/mapper/manage/patientinfo/PatientInfoMapper.xml b/postdischarge-manage/src/main/resources/mapper/manage/patientinfo/PatientInfoMapper.xml index 21f88aef..f1533dcd 100644 --- a/postdischarge-manage/src/main/resources/mapper/manage/patientinfo/PatientInfoMapper.xml +++ b/postdischarge-manage/src/main/resources/mapper/manage/patientinfo/PatientInfoMapper.xml @@ -274,6 +274,12 @@ and p.resident_id = #{residentId} + + and p.patient_info_import_id = #{patientInfoImportId} + + + and p.sn = #{sn} + and p.patient_name = #{patientName}