check_weight_api_controller.go 50KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  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. newprescribe.Remark = dialysisSolution.Remark
  328. if adminUserInfo.Org.Id == 10340 {
  329. newprescribe.TargetUltrafiltration = 0
  330. newprescribe.Sodium = 138
  331. newprescribe.Bicarbonate = 31.1
  332. newprescribe.DialysateFlow = 500
  333. }
  334. // 针对新化博翔
  335. if adminUserInfo.Org.Id == 10447 {
  336. newprescribe.DisplaceLiquiPart = 1
  337. newprescribe.DisplaceLiquiValue = 32
  338. newprescribe.DialysateFlow = 500
  339. }
  340. //插入透析处方
  341. err := service.AddSigleRecord(&newprescribe)
  342. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  343. redis := service.RedisClient()
  344. //清空key 值
  345. redis.Set(key, "", time.Second)
  346. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  347. redis.Set(keyTwo, "", time.Second)
  348. scheduleDateStartOne := thisTime.Format("2006-01-02")
  349. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  350. redis.Set(keyThree, "", time.Second)
  351. defer redis.Close()
  352. if err != nil {
  353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  354. }
  355. }
  356. if dialysisPrescribe == nil && dialysisSolution == nil {
  357. if lastDialysisPrescribe != nil {
  358. var newprescribe models.DialysisPrescription
  359. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  360. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  361. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  362. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  363. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  364. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  365. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  366. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  367. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  368. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  369. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  370. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  371. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  372. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  373. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  374. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  375. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  376. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  377. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  378. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  379. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  380. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  381. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  382. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  383. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  384. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  385. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  386. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  387. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  388. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  389. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  390. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  391. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  392. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  393. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  394. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  395. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  396. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  397. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  398. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  399. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  400. newprescribe.CreatedTime = time.Now().Unix()
  401. newprescribe.UpdatedTime = time.Now().Unix()
  402. newprescribe.RecordDate = theAssessmentDateTime
  403. newprescribe.DewaterAmount = dewater_amount
  404. newprescribe.TargetUltrafiltration = dewater_amount
  405. newprescribe.Status = 1
  406. newprescribe.Remark = lastDialysisPrescribe.Remark
  407. if adminUserInfo.Org.Id == 10340 {
  408. newprescribe.TargetUltrafiltration = 0
  409. }
  410. err := service.AddSigleRecord(&newprescribe)
  411. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  412. redis := service.RedisClient()
  413. //清空key 值
  414. redis.Set(key, "", time.Second)
  415. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  416. redis.Set(keyTwo, "", time.Second)
  417. scheduleDateStartOne := thisTime.Format("2006-01-02")
  418. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  419. redis.Set(keyThree, "", time.Second)
  420. defer redis.Close()
  421. if err != nil {
  422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  423. }
  424. } else if system_dialysisPrescribe != nil {
  425. var newprescribe models.DialysisPrescription
  426. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  427. newprescribe.PatientId = id
  428. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  429. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  430. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  431. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  432. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  433. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  434. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  435. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  436. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  437. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  438. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  439. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  440. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  441. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  442. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  443. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  444. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  445. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  446. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  447. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  448. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  449. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  450. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  451. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  452. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  453. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  454. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  455. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  456. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  457. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  458. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  459. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  460. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  461. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  462. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  463. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  464. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  465. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  466. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  467. newprescribe.CreatedTime = time.Now().Unix()
  468. newprescribe.UpdatedTime = time.Now().Unix()
  469. newprescribe.RecordDate = theAssessmentDateTime
  470. newprescribe.DewaterAmount = dewater_amount
  471. newprescribe.TargetUltrafiltration = dewater_amount
  472. newprescribe.Status = 1
  473. if adminUserInfo.Org.Id == 10340 {
  474. newprescribe.TargetUltrafiltration = 0
  475. }
  476. err := service.AddSigleRecord(&newprescribe)
  477. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  478. redis := service.RedisClient()
  479. //清空key 值
  480. redis.Set(key, "", time.Second)
  481. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  482. redis.Set(keyTwo, "", time.Second)
  483. scheduleDateStartOne := thisTime.Format("2006-01-02")
  484. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  485. redis.Set(keyThree, "", time.Second)
  486. defer redis.Close()
  487. if err != nil {
  488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  489. }
  490. } else {
  491. var newprescribe models.DialysisPrescription
  492. newprescribe.UserOrgId = adminUserInfo.Org.Id
  493. newprescribe.PatientId = id
  494. newprescribe.ModeId = mode_id
  495. newprescribe.CreatedTime = time.Now().Unix()
  496. newprescribe.UpdatedTime = time.Now().Unix()
  497. newprescribe.RecordDate = theAssessmentDateTime
  498. newprescribe.DewaterAmount = dewater_amount
  499. newprescribe.TargetUltrafiltration = dewater_amount
  500. newprescribe.Status = 1
  501. err := service.AddSigleRecord(&newprescribe)
  502. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  503. redis := service.RedisClient()
  504. //清空key 值
  505. redis.Set(key, "", time.Second)
  506. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  507. redis.Set(keyTwo, "", time.Second)
  508. scheduleDateStartOne := thisTime.Format("2006-01-02")
  509. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  510. redis.Set(keyThree, "", time.Second)
  511. defer redis.Close()
  512. if err != nil {
  513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  514. }
  515. }
  516. }
  517. if dialysisPrescribe != nil && dialysisPrescribe.TargetUltrafiltration == 0 {
  518. dialysisPrescribe.UpdatedTime = time.Now().Unix()
  519. dialysisPrescribe.RecordDate = theAssessmentDateTime
  520. dialysisPrescribe.DewaterAmount = dewater_amount
  521. dialysisPrescribe.TargetUltrafiltration = dewater_amount
  522. dialysisPrescribe.Status = 1
  523. if adminUserInfo.Org.Id == 10340 {
  524. dialysisPrescribe.TargetUltrafiltration = 0
  525. }
  526. updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  527. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  528. redis := service.RedisClient()
  529. //清空key 值
  530. redis.Set(key, "", time.Second)
  531. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  532. redis.Set(keyTwo, "", time.Second)
  533. scheduleDateStartOne := thisTime.Format("2006-01-02")
  534. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  535. redis.Set(keyThree, "", time.Second)
  536. defer redis.Close()
  537. if updateErr != nil {
  538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  539. }
  540. }
  541. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  542. if getPEErr != nil {
  543. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  545. return
  546. }
  547. var evaluation models.PredialysisEvaluation
  548. if theEvaluation != nil {
  549. evaluation = *theEvaluation
  550. }
  551. // 如果今天没有透前评估,则插入新的数据
  552. if theEvaluation == nil {
  553. evaluation.CreatedTime = time.Now().Unix()
  554. evaluation.Status = 1
  555. evaluation.AssessmentDate = theAssessmentDateTime
  556. evaluation.PatientId = id
  557. evaluation.UserOrgId = adminUserInfo.Org.Id
  558. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  559. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  560. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  561. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  562. if getAADErr != nil {
  563. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  565. return
  566. }
  567. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  568. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  569. if err == gorm.ErrRecordNotFound {
  570. if lastPredialysisEvaluation != nil {
  571. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  572. } else {
  573. evaluation.DryWeight = 0
  574. }
  575. } else {
  576. evaluation.DryWeight = weight.DryWeight
  577. }
  578. if assessmentAfterDislysis != nil {
  579. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  580. }
  581. if lastPredialysisEvaluation != nil {
  582. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  583. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  584. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight
  585. evaluation.Temperature = lastPredialysisEvaluation.Temperature
  586. evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
  587. evaluation.Catheter = lastPredialysisEvaluation.Catheter
  588. evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
  589. evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
  590. evaluation.Complication = lastPredialysisEvaluation.Complication
  591. evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
  592. evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase
  593. evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
  594. evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
  595. evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
  596. evaluation.InternalFistulaSkin = lastPredialysisEvaluation.InternalFistulaSkin //血透通路皮肤情况
  597. evaluation.CatheterBend = lastPredialysisEvaluation.CatheterBend //导管打折
  598. evaluation.IsHemorrhage = lastPredialysisEvaluation.IsHemorrhage //出血
  599. evaluation.IsInfect = lastPredialysisEvaluation.IsInfect //感染
  600. evaluation.Exposed = lastPredialysisEvaluation.Exposed // 外漏
  601. evaluation.DialysisCount = lastPredialysisEvaluation.DialysisCount //呼吸频次
  602. evaluation.Phinholing = lastPredialysisEvaluation.Phinholing //针眼
  603. evaluation.Remark = lastPredialysisEvaluation.Remark
  604. if adminUserInfo.Org.Id == 10318 {
  605. evaluation.Remark = "患者已确认无发热,无流行病学接触史"
  606. }
  607. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10447 {
  608. evaluation.BreathingRate = "20"
  609. }
  610. if adminUserInfo.Org.Id == 10445 {
  611. evaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
  612. }
  613. if adminUserInfo.Org.Id == 9829 {
  614. evaluation.PulseFrequency = 80
  615. }
  616. }
  617. } else {
  618. evaluation.UpdatedTime = time.Now().Unix()
  619. }
  620. evaluation.WeightBefore = weighing_before
  621. evaluation.AssessmentTime = time.Now().Unix()
  622. err := service.UpadatePredialysisEvaluation(&evaluation)
  623. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  624. redis := service.RedisClient()
  625. //清空key 值
  626. redis.Set(key, "", time.Second)
  627. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  628. redis.Set(keyOne, "", time.Second)
  629. assessdateDateStart := thisTime.Format("2006-01-02")
  630. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  631. redis.Set(keyTwo, "", time.Second)
  632. redis.Close()
  633. if err != nil {
  634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  635. return
  636. }
  637. c.ServeSuccessJSON(map[string]interface{}{
  638. "msg": "ok",
  639. "evaluation": evaluation,
  640. })
  641. return
  642. } else {
  643. // 保存透后相关数据
  644. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  645. if getAADErr != nil {
  646. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  648. return
  649. }
  650. var afterevaluation models.AssessmentAfterDislysis
  651. if assessmentAfterDislysis != nil {
  652. afterevaluation = *assessmentAfterDislysis
  653. }
  654. if assessmentAfterDislysis == nil {
  655. afterevaluation.CreatedTime = time.Now().Unix()
  656. afterevaluation.Status = 1
  657. afterevaluation.AssessmentDate = theAssessmentDateTime
  658. afterevaluation.PatientId = id
  659. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  660. } else {
  661. afterevaluation.UpdatedTime = time.Now().Unix()
  662. }
  663. afterevaluation.WeightAfter = weight_after
  664. afterevaluation.WeightLoss = weight_loss
  665. if adminUserInfo.Org.Id == 10138 {
  666. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  667. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  668. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  669. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk
  670. }
  671. if adminUserInfo.Org.Id == 10307 || adminUserInfo.Org.Id == 10445 {
  672. afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  673. }
  674. //北方营口
  675. if adminUserInfo.Org.Id == 10445 {
  676. prescribe, _ := service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  677. afterevaluation.ActualDisplacement = prescribe.DisplaceLiquiValue
  678. }
  679. //蓬安济民
  680. if adminUserInfo.Org.Id == 9829 {
  681. afterevaluation.PulseFrequency = 80
  682. }
  683. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  684. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
  685. redis := service.RedisClient()
  686. //清空key 值
  687. redis.Set(key, "", time.Second)
  688. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
  689. redis.Set(keyThree, "", time.Second)
  690. assessdateDateStart := thisTime.Format("2006-01-02")
  691. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  692. redis.Set(keyTwo, "", time.Second)
  693. redis.Close()
  694. if err == nil {
  695. c.ServeSuccessJSON(map[string]interface{}{
  696. "assessmentAfterDislysis": afterevaluation,
  697. })
  698. }
  699. }
  700. }
  701. func (c *CheckWeightApiController) SetSyncTime() {
  702. sn := c.GetString("sn")
  703. if len(sn) > 0 {
  704. redis := service.RedisClient()
  705. defer redis.Close()
  706. redis.Set(sn, 0, 0)
  707. }
  708. serviceTime := time.Now().Unix()
  709. c.ServeSuccessJSON(map[string]interface{}{
  710. "status": 1,
  711. "servicetime": serviceTime,
  712. })
  713. }
  714. func (c *CheckWeightApiController) GetPatientList() {
  715. ftype, _ := c.GetInt64("type", 0)
  716. sn := c.GetString("sn")
  717. syncTime := int64(0)
  718. redis := service.RedisClient()
  719. defer redis.Close()
  720. if len(sn) > 0 {
  721. syncTimeStr, _ := redis.Get(sn).Result()
  722. syncTime, _ = strconv.ParseInt(syncTimeStr, 10, 64)
  723. }
  724. if ftype == 1 {
  725. timeNow := time.Now().Unix()
  726. redis.Set(sn, timeNow, 0)
  727. }
  728. adminUserInfo := c.GetMobileAdminUserInfo()
  729. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
  730. need_update := 0
  731. if syncTime == 0 {
  732. need_update = 1
  733. }
  734. if error != nil {
  735. c.ErrorLog("获取病人列表失败:%v", error)
  736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  737. return
  738. }
  739. serviceTime := time.Now().Unix()
  740. c.ServeSuccessJSON(map[string]interface{}{
  741. "need_update": need_update,
  742. "patientlist": patientList,
  743. "total": total,
  744. "servicetime": serviceTime,
  745. })
  746. }
  747. func (c *CheckWeightApiController) GetPatientListForSchedules() {
  748. thisTime := time.Now()
  749. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  750. timeLayout := "2006-01-02 15:04:05"
  751. loc, _ := time.LoadLocation("Local")
  752. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  753. syncTime := theStartTime.Unix()
  754. adminUserInfo := c.GetMobileAdminUserInfo()
  755. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  756. patientSchedule := make([]map[string]interface{}, 0)
  757. for _, item := range patientList {
  758. patientTemp := make(map[string]interface{})
  759. patientTemp["patient_id"] = item.PatientId
  760. patientTemp["patient_name"] = item.Patient.Name
  761. patientTemp["schedule_type"] = item.ScheduleType
  762. patientSchedule = append(patientSchedule, patientTemp)
  763. }
  764. if error != nil {
  765. c.ErrorLog("获取病人列表失败:%v", error)
  766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  767. return
  768. }
  769. serviceTime := time.Now().Unix()
  770. c.ServeSuccessJSON(map[string]interface{}{
  771. "patientlist": patientSchedule,
  772. "total": total,
  773. "servicetime": serviceTime,
  774. })
  775. }
  776. func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
  777. patient_name := c.GetString("patient_name") //脉率
  778. thisTime := time.Now()
  779. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  780. timeLayout := "2006-01-02 15:04:05"
  781. loc, _ := time.LoadLocation("Local")
  782. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  783. syncTime := theStartTime.Unix()
  784. adminUserInfo := c.GetMobileAdminUserInfo()
  785. if len(patient_name) == 0 {
  786. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  787. patientSchedule := make([]map[string]interface{}, 0)
  788. for _, item := range patientList {
  789. patientTemp := make(map[string]interface{})
  790. patientTemp["patient_id"] = item.PatientId
  791. patientTemp["patient_name"] = item.Patient.Name
  792. patientTemp["schedule_type"] = item.ScheduleType
  793. patientSchedule = append(patientSchedule, patientTemp)
  794. }
  795. if error != nil {
  796. c.ErrorLog("获取病人列表失败:%v", error)
  797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  798. return
  799. }
  800. serviceTime := time.Now().Unix()
  801. c.ServeSuccessJSON(map[string]interface{}{
  802. "patientlist": patientSchedule,
  803. "total": total,
  804. "servicetime": serviceTime,
  805. })
  806. } else {
  807. patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime, patient_name)
  808. patientSchedule := make([]map[string]interface{}, 0)
  809. for _, item := range patientList {
  810. if item.Patient.ID > 0 {
  811. patientTemp := make(map[string]interface{})
  812. patientTemp["patient_id"] = item.PatientId
  813. patientTemp["patient_name"] = item.Patient.Name
  814. patientTemp["schedule_type"] = item.ScheduleType
  815. patientSchedule = append(patientSchedule, patientTemp)
  816. }
  817. }
  818. if error != nil {
  819. c.ErrorLog("获取病人列表失败:%v", error)
  820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  821. return
  822. }
  823. serviceTime := time.Now().Unix()
  824. c.ServeSuccessJSON(map[string]interface{}{
  825. "patientlist": patientSchedule,
  826. "total": total,
  827. "servicetime": serviceTime,
  828. })
  829. }
  830. }
  831. func (c *CheckWeightApiController) GetPatientListById() {
  832. patientId, _ := c.GetInt64("patient_id", 0)
  833. if patientId <= 0 {
  834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  835. return
  836. }
  837. adminUserInfo := c.GetMobileAdminUserInfo()
  838. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  839. if error != nil {
  840. c.ErrorLog("获取病人详情失败:%v", error)
  841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  842. return
  843. }
  844. c.ServeSuccessJSON(map[string]interface{}{
  845. "patientinfo": patient,
  846. })
  847. }
  848. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  849. id, _ := c.GetInt64("patient", 0)
  850. if id <= 0 {
  851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  852. return
  853. }
  854. adminUserInfo := c.GetMobileAdminUserInfo()
  855. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  856. if patient.ID <= 0 {
  857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  858. return
  859. }
  860. var dialysisinfo map[string]interface{}
  861. dialysisinfo = make(map[string]interface{})
  862. dialysisinfo["id"] = patient.ID
  863. dialysisinfo["name"] = patient.Name
  864. dialysisinfo["dialysis_no"] = patient.DialysisNo
  865. thisTime := time.Now()
  866. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  867. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  868. timeLayout := "2006-01-02 15:04:05"
  869. loc, _ := time.LoadLocation("Local")
  870. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  871. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  872. startTime := theStartTime.Unix()
  873. endTime := theEndTime.Unix()
  874. // 判断当前用户是透析前还是透析后
  875. var dialysistype int
  876. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  877. if dialysisOrder == nil {
  878. dialysistype = 1
  879. } else {
  880. dialysistype = 2
  881. }
  882. // 获取当前或者下次排班信息
  883. var sc map[string]interface{}
  884. sc = make(map[string]interface{})
  885. if dialysistype == 1 {
  886. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  887. if len(daySchedule) <= 0 {
  888. sc["code"] = 1
  889. sc["msg"] = "抱歉,您今天没有排版!"
  890. sc["mode"] = 0
  891. sc["data"] = daySchedule
  892. } else {
  893. if daySchedule[0].Schedule.ID > 0 {
  894. sc["code"] = 0
  895. sc["msg"] = ""
  896. sc["mode"] = daySchedule[0].Schedule.ModeId
  897. sc["data"] = daySchedule
  898. } else {
  899. sc["code"] = 1
  900. sc["msg"] = "抱歉,您今天没有排版!"
  901. sc["mode"] = 0
  902. sc["data"] = daySchedule
  903. }
  904. }
  905. // 排队叫号的签到
  906. go func() {
  907. ssoDomain := beego.AppConfig.String("call_domain")
  908. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  909. values := make(url.Values)
  910. http.PostForm(api, values)
  911. }()
  912. } else {
  913. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  914. if len(nextSchedule) <= 0 {
  915. sc["code"] = 1
  916. sc["msg"] = "抱歉,您后续没有排版!"
  917. sc["mode"] = 0
  918. sc["data"] = nextSchedule
  919. } else {
  920. if nextSchedule[0].Schedule.ID > 0 {
  921. sc["code"] = 0
  922. sc["msg"] = ""
  923. sc["mode"] = nextSchedule[0].Schedule.ModeId
  924. sc["data"] = nextSchedule
  925. } else {
  926. sc["code"] = 1
  927. sc["msg"] = "抱歉,您后续没有排版!"
  928. sc["mode"] = 0
  929. sc["data"] = nextSchedule
  930. }
  931. }
  932. }
  933. switch sc["mode"] {
  934. case 1:
  935. sc["mode"] = "HD"
  936. case 2:
  937. sc["mode"] = "HDF"
  938. case 3:
  939. sc["mode"] = "HD+HP"
  940. case 4:
  941. sc["mode"] = "HP"
  942. case 5:
  943. sc["mode"] = "HF"
  944. case 6:
  945. sc["mode"] = "SCUF"
  946. case 7:
  947. sc["mode"] = "IUF"
  948. case 8:
  949. sc["mode"] = "HFHD"
  950. case 9:
  951. sc["mode"] = "HFHD+HP"
  952. case 10:
  953. sc["mode"] = "PHF"
  954. case 11:
  955. sc["mode"] = "HFR"
  956. case 12:
  957. sc["mode"] = "HDF+HP"
  958. case 13:
  959. sc["mode"] = "CRRT"
  960. case 14:
  961. sc["mode"] = "腹水回输"
  962. case 15:
  963. sc["mode"] = "HD前置换"
  964. case 16:
  965. sc["mode"] = "HD后置换"
  966. case 17:
  967. sc["mode"] = "HDF前置换"
  968. case 18:
  969. sc["mode"] = "HDF后置换"
  970. default:
  971. sc["mode"] = "HD"
  972. }
  973. // 获取患者透前干体重或者获取患者透前体重
  974. var dry_weight map[string]interface{}
  975. dry_weight = make(map[string]interface{})
  976. var after_dry_weight map[string]interface{}
  977. after_dry_weight = make(map[string]interface{})
  978. if dialysistype == 1 {
  979. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  980. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  981. if err == gorm.ErrRecordNotFound {
  982. if getLPEErr != nil {
  983. dry_weight["code"] = 1
  984. dry_weight["dry_weight"] = nil
  985. } else {
  986. if lastPredialysisEvaluation == nil {
  987. dry_weight["code"] = 1
  988. dry_weight["dry_weight"] = nil
  989. } else {
  990. // 传输的干体重实际为干体重加上衣服重
  991. dry_weight["code"] = 0
  992. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  993. }
  994. }
  995. } else {
  996. if err != nil {
  997. dry_weight["code"] = 1
  998. dry_weight["dry_weight"] = nil
  999. } else {
  1000. dry_weight["code"] = 0
  1001. if getLPEErr != nil {
  1002. dry_weight["code"] = 0
  1003. dry_weight["dry_weight"] = weight.DryWeight
  1004. } else {
  1005. if lastPredialysisEvaluation == nil {
  1006. dry_weight["code"] = 1
  1007. dry_weight["dry_weight"] = weight.DryWeight
  1008. } else {
  1009. // 传输的干体重实际为干体重加上衣服重
  1010. dry_weight["code"] = 0
  1011. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1012. }
  1013. }
  1014. }
  1015. }
  1016. } else {
  1017. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1018. if getPEErr != nil {
  1019. dry_weight["code"] = 1
  1020. dry_weight["dry_weight"] = nil
  1021. } else {
  1022. if predialysisEvaluation == nil {
  1023. dry_weight["code"] = 1
  1024. dry_weight["dry_weight"] = nil
  1025. } else {
  1026. dry_weight["code"] = 0
  1027. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  1028. }
  1029. }
  1030. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1031. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1032. if err == gorm.ErrRecordNotFound {
  1033. if getLPEErr != nil {
  1034. after_dry_weight["code"] = 1
  1035. after_dry_weight["dry_weight"] = nil
  1036. } else {
  1037. if lastPredialysisEvaluation == nil {
  1038. after_dry_weight["code"] = 1
  1039. after_dry_weight["dry_weight"] = nil
  1040. } else {
  1041. // 传输的干体重实际为干体重加上衣服重
  1042. after_dry_weight["code"] = 0
  1043. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1044. }
  1045. }
  1046. } else {
  1047. if err != nil {
  1048. after_dry_weight["code"] = 1
  1049. after_dry_weight["dry_weight"] = nil
  1050. } else {
  1051. after_dry_weight["code"] = 0
  1052. if getLPEErr != nil {
  1053. after_dry_weight["code"] = 0
  1054. after_dry_weight["dry_weight"] = weight.DryWeight
  1055. } else {
  1056. if lastPredialysisEvaluation == nil {
  1057. after_dry_weight["code"] = 1
  1058. after_dry_weight["dry_weight"] = weight.DryWeight
  1059. } else {
  1060. // 传输的干体重实际为干体重加上衣服重
  1061. after_dry_weight["code"] = 0
  1062. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1063. }
  1064. }
  1065. }
  1066. }
  1067. }
  1068. c.ServeSuccessJSON(map[string]interface{}{
  1069. "dialysistype": dialysistype,
  1070. "patient": dialysisinfo,
  1071. "schedule": sc,
  1072. "dryweight": dry_weight,
  1073. "after_dry_weight": after_dry_weight,
  1074. })
  1075. return
  1076. }
  1077. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  1078. id, _ := c.GetInt64("patient", 0)
  1079. if id <= 0 {
  1080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1081. return
  1082. }
  1083. adminUserInfo := c.GetMobileAdminUserInfo()
  1084. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1085. if patient.ID == 0 {
  1086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1087. return
  1088. }
  1089. var dialysisinfo map[string]interface{}
  1090. dialysisinfo = make(map[string]interface{})
  1091. dialysisinfo["id"] = patient.ID
  1092. dialysisinfo["name"] = patient.Name
  1093. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1094. thisTime := time.Now()
  1095. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1096. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1097. fmt.Println(scheduleDateStart, scheduleDateEnd)
  1098. timeLayout := "2006-01-02 15:04:05"
  1099. loc, _ := time.LoadLocation("Local")
  1100. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1101. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1102. fmt.Println(theStartTime, theEndTime)
  1103. startTime := theStartTime.Unix()
  1104. endTime := theEndTime.Unix()
  1105. var sc map[string]interface{}
  1106. sc = make(map[string]interface{})
  1107. //一天只有排班一次
  1108. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  1109. if daySchedule.ID > 0 {
  1110. switch daySchedule.ModeId {
  1111. case 1:
  1112. sc["mode"] = "HD"
  1113. case 2:
  1114. sc["mode"] = "HDF"
  1115. case 3:
  1116. sc["mode"] = "HD+HP"
  1117. case 4:
  1118. sc["mode"] = "HP"
  1119. case 5:
  1120. sc["mode"] = "HF"
  1121. case 6:
  1122. sc["mode"] = "SCUF"
  1123. case 7:
  1124. sc["mode"] = "IUF"
  1125. case 8:
  1126. sc["mode"] = "HFHD"
  1127. case 9:
  1128. sc["mode"] = "HFHD+HP"
  1129. case 10:
  1130. sc["mode"] = "PHF"
  1131. case 11:
  1132. sc["mode"] = "HFR"
  1133. case 12:
  1134. sc["mode"] = "HDF+HP"
  1135. case 13:
  1136. sc["mode"] = "CRRT"
  1137. case 14:
  1138. sc["mode"] = "腹水回输"
  1139. case 15:
  1140. sc["mode"] = "HD前置换"
  1141. case 16:
  1142. sc["mode"] = "HD后置换"
  1143. case 17:
  1144. sc["mode"] = "HDF前置换"
  1145. case 18:
  1146. sc["mode"] = "HDF后置换"
  1147. default:
  1148. sc["mode"] = "HD"
  1149. }
  1150. sc["code"] = 0
  1151. sc["msg"] = ""
  1152. sc["data"] = daySchedule
  1153. } else {
  1154. sc["code"] = 1
  1155. sc["msg"] = "抱歉,您今天没有排版!"
  1156. sc["mode"] = ""
  1157. sc["data"] = daySchedule
  1158. }
  1159. fmt.Println(sc)
  1160. type dryWeight struct {
  1161. code int
  1162. dry_weight float64
  1163. }
  1164. var dry_weight map[string]interface{}
  1165. dry_weight = make(map[string]interface{})
  1166. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1167. if getLPEErr != nil {
  1168. dry_weight["code"] = 1
  1169. dry_weight["dry_weight"] = nil
  1170. } else {
  1171. if lastPredialysisEvaluation == nil {
  1172. dry_weight["code"] = 1
  1173. dry_weight["dry_weight"] = nil
  1174. } else {
  1175. dry_weight["code"] = 0
  1176. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1177. }
  1178. }
  1179. c.ServeSuccessJSON(map[string]interface{}{
  1180. "patient": dialysisinfo,
  1181. "schedule": sc,
  1182. "dryweight": dry_weight,
  1183. })
  1184. return
  1185. }