dialysis_api_controller_extend.go 26KB

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