check_weight_api_controller.go 52KB

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