dialysis_api_controller_extend.go 19KB

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