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