dialysis_record_api_controller.go 75KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807
  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. redis := service.RedisClient()
  65. defer redis.Close()
  66. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  67. patients, _ := service.GetAllPcPatientListByListEight(orgID)
  68. scheduals_json_str, _ := redis.Get(key).Result()
  69. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  70. scheduals, err := service.GetDialysisSchedualsOne(orgID, date.Unix())
  71. if err != nil {
  72. this.ErrorLog("获取排班信息失败:%v", err)
  73. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  74. } else {
  75. if len(scheduals) > 0 {
  76. dialysisOrders, _ := service.GetAllPcDialysisOrdersByList(orgID, date.Unix())
  77. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  78. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  79. treatmentSummarys, _ := service.GetAllPcTreatmentSummarysByList(orgID, date.Unix())
  80. AssessmentAfterDislysis, _ := service.GetAllPcAssessmentAfterDislysisByList(orgID, date.Unix())
  81. advices, _ := service.GetAllPcAdvicestByList(orgID, date.Unix())
  82. for key, item := range scheduals {
  83. // 获取患者信息
  84. for _, patient := range patients {
  85. if item.PatientId == patient.ID {
  86. scheduals[key].SchedualPatient = patient
  87. break
  88. }
  89. }
  90. for _, advice := range advices {
  91. if item.PatientId == advice.PatientId {
  92. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  93. }
  94. }
  95. // 医嘱信息
  96. for _, prescription := range prescriptions {
  97. if item.PatientId == prescription.PatientId {
  98. scheduals[key].Prescription = prescription
  99. break
  100. }
  101. }
  102. // 透前评估
  103. for _, assessmentBefore := range assessmentBefores {
  104. if item.PatientId == assessmentBefore.PatientId {
  105. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  106. break
  107. }
  108. }
  109. // 透析上下机
  110. for _, dialysisOrder := range dialysisOrders {
  111. if item.PatientId == dialysisOrder.PatientId {
  112. scheduals[key].DialysisOrder = dialysisOrder
  113. break
  114. }
  115. }
  116. // 治疗小节
  117. for _, afterDislysis := range AssessmentAfterDislysis {
  118. if item.PatientId == afterDislysis.PatientId {
  119. scheduals[key].AssessmentAfterDislysis = afterDislysis
  120. break
  121. }
  122. }
  123. // 透后评估
  124. for _, treatmentSummary := range treatmentSummarys {
  125. if item.PatientId == treatmentSummary.PatientId {
  126. scheduals[key].TreatmentSummary = treatmentSummary
  127. break
  128. }
  129. }
  130. }
  131. //缓存数据
  132. scheduals_json, err := json.Marshal(&scheduals)
  133. if err == nil {
  134. redis.Set(key, scheduals_json, time.Second*60)
  135. }
  136. }
  137. _, errcodes := service.GetOrgFollowIsExist(orgID)
  138. if errcodes == gorm.ErrRecordNotFound {
  139. information, _ := service.GetAdminUserRoleInformation(0)
  140. this.ServeSuccessJSON(map[string]interface{}{
  141. "schedules": scheduals,
  142. "information": information,
  143. })
  144. } else if errcodes == nil {
  145. information, _ := service.GetAdminUserRoleInformation(orgID)
  146. this.ServeSuccessJSON(map[string]interface{}{
  147. "schedules": scheduals,
  148. "information": information,
  149. })
  150. }
  151. }
  152. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  153. var dat []map[string]interface{}
  154. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  155. } else {
  156. }
  157. _, errcodes := service.GetOrgFollowIsExist(orgID)
  158. if errcodes == gorm.ErrRecordNotFound {
  159. information, _ := service.GetAdminUserRoleInformation(0)
  160. this.ServeSuccessJSON(map[string]interface{}{
  161. "schedules": dat,
  162. "information": information,
  163. })
  164. } else if errcodes == nil {
  165. information, _ := service.GetAdminUserRoleInformation(orgID)
  166. this.ServeSuccessJSON(map[string]interface{}{
  167. "schedules": dat,
  168. "information": information,
  169. })
  170. }
  171. }
  172. //if err != nil {
  173. // this.ErrorLog("获取排班信息失败:%v", err)
  174. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  175. //} else {
  176. // this.ServeSuccessJSON(map[string]interface{}{
  177. // "schedules": schedules,
  178. // })
  179. //}
  180. }
  181. // /api/dislysis/schedule [get]
  182. // @param patient_id:int
  183. // @param date:string (yyyy-MM-dd)
  184. func (this *DialysisRecordAPIController) DialysisSchedule() {
  185. patientID, _ := this.GetInt64("patient_id")
  186. recordDateStr := this.GetString("date")
  187. if patientID <= 0 {
  188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  189. return
  190. }
  191. if len(recordDateStr) == 0 {
  192. recordDateStr = time.Now().Format("2006-01-02")
  193. }
  194. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  195. if parseDateErr != nil {
  196. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. adminInfo := this.GetAdminUserInfo()
  201. ch := make(chan struct{})
  202. count := 15 // count 表示活动的协程个数
  203. var patient *service.MPatient
  204. var schedual *service.MDialysisScheduleVM
  205. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  206. var predialysisEvaluation *models.PredialysisEvaluation
  207. var doctorAdvices []*models.DoctorAdvice
  208. var dialysisOrder *models.DialysisOrder
  209. var doubleCheck *models.DoubleCheck
  210. var monitorRecords []*models.MonitoringRecord
  211. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  212. var treatmentSummary *models.TreatmentSummary
  213. var record models.GobalConfig
  214. var is_open_config models.XtHisConfig
  215. var stockType []*models.GoodsTypeOne
  216. var prepare []*models.XtDialysisBeforePrepare
  217. var lastAssessment models.XtPatientVascularAccess
  218. go func() {
  219. patient, _ = service.MobileGetPatientDetail(adminInfo.CurrentOrgId, patientID)
  220. ch <- struct{}{}
  221. }()
  222. go func() {
  223. schedual, _ = service.MobileGetSchedualDetail(adminInfo.CurrentOrgId, patientID, date.Unix())
  224. ch <- struct{}{}
  225. }()
  226. go func() {
  227. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  228. ch <- struct{}{}
  229. }()
  230. go func() {
  231. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.CurrentOrgId, patientID, date.Unix())
  232. ch <- struct{}{}
  233. }()
  234. go func() {
  235. doctorAdvices, _ = service.MobileGetDoctorAdvices(adminInfo.CurrentOrgId, patientID, date.Unix())
  236. ch <- struct{}{}
  237. }()
  238. go func() {
  239. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  240. ch <- struct{}{}
  241. }()
  242. go func() {
  243. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.CurrentOrgId, patientID, date.Unix())
  244. ch <- struct{}{}
  245. }()
  246. go func() {
  247. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.CurrentOrgId, patientID, date.Unix())
  248. ch <- struct{}{}
  249. }()
  250. go func() {
  251. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.CurrentOrgId, patientID, date.Unix())
  252. ch <- struct{}{}
  253. }()
  254. go func() {
  255. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.CurrentOrgId, patientID, date.Unix())
  256. ch <- struct{}{}
  257. }()
  258. go func() {
  259. _, record = service.FindAutomaticReduceRecordByOrgId(adminInfo.CurrentOrgId)
  260. ch <- struct{}{}
  261. }()
  262. go func() {
  263. _, is_open_config = service.FindXTHisRecordByOrgId(adminInfo.CurrentOrgId)
  264. ch <- struct{}{}
  265. }()
  266. go func() {
  267. //获取耗材类型
  268. stockType, _ = service.GetStockType(adminInfo.CurrentOrgId)
  269. ch <- struct{}{}
  270. }()
  271. go func() {
  272. prepare, _ = service.GetDialyStockOut(adminInfo.CurrentOrgId, date.Unix(), patientID)
  273. ch <- struct{}{}
  274. }()
  275. go func() {
  276. //获取患者的最后一次血管通路数据
  277. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.CurrentOrgId, patientID)
  278. ch <- struct{}{}
  279. }()
  280. for range ch {
  281. // 每次从ch中接收数据,表明一个活动的协程结束
  282. count--
  283. // 当所有活动的协程都结束时,关闭管道
  284. if count == 0 {
  285. close(ch)
  286. }
  287. }
  288. admins, getAdminsErr := service.GetAllAdminUsers(adminInfo.CurrentOrgId, adminInfo.CurrentAppId)
  289. if getAdminsErr != nil {
  290. this.ErrorLog("获取医护列表失败:%v", getAdminsErr)
  291. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  292. return
  293. }
  294. devices, getDevicesErr := service.GetValidDevicesBy(adminInfo.CurrentOrgId, 0, 0)
  295. if getDevicesErr != nil {
  296. this.ErrorLog("获取设备列表失败:%v", getDevicesErr)
  297. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  298. return
  299. }
  300. deviceNumbers, getDeviceNumbersErr := service.GetAllValidDeviceNumbers(adminInfo.CurrentOrgId)
  301. if getDeviceNumbersErr != nil {
  302. this.ErrorLog("获取床位号列表失败:%v", getDeviceNumbersErr)
  303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  304. return
  305. }
  306. lastPredialysisEvaluation, getLPEErr := service.GetLastTimePredialysisEvaluation(adminInfo.CurrentOrgId, patientID, date.Unix())
  307. if getLPEErr != nil {
  308. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  309. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  310. return
  311. }
  312. var lastMonitorRecord *models.MonitoringRecord
  313. lastMonitorRecord, getLastErr := service.GetLastMonitorRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  314. if getLastErr != nil {
  315. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  317. return
  318. }
  319. lastAssessmentAfterDislysis, getLAADErr := service.GetLastTimeAssessmentAfterDislysis(adminInfo.CurrentOrgId, patientID, date.Unix())
  320. if getLAADErr != nil {
  321. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  323. return
  324. }
  325. dialysisPrescribe, _ := service.GetDialysisPrescribe(adminInfo.CurrentOrgId, patientID, date.Unix())
  326. dialysisSolution, _ := service.GetDialysisSolution(adminInfo.CurrentOrgId, patientID, schedual.ModeId)
  327. lastDialysisPrescribe, _ := service.GetLastDialysisPrescribeByModeId(adminInfo.CurrentOrgId, patientID, schedual.ModeId)
  328. systemDialysisPrescribe, _ := service.GetSystemDialysisPrescribeByModeId(adminInfo.CurrentOrgId, schedual.ModeId)
  329. lastDryWeightDislysis, getDryErr := service.GetLastDryWeight(adminInfo.CurrentOrgId, patientID)
  330. if getDryErr != nil {
  331. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  332. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  333. return
  334. }
  335. headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  336. var his_advices []*models.HisDoctorAdviceInfo
  337. if is_open_config.IsOpen == 1 {
  338. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.CurrentOrgId, patientID, date.Unix())
  339. }
  340. //查询是否是开起
  341. adviceConfig, _ := service.FindAdviceSettingById(adminInfo.CurrentOrgId)
  342. if adviceConfig.IsAdviceOpen == 1 {
  343. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.CurrentOrgId, patientID, date.Unix())
  344. }
  345. _, errcode := service.GetOrgFollowIsExist(adminInfo.CurrentOrgId)
  346. if errcode == gorm.ErrRecordNotFound {
  347. information, _ := service.GetAdminUserRoleInformation(0)
  348. returnData := map[string]interface{}{
  349. "patient": patient,
  350. "schedual": schedual,
  351. "prescription": dialysisPrescribe,
  352. "solution": dialysisSolution,
  353. "receiver_treatment_access": receiverTreatmentAccess,
  354. "predialysis_evaluation": predialysisEvaluation,
  355. "doctor_advices": doctorAdvices,
  356. "double_check": doubleCheck,
  357. "assessment_after_dislysis": assessmentAfterDislysis,
  358. "treatment_summary": treatmentSummary,
  359. "monitor_records": monitorRecords,
  360. "dialysis_order": dialysisOrder,
  361. "doctors": admins,
  362. "config": record,
  363. "devices": devices,
  364. "device_numbers": deviceNumbers,
  365. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  366. "lastMonitorRecord": lastMonitorRecord,
  367. "lastAssessmentAfterDislysis": lastAssessmentAfterDislysis,
  368. "lastDialysisPrescribe": lastDialysisPrescribe,
  369. "lastDryWeightDislysis": lastDryWeightDislysis,
  370. "headNurses": headNurses,
  371. "system_prescribe": systemDialysisPrescribe,
  372. "his_advices": his_advices,
  373. "is_open_config": is_open_config,
  374. "stockType": stockType,
  375. "prepare": prepare,
  376. "lastAssessment": lastAssessment,
  377. "information": information,
  378. "is_advice_open": adviceConfig,
  379. }
  380. this.ServeSuccessJSON(returnData)
  381. } else if errcode == nil {
  382. information, _ := service.GetAdminUserRoleInformation(adminInfo.CurrentOrgId)
  383. returnData := map[string]interface{}{
  384. "patient": patient,
  385. "schedual": schedual,
  386. "prescription": dialysisPrescribe,
  387. "solution": dialysisSolution,
  388. "receiver_treatment_access": receiverTreatmentAccess,
  389. "predialysis_evaluation": predialysisEvaluation,
  390. "doctor_advices": doctorAdvices,
  391. "double_check": doubleCheck,
  392. "assessment_after_dislysis": assessmentAfterDislysis,
  393. "treatment_summary": treatmentSummary,
  394. "monitor_records": monitorRecords,
  395. "dialysis_order": dialysisOrder,
  396. "doctors": admins,
  397. "config": record,
  398. "devices": devices,
  399. "device_numbers": deviceNumbers,
  400. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  401. "lastMonitorRecord": lastMonitorRecord,
  402. "lastAssessmentAfterDislysis": lastAssessmentAfterDislysis,
  403. "lastDialysisPrescribe": lastDialysisPrescribe,
  404. "lastDryWeightDislysis": lastDryWeightDislysis,
  405. "headNurses": headNurses,
  406. "system_prescribe": systemDialysisPrescribe,
  407. "his_advices": his_advices,
  408. "is_open_config": is_open_config,
  409. "stockType": stockType,
  410. "prepare": prepare,
  411. "lastAssessment": lastAssessment,
  412. "information": information,
  413. "is_advice_open": adviceConfig,
  414. }
  415. this.ServeSuccessJSON(returnData)
  416. }
  417. }
  418. type EditMonitorParamObject struct {
  419. ID int64 `json:"id"`
  420. MonitoringDate int64 `json:"monitoring_date"`
  421. OperateTime int64 `json:"operate_time"`
  422. // MonitoringTime string `json:"monitoring_time"`
  423. SystolicBP float64 `json:"systolic_bp"`
  424. DiastolicBP float64 `json:"diastolic_bp"`
  425. PulseFrequency float64 `json:"pulse_frequency"`
  426. BreathingRated string `json:"breathing_rated"`
  427. BloodFlowVolume float64 `json:"blood_flow_volume"`
  428. VenousPressure float64 `json:"venous_pressure"`
  429. VenousPressureType int64 `json:"venous_pressure_type"`
  430. TransmembranePressure float64 `json:"transmembrane_pressure"`
  431. TransmembranePressureType int64 `json:"transmembrane_pressure_type"`
  432. UltrafiltrationVolume float64 `json:"ultrafiltration_volume"`
  433. UltrafiltrationRate float64 `json:"ultrafiltration_rate"`
  434. ArterialPressure float64 `json:"arterial_pressure"`
  435. ArterialPressureType int64 `json:"arterial_pressure_type"`
  436. SodiumConcentration float64 `json:"sodium_concentration"`
  437. DialysateTemperature float64 `json:"dialysate_temperature"`
  438. Temperature float64 `json:"temperature"`
  439. ReplacementRate float64 `json:"replacement_rate"`
  440. DisplacementQuantity float64 `json:"displacement_quantity"`
  441. KTV float64 `json:"ktv"`
  442. Symptom string `json:"symptom"`
  443. Dispose string `json:"dispose"`
  444. Result string `json:"result"`
  445. Conductivity float64 `json:"conductivity"`
  446. DisplacementFlowQuantity float64 `json:"displacement_flow_quantity"`
  447. BloodOxygenSaturation string `gorm:"column:blood_oxygen_saturation" json:"blood_oxygen_saturation" form:"blood_oxygen_saturation"`
  448. Heparin float64 `gorm:"column:heparin" json:"heparin" form:"heparin"`
  449. DialysateFlow float64 `gorm:"column:dialysate_flow" json:"dialysate_flow" form:"dialysate_flow"`
  450. Urr string `gorm:"column:urr" json:"urr" form:"urr"`
  451. BloodSugar float64 `gorm:"column:blood_sugar" json:"blood_sugar" form:"blood_sugar"`
  452. MonitorAnticoagulant int64 `gorm:"column:monitor_anticoagulant" json:"monitor_anticoagulant" form:"monitor_anticoagulant"`
  453. MonitorAnticoagulantValue string `gorm:"column:monitor_anticoagulant_value" json:"monitor_anticoagulant_value" form:"monitor_anticoagulant_value"`
  454. BloodPressureMonitoringSite int64 `gorm:"column:blood_pressure_monitoring_site" json:"blood_pressure_monitoring_site" form:"blood_pressure_monitoring_site"`
  455. Complication int64 `gorm:"column:complication" json:"complication" form:"complication"`
  456. AccumulatedBloodVolume float64 `gorm:"column:accumulated_blood_volume" json:"accumulated_blood_volume" form:"accumulated_blood_volume"`
  457. BloodTemperature float64 `gorm:"column:blood_temperature" json:"blood_temperature" form:"blood_temperature"`
  458. UreaMonitoring float64 `gorm:"column:urea_monitoring" json:"urea_monitoring" form:"urea_monitoring"`
  459. BloodThickness float64 `gorm:"column:blood_thickness" json:"blood_thickness" form:"blood_thickness"`
  460. BloodMonitor float64 `gorm:"column:blood_monitor" json:"blood_monitor" form:"blood_monitor"`
  461. HeparinAmount float64 `gorm:"column:heparin_amount" json:"heparin_amount" form:"heparin_amount"`
  462. Dehydration float64 `gorm:"column:dehydration" json:"dehydration" form:"dehydration"`
  463. }
  464. // /api/dislysis/monitor/edit [post]
  465. // @param patient_id:int 患者id
  466. // @param schedule_date:int 排班日期
  467. // 下面的参数放到 body
  468. // @param id?:int 监测记录ID(id为0时为创建记录,不为0时为修改记录)
  469. // @param monitoring_date:int 排班日期
  470. // @param operate_time:int 实际测量日期
  471. // @param monitoring_time:string (HH:mm) 监测时间 废弃
  472. // @param systolic_bp?:float 收缩压
  473. // @param diastolic_bp?:float 舒张压
  474. // @param pulse_frequency?:float 心率
  475. // @param breathing_rated?:float 呼吸频率
  476. // @param blood_flow_volume?:float 血流量
  477. // @param venous_pressure?:float 静脉压
  478. // @param transmembrane_pressure?:float 跨膜压
  479. // @param ultrafiltration_volume?:float 超滤量
  480. // @param ultrafiltration_rate?:float 超滤率
  481. // @param arterial_pressure?:float 动脉压
  482. // @param sodium_concentration?:float 钠浓度
  483. // @param dialysate_temperature?:float 透析液温度
  484. // @param replacement_rate?:float 置换率
  485. // @param displacement_quantity?:float 置换量
  486. // @param ktv?:float KT/V
  487. // @param symptom?:string 病情变化
  488. // @param dispose?:string 处理
  489. // @param result?:string 结果
  490. func (this *DialysisRecordAPIController) EditMonitor() {
  491. patientID, _ := this.GetInt64("patient_id")
  492. scheduleDate, _ := this.GetInt64("schedule_date")
  493. if patientID <= 0 || scheduleDate <= 0 {
  494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  495. return
  496. }
  497. var monitorParam EditMonitorParamObject
  498. if parseErr := json.Unmarshal(this.Ctx.Input.RequestBody, &monitorParam); parseErr != nil {
  499. this.ErrorLog("参数解析失败:%v", parseErr)
  500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  501. return
  502. }
  503. if monitorParam.MonitoringDate != scheduleDate {
  504. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  505. return
  506. }
  507. adminUserInfo := this.GetAdminUserInfo()
  508. schedule, getScheduleErr := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  509. if getScheduleErr != nil {
  510. this.ErrorLog("获取排班信息失败:%v", getScheduleErr)
  511. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  512. return
  513. } else if schedule == nil {
  514. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  515. return
  516. }
  517. // TODO 其实这里合理的逻辑是“透析记录存在的情况下才能添加监测记录的”
  518. dialysisOrder, getDialysisOrderErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  519. if getDialysisOrderErr != nil {
  520. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  522. return
  523. }
  524. orderID := int64(0)
  525. if dialysisOrder != nil {
  526. orderID = dialysisOrder.ID
  527. }
  528. if monitorParam.ID <= 0 { // 新建记录
  529. monitor := models.MonitoringRecord{
  530. UserOrgId: adminUserInfo.CurrentOrgId,
  531. PatientId: patientID,
  532. DialysisOrderId: orderID,
  533. MonitoringDate: monitorParam.MonitoringDate,
  534. OperateTime: monitorParam.OperateTime,
  535. // MonitoringTime: monitorParam.MonitoringTime,
  536. PulseFrequency: monitorParam.PulseFrequency,
  537. BreathingRate: monitorParam.BreathingRated,
  538. SystolicBloodPressure: monitorParam.SystolicBP,
  539. DiastolicBloodPressure: monitorParam.DiastolicBP,
  540. BloodFlowVolume: monitorParam.BloodFlowVolume,
  541. VenousPressure: monitorParam.VenousPressure,
  542. VenousPressureType: monitorParam.VenousPressureType,
  543. ArterialPressure: monitorParam.ArterialPressure,
  544. ArterialPressureType: monitorParam.ArterialPressureType,
  545. TransmembranePressure: monitorParam.TransmembranePressure,
  546. TransmembranePressureType: monitorParam.TransmembranePressureType,
  547. UltrafiltrationRate: monitorParam.UltrafiltrationRate,
  548. UltrafiltrationVolume: monitorParam.UltrafiltrationVolume,
  549. SodiumConcentration: monitorParam.SodiumConcentration,
  550. DialysateTemperature: monitorParam.DialysateTemperature,
  551. Temperature: monitorParam.Temperature,
  552. ReplacementRate: monitorParam.ReplacementRate,
  553. DisplacementQuantity: monitorParam.DisplacementQuantity,
  554. Ktv: monitorParam.KTV,
  555. Symptom: monitorParam.Symptom,
  556. Dispose: monitorParam.Dispose,
  557. Result: monitorParam.Result,
  558. MonitoringNurse: adminUserInfo.AdminUser.Id,
  559. Conductivity: monitorParam.Conductivity,
  560. DisplacementFlowQuantity: monitorParam.DisplacementFlowQuantity,
  561. Status: 1,
  562. CreatedTime: time.Now().Unix(),
  563. UpdatedTime: time.Now().Unix(),
  564. BloodOxygenSaturation: monitorParam.BloodOxygenSaturation,
  565. Creator: adminUserInfo.AdminUser.Id,
  566. Heparin: monitorParam.Heparin,
  567. DialysateFlow: monitorParam.DialysateFlow,
  568. Urr: monitorParam.Urr,
  569. BloodSugar: monitorParam.BloodSugar,
  570. MonitorAnticoagulant: monitorParam.MonitorAnticoagulant,
  571. MonitorAnticoagulantValue: monitorParam.MonitorAnticoagulantValue,
  572. BloodPressureMonitoringSite: monitorParam.BloodPressureMonitoringSite,
  573. Complication: monitorParam.Complication,
  574. AccumulatedBloodVolume: monitorParam.AccumulatedBloodVolume,
  575. BloodTemperature: monitorParam.BloodTemperature,
  576. UreaMonitoring: monitorParam.UreaMonitoring,
  577. BloodThickness: monitorParam.BloodThickness,
  578. BloodMonitor: monitorParam.BloodMonitor,
  579. HeparinAmount: monitorParam.HeparinAmount,
  580. Dehydration: monitorParam.Dehydration,
  581. }
  582. createErr := service.CreateMonitor(&monitor)
  583. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
  584. redis := service.RedisClient()
  585. //清空key 值
  586. redis.Set(key, "", time.Second)
  587. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitorParam.MonitoringDate, 10) + ":monitor_record_list_all"
  588. redis.Set(keyOne, "", time.Second)
  589. defer redis.Close()
  590. if createErr != nil {
  591. this.ErrorLog("创建监测记录失败:%v", createErr)
  592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  593. return
  594. }
  595. this.ServeSuccessJSON(map[string]interface{}{
  596. "monitor": monitor,
  597. })
  598. } else { // 修改记录
  599. monitor, getMonitorErr := service.GetMonitor(adminUserInfo.CurrentOrgId, patientID, monitorParam.ID)
  600. if getMonitorErr != nil {
  601. this.ErrorLog("获取透析监测记录失败:%v", getMonitorErr)
  602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  603. return
  604. } else if monitor == nil {
  605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorNotExist)
  606. return
  607. }
  608. //if monitor.MonitoringNurse != adminUserInfo.AdminUser.Id {
  609. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  610. // if getPermissionErr != nil {
  611. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  612. // return
  613. // } else if headNursePermission == nil {
  614. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  615. // return
  616. // }
  617. //}
  618. monitor.OperateTime = monitorParam.OperateTime
  619. monitor.PulseFrequency = monitorParam.PulseFrequency
  620. monitor.BreathingRate = monitorParam.BreathingRated
  621. monitor.SystolicBloodPressure = monitorParam.SystolicBP
  622. monitor.DiastolicBloodPressure = monitorParam.DiastolicBP
  623. monitor.BloodFlowVolume = monitorParam.BloodFlowVolume
  624. monitor.VenousPressure = monitorParam.VenousPressure
  625. monitor.VenousPressureType = monitorParam.VenousPressureType
  626. monitor.ArterialPressure = monitorParam.ArterialPressure
  627. monitor.ArterialPressureType = monitorParam.ArterialPressureType
  628. monitor.TransmembranePressure = monitorParam.TransmembranePressure
  629. monitor.TransmembranePressureType = monitorParam.TransmembranePressureType
  630. monitor.UltrafiltrationRate = monitorParam.UltrafiltrationRate
  631. monitor.UltrafiltrationVolume = monitorParam.UltrafiltrationVolume
  632. monitor.SodiumConcentration = monitorParam.SodiumConcentration
  633. monitor.DialysateTemperature = monitorParam.DialysateTemperature
  634. monitor.Temperature = monitorParam.Temperature
  635. monitor.ReplacementRate = monitorParam.ReplacementRate
  636. monitor.DisplacementQuantity = monitorParam.DisplacementQuantity
  637. monitor.Conductivity = monitorParam.Conductivity
  638. monitor.DisplacementFlowQuantity = monitorParam.DisplacementFlowQuantity
  639. monitor.Ktv = monitorParam.KTV
  640. monitor.Symptom = monitorParam.Symptom
  641. monitor.Dispose = monitorParam.Dispose
  642. monitor.Result = monitorParam.Result
  643. monitor.MonitoringNurse = adminUserInfo.AdminUser.Id
  644. monitor.UpdatedTime = time.Now().Unix()
  645. monitor.Modify = adminUserInfo.AdminUser.Id
  646. monitor.BloodOxygenSaturation = monitorParam.BloodOxygenSaturation
  647. monitor.Heparin = monitorParam.Heparin
  648. monitor.DialysateFlow = monitorParam.DialysateFlow
  649. monitor.Urr = monitorParam.Urr
  650. monitor.BloodSugar = monitorParam.BloodSugar
  651. monitor.MonitorAnticoagulant = monitorParam.MonitorAnticoagulant
  652. monitor.MonitorAnticoagulantValue = monitorParam.MonitorAnticoagulantValue
  653. monitor.AccumulatedBloodVolume = monitorParam.AccumulatedBloodVolume
  654. monitor.BloodTemperature = monitorParam.BloodTemperature
  655. monitor.UreaMonitoring = monitorParam.UreaMonitoring
  656. monitor.BloodThickness = monitorParam.BloodThickness
  657. monitor.BloodMonitor = monitorParam.BloodMonitor
  658. monitor.HeparinAmount = monitorParam.HeparinAmount
  659. monitor.Dehydration = monitorParam.Dehydration
  660. updateErr := service.UpdateMonitor(monitor)
  661. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":monitor_records"
  662. redis := service.RedisClient()
  663. defer redis.Close()
  664. //清空key 值
  665. redis.Set(key, "", time.Second)
  666. if updateErr != nil {
  667. this.ErrorLog("修改透析监测记录失败:%v", updateErr)
  668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  669. return
  670. }
  671. this.ServeSuccessJSON(map[string]interface{}{
  672. "monitor": monitor,
  673. })
  674. }
  675. }
  676. // /api/dialysis/start_record [post]
  677. // @param patient_id:int
  678. // @param date:string 排班时间 (yyyy-mm-dd)
  679. // @param nurse:int 上机护士
  680. // @param bed:int 上机床位号
  681. func (this *DialysisRecordAPIController) StartDialysis() {
  682. patientID, _ := this.GetInt64("patient_id")
  683. recordDateStr := this.GetString("date")
  684. nurseID, _ := this.GetInt64("nurse")
  685. punctureNurseId, _ := this.GetInt64("puncture_nurse")
  686. startDateStr := this.GetString("start_time")
  687. blood_drawing, _ := this.GetInt64("blood_drawing")
  688. schedual_type, _ := this.GetInt64("schedual_type")
  689. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  690. change_nurse, _ := this.GetInt64("change_nurse")
  691. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  692. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  693. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  694. bedID, _ := this.GetInt64("bed")
  695. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  697. return
  698. }
  699. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  700. if parseErr != nil {
  701. this.ErrorLog("时间解析失败:%v", parseErr)
  702. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  703. return
  704. }
  705. startDate, parseErr := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  706. if parseErr != nil {
  707. this.ErrorLog("时间解析失败:%v", parseErr)
  708. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  709. return
  710. }
  711. adminUserInfo := this.GetAdminUserInfo()
  712. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  713. if getPatientErr != nil {
  714. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  716. return
  717. } else if patient == nil {
  718. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  719. return
  720. }
  721. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  722. if getNurseErr != nil {
  723. this.ErrorLog("获取护士失败:%v", getNurseErr)
  724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  725. return
  726. } else if nurse == nil {
  727. this.ErrorLog("护士不存在")
  728. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  729. return
  730. }
  731. //nurse, getNurseErr = service.GetAdminUserByUserID(punctureNurseId)
  732. //
  733. //if getNurseErr != nil {
  734. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  735. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  736. // return
  737. //} else if nurse == nil {
  738. // this.ErrorLog("护士不存在")
  739. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  740. // return
  741. //}
  742. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  743. if getDeviceNumberErr != nil {
  744. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  746. return
  747. } else if deviceNumber == nil {
  748. this.ErrorLog("床位号不存在")
  749. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  750. return
  751. }
  752. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  753. if getRecordErr != nil {
  754. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  756. return
  757. } else if dialysisRecord != nil {
  758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  759. return
  760. }
  761. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  762. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  763. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  764. timeLayout := "2006-01-02 15:04:05"
  765. loc, _ := time.LoadLocation("Local")
  766. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  767. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  768. schedulestartTime := theStartTime.Unix()
  769. scheduleendTime := theEndTime.Unix()
  770. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  771. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  772. //查询该床位是否有人用了
  773. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  774. if err == gorm.ErrRecordNotFound { //空床位
  775. // 修改了床位逻辑
  776. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  777. if daySchedule.ID > 0 {
  778. //daySchedule.PartitionId = deviceNumber.ZoneID
  779. //daySchedule.BedId = bedID
  780. //daySchedule.ScheduleType = schedual_type
  781. //daySchedule.UpdatedTime = time.Now().Unix()
  782. //err := service.UpdateSchedule(&daySchedule)
  783. xtSchedule := models.Schedule{
  784. PartitionId: deviceNumber.ZoneID,
  785. BedId: bedID,
  786. ScheduleType: schedual_type,
  787. UpdatedTime: time.Now().Unix(),
  788. }
  789. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  790. if err != nil {
  791. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  792. return
  793. }
  794. }
  795. } else if err == nil {
  796. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  797. if order_err == nil {
  798. if order.ID > 0 { //该机位被其他人占用了
  799. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  800. return
  801. } else {
  802. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  803. if daySchedule.ID > 0 {
  804. //daySchedule.PartitionId = deviceNumber.ZoneID
  805. //daySchedule.BedId = bedID
  806. //daySchedule.ScheduleType = schedual_type
  807. //daySchedule.UpdatedTime = time.Now().Unix()
  808. //err := service.UpdateSchedule(&daySchedule)
  809. xtSchedule := models.Schedule{
  810. PartitionId: deviceNumber.ZoneID,
  811. BedId: bedID,
  812. ScheduleType: schedual_type,
  813. UpdatedTime: time.Now().Unix(),
  814. }
  815. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  816. if err != nil {
  817. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  818. return
  819. }
  820. }
  821. }
  822. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  823. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  824. if daySchedule.ID > 0 {
  825. //daySchedule.PartitionId = deviceNumber.ZoneID
  826. //daySchedule.BedId = bedID
  827. //daySchedule.ScheduleType = schedual_type
  828. //daySchedule.UpdatedTime = time.Now().Unix()
  829. //err := service.UpdateSchedule(&daySchedule)
  830. xtSchedule := models.Schedule{
  831. PartitionId: deviceNumber.ZoneID,
  832. BedId: bedID,
  833. ScheduleType: schedual_type,
  834. UpdatedTime: time.Now().Unix(),
  835. }
  836. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  837. if err != nil {
  838. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  839. return
  840. }
  841. }
  842. } else if order_err != nil {
  843. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  844. return
  845. }
  846. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  847. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  848. return
  849. }
  850. } else if err != nil {
  851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  852. return
  853. }
  854. dialysisRecord = &models.DialysisOrder{
  855. DialysisDate: recordDate.Unix(),
  856. UserOrgId: adminUserInfo.CurrentOrgId,
  857. PatientId: patientID,
  858. Stage: 1,
  859. BedID: bedID,
  860. StartNurse: nurseID,
  861. Status: 1,
  862. StartTime: startDate.Unix(),
  863. CreatedTime: time.Now().Unix(),
  864. UpdatedTime: time.Now().Unix(),
  865. PunctureNurse: punctureNurseId,
  866. Creator: adminUserInfo.AdminUser.Id,
  867. Modifier: adminUserInfo.AdminUser.Id,
  868. SchedualType: schedual_type,
  869. WashpipeNurse: washpipe_nurse,
  870. ChangeNurse: change_nurse,
  871. DifficultPunctureNurse: difficult_puncture_nurse,
  872. NewFistulaNurse: new_fistula_nurse,
  873. QualityNurseId: quality_nurse_id,
  874. }
  875. createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
  876. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  881. redis.Set(keyOne, "", time.Second)
  882. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  883. //清空key 值
  884. redis.Set(keyTwo, "", time.Second)
  885. defer redis.Close()
  886. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  887. if createErr != nil {
  888. this.ErrorLog("上机失败:%v", createErr)
  889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  890. return
  891. } else if createErr == nil {
  892. var tempdispose string
  893. // 只针对中能建
  894. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 9538 { //adminUserInfo.CurrentOrgId == 9538
  895. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  896. }
  897. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 10318 { //adminUserInfo.CurrentOrgId == 9538
  898. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  899. }
  900. var ultrafiltration_rate float64
  901. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  902. //获取预增水量
  903. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  904. if prescription.ID > 0 {
  905. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  906. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  907. //fmt.Println("total23232323232322332", totalMin)
  908. if (template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 36) && adminUserInfo.CurrentOrgId != 9671 {
  909. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  910. }
  911. //针对福建医师汇
  912. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10121 {
  913. if evaluation.ID > 0 {
  914. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  915. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  916. }
  917. }
  918. if template.TemplateId == 6 && adminUserInfo.CurrentOrgId == 10234 {
  919. if evaluation.ID > 0 {
  920. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  921. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  922. }
  923. }
  924. // 只针对方济医院
  925. if template.TemplateId == 1 && adminUserInfo.CurrentOrgId != 9849 {
  926. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  927. ultrafiltration_rate = value
  928. }
  929. //针对监利大垸医院
  930. if adminUserInfo.CurrentOrgId == 10101 {
  931. if evaluation.ID > 0 {
  932. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  933. }
  934. }
  935. //针对肇庆三鹤血液透析中心
  936. if adminUserInfo.CurrentOrgId == 10215 || template.TemplateId == 43 {
  937. if evaluation.ID > 0 {
  938. ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  939. }
  940. }
  941. }
  942. }
  943. record := models.MonitoringRecord{
  944. UserOrgId: adminUserInfo.CurrentOrgId,
  945. PatientId: patientID,
  946. DialysisOrderId: dialysisRecord.ID,
  947. MonitoringDate: schedulestartTime,
  948. OperateTime: startDate.Unix(),
  949. // MonitoringTime: recordTime,
  950. MonitoringNurse: nurseID,
  951. Dispose: tempdispose,
  952. UltrafiltrationRate: ultrafiltration_rate,
  953. UltrafiltrationVolume: 0,
  954. Status: 1,
  955. CreatedTime: time.Now().Unix(),
  956. UpdatedTime: time.Now().Unix(),
  957. }
  958. //只针对广慈医院
  959. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.CurrentOrgId == 9987 || adminUserInfo.CurrentOrgId == 9526 || template.TemplateId == 32 || adminUserInfo.CurrentOrgId == 9918 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 4 {
  960. // 查询病人是否有透前评估数据
  961. befor, errcode := service.GetAssessmentBefor(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  962. //如果有数据就插入
  963. if errcode == nil {
  964. record.SystolicBloodPressure = befor.SystolicBloodPressure
  965. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  966. record.BreathingRate = befor.BreathingRate
  967. record.PulseFrequency = befor.PulseFrequency
  968. record.Temperature = befor.Temperature
  969. }
  970. }
  971. // 如果当天有插入数据,则不再往透析纪录里插入数据
  972. if newdialysisRecord.ID > 0 {
  973. //针对长沙南雅医院
  974. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  975. record.Temperature = 36.5
  976. }
  977. err := service.CreateMonitor(&record)
  978. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  979. redis := service.RedisClient()
  980. //清空key 值
  981. redis.Set(key, "", time.Second)
  982. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  983. redis.Set(keyOne, "", time.Second)
  984. defer redis.Close()
  985. if err != nil {
  986. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  987. return
  988. }
  989. }
  990. go func() {
  991. ssoDomain := beego.AppConfig.String("call_domain")
  992. api := ssoDomain + "/index/uppatient"
  993. values := make(url.Values)
  994. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  995. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  996. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  997. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  998. http.PostForm(api, values)
  999. }()
  1000. this.ServeSuccessJSON(map[string]interface{}{
  1001. "dialysis_order": dialysisRecord,
  1002. "monitor": record,
  1003. })
  1004. }
  1005. }
  1006. // /api/dialysis/finish [post]
  1007. // @param patient_id:int
  1008. // @param date:string 排班时间 (yyyy-mm-dd)
  1009. // @param nurse:int 下机护士
  1010. func (this *DialysisRecordAPIController) FinishDialysis() {
  1011. patientID, _ := this.GetInt64("patient_id")
  1012. recordDateStr := this.GetString("date")
  1013. nurseID, _ := this.GetInt64("nurse")
  1014. end_time := this.GetString("end_time")
  1015. puncture_point_haematoma, _ := this.GetInt64("puncture_point_haematoma")
  1016. internal_fistula := this.GetString("internal_fistula")
  1017. catheter := this.GetString("catheter")
  1018. cruor := this.GetString("cruor")
  1019. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 {
  1020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1021. return
  1022. }
  1023. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1024. if parseErr != nil {
  1025. this.ErrorLog("时间解析失败:%v", parseErr)
  1026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1027. return
  1028. }
  1029. //if parseEndDateErr != nil {
  1030. // this.ErrorLog("时间解析失败:%v", parseEndDateErr)
  1031. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1032. // return
  1033. //}
  1034. adminUserInfo := this.GetAdminUserInfo()
  1035. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  1036. if getPatientErr != nil {
  1037. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1038. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1039. return
  1040. } else if patient == nil {
  1041. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1042. return
  1043. }
  1044. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1045. if getNurseErr != nil {
  1046. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1048. return
  1049. } else if nurse == nil {
  1050. this.ErrorLog("护士不存在")
  1051. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1052. return
  1053. }
  1054. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1055. if getRecordErr != nil {
  1056. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1057. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1058. return
  1059. }
  1060. if dialysisRecord.Stage == 2 {
  1061. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1062. return
  1063. }
  1064. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1065. if parseEndDateErr != nil {
  1066. this.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1068. return
  1069. }
  1070. // 获取当天的第一条透析纪录
  1071. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1072. if getMonitorRecordsErr != nil {
  1073. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1074. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1075. return
  1076. }
  1077. // 获取当前的最后一条透析纪录
  1078. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1079. if getMonitorRecordsErr != nil {
  1080. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1082. return
  1083. }
  1084. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1085. if getAADErr != nil {
  1086. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  1087. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1088. return
  1089. }
  1090. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1091. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1092. if assessmentAfterDislysis != nil {
  1093. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1094. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1095. } else {
  1096. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1097. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1098. tempassessmentAfterDislysis.Status = 1
  1099. tempassessmentAfterDislysis.PatientId = patientID
  1100. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.CurrentOrgId
  1101. }
  1102. if dialysisRecord.Stage == 1 {
  1103. temp_time := (float64(endDate.Unix()) - float64(dialysisRecord.StartTime)) / 3600
  1104. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1105. fmt.Println(value)
  1106. a, b := math.Modf(value)
  1107. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1108. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1109. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1110. fmt.Println(hour)
  1111. fmt.Println(minute)
  1112. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1113. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1114. }
  1115. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1116. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1117. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1118. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1119. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1120. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1121. //长沙南雅
  1122. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1123. //获取最后一条透析处方数据
  1124. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1125. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1126. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration
  1127. }
  1128. if adminUserInfo.CurrentOrgId == 10101 {
  1129. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1130. } else {
  1131. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1132. }
  1133. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1134. }
  1135. if adminUserInfo.CurrentOrgId == 9583 {
  1136. //获取最后一条透析处方数据
  1137. prescription, parseErr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1138. if parseErr != nil {
  1139. this.ErrorLog("获取透析处方失败:%v", getMonitorRecordsErr)
  1140. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1141. return
  1142. }
  1143. if prescription.ID > 0 && adminUserInfo.CurrentOrgId == 9583 {
  1144. tempassessmentAfterDislysis.ActualUltrafiltration = prescription.TargetUltrafiltration
  1145. }
  1146. if endmonitorRecords.ID > 0 && adminUserInfo.CurrentOrgId == 10060 {
  1147. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1148. }
  1149. }
  1150. if lastAssessmentAfterDislysis != nil {
  1151. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1152. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1153. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1154. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1155. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1156. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1157. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1158. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1159. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1160. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1161. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1162. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1163. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1164. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1165. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1166. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1167. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1168. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1169. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1170. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1171. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1172. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1173. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1174. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1175. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1176. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1177. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1178. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1179. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1180. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1181. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1182. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1183. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1184. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1185. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1186. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1187. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1188. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1189. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1190. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1191. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1192. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1193. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1194. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1195. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1196. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1197. }
  1198. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1199. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 10414 {
  1200. fmt.Println("进来2332233333333333333333333333333333333我的")
  1201. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1202. if evaluation.SystolicBloodPressure == 0 {
  1203. pre := models.PredialysisEvaluation{
  1204. SystolicBloodPressure: fmonitorRecords.SystolicBloodPressure,
  1205. }
  1206. fmt.Println("prew", pre)
  1207. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  1208. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1209. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1210. redis := service.RedisClient()
  1211. redis.Set(key, "", time.Second)
  1212. redis.Set(keyOne, "", time.Second)
  1213. defer redis.Close()
  1214. fmt.Println(getNurseErr)
  1215. }
  1216. if evaluation.DiastolicBloodPressure == 0 {
  1217. pres := models.PredialysisEvaluation{
  1218. DiastolicBloodPressure: fmonitorRecords.DiastolicBloodPressure,
  1219. }
  1220. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  1221. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1222. redis := service.RedisClient()
  1223. redis.Set(key, "", time.Second)
  1224. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1225. redis.Set(keyOne, "", time.Second)
  1226. defer redis.Close()
  1227. fmt.Println(getNurseErr)
  1228. }
  1229. if evaluation.PulseFrequency == 0 {
  1230. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  1231. press := models.PredialysisEvaluation{
  1232. PulseFrequency: evaluation.PulseFrequency,
  1233. }
  1234. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  1235. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1236. redis := service.RedisClient()
  1237. redis.Set(key, "", time.Second)
  1238. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1239. redis.Set(keyOne, "", time.Second)
  1240. defer redis.Close()
  1241. fmt.Println(getNurseErr)
  1242. }
  1243. if evaluation.Temperature == 0 {
  1244. evaluation.Temperature = fmonitorRecords.Temperature
  1245. press := models.PredialysisEvaluation{
  1246. Temperature: evaluation.Temperature,
  1247. }
  1248. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  1249. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1250. redis := service.RedisClient()
  1251. redis.Set(key, "", time.Second)
  1252. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1253. redis.Set(keyOne, "", time.Second)
  1254. defer redis.Close()
  1255. fmt.Println(getNurseErr)
  1256. }
  1257. }
  1258. if err != nil {
  1259. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1260. return
  1261. }
  1262. go func() {
  1263. ssoDomain := beego.AppConfig.String("call_domain")
  1264. api := ssoDomain + "/index/downpatient"
  1265. values := make(url.Values)
  1266. values.Set("org_id", strconv.FormatInt(adminUserInfo.CurrentOrgId, 10))
  1267. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1268. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1269. http.PostForm(api, values)
  1270. }()
  1271. //执行下机
  1272. updateErr := service.ModifyDialysisRecord(dialysisRecord.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor)
  1273. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1274. redis := service.RedisClient()
  1275. defer redis.Close()
  1276. //清空key 值
  1277. redis.Set(key, "", time.Second)
  1278. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1279. redis.Set(keyOne, "", time.Second)
  1280. if updateErr != nil {
  1281. this.ErrorLog("下机失败:%v", updateErr)
  1282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1283. return
  1284. } else {
  1285. dialysisRecord.Stage = 2
  1286. dialysisRecord.FinishNurse = nurseID
  1287. dialysisRecord.FinishCreator = adminUserInfo.AdminUser.Id
  1288. dialysisRecord.FinishModifier = adminUserInfo.AdminUser.Id
  1289. dialysisRecord.EndTime = endDate.Unix()
  1290. // 结束时候透析次数加1
  1291. service.UpdateSolutionByPatientId(patientID)
  1292. this.ServeSuccessJSON(map[string]interface{}{
  1293. "dialysis_order": dialysisRecord,
  1294. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1295. })
  1296. }
  1297. }
  1298. func (this *DialysisRecordAPIController) ModifyStartDialysis() {
  1299. record_id, _ := this.GetInt64("id")
  1300. nurseID, _ := this.GetInt64("nurse")
  1301. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1302. bedID, _ := this.GetInt64("bed")
  1303. start_time := this.GetString("start_time")
  1304. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1305. schedual_type, _ := this.GetInt64("schedual_type")
  1306. change_nurse, _ := this.GetInt64("change_nurse")
  1307. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1308. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1309. quality_nurse, _ := this.GetInt64("quality_nurse")
  1310. if record_id == 0 {
  1311. this.ErrorLog("id:%v", record_id)
  1312. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1313. return
  1314. }
  1315. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  1316. if parseStartDateErr != nil {
  1317. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1318. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1319. return
  1320. }
  1321. adminUserInfo := this.GetAdminUserInfo()
  1322. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1323. if getNurseErr != nil {
  1324. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1326. return
  1327. } else if nurse == nil {
  1328. this.ErrorLog("护士不存在")
  1329. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1330. return
  1331. }
  1332. //nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1333. //if getNurseErr != nil {
  1334. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  1335. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1336. // return
  1337. //} else if nurse == nil {
  1338. // this.ErrorLog("护士不存在")
  1339. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1340. // return
  1341. //}
  1342. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  1343. if getDeviceNumberErr != nil {
  1344. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1346. return
  1347. } else if deviceNumber == nil {
  1348. this.ErrorLog("床位号不存在")
  1349. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1350. return
  1351. }
  1352. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  1353. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  1354. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1355. // if getPermissionErr != nil {
  1356. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1357. // return
  1358. // } else if headNursePermission == nil {
  1359. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1360. // return
  1361. // }
  1362. //}
  1363. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1364. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1365. timeLayout := "2006-01-02 15:04:05"
  1366. loc, _ := time.LoadLocation("Local")
  1367. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1368. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1369. schedulestartTime := theStartTime.Unix()
  1370. scheduleendTime := theEndTime.Unix()
  1371. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1372. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  1373. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1374. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  1375. if err == gorm.ErrRecordNotFound { //空床位
  1376. // 修改了床位逻辑
  1377. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1378. if daySchedule.ID > 0 {
  1379. //daySchedule.BedId = bedID
  1380. //daySchedule.PartitionId = deviceNumber.ZoneID
  1381. //daySchedule.ScheduleType = schedual_type
  1382. //daySchedule.UpdatedTime = time.Now().Unix()
  1383. //err := service.UpdateSchedule(&daySchedule)
  1384. xtSchedule := models.Schedule{
  1385. PartitionId: deviceNumber.ZoneID,
  1386. BedId: bedID,
  1387. ScheduleType: schedual_type,
  1388. UpdatedTime: time.Now().Unix(),
  1389. }
  1390. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1391. if err != nil {
  1392. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1393. return
  1394. }
  1395. }
  1396. } else if err == nil {
  1397. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1398. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1399. if daySchedule.ID > 0 {
  1400. //daySchedule.BedId = bedID
  1401. //daySchedule.PartitionId = deviceNumber.ZoneID
  1402. //
  1403. //daySchedule.ScheduleType = schedual_type
  1404. //daySchedule.UpdatedTime = time.Now().Unix()
  1405. //err := service.UpdateSchedule(&daySchedule)
  1406. xtSchedule := models.Schedule{
  1407. PartitionId: deviceNumber.ZoneID,
  1408. BedId: bedID,
  1409. ScheduleType: schedual_type,
  1410. UpdatedTime: time.Now().Unix(),
  1411. }
  1412. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1413. if err != nil {
  1414. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1415. return
  1416. }
  1417. }
  1418. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1420. return
  1421. }
  1422. } else if err != nil {
  1423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1424. return
  1425. }
  1426. }
  1427. fmt.Println("quality_nurse", quality_nurse)
  1428. dialysisRecord := &models.DialysisOrder{
  1429. ID: record_id,
  1430. UserOrgId: adminUserInfo.CurrentOrgId,
  1431. BedID: bedID,
  1432. StartNurse: nurseID,
  1433. StartTime: startDate.Unix(),
  1434. PunctureNurse: puncture_nurse,
  1435. Creator: adminUserInfo.AdminUser.Id,
  1436. Modifier: adminUserInfo.AdminUser.Id,
  1437. SchedualType: schedual_type,
  1438. WashpipeNurse: washpipe_nurse,
  1439. ChangeNurse: change_nurse,
  1440. DifficultPunctureNurse: difficult_puncture_nurse,
  1441. NewFistulaNurse: new_fistula_nurse,
  1442. QualityNurseId: quality_nurse,
  1443. }
  1444. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  1445. redis := service.RedisClient()
  1446. key := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_order"
  1447. redis.Set(key, "", time.Second)
  1448. keyOne := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1449. //清空key 值
  1450. redis.Set(keyOne, "", time.Second)
  1451. scheduleDateStartOne := startDate.Format("2006-01-02")
  1452. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(tempDialysisRecord.UserOrgId, 10)
  1453. redis.Set(keyTwo, "", time.Second)
  1454. keyThree := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":doctor_advices"
  1455. redis.Set(keyThree, "", time.Second)
  1456. keyFour := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  1457. redis.Set(keyFour, "", time.Second)
  1458. keyFive := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":patient_info"
  1459. redis.Set(keyFive, "", time.Second)
  1460. keySix := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":his_doctor_advice"
  1461. redis.Set(keySix, "", time.Second)
  1462. keySeven := strconv.FormatInt(tempDialysisRecord.UserOrgId, 10) + ":" + ":device_list_all"
  1463. redis.Set(keySeven, "", time.Second)
  1464. if updateErr != nil {
  1465. this.ErrorLog("修改上机失败:%v", updateErr)
  1466. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1467. return
  1468. }
  1469. if updateErr == nil {
  1470. if tempDialysisRecord.Stage == 2 {
  1471. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  1472. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1473. fmt.Println(value)
  1474. a, b := math.Modf(value)
  1475. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1476. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1477. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1478. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  1479. redis := service.RedisClient()
  1480. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  1481. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":dialysis_orders_list_all"
  1482. redis.Set(key, "", time.Second)
  1483. redis.Set(keyThree, "", time.Second)
  1484. redis.Close()
  1485. if updateAssessmentErr != nil {
  1486. utils.ErrorLog("%v", updateAssessmentErr)
  1487. }
  1488. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecord.UserOrgId, tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  1489. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1490. this.ServeSuccessJSON(map[string]interface{}{
  1491. "dialysis_order": dialysisRecords,
  1492. "after": after,
  1493. })
  1494. } else {
  1495. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1496. this.ServeSuccessJSON(map[string]interface{}{
  1497. "dialysis_order": dialysisRecords,
  1498. })
  1499. }
  1500. }
  1501. }
  1502. func (c *DialysisRecordAPIController) ModifyFinishDialysis() {
  1503. record_id, _ := c.GetInt64("id")
  1504. nurseID, _ := c.GetInt64("nurse")
  1505. end_time := c.GetString("end_time")
  1506. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  1507. internal_fistula := c.GetString("internal_fistula")
  1508. catheter := c.GetString("catheter")
  1509. cruor := c.GetString("cruor")
  1510. if record_id <= 0 || nurseID <= 0 {
  1511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1512. return
  1513. }
  1514. adminUserInfo := c.GetAdminUserInfo()
  1515. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1516. if getNurseErr != nil {
  1517. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1519. return
  1520. } else if nurse == nil {
  1521. c.ErrorLog("护士不存在")
  1522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1523. return
  1524. }
  1525. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  1526. if parseEndDateErr != nil {
  1527. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1529. return
  1530. }
  1531. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  1532. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  1533. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1534. // if getPermissionErr != nil {
  1535. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1536. // return
  1537. // } else if headNursePermission == nil {
  1538. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1539. // return
  1540. // }
  1541. //}
  1542. dialysisRecord := &models.DialysisOrder{
  1543. ID: record_id,
  1544. UserOrgId: adminUserInfo.CurrentOrgId,
  1545. EndTime: endDate.Unix(),
  1546. FinishNurse: nurseID,
  1547. FinishModifier: adminUserInfo.AdminUser.Id,
  1548. PuncturePointHaematoma: puncture_point_haematoma,
  1549. BloodAccessInternalFistula: internal_fistula,
  1550. Catheter: catheter,
  1551. Cruor: cruor,
  1552. }
  1553. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  1554. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  1555. redis := service.RedisClient()
  1556. defer redis.Close()
  1557. //清空key 值
  1558. redis.Set(key, "", time.Second)
  1559. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":dialysis_orders_list_all"
  1560. redis.Set(keyOne, "", time.Second)
  1561. if updateErr != nil {
  1562. c.ErrorLog("修改下机失败:%v", updateErr)
  1563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1564. return
  1565. }
  1566. if updateErr == nil {
  1567. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  1568. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1569. fmt.Println(value)
  1570. a, b := math.Modf(value)
  1571. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1572. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1573. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1574. monitor, _ := service.GetLastMonitorRecord(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1575. updateAssessmentErr := service.UpdateAssessmentAfterDateOne(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute, monitor.BreathingRate)
  1576. if updateAssessmentErr != nil {
  1577. utils.ErrorLog("%v", updateAssessmentErr)
  1578. }
  1579. }
  1580. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  1581. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1582. c.ServeSuccessJSON(map[string]interface{}{
  1583. "dialysis_order": dialysisRecords,
  1584. "after": after,
  1585. })
  1586. }