dialysis_record_api_controller.go 85KB

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