package thyyxxk.webserver.dao.his.medicalinsurance.costcontrol;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.medicalinsurance.costcontrol.YbClnAvgParam;
import thyyxxk.webserver.entity.medicalinsurance.costcontrol.YbSetlInfo;

import java.util.List;

/**
 * @description: 长浏宁次均控费
 * @author: hsh
 * @date: 2022/10/26 15:02
 * @param:
 * @return: null
 **/
@Mapper
public interface YbClnTimesAvgDao {

    @Select(" select top 1 * from yb_cln_avg_param where year = #{year} and insur_name = #{insurName} ")
    YbClnAvgParam selectClnAvgParam(@Param("year") String year, @Param("insurName") String insurName);

    @Select("<script> " +
            " select t.*, datediff(day, isnull(zy.admiss_date, zya.admiss_date), isnull(zy.dis_date, zya.dis_date)) inDays, " +
            " rtrim(isnull(zy.small_dept, zya.small_dept)) as deptId, rtrim(isnull(z.name, d.name)) as deptName," +
            " rtrim(isnull(zy.refer_physician, zya.refer_physician)) as doctorId, rtrim(isnull(e.name, f.name)) as doctor " +
            " from t_si_setlinfo t " +
            " left join zy_inactpatient zy on (zy.inpatient_no = t.pat_no and zy.admiss_times = t.times) " +
            " left join zy_actpatient zya on (zya.inpatient_no = t.pat_no and zya.admiss_times = t.times) " +
            " left join zd_unit_code z on zy.small_dept = z.code " +
            " left join zd_unit_code d on zya.small_dept = d.code " +
            " left join a_employee_mi e on zy.refer_physician = e.code " +
            " left join a_employee_mi f on zya.refer_physician = f.code " +
            " where t.revoked = '0' and t.setl_type = '21' " +
            " and t.setl_time &gt;= #{beginTime} " +
            " and t.setl_time &lt;= #{endTime} " +
            " and t.medins_type = #{insurName} " +
            " <if test=\"dept != null and dept != '' \"> " +
            " and rtrim(isnull(z.name, d.name)) = #{dept} " +
            " </if> " +
            " </script> ")
    List<YbSetlInfo> selectClnSetlData(@Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("insurName") String insurName, @Param("dept") String dept);

    @Select("<script> " +
            " select t.*, datediff(day, isnull(zy.admiss_date, zya.admiss_date), isnull(zy.dis_date, zya.dis_date)) inDays, " +
            " rtrim(isnull(zy.small_dept, zya.small_dept)) as deptId, rtrim(isnull(z.name, d.name)) as deptName," +
            " rtrim(isnull(zy.refer_physician, zya.refer_physician)) as doctorId, rtrim(isnull(e.name, f.name)) as doctor, " +
            " zd.dis_diag_comment as mainDiagnosis, ss.ssmc as mainOperation " +
            " from t_si_setlinfo t " +
            " left join zy_inactpatient zy on (zy.inpatient_no = t.pat_no and zy.admiss_times = t.times) " +
            " left join zy_actpatient zya on (zya.inpatient_no = t.pat_no and zya.admiss_times = t.times) " +
            " left join zd_unit_code z on zy.small_dept = z.code " +
            " left join zd_unit_code d on zya.small_dept = d.code " +
            " left join a_employee_mi e on zy.refer_physician = e.code " +
            " left join a_employee_mi f on zya.refer_physician = f.code " +
            " left join zy_dis_diag_yb zd on (zd.inpatient_no = t.pat_no and zd.admiss_times = t.times and zd.dis_diag_no = '1') " +
            " left join batj_ba4 ss on (ss.bah = t.pat_no and ss.zycs = t.times and ss.ssxh = '1') " +
            " where t.revoked = '0' and t.setl_type = '21' " +
            " and t.setl_time &gt;= #{beginTime} " +
            " and t.setl_time &lt;= #{endTime} " +
            " and t.medins_type = #{insurName} " +
            " and rtrim(isnull(z.name, d.name)) = #{dept} " +
            " and rtrim(isnull(e.name, f.name)) = #{doctor} " +
            " </script> ")
    List<YbSetlInfo> selectClnAvgFeePatient(@Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("insurName") String insurName,
                                       @Param("dept") String dept, @Param("doctor") String doctor);

}
