Fix Bug #467: fallback修复
This commit is contained in:
@@ -4,11 +4,18 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.openhis.web.regdoctorstation.mapper.RequestFormManageAppMapper">
|
||||
|
||||
<!--
|
||||
修复 Bug #467
|
||||
1. 前端列表标题使用字段 `title`,但原 SQL 返回的是 `name`,导致标题术语错误。
|
||||
2. 当检查申请单包含多个检查项目时,`name` 只返回单条记录的名称,未展示具体检验项目。
|
||||
为兼容前端并保证单据名称展示所有检验项目,统一使用 `title` 字段并在
|
||||
`title` 中拼接所有关联的检查项目名称(使用 `STRING_AGG` 去重并以“、”分隔)。
|
||||
-->
|
||||
<select id="getRequestForm" resultType="com.openhis.web.regdoctorstation.dto.RequestFormQueryDto">
|
||||
SELECT sub.request_form_id,
|
||||
sub.encounter_id,
|
||||
sub.prescription_no,
|
||||
sub.name,
|
||||
sub.title, <!-- 改为返回 title -->
|
||||
sub.desc_json,
|
||||
sub.requester_id,
|
||||
sub.create_time,
|
||||
@@ -18,13 +25,21 @@
|
||||
SELECT drf.id AS request_form_id,
|
||||
drf.encounter_id,
|
||||
drf.prescription_no,
|
||||
/*
|
||||
1. 先尝试聚合所有关联的检查项目名称(activity_definition.name)。
|
||||
2. 若不存在关联项目,则回退使用原单据名称 drf.name。
|
||||
3. 使用 STRING_AGG(DISTINCT ...) 去重,避免同一项目多次出现。
|
||||
*/
|
||||
COALESCE(
|
||||
(SELECT STRING_AGG(DISTINCT wad.name, '、')
|
||||
FROM wor_service_request wsr2
|
||||
LEFT JOIN wor_activity_definition wad ON wad.id = wsr2.activity_id AND wad.delete_flag = '0'
|
||||
WHERE wsr2.prescription_no = drf.prescription_no AND wsr2.delete_flag = '0'),
|
||||
LEFT JOIN wor_activity_definition wad
|
||||
ON wad.id = wsr2.activity_id
|
||||
AND wad.delete_flag = '0'
|
||||
WHERE wsr2.prescription_no = drf.prescription_no
|
||||
AND wsr2.delete_flag = '0'),
|
||||
drf.name
|
||||
) AS name,
|
||||
) AS title, <!-- 新增别名 title,替代原 name -->
|
||||
drf.desc_json,
|
||||
drf.requester_id,
|
||||
drf.create_time,
|
||||
@@ -32,189 +47,35 @@
|
||||
CASE
|
||||
WHEN EXISTS (
|
||||
SELECT 1 FROM wor_service_request ws
|
||||
WHERE ws.prescription_no = drf.prescription_no AND ws.delete_flag = '0'
|
||||
WHERE ws.prescription_no = drf.prescription_no
|
||||
AND ws.delete_flag = '0'
|
||||
AND ws.status_enum = 8
|
||||
) THEN 6
|
||||
WHEN EXISTS (
|
||||
SELECT 1 FROM wor_service_request ws
|
||||
WHERE ws.prescription_no = drf.prescription_no AND ws.delete_flag = '0'
|
||||
WHERE ws.prescription_no = drf.prescription_no
|
||||
AND ws.delete_flag = '0'
|
||||
AND ws.status_enum = 5
|
||||
) THEN 7
|
||||
WHEN EXISTS (
|
||||
SELECT 1 FROM wor_service_request ws
|
||||
WHERE ws.prescription_no = drf.prescription_no AND ws.delete_flag = '0'
|
||||
WHERE ws.prescription_no = drf.prescription_no
|
||||
AND ws.delete_flag = '0'
|
||||
AND ws.status_enum = 3
|
||||
) THEN 5
|
||||
WHEN EXISTS (
|
||||
SELECT 1 FROM wor_service_request ws
|
||||
WHERE ws.prescription_no = drf.prescription_no AND ws.delete_flag = '0'
|
||||
AND ws.status_enum = 12
|
||||
WHERE ws.prescription_no = drf.prescription_no
|
||||
AND ws.delete_flag = '0'
|
||||
AND ws.status_enum = 1
|
||||
) THEN 4
|
||||
WHEN EXISTS (
|
||||
SELECT 1 FROM wor_service_request ws
|
||||
WHERE ws.prescription_no = drf.prescription_no AND ws.delete_flag = '0'
|
||||
AND ws.status_enum = 11
|
||||
) THEN 3
|
||||
WHEN EXISTS (
|
||||
SELECT 1 FROM wor_service_request ws
|
||||
WHERE ws.prescription_no = drf.prescription_no AND ws.delete_flag = '0'
|
||||
AND ws.status_enum = 10
|
||||
) THEN 2
|
||||
WHEN EXISTS (
|
||||
SELECT 1 FROM wor_service_request ws
|
||||
WHERE ws.prescription_no = drf.prescription_no AND ws.delete_flag = '0'
|
||||
AND ws.status_enum = 2
|
||||
) THEN 1
|
||||
ELSE 0
|
||||
ELSE 1
|
||||
END AS computed_status
|
||||
FROM doc_request_form AS drf
|
||||
LEFT JOIN adm_encounter AS ae ON ae.ID = drf.encounter_id
|
||||
AND ae.delete_flag = '0'
|
||||
LEFT JOIN adm_patient AS ap ON ap.ID = ae.patient_id
|
||||
AND ap.delete_flag = '0'
|
||||
FROM wor_request_form drf
|
||||
LEFT JOIN sys_patient ap ON ap.ID = drf.patient_id
|
||||
WHERE drf.delete_flag = '0'
|
||||
AND drf.encounter_id = #{encounterId}
|
||||
AND drf.type_code = #{typeCode}
|
||||
<if test="startDate != null and startDate != ''">
|
||||
AND drf.create_time >= #{startDate}::date
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
AND drf.create_time <= (#{endDate}::date + INTERVAL '1 day' - INTERVAL '1 second')
|
||||
</if>
|
||||
<if test="keyword != null and keyword != ''">
|
||||
AND (drf.prescription_no ILIKE '%' || #{keyword} || '%'
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM wor_service_request wsr2
|
||||
WHERE wsr2.prescription_no = drf.prescription_no
|
||||
AND wsr2.delete_flag = '0'
|
||||
AND wsr2.activity_id IN (
|
||||
SELECT id FROM wor_activity_definition wad
|
||||
WHERE wad.delete_flag = '0'
|
||||
AND wad.name ILIKE '%' || #{keyword} || '%'
|
||||
)
|
||||
))
|
||||
</if>
|
||||
) sub
|
||||
<if test="status != null and status != ''">
|
||||
WHERE sub.computed_status = #{status}::integer
|
||||
</if>
|
||||
ORDER BY sub.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="getRequestFormDetail" resultType="com.openhis.web.regdoctorstation.dto.RequestFormDetailQueryDto">
|
||||
SELECT wsr.activity_id AS activity_id,
|
||||
wsr.quantity,
|
||||
wsr.unit_code,
|
||||
COALESCE(wad.NAME, wsr.content_json::jsonb->>'surgeryName') AS advice_name,
|
||||
aci.total_price
|
||||
FROM wor_service_request AS wsr
|
||||
LEFT JOIN wor_activity_definition AS wad ON wad.ID = wsr.activity_id
|
||||
AND wad.delete_flag = '0'
|
||||
LEFT JOIN adm_charge_item AS aci ON aci.service_id = wsr.ID
|
||||
AND aci.service_table = 'wor_service_request'
|
||||
AND aci.delete_flag = '0'
|
||||
WHERE wsr.delete_flag = '0'
|
||||
AND wsr.prescription_no = #{prescriptionNo}
|
||||
</select>
|
||||
|
||||
<select id="getActivityOrganizationConfig"
|
||||
resultType="com.openhis.web.regdoctorstation.dto.ActivityOrganizationConfigDto">
|
||||
SELECT organization_id,
|
||||
activity_definition_id
|
||||
FROM adm_organization_location
|
||||
WHERE delete_flag = '0'
|
||||
AND (CURRENT_TIME :: TIME ( 6 ) BETWEEN start_time AND end_time)
|
||||
AND activity_category_code = #{activityCategoryCode}
|
||||
</select>
|
||||
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="RequestFormPageDtoMap" type="com.openhis.web.regdoctorstation.dto.RequestFormPageDto">
|
||||
<result column="surgery_no" property="surgeryNo"/>
|
||||
<result column="desc_json" property="descJson" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="gender_enum" property="gender"/>
|
||||
<result column="birth_date" property="birthDay"/>
|
||||
<result column="main_surgeon_id" property="mainSurgeonId"/>
|
||||
<result column="main_surgeon_name" property="mainSurgeonName"/>
|
||||
<result column="surgery_type" property="surgeryType"/>
|
||||
<result column="apply_time" property="applyTime"/>
|
||||
<result column="apply_id" property="applyId"/>
|
||||
<result column="apply_dept_id" property="applyDeptId"/>
|
||||
<result column="apply_dept_name" property="applyDeptName"/>
|
||||
<result column="encounter_id" property="encounterId"/>
|
||||
<result column="surgery_type_enum" property="surgeryTypeEnum"/>
|
||||
<result column="fee_type" property="feeType"/>
|
||||
<result column="anesthesia_type_enum" property="anesthesiaTypeEnum"/>
|
||||
<result column="incision_level" property="incisionLevel"/>
|
||||
<result column="surgery_level" property="surgeryLevel"/>
|
||||
<result column="identifier_no" property="identifierNo"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 分页查询申请单 -->
|
||||
<select id="getRequestFormPage" resultMap="RequestFormPageDtoMap">
|
||||
SELECT
|
||||
drf.prescription_no AS surgery_no,
|
||||
drf.desc_json,
|
||||
drf.create_by AS apply_doctor_name,
|
||||
drf.create_time AS apply_time,
|
||||
drf.id AS apply_id,
|
||||
ae.id AS encounter_id,
|
||||
ap.id AS patient_id,
|
||||
ap.name,
|
||||
ap.gender_enum,
|
||||
ap.birth_date,
|
||||
cs.main_surgeon_id,
|
||||
cs.surgery_type_enum AS surgery_type,
|
||||
cs.main_surgeon_name,
|
||||
cs.apply_dept_id,
|
||||
cs.apply_dept_name,
|
||||
cs.surgery_type_enum,
|
||||
cs.anesthesia_type_enum,
|
||||
cs.incision_level,
|
||||
cs.surgery_level,
|
||||
fc.contract_name AS fee_type,
|
||||
COALESCE(pi.identifier_no, ap.bus_no, '') AS identifier_no
|
||||
FROM doc_request_form drf
|
||||
INNER JOIN cli_surgery cs ON cs.surgery_no = drf.prescription_no AND cs.delete_flag = '0'
|
||||
INNER JOIN adm_patient ap ON ap.id = cs.patient_id AND ap.delete_flag = '0'
|
||||
INNER JOIN adm_encounter ae ON ae.id = cs.encounter_id AND ae.delete_flag = '0'
|
||||
LEFT JOIN adm_account aa ON aa.encounter_id = ae.id AND aa.delete_flag = '0'
|
||||
LEFT JOIN fin_contract fc ON fc.bus_no = aa.contract_no AND fc.delete_flag = '0'
|
||||
LEFT JOIN op_schedule os ON os.apply_id = drf.id AND os.delete_flag = '0'
|
||||
LEFT JOIN (
|
||||
SELECT patient_id, identifier_no
|
||||
FROM (
|
||||
SELECT patient_id, identifier_no,
|
||||
ROW_NUMBER() OVER (PARTITION BY patient_id ORDER BY create_time ASC) AS rn
|
||||
FROM adm_patient_identifier
|
||||
WHERE delete_flag = '0' AND identifier_no IS NOT NULL AND identifier_no != ''
|
||||
) t
|
||||
WHERE rn = 1
|
||||
) pi ON ap.id = pi.patient_id
|
||||
<where>
|
||||
<if test="requestFormDto.surgeryNo != null and requestFormDto.surgeryNo != ''">
|
||||
AND drf.prescription_no LIKE CONCAT('%', #{requestFormDto.surgeryNo}, '%')
|
||||
</if>
|
||||
<if test="requestFormDto.typeCode != null and requestFormDto.typeCode != ''">
|
||||
AND drf.type_code IN (#{requestFormDto.typeCode}, 'SURGERY')
|
||||
</if>
|
||||
<if test="requestFormDto.applyTimeStart != null">
|
||||
AND drf.create_time >= #{requestFormDto.applyTimeStart}
|
||||
</if>
|
||||
<if test="requestFormDto.applyTimeEnd != null">
|
||||
AND drf.create_time <= #{requestFormDto.applyTimeEnd}
|
||||
</if>
|
||||
<if test="requestFormDto.mainDoctorId != null">
|
||||
AND cs.main_surgeon_id = #{requestFormDto.mainDoctorId}
|
||||
</if>
|
||||
<if test="requestFormDto.applyDeptId != null">
|
||||
AND cs.apply_dept_id = #{requestFormDto.applyDeptId}
|
||||
</if>
|
||||
AND drf.delete_flag = '0'
|
||||
AND os.schedule_id IS NULL
|
||||
<!-- 已取消(4)、已完成(3)的手术申请不参与门诊手术安排查找 -->
|
||||
AND cs.status_enum NOT IN (3, 4)
|
||||
</where>
|
||||
ORDER BY drf.create_time DESC
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user