MedCheckInfoMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.diagbot.mapper.MedCheckInfoMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.diagbot.entity.MedCheckInfo">
  6. <id column="id" property="id" />
  7. <result column="is_deleted" property="isDeleted" />
  8. <result column="gmt_create" property="gmtCreate" />
  9. <result column="gmt_modified" property="gmtModified" />
  10. <result column="creator" property="creator" />
  11. <result column="modifier" property="modifier" />
  12. <result column="behospital_code" property="behospitalCode" />
  13. <result column="hospital_id" property="hospitalId" />
  14. <result column="check_id" property="checkId" />
  15. <result column="check_name" property="checkName" />
  16. <result column="check_time" property="checkTime" />
  17. <result column="status" property="status" />
  18. <result column="check_type" property="checkType" />
  19. <result column="job_creator" property="jobCreator" />
  20. <result column="job_creator_name" property="jobCreatorName" />
  21. <result column="job_create_time" property="jobCreateTime" />
  22. <result column="job_type" property="jobType" />
  23. <result column="job_distributor" property="jobDistributor" />
  24. <result column="job_distribution_name" property="jobDistributionName" />
  25. <result column="job_distribution_time" property="jobDistributionTime" />
  26. </resultMap>
  27. <!--获取核查人员用户科室、姓名、角色-->
  28. <select id="getCheckUser" resultType="com.diagbot.dto.CheckUserDTO">
  29. SELECT DISTINCT
  30. a.id doctorId,
  31. a.linkman doctorName,
  32. c.dept_id deptId,
  33. d.dept_name deptName
  34. from
  35. sys_user a,sys_user_role b,sys_user_dept c ,bas_dept_info d
  36. where a.id = b.user_id and a.is_deleted = "N" and b.is_deleted = "N" and c.is_deleted = "N" and a.id = c.user_id
  37. and d.dept_id = c.dept_id and c.hospital_id = d.hospital_id
  38. and c.hospital_id = #{hospitalId}
  39. <if test="roleIds !=null and roleIds.size()!=0 ">
  40. and b.role_id in
  41. <foreach collection="roleIds" item="item" open="(" close=")" separator=",">
  42. #{item}
  43. </foreach>
  44. </if>
  45. <if test="deptIds !=null and deptIds.size()!=0">
  46. and c.dept_id in
  47. <foreach collection="deptIds" item="item" open="(" close=")" separator=",">
  48. #{item}
  49. </foreach>
  50. </if>
  51. <if test="deptStations !=null and deptStations.size()!=0">
  52. and d.station in
  53. <foreach collection="deptStations" item="item" open="(" close=")" separator=",">
  54. #{item}
  55. </foreach>
  56. </if>
  57. order by c.dept_id
  58. </select>
  59. <!--核查人员通过id获取核查人员的核查任务数-->
  60. <select id="getDeptJobNumByUserId" resultType="com.diagbot.dto.DeptCheckUserDTO">
  61. SELECT
  62. a.beh_dept_id deptId ,
  63. b.check_id doctorId,
  64. count(*) as jobNum,
  65. b.`status`
  66. from
  67. med_behospital_info a LEFT JOIN med_check_info b on a.behospital_code = b.behospital_code and a.hospital_id = b.hospital_id
  68. where b.is_deleted = 'N' and a.is_deleted = 'N' and b.job_distribution_name is not null and b.`status` is not null
  69. <if test="jobType != null ">
  70. and b.job_type = #{jobType}
  71. </if>
  72. <if test="userList !=null and userList.size!=0">
  73. and b.check_id in
  74. <foreach collection="userList" item="item" open="(" close=")" separator=",">
  75. #{item}
  76. </foreach>
  77. </if>
  78. <if test="deptIds !=null and deptIds.size()!=0 and jobType ==0">
  79. and a.beh_dept_id in
  80. <foreach collection="deptIds" item="item" open="(" close=")" separator=",">
  81. #{item}
  82. </foreach>
  83. </if>
  84. <if test="deptIds !=null and deptIds.size()!=0 and jobType ==2">
  85. and a.beh_dept_id not in
  86. <foreach collection="deptIds" item="item" open="(" close=")" separator=",">
  87. #{item}
  88. </foreach>
  89. </if>
  90. <if test="jobType ==0">
  91. GROUP BY a.beh_dept_id,b.check_id,b.`status`
  92. </if>
  93. <if test="jobType ==1 or jobType ==2">
  94. GROUP BY b.check_id,b.`status`
  95. </if>
  96. </select>
  97. <!--获取待分配核查任务列表-->
  98. <select id="getCheckList" resultType="com.diagbot.dto.CheckJobDTO">
  99. SELECT
  100. a.behospital_code behospitalCode,
  101. a.beh_dept_name behospitalDept,
  102. a.doctor_name attendingDoctor,
  103. a.leave_hospital_date leaveHospitalDate,
  104. a.`name`,
  105. b.`value`,
  106. a.id,
  107. a.beh_dept_id behospitalDeptId,
  108. a.job_create_time jobCreateTime
  109. from
  110. (select
  111. a.behospital_code,
  112. a.`name`,
  113. a.beh_dept_name,
  114. a.doctor_name,
  115. a.leave_hospital_date,
  116. a.hospital_id,
  117. a.beh_dept_id,
  118. b.job_create_time,
  119. b.id
  120. from
  121. med_behospital_info a ,med_check_info b
  122. where a.behospital_code = b.behospital_code and a.hospital_id = b.hospital_id and a.is_deleted = 'N'
  123. and b.is_deleted = 'N' and b.job_distribution_name is NULL and b.`status` = 0
  124. <if test="jobType !=null and jobType != ''">
  125. and b.job_type = #{jobType}
  126. </if>
  127. <if test="startTime != null and startTime != ''">
  128. <![CDATA[ AND b.job_create_time >= #{startTime}]]>
  129. </if>
  130. <if test="endTime != null and endTime != ''">
  131. <![CDATA[ AND b.job_create_time <= #{endTime}]]>
  132. </if>
  133. <if test="behosDateStart != null and behosDateStart != ''">
  134. <![CDATA[ AND a.leave_hospital_date >= #{behosDateStart}]]>
  135. </if>
  136. <if test="behosDateEnd != null and behosDateEnd != ''">
  137. <![CDATA[ AND a.leave_hospital_date <= #{behosDateEnd}]]>
  138. </if>
  139. <if test="doctorName !=null and doctorName != ''">
  140. and a.doctor_name LIKE CONCAT('%',#{doctorName},'%')
  141. </if>
  142. <if test="behospitalCode !=null and behospitalCode != ''">
  143. and a.behospital_code LIKE CONCAT('%',#{behospitalCode},'%')
  144. </if>
  145. <if test="name !=null and name != ''">
  146. and a.`name` LIKE CONCAT('%',#{name},'%')
  147. </if>
  148. <if test="deptList !=null and deptList.size()!=0 ">
  149. and a.beh_dept_id in
  150. <foreach collection="deptList" item="item" open="(" close=")" separator=",">
  151. #{item}
  152. </foreach>
  153. </if>
  154. ) a JOIN med_behospital_type b on a.behospital_code = b.behospital_code
  155. and a.hospital_id = b.hospital_id and b.is_deleted = 'N' and b.`value` is not null
  156. <if test="values !=null and values.size()!=0 ">
  157. and b.`value` in
  158. <foreach collection="values" item="item" open="(" close=")" separator=",">
  159. #{item}
  160. </foreach>
  161. </if>
  162. </select>
  163. <!--获取指定核查人员的核查任务-->
  164. <select id="getCheckListByUserId" resultType="com.diagbot.dto.CheckJobDTO">
  165. SELECT
  166. a.behospital_code behospitalCode,
  167. a.beh_dept_name behospitalDept,
  168. a.doctor_name attendingDoctor,
  169. a.leave_hospital_date leaveHospitalDate,
  170. a.`name`,
  171. b.`value`,
  172. a.id,
  173. a.job_distributor jobDistributor,
  174. a.job_distribution_name jobDistributorName
  175. from
  176. (select
  177. a.behospital_code,
  178. a.`name`,
  179. a.beh_dept_name,
  180. a.doctor_name,
  181. a.leave_hospital_date,
  182. a.hospital_id,
  183. a.beh_dept_id,
  184. b.id,
  185. b.job_distributor,
  186. b.job_distribution_name
  187. from
  188. med_behospital_info a ,med_check_info b
  189. where a.behospital_code = b.behospital_code and a.hospital_id = b.hospital_id and a.is_deleted = 'N'
  190. and b.is_deleted = 'N' and b.`status` = 0
  191. <if test="jobType !=null and jobType != ''">
  192. and b.job_type = #{jobType}
  193. </if>
  194. <if test="startTime != null and startTime != ''">
  195. <![CDATA[ AND b.job_create_time >= #{startTime}]]>
  196. </if>
  197. <if test="endTime != null and endTime != ''">
  198. <![CDATA[ AND b.job_create_time <= #{endTime}]]>
  199. </if>
  200. <if test="behosDateStart != null and behosDateStart != ''">
  201. <![CDATA[ AND a.leave_hospital_date >= #{behosDateStart}]]>
  202. </if>
  203. <if test="behosDateEnd != null and behosDateEnd != ''">
  204. <![CDATA[ AND a.leave_hospital_date <= #{behosDateEnd}]]>
  205. </if>
  206. <if test="checkId !=null and checkId != ''">
  207. and b.check_id = #{checkId}
  208. </if>
  209. <if test="deptList !=null and deptList.size()!=0 and jobType==0">
  210. and a.beh_dept_id in
  211. <foreach collection="deptList" item="item" open="(" close=")" separator=",">
  212. #{item}
  213. </foreach>
  214. </if>
  215. <if test="deptList !=null and deptList.size()!=0 and jobType==2">
  216. and a.beh_dept_id not in
  217. <foreach collection="deptList" item="item" open="(" close=")" separator=",">
  218. #{item}
  219. </foreach>
  220. </if>
  221. ) a LEFT JOIN med_behospital_type b on a.behospital_code = b.behospital_code
  222. and a.hospital_id = b.hospital_id and b.is_deleted = 'N'
  223. </select>
  224. <select id="getCheckWorkPage" resultType="com.diagbot.dto.CheckWorkDTO">
  225. SELECT
  226. mbi.behospital_code behospitalCode,
  227. mbi.`name`,
  228. mbi.file_code fileCode,
  229. mbi.sex,
  230. mhp.age,
  231. mbi.beh_dept_name behDeptName,
  232. mbi.leave_hospital_date leaveHospitalDate,
  233. mhp.behospital_day_num+0 behospitalDayNum,
  234. mbi.doctor_name doctorName,
  235. mqi.score_res scoreRes,
  236. mqi.`level`,
  237. mbi.diagnose,
  238. CASE WHEN mbt.behospital_type='出院病人' THEN '6'
  239. WHEN mbt.behospital_type='死亡病人' THEN '6'
  240. WHEN mbt.behospital_type='危重病人' THEN '4'
  241. WHEN mbt.behospital_type='抢救病人' THEN '5'
  242. WHEN mbt.behospital_type='手术病人' THEN '2'
  243. WHEN mbt.behospital_type='疑难病人' THEN '3'
  244. WHEN mbt.behospital_type='输血病人' THEN '4' ELSE '0' END AS score,
  245. CASE WHEN ISNULL(mci.job_create_time) THEN '未生成' ELSE '已生成' END AS creatStatus,
  246. mci.job_create_time jobCreateTime,
  247. mci.job_creator jobCreator,
  248. mci.job_creator_name jobCreatorName,
  249. mci.check_time checkTime,
  250. mci.job_distribution_time jobDistributionTime
  251. FROM
  252. med_behospital_info mbi
  253. LEFT JOIN med_home_page mhp
  254. ON mbi.behospital_code=mhp.behospital_code
  255. AND mbi.hospital_id = mhp.hospital_id AND mhp.is_deleted = 'N'
  256. LEFT JOIN med_check_info mci
  257. ON mbi.behospital_code = mci.behospital_code
  258. AND mbi.hospital_id = mci.hospital_id AND mci.is_deleted = 'N'
  259. LEFT JOIN med_qcresult_info mqi
  260. ON mbi.behospital_code = mqi.behospital_code
  261. AND mbi.hospital_id = mqi.hospital_id AND mqi.is_deleted = 'N'
  262. JOIN med_behospital_type mbt ON mbi.behospital_code = mbt.behospital_code
  263. AND mbi.hospital_id = mbt.hospital_id AND mbt.is_deleted = 'N'
  264. WHERE mbi.hospital_id=#{hospitalId} AND mbi.is_deleted = 'N' and mqi.score_res is not null
  265. AND mci.check_id is null
  266. <if test="startDate != null">
  267. <![CDATA[ AND mbi.leave_hospital_date >= #{startDate}]]>
  268. </if>
  269. <if test="endDate != null">
  270. <![CDATA[ AND mbi.leave_hospital_date < #{endDate}]]>
  271. </if>
  272. <if test="creatStatus != null and creatStatus == '1'.toString()">
  273. AND mci.job_create_time is not null
  274. <if test="jobType != null and jobType != ''">
  275. AND mci.job_type=#{jobType}
  276. </if>
  277. </if>
  278. <if test="creatStatus != null and creatStatus == '0'.toString()">
  279. AND mci.job_create_time is null
  280. </if>
  281. <if test="name != null and name != ''">
  282. AND mbi.`name` like CONCAT('%',#{name},'%')
  283. </if>
  284. <if test="behospitalCode != null and behospitalCode != ''">
  285. AND mbi.behospital_code like CONCAT('%',#{behospitalCode},'%')
  286. </if>
  287. <if test="department !=null and department.size > 0">
  288. and mbi.beh_dept_id in
  289. <foreach collection="department" item="item" open="(" close=")" separator=",">
  290. #{item}
  291. </foreach>
  292. </if>
  293. <if test="smallDay != null">
  294. <![CDATA[ AND mhp.behospital_day_num >= #{smallDay}]]>
  295. </if>
  296. <if test="bigDay != null">
  297. <![CDATA[ AND mhp.behospital_day_num <= #{bigDay}]]>
  298. </if>
  299. <if test="doctorName != null and doctorName != ''">
  300. AND mbi.doctor_name LIKE CONCAT( '%', #{doctorName}, '%' )
  301. </if>
  302. <if test="diagnose != null and diagnose != ''">
  303. AND mbi.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
  304. </if>
  305. <if test="level != null and level != ''">
  306. AND mqi.`level`= #{level}
  307. </if>
  308. <if test="isPlacefile != null and isPlacefile != ''">
  309. AND mbi.is_placefile = #{isPlacefile}
  310. </if>
  311. <if test="values !=null and values.size > 0">
  312. and mbt.`value` in
  313. <foreach collection="values" item="item" open="(" close=")" separator=",">
  314. #{item}
  315. </foreach>
  316. </if>
  317. </select>
  318. <!--通过住院号,取消核查任务-->
  319. <update id="deleteBatchCodes">
  320. <foreach collection="list" item="item" separator=";">
  321. delete from
  322. med_check_info
  323. where behospital_code = #{item} and is_deleted = 'N'
  324. </foreach>
  325. </update>
  326. <select id="checkedRecordList" resultType="com.diagbot.dto.CheckedRecordListDTO">
  327. SELECT t1.*,SUM(if(t2.behospital_code is null,0,1)) as casesEntryNum
  328. from
  329. (select
  330. b.behospital_code as behospitalCode,
  331. a.`status` as status,
  332. b.beh_dept_id as behDeptId,
  333. b.beh_dept_name as behDeptName,
  334. b.`name` as name,
  335. b.file_code as fileCode,
  336. b.doctor_name as doctorName,
  337. b.leave_hospital_date as leaveHospitalDate,
  338. a.job_create_time as jobCreateTime,
  339. a.job_distribution_time as jobDistributionTime,
  340. a.check_id as checkId,
  341. a.check_name as checkName,
  342. a.check_time as checkTime,
  343. c.`level` as level,
  344. c.score_res as scoreRes,
  345. CASE WHEN a.job_type='0' THEN '科室任务'
  346. WHEN a.job_type='1' THEN '质控科任务'
  347. WHEN a.job_type='2' THEN '院级任务' END AS jobTypeName,
  348. <!-- 张三是A科室的监管员,李四是A科室和B科室的普通质控员,那么张三在核查任务列表中不能看到李四B科室的数据 -->
  349. case when a.job_type='0' and FIND_IN_SET(b.beh_dept_id,#{currentDeptIds})=0 then 0 else 1 end as isDel
  350. from med_check_info a join med_behospital_info b on a.hospital_id=b.hospital_id and
  351. a.behospital_code=b.behospital_code
  352. join med_qcresult_info c on b.hospital_id=c.hospital_id and b.behospital_code=c.behospital_code and
  353. b.is_deleted='N' and c.is_deleted = 'N'
  354. where a.hospital_id=#{hospitalId} and a.is_deleted='N'
  355. and b.hospital_id=#{hospitalId} and b.is_deleted='N'
  356. and c.hospital_id=#{hospitalId}
  357. and a.check_id in
  358. <foreach collection="currentGeneralUserIds" item="currentGeneralUserId" separator="," close=")" open="(">
  359. #{currentGeneralUserId}
  360. </foreach>
  361. <if test="status!=null">
  362. and a.`status`=#{status}
  363. </if>
  364. <if test="behDeptId!=null and behDeptId!=''">
  365. and b.beh_dept_id=#{behDeptId}
  366. </if>
  367. <if test="name!=null and name!=''">
  368. and b.`name` like concat('%',#{name},'%')
  369. </if>
  370. <if test="behospitalCode!=null and behospitalCode!=''">
  371. and b.behospital_code like concat('%',#{behospitalCode},'%')
  372. </if>
  373. <if test="doctorName!=null and doctorName!=''">
  374. and b.doctor_name like concat('%',#{doctorName},'%')
  375. </if>
  376. <if test="jobDistributionTimeStart!=null">
  377. and a.job_distribution_time >= #{jobDistributionTimeStart}
  378. </if>
  379. <if test="jobDistributionTimeEnd!=null">
  380. and #{jobDistributionTimeEnd} >= a.job_distribution_time
  381. </if>
  382. <if test="checkName!=null and checkName!=''">
  383. and a.check_name like concat('%',#{checkName},'%')
  384. </if>
  385. <if test="level!=null and level!=''">
  386. and c.`level`=#{level}
  387. </if>
  388. <if test="checkJobTypes!=null and checkJobTypes.size>0">
  389. and a.job_type in
  390. <foreach collection="checkJobTypes" item="checkJobType" separator="," close=")" open="(">
  391. #{checkJobType}
  392. </foreach>
  393. </if>
  394. ) t1 left join med_qcresult_detail t2 on t1.behospitalCode=t2.behospital_code and t2.hospital_id=#{hospitalId} and t2.is_deleted='N'
  395. where isDel>0
  396. group by t1.behospitalCode
  397. </select>
  398. </mapper>