dialysis_api_controller_extend.go 32KB

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