check_weight_api_controller.go 50KB

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