医共体导入修改

This commit is contained in:
zhangheng 2026-05-12 19:43:21 +08:00
parent 2512533dc3
commit 043ee08082
12 changed files with 363 additions and 186 deletions

View File

@ -7,6 +7,7 @@ import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType; import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil; import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.externalimport.ExternalImport; import com.xinelu.manage.domain.externalimport.ExternalImport;
import com.xinelu.manage.dto.externalimport.ExternalImportDto;
import com.xinelu.manage.service.externalimport.IExternalImportService; import com.xinelu.manage.service.externalimport.IExternalImportService;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -89,4 +90,12 @@ public class ExternalImportController extends BaseController {
public AjaxResult remove(@PathVariable Long[] ids) { public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(externalImportService.deleteExternalImportByIds(ids)); return toAjax(externalImportService.deleteExternalImportByIds(ids));
} }
/**
* 查询外部数据导入列表不分页sn不为空
*/
@PostMapping("/externalImports")
public List<ExternalImport> getExternalImports(ExternalImportDto externalImport) {
return externalImportService.getExternalImports(externalImport);
}
} }

View File

@ -5,6 +5,7 @@ import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult; import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo; import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.manage.domain.dialtime.DialTime; 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.service.patientinfoimportmain.IPatientInfoImportMainService;
import com.xinelu.manage.vo.patientinfo.PatientInfoVo; import com.xinelu.manage.vo.patientinfo.PatientInfoVo;
import com.xinelu.manage.vo.patientinfoimportmain.PatientInfoImportMainVO; import com.xinelu.manage.vo.patientinfoimportmain.PatientInfoImportMainVO;
@ -73,4 +74,12 @@ public class PatientInfoImportMainController extends BaseController {
public AjaxResult add(@RequestBody DialTime dialTime) { public AjaxResult add(@RequestBody DialTime dialTime) {
return patientInfoImportMainService.insertDialTime(dialTime); return patientInfoImportMainService.insertDialTime(dialTime);
} }
/**
* 手动创建患者导入信息
*/
@PostMapping("/manuallyCreate")
public AjaxResult manuallyCreate(@RequestBody PatientInfoImportMainDto patientInfoImportMainDto) {
return patientInfoImportMainService.manuallyCreate(patientInfoImportMainDto);
}
} }

View File

@ -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<String> departmentNameList;
}

View File

@ -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<ExternalImport> externalImports;
}

View File

@ -1,6 +1,7 @@
package com.xinelu.manage.mapper.externalimport; package com.xinelu.manage.mapper.externalimport;
import com.xinelu.manage.domain.externalimport.ExternalImport; import com.xinelu.manage.domain.externalimport.ExternalImport;
import com.xinelu.manage.dto.externalimport.ExternalImportDto;
import java.util.List; import java.util.List;
@ -74,4 +75,19 @@ public interface ExternalImportMapper {
* @return ExternalImport * @return ExternalImport
*/ */
List<ExternalImport> selectExternalByPhone(List<String> phones); List<ExternalImport> selectExternalByPhone(List<String> phones);
/**
* 查询外部数据导入列表不分页sn不为空
*
* @param externalImport 导入列表
* @return ExternalImport
*/
List<ExternalImport> getExternalImports(ExternalImportDto externalImport);
/**
* 查询医共体数据数量
*
* @return Long
*/
Long getExternalImportCount();
} }

View File

@ -1,6 +1,7 @@
package com.xinelu.manage.service.externalimport; package com.xinelu.manage.service.externalimport;
import com.xinelu.manage.domain.externalimport.ExternalImport; import com.xinelu.manage.domain.externalimport.ExternalImport;
import com.xinelu.manage.dto.externalimport.ExternalImportDto;
import java.util.List; import java.util.List;
@ -58,4 +59,12 @@ public interface IExternalImportService {
* @return 结果 * @return 结果
*/ */
int deleteExternalImportById(Long id); int deleteExternalImportById(Long id);
/**
* 查询外部数据导入列表不分页sn不为空
*
* @param externalImport 导入列表
* @return ExternalImport
*/
List<ExternalImport> getExternalImports(ExternalImportDto externalImport);
} }

View File

@ -1,6 +1,7 @@
package com.xinelu.manage.service.externalimport.impl; package com.xinelu.manage.service.externalimport.impl;
import com.xinelu.manage.domain.externalimport.ExternalImport; 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.mapper.externalimport.ExternalImportMapper;
import com.xinelu.manage.service.externalimport.IExternalImportService; import com.xinelu.manage.service.externalimport.IExternalImportService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -85,4 +86,15 @@ public class ExternalImportServiceImpl implements IExternalImportService {
public int deleteExternalImportById(Long id) { public int deleteExternalImportById(Long id) {
return externalImportMapper.deleteExternalImportById(id); return externalImportMapper.deleteExternalImportById(id);
} }
/**
* 查询外部数据导入列表不分页sn不为空
*
* @param externalImport 导入列表
* @return ExternalImport
*/
@Override
public List<ExternalImport> getExternalImports(ExternalImportDto externalImport) {
return externalImportMapper.getExternalImports(externalImport);
}
} }

View File

@ -3,6 +3,7 @@ package com.xinelu.manage.service.patientinfoimportmain;
import com.xinelu.common.core.domain.AjaxResult; import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.manage.domain.dialtime.DialTime; 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.patientinfo.PatientInfoVo;
import com.xinelu.manage.vo.patientinfoimportmain.PatientInfoImportMainVO; import com.xinelu.manage.vo.patientinfoimportmain.PatientInfoImportMainVO;
@ -42,4 +43,13 @@ public interface IPatientInfoImportMainService {
* @return 结果 * @return 结果
*/ */
AjaxResult insertDialTime(DialTime dialTime); AjaxResult insertDialTime(DialTime dialTime);
/**
*
* 手动创建患者导入信息
*
* @param patientInfoImportMainDto 患者导入信息
* @return AjaxResult
*/
AjaxResult manuallyCreate(PatientInfoImportMainDto patientInfoImportMainDto);
} }

View File

@ -1,28 +1,53 @@
package com.xinelu.manage.service.patientinfoimportmain.impl; package com.xinelu.manage.service.patientinfoimportmain.impl;
import com.xinelu.common.annotation.DataScope; 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.AjaxResult;
import com.xinelu.common.core.domain.entity.SysUser; 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.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.agency.Agency;
import com.xinelu.manage.domain.department.Department;
import com.xinelu.manage.domain.dialtime.DialTime; 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.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.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.service.patientinfoimportmain.IPatientInfoImportMainService;
import com.xinelu.manage.vo.patientinfo.PatientInfoVo; import com.xinelu.manage.vo.patientinfo.PatientInfoVo;
import com.xinelu.manage.vo.patientinfoimportmain.PatientInfoImportMainVO; import com.xinelu.manage.vo.patientinfoimportmain.PatientInfoImportMainVO;
import com.xinelu.system.mapper.SysUserMapper; import com.xinelu.system.mapper.SysUserMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; 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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors;
@Slf4j
@Service @Service
public class PatientInfoImportMainServiceImpl implements IPatientInfoImportMainService { public class PatientInfoImportMainServiceImpl implements IPatientInfoImportMainService {
@ -32,6 +57,20 @@ public class PatientInfoImportMainServiceImpl implements IPatientInfoImportMainS
private SysUserMapper sysUserMapper; private SysUserMapper sysUserMapper;
@Resource @Resource
private AgencyMapper agencyMapper; 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") @DataScope(agencyAlias = "p")
@ -133,4 +172,159 @@ public class PatientInfoImportMainServiceImpl implements IPatientInfoImportMainS
dialTime.setCreateBy(SecurityUtils.getUsername()); dialTime.setCreateBy(SecurityUtils.getUsername());
return AjaxResult.success(patientInfoImportMainMapper.insertDialTime(dialTime)); return AjaxResult.success(patientInfoImportMainMapper.insertDialTime(dialTime));
} }
/**
* 手动创建患者导入信息
*
* @param patientInfoImportMainDto 患者导入信息
* @return AjaxResult
*/
@Override
public AjaxResult manuallyCreate(PatientInfoImportMainDto patientInfoImportMainDto) {
//新增导入信息
Agency agency = agencyMapper.selectAgencyById(mainHospitalId);
List<Department> departments = new ArrayList<>();
List<String> difference;
Department department = new Department();
department.setHospitalAgencyId(mainHospitalId);
//科室信息组装-新增不存在科室
List<Department> departmentList = departmentMapper.selectDepartmentNameCount(department);
List<String> importDepartmentName = patientInfoImportMainDto.getExternalImports().stream().filter(Objects::nonNull).map(ExternalImport::getDepartmentName).distinct().collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(departmentList)) {
List<String> 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<PatientInfoImport> 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<ResidentInfo> residentInfos = residentInfoMapper.selectResidentInfoByPhoneList(patientInfoImportList);
List<PatientInfoImport> 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<PatientInfoImport> 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<PatientVisitRecord> 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();
}
} }

View File

@ -186,7 +186,7 @@
</trim> </trim>
</insert> </insert>
<insert id="insertExternalImportList" useGeneratedKeys="true" keyProperty="id"> <insert id="insertExternalImportList" useGeneratedKeys="true" keyProperty="id">
insert into external_import( insert into external_import(
patient_name, patient_name,
phone, phone,
@ -317,4 +317,34 @@
#{phones} #{phones}
</foreach> </foreach>
</select> </select>
<select id="getExternalImports" resultType="com.xinelu.manage.dto.externalimport.ExternalImportDto">
<include refid="selectExternalImportVo"/>
where sn is not null
<if test="departmentName != null and departmentNameList.size() > 0">
and department_name in
<foreach item="deptName" collection="departmentNameList" open="(" separator="," close=")">
#{deptName}
</foreach>
</if>
<if test="visitMethod != null and visitMethod != ''">
and visit_method = #{visitMethod}
</if>
<if test="visitDateStart != null ">
and date_format(visit_date, '%y%m%d') >= date_format(#{visitDateStart}, '%y%m%d')
</if>
<if test="visitDateEnd != null ">
and date_format(visit_date, '%y%m%d') &lt;= date_format(#{visitDateEnd}, '%y%m%d')
</if>
<if test="dischargeDateStart != null ">
and date_format(discharge_time, '%y%m%d') >= date_format(#{dischargeDateStart}, '%y%m%d')
</if>
<if test="dischargeDateEnd != null ">
and date_format(discharge_time, '%y%m%d') &lt;= date_format(#{dischargeDateEnd}, '%y%m%d')
</if>
</select>
<select id="getExternalImportCount" resultType="java.lang.Long">
select count(1) from external_import
</select>
</mapper> </mapper>

View File

@ -1,6 +1,7 @@
package com.xinelu.quartz.controller; package com.xinelu.quartz.controller;
import com.xinelu.quartz.domain.TbFollowUp; import com.xinelu.quartz.domain.TbFollowUp;
import com.xinelu.quartz.task.MedicalConsortiumPlatformTask;
import com.xinelu.quartz.task.SubscribeTask; import com.xinelu.quartz.task.SubscribeTask;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -23,6 +24,8 @@ public class MessageSubscriptionController {
@Resource @Resource
private SubscribeTask subscribeTask; private SubscribeTask subscribeTask;
@Resource
private MedicalConsortiumPlatformTask medicalConsortiumPlatformTask;
/** /**
* 手动执行专病路径定时任务 * 手动执行专病路径定时任务
@ -82,4 +85,9 @@ public class MessageSubscriptionController {
e.printStackTrace(); e.printStackTrace();
} }
} }
@PostMapping("/bbb")
public void bbb(){
medicalConsortiumPlatformTask.medicalConsortiumPlatformTask();
}
} }

View File

@ -1,29 +1,8 @@
package com.xinelu.quartz.task; 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.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.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.quartz.domain.TbFollowUp;
import com.xinelu.system.mapper.SysUserMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -55,33 +34,18 @@ public class MedicalConsortiumPlatformTask {
@Resource @Resource
private ExternalImportMapper externalImportMapper; 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}") @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) @Transactional(rollbackFor = Exception.class)
public void medicalConsortiumPlatformTask() { public void medicalConsortiumPlatformTask() {
log.info("开始获取医共体数据,时间:" + LocalDateTime.now()); log.info("开始获取医共体数据,时间:" + LocalDateTime.now());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
List<TbFollowUp> list = new ArrayList<>(); List<TbFollowUp> list = new ArrayList<>();
Long externalImportCount = externalImportMapper.getExternalImportCount();
//获取数据 //获取数据
try { try {
// 1.加载驱动 // 1.加载驱动
@ -89,7 +53,12 @@ public class MedicalConsortiumPlatformTask {
// 2.获取连接 // 2.获取连接
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@//172.19.116.212:1521/ORCL", "HK_ZJK", "DYWJWhkzjk5169"); Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@//172.19.116.212:1521/ORCL", "HK_ZJK", "DYWJWhkzjk5169");
// 3.创建Statement对象可以执行sql的对象 // 3.创建Statement对象可以执行sql的对象
PreparedStatement preparedStatement = connection.prepareStatement(sql); PreparedStatement preparedStatement;
if (externalImportCount > 0) {
preparedStatement = connection.prepareStatement(sql_date);
} else {
preparedStatement = connection.prepareStatement(sql);
}
// 4.获取结果集 // 4.获取结果集
ResultSet resultSet = preparedStatement.executeQuery(); ResultSet resultSet = preparedStatement.executeQuery();
// 5.对数据进行处理 // 5.对数据进行处理
@ -134,49 +103,6 @@ public class MedicalConsortiumPlatformTask {
//筛选就诊号并根据就诊号查询数据库 //筛选就诊号并根据就诊号查询数据库
List<ExternalImport> dataExternalImports = externalImportMapper.selectExternalByPhone(collect); List<ExternalImport> dataExternalImports = externalImportMapper.selectExternalByPhone(collect);
List<ExternalImport> externalImports = new ArrayList<>(); List<ExternalImport> externalImports = new ArrayList<>();
//科室信息组装-新增不存在科室
Agency agency = agencyMapper.selectAgencyById(mainHospitalId);
List<Department> departments = new ArrayList<>();
List<String> difference;
Department department = new Department();
department.setHospitalAgencyId(mainHospitalId);
List<Department> departmentList = departmentMapper.selectDepartmentNameCount(department);
List<String> importDepartmentName = list.stream().filter(Objects::nonNull).map(TbFollowUp::getJZKSMC).distinct().collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(departmentList)) {
List<String> 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<PatientInfoImport> patientInfoImportList = new ArrayList<>();
Long i = 1L;
//遍历塞数据 //遍历塞数据
for (TbFollowUp tbFollowUp : list) { for (TbFollowUp tbFollowUp : list) {
//去除与数据库重复项 //去除与数据库重复项
@ -188,9 +114,7 @@ public class MedicalConsortiumPlatformTask {
if (StringUtils.isNotBlank(identicalVisitCode.getPhone())) { if (StringUtils.isNotBlank(identicalVisitCode.getPhone())) {
continue; continue;
} }
PatientInfoImport patientInfoImport = new PatientInfoImport();
ExternalImport externalImport = new ExternalImport(); ExternalImport externalImport = new ExternalImport();
externalImport.setSn(sn);
externalImport.setPatientName(tbFollowUp.getXM()); externalImport.setPatientName(tbFollowUp.getXM());
externalImport.setPhone(tbFollowUp.getLXDH()); externalImport.setPhone(tbFollowUp.getLXDH());
externalImport.setAge(tbFollowUp.getNL()); externalImport.setAge(tbFollowUp.getNL());
@ -201,7 +125,6 @@ public class MedicalConsortiumPlatformTask {
externalImport.setVisitMethod(tbFollowUp.getMZZYBZ()); externalImport.setVisitMethod(tbFollowUp.getMZZYBZ());
if (Objects.nonNull(tbFollowUp.getJZSJ())) { if (Objects.nonNull(tbFollowUp.getJZSJ())) {
externalImport.setVisitDate(LocalDateTime.parse(tbFollowUp.getJZSJ(), formatter)); externalImport.setVisitDate(LocalDateTime.parse(tbFollowUp.getJZSJ(), formatter));
patientInfoImport.setVisitDate(LocalDate.parse(tbFollowUp.getJZSJ(), formatter));
} }
if (Objects.nonNull(tbFollowUp.getRYSJ())) { if (Objects.nonNull(tbFollowUp.getRYSJ())) {
externalImport.setAdmissionTime(LocalDateTime.parse(tbFollowUp.getRYSJ(), formatter)); externalImport.setAdmissionTime(LocalDateTime.parse(tbFollowUp.getRYSJ(), formatter));
@ -224,103 +147,8 @@ public class MedicalConsortiumPlatformTask {
externalImport.setDischargeMethod(tbFollowUp.getLYFS()); externalImport.setDischargeMethod(tbFollowUp.getLYFS());
externalImport.setDataGetTime(LocalDateTime.now()); externalImport.setDataGetTime(LocalDateTime.now());
externalImports.add(externalImport); 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); externalImportMapper.insertExternalImportList(externalImports);
log.info("获取医共体数据,共" + externalImports.size() + ""); log.info("获取医共体数据完成,共" + externalImports.size() + "");
//新增缓存表
patientInfoImportMapper.insertPatientInfoImportList(patientInfoImportList);
List<ResidentInfo> residentInfos = residentInfoMapper.selectResidentInfoByPhoneList(patientInfoImportList);
List<PatientInfoImport> 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<PatientInfoImport> 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<PatientVisitRecord> 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("获取医共体数据完成");
} }
} }