dialysis_record_api_controller.go 68KB

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