package thyyxxk.webserver.dao.his.medicaladvice.chaxunfenxi;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.medicaladvice.medicamanage.chaxunfenxi.ArrearagePatientVO;

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

/**
 * @Description:欠费病人清单
 * @Author:lihong
 * @Date: 2023/6/16
 */
@Mapper
public interface ArrearagePatientListDao {
    @Select(" SELECT code," +
            "       name" +
            " FROM zy_zd_responce_type")
    List<Map<String,Object>> listResponceType();
    @Select(" SELECT rtrim(a.ward) ward,\n" +
            "  refer_physician =isnull(a.refer_physician,a.admiss_physician),refer_physician_name =(select name from a_employee_mi where code= isnull(a.refer_physician,a.admiss_physician)),"+
            "        ward_name=(select name from zd_unit_code where code =a.ward)," +
            "       rtrim(a.inpatient_no) inpatient_no ,\n" +
            "       a.admiss_times,\n" +
            "       rtrim(a.name) name,\n" +
            "       zyts= datediff(day, a.admiss_date, getdate()) + 1, " +
            "       rtrim(a.bed_no) bed_no,\n" +
            "    rtrim(a.responce_type) responce_type,\n" +
            "       responce_type_name=(select rtrim(name) from zy_zd_responce_type where code=a.responce_type),\n" +
            "       admiss_date_str=convert(varchar(11), a.admiss_date, 121),\n" +
            "       b.total_charge,\n" +
            "       charge_yb=isnull(b.charge_yb,0),\n" +
            "       b.deposit,\n" +
            "       balance=b.balance,\n" +
            "       charge_jz=(select isnull(sum(depo_amount),0) from zy_deposit_file where inpatient_no=a.inpatient_no and admiss_times=a.admiss_times and depo_type='Y')\n" +
            "FROM zy_actpatient a   ,zy_ledger_file b\n" +
            "where    isnull(a.intern_code,'') <> '1' and\n" +
            "        a.ward = #{ward} and\n" +
            "        a.responce_type like #{responceType} and\n" +
            "            b.balance <= ${qfdx} and\n" +
            "        a.inpatient_no=b.inpatient_no and\n" +
            "        a.admiss_times=b.admiss_times and\n" +
            "        a.times_billed=b.ledger_sn  and\n" +
            "    (b.account_date is null or b.account_date=null)\n" +
            "order by cast(a.bed_no as int)")
    List<ArrearagePatientVO> listArrearagePatientVO(ArrearagePatientVO param);

}
