dialysis_api_controller_extend.go 39KB

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