yeshijie před 8 roky
rodič
revize
d6499a9e08

+ 1 - 0
patient-co-figure/src/main/java/com/yihu/figure/config/SwaggerConfig.java

@ -46,6 +46,7 @@ public class SwaggerConfig extends WebMvcConfigurerAdapter {
                        regex("/patient/.*"),
                        regex("/disease/.*"),
                        regex("/medicine/.*"),
                        regex("/job/.*"),
                        regex("/health/.*")
                ))
                .build()

+ 25 - 0
patient-co-figure/src/main/java/com/yihu/figure/config/quartz/JobFactory.java

@ -0,0 +1,25 @@
package com.yihu.figure.config.quartz;
import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.stereotype.Component;
/**
 * Created by Administrator on 2016.10.12.
 * 為了讓quartz種可以使用Spring的注入
 */
@Component("jobFactory")
public class JobFactory extends AdaptableJobFactory {
    @Autowired
    private AutowireCapableBeanFactory capableBeanFactory;
    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
        // 调用父类的方法
        Object jobInstance = super.createJobInstance(bundle);
       // 进行注入
        capableBeanFactory.autowireBean(jobInstance);
        return jobInstance;
    }
}

+ 52 - 0
patient-co-figure/src/main/java/com/yihu/figure/config/quartz/SchedulerConfig.java

@ -0,0 +1,52 @@
package com.yihu.figure.config.quartz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import javax.sql.DataSource;
import java.io.IOException;
import java.util.Properties;
/**
 * Created by chenweida on 2016/2/3.
 */
@Configuration
public class SchedulerConfig {
    @Autowired
    private ApplicationContext applicationContext;
    @Autowired
    private JobFactory jobFactory;
    @Autowired
    private DataSource dataSource;
    @Bean
    SchedulerFactoryBean schedulerFactoryBean() throws IOException {
        SchedulerFactoryBean bean = new SchedulerFactoryBean();
        bean.setJobFactory(jobFactory);
        bean.setApplicationContext(this.applicationContext);
        bean.setOverwriteExistingJobs(true);
        bean.setStartupDelay(20);// 延时启动
        bean.setAutoStartup(true);
        bean.setDataSource(dataSource);
        bean.setQuartzProperties(quartzProperties());
        return bean;
    }
    /**
     * quartz配置文件
     * @return
     * @throws IOException
     */
    @Bean
    public Properties quartzProperties() throws IOException {
        PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
        propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
        propertiesFactoryBean.afterPropertiesSet();
        return propertiesFactoryBean.getObject();
    }
}

+ 22 - 2
patient-co-figure/src/main/java/com/yihu/figure/controller/health/HealthIndexController.java

@ -33,7 +33,7 @@ public class HealthIndexController extends BaseController {
    @RequestMapping(value="autoHealth" ,method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "自动生成体征数据")
    public String autoHealth(@ApiParam(name="patient",value="居民",defaultValue = "915cd110-5b1d-11e6-8344-fa163e8aee56")
    public String autoHealth(@ApiParam(name="patient",value="居民",defaultValue = "915d1169-5b1d-11e6-8344-fa163e8aee56")
                             @RequestParam(value="patient",required = true) String patient,
                             @ApiParam(name="type",value="类型1血糖、2血压、3体重、4腰围",defaultValue = "4")
                             @RequestParam(value="type",required = false) String type){
@ -46,6 +46,26 @@ public class HealthIndexController extends BaseController {
        }
    }
    /**
     * 统计居民体征数据
     * @param patient
     * @return
     */
    @RequestMapping(value="staticsHealth" ,method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "统计居民体征数据")
    public String staticsHealth(@ApiParam(name="patient",value="居民",defaultValue = "915d1169-5b1d-11e6-8344-fa163e8aee56")
                                @RequestParam(value="patient",required = true) String patient){
        try{
            healthIndexService.statistics(patient);
            return write(200,"统计成功");
        }catch (Exception e){
            e.printStackTrace();
            return error(-1, "统计失败");
        }
    }
    /**
     * 自动生成体征数据
     * @param patient
@ -55,7 +75,7 @@ public class HealthIndexController extends BaseController {
    @RequestMapping(value="healthIndex" ,method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取居民体征数据")
    public String healthIndex(@ApiParam(name="patient",value="居民",defaultValue = "915cd110-5b1d-11e6-8344-fa163e8aee56")
    public String healthIndex(@ApiParam(name="patient",value="居民",defaultValue = "915d1169-5b1d-11e6-8344-fa163e8aee56")
                              @RequestParam(value="patient",required = true) String patient,
                              @ApiParam(name="type",value="类型1血糖、2血压",defaultValue = "1")
                              @RequestParam(value="type",required = true) String type,

+ 4 - 0
patient-co-figure/src/main/java/com/yihu/figure/dao/health/HealthIndexDao.java

@ -9,6 +9,7 @@ import com.yihu.figure.model.health.HealthIndex;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
public interface HealthIndexDao extends PagingAndSortingRepository<HealthIndex, Long> {
@ -18,4 +19,7 @@ public interface HealthIndexDao extends PagingAndSortingRepository<HealthIndex,
	@Query(value = "select * from wlyy_health_index where user=?1 and type =?2 and record_date between ?3 and ?4 order by record_date desc limit 0,1",nativeQuery = true)
	HealthIndex findByPatientAndType(String patient,String type,String startTime,String endTime);
	@Query("select p from HealthIndex p where p.user = ?1 and p.type=?2 and p.recordDate between ?3 and ?4 order by p.recordDate desc")
	List<HealthIndex> findByUserAndRecordDate(String patient,Integer type, Date startTime,Date endTime);
}

+ 9 - 0
patient-co-figure/src/main/java/com/yihu/figure/dao/health/HealthIndexStatisticsDao.java

@ -1,10 +1,19 @@
package com.yihu.figure.dao.health;
import com.yihu.figure.model.health.HealthIndexStatistics;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by yeshijie on 2017/3/6.
 */
public interface HealthIndexStatisticsDao extends PagingAndSortingRepository<HealthIndexStatistics, Long> {
    @Query(value = "select a.* from wlyy_health_index_statistics a where a.user=?1 and a.type=1 order by a.czrq desc limit 21",nativeQuery = true)
    List<HealthIndexStatistics> findByPatientXT(String patient);
    @Query(value = "select a.* from wlyy_health_index_statistics a where a.user=?1 and a.type=2 order by a.czrq desc limit 9",nativeQuery = true)
    List<HealthIndexStatistics> findByPatientXY(String patient);
}

+ 6 - 6
patient-co-figure/src/main/java/com/yihu/figure/model/health/HealthIndex.java

@ -22,17 +22,17 @@ public class HealthIndex extends IdEntity {
	private String user;
	// 血糖/收缩压/体重/腰围/早餐前空腹
	private String value1;
	// 舒张压/早餐后空腹
	// 舒张压/早餐后空腹 1空腹血糖 2早餐后血糖 3午餐前血糖 4午餐后血糖 5晚餐前血糖 6晚餐后血糖 7睡前血糖
	private String value2;
	// 午餐空腹
	// 心率
	private String value3;
	// 午餐后
	//
	private String value4;
	// 晚餐空腹
	//收缩压是否正常(0正常,1偏高,-1偏低)
	private String value5;
	// 晚餐后
	//舒张压是否正常(0正常,1偏高,-1偏低)
	private String value6;
	// 睡前
	// 血糖、血压、心率是否正常(0正常,1偏高,-1偏低)
	private String value7;
	// 健康指标类型(1血糖,2血压,3体重,4腰围)
	private int type;

+ 1 - 1
patient-co-figure/src/main/java/com/yihu/figure/model/health/HealthIndexStatistics.java

@ -28,7 +28,7 @@ public class HealthIndexStatistics extends IdEntity {
	private Integer type;
	//测试类型(1空腹血糖 2早餐后血糖 3午餐前血糖 4午餐后血糖 5晚餐前血糖 6晚餐后血糖 7睡前血糖,8舒张压,9收缩压,10心率)
	private Integer bloodType;
	//时间类型
	//时间类型(1近1个月,2近半年,3近1年)
	private Integer timeType;
	// 添加时间
	private Date czrq;

+ 217 - 14
patient-co-figure/src/main/java/com/yihu/figure/service/health/HealthIndexService.java

@ -36,6 +36,15 @@ public class HealthIndexService extends BaseService {
    private DecimalFormat df = new DecimalFormat("#.0");
    /**
     * 统计居民体征数据
     * @param patient
     */
    public void statistics(String patient){
        statisticsXT(patient);
        statisticsXY(patient);
    }
    /**
     * 获取居民体征数据
     * @param patient
@ -85,7 +94,7 @@ public class HealthIndexService extends BaseService {
                "where user = '"+patient+"' " +
                "and time_type="+timeType+" " +
                "and blood_type='"+bloodType+"' " +
                "limit 1";
                "order by czrq desc limit 1";
        List<Map<String,Object>> list2 = jdbcTemplate.queryForList(sql2);
        Map<String,Object> map = null;
        if(list2.size()>0){
@ -144,15 +153,15 @@ public class HealthIndexService extends BaseService {
     * @param idcard
     */
    public List<HealthIndex> xuetang(String patient, String deviceSn, String idcard, List<HealthIndex> list){
        String startTime = DateUtil.getStringDateShort()+" 00:00:00";
        String endTime = DateUtil.getStringDateShort()+" 23:59:59";
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR,-1);
        String startTime = DateUtil.dateToStrShort(cal.getTime())+" 00:00:00";
        String endTime = DateUtil.dateToStrShort(cal.getTime())+" 23:59:59";
        HealthIndex healthIndex = healthIndexDao.findByPatientAndType(patient,"1",startTime,endTime);
        if(healthIndex!=null){//判断是否已经生成过数据
            return list;
        }
        Calendar cal = Calendar.getInstance();
        String fasting = "07:00:00";
        String afterBreakfast = "09:00:00";
        String beforeLunch = "11:00:00";
@ -488,6 +497,200 @@ public class HealthIndexService extends BaseService {
        return list;
    }
    /**
     * 统计血压
     * @param patient
     * @param type 健康指标类型(1血糖,2血压)
    //     * @param bloodType 测试类型(8舒张压,9收缩压,10心率)
     * @param timeType 时间类型(1近1个月,2近半年,3近1年)
     * @param list
     * @param statisticsList
     */
    private void statisticsXY(String patient,Integer type, Integer timeType,List<HealthIndex> list,List<HealthIndexStatistics> statisticsList){
        int high1=0,low1=0,normal1=0;//舒张压
        int high2=0,low2=0,normal2=0;//收缩压
        int high3=0,low3=0,normal3=0;//心率
        for (HealthIndex healthIndex:list){
            //统计数据
            Double value1 = Double.parseDouble(healthIndex.getValue1());
            Double value2 = Double.parseDouble(healthIndex.getValue2());
            Double value3 = Double.parseDouble(healthIndex.getValue3());
            int flag1 = ETLConstantData.ssy(value1);
            int flag2 = ETLConstantData.szy(value2);
            int flag3 = ETLConstantData.heartRate(value3);
            if(flag1>0){
                high1 ++;
            }else if(flag1<0){
                low1 ++;
            }else {
                //正常
                normal1 ++;
            }
            if(flag2>0){
                high2 ++;
            }else if(flag2<0){
                low2 ++;
            }else {
                //正常
                normal2 ++;
            }
            if(flag3>0){
                high3 ++;
            }else if(flag3<0){
                low3 ++;
            }else {
                //正常
                normal3 ++;
            }
        }
        HealthIndexStatistics healthIndexStatistics1 = new HealthIndexStatistics(patient,high1,normal1,low1,type,8,timeType,new Date());
        HealthIndexStatistics healthIndexStatistics2 = new HealthIndexStatistics(patient,high2,normal2,low2,type,9,timeType,new Date());
        HealthIndexStatistics healthIndexStatistics3 = new HealthIndexStatistics(patient,high3,normal3,low3,type,10,timeType,new Date());
        statisticsList.add(healthIndexStatistics1);
        statisticsList.add(healthIndexStatistics2);
        statisticsList.add(healthIndexStatistics3);
    }
    /**
     * 统计血压
     * @param patient
     * @param timeType  时间类型(1近1个月,2近半年,3近1年)
     * @param startTime
     * @param endTime
     * @param statisticsList
     */
    private void statisticsXY(String patient,Integer timeType,Date startTime,Date endTime,List<HealthIndexStatistics> statisticsList){
        List<HealthIndex> list = healthIndexDao.findByUserAndRecordDate(patient,2,startTime,endTime);
        statisticsXY(patient,2,timeType,list,statisticsList);
    }
    /**
     * 统计血压
     * @param patient
     */
    private void statisticsXY(String patient){
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR,-29);
        String startMonth = DateUtil.dateToStrShort(cal.getTime())+" 00:00:00";
        cal.add(Calendar.DAY_OF_YEAR,-(182-30));
        String startHalfYear = DateUtil.dateToStrShort(cal.getTime())+" 00:00:00";
        cal.add(Calendar.DAY_OF_YEAR,-(365-182));
        String startYear = DateUtil.dateToStrShort(cal.getTime())+" 00:00:00";
        String endTime = DateUtil.getStringDateShort() + " 23:59:59";
        Date start1 = DateUtil.strToDate(startMonth);
        Date start2 = DateUtil.strToDate(startHalfYear);
        Date start3 = DateUtil.strToDate(startYear);
        Date end = DateUtil.strToDate(endTime);
        List<HealthIndexStatistics> statisticsList = new ArrayList<>();
        statisticsXY(patient,1,start1,end,statisticsList);
        statisticsXY(patient,2,start2,end,statisticsList);
        statisticsXY(patient,3,start3,end,statisticsList);
        healthIndexStatisticsDao.save(statisticsList);
    }
    /**
     * 统计血糖
     * @param patient
     * @param type 健康指标类型(1血糖,2血压)
     * @param bloodType 测试类型(1空腹血糖 2早餐后血糖 3午餐前血糖 4午餐后血糖 5晚餐前血糖 6晚餐后血糖 7睡前血糖)
     * @param timeType 时间类型(1近1个月,2近半年,3近1年)
     * @param list
     * @param statisticsList
     */
    private void statisticsXT(String patient,Integer type, Integer bloodType, Integer timeType,List<HealthIndex> list,List<HealthIndexStatistics> statisticsList){
        int high=0,low=0,normal=0;
        for (HealthIndex healthIndex:list){
            //统计数据
            Double value = Double.parseDouble(healthIndex.getValue1());
            int flag = 0;
            if(type%2==1){
                flag = ETLConstantData.xueTangBefore(value);
            }else{
                flag = ETLConstantData.xueTangAfter(value);
            }
            if(flag>0){
                high ++;
            }else if(flag<0){
                low ++;
            }else {
                //正常
                normal ++;
            }
        }
        HealthIndexStatistics healthIndexStatistics = new HealthIndexStatistics(patient,high,normal,low,type,bloodType,timeType,new Date());
        statisticsList.add(healthIndexStatistics);
    }
    /**
     * 统计血糖
     * @param patient
     * @param timeType  时间类型(1近1个月,2近半年,3近1年)
     * @param startTime
     * @param endTime
     * @param statisticsList
     */
    private void statisticsXT(String patient,Integer timeType,Date startTime,Date endTime,List<HealthIndexStatistics> statisticsList){
        List<HealthIndex> list = healthIndexDao.findByUserAndRecordDate(patient,1,startTime,endTime);
        List<HealthIndex> list1 = new ArrayList<>();
        List<HealthIndex> list2 = new ArrayList<>();
        List<HealthIndex> list3 = new ArrayList<>();
        List<HealthIndex> list4 = new ArrayList<>();
        List<HealthIndex> list5 = new ArrayList<>();
        List<HealthIndex> list6 = new ArrayList<>();
        List<HealthIndex> list7 = new ArrayList<>();
        for (HealthIndex healthIndex:list){
            String value2 = healthIndex.getValue2();
            if("1".equals(value2)){
                list1.add(healthIndex);
            }else if("2".equals(value2)){
                list2.add(healthIndex);
            }else if("3".equals(value2)){
                list3.add(healthIndex);
            }else if("4".equals(value2)){
                list4.add(healthIndex);
            }else if("5".equals(value2)){
                list5.add(healthIndex);
            }else if("6".equals(value2)){
                list6.add(healthIndex);
            }else if("7".equals(value2)){
                list7.add(healthIndex);
            }
        }
        statisticsXT(patient,1,1,timeType,list1,statisticsList);
        statisticsXT(patient,1,2,timeType,list2,statisticsList);
        statisticsXT(patient,1,3,timeType,list3,statisticsList);
        statisticsXT(patient,1,4,timeType,list4,statisticsList);
        statisticsXT(patient,1,5,timeType,list5,statisticsList);
        statisticsXT(patient,1,6,timeType,list6,statisticsList);
        statisticsXT(patient,1,7,timeType,list7,statisticsList);
    }
    /**
     * 统计血糖
     * @param patient
     */
    private void statisticsXT(String patient){
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR,-29);
        String startMonth = DateUtil.dateToStrShort(cal.getTime())+" 00:00:00";
        cal.add(Calendar.DAY_OF_YEAR,-(182-30));
        String startHalfYear = DateUtil.dateToStrShort(cal.getTime())+" 00:00:00";
        cal.add(Calendar.DAY_OF_YEAR,-(365-182));
        String startYear = DateUtil.dateToStrShort(cal.getTime())+" 00:00:00";
        String endTime = DateUtil.getStringDateShort() + " 23:59:59";
        Date start1 = DateUtil.strToDate(startMonth);
        Date start2 = DateUtil.strToDate(startHalfYear);
        Date start3 = DateUtil.strToDate(startYear);
        Date end = DateUtil.strToDate(endTime);
        List<HealthIndexStatistics> statisticsList = new ArrayList<>();
        statisticsXT(patient,1,start1,end,statisticsList);
        statisticsXT(patient,2,start2,end,statisticsList);
        statisticsXT(patient,3,start3,end,statisticsList);
        healthIndexStatisticsDao.save(statisticsList);
    }
    /**
     * 血压
     * @param patient
@ -495,15 +698,15 @@ public class HealthIndexService extends BaseService {
     * @param idcard
     */
    public List<HealthIndex> xueya(String patient, String deviceSn, String idcard, int age, String sex, List<HealthIndex> list){
        String startTime = DateUtil.getStringDateShort()+" 00:00:00";
        String endTime = DateUtil.getStringDateShort()+" 23:59:59";
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR,-1);
        String startTime = DateUtil.dateToStrShort(cal.getTime())+" 00:00:00";
        String endTime = DateUtil.dateToStrShort(cal.getTime())+" 23:59:59";
        HealthIndex healthIndex = healthIndexDao.findByPatientAndType(patient,"2",startTime,endTime);
        if(healthIndex!=null){//判断是否已经生成过数据
            return list;
        }
        Calendar cal = Calendar.getInstance();
        int value1,value2,value3,value4,intValue1,intValue2;
        //140/90mmHg至160/95mmHg之间,不能确定为高血压
        //成年人收缩压90-139.舒张压60-89为正常
@ -588,11 +791,11 @@ public class HealthIndexService extends BaseService {
                high32 += i<halfYear?1:0;
                high33 ++;
            }
//            else if(flag3<0){
//                low31 += i<month?1:0;
//                low31 += i<halfYear?1:0;
//                low31 ++;
//            }
            else if(flag3<0){
                low31 += i<month?1:0;
                low31 += i<halfYear?1:0;
                low31 ++;
            }
            else{
                normal31 += i<month?1:0;
                normal32 += i<halfYear?1:0;

+ 11 - 5
patient-co-figure/src/main/java/com/yihu/figure/util/ETLConstantData.java

@ -12,7 +12,7 @@ public class ETLConstantData {
    // 血糖餐前最大值
    public static final double HEALTH_STANDARD_ST_MAX_BEFORE = 7;
    // 血糖餐后最小值
    public static final double HEALTH_STANDARD_ST_MIN_AFTER = 4;
    public static final double HEALTH_STANDARD_ST_MIN_AFTER = 7;
    // 血糖餐后最大值
    public static final double HEALTH_STANDARD_ST_MAX_AFTER = 11.1;
@ -24,6 +24,10 @@ public class ETLConstantData {
    public static final int HEALTH_STANDARD_SSY_MIN = 90;
    // 收缩压最大值
    public static final int HEALTH_STANDARD_SSY_MAX = 140;
    // 心率最小值
    public static final int HEALTH_STANDARD_HEARTRATE_MIN = 50;
    // 心率最大值
    public static final int HEALTH_STANDARD_HEARTRATE_MAX = 100;
    /**
     * 性别
@ -102,11 +106,13 @@ public class ETLConstantData {
     * @return
     */
    public static int heartRate(double rate) {
        if (rate >= 40 && rate <= 160) {
            return 0;//"心率正常";
        } else {
            return 1;//"心率不正常";
        if (rate < ETLConstantData.HEALTH_STANDARD_HEARTRATE_MIN) {
            return -1;
        }
        if (rate > ETLConstantData.HEALTH_STANDARD_HEARTRATE_MAX) {
            return 1;
        }
        return 0;
    }