dialysis_record_api_controller.go 52KB

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