dialysis_api_controller_extend.go 20KB

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