dialysis_record_api_controller.go 63KB

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