111
liusheng
2026-10-09 809f28b2efe947cb0987356cffa42de959e2aa4d
smartor/src/main/resources/mapper/smartor/PatMedInhospMapper.xml
@@ -370,7 +370,38 @@
            order by b.endtime desc
        </if>
        <if test="cry != null and cry==0">
            order by b.starttime desc , b.bed_no asc
            <!--
              在院患者:可按入院床位正/倒序(bedSort=asc 或 desc),不传时保持默认排序(入院时间倒序 + 床位正序)。
              床位按自然序排(只用 5.7 也支持的 REGEXP/CAST/TRIM/LENGTH,不依赖 8.0 的 REGEXP_REPLACE):
                1) 床位为空/空串的排最后
                2) 纯数字床位排前面,按数值大小(2 在 10 前)
                3) 带字母/汉字的床位按长度 + 字符串(A2 在 A12 前)
                4) inhospid 兜底,保证翻页顺序稳定
              倒序只反转 2)、3) 两组内部顺序:空床位仍排最后,纯数字仍在前。
            -->
            <choose>
                <when test='"asc".equals(bedSort)'>
                    order by
                    coalesce(trim(b.bed_no), '') = '' ,
                    (trim(b.bed_no) regexp '^[0-9]+$') = 0 ,
                    cast(trim(b.bed_no) as unsigned) asc ,
                    length(trim(b.bed_no)) asc ,
                    trim(b.bed_no) asc ,
                    b.inhospid asc
                </when>
                <when test='"desc".equals(bedSort)'>
                    order by
                    coalesce(trim(b.bed_no), '') = '' ,
                    (trim(b.bed_no) regexp '^[0-9]+$') = 0 ,
                    cast(trim(b.bed_no) as unsigned) desc ,
                    length(trim(b.bed_no)) desc ,
                    trim(b.bed_no) desc ,
                    b.inhospid asc
                </when>
                <otherwise>
                    order by b.starttime desc , b.bed_no asc
                </otherwise>
            </choose>
        </if>
    </select>
@@ -630,6 +661,19 @@
          AND d.del_flag = 0
    </select>
    <!-- 批量取患者标签,替代逐行调用 getTagnameBypatid;每行含 patid、tagname 两个 key -->
    <select id="getTagnameByPatids" resultType="java.util.HashMap">
        SELECT d.patid                     AS patid,
               GROUP_CONCAT(d.tagname, ', ') AS tagname
        FROM pat_archivetag d
        WHERE d.del_flag = 0
          AND d.patid IN
        <foreach collection="patids" item="patid" open="(" separator="," close=")">
            #{patid}
        </foreach>
        GROUP BY d.patid
    </select>
    <select id="selectPatMedInhospByInhospid" parameterType="Long" resultMap="PatMedInhospResult">
        <include refid="selectPatMedInhospVo"/>
@@ -715,6 +759,18 @@
        <if test="medicalCompany != null  and medicalCompany != ''">and medical_company like
            concat('%'#{medicalCompany}, '%')
        </if>
    </select>
    <!-- 按患者编号 + 出院日期查询出院记录(出院时间只比较到天,不比较时分秒),用于判断患者是否再入院 -->
    <select id="selectOutInhospByPatnoAndOutDate" resultMap="PatMedInhospResult">
        <include refid="selectPatMedInhospVo"/>
        where del_flag = 0
        and inhospstate = '1'
        <if test="patno != null and patno != ''">and patno = #{patno}</if>
        <if test="dayStart != null">and endtime &gt;= #{dayStart}</if>
        <if test="dayEnd != null">and endtime &lt; #{dayEnd}</if>
        order by inhospid desc
    </select>
@@ -808,7 +864,8 @@
            <if test="deptcode != null">#{deptcode},</if>
            <if test="deptname != null">#{deptname},</if>
            <if test="roomno != null">#{roomno},</if>
            <if test="bedNo != null">#{bedNo},</if>
            <!-- 床位空串(HIS 无当前床位)落库为 null,保持"有值 or null"两种状态 -->
            <if test="bedNo != null">nullif(#{bedNo}, ''),</if>
            <if test="orgid != null">#{orgid},</if>
            <if test="campusid != null">#{campusid},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
@@ -861,6 +918,7 @@
            <if test="fuspecialadvice != null ">#{fuspecialadvice},</if>
            <if test="managementDoctor != null ">#{managementDoctor},</if>
            <if test="managementDoctorCode != null ">#{managementDoctorCode},</if>
            <if test="inhospMydFlag != null ">#{inhospMydFlag},</if>
            <if test="importanceFlagCode != null ">#{importanceFlagCode},</if>
            <if test="emergencyLevelCode != null ">#{emergencyLevelCode},</if>
            <if test="encounterSourceId != null ">#{encounterSourceId},</if>
@@ -885,7 +943,7 @@
        nurse_id, nurse_name, out_way_id, out_way_name, guid,
        operator, operator_id, inhospno, remark,
        fuflag, fudate, fuperiod, futypecode, futypedesc, fuadvice, fuspecialadvice, management_doctor,
        management_doctor_doctor,campusid, inhosp_myd_flag, importance_flag_code, emergency_level_code, encounter_source_id,
        management_doctor_code,campusid, inhosp_myd_flag, importance_flag_code, emergency_level_code, encounter_source_id,
        medical_code, medical_name, medical_company
        )
        values
@@ -894,7 +952,7 @@
            #{item.serialnum}, #{item.hospitalname}, #{item.hospitalcode}, #{item.hospitaldistrictcode},
            #{item.hospitaldistrictname},
            #{item.icd10code}, #{item.diagname}, #{item.starttime}, #{item.endtime}, #{item.deptcode}, #{item.deptname},
            #{item.roomno}, #{item.bedNo},
            #{item.roomno}, nullif(#{item.bedNo}, ''),
            #{item.orgid}, #{item.delFlag}, #{item.updateBy}, #{item.updateTime}, #{item.createBy}, #{item.createTime},
            #{item.isupload},
            #{item.uploadTime}, #{item.patid}, #{item.leavediagname}, #{item.leaveicd10code}, #{item.drcode},
@@ -919,6 +977,11 @@
    <update id="updatePatMedInhosp" parameterType="com.smartor.domain.PatMedInhosp">
        update pat_med_inhosp
        <trim prefix="SET" suffixOverrides=",">
            <!--
              兜底:下面字段全为空时(例如调用方只传了 inhospid),如果没有任何 SET 项会生成
              "update pat_med_inhosp where inhospid = ?" 这种非法 SQL。这里放一个自赋值,保证 SET 不为空且不改数据。
            -->
            inhospid = inhospid,
            <if test="serialnum != null">serialnum = #{serialnum},</if>
            <if test="hospitalname != null">hospitalname = #{hospitalname},</if>
            <if test="hospitalcode != null">hospitalcode = #{hospitalcode},</if>
@@ -931,7 +994,12 @@
            <if test="deptcode != null">deptcode = #{deptcode},</if>
            <if test="deptname != null">deptname = #{deptname},</if>
            <if test="roomno != null">roomno = #{roomno},</if>
            <if test="bedNo != null">bed_no = #{bedNo},</if>
            <!--
              床位:HIS 传空串代表"当前没有床位"(换床、或人已离院还没办出院手续),落库为 null;
              完全不传(null)则不改动床位。空串与 null 必须分开判断,不能都跳过,否则床位不会被清掉。
            -->
            <if test='bedNo != null and !"".equals(bedNo)'>bed_no = #{bedNo},</if>
            <if test='bedNo != null and "".equals(bedNo)'>bed_no = null,</if>
            <if test="orgid != null">orgid = #{orgid},</if>
            <if test="campusid != null">campusid = #{campusid},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>