diff --git a/tcm/src/main/java/com/ccsens/tcm/bean/dto/PatientDto.java b/tcm/src/main/java/com/ccsens/tcm/bean/dto/PatientDto.java index 66371261..1c46cc04 100644 --- a/tcm/src/main/java/com/ccsens/tcm/bean/dto/PatientDto.java +++ b/tcm/src/main/java/com/ccsens/tcm/bean/dto/PatientDto.java @@ -31,14 +31,16 @@ public class PatientDto { @Data @ApiModel("保存患者的多个病例信息") public static class saveCaseMes { + @ApiModelProperty("患者id") + private Long patientId; + @ApiModelProperty("患者病情记录") List list; } - @Data @ApiModel("患者的某个病例信息") public static class saveCaseMesSig { - @ApiModelProperty("患者id") - private Long patientId; + @ApiModelProperty("病患记录id") + private Long patientRecordId; @ApiModelProperty("问题id") private Long testQuestionsId; @ApiModelProperty("内容") @@ -46,6 +48,6 @@ public class PatientDto { @NotNull @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty("诊断时间") - private Date timeSlot; + private Date timeSlot=new Date(System.currentTimeMillis()); } } diff --git a/tcm/src/main/java/com/ccsens/tcm/service/PatientService.java b/tcm/src/main/java/com/ccsens/tcm/service/PatientService.java index 2a7f961f..25c1f50c 100644 --- a/tcm/src/main/java/com/ccsens/tcm/service/PatientService.java +++ b/tcm/src/main/java/com/ccsens/tcm/service/PatientService.java @@ -3,8 +3,11 @@ package com.ccsens.tcm.service; import cn.hutool.core.lang.Snowflake; import com.ccsens.tcm.bean.dto.PatientDto; 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.persist.mapper.PatientInformationMapper; +import com.ccsens.tcm.persist.mapper.PatientRecordMapper; import com.ccsens.tcm.persist.mapper.ReportCodeMapper; import com.ccsens.util.RedisUtil; import lombok.extern.slf4j.Slf4j; @@ -14,6 +17,10 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; @Slf4j @Service @@ -27,6 +34,9 @@ public class PatientService implements IPatientService { private RedisUtil redisUtil; @Resource private ReportCodeMapper reportCodeMapper; + @Resource + private PatientRecordMapper patientRecordMapper; + @Override public void savePatient(PatientDto.SavePatient param, Long userId) { @@ -38,22 +48,103 @@ public class PatientService implements IPatientService { @Override 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 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) { for (int i = 0; i < param.getList().size(); i++) { - //先查询试题id + //先查询试题id,查看需要记录的次数 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){ //试题只需要记录一次的 + patientRecord.setCollectTime(0); }else if(reportCode.getReportType()==(byte)1){ - //试题只需要记录3次的 + //算出时间差 + int cha=timeDifference(patientRecord.getTimeSlot(),onsetTime); + if(cha=one && cha=two){ + //记录two之后的 + patientRecord.setCollectTime(twoAfter); + } + }else if(reportCode.getReportType()==(byte)2){ //试题需要记录两次的 + int cha=timeDifference(patientRecord.getTimeSlot(),onsetTime); + if(cha