package com.yihu.wlyy.web.doctor.followup;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yihu.wlyy.entity.follow.FollowUpPlanRemind;
import com.yihu.wlyy.service.app.followup.FollowUpPlanRemindService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.MessageType;
import com.yihu.wlyy.web.BaseController;

/**
 * 医生端：随访提醒
 * @author George
 *
 */
@Controller
@RequestMapping(value = "/doctor/followup/remind")
@Api(description = "随访提醒")
public class DoctorFollowUpPlanRemindController extends BaseController {

	@Autowired
	private FollowUpPlanRemindService followUpPlanRemindService;

	/**
	 * 添加随访提醒
	 * @param patient 患者标识
	 * @param doctorName 医生姓名
	 * @param plan 计划标识
	 * @param content 提醒内容
	 * @return
	 */
	@RequestMapping(value = "add")
	@ResponseBody
	public String add(String patient, String doctorName, String plan, String content) {
		try {
			FollowUpPlanRemind remind = followUpPlanRemindService.add(patient, getUID(), doctorName, plan, content);
			if (remind == null) {
				// 添加失败
				return error(-1, "提醒失败！");
			} else {
				// 添加成功
				// 推送消息给患者
				PushMsgTask.getInstance().put(patient, MessageType.MESSAGE_TYPE_PATIENT_FOLLOW_UP_TIPS.P_FU_02.name(), MessageType.MESSAGE_TYPE_PATIENT_FOLLOW_UP_TIPS.随访提醒.name(), MessageType.MESSAGE_TYPE_PATIENT_FOLLOW_UP_TIPS.您有新的随访提醒.name(), String.valueOf(remind.getId()));
				return success("提醒成功！");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "提醒失败！");
		}
	}

}
