package cn.hnthyy.thmz.mapper.his;

import cn.hnthyy.thmz.entity.his.MzPatientMi;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MzPatientMiMapper {
    /**
     * 按照卡号查询病人信息
     * @param icCardNo
     * @return
     */
    @Select("select rtrim(social_no) social_no,rtrim(hic_no) hic_no,rtrim(name) name,rtrim(sex) sex,lv_date,rtrim(patient_id) patient_id,rtrim(p_bar_code) p_bar_code," +
            "rtrim(baddebt_mark) baddebt_mark,rtrim(response_type) response_type,rtrim(charge_type) charge_type,times,rtrim(reqdel_mark) reqdel_mark,age,birth_day," +
            "rtrim(ic_card_no) ic_card_no,rtrim(phone_no) phone_no,rtrim(adress) address,rtrim(yb_card_no) yb_card_no,first_date,rtrim(rel_name) rel_name from mz_patient_mi  where  ic_card_no =#{icCardNo}")
    MzPatientMi selectByIcCardNo(@Param("icCardNo") String icCardNo);


    /**
     * 按照病人姓名模糊查询病人信息
     * @param name
     * @return
     */
    @Select({"<script>",
            " select top ${pageSize} rtrim(social_no) social_no,rtrim(hic_no) hic_no,rtrim(name) name,rtrim(sex) sex,lv_date,rtrim(patient_id) patient_id,rtrim(p_bar_code) p_bar_code,",
            "rtrim(baddebt_mark) baddebt_mark,rtrim(response_type) response_type,rtrim(charge_type) charge_type,times,rtrim(reqdel_mark) reqdel_mark,age,birth_day," ,
            "rtrim(ic_card_no) ic_card_no,rtrim(phone_no) phone_no,rtrim(adress) address,rtrim(yb_card_no) yb_card_no,first_date,rtrim(rel_name) rel_name from   " ,
            "(SELECT ROW_NUMBER() OVER (ORDER BY mz_patient_mi.ic_card_no desc) AS RowNumber,* from mz_patient_mi ",
            "<when test='name!=null'>",
            "  where  name like #{name,jdbcType=VARCHAR}",
            "</when>",
            ") as A WHERE RowNumber >#{pageSize}*#{pageIndex} order by RowNumber asc",
            "</script>"})
    List<MzPatientMi> selectByNameFuzzy(@Param("name") String name,@Param("pageIndex") Integer pageIndex,@Param("pageSize") Integer pageSize);


    /**
     * 按照id查询病人信息
     * @param patientId
     * @return
     */
    @Select("select rtrim(social_no) social_no,rtrim(hic_no) hic_no,rtrim(name) name,rtrim(sex) sex,lv_date,rtrim(patient_id) patient_id,rtrim(p_bar_code) p_bar_code," +
            "rtrim(baddebt_mark) baddebt_mark,rtrim(response_type) response_type,rtrim(charge_type) charge_type,times,rtrim(reqdel_mark) reqdel_mark,age,birth_day," +
            "rtrim(ic_card_no) ic_card_no,rtrim(phone_no) phone_no,rtrim(adress) address,rtrim(yb_card_no) yb_card_no,first_date,rtrim(rel_name) rel_name from mz_patient_mi  where  patient_id =#{patientId}")
    MzPatientMi selectByPatientId(@Param("patientId") String patientId);

}
