dialysis_record_api_controller.go 56KB

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