dialysis_api_controller_extend.go 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. symptom := this.GetString("symptom")
  80. dispose := this.GetString("dispose")
  81. conductivity, _ := this.GetFloat("conductivity")
  82. displacement_flow_quantity, _ := this.GetFloat("displacement_flow_quantity")
  83. blood_oxygen_saturation := this.GetString("blood_oxygen_saturation")
  84. result := this.GetString("result")
  85. monitoringNurse, _ := this.GetInt64("monitoring_nurse")
  86. heparin, _ := this.GetFloat("heparin")
  87. dialysate_flow, _ := this.GetFloat("dialysate_flow")
  88. urr := this.GetString("urr")
  89. blood_sugar, _ := this.GetFloat("blood_sugar")
  90. adminInfo := this.GetMobileAdminUserInfo()
  91. patient, getPatientErr := service.MobileGetPatientById(adminInfo.Org.Id, patientID)
  92. if getPatientErr != nil {
  93. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  94. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  95. return
  96. } else if patient == nil {
  97. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  98. return
  99. }
  100. record := models.MonitoringRecord{
  101. UserOrgId: adminInfo.Org.Id,
  102. PatientId: patientID,
  103. DialysisOrderId: orderID,
  104. MonitoringDate: date,
  105. OperateTime: operateTime,
  106. // MonitoringTime: recordTime,
  107. PulseFrequency: pulseFrequency,
  108. BreathingRate: breathingRated,
  109. SystolicBloodPressure: systolicBP,
  110. DiastolicBloodPressure: diastolicBP,
  111. BloodPressureType: int64(BPType),
  112. BloodFlowVolume: bloodFlowVolume,
  113. VenousPressure: venousPressure,
  114. VenousPressureType: venousPressureType,
  115. ArterialPressure: arterialPressure,
  116. ArterialPressureType: arterialPressureType,
  117. TransmembranePressure: transmembranePressure,
  118. TransmembranePressureType: transmembranePressureType,
  119. UltrafiltrationRate: ultrafiltrationRate,
  120. UltrafiltrationVolume: ultrafiltrationVolume,
  121. SodiumConcentration: sodiumConcentration,
  122. DialysateTemperature: dialysateTemperature,
  123. Temperature: temperature,
  124. ReplacementRate: replacementRate,
  125. DisplacementQuantity: displacementQuantity,
  126. Ktv: ktv,
  127. Symptom: symptom,
  128. Dispose: dispose,
  129. Result: result,
  130. MonitoringNurse: monitoringNurse,
  131. Status: 1,
  132. CreatedTime: time.Now().Unix(),
  133. UpdatedTime: time.Now().Unix(),
  134. Conductivity: conductivity,
  135. DisplacementFlowQuantity: displacement_flow_quantity,
  136. BloodOxygenSaturation: blood_oxygen_saturation,
  137. Creator: adminInfo.AdminUser.Id,
  138. Modify: 0,
  139. Heparin: heparin,
  140. DialysateFlow: dialysate_flow,
  141. Urr: urr,
  142. BloodSugar: blood_sugar,
  143. }
  144. err := service.CreateMonitor(&record)
  145. if err != nil {
  146. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  147. return
  148. }
  149. this.ServeSuccessJSON(map[string]interface{}{
  150. "monitor": record,
  151. })
  152. }
  153. // /m/api/monitor/edit [post]
  154. // @param patient_id:int
  155. // @param order_id?:int 透析记录 ID
  156. // @param date?:int 日期(10位时间戳)
  157. // @param operate_time?:int 实际测量日期(10位时间戳)
  158. // @param time?:string 时间(hh:mm)废弃
  159. // @param pulse_frequency?:float 脉率(P)(次/min)
  160. // @param breathing_rated?:float 呼吸频率(R)(次/min)
  161. // @param systolic_bp?:float 收缩压
  162. // @param diastolic_bp?:float 舒张压
  163. // @param bp_type?:int 血压测量类型
  164. // @param blood_flow_volume?:float 血流量(ml/min)
  165. // @param venous_pressure?:float 静脉压
  166. // @param venous_pressure_unit?:string 静脉压单位
  167. // @param arterial_pressure?:float 动脉压
  168. // @param transmembrane_pressure?:float 跨膜压
  169. // @param transmembrane_pressure_unit?:string 跨膜压单位
  170. // @param ultrafiltration_rate?:float 超滤率(ml/h)
  171. // @param ultrafiltration_volume?:float 超滤量(ml)
  172. // @param sodium_concentration?:float 钠浓度(mmol/L)
  173. // @param dialysate_temperature?:float 透析液温度(℃)
  174. // @param replacement_rate?:float 置换率(ml/min)
  175. // @param displacement_quantity?:float 置换量(L)
  176. // @param ktv?:float KT/V(在线)
  177. // @param symptom?:string 症状
  178. // @param dispose?:string 处理
  179. // @param result?:string 结果
  180. // @param monitoring_nurse?:int 监测人
  181. func (this *DialysisAPIController) EditMonitorRecord() {
  182. patientID, _ := this.GetInt64("patient_id")
  183. if patientID <= 0 {
  184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  185. return
  186. }
  187. id, _ := this.GetInt64("id")
  188. if id <= 0 {
  189. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  190. return
  191. }
  192. orderID, _ := this.GetInt64("order_id")
  193. if orderID < 0 {
  194. orderID = 0
  195. }
  196. date, _ := this.GetInt64("date")
  197. operateTime, _ := this.GetInt64("operate_time")
  198. if date <= 0 {
  199. date = 0
  200. operateTime = 0
  201. }
  202. pulseFrequency, _ := this.GetFloat("pulse_frequency")
  203. breathingRated, _ := this.GetFloat("breathing_rated")
  204. systolicBP, _ := this.GetFloat("systolic_bp")
  205. diastolicBP, _ := this.GetFloat("diastolic_bp")
  206. BPType, _ := this.GetInt("bp_type")
  207. bloodFlowVolume, _ := this.GetFloat("blood_flow_volume")
  208. venousPressure, _ := this.GetFloat("venous_pressure")
  209. venousPressureType, _ := this.GetInt64("venous_pressure_type", 1)
  210. arterialPressure, _ := this.GetFloat("arterial_pressure")
  211. arterialPressureType, _ := this.GetInt64("arterial_pressure", 1)
  212. transmembranePressure, _ := this.GetFloat("transmembrane_pressure")
  213. transmembranePressureType, _ := this.GetInt64("transmembrane_pressure_type", 1)
  214. ultrafiltrationRate, _ := this.GetFloat("ultrafiltration_rate")
  215. ultrafiltrationVolume, _ := this.GetFloat("ultrafiltration_volume")
  216. sodiumConcentration, _ := this.GetFloat("sodium_concentration")
  217. dialysateTemperature, _ := this.GetFloat("dialysate_temperature")
  218. temperature, _ := this.GetFloat("temperature")
  219. replacementRate, _ := this.GetFloat("replacement_rate")
  220. displacementQuantity, _ := this.GetFloat("displacement_quantity")
  221. ktv, _ := this.GetFloat("ktv")
  222. symptom := this.GetString("symptom")
  223. dispose := this.GetString("dispose")
  224. result := this.GetString("result")
  225. blood_oxygen_saturation := this.GetString("blood_oxygen_saturation")
  226. monitoringNurse, _ := this.GetInt64("monitoring_nurse")
  227. conductivity, _ := this.GetFloat("conductivity")
  228. displacement_flow_quantity, _ := this.GetFloat("displacement_flow_quantity")
  229. heparin, _ := this.GetFloat("heparin")
  230. dialysate_flow, _ := this.GetFloat("dialysate_flow")
  231. urr := this.GetString("urr")
  232. blood_sugar, _ := this.GetFloat("blood_sugar")
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. monitor, err := service.GetMonitor(adminInfo.Org.Id, patientID, id)
  235. if err != nil {
  236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  237. return
  238. }
  239. if monitor == nil {
  240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorNotExist)
  241. return
  242. }
  243. monitor.Conductivity = conductivity
  244. monitor.DialysisOrderId = orderID
  245. monitor.MonitoringDate = date
  246. monitor.OperateTime = operateTime
  247. monitor.PulseFrequency = pulseFrequency
  248. monitor.BreathingRate = breathingRated
  249. monitor.SystolicBloodPressure = systolicBP
  250. monitor.DiastolicBloodPressure = diastolicBP
  251. monitor.BloodPressureType = int64(BPType)
  252. monitor.BloodFlowVolume = bloodFlowVolume
  253. monitor.VenousPressure = venousPressure
  254. monitor.VenousPressureType = venousPressureType
  255. monitor.ArterialPressure = arterialPressure
  256. monitor.ArterialPressureType = arterialPressureType
  257. monitor.TransmembranePressure = transmembranePressure
  258. monitor.TransmembranePressureType = transmembranePressureType
  259. monitor.UltrafiltrationRate = ultrafiltrationRate
  260. monitor.UltrafiltrationVolume = ultrafiltrationVolume
  261. monitor.SodiumConcentration = sodiumConcentration
  262. monitor.DialysateTemperature = dialysateTemperature
  263. monitor.Temperature = temperature
  264. monitor.ReplacementRate = replacementRate
  265. monitor.DisplacementQuantity = displacementQuantity
  266. monitor.Ktv = ktv
  267. monitor.Symptom = symptom
  268. monitor.Dispose = dispose
  269. monitor.Result = result
  270. monitor.MonitoringNurse = monitoringNurse
  271. monitor.Status = 1
  272. monitor.UpdatedTime = time.Now().Unix()
  273. monitor.DisplacementFlowQuantity = displacement_flow_quantity
  274. monitor.BloodOxygenSaturation = blood_oxygen_saturation
  275. monitor.Modify = adminInfo.AdminUser.Id
  276. monitor.Heparin = heparin
  277. monitor.DialysateFlow = dialysate_flow
  278. monitor.Urr = urr
  279. monitor.BloodSugar = blood_sugar
  280. err = service.UpdateMonitor(monitor)
  281. if err != nil {
  282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorUpdate)
  283. return
  284. }
  285. this.ServeSuccessJSON(map[string]interface{}{
  286. "monitor": monitor,
  287. })
  288. }
  289. // /m/api/monitor/delete [post]
  290. // @param record_id:int
  291. // @param patient_id:int
  292. func (this *DialysisAPIController) DeleteMonitor() {
  293. recordID, _ := this.GetInt64("record_id")
  294. patientID, _ := this.GetInt64("patient_id")
  295. if recordID <= 0 || patientID <= 0 {
  296. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  297. return
  298. }
  299. adminInfo := this.GetMobileAdminUserInfo()
  300. patient, getPatientErr := service.MobileGetPatientById(adminInfo.Org.Id, patientID)
  301. if getPatientErr != nil {
  302. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  304. return
  305. } else if patient == nil {
  306. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  307. return
  308. }
  309. monitor, getMonitorErr := service.GetMonitor(adminInfo.Org.Id, patientID, recordID)
  310. if getMonitorErr != nil {
  311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  312. return
  313. }
  314. err := service.DisableMonitor(adminInfo.Org.Id, patientID, recordID, adminInfo.AdminUser.Id)
  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. }