check_weight_api_controller.go 50KB

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