dialysis_api_controller_extend.go 39KB

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