dialysis_api_controller_extend.go 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. "strconv"
  10. "time"
  11. )
  12. // /m/api/monitor/add [post]
  13. // @param patient_id:int
  14. // @param order_id?:int 透析记录 ID
  15. // @param date?:int 日期(10位时间戳)
  16. // @param operate_time?:int 实际测量日期(10位时间戳)
  17. // @param time?:string 时间(hh:mm) 废弃
  18. // @param pulse_frequency?:float 脉率(P)(次/min)
  19. // @param breathing_rated?:float 呼吸频率(R)(次/min)
  20. // @param systolic_bp?:float 收缩压
  21. // @param diastolic_bp?:float 舒张压
  22. // @param bp_type?:int 血压测量类型
  23. // @param blood_flow_volume?:float 血流量(ml/min)
  24. // @param venous_pressure?:float 静脉压
  25. // @param venous_pressure_unit?:string 静脉压单位
  26. // @param arterial_pressure?:float 动脉压
  27. // @param transmembrane_pressure?:float 跨膜压
  28. // @param transmembrane_pressure_unit?:string 跨膜压单位
  29. // @param ultrafiltration_rate?:float 超滤率(ml/h)
  30. // @param ultrafiltration_volume?:float 超滤量(ml)
  31. // @param sodium_concentration?:float 钠浓度(mmol/L)
  32. // @param dialysate_temperature?:float 透析液温度(℃)
  33. // @param replacement_rate?:float 置换率(ml/min)
  34. // @param displacement_quantity?:float 置换量(L)
  35. // @param ktv?:float KT/V(在线)
  36. // @param symptom?:string 症状
  37. // @param dispose?:string 处理
  38. // @param result?:string 结果
  39. // @param monitoring_nurse?:int 监测人
  40. func (this *DialysisAPIController) AddMonitorRecord() {
  41. patientID, _ := this.GetInt64("patient_id")
  42. if patientID <= 0 {
  43. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  44. return
  45. }
  46. orderID, _ := this.GetInt64("order_id")
  47. if orderID < 0 {
  48. orderID = 0
  49. }
  50. date, _ := this.GetInt64("date")
  51. operateTime, _ := this.GetInt64("operate_time")
  52. // recordTime := this.GetString("time")
  53. if date <= 0 || operateTime <= 0 {
  54. date = 0
  55. operateTime = 0
  56. // recordTime = ""
  57. }
  58. fmt.Println(date)
  59. fmt.Println(operateTime)
  60. pulseFrequency, _ := this.GetFloat("pulse_frequency")
  61. //breathingRated, _ := this.GetFloat("breathing_rated")
  62. breathingRated := this.GetString("breathing_rated")
  63. systolicBP, _ := this.GetFloat("systolic_bp")
  64. diastolicBP, _ := this.GetFloat("diastolic_bp")
  65. BPType, _ := this.GetInt("bp_type")
  66. bloodFlowVolume, _ := this.GetFloat("blood_flow_volume")
  67. venousPressure, _ := this.GetFloat("venous_pressure")
  68. venousPressureType, _ := this.GetInt64("venous_pressure_type", 1)
  69. arterialPressure, _ := this.GetFloat("arterial_pressure")
  70. arterialPressureType, _ := this.GetInt64("arterial_pressure_type", 1)
  71. transmembranePressure, _ := this.GetFloat("transmembrane_pressure", 0)
  72. transmembranePressureType, _ := this.GetInt64("transmembrane_pressure_type", 1)
  73. ultrafiltrationRate, _ := this.GetFloat("ultrafiltration_rate")
  74. ultrafiltrationVolume, _ := this.GetFloat("ultrafiltration_volume")
  75. sodiumConcentration, _ := this.GetFloat("sodium_concentration")
  76. dialysateTemperature, _ := this.GetFloat("dialysate_temperature")
  77. temperature, _ := this.GetFloat("temperature")
  78. replacementRate, _ := this.GetFloat("replacement_rate")
  79. displacementQuantity, _ := this.GetFloat("displacement_quantity")
  80. ktv, _ := this.GetFloat("ktv")
  81. symptom := this.GetString("symptom")
  82. dispose := this.GetString("dispose")
  83. conductivity, _ := this.GetFloat("conductivity")
  84. displacement_flow_quantity, _ := this.GetFloat("displacement_flow_quantity")
  85. blood_oxygen_saturation := this.GetString("blood_oxygen_saturation")
  86. result := this.GetString("result")
  87. monitoringNurse, _ := this.GetInt64("monitoring_nurse")
  88. heparin, _ := this.GetFloat("heparin")
  89. dialysate_flow, _ := this.GetFloat("dialysate_flow")
  90. urr := this.GetString("urr")
  91. blood_sugar, _ := this.GetFloat("blood_sugar")
  92. monitor_anticoagulant, _ := this.GetInt64("monitor_anticoagulant")
  93. monitor_anticoagulant_value := this.GetString("monitor_anticoagulant_value")
  94. heparin_amount, _ := this.GetFloat("heparin_amount")
  95. blood_pressure_monitoring_site, _ := this.GetInt64("blood_pressure_monitoring_site")
  96. complication, _ := this.GetInt64("complication")
  97. accumulated_blood_volume, _ := this.GetFloat("accumulated_blood_volume")
  98. blood_temperature, _ := this.GetFloat("blood_temperature")
  99. urea_monitoring, _ := this.GetFloat("urea_monitoring")
  100. blood_thickness, _ := this.GetFloat("blood_thickness")
  101. blood_monitor, _ := this.GetFloat("blood_monitor")
  102. dehydration, _ := this.GetFloat("dehydration")
  103. adminInfo := this.GetMobileAdminUserInfo()
  104. patient, getPatientErr := service.MobileGetPatientById(adminInfo.Org.Id, patientID)
  105. if getPatientErr != nil {
  106. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  107. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  108. return
  109. } else if patient == nil {
  110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  111. return
  112. }
  113. record := models.MonitoringRecord{
  114. UserOrgId: adminInfo.Org.Id,
  115. PatientId: patientID,
  116. DialysisOrderId: orderID,
  117. MonitoringDate: date,
  118. OperateTime: operateTime,
  119. // MonitoringTime: recordTime,
  120. PulseFrequency: pulseFrequency,
  121. BreathingRate: breathingRated,
  122. SystolicBloodPressure: systolicBP,
  123. DiastolicBloodPressure: diastolicBP,
  124. BloodPressureType: int64(BPType),
  125. BloodFlowVolume: bloodFlowVolume,
  126. VenousPressure: venousPressure,
  127. VenousPressureType: venousPressureType,
  128. ArterialPressure: arterialPressure,
  129. ArterialPressureType: arterialPressureType,
  130. TransmembranePressure: transmembranePressure,
  131. TransmembranePressureType: transmembranePressureType,
  132. UltrafiltrationRate: ultrafiltrationRate,
  133. UltrafiltrationVolume: ultrafiltrationVolume,
  134. SodiumConcentration: sodiumConcentration,
  135. DialysateTemperature: dialysateTemperature,
  136. Temperature: temperature,
  137. ReplacementRate: replacementRate,
  138. DisplacementQuantity: displacementQuantity,
  139. Ktv: ktv,
  140. Symptom: symptom,
  141. Dispose: dispose,
  142. Result: result,
  143. MonitoringNurse: monitoringNurse,
  144. Status: 1,
  145. CreatedTime: time.Now().Unix(),
  146. UpdatedTime: time.Now().Unix(),
  147. Conductivity: conductivity,
  148. DisplacementFlowQuantity: displacement_flow_quantity,
  149. BloodOxygenSaturation: blood_oxygen_saturation,
  150. Creator: adminInfo.AdminUser.Id,
  151. Modify: 0,
  152. Heparin: heparin,
  153. DialysateFlow: dialysate_flow,
  154. Urr: urr,
  155. BloodSugar: blood_sugar,
  156. MonitorAnticoagulant: monitor_anticoagulant,
  157. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  158. BloodPressureMonitoringSite: blood_pressure_monitoring_site,
  159. Complication: complication,
  160. AccumulatedBloodVolume: accumulated_blood_volume,
  161. BloodTemperature: blood_temperature,
  162. UreaMonitoring: urea_monitoring,
  163. BloodThickness: blood_thickness,
  164. BloodMonitor: blood_monitor,
  165. HeparinAmount: heparin_amount,
  166. Dehydration: dehydration,
  167. }
  168. err := service.CreateMonitor(&record)
  169. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(date, 10) + ":monitor_records"
  170. redis := service.RedisClient()
  171. //清空key 值
  172. redis.Set(key, "", time.Second)
  173. keyOne := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(date, 10) + ":monitor_record_list_all"
  174. redis.Set(keyOne, "", time.Second)
  175. defer redis.Close()
  176. if err != nil {
  177. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  178. return
  179. }
  180. this.ServeSuccessJSON(map[string]interface{}{
  181. "monitor": record,
  182. })
  183. }
  184. // /m/api/monitor/edit [post]
  185. // @param patient_id:int
  186. // @param order_id?:int 透析记录 ID
  187. // @param date?:int 日期(10位时间戳)
  188. // @param operate_time?:int 实际测量日期(10位时间戳)
  189. // @param time?:string 时间(hh:mm)废弃
  190. // @param pulse_frequency?:float 脉率(P)(次/min)
  191. // @param breathing_rated?:float 呼吸频率(R)(次/min)
  192. // @param systolic_bp?:float 收缩压
  193. // @param diastolic_bp?:float 舒张压
  194. // @param bp_type?:int 血压测量类型
  195. // @param blood_flow_volume?:float 血流量(ml/min)
  196. // @param venous_pressure?:float 静脉压
  197. // @param venous_pressure_unit?:string 静脉压单位
  198. // @param arterial_pressure?:float 动脉压
  199. // @param transmembrane_pressure?:float 跨膜压
  200. // @param transmembrane_pressure_unit?:string 跨膜压单位
  201. // @param ultrafiltration_rate?:float 超滤率(ml/h)
  202. // @param ultrafiltration_volume?:float 超滤量(ml)
  203. // @param sodium_concentration?:float 钠浓度(mmol/L)
  204. // @param dialysate_temperature?:float 透析液温度(℃)
  205. // @param replacement_rate?:float 置换率(ml/min)
  206. // @param displacement_quantity?:float 置换量(L)
  207. // @param ktv?:float KT/V(在线)
  208. // @param symptom?:string 症状
  209. // @param dispose?:string 处理
  210. // @param result?:string 结果
  211. // @param monitoring_nurse?:int 监测人
  212. func (this *DialysisAPIController) EditMonitorRecord() {
  213. patientID, _ := this.GetInt64("patient_id")
  214. if patientID <= 0 {
  215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. id, _ := this.GetInt64("id")
  219. if id <= 0 {
  220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  221. return
  222. }
  223. orderID, _ := this.GetInt64("order_id")
  224. if orderID < 0 {
  225. orderID = 0
  226. }
  227. date, _ := this.GetInt64("date")
  228. operateTime, _ := this.GetInt64("operate_time")
  229. if date <= 0 {
  230. date = 0
  231. operateTime = 0
  232. }
  233. pulseFrequency, _ := this.GetFloat("pulse_frequency")
  234. //breathingRated, _ := this.GetFloat("breathing_rated")
  235. breathingRated := this.GetString("breathing_rated")
  236. systolicBP, _ := this.GetFloat("systolic_bp")
  237. diastolicBP, _ := this.GetFloat("diastolic_bp")
  238. BPType, _ := this.GetInt("bp_type")
  239. bloodFlowVolume, _ := this.GetFloat("blood_flow_volume")
  240. venousPressure, _ := this.GetFloat("venous_pressure")
  241. venousPressureType, _ := this.GetInt64("venous_pressure_type", 1)
  242. arterialPressure, _ := this.GetFloat("arterial_pressure")
  243. arterialPressureType, _ := this.GetInt64("arterial_pressure", 1)
  244. transmembranePressure, _ := this.GetFloat("transmembrane_pressure")
  245. transmembranePressureType, _ := this.GetInt64("transmembrane_pressure_type", 1)
  246. ultrafiltrationRate, _ := this.GetFloat("ultrafiltration_rate")
  247. ultrafiltrationVolume, _ := this.GetFloat("ultrafiltration_volume")
  248. sodiumConcentration, _ := this.GetFloat("sodium_concentration")
  249. dialysateTemperature, _ := this.GetFloat("dialysate_temperature")
  250. temperature, _ := this.GetFloat("temperature")
  251. replacementRate, _ := this.GetFloat("replacement_rate")
  252. displacementQuantity, _ := this.GetFloat("displacement_quantity")
  253. ktv, _ := this.GetFloat("ktv")
  254. symptom := this.GetString("symptom")
  255. dispose := this.GetString("dispose")
  256. result := this.GetString("result")
  257. blood_oxygen_saturation := this.GetString("blood_oxygen_saturation")
  258. monitoringNurse, _ := this.GetInt64("monitoring_nurse")
  259. conductivity, _ := this.GetFloat("conductivity")
  260. displacement_flow_quantity, _ := this.GetFloat("displacement_flow_quantity")
  261. heparin, _ := this.GetFloat("heparin")
  262. dialysate_flow, _ := this.GetFloat("dialysate_flow")
  263. urr := this.GetString("urr")
  264. blood_sugar, _ := this.GetFloat("blood_sugar")
  265. adminInfo := this.GetMobileAdminUserInfo()
  266. monitor_anticoagulant, _ := this.GetInt64("monitor_anticoagulant")
  267. monitor_anticoagulant_value := this.GetString("monitor_anticoagulant_value")
  268. blood_pressure_monitoring_site, _ := this.GetInt64("blood_pressure_monitoring_site")
  269. complication, _ := this.GetInt64("complication")
  270. accumulated_blood_volume, _ := this.GetFloat("accumulated_blood_volume")
  271. blood_temperature, _ := this.GetFloat("blood_temperature")
  272. urea_monitoring, _ := this.GetFloat("urea_monitoring")
  273. blood_thickness, _ := this.GetFloat("blood_thickness")
  274. blood_monitor, _ := this.GetFloat("blood_monitor")
  275. heparin_amount, _ := this.GetFloat("heparin_amount")
  276. dehydration, _ := this.GetFloat("dehydration")
  277. fmt.Println("id232323233232233223232332233223", id)
  278. monitor, err := service.GetMonitor(adminInfo.Org.Id, patientID, id)
  279. if err != nil {
  280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  281. return
  282. }
  283. if monitor == nil {
  284. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorNotExist)
  285. return
  286. }
  287. monitor.Conductivity = conductivity
  288. monitor.DialysisOrderId = orderID
  289. monitor.MonitoringDate = date
  290. monitor.OperateTime = operateTime
  291. monitor.PulseFrequency = pulseFrequency
  292. monitor.BreathingRate = breathingRated
  293. monitor.SystolicBloodPressure = systolicBP
  294. monitor.DiastolicBloodPressure = diastolicBP
  295. monitor.BloodPressureType = int64(BPType)
  296. monitor.BloodFlowVolume = bloodFlowVolume
  297. monitor.VenousPressure = venousPressure
  298. monitor.VenousPressureType = venousPressureType
  299. monitor.ArterialPressure = arterialPressure
  300. monitor.ArterialPressureType = arterialPressureType
  301. monitor.TransmembranePressure = transmembranePressure
  302. monitor.TransmembranePressureType = transmembranePressureType
  303. monitor.UltrafiltrationRate = ultrafiltrationRate
  304. monitor.UltrafiltrationVolume = ultrafiltrationVolume
  305. monitor.SodiumConcentration = sodiumConcentration
  306. monitor.DialysateTemperature = dialysateTemperature
  307. monitor.Temperature = temperature
  308. monitor.ReplacementRate = replacementRate
  309. monitor.DisplacementQuantity = displacementQuantity
  310. monitor.Ktv = ktv
  311. monitor.Symptom = symptom
  312. monitor.Dispose = dispose
  313. monitor.Result = result
  314. monitor.MonitoringNurse = monitoringNurse
  315. monitor.Status = 1
  316. monitor.UpdatedTime = time.Now().Unix()
  317. monitor.DisplacementFlowQuantity = displacement_flow_quantity
  318. monitor.BloodOxygenSaturation = blood_oxygen_saturation
  319. monitor.Modify = adminInfo.AdminUser.Id
  320. monitor.Heparin = heparin
  321. monitor.DialysateFlow = dialysate_flow
  322. monitor.Urr = urr
  323. monitor.BloodSugar = blood_sugar
  324. monitor.MonitorAnticoagulant = monitor_anticoagulant
  325. monitor.MonitorAnticoagulantValue = monitor_anticoagulant_value
  326. monitor.BloodPressureMonitoringSite = blood_pressure_monitoring_site
  327. monitor.Complication = complication
  328. monitor.AccumulatedBloodVolume = accumulated_blood_volume
  329. monitor.BloodMonitor = blood_monitor
  330. monitor.UreaMonitoring = urea_monitoring
  331. monitor.BloodThickness = blood_thickness
  332. monitor.BloodTemperature = blood_temperature
  333. monitor.HeparinAmount = heparin_amount
  334. monitor.Dehydration = dehydration
  335. err = service.UpdateMonitor(monitor)
  336. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(date, 10) + ":monitor_records"
  337. redis := service.RedisClient()
  338. //清空key 值
  339. redis.Set(key, "", time.Second)
  340. keyOne := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(date, 10) + ":monitor_record_list_all"
  341. redis.Set(keyOne, "", time.Second)
  342. defer redis.Close()
  343. if err != nil {
  344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorUpdate)
  345. return
  346. }
  347. this.ServeSuccessJSON(map[string]interface{}{
  348. "monitor": monitor,
  349. })
  350. }
  351. // /m/api/monitor/delete [post]
  352. // @param record_id:int
  353. // @param patient_id:int
  354. func (this *DialysisAPIController) DeleteMonitor() {
  355. recordID, _ := this.GetInt64("record_id")
  356. patientID, _ := this.GetInt64("patient_id")
  357. if recordID <= 0 || patientID <= 0 {
  358. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  359. return
  360. }
  361. adminInfo := this.GetMobileAdminUserInfo()
  362. patient, getPatientErr := service.MobileGetPatientById(adminInfo.Org.Id, patientID)
  363. if getPatientErr != nil {
  364. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  366. return
  367. } else if patient == nil {
  368. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  369. return
  370. }
  371. monitor, getMonitorErr := service.GetMonitor(adminInfo.Org.Id, patientID, recordID)
  372. if getMonitorErr != nil {
  373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  374. return
  375. }
  376. err := service.DisableMonitor(adminInfo.Org.Id, patientID, recordID, adminInfo.AdminUser.Id)
  377. orgid := this.GetMobileAdminUserInfo().Org.Id
  378. redis := service.RedisClient()
  379. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  380. redis.Set(key, "", time.Second)
  381. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  382. redis.Set(keyOne, "", time.Second)
  383. fmt.Println("keyo呢32332322332332232332", keyOne)
  384. redis.Close()
  385. if err != nil {
  386. this.ErrorLog("删除透析监测记录失败:%v", err)
  387. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  388. return
  389. }
  390. this.ServeSuccessJSON(map[string]interface{}{
  391. "record_id": monitor.ID,
  392. })
  393. }
  394. // /m/api/schedule/urgentinit [get]
  395. func (this *DialysisAPIController) UrgentScheduleInitData() {
  396. schedule_type, _ := this.GetInt("type", 0)
  397. adminUserInfo := this.GetMobileAdminUserInfo()
  398. today := utils.ZeroHourTimeOfDay(time.Now())
  399. //获取所有病人且没有上机记录的病人
  400. patients, getPatientsErr := service.MobileGetAllPatientsForUrgentSchedule(adminUserInfo.Org.Id, today.Unix())
  401. if getPatientsErr != nil {
  402. this.ErrorLog("获取所有患者失败:%v", getPatientsErr)
  403. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  404. return
  405. }
  406. modes, getModesErr := service.MobileGetAllTrearmentModesForUrgentSchedule()
  407. if getModesErr != nil {
  408. this.ErrorLog("获取所有治疗模式失败:%v", getModesErr)
  409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  410. return
  411. }
  412. deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildDeviceNumbers(adminUserInfo.Org.Id, today.Unix(), schedule_type)
  413. if getDeviceNumbersErr != nil {
  414. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  416. return
  417. }
  418. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.Org.Id, today.Unix(), schedule_type)
  419. if getSchedulesErr != nil {
  420. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  422. return
  423. }
  424. this.ServeSuccessJSON(map[string]interface{}{
  425. "patients": patients,
  426. "modes": modes,
  427. "device_numbers": deviceNumbers,
  428. "schedules": schedules,
  429. })
  430. }
  431. // /m/api/schedule/urgentadd [post]
  432. // @param patient_id:int
  433. // @param schedule_type:int
  434. // @param mode:int
  435. // @param bed:int
  436. func (this *DialysisAPIController) AddUrgentSchedule() {
  437. patientID, _ := this.GetInt64("patient_id")
  438. scheduleType, _ := this.GetInt64("schedule_type")
  439. modeID, _ := this.GetInt64("mode")
  440. bedID, _ := this.GetInt64("bed")
  441. if patientID <= 0 || scheduleType < 1 || scheduleType > 3 || modeID < 1 || modeID > 14 || bedID <= 0 {
  442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  443. return
  444. }
  445. adminUserInfo := this.GetMobileAdminUserInfo()
  446. patient, getPatientErr := service.GetPatientByID(adminUserInfo.Org.Id, patientID)
  447. if getPatientErr != nil {
  448. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  449. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  450. return
  451. } else if patient == nil {
  452. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  453. return
  454. }
  455. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  456. if getDeviceNumberErr != nil {
  457. this.ErrorLog("获取床位失败:%v", getDeviceNumberErr)
  458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  459. return
  460. } else if deviceNumber == nil {
  461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  462. return
  463. }
  464. scheduleDate := utils.ZeroHourTimeOfDay(time.Now())
  465. weekday := int64(scheduleDate.Weekday())
  466. if weekday == 0 {
  467. weekday = 7
  468. }
  469. //判断这个人今天是否有排班
  470. daySchedule, dayScheduleErr := service.GetDayScheduleTwo(adminUserInfo.Org.Id, scheduleDate.Unix(), patientID)
  471. //判断当前时段该床位是否有排班
  472. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, scheduleDate.Unix(), bedID, scheduleType)
  473. if dayScheduleErr == gorm.ErrRecordNotFound { //今天没有排班
  474. if err == gorm.ErrRecordNotFound { //空床位
  475. // 创建排班数据
  476. newSchedule := &models.Schedule{
  477. UserOrgId: adminUserInfo.Org.Id,
  478. PartitionId: deviceNumber.ZoneID,
  479. BedId: deviceNumber.ID,
  480. PatientId: patientID,
  481. ScheduleDate: scheduleDate.Unix(),
  482. ScheduleType: scheduleType,
  483. ScheduleWeek: weekday,
  484. ModeId: modeID,
  485. Status: 1,
  486. CreatedTime: time.Now().Unix(),
  487. UpdatedTime: time.Now().Unix(),
  488. IsExport: 5,
  489. }
  490. createErr := service.CreateSchedule(newSchedule)
  491. redis := service.RedisClient()
  492. timeStr := time.Now().Format("2006-01-02")
  493. key := "scheduals_" + timeStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  494. redis.Set(key, "", time.Second)
  495. //处方
  496. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":prescriptions_list_all"
  497. redis.Set(keyOne, "", time.Second)
  498. //医嘱
  499. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":advice_list_all"
  500. redis.Set(keyTwo, "", time.Second)
  501. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":assessment_befores_list_all"
  502. redis.Set(keySix, "", time.Second)
  503. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  504. redis.Set(keyThree, "", time.Second)
  505. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":monitor_record_list_all"
  506. redis.Set(keyFour, "", time.Second)
  507. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":treatment_summarys_list_all"
  508. redis.Set(keyFive, "", time.Second)
  509. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":dialysis_orders_list_all"
  510. redis.Set(keySeven, "", time.Second)
  511. redis.Close()
  512. if createErr != nil {
  513. this.ErrorLog("紧急排班失败:%v", createErr)
  514. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  515. return
  516. } else {
  517. this.ServeSuccessJSON(map[string]interface{}{
  518. "schedule": newSchedule,
  519. "patient": patient,
  520. })
  521. }
  522. } else if err == nil {
  523. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //该床位有排班没上机记录
  524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorSchedualcRepeatBed)
  525. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  527. return
  528. }
  529. } else if err != nil {
  530. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  531. return
  532. }
  533. } else if dayScheduleErr == nil { //今天有排班
  534. if daySchedule.ID > 0 && daySchedule.DialysisOrder.ID <= 0 { //今天有排班但是没上机
  535. if err == gorm.ErrRecordNotFound { //空床位
  536. // 修改了床位逻辑
  537. daySchedule, _ := service.GetDayScheduleTwo(adminUserInfo.Org.Id, scheduleDate.Unix(), patientID)
  538. if daySchedule.ID > 0 {
  539. daySchedule.PartitionId = deviceNumber.ZoneID
  540. daySchedule.BedId = bedID
  541. daySchedule.ModeId = modeID
  542. daySchedule.ScheduleType = scheduleType
  543. daySchedule.UpdatedTime = time.Now().Unix()
  544. err := service.UpdateSchedule(&daySchedule)
  545. redis := service.RedisClient()
  546. timeStr := time.Now().Format("2006-01-02")
  547. key := "scheduals_" + timeStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  548. redis.Set(key, "", time.Second)
  549. //处方
  550. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":prescriptions_list_all"
  551. redis.Set(keyOne, "", time.Second)
  552. //医嘱
  553. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  554. redis.Set(keyTwo, "", time.Second)
  555. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  556. redis.Set(keySix, "", time.Second)
  557. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_after_dislysis_list_all"
  558. redis.Set(keyThree, "", time.Second)
  559. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":monitor_record_list_all"
  560. redis.Set(keyFour, "", time.Second)
  561. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":treatment_summarys_list_all"
  562. redis.Set(keyFive, "", time.Second)
  563. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":dialysis_orders_list_all"
  564. redis.Set(keySeven, "", time.Second)
  565. redis.Close()
  566. if err != nil {
  567. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  568. return
  569. }
  570. this.ServeSuccessJSON(map[string]interface{}{
  571. "schedule": daySchedule,
  572. "patient": patient,
  573. })
  574. }
  575. } else if err == nil { //该床位被人霸占
  576. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //霸占该床位的病人有排班没上机记录
  577. this.ServeFailJSONWithSGJErrorCode(enums.ErrorSchedualcRepeatBed)
  578. return
  579. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //霸占该床位的病人有排班且有上机记录
  580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  581. return
  582. }
  583. } else if err != nil {
  584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  585. return
  586. }
  587. } else if daySchedule.ID > 0 && daySchedule.DialysisOrder.ID > 0 { //今天有排班且上机
  588. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrder)
  589. return
  590. }
  591. }
  592. }