BusPatientMapper.xml 20 KB

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