dialysis_api_controller_extend.go 28KB

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