@ -1,6 +1,7 @@
package com.xinelu.manage.service.patientinfo.impl ;
import com.xinelu.common.annotation.DataScope ;
import com.xinelu.common.constant.HttpStatus ;
import com.xinelu.common.constant.SignRecordServiceStatusConstants ;
import com.xinelu.common.core.domain.AjaxResult ;
import com.xinelu.common.core.domain.entity.SysUser ;
@ -39,6 +40,7 @@ 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 ;
@ -317,28 +319,25 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
@Transactional ( rollbackFor = Exception . class )
@Override
public AjaxResult patientUpload ( List < PatientInfoImport > list ) {
public AjaxResult patientUpload ( List < PatientInfoImport > list , Integer records ) {
if ( CollectionUtils . isEmpty ( list ) | | list . size ( ) = = 0 ) {
return AjaxResult . error ( " 导入用户数据不能为空! " ) ;
}
PatientInfoImport regexPhone = list . stream ( ) . filter ( item - > StringUtils . is NotBlank( item . getPatientPhone ( ) ) ) . filter ( item - > BooleanUtils . isFalse ( regexUtil . regexPhone ( item . getPatientPhone ( ) ) ) ) . findFirst ( ) . orElse ( new PatientInfoImpor t( ) ) ;
if ( StringUtils. isNotBlank ( regexPhone . getPatientPhone ( ) ) ) {
return AjaxResult . error ( " 手机号号码:" + regexPhone . getPatientPhone ( ) + " 格式不正确,请重新录入 ! " ) ;
List< PatientInfoImport > collect = list . stream ( ) . filter ( Objects: : nonNull ) . filter ( item - > StringUtils . is Empty( item . getPatientName ( ) ) | | StringUtils . isEmpty ( item . getPatientPhone ( ) ) | | StringUtils . isEmpty ( item . getDeptAlias ( ) ) | | Objects . isNull ( item . getVisitDate ( ) ) ) . collect ( Collectors . toLis t( ) ) ;
if ( CollectionUtils. isNotEmpty ( collect ) ) {
return AjaxResult . error ( " 请填写完整 ! " ) ;
}
PatientInfoImport regexCardNo = list . stream ( ) . filter ( item - > StringUtils . isNotBlank ( item . get CardNo ( ) ) ) . filter ( item - > BooleanUtils . isFalse ( regexUtil . regex CardNo( item . getCardNo ( ) ) ) ) . findFirst ( ) . orElse ( new PatientInfoImpor t( ) ) ;
if ( StringUtils. isNotBlank ( regexCardNo . getCardNo ( ) ) ) {
return AjaxResult . error ( " 身份证号: " + regexCardNo . getCardNo ( ) + " 格式不正确,请重新录入! " ) ;
List< PatientInfoImport > regexPhoneList = list . stream ( ) . filter ( item - > StringUtils . isNotBlank ( item . get PatientPhone ( ) ) ) . filter ( item - > BooleanUtils . isFalse ( regexUtil . regex Phone( item . getPatientPhone ( ) ) ) ) . collect ( Collectors . toLis t( ) ) ;
if ( CollectionUtils. isNotEmpty ( regexPhoneList ) ) {
return AjaxResult . error ( HttpStatus . ERROR_TWO , " 手机号号码格式不正确,请重新录入! " , regexPhoneList ) ;
}
/ / 导入重复
/ / 导入重复 过滤
List < PatientInfoImport > distinctCollect = list . stream ( ) . filter ( Objects : : nonNull ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
if ( list . size ( ) ! = distinctCollect . size ( ) ) {
List < PatientInfoImport > contains = list . stream ( ) . filter ( item - > ! distinctCollect . contains ( item ) ) . collect ( Collectors . toList ( ) ) ;
return AjaxResult . error ( " 导入数据重复 " , contains ) ;
}
LocalDate nowDate = LocalDate . now ( ) ;
/ / 与数据库重复
List < PatientInfo > patientInfos = patientInfoMapper . selectPatientInfoByPatientName ( list ) ;
if ( CollectionUtils. isEmpty ( patientInfos ) ) {
return AjaxResult . error ( " 有 " + patientInfos . size ( ) + " 条记录当天已导入,是否继续导入 " ) ;
List < PatientInfo > patientInfos = new ArrayList < > ( ) ;
if ( Objects . isNull ( records ) | | records = = 1 ) {
patientInfos = patientInfoMapper . selectPatientInfoByPatientName ( list , nowDate ) ;
}
/ / sn
String sn = LocalDateTime . now ( ) . format ( DateTimeFormatter . ofPattern ( " yyyyMMddHHmmss " ) ) ;
@ -350,22 +349,36 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
}
department . setHospitalAgencyId ( sysUser . getHospitalAgencyId ( ) ) ;
List < Department > departmentList = departmentMapper . selectDepartmentNameCount ( department ) ;
if ( CollectionUtils . isEmpty ( departmentList ) ) {
return AjaxResult . error ( " 该账号所属医院无下级科室,请先维护所属医院的下级科室信息! " ) ;
}
PatientInfoImportVO patientInfoImportVO = new PatientInfoImportVO ( ) ;
List < DeptAliasVO > deptAliasVOS = new ArrayList < > ( ) ;
/ / 组装数据
for ( PatientInfoImport patientInfoImport : list ) {
List < PatientInfoImport > patientInfoImportList = new ArrayList < > ( ) ;
/ / 选择自动去除当日重复记录
for ( PatientInfoImport patientInfoImport : distinctCollect ) {
if ( CollectionUtils . isNotEmpty ( patientInfos ) ) {
List < PatientInfo > collect1 = patientInfos . stream ( ) . filter ( Objects : : nonNull ) . filter ( item - > patientInfoImport . getPatientName ( ) . equals ( item . getPatientName ( ) ) & & patientInfoImport . getPatientPhone ( ) . equals ( item . getPatientPhone ( ) ) ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtils . isNotEmpty ( collect1 ) ) {
continue ;
}
}
/ / 判断是否有科室名称或别名一致
Department equalsDepartment = departmentList . stream ( ) . filter ( Objects : : nonNull ) . filter ( item - > patientInfoImport . getDeptAlias ( ) . equals ( item . getDepartmentName ( ) ) | | item . getDepartmentAbbreviation ( ) . contains ( patientInfoImport . getDeptAlias ( ) ) ) . findFirst ( ) . orElse ( new Department ( ) ) ;
patientInfoImport . setSn ( sn ) ;
patientInfoImport . setCreateBy ( SecurityUtils . getUsername ( ) ) ;
patientInfoImport . setCreateTime ( LocalDateTime . now ( ) ) ;
/ / 一致塞值 , 不一致取数据返回
/ / 医院有科室且名称一致塞值 , 不一致取数据返回 , 医院没科室科室数据返回
if ( CollectionUtils . isNotEmpty ( departmentList ) ) {
Department equalsDepartment = departmentList . stream ( ) . filter ( Objects : : nonNull )
. filter ( item - > patientInfoImport . getDeptAlias ( ) . equals ( item . getDepartmentName ( ) ) | | ( StringUtils . isNotEmpty ( item . getDepartmentAbbreviation ( ) ) & & item . getDepartmentAbbreviation ( ) . contains ( patientInfoImport . getDeptAlias ( ) ) ) ) . findFirst ( ) . orElse ( new Department ( ) ) ;
if ( Objects . nonNull ( equalsDepartment . getId ( ) ) ) {
patientInfoImport . setDepartmentId ( equalsDepartment . getId ( ) ) ;
patientInfoImport . setDepartmentName ( patientInfoImport . getDepartmentName ( ) ) ;
patientInfoImportList . add ( patientInfoImport ) ;
} else {
DeptAliasVO deptAliasVO = new DeptAliasVO ( ) ;
deptAliasVO . setSn ( sn ) ;
deptAliasVO . setDeptAlias ( patientInfoImport . getDeptAlias ( ) ) ;
deptAliasVOS . add ( deptAliasVO ) ;
}
} else {
DeptAliasVO deptAliasVO = new DeptAliasVO ( ) ;
deptAliasVO . setSn ( sn ) ;
@ -373,15 +386,16 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
deptAliasVOS . add ( deptAliasVO ) ;
}
}
List < PatientInfoImport > patientInfoImports = new ArrayList < > ( list ) ;
/ / 组装返回数据
List < PatientInfoImport > patientInfoImports = new ArrayList < > ( patientInfoImportList ) ;
patientInfoImportVO . setSn ( sn ) ;
patientInfoImportVO . setDepartments ( departmentList ) ;
if ( CollectionUtils . isNotEmpty ( deptAliasVOS ) ) {
deptAliasVOS = deptAliasVOS . stream ( ) . filter ( Objects : : nonNull ) . filter ( item - > Objects . nonNull ( item . getDep artmentId ( ) ) ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
deptAliasVOS = deptAliasVOS . stream ( ) . filter ( Objects : : nonNull ) . filter ( item - > Objects . nonNull ( item . getDep tAlias ( ) ) ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
patientInfoImportVO . setDeptAliasVOS ( deptAliasVOS ) ;
}
/ / 新增缓存表
int insertCount = patientInfoImportMapper . insertPatientInfoImportList ( l ist) ;
int insertCount = patientInfoImportMapper . insertPatientInfoImportList ( patientInfoImportL ist) ;
if ( insertCount < = 0 ) {
return AjaxResult . error ( " 导入失败,请联系管理员! " ) ;
}
@ -389,16 +403,19 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
if ( CollectionUtils . isNotEmpty ( deptAliasVOS ) ) {
return AjaxResult . success ( " 科室名称不存在 " , patientInfoImportVO ) ;
} else {
int i = patientInfoMapper . insertPatientInfoList ( list ) ;
/ / 新增患者表
int i = patientInfoMapper . insertPatientInfoList ( patientInfoImportList ) ;
if ( i < = 0 ) {
return AjaxResult . error ( " 导入失败,请联系管理员! " ) ;
}
List < PatientInfoImport > patientInfoIds = new ArrayList < > ( list ) ;
int residentCount = residentInfoMapper . insertResidentInfoList ( list ) ;
/ / 新增居民表
List < PatientInfoImport > patientInfoIds = new ArrayList < > ( patientInfoImportList ) ;
int residentCount = residentInfoMapper . insertResidentInfoList ( patientInfoImportList ) ;
if ( residentCount < = 0 ) {
return AjaxResult . error ( " 导入失败,请联系管理员! " ) ;
}
List < PatientInfoImport > residentIds = new ArrayList < > ( list ) ;
/ / 新增就诊记录表
List < PatientInfoImport > residentIds = new ArrayList < > ( patientInfoImportList ) ;
List < PatientVisitRecord > patientVisitRecords = new ArrayList < > ( ) ;
for ( PatientInfoImport patientInfoImport : patientInfoImports ) {
PatientInfoImport patientInfoId = patientInfoIds . stream ( ) . filter ( Objects : : nonNull ) . filter ( item - > patientInfoImport . getPatientName ( ) . equals ( item . getPatientName ( ) ) & & patientInfoImport . getPatientPhone ( ) . equals ( item . getPatientPhone ( ) ) ) . findFirst ( ) . orElse ( new PatientInfoImport ( ) ) ;
@ -406,14 +423,6 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
PatientVisitRecord patientVisitRecord = new PatientVisitRecord ( ) ;
patientVisitRecord . setPatientId ( patientInfoId . getId ( ) ) ;
patientVisitRecord . setResidentId ( residentId . getId ( ) ) ;
/ / patientVisitRecord . setVisitDate ( patientInfoImport . getVisitDate ( ) ) ;
/ / patientVisitRecord . setCardNo ( patientInfoImport . getCardNo ( ) ) ;
/ / patientVisitRecord . setAge ( patientInfoImport . getAge ( ) ) ;
/ / patientVisitRecord . setMainDiagnosis ( patientInfoImport . getMainDiagnosis ( ) ) ;
/ / patientVisitRecord . setPatientPhone ( patientInfoImport . getPatientPhone ( ) ) ;
/ / patientVisitRecord . setPatientName ( patientInfoImport . getPatientName ( ) ) ;
/ / patientVisitRecord . setDepartmentId ( patientInfoImport . getDepartmentId ( ) ) ;
/ / patientVisitRecord . setDepartmentName ( patientInfoImport . getDepartmentName ( ) ) ;
BeanUtils . copyProperties ( patientInfoImport , patientVisitRecord ) ;
patientVisitRecord . setDelFlag ( 0 ) ;
patientVisitRecord . setHospitalAgencyId ( departmentList . get ( 0 ) . getHospitalAgencyId ( ) ) ;
@ -456,6 +465,7 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
if ( CollectionUtils . isEmpty ( departmentList ) ) {
return AjaxResult . error ( " 该账号所属医院无下级科室,请先维护所属医院的下级科室信息! " ) ;
}
/ / 科室组装别名
List < Department > departments = new ArrayList < > ( ) ;
for ( Department department1 : departmentList ) {
Department deptAliasdepartment = new Department ( ) ;
@ -474,16 +484,19 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
departments . add ( deptAliasdepartment ) ;
}
}
/ / 修改科室表别名信息
if ( CollectionUtils . isNotEmpty ( departments ) ) {
int i = departmentMapper . updateDepartmentListByIds ( departments ) ;
if ( i < = 0 ) {
return AjaxResult . error ( " 导入失败,请联系管理员! " ) ;
}
}
/ / 新增患者表信息
int i = patientInfoMapper . insertPatientInfoList ( patientInfoImports ) ;
if ( i < = 0 ) {
return AjaxResult . error ( " 导入失败,请联系管理员! " ) ;
}
/ / 新增居民表信息
List < PatientInfoImport > patientInfoIds = new ArrayList < > ( patientInfoImports ) ;
int residentCount = residentInfoMapper . insertResidentInfoList ( patientInfoImports ) ;
if ( residentCount < = 0 ) {
@ -497,14 +510,6 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
PatientVisitRecord patientVisitRecord = new PatientVisitRecord ( ) ;
patientVisitRecord . setPatientId ( patientInfoId . getId ( ) ) ;
patientVisitRecord . setResidentId ( residentId . getId ( ) ) ;
/ / patientVisitRecord . setVisitDate ( patientInfoImport . getVisitDate ( ) ) ;
/ / patientVisitRecord . setCardNo ( patientInfoImport . getCardNo ( ) ) ;
/ / patientVisitRecord . setAge ( patientInfoImport . getAge ( ) ) ;
/ / patientVisitRecord . setMainDiagnosis ( patientInfoImport . getMainDiagnosis ( ) ) ;
/ / patientVisitRecord . setPatientPhone ( patientInfoImport . getPatientPhone ( ) ) ;
/ / patientVisitRecord . setPatientName ( patientInfoImport . getPatientName ( ) ) ;
/ / patientVisitRecord . setDepartmentId ( patientInfoImport . getDepartmentId ( ) ) ;
/ / patientVisitRecord . setDepartmentName ( patientInfoImport . getDepartmentName ( ) ) ;
BeanUtils . copyProperties ( patientInfoImport , patientVisitRecord ) ;
patientVisitRecord . setDelFlag ( 0 ) ;
patientVisitRecord . setHospitalAgencyId ( department . getHospitalAgencyId ( ) ) ;