package cn.hnthyy.thmz.mapper.his.yz;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

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

public interface YzYpZyOrderMapper {
    /**
     * 查询医瞩药品接口表中的住院明细
     * @param inpatientNo 住院号
     * @param admissTimes 住院次数
     * @param infantFlag 是否婴儿
     * @return
     */
    @Select({"<script>",
            "SELECT " +
                    " rtrim(inpatient_no) inpatientNo, " +
                    " admiss_times admissTimes, " +
                    " chargeDate = occ_time, " +
                    " rtrim(charge_code) chargeCode, " +
                    " infant_flag infantFlag, " +
                    " chargeStatus = " +
                    "CASE " +
                    "   " +
                    "  WHEN status_flag = '1'  " +
                    " AND ( CASE WHEN amount  <![CDATA[<]]> 0 THEN isnull( page_no_ty, 0 ) ELSE page_no END )  <![CDATA[>]]> 0  " +
                    " AND ( amount  <![CDATA[>]]> 0 OR ( amount  <![CDATA[<]]> 0 AND drug_class  <![CDATA[<>]]> 'd' ) ) THEN " +
                    "  '5'  " +
                    "   " +
                    "  WHEN status_flag = '1'  " +
                    " AND ( CASE WHEN amount  <![CDATA[<]]> 0then isnull( page_no_ty, 0 ) ELSE page_no END ) = 0 THEN " +
                    " '9'  " +
                    " ELSE '7'  " +
                    " END, " +
                    " chargeFee = round( retprice * amount, 2 ), " +
                    " self_flag selfFlag, " +
                    " separate_flag separateFlag, " +
                    " suprice_flag supriceFlag, " +
                    " ward_code wardCode, " +
                    " opFlag = '0', " +
                    " dept_code deptCode, " +
                    " orderNo = abs( act_order_no ), " +
                    " chargeAmount = amount, " +
                    " pageNo = " +
                    "CASE " +
                    "   " +
                    "  WHEN amount  <![CDATA[<]]> 0 then isnull( page_no_ty, 0 ) ELSE page_no  " +
                    " END " +
                    ",serial=serail " +
                    " FROM " +
                    "  yz_yp_zy_order ( nolock )  " +
                    " WHERE " +
                    "  inpatient_no = #{inpatientNo,jdbcType=CHAR}  " +
                    "  AND admiss_times = #{admissTimes,jdbcType=SMALLINT}  " +
                    "  AND status_flag IN ( '1', '2' )  " +
                    "  AND pay_self NOT IN ( '2', '3' )  " +
                    "  AND infant_flag =#{infantFlag,jdbcType=CHAR}"
            ,"</script>"})
    List<Map<String, Object>> selectZyDetailChargesFromYzYpZyOrder(@Param("inpatientNo")String inpatientNo, @Param("admissTimes")Integer admissTimes, @Param("infantFlag")String infantFlag);
}
