check_weight_api_controller.go 64KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819
  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 == 10490 {
  375. newprescribe.Remark = ""
  376. }
  377. if adminUserInfo.Org.Id == 10599 {
  378. // 获取透析模版
  379. solutionone, _ := service.MobileGetDialysisSolutionByModeIdSevenTwety(adminUserInfo.Org.Id, id, schedual.ModeId)
  380. if solutionone.Anticoagulant > 0 {
  381. newprescribe.Anticoagulant = solutionone.Anticoagulant
  382. newprescribe.AnticoagulantShouji = solutionone.AnticoagulantShouji
  383. newprescribe.AnticoagulantWeichi = solutionone.AnticoagulantWeichi
  384. newprescribe.AnticoagulantZongliang = solutionone.AnticoagulantZongliang
  385. newprescribe.BloodAccess = solutionone.BloodAccess
  386. newprescribe.DialysisDurationHour = solutionone.DialysisDurationHour
  387. newprescribe.DialysisDurationMinute = solutionone.DialysisDurationMinute
  388. newprescribe.DialysisIrrigation = solutionone.DialysisIrrigation
  389. newprescribe.DialysisDialyszers = solutionone.DialysisDialyszers
  390. newprescribe.DialysisStrainer = solutionone.DialysisStrainer
  391. }
  392. }
  393. //针对普宁和揭阳
  394. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10599 {
  395. prescriptionTwenty, _ := service.GetLastDialysisPrescriptionTwenty(newprescribe.PatientId, newprescribe.RecordDate, newprescribe.UserOrgId)
  396. if prescriptionTwenty.ID == 0 {
  397. //插入透析处方
  398. service.AddSigleRecord(&newprescribe)
  399. } else {
  400. //插入透析处方
  401. service.UpdateAddSigleRecord(prescriptionTwenty.ID, newprescribe.TargetUltrafiltration)
  402. }
  403. } else {
  404. //插入透析处方
  405. service.AddSigleRecord(&newprescribe)
  406. }
  407. //记录日志
  408. byterequest, _ := json.Marshal(newprescribe)
  409. prescriptionLog := models.XtDialysisPrescriptionLog{
  410. UserOrgId: newprescribe.UserOrgId,
  411. Ctime: time.Now().Unix(),
  412. Mtime: 0,
  413. ErrLog: string(byterequest),
  414. AdminUserId: adminUserInfo.AdminUser.Id,
  415. RecordDate: newprescribe.RecordDate,
  416. PatientId: newprescribe.PatientId,
  417. Source: "物联网上传",
  418. Status: 1,
  419. }
  420. service.CreatePrescriptionLog(prescriptionLog)
  421. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  422. redis := service.RedisClient()
  423. //清空key 值
  424. redis.Set(key, "", time.Second)
  425. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  426. redis.Set(keyTwo, "", time.Second)
  427. scheduleDateStartOne := thisTime.Format("2006-01-02")
  428. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  429. redis.Set(keyThree, "", time.Second)
  430. defer redis.Close()
  431. }
  432. if dialysisPrescribe == nil && dialysisSolution == nil {
  433. if lastDialysisPrescribe != nil {
  434. var newprescribe models.DialysisPrescription
  435. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  436. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  437. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  438. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  439. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  440. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  441. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  442. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  443. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  444. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  445. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  446. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  447. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  448. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  449. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  450. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  451. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  452. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  453. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  454. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  455. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  456. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  457. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  458. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  459. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  460. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  461. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  462. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  463. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  464. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  465. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  466. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  467. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  468. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  469. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  470. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  471. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  472. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  473. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  474. newprescribe.DialysisStrainer = lastDialysisPrescribe.DialysisStrainer
  475. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  476. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  477. newprescribe.BloodAccessPartId = lastDialysisPrescribe.BloodAccessPartId
  478. newprescribe.CreatedTime = time.Now().Unix()
  479. newprescribe.UpdatedTime = time.Now().Unix()
  480. newprescribe.RecordDate = theAssessmentDateTime
  481. newprescribe.DewaterAmount = dewater_amount
  482. newprescribe.TargetUltrafiltration = dewater_amount
  483. newprescribe.PrescriptionWater = dewater_amount
  484. newprescribe.Status = 1
  485. //if adminUserInfo.Org.Id != 10490 {
  486. // newprescribe.Remark = lastDialysisPrescribe.Remark
  487. //} else {
  488. // newprescribe.Remark = ""
  489. //}
  490. if adminUserInfo.Org.Id == 10490 {
  491. newprescribe.Remark = ""
  492. }
  493. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  494. newprescribe.PrescribingNumber = 1
  495. if adminUserInfo.Org.Id == 10340 {
  496. newprescribe.TargetUltrafiltration = 0
  497. }
  498. if adminUserInfo.Org.Id == 10121 {
  499. newprescribe.DialysisDurationHour = 4
  500. newprescribe.DialysisDurationMinute = 0
  501. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  502. }
  503. if adminUserInfo.Org.Id == 10445 {
  504. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  505. newprescribe.Remark = lastDialysisPrescription.Remark
  506. }
  507. //err := service.AddSigleRecord(&newprescribe)
  508. var err error
  509. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10599 || adminUserInfo.Org.Id == 3877 {
  510. prescriptionTwenty, _ := service.GetLastDialysisPrescriptionTwenty(newprescribe.PatientId, newprescribe.RecordDate, newprescribe.UserOrgId)
  511. if prescriptionTwenty.ID == 0 {
  512. //插入透析处方
  513. service.AddSigleRecord(&newprescribe)
  514. } else {
  515. //插入透析处方
  516. service.UpdateAddSigleRecord(prescriptionTwenty.ID, newprescribe.TargetUltrafiltration)
  517. }
  518. } else {
  519. //插入透析处方
  520. err = service.AddSigleRecord(&newprescribe)
  521. }
  522. //记录日志
  523. byterequest, _ := json.Marshal(newprescribe)
  524. prescriptionLog := models.XtDialysisPrescriptionLog{
  525. UserOrgId: adminUserInfo.Org.Id,
  526. Ctime: time.Now().Unix(),
  527. Mtime: 0,
  528. ErrLog: string(byterequest),
  529. AdminUserId: adminUserInfo.AdminUser.Id,
  530. RecordDate: newprescribe.RecordDate,
  531. PatientId: id,
  532. Source: "物联网上传",
  533. Status: 1,
  534. }
  535. service.CreatePrescriptionLog(prescriptionLog)
  536. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  537. redis := service.RedisClient()
  538. //清空key 值
  539. redis.Set(key, "", time.Second)
  540. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  541. redis.Set(keyTwo, "", time.Second)
  542. scheduleDateStartOne := thisTime.Format("2006-01-02")
  543. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  544. redis.Set(keyThree, "", time.Second)
  545. defer redis.Close()
  546. if err != nil {
  547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  548. }
  549. } else if system_dialysisPrescribe != nil {
  550. var newprescribe models.DialysisPrescription
  551. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  552. newprescribe.PatientId = id
  553. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  554. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  555. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  556. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  557. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  558. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  559. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  560. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  561. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  562. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  563. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  564. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  565. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  566. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  567. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  568. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  569. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  570. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  571. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  572. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  573. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  574. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  575. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  576. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  577. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  578. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  579. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  580. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  581. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  582. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  583. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  584. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  585. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  586. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  587. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  588. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  589. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  590. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  591. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  592. newprescribe.CreatedTime = time.Now().Unix()
  593. newprescribe.UpdatedTime = time.Now().Unix()
  594. newprescribe.RecordDate = theAssessmentDateTime
  595. newprescribe.DewaterAmount = dewater_amount
  596. newprescribe.TargetUltrafiltration = dewater_amount
  597. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  598. newprescribe.BloodAccessPartId = lastDialysisPrescribe.BloodAccessPartId
  599. newprescribe.Status = 1
  600. newprescribe.PrescribingNumber = 1
  601. if adminUserInfo.Org.Id == 10340 {
  602. newprescribe.TargetUltrafiltration = 0
  603. }
  604. if adminUserInfo.Org.Id == 10121 {
  605. newprescribe.DialysisDurationHour = 4
  606. newprescribe.DialysisDurationMinute = 0
  607. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  608. }
  609. if adminUserInfo.Org.Id == 10445 {
  610. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  611. newprescribe.Remark = lastDialysisPrescription.Remark
  612. }
  613. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10599 || adminUserInfo.Org.Id == 3877 {
  614. prescriptionTwenty, _ := service.GetLastDialysisPrescriptionTwenty(newprescribe.PatientId, newprescribe.RecordDate, newprescribe.UserOrgId)
  615. if prescriptionTwenty.ID == 0 {
  616. //插入透析处方
  617. service.AddSigleRecord(&newprescribe)
  618. } else {
  619. //插入透析处方
  620. service.UpdateAddSigleRecord(prescriptionTwenty.ID, newprescribe.TargetUltrafiltration)
  621. }
  622. } else {
  623. service.AddSigleRecord(&newprescribe)
  624. }
  625. //记录日志
  626. byterequest, _ := json.Marshal(newprescribe)
  627. prescriptionLog := models.XtDialysisPrescriptionLog{
  628. UserOrgId: adminUserInfo.Org.Id,
  629. Ctime: time.Now().Unix(),
  630. Mtime: 0,
  631. ErrLog: string(byterequest),
  632. AdminUserId: adminUserInfo.AdminUser.Id,
  633. RecordDate: newprescribe.RecordDate,
  634. PatientId: id,
  635. Source: "物联网上传",
  636. Status: 1,
  637. }
  638. service.CreatePrescriptionLog(prescriptionLog)
  639. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  640. redis := service.RedisClient()
  641. //清空key 值
  642. redis.Set(key, "", time.Second)
  643. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  644. redis.Set(keyTwo, "", time.Second)
  645. scheduleDateStartOne := thisTime.Format("2006-01-02")
  646. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  647. redis.Set(keyThree, "", time.Second)
  648. defer redis.Close()
  649. } else {
  650. var newprescribe models.DialysisPrescription
  651. newprescribe.UserOrgId = adminUserInfo.Org.Id
  652. newprescribe.PatientId = id
  653. newprescribe.ModeId = mode_id
  654. newprescribe.CreatedTime = time.Now().Unix()
  655. newprescribe.UpdatedTime = time.Now().Unix()
  656. newprescribe.RecordDate = theAssessmentDateTime
  657. newprescribe.DewaterAmount = dewater_amount
  658. newprescribe.TargetUltrafiltration = dewater_amount
  659. newprescribe.Status = 1
  660. if adminUserInfo.Org.Id == 10445 {
  661. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  662. newprescribe.Remark = lastDialysisPrescription.Remark
  663. }
  664. err := service.AddSigleRecord(&newprescribe)
  665. //记录日志
  666. byterequest, _ := json.Marshal(newprescribe)
  667. prescriptionLog := models.XtDialysisPrescriptionLog{
  668. UserOrgId: adminUserInfo.Org.Id,
  669. Ctime: time.Now().Unix(),
  670. Mtime: 0,
  671. ErrLog: string(byterequest),
  672. AdminUserId: adminUserInfo.AdminUser.Id,
  673. RecordDate: newprescribe.RecordDate,
  674. PatientId: id,
  675. Source: "物联网上传",
  676. Status: 1,
  677. }
  678. service.CreatePrescriptionLog(prescriptionLog)
  679. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  680. redis := service.RedisClient()
  681. //清空key 值
  682. redis.Set(key, "", time.Second)
  683. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  684. redis.Set(keyTwo, "", time.Second)
  685. scheduleDateStartOne := thisTime.Format("2006-01-02")
  686. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  687. redis.Set(keyThree, "", time.Second)
  688. defer redis.Close()
  689. if err != nil {
  690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  691. }
  692. }
  693. }
  694. if dialysisPrescribe != nil && dialysisPrescribe.TargetUltrafiltration == 0 {
  695. dialysisPrescribe.UpdatedTime = time.Now().Unix()
  696. dialysisPrescribe.RecordDate = theAssessmentDateTime
  697. dialysisPrescribe.DewaterAmount = dewater_amount
  698. dialysisPrescribe.TargetUltrafiltration = dewater_amount
  699. dialysisPrescribe.Status = 1
  700. if adminUserInfo.Org.Id == 10340 {
  701. dialysisPrescribe.TargetUltrafiltration = 0
  702. }
  703. if adminUserInfo.Org.Id == 10445 {
  704. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  705. dialysisPrescribe.Remark = lastDialysisPrescription.Remark
  706. }
  707. updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  708. //记录日志
  709. byterequest, _ := json.Marshal(dialysisPrescribe)
  710. prescriptionLog := models.XtDialysisPrescriptionLog{
  711. UserOrgId: adminUserInfo.Org.Id,
  712. Ctime: time.Now().Unix(),
  713. Mtime: 0,
  714. ErrLog: string(byterequest),
  715. AdminUserId: adminUserInfo.AdminUser.Id,
  716. RecordDate: dialysisPrescribe.RecordDate,
  717. PatientId: id,
  718. Source: "物联网上传",
  719. Status: 1,
  720. }
  721. service.CreatePrescriptionLog(prescriptionLog)
  722. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  723. redis := service.RedisClient()
  724. //清空key 值
  725. redis.Set(key, "", time.Second)
  726. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  727. redis.Set(keyTwo, "", time.Second)
  728. scheduleDateStartOne := thisTime.Format("2006-01-02")
  729. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  730. redis.Set(keyThree, "", time.Second)
  731. defer redis.Close()
  732. if updateErr != nil {
  733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  734. }
  735. }
  736. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  737. if getPEErr != nil {
  738. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  740. return
  741. }
  742. var evaluation models.PredialysisEvaluation
  743. if theEvaluation != nil {
  744. evaluation = *theEvaluation
  745. }
  746. // 如果今天没有透前评估,则插入新的数据
  747. if theEvaluation == nil {
  748. evaluation.CreatedTime = time.Now().Unix()
  749. evaluation.Status = 1
  750. evaluation.AssessmentDate = theAssessmentDateTime
  751. evaluation.PatientId = id
  752. evaluation.UserOrgId = adminUserInfo.Org.Id
  753. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  754. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  755. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  756. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  757. if getAADErr != nil {
  758. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  760. return
  761. }
  762. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  763. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  764. if err == gorm.ErrRecordNotFound {
  765. if lastPredialysisEvaluation != nil {
  766. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  767. } else {
  768. evaluation.DryWeight = 0
  769. }
  770. } else {
  771. evaluation.DryWeight = weight.DryWeight
  772. }
  773. if assessmentAfterDislysis != nil {
  774. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  775. }
  776. if lastPredialysisEvaluation != nil {
  777. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  778. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  779. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight
  780. evaluation.Temperature = lastPredialysisEvaluation.Temperature
  781. evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
  782. evaluation.Catheter = lastPredialysisEvaluation.Catheter
  783. evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
  784. evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
  785. evaluation.Complication = lastPredialysisEvaluation.Complication
  786. evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
  787. evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase
  788. evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
  789. evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
  790. evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
  791. evaluation.InternalFistulaSkin = lastPredialysisEvaluation.InternalFistulaSkin //血透通路皮肤情况
  792. evaluation.CatheterBend = lastPredialysisEvaluation.CatheterBend //导管打折
  793. evaluation.IsHemorrhage = lastPredialysisEvaluation.IsHemorrhage //出血
  794. evaluation.IsInfect = lastPredialysisEvaluation.IsInfect //感染
  795. evaluation.Exposed = lastPredialysisEvaluation.Exposed // 外漏
  796. evaluation.DialysisCount = lastPredialysisEvaluation.DialysisCount //呼吸频次
  797. evaluation.Phinholing = lastPredialysisEvaluation.Phinholing //针眼
  798. evaluation.Remark = lastPredialysisEvaluation.Remark
  799. if adminUserInfo.Org.Id == 10318 || adminUserInfo.Org.Id == 10490 {
  800. evaluation.Remark = ""
  801. }
  802. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10447 {
  803. evaluation.BreathingRate = "20"
  804. }
  805. if adminUserInfo.Org.Id == 10445 {
  806. evaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
  807. }
  808. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
  809. evaluation.PulseFrequency = 80
  810. }
  811. if adminUserInfo.Org.Id == 10440 {
  812. evaluation.Temperature = 36.5
  813. }
  814. if adminUserInfo.Org.Id == 10469 {
  815. evaluation.Temperature = 36.5
  816. }
  817. if adminUserInfo.Org.Id == 10471 {
  818. evaluation.Temperature = 36.5
  819. }
  820. }
  821. } else {
  822. evaluation.UpdatedTime = time.Now().Unix()
  823. }
  824. evaluation.WeightBefore = weighing_before
  825. evaluation.AssessmentTime = time.Now().Unix()
  826. err := service.UpadatePredialysisEvaluation(&evaluation)
  827. //记录日志
  828. byterequest, _ := json.Marshal(evaluation)
  829. beforLog := models.XtAssessmentBeforeDislysisLog{
  830. UserOrgId: adminUserInfo.Org.Id,
  831. Ctime: time.Now().Unix(),
  832. Mtime: 0,
  833. ErrLog: string(byterequest),
  834. AdminUserId: adminUserInfo.AdminUser.Id,
  835. RecordDate: evaluation.AssessmentDate,
  836. PatientId: id,
  837. Source: "物联网上传",
  838. Status: 1,
  839. }
  840. service.CreateBeforLog(beforLog)
  841. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  842. redis := service.RedisClient()
  843. //清空key 值
  844. redis.Set(key, "", time.Second)
  845. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  846. redis.Set(keyOne, "", time.Second)
  847. assessdateDateStart := thisTime.Format("2006-01-02")
  848. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  849. redis.Set(keyTwo, "", time.Second)
  850. redis.Close()
  851. if err != nil {
  852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  853. return
  854. }
  855. c.ServeSuccessJSON(map[string]interface{}{
  856. "msg": "ok",
  857. "evaluation": evaluation,
  858. })
  859. return
  860. } else {
  861. // 保存透后相关数据
  862. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  863. if getAADErr != nil {
  864. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  866. return
  867. }
  868. var afterevaluation models.AssessmentAfterDislysis
  869. if assessmentAfterDislysis != nil {
  870. afterevaluation = *assessmentAfterDislysis
  871. }
  872. if assessmentAfterDislysis == nil {
  873. afterevaluation.CreatedTime = time.Now().Unix()
  874. afterevaluation.Status = 1
  875. afterevaluation.AssessmentDate = theAssessmentDateTime
  876. afterevaluation.PatientId = id
  877. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  878. } else {
  879. afterevaluation.UpdatedTime = time.Now().Unix()
  880. }
  881. afterevaluation.WeightAfter = weight_after
  882. afterevaluation.WeightLoss = weight_loss
  883. if adminUserInfo.Org.Id == 10138 {
  884. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  885. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  886. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  887. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk
  888. }
  889. if adminUserInfo.Org.Id == 10307 || adminUserInfo.Org.Id == 10445 {
  890. afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  891. }
  892. //北方营口
  893. if adminUserInfo.Org.Id == 10445 {
  894. prescribe, _ := service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  895. afterevaluation.ActualDisplacement = prescribe.DisplaceLiquiValue
  896. }
  897. //蓬安济民
  898. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  899. afterevaluation.PulseFrequency = 80
  900. }
  901. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  902. //记录日志
  903. byterequest, _ := json.Marshal(afterevaluation)
  904. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  905. UserOrgId: afterevaluation.UserOrgId,
  906. PatientId: afterevaluation.PatientId,
  907. RecordDate: afterevaluation.AssessmentDate,
  908. Status: 1,
  909. ErrLog: string(byterequest),
  910. AdminUserId: adminUserInfo.AdminUser.Id,
  911. Ctime: time.Now().Unix(),
  912. Mtime: 0,
  913. Source: "物联网称重",
  914. }
  915. service.CreateAfterDialysisLog(afterDialysisLog)
  916. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
  917. redis := service.RedisClient()
  918. //清空key 值
  919. redis.Set(key, "", time.Second)
  920. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
  921. redis.Set(keyThree, "", time.Second)
  922. assessdateDateStart := thisTime.Format("2006-01-02")
  923. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  924. redis.Set(keyTwo, "", time.Second)
  925. redis.Close()
  926. if err == nil {
  927. c.ServeSuccessJSON(map[string]interface{}{
  928. "assessmentAfterDislysis": afterevaluation,
  929. })
  930. }
  931. }
  932. }
  933. func (c *CheckWeightApiController) SetSyncTime() {
  934. sn := c.GetString("sn")
  935. if len(sn) > 0 {
  936. redis := service.RedisClient()
  937. defer redis.Close()
  938. redis.Set(sn, 0, 0)
  939. }
  940. serviceTime := time.Now().Unix()
  941. c.ServeSuccessJSON(map[string]interface{}{
  942. "status": 1,
  943. "servicetime": serviceTime,
  944. })
  945. }
  946. func (c *CheckWeightApiController) GetPatientList() {
  947. ftype, _ := c.GetInt64("type", 0)
  948. sn := c.GetString("sn")
  949. syncTime := int64(0)
  950. redis := service.RedisClient()
  951. defer redis.Close()
  952. if len(sn) > 0 {
  953. syncTimeStr, _ := redis.Get(sn).Result()
  954. syncTime, _ = strconv.ParseInt(syncTimeStr, 10, 64)
  955. }
  956. if ftype == 1 {
  957. timeNow := time.Now().Unix()
  958. redis.Set(sn, timeNow, 0)
  959. }
  960. adminUserInfo := c.GetMobileAdminUserInfo()
  961. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
  962. need_update := 0
  963. if syncTime == 0 {
  964. need_update = 1
  965. }
  966. if error != nil {
  967. c.ErrorLog("获取病人列表失败:%v", error)
  968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  969. return
  970. }
  971. serviceTime := time.Now().Unix()
  972. c.ServeSuccessJSON(map[string]interface{}{
  973. "need_update": need_update,
  974. "patientlist": patientList,
  975. "total": total,
  976. "servicetime": serviceTime,
  977. })
  978. }
  979. func (c *CheckWeightApiController) GetPatientListForSchedules() {
  980. thisTime := time.Now()
  981. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  982. timeLayout := "2006-01-02 15:04:05"
  983. loc, _ := time.LoadLocation("Local")
  984. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  985. syncTime := theStartTime.Unix()
  986. adminUserInfo := c.GetMobileAdminUserInfo()
  987. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  988. patientSchedule := make([]map[string]interface{}, 0)
  989. for _, item := range patientList {
  990. patientTemp := make(map[string]interface{})
  991. patientTemp["patient_id"] = item.PatientId
  992. patientTemp["patient_name"] = item.Patient.Name
  993. patientTemp["schedule_type"] = item.ScheduleType
  994. patientSchedule = append(patientSchedule, patientTemp)
  995. }
  996. if error != nil {
  997. c.ErrorLog("获取病人列表失败:%v", error)
  998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  999. return
  1000. }
  1001. serviceTime := time.Now().Unix()
  1002. c.ServeSuccessJSON(map[string]interface{}{
  1003. "patientlist": patientSchedule,
  1004. "total": total,
  1005. "servicetime": serviceTime,
  1006. })
  1007. }
  1008. func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
  1009. patient_name := c.GetString("patient_name") //脉率
  1010. thisTime := time.Now()
  1011. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1012. timeLayout := "2006-01-02 15:04:05"
  1013. loc, _ := time.LoadLocation("Local")
  1014. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1015. syncTime := theStartTime.Unix()
  1016. adminUserInfo := c.GetMobileAdminUserInfo()
  1017. if len(patient_name) == 0 {
  1018. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  1019. patientSchedule := make([]map[string]interface{}, 0)
  1020. for _, item := range patientList {
  1021. patientTemp := make(map[string]interface{})
  1022. patientTemp["patient_id"] = item.PatientId
  1023. patientTemp["patient_name"] = item.Patient.Name
  1024. patientTemp["schedule_type"] = item.ScheduleType
  1025. patientSchedule = append(patientSchedule, patientTemp)
  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. } else {
  1039. patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime, patient_name)
  1040. patientSchedule := make([]map[string]interface{}, 0)
  1041. for _, item := range patientList {
  1042. if item.Patient.ID > 0 {
  1043. patientTemp := make(map[string]interface{})
  1044. patientTemp["patient_id"] = item.PatientId
  1045. patientTemp["patient_name"] = item.Patient.Name
  1046. patientTemp["schedule_type"] = item.ScheduleType
  1047. patientSchedule = append(patientSchedule, patientTemp)
  1048. }
  1049. }
  1050. if error != nil {
  1051. c.ErrorLog("获取病人列表失败:%v", error)
  1052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1053. return
  1054. }
  1055. serviceTime := time.Now().Unix()
  1056. c.ServeSuccessJSON(map[string]interface{}{
  1057. "patientlist": patientSchedule,
  1058. "total": total,
  1059. "servicetime": serviceTime,
  1060. })
  1061. }
  1062. }
  1063. func (c *CheckWeightApiController) GetPatientListById() {
  1064. patientId, _ := c.GetInt64("patient_id", 0)
  1065. if patientId <= 0 {
  1066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1067. return
  1068. }
  1069. adminUserInfo := c.GetMobileAdminUserInfo()
  1070. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  1071. if error != nil {
  1072. c.ErrorLog("获取病人详情失败:%v", error)
  1073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1074. return
  1075. }
  1076. c.ServeSuccessJSON(map[string]interface{}{
  1077. "patientinfo": patient,
  1078. })
  1079. }
  1080. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  1081. id, _ := c.GetInt64("patient", 0)
  1082. if id <= 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1084. return
  1085. }
  1086. adminUserInfo := c.GetMobileAdminUserInfo()
  1087. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1088. if patient.ID <= 0 {
  1089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1090. return
  1091. }
  1092. var dialysisinfo map[string]interface{}
  1093. dialysisinfo = make(map[string]interface{})
  1094. dialysisinfo["id"] = patient.ID
  1095. dialysisinfo["name"] = patient.Name
  1096. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1097. thisTime := time.Now()
  1098. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1099. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1100. timeLayout := "2006-01-02 15:04:05"
  1101. loc, _ := time.LoadLocation("Local")
  1102. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1103. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1104. startTime := theStartTime.Unix()
  1105. endTime := theEndTime.Unix()
  1106. // 判断当前用户是透析前还是透析后
  1107. var dialysistype int
  1108. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  1109. if dialysisOrder == nil {
  1110. dialysistype = 1
  1111. } else {
  1112. dialysistype = 2
  1113. }
  1114. // 获取当前或者下次排班信息
  1115. var sc map[string]interface{}
  1116. sc = make(map[string]interface{})
  1117. if dialysistype == 1 {
  1118. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  1119. if len(daySchedule) <= 0 {
  1120. sc["code"] = 1
  1121. sc["msg"] = "抱歉,您今天没有排版!"
  1122. sc["mode"] = 0
  1123. sc["data"] = daySchedule
  1124. } else {
  1125. if daySchedule[0].Schedule.ID > 0 {
  1126. sc["code"] = 0
  1127. sc["msg"] = ""
  1128. var mode = "HD"
  1129. if daySchedule[0].Schedule.ModeId == 1 {
  1130. mode = "HD"
  1131. }
  1132. if daySchedule[0].Schedule.ModeId == 2 {
  1133. mode = "HDF"
  1134. }
  1135. if daySchedule[0].Schedule.ModeId == 3 {
  1136. mode = "HD+HP"
  1137. }
  1138. if daySchedule[0].Schedule.ModeId == 4 {
  1139. mode = "HP"
  1140. }
  1141. if daySchedule[0].Schedule.ModeId == 5 {
  1142. mode = "HF"
  1143. }
  1144. if daySchedule[0].Schedule.ModeId == 6 {
  1145. mode = "SCUF"
  1146. }
  1147. if daySchedule[0].Schedule.ModeId == 7 {
  1148. mode = "IUF"
  1149. }
  1150. if daySchedule[0].Schedule.ModeId == 8 {
  1151. mode = "HFHD"
  1152. }
  1153. if daySchedule[0].Schedule.ModeId == 9 {
  1154. mode = "HFHD+HP"
  1155. }
  1156. if daySchedule[0].Schedule.ModeId == 10 {
  1157. mode = "PHF"
  1158. }
  1159. if daySchedule[0].Schedule.ModeId == 11 {
  1160. mode = "HFR"
  1161. }
  1162. if daySchedule[0].Schedule.ModeId == 12 {
  1163. mode = "HDF+HP"
  1164. }
  1165. if daySchedule[0].Schedule.ModeId == 13 {
  1166. mode = "CRRT"
  1167. }
  1168. if daySchedule[0].Schedule.ModeId == 14 {
  1169. mode = "腹水回输"
  1170. }
  1171. if daySchedule[0].Schedule.ModeId == 19 {
  1172. mode = "IUF+HD"
  1173. }
  1174. if daySchedule[0].Schedule.ModeId == 20 {
  1175. mode = "UF"
  1176. }
  1177. if daySchedule[0].Schedule.ModeId == 21 {
  1178. mode = "HD+"
  1179. }
  1180. if daySchedule[0].Schedule.ModeId == 22 {
  1181. mode = "血浆胆红素吸附+HDF"
  1182. }
  1183. if daySchedule[0].Schedule.ModeId == 23 {
  1184. mode = "血浆胆红素吸附"
  1185. }
  1186. if daySchedule[0].Schedule.ModeId == 24 {
  1187. mode = "I-HDF"
  1188. }
  1189. if daySchedule[0].Schedule.ModeId == 25 {
  1190. mode = "HD高通"
  1191. }
  1192. if daySchedule[0].Schedule.ModeId == 26 {
  1193. mode = "CVVH"
  1194. }
  1195. if daySchedule[0].Schedule.ModeId == 27 {
  1196. mode = "CVVHD"
  1197. }
  1198. if daySchedule[0].Schedule.ModeId == 28 {
  1199. mode = "CVVHDF"
  1200. }
  1201. if daySchedule[0].Schedule.ModeId == 29 {
  1202. mode = "PE"
  1203. }
  1204. if daySchedule[0].Schedule.ModeId == 30 {
  1205. mode = "血浆胆红素吸附+HP"
  1206. }
  1207. if daySchedule[0].Schedule.ModeId == 31 {
  1208. mode = "HPD"
  1209. }
  1210. if daySchedule[0].Schedule.ModeId == 32 {
  1211. mode = "HDP"
  1212. }
  1213. if daySchedule[0].Schedule.ModeId == 33 {
  1214. mode = "HFD"
  1215. }
  1216. if daySchedule[0].Schedule.ModeId == 34 {
  1217. mode = "HDF100"
  1218. }
  1219. if daySchedule[0].Schedule.ModeId == 35 {
  1220. mode = "HDF600"
  1221. }
  1222. if daySchedule[0].Schedule.ModeId == 36 {
  1223. mode = "HDF800"
  1224. }
  1225. if daySchedule[0].Schedule.ModeId == 37 {
  1226. mode = "HDF1000"
  1227. }
  1228. sc["mode"] = mode
  1229. sc["data"] = daySchedule
  1230. } else {
  1231. sc["code"] = 1
  1232. sc["msg"] = "抱歉,您今天没有排版!"
  1233. sc["mode"] = 0
  1234. sc["data"] = daySchedule
  1235. }
  1236. }
  1237. // 排队叫号的签到
  1238. go func() {
  1239. ssoDomain := beego.AppConfig.String("call_domain")
  1240. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  1241. values := make(url.Values)
  1242. http.PostForm(api, values)
  1243. }()
  1244. } else {
  1245. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  1246. if len(nextSchedule) <= 0 {
  1247. sc["code"] = 1
  1248. sc["msg"] = "抱歉,您后续没有排版!"
  1249. sc["mode"] = 0
  1250. sc["data"] = nextSchedule
  1251. } else {
  1252. if nextSchedule[0].Schedule.ID > 0 {
  1253. sc["code"] = 0
  1254. sc["msg"] = ""
  1255. var mode = "HD"
  1256. if nextSchedule[0].Schedule.ModeId == 1 {
  1257. mode = "HD"
  1258. }
  1259. if nextSchedule[0].Schedule.ModeId == 2 {
  1260. mode = "HDF"
  1261. }
  1262. if nextSchedule[0].Schedule.ModeId == 3 {
  1263. mode = "HD+HP"
  1264. }
  1265. if nextSchedule[0].Schedule.ModeId == 4 {
  1266. mode = "HP"
  1267. }
  1268. if nextSchedule[0].Schedule.ModeId == 5 {
  1269. mode = "HF"
  1270. }
  1271. if nextSchedule[0].Schedule.ModeId == 6 {
  1272. mode = "SCUF"
  1273. }
  1274. if nextSchedule[0].Schedule.ModeId == 7 {
  1275. mode = "IUF"
  1276. }
  1277. if nextSchedule[0].Schedule.ModeId == 8 {
  1278. mode = "HFHD"
  1279. }
  1280. if nextSchedule[0].Schedule.ModeId == 9 {
  1281. mode = "HFHD+HP"
  1282. }
  1283. if nextSchedule[0].Schedule.ModeId == 10 {
  1284. mode = "PHF"
  1285. }
  1286. if nextSchedule[0].Schedule.ModeId == 11 {
  1287. mode = "HFR"
  1288. }
  1289. if nextSchedule[0].Schedule.ModeId == 12 {
  1290. mode = "HDF+HP"
  1291. }
  1292. if nextSchedule[0].Schedule.ModeId == 13 {
  1293. mode = "CRRT"
  1294. }
  1295. if nextSchedule[0].Schedule.ModeId == 14 {
  1296. mode = "腹水回输"
  1297. }
  1298. if nextSchedule[0].Schedule.ModeId == 19 {
  1299. mode = "IUF+HD"
  1300. }
  1301. if nextSchedule[0].Schedule.ModeId == 20 {
  1302. mode = "UF"
  1303. }
  1304. if nextSchedule[0].Schedule.ModeId == 21 {
  1305. mode = "HD+"
  1306. }
  1307. if nextSchedule[0].Schedule.ModeId == 22 {
  1308. mode = "血浆胆红素吸附+HDF"
  1309. }
  1310. if nextSchedule[0].Schedule.ModeId == 23 {
  1311. mode = "血浆胆红素吸附"
  1312. }
  1313. if nextSchedule[0].Schedule.ModeId == 24 {
  1314. mode = "I-HDF"
  1315. }
  1316. if nextSchedule[0].Schedule.ModeId == 25 {
  1317. mode = "HD高通"
  1318. }
  1319. if nextSchedule[0].Schedule.ModeId == 26 {
  1320. mode = "CVVH"
  1321. }
  1322. if nextSchedule[0].Schedule.ModeId == 27 {
  1323. mode = "CVVHD"
  1324. }
  1325. if nextSchedule[0].Schedule.ModeId == 28 {
  1326. mode = "CVVHDF"
  1327. }
  1328. if nextSchedule[0].Schedule.ModeId == 29 {
  1329. mode = "PE"
  1330. }
  1331. if nextSchedule[0].Schedule.ModeId == 30 {
  1332. mode = "血浆胆红素吸附+HP"
  1333. }
  1334. if nextSchedule[0].Schedule.ModeId == 31 {
  1335. mode = "HPD"
  1336. }
  1337. if nextSchedule[0].Schedule.ModeId == 32 {
  1338. mode = "HDP"
  1339. }
  1340. if nextSchedule[0].Schedule.ModeId == 33 {
  1341. mode = "HFD"
  1342. }
  1343. if nextSchedule[0].Schedule.ModeId == 34 {
  1344. mode = "HDF100"
  1345. }
  1346. if nextSchedule[0].Schedule.ModeId == 35 {
  1347. mode = "HDF600"
  1348. }
  1349. if nextSchedule[0].Schedule.ModeId == 36 {
  1350. mode = "HDF800"
  1351. }
  1352. if nextSchedule[0].Schedule.ModeId == 37 {
  1353. mode = "HDF1000"
  1354. }
  1355. sc["mode"] = mode
  1356. sc["data"] = nextSchedule
  1357. } else {
  1358. sc["code"] = 1
  1359. sc["msg"] = "抱歉,您后续没有排版!"
  1360. sc["mode"] = 0
  1361. sc["data"] = nextSchedule
  1362. }
  1363. }
  1364. }
  1365. //switch sc["mode"] {
  1366. //case 1:
  1367. // sc["mode"] = "HD"
  1368. // break
  1369. //case 2:
  1370. // sc["mode"] = "HDF"
  1371. // break
  1372. //case 3:
  1373. // sc["mode"] = "HD+HP"
  1374. // break
  1375. //case 4:
  1376. // sc["mode"] = "HP"
  1377. // break
  1378. //case 5:
  1379. // sc["mode"] = "HF"
  1380. // break
  1381. //case 6:
  1382. // sc["mode"] = "SCUF"
  1383. // break
  1384. //case 7:
  1385. // sc["mode"] = "IUF"
  1386. // break
  1387. //case 8:
  1388. // sc["mode"] = "HFHD"
  1389. // break
  1390. //case 9:
  1391. // sc["mode"] = "HFHD+HP"
  1392. // break
  1393. //case 10:
  1394. // sc["mode"] = "PHF"
  1395. // break
  1396. //case 11:
  1397. // sc["mode"] = "HFR"
  1398. // break
  1399. //case 12:
  1400. // sc["mode"] = "HDF+HP"
  1401. // break
  1402. //case 13:
  1403. // sc["mode"] = "CRRT"
  1404. // break
  1405. //case 14:
  1406. // sc["mode"] = "腹水回输"
  1407. // break
  1408. //case 15:
  1409. // sc["mode"] = "HD前置换"
  1410. // break
  1411. //case 16:
  1412. // sc["mode"] = "HD后置换"
  1413. // break
  1414. //case 17:
  1415. // sc["mode"] = "HDF前置换"
  1416. // break
  1417. //case 18:
  1418. // sc["mode"] = "HDF后置换"
  1419. // break
  1420. //default:
  1421. // sc["mode"] = "HD"
  1422. // break
  1423. //}
  1424. // 获取患者透前干体重或者获取患者透前体重
  1425. var dry_weight map[string]interface{}
  1426. dry_weight = make(map[string]interface{})
  1427. var after_dry_weight map[string]interface{}
  1428. after_dry_weight = make(map[string]interface{})
  1429. if dialysistype == 1 {
  1430. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1431. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1432. if err == gorm.ErrRecordNotFound {
  1433. if getLPEErr != nil {
  1434. dry_weight["code"] = 1
  1435. dry_weight["dry_weight"] = nil
  1436. } else {
  1437. if lastPredialysisEvaluation == nil {
  1438. dry_weight["code"] = 1
  1439. dry_weight["dry_weight"] = nil
  1440. } else {
  1441. // 传输的干体重实际为干体重加上衣服重
  1442. dry_weight["code"] = 0
  1443. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1444. }
  1445. }
  1446. } else {
  1447. if err != nil {
  1448. dry_weight["code"] = 1
  1449. dry_weight["dry_weight"] = nil
  1450. } else {
  1451. dry_weight["code"] = 0
  1452. if getLPEErr != nil {
  1453. dry_weight["code"] = 0
  1454. dry_weight["dry_weight"] = weight.DryWeight
  1455. } else {
  1456. if lastPredialysisEvaluation == nil {
  1457. dry_weight["code"] = 1
  1458. dry_weight["dry_weight"] = weight.DryWeight
  1459. } else {
  1460. // 传输的干体重实际为干体重加上衣服重
  1461. dry_weight["code"] = 0
  1462. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1463. }
  1464. }
  1465. }
  1466. }
  1467. } else {
  1468. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1469. if getPEErr != nil {
  1470. dry_weight["code"] = 1
  1471. dry_weight["dry_weight"] = nil
  1472. } else {
  1473. if predialysisEvaluation == nil {
  1474. dry_weight["code"] = 1
  1475. dry_weight["dry_weight"] = nil
  1476. } else {
  1477. dry_weight["code"] = 0
  1478. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  1479. }
  1480. }
  1481. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1482. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1483. if err == gorm.ErrRecordNotFound {
  1484. if getLPEErr != nil {
  1485. after_dry_weight["code"] = 1
  1486. after_dry_weight["dry_weight"] = nil
  1487. } else {
  1488. if lastPredialysisEvaluation == nil {
  1489. after_dry_weight["code"] = 1
  1490. after_dry_weight["dry_weight"] = nil
  1491. } else {
  1492. // 传输的干体重实际为干体重加上衣服重
  1493. after_dry_weight["code"] = 0
  1494. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1495. }
  1496. }
  1497. } else {
  1498. if err != nil {
  1499. after_dry_weight["code"] = 1
  1500. after_dry_weight["dry_weight"] = nil
  1501. } else {
  1502. after_dry_weight["code"] = 0
  1503. if getLPEErr != nil {
  1504. after_dry_weight["code"] = 0
  1505. after_dry_weight["dry_weight"] = weight.DryWeight
  1506. } else {
  1507. if lastPredialysisEvaluation == nil {
  1508. after_dry_weight["code"] = 1
  1509. after_dry_weight["dry_weight"] = weight.DryWeight
  1510. } else {
  1511. // 传输的干体重实际为干体重加上衣服重
  1512. after_dry_weight["code"] = 0
  1513. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1514. }
  1515. }
  1516. }
  1517. }
  1518. }
  1519. c.ServeSuccessJSON(map[string]interface{}{
  1520. "dialysistype": dialysistype,
  1521. "patient": dialysisinfo,
  1522. "schedule": sc,
  1523. "dryweight": dry_weight,
  1524. "after_dry_weight": after_dry_weight,
  1525. })
  1526. return
  1527. }
  1528. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  1529. id, _ := c.GetInt64("patient", 0)
  1530. if id <= 0 {
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1532. return
  1533. }
  1534. adminUserInfo := c.GetMobileAdminUserInfo()
  1535. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1536. if patient.ID == 0 {
  1537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1538. return
  1539. }
  1540. var dialysisinfo map[string]interface{}
  1541. dialysisinfo = make(map[string]interface{})
  1542. dialysisinfo["id"] = patient.ID
  1543. dialysisinfo["name"] = patient.Name
  1544. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1545. thisTime := time.Now()
  1546. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1547. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1548. fmt.Println(scheduleDateStart, scheduleDateEnd)
  1549. timeLayout := "2006-01-02 15:04:05"
  1550. loc, _ := time.LoadLocation("Local")
  1551. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1552. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1553. fmt.Println(theStartTime, theEndTime)
  1554. startTime := theStartTime.Unix()
  1555. endTime := theEndTime.Unix()
  1556. var sc map[string]interface{}
  1557. sc = make(map[string]interface{})
  1558. //一天只有排班一次
  1559. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  1560. if daySchedule.ID > 0 {
  1561. switch daySchedule.ModeId {
  1562. case 1:
  1563. sc["mode"] = "HD"
  1564. case 2:
  1565. sc["mode"] = "HDF"
  1566. case 3:
  1567. sc["mode"] = "HD+HP"
  1568. case 4:
  1569. sc["mode"] = "HP"
  1570. case 5:
  1571. sc["mode"] = "HF"
  1572. case 6:
  1573. sc["mode"] = "SCUF"
  1574. case 7:
  1575. sc["mode"] = "IUF"
  1576. case 8:
  1577. sc["mode"] = "HFHD"
  1578. case 9:
  1579. sc["mode"] = "HFHD+HP"
  1580. case 10:
  1581. sc["mode"] = "PHF"
  1582. case 11:
  1583. sc["mode"] = "HFR"
  1584. case 12:
  1585. sc["mode"] = "HDF+HP"
  1586. case 13:
  1587. sc["mode"] = "CRRT"
  1588. case 14:
  1589. sc["mode"] = "腹水回输"
  1590. case 15:
  1591. sc["mode"] = "HD前置换"
  1592. case 16:
  1593. sc["mode"] = "HD后置换"
  1594. case 17:
  1595. sc["mode"] = "HDF前置换"
  1596. case 18:
  1597. sc["mode"] = "HDF后置换"
  1598. default:
  1599. sc["mode"] = "HD"
  1600. }
  1601. sc["code"] = 0
  1602. sc["msg"] = ""
  1603. sc["data"] = daySchedule
  1604. } else {
  1605. sc["code"] = 1
  1606. sc["msg"] = "抱歉,您今天没有排版!"
  1607. sc["mode"] = ""
  1608. sc["data"] = daySchedule
  1609. }
  1610. fmt.Println(sc)
  1611. type dryWeight struct {
  1612. code int
  1613. dry_weight float64
  1614. }
  1615. var dry_weight map[string]interface{}
  1616. dry_weight = make(map[string]interface{})
  1617. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1618. if getLPEErr != nil {
  1619. dry_weight["code"] = 1
  1620. dry_weight["dry_weight"] = nil
  1621. } else {
  1622. if lastPredialysisEvaluation == nil {
  1623. dry_weight["code"] = 1
  1624. dry_weight["dry_weight"] = nil
  1625. } else {
  1626. dry_weight["code"] = 0
  1627. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1628. }
  1629. }
  1630. c.ServeSuccessJSON(map[string]interface{}{
  1631. "patient": dialysisinfo,
  1632. "schedule": sc,
  1633. "dryweight": dry_weight,
  1634. })
  1635. return
  1636. }