check_weight_api_controller.go 56KB

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