check_weight_api_controller.go 48KB

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