dialysis_api_controller_extend.go 31KB

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