check_weight_api_controller.go 51KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  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 || adminUserInfo.Org.Id == 10469 {
  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 || adminUserInfo.Org.Id == 10469 {
  616. evaluation.PulseFrequency = 80
  617. }
  618. if adminUserInfo.Org.Id == 10440 {
  619. evaluation.Temperature = 36.5
  620. }
  621. if adminUserInfo.Org.Id == 10469 {
  622. evaluation.Temperature = 36.5
  623. }
  624. }
  625. } else {
  626. evaluation.UpdatedTime = time.Now().Unix()
  627. }
  628. evaluation.WeightBefore = weighing_before
  629. evaluation.AssessmentTime = time.Now().Unix()
  630. err := service.UpadatePredialysisEvaluation(&evaluation)
  631. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  632. redis := service.RedisClient()
  633. //清空key 值
  634. redis.Set(key, "", time.Second)
  635. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  636. redis.Set(keyOne, "", time.Second)
  637. assessdateDateStart := thisTime.Format("2006-01-02")
  638. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  639. redis.Set(keyTwo, "", time.Second)
  640. redis.Close()
  641. if err != nil {
  642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  643. return
  644. }
  645. c.ServeSuccessJSON(map[string]interface{}{
  646. "msg": "ok",
  647. "evaluation": evaluation,
  648. })
  649. return
  650. } else {
  651. // 保存透后相关数据
  652. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  653. if getAADErr != nil {
  654. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  656. return
  657. }
  658. var afterevaluation models.AssessmentAfterDislysis
  659. if assessmentAfterDislysis != nil {
  660. afterevaluation = *assessmentAfterDislysis
  661. }
  662. if assessmentAfterDislysis == nil {
  663. afterevaluation.CreatedTime = time.Now().Unix()
  664. afterevaluation.Status = 1
  665. afterevaluation.AssessmentDate = theAssessmentDateTime
  666. afterevaluation.PatientId = id
  667. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  668. } else {
  669. afterevaluation.UpdatedTime = time.Now().Unix()
  670. }
  671. afterevaluation.WeightAfter = weight_after
  672. afterevaluation.WeightLoss = weight_loss
  673. if adminUserInfo.Org.Id == 10138 {
  674. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  675. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  676. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  677. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk
  678. }
  679. if adminUserInfo.Org.Id == 10307 || adminUserInfo.Org.Id == 10445 {
  680. afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  681. }
  682. //北方营口
  683. if adminUserInfo.Org.Id == 10445 {
  684. prescribe, _ := service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  685. afterevaluation.ActualDisplacement = prescribe.DisplaceLiquiValue
  686. }
  687. //蓬安济民
  688. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  689. afterevaluation.PulseFrequency = 80
  690. }
  691. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  692. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
  693. redis := service.RedisClient()
  694. //清空key 值
  695. redis.Set(key, "", time.Second)
  696. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
  697. redis.Set(keyThree, "", time.Second)
  698. assessdateDateStart := thisTime.Format("2006-01-02")
  699. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  700. redis.Set(keyTwo, "", time.Second)
  701. redis.Close()
  702. if err == nil {
  703. c.ServeSuccessJSON(map[string]interface{}{
  704. "assessmentAfterDislysis": afterevaluation,
  705. })
  706. }
  707. }
  708. }
  709. func (c *CheckWeightApiController) SetSyncTime() {
  710. sn := c.GetString("sn")
  711. if len(sn) > 0 {
  712. redis := service.RedisClient()
  713. defer redis.Close()
  714. redis.Set(sn, 0, 0)
  715. }
  716. serviceTime := time.Now().Unix()
  717. c.ServeSuccessJSON(map[string]interface{}{
  718. "status": 1,
  719. "servicetime": serviceTime,
  720. })
  721. }
  722. func (c *CheckWeightApiController) GetPatientList() {
  723. ftype, _ := c.GetInt64("type", 0)
  724. sn := c.GetString("sn")
  725. syncTime := int64(0)
  726. redis := service.RedisClient()
  727. defer redis.Close()
  728. if len(sn) > 0 {
  729. syncTimeStr, _ := redis.Get(sn).Result()
  730. syncTime, _ = strconv.ParseInt(syncTimeStr, 10, 64)
  731. }
  732. if ftype == 1 {
  733. timeNow := time.Now().Unix()
  734. redis.Set(sn, timeNow, 0)
  735. }
  736. adminUserInfo := c.GetMobileAdminUserInfo()
  737. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
  738. need_update := 0
  739. if syncTime == 0 {
  740. need_update = 1
  741. }
  742. if error != nil {
  743. c.ErrorLog("获取病人列表失败:%v", error)
  744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  745. return
  746. }
  747. serviceTime := time.Now().Unix()
  748. c.ServeSuccessJSON(map[string]interface{}{
  749. "need_update": need_update,
  750. "patientlist": patientList,
  751. "total": total,
  752. "servicetime": serviceTime,
  753. })
  754. }
  755. func (c *CheckWeightApiController) GetPatientListForSchedules() {
  756. thisTime := time.Now()
  757. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  758. timeLayout := "2006-01-02 15:04:05"
  759. loc, _ := time.LoadLocation("Local")
  760. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  761. syncTime := theStartTime.Unix()
  762. adminUserInfo := c.GetMobileAdminUserInfo()
  763. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  764. patientSchedule := make([]map[string]interface{}, 0)
  765. for _, item := range patientList {
  766. patientTemp := make(map[string]interface{})
  767. patientTemp["patient_id"] = item.PatientId
  768. patientTemp["patient_name"] = item.Patient.Name
  769. patientTemp["schedule_type"] = item.ScheduleType
  770. patientSchedule = append(patientSchedule, patientTemp)
  771. }
  772. if error != nil {
  773. c.ErrorLog("获取病人列表失败:%v", error)
  774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  775. return
  776. }
  777. serviceTime := time.Now().Unix()
  778. c.ServeSuccessJSON(map[string]interface{}{
  779. "patientlist": patientSchedule,
  780. "total": total,
  781. "servicetime": serviceTime,
  782. })
  783. }
  784. func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
  785. patient_name := c.GetString("patient_name") //脉率
  786. thisTime := time.Now()
  787. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  788. timeLayout := "2006-01-02 15:04:05"
  789. loc, _ := time.LoadLocation("Local")
  790. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  791. syncTime := theStartTime.Unix()
  792. adminUserInfo := c.GetMobileAdminUserInfo()
  793. if len(patient_name) == 0 {
  794. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  795. patientSchedule := make([]map[string]interface{}, 0)
  796. for _, item := range patientList {
  797. patientTemp := make(map[string]interface{})
  798. patientTemp["patient_id"] = item.PatientId
  799. patientTemp["patient_name"] = item.Patient.Name
  800. patientTemp["schedule_type"] = item.ScheduleType
  801. patientSchedule = append(patientSchedule, patientTemp)
  802. }
  803. if error != nil {
  804. c.ErrorLog("获取病人列表失败:%v", error)
  805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  806. return
  807. }
  808. serviceTime := time.Now().Unix()
  809. c.ServeSuccessJSON(map[string]interface{}{
  810. "patientlist": patientSchedule,
  811. "total": total,
  812. "servicetime": serviceTime,
  813. })
  814. } else {
  815. patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime, patient_name)
  816. patientSchedule := make([]map[string]interface{}, 0)
  817. for _, item := range patientList {
  818. if item.Patient.ID > 0 {
  819. patientTemp := make(map[string]interface{})
  820. patientTemp["patient_id"] = item.PatientId
  821. patientTemp["patient_name"] = item.Patient.Name
  822. patientTemp["schedule_type"] = item.ScheduleType
  823. patientSchedule = append(patientSchedule, patientTemp)
  824. }
  825. }
  826. if error != nil {
  827. c.ErrorLog("获取病人列表失败:%v", error)
  828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  829. return
  830. }
  831. serviceTime := time.Now().Unix()
  832. c.ServeSuccessJSON(map[string]interface{}{
  833. "patientlist": patientSchedule,
  834. "total": total,
  835. "servicetime": serviceTime,
  836. })
  837. }
  838. }
  839. func (c *CheckWeightApiController) GetPatientListById() {
  840. patientId, _ := c.GetInt64("patient_id", 0)
  841. if patientId <= 0 {
  842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  843. return
  844. }
  845. adminUserInfo := c.GetMobileAdminUserInfo()
  846. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  847. if error != nil {
  848. c.ErrorLog("获取病人详情失败:%v", error)
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  850. return
  851. }
  852. c.ServeSuccessJSON(map[string]interface{}{
  853. "patientinfo": patient,
  854. })
  855. }
  856. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  857. id, _ := c.GetInt64("patient", 0)
  858. if id <= 0 {
  859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  860. return
  861. }
  862. adminUserInfo := c.GetMobileAdminUserInfo()
  863. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  864. if patient.ID <= 0 {
  865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  866. return
  867. }
  868. var dialysisinfo map[string]interface{}
  869. dialysisinfo = make(map[string]interface{})
  870. dialysisinfo["id"] = patient.ID
  871. dialysisinfo["name"] = patient.Name
  872. dialysisinfo["dialysis_no"] = patient.DialysisNo
  873. thisTime := time.Now()
  874. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  875. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  876. timeLayout := "2006-01-02 15:04:05"
  877. loc, _ := time.LoadLocation("Local")
  878. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  879. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  880. startTime := theStartTime.Unix()
  881. endTime := theEndTime.Unix()
  882. // 判断当前用户是透析前还是透析后
  883. var dialysistype int
  884. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  885. if dialysisOrder == nil {
  886. dialysistype = 1
  887. } else {
  888. dialysistype = 2
  889. }
  890. // 获取当前或者下次排班信息
  891. var sc map[string]interface{}
  892. sc = make(map[string]interface{})
  893. if dialysistype == 1 {
  894. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  895. if len(daySchedule) <= 0 {
  896. sc["code"] = 1
  897. sc["msg"] = "抱歉,您今天没有排版!"
  898. sc["mode"] = 0
  899. sc["data"] = daySchedule
  900. } else {
  901. if daySchedule[0].Schedule.ID > 0 {
  902. sc["code"] = 0
  903. sc["msg"] = ""
  904. sc["mode"] = daySchedule[0].Schedule.ModeId
  905. sc["data"] = daySchedule
  906. } else {
  907. sc["code"] = 1
  908. sc["msg"] = "抱歉,您今天没有排版!"
  909. sc["mode"] = 0
  910. sc["data"] = daySchedule
  911. }
  912. }
  913. // 排队叫号的签到
  914. go func() {
  915. ssoDomain := beego.AppConfig.String("call_domain")
  916. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  917. values := make(url.Values)
  918. http.PostForm(api, values)
  919. }()
  920. } else {
  921. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  922. if len(nextSchedule) <= 0 {
  923. sc["code"] = 1
  924. sc["msg"] = "抱歉,您后续没有排版!"
  925. sc["mode"] = 0
  926. sc["data"] = nextSchedule
  927. } else {
  928. if nextSchedule[0].Schedule.ID > 0 {
  929. sc["code"] = 0
  930. sc["msg"] = ""
  931. sc["mode"] = nextSchedule[0].Schedule.ModeId
  932. sc["data"] = nextSchedule
  933. } else {
  934. sc["code"] = 1
  935. sc["msg"] = "抱歉,您后续没有排版!"
  936. sc["mode"] = 0
  937. sc["data"] = nextSchedule
  938. }
  939. }
  940. }
  941. switch sc["mode"] {
  942. case 1:
  943. sc["mode"] = "HD"
  944. case 2:
  945. sc["mode"] = "HDF"
  946. case 3:
  947. sc["mode"] = "HD+HP"
  948. case 4:
  949. sc["mode"] = "HP"
  950. case 5:
  951. sc["mode"] = "HF"
  952. case 6:
  953. sc["mode"] = "SCUF"
  954. case 7:
  955. sc["mode"] = "IUF"
  956. case 8:
  957. sc["mode"] = "HFHD"
  958. case 9:
  959. sc["mode"] = "HFHD+HP"
  960. case 10:
  961. sc["mode"] = "PHF"
  962. case 11:
  963. sc["mode"] = "HFR"
  964. case 12:
  965. sc["mode"] = "HDF+HP"
  966. case 13:
  967. sc["mode"] = "CRRT"
  968. case 14:
  969. sc["mode"] = "腹水回输"
  970. case 15:
  971. sc["mode"] = "HD前置换"
  972. case 16:
  973. sc["mode"] = "HD后置换"
  974. case 17:
  975. sc["mode"] = "HDF前置换"
  976. case 18:
  977. sc["mode"] = "HDF后置换"
  978. default:
  979. sc["mode"] = "HD"
  980. }
  981. // 获取患者透前干体重或者获取患者透前体重
  982. var dry_weight map[string]interface{}
  983. dry_weight = make(map[string]interface{})
  984. var after_dry_weight map[string]interface{}
  985. after_dry_weight = make(map[string]interface{})
  986. if dialysistype == 1 {
  987. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  988. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  989. if err == gorm.ErrRecordNotFound {
  990. if getLPEErr != nil {
  991. dry_weight["code"] = 1
  992. dry_weight["dry_weight"] = nil
  993. } else {
  994. if lastPredialysisEvaluation == nil {
  995. dry_weight["code"] = 1
  996. dry_weight["dry_weight"] = nil
  997. } else {
  998. // 传输的干体重实际为干体重加上衣服重
  999. dry_weight["code"] = 0
  1000. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1001. }
  1002. }
  1003. } else {
  1004. if err != nil {
  1005. dry_weight["code"] = 1
  1006. dry_weight["dry_weight"] = nil
  1007. } else {
  1008. dry_weight["code"] = 0
  1009. if getLPEErr != nil {
  1010. dry_weight["code"] = 0
  1011. dry_weight["dry_weight"] = weight.DryWeight
  1012. } else {
  1013. if lastPredialysisEvaluation == nil {
  1014. dry_weight["code"] = 1
  1015. dry_weight["dry_weight"] = weight.DryWeight
  1016. } else {
  1017. // 传输的干体重实际为干体重加上衣服重
  1018. dry_weight["code"] = 0
  1019. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1020. }
  1021. }
  1022. }
  1023. }
  1024. } else {
  1025. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1026. if getPEErr != nil {
  1027. dry_weight["code"] = 1
  1028. dry_weight["dry_weight"] = nil
  1029. } else {
  1030. if predialysisEvaluation == nil {
  1031. dry_weight["code"] = 1
  1032. dry_weight["dry_weight"] = nil
  1033. } else {
  1034. dry_weight["code"] = 0
  1035. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  1036. }
  1037. }
  1038. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1039. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1040. if err == gorm.ErrRecordNotFound {
  1041. if getLPEErr != nil {
  1042. after_dry_weight["code"] = 1
  1043. after_dry_weight["dry_weight"] = nil
  1044. } else {
  1045. if lastPredialysisEvaluation == nil {
  1046. after_dry_weight["code"] = 1
  1047. after_dry_weight["dry_weight"] = nil
  1048. } else {
  1049. // 传输的干体重实际为干体重加上衣服重
  1050. after_dry_weight["code"] = 0
  1051. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1052. }
  1053. }
  1054. } else {
  1055. if err != nil {
  1056. after_dry_weight["code"] = 1
  1057. after_dry_weight["dry_weight"] = nil
  1058. } else {
  1059. after_dry_weight["code"] = 0
  1060. if getLPEErr != nil {
  1061. after_dry_weight["code"] = 0
  1062. after_dry_weight["dry_weight"] = weight.DryWeight
  1063. } else {
  1064. if lastPredialysisEvaluation == nil {
  1065. after_dry_weight["code"] = 1
  1066. after_dry_weight["dry_weight"] = weight.DryWeight
  1067. } else {
  1068. // 传输的干体重实际为干体重加上衣服重
  1069. after_dry_weight["code"] = 0
  1070. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1071. }
  1072. }
  1073. }
  1074. }
  1075. }
  1076. c.ServeSuccessJSON(map[string]interface{}{
  1077. "dialysistype": dialysistype,
  1078. "patient": dialysisinfo,
  1079. "schedule": sc,
  1080. "dryweight": dry_weight,
  1081. "after_dry_weight": after_dry_weight,
  1082. })
  1083. return
  1084. }
  1085. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  1086. id, _ := c.GetInt64("patient", 0)
  1087. if id <= 0 {
  1088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1089. return
  1090. }
  1091. adminUserInfo := c.GetMobileAdminUserInfo()
  1092. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1093. if patient.ID == 0 {
  1094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1095. return
  1096. }
  1097. var dialysisinfo map[string]interface{}
  1098. dialysisinfo = make(map[string]interface{})
  1099. dialysisinfo["id"] = patient.ID
  1100. dialysisinfo["name"] = patient.Name
  1101. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1102. thisTime := time.Now()
  1103. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1104. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1105. fmt.Println(scheduleDateStart, scheduleDateEnd)
  1106. timeLayout := "2006-01-02 15:04:05"
  1107. loc, _ := time.LoadLocation("Local")
  1108. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1109. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1110. fmt.Println(theStartTime, theEndTime)
  1111. startTime := theStartTime.Unix()
  1112. endTime := theEndTime.Unix()
  1113. var sc map[string]interface{}
  1114. sc = make(map[string]interface{})
  1115. //一天只有排班一次
  1116. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  1117. if daySchedule.ID > 0 {
  1118. switch daySchedule.ModeId {
  1119. case 1:
  1120. sc["mode"] = "HD"
  1121. case 2:
  1122. sc["mode"] = "HDF"
  1123. case 3:
  1124. sc["mode"] = "HD+HP"
  1125. case 4:
  1126. sc["mode"] = "HP"
  1127. case 5:
  1128. sc["mode"] = "HF"
  1129. case 6:
  1130. sc["mode"] = "SCUF"
  1131. case 7:
  1132. sc["mode"] = "IUF"
  1133. case 8:
  1134. sc["mode"] = "HFHD"
  1135. case 9:
  1136. sc["mode"] = "HFHD+HP"
  1137. case 10:
  1138. sc["mode"] = "PHF"
  1139. case 11:
  1140. sc["mode"] = "HFR"
  1141. case 12:
  1142. sc["mode"] = "HDF+HP"
  1143. case 13:
  1144. sc["mode"] = "CRRT"
  1145. case 14:
  1146. sc["mode"] = "腹水回输"
  1147. case 15:
  1148. sc["mode"] = "HD前置换"
  1149. case 16:
  1150. sc["mode"] = "HD后置换"
  1151. case 17:
  1152. sc["mode"] = "HDF前置换"
  1153. case 18:
  1154. sc["mode"] = "HDF后置换"
  1155. default:
  1156. sc["mode"] = "HD"
  1157. }
  1158. sc["code"] = 0
  1159. sc["msg"] = ""
  1160. sc["data"] = daySchedule
  1161. } else {
  1162. sc["code"] = 1
  1163. sc["msg"] = "抱歉,您今天没有排版!"
  1164. sc["mode"] = ""
  1165. sc["data"] = daySchedule
  1166. }
  1167. fmt.Println(sc)
  1168. type dryWeight struct {
  1169. code int
  1170. dry_weight float64
  1171. }
  1172. var dry_weight map[string]interface{}
  1173. dry_weight = make(map[string]interface{})
  1174. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1175. if getLPEErr != nil {
  1176. dry_weight["code"] = 1
  1177. dry_weight["dry_weight"] = nil
  1178. } else {
  1179. if lastPredialysisEvaluation == nil {
  1180. dry_weight["code"] = 1
  1181. dry_weight["dry_weight"] = nil
  1182. } else {
  1183. dry_weight["code"] = 0
  1184. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1185. }
  1186. }
  1187. c.ServeSuccessJSON(map[string]interface{}{
  1188. "patient": dialysisinfo,
  1189. "schedule": sc,
  1190. "dryweight": dry_weight,
  1191. })
  1192. return
  1193. }