MedCheckInfoMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. </select>
  58. <!--通过核查人员id获取核查人员的核查任务数-->
  59. <select id="getJobNumByUserId" resultType="com.diagbot.dto.DeptCheckUserDTO">
  60. SELECT
  61. a.beh_dept_id deptId ,
  62. b.check_id doctorId,
  63. count(*) as jobNum
  64. from
  65. med_behospital_info a LEFT JOIN med_check_info b on a.behospital_code = b.behospital_code and a.hospital_id = b.hospital_id
  66. where b.is_deleted = 'N' and b.job_distribution_name is not null
  67. <if test="jobType != null ">
  68. and b.job_type = #{jobType}
  69. </if>
  70. <if test="userList !=null and userList.size!=0">
  71. and b.check_id in
  72. <foreach collection="userList" item="item" open="(" close=")" separator=",">
  73. #{item}
  74. </foreach>
  75. </if>
  76. <if test="deptIds !=null and deptIds.size()!=0">
  77. and a.beh_dept_id in
  78. <foreach collection="deptIds" item="item" open="(" close=")" separator=",">
  79. #{item}
  80. </foreach>
  81. </if>
  82. GROUP BY a.beh_dept_id
  83. </select>
  84. <!--获取待分配核查任务列表-->
  85. <select id="getCheckList" resultType="com.diagbot.dto.CheckJobDTO">
  86. SELECT
  87. a.behospital_code behospitalCode,
  88. a.beh_dept_name behospitalDept,
  89. a.doctor_name attendingDoctor,
  90. a.leave_hospital_date leaveHospitalDate,
  91. a.`name`,
  92. b.`value`,
  93. a.id
  94. from
  95. (select
  96. a.behospital_code,
  97. a.`name`,
  98. a.beh_dept_name,
  99. a.doctor_name,
  100. a.leave_hospital_date,
  101. a.hospital_id,
  102. a.beh_dept_id,
  103. b.id
  104. from
  105. med_behospital_info a ,med_check_info b
  106. where a.behospital_code = b.behospital_code and a.hospital_id = b.hospital_id and a.is_deleted = 'N'
  107. and b.is_deleted = 'N' and b.job_distribution_name is NULL and b.`status` = 0
  108. <if test="jobType !=null and jobType != ''">
  109. and b.job_type = #{jobType}
  110. </if>
  111. <if test="startTime != null and startTime != ''">
  112. <![CDATA[ AND b.job_create_time >= #{startTime}]]>
  113. </if>
  114. <if test="endTime != null and endTime != ''">
  115. <![CDATA[ AND b.job_create_time <= #{endTime}]]>
  116. </if>
  117. <if test="behosDateStart != null and behosDateStart != ''">
  118. <![CDATA[ AND a.leave_hospital_date >= #{behosDateStart}]]>
  119. </if>
  120. <if test="behosDateEnd != null and behosDateEnd != ''">
  121. <![CDATA[ AND a.leave_hospital_date <= #{behosDateEnd}]]>
  122. </if>
  123. <if test="doctorName !=null and doctorName != ''">
  124. and a.doctor_name LIKE CONCAT('%',#{doctorName},'%')
  125. </if>
  126. <if test="behospitalCode !=null and behospitalCode != ''">
  127. and a.behospital_code LIKE CONCAT('%',#{behospitalCode},'%')
  128. </if>
  129. <if test="name !=null and name != ''">
  130. and a.`name` LIKE CONCAT('%',#{name},'%')
  131. </if>
  132. <if test="deptList !=null and deptList.size()!=0">
  133. and a.beh_dept_id in
  134. <foreach collection="deptList" item="item" open="(" close=")" separator=",">
  135. #{item}
  136. </foreach>
  137. </if>
  138. ) a LEFT JOIN med_behospital_type b on a.behospital_code = b.behospital_code
  139. and a.hospital_id = b.hospital_id and b.is_deleted = 'N'
  140. </select>
  141. <!--获取指定核查人员的核查任务-->
  142. <select id="getCheckListByUserId" resultType="com.diagbot.dto.CheckJobDTO">
  143. SELECT
  144. a.behospital_code behospitalCode,
  145. a.beh_dept_name behospitalDept,
  146. a.doctor_name attendingDoctor,
  147. a.leave_hospital_date leaveHospitalDate,
  148. a.`name`,
  149. b.`value`,
  150. a.id,
  151. a.job_distributor jobDistributor
  152. from
  153. (select
  154. a.behospital_code,
  155. a.`name`,
  156. a.beh_dept_name,
  157. a.doctor_name,
  158. a.leave_hospital_date,
  159. a.hospital_id,
  160. a.beh_dept_id,
  161. b.id,
  162. b.job_distributor
  163. from
  164. med_behospital_info a ,med_check_info b
  165. where a.behospital_code = b.behospital_code and a.hospital_id = b.hospital_id and a.is_deleted = 'N'
  166. and b.is_deleted = 'N' and b.`status` = 0
  167. <if test="startTime != null and startTime != ''">
  168. <![CDATA[ AND b.job_create_time >= #{startTime}]]>
  169. </if>
  170. <if test="endTime != null and endTime != ''">
  171. <![CDATA[ AND b.job_create_time <= #{endTime}]]>
  172. </if>
  173. <if test="behosDateStart != null and behosDateStart != ''">
  174. <![CDATA[ AND a.leave_hospital_date >= #{behosDateStart}]]>
  175. </if>
  176. <if test="behosDateEnd != null and behosDateEnd != ''">
  177. <![CDATA[ AND a.leave_hospital_date <= #{behosDateEnd}]]>
  178. </if>
  179. <if test="checkId !=null and checkId != ''">
  180. and b.check_id = #{checkId}
  181. </if>
  182. <if test="deptList !=null and deptList.size()!=0">
  183. and a.beh_dept_id in
  184. <foreach collection="deptList" item="item" open="(" close=")" separator=",">
  185. #{item}
  186. </foreach>
  187. </if>
  188. ) a LEFT JOIN med_behospital_type b on a.behospital_code = b.behospital_code
  189. and a.hospital_id = b.hospital_id and b.is_deleted = 'N'
  190. </select>
  191. <select id="getCheckWorkPage" resultType="com.diagbot.dto.CheckWorkDTO">
  192. SELECT
  193. mbi.behospital_code behospitalCode,
  194. mbi.name,
  195. mbi.file_code fileCode,
  196. mbi.sex,
  197. mhp.age,
  198. TIMESTAMPDIFF(year,ifnull(mhp.birthday,mbi.birthday),mbi.behospital_date) as ageYear,
  199. TIMESTAMPDIFF(month,DATE_ADD(ifnull(mhp.birthday,mbi.birthday),INTERVAL TIMESTAMPDIFF(year,ifnull(mhp.birthday,mbi.birthday),mbi.behospital_date) year),mbi.behospital_date) as ageMon,
  200. TIMESTAMPDIFF(day,DATE_ADD(ifnull(mhp.birthday,mbi.birthday),INTERVAL TIMESTAMPDIFF(month,ifnull(mhp.birthday,mbi.birthday),mbi.behospital_date) month),mbi.behospital_date) as ageDay,
  201. mbi.beh_dept_name behDeptName,
  202. mbi.leave_hospital_date leaveHospitalDate,
  203. mhp.behospital_day_num behospitalDayNum,
  204. mbi.doctor_name doctorName,
  205. mqi.score_res scoreRes,
  206. mqi.level,
  207. mbi.diagnose,
  208. CASE WHEN mbt.behospital_type='出院病人' THEN '6'
  209. WHEN mbt.behospital_type='死亡病人' THEN '6'
  210. WHEN mbt.behospital_type='危重病人' THEN '4'
  211. WHEN mbt.behospital_type='抢救病人' THEN '5'
  212. WHEN mbt.behospital_type='手术病人' THEN '2'
  213. WHEN mbt.behospital_type='疑难病人' THEN '3'
  214. WHEN mbt.behospital_type='输血病人' THEN '4' ELSE '0' END AS score,
  215. CASE WHEN ISNULL(mci.job_create_time) THEN '未生成' ELSE '已生成' END AS creatStatus,
  216. mci.job_create_time jobCreateTime,
  217. mci.job_creator_name jobCreatorName,
  218. mci.check_time checkTime,
  219. mci.job_distribution_time jobDistributionTime
  220. FROM
  221. med_behospital_info mbi
  222. LEFT JOIN med_home_page mhp
  223. ON mbi.behospital_code=mhp.behospital_code
  224. AND mbi.hospital_id = mhp.hospital_id AND mhp.is_deleted = 'N'
  225. LEFT JOIN med_check_info mci
  226. ON mbi.behospital_code = mci.behospital_code
  227. AND mbi.hospital_id = mci.hospital_id AND mci.is_deleted = 'N'
  228. AND mci.check_id is null
  229. LEFT JOIN med_qcresult_info mqi
  230. ON mbi.behospital_code = mqi.behospital_code
  231. AND mbi.hospital_id = mqi.hospital_id AND mqi.is_deleted = 'N'
  232. JOIN med_behospital_type mbt ON mbi.behospital_code = mbt.behospital_code
  233. AND mbi.hospital_id = mbt.hospital_id AND mbt.is_deleted = 'N'
  234. WHERE mbi.hospital_id=#{hospitalId} AND mbi.is_deleted = 'N' and mqi.score_res is not null
  235. <if test="startDate != null">
  236. <![CDATA[ AND mbi.leave_hospital_date >= #{startDate}]]>
  237. </if>
  238. <if test="endDate != null">
  239. <![CDATA[ AND mbi.leave_hospital_date < #{endDate}]]>
  240. </if>
  241. <if test="creatStatus != null and creatStatus == '1'.toString()">
  242. AND mci.job_create_time is not null
  243. <if test="jobType != null and jobType != ''">
  244. AND mci.job_type=#{jobType}
  245. </if>
  246. </if>
  247. <if test="creatStatus != null and creatStatus == '0'.toString()">
  248. AND mci.job_create_time is null
  249. </if>
  250. <if test="name != null and name != ''">
  251. AND mbi.name like CONCAT('%',#{name},'%')
  252. </if>
  253. <if test="behospitalCode != null and behospitalCode != ''">
  254. AND mbi.behospital_code like CONCAT('%',#{behospitalCode},'%')
  255. </if>
  256. <if test="department !=null and department.size > 0">
  257. and mbi.beh_dept_id in
  258. <foreach collection="department" item="item" open="(" close=")" separator=",">
  259. #{item}
  260. </foreach>
  261. </if>
  262. <if test="smallDay != null">
  263. <![CDATA[ AND mhp.behospital_day_num >= #{smallDay}]]>
  264. </if>
  265. <if test="bigDay != null">
  266. <![CDATA[ AND mhp.behospital_day_num <= #{bigDay}]]>
  267. </if>
  268. <if test="doctorName != null and doctorName != ''">
  269. AND mbi.doctor_name LIKE CONCAT( '%', #{doctorName}, '%' )
  270. </if>
  271. <if test="diagnose != null and diagnose != ''">
  272. AND mbi.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
  273. </if>
  274. <if test="level != null and level != ''">
  275. AND mqi.level= #{level}
  276. </if>
  277. <if test="isPlacefile != null and isPlacefile != ''">
  278. AND mbi.is_placefile = #{isPlacefile}
  279. </if>
  280. </select>
  281. <!--通过住院号,取消核查任务-->
  282. <update id="deleteBatchCodes">
  283. <foreach collection="list" item="item" separator=";">
  284. delete from
  285. med_check_info
  286. where behospital_code = #{item} and is_deleted = 'N'
  287. </foreach>
  288. </update>
  289. <select id="checkedRecordList" resultType="com.diagbot.dto.CheckedRecordListDTO">
  290. SELECT *
  291. from
  292. (select
  293. b.behospital_code as behospitalCode,
  294. a.`status` as status,
  295. b.beh_dept_id as behDeptId,
  296. b.beh_dept_name as behDeptName,
  297. b.`name` as name,
  298. b.file_code as fileCode,
  299. b.doctor_name as doctorName,
  300. b.leave_hospital_date as leaveHospitalDate,
  301. a.job_create_time as jobCreateTime,
  302. a.job_distribution_time as jobDistributionTime,
  303. a.check_id as checkId,
  304. a.check_name as checkName,
  305. a.check_time as checkTime,
  306. c.`level` as level,
  307. c.score_res as scoreRes,
  308. <!-- 张三是A科室的监管员,李四是A科室和B科室的普通质控员,那么张三在核查任务列表中不能看到李四B科室的数据 -->
  309. case when a.check_type='0' and FIND_IN_SET(b.beh_dept_id,#{currentDeptIds})=0 then 0 else 1 end as isDel
  310. from med_check_info a join med_behospital_info b on a.hospital_id=b.hospital_id and
  311. a.behospital_code=b.behospital_code
  312. join med_qcresult_info c on b.hospital_id=c.hospital_id and b.behospital_code=c.behospital_code and
  313. b.is_deleted='N'
  314. where a.hospital_id=#{hospitalId} and a.is_deleted='N'
  315. and b.hospital_id=#{hospitalId} and b.is_deleted='N'
  316. and c.hospital_id=#{hospitalId}
  317. and a.check_id in
  318. <foreach collection="currentGeneralUserIds" item="currentGeneralUserId" separator="," close=")" open="(">
  319. #{currentGeneralUserId}
  320. </foreach>
  321. <if test="status!=null">
  322. and a.`status`=#{status}
  323. </if>
  324. <if test="behDeptId!=null and behDeptId!=''">
  325. and b.beh_dept_id=#{behDeptId}
  326. </if>
  327. <if test="name!=null and name!=''">
  328. and b.`name` like concat('%',#{name},'%')
  329. </if>
  330. <if test="behospitalCode!=null and behospitalCode!=''">
  331. and b.behospital_code like concat('%',#{behospitalCode},'%')
  332. </if>
  333. <if test="doctorName!=null and doctorName!=''">
  334. and b.doctor_name like concat('%',#{doctorName},'%')
  335. </if>
  336. <if test="jobDistributionTimeStart!=null">
  337. and a.job_distribution_time >= #{jobDistributionTimeStart}
  338. </if>
  339. <if test="jobDistributionTimeEnd!=null">
  340. and #{jobDistributionTimeEnd} >= a.job_distribution_time
  341. </if>
  342. <if test="checkName!=null and checkName!=''">
  343. and a.check_name like concat('%',#{checkName},'%')
  344. </if>
  345. <if test="level!=null and level!=''">
  346. and c.`level`=#{level}
  347. </if>
  348. <if test="checkJobTypes!=null and checkJobTypes.size>0">
  349. and a.job_type in
  350. <foreach collection="checkJobTypes" item="checkJobType" separator="," close=")" open="(">
  351. #{checkJobType}
  352. </foreach>
  353. </if>
  354. ) tab
  355. where isDel>0
  356. order by jobDistributionTime desc
  357. </select>
  358. </mapper>