package thyyxxk.webserver.dao.his.medicalinsurance;

import org.apache.ibatis.annotations.*;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.entity.medicalinsurance.injury.InjurySiPatInfo;

@Mapper
public interface SiInjuryDao {

    @Select("select count(1) from t_injury_si_pat_info where pat_no=#{patNo} and times=#{times} and ledger_sn=#{ledgerSn}")
    int selectCount(@Param("patNo") String patNo,
                    @Param("times") int times,
                    @Param("ledgerSn") int ledgerSn);

    @Insert("insert into t_injury_si_pat_info (pat_no, times, ledger_sn, indi_id, center_id, pers_type, injury_area) " +
            "values (#{patNo}, #{times}, #{ledgerSn}, #{indiId}, #{centerId}, #{persType}, #{injuryArea})")
    void insertNewInjurybase(@Param("patNo") String patNo,
                             @Param("times") int times,
                             @Param("ledgerSn") int ledgerSn,
                             @Param("indiId") String indiId,
                             @Param("centerId") String centerId,
                             @Param("persType") String persType,
                             @Param("injuryArea") int injuryArea);

    @Update("update t_injury_si_pat_info set indi_id=#{indiId},center_id=#{centerId},pers_type=#{persType}," +
            "injury_area=#{injuryArea} where pat_no=#{patNo} and times=#{times} and ledger_sn=#{ledgerSn}")
    void updateInjurybase(@Param("patNo") String patNo,
                          @Param("times") int times,
                          @Param("ledgerSn") int ledgerSn,
                          @Param("indiId") String indiId,
                          @Param("centerId") String centerId,
                          @Param("persType") String persType,
                          @Param("injuryArea") int injuryArea);
    
    @Update("update t_injury_si_pat_info set serial_pers=#{serialPers},medic_flag=#{medicFlag}, " +
            "identify_code=#{identifyCode},injury_cert=#{injuryCert},identify_flag=#{identifyFlag}, " +
            "disease_flag=#{diseaseFlag}, recur_flag=#{recurFlag},injury_type=#{injuryType}, " +
            "identy_date=#{identyDate},accident_grade=#{accidentGrade},injury_part=#{injuryPart}, " +
            "injury_degree_name=#{injuryDegreeName},report_date=#{reportDate},accident_date=#{accidentDate}, " +
            "accident_detail=#{accidentDetail},months=#{months} " +
            "where pat_no=#{patNo} and times=#{times} and ledger_sn=#{ledgerSn}")
    void updateInjuryinfo(InjurySiPatInfo info);

    @Select("select * from t_injury_si_pat_info where pat_no=#{patNo} and times=#{times} and ledger_sn=#{ledgerSn}")
    InjurySiPatInfo selectInjuryinfo(@Param("patNo") String patNo,
                                     @Param("times") int times,
                                     @Param("ledgerSn") int ledgerSn);

    @Select("select icd_code as code, icd_text as name from zy_in_diag_yb where inpatient_no=#{patNo} " +
            "and admiss_times=#{times} and diag_no=1")
    CodeName selectMainDiag(@Param("patNo") String patNo,
                            @Param("times") int times);
}
