package thyyxxk.webserver.dao.his.zhuyuanyiji;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.inpatient.ZyActpatient;

/**
 * <p>
 * 描述：住院以及费用录入
 * </p>
 *
 * @author xc
 * @date 2021-09-13 15:43
 */
@Mapper
public interface YiJiFeiYongLuRuDao {

    @Select("<script>" +
            "SELECT rtrim(a.inpatient_no) inpatient_no," +
            "       a.admiss_times," +
            "       ledger_sn = " +
            "(select max(ledger_sn)ledger_sn from zy_ledger_file where  zy_ledger_file.inpatient_no = a.inpatient_no and zy_ledger_file.admiss_times = a.admiss_times)," +
            "       a.admiss_dept," +
            "       rtrim(a.name) name," +
            "       rtrim(a.bed_no) bed_no," +
            "       a.ward," +
            "       ward_name=(select rtrim(name) name from zd_unit_code where zd_unit_code.code = a.ward)," +
            "       a.responce_type," +
            "       responce_type_name=(select rtrim(name) name from zy_zd_responce_type where a.responce_type = zy_zd_responce_type.code)," +
            "       a.balance," +
            "       a.dept," +
            "       a.refer_physician," +
            "       a.total_charge," +
            "       rtrim(a.charge_type) charge_type," +
            "       a.times_billed," +
            "       rtrim(a.admiss_diag_str) admiss_diag_str," +
            "       rtrim(a.admiss_diag) admiss_diag," +
            "       a.admiss_date," +
            "       a.sex," +
            "       a.zy_serial_no," +
            "       a.mz_no," +
            "       rtrim(a.intern_code) intern_code," +
            "       a.zk_ward " +
            "FROM ${tableName} a " +
            "WHERE  inpatient_no = #{inpatientNo} " +
            "<if test=\"admissTimes != 0 \">" +
            "and admiss_times = #{admissTimes} " +
            "</if>" +
            "</script>")
    ZyActpatient getHuanZheXinXi(@Param("inpatientNo") String inpatientNo,
                                 @Param("tableName") String tableName,
                                 @Param("admissTimes") Integer admissTimes);

    @Select("select max(admiss_times) from zy_inactpatient where inpatient_no = #{inpatientNo} ")
    Integer maxAdmissTimes(@Param("inpatientNo") String inpatientNo);

    @Select("select settle_type from zy_ledger_file where " +
            "inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} " +
            "and ledger_sn = (select max(ledger_sn)ledger_sn from zy_ledger_file where  zy_ledger_file.inpatient_no = #{inpatientNo} " +
            "and zy_ledger_file.admiss_times = #{admissTimes}) ")
    Integer getHuanZheSFJieSuan(@Param("inpatientNo") String inpatientNo,
                                @Param("admissTimes") Integer admissTimes);
}
