<?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.datadictionary.mapper.ActivityDefinitionManageMapper">
    <select id="getDiseaseTreatmentPage" parameterType="java.util.Map"
            resultType="com.openhis.web.datadictionary.dto.DiagnosisTreatmentDto">

        SELECT
        T3.id,
        T3.category_code,
        T3.bus_no,
        T3.name,
        T3.py_str,
        T3.wb_str,
        T3.type_enum,
        T3.permitted_unit_code,
        T3.org_id,
        T3.location_id,
        T3.yb_flag,
        T3.yb_no,
        T3.yb_match_flag,
        T3.status_enum,
        T3.body_site_code,
        T3.specimen_code,
        T3.description_text,
        T3.rule_id,
        T3.tenant_id,
        T3.item_type_code,
        T3.yb_type,
        T3.retail_price,
        T3.maximum_retail_price,
        T3.chrgitm_lv,--医保等级
        T3.children_json,--子项json
        T3.pricing_flag--划价标记
        FROM
        (
        SELECT
        T1.id,
        T1.category_code,
        T1.bus_no,
        T1.name,
        T1.py_str,
        T1.wb_str,
        T1.type_enum,
        T1.permitted_unit_code,
        T1.org_id,
        T1.location_id,
        T1.yb_flag,
        T1.yb_no,
        T1.yb_match_flag,
        T1.status_enum,
        T1.body_site_code,
        T1.specimen_code,
        T1.description_text,
        T1.rule_id,
        T1.tenant_id,
        T1.chrgitm_lv,--医保等级
        T2.type_code as item_type_code,
        T2.yb_type,
        T2.price as retail_price,--零售价
        (   SELECT T4.amount
        FROM adm_charge_item_definition T5
        LEFT JOIN  adm_charge_item_def_detail T4 ON  T4.definition_id = T5.id
        WHERE   T4.condition_code = '4'--4:限制
        AND T5.instance_id = T1.id
        AND T5.instance_table = 'wor_activity_definition'
        ) as maximum_retail_price,--最高零售价
        T1.children_json,--子项json
        T1.pricing_flag--划价标记
        FROM wor_activity_definition T1
        LEFT JOIN adm_charge_item_definition T2 ON T1.id = T2.instance_id
        <where>
            T1.delete_flag = '0'
            AND  T2.instance_table = 'wor_activity_definition'
        </where>
        ORDER BY T1.bus_no DESC
        ) AS T3
        ${ew.customSqlSegment}

    </select>

    <select id="getDiseaseTreatmentOne" resultType="com.openhis.web.datadictionary.dto.DiagnosisTreatmentDto">
        SELECT
        T1.id,
        T1.category_code,
        T1.bus_no,
        T1.name,
        T1.py_str,
        T1.wb_str,
        T1.type_enum,
        T1.permitted_unit_code,
        T1.org_id,
        T1.location_id,
        T1.yb_flag,
        T1.yb_no,
        T1.yb_match_flag,
        T1.status_enum,
        T1.body_site_code,
        T1.specimen_code,
        T1.description_text,
        T1.rule_id,
        T1.tenant_id,
        T2.type_code as item_type_code,
        T2.yb_type,
        T2.price as retail_price,--零售价,
        (   SELECT T4.amount
        FROM adm_charge_item_definition T5
        LEFT JOIN  adm_charge_item_def_detail T4 ON  T4.definition_id = T5.id
        WHERE   T4.condition_code = '4'--4:限制
        AND T5.instance_id = T1.id
        AND T5.instance_table = 'wor_activity_definition'
        ) as maximum_retail_price,--最高零售价
        T1.chrgitm_lv,--医保等级
        T1.children_json,--子项json
        T1.pricing_flag--划价标记
        FROM wor_activity_definition T1
        LEFT JOIN adm_charge_item_definition T2 ON T1.id = T2.instance_id
        <where>
            T1.delete_flag = '0'
            AND  T2.instance_table = 'wor_activity_definition'

            <if test="id!= null">
                AND T1.id = #{id}
            </if>
            <if test="tenantId!= null">
                AND T1.tenant_id = #{tenantId}
            </if>
        </where>
    </select>

</mapper>