Browse Source

Merge branch 'dev' of huangzhanpeng/wlyy_management into dev

lyr 8 years ago
parent
commit
37e70ccf92

+ 26 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/job/FollowupPlanJob.java

@ -0,0 +1,26 @@
package com.yihu.wlyy.job;
import com.yihu.wlyy.service.app.followup.FollowUpService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
/**
 * Created by hzp on 2017.1.4.
 */
public class FollowupPlanJob implements Job {
    @Autowired
    FollowUpService followUpService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        System.out.print("follow plan message sending...");
        //发送随访计划消息
        followUpService.sendMessage();
    }
}

+ 4 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/followup/FollowUpDao.java

@ -15,6 +15,7 @@ import com.yihu.wlyy.entity.followup.Followup;
import java.util.Date;
import java.util.List;
import java.util.Map;
public interface FollowUpDao extends PagingAndSortingRepository<Followup, Long>, JpaSpecificationExecutor<Followup> {
@ -26,4 +27,7 @@ public interface FollowUpDao extends PagingAndSortingRepository<Followup, Long>,
    @Query(value = "select a.* from wlyy_followup a where a.doctor_code in ?1 and a.patient_code = ?2 and a.followup_class=?3 and a.status ='1' order by a.followup_date DESC limit 1",nativeQuery = true)
    Followup findLastFollowup(String[] doctors,String patientCode,String followClass) throws Exception;
    @Query(value = "select doctor_code,count(1) count from wlyy_followup where status not in ('0','1') and followup_plan_date>=?1 and followup_plan_date<=?2 group by doctor_code",nativeQuery = true)
    List<Map<String,String>> getFollowupToday(String start,String end) throws Exception;
}

+ 5 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/message/MessageDao.java

@ -14,6 +14,8 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface MessageDao extends PagingAndSortingRepository<Message, Long>, JpaSpecificationExecutor<Message> {
    @Query("select count(a) from Message a where a.type =1 and a.read= 1 and a.receiver=?1 ")
@ -43,4 +45,7 @@ public interface MessageDao extends PagingAndSortingRepository<Message, Long>, J
    @Query("select count(a) from Message a where a.read = 0 and a.over ='0'  and a.receiver=?1 and a.type=?2 ")
    int findMessageNum(String doctor, Integer type);
    @Query("select a from Message a where a.read= 1 and a.receiver = ?1 and a.sender=?2 and a.tzType=?3")
    List<Message> getHealthIndexMessageByPatient(String doctor,String patient,String type,Pageable pageRequest);
}

+ 57 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/followup/FollowUpService.java

@ -8,16 +8,18 @@ import com.yihu.wlyy.entity.dict.SystemDict;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.followup.Followup;
import com.yihu.wlyy.entity.followup.FollowupContent;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.followup.FollowupContentDao;
import com.yihu.wlyy.repository.message.MessageDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.team.DrHealthTeamService;
import com.yihu.wlyy.service.system.SystemDictService;
import com.yihu.wlyy.task.FollowupUploadTask;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -64,6 +66,9 @@ public class FollowUpService extends BaseService {
	@Autowired
	private DrHealthTeamService drHealthTeamService;
	@Autowired
	private MessageDao messageDao;
	/**
	 * 转译随访信息
     */
@ -550,7 +555,7 @@ public class FollowUpService extends BaseService {
				FollowupContent copyItem = new FollowupContent();
				copyItem.setFollowupId(id);
				copyItem.setFollowupKey(item.getFollowupKey());
				copyItem.setFollowupValue(item.getFollowupKey());
				copyItem.setFollowupValue(item.getFollowupValue());
				copyItem.setFollowupProject(item.getFollowupProject());
				copyItem.setCreateTime(new Date());
				copyList.add(copyItem);
@ -559,4 +564,54 @@ public class FollowUpService extends BaseService {
			followupContentDao.save(copyList);
		}
	}
	/**************************************** 随访计划消息 ******************************************/
	/**
	 * 每日发送随访计划提醒消息
     */
	@Transactional
	public void sendMessage()
	{
	    try{
			String date = DateUtil.dateToStrShort(new Date());
			String start = date +" 00:00:00";
			String end = date +" 23:59:59";
			//获取所有未执行随访计划
			List<Map<String,String>> followupToday = followupDao.getFollowupToday(start,end);
			if(followupToday!=null)
			{
				List<Message> list = new ArrayList<>();
				for(Map<String,String> map:followupToday)
				{
					String doctor = map.get("doctor_code");
					String count = map.get("count");
					// 添加签约消息
					Message message = new Message();
					message.setCode(getCode());
					message.setCzrq(new Date());
					message.setContent("您有一条新的家庭签约申请!");
					message.setRead(1);//设置未读
					message.setReceiver(doctor);//设置接受医生的code
					message.setSender("system");//设置发送的用户
					message.setTitle("随访计划提醒");
					message.setType(4);//随访计划提醒
					message.setReadonly(1);//是否只读消息
					list.add(message);
					// 推送消息给医生
					PushMsgTask.getInstance().put(doctor,"4","随访计划提醒","您今日有" +count+"个随访计划待处理","");
				}
				messageDao.save(list);
			}
		}
		catch (Exception e)
		{
		   e.printStackTrace();
		}
	}
}

+ 81 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/message/MessageService.java

@ -7,9 +7,11 @@ import javax.transaction.Transactional;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.message.MessageDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.SystemConf;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
@ -17,6 +19,7 @@ import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
@ -46,6 +49,8 @@ public class MessageService extends BaseService {
    private MessageDao messageDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private PatientDao patientDao;
    /**
     * 汇总查询医生的消息总数
@ -252,8 +257,81 @@ public class MessageService extends BaseService {
        return jo;
    }
    public void changeMessageToRead(Long id) {
        Message message= messageDao.findOne(id);
        message.setRead(1);
    /**
     * 获取超标指标消息--根据患者分组
     */
    public List<Map<String,Object>> getHealthIndexMessage(String doctor)throws Exception{
        List<Map<String,Object>> re = new ArrayList<>();
        String sql = "select a.sender,a.tz_type,count(1) count,max(date_format(a.czrq,'%Y-%c-%d %h:%i:%s')) last_time from wlyy_Message a where a.receiver='"+doctor+"' and a.has_read='1' and a.type='2' group by a.sender,a.tz_type order by last_time desc";
        List<Map<String,Object>> list =jdbcTemplate.queryForList(sql);
        for(Map<String,Object> item:list)
        {
            Map<String,Object> obj = new HashMap<>();
            String patientCode = String.valueOf(item.get("sender"));
            //获取患者信息
            Patient patient =patientDao.findByCode(patientCode);
            if(patient!=null)
            {
                String type = String.valueOf(item.get("tz_type")); //1血糖,2血压,3体重,4腰
                obj.put("patient",patientCode);
                obj.put("type",type);
                obj.put("time",item.get("last_time"));
                obj.put("name",patient.getName());
                obj.put("sex",patient.getSex());
                obj.put("birthday",DateUtil.dateToStrShort(patient.getBirthday()));
                obj.put("sex",patient.getSex());
                obj.put("photo",patient.getPhoto());
                if("1".equals(type))
                {
                    obj.put("message","有"+item.get("count")+"条血糖异常未读消息") ;
                }
                else if("2".equals(type))
                {
                    obj.put("message","有"+item.get("count")+"条血压异常未读消息") ;
                }
                else{
                    break;
                }
                re.add(obj);
            }
            else{
                System.out.print("not exit patient!code:"+patientCode);
            }
        }
        return re;
    }
    /**
     * 获取患者超标指标消息
     */
    public List<Map<String,String>> getHealthIndexMessageByPatient(String doctor, String patient, String type, Integer page, Integer pagesize)throws Exception{
        List<Map<String,String>> re = new ArrayList<>();
        // 排序
        Sort sort = new Sort(Sort.Direction.DESC, "czrq");
        Pageable pageRequest = new PageRequest(page-1, pagesize, sort);
        List<Message> list= messageDao.getHealthIndexMessageByPatient(doctor,patient,type,pageRequest);
        if(list!=null && list.size()>0)
        {
            for(Message item:list)
            {
                Map<String,String> map = new HashMap<>();
                map.put("id",String.valueOf(item.getId()));
                map.put("sender",item.getSender());
                map.put("senderName",item.getSenderName());
                map.put("senderPhoto",item.getSenderPhoto());
                map.put("type",type);
                map.put("read",String.valueOf(item.getRead()));
                map.put("sex",String.valueOf(item.getSex()));
                map.put("value1",String.valueOf(item.getValue1()));
                map.put("value2",String.valueOf(item.getValue2()));
                map.put("czrq",DateUtil.dateToStrLong(item.getCzrq()));
                re.add(map);
            }
        }
        return re;
    }
}

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

@ -300,4 +300,6 @@ public class DoctorHealthController extends BaseController {
		}
	}
}

+ 31 - 11
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/message/DoctorMessageController.java

@ -2,6 +2,8 @@ package com.yihu.wlyy.web.doctor.message;
import com.yihu.wlyy.entity.message.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -19,6 +21,7 @@ import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.web.BaseController;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value = "/doctor/message", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ -263,21 +266,38 @@ public class DoctorMessageController extends BaseController {
			return error(-1, "获取消息失败!");
		}
	}
	/**
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "changeMessageToRead")
	@RequestMapping(value = "getHealthIndexMessage",method = RequestMethod.GET)
	@ResponseBody
	public String changeMessageToRead(Long id) {
	@ApiOperation("获取超标指标消息--根据患者分组")
	public String getHealthIndexMessage()throws Exception{
		try {
			List<Map<String,Object>> list = messageService.getHealthIndexMessage(getUID());     //"D20161008003"
			return write(200, "获取超标指标消息成功", "data", list);
		} catch (Exception ex) {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
			 messageService.changeMessageToRead(id);
	@RequestMapping(value = "getHealthIndexMessageByPatient",method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation("获取患者超标指标消息")
	public String getHealthIndexMessageByPatient(@ApiParam(name="patient",value="患者代码",defaultValue = "P20161008001")
												 @RequestParam(value="patient",required = true) String patient,
												 @ApiParam(name="type",value="健康指标类型1血糖,2血压,3体重",defaultValue = "1")
												 @RequestParam(value="type",required = true) String type,
												 @ApiParam(name="page",value="第几页",defaultValue = "1")
												 @RequestParam(value="page",required = true) Integer page,
												 @ApiParam(name="pagesize",value="每页几行",defaultValue = "10")
												 @RequestParam(value="pagesize",required = true) Integer pagesize)throws Exception{
		try {
			List<Map<String,String>> list = messageService.getHealthIndexMessageByPatient(getUID(),patient,type,page,pagesize);
			return write(200, "修改成功!");
		} catch (Exception e) {
			error(e);
			return error(-1, "获取消息失败!");
			return write(200, "获取超标指标消息成功", "data", list);
		} catch (Exception ex) {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
}

+ 20 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/quota/JobController.java

@ -1,5 +1,6 @@
package com.yihu.wlyy.web.quota;
import com.yihu.wlyy.job.FollowupPlanJob;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.job.consult.ConsultCleanerJob;
import com.yihu.wlyy.job.consult.FamousConsultTimesJob;
@ -322,4 +323,23 @@ public class JobController extends BaseController {
            return error(-1, e.getMessage());
        }
    }
    /******************************************** 随访计划任务 **********************************************************************/
    @RequestMapping(value = "/followup/planJob", method = RequestMethod.POST)
    @ApiOperation("随访计划消息发送任务")
    public String addFollowPlanJob() {
        try {
            String jobKey = "followup-plan";
            if (!quartzHelper.isExistJob(jobKey)) {
                quartzHelper.addJob(FollowupPlanJob.class, "0 0/5 0 * * ?", jobKey, new HashMap<String, Object>());
                return write(200, "启动成功");
            } else {
                return write(200, "任务已存在");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "启动失败");
        }
    }
}