check_weight_api_controller.go 50KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. _ "XT_New/utils"
  7. _ "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. _ "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "net/http"
  13. "net/url"
  14. "strconv"
  15. _ "strings"
  16. // "fmt"
  17. _ "reflect"
  18. "time"
  19. )
  20. type CheckWeightApiController struct {
  21. MobileBaseAPIAuthController
  22. }
  23. func (c *CheckWeightApiController) SaveBloodPressure() {
  24. id, _ := c.GetInt64("patient", 0)
  25. dialysistype, _ := c.GetInt64("dialysistype", 0)
  26. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0) //收缩压
  27. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0) //舒张压
  28. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0) //脉率
  29. if id <= 0 {
  30. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  31. return
  32. }
  33. if dialysistype <= 0 {
  34. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  35. return
  36. }
  37. if systolic_blood_pressure <= 0 {
  38. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  39. return
  40. }
  41. if diastolic_blood_pressure <= 0 {
  42. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  43. return
  44. }
  45. adminUserInfo := c.GetMobileAdminUserInfo()
  46. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  47. if patient.ID == 0 {
  48. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  49. return
  50. }
  51. thisTime := time.Now()
  52. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  53. timeLayout := "2006-01-02 15:04:05"
  54. loc, _ := time.LoadLocation("Local")
  55. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  56. theAssessmentDateTime := theStartTime.Unix()
  57. if dialysistype == 1 {
  58. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  59. if getPEErr != nil {
  60. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  61. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  62. return
  63. }
  64. var evaluation models.PredialysisEvaluation
  65. if theEvaluation != nil {
  66. evaluation = *theEvaluation
  67. }
  68. // 如果今天没有透前评估,则插入新的数据
  69. if theEvaluation == nil {
  70. evaluation.CreatedTime = time.Now().Unix()
  71. evaluation.Status = 1
  72. evaluation.AssessmentDate = theAssessmentDateTime
  73. evaluation.PatientId = id
  74. evaluation.UserOrgId = adminUserInfo.Org.Id
  75. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  76. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  77. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  78. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  79. if getAADErr != nil {
  80. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  81. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  82. return
  83. }
  84. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  85. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  86. if err == gorm.ErrRecordNotFound {
  87. if lastPredialysisEvaluation != nil {
  88. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  89. } else {
  90. evaluation.DryWeight = 0
  91. }
  92. } else {
  93. evaluation.DryWeight = weight.DryWeight
  94. }
  95. if assessmentAfterDislysis != nil {
  96. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  97. }
  98. if lastPredialysisEvaluation != nil {
  99. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  100. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  101. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight // 衣物重
  102. //从化益达 备注默认上一次数据
  103. if adminUserInfo.Org.Id == 10318 {
  104. evaluation.Remark = lastPredialysisEvaluation.Remark
  105. }
  106. }
  107. } else {
  108. evaluation.UpdatedTime = time.Now().Unix()
  109. }
  110. evaluation.SystolicBloodPressure = systolic_blood_pressure // 收缩压
  111. evaluation.DiastolicBloodPressure = diastolic_blood_pressure // 舒张压
  112. evaluation.PulseFrequency = pulse_frequency // 脉率
  113. evaluation.AssessmentTime = time.Now().Unix()
  114. err := service.UpadatePredialysisEvaluation(&evaluation)
  115. assessdateDateStart := thisTime.Format("2006-01-02")
  116. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  117. redis := service.RedisClient()
  118. defer redis.Close()
  119. //清空key 值
  120. redis.Set(key, "", time.Second)
  121. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  122. redis.Set(keyOne, "", time.Second)
  123. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  124. redis.Set(keyTwo, "", time.Second)
  125. redis.Close()
  126. if err != nil {
  127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  128. return
  129. }
  130. c.ServeSuccessJSON(map[string]interface{}{
  131. "msg": "ok",
  132. "evaluation": evaluation,
  133. })
  134. return
  135. } else {
  136. // 保存透后相关数据
  137. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  138. if getAADErr != nil {
  139. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  141. return
  142. }
  143. var afterevaluation models.AssessmentAfterDislysis
  144. if assessmentAfterDislysis != nil {
  145. afterevaluation = *assessmentAfterDislysis
  146. }
  147. if assessmentAfterDislysis == nil {
  148. afterevaluation.CreatedTime = time.Now().Unix()
  149. afterevaluation.Status = 1
  150. afterevaluation.AssessmentDate = theAssessmentDateTime
  151. afterevaluation.PatientId = id
  152. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  153. } else {
  154. afterevaluation.UpdatedTime = time.Now().Unix()
  155. }
  156. afterevaluation.SystolicBloodPressure = systolic_blood_pressure // 收缩压
  157. afterevaluation.DiastolicBloodPressure = diastolic_blood_pressure // 舒张压
  158. afterevaluation.PulseFrequency = pulse_frequency // 脉率
  159. if adminUserInfo.Org.Id == 10138 {
  160. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  161. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  162. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  163. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk //跌倒风险
  164. }
  165. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  166. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
  167. redis := service.RedisClient()
  168. //清空key 值
  169. redis.Set(key, "", time.Second)
  170. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
  171. redis.Set(keyThree, "", time.Second)
  172. assessdateDateStart := thisTime.Format("2006-01-02")
  173. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  174. redis.Set(keyTwo, "", time.Second)
  175. defer redis.Close()
  176. if err == nil {
  177. c.ServeSuccessJSON(map[string]interface{}{
  178. "assessmentAfterDislysis": afterevaluation,
  179. })
  180. }
  181. }
  182. }
  183. func (c *CheckWeightApiController) SavePatientInfoDialysis() {
  184. id, _ := c.GetInt64("patient", 0)
  185. dialysistype, _ := c.GetInt64("dialysistype", 0)
  186. if id <= 0 {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  188. return
  189. }
  190. if dialysistype <= 0 {
  191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  192. return
  193. }
  194. adminUserInfo := c.GetMobileAdminUserInfo()
  195. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  196. if patient.ID == 0 {
  197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  198. return
  199. }
  200. thisTime := time.Now()
  201. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  202. // scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  203. timeLayout := "2006-01-02 15:04:05"
  204. loc, _ := time.LoadLocation("Local")
  205. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  206. // theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  207. theAssessmentDateTime := theStartTime.Unix()
  208. // endTime := theEndTime.Unix()
  209. // dry_weight,_ := c.GetFloat("dry_weight",0) // 干体重
  210. weighing_before, _ := c.GetFloat("weighing_before", 0) // 透前体重
  211. dewater_amount, _ := c.GetFloat("dewater_amount", 0) // 目标脱水量(L)
  212. weight_after, _ := c.GetFloat("weight_after", 0) // 透后体重
  213. weight_loss, _ := c.GetFloat("weight_loss", 0) // 体重减少
  214. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix())
  215. //dialysisSolution,_ := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id,patient.ID,schedual.ModeId)
  216. //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
  217. //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
  218. //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
  219. // 查询当前用户今天有没有排班,没有排班,则不处理
  220. // daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, theAssessmentDateTime, endTime, id)
  221. // if(len(daySchedule) <= 0) {
  222. // c.ServeSuccessJSON(map[string]interface{}{
  223. // "msg": "ok",
  224. // })
  225. // return
  226. // }
  227. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  228. if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10138 || adminUserInfo.Org.Id == 10278 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10440 {
  229. if adminUserInfo.Org.Id != 10447 {
  230. dewater_amount = dewater_amount * 1000
  231. }
  232. }
  233. if dewater_amount < 0 {
  234. dewater_amount = 0
  235. }
  236. if dialysistype == 1 {
  237. // 保存透前相关数据
  238. // 获取透析处方
  239. var lastDialysisPrescribe *models.DialysisPrescription
  240. var dialysisSolution *models.DialysisSolution
  241. var dialysisPrescribe *models.DialysisPrescription
  242. var system_dialysisPrescribe *models.SystemPrescription
  243. var mode_id int64
  244. //weightfirst, _ := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  245. //if weightfirst.DryWeight > weighing_before {
  246. // return
  247. //}
  248. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  249. if schedual != nil {
  250. // 获取透析模版
  251. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  252. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  253. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  254. //判断透析模式,针对河间咸的
  255. if adminUserInfo.Org.Id == 10090 {
  256. if dialysisSolution.ModeId != 2 && dialysisSolution.ModeId != 5 && dialysisSolution.ModeId != 12 {
  257. dialysisSolution.DisplaceLiquiPart = 0
  258. dialysisSolution.DisplaceLiquiValue = 0
  259. }
  260. if lastDialysisPrescribe.ModeId != 2 && lastDialysisPrescribe.ModeId != 5 && lastDialysisPrescribe.ModeId != 12 {
  261. dialysisSolution.DisplaceLiquiPart = 0
  262. dialysisSolution.DisplaceLiquiValue = 0
  263. }
  264. }
  265. mode_id = schedual.ModeId
  266. } else {
  267. // 获取透析模版
  268. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  269. if dialysisPrescribe == nil && dialysisSolution != nil {
  270. mode_id = dialysisSolution.ModeId
  271. }
  272. if dialysisPrescribe == nil && dialysisSolution == nil {
  273. mode_id = 0
  274. }
  275. }
  276. // 插入透析处方
  277. if dialysisPrescribe == nil && dialysisSolution != nil {
  278. var newprescribe models.DialysisPrescription
  279. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  280. newprescribe.PatientId = dialysisSolution.PatientId
  281. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  282. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  283. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  284. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  285. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  286. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  287. newprescribe.ModeId = dialysisSolution.ModeId
  288. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  289. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  290. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  291. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  292. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  293. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  294. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  295. newprescribe.Glucose = dialysisSolution.Glucose
  296. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  297. newprescribe.Kalium = dialysisSolution.Kalium
  298. newprescribe.Sodium = dialysisSolution.Sodium
  299. newprescribe.Calcium = dialysisSolution.Calcium
  300. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  301. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  302. newprescribe.Conductivity = dialysisSolution.Conductivity
  303. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  304. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  305. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  306. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  307. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  308. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  309. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  310. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  311. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  312. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  313. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  314. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  315. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  316. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  317. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  318. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  319. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  320. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  321. newprescribe.CreatedTime = time.Now().Unix()
  322. newprescribe.UpdatedTime = time.Now().Unix()
  323. newprescribe.RecordDate = theAssessmentDateTime
  324. newprescribe.DewaterAmount = dewater_amount
  325. newprescribe.TargetUltrafiltration = dewater_amount
  326. newprescribe.Status = 1
  327. if adminUserInfo.Org.Id != 10013 && adminUserInfo.Org.Id != 10014 {
  328. newprescribe.Remark = dialysisSolution.Remark
  329. }
  330. if adminUserInfo.Org.Id == 10340 {
  331. newprescribe.TargetUltrafiltration = 0
  332. newprescribe.Sodium = 138
  333. newprescribe.Bicarbonate = 31.1
  334. newprescribe.DialysateFlow = 500
  335. }
  336. // 针对新化博翔
  337. if adminUserInfo.Org.Id == 10447 {
  338. newprescribe.DisplaceLiquiPart = 1
  339. newprescribe.DisplaceLiquiValue = 32
  340. newprescribe.DialysateFlow = 500
  341. }
  342. //插入透析处方
  343. err := service.AddSigleRecord(&newprescribe)
  344. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  345. redis := service.RedisClient()
  346. //清空key 值
  347. redis.Set(key, "", time.Second)
  348. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  349. redis.Set(keyTwo, "", time.Second)
  350. scheduleDateStartOne := thisTime.Format("2006-01-02")
  351. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  352. redis.Set(keyThree, "", time.Second)
  353. defer redis.Close()
  354. if err != nil {
  355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  356. }
  357. }
  358. if dialysisPrescribe == nil && dialysisSolution == nil {
  359. if lastDialysisPrescribe != nil {
  360. var newprescribe models.DialysisPrescription
  361. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  362. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  363. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  364. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  365. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  366. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  367. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  368. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  369. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  370. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  371. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  372. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  373. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  374. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  375. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  376. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  377. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  378. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  379. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  380. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  381. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  382. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  383. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  384. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  385. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  386. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  387. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  388. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  389. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  390. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  391. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  392. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  393. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  394. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  395. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  396. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  397. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  398. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  399. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  400. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  401. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  402. newprescribe.CreatedTime = time.Now().Unix()
  403. newprescribe.UpdatedTime = time.Now().Unix()
  404. newprescribe.RecordDate = theAssessmentDateTime
  405. newprescribe.DewaterAmount = dewater_amount
  406. newprescribe.TargetUltrafiltration = dewater_amount
  407. newprescribe.Status = 1
  408. newprescribe.Remark = lastDialysisPrescribe.Remark
  409. if adminUserInfo.Org.Id == 10340 {
  410. newprescribe.TargetUltrafiltration = 0
  411. }
  412. err := service.AddSigleRecord(&newprescribe)
  413. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  414. redis := service.RedisClient()
  415. //清空key 值
  416. redis.Set(key, "", time.Second)
  417. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  418. redis.Set(keyTwo, "", time.Second)
  419. scheduleDateStartOne := thisTime.Format("2006-01-02")
  420. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  421. redis.Set(keyThree, "", time.Second)
  422. defer redis.Close()
  423. if err != nil {
  424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  425. }
  426. } else if system_dialysisPrescribe != nil {
  427. var newprescribe models.DialysisPrescription
  428. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  429. newprescribe.PatientId = id
  430. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  431. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  432. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  433. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  434. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  435. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  436. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  437. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  438. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  439. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  440. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  441. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  442. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  443. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  444. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  445. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  446. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  447. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  448. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  449. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  450. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  451. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  452. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  453. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  454. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  455. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  456. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  457. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  458. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  459. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  460. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  461. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  462. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  463. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  464. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  465. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  466. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  467. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  468. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  469. newprescribe.CreatedTime = time.Now().Unix()
  470. newprescribe.UpdatedTime = time.Now().Unix()
  471. newprescribe.RecordDate = theAssessmentDateTime
  472. newprescribe.DewaterAmount = dewater_amount
  473. newprescribe.TargetUltrafiltration = dewater_amount
  474. newprescribe.Status = 1
  475. if adminUserInfo.Org.Id == 10340 {
  476. newprescribe.TargetUltrafiltration = 0
  477. }
  478. err := service.AddSigleRecord(&newprescribe)
  479. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  480. redis := service.RedisClient()
  481. //清空key 值
  482. redis.Set(key, "", time.Second)
  483. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  484. redis.Set(keyTwo, "", time.Second)
  485. scheduleDateStartOne := thisTime.Format("2006-01-02")
  486. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  487. redis.Set(keyThree, "", time.Second)
  488. defer redis.Close()
  489. if err != nil {
  490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  491. }
  492. } else {
  493. var newprescribe models.DialysisPrescription
  494. newprescribe.UserOrgId = adminUserInfo.Org.Id
  495. newprescribe.PatientId = id
  496. newprescribe.ModeId = mode_id
  497. newprescribe.CreatedTime = time.Now().Unix()
  498. newprescribe.UpdatedTime = time.Now().Unix()
  499. newprescribe.RecordDate = theAssessmentDateTime
  500. newprescribe.DewaterAmount = dewater_amount
  501. newprescribe.TargetUltrafiltration = dewater_amount
  502. newprescribe.Status = 1
  503. err := service.AddSigleRecord(&newprescribe)
  504. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  505. redis := service.RedisClient()
  506. //清空key 值
  507. redis.Set(key, "", time.Second)
  508. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  509. redis.Set(keyTwo, "", time.Second)
  510. scheduleDateStartOne := thisTime.Format("2006-01-02")
  511. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  512. redis.Set(keyThree, "", time.Second)
  513. defer redis.Close()
  514. if err != nil {
  515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  516. }
  517. }
  518. }
  519. if dialysisPrescribe != nil && dialysisPrescribe.TargetUltrafiltration == 0 {
  520. dialysisPrescribe.UpdatedTime = time.Now().Unix()
  521. dialysisPrescribe.RecordDate = theAssessmentDateTime
  522. dialysisPrescribe.DewaterAmount = dewater_amount
  523. dialysisPrescribe.TargetUltrafiltration = dewater_amount
  524. dialysisPrescribe.Status = 1
  525. if adminUserInfo.Org.Id == 10340 {
  526. dialysisPrescribe.TargetUltrafiltration = 0
  527. }
  528. updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  529. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  530. redis := service.RedisClient()
  531. //清空key 值
  532. redis.Set(key, "", time.Second)
  533. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  534. redis.Set(keyTwo, "", time.Second)
  535. scheduleDateStartOne := thisTime.Format("2006-01-02")
  536. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  537. redis.Set(keyThree, "", time.Second)
  538. defer redis.Close()
  539. if updateErr != nil {
  540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  541. }
  542. }
  543. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  544. if getPEErr != nil {
  545. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  547. return
  548. }
  549. var evaluation models.PredialysisEvaluation
  550. if theEvaluation != nil {
  551. evaluation = *theEvaluation
  552. }
  553. // 如果今天没有透前评估,则插入新的数据
  554. if theEvaluation == nil {
  555. evaluation.CreatedTime = time.Now().Unix()
  556. evaluation.Status = 1
  557. evaluation.AssessmentDate = theAssessmentDateTime
  558. evaluation.PatientId = id
  559. evaluation.UserOrgId = adminUserInfo.Org.Id
  560. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  561. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  562. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  563. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  564. if getAADErr != nil {
  565. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  567. return
  568. }
  569. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  570. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  571. if err == gorm.ErrRecordNotFound {
  572. if lastPredialysisEvaluation != nil {
  573. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  574. } else {
  575. evaluation.DryWeight = 0
  576. }
  577. } else {
  578. evaluation.DryWeight = weight.DryWeight
  579. }
  580. if assessmentAfterDislysis != nil {
  581. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  582. }
  583. if lastPredialysisEvaluation != nil {
  584. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  585. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  586. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight
  587. evaluation.Temperature = lastPredialysisEvaluation.Temperature
  588. evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
  589. evaluation.Catheter = lastPredialysisEvaluation.Catheter
  590. evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
  591. evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
  592. evaluation.Complication = lastPredialysisEvaluation.Complication
  593. evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
  594. evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase
  595. evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
  596. evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
  597. evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
  598. evaluation.InternalFistulaSkin = lastPredialysisEvaluation.InternalFistulaSkin //血透通路皮肤情况
  599. evaluation.CatheterBend = lastPredialysisEvaluation.CatheterBend //导管打折
  600. evaluation.IsHemorrhage = lastPredialysisEvaluation.IsHemorrhage //出血
  601. evaluation.IsInfect = lastPredialysisEvaluation.IsInfect //感染
  602. evaluation.Exposed = lastPredialysisEvaluation.Exposed // 外漏
  603. evaluation.DialysisCount = lastPredialysisEvaluation.DialysisCount //呼吸频次
  604. evaluation.Phinholing = lastPredialysisEvaluation.Phinholing //针眼
  605. evaluation.Remark = lastPredialysisEvaluation.Remark
  606. if adminUserInfo.Org.Id == 10318 {
  607. evaluation.Remark = "患者已确认无发热,无流行病学接触史"
  608. }
  609. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10447 {
  610. evaluation.BreathingRate = "20"
  611. }
  612. if adminUserInfo.Org.Id == 10445 {
  613. evaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
  614. }
  615. if adminUserInfo.Org.Id == 9829 {
  616. evaluation.PulseFrequency = 80
  617. }
  618. if adminUserInfo.Org.Id == 10440 {
  619. evaluation.Temperature = 36.5
  620. }
  621. }
  622. } else {
  623. evaluation.UpdatedTime = time.Now().Unix()
  624. }
  625. evaluation.WeightBefore = weighing_before
  626. evaluation.AssessmentTime = time.Now().Unix()
  627. err := service.UpadatePredialysisEvaluation(&evaluation)
  628. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  629. redis := service.RedisClient()
  630. //清空key 值
  631. redis.Set(key, "", time.Second)
  632. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  633. redis.Set(keyOne, "", time.Second)
  634. assessdateDateStart := thisTime.Format("2006-01-02")
  635. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  636. redis.Set(keyTwo, "", time.Second)
  637. redis.Close()
  638. if err != nil {
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  640. return
  641. }
  642. c.ServeSuccessJSON(map[string]interface{}{
  643. "msg": "ok",
  644. "evaluation": evaluation,
  645. })
  646. return
  647. } else {
  648. // 保存透后相关数据
  649. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  650. if getAADErr != nil {
  651. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  653. return
  654. }
  655. var afterevaluation models.AssessmentAfterDislysis
  656. if assessmentAfterDislysis != nil {
  657. afterevaluation = *assessmentAfterDislysis
  658. }
  659. if assessmentAfterDislysis == nil {
  660. afterevaluation.CreatedTime = time.Now().Unix()
  661. afterevaluation.Status = 1
  662. afterevaluation.AssessmentDate = theAssessmentDateTime
  663. afterevaluation.PatientId = id
  664. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  665. } else {
  666. afterevaluation.UpdatedTime = time.Now().Unix()
  667. }
  668. afterevaluation.WeightAfter = weight_after
  669. afterevaluation.WeightLoss = weight_loss
  670. if adminUserInfo.Org.Id == 10138 {
  671. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  672. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  673. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  674. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk
  675. }
  676. if adminUserInfo.Org.Id == 10307 || adminUserInfo.Org.Id == 10445 {
  677. afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  678. }
  679. //北方营口
  680. if adminUserInfo.Org.Id == 10445 {
  681. prescribe, _ := service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  682. afterevaluation.ActualDisplacement = prescribe.DisplaceLiquiValue
  683. }
  684. //蓬安济民
  685. if adminUserInfo.Org.Id == 9829 {
  686. afterevaluation.PulseFrequency = 80
  687. }
  688. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  689. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
  690. redis := service.RedisClient()
  691. //清空key 值
  692. redis.Set(key, "", time.Second)
  693. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
  694. redis.Set(keyThree, "", time.Second)
  695. assessdateDateStart := thisTime.Format("2006-01-02")
  696. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  697. redis.Set(keyTwo, "", time.Second)
  698. redis.Close()
  699. if err == nil {
  700. c.ServeSuccessJSON(map[string]interface{}{
  701. "assessmentAfterDislysis": afterevaluation,
  702. })
  703. }
  704. }
  705. }
  706. func (c *CheckWeightApiController) SetSyncTime() {
  707. sn := c.GetString("sn")
  708. if len(sn) > 0 {
  709. redis := service.RedisClient()
  710. defer redis.Close()
  711. redis.Set(sn, 0, 0)
  712. }
  713. serviceTime := time.Now().Unix()
  714. c.ServeSuccessJSON(map[string]interface{}{
  715. "status": 1,
  716. "servicetime": serviceTime,
  717. })
  718. }
  719. func (c *CheckWeightApiController) GetPatientList() {
  720. ftype, _ := c.GetInt64("type", 0)
  721. sn := c.GetString("sn")
  722. syncTime := int64(0)
  723. redis := service.RedisClient()
  724. defer redis.Close()
  725. if len(sn) > 0 {
  726. syncTimeStr, _ := redis.Get(sn).Result()
  727. syncTime, _ = strconv.ParseInt(syncTimeStr, 10, 64)
  728. }
  729. if ftype == 1 {
  730. timeNow := time.Now().Unix()
  731. redis.Set(sn, timeNow, 0)
  732. }
  733. adminUserInfo := c.GetMobileAdminUserInfo()
  734. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
  735. need_update := 0
  736. if syncTime == 0 {
  737. need_update = 1
  738. }
  739. if error != nil {
  740. c.ErrorLog("获取病人列表失败:%v", error)
  741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  742. return
  743. }
  744. serviceTime := time.Now().Unix()
  745. c.ServeSuccessJSON(map[string]interface{}{
  746. "need_update": need_update,
  747. "patientlist": patientList,
  748. "total": total,
  749. "servicetime": serviceTime,
  750. })
  751. }
  752. func (c *CheckWeightApiController) GetPatientListForSchedules() {
  753. thisTime := time.Now()
  754. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  755. timeLayout := "2006-01-02 15:04:05"
  756. loc, _ := time.LoadLocation("Local")
  757. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  758. syncTime := theStartTime.Unix()
  759. adminUserInfo := c.GetMobileAdminUserInfo()
  760. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  761. patientSchedule := make([]map[string]interface{}, 0)
  762. for _, item := range patientList {
  763. patientTemp := make(map[string]interface{})
  764. patientTemp["patient_id"] = item.PatientId
  765. patientTemp["patient_name"] = item.Patient.Name
  766. patientTemp["schedule_type"] = item.ScheduleType
  767. patientSchedule = append(patientSchedule, patientTemp)
  768. }
  769. if error != nil {
  770. c.ErrorLog("获取病人列表失败:%v", error)
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  772. return
  773. }
  774. serviceTime := time.Now().Unix()
  775. c.ServeSuccessJSON(map[string]interface{}{
  776. "patientlist": patientSchedule,
  777. "total": total,
  778. "servicetime": serviceTime,
  779. })
  780. }
  781. func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
  782. patient_name := c.GetString("patient_name") //脉率
  783. thisTime := time.Now()
  784. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  785. timeLayout := "2006-01-02 15:04:05"
  786. loc, _ := time.LoadLocation("Local")
  787. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  788. syncTime := theStartTime.Unix()
  789. adminUserInfo := c.GetMobileAdminUserInfo()
  790. if len(patient_name) == 0 {
  791. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  792. patientSchedule := make([]map[string]interface{}, 0)
  793. for _, item := range patientList {
  794. patientTemp := make(map[string]interface{})
  795. patientTemp["patient_id"] = item.PatientId
  796. patientTemp["patient_name"] = item.Patient.Name
  797. patientTemp["schedule_type"] = item.ScheduleType
  798. patientSchedule = append(patientSchedule, patientTemp)
  799. }
  800. if error != nil {
  801. c.ErrorLog("获取病人列表失败:%v", error)
  802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  803. return
  804. }
  805. serviceTime := time.Now().Unix()
  806. c.ServeSuccessJSON(map[string]interface{}{
  807. "patientlist": patientSchedule,
  808. "total": total,
  809. "servicetime": serviceTime,
  810. })
  811. } else {
  812. patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime, patient_name)
  813. patientSchedule := make([]map[string]interface{}, 0)
  814. for _, item := range patientList {
  815. if item.Patient.ID > 0 {
  816. patientTemp := make(map[string]interface{})
  817. patientTemp["patient_id"] = item.PatientId
  818. patientTemp["patient_name"] = item.Patient.Name
  819. patientTemp["schedule_type"] = item.ScheduleType
  820. patientSchedule = append(patientSchedule, patientTemp)
  821. }
  822. }
  823. if error != nil {
  824. c.ErrorLog("获取病人列表失败:%v", error)
  825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  826. return
  827. }
  828. serviceTime := time.Now().Unix()
  829. c.ServeSuccessJSON(map[string]interface{}{
  830. "patientlist": patientSchedule,
  831. "total": total,
  832. "servicetime": serviceTime,
  833. })
  834. }
  835. }
  836. func (c *CheckWeightApiController) GetPatientListById() {
  837. patientId, _ := c.GetInt64("patient_id", 0)
  838. if patientId <= 0 {
  839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  840. return
  841. }
  842. adminUserInfo := c.GetMobileAdminUserInfo()
  843. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  844. if error != nil {
  845. c.ErrorLog("获取病人详情失败:%v", error)
  846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  847. return
  848. }
  849. c.ServeSuccessJSON(map[string]interface{}{
  850. "patientinfo": patient,
  851. })
  852. }
  853. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  854. id, _ := c.GetInt64("patient", 0)
  855. if id <= 0 {
  856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. return
  858. }
  859. adminUserInfo := c.GetMobileAdminUserInfo()
  860. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  861. if patient.ID <= 0 {
  862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  863. return
  864. }
  865. var dialysisinfo map[string]interface{}
  866. dialysisinfo = make(map[string]interface{})
  867. dialysisinfo["id"] = patient.ID
  868. dialysisinfo["name"] = patient.Name
  869. dialysisinfo["dialysis_no"] = patient.DialysisNo
  870. thisTime := time.Now()
  871. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  872. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  873. timeLayout := "2006-01-02 15:04:05"
  874. loc, _ := time.LoadLocation("Local")
  875. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  876. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  877. startTime := theStartTime.Unix()
  878. endTime := theEndTime.Unix()
  879. // 判断当前用户是透析前还是透析后
  880. var dialysistype int
  881. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  882. if dialysisOrder == nil {
  883. dialysistype = 1
  884. } else {
  885. dialysistype = 2
  886. }
  887. // 获取当前或者下次排班信息
  888. var sc map[string]interface{}
  889. sc = make(map[string]interface{})
  890. if dialysistype == 1 {
  891. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  892. if len(daySchedule) <= 0 {
  893. sc["code"] = 1
  894. sc["msg"] = "抱歉,您今天没有排版!"
  895. sc["mode"] = 0
  896. sc["data"] = daySchedule
  897. } else {
  898. if daySchedule[0].Schedule.ID > 0 {
  899. sc["code"] = 0
  900. sc["msg"] = ""
  901. sc["mode"] = daySchedule[0].Schedule.ModeId
  902. sc["data"] = daySchedule
  903. } else {
  904. sc["code"] = 1
  905. sc["msg"] = "抱歉,您今天没有排版!"
  906. sc["mode"] = 0
  907. sc["data"] = daySchedule
  908. }
  909. }
  910. // 排队叫号的签到
  911. go func() {
  912. ssoDomain := beego.AppConfig.String("call_domain")
  913. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  914. values := make(url.Values)
  915. http.PostForm(api, values)
  916. }()
  917. } else {
  918. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  919. if len(nextSchedule) <= 0 {
  920. sc["code"] = 1
  921. sc["msg"] = "抱歉,您后续没有排版!"
  922. sc["mode"] = 0
  923. sc["data"] = nextSchedule
  924. } else {
  925. if nextSchedule[0].Schedule.ID > 0 {
  926. sc["code"] = 0
  927. sc["msg"] = ""
  928. sc["mode"] = nextSchedule[0].Schedule.ModeId
  929. sc["data"] = nextSchedule
  930. } else {
  931. sc["code"] = 1
  932. sc["msg"] = "抱歉,您后续没有排版!"
  933. sc["mode"] = 0
  934. sc["data"] = nextSchedule
  935. }
  936. }
  937. }
  938. switch sc["mode"] {
  939. case 1:
  940. sc["mode"] = "HD"
  941. case 2:
  942. sc["mode"] = "HDF"
  943. case 3:
  944. sc["mode"] = "HD+HP"
  945. case 4:
  946. sc["mode"] = "HP"
  947. case 5:
  948. sc["mode"] = "HF"
  949. case 6:
  950. sc["mode"] = "SCUF"
  951. case 7:
  952. sc["mode"] = "IUF"
  953. case 8:
  954. sc["mode"] = "HFHD"
  955. case 9:
  956. sc["mode"] = "HFHD+HP"
  957. case 10:
  958. sc["mode"] = "PHF"
  959. case 11:
  960. sc["mode"] = "HFR"
  961. case 12:
  962. sc["mode"] = "HDF+HP"
  963. case 13:
  964. sc["mode"] = "CRRT"
  965. case 14:
  966. sc["mode"] = "腹水回输"
  967. case 15:
  968. sc["mode"] = "HD前置换"
  969. case 16:
  970. sc["mode"] = "HD后置换"
  971. case 17:
  972. sc["mode"] = "HDF前置换"
  973. case 18:
  974. sc["mode"] = "HDF后置换"
  975. default:
  976. sc["mode"] = "HD"
  977. }
  978. // 获取患者透前干体重或者获取患者透前体重
  979. var dry_weight map[string]interface{}
  980. dry_weight = make(map[string]interface{})
  981. var after_dry_weight map[string]interface{}
  982. after_dry_weight = make(map[string]interface{})
  983. if dialysistype == 1 {
  984. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  985. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  986. if err == gorm.ErrRecordNotFound {
  987. if getLPEErr != nil {
  988. dry_weight["code"] = 1
  989. dry_weight["dry_weight"] = nil
  990. } else {
  991. if lastPredialysisEvaluation == nil {
  992. dry_weight["code"] = 1
  993. dry_weight["dry_weight"] = nil
  994. } else {
  995. // 传输的干体重实际为干体重加上衣服重
  996. dry_weight["code"] = 0
  997. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  998. }
  999. }
  1000. } else {
  1001. if err != nil {
  1002. dry_weight["code"] = 1
  1003. dry_weight["dry_weight"] = nil
  1004. } else {
  1005. dry_weight["code"] = 0
  1006. if getLPEErr != nil {
  1007. dry_weight["code"] = 0
  1008. dry_weight["dry_weight"] = weight.DryWeight
  1009. } else {
  1010. if lastPredialysisEvaluation == nil {
  1011. dry_weight["code"] = 1
  1012. dry_weight["dry_weight"] = weight.DryWeight
  1013. } else {
  1014. // 传输的干体重实际为干体重加上衣服重
  1015. dry_weight["code"] = 0
  1016. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1017. }
  1018. }
  1019. }
  1020. }
  1021. } else {
  1022. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1023. if getPEErr != nil {
  1024. dry_weight["code"] = 1
  1025. dry_weight["dry_weight"] = nil
  1026. } else {
  1027. if predialysisEvaluation == nil {
  1028. dry_weight["code"] = 1
  1029. dry_weight["dry_weight"] = nil
  1030. } else {
  1031. dry_weight["code"] = 0
  1032. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  1033. }
  1034. }
  1035. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1036. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1037. if err == gorm.ErrRecordNotFound {
  1038. if getLPEErr != nil {
  1039. after_dry_weight["code"] = 1
  1040. after_dry_weight["dry_weight"] = nil
  1041. } else {
  1042. if lastPredialysisEvaluation == nil {
  1043. after_dry_weight["code"] = 1
  1044. after_dry_weight["dry_weight"] = nil
  1045. } else {
  1046. // 传输的干体重实际为干体重加上衣服重
  1047. after_dry_weight["code"] = 0
  1048. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1049. }
  1050. }
  1051. } else {
  1052. if err != nil {
  1053. after_dry_weight["code"] = 1
  1054. after_dry_weight["dry_weight"] = nil
  1055. } else {
  1056. after_dry_weight["code"] = 0
  1057. if getLPEErr != nil {
  1058. after_dry_weight["code"] = 0
  1059. after_dry_weight["dry_weight"] = weight.DryWeight
  1060. } else {
  1061. if lastPredialysisEvaluation == nil {
  1062. after_dry_weight["code"] = 1
  1063. after_dry_weight["dry_weight"] = weight.DryWeight
  1064. } else {
  1065. // 传输的干体重实际为干体重加上衣服重
  1066. after_dry_weight["code"] = 0
  1067. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1068. }
  1069. }
  1070. }
  1071. }
  1072. }
  1073. c.ServeSuccessJSON(map[string]interface{}{
  1074. "dialysistype": dialysistype,
  1075. "patient": dialysisinfo,
  1076. "schedule": sc,
  1077. "dryweight": dry_weight,
  1078. "after_dry_weight": after_dry_weight,
  1079. })
  1080. return
  1081. }
  1082. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  1083. id, _ := c.GetInt64("patient", 0)
  1084. if id <= 0 {
  1085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1086. return
  1087. }
  1088. adminUserInfo := c.GetMobileAdminUserInfo()
  1089. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1090. if patient.ID == 0 {
  1091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1092. return
  1093. }
  1094. var dialysisinfo map[string]interface{}
  1095. dialysisinfo = make(map[string]interface{})
  1096. dialysisinfo["id"] = patient.ID
  1097. dialysisinfo["name"] = patient.Name
  1098. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1099. thisTime := time.Now()
  1100. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1101. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1102. fmt.Println(scheduleDateStart, scheduleDateEnd)
  1103. timeLayout := "2006-01-02 15:04:05"
  1104. loc, _ := time.LoadLocation("Local")
  1105. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1106. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1107. fmt.Println(theStartTime, theEndTime)
  1108. startTime := theStartTime.Unix()
  1109. endTime := theEndTime.Unix()
  1110. var sc map[string]interface{}
  1111. sc = make(map[string]interface{})
  1112. //一天只有排班一次
  1113. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  1114. if daySchedule.ID > 0 {
  1115. switch daySchedule.ModeId {
  1116. case 1:
  1117. sc["mode"] = "HD"
  1118. case 2:
  1119. sc["mode"] = "HDF"
  1120. case 3:
  1121. sc["mode"] = "HD+HP"
  1122. case 4:
  1123. sc["mode"] = "HP"
  1124. case 5:
  1125. sc["mode"] = "HF"
  1126. case 6:
  1127. sc["mode"] = "SCUF"
  1128. case 7:
  1129. sc["mode"] = "IUF"
  1130. case 8:
  1131. sc["mode"] = "HFHD"
  1132. case 9:
  1133. sc["mode"] = "HFHD+HP"
  1134. case 10:
  1135. sc["mode"] = "PHF"
  1136. case 11:
  1137. sc["mode"] = "HFR"
  1138. case 12:
  1139. sc["mode"] = "HDF+HP"
  1140. case 13:
  1141. sc["mode"] = "CRRT"
  1142. case 14:
  1143. sc["mode"] = "腹水回输"
  1144. case 15:
  1145. sc["mode"] = "HD前置换"
  1146. case 16:
  1147. sc["mode"] = "HD后置换"
  1148. case 17:
  1149. sc["mode"] = "HDF前置换"
  1150. case 18:
  1151. sc["mode"] = "HDF后置换"
  1152. default:
  1153. sc["mode"] = "HD"
  1154. }
  1155. sc["code"] = 0
  1156. sc["msg"] = ""
  1157. sc["data"] = daySchedule
  1158. } else {
  1159. sc["code"] = 1
  1160. sc["msg"] = "抱歉,您今天没有排版!"
  1161. sc["mode"] = ""
  1162. sc["data"] = daySchedule
  1163. }
  1164. fmt.Println(sc)
  1165. type dryWeight struct {
  1166. code int
  1167. dry_weight float64
  1168. }
  1169. var dry_weight map[string]interface{}
  1170. dry_weight = make(map[string]interface{})
  1171. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1172. if getLPEErr != nil {
  1173. dry_weight["code"] = 1
  1174. dry_weight["dry_weight"] = nil
  1175. } else {
  1176. if lastPredialysisEvaluation == nil {
  1177. dry_weight["code"] = 1
  1178. dry_weight["dry_weight"] = nil
  1179. } else {
  1180. dry_weight["code"] = 0
  1181. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1182. }
  1183. }
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "patient": dialysisinfo,
  1186. "schedule": sc,
  1187. "dryweight": dry_weight,
  1188. })
  1189. return
  1190. }