package thyyxxk.webserver.dao.his.dashboard;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.dashboard.InpatientBrief;

import java.util.List;

@Mapper
public interface DashboardDao {

    @Select("select rtrim(bed_no) as bedNo, " +
            "rtrim(name) as name, " +
            "sex as gender, " +
            "rtrim(inpatient_no) as patNo, " +
            "birthDate=(select t.birth_date from a_patient_mi t where t.inpatient_no=a.inpatient_no), " +
            "admiss_date, " +
            "convertAdmissDate=admiss_date, " +
            "physician=(select rtrim(t.name) from a_employee_mi t where t.code=a.refer_physician), " +
            "a.med_type, " +
            "surgery=(select top 1 rtrim(op_name) from op_record t where t.inpatient_no=a.inpatient_no " +
            "and t.admiss_times=a.admiss_times and t.status!='d' and datediff(day ,getdate(), t.op_datetime)=0), " +
            "nursingLevel=(select top 1 rtrim(order_name) from yz_act_order t where " +
            "t.order_code in ('05298','05299','05300','05301') and t.group_no='00' and t.status_flag in ('3','4')  " +
            "and t.inpatient_no=a.inpatient_no order by t.start_time desc), " +
            "sickLevelOrderName=(select top 1 rtrim(order_name) from yz_act_order t where " +
            "t.order_code in ('05887','05888') and t.group_no='00' and t.status_flag in ('3','4')  " +
            "and t.inpatient_no=a.inpatient_no order by t.start_time desc)  " +
            "from zy_actpatient a where (zk_ward=#{dept} or zk_ward in " +
            "(select small_dept from zd_dept_all t where t.dept=#{dept})) " +
            "order by cast(bed_no as int)")
    List<InpatientBrief> selectInpatientBrief(@Param("dept") String dept);
}
