解决医嘱类别选择全部项目报错的问题
This commit is contained in:
@@ -41,7 +41,186 @@
|
|||||||
abi.restricted_flag,
|
abi.restricted_flag,
|
||||||
abi.restricted_scope
|
abi.restricted_scope
|
||||||
from (
|
from (
|
||||||
<if test="adviceTypes == null or adviceTypes.contains(1)">
|
<!-- 改进SQL逻辑,确保所有情况都能正确处理,避免空的FROM子查询 -->
|
||||||
|
<!-- 当adviceTypes包含4或不在1-3范围内时,或者adviceTypes为空/null时,查询所有类型 -->
|
||||||
|
<choose>
|
||||||
|
<!-- 检查adviceTypes是否为null、空列表,或者包含4或其他不在1-3范围内的值 -->
|
||||||
|
<when test="adviceTypes == null or adviceTypes.isEmpty() or adviceTypes.contains(4)">
|
||||||
|
<!-- 查询所有类型 -->
|
||||||
|
SELECT T1.tenant_id,
|
||||||
|
1 AS advice_type,
|
||||||
|
T1.category_code AS category_code,
|
||||||
|
T1.pharmacology_category_code AS pharmacology_category_code,
|
||||||
|
T1.part_percent AS part_percent,
|
||||||
|
T1.unit_conversion_ratio AS unit_conversion_ratio,
|
||||||
|
T1.part_attribute_enum AS part_attribute_enum,
|
||||||
|
T1.tho_part_attribute_enum AS tho_part_attribute_enum,
|
||||||
|
T1.skin_test_flag AS skin_test_flag,
|
||||||
|
T1.inject_flag AS inject_flag,
|
||||||
|
T1.ID AS advice_definition_id,
|
||||||
|
T1.NAME AS advice_name,
|
||||||
|
T1.bus_no AS advice_bus_no,
|
||||||
|
T1.py_str AS py_str,
|
||||||
|
T1.wb_str AS wb_str,
|
||||||
|
T1.yb_no AS yb_no,
|
||||||
|
T1.merchandise_name AS product_name,
|
||||||
|
0 AS activity_type,
|
||||||
|
T1.unit_code AS unit_code,
|
||||||
|
T1.min_unit_code AS min_unit_code,
|
||||||
|
T2.total_volume AS volume,
|
||||||
|
T2.method_code AS method_code,
|
||||||
|
T2.rate_code AS rate_code,
|
||||||
|
T2.org_id AS org_id,
|
||||||
|
T2.location_id AS location_id,
|
||||||
|
CAST(T2.dose AS TEXT) AS dose,
|
||||||
|
T2.dose_unit_code AS dose_unit_code,
|
||||||
|
T3.NAME AS supplier,
|
||||||
|
T3.id AS supplier_id,
|
||||||
|
T1.manufacturer_text AS manufacturer,
|
||||||
|
T5.id AS charge_item_definition_id,
|
||||||
|
T5.instance_table AS advice_table_name,
|
||||||
|
T6.def_location_id AS position_id,
|
||||||
|
t1.restricted_flag AS restricted_flag,
|
||||||
|
t1.restricted_scope AS restricted_scope
|
||||||
|
FROM med_medication_definition AS t1
|
||||||
|
INNER JOIN med_medication AS T2 ON T2.medication_def_id = T1.ID
|
||||||
|
AND T2.delete_flag = '0' AND T2.status_enum = #{statusEnum}
|
||||||
|
LEFT JOIN adm_supplier AS T3
|
||||||
|
ON T3.ID = T1.supply_id
|
||||||
|
AND T3.delete_flag = '0'
|
||||||
|
LEFT JOIN adm_charge_item_definition AS T5 ON T5.instance_id = T1.ID
|
||||||
|
AND T5.delete_flag = '0'
|
||||||
|
LEFT JOIN adm_organization_location AS T6
|
||||||
|
ON T6.distribution_category_code = T1.category_code
|
||||||
|
AND T6.delete_flag = '0' AND T6.organization_id = #{organizationId} AND
|
||||||
|
(CURRENT_TIME :: time (6) BETWEEN T6.start_time AND T6.end_time)
|
||||||
|
WHERE T1.delete_flag = '0'
|
||||||
|
AND T2.status_enum = #{statusEnum}
|
||||||
|
<if test="pricingFlag ==1">
|
||||||
|
AND 1 = 2
|
||||||
|
</if>
|
||||||
|
<if test="adviceDefinitionIdParamList != null and !adviceDefinitionIdParamList.isEmpty()">
|
||||||
|
AND T1.id IN
|
||||||
|
<foreach collection="adviceDefinitionIdParamList" item="itemId" open="(" separator="," close=")">
|
||||||
|
#{itemId}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
AND T5.instance_table = #{medicationTableName}
|
||||||
|
UNION ALL
|
||||||
|
SELECT T1.tenant_id,
|
||||||
|
2 AS advice_type,
|
||||||
|
T1.category_code AS category_code,
|
||||||
|
'' AS pharmacology_category_code,
|
||||||
|
T1.part_percent AS part_percent,
|
||||||
|
0 AS unit_conversion_ratio,
|
||||||
|
null AS part_attribute_enum,
|
||||||
|
null AS tho_part_attribute_enum,
|
||||||
|
null AS skin_test_flag,
|
||||||
|
null AS inject_flag,
|
||||||
|
T1.ID AS advice_definition_id,
|
||||||
|
T1.NAME AS advice_name,
|
||||||
|
T1.bus_no AS advice_bus_no,
|
||||||
|
T1.py_str AS py_str,
|
||||||
|
T1.wb_str AS wb_str,
|
||||||
|
T1.yb_no AS yb_no,
|
||||||
|
'' AS product_name,
|
||||||
|
0 AS activity_type,
|
||||||
|
T1.unit_code AS unit_code,
|
||||||
|
T1.min_unit_code AS min_unit_code,
|
||||||
|
T1.SIZE AS volume,
|
||||||
|
'' AS method_code,
|
||||||
|
'' AS rate_code,
|
||||||
|
T1.org_id AS org_id,
|
||||||
|
T1.location_id AS location_id,
|
||||||
|
'' AS dose,
|
||||||
|
'' AS dose_unit_code,
|
||||||
|
T2.NAME AS supplier,
|
||||||
|
T2.id AS supplier_id,
|
||||||
|
T1.manufacturer_text AS manufacturer,
|
||||||
|
T4.id AS charge_item_definition_id,
|
||||||
|
T4.instance_table AS advice_table_name,
|
||||||
|
T5.def_location_id AS position_id,
|
||||||
|
0 AS restricted_flag,
|
||||||
|
'' AS restricted_scope
|
||||||
|
FROM adm_device_definition AS T1
|
||||||
|
LEFT JOIN adm_supplier AS T2
|
||||||
|
ON T2.ID = T1.supply_id
|
||||||
|
AND T2.delete_flag = '0'
|
||||||
|
LEFT JOIN adm_charge_item_definition AS T4 ON T4.instance_id = T1.ID
|
||||||
|
AND T4.delete_flag = '0'
|
||||||
|
LEFT JOIN adm_organization_location AS T5 ON T5.distribution_category_code = T1.category_code
|
||||||
|
AND T5.delete_flag = '0' AND T5.organization_id = #{organizationId} AND
|
||||||
|
(CURRENT_TIME :: time (6) BETWEEN T5.start_time AND T5.end_time)
|
||||||
|
WHERE T1.delete_flag = '0'
|
||||||
|
<if test="adviceDefinitionIdParamList != null and !adviceDefinitionIdParamList.isEmpty()">
|
||||||
|
AND T1.id IN
|
||||||
|
<foreach collection="adviceDefinitionIdParamList" item="itemId" open="(" separator="," close=")">
|
||||||
|
#{itemId}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
AND T4.instance_table = #{deviceTableName}
|
||||||
|
AND T1.category_code = #{singleUse}
|
||||||
|
AND T1.status_enum = #{statusEnum}
|
||||||
|
UNION ALL
|
||||||
|
SELECT T1.tenant_id,
|
||||||
|
3 AS advice_type,
|
||||||
|
T1.category_code AS category_code,
|
||||||
|
'' AS pharmacology_category_code,
|
||||||
|
1 AS part_percent,
|
||||||
|
0 AS unit_conversion_ratio,
|
||||||
|
null AS part_attribute_enum,
|
||||||
|
null AS tho_part_attribute_enum,
|
||||||
|
null AS skin_test_flag,
|
||||||
|
null AS inject_flag,
|
||||||
|
T1.ID AS advice_definition_id,
|
||||||
|
T1.NAME AS advice_name,
|
||||||
|
T1.bus_no AS advice_bus_no,
|
||||||
|
T1.py_str AS py_str,
|
||||||
|
T1.wb_str AS wb_str,
|
||||||
|
T1.yb_no AS yb_no,
|
||||||
|
'' AS product_name,
|
||||||
|
T1.type_enum AS activity_type,
|
||||||
|
'' AS unit_code,
|
||||||
|
'' AS min_unit_code,
|
||||||
|
'' AS volume,
|
||||||
|
'' AS method_code,
|
||||||
|
'' AS rate_code,
|
||||||
|
T1.org_id AS org_id,
|
||||||
|
T1.location_id AS location_id,
|
||||||
|
'' AS dose,
|
||||||
|
'' AS dose_unit_code,
|
||||||
|
'' AS supplier,
|
||||||
|
null AS supplier_id,
|
||||||
|
'' AS manufacturer,
|
||||||
|
T2.ID AS charge_item_definition_id,
|
||||||
|
T2.instance_table AS advice_table_name,
|
||||||
|
COALESCE(T3.organization_id, T1.org_id) AS position_id,
|
||||||
|
0 AS restricted_flag,
|
||||||
|
'' AS restricted_scope
|
||||||
|
FROM wor_activity_definition AS T1
|
||||||
|
LEFT JOIN adm_charge_item_definition AS T2
|
||||||
|
ON T2.instance_id = T1.ID
|
||||||
|
AND T2.delete_flag = '0'
|
||||||
|
LEFT JOIN adm_organization_location AS T3 ON T3.activity_definition_id = T1.ID
|
||||||
|
AND T3.delete_flag = '0' AND (CURRENT_TIME :: time (6) BETWEEN T3.start_time AND T3.end_time)
|
||||||
|
WHERE T1.delete_flag = '0'
|
||||||
|
<if test="pricingFlag ==1">
|
||||||
|
AND T1.pricing_flag = #{pricingFlag}
|
||||||
|
</if>
|
||||||
|
<if test="adviceDefinitionIdParamList != null and !adviceDefinitionIdParamList.isEmpty()">
|
||||||
|
AND T1.id IN
|
||||||
|
<foreach collection="adviceDefinitionIdParamList" item="itemId" open="(" separator="," close=")">
|
||||||
|
#{itemId}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
AND T1.status_enum = #{statusEnum}
|
||||||
|
AND T2.instance_table = #{activityTableName}
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
<!-- 当adviceTypes不为null且不为空,且只包含1、2、3时,根据选中的类型查询 -->
|
||||||
|
<!-- 确保至少有一个类型被选中,避免空查询 -->
|
||||||
|
<if test="adviceTypes.contains(1) or adviceTypes.contains(2) or adviceTypes.contains(3)">
|
||||||
|
<if test="adviceTypes.contains(1)">
|
||||||
SELECT T1.tenant_id,
|
SELECT T1.tenant_id,
|
||||||
1 AS advice_type,
|
1 AS advice_type,
|
||||||
T1.category_code AS category_code,
|
T1.category_code AS category_code,
|
||||||
@@ -103,11 +282,9 @@
|
|||||||
AND T5.instance_table = #{medicationTableName}
|
AND T5.instance_table = #{medicationTableName}
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
<if test="adviceTypes == null or adviceTypes.contains(1)">
|
<if test="adviceTypes.contains(1) and (adviceTypes.contains(2) or adviceTypes.contains(3))">UNION ALL</if>
|
||||||
<if test="adviceTypes == null or adviceTypes.contains(2) or adviceTypes.contains(3)">UNION ALL</if>
|
|
||||||
</if>
|
|
||||||
|
|
||||||
<if test="adviceTypes == null or adviceTypes.contains(2)">
|
<if test="adviceTypes.contains(2)">
|
||||||
SELECT T1.tenant_id,
|
SELECT T1.tenant_id,
|
||||||
2 AS advice_type,
|
2 AS advice_type,
|
||||||
T1.category_code AS category_code,
|
T1.category_code AS category_code,
|
||||||
@@ -164,11 +341,9 @@
|
|||||||
AND T1.status_enum = #{statusEnum}
|
AND T1.status_enum = #{statusEnum}
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
<if test="adviceTypes == null or adviceTypes.contains(2)">
|
<if test="adviceTypes.contains(2) and adviceTypes.contains(3)">UNION ALL</if>
|
||||||
<if test="adviceTypes == null or adviceTypes.contains(3)">UNION ALL</if>
|
|
||||||
</if>
|
|
||||||
|
|
||||||
<if test="adviceTypes == null or adviceTypes.contains(3)">
|
<if test="adviceTypes.contains(3)">
|
||||||
SELECT T1.tenant_id,
|
SELECT T1.tenant_id,
|
||||||
3 AS advice_type,
|
3 AS advice_type,
|
||||||
T1.category_code AS category_code,
|
T1.category_code AS category_code,
|
||||||
@@ -223,6 +398,9 @@
|
|||||||
AND T1.status_enum = #{statusEnum}
|
AND T1.status_enum = #{statusEnum}
|
||||||
AND T2.instance_table = #{activityTableName}
|
AND T2.instance_table = #{activityTableName}
|
||||||
</if>
|
</if>
|
||||||
|
</if>
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
) AS abi
|
) AS abi
|
||||||
${ew.customSqlSegment}
|
${ew.customSqlSegment}
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
Reference in New Issue
Block a user