123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618 |
- package service
-
- import (
- "Xcx_New/models"
- "fmt"
- "github.com/jinzhu/gorm"
- "time"
- )
-
- func GetClassName(orgid int64, class_name string) (*models.DoctorSchedules, error) {
-
- schedules := models.DoctorSchedules{}
- err := XTReadDB().Model(&schedules).Where("user_org_id = ? and status = 1 and class_name = ?", orgid, class_name).Find(&schedules).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &schedules, nil
- }
-
- func CreateDotorSchedule(schedules *models.DoctorSchedules) error {
-
- err := XTWriteDB().Create(&schedules).Error
- return err
- }
-
- func GetDoctorScheduleByOrgId(orgid int64) (*models.DoctorSchedules, error) {
- schedules := models.DoctorSchedules{}
- err := XTReadDB().Model(&schedules).Where("user_org_id = ? and status = 1", orgid).Find(&schedules).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &schedules, nil
- }
-
- func GetDoctorScheduleList(orgid int64, page int64, limit int64) (schedules []*models.DoctorSchedules, total int64, err error) {
- offset := (page - 1) * limit
- err = XTReadDB().Model(&schedules).Where("user_org_id = ? and status =1", orgid).Count(&total).Offset(offset).Limit(limit).Find(&schedules).Error
- return schedules, total, err
- }
-
- func GetScheduleDetail(id int64) (models.DoctorSchedules, error) {
- schedules := models.DoctorSchedules{}
- err := XTReadDB().Model(&schedules).Where("id=? and status = 1", id).Find(&schedules).Error
- return schedules, err
- }
-
- func GetClassNameIsExsit(classname string, orgid int64, id int64) (schedule models.DoctorSchedules, err error) {
-
- err = XTReadDB().Model(&schedule).Where("class_name = ? and user_org_id =? and id <> ?", classname, orgid, id).First(&schedule).Error
- return schedule, err
- }
-
- func UpdateScheduleList(id int64, schedules *models.DoctorSchedules) error {
-
- err := XTReadDB().Model(&schedules).Where("id=?", id).Updates(map[string]interface{}{"class_name": schedules.ClassName, "class_attributes": schedules.ClassAttributes, "timeone_start": schedules.TimeoneStart, "timeone_type": schedules.TimeoneType, "timeone_end": schedules.TimeoneEnd, "timetwo_start": schedules.TimetwoStart, "timetwo_type": schedules.TimetwoType, "timetwo_end": schedules.TimetwoEnd, "work_time": schedules.WorkTime, "remarks": schedules.Remarks, "minute": schedules.Minute, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetStaffScheduleByScheduleType(id int64, orgid int64) (*models.StaffSchedule, error) {
- schedule := models.StaffSchedule{}
- err := XTReadDB().Model(&schedule).Where("schedule_type = ? and user_org_id = ? and status = 1", id, orgid).Find(&schedule).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &schedule, nil
- }
-
- func DeleteScheduleById(id int64) error {
- schedules := models.DoctorSchedules{}
- err := XTWriteDB().Model(&schedules).Where("id=?", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetDoctorList(orgid int64, appid int64) (role []*models.XTSgjUserAdminRole, err error) {
-
- err = UserReadDB().Model(&role).Where("org_id = ? and app_id = ? and (user_type = 2 or user_type = 3) and status = 1 and is_sort = 1", orgid, appid).Order("user_type desc").Find(&role).Error
- return role, err
- }
-
- func GetAllDoctorList(orgid int64, appid int64) (role []*models.XTSgjUserAdminRole, err error) {
-
- err = UserReadDB().Model(&role).Where("org_id =? and app_id = ? and user_type = 2 and status = 1", orgid, appid).Order("sort desc").Find(&role).Error
- return role, err
- }
-
- func GetAllNurseList(orgid int64, appid int64) (role []*models.XTSgjUserAdminRole, err error) {
-
- err = UserReadDB().Model(&role).Where("org_id = ? and app_id = ? and user_type =3 and status =1", orgid, appid).Order("sort desc").Find(&role).Error
- return role, err
- }
-
- func GetScheduleList(orgid int64) (schedule []*models.DoctorSchedules, err error) {
-
- err = XTReadDB().Model(&schedule).Where("user_org_id = ? and status = 1", orgid).Find(&schedule).Error
- return schedule, err
- }
-
- func GetScheduleListDetail(doctor_id int64, orgid int64, scheduledate int64) (*models.StaffSchedule, error) {
- schedule := models.StaffSchedule{}
- err := XTReadDB().Model(&schedule).Where("doctor_id = ? and user_org_id = ? and status =1 and schedule_date = ?", doctor_id, orgid, scheduledate).Find(&schedule).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &schedule, nil
- }
-
- func AddSchedule(schedule *models.StaffSchedule) error {
-
- err := XTWriteDB().Create(&schedule).Error
- return err
- }
-
- func UpdateStaffList(schedule *models.StaffSchedule, id int64) error {
- err := XTReadDB().Model(&schedule).Where("id=?", id).Updates(map[string]interface{}{"doctor_id": schedule.DoctorId, "doctor_type": schedule.DoctorType, "schedule_type": schedule.ScheduleType, "schedule_week": schedule.ScheduleWeek, "schedule_date": schedule.ScheduleDate, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetStaffScheduleList(orgid int64, startime int64, endtime int64) (schedule []*models.XtStaffSchedule, err error) {
-
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.id").Select("x.id,x.doctor_id,x.doctor_type,x.schedule_type,x.schedule_week,x.user_org_id,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.admin_user_id,r.user_type,s.class_attributes,r.sort,r.is_sort,s.work_time,s.minute").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and r.is_sort = 1", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GetStaffScheduleListTwo(orgid int64, startime int64, endtime int64) (schedule []*models.StaffSchedule, err error) {
-
- err = XTReadDB().Model(&schedule).Where("user_org_id = ? and start_time>=? and end_time<=? and status = 1", orgid, startime, endtime).Find(&schedule).Error
- return schedule, err
- }
-
- func GetNextWeekSchedule(orgid int64, startime int64, endtime int64) (*models.StaffSchedule, error) {
- schedule := models.StaffSchedule{}
- err := XTReadDB().Model(&schedule).Where("user_org_id = ? and status = 1 and start_time >=? and end_time<=?", orgid, startime, endtime).Find(&schedule).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &schedule, nil
- }
-
- func GetScheduleByDoctorId(doctorid int64, startime int64, endtime int64, orgid int64) (schedule []*models.XtStaffSchedule, err error) {
- fmt.Println(doctorid, startime, endtime)
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if doctorid == 0 {
- db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
- }
- if doctorid > 0 {
- db = db.Where("x.doctor_type = ?", doctorid)
- }
- err = db.Group("x.id").Select("x.id,x.doctor_id,x.doctor_type,x.schedule_type,x.schedule_week,x.user_org_id,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.admin_user_id,s.class_attributes,r.sort,r.is_sort").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ?", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func ToSearchSeacheduleList(keywords string, startime int64, endtime int64, orgid int64) (schedule []*models.XtStaffSchedule, err error) {
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- likeKey := "%" + keywords + "%"
- //if(doctorid >0){
- // db = db.Where("x.doctor_id = ?", doctorid)
- //}
- err = db.Group("x.id").Select("x.id,x.doctor_id,x.doctor_type,x.schedule_type,x.schedule_week,x.user_org_id,x.start_time,x.schedule_date,x.end_time,r.user_type,r.user_name,s.class_name,r.admin_user_id,s.class_attributes,r.sort,r.is_sort").Joins("left join sgj_users.sgj_user_admin_role AS r ON r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type and s.user_org_id = ?", orgid).Where("r.org_id = ? and r.status = 1 and r.is_sort = 1 and r.user_name like ?", orgid, likeKey).Scan(&schedule).Error
- return schedule, err
- }
-
- func DeleteStaffSchedule(orgid int64, startime int64, endtime int64) error {
-
- schedule := models.StaffSchedule{}
- err := XTWriteDB().Model(&schedule).Where("user_org_id = ? and start_time >= ? and end_time <=?", orgid, startime, endtime).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetContinueScheduleByOrgId(orgid int64) (*models.ContinueSchedule, error) {
-
- //schedules := models.DoctorSchedules{}
- //err := XTReadDB().Model(&schedules).Where("user_org_id = ? and status = 1", orgid).Find(&schedules).Error
- //if err == gorm.ErrRecordNotFound {
- // return nil, err
- //}
- //if err != nil {
- // return nil, err
- //}
- //return &schedules, nil
- schedule := models.ContinueSchedule{}
- err := XTReadDB().Model(&schedule).Where("user_org_id = ? and status = 1", orgid).Find(&schedule).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &schedule, nil
- }
-
- func UpdateContinusSchedule(schedule *models.ContinueSchedule, orgid int64) error {
-
- err := XTWriteDB().Model(&schedule).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"is_status": schedule.IsStatus, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func SaveNurseSort(role *models.App_Role, id int64) error {
-
- err := UserWriteDB().Model(&role).Where("id = ?", id).Updates(map[string]interface{}{"sort": role.Sort}).Error
- return err
- }
-
- func SaveIsSchedule(id int64, role *models.App_Role) error {
-
- err := UserWriteDB().Model(&role).Where("id=?", id).Updates(map[string]interface{}{"is_sort": role.IsSort}).Error
- return err
- }
-
- func GetScheduleListTotal(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
-
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.doctor_id,x.schedule_type").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,count(s.class_name) as count").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GetTotalMinutes(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
-
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,sum(s.minute) as totalminute").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and s.class_attributes = 1", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GetTotalMinutesOne(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,sum(s.minute) as totalminute").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 ", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GetTotalMinutesTwo(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,sum(s.minute) as workminute").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and s.class_attributes = 1", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GetChartTotalMinutesOne(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
- likeKey := "%" + keywords + "%"
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,sum(s.minute) as totalminute").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Where("r.user_name like ?", likeKey).Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 ", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GetChartTotalMinutesTwo(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
- likeKey := "%" + keywords + "%"
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,sum(s.minute) as workminute").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Where("r.user_name like ?", likeKey).Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and s.class_attributes = 1", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GetTotalWorkDay(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
-
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,count(x.id) as count").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and s.class_attributes = 1", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GetTotalNoWorkDay(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
-
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,count(x.id) as count").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and s.class_attributes = 2", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GetSearchScheduleListTotal(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
- likeKey := "%" + keywords + "%"
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.doctor_id,x.schedule_type").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,count(s.class_name) as count").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Where("r.user_name like ?", likeKey).Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 ", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GeSearchtTotalMinutes(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
- likeKey := "%" + keywords + "%"
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,sum(s.minute) as totalminute").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Where("r.user_name like ?", likeKey).Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and s.class_attributes = 1", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GetSearchWorkDay(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
- likeKey := "%" + keywords + "%"
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,count(x.id) as count").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Where("r.user_name like ?", likeKey).Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and s.class_attributes = 1", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GetSearchWorkNoDay(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
- likeKey := "%" + keywords + "%"
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,count(x.id) as count").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Where("r.user_name like ?", likeKey).Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and s.class_attributes = 2", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func ChagneScheduleListTotal(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
-
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if doctortype == 0 {
- db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
- }
- if doctortype > 0 {
- db = db.Where("x.doctor_type = ?", doctortype)
- }
- err = db.Group("x.doctor_id,x.schedule_type").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,count(s.class_name) as count").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 ", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func ChangeScheduleMinute(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
-
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if doctortype == 0 {
- db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
- }
- if doctortype > 0 {
- db = db.Where("x.doctor_type = ?", doctortype)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,sum(s.minute) as totalminute").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and s.class_attributes = 1", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func ChangeWorkDay(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
-
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if doctortype == 0 {
- db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
- }
- if doctortype > 0 {
- db = db.Where("x.doctor_type = ?", doctortype)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,count(x.id) as count").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and s.class_attributes = 1", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func ChangeNoWorkDay(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
-
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if doctortype == 0 {
- db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
- }
- if doctortype > 0 {
- db = db.Where("x.doctor_type = ?", doctortype)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,count(x.id) as count").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and s.class_attributes = 2", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func ChartTotalMinute(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if doctortype == 0 {
- db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
- }
- if doctortype > 0 {
- db = db.Where("x.doctor_type = ?", doctortype)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,sum(s.minute) as totalminute").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 ", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func ChartWorkDayMinute(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
-
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.start_time >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if doctortype == 0 {
- db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
- }
- if doctortype > 0 {
- db = db.Where("x.doctor_type = ?", doctortype)
- }
- err = db.Group("x.doctor_id").Select("x.doctor_id,x.schedule_type,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.sort,r.is_sort,sum(s.minute) as workminute").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and s.class_attributes = 1", orgid, orgid).Scan(&schedule).Error
- return schedule, err
- }
-
- func GetMySchedule(startime int64, endtime int64, orgid int64, creator int64) (schedule []*models.XtStaffSchedule, err error) {
- db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
- err = db.Group("x.id").Select("x.doctor_id,x.schedule_week,s.class_name").Where("x.start_time >=? and x.end_time<=? and x.user_org_id = ? and x.doctor_id = ?", startime, endtime, orgid, creator).Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Scan(&schedule).Error
- return schedule, err
- }
-
- func GetAllMobileZone(orgid int64) (zone []*models.DeviceZone, err error) {
-
- err = XTReadDB().Model(&zone).Where("org_id = ? and status = 1", orgid).Find(&zone).Error
- return zone, err
- }
-
- func GetPatientSchedule(startime int64, zoneid int64, classtype int64, orgid int64) (schedule []*models.Schedule, err error) {
-
- db := XTReadDB().Table("xt_schedule as s")
- if zoneid > 0 {
- db = db.Where("s.partition_id = ?", zoneid)
- }
- if classtype > 0 {
- db = db.Where("s.schedule_type = ?", classtype)
- }
- err = db.Preload("DeviceZone", " status= 1").Preload("DeviceNumber", "status= 1").
- Preload("DialysisOrder", "status =1").Joins("JOIN xt_patients as p ON p.id = s.patient_id").Where("s.user_org_id = ? and s.schedule_date = ? and s.status =1", orgid, startime).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id,p.name as patient").Find(&schedule).Error
- return schedule, err
- }
-
- func DeleteSchedule(id int64) error {
-
- schedule := models.XtSchedule{}
-
- err := XTWriteDB().Model(&schedule).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetSearchPatient(keywords string, orgid int64, startime int64) (schedule []*models.Schedule, err error) {
-
- likeKey := "%" + keywords + "%"
- db := XTReadDB().Table("xt_schedule as s")
- err = db.Preload("DeviceZone", " status= 1").Preload("DeviceNumber", "status= 1").
- Preload("DialysisOrder", "status =1").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id And(p.name LIKE ? OR p.dialysis_no LIKE ?)", likeKey, likeKey).Where("s.user_org_id = ? and s.schedule_date = ? and s.status =1", orgid, startime).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id,p.name as patient").Find(&schedule).Error
- return schedule, err
- }
|