浏览代码

编码检索诊断

zhaops 3 年之前
父节点
当前提交
f788baf6cc
共有 1 个文件被更改,包括 38 次插入69 次删除
  1. 38 69
      src/main/resources/mapper/KlConceptMapper.xml

+ 38 - 69
src/main/resources/mapper/KlConceptMapper.xml

@@ -1224,77 +1224,55 @@
     <!--ICD编码查询-->
     <select id="diseaseIndex" resultType="com.diagbot.dto.DiseaseIndexDTO">
         SELECT
-        t.id,
-        <if test="diseaseIndexPageVO.type != null">
+        k.id,
+        k.name,
+        k.code,
+        k.spell,
+        k.pos,
+        least( k.nameLen, k.spellLen, k.codeLen ) AS len
+        FROM
+        (
+        SELECT
+        t.*,
+        LEAST( t.namePos, t.spellPos, t.codePos ) AS pos,
+        IF( LEAST( t.namePos, t.spellPos, t.codePos )= namePos, CHAR_LENGTH( t.name ), 999 ) AS nameLen,
+        IF( LEAST( t.namePos, t.spellPos, t.codePos )= spellPos, CHAR_LENGTH( t.spell ), 999 ) AS spellLen,
+        IF( LEAST( t.namePos, t.spellPos, t.codePos )= codePos, CHAR_LENGTH( t.code ), 999 ) AS codeLen
+        FROM
+        (
+        SELECT
+        <if test="diseaseIndexPageVO.inputStr != null and diseaseIndexPageVO.inputStr != '' and diseaseIndexPageVO.type != null">
             <choose>
                 <when test="diseaseIndexPageVO.type == 1">
-                    t.lib_name AS NAME,
-                    t.icd10_code AS CODE,
-                    t.spell AS spell,
+                    IF( POSITION( #{diseaseIndexPageVO.inputStr} IN a.lib_name )> 0, POSITION( #{diseaseIndexPageVO.inputStr} IN a.lib_name ), 999 ) AS namePos,
+                    IF( POSITION( #{diseaseIndexPageVO.inputStr} IN b.spell )> 0, POSITION( #{diseaseIndexPageVO.inputStr} IN b.spell ), 999 ) AS spellPos,
+                    IF( POSITION( #{diseaseIndexPageVO.inputStr} IN c.icd10_code )> 0, POSITION( #{diseaseIndexPageVO.inputStr} IN c.icd10_code ), 999 ) AS codePos,
                 </when>
                 <when test="diseaseIndexPageVO.type == 2">
-                    t.guoname AS NAME,
-                    t.guocode AS CODE,
-                    t.guospell AS spell,
+                    IF( POSITION( #{diseaseIndexPageVO.inputStr} IN c.guoname )> 0, POSITION( #{diseaseIndexPageVO.inputStr} IN c.guoname ), 999 ) AS namePos,
+                    IF( POSITION( #{diseaseIndexPageVO.inputStr} IN c.guospell )> 0, POSITION( #{diseaseIndexPageVO.inputStr} IN c.guospell ), 999 ) AS spellPos,
+                    IF( POSITION( #{diseaseIndexPageVO.inputStr} IN c.guocode )> 0, POSITION( #{diseaseIndexPageVO.inputStr} IN c.guocode ), 999 ) AS codePos,
                 </when>
-                <otherwise>
-                </otherwise>
+                <otherwise></otherwise>
             </choose>
         </if>
-        t.pos,
-        t.len
-        FROM
-        (
-        SELECT
-        a.id,
-        a.lib_name,
-        b.spell,
-        c.icd10_code,
-        <if test="diseaseIndexPageVO.inputStr != null and diseaseIndexPageVO.inputStr != '' and diseaseIndexPageVO.type != null">
+        <if test="diseaseIndexPageVO.type != null">
             <choose>
                 <when test="diseaseIndexPageVO.type == 1">
-                    CASE
-                    WHEN POSITION( #{diseaseIndexPageVO.inputStr} IN a.lib_name )> 0 THEN
-                    POSITION( #{diseaseIndexPageVO.inputStr} IN a.lib_name )
-                    WHEN POSITION( #{diseaseIndexPageVO.inputStr} IN b.spell )> 0 THEN
-                    POSITION( #{diseaseIndexPageVO.inputStr} IN b.spell )
-                    WHEN POSITION( #{diseaseIndexPageVO.inputStr} IN c.icd10_code )> 0 THEN
-                    POSITION( #{diseaseIndexPageVO.inputStr} IN c.icd10_code )
-                    END AS pos,
-                    CASE
-                    WHEN POSITION( #{diseaseIndexPageVO.inputStr} IN a.lib_name )> 0 THEN
-                    LENGTH( a.lib_name )
-                    WHEN POSITION( #{diseaseIndexPageVO.inputStr} IN b.spell )> 0 THEN
-                    LENGTH( b.spell )
-                    WHEN POSITION( #{diseaseIndexPageVO.inputStr} IN c.icd10_code )> 0 THEN
-                    LENGTH( c.icd10_code )
-                    END AS len,
+                    a.lib_name AS NAME,
+                    c.icd10_code AS CODE,
+                    b.spell AS spell,
                 </when>
-                <when test="diseaseIndexPageVO.type == 1">
-                    CASE
-                    WHEN POSITION( #{diseaseIndexPageVO.inputStr} IN c.guoname )> 0 THEN
-                    POSITION( #{diseaseIndexPageVO.inputStr} IN c.guoname )
-                    WHEN POSITION( #{diseaseIndexPageVO.inputStr} IN c.guospell )> 0 THEN
-                    POSITION( #{diseaseIndexPageVO.inputStr} IN c.guospell )
-                    WHEN POSITION( #{diseaseIndexPageVO.inputStr} IN c.guocode )> 0 THEN
-                    POSITION( #{diseaseIndexPageVO.inputStr} IN c.guocode )
-                    END AS pos,
-                    CASE
-                    WHEN POSITION( #{diseaseIndexPageVO.inputStr} IN c.guoname )> 0 THEN
-                    LENGTH( c.guoname )
-                    WHEN POSITION( #{diseaseIndexPageVO.inputStr} IN c.guospell )> 0 THEN
-                    LENGTH( c.guospell )
-                    WHEN POSITION( #{diseaseIndexPageVO.inputStr} IN c.guocode )> 0 THEN
-                    LENGTH( c.guocode )
-                    END AS len,
+                <when test="diseaseIndexPageVO.type == 2">
+                    c.guoname AS NAME,
+                    c.guocode AS CODE,
+                    c.guospell AS spell,
                 </when>
-                <otherwise> 0 as pos,0 as len,
+                <otherwise>
                 </otherwise>
             </choose>
         </if>
-        c.guoname,
-        c.guocode,
-        c.guospell
+        a.id
         FROM
         kl_concept a,
         kl_library_info b,
@@ -1316,29 +1294,20 @@
                     AND ( a.lib_name LIKE  CONCAT( '%', #{diseaseIndexPageVO.inputStr}, '%' )
                     OR b.spell LIKE  CONCAT( '%', #{diseaseIndexPageVO.inputStr}, '%' )
                     OR c.icd10_code LIKE  CONCAT( '%', #{diseaseIndexPageVO.inputStr}, '%' ) )
-                    AND (
-                    a.lib_name NOT LIKE CONCAT(  #{diseaseIndexPageVO.inputStr}, '%' )
-                    AND b.spell NOT LIKE CONCAT(  #{diseaseIndexPageVO.inputStr}, '%' )
-                    AND c.icd10_code NOT LIKE CONCAT(  #{diseaseIndexPageVO.inputStr}, '%' )
-                    )
                 </when>
                 <when test="diseaseIndexPageVO.type == 2">
                     AND c.guocode != ''
                     AND ( c.guoname LIKE  CONCAT( '%', #{diseaseIndexPageVO.inputStr}, '%' )
                     OR c.guospell LIKE CONCAT( '%', #{diseaseIndexPageVO.inputStr}, '%' )
                     OR c.guocode LIKE  CONCAT( '%', #{diseaseIndexPageVO.inputStr}, '%' ) )
-                    AND (
-                    c.guoname NOT LIKE CONCAT(  #{diseaseIndexPageVO.inputStr}, '%' )
-                    AND c.guospell NOT LIKE CONCAT(  #{diseaseIndexPageVO.inputStr}, '%' )
-                    AND c.guocode NOT LIKE CONCAT(  #{diseaseIndexPageVO.inputStr}, '%' )
-                    )
                 </when>
                 <otherwise></otherwise>
             </choose>
         </if>
         ) t
+        ) k
         ORDER BY
-        t.pos,
-        t.len
+        k.pos,
+        len
     </select>
 </mapper>