package thyyxxk.webserver.dao.his.jimubaobiao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.querydata.BaoBiaoChaXun;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;

/**
 * <p>
 * 描述： 积木报表
 * </p>
 *
 * @author xc
 * @date 2021-09-02 10:22
 */
@Mapper
public interface JiMuBaoBiaoDao {


    /**
     * 查询患者住院 是否超 30 天
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return list
     */
    @Select("select '超30天' name,count(*) value,'天' unit " +
            "from zy_inactpatient where admiss_date >= #{startTime} and admiss_date <= #{endTime} " +
            "and date_part('day',  cast(dis_date as TIMESTAMP) - cast(admiss_date as TIMESTAMP)) > 30 " +
            "union all " +
            "select '未超30天' name,count(*) value,'天' unit from zy_inactpatient where admiss_date >= #{startTime} and admiss_date <= #{endTime} " +
            "and date_part('day',  cast(dis_date as TIMESTAMP) - cast(admiss_date as TIMESTAMP)) < 30;")
    List<BaoBiaoChaXun> huanZheZhuYuanChao(@Param("startTime") Timestamp startTime,
                                           @Param("endTime") Timestamp endTime);

    /**
     * 查询患者入院间隔
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return list
     */
    @Select("select date_part('day',cast(dis_date as TIMESTAMP) - cast(admiss_date as TIMESTAMP)) tian_shu from zy_inactpatient " +
            "where admiss_date >= #{startTime} and admiss_date <= #{endTime}")
    List<BigDecimal> huanZheRuYuanJianGe(@Param("startTime") Timestamp startTime,
                                         @Param("endTime") Timestamp endTime);

    /**
     * 获取患者人数
     *
     * @param startTime 时间时间
     * @param endTime   结束时间
     * @return list
     */
    @Select("select count(*) count from zy_inactpatient where admiss_date >= #{startTime} and admiss_date <= #{endTime}")
    BigDecimal huanZheRenShu(@Param("startTime") Timestamp startTime,
                             @Param("endTime") Timestamp endTime);

}
