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.datamodify.ZyDetailCharge;

import java.util.List;
import java.util.Map;

@Mapper
public interface YbUtilDao {

    @Select("<script> " +
            "select top 40 rtrim(name) as name, rtrim(code) as code from zd_unit_code with(nolock) where code not like '8%' and del_flag = 0 " +
            "<if test=\"str != null and str != '' \"> " +
            " and (name like '%${str}%' or code like '%${str}%' or py_code like ('%' + upper(#{str}) + '%') or d_code like ('%' + upper(#{str}) + '%') ) " +
            "</if> " +
            "order by code " +
            "</script> ")
    List<Map<String, Object>> selectSmallDept(@Param("str") String str);

    @Select("<script> " +
            "select top 40 rtrim(name) as name, rtrim(code) as code from a_employee_mi with(nolock) where 1 = 1 " +
            "<if test=\"str != null and str != '' \"> " +
            " and (name like '%${str}%' or code like '%${str}%' or py_code like ('%' + upper(#{str}) + '%') or d_code like ('%' + upper(#{str}) + '%') ) " +
            "</if> " +
            "order by py_code " +
            "</script> ")
    List<Map<String, Object>> selectDoctor(@Param("str") String str);

    /**
     * @description: 查询使用了特殊的项目或者材料
     * @author: hsh
     * @date: 2022/11/1 11:20
     * @param: [patNo, times, ledgerSn]
     * @return: List<ZyDetailChargeTable>
     **/
    @Select(" select * from zy_detail_charge " +
            "where inpatient_no = #{patNo} and admiss_times = #{times} and ledger_sn = #{ledgerSn} " +
            "and charge_code in ( " +
            "select code from zd_charge_item where national_code like #{item} " +
            ") ")
    List<ZyDetailCharge> selectInterventionalProject(@Param("patNo") String patNo, @Param("times") Integer times,
        @Param("ledgerSn") Integer ledgerSn, @Param("item") String item);

    /**
     * @description: 查询病人使用抗肿瘤药物（做化疗时用到的药，但不包括抗肿瘤辅助用药）
     * @author: hsh
     * @date: 2022/11/8 15:50
     * @param: [patNo, times]
     * @return: List<Map<String,Object>>
     **/
    @Select(" select top 10 * from yp_zy_patient" +
            " where rtrim(inpatient_no) = #{patNo} and admiss_times = #{times} " +
            " and charge_code in " +
            " (select charge_code from yp_base " +
            "  where class_code in " +
            "  (select code from yp_zd_class where code like '09%' and code <> '090900' ) " +
            " ) ")
    List<Map<String, Object>> selectChemotherapyDigan(@Param("patNo") String patNo, @Param("times") Integer times);

    @Select("<script> " +
            "select rtrim(name) as label, rtrim(code) as value from zd_unit_code with(nolock) where code not like '8%' and del_flag = 0 " +
            "<if test=\"str != null and str != '' \"> " +
            " and (name like '%${str}%' or code like '%${str}%' or py_code like ('%' + upper(#{str}) + '%') or d_code like ('%' + upper(#{str}) + '%') ) " +
            "</if> " +
            "order by code " +
            "</script> ")
    List<Map<String, Object>> selectAllSmallDept(@Param("str") String str);

    @Select("<script> " +
            "select rtrim(name) as label, rtrim(code) as value from a_employee_mi with(nolock) where 1 = 1 " +
            "<if test=\"str != null and str != '' \"> " +
            " and (name like '%${str}%' or code like '%${str}%' or py_code like ('%' + upper(#{str}) + '%') or d_code like ('%' + upper(#{str}) + '%') ) " +
            "</if> " +
            "<if test=\"dept != null and dept != '' \"> " +
            "and dept_code = #{dept} " +
            "</if> " +
            "order by py_code " +
            "</script> ")
    List<Map<String, Object>> selectAllDoctor(@Param("str") String str, @Param("dept") String dept);

    @Select("<script> " +
            "select rtrim(name) as label, rtrim(code) as value from zd_unit_code with(nolock) where del_flag = 0 " +
            "<if test=\"str != null and str != '' \"> " +
            " and (name like '%${str}%' or code like '%${str}%' or py_code like ('%' + upper(#{str}) + '%') or d_code like ('%' + upper(#{str}) + '%') ) " +
            "</if> " +
            "order by code " +
            "</script> ")
    List<Map<String, Object>> selectAllDept(@Param("str") String str);

    @Select("<script> " +
            "select rtrim(name) as label, rtrim(code) as value from mzy_zd_charge_type where isnull(del_flag, '0') = '0'  " +
            "<if test=\"str != null and str != '' \"> " +
            " and (name like '%${str}%' or code like '%${str}%' or py_code like ('%' + upper(#{str}) + '%') or d_code like ('%' + upper(#{str}) + '%') ) " +
            "</if> " +
            "order by rtrim(code) " +
            "</script> ")
    List<Map<String, Object>> selectAllRegLevel(@Param("str") String str);

    @Select(" select name from sys_parameters where code = #{code} ")
    String selectDeptYbbQxByRole(@Param("code") String code);

    @Select("<script> " +
            "select rtrim(name) as name, rtrim(code) as code from zd_unit_code with(nolock) where code not like '8%' and del_flag = 0 " +
            "<if test=\"codeList != null \"> " +
            " and code in " +
            "<foreach collection='codeList' item='code' separator=',' open='(' close=')'>" +
            "#{code}" +
            "</foreach> " +
            "</if> " +
            "order by code " +
            "</script> ")
    List<Map<String, Object>> selectSmallDeptByCode(@Param("codeList") List<String> codeList);

}
