BusPatientMapper.xml 19 KB

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