check_weight_api_controller.go 49KB

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