check_weight_api_controller.go 49KB

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