<?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.lantone.mapper.med.KlLibraryInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lantone.entity.med.KlLibraryInfo">
        <id column="id" property="id"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="creator" property="creator"/>
        <result column="modifier" property="modifier"/>
        <result column="name" property="name"/>
        <result column="concept_id" property="conceptId"/>
        <result column="is_concept" property="isConcept"/>
        <result column="type_id" property="typeId"/>
        <result column="spell" property="spell"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="getConcept" resultType="com.lantone.dto.med.TermConceptDTO">
        SELECT DISTINCT
        t.id as id,
        t.name ,
        t.isConcept as source
        <if test="type!=null and type==100">,
            t.code as code
        </if>
        <if test="type!=null and type==127">,
            t.code as code
        </if>
        <if test="type!=null and type==128">,
            t.code as code
        </if>
        <if test="type!=null and type==106">,
            t.code as code
        </if>
        FROM
        (SELECT DISTINCT
        a.concept_id as id,
        c.lib_name AS name,
        a.is_concept as isConcept
        <if test="type!=null and type==100">,
            b.icd10_code as code
        </if>
        <if test="type!=null and type==127">,
            b.code as code
        </if>
        <if test="type!=null and type==128">,
            b.code as code
        </if>
        <if test="type!=null and type==106">,
            b.operation_code as code
        </if>
        FROM
        kl_library_info a
        LEFT JOIN kl_concept c
        ON a.concept_id = c.id
        <if test="type!=null and type==100">
            left join kl_disease b
            on b.is_deleted = 'N'
            and a.concept_id = b.concept_id
        </if>
        <if test="type!=null and type==127">
            left join kl_tcm_disease b
            on b.is_deleted = 'N'
            and a.concept_id = b.concept_id
        </if>
        <if test="type!=null and type==128">
            left join kl_tcm_syndrome b
            on b.is_deleted = 'N'
            and a.concept_id = b.concept_id
        </if>
        <if test="type!=null and type==106">
            left join kl_operation b
            on b.is_deleted = 'N'
            and a.concept_id = b.concept_id
        </if>
        WHERE a.is_deleted = "N"
        AND c.status = 1
        <if test="type!=null">
            AND a.type_id = #{type}
        </if>
        <if test="inputStr!=null and inputStr!=''">
            AND a.name = #{inputStr}
        </if>
        ) t
    </select>

    <select id="getConceptList" resultType="com.lantone.dto.med.TermConceptDTO">
        SELECT DISTINCT
        t.id as id,
        t.name ,
        t.isConcept as source
        <if test="type!=null and type==100">,
            t.code as code
        </if>
        <if test="type!=null and type==127">,
            t.code as code
        </if>
        <if test="type!=null and type==128">,
            t.code as code
        </if>
        <if test="type!=null and type==106">,
            t.code as code
        </if>
        FROM
        (SELECT DISTINCT
        a.concept_id as id,
        c.lib_name AS name,
        a.is_concept as isConcept
        <if test="type!=null and type==100">,
            b.icd10_code as code
        </if>
        <if test="type!=null and type==127">,
            b.code as code
        </if>
        <if test="type!=null and type==128">,
            b.code as code
        </if>
        <if test="type!=null and type==106">,
            b.operation_code as code
        </if>
        FROM
        kl_library_info a
        LEFT JOIN kl_concept c
        ON a.concept_id = c.id
        <if test="type!=null and type==100">
            left join kl_disease b
            on b.is_deleted = 'N'
            and a.concept_id = b.concept_id
        </if>
        <if test="type!=null and type==127">
            left join kl_tcm_disease b
            on b.is_deleted = 'N'
            and a.concept_id = b.concept_id
        </if>
        <if test="type!=null and type==128">
            left join kl_tcm_syndrome b
            on b.is_deleted = 'N'
            and a.concept_id = b.concept_id
        </if>
        <if test="type!=null and type==106">
            left join kl_operation b
            on b.is_deleted = 'N'
            and a.concept_id = b.concept_id
        </if>
        WHERE a.is_deleted = "N"
        AND c.status = 1
        <if test="type!=null">
            AND a.type_id = #{type}
        </if>
        <if test="placeToList != null and placeToList.size > 0">
            and a.name in
            <foreach item="name" collection="placeToList" open="(" separator="," close=")">
                #{name}
            </foreach>
        </if>
        ) t
    </select>

</mapper>
