From 043ee080820226e7a773bb1bf9e4b569477612a4 Mon Sep 17 00:00:00 2001 From: zhangheng <3226558941@qq.com> Date: Tue, 12 May 2026 19:43:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BB=E5=85=B1=E4=BD=93=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExternalImportController.java | 9 + .../PatientInfoImportMainController.java | 9 + .../dto/externalimport/ExternalImportDto.java | 36 ++++ .../PatientInfoImportMainDto.java | 16 ++ .../externalimport/ExternalImportMapper.java | 16 ++ .../IExternalImportService.java | 9 + .../impl/ExternalImportServiceImpl.java | 12 ++ .../IPatientInfoImportMainService.java | 10 + .../PatientInfoImportMainServiceImpl.java | 196 +++++++++++++++++- .../externalImport/ExternalImportMapper.xml | 32 ++- .../MessageSubscriptionController.java | 8 + .../task/MedicalConsortiumPlatformTask.java | 196 ++---------------- 12 files changed, 363 insertions(+), 186 deletions(-) create mode 100644 postdischarge-manage/src/main/java/com/xinelu/manage/dto/externalimport/ExternalImportDto.java create mode 100644 postdischarge-manage/src/main/java/com/xinelu/manage/dto/patientinfoimportmain/PatientInfoImportMainDto.java diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/controller/externalimport/ExternalImportController.java b/postdischarge-manage/src/main/java/com/xinelu/manage/controller/externalimport/ExternalImportController.java index b4ed093f..584b5e39 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/controller/externalimport/ExternalImportController.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/controller/externalimport/ExternalImportController.java @@ -7,6 +7,7 @@ import com.xinelu.common.core.page.TableDataInfo; import com.xinelu.common.enums.BusinessType; import com.xinelu.common.utils.poi.ExcelUtil; import com.xinelu.manage.domain.externalimport.ExternalImport; +import com.xinelu.manage.dto.externalimport.ExternalImportDto; import com.xinelu.manage.service.externalimport.IExternalImportService; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -89,4 +90,12 @@ public class ExternalImportController extends BaseController { public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(externalImportService.deleteExternalImportByIds(ids)); } + + /** + * 查询外部数据导入列表、不分页、sn不为空 + */ + @PostMapping("/externalImports") + public List getExternalImports(ExternalImportDto externalImport) { + return externalImportService.getExternalImports(externalImport); + } } \ No newline at end of file diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/controller/patientinfoimportmain/PatientInfoImportMainController.java b/postdischarge-manage/src/main/java/com/xinelu/manage/controller/patientinfoimportmain/PatientInfoImportMainController.java index f48dc662..95e2ba32 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/controller/patientinfoimportmain/PatientInfoImportMainController.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/controller/patientinfoimportmain/PatientInfoImportMainController.java @@ -5,6 +5,7 @@ import com.xinelu.common.core.controller.BaseController; import com.xinelu.common.core.domain.AjaxResult; import com.xinelu.common.core.page.TableDataInfo; import com.xinelu.manage.domain.dialtime.DialTime; +import com.xinelu.manage.dto.patientinfoimportmain.PatientInfoImportMainDto; import com.xinelu.manage.service.patientinfoimportmain.IPatientInfoImportMainService; import com.xinelu.manage.vo.patientinfo.PatientInfoVo; import com.xinelu.manage.vo.patientinfoimportmain.PatientInfoImportMainVO; @@ -73,4 +74,12 @@ public class PatientInfoImportMainController extends BaseController { public AjaxResult add(@RequestBody DialTime dialTime) { return patientInfoImportMainService.insertDialTime(dialTime); } + + /** + * 手动创建患者导入信息 + */ + @PostMapping("/manuallyCreate") + public AjaxResult manuallyCreate(@RequestBody PatientInfoImportMainDto patientInfoImportMainDto) { + return patientInfoImportMainService.manuallyCreate(patientInfoImportMainDto); + } } diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/dto/externalimport/ExternalImportDto.java b/postdischarge-manage/src/main/java/com/xinelu/manage/dto/externalimport/ExternalImportDto.java new file mode 100644 index 00000000..4282b978 --- /dev/null +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/dto/externalimport/ExternalImportDto.java @@ -0,0 +1,36 @@ +package com.xinelu.manage.dto.externalimport; + +import com.xinelu.manage.domain.externalimport.ExternalImport; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDate; +import java.util.List; + +@EqualsAndHashCode(callSuper = true) +@Data +public class ExternalImportDto extends ExternalImport { + + @ApiModelProperty(value = "就诊开始时间") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDate visitDateStart; + + @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDate visitDateEnd; + + @ApiModelProperty(value = "出院开始时间") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDate dischargeDateStart; + + @ApiModelProperty(value = "出院结束时间") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDate dischargeDateEnd; + + @ApiModelProperty(value = "就诊方式,门诊:1,住院:2") + private String visitMethod; + + @ApiModelProperty(value = "科室集合") + private List departmentNameList; +} diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/dto/patientinfoimportmain/PatientInfoImportMainDto.java b/postdischarge-manage/src/main/java/com/xinelu/manage/dto/patientinfoimportmain/PatientInfoImportMainDto.java new file mode 100644 index 00000000..52bd7429 --- /dev/null +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/dto/patientinfoimportmain/PatientInfoImportMainDto.java @@ -0,0 +1,16 @@ +package com.xinelu.manage.dto.patientinfoimportmain; + +import com.xinelu.manage.domain.externalimport.ExternalImport; +import com.xinelu.manage.domain.patientinfoimportmain.PatientInfoImportMain; +import lombok.Data; + +import java.util.List; + +/** + * 手动创建患者导入信息 + */ +@Data +public class PatientInfoImportMainDto extends PatientInfoImportMain { + + List externalImports; +} \ No newline at end of file diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/externalimport/ExternalImportMapper.java b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/externalimport/ExternalImportMapper.java index 50a3de44..29c51853 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/externalimport/ExternalImportMapper.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/externalimport/ExternalImportMapper.java @@ -1,6 +1,7 @@ package com.xinelu.manage.mapper.externalimport; import com.xinelu.manage.domain.externalimport.ExternalImport; +import com.xinelu.manage.dto.externalimport.ExternalImportDto; import java.util.List; @@ -74,4 +75,19 @@ public interface ExternalImportMapper { * @return ExternalImport */ List selectExternalByPhone(List phones); + + /** + * 查询外部数据导入列表、不分页、sn不为空 + * + * @param externalImport 导入列表 + * @return ExternalImport + */ + List getExternalImports(ExternalImportDto externalImport); + + /** + * 查询医共体数据数量 + * + * @return Long + */ + Long getExternalImportCount(); } \ No newline at end of file diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/externalimport/IExternalImportService.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/externalimport/IExternalImportService.java index 0a84f624..7c445b59 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/service/externalimport/IExternalImportService.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/externalimport/IExternalImportService.java @@ -1,6 +1,7 @@ package com.xinelu.manage.service.externalimport; import com.xinelu.manage.domain.externalimport.ExternalImport; +import com.xinelu.manage.dto.externalimport.ExternalImportDto; import java.util.List; @@ -58,4 +59,12 @@ public interface IExternalImportService { * @return 结果 */ int deleteExternalImportById(Long id); + + /** + * 查询外部数据导入列表、不分页、sn不为空 + * + * @param externalImport 导入列表 + * @return ExternalImport + */ + List getExternalImports(ExternalImportDto externalImport); } \ No newline at end of file diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/externalimport/impl/ExternalImportServiceImpl.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/externalimport/impl/ExternalImportServiceImpl.java index fe3cd015..2a8ef7d8 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/service/externalimport/impl/ExternalImportServiceImpl.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/externalimport/impl/ExternalImportServiceImpl.java @@ -1,6 +1,7 @@ package com.xinelu.manage.service.externalimport.impl; import com.xinelu.manage.domain.externalimport.ExternalImport; +import com.xinelu.manage.dto.externalimport.ExternalImportDto; import com.xinelu.manage.mapper.externalimport.ExternalImportMapper; import com.xinelu.manage.service.externalimport.IExternalImportService; import org.springframework.stereotype.Service; @@ -85,4 +86,15 @@ public class ExternalImportServiceImpl implements IExternalImportService { public int deleteExternalImportById(Long id) { return externalImportMapper.deleteExternalImportById(id); } + + /** + * 查询外部数据导入列表、不分页、sn不为空 + * + * @param externalImport 导入列表 + * @return ExternalImport + */ + @Override + public List getExternalImports(ExternalImportDto externalImport) { + return externalImportMapper.getExternalImports(externalImport); + } } \ No newline at end of file diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfoimportmain/IPatientInfoImportMainService.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfoimportmain/IPatientInfoImportMainService.java index 0c27aef2..ad09c91a 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfoimportmain/IPatientInfoImportMainService.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfoimportmain/IPatientInfoImportMainService.java @@ -3,6 +3,7 @@ package com.xinelu.manage.service.patientinfoimportmain; import com.xinelu.common.core.domain.AjaxResult; import com.xinelu.manage.domain.dialtime.DialTime; +import com.xinelu.manage.dto.patientinfoimportmain.PatientInfoImportMainDto; import com.xinelu.manage.vo.patientinfo.PatientInfoVo; import com.xinelu.manage.vo.patientinfoimportmain.PatientInfoImportMainVO; @@ -42,4 +43,13 @@ public interface IPatientInfoImportMainService { * @return 结果 */ AjaxResult insertDialTime(DialTime dialTime); + + /** + * + * 手动创建患者导入信息 + * + * @param patientInfoImportMainDto 患者导入信息 + * @return AjaxResult + */ + AjaxResult manuallyCreate(PatientInfoImportMainDto patientInfoImportMainDto); } diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfoimportmain/impl/PatientInfoImportMainServiceImpl.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfoimportmain/impl/PatientInfoImportMainServiceImpl.java index 88a48d73..aae4761c 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfoimportmain/impl/PatientInfoImportMainServiceImpl.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/patientinfoimportmain/impl/PatientInfoImportMainServiceImpl.java @@ -1,28 +1,53 @@ package com.xinelu.manage.service.patientinfoimportmain.impl; import com.xinelu.common.annotation.DataScope; +import com.xinelu.common.constant.Constants; +import com.xinelu.common.constant.VisitMethodConstants; import com.xinelu.common.core.domain.AjaxResult; import com.xinelu.common.core.domain.entity.SysUser; +import com.xinelu.common.enums.ImportStatusEnum; +import com.xinelu.common.enums.NodeTypeEnum; +import com.xinelu.common.enums.PatientTypeEnum; import com.xinelu.common.utils.SecurityUtils; +import com.xinelu.common.utils.bean.BeanUtils; +import com.xinelu.common.utils.codes.GenerateSystemCodeUtil; import com.xinelu.manage.domain.agency.Agency; +import com.xinelu.manage.domain.department.Department; import com.xinelu.manage.domain.dialtime.DialTime; +import com.xinelu.manage.domain.externalimport.ExternalImport; +import com.xinelu.manage.domain.patientinfoimport.PatientInfoImport; +import com.xinelu.manage.domain.patientinfoimportmain.PatientInfoImportMain; +import com.xinelu.manage.domain.patientvisitrecord.PatientVisitRecord; +import com.xinelu.manage.domain.residentinfo.ResidentInfo; +import com.xinelu.manage.dto.patientinfoimportmain.PatientInfoImportMainDto; import com.xinelu.manage.mapper.agency.AgencyMapper; +import com.xinelu.manage.mapper.department.DepartmentMapper; +import com.xinelu.manage.mapper.patientinfo.PatientInfoMapper; +import com.xinelu.manage.mapper.patientinfoimport.PatientInfoImportMapper; import com.xinelu.manage.mapper.patientinfoimportmain.PatientInfoImportMainMapper; +import com.xinelu.manage.mapper.patientvisitrecord.PatientVisitRecordMapper; +import com.xinelu.manage.mapper.residentinfo.ResidentInfoMapper; import com.xinelu.manage.service.patientinfoimportmain.IPatientInfoImportMainService; import com.xinelu.manage.vo.patientinfo.PatientInfoVo; import com.xinelu.manage.vo.patientinfoimportmain.PatientInfoImportMainVO; import com.xinelu.system.mapper.SysUserMapper; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; - +@Slf4j @Service public class PatientInfoImportMainServiceImpl implements IPatientInfoImportMainService { @@ -32,6 +57,20 @@ public class PatientInfoImportMainServiceImpl implements IPatientInfoImportMainS private SysUserMapper sysUserMapper; @Resource private AgencyMapper agencyMapper; + @Resource + private DepartmentMapper departmentMapper; + @Value("${xinyilu-database.main_hospital}") + private Long mainHospitalId; + @Resource + private GenerateSystemCodeUtil generateSystemCodeUtil; + @Resource + private PatientInfoImportMapper patientInfoImportMapper; + @Resource + private ResidentInfoMapper residentInfoMapper; + @Resource + private PatientInfoMapper patientInfoMapper; + @Resource + private PatientVisitRecordMapper patientVisitRecordMapper; @DataScope(agencyAlias = "p") @@ -133,4 +172,159 @@ public class PatientInfoImportMainServiceImpl implements IPatientInfoImportMainS dialTime.setCreateBy(SecurityUtils.getUsername()); return AjaxResult.success(patientInfoImportMainMapper.insertDialTime(dialTime)); } + + /** + * 手动创建患者导入信息 + * + * @param patientInfoImportMainDto 患者导入信息 + * @return AjaxResult + */ + @Override + public AjaxResult manuallyCreate(PatientInfoImportMainDto patientInfoImportMainDto) { + //新增导入信息 + Agency agency = agencyMapper.selectAgencyById(mainHospitalId); + List departments = new ArrayList<>(); + List difference; + Department department = new Department(); + department.setHospitalAgencyId(mainHospitalId); + //科室信息组装-新增不存在科室 + List departmentList = departmentMapper.selectDepartmentNameCount(department); + List importDepartmentName = patientInfoImportMainDto.getExternalImports().stream().filter(Objects::nonNull).map(ExternalImport::getDepartmentName).distinct().collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(departmentList)) { + List dateDepartmentName = departmentList.stream().filter(Objects::nonNull).map(Department::getDepartmentName).distinct().collect(Collectors.toList()); + difference = importDepartmentName.stream().filter(element -> !dateDepartmentName.contains(element)).collect(Collectors.toList()); + } else { + difference = importDepartmentName; + } + if (CollectionUtils.isNotEmpty(difference) || difference.size() > 0) { + for (String s : difference) { + Department newDepartment = new Department(); + newDepartment.setParentDepartmentId(0L); + newDepartment.setNodeType(NodeTypeEnum.DEPARTMENT.getInfo()); + newDepartment.setDepartmentName(s); + newDepartment.setDepartmentCode(Constants.DEPARTMENT_IMPORT_CODE + generateSystemCodeUtil.generateSystemCode(Constants.DEPARTMENT_IMPORT_CODE)); + newDepartment.setHospitalAgencyName(agency.getAgencyName()); + newDepartment.setHospitalAgencyId(agency.getId()); + newDepartment.setCreateTime(LocalDateTime.now()); + newDepartment.setCreateBy("数据导入"); + departments.add(newDepartment); + } + departmentMapper.insertPartDepartmentList(departments); + departmentList.addAll(departments); + } + //新增导入信息 + PatientInfoImportMain patientInfoImportMain = new PatientInfoImportMain(); + patientInfoImportMain.setHospitalAgencyId(agency.getId()); + patientInfoImportMain.setHospitalAgencyName(agency.getAgencyName()); + patientInfoImportMain.setCreateBy(SecurityUtils.getUsername()); + patientInfoImportMain.setCreateTime(LocalDateTime.now()); + String sn = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); + patientInfoImportMain.setSn(sn); + patientInfoImportMain.setImportStatus(ImportStatusEnum.UNFINISHED.getInfo()); + patientInfoImportMain.setImportName(LocalDate.now() + "医共体获取数据"); + patientInfoImportMainMapper.insertPatientInfoImportMain(patientInfoImportMain); + List patientInfoImportList = new ArrayList<>(); + Long i = 1L; + for (ExternalImport externalImport : patientInfoImportMainDto.getExternalImports()) { + PatientInfoImport patientInfoImport = new PatientInfoImport(); + externalImport.setSn(sn); + if (Objects.nonNull(externalImport.getVisitDate())) { + patientInfoImport.setVisitDate(externalImport.getVisitDate().toLocalDate()); + } + //导入数据 + patientInfoImport.setOrderNum(i); + i++; + patientInfoImport.setDepartmentName(externalImport.getDepartmentName()); + patientInfoImport.setInHospitalNumber(externalImport.getVisitCode()); + patientInfoImport.setPatientName(externalImport.getPatientName()); + patientInfoImport.setCardNo(externalImport.getCardNo()); + patientInfoImport.setAge(Integer.valueOf(externalImport.getAge())); + if (externalImport.getVisitMethod().equals("1")) { + patientInfoImport.setPatientType(PatientTypeEnum.OUTPATIENT.getInfo()); + patientInfoImport.setVisitMethod(VisitMethodConstants.OUTPATIENT_SERVICE); + } + if (externalImport.getVisitMethod().equals("2")) { + patientInfoImport.setPatientType(PatientTypeEnum.IN_HOSPITAL_PATIENT.getInfo()); + patientInfoImport.setVisitMethod(VisitMethodConstants.BE_IN_HOSPITAL); + } + patientInfoImport.setMainDiagnosis(externalImport.getMainDiagnosis()); + patientInfoImport.setPatientPhone(externalImport.getPhone()); + patientInfoImport.setSn(sn); + patientInfoImport.setCreateBy(SecurityUtils.getUsername()); + patientInfoImport.setCreateTime(LocalDateTime.now()); + patientInfoImport.setHospitalAgencyId(agency.getId()); + patientInfoImport.setHospitalAgencyName(agency.getAgencyName()); + if (CollectionUtils.isNotEmpty(departmentList)) { + Department equalsDepartment = departmentList.stream().filter(Objects::nonNull).filter(item -> externalImport.getDepartmentName().equals(item.getDepartmentName())).findFirst().orElse(new Department()); + //科室名称一致塞值 + if (Objects.nonNull(equalsDepartment.getId())) { + patientInfoImport.setDepartmentId(equalsDepartment.getId()); + patientInfoImport.setDepartmentName(equalsDepartment.getDepartmentName()); + } + } + patientInfoImportList.add(patientInfoImport); + } + //新增缓存表 + patientInfoImportMapper.insertPatientInfoImportList(patientInfoImportList); + List residentInfos = residentInfoMapper.selectResidentInfoByPhoneList(patientInfoImportList); + List resident = new ArrayList<>(); + patientInfoImportList.forEach(item -> { + //设置导入记录ID + item.setPatientInfoImportId(item.getId()); + if (StringUtils.isNotBlank(item.getPatientPhone())) { + //居民信息根据姓名和手机号去重 + if (residentInfos.stream().filter(residentInfo -> residentInfo.getPatientName().equals(item.getPatientName()) + && residentInfo.getPatientPhone().equals(item.getPatientPhone())).collect(Collectors.toSet()).size() == 0) { + resident.add(item); + } else { + item.setResidentId(residentInfos.stream().filter(residentInfo -> residentInfo.getPatientName().equals(item.getPatientName()) + && residentInfo.getPatientPhone().equals(item.getPatientPhone())).findFirst().orElse(new ResidentInfo()).getId()); + } + } + } + ); + if (resident.size() > 0) { + //去重 + List residents = new ArrayList<>(resident.stream().collect(Collectors.toMap( + companyVo -> companyVo.getPatientName() + "-" + companyVo.getPatientPhone(), + companyVo -> companyVo, + (existing, replacement) -> existing + )).values()); + int residentCount = residentInfoMapper.insertResidentInfoList(residents); + if (residentCount <= 0) { + log.info("居民表新增失败!"); + } + for (PatientInfoImport patientInfoImport : patientInfoImportList) { + if (Objects.isNull(patientInfoImport.getResidentId())) { + PatientInfoImport patientInfoImport1 = residents.stream().filter(item -> patientInfoImport.getPatientPhone().equals(item.getPatientPhone()) && patientInfoImport.getPatientName().equals(item.getPatientName())).findFirst().orElse(new PatientInfoImport()); + if (Objects.nonNull(patientInfoImport1.getId())) { + patientInfoImport.setResidentId(patientInfoImport1.getId()); + } + } + } + } + //新增患者表 + int insertPatientInfo = patientInfoMapper.insertPatientInfoList(patientInfoImportList); + if (insertPatientInfo <= 0) { + log.info("患者表新增失败!"); + } + patientInfoImportList.forEach(item -> item.setPatientInfoId(item.getId())); + //新增就诊记录表 + List patientVisitRecords = new ArrayList<>(); + for (PatientInfoImport patientInfoImport : patientInfoImportList) { + PatientVisitRecord patientVisitRecord = new PatientVisitRecord(); + patientVisitRecord.setPatientId(patientInfoImport.getPatientInfoId()); + patientVisitRecord.setResidentId(patientInfoImport.getResidentId()); + BeanUtils.copyProperties(patientInfoImport, patientVisitRecord); + patientVisitRecord.setDelFlag(0); + patientVisitRecord.setCreateBy("数据导入"); + patientVisitRecord.setCreateTime(LocalDateTime.now()); + patientVisitRecords.add(patientVisitRecord); + } + int patientVisitRecordCount = patientVisitRecordMapper.insertPatientVisitRecordList(patientVisitRecords); + if (patientVisitRecordCount <= 0) { + log.info("就诊记录表新增失败!"); + } + return AjaxResult.success(); + } } diff --git a/postdischarge-manage/src/main/resources/mapper/manage/externalImport/ExternalImportMapper.xml b/postdischarge-manage/src/main/resources/mapper/manage/externalImport/ExternalImportMapper.xml index 51efa744..62120c4e 100644 --- a/postdischarge-manage/src/main/resources/mapper/manage/externalImport/ExternalImportMapper.xml +++ b/postdischarge-manage/src/main/resources/mapper/manage/externalImport/ExternalImportMapper.xml @@ -186,7 +186,7 @@ - + insert into external_import( patient_name, phone, @@ -317,4 +317,34 @@ #{phones} + + + + \ No newline at end of file diff --git a/postdischarge-quartz/src/main/java/com/xinelu/quartz/controller/MessageSubscriptionController.java b/postdischarge-quartz/src/main/java/com/xinelu/quartz/controller/MessageSubscriptionController.java index 750c442f..cd6812e9 100644 --- a/postdischarge-quartz/src/main/java/com/xinelu/quartz/controller/MessageSubscriptionController.java +++ b/postdischarge-quartz/src/main/java/com/xinelu/quartz/controller/MessageSubscriptionController.java @@ -1,6 +1,7 @@ package com.xinelu.quartz.controller; import com.xinelu.quartz.domain.TbFollowUp; +import com.xinelu.quartz.task.MedicalConsortiumPlatformTask; import com.xinelu.quartz.task.SubscribeTask; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -23,6 +24,8 @@ public class MessageSubscriptionController { @Resource private SubscribeTask subscribeTask; + @Resource + private MedicalConsortiumPlatformTask medicalConsortiumPlatformTask; /** * 手动执行专病路径定时任务 @@ -82,4 +85,9 @@ public class MessageSubscriptionController { e.printStackTrace(); } } + + @PostMapping("/bbb") + public void bbb(){ + medicalConsortiumPlatformTask.medicalConsortiumPlatformTask(); + } } diff --git a/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/MedicalConsortiumPlatformTask.java b/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/MedicalConsortiumPlatformTask.java index 0069581e..006f134a 100644 --- a/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/MedicalConsortiumPlatformTask.java +++ b/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/MedicalConsortiumPlatformTask.java @@ -1,29 +1,8 @@ package com.xinelu.quartz.task; -import com.xinelu.common.constant.Constants; -import com.xinelu.common.constant.VisitMethodConstants; -import com.xinelu.common.enums.ImportStatusEnum; -import com.xinelu.common.enums.NodeTypeEnum; -import com.xinelu.common.enums.PatientTypeEnum; -import com.xinelu.common.utils.bean.BeanUtils; -import com.xinelu.common.utils.codes.GenerateSystemCodeUtil; -import com.xinelu.manage.domain.agency.Agency; -import com.xinelu.manage.domain.department.Department; import com.xinelu.manage.domain.externalimport.ExternalImport; -import com.xinelu.manage.domain.patientinfoimport.PatientInfoImport; -import com.xinelu.manage.domain.patientinfoimportmain.PatientInfoImportMain; -import com.xinelu.manage.domain.patientvisitrecord.PatientVisitRecord; -import com.xinelu.manage.domain.residentinfo.ResidentInfo; -import com.xinelu.manage.mapper.agency.AgencyMapper; -import com.xinelu.manage.mapper.department.DepartmentMapper; import com.xinelu.manage.mapper.externalimport.ExternalImportMapper; -import com.xinelu.manage.mapper.patientinfo.PatientInfoMapper; -import com.xinelu.manage.mapper.patientinfoimport.PatientInfoImportMapper; -import com.xinelu.manage.mapper.patientinfoimportmain.PatientInfoImportMainMapper; -import com.xinelu.manage.mapper.patientvisitrecord.PatientVisitRecordMapper; -import com.xinelu.manage.mapper.residentinfo.ResidentInfoMapper; import com.xinelu.quartz.domain.TbFollowUp; -import com.xinelu.system.mapper.SysUserMapper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -55,33 +34,18 @@ public class MedicalConsortiumPlatformTask { @Resource private ExternalImportMapper externalImportMapper; - @Resource - private SysUserMapper sysUserMapper; - @Resource - private AgencyMapper agencyMapper; - @Resource - private PatientInfoImportMainMapper patientInfoImportMainMapper; - @Resource - private PatientInfoImportMapper patientInfoImportMapper; - @Resource - private ResidentInfoMapper residentInfoMapper; - @Resource - private PatientInfoMapper patientInfoMapper; - @Resource - private PatientVisitRecordMapper patientVisitRecordMapper; - @Resource - private DepartmentMapper departmentMapper; - @Resource - private GenerateSystemCodeUtil generateSystemCodeUtil; + @Value("${xinyilu-database.main_hospital}") - private Long mainHospitalId; - static String sql = "SELECT * FROM tb_follow_up"; + + static final String sql = "SELECT * FROM tb_follow_up"; + static final String sql_date = "SELECT * FROM tb_follow_up where TSXJ > TO_DATE('" + LocalDate.now() + "', 'YYYY-MM-DD HH24:MI:SS') AND TSXJ < TO_DATE('" + LocalDate.now().plusDays(1) + "', 'YYYY-MM-DD HH24:MI:SS')"; @Transactional(rollbackFor = Exception.class) public void medicalConsortiumPlatformTask() { log.info("开始获取医共体数据,时间:" + LocalDateTime.now()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); List list = new ArrayList<>(); + Long externalImportCount = externalImportMapper.getExternalImportCount(); //获取数据 try { // 1.加载驱动 @@ -89,7 +53,12 @@ public class MedicalConsortiumPlatformTask { // 2.获取连接 Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@//172.19.116.212:1521/ORCL", "HK_ZJK", "DYWJWhkzjk5169"); // 3.创建Statement对象(可以执行sql的对象) - PreparedStatement preparedStatement = connection.prepareStatement(sql); + PreparedStatement preparedStatement; + if (externalImportCount > 0) { + preparedStatement = connection.prepareStatement(sql_date); + } else { + preparedStatement = connection.prepareStatement(sql); + } // 4.获取结果集 ResultSet resultSet = preparedStatement.executeQuery(); // 5.对数据进行处理 @@ -134,49 +103,6 @@ public class MedicalConsortiumPlatformTask { //筛选就诊号并根据就诊号查询数据库 List dataExternalImports = externalImportMapper.selectExternalByPhone(collect); List externalImports = new ArrayList<>(); - //科室信息组装-新增不存在科室 - Agency agency = agencyMapper.selectAgencyById(mainHospitalId); - List departments = new ArrayList<>(); - List difference; - Department department = new Department(); - department.setHospitalAgencyId(mainHospitalId); - List departmentList = departmentMapper.selectDepartmentNameCount(department); - List importDepartmentName = list.stream().filter(Objects::nonNull).map(TbFollowUp::getJZKSMC).distinct().collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(departmentList)) { - List dateDepartmentName = departmentList.stream().filter(Objects::nonNull).map(Department::getDepartmentName).distinct().collect(Collectors.toList()); - difference = importDepartmentName.stream().filter(element -> !dateDepartmentName.contains(element)).collect(Collectors.toList()); - } else { - difference = importDepartmentName; - } - if (CollectionUtils.isNotEmpty(difference) || difference.size() > 0) { - for (String s : difference) { - Department newDepartment = new Department(); - newDepartment.setParentDepartmentId(0L); - newDepartment.setNodeType(NodeTypeEnum.DEPARTMENT.getInfo()); - newDepartment.setDepartmentName(s); - newDepartment.setDepartmentCode(Constants.DEPARTMENT_IMPORT_CODE + generateSystemCodeUtil.generateSystemCode(Constants.DEPARTMENT_IMPORT_CODE)); - newDepartment.setHospitalAgencyName(agency.getAgencyName()); - newDepartment.setHospitalAgencyId(agency.getId()); - newDepartment.setCreateTime(LocalDateTime.now()); - newDepartment.setCreateBy("数据导入"); - departments.add(newDepartment); - } - departmentMapper.insertPartDepartmentList(departments); - departmentList.addAll(departments); - } - //新增导入信息 - PatientInfoImportMain patientInfoImportMain = new PatientInfoImportMain(); - patientInfoImportMain.setHospitalAgencyId(agency.getId()); - patientInfoImportMain.setHospitalAgencyName(agency.getAgencyName()); - patientInfoImportMain.setCreateBy("数据导入"); - patientInfoImportMain.setCreateTime(LocalDateTime.now()); - String sn = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); - patientInfoImportMain.setSn(sn); - patientInfoImportMain.setImportStatus(ImportStatusEnum.FINISHED.getInfo()); - patientInfoImportMain.setImportName(LocalDate.now() + "医共体获取数据"); - patientInfoImportMainMapper.insertPatientInfoImportMain(patientInfoImportMain); - List patientInfoImportList = new ArrayList<>(); - Long i = 1L; //遍历塞数据 for (TbFollowUp tbFollowUp : list) { //去除与数据库重复项 @@ -188,9 +114,7 @@ public class MedicalConsortiumPlatformTask { if (StringUtils.isNotBlank(identicalVisitCode.getPhone())) { continue; } - PatientInfoImport patientInfoImport = new PatientInfoImport(); ExternalImport externalImport = new ExternalImport(); - externalImport.setSn(sn); externalImport.setPatientName(tbFollowUp.getXM()); externalImport.setPhone(tbFollowUp.getLXDH()); externalImport.setAge(tbFollowUp.getNL()); @@ -201,7 +125,6 @@ public class MedicalConsortiumPlatformTask { externalImport.setVisitMethod(tbFollowUp.getMZZYBZ()); if (Objects.nonNull(tbFollowUp.getJZSJ())) { externalImport.setVisitDate(LocalDateTime.parse(tbFollowUp.getJZSJ(), formatter)); - patientInfoImport.setVisitDate(LocalDate.parse(tbFollowUp.getJZSJ(), formatter)); } if (Objects.nonNull(tbFollowUp.getRYSJ())) { externalImport.setAdmissionTime(LocalDateTime.parse(tbFollowUp.getRYSJ(), formatter)); @@ -224,103 +147,8 @@ public class MedicalConsortiumPlatformTask { externalImport.setDischargeMethod(tbFollowUp.getLYFS()); externalImport.setDataGetTime(LocalDateTime.now()); externalImports.add(externalImport); - //导入数据 - patientInfoImport.setOrderNum(i); - i++; - patientInfoImport.setDepartmentName(tbFollowUp.getJZKSMC()); - patientInfoImport.setInHospitalNumber(tbFollowUp.getJZLSH()); - patientInfoImport.setPatientName(tbFollowUp.getXM()); - patientInfoImport.setCardNo(tbFollowUp.getZJHM()); - if (StringUtils.isNotBlank(tbFollowUp.getNL())) { - patientInfoImport.setAge(Integer.valueOf(tbFollowUp.getNL())); - } - if (tbFollowUp.getMZZYBZ().equals("1")) { - patientInfoImport.setPatientType(PatientTypeEnum.OUTPATIENT.getInfo()); - patientInfoImport.setVisitMethod(VisitMethodConstants.OUTPATIENT_SERVICE); - } else { - patientInfoImport.setPatientType(PatientTypeEnum.IN_HOSPITAL_PATIENT.getInfo()); - patientInfoImport.setVisitMethod(VisitMethodConstants.BE_IN_HOSPITAL); - } - patientInfoImport.setMainDiagnosis(tbFollowUp.getJZZDSM()); - patientInfoImport.setPatientPhone(tbFollowUp.getLXDH()); - patientInfoImport.setSn(sn); - patientInfoImport.setCreateBy("数据导入"); - patientInfoImport.setCreateTime(LocalDateTime.now()); - patientInfoImport.setHospitalAgencyId(agency.getId()); - patientInfoImport.setHospitalAgencyName(agency.getAgencyName()); - if (CollectionUtils.isNotEmpty(departmentList)) { - Department equalsDepartment = departmentList.stream().filter(Objects::nonNull).filter(item -> tbFollowUp.getJZKSMC().equals(item.getDepartmentName())).findFirst().orElse(new Department()); - //科室名称一致塞值 - if (Objects.nonNull(equalsDepartment.getId())) { - patientInfoImport.setDepartmentId(equalsDepartment.getId()); - patientInfoImport.setDepartmentName(equalsDepartment.getDepartmentName()); - } - } - patientInfoImportList.add(patientInfoImport); } externalImportMapper.insertExternalImportList(externalImports); - log.info("获取医共体数据,共" + externalImports.size() + "条"); - //新增缓存表 - patientInfoImportMapper.insertPatientInfoImportList(patientInfoImportList); - List residentInfos = residentInfoMapper.selectResidentInfoByPhoneList(patientInfoImportList); - List resident = new ArrayList<>(); - patientInfoImportList.forEach(item -> { - //设置导入记录ID - item.setPatientInfoImportId(item.getId()); - if (StringUtils.isNotBlank(item.getPatientPhone())) { - //居民信息根据姓名和手机号去重 - if (residentInfos.stream().filter(residentInfo -> residentInfo.getPatientName().equals(item.getPatientName()) - && residentInfo.getPatientPhone().equals(item.getPatientPhone())).collect(Collectors.toSet()).size() == 0) { - resident.add(item); - } else { - item.setResidentId(residentInfos.stream().filter(residentInfo -> residentInfo.getPatientName().equals(item.getPatientName()) - && residentInfo.getPatientPhone().equals(item.getPatientPhone())).findFirst().orElse(new ResidentInfo()).getId()); - } - } - } - ); - if (resident.size() > 0) { - //去重 - List residents = new ArrayList<>(resident.stream().collect(Collectors.toMap( - companyVo -> companyVo.getPatientName() + "-" + companyVo.getPatientPhone(), - companyVo -> companyVo, - (existing, replacement) -> existing - )).values()); - int residentCount = residentInfoMapper.insertResidentInfoList(residents); - if (residentCount <= 0) { - log.info("居民表新增失败!"); - } - for (PatientInfoImport patientInfoImport : patientInfoImportList) { - if (Objects.isNull(patientInfoImport.getResidentId())) { - PatientInfoImport patientInfoImport1 = residents.stream().filter(item -> patientInfoImport.getPatientPhone().equals(item.getPatientPhone()) && patientInfoImport.getPatientName().equals(item.getPatientName())).findFirst().orElse(new PatientInfoImport()); - if (Objects.nonNull(patientInfoImport1.getId())) { - patientInfoImport.setResidentId(patientInfoImport1.getId()); - } - } - } - } - //新增患者表 - int insertPatientInfo = patientInfoMapper.insertPatientInfoList(patientInfoImportList); - if (insertPatientInfo <= 0) { - log.info("患者表新增失败!"); - } - patientInfoImportList.forEach(item -> item.setPatientInfoId(item.getId())); - //新增就诊记录表 - List patientVisitRecords = new ArrayList<>(); - for (PatientInfoImport patientInfoImport : patientInfoImportList) { - PatientVisitRecord patientVisitRecord = new PatientVisitRecord(); - patientVisitRecord.setPatientId(patientInfoImport.getPatientInfoId()); - patientVisitRecord.setResidentId(patientInfoImport.getResidentId()); - BeanUtils.copyProperties(patientInfoImport, patientVisitRecord); - patientVisitRecord.setDelFlag(0); - patientVisitRecord.setCreateBy("数据导入"); - patientVisitRecord.setCreateTime(LocalDateTime.now()); - patientVisitRecords.add(patientVisitRecord); - } - int patientVisitRecordCount = patientVisitRecordMapper.insertPatientVisitRecordList(patientVisitRecords); - if (patientVisitRecordCount <= 0) { - log.info("就诊记录表新增失败!"); - } - log.info("获取医共体数据完成"); + log.info("获取医共体数据完成,共" + externalImports.size() + "条"); } } \ No newline at end of file