check_weight_api_controller.go 51KB

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