dialysis_record_api_controller.go 88KB

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