dialysis_record_api_controller.go 57KB

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