KlRuleMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.diagbot.mapper.KlRuleMapper">
  5. <!-- 通用查询映射结果 -->
  6. <resultMap id="BaseResultMap" type="com.diagbot.entity.KlRule">
  7. <id column="id" property="id"/>
  8. <result column="is_deleted" property="isDeleted"/>
  9. <result column="gmt_create" property="gmtCreate"/>
  10. <result column="gmt_modified" property="gmtModified"/>
  11. <result column="creator" property="creator"/>
  12. <result column="modifier" property="modifier"/>
  13. <result column="concept_id" property="conceptId"/>
  14. <result column="description" property="description"/>
  15. <result column="rule_type" property="ruleType"/>
  16. <result column="status" property="status"/>
  17. </resultMap>
  18. <resultMap id="SchemaResultMap" type="com.diagbot.dto.RuleDTO">
  19. <result column="libName" property="libName"/>
  20. <result column="libType" property="libType"/>
  21. <result column="ruleType" property="ruleType"/>
  22. <collection property="ruleConditionDTOList" ofType="com.diagbot.dto.RuleConditionDTO">
  23. <result column="hasSubCond" property="hasSubCond"/>
  24. <result column="ruleGroup" property="ruleGroup"/>
  25. <result column="msg" property="msg"/>
  26. <collection property="ruleBaseDTOList" ofType="com.diagbot.dto.RuleBaseDTO">
  27. <result column="baseLibName" property="baseLibName"/>
  28. <result column="baseLibType" property="baseLibType"/>
  29. <result column="baseType" property="baseType"/>
  30. <result column="baseMinOperator" property="baseMinOperator"/>
  31. <result column="baseMinValue" property="baseMinValue"/>
  32. <result column="baseMinUnit" property="baseMinUnit"/>
  33. <result column="baseMaxOperator" property="baseMaxOperator"/>
  34. <result column="baseMaxValue" property="baseMaxValue"/>
  35. <result column="baseMaxUnit" property="baseMaxUnit"/>
  36. <result column="baseEqOperator" property="baseEqOperator"/>
  37. <result column="baseEqValue" property="baseEqValue"/>
  38. <result column="baseEqUnit" property="baseEqUnit"/>
  39. </collection>
  40. </collection>
  41. </resultMap>
  42. <select id="getAllRule" resultMap="SchemaResultMap">
  43. SELECT
  44. t10.*
  45. FROM
  46. (
  47. SELECT
  48. t4.lib_name AS libName,
  49. t4.lib_type AS libType,
  50. t1.rule_type AS ruleType,
  51. t1.msg AS msg,
  52. t1.has_sub_cond AS hasSubCond,
  53. CONCAT_WS("-", t1.id, 1) AS ruleGroup,
  54. "" AS baseLibName,
  55. 0 AS baseLibType,
  56. 0 AS baseType,
  57. "" AS baseMinOperator,
  58. "" AS baseMinValue,
  59. "" AS baseMinUnit,
  60. "" AS baseMaxOperator,
  61. "" AS baseMaxValue,
  62. "" AS baseMaxUnit,
  63. "" AS baseEqOperator,
  64. "" AS baseEqValue,
  65. "" AS baseEqUnit
  66. FROM
  67. kl_rule t1,
  68. kl_concept t4
  69. WHERE
  70. t1.is_deleted = "N"
  71. AND t4.is_deleted = "N"
  72. AND t1.concept_id = t4.id
  73. AND t1. STATUS = 1
  74. AND t4. STATUS = 1
  75. AND t1.has_sub_cond = 0
  76. UNION ALL
  77. SELECT
  78. t4.lib_name AS libName,
  79. t4.lib_type AS libType,
  80. t1.rule_type AS ruleType,
  81. t1.msg AS msg,
  82. t1.has_sub_cond AS hasSubCond,
  83. CONCAT_WS("-", t1.id, t2.group_type) AS ruleGroup,
  84. t5.lib_name AS baseLibName,
  85. t5.lib_type AS baseLibType,
  86. t3.type AS baseType,
  87. t3.min_operator AS baseMinOperator,
  88. t3.min_value AS baseMinValue,
  89. t3.min_unit AS baseMinUnit,
  90. t3.max_operator AS baseMaxOperator,
  91. t3.max_value AS baseMaxValue,
  92. t3.max_unit AS baseMaxUnit,
  93. t3.eq_operator AS baseEqOperator,
  94. t3.eq_value AS baseEqValue,
  95. t3.eq_unit AS baseEqUnit
  96. FROM
  97. kl_rule t1,
  98. kl_rule_condition t2,
  99. kl_rule_base t3,
  100. kl_concept t4,
  101. kl_concept t5
  102. WHERE
  103. t1.is_deleted = "N"
  104. AND t2.is_deleted = "N"
  105. AND t3.is_deleted = "N"
  106. AND t4.is_deleted = "N"
  107. AND t5.is_deleted = "N"
  108. AND t1. STATUS = 1
  109. AND t3. STATUS = 1
  110. AND t4. STATUS = 1
  111. AND t5. STATUS = 1
  112. AND t1.id = t2.rule_id
  113. AND t2.rule_base_id = t3.id
  114. AND t1.concept_id = t4.id
  115. AND t3.concept_id = t5.id
  116. AND t1.has_sub_cond = 1
  117. ) t10
  118. ORDER BY
  119. t10.libType,
  120. t10.libName,
  121. t10.ruleType,
  122. t10.ruleGroup
  123. </select>
  124. <select id="getKlRuleInfoPage" resultType="com.diagbot.dto.KlRuleInfoDTO">
  125. SELECT
  126. ru.id as parId,
  127. ru.description as parDescription,
  128. ru.rule_type as parRuleType,
  129. ru.concept_id as parConceptId,
  130. co.lib_name as parConceptName,
  131. le.name as parLibTypeName,
  132. ru.has_sub_cond as parHasSub,
  133. ru.msg as parMsg,
  134. ru.status as parStatus,
  135. ru.gmt_modified as gmtModified,
  136. ru.modifier as modifier
  137. FROM
  138. kl_rule ru,
  139. kl_concept co,
  140. kl_lexicon le
  141. WHERE ru.is_deleted = 'N'
  142. AND co.is_deleted = 'N'
  143. AND le.is_deleted = 'N'
  144. AND ru.concept_id = co.`id`
  145. AND co.lib_type = le.`code`
  146. <if test="parDescription!=null and parDescription!=''">
  147. AND UPPER(ru.description) LIKE CONCAT('%', UPPER(trim(#{parDescription})), '%')
  148. </if>
  149. <if test="parRuleType !=null">
  150. AND ru.rule_type = #{parRuleType}
  151. </if>
  152. <if test="parConceptName!=null and parConceptName!=''">
  153. AND UPPER(co.lib_name) LIKE CONCAT('%', UPPER(trim(#{parConceptName})), '%')
  154. </if>
  155. <if test="parStatus!=null">
  156. AND ru.status = #{parStatus}
  157. </if>
  158. ORDER BY ru.status DESC ,ru.gmt_modified DESC,ru.id DESC
  159. </select>
  160. <select id="getByIdRuleInfo" resultType="com.diagbot.dto.KlRuleByIdDTO">
  161. SELECT
  162. par.*,
  163. CASE
  164. WHEN ISNULL(ruco.rule_id)
  165. THEN par.parId
  166. ELSE ruco.rule_id
  167. END AS ruleId,
  168. sub.*,
  169. ruco.msg AS subMsg,
  170. ruco.group_type AS groupType
  171. FROM
  172. (SELECT
  173. a.id AS parId,
  174. a.description AS parDescription,
  175. a.rule_type AS parRuleType,
  176. a.concept_id AS parconceptId,
  177. b.lib_name AS parlibName,
  178. a.has_sub_cond AS parHasSub,
  179. a.msg AS parMsg,
  180. a.status AS parStatus,
  181. c.name AS parLenName,
  182. c.code AS parLenCode
  183. FROM
  184. kl_rule a,
  185. kl_concept b,
  186. kl_lexicon c
  187. WHERE a.is_deleted = 'N'
  188. AND b.is_deleted = 'N'
  189. AND c.is_deleted = 'N'
  190. AND a.concept_id = b.id
  191. <if test="id != null">
  192. and a.id = #{id}
  193. </if>
  194. AND b.lib_type = c.code) par
  195. LEFT JOIN kl_rule_condition ruco
  196. ON par.parId = ruco.rule_id
  197. LEFT JOIN
  198. (SELECT
  199. c.id AS subId,
  200. c.description AS subDescription,
  201. c.concept_id AS subConceptId,
  202. d.lib_name AS subLibName,
  203. f.name AS subLenName,
  204. f.code AS subLenCode,
  205. c.type AS subType,
  206. c.min_operator AS subMinOperator,
  207. c.min_value AS subMinValue,
  208. c.min_unit AS subMinUnit,
  209. c.max_operator AS subMaxOperator,
  210. c.max_value AS subMaxValue,
  211. c.max_unit AS subMaxUnit,
  212. c.eq_operator AS subEqOperator,
  213. c.eq_value AS subEqValue,
  214. c.eq_unit AS subEqUnit
  215. FROM
  216. kl_rule_base c,
  217. kl_concept d,
  218. kl_lexicon f
  219. WHERE c.is_deleted = 'N'
  220. AND d.is_deleted = 'N'
  221. AND f.is_deleted = 'N'
  222. AND c.concept_id = d.id
  223. AND d.lib_type = f.code) sub
  224. ON sub.subId = ruco.rule_base_id
  225. </select>
  226. <select id="exportIndication" resultType="com.diagbot.dto.IndicationExportDTO">
  227. SELECT
  228. tt1.par_name,
  229. tt1.par_type,
  230. tt2.lib_name base_name,
  231. xx2.NAME base_type,
  232. CASE
  233. when tt1.type = '1' then '等于术语'
  234. when tt1.type = '2' then '比较'
  235. when tt1.type = '3' then '不等于术语'
  236. when tt1.type = '4' then '过敏'
  237. when tt1.type = '5' then '开单项互斥'
  238. when tt1.type = '6' then '正则'
  239. else '错误类型'
  240. end taboo_type,
  241. tt1.eq_value,
  242. tt1.min_value,
  243. tt1.min_operator,
  244. tt1.min_unit,
  245. tt1.max_value,
  246. tt1.max_operator,
  247. tt1.max_unit,
  248. tt1.description,
  249. tt1.msg,
  250. tt1.rule_id,
  251. tt1.cond_id
  252. FROM
  253. (
  254. SELECT
  255. c1.lib_name par_name,
  256. c1.id par_id,
  257. x1.`name` par_type,
  258. t1.id rule_id,
  259. t1.description,
  260. t1.rule_type,
  261. t1.has_sub_cond,
  262. t2.id cond_id,
  263. t2.msg,
  264. t3.type,
  265. t3.concept_id base_id,
  266. t3.eq_value,
  267. t3.min_value,
  268. t3.min_operator,
  269. t3.min_unit,
  270. t3.max_value,
  271. t3.max_operator,
  272. t3.max_unit
  273. FROM
  274. kl_concept c1,
  275. kl_lexicon x1,
  276. kl_rule t1,
  277. kl_rule_condition t2,
  278. kl_rule_base t3
  279. WHERE
  280. c1.is_deleted = 'N'
  281. AND t1.is_deleted = 'N'
  282. AND t2.is_deleted = 'N'
  283. AND t3.is_deleted = 'N'
  284. AND c1.`status` = 1
  285. AND t1.`status` = 1
  286. AND c1.id = t1.concept_id
  287. AND t1.id = t2.rule_id
  288. AND t2.rule_base_id = t3.id
  289. AND t1.rule_type = 1
  290. AND x1.`code` = c1.lib_type
  291. ) tt1
  292. LEFT JOIN kl_concept tt2 ON tt2.is_deleted = 'N'
  293. AND tt2.`status` = 1
  294. AND tt1.base_id = tt2.id
  295. LEFT JOIN kl_lexicon xx2 ON tt2.lib_type = xx2.CODE
  296. ORDER BY par_name, rule_id
  297. </select>
  298. <select id="getRuleInitDTO" resultType="com.diagbot.dto.RuleInitDTO">
  299. SELECT
  300. *
  301. FROM
  302. (
  303. SELECT
  304. t1.concept_id AS conceptId,
  305. CONCAT_WS(
  306. "_",
  307. t1.concept_id,
  308. t1.rule_type
  309. ) AS conceptGroup,
  310. t1.id AS ruleId,
  311. t4.lib_name AS libName,
  312. t4.lib_type AS libType,
  313. t1.rule_type AS ruleType,
  314. t1.has_sub_cond AS hasSubCond,
  315. t1.msg AS msg,
  316. t1.gmt_modified AS gmtModified
  317. FROM
  318. kl_rule t1,
  319. kl_concept t4
  320. WHERE
  321. t1.is_deleted = "N"
  322. AND t4.is_deleted = "N"
  323. AND t1.concept_id = t4.id
  324. AND t1. STATUS = 1
  325. AND t4. STATUS = 1
  326. AND t4.lib_type BETWEEN 100 AND 299
  327. UNION
  328. SELECT
  329. t11.id AS conceptId,
  330. CONCAT_WS("_", t11.id, t1.rule_type) AS conceptGroup,
  331. t1.id AS ruleId,
  332. t11.lib_name AS libName,
  333. t11.lib_type AS libType,
  334. t1.rule_type AS ruleType,
  335. t1.has_sub_cond AS hasSubCond,
  336. t1.msg AS msg,
  337. t1.gmt_modified AS gmtModified
  338. FROM
  339. kl_rule t1,
  340. kl_concept t4,
  341. kl_relation t10,
  342. kl_concept t11
  343. WHERE
  344. t1.is_deleted = "N"
  345. AND t4.is_deleted = "N"
  346. AND t1.concept_id = t4.id
  347. AND t1. STATUS = 1
  348. AND t4. STATUS = 1
  349. AND t4.lib_type BETWEEN 300 AND 399
  350. AND t10.start_id = t4.id
  351. AND t10.relation_id = 600
  352. AND t10.end_id = t11.id
  353. AND t11.lib_type BETWEEN 100 AND 299
  354. AND t10.is_deleted = "N"
  355. AND t11.is_deleted = "N"
  356. AND t10. STATUS = 1
  357. AND t11. STATUS = 1
  358. ) t12
  359. ORDER BY
  360. t12.conceptId,
  361. t12.ruleType,
  362. t12.hasSubCond,
  363. t12.gmtModified DESC,
  364. t12.ruleId DESC
  365. </select>
  366. <select id="getRuleConditionInitDTO" resultType="com.diagbot.dto.RuleConditionInitDTO">
  367. SELECT
  368. t2.rule_id AS ruleId,
  369. CONCAT_WS("-", t2.rule_id, t2.group_type) AS ruleGroup,
  370. t2.rule_base_id as ruleBaseId,
  371. t2.msg as msg
  372. FROM
  373. kl_rule_condition t2
  374. WHERE
  375. t2.is_deleted = "N"
  376. ORDER BY
  377. t2.id DESC
  378. </select>
  379. <select id="getRuleBaseInitDTO" resultType="com.diagbot.dto.RuleBaseInitDTO">
  380. SELECT
  381. t3.id as ruleBaseId,
  382. t5.lib_name AS baseLibName,
  383. t5.lib_type AS baseLibType,
  384. t3.type AS baseType,
  385. t3.min_operator AS baseMinOperator,
  386. t3.min_value AS baseMinValue,
  387. t3.min_unit AS baseMinUnit,
  388. t3.max_operator AS baseMaxOperator,
  389. t3.max_value AS baseMaxValue,
  390. t3.max_unit AS baseMaxUnit,
  391. t3.eq_operator AS baseEqOperator,
  392. t3.eq_value AS baseEqValue,
  393. t3.eq_unit AS baseEqUnit
  394. FROM
  395. kl_rule_base t3,
  396. kl_concept t5
  397. WHERE
  398. t3.is_deleted = "N"
  399. AND t5.is_deleted = "N"
  400. AND t3. STATUS = 1
  401. AND t5. STATUS = 1
  402. AND t3.concept_id = t5.id
  403. </select>
  404. <select id="getRuleInitDTONotHaveClass" resultType="com.diagbot.dto.RuleInitDTO">
  405. SELECT
  406. CONCAT_WS("_",t1.concept_id,t1.rule_type) AS conceptGroup,
  407. t1.id AS ruleId,
  408. t4.lib_name AS libName,
  409. t4.lib_type AS libType,
  410. t1.rule_type AS ruleType,
  411. t1.msg AS msg,
  412. t1.has_sub_cond AS hasSubCond
  413. FROM
  414. kl_rule t1,
  415. kl_concept t4
  416. WHERE
  417. t1.is_deleted = "N"
  418. AND t4.is_deleted = "N"
  419. AND t1.concept_id = t4.id
  420. AND t1. STATUS = 1
  421. AND t4. STATUS = 1
  422. AND t4.lib_type BETWEEN 100 AND 299
  423. </select>
  424. <select id="getRuleInitDTOHaveClass" resultType="com.diagbot.dto.RuleInitDTO">
  425. SELECT
  426. CONCAT_WS("_", t11.id, t1.rule_type) AS conceptGroup,
  427. t1.id AS ruleId,
  428. t11.lib_name AS libName,
  429. t11.lib_type AS libType,
  430. t1.rule_type AS ruleType,
  431. t1.msg AS msg,
  432. t1.has_sub_cond AS hasSubCond
  433. FROM
  434. kl_rule t1,
  435. kl_concept t4,
  436. kl_relation t10,
  437. kl_concept t11
  438. WHERE
  439. t1.is_deleted = "N"
  440. AND t4.is_deleted = "N"
  441. AND t1.concept_id = t4.id
  442. AND t1. STATUS = 1
  443. AND t4. STATUS = 1
  444. AND t4.lib_type BETWEEN 300 AND 399
  445. AND t10.start_id = t4.id
  446. AND t10.relation_id = 600
  447. AND t10.end_id = t11.id
  448. AND t11.lib_type BETWEEN 100 AND 299
  449. AND t10.is_deleted = "N"
  450. AND t11.is_deleted = "N"
  451. AND t10. STATUS = 1
  452. AND t11. STATUS = 1
  453. </select>
  454. <select id="getRuleBaseInitDTONotHaveClass" resultType="com.diagbot.dto.RuleBaseInitDTO">
  455. SELECT
  456. t3.id AS ruleBaseId,
  457. t5.lib_name AS baseLibName,
  458. t5.lib_type AS baseLibType,
  459. t3.type AS baseType,
  460. t3.min_operator AS baseMinOperator,
  461. t3.min_value AS baseMinValue,
  462. t3.min_unit AS baseMinUnit,
  463. t3.max_operator AS baseMaxOperator,
  464. t3.max_value AS baseMaxValue,
  465. t3.max_unit AS baseMaxUnit,
  466. t3.eq_operator AS baseEqOperator,
  467. t3.eq_value AS baseEqValue,
  468. t3.eq_unit AS baseEqUnit
  469. FROM
  470. kl_rule_base t3,
  471. kl_concept t5
  472. WHERE
  473. t3.is_deleted = "N"
  474. AND t5.is_deleted = "N"
  475. AND t3. STATUS = 1
  476. AND t5. STATUS = 1
  477. AND t3.concept_id = t5.id
  478. AND (t5.lib_type BETWEEN 100 AND 299
  479. OR t5.lib_type= 410)
  480. ORDER BY t5.id
  481. </select>
  482. <select id="getRuleBaseInitDTOHaveClass" resultType="com.diagbot.dto.RuleBaseInitDTO">
  483. SELECT
  484. t3.id AS ruleBaseId,
  485. t11.lib_name AS baseLibName,
  486. t11.lib_type AS baseLibType,
  487. t3.type AS baseType,
  488. t3.min_operator AS baseMinOperator,
  489. t3.min_value AS baseMinValue,
  490. t3.min_unit AS baseMinUnit,
  491. t3.max_operator AS baseMaxOperator,
  492. t3.max_value AS baseMaxValue,
  493. t3.max_unit AS baseMaxUnit,
  494. t3.eq_operator AS baseEqOperator,
  495. t3.eq_value AS baseEqValue,
  496. t3.eq_unit AS baseEqUnit
  497. FROM
  498. kl_rule_base t3,
  499. kl_concept t5,
  500. kl_relation t10,
  501. kl_concept t11
  502. WHERE
  503. t3.is_deleted = "N"
  504. AND t5.is_deleted = "N"
  505. AND t3. STATUS = 1
  506. AND t5. STATUS = 1
  507. AND t3.concept_id = t5.id
  508. AND t5.lib_type BETWEEN 300 AND 399
  509. AND t10.start_id = t5.id
  510. AND t10.relation_id = 600
  511. AND t10.end_id = t11.id
  512. AND (t11.lib_type BETWEEN 100 AND 299
  513. OR t11.lib_type = 410)
  514. AND t10.is_deleted = "N"
  515. AND t11.is_deleted = "N"
  516. AND t10. STATUS = 1
  517. AND t11. STATUS = 1
  518. ORDER BY t11.id
  519. </select>
  520. </mapper>