1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306 |
- package mobile_api_controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- _ "XT_New/utils"
- _ "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- _ "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- "net/http"
- "net/url"
- "strconv"
- _ "strings"
-
- // "fmt"
- _ "reflect"
- "time"
- )
-
- type CheckWeightApiController struct {
- MobileBaseAPIAuthController
- }
-
- func (c *CheckWeightApiController) SaveBloodPressure() {
- id, _ := c.GetInt64("patient", 0)
- dialysistype, _ := c.GetInt64("dialysistype", 0)
- systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0) //收缩压
- diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0) //舒张压
- pulse_frequency, _ := c.GetFloat("pulse_frequency", 0) //脉率
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if dialysistype <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if systolic_blood_pressure <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if diastolic_blood_pressure <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- thisTime := time.Now()
-
- scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theAssessmentDateTime := theStartTime.Unix()
-
- if dialysistype == 1 {
-
- theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
- if getPEErr != nil {
- c.ErrorLog("获取透前评估失败:%v", getPEErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- var evaluation models.PredialysisEvaluation
- if theEvaluation != nil {
- evaluation = *theEvaluation
- }
-
- // 如果今天没有透前评估,则插入新的数据
- if theEvaluation == nil {
- evaluation.CreatedTime = time.Now().Unix()
- evaluation.Status = 1
- evaluation.AssessmentDate = theAssessmentDateTime
- evaluation.PatientId = id
- evaluation.UserOrgId = adminUserInfo.Org.Id
- // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
- lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
- // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
- assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
-
- if getAADErr != nil {
- c.ErrorLog("获取透后评估失败:%v", getAADErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
- weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
- if err == gorm.ErrRecordNotFound {
- if lastPredialysisEvaluation != nil {
- evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
- } else {
- evaluation.DryWeight = 0
- }
- } else {
- evaluation.DryWeight = weight.DryWeight
- }
-
- if assessmentAfterDislysis != nil {
- evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
- }
-
- if lastPredialysisEvaluation != nil {
- evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
- evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
- evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight // 衣物重
-
- //从化益达 备注默认上一次数据
- if adminUserInfo.Org.Id == 10318 {
- evaluation.Remark = lastPredialysisEvaluation.Remark
- }
- }
- } else {
- evaluation.UpdatedTime = time.Now().Unix()
- }
-
- evaluation.SystolicBloodPressure = systolic_blood_pressure // 收缩压
- evaluation.DiastolicBloodPressure = diastolic_blood_pressure // 舒张压
- evaluation.PulseFrequency = pulse_frequency // 脉率
-
- evaluation.AssessmentTime = time.Now().Unix()
-
- err := service.UpadatePredialysisEvaluation(&evaluation)
-
- assessdateDateStart := thisTime.Format("2006-01-02")
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
- keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyTwo, "", time.Second)
- redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "evaluation": evaluation,
- })
- return
-
- } else {
-
- // 保存透后相关数据
- assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
-
- if getAADErr != nil {
- c.ErrorLog("获取透后评估失败:%v", getAADErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- var afterevaluation models.AssessmentAfterDislysis
- if assessmentAfterDislysis != nil {
- afterevaluation = *assessmentAfterDislysis
- }
- if assessmentAfterDislysis == nil {
- afterevaluation.CreatedTime = time.Now().Unix()
- afterevaluation.Status = 1
- afterevaluation.AssessmentDate = theAssessmentDateTime
- afterevaluation.PatientId = id
- afterevaluation.UserOrgId = adminUserInfo.Org.Id
- } else {
-
- afterevaluation.UpdatedTime = time.Now().Unix()
- }
-
- afterevaluation.SystolicBloodPressure = systolic_blood_pressure // 收缩压
- afterevaluation.DiastolicBloodPressure = diastolic_blood_pressure // 舒张压
- afterevaluation.PulseFrequency = pulse_frequency // 脉率
-
- if adminUserInfo.Org.Id == 10138 {
- afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
- afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
- afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
- afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk //跌倒风险
- }
-
- err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyThree, "", time.Second)
- assessdateDateStart := thisTime.Format("2006-01-02")
- keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyTwo, "", time.Second)
- defer redis.Close()
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "assessmentAfterDislysis": afterevaluation,
- })
- }
- }
-
- }
-
- func (c *CheckWeightApiController) SavePatientInfoDialysis() {
- id, _ := c.GetInt64("patient", 0)
- dialysistype, _ := c.GetInt64("dialysistype", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if dialysistype <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- thisTime := time.Now()
-
- scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
- // scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- // theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- theAssessmentDateTime := theStartTime.Unix()
- // endTime := theEndTime.Unix()
- // dry_weight,_ := c.GetFloat("dry_weight",0) // 干体重
- weighing_before, _ := c.GetFloat("weighing_before", 0) // 透前体重
- dewater_amount, _ := c.GetFloat("dewater_amount", 0) // 目标脱水量(L)
-
- weight_after, _ := c.GetFloat("weight_after", 0) // 透后体重
- weight_loss, _ := c.GetFloat("weight_loss", 0) // 体重减少
-
- schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix())
-
- //dialysisSolution,_ := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id,patient.ID,schedual.ModeId)
-
- //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
-
- //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
-
- //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
-
- // 查询当前用户今天有没有排班,没有排班,则不处理
- // daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, theAssessmentDateTime, endTime, id)
- // if(len(daySchedule) <= 0) {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "ok",
- // })
- // return
- // }
-
- template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
-
- 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 {
- if adminUserInfo.Org.Id != 10447 {
- dewater_amount = dewater_amount * 1000
- }
-
- }
-
- if dewater_amount < 0 {
- dewater_amount = 0
- }
-
- if dialysistype == 1 {
- // 保存透前相关数据
- // 获取透析处方
-
- var lastDialysisPrescribe *models.DialysisPrescription
- var dialysisSolution *models.DialysisSolution
- var dialysisPrescribe *models.DialysisPrescription
- var system_dialysisPrescribe *models.SystemPrescription
-
- var mode_id int64
- //weightfirst, _ := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
- //if weightfirst.DryWeight > weighing_before {
- // return
- //}
- dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
- if schedual != nil {
- // 获取透析模版
- dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
- system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
- lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
-
- //判断透析模式,针对河间咸的
- if adminUserInfo.Org.Id == 10090 {
- if dialysisSolution.ModeId != 2 && dialysisSolution.ModeId != 5 && dialysisSolution.ModeId != 12 {
- dialysisSolution.DisplaceLiquiPart = 0
- dialysisSolution.DisplaceLiquiValue = 0
- }
- if lastDialysisPrescribe.ModeId != 2 && lastDialysisPrescribe.ModeId != 5 && lastDialysisPrescribe.ModeId != 12 {
- dialysisSolution.DisplaceLiquiPart = 0
- dialysisSolution.DisplaceLiquiValue = 0
- }
- }
-
- mode_id = schedual.ModeId
- } else {
- // 获取透析模版
- dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
-
- if dialysisPrescribe == nil && dialysisSolution != nil {
- mode_id = dialysisSolution.ModeId
- }
-
- if dialysisPrescribe == nil && dialysisSolution == nil {
- mode_id = 0
- }
- }
-
- // 插入透析处方
- if dialysisPrescribe == nil && dialysisSolution != nil {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = dialysisSolution.UserOrgId
- newprescribe.PatientId = dialysisSolution.PatientId
- newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
- newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
- newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
- newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
- newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
- newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
- newprescribe.ModeId = dialysisSolution.ModeId
- newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
- newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
- newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
- newprescribe.BloodFilter = dialysisSolution.BloodFilter
- newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
- newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
- newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
- newprescribe.Glucose = dialysisSolution.Glucose
- newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
- newprescribe.Kalium = dialysisSolution.Kalium
- newprescribe.Sodium = dialysisSolution.Sodium
- newprescribe.Calcium = dialysisSolution.Calcium
- newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
- newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
- newprescribe.Conductivity = dialysisSolution.Conductivity
- newprescribe.BodyFluid = dialysisSolution.BodyFluid
- newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
- newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
- newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
- newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
- newprescribe.BloodAccess = dialysisSolution.BloodAccess
- newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
- newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
- newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
- newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
- newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
- newprescribe.Dialyzer = dialysisSolution.Dialyzer
- newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
- newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
- newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
- newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
- newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
- newprescribe.TargetKtv = dialysisSolution.TargetKtv
-
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = theAssessmentDateTime
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Status = 1
- newprescribe.Remark = dialysisSolution.Remark
- if adminUserInfo.Org.Id == 10340 {
- newprescribe.TargetUltrafiltration = 0
- newprescribe.Sodium = 138
- newprescribe.Bicarbonate = 31.1
- newprescribe.DialysateFlow = 500
- }
- // 针对新化博翔
- if adminUserInfo.Org.Id == 10447 {
- newprescribe.DisplaceLiquiPart = 1
- newprescribe.DisplaceLiquiValue = 32
- newprescribe.DialysateFlow = 500
- }
- //插入透析处方
- err := service.AddSigleRecord(&newprescribe)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keyTwo, "", time.Second)
- scheduleDateStartOne := thisTime.Format("2006-01-02")
- keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- }
-
- if dialysisPrescribe == nil && dialysisSolution == nil {
- if lastDialysisPrescribe != nil {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
- newprescribe.PatientId = lastDialysisPrescribe.PatientId
- newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
- newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
- newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
- newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
- newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
- newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
- newprescribe.ModeId = lastDialysisPrescribe.ModeId
- newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
- newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
- newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
- newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
- newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
- newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
- newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
- newprescribe.Glucose = lastDialysisPrescribe.Glucose
- newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
- newprescribe.Kalium = lastDialysisPrescribe.Kalium
- newprescribe.Sodium = lastDialysisPrescribe.Sodium
- newprescribe.Calcium = lastDialysisPrescribe.Calcium
- newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
- newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
- newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
- newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
- newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
- newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
- newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
- newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
- newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
- newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
- newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
- newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
- newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
- newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
- newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
- newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
- newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
- newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
- newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
- newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = theAssessmentDateTime
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Status = 1
- newprescribe.Remark = lastDialysisPrescribe.Remark
- if adminUserInfo.Org.Id == 10340 {
- newprescribe.TargetUltrafiltration = 0
- }
- err := service.AddSigleRecord(&newprescribe)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keyTwo, "", time.Second)
- scheduleDateStartOne := thisTime.Format("2006-01-02")
- keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- } else if system_dialysisPrescribe != nil {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
- newprescribe.PatientId = id
- newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
- newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
- newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
- newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
- newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
- newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
- newprescribe.ModeId = system_dialysisPrescribe.ModeId
- newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
- newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
- newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
- newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
- newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
- newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
- newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
- newprescribe.Glucose = system_dialysisPrescribe.Glucose
- newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
- newprescribe.Kalium = system_dialysisPrescribe.Kalium
- newprescribe.Sodium = system_dialysisPrescribe.Sodium
- newprescribe.Calcium = system_dialysisPrescribe.Calcium
- newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
- newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
- newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
- newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
- newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
- newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
- newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
- newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
- newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
- newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
- newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
- newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
- newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
- newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
- newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
- newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
- newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
- newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
- newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
- newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = theAssessmentDateTime
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Status = 1
-
- if adminUserInfo.Org.Id == 10340 {
- newprescribe.TargetUltrafiltration = 0
- }
- err := service.AddSigleRecord(&newprescribe)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keyTwo, "", time.Second)
- scheduleDateStartOne := thisTime.Format("2006-01-02")
- keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
-
- } else {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = adminUserInfo.Org.Id
- newprescribe.PatientId = id
- newprescribe.ModeId = mode_id
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = theAssessmentDateTime
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Status = 1
-
- err := service.AddSigleRecord(&newprescribe)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keyTwo, "", time.Second)
- scheduleDateStartOne := thisTime.Format("2006-01-02")
- keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- }
- }
-
- if dialysisPrescribe != nil && dialysisPrescribe.TargetUltrafiltration == 0 {
- dialysisPrescribe.UpdatedTime = time.Now().Unix()
- dialysisPrescribe.RecordDate = theAssessmentDateTime
- dialysisPrescribe.DewaterAmount = dewater_amount
- dialysisPrescribe.TargetUltrafiltration = dewater_amount
- dialysisPrescribe.Status = 1
- if adminUserInfo.Org.Id == 10340 {
- dialysisPrescribe.TargetUltrafiltration = 0
- }
- updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keyTwo, "", time.Second)
- scheduleDateStartOne := thisTime.Format("2006-01-02")
- keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- if updateErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- }
-
- theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
- if getPEErr != nil {
- c.ErrorLog("获取透前评估失败:%v", getPEErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- var evaluation models.PredialysisEvaluation
- if theEvaluation != nil {
- evaluation = *theEvaluation
- }
-
- // 如果今天没有透前评估,则插入新的数据
- if theEvaluation == nil {
- evaluation.CreatedTime = time.Now().Unix()
- evaluation.Status = 1
- evaluation.AssessmentDate = theAssessmentDateTime
- evaluation.PatientId = id
- evaluation.UserOrgId = adminUserInfo.Org.Id
- // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
- lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
- // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
- assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
- if getAADErr != nil {
- c.ErrorLog("获取透后评估失败:%v", getAADErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
- weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
- if err == gorm.ErrRecordNotFound {
- if lastPredialysisEvaluation != nil {
- evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
- } else {
- evaluation.DryWeight = 0
- }
- } else {
- evaluation.DryWeight = weight.DryWeight
- }
-
- if assessmentAfterDislysis != nil {
- evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
- }
-
- if lastPredialysisEvaluation != nil {
- evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
- evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
- evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight
- evaluation.Temperature = lastPredialysisEvaluation.Temperature
- evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
- evaluation.Catheter = lastPredialysisEvaluation.Catheter
- evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
- evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
- evaluation.Complication = lastPredialysisEvaluation.Complication
- evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
- evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase
- evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
- evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
- evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
-
- evaluation.InternalFistulaSkin = lastPredialysisEvaluation.InternalFistulaSkin //血透通路皮肤情况
- evaluation.CatheterBend = lastPredialysisEvaluation.CatheterBend //导管打折
- evaluation.IsHemorrhage = lastPredialysisEvaluation.IsHemorrhage //出血
- evaluation.IsInfect = lastPredialysisEvaluation.IsInfect //感染
- evaluation.Exposed = lastPredialysisEvaluation.Exposed // 外漏
- evaluation.DialysisCount = lastPredialysisEvaluation.DialysisCount //呼吸频次
- evaluation.Phinholing = lastPredialysisEvaluation.Phinholing //针眼
- evaluation.Remark = lastPredialysisEvaluation.Remark
- if adminUserInfo.Org.Id == 10318 {
- evaluation.Remark = "患者已确认无发热,无流行病学接触史"
- }
- if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10447 {
- evaluation.BreathingRate = "20"
- }
- if adminUserInfo.Org.Id == 10445 {
- evaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
- }
-
- if adminUserInfo.Org.Id == 9829 {
- evaluation.PulseFrequency = 80
- }
- }
- } else {
- evaluation.UpdatedTime = time.Now().Unix()
- }
-
- evaluation.WeightBefore = weighing_before
- evaluation.AssessmentTime = time.Now().Unix()
-
- err := service.UpadatePredialysisEvaluation(&evaluation)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
- assessdateDateStart := thisTime.Format("2006-01-02")
- keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyTwo, "", time.Second)
- redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "evaluation": evaluation,
- })
- return
-
- } else {
-
- // 保存透后相关数据
- assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
- if getAADErr != nil {
- c.ErrorLog("获取透后评估失败:%v", getAADErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- var afterevaluation models.AssessmentAfterDislysis
- if assessmentAfterDislysis != nil {
- afterevaluation = *assessmentAfterDislysis
- }
- if assessmentAfterDislysis == nil {
- afterevaluation.CreatedTime = time.Now().Unix()
- afterevaluation.Status = 1
- afterevaluation.AssessmentDate = theAssessmentDateTime
- afterevaluation.PatientId = id
- afterevaluation.UserOrgId = adminUserInfo.Org.Id
- } else {
-
- afterevaluation.UpdatedTime = time.Now().Unix()
- }
-
- afterevaluation.WeightAfter = weight_after
- afterevaluation.WeightLoss = weight_loss
-
- if adminUserInfo.Org.Id == 10138 {
- afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
- afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
- afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
- afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk
- }
-
- if adminUserInfo.Org.Id == 10307 || adminUserInfo.Org.Id == 10445 {
- afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
- }
- //北方营口
- if adminUserInfo.Org.Id == 10445 {
- prescribe, _ := service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
- afterevaluation.ActualDisplacement = prescribe.DisplaceLiquiValue
- }
-
- //蓬安济民
-
- if adminUserInfo.Org.Id == 9829 {
- afterevaluation.PulseFrequency = 80
- }
-
- err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyThree, "", time.Second)
- assessdateDateStart := thisTime.Format("2006-01-02")
- keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyTwo, "", time.Second)
- redis.Close()
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "assessmentAfterDislysis": afterevaluation,
- })
- }
- }
- }
-
- func (c *CheckWeightApiController) SetSyncTime() {
- sn := c.GetString("sn")
- if len(sn) > 0 {
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(sn, 0, 0)
- }
- serviceTime := time.Now().Unix()
- c.ServeSuccessJSON(map[string]interface{}{
- "status": 1,
- "servicetime": serviceTime,
- })
- }
-
- func (c *CheckWeightApiController) GetPatientList() {
- ftype, _ := c.GetInt64("type", 0)
- sn := c.GetString("sn")
- syncTime := int64(0)
-
- redis := service.RedisClient()
- defer redis.Close()
- if len(sn) > 0 {
- syncTimeStr, _ := redis.Get(sn).Result()
- syncTime, _ = strconv.ParseInt(syncTimeStr, 10, 64)
- }
-
- if ftype == 1 {
- timeNow := time.Now().Unix()
- redis.Set(sn, timeNow, 0)
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
- need_update := 0
- if syncTime == 0 {
- need_update = 1
- }
- if error != nil {
- c.ErrorLog("获取病人列表失败:%v", error)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- serviceTime := time.Now().Unix()
- c.ServeSuccessJSON(map[string]interface{}{
- "need_update": need_update,
- "patientlist": patientList,
- "total": total,
- "servicetime": serviceTime,
- })
- }
-
- func (c *CheckWeightApiController) GetPatientListForSchedules() {
- thisTime := time.Now()
- scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- syncTime := theStartTime.Unix()
- adminUserInfo := c.GetMobileAdminUserInfo()
- patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
- patientSchedule := make([]map[string]interface{}, 0)
- for _, item := range patientList {
- patientTemp := make(map[string]interface{})
- patientTemp["patient_id"] = item.PatientId
- patientTemp["patient_name"] = item.Patient.Name
- patientTemp["schedule_type"] = item.ScheduleType
- patientSchedule = append(patientSchedule, patientTemp)
- }
-
- if error != nil {
- c.ErrorLog("获取病人列表失败:%v", error)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- serviceTime := time.Now().Unix()
- c.ServeSuccessJSON(map[string]interface{}{
- "patientlist": patientSchedule,
- "total": total,
- "servicetime": serviceTime,
- })
- }
-
- func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
- patient_name := c.GetString("patient_name") //脉率
- thisTime := time.Now()
- scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- syncTime := theStartTime.Unix()
- adminUserInfo := c.GetMobileAdminUserInfo()
- if len(patient_name) == 0 {
- patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
- patientSchedule := make([]map[string]interface{}, 0)
- for _, item := range patientList {
- patientTemp := make(map[string]interface{})
- patientTemp["patient_id"] = item.PatientId
- patientTemp["patient_name"] = item.Patient.Name
- patientTemp["schedule_type"] = item.ScheduleType
- patientSchedule = append(patientSchedule, patientTemp)
- }
-
- if error != nil {
- c.ErrorLog("获取病人列表失败:%v", error)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- serviceTime := time.Now().Unix()
- c.ServeSuccessJSON(map[string]interface{}{
- "patientlist": patientSchedule,
- "total": total,
- "servicetime": serviceTime,
- })
- } else {
- patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime, patient_name)
- patientSchedule := make([]map[string]interface{}, 0)
- for _, item := range patientList {
- if item.Patient.ID > 0 {
- patientTemp := make(map[string]interface{})
- patientTemp["patient_id"] = item.PatientId
- patientTemp["patient_name"] = item.Patient.Name
- patientTemp["schedule_type"] = item.ScheduleType
- patientSchedule = append(patientSchedule, patientTemp)
- }
- }
-
- if error != nil {
- c.ErrorLog("获取病人列表失败:%v", error)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- serviceTime := time.Now().Unix()
- c.ServeSuccessJSON(map[string]interface{}{
- "patientlist": patientSchedule,
- "total": total,
- "servicetime": serviceTime,
- })
- }
- }
-
- func (c *CheckWeightApiController) GetPatientListById() {
- patientId, _ := c.GetInt64("patient_id", 0)
- if patientId <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
- if error != nil {
- c.ErrorLog("获取病人详情失败:%v", error)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "patientinfo": patient,
- })
- }
-
- func (c *CheckWeightApiController) GetPatientInfoDialysis() {
- id, _ := c.GetInt64("patient", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
- if patient.ID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var dialysisinfo map[string]interface{}
- dialysisinfo = make(map[string]interface{})
-
- dialysisinfo["id"] = patient.ID
- dialysisinfo["name"] = patient.Name
- dialysisinfo["dialysis_no"] = patient.DialysisNo
-
- thisTime := time.Now()
-
- scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
- scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- startTime := theStartTime.Unix()
- endTime := theEndTime.Unix()
-
- // 判断当前用户是透析前还是透析后
- var dialysistype int
-
- _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
- if dialysisOrder == nil {
- dialysistype = 1
- } else {
- dialysistype = 2
- }
-
- // 获取当前或者下次排班信息
- var sc map[string]interface{}
- sc = make(map[string]interface{})
- if dialysistype == 1 {
- daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
- if len(daySchedule) <= 0 {
- sc["code"] = 1
- sc["msg"] = "抱歉,您今天没有排版!"
- sc["mode"] = 0
- sc["data"] = daySchedule
- } else {
- if daySchedule[0].Schedule.ID > 0 {
- sc["code"] = 0
- sc["msg"] = ""
- sc["mode"] = daySchedule[0].Schedule.ModeId
- sc["data"] = daySchedule
- } else {
- sc["code"] = 1
- sc["msg"] = "抱歉,您今天没有排版!"
- sc["mode"] = 0
- sc["data"] = daySchedule
- }
- }
-
- // 排队叫号的签到
- go func() {
- ssoDomain := beego.AppConfig.String("call_domain")
- api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
- values := make(url.Values)
- http.PostForm(api, values)
- }()
- } else {
- nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
- if len(nextSchedule) <= 0 {
- sc["code"] = 1
- sc["msg"] = "抱歉,您后续没有排版!"
- sc["mode"] = 0
- sc["data"] = nextSchedule
- } else {
- if nextSchedule[0].Schedule.ID > 0 {
- sc["code"] = 0
- sc["msg"] = ""
- sc["mode"] = nextSchedule[0].Schedule.ModeId
- sc["data"] = nextSchedule
- } else {
- sc["code"] = 1
- sc["msg"] = "抱歉,您后续没有排版!"
- sc["mode"] = 0
- sc["data"] = nextSchedule
- }
- }
- }
-
- switch sc["mode"] {
- case 1:
- sc["mode"] = "HD"
- case 2:
- sc["mode"] = "HDF"
- case 3:
- sc["mode"] = "HD+HP"
- case 4:
- sc["mode"] = "HP"
- case 5:
- sc["mode"] = "HF"
- case 6:
- sc["mode"] = "SCUF"
- case 7:
- sc["mode"] = "IUF"
- case 8:
- sc["mode"] = "HFHD"
- case 9:
- sc["mode"] = "HFHD+HP"
- case 10:
- sc["mode"] = "PHF"
- case 11:
- sc["mode"] = "HFR"
- case 12:
- sc["mode"] = "HDF+HP"
- case 13:
- sc["mode"] = "CRRT"
- case 14:
- sc["mode"] = "腹水回输"
- case 15:
- sc["mode"] = "HD前置换"
- case 16:
- sc["mode"] = "HD后置换"
- case 17:
- sc["mode"] = "HDF前置换"
- case 18:
- sc["mode"] = "HDF后置换"
- default:
- sc["mode"] = "HD"
- }
-
- // 获取患者透前干体重或者获取患者透前体重
- var dry_weight map[string]interface{}
- dry_weight = make(map[string]interface{})
- var after_dry_weight map[string]interface{}
- after_dry_weight = make(map[string]interface{})
- if dialysistype == 1 {
-
- lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
- weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
- if err == gorm.ErrRecordNotFound {
- if getLPEErr != nil {
- dry_weight["code"] = 1
- dry_weight["dry_weight"] = nil
- } else {
- if lastPredialysisEvaluation == nil {
- dry_weight["code"] = 1
- dry_weight["dry_weight"] = nil
- } else {
- // 传输的干体重实际为干体重加上衣服重
- dry_weight["code"] = 0
- dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
- }
- }
- } else {
- if err != nil {
- dry_weight["code"] = 1
- dry_weight["dry_weight"] = nil
- } else {
- dry_weight["code"] = 0
- if getLPEErr != nil {
- dry_weight["code"] = 0
- dry_weight["dry_weight"] = weight.DryWeight
- } else {
- if lastPredialysisEvaluation == nil {
- dry_weight["code"] = 1
- dry_weight["dry_weight"] = weight.DryWeight
- } else {
- // 传输的干体重实际为干体重加上衣服重
- dry_weight["code"] = 0
- dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
- }
- }
- }
- }
-
- } else {
- predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
- if getPEErr != nil {
- dry_weight["code"] = 1
- dry_weight["dry_weight"] = nil
- } else {
- if predialysisEvaluation == nil {
- dry_weight["code"] = 1
- dry_weight["dry_weight"] = nil
- } else {
- dry_weight["code"] = 0
- dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
- }
- }
-
- lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
- weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
- if err == gorm.ErrRecordNotFound {
- if getLPEErr != nil {
- after_dry_weight["code"] = 1
- after_dry_weight["dry_weight"] = nil
- } else {
- if lastPredialysisEvaluation == nil {
- after_dry_weight["code"] = 1
- after_dry_weight["dry_weight"] = nil
- } else {
- // 传输的干体重实际为干体重加上衣服重
- after_dry_weight["code"] = 0
- after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
- }
- }
- } else {
- if err != nil {
- after_dry_weight["code"] = 1
- after_dry_weight["dry_weight"] = nil
- } else {
- after_dry_weight["code"] = 0
- if getLPEErr != nil {
- after_dry_weight["code"] = 0
- after_dry_weight["dry_weight"] = weight.DryWeight
- } else {
- if lastPredialysisEvaluation == nil {
- after_dry_weight["code"] = 1
- after_dry_weight["dry_weight"] = weight.DryWeight
- } else {
- // 传输的干体重实际为干体重加上衣服重
- after_dry_weight["code"] = 0
- after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
- }
- }
- }
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysistype": dialysistype,
- "patient": dialysisinfo,
- "schedule": sc,
- "dryweight": dry_weight,
- "after_dry_weight": after_dry_weight,
- })
- return
- }
- func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
- id, _ := c.GetInt64("patient", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var dialysisinfo map[string]interface{}
- dialysisinfo = make(map[string]interface{})
-
- dialysisinfo["id"] = patient.ID
- dialysisinfo["name"] = patient.Name
- dialysisinfo["dialysis_no"] = patient.DialysisNo
-
- thisTime := time.Now()
-
- scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
- scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
- fmt.Println(scheduleDateStart, scheduleDateEnd)
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- fmt.Println(theStartTime, theEndTime)
- startTime := theStartTime.Unix()
- endTime := theEndTime.Unix()
-
- var sc map[string]interface{}
- sc = make(map[string]interface{})
- //一天只有排班一次
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
- if daySchedule.ID > 0 {
- switch daySchedule.ModeId {
- case 1:
- sc["mode"] = "HD"
- case 2:
- sc["mode"] = "HDF"
- case 3:
- sc["mode"] = "HD+HP"
- case 4:
- sc["mode"] = "HP"
- case 5:
- sc["mode"] = "HF"
- case 6:
- sc["mode"] = "SCUF"
- case 7:
- sc["mode"] = "IUF"
- case 8:
- sc["mode"] = "HFHD"
- case 9:
- sc["mode"] = "HFHD+HP"
- case 10:
- sc["mode"] = "PHF"
- case 11:
- sc["mode"] = "HFR"
- case 12:
- sc["mode"] = "HDF+HP"
- case 13:
- sc["mode"] = "CRRT"
- case 14:
- sc["mode"] = "腹水回输"
- case 15:
- sc["mode"] = "HD前置换"
- case 16:
- sc["mode"] = "HD后置换"
- case 17:
- sc["mode"] = "HDF前置换"
- case 18:
- sc["mode"] = "HDF后置换"
- default:
- sc["mode"] = "HD"
- }
- sc["code"] = 0
- sc["msg"] = ""
- sc["data"] = daySchedule
- } else {
- sc["code"] = 1
- sc["msg"] = "抱歉,您今天没有排版!"
- sc["mode"] = ""
- sc["data"] = daySchedule
- }
-
- fmt.Println(sc)
-
- type dryWeight struct {
- code int
- dry_weight float64
- }
-
- var dry_weight map[string]interface{}
- dry_weight = make(map[string]interface{})
-
- lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
- if getLPEErr != nil {
- dry_weight["code"] = 1
- dry_weight["dry_weight"] = nil
- } else {
- if lastPredialysisEvaluation == nil {
- dry_weight["code"] = 1
- dry_weight["dry_weight"] = nil
- } else {
- dry_weight["code"] = 0
- dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": dialysisinfo,
- "schedule": sc,
- "dryweight": dry_weight,
- })
- return
- }
|