BusPatientMapper.xml 22 KB

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