dialysis_api_controller_extend.go 19KB

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