dialysis_record_api_controller.go 55KB

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