dialysis_api_controller_extend.go 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. "strconv"
  10. "time"
  11. )
  12. // /m/api/monitor/add [post]
  13. // @param patient_id:int
  14. // @param order_id?:int 透析记录 ID
  15. // @param date?:int 日期(10位时间戳)
  16. // @param operate_time?:int 实际测量日期(10位时间戳)
  17. // @param time?:string 时间(hh:mm) 废弃
  18. // @param pulse_frequency?:float 脉率(P)(次/min)
  19. // @param breathing_rated?:float 呼吸频率(R)(次/min)
  20. // @param systolic_bp?:float 收缩压
  21. // @param diastolic_bp?:float 舒张压
  22. // @param bp_type?:int 血压测量类型
  23. // @param blood_flow_volume?:float 血流量(ml/min)
  24. // @param venous_pressure?:float 静脉压
  25. // @param venous_pressure_unit?:string 静脉压单位
  26. // @param arterial_pressure?:float 动脉压
  27. // @param transmembrane_pressure?:float 跨膜压
  28. // @param transmembrane_pressure_unit?:string 跨膜压单位
  29. // @param ultrafiltration_rate?:float 超滤率(ml/h)
  30. // @param ultrafiltration_volume?:float 超滤量(ml)
  31. // @param sodium_concentration?:float 钠浓度(mmol/L)
  32. // @param dialysate_temperature?:float 透析液温度(℃)
  33. // @param replacement_rate?:float 置换率(ml/min)
  34. // @param displacement_quantity?:float 置换量(L)
  35. // @param ktv?:float KT/V(在线)
  36. // @param symptom?:string 症状
  37. // @param dispose?:string 处理
  38. // @param result?:string 结果
  39. // @param monitoring_nurse?:int 监测人
  40. func (this *DialysisAPIController) AddMonitorRecord() {
  41. patientID, _ := this.GetInt64("patient_id")
  42. if patientID <= 0 {
  43. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  44. return
  45. }
  46. orderID, _ := this.GetInt64("order_id")
  47. if orderID < 0 {
  48. orderID = 0
  49. }
  50. date, _ := this.GetInt64("date")
  51. operateTime, _ := this.GetInt64("operate_time")
  52. // recordTime := this.GetString("time")
  53. if date <= 0 || operateTime <= 0 {
  54. date = 0
  55. operateTime = 0
  56. // recordTime = ""
  57. }
  58. fmt.Println(date)
  59. fmt.Println(operateTime)
  60. pulseFrequency, _ := this.GetFloat("pulse_frequency")
  61. //breathingRated, _ := this.GetFloat("breathing_rated")
  62. breathingRated := this.GetString("breathing_rated")
  63. systolicBP, _ := this.GetFloat("systolic_bp")
  64. diastolicBP, _ := this.GetFloat("diastolic_bp")
  65. BPType, _ := this.GetInt("bp_type")
  66. bloodFlowVolume, _ := this.GetFloat("blood_flow_volume")
  67. venousPressure, _ := this.GetFloat("venous_pressure")
  68. venousPressureType, _ := this.GetInt64("venous_pressure_type", 1)
  69. arterialPressure, _ := this.GetFloat("arterial_pressure")
  70. arterialPressureType, _ := this.GetInt64("arterial_pressure_type", 1)
  71. transmembranePressure, _ := this.GetFloat("transmembrane_pressure", 0)
  72. transmembranePressureType, _ := this.GetInt64("transmembrane_pressure_type", 1)
  73. ultrafiltrationRate, _ := this.GetFloat("ultrafiltration_rate")
  74. ultrafiltrationVolume, _ := this.GetFloat("ultrafiltration_volume")
  75. sodiumConcentration, _ := this.GetFloat("sodium_concentration")
  76. dialysateTemperature, _ := this.GetFloat("dialysate_temperature")
  77. temperature, _ := this.GetFloat("temperature")
  78. replacementRate, _ := this.GetFloat("replacement_rate")
  79. displacementQuantity, _ := this.GetFloat("displacement_quantity")
  80. ktv, _ := this.GetFloat("ktv")
  81. symptom := this.GetString("symptom")
  82. dispose := this.GetString("dispose")
  83. conductivity, _ := this.GetFloat("conductivity")
  84. displacement_flow_quantity, _ := this.GetFloat("displacement_flow_quantity")
  85. blood_oxygen_saturation := this.GetString("blood_oxygen_saturation")
  86. result := this.GetString("result")
  87. monitoringNurse, _ := this.GetInt64("monitoring_nurse")
  88. heparin, _ := this.GetFloat("heparin")
  89. dialysate_flow, _ := this.GetFloat("dialysate_flow")
  90. urr := this.GetString("urr")
  91. blood_sugar, _ := this.GetFloat("blood_sugar")
  92. monitor_anticoagulant, _ := this.GetInt64("monitor_anticoagulant")
  93. monitor_anticoagulant_value := this.GetString("monitor_anticoagulant_value")
  94. heparin_amount, _ := this.GetFloat("heparin_amount")
  95. blood_pressure_monitoring_site, _ := this.GetInt64("blood_pressure_monitoring_site")
  96. complication, _ := this.GetInt64("complication")
  97. accumulated_blood_volume, _ := this.GetFloat("accumulated_blood_volume")
  98. blood_temperature, _ := this.GetFloat("blood_temperature")
  99. urea_monitoring, _ := this.GetFloat("urea_monitoring")
  100. blood_thickness, _ := this.GetFloat("blood_thickness")
  101. blood_monitor, _ := this.GetFloat("blood_monitor")
  102. dehydration, _ := this.GetFloat("dehydration")
  103. filter_pressure := this.GetString("filter_pressure")
  104. replacement_speed, _ := this.GetFloat("replacement_speed")
  105. dicarbonate, _ := this.GetFloat("dicarbonate")
  106. adminInfo := this.GetMobileAdminUserInfo()
  107. patient, getPatientErr := service.MobileGetPatientById(adminInfo.Org.Id, patientID)
  108. if getPatientErr != nil {
  109. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  111. return
  112. } else if patient == nil {
  113. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  114. return
  115. }
  116. // 查询信息规挡的设置天数
  117. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  118. if infor.ID > 0 && infor.WeekDay > 0 {
  119. var cha_time int64
  120. timeNowStr := time.Now().Format("2006-01-02")
  121. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  122. //今日的日期减去设置的日期
  123. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  124. if cha_time >= date {
  125. //查询审核是否允许
  126. infor, _ := service.GetDialysisInformationByRecordDate(patientID, date, adminInfo.Org.Id)
  127. //申请状态不允许的情况 拒绝修改
  128. if infor.ApplicationStatus != 1 {
  129. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  130. return
  131. }
  132. }
  133. }
  134. record := models.MonitoringRecord{
  135. UserOrgId: adminInfo.Org.Id,
  136. PatientId: patientID,
  137. DialysisOrderId: orderID,
  138. MonitoringDate: date,
  139. OperateTime: operateTime,
  140. // MonitoringTime: recordTime,
  141. PulseFrequency: pulseFrequency,
  142. BreathingRate: breathingRated,
  143. SystolicBloodPressure: systolicBP,
  144. DiastolicBloodPressure: diastolicBP,
  145. BloodPressureType: int64(BPType),
  146. BloodFlowVolume: bloodFlowVolume,
  147. VenousPressure: venousPressure,
  148. VenousPressureType: venousPressureType,
  149. ArterialPressure: arterialPressure,
  150. ArterialPressureType: arterialPressureType,
  151. TransmembranePressure: transmembranePressure,
  152. TransmembranePressureType: transmembranePressureType,
  153. UltrafiltrationRate: ultrafiltrationRate,
  154. UltrafiltrationVolume: ultrafiltrationVolume,
  155. SodiumConcentration: sodiumConcentration,
  156. DialysateTemperature: dialysateTemperature,
  157. Temperature: temperature,
  158. ReplacementRate: replacementRate,
  159. DisplacementQuantity: displacementQuantity,
  160. Ktv: ktv,
  161. Symptom: symptom,
  162. Dispose: dispose,
  163. Result: result,
  164. MonitoringNurse: monitoringNurse,
  165. Status: 1,
  166. CreatedTime: time.Now().Unix(),
  167. UpdatedTime: time.Now().Unix(),
  168. Conductivity: conductivity,
  169. DisplacementFlowQuantity: displacement_flow_quantity,
  170. BloodOxygenSaturation: blood_oxygen_saturation,
  171. Creator: adminInfo.AdminUser.Id,
  172. Modify: 0,
  173. Heparin: heparin,
  174. DialysateFlow: dialysate_flow,
  175. Urr: urr,
  176. BloodSugar: blood_sugar,
  177. MonitorAnticoagulant: monitor_anticoagulant,
  178. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  179. BloodPressureMonitoringSite: blood_pressure_monitoring_site,
  180. Complication: complication,
  181. AccumulatedBloodVolume: accumulated_blood_volume,
  182. BloodTemperature: blood_temperature,
  183. UreaMonitoring: urea_monitoring,
  184. BloodThickness: blood_thickness,
  185. BloodMonitor: blood_monitor,
  186. HeparinAmount: heparin_amount,
  187. Dehydration: dehydration,
  188. FilterPressure: filter_pressure,
  189. Dicarbonate: dicarbonate,
  190. ReplacementSpeed: replacement_speed,
  191. }
  192. err := service.CreateMonitor(&record)
  193. finish := models.XtDialysisFinish{
  194. IsFinish: 1,
  195. UserOrgId: record.UserOrgId,
  196. Status: 1,
  197. Ctime: time.Now().Unix(),
  198. Mtime: 0,
  199. Module: 7,
  200. RecordDate: record.MonitoringDate,
  201. Sourse: 1,
  202. PatientId: patientID,
  203. }
  204. dialysisFinish, err := service.GetDialysisFinish(record.UserOrgId, record.MonitoringDate, 7, patientID)
  205. if dialysisFinish.ID == 0 {
  206. service.CreateDialysisFinish(finish)
  207. }
  208. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(date, 10) + ":monitor_records"
  209. redis := service.RedisClient()
  210. //清空key 值
  211. redis.Set(key, "", time.Second)
  212. keyOne := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(date, 10) + ":monitor_record_list_all"
  213. redis.Set(keyOne, "", time.Second)
  214. defer redis.Close()
  215. if err != nil {
  216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  217. return
  218. }
  219. this.ServeSuccessJSON(map[string]interface{}{
  220. "monitor": record,
  221. })
  222. }
  223. // /m/api/monitor/edit [post]
  224. // @param patient_id:int
  225. // @param order_id?:int 透析记录 ID
  226. // @param date?:int 日期(10位时间戳)
  227. // @param operate_time?:int 实际测量日期(10位时间戳)
  228. // @param time?:string 时间(hh:mm)废弃
  229. // @param pulse_frequency?:float 脉率(P)(次/min)
  230. // @param breathing_rated?:float 呼吸频率(R)(次/min)
  231. // @param systolic_bp?:float 收缩压
  232. // @param diastolic_bp?:float 舒张压
  233. // @param bp_type?:int 血压测量类型
  234. // @param blood_flow_volume?:float 血流量(ml/min)
  235. // @param venous_pressure?:float 静脉压
  236. // @param venous_pressure_unit?:string 静脉压单位
  237. // @param arterial_pressure?:float 动脉压
  238. // @param transmembrane_pressure?:float 跨膜压
  239. // @param transmembrane_pressure_unit?:string 跨膜压单位
  240. // @param ultrafiltration_rate?:float 超滤率(ml/h)
  241. // @param ultrafiltration_volume?:float 超滤量(ml)
  242. // @param sodium_concentration?:float 钠浓度(mmol/L)
  243. // @param dialysate_temperature?:float 透析液温度(℃)
  244. // @param replacement_rate?:float 置换率(ml/min)
  245. // @param displacement_quantity?:float 置换量(L)
  246. // @param ktv?:float KT/V(在线)
  247. // @param symptom?:string 症状
  248. // @param dispose?:string 处理
  249. // @param result?:string 结果
  250. // @param monitoring_nurse?:int 监测人
  251. func (this *DialysisAPIController) EditMonitorRecord() {
  252. patientID, _ := this.GetInt64("patient_id")
  253. if patientID <= 0 {
  254. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. return
  256. }
  257. id, _ := this.GetInt64("id")
  258. if id <= 0 {
  259. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  260. return
  261. }
  262. orderID, _ := this.GetInt64("order_id")
  263. if orderID < 0 {
  264. orderID = 0
  265. }
  266. date, _ := this.GetInt64("date")
  267. operateTime, _ := this.GetInt64("operate_time")
  268. if date <= 0 {
  269. date = 0
  270. operateTime = 0
  271. }
  272. pulseFrequency, _ := this.GetFloat("pulse_frequency")
  273. //breathingRated, _ := this.GetFloat("breathing_rated")
  274. breathingRated := this.GetString("breathing_rated")
  275. systolicBP, _ := this.GetFloat("systolic_bp")
  276. diastolicBP, _ := this.GetFloat("diastolic_bp")
  277. BPType, _ := this.GetInt("bp_type")
  278. bloodFlowVolume, _ := this.GetFloat("blood_flow_volume")
  279. venousPressure, _ := this.GetFloat("venous_pressure")
  280. venousPressureType, _ := this.GetInt64("venous_pressure_type", 1)
  281. arterialPressure, _ := this.GetFloat("arterial_pressure")
  282. arterialPressureType, _ := this.GetInt64("arterial_pressure", 1)
  283. transmembranePressure, _ := this.GetFloat("transmembrane_pressure")
  284. transmembranePressureType, _ := this.GetInt64("transmembrane_pressure_type", 1)
  285. ultrafiltrationRate, _ := this.GetFloat("ultrafiltration_rate")
  286. ultrafiltrationVolume, _ := this.GetFloat("ultrafiltration_volume")
  287. sodiumConcentration, _ := this.GetFloat("sodium_concentration")
  288. dialysateTemperature, _ := this.GetFloat("dialysate_temperature")
  289. temperature, _ := this.GetFloat("temperature")
  290. replacementRate, _ := this.GetFloat("replacement_rate")
  291. displacementQuantity, _ := this.GetFloat("displacement_quantity")
  292. ktv, _ := this.GetFloat("ktv")
  293. symptom := this.GetString("symptom")
  294. dispose := this.GetString("dispose")
  295. result := this.GetString("result")
  296. blood_oxygen_saturation := this.GetString("blood_oxygen_saturation")
  297. monitoringNurse, _ := this.GetInt64("monitoring_nurse")
  298. conductivity, _ := this.GetFloat("conductivity")
  299. displacement_flow_quantity, _ := this.GetFloat("displacement_flow_quantity")
  300. heparin, _ := this.GetFloat("heparin")
  301. dialysate_flow, _ := this.GetFloat("dialysate_flow")
  302. urr := this.GetString("urr")
  303. blood_sugar, _ := this.GetFloat("blood_sugar")
  304. adminInfo := this.GetMobileAdminUserInfo()
  305. monitor_anticoagulant, _ := this.GetInt64("monitor_anticoagulant")
  306. monitor_anticoagulant_value := this.GetString("monitor_anticoagulant_value")
  307. blood_pressure_monitoring_site, _ := this.GetInt64("blood_pressure_monitoring_site")
  308. complication, _ := this.GetInt64("complication")
  309. accumulated_blood_volume, _ := this.GetFloat("accumulated_blood_volume")
  310. blood_temperature, _ := this.GetFloat("blood_temperature")
  311. urea_monitoring, _ := this.GetFloat("urea_monitoring")
  312. blood_thickness, _ := this.GetFloat("blood_thickness")
  313. blood_monitor, _ := this.GetFloat("blood_monitor")
  314. heparin_amount, _ := this.GetFloat("heparin_amount")
  315. dehydration, _ := this.GetFloat("dehydration")
  316. filter_pressure := this.GetString("filter_pressure")
  317. replacement_speed, _ := this.GetFloat("replacement_speed")
  318. dicarbonate, _ := this.GetFloat("dicarbonate")
  319. monitor, err := service.GetMonitor(adminInfo.Org.Id, patientID, id)
  320. if err != nil {
  321. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  322. return
  323. }
  324. if monitor == nil {
  325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorNotExist)
  326. return
  327. }
  328. monitor.Conductivity = conductivity
  329. monitor.DialysisOrderId = orderID
  330. monitor.MonitoringDate = date
  331. monitor.OperateTime = operateTime
  332. monitor.PulseFrequency = pulseFrequency
  333. monitor.BreathingRate = breathingRated
  334. monitor.SystolicBloodPressure = systolicBP
  335. monitor.DiastolicBloodPressure = diastolicBP
  336. monitor.BloodPressureType = int64(BPType)
  337. monitor.BloodFlowVolume = bloodFlowVolume
  338. monitor.VenousPressure = venousPressure
  339. monitor.VenousPressureType = venousPressureType
  340. monitor.ArterialPressure = arterialPressure
  341. monitor.ArterialPressureType = arterialPressureType
  342. monitor.TransmembranePressure = transmembranePressure
  343. monitor.TransmembranePressureType = transmembranePressureType
  344. monitor.UltrafiltrationRate = ultrafiltrationRate
  345. monitor.UltrafiltrationVolume = ultrafiltrationVolume
  346. monitor.SodiumConcentration = sodiumConcentration
  347. monitor.DialysateTemperature = dialysateTemperature
  348. monitor.Temperature = temperature
  349. monitor.ReplacementRate = replacementRate
  350. monitor.DisplacementQuantity = displacementQuantity
  351. monitor.Ktv = ktv
  352. monitor.Symptom = symptom
  353. monitor.Dispose = dispose
  354. monitor.Result = result
  355. monitor.MonitoringNurse = monitoringNurse
  356. monitor.Status = 1
  357. monitor.UpdatedTime = time.Now().Unix()
  358. monitor.DisplacementFlowQuantity = displacement_flow_quantity
  359. monitor.BloodOxygenSaturation = blood_oxygen_saturation
  360. monitor.Modify = adminInfo.AdminUser.Id
  361. monitor.Heparin = heparin
  362. monitor.DialysateFlow = dialysate_flow
  363. monitor.Urr = urr
  364. monitor.BloodSugar = blood_sugar
  365. monitor.MonitorAnticoagulant = monitor_anticoagulant
  366. monitor.MonitorAnticoagulantValue = monitor_anticoagulant_value
  367. monitor.BloodPressureMonitoringSite = blood_pressure_monitoring_site
  368. monitor.Complication = complication
  369. monitor.AccumulatedBloodVolume = accumulated_blood_volume
  370. monitor.BloodMonitor = blood_monitor
  371. monitor.UreaMonitoring = urea_monitoring
  372. monitor.BloodThickness = blood_thickness
  373. monitor.BloodTemperature = blood_temperature
  374. monitor.HeparinAmount = heparin_amount
  375. monitor.Dehydration = dehydration
  376. monitor.FilterPressure = filter_pressure
  377. // 查询信息规挡的设置天数
  378. infor, _ := service.GetDialysisInformationSetting(monitor.MonitoringDate)
  379. if infor.ID > 0 && infor.WeekDay > 0 {
  380. var cha_time int64
  381. timeNowStr := time.Now().Format("2006-01-02")
  382. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  383. //今日的日期减去设置的日期
  384. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  385. if cha_time >= monitor.MonitoringDate {
  386. //查询审核是否允许
  387. infor, _ := service.GetDialysisInformationByRecordDate(id, monitor.MonitoringDate, monitor.UserOrgId)
  388. //申请状态不允许的情况 拒绝修改
  389. if infor.ApplicationStatus != 1 {
  390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  391. return
  392. }
  393. }
  394. }
  395. monitor.ReplacementSpeed = replacement_speed
  396. monitor.Dicarbonate = dicarbonate
  397. err = service.UpdateMonitor(monitor)
  398. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(date, 10) + ":monitor_records"
  399. redis := service.RedisClient()
  400. //清空key 值
  401. redis.Set(key, "", time.Second)
  402. keyOne := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(date, 10) + ":monitor_record_list_all"
  403. redis.Set(keyOne, "", time.Second)
  404. defer redis.Close()
  405. if err != nil {
  406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorUpdate)
  407. return
  408. }
  409. this.ServeSuccessJSON(map[string]interface{}{
  410. "monitor": monitor,
  411. })
  412. }
  413. // /m/api/monitor/delete [post]
  414. // @param record_id:int
  415. // @param patient_id:int
  416. func (this *DialysisAPIController) DeleteMonitor() {
  417. recordID, _ := this.GetInt64("record_id")
  418. patientID, _ := this.GetInt64("patient_id")
  419. if recordID <= 0 || patientID <= 0 {
  420. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  421. return
  422. }
  423. adminInfo := this.GetMobileAdminUserInfo()
  424. patient, getPatientErr := service.MobileGetPatientById(adminInfo.Org.Id, patientID)
  425. if getPatientErr != nil {
  426. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  427. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  428. return
  429. } else if patient == nil {
  430. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  431. return
  432. }
  433. monitor, getMonitorErr := service.GetMonitor(adminInfo.Org.Id, patientID, recordID)
  434. if getMonitorErr != nil {
  435. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  436. return
  437. }
  438. // 查询信息规挡的设置天数
  439. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  440. if infor.ID > 0 && infor.WeekDay > 0 {
  441. var cha_time int64
  442. timeNowStr := time.Now().Format("2006-01-02")
  443. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  444. //今日的日期减去设置的日期
  445. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  446. if cha_time >= monitor.MonitoringDate {
  447. //查询审核是否允许
  448. infor, _ := service.GetDialysisInformationByRecordDate(monitor.PatientId, monitor.MonitoringDate, monitor.UserOrgId)
  449. //申请状态不允许的情况 拒绝修改
  450. if infor.ApplicationStatus != 1 {
  451. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  452. return
  453. }
  454. }
  455. }
  456. err := service.DisableMonitor(adminInfo.Org.Id, patientID, recordID, adminInfo.AdminUser.Id)
  457. orgid := this.GetMobileAdminUserInfo().Org.Id
  458. redis := service.RedisClient()
  459. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  460. redis.Set(key, "", time.Second)
  461. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  462. redis.Set(keyOne, "", time.Second)
  463. redis.Close()
  464. if err != nil {
  465. this.ErrorLog("删除透析监测记录失败:%v", err)
  466. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  467. return
  468. }
  469. this.ServeSuccessJSON(map[string]interface{}{
  470. "record_id": monitor.ID,
  471. })
  472. }
  473. // /m/api/schedule/urgentinit [get]
  474. func (this *DialysisAPIController) UrgentScheduleInitData() {
  475. schedule_type, _ := this.GetInt("type", 0)
  476. adminUserInfo := this.GetMobileAdminUserInfo()
  477. today := utils.ZeroHourTimeOfDay(time.Now())
  478. //获取所有病人且没有上机记录的病人
  479. patients, getPatientsErr := service.MobileGetAllPatientsForUrgentSchedule(adminUserInfo.Org.Id, today.Unix())
  480. if getPatientsErr != nil {
  481. this.ErrorLog("获取所有患者失败:%v", getPatientsErr)
  482. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  483. return
  484. }
  485. modes, getModesErr := service.MobileGetAllTrearmentModesForUrgentSchedule()
  486. if getModesErr != nil {
  487. this.ErrorLog("获取所有治疗模式失败:%v", getModesErr)
  488. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  489. return
  490. }
  491. deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildDeviceNumbers(adminUserInfo.Org.Id, today.Unix(), schedule_type)
  492. if getDeviceNumbersErr != nil {
  493. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  495. return
  496. }
  497. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.Org.Id, today.Unix(), schedule_type)
  498. if getSchedulesErr != nil {
  499. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  501. return
  502. }
  503. this.ServeSuccessJSON(map[string]interface{}{
  504. "patients": patients,
  505. "modes": modes,
  506. "device_numbers": deviceNumbers,
  507. "schedules": schedules,
  508. })
  509. }
  510. // /m/api/schedule/urgentadd [post]
  511. // @param patient_id:int
  512. // @param schedule_type:int
  513. // @param mode:int
  514. // @param bed:int
  515. func (this *DialysisAPIController) AddUrgentSchedule() {
  516. patientID, _ := this.GetInt64("patient_id")
  517. scheduleType, _ := this.GetInt64("schedule_type")
  518. modeID, _ := this.GetInt64("mode")
  519. bedID, _ := this.GetInt64("bed")
  520. if patientID <= 0 || scheduleType < 1 || scheduleType > 3 || modeID < 1 || modeID > 14 || bedID <= 0 {
  521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  522. return
  523. }
  524. adminUserInfo := this.GetMobileAdminUserInfo()
  525. patient, getPatientErr := service.GetPatientByID(adminUserInfo.Org.Id, patientID)
  526. if getPatientErr != nil {
  527. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  529. return
  530. } else if patient == nil {
  531. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  532. return
  533. }
  534. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  535. if getDeviceNumberErr != nil {
  536. this.ErrorLog("获取床位失败:%v", getDeviceNumberErr)
  537. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  538. return
  539. } else if deviceNumber == nil {
  540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  541. return
  542. }
  543. scheduleDate := utils.ZeroHourTimeOfDay(time.Now())
  544. weekday := int64(scheduleDate.Weekday())
  545. if weekday == 0 {
  546. weekday = 7
  547. }
  548. //判断这个人今天是否有排班
  549. daySchedule, dayScheduleErr := service.GetDayScheduleTwo(adminUserInfo.Org.Id, scheduleDate.Unix(), patientID)
  550. //判断当前时段该床位是否有排班
  551. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, scheduleDate.Unix(), bedID, scheduleType)
  552. if dayScheduleErr == gorm.ErrRecordNotFound { //今天没有排班
  553. if err == gorm.ErrRecordNotFound { //空床位
  554. // 创建排班数据
  555. newSchedule := &models.Schedule{
  556. UserOrgId: adminUserInfo.Org.Id,
  557. PartitionId: deviceNumber.ZoneID,
  558. BedId: deviceNumber.ID,
  559. PatientId: patientID,
  560. ScheduleDate: scheduleDate.Unix(),
  561. ScheduleType: scheduleType,
  562. ScheduleWeek: weekday,
  563. ModeId: modeID,
  564. Status: 1,
  565. CreatedTime: time.Now().Unix(),
  566. UpdatedTime: time.Now().Unix(),
  567. IsExport: 5,
  568. }
  569. createErr := service.CreateScheduleTwo(newSchedule)
  570. redis := service.RedisClient()
  571. timeStr := time.Now().Format("2006-01-02")
  572. key := "scheduals_" + timeStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  573. redis.Set(key, "", time.Second)
  574. //处方
  575. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":prescriptions_list_all"
  576. redis.Set(keyOne, "", time.Second)
  577. //医嘱
  578. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":advice_list_all"
  579. redis.Set(keyTwo, "", time.Second)
  580. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":assessment_befores_list_all"
  581. redis.Set(keySix, "", time.Second)
  582. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  583. redis.Set(keyThree, "", time.Second)
  584. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":monitor_record_list_all"
  585. redis.Set(keyFour, "", time.Second)
  586. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":treatment_summarys_list_all"
  587. redis.Set(keyFive, "", time.Second)
  588. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(scheduleDate.Unix(), 10) + ":dialysis_orders_list_all"
  589. redis.Set(keySeven, "", time.Second)
  590. redis.Close()
  591. if createErr != nil {
  592. this.ErrorLog("紧急排班失败:%v", createErr)
  593. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  594. return
  595. } else {
  596. this.ServeSuccessJSON(map[string]interface{}{
  597. "schedule": newSchedule,
  598. "patient": patient,
  599. })
  600. }
  601. } else if err == nil {
  602. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //该床位有排班没上机记录
  603. this.ServeFailJSONWithSGJErrorCode(enums.ErrorSchedualcRepeatBed)
  604. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  606. return
  607. }
  608. } else if err != nil {
  609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  610. return
  611. }
  612. } else if dayScheduleErr == nil { //今天有排班
  613. if daySchedule.ID > 0 && daySchedule.DialysisOrder.ID <= 0 { //今天有排班但是没上机
  614. if err == gorm.ErrRecordNotFound { //空床位
  615. // 修改了床位逻辑
  616. daySchedule, _ := service.GetDayScheduleTwo(adminUserInfo.Org.Id, scheduleDate.Unix(), patientID)
  617. if daySchedule.ID > 0 {
  618. daySchedule.PartitionId = deviceNumber.ZoneID
  619. daySchedule.BedId = bedID
  620. daySchedule.ModeId = modeID
  621. daySchedule.ScheduleType = scheduleType
  622. daySchedule.UpdatedTime = time.Now().Unix()
  623. err := service.UpdateSchedule(&daySchedule)
  624. redis := service.RedisClient()
  625. timeStr := time.Now().Format("2006-01-02")
  626. key := "scheduals_" + timeStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  627. redis.Set(key, "", time.Second)
  628. //处方
  629. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":prescriptions_list_all"
  630. redis.Set(keyOne, "", time.Second)
  631. //医嘱
  632. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  633. redis.Set(keyTwo, "", time.Second)
  634. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  635. redis.Set(keySix, "", time.Second)
  636. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_after_dislysis_list_all"
  637. redis.Set(keyThree, "", time.Second)
  638. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":monitor_record_list_all"
  639. redis.Set(keyFour, "", time.Second)
  640. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":treatment_summarys_list_all"
  641. redis.Set(keyFive, "", time.Second)
  642. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":dialysis_orders_list_all"
  643. redis.Set(keySeven, "", time.Second)
  644. redis.Close()
  645. if err != nil {
  646. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  647. return
  648. }
  649. this.ServeSuccessJSON(map[string]interface{}{
  650. "schedule": daySchedule,
  651. "patient": patient,
  652. })
  653. }
  654. } else if err == nil { //该床位被人霸占
  655. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //霸占该床位的病人有排班没上机记录
  656. this.ServeFailJSONWithSGJErrorCode(enums.ErrorSchedualcRepeatBed)
  657. return
  658. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //霸占该床位的病人有排班且有上机记录
  659. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  660. return
  661. }
  662. } else if err != nil {
  663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  664. return
  665. }
  666. } else if daySchedule.ID > 0 && daySchedule.DialysisOrder.ID > 0 { //今天有排班且上机
  667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrder)
  668. return
  669. }
  670. }
  671. }