医共体数据添加
This commit is contained in:
parent
44572acc61
commit
f71f2ec347
@ -170,6 +170,8 @@ public class ExternalImport extends BaseEntity {
|
||||
@Excel(name = "数据获取时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime dataGetTime;
|
||||
|
||||
private String sn;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
|
||||
@ -12,7 +12,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】对象 patient_info_import_main
|
||||
* 导入文件信息对象 patient_info_import_main
|
||||
*
|
||||
* @author xinelu
|
||||
* @date 2024-11-29
|
||||
@ -21,7 +21,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "【请填写功能名称】对象", description = "patient_info_import_main")
|
||||
@ApiModel(value = "导入文件信息对象", description = "patient_info_import_main")
|
||||
public class PatientInfoImportMain extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@ -357,15 +357,6 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
|
||||
if (CollectionUtils.isNotEmpty(list) && list.size() > number) {
|
||||
return AjaxResult.error("本次导入表数据超过" + number + "人次上限!");
|
||||
}
|
||||
// PatientInfoImport patientInfoImport1 = new PatientInfoImport();
|
||||
// patientInfoImport1.setCreateTime(LocalDateTime.now());
|
||||
// List<PatientInfoImport> patientInfoImports = patientInfoImportMapper.selectPatientInfoImportList(patientInfoImport1);
|
||||
// if (CollectionUtils.isNotEmpty(patientInfoImports) && patientInfoImports.size() > number) {
|
||||
// return AjaxResult.error("今日导入已达" + number + "人次上限!");
|
||||
// }
|
||||
// if (CollectionUtils.isNotEmpty(list) && CollectionUtils.isNotEmpty(patientInfoImports) && (list.size() + patientInfoImports.size() > number)) {
|
||||
// return AjaxResult.error("总计导入超过" + number + "人次上限,请修改后重新导入!");
|
||||
// }
|
||||
}
|
||||
//登录用户科室信息
|
||||
SysUser sysUser = sysUserMapper.selectUserById(SecurityUtils.getUserId());
|
||||
@ -601,7 +592,6 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
|
||||
return AjaxResult.error("患者信息新增失败;");
|
||||
}
|
||||
patientInfoImportList.forEach(item -> item.setPatientInfoId(item.getId()));
|
||||
//新增就诊记录表
|
||||
//region 新增就诊记录表
|
||||
List<PatientVisitRecord> patientVisitRecords = new ArrayList<>();
|
||||
for (PatientInfoImport patientInfoImport : patientInfoImportList) {
|
||||
|
||||
@ -25,10 +25,11 @@
|
||||
<result property="dischargeMethod" column="discharge_method"/>
|
||||
<result property="healthState" column="health_state"/>
|
||||
<result property="dataGetTime" column="data_get_time"/>
|
||||
<result property="sn" column="sn"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectExternalImportVo">
|
||||
select id, patient_name, phone, age, card_no, sex, department_name, visit_code, visit_method, visit_date, admission_time, discharge_time, push_time, plan_follow_up, follow_up_template, main_diagnosis, data_source, discharge_method, health_state, data_get_time from external_import
|
||||
select id, patient_name, phone, age, card_no, sex, department_name, visit_code, visit_method, visit_date, admission_time, discharge_time, push_time, plan_follow_up, follow_up_template, main_diagnosis, data_source, discharge_method, health_state, data_get_time, sn from external_import
|
||||
</sql>
|
||||
|
||||
<select id="selectExternalImportList" parameterType="com.xinelu.manage.domain.externalimport.ExternalImport" resultMap="ExternalImportResult">
|
||||
@ -205,7 +206,8 @@
|
||||
data_source,
|
||||
discharge_method,
|
||||
health_state,
|
||||
data_get_time
|
||||
data_get_time,
|
||||
sn
|
||||
) values
|
||||
<foreach item="ExternalImport" index="index" collection="list" separator=",">
|
||||
(
|
||||
@ -227,7 +229,8 @@
|
||||
#{ExternalImport.dataSource},
|
||||
#{ExternalImport.dischargeMethod},
|
||||
#{ExternalImport.healthState},
|
||||
#{ExternalImport.dataGetTime}
|
||||
#{ExternalImport.dataGetTime},
|
||||
#{ExternalImport.sn}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
@ -1,30 +1,53 @@
|
||||
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;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
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;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @description: 医共体数据导入定时任务
|
||||
* @author: haown
|
||||
* @create: 2024-06-28 14:27
|
||||
* @author: zh
|
||||
* @create: 2026-06-30
|
||||
**/
|
||||
@Slf4j
|
||||
@Component("MedicalConsortiumPlatformTask")
|
||||
@ -32,8 +55,29 @@ 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;
|
||||
|
||||
public void medicalConsortiumPlatformTask() throws Exception {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void medicalConsortiumPlatformTask() {
|
||||
log.info("开始获取医共体数据,时间:" + LocalDateTime.now());
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
List<TbFollowUp> list = new ArrayList<>();
|
||||
@ -43,7 +87,6 @@ public class MedicalConsortiumPlatformTask {
|
||||
Class.forName("oracle.jdbc.OracleDriver");
|
||||
// 2.获取连接
|
||||
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@//172.19.116.212:1521/ORCL", "HK_ZJK", "DYWJWhkzjk5169");
|
||||
System.out.println(connection.getMetaData());
|
||||
// 3.创建Statement对象(可以执行sql的对象)
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("select * from tb_follow_up");
|
||||
// 4.获取结果集
|
||||
@ -75,23 +118,73 @@ public class MedicalConsortiumPlatformTask {
|
||||
preparedStatement.close();
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
log.info("获取医共体数据失败,数据连接不成功,时间:" + LocalDateTime.now());
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (CollectionUtils.isEmpty(list) || list.size() == 0) {
|
||||
log.info("获取医共体数据" + list.size() + "条");
|
||||
return;
|
||||
}
|
||||
//筛选就诊号并根据就诊号查询数据库
|
||||
List<String> collect = list.stream().filter(Objects::nonNull).map(TbFollowUp::getJZLSH).collect(Collectors.toList());
|
||||
List<ExternalImport> dataExternalImports = externalImportMapper.selectExternalByPhone(collect);
|
||||
list = list.stream().filter(Objects::nonNull).filter(item -> StringUtils.isNotBlank(item.getJZLSH()) && StringUtils.isNotBlank(item.getXM())).collect(Collectors.toList());
|
||||
//ExternalImport表 过滤姓名为空和就诊号为空的数据
|
||||
list = list.stream().filter(Objects::nonNull).filter(item -> StringUtils.isNotBlank(item.getJZLSH())
|
||||
&& StringUtils.isNotBlank(item.getXM()) && StringUtils.isNotBlank(item.getLXDH()) && StringUtils.isNotBlank(item.getZJHM())).collect(Collectors.toList());
|
||||
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) {
|
||||
//去除与数据库重复项
|
||||
ExternalImport identicalVisitCode = dataExternalImports.stream().filter(item -> tbFollowUp.getJZLSH().equals(item.getVisitCode())).findFirst().orElse(new ExternalImport());
|
||||
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());
|
||||
@ -102,6 +195,7 @@ 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));
|
||||
@ -115,7 +209,7 @@ public class MedicalConsortiumPlatformTask {
|
||||
if (Objects.nonNull(tbFollowUp.getSFSJ())) {
|
||||
externalImport.setPlanFollowUp(LocalDateTime.parse(tbFollowUp.getSFSJ(), formatter));
|
||||
}
|
||||
if (StringUtils.isNotBlank(tbFollowUp.getMBID())){
|
||||
if (StringUtils.isNotBlank(tbFollowUp.getMBID())) {
|
||||
externalImport.setFollowUpTemplate(Long.valueOf(tbFollowUp.getMBID()));
|
||||
}
|
||||
externalImport.setMainDiagnosis(tbFollowUp.getJZZDSM());
|
||||
@ -124,8 +218,103 @@ 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() + "条");
|
||||
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("获取医共体数据完成");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user