|
@ -3,8 +3,11 @@ package com.ccsens.tcm.service; |
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
import com.ccsens.tcm.bean.dto.PatientDto; |
|
|
import com.ccsens.tcm.bean.dto.PatientDto; |
|
|
import com.ccsens.tcm.bean.po.PatientInformation; |
|
|
import com.ccsens.tcm.bean.po.PatientInformation; |
|
|
|
|
|
import com.ccsens.tcm.bean.po.PatientRecord; |
|
|
|
|
|
import com.ccsens.tcm.bean.po.PatientRecordExample; |
|
|
import com.ccsens.tcm.bean.po.ReportCode; |
|
|
import com.ccsens.tcm.bean.po.ReportCode; |
|
|
import com.ccsens.tcm.persist.mapper.PatientInformationMapper; |
|
|
import com.ccsens.tcm.persist.mapper.PatientInformationMapper; |
|
|
|
|
|
import com.ccsens.tcm.persist.mapper.PatientRecordMapper; |
|
|
import com.ccsens.tcm.persist.mapper.ReportCodeMapper; |
|
|
import com.ccsens.tcm.persist.mapper.ReportCodeMapper; |
|
|
import com.ccsens.util.RedisUtil; |
|
|
import com.ccsens.util.RedisUtil; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
@ -14,6 +17,10 @@ import org.springframework.transaction.annotation.Propagation; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
|
|
|
import java.text.ParseException; |
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
@ -27,6 +34,9 @@ public class PatientService implements IPatientService { |
|
|
private RedisUtil redisUtil; |
|
|
private RedisUtil redisUtil; |
|
|
@Resource |
|
|
@Resource |
|
|
private ReportCodeMapper reportCodeMapper; |
|
|
private ReportCodeMapper reportCodeMapper; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private PatientRecordMapper patientRecordMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void savePatient(PatientDto.SavePatient param, Long userId) { |
|
|
public void savePatient(PatientDto.SavePatient param, Long userId) { |
|
@ -38,22 +48,103 @@ public class PatientService implements IPatientService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void saveCaseMes(PatientDto.saveCaseMes param, Long userId) { |
|
|
public void saveCaseMes(PatientDto.saveCaseMes param, Long userId) { |
|
|
//获取发病时间id
|
|
|
//获取上次的发病时间
|
|
|
Integer onsetTime=Integer.parseInt((String) redisUtil.get("disease_time")); |
|
|
Long disease_time=Long.parseLong((String) redisUtil.get("disease_time")); |
|
|
|
|
|
PatientRecordExample patientRecordExample1=new PatientRecordExample(); |
|
|
|
|
|
patientRecordExample1.createCriteria().andPatientIdEqualTo(param.getPatientId()).andTestQuestionsIdEqualTo(disease_time).andRecStatusEqualTo((byte)0); |
|
|
|
|
|
List<PatientRecord> patientRecordList = patientRecordMapper.selectByExample(patientRecordExample1); |
|
|
|
|
|
Date onsetTime=null; |
|
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
if(patientRecordList.size()>0){ |
|
|
|
|
|
//有病发试题的情况
|
|
|
|
|
|
try { |
|
|
|
|
|
onsetTime=format.parse(patientRecordList.get(0).getContents().trim()); |
|
|
|
|
|
} catch (ParseException e) { |
|
|
|
|
|
PatientInformation patientInformation = patientInformationMapper.selectByPrimaryKey(param.getPatientId()); |
|
|
|
|
|
onsetTime=patientInformation.getCreatedAt(); |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
}else { |
|
|
|
|
|
//没有病发试题的情况
|
|
|
|
|
|
PatientInformation patientInformation = patientInformationMapper.selectByPrimaryKey(param.getPatientId()); |
|
|
|
|
|
onsetTime=patientInformation.getCreatedAt(); |
|
|
|
|
|
} |
|
|
|
|
|
//试题只需要记录3次的 9 和30 算分界限 <9 =0 ;<30 =14 ; >30 =90
|
|
|
|
|
|
int one=9; |
|
|
|
|
|
int two=30; |
|
|
|
|
|
int oneFront=0; |
|
|
|
|
|
int oneAfter=14; |
|
|
|
|
|
int twoAfter=90; |
|
|
|
|
|
int three=270; |
|
|
|
|
|
int threeFront=180; |
|
|
|
|
|
int threeAfter=365; |
|
|
|
|
|
//试题只需要记录2次的
|
|
|
|
|
|
|
|
|
if(param.getList().size()>0) { |
|
|
if(param.getList().size()>0) { |
|
|
for (int i = 0; i < param.getList().size(); i++) { |
|
|
for (int i = 0; i < param.getList().size(); i++) { |
|
|
//先查询试题id
|
|
|
//先查询试题id,查看需要记录的次数
|
|
|
ReportCode reportCode = reportCodeMapper.selectByPrimaryKey(param.getList().get(i).getTestQuestionsId()); |
|
|
ReportCode reportCode = reportCodeMapper.selectByPrimaryKey(param.getList().get(i).getTestQuestionsId()); |
|
|
|
|
|
|
|
|
|
|
|
PatientRecord patientRecord=new PatientRecord(); |
|
|
|
|
|
BeanUtils.copyProperties(param.getList().get(i),patientRecord); |
|
|
|
|
|
patientRecord.setPatientId(param.getPatientId()); |
|
|
|
|
|
|
|
|
|
|
|
if(param.getList().get(i).getPatientRecordId()!=null){ |
|
|
|
|
|
//患者记录表的id
|
|
|
|
|
|
patientRecord.setId(param.getList().get(i).getPatientRecordId()); |
|
|
|
|
|
} |
|
|
|
|
|
patientRecord.setUserId(userId); |
|
|
if(reportCode.getReportType()==(byte)0){ |
|
|
if(reportCode.getReportType()==(byte)0){ |
|
|
//试题只需要记录一次的
|
|
|
//试题只需要记录一次的
|
|
|
|
|
|
patientRecord.setCollectTime(0); |
|
|
}else if(reportCode.getReportType()==(byte)1){ |
|
|
}else if(reportCode.getReportType()==(byte)1){ |
|
|
//试题只需要记录3次的
|
|
|
//算出时间差
|
|
|
|
|
|
int cha=timeDifference(patientRecord.getTimeSlot(),onsetTime); |
|
|
|
|
|
if(cha<one){ |
|
|
|
|
|
//记录的one之前的
|
|
|
|
|
|
patientRecord.setCollectTime(oneFront); |
|
|
|
|
|
}else if(cha>=one && cha<two){ |
|
|
|
|
|
//记录oneh和two之间的
|
|
|
|
|
|
patientRecord.setCollectTime(oneAfter); |
|
|
|
|
|
}else if(cha>=two){ |
|
|
|
|
|
//记录two之后的
|
|
|
|
|
|
patientRecord.setCollectTime(twoAfter); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
}else if(reportCode.getReportType()==(byte)2){ |
|
|
}else if(reportCode.getReportType()==(byte)2){ |
|
|
//试题需要记录两次的
|
|
|
//试题需要记录两次的
|
|
|
|
|
|
int cha=timeDifference(patientRecord.getTimeSlot(),onsetTime); |
|
|
|
|
|
if(cha<three){ |
|
|
|
|
|
patientRecord.setCollectTime(threeFront); |
|
|
|
|
|
}else { |
|
|
|
|
|
patientRecord.setCollectTime(threeAfter); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//进行数据更新
|
|
|
|
|
|
if(patientRecord.getId()!=null){ |
|
|
|
|
|
//更新
|
|
|
|
|
|
patientRecordMapper.updateByPrimaryKeySelective(patientRecord); |
|
|
|
|
|
}else { |
|
|
|
|
|
//添加
|
|
|
|
|
|
patientRecord.setId(snowflake.nextId()); |
|
|
|
|
|
patientRecordMapper.insertSelective(patientRecord); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 换算时间差 ,返回两个时间 之间差几天,要是小于1天,按照1的算,要是大于1的话,小于2的话,说的是秒啊。按照2的算,进一法啊 |
|
|
|
|
|
* @param bigDate 大时间 |
|
|
|
|
|
* @param simDate 小时间 |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
public int timeDifference(Date bigDate,Date simDate){ |
|
|
|
|
|
int a=0; |
|
|
|
|
|
double c= (((double)(bigDate.getTime() - simDate.getTime())) / (1000*3600*24)); |
|
|
|
|
|
a=(int)Math.ceil(c); |
|
|
|
|
|
return a; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|