check_weight_api_controller.go 50KB

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