package thyyxxk.webserver.dao.his.medicine;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.medicine.vo.YpCodgVo;

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

@Mapper
public interface YpCodgMatchDao {

    @Select("<script> " +
            " select distinct rtrim(mz.patient_id) as patientId, rtrim(mz.patient_id) as patNo, mz.times, " +
            " mz.receipt_no as receiptNo, mz.order_no as orderNo, mz.real_no as realNo, " +
            " mz.name, mz.charge_date as chargeDate, mz.confirm_flag as confirmFlag, " +
            " mz.warn_dept as warnDept, rtrim(mz.serial_no) as serialNo, mz.print_flag as printFlag, " +
            " mz.group_no as groupNo, rtrim(c.name) as deptName, yp.drug_flag as drugFlag " +
            " from mz_charge_detail as mz with(nolock) " +
            " left join zd_unit_code as c on mz.warn_dept = c.code " +
            " inner join yp_zd_dict as yp with(nolock) on mz.charge_item_code = yp.code and mz.serial = yp.serial " +
            " where mz.pay_mark = '0'  " +
            " and mz.serial_no &gt; 0 " +
            " and isnull(mz.confirm_zs, '') &lt;&gt; '1' " +
            " and mz.group_no = #{vo.groupNo} " +
            " and mz.charge_date &gt;= #{vo.startTime} " +
            " and mz.charge_date &lt;= #{vo.endTime} " +
            "<if test=\" vo.patName != null and vo.patName != '' \">" +
            " and mz.name like ('%' + #{vo.patName} + '%') " +
            "</if>" +
            "<if test=\" vo.patNo != null and vo.patNo != '' \">" +
            " and mz.patient_id = #{vo.patNo} " +
            "</if>" +
            "<if test=\" vo.confirmFlag != null and vo.confirmFlag != '' \">" +
            " and mz.confirm_flag = #{vo.confirmFlag} " +
            "</if>" +
            "<if test=\" vo.dept != null and vo.dept != '' \">" +
            " and isnull(mz.warn_dept, '') = #{vo.dept} " +
            "</if>" +
            " order by charge_date desc " +
            "</script>")
    List<Map<String, Object>> selectMzChargePrescription(@Param("vo") YpCodgVo vo);

    @Select("<script> " +
            " select rtrim(mz.patient_id) as patientId, mz.times, mz.item_no as itemNo, " +
            " mz.receipt_no as receiptNo, mz.order_no as orderNo, mz.real_no as realNo, " +
            " mz.name, mz.charge_date as chargeDate, mz.confirm_flag as confirmFlag, mz.group_no as groupNo, " +
            " mz.warn_dept as warnDept, rtrim(mz.serial_no) as serialNo, mz.print_flag as printFlag, " +
            " mz.quantity, mz.supply_code as supplyCode, mz.manu_no as manuNo, rtrim(mz.charge_item_code) as chargeCode, " +
            " rtrim(c.name) as deptName, yp.drug_flag as drugFlag, yp.name as chargeName, yp.location, yp.retprice, " +
            " rtrim(yp.specification) as specification, rtrim(cj.name) as factory, mz.serial " +
            " from mz_charge_detail as mz with(nolock) " +
            " left join zd_unit_code as c on mz.warn_dept = c.code " +
            " inner join yp_zd_dict as yp with(nolock) on mz.charge_item_code = yp.code and mz.serial = yp.serial " +
            " inner join yp_zd_manufactory as cj on yp.manu_code = cj.code " +
            " where mz.pay_mark = '0' " +
            " and mz.patient_id = #{vo.patNo} " +
            " and mz.times = #{vo.times} " +
            " and mz.receipt_no = #{vo.receiptNo} " +
            " and mz.order_no = #{vo.orderNo} " +
            " and mz.real_no = #{vo.realNo} " +
            " and mz.group_no = #{vo.groupNo} " +
            " order by mz.charge_date desc " +
            "</script>")
    List<Map<String, Object>> selectMzCfDetail(@Param("vo") YpCodgVo vo);

    @Select(" select name from sys_parameters where code = 'classCodeFskYp' ")
    String selectFskYpClassCode();

    @Select(" select name from sys_parameters where code = 'deptCodeXts' ")
    String selectXtsDeptCode();

    @Select(" select name from sys_parameters where code = 'isOpenTaoBaoMatch' ")
    String selectIsOpenTb();

}
