package thyyxxk.webserver.dao.his.medicalinsurance;

import org.apache.ibatis.annotations.*;
import thyyxxk.webserver.entity.medicalinsurance.inpatient.SiAdmissApply;

import java.util.List;

/**
 * @author dj
 */
@Mapper
public interface SiAdmVerifyDao {

    @Select("select status,handle_comment,admiss_datetime from t_si_admiss_apply with(nolock) where pat_no=#{patNo} " +
            "and times=#{times} and ledger_sn=#{ledger}")
    SiAdmissApply selectAdmissApply(@Param("patNo") String patNo,
                                    @Param("times") int times,
                                    @Param("ledger") int ledger);

    @Delete("delete from t_si_admiss_apply where pat_no=#{patNo} and times=#{times} and ledger_sn=#{ledger}")
    void deleteAdmissApply(@Param("patNo") String patNo,
                           @Param("times") int times,
                           @Param("ledger") int ledger);

    @Insert("insert into t_si_admiss_apply (pat_no,times,ledger_sn,input_staff,input_comment,input_datetime,status," +
            "admiss_datetime,registered) values (#{patNo},#{times},#{ledgerSn},#{inputStaff},#{inputComment},getdate()," +
            "0,#{admissDatetime},0)")
    void insertAdmissApply(SiAdmissApply apply);

    @Select("select a.pat_no,a.times,a.ledger_sn,a.status,c.sex as gender,rtrim(c.name) as name,c.med_type, " +
            "wardName=(select rtrim(name) from zd_unit_code with(nolock) where code=c.ward),a.input_staff,c.admdvs, " +
            "a.input_comment,a.input_datetime,a.status,a.handle_staff,a.handle_comment,a.handle_datetime,a.admiss_datetime " +
            "from t_si_admiss_apply a with(nolock), zy_actpatient c with(nolock) " +
            "where a.registered=0 and a.pat_no=c.inpatient_no and a.times=c.admiss_times")
    List<SiAdmissApply> selectUnhandledApplies();

    @Update("update t_si_admiss_apply set status=#{status},handle_staff=#{handleStaff},handle_comment=#{handleComment}, " +
            "handle_datetime=getdate() where pat_no=#{patNo} and times=#{times} and ledger_sn=#{ledgerSn} ")
    void handleApply(SiAdmissApply apply);

}
