package com.yihu.wlyy.statistics.dao;

import com.yihu.wlyy.statistics.model.label.SignPatientLabelInfo;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created by lyr on 2016/10/9.
 */
public interface SignPatientLabelInfoDao extends
        PagingAndSortingRepository<SignPatientLabelInfo, Long>,
        JpaSpecificationExecutor<SignPatientLabelInfo> {

    /**
     * 查询某个患者的标签
     *
     * @param patient 患者
     * @param status  状态
     * @return
     */
    List<SignPatientLabelInfo> findByPatientAndStatus(String patient, Integer status);

    /**
     * 查询某个患者的某个类型标签
     *
     * @param patient   患者
     * @param labelType 标签类型
     * @param status    状态
     * @return
     */
    List<SignPatientLabelInfo> findByPatientAndLabelTypeAndStatus(String patient, String labelType, Integer status);

    /**
     * 查询某个患者的某个类型的某个标签
     *
     * @param patient   患者
     * @param labelCode  标签代码
     * @param labelType 标签类型
     * @param status    状态
     * @return
     */
    SignPatientLabelInfo findByPatientAndLabelAndLabelTypeAndStatus(String patient, String labelCode, String labelType, Integer status);

    /**
     * 删除患者的某个标签类型的所有指定状态标签
     *
     * @param patient
     * @param labelType
     * @param status
     * @return
     */
    int deleteByPatientAndLabelTypeAndStatus(String patient, String labelType, Integer status);

    /**
     * 更新某个标签名称
     *
     * @param labelName
     * @param labelCode
     * @return
     */
    @Query("update SignPatientLabelInfo a set a.labelName = ?1 where a.label= ?2 and a.labelType = '4' ")
    int updateLabelName(String labelName, String labelCode);

    List<SignPatientLabelInfo> findByLabelTypeAndStatus(String s, int i);
}
