check_weight_api_controller.go 58KB

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