check_weight_api_controller.go 48KB

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