dialysis_record_api_controller.go 91KB

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