package com.yihu.wlyy.web.patient.family;

import com.yihu.wlyy.entity.patient.invitation.PatientInvitationLog;
import com.yihu.wlyy.service.app.family.FamilyService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2016.08.20.
 */
@Controller
@RequestMapping(value = "/patient/family", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "患者家庭")
public class PatientFamilyController extends BaseController {
    @Autowired
    private FamilyService familyService;


    /**
     * 查询医生是否有邀请改患者
     *
     * @param doctorCode 医生code
     * @return
     */
    @ResponseBody
    @RequestMapping("/getPatientInviteLog")
    public String getPatientInviteLog(String doctorCode, String invitePatientCode) {
        try {
            PatientInvitationLog patientInvitationLog = familyService.getPatientInviteLog(doctorCode, getUID(), invitePatientCode);
            if (patientInvitationLog != null) {
                return write(200, "查询成功!", "data", patientInvitationLog);
            }
            return write(200, "查询成功!", "data", "");
        } catch (Exception e) {
            error(e);
            return error(-1, "更新已读失败！");
        }
    }

    @ResponseBody
    @RequestMapping("/findPatientInviteLog")
    public String findPatientInviteLog(String invitePatientCode) {
        try {
            PatientInvitationLog patientInvitationLog = familyService.getPatientInviteLog( invitePatientCode);
            if (patientInvitationLog != null) {
                return write(200, "查询成功!", "data", patientInvitationLog);
            }
            return write(200, "查询成功!", "data", "");
        } catch (Exception e) {
            error(e);
            return error(-1, "更新已读失败！");
        }
    }

    /**
     * 更新邀请日志
     * @param patientInviteLogCode
     * @param type
     * @return
     */
    @ResponseBody
    @RequestMapping("/updatePatientInviteLog")
    public String updatePatientInviteLog(String patientInviteLogCode,
                                         String type) {
        try {
           familyService.updatePatientInviteLog(patientInviteLogCode, getUID(), type);

            return write(200, "更新成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "更新失败！"+e.getMessage());
        }
    }
}
