dialysis_api_controller_extend.go 31KB

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