dialysis_record_api_controller.go 79KB

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