package thyyxxk.webserver.dao.his.zhuyuanyiji;

import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.inpatient.FeeSelect;
import thyyxxk.webserver.entity.inpatient.chargeinputinquiry.ChargeInputItem;
import thyyxxk.webserver.entity.inpatient.chargeinputinquiry.InquiryParams;

import java.util.List;

public interface ChargeInputInquiryDao {

    @Select("select distinct code,name,specification=N'诊疗项目', " +
            "manufactor=(select d.name from yp_zd_manufactory d where manu_code=d.code) from zd_charge_item  " +
            "where (py_code like #{content} or code like #{content} or name like #{content})")
    List<FeeSelect> selectProjectCharges(String content);

    @Select("select distinct code,name,specification, " +
            "manufactor=(select d.name from yp_zd_manufactory d where manu_code=d.code) from yp_zd_dict " +
            "where (py_code like #{content} or code like #{content} or name like #{content})")
    List<FeeSelect> selectMedicineCharges(String content);

    @Select("select rtrim(dept_code) from a_employee_mi where code=#{code}")
    String selectUserDept(String code);

    @Select("select rtrim(a.inpatient_no) as patNo,a.admiss_times as times,a.ledger_sn,a.detail_sn, " +
            "staffName=(select rtrim(e.name) from a_employee_mi e where e.code=a.op_id_code), " +
            "a.charge_fee,a.charge_date,inOutFlag=1,orderNo=cast(cast(a.order_no as decimal) as varchar),a.charge_amount,a.gen_time, " +
            "chargeStatus=case when a.charge_status='2' then N'上账' when a.charge_status='3' then N'结算' else N'录入' end, " +
            "deptName=(select e.name from zd_unit_code e where e.code=a.ward_code), " +
            "opeFlag=case when a.ope_flag='1' then N'是' else N'否' end, " +
            "a.charge_code_mx,a.serial,patName=b.name,spec=c.specification,drugName=c.name,orderName=c.name " +
            "FROM zy_detail_charge a with (nolock),a_patient_mi b with (nolock),yp_zd_dict c with (nolock),zy_actpatient d with (nolock) " +
            "where a.charge_code in ('BILL01','BILL02','BILL28') and a.inpatient_no=b.inpatient_no  " +
            "and a.charge_code_mx=c.code and a.serial=c.serial and a.inpatient_no=d.inpatient_no  " +
            "and a.admiss_times=d.admiss_times and a.gen_time>=#{start} and a.gen_time<=#{end} " +
            "and a.inpatient_no like '${patNo}' and a.charge_code_mx like '${chargeCode}' " +
            "and a.op_id_code in (select code from a_employee_mi where dept_code=#{dept}) " +
            "union all " +
            "select rtrim(a.inpatient_no) as patNo,a.admiss_times as times,a.ledger_sn,a.detail_sn, " +
            "staffName=(select rtrim(e.name) from a_employee_mi e where e.code=a.op_id_code), " +
            "a.charge_fee,a.charge_date,inOutFlag=2,orderNo=cast(cast(a.order_no as decimal) as varchar),a.charge_amount,a.gen_time, " +
            "chargeStatus=case when a.charge_status='2' then N'上账' when a.charge_status='3' then N'结算' else N'录入' end, " +
            "deptName=(select e.name from zd_unit_code e where e.code=a.ward_code), " +
            "opeFlag=case when a.ope_flag='1' then N'是' else N'否' end, " +
            "a.charge_code_mx,a.serial,patName=b.name,spec=c.specification,drugName=c.name,orderName=c.name " +
            "FROM zy_detail_charge a with (nolock),a_patient_mi b with (nolock), " +
            "yp_zd_dict c with (nolock),zy_inactpatient d with (nolock) " +
            "where a.charge_code in ('BILL01','BILL02','BILL28') and a.inpatient_no=b.inpatient_no  " +
            "and a.charge_code_mx=c.code and a.serial=c.serial and a.inpatient_no=d.inpatient_no  " +
            "and a.admiss_times=d.admiss_times and a.gen_time>=#{start} and a.gen_time<=#{end} " +
            "and a.inpatient_no like '${patNo}' and a.charge_code_mx like '${chargeCode}' " +
            "and a.op_id_code in (select code from a_employee_mi where dept_code=#{dept}) ")
    List<ChargeInputItem> selectMedicineInputItems(InquiryParams params);

    @Select("SELECT rtrim(a.inpatient_no) as patNo,a.admiss_times as times,a.ledger_sn,a.detail_sn, " +
            "staffName=(select rtrim(e.name) from a_employee_mi e where e.code=a.op_id_code), " +
            "chargeStatus=case when a.charge_status='2' then N'上账' when a.charge_status='3' then N'结算' else N'录入' end, " +
            "deptName=(select e.name from zd_unit_code e where e.code=a.ward_code), " +
            "orderNo=cast(cast(a.order_no as decimal) as varchar),a.charge_amount,a.gen_time,a.charge_code_mx,a.charge_fee,a.charge_date, " +
            "opeFlag=case when a.ope_flag='1' then N'是' else N'否' end, " +
            "a.serial,patName=b.name,spec=c.charge_unit,drugName=c.name,orderName=c.name,c.class_code,inOutFlag=1 " +
            "FROM zy_detail_charge a with (nolock),a_patient_mi b with (nolock),zd_charge_item c with (nolock),zy_actpatient d with (nolock) " +
            "where a.charge_code not in ('BILL01','BILL02','BILL03','BILL28')  and a.inpatient_no=b.inpatient_no " +
            "and a.charge_code=c.code and a.inpatient_no=d.inpatient_no and a.admiss_times=d.admiss_times " +
            "and a.gen_time>=#{start} and a.gen_time<=#{end} and a.charge_code_mx like '${chargeCode}' " +
            "and a.inpatient_no like '${patNo}' and a.op_id_code in (select code from a_employee_mi where dept_code=#{dept}) " +
            "union all " +
            "SELECT rtrim(a.inpatient_no) as patNo,a.admiss_times as times,a.ledger_sn,a.detail_sn, " +
            "staffName=(select rtrim(e.name) from a_employee_mi e where e.code=a.op_id_code), " +
            "chargeStatus=case when a.charge_status='2' then N'上账' when a.charge_status='3' then N'结算' else N'录入' end, " +
            "deptName=(select e.name from zd_unit_code e where e.code=a.ward_code), " +
            "orderNo=cast(cast(a.order_no as decimal) as varchar),a.charge_amount,a.gen_time,a.charge_code_mx,a.charge_fee,a.charge_date, " +
            "opeFlag=case when a.ope_flag='1' then N'是' else N'否' end, " +
            "a.serial,patName=b.name,spec=c.charge_unit,drugName=c.name,orderName=c.name,c.class_code,inOutFlag=2 " +
            "FROM zy_detail_charge a with (nolock),a_patient_mi b with (nolock),zd_charge_item c with (nolock),zy_inactpatient d with (nolock) " +
            "where a.charge_code not in ('BILL01','BILL02','BILL03','BILL28')  and a.inpatient_no=b.inpatient_no " +
            "and a.charge_code=c.code and a.inpatient_no=d.inpatient_no and a.admiss_times=d.admiss_times " +
            "and a.gen_time>=#{start} and a.gen_time<=#{end} and a.charge_code_mx like '${chargeCode}' " +
            "and a.inpatient_no like '${patNo}' and a.op_id_code in (select code from a_employee_mi where dept_code=#{dept}) ")
    List<ChargeInputItem> selectProjectInputItems(InquiryParams params);
}
