check_weight_api_controller.go 48KB

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