dialysis_record_api_controller.go 55KB

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