dialysis_api_controller_extend.go 26KB

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