dialysis_record_api_controller.go 91KB

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