check_weight_api_controller.go 48KB

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