dialysis_api_controller_extend.go 25KB

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