dialysis_api_controller_extend.go 19KB

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