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

import cn.hnthyy.thmz.entity.his.zy.ZyAdt;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

public interface ZyAdtMapper {
    /**
     * 根据住院号与住院次数删除流转记录
     * @param inpatientNo
     * @param admissTimes
     * @return
     */
    @Delete(" DELETE FROM zy_adt WHERE inpatient_no =#{inpatientNo} AND admiss_times =#{admissTimes} ")
    int deleteZyAdt(@Param("inpatientNo") String inpatientNo,@Param("admissTimes") Integer admissTimes);

    /**
     * 入库流转记录
     * @param zyAdt
     * @return
     */
    @Insert("INSERT INTO zy_adt ( zy_serial_no , inpatient_no , admiss_times , trans_times , admiss_date , curr_ward , curr_dept , curr_room , curr_bed , mark ) " +
            "VALUES ( #{zySerialNo} , #{inpatientNo} , #{admissTimes} , #{transTimes} , #{admissDate} , #{currWard} , #{currDept} , #{currRoom} , #{currBed} , #{mark}) ")
    int inserZyAdt(ZyAdt zyAdt);

    /**
     * 出院时修改住院动态表
     * @param disDate 出院日期
     * @param origWard 原病房
     * @param origDept 原科室
     * @param origBed 原床位
     * @param inpatientNo 住院号
     * @param admissTimes 住院次数
     * @return
     */
    @Update("update zy_adt SET dis_date =#{disDate} , orig_ward =#{origWard} , orig_dept =#{origDept} , orig_bed =#{origBed} WHERE inpatient_no =#{inpatientNo} AND admiss_times =#{admissTimes} AND trans_times =0 ")
    int updateZyAdtForDis(@Param("disDate")Date disDate,@Param("origWard")String origWard,@Param("origDept")String origDept,@Param("origBed")String origBed,@Param("inpatientNo") String inpatientNo,@Param("admissTimes") Integer admissTimes);

    /**
     * 召回时修改住院动态表
     * @param inpatientNo
     * @param admissTimes
     * @return
     */
    @Update("update zy_adt SET dis_date =NULL , orig_ward =NULL , orig_dept =NULL , orig_bed =NULL WHERE inpatient_no =#{inpatientNo} AND admiss_times =#{admissTimes} AND trans_times =0 ")
    int updateForRecall(@Param("inpatientNo") String inpatientNo,@Param("admissTimes") Integer admissTimes);
}
