dialysis_record_api_controller.go 52KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "encoding/json"
  5. "github.com/jinzhu/gorm"
  6. "math"
  7. "strconv"
  8. "time"
  9. "XT_New/enums"
  10. "XT_New/service"
  11. "XT_New/utils"
  12. "net/http"
  13. "net/url"
  14. "fmt"
  15. "github.com/astaxie/beego"
  16. )
  17. func DialysisRecordAPIControllerRegistRouter() {
  18. beego.Router("/api/dialysis/initdata", &DialysisRecordAPIController{}, "get:RecordInitData")
  19. beego.Router("/api/dialysis/schedules", &DialysisRecordAPIController{}, "get:GetSchedules")
  20. beego.Router("/api/dislysis/schedule", &DialysisRecordAPIController{}, "get:DialysisSchedule")
  21. beego.Router("/api/dislysis/monitor/edit", &DialysisRecordAPIController{}, "post:EditMonitor")
  22. beego.Router("/api/dialysis/start_record", &DialysisRecordAPIController{}, "post:StartDialysis")
  23. beego.Router("/api/dialysis/finish", &DialysisRecordAPIController{}, "post:FinishDialysis")
  24. beego.Router("/api/start_dialysis/modify", &DialysisRecordAPIController{}, "post:ModifyStartDialysis")
  25. beego.Router("/api/finish_dialysis/modify", &DialysisRecordAPIController{}, "post:ModifyFinishDialysis")
  26. }
  27. type DialysisRecordAPIController struct {
  28. BaseAuthAPIController
  29. }
  30. // /api/dialysis/initdata [get]
  31. func (this *DialysisRecordAPIController) RecordInitData() {
  32. adminInfo := this.GetAdminUserInfo()
  33. orgID := adminInfo.CurrentOrgId
  34. now := time.Now()
  35. ymdDate, _ := utils.ParseTimeStringToTime("2006-01-02", now.Format("2006-01-02"))
  36. schedules, getSchedulesErr := service.GetDialysisScheduals(orgID, ymdDate.Unix())
  37. if getSchedulesErr != nil {
  38. this.ErrorLog("获取排班信息失败:%v", getSchedulesErr)
  39. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  40. return
  41. }
  42. zones, getZonesErr := service.GetAllValidDeviceZones(orgID)
  43. if getZonesErr != nil {
  44. this.ErrorLog("获取全部分区失败:%v", getZonesErr)
  45. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  46. return
  47. }
  48. this.ServeSuccessJSON(map[string]interface{}{
  49. "schedules": schedules,
  50. "zones": zones,
  51. })
  52. }
  53. // /api/dialysis/schedules [get]
  54. // @param date:string (yyyy-mm-dd)
  55. func (this *DialysisRecordAPIController) GetSchedules() {
  56. schedualDate := this.GetString("date")
  57. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  58. if parseDateErr != nil {
  59. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  60. return
  61. }
  62. adminInfo := this.GetAdminUserInfo()
  63. orgID := adminInfo.CurrentOrgId
  64. schedules, err := service.GetDialysisScheduals(orgID, date.Unix())
  65. if err != nil {
  66. this.ErrorLog("获取排班信息失败:%v", err)
  67. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  68. } else {
  69. this.ServeSuccessJSON(map[string]interface{}{
  70. "schedules": schedules,
  71. })
  72. }
  73. }
  74. // /api/dislysis/schedule [get]
  75. // @param patient_id:int
  76. // @param date:string (yyyy-MM-dd)
  77. func (this *DialysisRecordAPIController) DialysisSchedule() {
  78. patientID, _ := this.GetInt64("patient_id")
  79. recordDateStr := this.GetString("date")
  80. if patientID <= 0 {
  81. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  82. return
  83. }
  84. if len(recordDateStr) == 0 {
  85. recordDateStr = time.Now().Format("2006-01-02")
  86. }
  87. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  88. if parseDateErr != nil {
  89. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  90. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  91. return
  92. }
  93. adminInfo := this.GetAdminUserInfo()
  94. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.CurrentOrgId, patientID)
  95. if getPatientErr != nil {
  96. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  97. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  98. return
  99. } else if patient == nil {
  100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  101. return
  102. }
  103. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.CurrentOrgId, patientID, date.Unix())
  104. if getSchedualErr != nil {
  105. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  107. return
  108. }
  109. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  110. if getRTARErr != nil {
  111. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  113. return
  114. }
  115. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.CurrentOrgId, patientID, date.Unix())
  116. fmt.Println("predialysisEvaluatiotion", predialysisEvaluation)
  117. if getPEErr != nil {
  118. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  119. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  120. return
  121. }
  122. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvices(adminInfo.CurrentOrgId, patientID, date.Unix())
  123. if getDoctorAdvicesErr != nil {
  124. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  125. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  126. return
  127. }
  128. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  129. if getDialysisOrderErr != nil {
  130. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  131. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  132. return
  133. }
  134. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.CurrentOrgId, patientID, date.Unix())
  135. if getDoubleCheckErr != nil {
  136. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  138. return
  139. }
  140. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.CurrentOrgId, patientID, date.Unix())
  141. if getMonitorRecordsErr != nil {
  142. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  143. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  144. return
  145. }
  146. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.CurrentOrgId, patientID, date.Unix())
  147. if getAADErr != nil {
  148. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  150. return
  151. }
  152. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.CurrentOrgId, patientID, date.Unix())
  153. if getTreatmentSummaryErr != nil {
  154. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  155. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  156. return
  157. }
  158. admins, getAdminsErr := service.GetAllAdminUsers(adminInfo.CurrentOrgId, adminInfo.CurrentAppId)
  159. if getAdminsErr != nil {
  160. this.ErrorLog("获取医护列表失败:%v", getAdminsErr)
  161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  162. return
  163. }
  164. devices, getDevicesErr := service.GetValidDevicesBy(adminInfo.CurrentOrgId, 0, 0)
  165. if getDevicesErr != nil {
  166. this.ErrorLog("获取设备列表失败:%v", getDevicesErr)
  167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  168. return
  169. }
  170. deviceNumbers, getDeviceNumbersErr := service.GetAllValidDeviceNumbers(adminInfo.CurrentOrgId)
  171. if getDeviceNumbersErr != nil {
  172. this.ErrorLog("获取床位号列表失败:%v", getDeviceNumbersErr)
  173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  174. return
  175. }
  176. lastPredialysisEvaluation, getLPEErr := service.GetLastTimePredialysisEvaluation(adminInfo.CurrentOrgId, patientID, date.Unix())
  177. if getLPEErr != nil {
  178. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  180. return
  181. }
  182. var lastMonitorRecord *models.MonitoringRecord
  183. lastMonitorRecord, getLastErr := service.GetLastMonitorRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  184. if getLastErr != nil {
  185. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  186. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  187. return
  188. }
  189. lastAssessmentAfterDislysis, getLAADErr := service.GetLastTimeAssessmentAfterDislysis(adminInfo.CurrentOrgId, patientID, date.Unix())
  190. if getLAADErr != nil {
  191. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  193. return
  194. }
  195. dialysisPrescribe, getDialysisPrescribeErr := service.GetDialysisPrescribe(adminInfo.CurrentOrgId, patientID, date.Unix())
  196. if getDialysisPrescribeErr != nil {
  197. this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  198. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  199. return
  200. }
  201. dialysisSolution, getDialysisSolutionErr := service.GetDialysisSolution(adminInfo.CurrentOrgId, patientID, schedual.ModeId)
  202. if getDialysisSolutionErr != nil {
  203. this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  205. return
  206. }
  207. lastDialysisPrescribe, getDialysisPrescribeErr := service.GetLastDialysisPrescribeByModeId(adminInfo.CurrentOrgId, patientID, schedual.ModeId)
  208. if getDialysisPrescribeErr != nil {
  209. this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  210. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  211. return
  212. }
  213. systemDialysisPrescribe, getSystemDialysisPrescribeErr := service.GetSystemDialysisPrescribeByModeId(adminInfo.CurrentOrgId, schedual.ModeId)
  214. if getSystemDialysisPrescribeErr != nil {
  215. this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  217. return
  218. }
  219. if getLPEErr != nil {
  220. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  221. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  222. return
  223. }
  224. lastDryWeightDislysis, getDryErr := service.GetLastDryWeight(adminInfo.CurrentOrgId, patientID)
  225. if getDryErr != nil {
  226. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  227. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  228. return
  229. }
  230. headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  231. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.CurrentOrgId)
  232. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.CurrentOrgId)
  233. var his_advices []*models.HisDoctorAdviceInfo
  234. if is_open_config.IsOpen == 1 {
  235. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.CurrentOrgId, patientID, date.Unix())
  236. }
  237. returnData := map[string]interface{}{
  238. "patient": patient,
  239. "schedual": schedual,
  240. "prescription": dialysisPrescribe,
  241. "solution": dialysisSolution,
  242. "receiver_treatment_access": receiverTreatmentAccess,
  243. "predialysis_evaluation": predialysisEvaluation,
  244. "doctor_advices": doctorAdvices,
  245. "double_check": doubleCheck,
  246. "assessment_after_dislysis": assessmentAfterDislysis,
  247. "treatment_summary": treatmentSummary,
  248. "monitor_records": monitorRecords,
  249. "dialysis_order": dialysisOrder,
  250. "doctors": admins,
  251. "config": record,
  252. "devices": devices,
  253. "device_numbers": deviceNumbers,
  254. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  255. "lastMonitorRecord": lastMonitorRecord,
  256. "lastAssessmentAfterDislysis": lastAssessmentAfterDislysis,
  257. "lastDialysisPrescribe": lastDialysisPrescribe,
  258. "lastDryWeightDislysis": lastDryWeightDislysis,
  259. "headNurses": headNurses,
  260. "system_prescribe": systemDialysisPrescribe,
  261. "his_advices": his_advices,
  262. "is_open_config": is_open_config,
  263. }
  264. this.ServeSuccessJSON(returnData)
  265. }
  266. type EditMonitorParamObject struct {
  267. ID int64 `json:"id"`
  268. MonitoringDate int64 `json:"monitoring_date"`
  269. OperateTime int64 `json:"operate_time"`
  270. // MonitoringTime string `json:"monitoring_time"`
  271. SystolicBP float64 `json:"systolic_bp"`
  272. DiastolicBP float64 `json:"diastolic_bp"`
  273. PulseFrequency float64 `json:"pulse_frequency"`
  274. BreathingRated float64 `json:"breathing_rated"`
  275. BloodFlowVolume float64 `json:"blood_flow_volume"`
  276. VenousPressure float64 `json:"venous_pressure"`
  277. VenousPressureType int64 `json:"venous_pressure_type"`
  278. TransmembranePressure float64 `json:"transmembrane_pressure"`
  279. TransmembranePressureType int64 `json:"transmembrane_pressure_type"`
  280. UltrafiltrationVolume float64 `json:"ultrafiltration_volume"`
  281. UltrafiltrationRate float64 `json:"ultrafiltration_rate"`
  282. ArterialPressure float64 `json:"arterial_pressure"`
  283. ArterialPressureType int64 `json:"arterial_pressure_type"`
  284. SodiumConcentration float64 `json:"sodium_concentration"`
  285. DialysateTemperature float64 `json:"dialysate_temperature"`
  286. Temperature float64 `json:"temperature"`
  287. ReplacementRate float64 `json:"replacement_rate"`
  288. DisplacementQuantity float64 `json:"displacement_quantity"`
  289. KTV float64 `json:"ktv"`
  290. Symptom string `json:"symptom"`
  291. Dispose string `json:"dispose"`
  292. Result string `json:"result"`
  293. Conductivity float64 `json:"conductivity"`
  294. DisplacementFlowQuantity float64 `json:"displacement_flow_quantity"`
  295. BloodOxygenSaturation string `gorm:"column:blood_oxygen_saturation" json:"blood_oxygen_saturation" form:"blood_oxygen_saturation"`
  296. Heparin float64 `gorm:"column:heparin" json:"heparin" form:"heparin"`
  297. DialysateFlow float64 `gorm:"column:dialysate_flow" json:"dialysate_flow" form:"dialysate_flow"`
  298. Urr string `gorm:"column:urr" json:"urr" form:"urr"`
  299. BloodSugar float64 `gorm:"column:blood_sugar" json:"blood_sugar" form:"blood_sugar"`
  300. }
  301. // /api/dislysis/monitor/edit [post]
  302. // @param patient_id:int 患者id
  303. // @param schedule_date:int 排班日期
  304. // 下面的参数放到 body
  305. // @param id?:int 监测记录ID(id为0时为创建记录,不为0时为修改记录)
  306. // @param monitoring_date:int 排班日期
  307. // @param operate_time:int 实际测量日期
  308. // @param monitoring_time:string (HH:mm) 监测时间 废弃
  309. // @param systolic_bp?:float 收缩压
  310. // @param diastolic_bp?:float 舒张压
  311. // @param pulse_frequency?:float 心率
  312. // @param breathing_rated?:float 呼吸频率
  313. // @param blood_flow_volume?:float 血流量
  314. // @param venous_pressure?:float 静脉压
  315. // @param transmembrane_pressure?:float 跨膜压
  316. // @param ultrafiltration_volume?:float 超滤量
  317. // @param ultrafiltration_rate?:float 超滤率
  318. // @param arterial_pressure?:float 动脉压
  319. // @param sodium_concentration?:float 钠浓度
  320. // @param dialysate_temperature?:float 透析液温度
  321. // @param replacement_rate?:float 置换率
  322. // @param displacement_quantity?:float 置换量
  323. // @param ktv?:float KT/V
  324. // @param symptom?:string 病情变化
  325. // @param dispose?:string 处理
  326. // @param result?:string 结果
  327. func (this *DialysisRecordAPIController) EditMonitor() {
  328. patientID, _ := this.GetInt64("patient_id")
  329. scheduleDate, _ := this.GetInt64("schedule_date")
  330. if patientID <= 0 || scheduleDate <= 0 {
  331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  332. return
  333. }
  334. var monitorParam EditMonitorParamObject
  335. if parseErr := json.Unmarshal(this.Ctx.Input.RequestBody, &monitorParam); parseErr != nil {
  336. this.ErrorLog("参数解析失败:%v", parseErr)
  337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  338. return
  339. }
  340. if monitorParam.MonitoringDate != scheduleDate {
  341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  342. return
  343. }
  344. adminUserInfo := this.GetAdminUserInfo()
  345. schedule, getScheduleErr := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  346. if getScheduleErr != nil {
  347. this.ErrorLog("获取排班信息失败:%v", getScheduleErr)
  348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  349. return
  350. } else if schedule == nil {
  351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  352. return
  353. }
  354. // TODO 其实这里合理的逻辑是“透析记录存在的情况下才能添加监测记录的”
  355. dialysisOrder, getDialysisOrderErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  356. if getDialysisOrderErr != nil {
  357. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  358. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  359. return
  360. }
  361. orderID := int64(0)
  362. if dialysisOrder != nil {
  363. orderID = dialysisOrder.ID
  364. }
  365. if monitorParam.ID <= 0 { // 新建记录
  366. monitor := models.MonitoringRecord{
  367. UserOrgId: adminUserInfo.CurrentOrgId,
  368. PatientId: patientID,
  369. DialysisOrderId: orderID,
  370. MonitoringDate: monitorParam.MonitoringDate,
  371. OperateTime: monitorParam.OperateTime,
  372. // MonitoringTime: monitorParam.MonitoringTime,
  373. PulseFrequency: monitorParam.PulseFrequency,
  374. BreathingRate: monitorParam.BreathingRated,
  375. SystolicBloodPressure: monitorParam.SystolicBP,
  376. DiastolicBloodPressure: monitorParam.DiastolicBP,
  377. BloodFlowVolume: monitorParam.BloodFlowVolume,
  378. VenousPressure: monitorParam.VenousPressure,
  379. VenousPressureType: monitorParam.VenousPressureType,
  380. ArterialPressure: monitorParam.ArterialPressure,
  381. ArterialPressureType: monitorParam.ArterialPressureType,
  382. TransmembranePressure: monitorParam.TransmembranePressure,
  383. TransmembranePressureType: monitorParam.TransmembranePressureType,
  384. UltrafiltrationRate: monitorParam.UltrafiltrationRate,
  385. UltrafiltrationVolume: monitorParam.UltrafiltrationVolume,
  386. SodiumConcentration: monitorParam.SodiumConcentration,
  387. DialysateTemperature: monitorParam.DialysateTemperature,
  388. Temperature: monitorParam.Temperature,
  389. ReplacementRate: monitorParam.ReplacementRate,
  390. DisplacementQuantity: monitorParam.DisplacementQuantity,
  391. Ktv: monitorParam.KTV,
  392. Symptom: monitorParam.Symptom,
  393. Dispose: monitorParam.Dispose,
  394. Result: monitorParam.Result,
  395. MonitoringNurse: adminUserInfo.AdminUser.Id,
  396. Conductivity: monitorParam.Conductivity,
  397. DisplacementFlowQuantity: monitorParam.DisplacementFlowQuantity,
  398. Status: 1,
  399. CreatedTime: time.Now().Unix(),
  400. UpdatedTime: time.Now().Unix(),
  401. BloodOxygenSaturation: monitorParam.BloodOxygenSaturation,
  402. Creator: adminUserInfo.AdminUser.Id,
  403. Heparin: monitorParam.Heparin,
  404. DialysateFlow: monitorParam.DialysateFlow,
  405. Urr: monitorParam.Urr,
  406. BloodSugar: monitorParam.BloodSugar,
  407. }
  408. createErr := service.CreateMonitor(&monitor)
  409. if createErr != nil {
  410. this.ErrorLog("创建监测记录失败:%v", createErr)
  411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  412. return
  413. }
  414. this.ServeSuccessJSON(map[string]interface{}{
  415. "monitor": monitor,
  416. })
  417. } else { // 修改记录
  418. monitor, getMonitorErr := service.GetMonitor(adminUserInfo.CurrentOrgId, patientID, monitorParam.ID)
  419. if getMonitorErr != nil {
  420. this.ErrorLog("获取透析监测记录失败:%v", getMonitorErr)
  421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  422. return
  423. } else if monitor == nil {
  424. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorNotExist)
  425. return
  426. }
  427. //if monitor.MonitoringNurse != adminUserInfo.AdminUser.Id {
  428. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  429. // if getPermissionErr != nil {
  430. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  431. // return
  432. // } else if headNursePermission == nil {
  433. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  434. // return
  435. // }
  436. //}
  437. monitor.OperateTime = monitorParam.OperateTime
  438. monitor.PulseFrequency = monitorParam.PulseFrequency
  439. monitor.BreathingRate = monitorParam.BreathingRated
  440. monitor.SystolicBloodPressure = monitorParam.SystolicBP
  441. monitor.DiastolicBloodPressure = monitorParam.DiastolicBP
  442. monitor.BloodFlowVolume = monitorParam.BloodFlowVolume
  443. monitor.VenousPressure = monitorParam.VenousPressure
  444. monitor.VenousPressureType = monitorParam.VenousPressureType
  445. monitor.ArterialPressure = monitorParam.ArterialPressure
  446. monitor.ArterialPressureType = monitorParam.ArterialPressureType
  447. monitor.TransmembranePressure = monitorParam.TransmembranePressure
  448. monitor.TransmembranePressureType = monitorParam.TransmembranePressureType
  449. monitor.UltrafiltrationRate = monitorParam.UltrafiltrationRate
  450. monitor.UltrafiltrationVolume = monitorParam.UltrafiltrationVolume
  451. monitor.SodiumConcentration = monitorParam.SodiumConcentration
  452. monitor.DialysateTemperature = monitorParam.DialysateTemperature
  453. monitor.Temperature = monitorParam.Temperature
  454. monitor.ReplacementRate = monitorParam.ReplacementRate
  455. monitor.DisplacementQuantity = monitorParam.DisplacementQuantity
  456. monitor.Conductivity = monitorParam.Conductivity
  457. monitor.DisplacementFlowQuantity = monitorParam.DisplacementFlowQuantity
  458. monitor.Ktv = monitorParam.KTV
  459. monitor.Symptom = monitorParam.Symptom
  460. monitor.Dispose = monitorParam.Dispose
  461. monitor.Result = monitorParam.Result
  462. monitor.MonitoringNurse = adminUserInfo.AdminUser.Id
  463. monitor.UpdatedTime = time.Now().Unix()
  464. monitor.Modify = adminUserInfo.AdminUser.Id
  465. monitor.BloodOxygenSaturation = monitorParam.BloodOxygenSaturation
  466. monitor.Heparin = monitorParam.Heparin
  467. monitor.DialysateFlow = monitorParam.DialysateFlow
  468. monitor.Urr = monitorParam.Urr
  469. monitor.BloodSugar = monitorParam.BloodSugar
  470. updateErr := service.UpdateMonitor(monitor)
  471. if updateErr != nil {
  472. this.ErrorLog("修改透析监测记录失败:%v", updateErr)
  473. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  474. return
  475. }
  476. this.ServeSuccessJSON(map[string]interface{}{
  477. "monitor": monitor,
  478. })
  479. }
  480. }
  481. // /api/dialysis/start_record [post]
  482. // @param patient_id:int
  483. // @param date:string 排班时间 (yyyy-mm-dd)
  484. // @param nurse:int 上机护士
  485. // @param bed:int 上机床位号
  486. func (this *DialysisRecordAPIController) StartDialysis() {
  487. patientID, _ := this.GetInt64("patient_id")
  488. recordDateStr := this.GetString("date")
  489. nurseID, _ := this.GetInt64("nurse")
  490. punctureNurseId, _ := this.GetInt64("puncture_nurse")
  491. startDateStr := this.GetString("start_time")
  492. blood_drawing, _ := this.GetInt64("blood_drawing")
  493. schedual_type, _ := this.GetInt64("schedual_type")
  494. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  495. bedID, _ := this.GetInt64("bed")
  496. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  498. return
  499. }
  500. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  501. if parseErr != nil {
  502. this.ErrorLog("时间解析失败:%v", parseErr)
  503. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  504. return
  505. }
  506. startDate, parseErr := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  507. if parseErr != nil {
  508. this.ErrorLog("时间解析失败:%v", parseErr)
  509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  510. return
  511. }
  512. adminUserInfo := this.GetAdminUserInfo()
  513. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  514. if getPatientErr != nil {
  515. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  517. return
  518. } else if patient == nil {
  519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  520. return
  521. }
  522. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  523. if getNurseErr != nil {
  524. this.ErrorLog("获取护士失败:%v", getNurseErr)
  525. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  526. return
  527. } else if nurse == nil {
  528. this.ErrorLog("护士不存在")
  529. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  530. return
  531. }
  532. nurse, getNurseErr = service.GetAdminUserByUserID(punctureNurseId)
  533. if getNurseErr != nil {
  534. this.ErrorLog("获取护士失败:%v", getNurseErr)
  535. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  536. return
  537. } else if nurse == nil {
  538. this.ErrorLog("护士不存在")
  539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  540. return
  541. }
  542. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  543. if getDeviceNumberErr != nil {
  544. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  546. return
  547. } else if deviceNumber == nil {
  548. this.ErrorLog("床位号不存在")
  549. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  550. return
  551. }
  552. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  553. if getRecordErr != nil {
  554. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  555. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  556. return
  557. } else if dialysisRecord != nil {
  558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  559. return
  560. }
  561. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  562. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  563. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  564. timeLayout := "2006-01-02 15:04:05"
  565. loc, _ := time.LoadLocation("Local")
  566. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  567. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  568. schedulestartTime := theStartTime.Unix()
  569. scheduleendTime := theEndTime.Unix()
  570. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  571. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  572. //查询该床位是否有人用了
  573. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  574. if err == gorm.ErrRecordNotFound { //空床位
  575. // 修改了床位逻辑
  576. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  577. if daySchedule.ID > 0 {
  578. daySchedule.PartitionId = deviceNumber.ZoneID
  579. daySchedule.BedId = bedID
  580. daySchedule.ScheduleType = schedual_type
  581. daySchedule.UpdatedTime = time.Now().Unix()
  582. err := service.UpdateSchedule(&daySchedule)
  583. if err != nil {
  584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  585. return
  586. }
  587. }
  588. } else if err == nil {
  589. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  590. if order_err == nil {
  591. if order.ID > 0 { //该机位被其他人占用了
  592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  593. return
  594. } else {
  595. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  596. if daySchedule.ID > 0 {
  597. daySchedule.PartitionId = deviceNumber.ZoneID
  598. daySchedule.BedId = bedID
  599. daySchedule.ScheduleType = schedual_type
  600. daySchedule.UpdatedTime = time.Now().Unix()
  601. err := service.UpdateSchedule(&daySchedule)
  602. if err != nil {
  603. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  604. return
  605. }
  606. }
  607. }
  608. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  609. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  610. if daySchedule.ID > 0 {
  611. daySchedule.PartitionId = deviceNumber.ZoneID
  612. daySchedule.BedId = bedID
  613. daySchedule.ScheduleType = schedual_type
  614. daySchedule.UpdatedTime = time.Now().Unix()
  615. err := service.UpdateSchedule(&daySchedule)
  616. if err != nil {
  617. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  618. return
  619. }
  620. }
  621. } else if order_err != nil {
  622. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  623. return
  624. }
  625. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  626. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  627. return
  628. }
  629. } else if err != nil {
  630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  631. return
  632. }
  633. dialysisRecord = &models.DialysisOrder{
  634. DialysisDate: recordDate.Unix(),
  635. UserOrgId: adminUserInfo.CurrentOrgId,
  636. PatientId: patientID,
  637. Stage: 1,
  638. BedID: bedID,
  639. StartNurse: nurseID,
  640. Status: 1,
  641. StartTime: startDate.Unix(),
  642. CreatedTime: time.Now().Unix(),
  643. UpdatedTime: time.Now().Unix(),
  644. PunctureNurse: punctureNurseId,
  645. Creator: adminUserInfo.AdminUser.Id,
  646. Modifier: adminUserInfo.AdminUser.Id,
  647. SchedualType: schedual_type,
  648. WashpipeNurse: washpipe_nurse,
  649. }
  650. createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
  651. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  652. if createErr != nil {
  653. this.ErrorLog("上机失败:%v", createErr)
  654. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  655. return
  656. } else if createErr == nil {
  657. var tempdispose string
  658. // 只针对中能建
  659. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 9538 { //adminUserInfo.CurrentOrgId == 9538
  660. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  661. }
  662. var ultrafiltration_rate float64
  663. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  664. if prescription.ID > 0 {
  665. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  666. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  667. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 {
  668. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  669. }
  670. // 只针对方济医院
  671. if template.TemplateId == 1 && adminUserInfo.CurrentOrgId != 9849 {
  672. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  673. ultrafiltration_rate = value
  674. }
  675. }
  676. }
  677. record := models.MonitoringRecord{
  678. UserOrgId: adminUserInfo.CurrentOrgId,
  679. PatientId: patientID,
  680. DialysisOrderId: dialysisRecord.ID,
  681. MonitoringDate: schedulestartTime,
  682. OperateTime: startDate.Unix(),
  683. // MonitoringTime: recordTime,
  684. MonitoringNurse: nurseID,
  685. Dispose: tempdispose,
  686. UltrafiltrationRate: ultrafiltration_rate,
  687. UltrafiltrationVolume: 0,
  688. Status: 1,
  689. CreatedTime: time.Now().Unix(),
  690. UpdatedTime: time.Now().Unix(),
  691. }
  692. // 如果当天有插入数据,则不再往透析纪录里插入数据
  693. if newdialysisRecord.ID > 0 {
  694. err := service.CreateMonitor(&record)
  695. if err != nil {
  696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  697. return
  698. }
  699. }
  700. go func (){
  701. ssoDomain := beego.AppConfig.String("call_domain")
  702. api := ssoDomain + "/index/uppatient"
  703. values := make(url.Values)
  704. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId,10))
  705. values.Set("admin_user_id", strconv.FormatInt(nurseID,10))
  706. values.Set("patient_id", strconv.FormatInt(patientID,10))
  707. values.Set("up_time", strconv.FormatInt(startDate.Unix(),10))
  708. http.PostForm(api, values)
  709. } ()
  710. this.ServeSuccessJSON(map[string]interface{}{
  711. "dialysis_order": dialysisRecord,
  712. "monitor": record,
  713. })
  714. }
  715. }
  716. // /api/dialysis/finish [post]
  717. // @param patient_id:int
  718. // @param date:string 排班时间 (yyyy-mm-dd)
  719. // @param nurse:int 下机护士
  720. func (this *DialysisRecordAPIController) FinishDialysis() {
  721. patientID, _ := this.GetInt64("patient_id")
  722. recordDateStr := this.GetString("date")
  723. nurseID, _ := this.GetInt64("nurse")
  724. end_time := this.GetString("end_time")
  725. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 {
  726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  727. return
  728. }
  729. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  730. if parseErr != nil {
  731. this.ErrorLog("时间解析失败:%v", parseErr)
  732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  733. return
  734. }
  735. //if parseEndDateErr != nil {
  736. // this.ErrorLog("时间解析失败:%v", parseEndDateErr)
  737. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  738. // return
  739. //}
  740. adminUserInfo := this.GetAdminUserInfo()
  741. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  742. if getPatientErr != nil {
  743. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  745. return
  746. } else if patient == nil {
  747. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  748. return
  749. }
  750. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  751. if getNurseErr != nil {
  752. this.ErrorLog("获取护士失败:%v", getNurseErr)
  753. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  754. return
  755. } else if nurse == nil {
  756. this.ErrorLog("护士不存在")
  757. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  758. return
  759. }
  760. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  761. if getRecordErr != nil {
  762. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  763. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  764. return
  765. }
  766. if dialysisRecord.Stage == 2 {
  767. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  768. return
  769. }
  770. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  771. if parseEndDateErr != nil {
  772. this.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  774. return
  775. }
  776. // 获取当天的第一条透析纪录
  777. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  778. if getMonitorRecordsErr != nil {
  779. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  781. return
  782. }
  783. // 获取当前的最后一条透析纪录
  784. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  785. if getMonitorRecordsErr != nil {
  786. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  788. return
  789. }
  790. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  791. if getAADErr != nil {
  792. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  794. return
  795. }
  796. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  797. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  798. if assessmentAfterDislysis != nil {
  799. tempassessmentAfterDislysis = *assessmentAfterDislysis
  800. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  801. } else {
  802. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  803. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  804. tempassessmentAfterDislysis.Status = 1
  805. tempassessmentAfterDislysis.PatientId = patientID
  806. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.CurrentOrgId
  807. }
  808. if dialysisRecord.Stage == 1 {
  809. temp_time := (float64(endDate.Unix()) - float64(dialysisRecord.StartTime)) / 3600
  810. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  811. fmt.Println(value)
  812. a, b := math.Modf(value)
  813. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  814. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  815. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  816. fmt.Println(hour)
  817. fmt.Println(minute)
  818. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  819. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  820. }
  821. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  822. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  823. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  824. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  825. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  826. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  827. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  828. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  829. }
  830. if adminUserInfo.CurrentOrgId == 9583 {
  831. //获取最后一条透析处方数据
  832. prescription, parseErr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  833. if parseErr != nil {
  834. this.ErrorLog("获取透析处方失败:%v", getMonitorRecordsErr)
  835. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  836. return
  837. }
  838. if prescription.ID > 0 && adminUserInfo.CurrentOrgId == 9583 {
  839. tempassessmentAfterDislysis.ActualUltrafiltration = prescription.TargetUltrafiltration
  840. }
  841. }
  842. if lastAssessmentAfterDislysis != nil {
  843. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  844. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  845. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  846. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  847. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  848. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  849. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  850. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  851. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  852. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  853. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  854. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  855. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  856. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  857. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  858. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  859. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  860. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  861. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  862. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  863. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  864. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  865. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  866. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  867. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  868. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  869. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  870. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  871. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  872. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  873. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  874. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  875. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  876. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  877. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  878. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  879. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  880. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  881. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  882. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  883. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  884. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  885. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  886. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  887. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  888. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  889. }
  890. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  891. if err != nil {
  892. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  893. return
  894. }
  895. go func (){
  896. ssoDomain := beego.AppConfig.String("call_domain")
  897. api := ssoDomain + "/index/downpatient"
  898. values := make(url.Values)
  899. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId,10))
  900. values.Set("admin_user_id", strconv.FormatInt(nurseID,10))
  901. values.Set("patient_id", strconv.FormatInt(patientID,10))
  902. http.PostForm(api, values)
  903. } ()
  904. updateErr := service.ModifyDialysisRecord(dialysisRecord.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  905. if updateErr != nil {
  906. this.ErrorLog("下机失败:%v", updateErr)
  907. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  908. return
  909. } else {
  910. dialysisRecord.Stage = 2
  911. dialysisRecord.FinishNurse = nurseID
  912. dialysisRecord.FinishCreator = adminUserInfo.AdminUser.Id
  913. dialysisRecord.FinishModifier = adminUserInfo.AdminUser.Id
  914. dialysisRecord.EndTime = endDate.Unix()
  915. // 结束时候透析次数加1
  916. service.UpdateSolutionByPatientId(patientID)
  917. this.ServeSuccessJSON(map[string]interface{}{
  918. "dialysis_order": dialysisRecord,
  919. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  920. })
  921. }
  922. }
  923. func (this *DialysisRecordAPIController) ModifyStartDialysis() {
  924. record_id, _ := this.GetInt64("id")
  925. nurseID, _ := this.GetInt64("nurse")
  926. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  927. bedID, _ := this.GetInt64("bed")
  928. start_time := this.GetString("start_time")
  929. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  930. schedual_type, _ := this.GetInt64("schedual_type")
  931. if record_id == 0 {
  932. this.ErrorLog("id:%v", record_id)
  933. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  934. return
  935. }
  936. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  937. if parseStartDateErr != nil {
  938. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  940. return
  941. }
  942. adminUserInfo := this.GetAdminUserInfo()
  943. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  944. if getNurseErr != nil {
  945. this.ErrorLog("获取护士失败:%v", getNurseErr)
  946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  947. return
  948. } else if nurse == nil {
  949. this.ErrorLog("护士不存在")
  950. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  951. return
  952. }
  953. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  954. if getNurseErr != nil {
  955. this.ErrorLog("获取护士失败:%v", getNurseErr)
  956. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  957. return
  958. } else if nurse == nil {
  959. this.ErrorLog("护士不存在")
  960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  961. return
  962. }
  963. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  964. if getDeviceNumberErr != nil {
  965. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  966. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  967. return
  968. } else if deviceNumber == nil {
  969. this.ErrorLog("床位号不存在")
  970. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  971. return
  972. }
  973. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  974. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  975. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  976. // if getPermissionErr != nil {
  977. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  978. // return
  979. // } else if headNursePermission == nil {
  980. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  981. // return
  982. // }
  983. //}
  984. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  985. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  986. timeLayout := "2006-01-02 15:04:05"
  987. loc, _ := time.LoadLocation("Local")
  988. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  989. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  990. schedulestartTime := theStartTime.Unix()
  991. scheduleendTime := theEndTime.Unix()
  992. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  993. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  994. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  995. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  996. if err == gorm.ErrRecordNotFound { //空床位
  997. // 修改了床位逻辑
  998. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  999. if daySchedule.ID > 0 {
  1000. daySchedule.BedId = bedID
  1001. daySchedule.PartitionId = deviceNumber.ZoneID
  1002. daySchedule.ScheduleType = schedual_type
  1003. daySchedule.UpdatedTime = time.Now().Unix()
  1004. err := service.UpdateSchedule(&daySchedule)
  1005. if err != nil {
  1006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1007. return
  1008. }
  1009. }
  1010. } else if err == nil {
  1011. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1012. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1013. if daySchedule.ID > 0 {
  1014. daySchedule.BedId = bedID
  1015. daySchedule.PartitionId = deviceNumber.ZoneID
  1016. daySchedule.ScheduleType = schedual_type
  1017. daySchedule.UpdatedTime = time.Now().Unix()
  1018. err := service.UpdateSchedule(&daySchedule)
  1019. if err != nil {
  1020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1021. return
  1022. }
  1023. }
  1024. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1025. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1026. return
  1027. }
  1028. } else if err != nil {
  1029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1030. return
  1031. }
  1032. }
  1033. dialysisRecord := &models.DialysisOrder{
  1034. ID: record_id,
  1035. UserOrgId: adminUserInfo.CurrentOrgId,
  1036. BedID: bedID,
  1037. StartNurse: nurseID,
  1038. StartTime: startDate.Unix(),
  1039. PunctureNurse: puncture_nurse,
  1040. Creator: adminUserInfo.AdminUser.Id,
  1041. Modifier: adminUserInfo.AdminUser.Id,
  1042. SchedualType: schedual_type,
  1043. WashpipeNurse: washpipe_nurse,
  1044. }
  1045. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  1046. if updateErr != nil {
  1047. this.ErrorLog("修改上机失败:%v", updateErr)
  1048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1049. return
  1050. }
  1051. if updateErr == nil {
  1052. if tempDialysisRecord.Stage == 2 {
  1053. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  1054. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1055. fmt.Println(value)
  1056. a, b := math.Modf(value)
  1057. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1058. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1059. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1060. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  1061. if updateAssessmentErr != nil {
  1062. utils.ErrorLog("%v", updateAssessmentErr)
  1063. }
  1064. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecord.UserOrgId, tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  1065. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1066. this.ServeSuccessJSON(map[string]interface{}{
  1067. "dialysis_order": dialysisRecords,
  1068. "after": after,
  1069. })
  1070. } else {
  1071. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1072. this.ServeSuccessJSON(map[string]interface{}{
  1073. "dialysis_order": dialysisRecords,
  1074. })
  1075. }
  1076. }
  1077. }
  1078. func (c *DialysisRecordAPIController) ModifyFinishDialysis() {
  1079. record_id, _ := c.GetInt64("id")
  1080. nurseID, _ := c.GetInt64("nurse")
  1081. end_time := c.GetString("end_time")
  1082. if record_id <= 0 || nurseID <= 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1084. return
  1085. }
  1086. adminUserInfo := c.GetAdminUserInfo()
  1087. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1088. if getNurseErr != nil {
  1089. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1091. return
  1092. } else if nurse == nil {
  1093. c.ErrorLog("护士不存在")
  1094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1095. return
  1096. }
  1097. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1098. if parseEndDateErr != nil {
  1099. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1101. return
  1102. }
  1103. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  1104. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  1105. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1106. // if getPermissionErr != nil {
  1107. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1108. // return
  1109. // } else if headNursePermission == nil {
  1110. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1111. // return
  1112. // }
  1113. //}
  1114. dialysisRecord := &models.DialysisOrder{
  1115. ID: record_id,
  1116. UserOrgId: adminUserInfo.CurrentOrgId,
  1117. EndTime: endDate.Unix(),
  1118. FinishNurse: nurseID,
  1119. FinishModifier: adminUserInfo.AdminUser.Id,
  1120. }
  1121. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  1122. if updateErr != nil {
  1123. c.ErrorLog("修改下机失败:%v", updateErr)
  1124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1125. return
  1126. }
  1127. if updateErr == nil {
  1128. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  1129. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1130. fmt.Println(value)
  1131. a, b := math.Modf(value)
  1132. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1133. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1134. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1135. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  1136. if updateAssessmentErr != nil {
  1137. utils.ErrorLog("%v", updateAssessmentErr)
  1138. }
  1139. }
  1140. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1141. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1142. c.ServeSuccessJSON(map[string]interface{}{
  1143. "dialysis_order": dialysisRecords,
  1144. "after": after,
  1145. })
  1146. }