package service import ( "XT_New/models" "fmt" "time" "github.com/jinzhu/gorm" ) func GetAdminUserByUserID(userID int64) (*models.AdminUser, error) { var user models.AdminUser err := readUserDb.Model(&models.AdminUser{}).Where("id = ?", userID).First(&user).Error if err != nil { if err == gorm.ErrRecordNotFound { return nil, nil } else { return nil, err } } return &user, nil } type AdminUserList struct { Id int64 `json:"id"` Name string `json:"name"` UserType int64 `json:"user_type"` Status int64 `json:"status"` } func GetAllDoctorAndNurse(orgId int64, appid int64) (doctors []AdminUserList, nurses []AdminUserList, err error) { var users []AdminUserList err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and org_id=? and app_id =? and uar.user_type IN (2,3) and ua.status=1", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type,uar.status").Scan(&users).Error if err != nil { return } if len(users) == 0 { return } for _, item := range users { if item.UserType == 2 { doctors = append(doctors, item) } else { nurses = append(nurses, item) } } return } func GetAllDoctorAndNurseSix(orgId int64, appid int64) (doctors []AdminUserList, nurses []AdminUserList, err error) { var users []AdminUserList err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("org_id=? and app_id =? and uar.user_type IN (2,3)", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type,uar.status").Scan(&users).Error if err != nil { return } if len(users) == 0 { return } for _, item := range users { if item.UserType == 2 { doctors = append(doctors, item) } else { nurses = append(nurses, item) } } return } func GetAllDoctorAndNurseSeven(orgId int64) (doctors []AdminUserList, nurses []AdminUserList, err error) { var users []AdminUserList err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("org_id=? and uar.user_type IN (2,3)", orgId).Select("ua.id, uar.user_name as name, uar.user_type,uar.status").Scan(&users).Error if err != nil { return } if len(users) == 0 { return } for _, item := range users { if item.UserType == 2 { doctors = append(doctors, item) } else { nurses = append(nurses, item) } } return } func GetAllAdminUsers(orgId, appid int64) (list []*AdminUserList, err error) { err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.org_id=? and uar.app_id =?", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type,uar.status").Scan(&list).Error //err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and ua.status=1").Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error return } func GetAllAdminUsersTwo(orgId int64) (list []*AdminUserList, err error) { err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=? and ua.status=1", orgId).Select("ua.id, uar.user_name as name, uar.user_type,uar.status").Scan(&list).Error //err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and ua.status=1").Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error return } func GetAdminUser(orgId, appid, id int64) (*AdminUserList, error) { var err error var user AdminUserList err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=? and uar.app_id =? and uar.admin_user_id = ? and ua.status=1", orgId, appid, id).Select("ua.id, uar.user_name as name, uar.user_type,uar.status").Order("uar.id ASC").Take(&user).Error if err == gorm.ErrRecordNotFound { return nil, nil } if err != nil { return nil, err } return &user, nil } func GetSgjUserByMobild(mobile string) (user models.SgjUser, err error) { err = readUserDb.Model(&models.SgjUser{}).Where("mobile=?", mobile).First(&user).Error return } func GetSgjCoustomerByMobile(orgId int64, mobile string) (*models.SgjCustomer, error) { var c models.SgjCustomer var err error err = readUserDb.Model(&models.SgjCustomer{}).Where("user_org_id=? and mobile=?", orgId, mobile).First(&c).Error return &c, err } func GetAllGeneralAdminUsers(orgId, appid int64) (users []AdminUserList, err error) { err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and org_id=? and app_id =? and uar.user_type <> 1 and ua.status=1", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type").Scan(&users).Error return } func GetDryWeightByPatientId(patientid int64, orgid int64) (pre []*models.SgjPatientDryweight, err error) { err = XTReadDB().Where("patient_id = ? AND user_org_id = ?", patientid, orgid).Last(&pre).Error return pre, err } func GetAllDoctor(orgid int64, appid int64) (appRole []*models.App_Role, err error) { err = UserReadDB().Where("org_id = ? AND app_id = ? AND status = ? AND (user_type = ? OR user_type = ?) ", orgid, appid, 1, 2, 1).Find(&appRole).Error return appRole, err } func GetAllDoctorThree(orgid int64) (appRole []*models.App_Role, err error) { err = UserReadDB().Where("org_id = ? AND status = ? AND (user_type = ? OR user_type = ?) ", orgid, 1, 2, 1).Find(&appRole).Error return appRole, err } func QueryDryWeight(orgid int64, patientid int64) (*models.SgjPatientDryweight, error) { var dryweight models.SgjPatientDryweight var err error err = XTReadDB().Where("user_org_id = ? AND patient_id = ?", orgid, patientid).Find(&dryweight).Error if err == gorm.ErrRecordNotFound { return nil, err } if err != nil { return nil, err } return &dryweight, nil } func CreatePatientWeight(dryweight *models.SgjPatientDryweight) error { err := XTWriteDB().Create(&dryweight).Error return err } func GetLastData(orgid int64) (models.SgjPatientDryweight, error) { dryweight := models.SgjPatientDryweight{} err := XTReadDB().Where("user_org_id = ? AND status = ?", orgid, 1).Last(&dryweight).Error return dryweight, err } func UpdateDialysisPrescription(patientid int64, orgid int64, dryweight float64, prescription models.PredialysisEvaluation) error { err := XTWriteDB().Model(&prescription).Where("patient_id = ? AND user_org_id = ? and assessment_date = ?", patientid, orgid, prescription.AssessmentDate).Update(map[string]interface{}{"dry_weight": prescription.DryWeight, "mtime": time.Now().Unix()}).Error fmt.Println("错误是设么", err) return err } func GetAllData(orgid int64, id int64, page int64, limit int64) (dry []*models.XtPatientDryweight, total int64, err error) { offset := (page - 1) * limit table := XTReadDB().Table("sgj_users.sgj_user_admin_role AS a") fmt.Println("table", table) err = XTReadDB().Table("xt_patient_dryweight as x").Select("x.id,x.dry_weight,x.creator,x.remakes,x.patient_id,x.ctime,x.status,x.user_org_id,x.adjusted_value,a.user_name").Where("x.user_org_id = ? AND x.patient_id = ? AND x.status = ?", orgid, id, 1).Count(&total).Joins("LEFT JOIN sgj_users.sgj_user_admin_role AS a ON a.admin_user_id = x.creator").Order("x.ctime desc").Offset(offset).Limit(limit).Group("id").Scan(&dry).Error if err != nil { return } return } func GetDryWeightDetailById(id int64) (models.SgjPatientDryweight, error) { dryweight := models.SgjPatientDryweight{} err := XTReadDB().Model(&dryweight).Where("id=? and status = 1", id).Find(&dryweight).Error return dryweight, err } func ModifyDryWeightData(adjust *models.SgjPatientDryweight, id int64) error { err := XTWriteDB().Model(&adjust).Where("id=?", id).Updates(map[string]interface{}{"dry_weight": adjust.DryWeight, "creator": adjust.Creator, "remakes": adjust.Remakes, "adjusted_value": adjust.AdjustedValue}).Error return err } func GetAllHisDoctor(orgid int64) (appRole []*models.App_Role, err error) { err = UserReadDB().Where("org_id = ? AND status = 1 AND (user_type = ? OR user_type = ?) ", orgid, 2, 1).Find(&appRole).Error return appRole, err } func GetDrugFlowDetailById(drug_id int64, org_id int64) (flow []*models.DrugFlow, err error) { if org_id == 10188 { err = XTReadDB().Model(&flow).Where("drug_id = ? and status =1 and user_org_id =? and system_time>=1717171200", drug_id, org_id).Order("ctime asc").Find(&flow).Error } else { err = XTReadDB().Model(&flow).Where("drug_id = ? and status =1 and user_org_id =?", drug_id, org_id).Order("ctime asc").Find(&flow).Error } return flow, err }