dialysis_api_controller_extend.go 26KB

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