|
|
@ -3,33 +3,29 @@ package com.ccsens.tcm.service; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.ccsens.tcm.bean.dto.BiologicalSamplesDto; |
|
|
|
import com.ccsens.tcm.bean.dto.ConRecDto; |
|
|
|
import com.ccsens.tcm.bean.dto.PatientDto; |
|
|
|
import com.ccsens.tcm.bean.dto.StatisticDto; |
|
|
|
import com.ccsens.tcm.bean.po.*; |
|
|
|
import com.ccsens.tcm.bean.vo.*; |
|
|
|
import com.ccsens.tcm.persist.dao.DoctorDao; |
|
|
|
import com.ccsens.tcm.persist.dao.PatientDao; |
|
|
|
import com.ccsens.tcm.persist.mapper.*; |
|
|
|
import com.ccsens.tcm.uitl.Constant; |
|
|
|
import com.ccsens.util.CodeEnum; |
|
|
|
import com.ccsens.util.RedisUtil; |
|
|
|
import com.ccsens.util.bean.dto.QueryDto; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.text.DecimalFormat; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@Slf4j |
|
|
@ -55,7 +51,8 @@ public class PatientService implements IPatientService { |
|
|
|
@Resource |
|
|
|
private HospitalMapper hospitalMapper; |
|
|
|
@Resource |
|
|
|
private DoctorMapper doctorMapper; |
|
|
|
private DoctorDao doctorDao; |
|
|
|
|
|
|
|
// @Value("${day.one}")
|
|
|
|
// public int one;
|
|
|
|
// @Value("${day.two}")
|
|
|
@ -76,30 +73,30 @@ public class PatientService implements IPatientService { |
|
|
|
@Override |
|
|
|
public void savePatient(PatientDto.SavePatient param, Long userId) { |
|
|
|
Hospital hospital = selUserIdToHosId(userId); |
|
|
|
Inpatient inpatient = inpatientMapper.selectByPrimaryKey(param.getInpatientId()); |
|
|
|
if (inpatient == null) { |
|
|
|
throw new BaseException(CodeEnum.PARAM_ERROR); |
|
|
|
} |
|
|
|
log.info("医院:{},对照组:{}", hospital, inpatient); |
|
|
|
// 生成编号
|
|
|
|
DecimalFormat df=new DecimalFormat("000"); |
|
|
|
String num = hospital.getCode() + inpatient.getCode() + df.format(param.getCodeNum()); |
|
|
|
log.info("编号:{}", num); |
|
|
|
// 判断住院号是否存在
|
|
|
|
PatientInformationExample patientInformationExample=new PatientInformationExample(); |
|
|
|
patientInformationExample.createCriteria().andHospitalizationEqualTo(param.getHospitalization()) |
|
|
|
.andHospitalIdEqualTo(hospital.getId()).andRecStatusEqualTo((byte)0); |
|
|
|
patientInformationExample.createCriteria().andCodeEqualTo(num); |
|
|
|
long l = patientInformationMapper.countByExample(patientInformationExample); |
|
|
|
if(l>0){ |
|
|
|
throw new BaseException(CodeEnum.ZHUYUANIDCHONGFU); |
|
|
|
} |
|
|
|
|
|
|
|
Inpatient inpatient = inpatientMapper.selectByPrimaryKey(param.getInpatientId()); |
|
|
|
if (inpatient == null) { |
|
|
|
throw new BaseException(CodeEnum.PARAM_ERROR); |
|
|
|
} |
|
|
|
log.info("医院:{},对照组:{}", hospital, inpatient); |
|
|
|
|
|
|
|
PatientInformation patientInformation=new PatientInformation(); |
|
|
|
BeanUtils.copyProperties(param,patientInformation); |
|
|
|
patientInformation.setId(snowflake.nextId()); |
|
|
|
patientInformation.setHospitalId(hospital.getId()); |
|
|
|
patientInformation.setUserId(userId); |
|
|
|
// 生成编号
|
|
|
|
long incr = redisUtil.incr(StrUtil.format(Constant.Redis.HOSPITAL_NUM, hospital.getCode(), inpatient.getCode()) , 1); |
|
|
|
DecimalFormat df=new DecimalFormat("000"); |
|
|
|
String num = hospital.getCode() + inpatient.getCode() + df.format(incr); |
|
|
|
log.info("编号:{}", num); |
|
|
|
|
|
|
|
patientInformation.setCode(num); |
|
|
|
patientInformationMapper.insertSelective(patientInformation); |
|
|
|
} |
|
|
@ -114,7 +111,7 @@ public class PatientService implements IPatientService { |
|
|
|
public Hospital selUserIdToHosId(Long userId) { |
|
|
|
DoctorExample doctorExample=new DoctorExample(); |
|
|
|
doctorExample.createCriteria().andUserIdEqualTo(userId).andRecStatusEqualTo((byte)0); |
|
|
|
List<Doctor> doctors = doctorMapper.selectByExample(doctorExample); |
|
|
|
List<Doctor> doctors = doctorDao.selectByExample(doctorExample); |
|
|
|
if(doctors.size()!=1){ |
|
|
|
throw new BaseException(CodeEnum.MEIYOUGAIYISHENG); |
|
|
|
} |
|
|
@ -272,7 +269,21 @@ public class PatientService implements IPatientService { |
|
|
|
@Override |
|
|
|
public PageInfo<PatientVo.SelPatient> selPatientInformationList(PatientDto.SelPatientList param, Long userId) { |
|
|
|
PageHelper.startPage(param.getPageNum(),param.getPageSize()); |
|
|
|
List<PatientVo.SelPatient> selPatientList= patientDao.selPatientInformationList(param); |
|
|
|
if (param.getHospitalIds() == null) { |
|
|
|
param.setHospitalIds(new ArrayList<>()); |
|
|
|
} |
|
|
|
List<DoctorVo.Detail> doctors = doctorDao.queryDetail(userId); |
|
|
|
for (DoctorVo.Detail doctor: doctors) { |
|
|
|
if (doctor.getHospitalType() == Constant.HOSPITAL_PROJECT) { |
|
|
|
param.getHospitalIds().clear(); |
|
|
|
break; |
|
|
|
} else { |
|
|
|
param.getHospitalIds().add(doctor.getHospitalId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<PatientVo.SelPatient> selPatientList= patientDao.selPatientInformationList(param, userId); |
|
|
|
return new PageInfo<>(selPatientList); |
|
|
|
} |
|
|
|
|
|
|
@ -347,20 +358,27 @@ public class PatientService implements IPatientService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void addBiologicalSamples(BiologicalSamplesDto.AddBiolog param, Long userId) { |
|
|
|
if (CollectionUtil.isEmpty(param.getSampleTypes())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
PatientInformationExample patientInformationExample=new PatientInformationExample(); |
|
|
|
patientInformationExample.createCriteria().andHospitalizationEqualTo(param.getHospitalization()).andRecStatusEqualTo((byte)0); |
|
|
|
patientInformationExample.createCriteria().andCodeEqualTo(param.getCode()).andRecStatusEqualTo((byte)0); |
|
|
|
List<PatientInformation> patientInformations = patientInformationMapper.selectByExample(patientInformationExample); |
|
|
|
if(patientInformations.size()!=1){ |
|
|
|
throw new BaseException(CodeEnum.QUANTITYERROR); |
|
|
|
} |
|
|
|
BiologicalSamples biologicalSamples=new BiologicalSamples(); |
|
|
|
biologicalSamples.setUserId(userId); |
|
|
|
biologicalSamples.setId(snowflake.nextId()); |
|
|
|
biologicalSamples.setPatientInformationId(patientInformations.get(0).getId()); |
|
|
|
BeanUtils.copyProperties(param,biologicalSamples); |
|
|
|
biologicalSamples.setCode(patientInformations.get(0).getCode() + Constant.SPLIT_STRIKE + Constant.Biological.getByType(param.getSampleType()).getCode() + Constant.SPLIT_STRIKE + param.getCollectTime()); |
|
|
|
biologicalSamplesMapper.insertSelective(biologicalSamples); |
|
|
|
|
|
|
|
param.getSampleTypes().forEach(type->{ |
|
|
|
BiologicalSamples biologicalSamples=new BiologicalSamples(); |
|
|
|
biologicalSamples.setUserId(userId); |
|
|
|
biologicalSamples.setId(snowflake.nextId()); |
|
|
|
biologicalSamples.setPatientInformationId(patientInformations.get(0).getId()); |
|
|
|
biologicalSamples.setCollectTime(param.getCollectTime()); |
|
|
|
biologicalSamples.setSampleType(type); |
|
|
|
biologicalSamplesMapper.insertSelective(biologicalSamples); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -448,5 +466,10 @@ public class PatientService implements IPatientService { |
|
|
|
patientInformationMapper.updateByExampleSelective(patientInformation,patientInformationExample); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<BiologicalSamplesVo.selBiolog> queryByPatient(BiologicalSamplesDto.QueryByPatient param, Long userId) { |
|
|
|
return patientDao.queryByPatient(param, userId); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|