package thyyxxk.webserver.dao.his.zygl;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.zygl.APatientMi;

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

/**
 * @Description:
 * @Author:lihong
 * @Date: 2025/5/8
 */
@Mapper
public interface APatientMiDao {

    /**
     * 根据门诊号码查询对应的住院id
     * @param mzNo
     * @return
     */
    @Select("select rtrim(inpatient_no) from a_patient_mi where mz_no = #{mzNo}")
    List<String> selectInPatientNoByMzNo(@Param("mzNo") String mzNo);

    /**
     * 根据住院号查询病人信息
     * @param inpatientNo
     * @return
     */
    @Select("select top 1 rtrim(inpatient_no) inpatient_no,rtrim(outpatient_no) outpatient_no,rtrim(name) name,birth_date,rtrim(sex) sex,rtrim(marry_code) marry_code,rtrim(nation_code) nation_code," +
            "rtrim(occupation_code) occupation_code,rtrim(vip_code) vip_code,rtrim(social_no) social_no,rtrim(home_tel) home_tel,rtrim(home_street) home_street,rtrim(home_district) home_district," +
            "rtrim(home_zipcode) home_zipcode,rtrim(temp_street) temp_street,rtrim(temp_tel) temp_tel,rtrim(temp_zipcode) temp_zipcode,rtrim(employer_name) employer_name," +
            "rtrim(employer_street) employer_street,rtrim(employer_district) employer_district,rtrim(employer_tel) employer_tel,rtrim(employer_zipcode) employer_zipcode," +
            "rtrim(relation_name) relation_name,rtrim(relation_code) relation_code,rtrim(relation_street) relation_street,rtrim(relation_district) relation_district," +
            "rtrim(relation_tel) relation_tel,rtrim(relation_zipcode) relation_zipcode,rtrim(contract_code) contract_code,rtrim(insur1_code) insur1_code" +
            ",rtrim(insur2_code) insur2_code,lastvisit_date,lastadmiss_times,lastbill_acc,baddebit_acc,baddebit_date,rtrim(birth_place) birth_place,rtrim(country) country," +
            "rtrim(temp_district) temp_district,rtrim(fv_dept) fv_dept,fv_date,rtrim(hic_no) hic_no,rtrim(py_code) py_code,rtrim(cpy) cpy,rtrim(yb_card_no) yb_card_no," +
            "rtrim(mz_no) mz_no,rtrim(dnh) dnh,rtrim(account_street) account_street,rtrim(account_district) account_district,rtrim(account_zipcode) account_zipcode,rtrim(origin_type) origin_type" +
            ",rtrim(card_iden) card_iden,rtrim(card_no) card_no,rtrim(indi_id) indi_id,rtrim(hic_no_new) hic_no_new,rtrim(health_card_no) health_card_no" +
            ",rtrim(psn_cert_type) psn_cert_type,rtrim(province_code) province_code,rtrim(city_code) city_code,rtrim(district_code) district_code from a_patient_mi where inpatient_no = #{inpatientNo}")
    APatientMi selectPatientMiByInPatientNo(@Param("inpatientNo") String inpatientNo);



    /**
     * 根据门诊号码查询对应的住院病人信息
     * @param mzNo
     * @return
     */
    @Select("select rtrim(inpatient_no) inpatient_no,rtrim(outpatient_no) outpatient_no,rtrim(name) name,birth_date,rtrim(sex) sex,rtrim(marry_code) marry_code,rtrim(nation_code) nation_code," +
            "rtrim(occupation_code) occupation_code,rtrim(vip_code) vip_code,rtrim(social_no) social_no,rtrim(home_tel) home_tel,rtrim(home_street) home_street,rtrim(home_district) home_district," +
            "rtrim(home_zipcode) home_zipcode,rtrim(temp_street) temp_street,rtrim(temp_tel) temp_tel,rtrim(temp_zipcode) temp_zipcode,rtrim(employer_name) employer_name," +
            "rtrim(employer_street) employer_street,rtrim(employer_district) employer_district,rtrim(employer_tel) employer_tel,rtrim(employer_zipcode) employer_zipcode," +
            "rtrim(relation_name) relation_name,rtrim(relation_code) relation_code,rtrim(relation_street) relation_street,rtrim(relation_district) relation_district," +
            "rtrim(relation_tel) relation_tel,rtrim(relation_zipcode) relation_zipcode,rtrim(contract_code) contract_code,rtrim(insur1_code) insur1_code" +
            ",rtrim(insur2_code) insur2_code,lastvisit_date,lastadmiss_times,lastbill_acc,baddebit_acc,baddebit_date,rtrim(birth_place) birth_place,rtrim(country) country," +
            "rtrim(temp_district) temp_district,rtrim(fv_dept) fv_dept,fv_date,rtrim(hic_no) hic_no,rtrim(py_code) py_code,rtrim(cpy) cpy,rtrim(yb_card_no) yb_card_no," +
            "rtrim(mz_no) mz_no,rtrim(dnh) dnh,rtrim(account_street) account_street,rtrim(account_district) account_district,rtrim(account_zipcode) account_zipcode,rtrim(origin_type) origin_type" +
            ",rtrim(card_iden) card_iden,rtrim(card_no) card_no,rtrim(indi_id) indi_id,rtrim(hic_no_new) hic_no_new,rtrim(health_card_no) health_card_no" +
            ",rtrim(psn_cert_type) psn_cert_type,rtrim(province_code) province_code,rtrim(city_code) city_code,rtrim(district_code) district_code from a_patient_mi where mz_no = #{mzNo}")
    List<APatientMi> selectAPatientByMzNo(@Param("mzNo") String mzNo);


    /**
     * 根据身份证号码查询对应的住院病人信息
     * @param socialNo
     * @return
     */
    @Select("select rtrim(inpatient_no) inpatient_no,rtrim(outpatient_no) outpatient_no,rtrim(name) name,birth_date,rtrim(sex) sex,rtrim(marry_code) marry_code,rtrim(nation_code) nation_code," +
            "rtrim(occupation_code) occupation_code,rtrim(vip_code) vip_code,rtrim(social_no) social_no,rtrim(home_tel) home_tel,rtrim(home_street) home_street,rtrim(home_district) home_district," +
            "rtrim(home_zipcode) home_zipcode,rtrim(temp_street) temp_street,rtrim(temp_tel) temp_tel,rtrim(temp_zipcode) temp_zipcode,rtrim(employer_name) employer_name," +
            "rtrim(employer_street) employer_street,rtrim(employer_district) employer_district,rtrim(employer_tel) employer_tel,rtrim(employer_zipcode) employer_zipcode," +
            "rtrim(relation_name) relation_name,rtrim(relation_code) relation_code,rtrim(relation_street) relation_street,rtrim(relation_district) relation_district," +
            "rtrim(relation_tel) relation_tel,rtrim(relation_zipcode) relation_zipcode,rtrim(contract_code) contract_code,rtrim(insur1_code) insur1_code" +
            ",rtrim(insur2_code) insur2_code,lastvisit_date,lastadmiss_times,lastbill_acc,baddebit_acc,baddebit_date,rtrim(birth_place) birth_place,rtrim(country) country," +
            "rtrim(temp_district) temp_district,rtrim(fv_dept) fv_dept,fv_date,rtrim(hic_no) hic_no,rtrim(py_code) py_code,rtrim(cpy) cpy,rtrim(yb_card_no) yb_card_no," +
            "rtrim(mz_no) mz_no,rtrim(dnh) dnh,rtrim(account_street) account_street,rtrim(account_district) account_district,rtrim(account_zipcode) account_zipcode,rtrim(origin_type) origin_type" +
            ",rtrim(card_iden) card_iden,rtrim(card_no) card_no,rtrim(indi_id) indi_id,rtrim(hic_no_new) hic_no_new,rtrim(health_card_no) health_card_no" +
            ",rtrim(psn_cert_type) psn_cert_type,rtrim(province_code) province_code,rtrim(city_code) city_code,rtrim(district_code) district_code from a_patient_mi where social_no = #{socialNo}")
    List<APatientMi> selectAPatientBySocialNo(@Param("socialNo") String socialNo);



    /**
     * 保存住院病人信息
     * @param aPatientMi
     * @return
     */
    @Insert("INSERT INTO a_patient_mi(inpatient_no, outpatient_no, name, birth_date, sex, marry_code, nation_code, occupation_code, vip_code, social_no, home_tel," +
            " home_street, home_district, home_zipcode, temp_street, temp_tel, temp_zipcode, employer_name, employer_street, employer_district, employer_tel, " +
            "employer_zipcode, relation_name, relation_code, relation_street, relation_district, relation_tel, relation_zipcode, contract_code, insur1_code, " +
            "insur2_code, lastvisit_date, lastadmiss_times, lastbill_acc, baddebit_acc, baddebit_date, birth_place, country, temp_district, fv_dept, fv_date, " +
            "hic_no, py_code, cpy, yb_card_no, mz_no, dnh, account_street, account_district, account_zipcode, origin_type, card_iden, card_no, indi_id, hic_no_new," +
            " health_card_no,psn_cert_type,province_code,city_code,district_code) " +
            "VALUES(#{inpatientNo,jdbcType=CHAR},#{outpatientNo,jdbcType=CHAR},#{name,jdbcType=CHAR},#{birthDate,jdbcType=TIMESTAMP},#{sex,jdbcType=CHAR},#{marryCode,jdbcType=CHAR}," +
            "#{nationCode,jdbcType=CHAR},#{occupationCode,jdbcType=CHAR},#{vipCode,jdbcType=CHAR},#{socialNo,jdbcType=VARCHAR},#{homeTel,jdbcType=CHAR}," +
            "#{homeStreet,jdbcType=CHAR},#{homeDistrict,jdbcType=CHAR},#{homeZipcode,jdbcType=CHAR},#{tempStreet,jdbcType=CHAR},#{tempTel,jdbcType=CHAR}," +
            "#{tempZipcode,jdbcType=CHAR},#{employerName,jdbcType=CHAR},#{employerStreet,jdbcType=CHAR},#{employerDistrict,jdbcType=CHAR},#{employerTel,jdbcType=CHAR}," +
            "#{employerZipcode,jdbcType=CHAR},#{relationName,jdbcType=CHAR},#{relationCode,jdbcType=CHAR},#{relationStreet,jdbcType=CHAR},#{relationDistrict,jdbcType=CHAR}," +
            "#{relationTel,jdbcType=CHAR},#{relationZipcode,jdbcType=CHAR},#{contractCode,jdbcType=CHAR},#{insur1Code,jdbcType=CHAR},#{insur2Code,jdbcType=CHAR}," +
            "#{lastvisitDate,jdbcType=TIMESTAMP},#{lastadmissTimes,jdbcType=SMALLINT},#{lastbillAcc,jdbcType=FLOAT},#{baddebitAcc,jdbcType=FLOAT}," +
            "#{baddebitDate,jdbcType=TIMESTAMP},#{birthPlace,jdbcType=CHAR},#{country,jdbcType=CHAR},#{tempDistrict,jdbcType=CHAR},#{fvDept,jdbcType=CHAR}," +
            "#{fvDate,jdbcType=TIMESTAMP},#{hicNo,jdbcType=CHAR},#{pyCode,jdbcType=CHAR},#{cpy,jdbcType=CHAR},#{ybCardNo,jdbcType=VARCHAR},#{mzNo,jdbcType=CHAR}," +
            "#{dnh,jdbcType=VARCHAR},#{accountStreet,jdbcType=VARCHAR},#{accountDistrict,jdbcType=VARCHAR},#{accountZipcode,jdbcType=CHAR},#{originType,jdbcType=CHAR}," +
            "#{cardIden,jdbcType=CHAR},#{cardNo,jdbcType=VARCHAR},#{indiId,jdbcType=VARCHAR},#{hicNoNew,jdbcType=CHAR},#{healthCardNo,jdbcType=VARCHAR}," +
            "#{psnCertType,jdbcType=VARCHAR},#{provinceCode},#{cityCode},#{districtCode}) ")
    int insertMzPatientMi(APatientMi aPatientMi);





    /**
     * 更新病人信息 根据门诊号修改
     * @param aPatientMi
     * @return
     */
    @Update({"<script>",
            "update a_patient_mi ",
            "<trim prefix='set' prefixOverrides=',' suffix=' where mz_no =#{mzNo}' >",
            "<when test='name!=null'>",
            "name =#{name,jdbcType=CHAR}",
            "</when>",
            "<when test='sex!=null'>",
            ",sex =#{sex,jdbcType=CHAR}",
            "</when>",
            "<when test='birthDate!=null'>",
            ",birth_date =#{birthDate,jdbcType=TIMESTAMP}",
            "</when>",
            "<when test='birthDate!=null'>",
            ",occupation_code =#{occupationCode,jdbcType=CHAR}",
            "</when>",
            "<when test='mzNo!=null'>",
            ",mz_no =#{mzNo,jdbcType=CHAR}",
            "</when>",
            "<when test='homeTel!=null'>",
            ",home_tel =#{homeTel,jdbcType=CHAR}",
            "</when>",
            "<when test='marryCode!=null'>",
            ",marry_code =#{marryCode,jdbcType=CHAR}",
            "</when>",
            "<when test='country!=null'>",
            ",country =#{country,jdbcType=CHAR}",
            "</when>",
            "<when test='nationCode!=null'>",
            ",nation_code =#{nationCode,jdbcType=CHAR}",
            "</when>",
            "<when test='birthPlace!=null'>",
            ",birth_place =#{birthPlace,jdbcType=CHAR}",
            "</when>",
            "<when test='accountStreet!=null'>",
            ",account_street =#{accountStreet,jdbcType=CHAR}",
            "</when>",
            "<when test='socialNo!=null'>",
            ",social_no =#{socialNo,jdbcType=CHAR}",
            "</when>",
            "<when test='homeStreet!=null'>",
            ",home_street =#{homeStreet,jdbcType=CHAR}",
            "</when>",
            "<when test='inpatientNo!=null'>",
            ",inpatient_no =#{inpatientNo,jdbcType=CHAR}",
            "</when>",
            "<when test='employerStreet!=null'>",
            ",employer_street =#{employerStreet,jdbcType=CHAR}",
            "</when>",
            "<when test='relationName!=null'>",
            ",relation_name =#{relationName,jdbcType=CHAR}",
            "</when>",
            "<when test='relationCode!=null'>",
            ",relation_code =#{relationCode,jdbcType=CHAR}",
            "</when>",
            "<when test='relationTel!=null'>",
            ",relation_tel =#{relationTel,jdbcType=CHAR}",
            "</when>",
            "<when test='relationStreet!=null'>",
            ",relation_street =#{relationStreet,jdbcType=CHAR}",
            "</when>",
            "<when test='lastadmissTimes!=null'>",
            ",lastadmiss_times =#{lastadmissTimes,jdbcType=SMALLINT}",
            "</when>",
            "<when test='psnCertType!=null'>",
            ",psn_cert_type =#{psnCertType,jdbcType=VARCHAR}",
            "</when>",
            "<when test='provinceCode!=null'>",
            ",province_code =#{provinceCode}",
            "</when>",
            "<when test='cityCode!=null'>",
            ",city_code =#{cityCode}",
            "</when>",
            "<when test='districtCode!=null'>",
            ",district_code =#{districtCode}",
            "</when>",
            "</trim>"
            ,"</script>"})
    int updateMzPatientMiByMzno(APatientMi aPatientMi);



    /**
     * 更新病人信息 根据住院号修改
     * @param aPatientMi
     * @return
     */
    @Update({"<script>",
            "update a_patient_mi ",
            "<trim prefix='set' prefixOverrides=',' suffix=' where inpatient_no =#{oldInpatientNo}' >",
            "<when test='inpatientNo!=null'>",
            "inpatient_no =#{inpatientNo,jdbcType=CHAR}",
            "</when>",
            "<when test='outpatientNo!=null'>",
            ",outpatient_no =#{outpatientNo,jdbcType=CHAR}",
            "</when>",
            "<when test='name!=null'>",
            ",name =#{name,jdbcType=CHAR}",
            "</when>",
            "<when test='sex!=null'>",
            ",sex =#{sex,jdbcType=CHAR}",
            "</when>",
            "<when test='birthDate!=null'>",
            ",birth_date =#{birthDate,jdbcType=TIMESTAMP}",
            "</when>",
            "<when test='mzNo!=null'>",
            ",mz_no =#{mzNo,jdbcType=CHAR}",
            "</when>",
            "<when test='homeTel!=null'>",
            ",home_tel =#{homeTel,jdbcType=CHAR}",
            "</when>",
            "<when test='marryCode!=null'>",
            ",marry_code =#{marryCode,jdbcType=CHAR}",
            "</when>",
            "<when test='country!=null'>",
            ",country =#{country,jdbcType=CHAR}",
            "</when>",
            "<when test='nationCode!=null'>",
            ",nation_code =#{nationCode,jdbcType=CHAR}",
            "</when>",
            "<when test='birthPlace!=null'>",
            ",birth_place =#{birthPlace,jdbcType=CHAR}",
            "</when>",
            "<when test='accountStreet!=null'>",
            ",account_street =#{accountStreet,jdbcType=CHAR}",
            "</when>",
            "<when test='socialNo!=null'>",
            ",social_no =#{socialNo,jdbcType=CHAR}",
            "</when>",
            "<when test='homeStreet!=null'>",
            ",home_street =#{homeStreet,jdbcType=CHAR}",
            "</when>",
            "<when test='inpatientNo!=null'>",
            ",inpatient_no =#{inpatientNo,jdbcType=CHAR}",
            "</when>",
            "<when test='employerStreet!=null'>",
            ",employer_street =#{employerStreet,jdbcType=CHAR}",
            "</when>",
            "<when test='relationName!=null'>",
            ",relation_name =#{relationName,jdbcType=CHAR}",
            "</when>",
            "<when test='relationCode!=null'>",
            ",relation_code =#{relationCode,jdbcType=CHAR}",
            "</when>",
            "<when test='relationTel!=null'>",
            ",relation_tel =#{relationTel,jdbcType=CHAR}",
            "</when>",
            "<when test='relationStreet!=null'>",
            ",relation_street =#{relationStreet,jdbcType=CHAR}",
            "</when>",
            "<when test='lastadmissTimes!=null'>",
            ",lastadmiss_times =#{lastadmissTimes,jdbcType=SMALLINT}",
            "</when>",
            "<when test='psnCertType!=null'>",
            ",psn_cert_type =#{psnCertType,jdbcType=VARCHAR}",
            "</when>",
            "<when test='provinceCode!=null'>",
            ",province_code =#{provinceCode}",
            "</when>",
            "<when test='cityCode!=null'>",
            ",city_code =#{cityCode}",
            "</when>",
            "<when test='districtCode!=null'>",
            ",district_code =#{districtCode}",
            "</when>",
            "</trim>"
            ,"</script>"})
    int updateMzPatientMiByInpatientNo(APatientMi aPatientMi);



    /**
     * 查询住院号对应的病人最大的住院次数
     * @param inpatientNo
     * @return
     */
    @Select("select count (*) , max (lastadmiss_times) lastadmiss_times from a_patient_mi  where inpatient_no =#{inpatientNo} ")
    Map<String,Object> selectMaxLastadmissTimes(@Param("inpatientNo") String inpatientNo);

    /**
     *
     * @return
     */
    @Delete("delete a_patient_mi where inpatient_no =#{inpatientNo} ")
    int deleteByInpatientNo(@Param("inpatientNo") String inpatientNo);

    /**
     * 插入数据记录（实际时作为修改使用，因为没有主键） + 一条删除语句
     * @param aPatientMi
     * @return
     */
    @Insert("INSERT INTO a_patient_mi ( inpatient_no , outpatient_no , name , birth_date , sex , marry_code , nation_code , occupation_code , vip_code , social_no ," +
            " home_tel , home_street , home_district , home_zipcode , temp_street , temp_tel , temp_zipcode , employer_name , employer_street , employer_district , " +
            "employer_tel , employer_zipcode , relation_name , relation_code , relation_street , relation_district , relation_tel , relation_zipcode , contract_code , " +
            "insur1_code , insur2_code , lastvisit_date , lastadmiss_times , lastbill_acc , baddebit_acc , baddebit_date , birth_place , country , temp_district , mz_no," +
            "psn_cert_type,province_code,city_code,district_code )" +
            " SELECT #{inpatientNo,jdbcType=CHAR} , #{inpatientNo,jdbcType=CHAR} , #{name} , birth_date , sex , marry_code , nation_code , occupation_code , vip_code , social_no , home_tel , home_street , " +
            "home_district , home_zipcode , temp_street , temp_tel , temp_zipcode , employer_name , employer_street , employer_district , employer_tel , employer_zipcode , " +
            "relation_name , relation_code , relation_street , relation_district , relation_tel , relation_zipcode , contract_code , insur1_code , insur2_code , " +
            "lastvisit_date , #{lastadmissTimes} , lastbill_acc , baddebit_acc , baddebit_date , birth_place , country , temp_district , isnull ( #{mzNo} , mz_no )," +
            "psn_cert_type,province_code,city_code,district_code FROM a_patient_mi b " +
            "WHERE b.inpatient_no =#{oldInpatientNo,jdbcType=CHAR} ")
    int insertFromOtherItem(APatientMi aPatientMi);
    /**
     * @description: 更新住院次数
     * @author: lihong
     * @date: 2023/11/15 15:26
     * @param: aPatientMiDb
     * @return: int
     **/
    @Update(" update a_patient_mi set lastadmiss_times =#{lastadmissTimes} where inpatient_no =#{inpatientNo}  ")
    int updateLastadmissTimes(APatientMi aPatientMiDb);
    @Update("  delete  from a_patient_mi  where inpatient_no =#{inpatientNo} ")
    int clearInpatientNo(APatientMi aPatientMiDb);
    @Update({"<script>",
            "update a_patient_mi ",
            "<trim prefix='set' prefixOverrides=',' suffix=' where inpatient_no =#{inpatientNo}' >",
            "<when test='name!=null'>",
            "name =#{name,jdbcType=CHAR}",
            "</when>",
            "<when test='sex!=null'>",
            ",sex =#{sex,jdbcType=CHAR}",
            "</when>",
            "<when test='birthDate!=null'>",
            ",birth_date =#{birthDate,jdbcType=TIMESTAMP}",
            "</when>",
            "<when test='birthDate!=null'>",
            ",occupation_code =#{occupationCode,jdbcType=CHAR}",
            "</when>",
            "<when test='mzNo!=null'>",
            ",mz_no =#{mzNo,jdbcType=CHAR}",
            "</when>",
            "<when test='homeTel!=null'>",
            ",home_tel =#{homeTel,jdbcType=CHAR}",
            "</when>",
            "<when test='marryCode!=null'>",
            ",marry_code =#{marryCode,jdbcType=CHAR}",
            "</when>",
            "<when test='country!=null'>",
            ",country =#{country,jdbcType=CHAR}",
            "</when>",
            "<when test='nationCode!=null'>",
            ",nation_code =#{nationCode,jdbcType=CHAR}",
            "</when>",
            "<when test='birthPlace!=null'>",
            ",birth_place =#{birthPlace,jdbcType=CHAR}",
            "</when>",
            "<when test='accountStreet!=null'>",
            ",account_street =#{accountStreet,jdbcType=CHAR}",
            "</when>",
            "<when test='socialNo!=null'>",
            ",social_no =#{socialNo,jdbcType=CHAR}",
            "</when>",
            "<when test='homeStreet!=null'>",
            ",home_street =#{homeStreet,jdbcType=CHAR}",
            "</when>",
            "<when test='inpatientNo!=null'>",
            ",inpatient_no =#{inpatientNo,jdbcType=CHAR}",
            "</when>",
            "<when test='employerStreet!=null'>",
            ",employer_street =#{employerStreet,jdbcType=CHAR}",
            "</when>",
            "<when test='relationName!=null'>",
            ",relation_name =#{relationName,jdbcType=CHAR}",
            "</when>",
            "<when test='relationCode!=null'>",
            ",relation_code =#{relationCode,jdbcType=CHAR}",
            "</when>",
            "<when test='relationTel!=null'>",
            ",relation_tel =#{relationTel,jdbcType=CHAR}",
            "</when>",
            "<when test='relationStreet!=null'>",
            ",relation_street =#{relationStreet,jdbcType=CHAR}",
            "</when>",
            "<when test='lastadmissTimes!=null'>",
            ",lastadmiss_times =#{lastadmissTimes,jdbcType=SMALLINT}",
            "</when>",
            "<when test='psnCertType!=null'>",
            ",psn_cert_type =#{psnCertType,jdbcType=VARCHAR}",
            "</when>",
            "<when test='provinceCode!=null'>",
            ",province_code =#{provinceCode}",
            "</when>",
            "<when test='cityCode!=null'>",
            ",city_code =#{cityCode}",
            "</when>",
            "<when test='districtCode!=null'>",
            ",district_code =#{districtCode}",
            "</when>",
            "<when test='homeZipcode!=null'>",
            ",home_zipcode =#{homeZipcode}",
            "</when>",
            "<when test='homeDistrict!=null'>",
            ",home_district =#{homeDistrict}",
            "</when>",
            "</trim>"
            ,"</script>"})
    int updateMzPatientMiInpatientNo(APatientMi aPatientMi);
    @Select(" select *  from a_patient_mi where name =#{keyWard} or social_no=#{keyWard} or mz_no =#{keyWard} or home_tel =#{keyWard} or inpatient_no = #{keyWard} ")
    List<APatientMi> selectByKeyWard(String keyWard);
    @Update(" update a_patient_mi set mz_no = #{mzNo} where inpatient_no =#{inpatientNo} ")
    int updateMzNoByInpatientNo(@Param("inpatientNo") String inpatientNo, @Param("mzNo") String mzNo);

    @Update({"<script>",
            "update zy_actpatient ",
            "<trim prefix='set' prefixOverrides=',' suffix=' where inpatient_no =#{inpatientNo}' >",
            "<when test='name!=null'>",
            "name =#{name,jdbcType=CHAR}",
            "</when>",
            "<when test='sex!=null'>",
            ",sex =#{sex,jdbcType=CHAR}",
            "</when>",
            "</trim>"
            ,"</script>"})
    void updateZyAcPatient(APatientMi aPatientMi);
    @Select(" select distinct rtrim(inpatient_no) inpatient_no  from a_patient_mi where  mz_no =#{keyWard}  or inpatient_no = #{keyWard} or name = #{keyWard}  ")
    List<String> selectInpatientNoByKeyWard(String keyWard);
}
