瀏覽代碼

代码提交

huangwenjie 7 年之前
父節點
當前提交
08f1d0ae47
共有 14 個文件被更改,包括 339 次插入16 次删除
  1. 4 1
      patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/common/dao/PatientHealthIndexDao.java
  2. 15 10
      patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/service/DeviceService.java
  3. 1 1
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/controller/SignController.java
  4. 2 2
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/ZysoftService.java
  5. 9 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/event/ApplicationEvent.java
  6. 41 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/PatientDiseaseConditionSynJob.java
  7. 5 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/patient/PatientDao.java
  8. 41 0
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java
  9. 58 1
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java
  10. 60 1
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/web/quota/JobController.java
  11. 3 0
      patient-co/patient-co-wlyy-job/src/main/resources/system.properties
  12. 14 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java
  13. 5 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java
  14. 81 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthController.java

+ 4 - 1
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/common/dao/PatientHealthIndexDao.java

@ -53,5 +53,8 @@ public interface PatientHealthIndexDao
	List<PatientHealthIndex> findByType(String patient, String deviceSn, String value1, Integer type, Date recordDate);
	@Query("select a from PatientHealthIndex a where a.user = ?1 and a.type =?2  order by recordDate desc ")
    List<PatientHealthIndex> findByPatientAndType(String patientCode, String diseaseType, Pageable pageable);
    List<PatientHealthIndex> findByPatientAndType(String patientCode, int type, Pageable pageable);
	@Query("select count(a) from PatientHealthIndex a where a.recordDate >= ?1 and a.recordDate <= ?2 and a.type in (1,2) and a.status = ?3 and a.del = '1'")
	int getCountByTimeAndStatus(Date start, Date end,int status);
}

+ 15 - 10
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/service/DeviceService.java

@ -397,7 +397,6 @@ public class DeviceService {
                //连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----START
                String patientCode = result.getUser();
                //患者信息
                Patient patient = patientDao.findByCode(patientCode);
@ -408,19 +407,16 @@ public class DeviceService {
                Sort sort = new Sort(Sort.Direction.DESC, "recordDate");
                // 分页信息
                Pageable pageRequest = new PageRequest(0, 5, sort);
                Pageable pageable = new PageRequest(1, 5);
                List<PatientHealthIndex> bloodPressurepatientHealthIndices = new ArrayList<>();
                List<PatientHealthIndex> bloodSuggurpatientHealthIndices = new ArrayList<>();
                if( 1 == patient.getDisease()){
                    bloodPressurepatientHealthIndices = patientHealthIndexDao.findByPatientAndType(patientCode,"2",pageable);
                    bloodPressurepatientHealthIndices = patientHealthIndexDao.findByPatientAndType(patientCode,2,pageable);
                } else if( 2 == patient.getDisease()){
                    bloodSuggurpatientHealthIndices = patientHealthIndexDao.findByPatientAndType(patientCode,"1",pageable);
                    bloodSuggurpatientHealthIndices = patientHealthIndexDao.findByPatientAndType(patientCode,1,pageable);
                } else {
                    bloodPressurepatientHealthIndices = patientHealthIndexDao.findByPatientAndType(patientCode,"2",pageable);
                    bloodSuggurpatientHealthIndices = patientHealthIndexDao.findByPatientAndType(patientCode,"1",pageable);
                    bloodPressurepatientHealthIndices = patientHealthIndexDao.findByPatientAndType(patientCode,2,pageable);
                    bloodSuggurpatientHealthIndices = patientHealthIndexDao.findByPatientAndType(patientCode,1,pageable);
                }
                for (PatientHealthIndex patientHealthIndex : bloodPressurepatientHealthIndices) {
@ -436,9 +432,17 @@ public class DeviceService {
                }
                //连续5次异常,修改用户为预警状态
                if( (5 == bloodPressureBbnormalCount || 5 == bloodSuggurBbnormalCount) && 0 == patient.getStandardStatus()){
                //连续3次异常,修改用户为预警状态
                if( (3 == bloodPressureBbnormalCount || 3 == bloodSuggurBbnormalCount) && 0 == patient.getStandardStatus()){
                    patient.setStandardStatus(1);
                }else{
                    Date end = new Date();
                    Date start = DateUtil.setDateTime(end,-7);
                    //计算血糖或者血压一周内的异常记录数量
                    int errorCount = patientHealthIndexDao.getCountByTimeAndStatus(start,end,1);
                    if(errorCount >= 5){
                        patient.setStandardStatus(1);
                    }
                }
                //连续5次正常,修改用户为非预警状态
@ -446,6 +450,7 @@ public class DeviceService {
                    patient.setStandardStatus(0);
                }
                patientDao.save(patient);
                //连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----END
            }
        } catch (Exception e) {

+ 1 - 1
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/controller/SignController.java

@ -80,7 +80,7 @@ public class SignController {
			@RequestParam(value="TIME_END",required = true) String TIME_END){
		try {
			String response = signZYService.getSickFamilyDoctorSpecialistControl(TIME_START,TIME_END);
			return Result.success("查询签约成功!","");
			return Result.success("查询签约成功!",response);
		} catch (Exception ex) {
			ex.printStackTrace();
			if(ex instanceof ApiException)

+ 2 - 2
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/ZysoftService.java

@ -771,8 +771,8 @@ public class ZysoftService {
        header.put("LICENCE",licence);
        Map<String,String> params = new HashMap<>();
        params.put("TEAM_CODE",time_start);
        params.put("TEAM_CODE",time_end);
        params.put("TIME_START",time_start);
        params.put("TIME_END",time_end);
        String response = postSecond("getSickFamilyDoctorSpecialistControl","查询家签慢病患者定标情况接口",params,header,false);

+ 9 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/event/ApplicationEvent.java

@ -116,6 +116,15 @@ public class ApplicationEvent implements ApplicationListener<ContextRefreshedEve
                logger.info("doctor_feldsher_template_job reorder job job exist");
            }
            //慢病患者定标情况同步,每天凌晨2点执行一次
            if (!quartzHelper.isExistJob("patient_disease_contion_syn_job")) {
                String trigger = SystemConf.getInstance().getSystemProperties().getProperty("patient_disease_contion_syn_job");
                quartzHelper.addJob(PatientDiseaseConditionSynJob.class, trigger, "patient_disease_contion_syn_job", new HashMap<String, Object>());
                logger.info("patient_disease_contion_syn_job  job success");
            } else {
                logger.info("patient_disease_contion_syn_job  job exist");
            }
            // 启动redis 消息队列线程
            logger.info("redis message start");

+ 41 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/PatientDiseaseConditionSynJob.java

@ -0,0 +1,41 @@
package com.yihu.wlyy.job;
import com.yihu.wlyy.service.third.jw.JwPrescriptionService;
import com.yihu.wlyy.util.DateUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * 慢病患者定标情况同步JOB
 * @author huangwenjie
 * @date 2017/9/17 21:28
 */
public class PatientDiseaseConditionSynJob implements Job {
    private static final Logger logger = LoggerFactory.getLogger(PatientDiseaseConditionSynJob.class);
    @Autowired
    private JwPrescriptionService jwPrescriptionService;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        logger.info("START=====开始更新慢病患者定标情况的JOB");
        try {
            String startdate = DateUtil.getStringDateShort() + " 00:00:00";
            String enddate = DateUtil.getStringDateShort() + " 23:59:59";
            //根据起止时间查询家签慢病患者定标情况,并同步到本地数据库
            jwPrescriptionService.getPatientDiseaseContentMapByTime(startdate,enddate);
            logger.info("END========开始更新慢病患者定标情况成功JOB");
        }catch (Exception e){
            e.printStackTrace();
            logger.info("END===ERROE===开始更新慢病患者定标情况JOB,message:"+e.getMessage());
        }
    }
}

+ 5 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/patient/PatientDao.java

@ -64,4 +64,9 @@ public interface PatientDao extends PagingAndSortingRepository<Patient, Long> {
    //获取所有的openid并排重
    @Query("select distinct p.openid from Patient p where p.openid is not null and p.openid <> '' ")
    List<String> findOpenids();
    //根据患者身份证号更新患者颜色定标情况
    @Modifying
    @Query("update Patient p set p.diseaseCondition = ?2 where p.idcard = ?1")
    void updatePatientDiseascontionByIdcard(String idcard, Integer diseaseCondition);
}

+ 41 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java

@ -12,6 +12,7 @@ import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.ServerLabelTree;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.SignFamilyRenew;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionLog;
import com.yihu.wlyy.entity.security.Token;
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
@ -19,6 +20,7 @@ import com.yihu.wlyy.repository.doctor.DoctorPatientDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.security.TokenDao;
import com.yihu.wlyy.service.third.jw.JwPrescriptionService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.EncodesUtil;
import com.yihu.wlyy.util.IdcardInfoExtractor;
@ -27,13 +29,19 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springside.modules.utils.Clock;
import java.text.DateFormat;
@ -49,6 +57,8 @@ import java.util.*;
@Transactional(rollbackFor = Exception.class)
public class PatientService extends TokenService {
    private static final Logger logger = LoggerFactory.getLogger(PatientService.class);
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
@ -64,6 +74,9 @@ public class PatientService extends TokenService {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    private JpaTransactionManager transactionManager;
    private Clock clock = Clock.DEFAULT;
    //可续签月份
    private int[] canRenewMonth = {4, 5, 6, 7};
@ -982,4 +995,32 @@ public class PatientService extends TokenService {
    public void save(Patient patient) {
        patientDao.save(patient);
    }
    /**
     * 根据患者身份证号更新患者颜色定标情况
     * @param idcard_diseasecontion_map
     */
    @Transactional
    public void updatePatientDiseascontionByIdcard(HashMap<String, Integer> idcard_diseasecontion_map){
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别,开启新事务
        TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态
        try {
            for (String idcard : idcard_diseasecontion_map.keySet()) {
                patientDao.updatePatientDiseascontionByIdcard(idcard,idcard_diseasecontion_map.get(idcard));
            }
            //事务提交
            transactionManager.commit(status);
        } catch (Exception ex) {
            logger.info("更新患者颜色定标情况出错,从基卫获取的患者数据为:START");
            for (String idcard : idcard_diseasecontion_map.keySet()) {
                logger.info("idcard:"+idcard);
                logger.info("idcard:"+idcard_diseasecontion_map.get(idcard));
            }
            logger.info("更新患者颜色定标情况出错,从基卫获取的患者数据为:END");
            //报错事务回滚
            transactionManager.rollback(status);
        }
    }
}

+ 58 - 1
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java

@ -1,9 +1,11 @@
package com.yihu.wlyy.service.third.jw;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.util.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
@ -16,6 +18,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -36,7 +39,8 @@ public class JwPrescriptionService {
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private PrescriptionDao prescriptionDao;
    @Autowired
    private PatientService patientService;
    /**
     * 获取字典列表
     * @param dictName 字典名称
@ -228,4 +232,57 @@ public class JwPrescriptionService {
        return response;
    }
    /**
     * 根据起止时间查询家签慢病患者定标情况,并同步到本地数据库
     * @param startdate
     * @param enddate
     * @return
     */
    public void getPatientDiseaseContentMapByTime(String startdate, String enddate)throws Exception {
        logger.info("查询家签慢病患者定标情况,开始时间"+startdate+",结束时间:"+enddate);
        String url = jwUrl + "/third/sign/getSickFamilyDoctorSpecialistControl";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("TIME_START", startdate));//开始时间
        params.add(new BasicNameValuePair("TIME_END", enddate));//结束时间
        String response = httpClientUtil.post(url, params, "UTF-8");
        HashMap<String, Integer> idcard_diseasecontion_map = new HashMap<>();
        if(StringUtils.isNotBlank(response)){
            JSONObject reobj =  JSON.parseObject(response);
            Integer status = reobj.getInteger("status");
            String errmsg = reobj.getString("msg");
            if(200 == status){
                JSONObject jwData = reobj.getJSONObject("data");
                Integer jwCode = jwData.getInteger("CODE");
                if(1 == jwCode){
                    JSONArray dataArray = jwData.getJSONArray("DATA");
                    for (int i = 0; i < dataArray.size(); i++) {
                        JSONObject json = dataArray.getJSONObject(i);
                        String idcard = json.getString("IDENTITY_CARD_NO");//身份证号码
                        Integer diseaseCondition = json.getInteger("SPECIALIST_CONTROL");//定标情况【 0 绿标 1 黄标 2 红标】
                        idcard_diseasecontion_map.put(idcard,diseaseCondition);
                    }
                    if(idcard_diseasecontion_map != null && !idcard_diseasecontion_map.keySet().isEmpty()){
                        logger.info("从基卫接口获取需要更新定标情况的慢病患者个数为"+idcard_diseasecontion_map.keySet().size());
                        patientService.updatePatientDiseascontionByIdcard(idcard_diseasecontion_map);
                    }else{
                        logger.info("从基卫接口获取需要更新定标情况的慢病患者个数为"+idcard_diseasecontion_map.keySet().size());
                    }
                }else{
                    String jwMessage = jwData.getString("MESSAGE");
                    throw new Exception("获取慢病患者定标情况,请求基卫接口失败:"+jwMessage);
                }
            }else{
                throw new Exception("获取慢病患者定标情况请求失败,"+errmsg);
            }
        }else{
            throw new Exception("获取慢病患者定标情况请求失败,无数据返回!");
        }
    }
}

+ 60 - 1
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/web/quota/JobController.java

@ -8,14 +8,19 @@ import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.app.statistics.StatisticsService;
import com.yihu.wlyy.service.quota.JobService;
import com.yihu.wlyy.service.third.jw.JwPrescriptionService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
@ -40,15 +45,17 @@ public class JobController extends BaseController {
    private final QuartzHelper quartzHelper;
    private final DoctorWorkTimeService workTimeService;
    private final StatisticsService statisticsService;
    private final JwPrescriptionService jwPrescriptionService;
    @Autowired
    public JobController(StatisticsService statisticsService, JobService jobService, StringRedisTemplate redisTemplate, DoctorWorkTimeService workTimeService, PatientDiseaseService diseaseService, QuartzHelper quartzHelper) {
    public JobController(StatisticsService statisticsService, JobService jobService, StringRedisTemplate redisTemplate, DoctorWorkTimeService workTimeService, PatientDiseaseService diseaseService, QuartzHelper quartzHelper,JwPrescriptionService jwPrescriptionService) {
        this.statisticsService = statisticsService;
        this.jobService = jobService;
        this.redisTemplate = redisTemplate;
        this.workTimeService = workTimeService;
        this.diseaseService = diseaseService;
        this.quartzHelper = quartzHelper;
        this.jwPrescriptionService = jwPrescriptionService;
    }
    /**
@ -445,6 +452,7 @@ public class JobController extends BaseController {
        }
    }
    //******************************长处方 end********************************
    /**
     * 居民监测方案提醒通知
@ -463,4 +471,55 @@ public class JobController extends BaseController {
            return error(-1, e.getMessage());
        }
    }
    /**
     *立即执行当天的慢病患者定标情况同步
     *@author huangwenjie
     *@date 2017/9/17 14:16
     */
    @RequestMapping(value = "/executePatientDiseaseConditionSynJob", method = RequestMethod.POST)
    @ApiOperation("立即执行当天的慢病患者定标情况同步")
    public String executePatientDiseaseConditionSynJob() {
        try {
            quartzHelper.startNow(PatientDiseaseConditionSynJob.class, "PATIENT-DISEASE-CONDITION-SYN", null);
            return write(200, "启动成功");
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
    /**
     *根据时间范围执行慢病患者定标情况同步
     *@author huangwenjie
     *@date 2017/9/17 14:16
     */
    @RequestMapping(value = "/executePatientDiseaseConditionSynJobByTime", method = RequestMethod.POST)
    @ApiOperation("根据时间范围执行慢病患者定标情况同步")
    public String executePatientDiseaseConditionSynJobByTime(
            @ApiParam(name="startdate", value="开始时间:yyyy-mm-dd")
            @RequestParam(value = "startdate",required = true) String startdate,
            @ApiParam(name="enddate", value="结束时间:yyyy-mm-dd")
            @RequestParam(value = "enddate",required = true) String enddate) {
        try {
            String start = "";
            String end = "";
            do{
                start = startdate + " 00:00:00";
                end = startdate + " 23:59:59";
                //根据起止时间查询家签慢病患者定标情况,并同步到本地数据库
                jwPrescriptionService.getPatientDiseaseContentMapByTime(start,end);
                startdate = DateUtil.getNextDay(startdate,1);
            }while (!startdate.equals(enddate));
            return write(200, "执行成功");
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
}

+ 3 - 0
patient-co/patient-co-wlyy-job/src/main/resources/system.properties

@ -98,6 +98,9 @@ finish_consult_job=* 59 * * * ?
#提醒有监测方案的居民上传数据,每29分钟执行一次
doctor_feldsher_template_job=0 0/29 * * * ?
#病患者定标情况同步JOB (每天2点一次)
patient_disease_contion_syn_job=0 0 2 * * ?
#统一支付平台支付成功后页面跳转地址
return_url={server}/wx/html/qygl/html/pay_result.html

+ 14 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java

@ -1352,4 +1352,18 @@ public class PatientHealthIndexService extends BaseService {
    public Iterable<DoctorHealthStandard> findDoctorStandardByDoctor(String code) {
        return doctorHealthStandardDao.findByDoctor(code);
    }
    /**
     * 批量保存患者预警方案
     * @param list
     * @param patients
     * @return
     */
    public Iterable<PatientHealthStandard> saveStandardPatients(List<PatientHealthStandard> list, List<Patient> patients) {
        for (Patient patient:patients) {
            patientHealthStandardDao.deleteByPatient(patient.getCode());
        }
        return patientHealthStandardDao.save(list);
    }
}

+ 5 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java

@ -1011,4 +1011,9 @@ public class PatientService extends TokenService {
    public void save(Patient patient) {
        patientDao.save(patient);
    }
    public List<Patient> findAllSignPatientTeamcode(String teamcode) {
        return patientDao.findAllSignPatientTeamcode(teamcode);
    }
}

+ 81 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthController.java

@ -3,8 +3,10 @@ package com.yihu.wlyy.web.doctor.health;
import com.yihu.device.entity.DevicePatientHealthIndex;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.doctor.health.DoctorHealthStandard;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientHealthStandard;
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
@ -32,6 +34,9 @@ public class DoctorHealthController extends BaseController {
	@Autowired
	private PatientHealthIndexService healthIndexService;
	@Autowired
	private PatientService patientService;
	@RequestMapping(value = "recent",method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation("患者最近填写的健康指标")
@ -391,4 +396,80 @@ public class DoctorHealthController extends BaseController {
		}
	}
	@RequestMapping(value = "savastandbyteamcode",method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation("医生保存团队下所有居民的预警方案")
	public String doctorSaveStandardByTeamCode(
			@ApiParam("团队代码") @RequestParam String teamcode,
			@ApiParam("预警值Json") @RequestParam String json) {
		try {
			JSONArray array = new JSONArray(json);
			if (StringUtils.isEmpty(teamcode) || array == null || array.length() == 0) {
				return error(-1, "保存失败!");
			}
			List<Patient> patients = patientService.findAllSignPatientTeamcode(teamcode);
			if(!patients.isEmpty()){
				// 生成数据对象
				List<PatientHealthStandard> list = new ArrayList<>();
				//保存患者的数据时,同时医生的预警值方案
				List<DoctorHealthStandard> doclist = new ArrayList<>();
				for (int i = 0; i < array.length(); i++) {
					JSONObject obj = array.getJSONObject(i);
					if (obj == null) {
						continue;
					}
					for (Patient patient: patients) {
						PatientHealthStandard standard = new PatientHealthStandard();
						standard.setDoctor(getUID());
						standard.setMaxValue1(obj.has("max_value1") ? NumberUtils.toDouble(obj.getString("max_value1"), 0) : 0);
						standard.setMaxValue2(obj.has("max_value2") ? NumberUtils.toDouble(obj.getString("max_value2"), 0) : 0);
						standard.setMinValue1(obj.has("min_value1") ? NumberUtils.toDouble(obj.getString("min_value1"), 0) : 0);
						standard.setMinValue2(obj.has("min_value2") ? NumberUtils.toDouble(obj.getString("min_value2"), 0) : 0);
						standard.setType(obj.getInt("type"));
						standard.setPatient(patient.getCode());
						standard.setCzrq(new Date());
						list.add(standard);
					}
					DoctorHealthStandard doctorHealthStandard = new DoctorHealthStandard();
					doctorHealthStandard.setDoctor(getUID());
					doctorHealthStandard.setMaxValue1(obj.has("max_value1") ? NumberUtils.toDouble(obj.getString("max_value1"), 0) : 0);
					doctorHealthStandard.setMaxValue2(obj.has("max_value2") ? NumberUtils.toDouble(obj.getString("max_value2"), 0) : 0);
					doctorHealthStandard.setMinValue1(obj.has("min_value1") ? NumberUtils.toDouble(obj.getString("min_value1"), 0) : 0);
					doctorHealthStandard.setMinValue2(obj.has("min_value2") ? NumberUtils.toDouble(obj.getString("min_value2"), 0) : 0);
					doctorHealthStandard.setType(obj.getInt("type"));
					doctorHealthStandard.setCzrq(new Date());
					doclist.add(doctorHealthStandard);
				}
				if (list.size() == 0) {
					return error(-1, "保存失败!");
				}
				// 保存数据库
				Iterable<PatientHealthStandard> iterable = healthIndexService.saveStandardPatients(list, patients);
				if (iterable == null || iterable.iterator() == null || !iterable.iterator().hasNext()) {
					return error(-1, "保存失败!");
				}
				Iterable<DoctorHealthStandard> dociterable = healthIndexService.saveDocStandard(doclist, getUID());
				if (dociterable == null || dociterable.iterator() == null || !dociterable.iterator().hasNext()) {
					return error(-1, "保存失败!");
				}
			}
			return write(200, "保存成功");
		} catch (Exception e) {
			error(e);
			return invalidUserException(e, -1, "操作失败!");
		}
	}
}