@ -5,15 +5,13 @@ import cn.hutool.core.lang.Snowflake;
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.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.* ;
import com.ccsens.tcm.bean.vo.ConRecVo ;
import com.ccsens.tcm.bean.vo.PatientVo ;
import com.ccsens.tcm.bean.vo.QuestionVo ;
import com.ccsens.tcm.bean.vo.StatisticVo ;
import com.ccsens.tcm.persist.dao.PatientDao ;
import com.ccsens.tcm.persist.mapper.InpatientMapper ;
import com.ccsens.tcm.persist.mapper.PatientInformationMapper ;
import com.ccsens.tcm.persist.mapper.PatientRecordMapper ;
import com.ccsens.tcm.persist.mapper.ReportCodeMapper ;
@ -32,6 +30,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource ;
import java.text.ParseException ;
import java.text.SimpleDateFormat ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Date ;
import java.util.List ;
@ -51,6 +51,8 @@ public class PatientService implements IPatientService {
private PatientRecordMapper patientRecordMapper ;
@Resource
private PatientDao patientDao ;
@Resource
private InpatientMapper inpatientMapper ;
@Override
public void savePatient ( PatientDto . SavePatient param , Long userId ) {
@ -62,28 +64,33 @@ public class PatientService implements IPatientService {
@Override
public void saveCaseMes ( PatientDto . saveCaseMes param , Long userId ) {
//获取上次的发病时间
//拿到这个患者的基本信息
PatientInformation patientInformation = patientInformationMapper . selectByPrimaryKey ( param . getPatientId ( ) ) ;
//发病时间的试题id
Long disease_time = Long . parseLong ( String . valueOf ( redisUtil . get ( Constant . Redis . DISEASE_TIME ) ) ) ;
//Long disease_time=1355131504711442432L;
//升序查询,发病试题答案的数量
PatientRecordExample patientRecordExample1 = new PatientRecordExample ( ) ;
patientRecordExample1 . setOrderByClause ( "rec_status" ) ;
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 记录2次的 270 算分界线 <270 算180 ,>270 算365
int one = 9 ;
int two = 30 ;
@ -93,26 +100,30 @@ public class PatientService implements IPatientService {
int three = 270 ;
int threeFront = 180 ;
int threeAfter = 365 ;
//试题只需要记录2次的
//是否需要去修改基本信息表中的录入状态
Boolean update = false ;
//先查看这个患者的需要的记录次数,在下面的这个对照组对象中呢
Inpatient inpatient = inpatientMapper . selectByPrimaryKey ( patientInformation . getInpatientId ( ) ) ;
//下面是对试题进行提交
if ( param . getList ( ) . size ( ) > 0 ) {
for ( int i = 0 ; i < param . getList ( ) . size ( ) ; i + + ) {
//先查询试题id,查看需要记录的次数
ReportCode reportCode = reportCodeMapper . selectByPrimaryKey ( param . getList ( ) . get ( i ) . getTestQuestionsId ( ) ) ;
// // 先查询试题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 ) {
if ( inpatient . getCollectionNum ( ) = = 1 ) {
//试题只需要记录一次的
patientRecord . setCollectTime ( 0 ) ;
} else if ( reportCode . getReportType ( ) = = ( byte ) 1 ) {
} else if ( inpatient . getCollectionNum ( ) = = 3 ) {
//需要记录三次的
//算出时间差
int cha = timeDifference ( patientRecord . getTimeSlot ( ) , onsetTime ) ;
if ( cha < one ) {
@ -126,7 +137,7 @@ public class PatientService implements IPatientService {
patientRecord . setCollectTime ( twoAfter ) ;
}
} else if ( reportCode . getReportType ( ) = = ( byte ) 2 ) {
} else if ( inpatient . getCollectionNum ( ) = = 2 ) {
//试题需要记录两次的
int cha = timeDifference ( patientRecord . getTimeSlot ( ) , onsetTime ) ;
if ( cha < three ) {
@ -139,13 +150,26 @@ public class PatientService implements IPatientService {
if ( patientRecord . getId ( ) ! = null ) {
//更新
patientRecordMapper . updateByPrimaryKeySelective ( patientRecord ) ;
} else {
//添加
patientRecord . setId ( snowflake . nextId ( ) ) ;
patientRecordMapper . insertSelective ( patientRecord ) ;
update = true ;
}
}
}
//根据获取的发病时间答案数和需要搜集次数以及本次是需要更新,还是插入答案 , 来做修改基本信息中的录入状态
if ( update ) {
if ( patientRecordList . size ( ) + 1 < inpatient . getCollectionNum ( ) ) {
//数据搜集中
patientInformation . setInputStatus ( ( byte ) 1 ) ;
} else if ( patientRecordList . size ( ) + 1 = = inpatient . getCollectionNum ( ) ) {
patientInformation . setInputStatus ( ( byte ) 2 ) ;
}
patientInformationMapper . updateByPrimaryKeySelective ( patientInformation ) ;
}
}
@Override
@ -214,6 +238,21 @@ public class PatientService implements IPatientService {
return selCountS ;
}
@Override
public List < StatisticVo . SelGroupNum > countAnalysis ( StatisticDto . SelBinLCount param , Long userId ) {
List < StatisticVo . SelGroupNum > selGroupNumsList = new ArrayList < StatisticVo . SelGroupNum > ( ) ;
if ( param . getInpatientId ( ) ! = null & & param . getInpatientId ( ) . length = = 0 )
return selGroupNumsList ;
for ( int i = 0 ; i < param . getInpatientId ( ) . length ; i + + ) {
StatisticVo . SelGroupNum selGroupNum = new StatisticVo . SelGroupNum ( ) ;
StatisticVo . SelGroupList selGroupList = patientDao . countAnalysis ( param . getConditionList ( ) , param . getConditionListDate ( ) , param . getInpatientId ( ) [ i ] , param . getTestQuestionsId ( ) , param . getHospitalization ( ) , param . getInputStatus ( ) , param . getHospitalId ( ) ) ;
selGroupNum . setInpatientId ( param . getInpatientId ( ) [ i ] ) ;
selGroupNum . getList ( ) . add ( selGroupList ) ;
selGroupNumsList . add ( selGroupNum ) ;
}
return selGroupNumsList ;
}
/ * *
* 换算时间差 , 返回两个时间 之间差几天 , 要是小于1天 , 按照1的算 , 要是大于1的话 , 小于2的话 , 说的是秒啊 。 按照2的算 , 进一法啊
* @param bigDate 大时间