package thyyxxk.webserver.dao.his.scheduled;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.scheduled.ClinicCount;
import thyyxxk.webserver.entity.scheduled.DailyPatientCount;

import java.util.List;

@Mapper
public interface DailyPatientCountDao {
    @Select("select inHospCount=((select count(1) from zy_actpatient with(nolock) where inpatient_no not like 'JT%')- " +
            "(select count(1) from zy_actpatient a with(nolock),yz_act_order b where a.inpatient_no not like 'JT%' " +
            "and a.inpatient_no=b.inpatient_no and a.admiss_times=b.admiss_times and b.status_flag > '2' and " +
            "isnull(b.group_no,'00' )='00' and b.order_code in " +
            "(select order_code from yz_zd_order_item_confirm where item_name in (N'出院',N'死亡')))), " +
            "admissCount=(select count(1) from zy_actpatient with(nolock) where datediff(day,admiss_date,getdate())=1), " +
            "dismissCount=((select count(1) from yz_act_order with(nolock) where status_flag > '2' and " +
            "datediff(day,start_time,getdate())=1 and isnull(group_no,'00' )='00' and order_code in " +
            "(select order_code from yz_zd_order_item_confirm where item_name=N'出院')) " +
            "+ (select count(1) from yz_inact_order with(nolock) where status_flag > '2' and " +
            "datediff(day,start_time,getdate())=1 and isnull(group_no,'00' )='00' and order_code in " +
            "(select order_code from yz_zd_order_item_confirm where item_name=N'出院'))), " +
            "deadCount=((select count(1) from yz_act_order with(nolock) where status_flag > '2' and " +
            "datediff(day,start_time,getdate())=1 and isnull(group_no,'00' )='00' and " +
            "order_code in (select order_code from yz_zd_order_item_confirm where item_name=N'死亡')) + " +
            "(select count(1) from yz_inact_order with(nolock) where status_flag > '2' and " +
            "datediff(day,start_time,getdate())=1 and isnull(group_no,'00' )='00' and order_code in " +
            "(select order_code from yz_zd_order_item_confirm where item_name=N'死亡')))," +
            "heavyCount=(select count(1) from yz_act_order with(nolock) where status_flag!='5' " +
            "and isnull(group_no,'00' )='00' and order_code='05888'), " +
            "dangerCount=(select count(1) from yz_act_order with(nolock) where status_flag!='5' " +
            "and isnull(group_no,'00' )='00' and order_code='05887'), " +
            "operationCount=(select count(1) from op_record with(nolock) where status!='d' and datediff(day,op_datetime,getdate())=1), " +
            "rescueCount=((select count(1) from yz_act_order with(nolock) where status_flag > '2' and " +
            "datediff(day,start_time,getdate())=1 and isnull(group_no,'00' )='00' and order_code in " +
            "('05202','04311','08893','08894','01535','01537','05243','02628','05240','05242','05241','04313','01446','06383', " +
            "'08897','08898','05011','01445','04312','08895','08896')) " +
            "+ (select count(1) from yz_inact_order with(nolock) where status_flag > '2' and " +
            "datediff(day,start_time,getdate())=1 and isnull(group_no,'00' )='00' and order_code in " +
            "('05202','04311','08893','08894','01535','01537','05243','02628','05240','05242','05241','04313','01446','06383', " +
            "'08897','08898','05011','01445','04312','08895','08896')))")
    DailyPatientCount selectDailyCount();

    @Select("select unit_code,unit_name=(select rtrim(name) from zd_unit_code with(nolock) where code=unit_code),count(1) as count " +
            "from mzy_reqrec with(nolock) where datediff(day,request_day,getdate())=1 and cancel_mark=0 group by unit_code " +
            "order by count desc")
    List<ClinicCount> selectClinicCount();

}
