check_weight_api_controller.go 51KB

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