check_weight_api_controller.go 49KB

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