dialysis_api_controller_extend.go 19KB

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