BusPatientMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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.coffee.bus.mapper.BusPatientMapper">
  4. <resultMap id="repeatDeviceResult" type="com.coffee.bus.entity.PatientDeviceRepeatDomain">
  5. <result column="name" property="name"/>
  6. <result column="gender" property="gender"/>
  7. <result column="code" property="code"/>
  8. <result column="age" property="age"/>
  9. <result column="ward" property="ward"/>
  10. <result column="bed_no" property="bedNo"/>
  11. <result column="clinic_name" property="clinicName"/>
  12. <result column="device_running_id" property="deviceRunningId"/>
  13. <result column="device_id" property="deviceId"/>
  14. <result column="device_alias" property="deviceAlias"/>
  15. <result column="device_run_state" property="deviceRunState"/>
  16. <result column="clinic_id" property="clinicId"/>
  17. <result column="device_alarm" property="deviceAlarm" />
  18. <result column="infusion_start_time" property="infusionStartTime"/>
  19. <result column="master" property="master"/>
  20. </resultMap>
  21. <resultMap id="monitorResult" type="com.coffee.bus.service.dto.PatientMonitorResult">
  22. <result column="patient_name" property="patientName"/>
  23. <result column="patient_code" property="patientCode"/>
  24. <result column="patient_age" property="patientAge"/>
  25. <result column="gender" property="gender"/>
  26. <result column="infusion_id" property="infusionId"/>
  27. <result column="patient_alarm" property="patientAlarm"/>
  28. <result column="device_id" property="deviceId"/>
  29. <result column="device_alias" property="deviceAlias"/>
  30. <result column="clinic_id" property="clinicId"/>
  31. <result column="infusion_finished" property="infusionFinished"/>
  32. <result column="ward" property="ward"/>
  33. <result column="bed_no" property="bedNo"/>
  34. <result column="total_dose" property="totalDose"/>
  35. <result column="first_dose" property="firstDose"/>
  36. <result column="remain_dose" property="remainDose"/>
  37. <result column="input_dose" property="inputDose"/>
  38. <result column="append_dose" property="appendDose"/>
  39. <result column="append_lock_time" property="appendLockTime"/>
  40. <result column="max_dose" property="maxDose"/>
  41. <result column="self_control_count" property="selfControlCount"/>
  42. <result column="self_control_lock_time" property="selfControlLockTime"/>
  43. <result column="pca_valid_count" property="pcaValidCount"/>
  44. <result column="pca_invalid_count" property="pcaInvalidCount"/>
  45. <result column="pca_total_count" property="pcaTotalCount"/>
  46. <result column="continue_dose" property="continueDose"/>
  47. <result column="pulse_dose" property="pulseDose"/>
  48. <result column="pulse_first_lock_time" property="pulseFirstLockTime"/>
  49. <result column="pulse_lock_time" property="pulseLockTime"/>
  50. <result column="flow_up_cycle" property="flowUpCycle"/>
  51. <result column="flow_down_cycle" property="flowDownCycle"/>
  52. <result column="flow_count" property="flowCount"/>
  53. <result column="flow_up_limit" property="flowUpLimit"/>
  54. <result column="flow_down_limit" property="flowDownLimit"/>
  55. <result column="flow_adjust_rate" property="flowAdjustRate"/>
  56. <result column="run_state" property="deviceRunState"/>
  57. <result column="electric_quantity" property="electricQuantity"/>
  58. <result column="warn_flow" property="warnFlow"/>
  59. <result column="warn_analgesic_poor" property="warnAnalgesicPoor"/>
  60. <result column="warn_low_battery" property="warnLowBattery"/>
  61. <result column="warn_will_finished" property="warnWillFinished"/>
  62. <result column="device_alarm" property="deviceAlarm"/>
  63. <result column="infusion_start_time" property="infusionStartTime"/>
  64. <result column="remark" property="remark"/>
  65. <result column="device_type" property="deviceType"/>
  66. <result column="anal_type" property="analType"/>
  67. <result column="ana_doctor" property="anaDoctor"/>
  68. <result column="ana_type" property="anaType"/>
  69. <result column="surgery_doctor" property="surgeryDoctor"/>
  70. <result column="surgery_name" property="surgeryName"/>
  71. <result column="finished" property="clinicFinished"/>
  72. <result column="monitor_end_time" property="monitorEndTime"/>
  73. <result column="monitor_start_time" property="monitorStartTime"/>
  74. </resultMap>
  75. <resultMap id="deviceNone" type="com.coffee.bus.service.dto.PatientDeviceNoneResult">
  76. <result column="clinic_id" property="clinicId"/>
  77. <result column="name" property="name"/>
  78. <result column="gender" property="gender"/>
  79. <result column="code" property="code"/>
  80. <result column="age" property="age"/>
  81. <result column="ward" property="ward"/>
  82. <result column="bed_no" property="bedNo"/>
  83. <result column="clinic_name" property="clinicName"/>
  84. <result column="weight" property="weight"/>
  85. <result column="height" property="height"/>
  86. <result column="ana_doctor" property="anaDoctor"/>
  87. <result column="ana_type" property="anaType"/>
  88. <result column="anal_type" property="analType"/>
  89. <result column="surgery_doctor" property="surgeryDoctor"/>
  90. <result column="asa" property="asa"/>
  91. <result column="formula" property="formula"/>
  92. <result column="finished" property="finished"/>
  93. <result column="config_person" property="configPerson"/>
  94. </resultMap>
  95. <select id="selectRepeatDevice" resultMap="repeatDeviceResult">
  96. SELECT
  97. p.code as code,
  98. c.patient_gender as gender,
  99. c.`patient_name` as name,
  100. c.patient_age as age,
  101. c.ward,
  102. c.bed_no,
  103. c.id as clinic_id,
  104. c.`name` as clinic_name,
  105. d.id as device_running_id,
  106. d.device_id as device_id,
  107. d.alias as device_alias,
  108. d.run_state as device_run_state,
  109. d.alarm as device_alarm,
  110. d.start_time as infusion_start_time,
  111. d.master
  112. FROM (SELECT `name`,gender,CODE FROM bus_patient WHERE bus_patient.`alarm`=1) AS p
  113. left join (SELECT * from bus_device_running where monitor_type=1 ) as d on p.CODE=d.patient_code
  114. left join (SELECT * FROM bus_clinic WHERE finished=0 ) AS c ON c.`patient_code`=p.code;
  115. </select>
  116. <select id="selectNoneDevice" resultMap="deviceNone">
  117. SELECT
  118. p.code as code,
  119. c.id as clinic_id,
  120. c.patient_gender as gender,
  121. c.`patient_name` as name,
  122. c.patient_age as age,
  123. c.ward as ward,
  124. c.bed_no as bed_no,
  125. c.`name` as clinic_name,
  126. c.weight as weight,
  127. c.height as height,
  128. c.ana_doctor as ana_doctor,
  129. c.ana_type as ana_type,
  130. c.anal_type as anal_type,
  131. c.surgery_doctor as surgery_doctor,
  132. c.asa as asa,
  133. c.formula as formula,
  134. c.finished as finished,
  135. c.monitor_start_time as monitor_start_time,
  136. c.config_person as config_person
  137. FROM (SELECT `name`,gender,CODE,tenant_id FROM bus_patient WHERE bus_patient.`alarm`=2 ) AS p
  138. left join (SELECT * FROM bus_clinic WHERE finished=0 ) AS c ON c.`patient_code`=p.code
  139. order by c.monitor_start_time desc;
  140. </select>
  141. <select id="selectMonitor" resultMap="monitorResult" parameterType="com.coffee.bus.service.dto.PatientMonitorQuery">
  142. select
  143. p.`code` as patient_code,
  144. p.alarm as patient_alarm,
  145. i.id as infusion_id,
  146. i.device_id as device_id,
  147. i.clinic_id as clinic_id,
  148. i.ward as ward,
  149. i.bed_no as bed_no,
  150. i.total_dose as total_dose,
  151. i.first_dose as first_dose,
  152. i.remain_dose as remain_dose,
  153. i.input_dose as input_dose,
  154. i.append_dose as append_dose,
  155. i.append_lock_time as append_lock_time,
  156. i.max_dose as max_dose,
  157. i.finished as infusion_finished,
  158. i.electric_quantity as electric_quantity,
  159. i.warn_flow as warn_flow,
  160. i.self_control_count as self_control_count,
  161. i.self_control_lock_time as self_control_lock_time,
  162. i.pca_valid_count as pca_valid_count,
  163. i.pca_invalid_count as pca_invalid_count,
  164. i.pca_total_count as pca_total_count,
  165. i.continue_dose as continue_dose,
  166. i.pulse_dose as pulse_dose,
  167. i.pulse_lock_time as pulse_lock_time,
  168. i.pulse_first_lock_time as pulse_first_lock_time,
  169. i.flow_up_cycle as flow_up_cycle,
  170. i.flow_down_cycle as flow_down_cycle,
  171. i.flow_count as flow_count,
  172. i.flow_up_limit as flow_up_limit,
  173. i.flow_down_limit as flow_down_limit,
  174. i.flow_adjust_rate as flow_adjust_rate,
  175. i.run_state as run_state,
  176. i.warn_will_finished as warn_will_finished,
  177. i.warn_analgesic_poor as warn_analgesic_poor,
  178. i.warn_low_battery as warn_low_battery,
  179. i.alarm as device_alarm,
  180. i.start_time as infusion_start_time,
  181. i.remark as remark,
  182. i.type as device_type,
  183. r.alias as device_alias,
  184. c.patient_gender as patient_gender,
  185. c.`patient_name` as patient_name,
  186. c.finished as finished,
  187. c.monitor_start_time as monitor_start_time,
  188. c.end_time as monitor_end_time,
  189. c.ana_doctor as ana_doctor,
  190. c.patient_age as patient_age,
  191. c.ana_type as ana_type,
  192. c.anal_type as anal_type,
  193. c.surgery_doctor as surgery_doctor,
  194. c.surgery_name as surgery_name
  195. from
  196. (select * from bus_patient
  197. <where>
  198. <if test="query.tenantId!=null">
  199. and tenant_id=#{query.tenantId}
  200. </if>
  201. </where>
  202. )
  203. as p
  204. join
  205. (select * from bus_infusion_history
  206. <where>
  207. is_undo='0'
  208. <if test="query.wards != null and query.wards.size > 0">
  209. and ward in
  210. <foreach item="ward" index="index" collection="query.wards" open="(" separator="," close=")">
  211. #{ward, jdbcType=VARCHAR}
  212. </foreach>
  213. </if>
  214. <if test="query.types != null and query.types.size > 0">
  215. and type in
  216. <foreach item="type" index="index" collection="query.types" open="(" separator="," close=")">
  217. #{type, jdbcType=VARCHAR}
  218. </foreach>
  219. </if>
  220. <choose>
  221. <when test="query.deviceStatus != null and query.deviceStatus.size > 0">
  222. and (
  223. run_state in
  224. <foreach item="status" index="index" collection="query.deviceStatus" open="(" separator=","
  225. close=")">
  226. #{status, jdbcType=VARCHAR}
  227. </foreach>
  228. <if test="query.deviceAlarms != null and query.deviceAlarms.size > 0">
  229. or alarm in
  230. <foreach item="alarm" index="index" collection="query.deviceAlarms" open="(" separator=","
  231. close=")">
  232. #{alarm, jdbcType=VARCHAR}
  233. </foreach>
  234. </if>
  235. )
  236. </when>
  237. <otherwise>
  238. <if test="query.deviceAlarms != null and query.deviceAlarms.size > 0">
  239. and alarm in
  240. <foreach item="alarm" index="index" collection="query.deviceAlarms" open="(" separator="," close=")">
  241. #{alarm, jdbcType=VARCHAR}
  242. </foreach>
  243. </if>
  244. </otherwise>
  245. </choose>
  246. <choose>
  247. <when test="query.warnWillFinished != false or query.warnAnalgesicPoor != false or query.warnLowBattery != false">
  248. and (
  249. <choose>
  250. <when test="query.warnWillFinished != false">warn_will_finished=1</when>
  251. <otherwise>warn_will_finished!=1</otherwise>
  252. </choose>
  253. <if test="query.warnAnalgesicPoor != false">or warn_analgesic_poor=1 </if>
  254. <if test="query.warnLowBattery != false"> or warn_low_battery=1 </if>
  255. <if test="query.warnFlow !=null">
  256. or warn_flow= #{query.warnFlow}
  257. </if>
  258. )
  259. </when>
  260. <otherwise>
  261. <if test="query.warnFlow !=null">
  262. and warn_flow= #{query.warnFlow}
  263. </if>
  264. </otherwise>
  265. </choose>
  266. </where>
  267. ) as i on p.infusion_id=i.id
  268. join (select device_id,alias from bus_device_running) as r on r.device_id=i.device_id
  269. join (select * from bus_clinic
  270. <where>
  271. <if test="query.timeRange != null and query.timeRange.size >0">
  272. and monitor_start_time &gt; #{query.timeRange[0]} and monitor_start_time &lt; #{query.timeRange[1]}
  273. </if>
  274. </where>
  275. ) c on i.clinic_id=c.id
  276. <if test="query.bedNo!=null || query.name!=null || query.code!=null || query.anaDoctor!=null || query.surgeName!=null ||query.gender!=null ||query.anaType!=null">
  277. <where>
  278. (1=0
  279. <if test="query.bedNo!=null">
  280. or i.bed_no LIKE concat('%', #{query.bedNo}, '%')
  281. </if>
  282. <if test="query.name!=null">
  283. or p.`name` LIKE concat('%', #{query.name}, '%')
  284. </if>
  285. <if test="query.code!=null">
  286. or p.`code` LIKE concat('%', #{query.code}, '%')
  287. </if>
  288. <if test="query.anaDoctor!=null">
  289. or c.`ana_doctor` like concat('%', #{query.anaDoctor}, '%')
  290. </if>
  291. <if test="query.surgeName!=null">
  292. or c.`surgery_name` like concat('%',#{query.surgeName}, '%')
  293. </if>
  294. <if test="query.gender!=null">
  295. or p.gender LIKE concat('%', #{query.gender}, '%')
  296. </if>
  297. <if test="query.anaType!=null">
  298. or c.ana_type LIKE concat('%', #{query.anaType}, '%')
  299. </if>)
  300. </where>
  301. </if>
  302. order by c.monitor_start_time desc
  303. </select>
  304. <select id="findByPatientCode" resultMap="monitorResult">
  305. select
  306. p.alarm as patient_alarm,
  307. p.`code` as patient_code,
  308. i.device_id as device_id,
  309. i.clinic_id as clinic_id,
  310. i.ward as ward,
  311. i.bed_no as bed_no,
  312. i.total_dose as total_dose,
  313. i.first_dose as first_dose,
  314. i.remain_dose as remain_dose,
  315. i.input_dose as input_dose,
  316. i.append_dose as append_dose,
  317. i.append_lock_time as append_lock_time,
  318. i.max_dose as max_dose,
  319. i.electric_quantity as electric_quantity,
  320. i.warn_flow as warn_flow,
  321. i.self_control_count as self_control_count,
  322. i.self_control_lock_time as self_control_lock_time,
  323. i.pca_valid_count as pca_valid_count,
  324. i.pca_invalid_count as pca_invalid_count,
  325. i.pca_total_count as pca_total_count,
  326. i.continue_dose as continue_dose,
  327. i.pulse_dose as pulse_dose,
  328. i.pulse_lock_time as pulse_lock_time,
  329. i.pulse_first_lock_time as pulse_first_lock_time,
  330. i.flow_up_cycle as flow_up_cycle,
  331. i.flow_down_cycle as flow_down_cycle,
  332. i.flow_count as flow_count,
  333. i.flow_up_limit as flow_up_limit,
  334. i.flow_down_limit as flow_down_limit,
  335. i.flow_adjust_rate as flow_adjust_rate,
  336. i.run_state as run_state,
  337. i.warn_will_finished as warn_will_finished,
  338. i.warn_analgesic_poor as warn_analgesic_poor,
  339. i.warn_low_battery as warn_low_battery,
  340. i.alarm as device_alarm,
  341. i.start_time as infusion_start_time,
  342. i.remark as remark,
  343. i.type as device_type,
  344. r.alias as device_alias,
  345. c.finished as finished,
  346. c.`patient_name` as patient_name,
  347. c.patient_gender as gender,
  348. c.monitor_start_time as monitor_start_time,
  349. c.end_time as monitor_end_time,
  350. c.ana_doctor as ana_doctor,
  351. c.patient_age as patient_age,
  352. c.ana_type as ana_type,
  353. c.anal_type as anal_type,
  354. c.surgery_doctor as surgery_doctor,
  355. c.surgery_name as surgery_name
  356. from
  357. (select * from bus_patient where tenant_id=#{tenantId} and code=#{patientCode} )
  358. as p
  359. join
  360. bus_infusion_history as i on p.infusion_id=i.id
  361. join (select device_id,alias from bus_device_running) as r on r.device_id=i.device_id
  362. left join bus_clinic c on i.clinic_id=c.id
  363. limit 1
  364. </select>
  365. </mapper>