dialysis_record_api_controller.go 77KB

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