123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804 |
- package service
-
- import (
- "XT_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 GetAllDoctorListSix(orgid int64, appid int64) (role []*models.XTSgjUserAdminRole, err error) {
-
- err = UserReadDB().Model(&role).Where("org_id =? and app_id = ? 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 GetAllMobileZonePb(orgid int64) (zone []*models.DeviceZonePb, err error) {
-
- err = XTReadDB().Model(&zone).Preload("DeviceNumber", "status =1").Where("org_id = ? and status = 1", orgid).Find(&zone).Error
- return zone, err
- }
-
- func GetPatientScheduleByPd(schedule_date int64, zoneid int64, orgid int64, class_type int64) (list []*models.DeviceZonePb, err error) {
-
- db := XTReadDB().Table("xt_device_zone as x").Where("x.status = 1")
- if zoneid > 0 {
- db = db.Where("x.id = ?", zoneid)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if class_type > 0 {
- err = db.Select("x.id,x.org_id,x.name,x.type,x.sort").Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Model(&models.DeviceNumber{}).Where("status = 1").Preload("Schedule", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Model(&models.BlodSchedule{}).Where("status = 1 AND user_org_id = ? and schedule_date = ? and schedule_type = ?", orgid, schedule_date, class_type).Preload("VmBloodPatients", "status = 1 and user_org_id = ?", orgid).Preload("BloodDialysisOrder", "status = 1 and dialysis_date = ?", schedule_date).Preload("BloodDialysisPrescription", "status = 1 and record_date = ?", schedule_date).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
- return db.Where("user_org_id = ? and status = 1", orgid).Group("patient_id,mode_id").Order("created_time asc")
- })
- })
- }).Find(&list).Error
- } else {
- err = db.Select("x.id,x.org_id,x.name,x.type,x.sort").Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Model(&models.DeviceNumber{}).Where("status = 1").Preload("Schedule", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Model(&models.BlodSchedule{}).Where("status = 1 AND user_org_id = ? and schedule_date = ?", orgid, schedule_date).Preload("VmBloodPatients", "status = 1 and user_org_id = ?", orgid).Preload("BloodDialysisOrder", "status = 1 and dialysis_date = ?", schedule_date).Preload("BloodDialysisPrescription", "status = 1 and record_date = ?", schedule_date).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
- return db.Where("user_org_id = ? and status = 1", orgid).Group("patient_id,mode_id").Order("created_time asc")
- })
- })
- }).Find(&list).Error
- }
-
- return list, err
- }
-
- func GetPatientSchedule(startime int64, zoneid int64, classtype int64, orgid int64) (schedule []*models.ScheduleTwenty, 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", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Model(&models.DeviceNumber{}).Where("status = 1 AND org_id = ?", orgid).Order("sort asc")
- }).Preload("DialysisOrderTwenty", "status =1").Joins("JOIN xt_patients as p ON p.id = s.patient_id and p.lapseto = 1 and p.user_org_id =?", orgid).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,s.is_export,p.name as patient").Find(&schedule).Error
- return schedule, err
- }
-
- func GetPatientScheduleByBed(schedule_date int64, zoneid int64, orgid int64, class_type int64) (list []*models.PatientDeviceNumber, err error) {
-
- db := XTReadDB().Table("xt_device_number as x").Where("x.status = 1")
- if zoneid > 0 {
- db = db.Where("x.zone_id = ?", zoneid)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if class_type > 0 {
- err = db.Select("x.id,x.number,x.sort,x.group_id,x.zone_id,x.sort").Preload("DeviceZone", "status = 1").Preload("Schedule", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Model(&models.BlodSchedule{}).Where("status = 1 AND user_org_id = ? and schedule_date = ? and schedule_type = ?", orgid, schedule_date, class_type).Preload("VmBloodPatients", "status = 1 and user_org_id = ?", orgid).Preload("BloodDialysisOrder", "status = 1 and dialysis_date = ?", schedule_date).Preload("BloodDialysisPrescription", "status = 1 and record_date = ?", schedule_date)
- }).Find(&list).Error
- } else {
- err = db.Select("x.id,x.number,x.sort,x.group_id,x.zone_id,x.sort").Preload("DeviceZone", "status = 1").Preload("Schedule", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Model(&models.BlodSchedule{}).Where("status = 1 AND user_org_id = ? and schedule_date = ?", orgid, schedule_date).Preload("VmBloodPatients", "status = 1 and user_org_id = ?", orgid).Preload("BloodDialysisOrder", "status = 1 and dialysis_date = ?", schedule_date).Preload("BloodDialysisPrescription", "status = 1 and record_date = ?", schedule_date)
- }).Find(&list).Error
- }
-
- return list, err
- }
-
- func GetPatientDialysisOrderDate(shcedule_date int64, class_type int64, orgid int64) (schedule []*models.Schedule, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if shcedule_date > 0 {
- db = db.Where("x.schedule_date = ?", shcedule_date)
- }
- if class_type > 0 {
- db = db.Where("x.schedule_type = ?", class_type)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Select("x.id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id").Preload("DialysisOrder", "status = 1").Preload("DialysisPrescription", "status = 1").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 DeleteScheduleByPatientId(patient_id int64, schedule_date int64, user_org_id int64) (models.XtSchedules, error) {
-
- schedules := models.XtSchedules{}
- err := XTWriteDB().Model(&schedules).Where("patient_id = ? and schedule_date = ? and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return schedules, 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", func(db *gorm.DB) *gorm.DB {
- return db.Where("status =1").Preload("DeviceZone", "status = 1")
- }).Preload("DialysisOrder", "status =1").Preload("DialysisPrescription", "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
- }
-
- func GetStaffScheduleById(ids []string) (schedule []*models.XtSchedule, err error) {
-
- err = XTReadDB().Where("id in(?)", ids).Find(&schedule).Error
- return schedule, err
-
- }
-
- func UpdateStaffSchedule(nextid int64, schedule models.XtSchedule) error {
-
- err := XTWriteDB().Model(&schedule).Where("id = ?", nextid).Updates(map[string]interface{}{"patient_id": schedule.PatientId, "mode_id": schedule.ModeId, "dialysis_machine_name": schedule.DialysisMachineName}).Error
- return err
- }
-
- func UpdateStaffScheduleOne(nextid int64, schedule models.WeekSchedule) error {
-
- err := XTWriteDB().Model(&schedule).Where("id = ?", nextid).Updates(map[string]interface{}{"patient_id": schedule.PatientId, "mode_id": schedule.ModeId, "dialysis_machine_name": schedule.DialysisMachineName}).Error
- return err
- }
-
- func UpdatedScheduleMode(schedule models.XtSchedule, id int64) error {
-
- xtSchedule := models.XtSchedule{}
- err := XTWriteDB().Model(&xtSchedule).Where("id = ? and status =1 ", id).Updates(map[string]interface{}{"mode_id": schedule.ModeId}).Error
- return err
- }
-
- func UpdatedSchedule(schedule models.XtSchedule, patient_id int64, schedule_date int64, schedule_type int64, bed_id int64) error {
-
- xtSchedule := models.XtSchedule{}
- err := XTWriteDB().Model(&xtSchedule).Where("patient_id = ? and status =1 and schedule_date = ? and bed_id = ?", patient_id, schedule_date, bed_id).Updates(map[string]interface{}{"schedule_type": schedule.ScheduleType, "mode_id": schedule.ModeId}).Error
- return err
- }
-
- func GetDialyisSolution(patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
-
- prescription := models.DialysisPrescription{}
-
- err := XTReadDB().Where("patient_id = ? and record_date = ? and status = 1", patientid, recorddate).Find(&prescription).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, err
- } else {
- return nil, err
- }
- }
- return &prescription, nil
- }
-
- func GetPatientScheduleIsExist(startime int64, schedule_type int64, bed_id int64, user_org_id int64) (*models.ScheduleNewPatients, error) {
-
- schedule := models.ScheduleNewPatients{}
- err := XTReadDB().Model(&schedule).Where("schedule_date = ? and schedule_type = ? and bed_id = ? and status = 1 and user_org_id = ?", startime, schedule_type, bed_id, user_org_id).Find(&schedule).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &schedule, nil
- }
-
- func CreateDialysisPrescription(prescription *models.DialysisPrescription) error {
-
- err := XTReadDB().Create(&prescription).Error
-
- return err
- }
-
- func CreateDialysisSolution(solution models.DialysisSolution) error {
-
- err := XTReadDB().Create(&solution).Error
- return err
- }
-
- func UpdateDialysisPrescriptionOne(prescription models.DialysisPrescription, patientid int64, recordate int64, mode_id int64) error {
-
- err := XTReadDB().Model(&prescription).Where("patient_id = ? and record_date = ? and status = 1", patientid, recordate).Updates(map[string]interface{}{"dialysis_dialyszers": prescription.DialysisDialyszers, "mode_id": mode_id, "dialysis_irrigation": prescription.DialysisIrrigation}).Error
- return err
- }
-
- func GetPatientScheduleListByZone(schedule_date int64, class_tye int64, orgid int64) (schedule []*models.ScheduleTwentyOne, err error) {
-
- db := XTReadDB().Model(&schedule).Where("status = 1")
-
- if schedule_date > 0 {
- db = db.Where("schedule_date = ?", schedule_date)
- }
- if class_tye > 0 {
- db = db.Where("schedule_type = ?", class_tye)
- }
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- err = db.Select("partition_id,Count(id) as id,user_org_id").Group("partition_id").Scan(&schedule).Error
- return schedule, err
- }
|