doctor_schedule_service.go 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. package service
  2. import (
  3. "Xcx_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "time"
  7. )
  8. func GetClassName(orgid int64, class_name string) (*models.DoctorSchedules, error) {
  9. schedules := models.DoctorSchedules{}
  10. err := XTReadDB().Model(&schedules).Where("user_org_id = ? and status = 1 and class_name = ?", orgid, class_name).Find(&schedules).Error
  11. if err == gorm.ErrRecordNotFound {
  12. return nil, err
  13. }
  14. if err != nil {
  15. return nil, err
  16. }
  17. return &schedules, nil
  18. }
  19. func CreateDotorSchedule(schedules *models.DoctorSchedules) error {
  20. err := XTWriteDB().Create(&schedules).Error
  21. return err
  22. }
  23. func GetDoctorScheduleByOrgId(orgid int64) (*models.DoctorSchedules, error) {
  24. schedules := models.DoctorSchedules{}
  25. err := XTReadDB().Model(&schedules).Where("user_org_id = ? and status = 1", orgid).Find(&schedules).Error
  26. if err == gorm.ErrRecordNotFound {
  27. return nil, err
  28. }
  29. if err != nil {
  30. return nil, err
  31. }
  32. return &schedules, nil
  33. }
  34. func GetDoctorScheduleList(orgid int64, page int64, limit int64) (schedules []*models.DoctorSchedules, total int64, err error) {
  35. offset := (page - 1) * limit
  36. err = XTReadDB().Model(&schedules).Where("user_org_id = ? and status =1", orgid).Count(&total).Offset(offset).Limit(limit).Find(&schedules).Error
  37. return schedules, total, err
  38. }
  39. func GetScheduleDetail(id int64) (models.DoctorSchedules, error) {
  40. schedules := models.DoctorSchedules{}
  41. err := XTReadDB().Model(&schedules).Where("id=? and status = 1", id).Find(&schedules).Error
  42. return schedules, err
  43. }
  44. func GetClassNameIsExsit(classname string, orgid int64, id int64) (schedule models.DoctorSchedules, err error) {
  45. err = XTReadDB().Model(&schedule).Where("class_name = ? and user_org_id =? and id <> ?", classname, orgid, id).First(&schedule).Error
  46. return schedule, err
  47. }
  48. func UpdateScheduleList(id int64, schedules *models.DoctorSchedules) error {
  49. 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
  50. return err
  51. }
  52. func GetStaffScheduleByScheduleType(id int64, orgid int64) (*models.StaffSchedule, error) {
  53. schedule := models.StaffSchedule{}
  54. err := XTReadDB().Model(&schedule).Where("schedule_type = ? and user_org_id = ? and status = 1", id, orgid).Find(&schedule).Error
  55. if err == gorm.ErrRecordNotFound {
  56. return nil, err
  57. }
  58. if err != nil {
  59. return nil, err
  60. }
  61. return &schedule, nil
  62. }
  63. func DeleteScheduleById(id int64) error {
  64. schedules := models.DoctorSchedules{}
  65. err := XTWriteDB().Model(&schedules).Where("id=?", id).Updates(map[string]interface{}{"status": 0}).Error
  66. return err
  67. }
  68. func GetDoctorList(orgid int64, appid int64) (role []*models.XTSgjUserAdminRole, err error) {
  69. 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
  70. return role, err
  71. }
  72. func GetAllDoctorList(orgid int64, appid int64) (role []*models.XTSgjUserAdminRole, err error) {
  73. 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
  74. return role, err
  75. }
  76. func GetAllNurseList(orgid int64, appid int64) (role []*models.XTSgjUserAdminRole, err error) {
  77. 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
  78. return role, err
  79. }
  80. func GetScheduleList(orgid int64) (schedule []*models.DoctorSchedules, err error) {
  81. err = XTReadDB().Model(&schedule).Where("user_org_id = ? and status = 1", orgid).Find(&schedule).Error
  82. return schedule, err
  83. }
  84. func GetScheduleListDetail(doctor_id int64, orgid int64, scheduledate int64) (*models.StaffSchedule, error) {
  85. schedule := models.StaffSchedule{}
  86. err := XTReadDB().Model(&schedule).Where("doctor_id = ? and user_org_id = ? and status =1 and schedule_date = ?", doctor_id, orgid, scheduledate).Find(&schedule).Error
  87. if err == gorm.ErrRecordNotFound {
  88. return nil, err
  89. }
  90. if err != nil {
  91. return nil, err
  92. }
  93. return &schedule, nil
  94. }
  95. func AddSchedule(schedule *models.StaffSchedule) error {
  96. err := XTWriteDB().Create(&schedule).Error
  97. return err
  98. }
  99. func UpdateStaffList(schedule *models.StaffSchedule, id int64) error {
  100. 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
  101. return err
  102. }
  103. func GetStaffScheduleList(orgid int64, startime int64, endtime int64) (schedule []*models.XtStaffSchedule, err error) {
  104. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  105. if startime > 0 {
  106. db = db.Where("x.start_time >=?", startime)
  107. }
  108. if endtime > 0 {
  109. db = db.Where("x.end_time <=?", endtime)
  110. }
  111. if orgid > 0 {
  112. db = db.Where("x.user_org_id = ?", orgid)
  113. }
  114. 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
  115. return schedule, err
  116. }
  117. func GetStaffScheduleListTwo(orgid int64, startime int64, endtime int64) (schedule []*models.StaffSchedule, err error) {
  118. err = XTReadDB().Model(&schedule).Where("user_org_id = ? and start_time>=? and end_time<=? and status = 1", orgid, startime, endtime).Find(&schedule).Error
  119. return schedule, err
  120. }
  121. func GetNextWeekSchedule(orgid int64, startime int64, endtime int64) (*models.StaffSchedule, error) {
  122. schedule := models.StaffSchedule{}
  123. err := XTReadDB().Model(&schedule).Where("user_org_id = ? and status = 1 and start_time >=? and end_time<=?", orgid, startime, endtime).Find(&schedule).Error
  124. if err == gorm.ErrRecordNotFound {
  125. return nil, err
  126. }
  127. if err != nil {
  128. return nil, err
  129. }
  130. return &schedule, nil
  131. }
  132. func GetScheduleByDoctorId(doctorid int64, startime int64, endtime int64, orgid int64) (schedule []*models.XtStaffSchedule, err error) {
  133. fmt.Println(doctorid, startime, endtime)
  134. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  135. if startime > 0 {
  136. db = db.Where("x.start_time >=?", startime)
  137. }
  138. if endtime > 0 {
  139. db = db.Where("x.end_time <=?", endtime)
  140. }
  141. if orgid > 0 {
  142. db = db.Where("x.user_org_id = ?", orgid)
  143. }
  144. if doctorid == 0 {
  145. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  146. }
  147. if doctorid > 0 {
  148. db = db.Where("x.doctor_type = ?", doctorid)
  149. }
  150. 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
  151. return schedule, err
  152. }
  153. func ToSearchSeacheduleList(keywords string, startime int64, endtime int64, orgid int64) (schedule []*models.XtStaffSchedule, err error) {
  154. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  155. if startime > 0 {
  156. db = db.Where("x.start_time >=?", startime)
  157. }
  158. if endtime > 0 {
  159. db = db.Where("x.end_time <=?", endtime)
  160. }
  161. if orgid > 0 {
  162. db = db.Where("x.user_org_id = ?", orgid)
  163. }
  164. likeKey := "%" + keywords + "%"
  165. //if(doctorid >0){
  166. // db = db.Where("x.doctor_id = ?", doctorid)
  167. //}
  168. 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
  169. return schedule, err
  170. }
  171. func DeleteStaffSchedule(orgid int64, startime int64, endtime int64) error {
  172. schedule := models.StaffSchedule{}
  173. err := XTWriteDB().Model(&schedule).Where("user_org_id = ? and start_time >= ? and end_time <=?", orgid, startime, endtime).Updates(map[string]interface{}{"status": 0}).Error
  174. return err
  175. }
  176. func GetContinueScheduleByOrgId(orgid int64) (*models.ContinueSchedule, error) {
  177. //schedules := models.DoctorSchedules{}
  178. //err := XTReadDB().Model(&schedules).Where("user_org_id = ? and status = 1", orgid).Find(&schedules).Error
  179. //if err == gorm.ErrRecordNotFound {
  180. // return nil, err
  181. //}
  182. //if err != nil {
  183. // return nil, err
  184. //}
  185. //return &schedules, nil
  186. schedule := models.ContinueSchedule{}
  187. err := XTReadDB().Model(&schedule).Where("user_org_id = ? and status = 1", orgid).Find(&schedule).Error
  188. if err == gorm.ErrRecordNotFound {
  189. return nil, err
  190. }
  191. if err != nil {
  192. return nil, err
  193. }
  194. return &schedule, nil
  195. }
  196. func UpdateContinusSchedule(schedule *models.ContinueSchedule, orgid int64) error {
  197. 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
  198. return err
  199. }
  200. func SaveNurseSort(role *models.App_Role, id int64) error {
  201. err := UserWriteDB().Model(&role).Where("id = ?", id).Updates(map[string]interface{}{"sort": role.Sort}).Error
  202. return err
  203. }
  204. func SaveIsSchedule(id int64, role *models.App_Role) error {
  205. err := UserWriteDB().Model(&role).Where("id=?", id).Updates(map[string]interface{}{"is_sort": role.IsSort}).Error
  206. return err
  207. }
  208. func GetScheduleListTotal(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
  209. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  210. if startime > 0 {
  211. db = db.Where("x.start_time >=?", startime)
  212. }
  213. if endtime > 0 {
  214. db = db.Where("x.end_time <=?", endtime)
  215. }
  216. if orgid > 0 {
  217. db = db.Where("x.user_org_id = ?", orgid)
  218. }
  219. 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
  220. return schedule, err
  221. }
  222. func GetTotalMinutes(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
  223. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  224. if startime > 0 {
  225. db = db.Where("x.start_time >=?", startime)
  226. }
  227. if endtime > 0 {
  228. db = db.Where("x.end_time <=?", endtime)
  229. }
  230. if orgid > 0 {
  231. db = db.Where("x.user_org_id = ?", orgid)
  232. }
  233. 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
  234. return schedule, err
  235. }
  236. func GetTotalMinutesOne(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
  237. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  238. if startime > 0 {
  239. db = db.Where("x.start_time >=?", startime)
  240. }
  241. if endtime > 0 {
  242. db = db.Where("x.end_time <=?", endtime)
  243. }
  244. if orgid > 0 {
  245. db = db.Where("x.user_org_id = ?", orgid)
  246. }
  247. 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
  248. return schedule, err
  249. }
  250. func GetTotalMinutesTwo(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
  251. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  252. if startime > 0 {
  253. db = db.Where("x.start_time >=?", startime)
  254. }
  255. if endtime > 0 {
  256. db = db.Where("x.end_time <=?", endtime)
  257. }
  258. if orgid > 0 {
  259. db = db.Where("x.user_org_id = ?", orgid)
  260. }
  261. 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
  262. return schedule, err
  263. }
  264. func GetChartTotalMinutesOne(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
  265. likeKey := "%" + keywords + "%"
  266. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  267. if startime > 0 {
  268. db = db.Where("x.start_time >=?", startime)
  269. }
  270. if endtime > 0 {
  271. db = db.Where("x.end_time <=?", endtime)
  272. }
  273. if orgid > 0 {
  274. db = db.Where("x.user_org_id = ?", orgid)
  275. }
  276. 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
  277. return schedule, err
  278. }
  279. func GetChartTotalMinutesTwo(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
  280. likeKey := "%" + keywords + "%"
  281. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  282. if startime > 0 {
  283. db = db.Where("x.start_time >=?", startime)
  284. }
  285. if endtime > 0 {
  286. db = db.Where("x.end_time <=?", endtime)
  287. }
  288. if orgid > 0 {
  289. db = db.Where("x.user_org_id = ?", orgid)
  290. }
  291. 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
  292. return schedule, err
  293. }
  294. func GetTotalWorkDay(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
  295. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  296. if startime > 0 {
  297. db = db.Where("x.start_time >=?", startime)
  298. }
  299. if endtime > 0 {
  300. db = db.Where("x.end_time <=?", endtime)
  301. }
  302. if orgid > 0 {
  303. db = db.Where("x.user_org_id = ?", orgid)
  304. }
  305. 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
  306. return schedule, err
  307. }
  308. func GetTotalNoWorkDay(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
  309. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  310. if startime > 0 {
  311. db = db.Where("x.start_time >=?", startime)
  312. }
  313. if endtime > 0 {
  314. db = db.Where("x.end_time <=?", endtime)
  315. }
  316. if orgid > 0 {
  317. db = db.Where("x.user_org_id = ?", orgid)
  318. }
  319. 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
  320. return schedule, err
  321. }
  322. func GetSearchScheduleListTotal(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
  323. likeKey := "%" + keywords + "%"
  324. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  325. if startime > 0 {
  326. db = db.Where("x.start_time >=?", startime)
  327. }
  328. if endtime > 0 {
  329. db = db.Where("x.end_time <=?", endtime)
  330. }
  331. if orgid > 0 {
  332. db = db.Where("x.user_org_id = ?", orgid)
  333. }
  334. 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
  335. return schedule, err
  336. }
  337. func GeSearchtTotalMinutes(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
  338. likeKey := "%" + keywords + "%"
  339. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  340. if startime > 0 {
  341. db = db.Where("x.start_time >=?", startime)
  342. }
  343. if endtime > 0 {
  344. db = db.Where("x.end_time <=?", endtime)
  345. }
  346. if orgid > 0 {
  347. db = db.Where("x.user_org_id = ?", orgid)
  348. }
  349. 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
  350. return schedule, err
  351. }
  352. func GetSearchWorkDay(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
  353. likeKey := "%" + keywords + "%"
  354. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  355. if startime > 0 {
  356. db = db.Where("x.start_time >=?", startime)
  357. }
  358. if endtime > 0 {
  359. db = db.Where("x.end_time <=?", endtime)
  360. }
  361. if orgid > 0 {
  362. db = db.Where("x.user_org_id = ?", orgid)
  363. }
  364. 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
  365. return schedule, err
  366. }
  367. func GetSearchWorkNoDay(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
  368. likeKey := "%" + keywords + "%"
  369. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  370. if startime > 0 {
  371. db = db.Where("x.start_time >=?", startime)
  372. }
  373. if endtime > 0 {
  374. db = db.Where("x.end_time <=?", endtime)
  375. }
  376. if orgid > 0 {
  377. db = db.Where("x.user_org_id = ?", orgid)
  378. }
  379. 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
  380. return schedule, err
  381. }
  382. func ChagneScheduleListTotal(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
  383. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  384. if startime > 0 {
  385. db = db.Where("x.start_time >=?", startime)
  386. }
  387. if endtime > 0 {
  388. db = db.Where("x.end_time <=?", endtime)
  389. }
  390. if orgid > 0 {
  391. db = db.Where("x.user_org_id = ?", orgid)
  392. }
  393. if doctortype == 0 {
  394. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  395. }
  396. if doctortype > 0 {
  397. db = db.Where("x.doctor_type = ?", doctortype)
  398. }
  399. 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
  400. return schedule, err
  401. }
  402. func ChangeScheduleMinute(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
  403. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  404. if startime > 0 {
  405. db = db.Where("x.start_time >=?", startime)
  406. }
  407. if endtime > 0 {
  408. db = db.Where("x.end_time <=?", endtime)
  409. }
  410. if orgid > 0 {
  411. db = db.Where("x.user_org_id = ?", orgid)
  412. }
  413. if doctortype == 0 {
  414. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  415. }
  416. if doctortype > 0 {
  417. db = db.Where("x.doctor_type = ?", doctortype)
  418. }
  419. 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
  420. return schedule, err
  421. }
  422. func ChangeWorkDay(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
  423. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  424. if startime > 0 {
  425. db = db.Where("x.start_time >=?", startime)
  426. }
  427. if endtime > 0 {
  428. db = db.Where("x.end_time <=?", endtime)
  429. }
  430. if orgid > 0 {
  431. db = db.Where("x.user_org_id = ?", orgid)
  432. }
  433. if doctortype == 0 {
  434. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  435. }
  436. if doctortype > 0 {
  437. db = db.Where("x.doctor_type = ?", doctortype)
  438. }
  439. 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
  440. return schedule, err
  441. }
  442. func ChangeNoWorkDay(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
  443. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  444. if startime > 0 {
  445. db = db.Where("x.start_time >=?", startime)
  446. }
  447. if endtime > 0 {
  448. db = db.Where("x.end_time <=?", endtime)
  449. }
  450. if orgid > 0 {
  451. db = db.Where("x.user_org_id = ?", orgid)
  452. }
  453. if doctortype == 0 {
  454. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  455. }
  456. if doctortype > 0 {
  457. db = db.Where("x.doctor_type = ?", doctortype)
  458. }
  459. 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
  460. return schedule, err
  461. }
  462. func ChartTotalMinute(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
  463. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  464. if startime > 0 {
  465. db = db.Where("x.start_time >=?", startime)
  466. }
  467. if endtime > 0 {
  468. db = db.Where("x.end_time <=?", endtime)
  469. }
  470. if orgid > 0 {
  471. db = db.Where("x.user_org_id = ?", orgid)
  472. }
  473. if doctortype == 0 {
  474. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  475. }
  476. if doctortype > 0 {
  477. db = db.Where("x.doctor_type = ?", doctortype)
  478. }
  479. 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
  480. return schedule, err
  481. }
  482. func ChartWorkDayMinute(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
  483. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  484. if startime > 0 {
  485. db = db.Where("x.start_time >=?", startime)
  486. }
  487. if endtime > 0 {
  488. db = db.Where("x.end_time <=?", endtime)
  489. }
  490. if orgid > 0 {
  491. db = db.Where("x.user_org_id = ?", orgid)
  492. }
  493. if doctortype == 0 {
  494. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  495. }
  496. if doctortype > 0 {
  497. db = db.Where("x.doctor_type = ?", doctortype)
  498. }
  499. 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
  500. return schedule, err
  501. }
  502. func GetMySchedule(startime int64, endtime int64, orgid int64, creator int64) (schedule []*models.XtStaffSchedule, err error) {
  503. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  504. 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
  505. return schedule, err
  506. }
  507. func GetAllMobileZone(orgid int64) (zone []*models.DeviceZone, err error) {
  508. err = XTReadDB().Model(&zone).Where("org_id = ? and status = 1", orgid).Find(&zone).Error
  509. return zone, err
  510. }
  511. func GetPatientSchedule(startime int64, zoneid int64, classtype int64, orgid int64) (schedule []*models.Schedule, err error) {
  512. db := XTReadDB().Table("xt_schedule as s")
  513. if zoneid > 0 {
  514. db = db.Where("s.partition_id = ?", zoneid)
  515. }
  516. if classtype > 0 {
  517. db = db.Where("s.schedule_type = ?", classtype)
  518. }
  519. err = db.Preload("DeviceZone", " status= 1").Preload("DeviceNumber", "status= 1").
  520. 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).
  521. 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
  522. return schedule, err
  523. }
  524. func DeleteSchedule(id int64) error {
  525. schedule := models.XtSchedule{}
  526. err := XTWriteDB().Model(&schedule).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  527. return err
  528. }
  529. func GetSearchPatient(keywords string, orgid int64, startime int64) (schedule []*models.Schedule, err error) {
  530. likeKey := "%" + keywords + "%"
  531. db := XTReadDB().Table("xt_schedule as s")
  532. err = db.Preload("DeviceZone", " status= 1").Preload("DeviceNumber", "status= 1").
  533. Preload("DialysisOrder", "status =1").
  534. 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).
  535. 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
  536. return schedule, err
  537. }