liusheng
2024-07-20 ad82e755b335e38e29a5d722f7e8abe67b35a4c8
smartor/src/main/resources/mapper/smartor/PatArchiveMapper.xml
@@ -1,190 +1,501 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.smartor.mapper.PatArchiveMapper">
    <resultMap type="PatArchive" id="PatArchiveResult">
        <result property="PatID"    column="PatID"    />
        <result property="Name"    column="Name"    />
        <result property="Gender"    column="Gender"    />
        <result property="PapersNumber"    column="PapersNumber"    />
        <result property="BirthDate"    column="BirthDate"    />
        <result property="Source"    column="Source"    />
        <result property="MakeArchiveTime"    column="MakeArchiveTime"    />
        <result property="MakeArchivePeople"    column="MakeArchivePeople"    />
        <result property="MobileNumberCode"    column="MobileNumberCode"    />
        <result property="RelativesNumber"    column="RelativesNumber"    />
        <result property="PapersType"    column="PapersType"    />
        <result property="OrgID"    column="OrgID"    />
        <result property="delFlag"    column="Del_Flag"    />
        <result property="updateBy"    column="Update_By"    />
        <result property="updateTime"    column="Update_Time"    />
        <result property="createBy"    column="Create_By"    />
        <result property="createTime"    column="Create_Time"    />
        <result property="IsUpload"    column="IsUpload"    />
        <result property="uploadTime"    column="Upload_Time"    />
        <result property="Age"    column="Age"    />
        <result property="OpenId"    column="OpenId"    />
    </resultMap>
    <resultMap id="PatArchivePatMedOuthospResult" type="PatArchive" extends="PatArchiveResult">
        <collection property="patMedOuthospList" notNullColumn="sub_ID" javaType="java.util.List" resultMap="PatMedOuthospResult" />
    </resultMap>
    <resultMap type="PatMedOuthosp" id="PatMedOuthospResult">
        <result property="ID"    column="sub_ID"    />
        <result property="SerialNum"    column="sub_SerialNum"    />
        <result property="PatID"    column="sub_PatID"    />
        <result property="HospitalName"    column="sub_HospitalName"    />
        <result property="HospitalCode"    column="sub_HospitalCode"    />
        <result property="Icd10Code"    column="sub_Icd10Code"    />
        <result property="DiagName"    column="sub_DiagName"    />
        <result property="DeptCode"    column="sub_DeptCode"    />
        <result property="DeptName"    column="sub_DeptName"    />
        <result property="DrCode"    column="sub_DrCode"    />
        <result property="DrName"    column="sub_DrName"    />
        <result property="AdmitDate"    column="sub_AdmitDate"    />
        <result property="OrgID"    column="sub_OrgID"    />
        <result property="delFlag"    column="sub_Del_Flag"    />
        <result property="updateBy"    column="sub_Update_By"    />
        <result property="updateTime"    column="sub_Update_Time"    />
        <result property="createBy"    column="sub_Create_By"    />
        <result property="createTime"    column="sub_Create_Time"    />
        <result property="IsUpload"    column="sub_IsUpload"    />
        <result property="uploadTime"    column="sub_Upload_Time"    />
        <result property="SchemeStatus"    column="sub_SchemeStatus"    />
        <result property="DeptID"    column="sub_DeptID"    />
        <result property="SchemeTime"    column="sub_SchemeTime"    />
        <result property="HPI"    column="sub_HPI"    />
        <result property="MainSuit"    column="sub_MainSuit"    />
    <resultMap type="com.smartor.domain.PatArchive" id="PatArchiveResult">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="sex" column="sex"/>
        <result property="nation" column="nation"/>
        <result property="nativePlace" column="native_place"/>
        <result property="placeOfResidence" column="place_of_residence"/>
        <result property="birthplace" column="birthplace"/>
        <result property="idcardno" column="idcardno"/>
        <result property="birthdate" column="birthdate"/>
        <result property="age" column="age"/>
        <result property="sourcefrom" column="sourcefrom"/>
        <result property="archivetime" column="archivetime"/>
        <result property="archiveby" column="archiveby"/>
        <result property="telcode" column="telcode"/>
        <result property="relativetelcode" column="relativetelcode"/>
        <result property="idcardtype" column="idcardtype"/>
        <result property="orgid" column="orgid"/>
        <result property="openid" column="openid"/>
        <result property="delFlag" column="del_flag"/>
        <result property="dept" column="deptname"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="isupload" column="isupload"/>
        <result property="uploadTime" column="upload_time"/>
        <result property="tag" column="tag"/>
        <result property="pattype" column="pattype"/>
        <result property="bedNo" column="bedno"/>
        <result property="inhosptime" column="inhosptime"/>
        <result property="viptype" column="viptype"/>
    </resultMap>
    <sql id="selectPatArchiveVo">
        select PatID, Name, Gender, PapersNumber, BirthDate, Source, MakeArchiveTime, MakeArchivePeople, MobileNumberCode, RelativesNumber, PapersType, OrgID, Del_Flag, Update_By, Update_Time, Create_By, Create_Time, IsUpload, Upload_Time, Age, OpenId from pat_archive
        select id,
               name,
               sex,
               idcardno,
               birthdate,
               age,
               nation,
               native_place,
               place_of_residence,
               birthplace,
               sourcefrom,
               archivetime,
               archiveby,
               telcode,
               relativetelcode,
               idcardtype,
               orgid,
               openid,
               del_flag,
               update_by,
               update_time,
               create_by,
               create_time,
               isupload,
               pattype,
               viptype,
               upload_time
        from pat_archive
    </sql>
    <select id="selectPatArchiveList" parameterType="PatArchive" resultMap="PatArchiveResult">
    <select id="selectPatArchiveList" parameterType="com.smartor.domain.PatArchive" resultMap="PatArchiveResult">
        <include refid="selectPatArchiveVo"/>
        <where>
            <if test="Name != null  and Name != ''"> and Name like concat('%', #{Name}, '%')</if>
            <if test="PapersNumber != null  and PapersNumber != ''"> and PapersNumber = #{PapersNumber}</if>
            <if test="Source != null "> and Source = #{Source}</if>
            <if test="MobileNumberCode != null  and MobileNumberCode != ''"> and MobileNumberCode = #{MobileNumberCode}</if>
            <if test="OrgID != null  and OrgID != ''"> and OrgID = #{OrgID}</if>
            <if test="delFlag != null  and delFlag != ''"> and Del_Flag = #{delFlag}</if>
        <where>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and idcardno = #{idcardno}</if>
            <if test="sourcefrom != null ">and sourcefrom = #{sourcefrom}</if>
            <if test="telcode != null  and telcode != ''">and telcode = #{telcode}</if>
            <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
            <if test="id != null  and id != ''">and id = #{id}</if>
            <if test="isupload != null ">and isupload = #{isupload}</if>
            <if test="uploadTime != null ">and upload_time = #{uploadTime}</if>
            <if test="viptype != null ">and viptype = #{viptype}</if>
        </where>
    </select>
    <select id="selectPatArchiveByPatID" parameterType="Long" resultMap="PatArchivePatMedOuthospResult">
        select a.PatID, a.Name, a.Gender, a.PapersNumber, a.BirthDate, a.Source, a.MakeArchiveTime, a.MakeArchivePeople, a.MobileNumberCode, a.RelativesNumber, a.PapersType, a.OrgID, a.Del_Flag, a.Update_By, a.Update_Time, a.Create_By, a.Create_Time, a.IsUpload, a.Upload_Time, a.Age, a.OpenId,
 b.ID as sub_ID, b.SerialNum as sub_SerialNum, b.PatID as sub_PatID, b.HospitalName as sub_HospitalName, b.HospitalCode as sub_HospitalCode, b.Icd10Code as sub_Icd10Code, b.DiagName as sub_DiagName, b.DeptCode as sub_DeptCode, b.DeptName as sub_DeptName, b.DrCode as sub_DrCode, b.DrName as sub_DrName, b.AdmitDate as sub_AdmitDate, b.OrgID as sub_OrgID, b.Del_Flag as sub_Del_Flag, b.Update_By as sub_Update_By, b.Update_Time as sub_Update_Time, b.Create_By as sub_Create_By, b.Create_Time as sub_Create_Time, b.IsUpload as sub_IsUpload, b.Upload_Time as sub_Upload_Time, b.SchemeStatus as sub_SchemeStatus, b.DeptID as sub_DeptID, b.SchemeTime as sub_SchemeTime, b.HPI as sub_HPI, b.MainSuit as sub_MainSuit
        from pat_archive a
        left join pat_med_outhosp b on b.PatID = a.PatID
        where a.PatID = #{PatID}
    <select id="patInfoByContion" parameterType="com.smartor.domain.PatArchiveReq" resultMap="PatArchiveResult">
        select
        a.id,
        a.name,
        a.sex,
        c.tagname as tag,
        a.idcardtype,
        a.idcardno,
        a.age,
        a.telcode,
        a.create_time,
        a.update_time,
        a.viptype,
        a.birthdate
        from pat_archive a,pat_archivetag b ,base_tag c
        <where>
            a.del_flag=0 and
            a.id = b.patid and b.tagid = c.tagid
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and idcardno = #{idcardno}</if>
            <if test="telcode != null  and telcode != ''">and telcode = #{telcode}</if>
            <if test="tagIds != null  and tagIds != ''">and c.tagid in
                <foreach collection="tagIds" item="tagId" open="(" separator="," close=")">
                    #{tagId}
                </foreach>
            </if>
        </where>
    </select>
    <insert id="insertPatArchive" parameterType="PatArchive" useGeneratedKeys="true" keyProperty="PatID">
        insert into pat_archive
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="Name != null">Name,</if>
            <if test="Gender != null">Gender,</if>
            <if test="PapersNumber != null">PapersNumber,</if>
            <if test="BirthDate != null">BirthDate,</if>
            <if test="Source != null">Source,</if>
            <if test="MakeArchiveTime != null">MakeArchiveTime,</if>
            <if test="MakeArchivePeople != null">MakeArchivePeople,</if>
            <if test="MobileNumberCode != null">MobileNumberCode,</if>
            <if test="RelativesNumber != null">RelativesNumber,</if>
            <if test="PapersType != null">PapersType,</if>
            <if test="OrgID != null">OrgID,</if>
            <if test="delFlag != null and delFlag != ''">Del_Flag,</if>
            <if test="updateBy != null">Update_By,</if>
            <if test="updateTime != null">Update_Time,</if>
            <if test="createBy != null">Create_By,</if>
            <if test="createTime != null">Create_Time,</if>
            <if test="IsUpload != null">IsUpload,</if>
            <if test="uploadTime != null">Upload_Time,</if>
            <if test="Age != null">Age,</if>
            <if test="OpenId != null">OpenId,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="Name != null">#{Name},</if>
            <if test="Gender != null">#{Gender},</if>
            <if test="PapersNumber != null">#{PapersNumber},</if>
            <if test="BirthDate != null">#{BirthDate},</if>
            <if test="Source != null">#{Source},</if>
            <if test="MakeArchiveTime != null">#{MakeArchiveTime},</if>
            <if test="MakeArchivePeople != null">#{MakeArchivePeople},</if>
            <if test="MobileNumberCode != null">#{MobileNumberCode},</if>
            <if test="RelativesNumber != null">#{RelativesNumber},</if>
            <if test="PapersType != null">#{PapersType},</if>
            <if test="OrgID != null">#{OrgID},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="IsUpload != null">#{IsUpload},</if>
            <if test="uploadTime != null">#{uploadTime},</if>
            <if test="Age != null">#{Age},</if>
            <if test="OpenId != null">#{OpenId},</if>
         </trim>
    <select id="selectPatArchiveByPatid" parameterType="Long" resultMap="PatArchiveResult">
        <include refid="selectPatArchiveVo"/>
        where id = #{id} and del_flag=0
    </select>
    <insert id="insertPatArchive">
        <!--        insert into pat_archive-->
        <!--        <trim prefix="(" suffix=")" suffixOverrides=",">-->
        <!--            name,-->
        <!--            sex,-->
        <!--            iccardno-->
        <!--&lt;!&ndash;            <if test="birthdate != null">birthdate,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="age != null">age,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="sourcefrom != null">sourcefrom,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="archivetime != null">archivetime,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="archiveby != null">archiveby,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="telcode != null">telcode,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="relativetelcode != null">relativetelcode,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="iccardtype != null">iccardtype,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="orgid != null">orgid,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="openid != null">openid,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="delFlag != null and delFlag != ''">del_flag,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="updateBy != null">update_by,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="updateTime != null">update_time,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="createBy != null">create_by,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="createTime != null">create_time,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="isupload != null">isupload,</if>&ndash;&gt;-->
        <!--&lt;!&ndash;            <if test="uploadTime != null">upload_time,</if>&ndash;&gt;-->
        <!--        </trim>-->
        <!--        <trim prefix="values (" suffix=")" suffixOverrides=",">-->
        <!--            <foreach item="item" index="index" collection="list" separator=",">-->
        <!--                <if test="name != null">#{item.name},</if>-->
        <!--                <if test="sex != null">#{item.sex},</if>-->
        <!--                <if test="iccardno != null">#{item.iccardno},</if>-->
        <!--&lt;!&ndash;                <if test="birthdate != null">#{birthdate},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="age != null">#{item.age},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="sourcefrom != null">#{item.sourcefrom},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="archivetime != null">#{item.archivetime},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="archiveby != null">#{item.archiveby},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="telcode != null">#{item.telcode},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="relativetelcode != null">#{item.relativetelcode},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="iccardtype != null">#{item.iccardtype},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="orgid != null">#{item.orgid},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="openid != null">#{item.openid},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="delFlag != null and delFlag != ''">#{item.delFlag},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="updateBy != null">#{item.updateBy},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="updateTime != null">#{item.updateTime},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="createBy != null">#{item.createBy},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="createTime != null">#{item.createTime},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="isupload != null">#{item.isupload},</if>&ndash;&gt;-->
        <!--&lt;!&ndash;                <if test="uploadTime != null">#{item.uploadTime},</if>&ndash;&gt;-->
        <!--            </foreach>-->
        <!--        </trim>-->
        insert into
        pat_archive(name,viptype,sex,idcardno,birthdate,birthplace,place_of_residence,age,sourcefrom,archivetime,archiveby,telcode,relativetelcode,idcardtype,orgid,openid,dduserid,update_by,update_time
        ,create_by,create_time,isupload,upload_time,pattype,place_of_residence,nation,birthplace,native_place) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.name},#{item.viptype},#{item.sex},#{item.idcardno},#{item.birthdate},#{item.birthplace},#{item.placeOfResidence},#{item.age},#{item.sourcefrom},#{item.archivetime},#{item.archiveby}
            ,#{item.telcode},#{item.archiveby},#{item.idcardtype},#{item.orgid},#{item.openid},#{item.dduserid},#{item.updateBy},
            #{item.updateTime},#{item.createBy},#{item.createTime},#{item.isupload},#{item.uploadTime},#{item.pattype},#{item.placeOfResidence},#{item.nation},#{item.birthplace},#{item.nativePlace}
            )
        </foreach>
    </insert>
    <update id="updatePatArchive" parameterType="PatArchive">
    <update id="updatePatArchive" parameterType="com.smartor.domain.PatArchive">
        update pat_archive
        <trim prefix="SET" suffixOverrides=",">
            <if test="Name != null">Name = #{Name},</if>
            <if test="Gender != null">Gender = #{Gender},</if>
            <if test="PapersNumber != null">PapersNumber = #{PapersNumber},</if>
            <if test="BirthDate != null">BirthDate = #{BirthDate},</if>
            <if test="Source != null">Source = #{Source},</if>
            <if test="MakeArchiveTime != null">MakeArchiveTime = #{MakeArchiveTime},</if>
            <if test="MakeArchivePeople != null">MakeArchivePeople = #{MakeArchivePeople},</if>
            <if test="MobileNumberCode != null">MobileNumberCode = #{MobileNumberCode},</if>
            <if test="RelativesNumber != null">RelativesNumber = #{RelativesNumber},</if>
            <if test="PapersType != null">PapersType = #{PapersType},</if>
            <if test="OrgID != null">OrgID = #{OrgID},</if>
            <if test="delFlag != null and delFlag != ''">Del_Flag = #{delFlag},</if>
            <if test="updateBy != null">Update_By = #{updateBy},</if>
            <if test="updateTime != null">Update_Time = #{updateTime},</if>
            <if test="createBy != null">Create_By = #{createBy},</if>
            <if test="createTime != null">Create_Time = #{createTime},</if>
            <if test="IsUpload != null">IsUpload = #{IsUpload},</if>
            <if test="uploadTime != null">Upload_Time = #{uploadTime},</if>
            <if test="Age != null">Age = #{Age},</if>
            <if test="OpenId != null">OpenId = #{OpenId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="idcardno != null">idcardno = #{idcardno},</if>
            <if test="birthdate != null">birthdate = #{birthdate},</if>
            <if test="placeOfResidence != null">place_of_residence = #{placeOfResidence},</if>
            <if test="birthplace != null">birthplace = #{birthplace},</if>
            <if test="age != null">age = #{age},</if>
            <if test="sourcefrom != null">sourcefrom = #{sourcefrom},</if>
            <if test="archivetime != null">archivetime = #{archivetime},</if>
            <if test="archiveby != null">archiveby = #{archiveby},</if>
            <if test="telcode != null">telcode = #{telcode},</if>
            <if test="relativetelcode != null">relativetelcode = #{relativetelcode},</if>
            <if test="idcardtype != null">idcardtype = #{idcardtype},</if>
            <if test="orgid != null">orgid = #{orgid},</if>
            <if test="openid != null">openid = #{openid},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="isupload != null">isupload = #{isupload},</if>
            <if test="uploadTime != null">upload_time = #{uploadTime},</if>
            <if test="viptype != null">viptype = #{viptype},</if>
        </trim>
        where PatID = #{PatID}
        where id = #{id}
    </update>
    <delete id="deletePatArchiveByPatID" parameterType="Long">
        delete from pat_archive where PatID = #{PatID}
    <delete id="deletePatArchiveByPatid" parameterType="Long">
        delete
        from pat_archive
        where id = #{id}
    </delete>
    <delete id="deletePatArchiveByPatIDs" parameterType="String">
        delete from pat_archive where PatID in
        <foreach item="PatID" collection="array" open="(" separator="," close=")">
            #{PatID}
        </foreach>
    </delete>
    <delete id="deletePatMedOuthospByPatIDs" parameterType="String">
        delete from pat_med_outhosp where PatID in
        <foreach item="patID" collection="array" open="(" separator="," close=")">
            #{patID}
    <delete id="deletePatArchiveByPatids" parameterType="String">
        delete from pat_archive where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deletePatMedOuthospByPatID" parameterType="Long">
        delete from pat_med_outhosp where PatID = #{patID}
    </delete>
    <select id="selectPatArchiveInfoByAllhosp" parameterType="com.smartor.domain.PatArchiveReq"
            resultMap="PatArchiveResult">
    <insert id="batchPatMedOuthosp">
        insert into pat_med_outhosp( ID, SerialNum, PatID, HospitalName, HospitalCode, Icd10Code, DiagName, DeptCode, DeptName, DrCode, DrName, AdmitDate, OrgID, Del_Flag, Update_By, Update_Time, Create_By, Create_Time, IsUpload, Upload_Time, SchemeStatus, DeptID, SchemeTime, HPI, MainSuit) values
      <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.ID}, #{item.SerialNum}, #{item.PatID}, #{item.HospitalName}, #{item.HospitalCode}, #{item.Icd10Code}, #{item.DiagName}, #{item.DeptCode}, #{item.DeptName}, #{item.DrCode}, #{item.DrName}, #{item.AdmitDate}, #{item.OrgID}, #{item.delFlag}, #{item.updateBy}, #{item.updateTime}, #{item.createBy}, #{item.createTime}, #{item.IsUpload}, #{item.uploadTime}, #{item.SchemeStatus}, #{item.DeptID}, #{item.SchemeTime}, #{item.HPI}, #{item.MainSuit})
        </foreach>
    </insert>
</mapper>
        SELECT
        a.id,
        a.NAME,
        a.sex,
        a.nation,
        a.native_place,
        a.place_of_residence,
        a.birthplace,
        a.idcardno,
        a.birthdate,
        a.age,
        a.sourcefrom,
        a.archivetime,
        a.archiveby,
        a.telcode,
        a.relativetelcode,
        a.idcardtype,
        a.orgid,
        a.openid,
        a.del_flag,
        a.update_by,
        a.update_time,
        a.create_by,
        a.create_time,
        a.isupload,
        a.upload_time,
        a.viptype,
        a.pattype,
        b.tagname AS tag,
        b.tagid AS tagid
        FROM
        pat_archive a
        LEFT JOIN pat_archivetag b ON a.id = b.patid AND b.del_flag = 0
        <where>
            a.del_flag = 0
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>
            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>
            <if test="telcode != null  and telcode != ''">and a.telcode = #{telcode}</if>
            <if test="tagIds != null  and tagIds != ''">and b.tagid in
                <foreach collection="tagIds" item="tagId" open="(" separator="," close=")">
                    #{tagId}
                </foreach>
            </if>
        </where>
    </select>
    <select id="selectPatArchiveInfoByInhosp" parameterType="com.smartor.domain.PatArchiveReq"
            resultMap="PatArchiveResult">
        select
        a.id,
        a.NAME,
        d.deptname,
        a.sex,
        a.nation,
        a.native_place,
        a.place_of_residence,
        a.birthplace,
        a.idcardno,
        a.birthdate,
        a.age,
        a.sourcefrom,
        a.archivetime,
        a.archiveby,
        a.telcode,
        a.relativetelcode,
        a.idcardtype,
        a.orgid,
        a.viptype,
        a.openid,
        a.del_flag,
        a.update_by,
        a.update_time,
        a.create_by,
        a.create_time,
        a.isupload,
        a.upload_time,
        a.pattype,
        d.bed_no,
        d.starttime AS inhosptime,
        t.tagname
        FROM
        pat_med_inhosp d
        JOIN pat_archive a ON a.id = d.patid
        LEFT JOIN ( SELECT patid, GROUP_CONCAT( tagname ) AS tagname FROM pat_archivetag GROUP BY patid ) t ON t.patid =
        d.patid
        <where>
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>
            <if test="pid != null  and pid != ''">and a.id = #{id}</if>
            <if test="telcode != null  and telcode != ''">and a.telcode = #{telcode}</if>
            <if test="hospitalname != null and hospitalname != ''">
                AND d.hospitalname = #{hospitalname}
            </if>
            <if test="hospitaldistrictname != null and hospitaldistrictname != ''">
                AND d.hospitaldistrictname LIKE concat('%',#{hospitaldistrictname}, '%')
            </if>
            <if test="leaveicd10code != null and leaveicd10code != ''">
                AND d.leaveicd10code LIKE concat('%',#{leaveicd10code}, '%')
            </if>
            <if test="endtime != null">
                AND d.endtime = #{endtime}
            </if>
            <if test="visitno != null and visitno != ''">
                AND d.inhospno = #{visitno}
            </if>
            <if test="deptname != null and deptname != ''">
                and d.deptname LIKE concat('%', #{deptname}, '%')
            </if>
            <if test="drname != null and drname != ''">
                AND d.drname LIKE concat('%',#{drname}, '%')
            </if>
            <if test="diagname != null and diagname != ''">
                AND d.diagname LIKE concat('%',#{diagname}, '%')
            </if>
            <if test="deptname != null and deptname != ''">
                AND d.deptname LIKE concat('%',#{deptname}, '%')
            </if>
            <if test="pids != null">
                AND a.id NOT IN
                <foreach collection="pids" item="pid" open="(" separator="," close=")">
                    #{pid}
                </foreach>
            </if>
            AND d.del_flag != 1
            AND a.del_flag != 1
        </where>
    </select>
    <select id="selectPatArchiveInfoByOuthosp" parameterType="com.smartor.domain.PatArchiveReq"
            resultMap="PatArchiveResult">
        select
        a.id,
        d.deptname,
        a.name,
        a.sex,
        a.nation,
        a.native_place,
        a.place_of_residence,
        a.birthplace,
        a.idcardno,
        a.birthdate,
        a.age,
        a.viptype,
        a.sourcefrom,
        a.archivetime,
        a.archiveby,
        a.telcode,
        a.relativetelcode,
        a.idcardtype,
        a.orgid,
        a.openid,
        a.del_flag,
        a.update_by,
        a.update_time,
        a.create_by,
        a.create_time,
        a.isupload,
        a.upload_time,
        a.pattype
        from pat_med_outhosp d JOIN pat_archive a ON a.id = d.patid
        LEFT JOIN ( SELECT patid, GROUP_CONCAT( tagname ) AS tagname FROM pat_archivetag GROUP BY patid ) t ON t.patid =
        d.patid
        <where>
            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>
            <if test="telcode != null  and telcode != ''">and a.telcode = #{telcode}</if>
            <if test="hospitaldistrictname != null and hospitaldistrictname != ''">
                AND d.hospitaldistrictname LIKE concat('%',#{hospitaldistrictname}, '%')
            </if>
            <if test="diagname != null and diagname != ''">
                AND d.diagname LIKE concat('%',#{diagname}, '%')
            </if>
            <if test="hospitalname != null and hospitalname != ''">
                AND d.hospitalname = #{hospitalname}
            </if>
            <if test="visitno != null and visitno != ''">
                AND d.outhospno = #{visitno}
            </if>
            <if test="deptname != null and deptname != ''">
                and d.deptname LIKE concat('%', #{deptname}, '%')
            </if>
            <if test="drname != null and drname != ''">
                AND d.drname LIKE concat('%',#{drname}, '%')
            </if>
            <if test="pids != null">
                AND a.id NOT IN
                <foreach collection="pids" item="pid" open="(" separator="," close=")">
                    #{pid}
                </foreach>
            </if>
            AND d.del_flag != 1
            AND a.del_flag != 1
        </where>
    </select>
    <select id="selectPatArchiveInfoByPhysical" parameterType="com.smartor.domain.PatArchiveReq"
            resultMap="PatArchiveResult">
        select
        a.id,
        a.name,
        a.sex,
        d.deptname,
        a.nation,
        a.native_place,
        a.place_of_residence,
        a.birthplace,
        a.viptype,
        a.idcardno,
        a.birthdate,
        a.age,
        a.sourcefrom,
        a.archivetime,
        a.archiveby,
        a.telcode,
        a.relativetelcode,
        a.idcardtype,
        a.orgid,
        a.openid,
        a.del_flag,
        a.update_by,
        a.update_time,
        a.create_by,
        a.create_time,
        a.isupload,
        a.upload_time,
        a.pattype
        from pat_med_physical d JOIN pat_archive a ON a.id = d.patid
        LEFT JOIN ( SELECT patid, GROUP_CONCAT( tagname ) AS tagname FROM pat_archivetag GROUP BY patid ) t ON t.patid =
        d.patid
        <where>
            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>
            <if test="telcode != null  and telcode != ''">and a.telcode = #{telcode}</if>
            <if test="hospitaldistrictname != null and hospitaldistrictname != ''">
                AND d.hospitaldistrictname LIKE concat('%',#{hospitaldistrictname}, '%')
            </if>
            <if test="diagname != null and diagname != ''">
                AND d.diagname LIKE concat('%',#{diagname}, '%')
            </if>
            <if test="hospitalname != null and hospitalname != ''">
                AND d.hospitalname = #{hospitalname}
            </if>
            <if test="visitno != null and visitno != ''">
                AND d.physno = #{visitno}
            </if>
            <if test="deptname != null and deptname != ''">
                and d.deptname LIKE concat('%', #{deptname}, '%')
            </if>
            <if test="drname != null and drname != ''">
                AND d.drname LIKE concat('%',#{drname}, '%')
            </if>
            <if test="pids != null">
                AND a.id NOT IN
                <foreach collection="pids" item="pid" open="(" separator="," close=")">
                    #{pid}
                </foreach>
            </if>
            AND d.del_flag != 1
            AND a.del_flag != 1
        </where>
    </select>
</mapper>