dialysis_api_controller_extend.go 19KB

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