<?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.ChargeItemDefSearchMapper">
    <select id="getMedList" resultType="com.openhis.web.datadictionary.dto.ChargeItemDefPageDto">
        SELECT
        T5.id,
        T5.charge_name,
        T5.status_enum,
        T5.status_enum_text,
        T5.description,
        T5.effective_start,
        T5.effective_end,
        T5.instance_table,
        T5.price,
        T5.create_time,
        T5.update_time,
        T5.item_id,
        T5.condition_rule_id,
        T5.condition_value,
        T5.condition_code,
        T5.priority,
        T5.amount,
        T5.item_no,
        T5.py_str,
        T5.wb_str,
        T5.unit_code,
        T5.category_code,
        T5.part_percent,
        T5.total_volume,
        T5.lot_number
        FROM (
        SELECT
        T1.id,
        T1.charge_name,
        T1.status_enum,
        CASE
            WHEN T1.status_enum = 1 THEN '草稿'
            WHEN T1.status_enum = 2 THEN '有效'
            WHEN T1.status_enum = 3 THEN '停用'
            WHEN T1.status_enum = 4 THEN '未知'
        END AS status_enum_text,
        T1.description,
        T1.effective_start,
        T1.effective_end,
        T1.instance_table,
        T1.price,
        T1.create_time,
        T1.update_time,
        T2.id AS item_id,
        T2.condition_rule_id,
        T2.condition_value,
        T2.condition_code,
        T2.priority,
        T2.amount,
        T3.bus_no AS item_no,
        T3.py_str,
        T3.wb_str,
        T3.unit_code,
        T1.yb_type AS category_code,
        T3.part_percent,
        T4.total_volume,
        T4.lot_number
        FROM
        adm_charge_item_definition T1
        LEFT JOIN adm_charge_item_def_detail T2
        ON T1.id = T2.definition_id
        LEFT JOIN med_medication_definition T3
        ON T1.instance_id = T3.id
        LEFT JOIN med_medication T4
        ON T3.id = T4.medication_def_id
        ORDER BY T1.create_time DESC) T5
        ${ew.customSqlSegment}
    </select>
    <select id="getDevList" resultType="com.openhis.web.datadictionary.dto.ChargeItemDefPageDto">
        SELECT
        T5.id,
        T5.charge_name,
        T5.status_enum,
        T5.status_enum_text,
        T5.description,
        T5.effective_start,
        T5.effective_end,
        T5.instance_table,
        T5.price,
        T5.create_time,
        T5.update_time,
        T5.item_id,
        T5.condition_rule_id,
        T5.condition_value,
        T5.condition_code,
        T5.priority,
        T5.amount,
        T5.item_no,
        T5.py_str,
        T5.wb_str,
        T5.unit_code,
        T5.category_code,
        T5.part_percent,
        T5.lot_number
        FROM (
        SELECT
        T1.id,
        T1.charge_name,
        T1.status_enum,
        CASE
            WHEN T1.status_enum = 1 THEN '草稿'
            WHEN T1.status_enum = 2 THEN '有效'
            WHEN T1.status_enum = 3 THEN '停用'
            WHEN T1.status_enum = 4 THEN '未知'
        END AS status_enum_text,
        T1.description,
        T1.effective_start,
        T1.effective_end,
        T1.instance_table,
        T1.price,
        T1.create_time,
        T1.update_time,
        T2.id AS item_id,
        T2.condition_rule_id,
        T2.condition_value,
        T2.condition_code,
        T2.priority,
        T2.amount,
        T3.bus_no AS item_no,
        T3.py_str,
        T3.wb_str,
        T3.unit_code AS unit_code,
        T1.yb_type AS category_code,
        T3.part_percent,
        T4.lot_number
        FROM
        adm_charge_item_definition T1
        LEFT JOIN adm_charge_item_def_detail T2
        ON T1.id = T2.definition_id
        LEFT JOIN adm_device_definition T3
        ON T1.instance_id = T3.id
        LEFT JOIN adm_device T4
        ON T3.id = T4.device_def_id
        ORDER BY T1.create_time DESC) T5
        ${ew.customSqlSegment}
    </select>
    <select id="getActList" resultType="com.openhis.web.datadictionary.dto.ChargeItemDefPageDto">
        SELECT
        T5.id,
        T5.charge_name,
        T5.status_enum,
        T5.status_enum_text,
        T5.description,
        T5.effective_start,
        T5.effective_end,
        T5.instance_table,
        T5.price,
        T5.create_time,
        T5.update_time,
        T5.item_id,
        T5.condition_rule_id,
        T5.condition_value,
        T5.condition_code,
        T5.priority,
        T5.amount,
        T5.item_no,
        T5.py_str,
        T5.wb_str,
        T5.unit_code,
        T5.category_code
        FROM (
        SELECT
        T1.id,
        T1.charge_name,
        T1.status_enum,
        CASE
            WHEN T1.status_enum = 1 THEN '草稿'
            WHEN T1.status_enum = 2 THEN '有效'
            WHEN T1.status_enum = 3 THEN '停用'
            WHEN T1.status_enum = 4 THEN '未知'
        END AS status_enum_text,
        T1.description,
        T1.effective_start,
        T1.effective_end,
        T1.instance_table,
        T1.price,
        T1.create_time,
        T1.update_time,
        T2.id AS item_id,
        T2.condition_rule_id,
        T2.condition_value,
        T2.condition_code,
        T2.priority,
        T2.amount,
        T3.bus_no AS item_no,
        T3.py_str,
        T3.wb_str,
        T3.permitted_unit_code AS unit_code,
        T1.yb_type AS category_code
        FROM
        adm_charge_item_definition T1
        LEFT JOIN adm_charge_item_def_detail T2
        ON T1.id = T2.definition_id
        LEFT JOIN wor_activity_definition T3
        ON T1.instance_id = T3.id
        ORDER BY T1.create_time DESC) T5
        ${ew.customSqlSegment}
    </select>
</mapper>