dialysis_record_api_controller.go 103KB

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