<?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">
<mapper namespace="com.openhis.web.paymentmanage.mapper.ChargeBillMapper">

    <select id="selectChargeItemExtendInfoList" resultType="com.openhis.web.paymentmanage.dto.ChargeItemExtendInfoDto">
        SELECT
        T1.total_price,
        T1.org_id,
        T1.yb_type
        FROM(
            SELECT
                a.total_price,
                COALESCE(b1.org_id, b2.org_id, b3.org_id, b4.offered_org_id, b5.org_id) AS org_id,
                --COALESCE(b1.yb_class_enum, b2.yb_class_enum, b3.yb_class_enum) AS yb_class_enum,
                b5.yb_type

                -- 添加更多需要的字段
            FROM
                adm_charge_item a
            LEFT JOIN
                med_medication_request b1 ON a.service_id = b1.id AND a.service_table = 'med_medication_request'
            LEFT JOIN
                wor_device_request b2 ON a.service_id = b2.id AND a.service_table = 'wor_device_request'
            LEFT JOIN
                wor_service_request b3 ON a.service_id = b3.id AND a.service_table = 'wor_service_request'
            LEFT JOIN
                adm_healthcare_service b4 ON a.service_id = b4.id AND a.service_table = 'adm_healthcare_service'
            LEFT JOIN
                adm_charge_item_definition b5 ON a.definition_id = b5.id
            WHERE
                a.delete_flag = '0'
            AND
                a.id IN
                <foreach collection="list" item="item" open="(" separator="," close=")">
                #{item}
                </foreach>
        ) AS T1
        <if test="orgIdList!=null and !orgIdList.isEmpty()">
            WHERE T1.org_id IN
            <foreach collection="orgIdList" item="orgId" open="(" separator="," close=")">
                #{orgId}
            </foreach>
        </if>
    </select>
</mapper>