doctor_schedule_service.go 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. package service
  2. import (
  3. "fmt"
  4. "time"
  5. "XT_New/models"
  6. "github.com/jinzhu/gorm"
  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 := XTWriteDB().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 GetAllDoctorListSix(orgid int64, appid int64) (role []*models.XTSgjUserAdminRole, err error) {
  77. err = UserReadDB().Model(&role).Where("org_id =? and app_id = ? and status = 1", orgid, appid).Order("sort desc").Find(&role).Error
  78. return role, err
  79. }
  80. func GetAllNurseList(orgid int64, appid int64) (role []*models.XTSgjUserAdminRole, err error) {
  81. 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
  82. return role, err
  83. }
  84. func GetScheduleList(orgid int64) (schedule []*models.DoctorSchedules, err error) {
  85. err = XTReadDB().Model(&schedule).Where("user_org_id = ? and status = 1", orgid).Find(&schedule).Error
  86. return schedule, err
  87. }
  88. func GetScheduleListDetail(doctor_id int64, orgid int64, scheduledate int64) (*models.StaffSchedule, error) {
  89. schedule := models.StaffSchedule{}
  90. err := XTReadDB().Model(&schedule).Where("doctor_id = ? and user_org_id = ? and status =1 and schedule_date = ?", doctor_id, orgid, scheduledate).Find(&schedule).Error
  91. if err == gorm.ErrRecordNotFound {
  92. return nil, err
  93. }
  94. if err != nil {
  95. return nil, err
  96. }
  97. return &schedule, nil
  98. }
  99. func AddSchedule(schedule *models.StaffSchedule) error {
  100. err := XTWriteDB().Create(&schedule).Error
  101. return err
  102. }
  103. func UpdateStaffList(schedule *models.StaffSchedule, id int64) error {
  104. err := XTWriteDB().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
  105. return err
  106. }
  107. func GetStaffScheduleList(orgid int64, startime int64, endtime int64) (schedule []*models.XtStaffSchedule, err error) {
  108. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  109. if startime > 0 {
  110. db = db.Where("x.start_time >=?", startime)
  111. }
  112. if endtime > 0 {
  113. db = db.Where("x.end_time <=?", endtime)
  114. }
  115. if orgid > 0 {
  116. db = db.Where("x.user_org_id = ?", orgid)
  117. }
  118. if orgid > 0 {
  119. db = db.Where("r.org_id =?", orgid)
  120. }
  121. 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,x.remark,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
  122. return schedule, err
  123. }
  124. func GetStaffScheduleListTwo(orgid int64, startime int64, endtime int64) (schedule []*models.StaffSchedule, err error) {
  125. err = XTReadDB().Model(&schedule).Where("user_org_id = ? and start_time>=? and end_time<=? and status = 1", orgid, startime, endtime).Find(&schedule).Error
  126. return schedule, err
  127. }
  128. func GetNextWeekSchedule(orgid int64, startime int64, endtime int64) (*models.StaffSchedule, error) {
  129. schedule := models.StaffSchedule{}
  130. err := XTReadDB().Model(&schedule).Where("user_org_id = ? and status = 1 and start_time >=? and end_time<=?", orgid, startime, endtime).Find(&schedule).Error
  131. if err == gorm.ErrRecordNotFound {
  132. return nil, err
  133. }
  134. if err != nil {
  135. return nil, err
  136. }
  137. return &schedule, nil
  138. }
  139. func GetScheduleByDoctorId(doctorid int64, startime int64, endtime int64, orgid int64) (schedule []*models.XtStaffSchedule, err error) {
  140. fmt.Println(doctorid, startime, endtime)
  141. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  142. if startime > 0 {
  143. db = db.Where("x.start_time >=?", startime)
  144. }
  145. if endtime > 0 {
  146. db = db.Where("x.end_time <=?", endtime)
  147. }
  148. if orgid > 0 {
  149. db = db.Where("x.user_org_id = ?", orgid)
  150. }
  151. if orgid > 0 {
  152. db = db.Where("r.org_id = ?", orgid)
  153. }
  154. if doctorid == 0 {
  155. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  156. }
  157. if doctorid > 0 {
  158. db = db.Where("x.doctor_type = ?", doctorid)
  159. }
  160. 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,r.remark").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
  161. return schedule, err
  162. }
  163. func ToSearchSeacheduleList(keywords string, startime int64, endtime int64, orgid int64) (schedule []*models.XtStaffSchedule, err error) {
  164. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  165. if startime > 0 {
  166. db = db.Where("x.start_time >=?", startime)
  167. }
  168. if endtime > 0 {
  169. db = db.Where("x.end_time <=?", endtime)
  170. }
  171. if orgid > 0 {
  172. db = db.Where("x.user_org_id = ?", orgid)
  173. }
  174. likeKey := "%" + keywords + "%"
  175. //if(doctorid >0){
  176. // db = db.Where("x.doctor_id = ?", doctorid)
  177. //}
  178. 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
  179. return schedule, err
  180. }
  181. func DeleteStaffSchedule(orgid int64, startime int64, endtime int64) error {
  182. schedule := models.StaffSchedule{}
  183. err := XTWriteDB().Model(&schedule).Where("user_org_id = ? and start_time >= ? and end_time <=?", orgid, startime, endtime).Updates(map[string]interface{}{"status": 0}).Error
  184. return err
  185. }
  186. func GetContinueScheduleByOrgId(orgid int64) (*models.ContinueSchedule, error) {
  187. //schedules := models.DoctorSchedules{}
  188. //err := XTReadDB().Model(&schedules).Where("user_org_id = ? and status = 1", orgid).Find(&schedules).Error
  189. //if err == gorm.ErrRecordNotFound {
  190. // return nil, err
  191. //}
  192. //if err != nil {
  193. // return nil, err
  194. //}
  195. //return &schedules, nil
  196. schedule := models.ContinueSchedule{}
  197. err := XTReadDB().Model(&schedule).Where("user_org_id = ? and status = 1", orgid).Find(&schedule).Error
  198. if err == gorm.ErrRecordNotFound {
  199. return nil, err
  200. }
  201. if err != nil {
  202. return nil, err
  203. }
  204. return &schedule, nil
  205. }
  206. func UpdateContinusSchedule(schedule *models.ContinueSchedule, orgid int64) error {
  207. 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
  208. return err
  209. }
  210. func SaveNurseSort(role *models.App_Role, id int64) error {
  211. err := UserWriteDB().Model(&role).Where("id = ?", id).Updates(map[string]interface{}{"sort": role.Sort}).Error
  212. return err
  213. }
  214. func SaveIsSchedule(id int64, role *models.App_Role) error {
  215. err := UserWriteDB().Model(&role).Where("id=?", id).Updates(map[string]interface{}{"is_sort": role.IsSort}).Error
  216. return err
  217. }
  218. func GetScheduleListTotal(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
  219. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  220. if startime > 0 {
  221. db = db.Where("x.start_time >=?", startime)
  222. }
  223. if endtime > 0 {
  224. db = db.Where("x.end_time <=?", endtime)
  225. }
  226. if orgid > 0 {
  227. db = db.Where("x.user_org_id = ?", orgid)
  228. }
  229. 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
  230. return schedule, err
  231. }
  232. func GetTotalMinutes(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
  233. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  234. if startime > 0 {
  235. db = db.Where("x.start_time >=?", startime)
  236. }
  237. if endtime > 0 {
  238. db = db.Where("x.end_time <=?", endtime)
  239. }
  240. if orgid > 0 {
  241. db = db.Where("x.user_org_id = ?", orgid)
  242. }
  243. 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
  244. return schedule, err
  245. }
  246. func GetTotalMinutesOne(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
  247. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  248. if startime > 0 {
  249. db = db.Where("x.start_time >=?", startime)
  250. }
  251. if endtime > 0 {
  252. db = db.Where("x.end_time <=?", endtime)
  253. }
  254. if orgid > 0 {
  255. db = db.Where("x.user_org_id = ?", orgid)
  256. }
  257. 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
  258. return schedule, err
  259. }
  260. func GetTotalMinutesTwo(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
  261. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  262. if startime > 0 {
  263. db = db.Where("x.start_time >=?", startime)
  264. }
  265. if endtime > 0 {
  266. db = db.Where("x.end_time <=?", endtime)
  267. }
  268. if orgid > 0 {
  269. db = db.Where("x.user_org_id = ?", orgid)
  270. }
  271. 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
  272. return schedule, err
  273. }
  274. func GetChartTotalMinutesOne(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
  275. likeKey := "%" + keywords + "%"
  276. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  277. if startime > 0 {
  278. db = db.Where("x.start_time >=?", startime)
  279. }
  280. if endtime > 0 {
  281. db = db.Where("x.end_time <=?", endtime)
  282. }
  283. if orgid > 0 {
  284. db = db.Where("x.user_org_id = ?", orgid)
  285. }
  286. 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
  287. return schedule, err
  288. }
  289. func GetChartTotalMinutesTwo(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
  290. likeKey := "%" + keywords + "%"
  291. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  292. if startime > 0 {
  293. db = db.Where("x.start_time >=?", startime)
  294. }
  295. if endtime > 0 {
  296. db = db.Where("x.end_time <=?", endtime)
  297. }
  298. if orgid > 0 {
  299. db = db.Where("x.user_org_id = ?", orgid)
  300. }
  301. 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
  302. return schedule, err
  303. }
  304. func GetTotalWorkDay(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
  305. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  306. if startime > 0 {
  307. db = db.Where("x.start_time >=?", startime)
  308. }
  309. if endtime > 0 {
  310. db = db.Where("x.end_time <=?", endtime)
  311. }
  312. if orgid > 0 {
  313. db = db.Where("x.user_org_id = ?", orgid)
  314. }
  315. 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
  316. return schedule, err
  317. }
  318. func GetTotalNoWorkDay(orgid int64, startime int64, endtime int64) (schedule []*models.CountStaffSchedule, err error) {
  319. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  320. if startime > 0 {
  321. db = db.Where("x.start_time >=?", startime)
  322. }
  323. if endtime > 0 {
  324. db = db.Where("x.end_time <=?", endtime)
  325. }
  326. if orgid > 0 {
  327. db = db.Where("x.user_org_id = ?", orgid)
  328. }
  329. 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
  330. return schedule, err
  331. }
  332. func GetSearchScheduleListTotal(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
  333. likeKey := "%" + keywords + "%"
  334. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  335. if startime > 0 {
  336. db = db.Where("x.start_time >=?", startime)
  337. }
  338. if endtime > 0 {
  339. db = db.Where("x.end_time <=?", endtime)
  340. }
  341. if orgid > 0 {
  342. db = db.Where("x.user_org_id = ?", orgid)
  343. }
  344. 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
  345. return schedule, err
  346. }
  347. func GeSearchtTotalMinutes(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
  348. likeKey := "%" + keywords + "%"
  349. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  350. if startime > 0 {
  351. db = db.Where("x.start_time >=?", startime)
  352. }
  353. if endtime > 0 {
  354. db = db.Where("x.end_time <=?", endtime)
  355. }
  356. if orgid > 0 {
  357. db = db.Where("x.user_org_id = ?", orgid)
  358. }
  359. 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
  360. return schedule, err
  361. }
  362. func GetSearchWorkDay(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
  363. likeKey := "%" + keywords + "%"
  364. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  365. if startime > 0 {
  366. db = db.Where("x.start_time >=?", startime)
  367. }
  368. if endtime > 0 {
  369. db = db.Where("x.end_time <=?", endtime)
  370. }
  371. if orgid > 0 {
  372. db = db.Where("x.user_org_id = ?", orgid)
  373. }
  374. 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
  375. return schedule, err
  376. }
  377. func GetSearchWorkNoDay(orgid int64, startime int64, endtime int64, keywords string) (schedule []*models.CountStaffSchedule, err error) {
  378. likeKey := "%" + keywords + "%"
  379. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  380. if startime > 0 {
  381. db = db.Where("x.start_time >=?", startime)
  382. }
  383. if endtime > 0 {
  384. db = db.Where("x.end_time <=?", endtime)
  385. }
  386. if orgid > 0 {
  387. db = db.Where("x.user_org_id = ?", orgid)
  388. }
  389. 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
  390. return schedule, err
  391. }
  392. func ChagneScheduleListTotal(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
  393. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  394. if startime > 0 {
  395. db = db.Where("x.start_time >=?", startime)
  396. }
  397. if endtime > 0 {
  398. db = db.Where("x.end_time <=?", endtime)
  399. }
  400. if orgid > 0 {
  401. db = db.Where("x.user_org_id = ?", orgid)
  402. }
  403. if doctortype == 0 {
  404. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  405. }
  406. if doctortype > 0 {
  407. db = db.Where("x.doctor_type = ?", doctortype)
  408. }
  409. 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
  410. return schedule, err
  411. }
  412. func ChangeScheduleMinute(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
  413. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  414. if startime > 0 {
  415. db = db.Where("x.start_time >=?", startime)
  416. }
  417. if endtime > 0 {
  418. db = db.Where("x.end_time <=?", endtime)
  419. }
  420. if orgid > 0 {
  421. db = db.Where("x.user_org_id = ?", orgid)
  422. }
  423. if doctortype == 0 {
  424. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  425. }
  426. if doctortype > 0 {
  427. db = db.Where("x.doctor_type = ?", doctortype)
  428. }
  429. 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
  430. return schedule, err
  431. }
  432. func ChangeWorkDay(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
  433. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  434. if startime > 0 {
  435. db = db.Where("x.start_time >=?", startime)
  436. }
  437. if endtime > 0 {
  438. db = db.Where("x.end_time <=?", endtime)
  439. }
  440. if orgid > 0 {
  441. db = db.Where("x.user_org_id = ?", orgid)
  442. }
  443. if doctortype == 0 {
  444. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  445. }
  446. if doctortype > 0 {
  447. db = db.Where("x.doctor_type = ?", doctortype)
  448. }
  449. 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
  450. return schedule, err
  451. }
  452. func ChangeNoWorkDay(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
  453. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  454. if startime > 0 {
  455. db = db.Where("x.start_time >=?", startime)
  456. }
  457. if endtime > 0 {
  458. db = db.Where("x.end_time <=?", endtime)
  459. }
  460. if orgid > 0 {
  461. db = db.Where("x.user_org_id = ?", orgid)
  462. }
  463. if doctortype == 0 {
  464. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  465. }
  466. if doctortype > 0 {
  467. db = db.Where("x.doctor_type = ?", doctortype)
  468. }
  469. 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
  470. return schedule, err
  471. }
  472. func ChartTotalMinute(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
  473. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  474. if startime > 0 {
  475. db = db.Where("x.start_time >=?", startime)
  476. }
  477. if endtime > 0 {
  478. db = db.Where("x.end_time <=?", endtime)
  479. }
  480. if orgid > 0 {
  481. db = db.Where("x.user_org_id = ?", orgid)
  482. }
  483. if doctortype == 0 {
  484. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  485. }
  486. if doctortype > 0 {
  487. db = db.Where("x.doctor_type = ?", doctortype)
  488. }
  489. 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
  490. return schedule, err
  491. }
  492. func ChartWorkDayMinute(orgid int64, startime int64, endtime int64, doctortype int64) (schedule []*models.CountStaffSchedule, err error) {
  493. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  494. if startime > 0 {
  495. db = db.Where("x.start_time >=?", startime)
  496. }
  497. if endtime > 0 {
  498. db = db.Where("x.end_time <=?", endtime)
  499. }
  500. if orgid > 0 {
  501. db = db.Where("x.user_org_id = ?", orgid)
  502. }
  503. if doctortype == 0 {
  504. db = db.Where("x.doctor_type = 2 or x.doctor_type = 3")
  505. }
  506. if doctortype > 0 {
  507. db = db.Where("x.doctor_type = ?", doctortype)
  508. }
  509. 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
  510. return schedule, err
  511. }
  512. func GetMySchedule(startime int64, endtime int64, orgid int64, creator int64) (schedule []*models.XtStaffSchedule, err error) {
  513. db := XTReadDB().Table("xt_staff_schedule as x").Where("x.status = 1")
  514. 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
  515. return schedule, err
  516. }
  517. func GetAllMobileZone(orgid int64) (zone []*models.DeviceZone, err error) {
  518. err = XTReadDB().Model(&zone).Where("org_id = ? and status = 1", orgid).Find(&zone).Error
  519. return zone, err
  520. }
  521. func GetAllMobileZonePb(orgid int64) (zone []*models.DeviceZonePb, err error) {
  522. err = XTReadDB().Model(&zone).Preload("DeviceNumber", "status =1").Where("org_id = ? and status = 1", orgid).Find(&zone).Error
  523. return zone, err
  524. }
  525. func GetPatientScheduleByPd(schedule_date int64, zoneid int64, orgid int64, class_type int64) (list []*models.DeviceZonePb, err error) {
  526. db := XTReadDB().Table("xt_device_zone as x").Where("x.status = 1")
  527. if zoneid > 0 {
  528. db = db.Where("x.id = ?", zoneid)
  529. }
  530. if orgid > 0 {
  531. db = db.Where("x.org_id = ?", orgid)
  532. }
  533. if class_type > 0 {
  534. err = db.Select("x.id,x.org_id,x.name,x.type,x.sort").Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
  535. return XTReadDB().Model(&models.DeviceNumber{}).Where("status = 1").Preload("Schedule", func(db *gorm.DB) *gorm.DB {
  536. 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 {
  537. return db.Where("user_org_id = ? and status = 1 and solution_status =1", orgid).Group("patient_id,mode_id").Order("created_time asc")
  538. })
  539. })
  540. }).Find(&list).Error
  541. } else {
  542. err = db.Select("x.id,x.org_id,x.name,x.type,x.sort").Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
  543. return XTReadDB().Model(&models.DeviceNumber{}).Where("status = 1").Preload("Schedule", func(db *gorm.DB) *gorm.DB {
  544. 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 {
  545. return db.Where("user_org_id = ? and status = 1 and solution_status =1", orgid).Group("patient_id,mode_id").Order("created_time asc")
  546. })
  547. })
  548. }).Find(&list).Error
  549. }
  550. return list, err
  551. }
  552. func GetPatientSchedule(startime int64, zoneid int64, classtype int64, orgid int64) (schedule []*models.ScheduleTwenty, err error) {
  553. db := XTReadDB().Table("xt_schedule as s")
  554. if zoneid > 0 {
  555. db = db.Where("s.partition_id = ?", zoneid)
  556. }
  557. if classtype > 0 {
  558. db = db.Where("s.schedule_type = ?", classtype)
  559. }
  560. err = db.Preload("DeviceZone", " status= 1").Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
  561. return XTReadDB().Model(&models.DeviceNumber{}).Where("status = 1 AND org_id = ?", orgid).Order("sort asc")
  562. }).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).
  563. 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
  564. return schedule, err
  565. }
  566. func GetPatientScheduleByBed(schedule_date int64, zoneid int64, orgid int64, class_type int64) (list []*models.PatientDeviceNumber, err error) {
  567. db := XTReadDB().Table("xt_device_number as x").Where("x.status = 1")
  568. if zoneid > 0 {
  569. db = db.Where("x.zone_id = ?", zoneid)
  570. }
  571. if orgid > 0 {
  572. db = db.Where("x.org_id = ?", orgid)
  573. }
  574. if class_type > 0 {
  575. 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 {
  576. 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)
  577. }).Find(&list).Error
  578. } else {
  579. 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 {
  580. 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)
  581. }).Find(&list).Error
  582. }
  583. return list, err
  584. }
  585. func GetPatientDialysisOrderDate(shcedule_date int64, class_type int64, orgid int64) (schedule []*models.Schedule, err error) {
  586. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  587. if shcedule_date > 0 {
  588. db = db.Where("x.schedule_date = ?", shcedule_date)
  589. }
  590. if class_type > 0 {
  591. db = db.Where("x.schedule_type = ?", class_type)
  592. }
  593. if orgid > 0 {
  594. db = db.Where("x.user_org_id = ?", orgid)
  595. }
  596. 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
  597. return schedule, err
  598. }
  599. func DeleteSchedule(id int64) error {
  600. schedule := models.XtSchedule{}
  601. err := XTWriteDB().Model(&schedule).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  602. return err
  603. }
  604. func DeleteScheduleByPatientId(patient_id int64, schedule_date int64, user_org_id int64) (models.XtSchedules, error) {
  605. schedules := models.XtSchedules{}
  606. 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
  607. return schedules, err
  608. }
  609. func GetSearchPatient(keywords string, orgid int64, startime int64) (schedule []*models.Schedule, err error) {
  610. likeKey := "%" + keywords + "%"
  611. db := XTReadDB().Table("xt_schedule as s")
  612. err = db.Preload("DeviceZone", " status= 1").Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
  613. return db.Where("status =1").Preload("DeviceZone", "status = 1")
  614. }).Preload("DialysisOrder", "status =1").Preload("DialysisPrescription", "status =1").
  615. 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).
  616. 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
  617. return schedule, err
  618. }
  619. func GetStaffScheduleById(ids []string) (schedule []*models.XtSchedule, err error) {
  620. err = XTReadDB().Where("id in(?)", ids).Find(&schedule).Error
  621. return schedule, err
  622. }
  623. func UpdateStaffSchedule(nextid int64, schedule models.XtSchedule) error {
  624. 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
  625. return err
  626. }
  627. func UpdateStaffScheduleOne(nextid int64, schedule models.WeekSchedule) error {
  628. 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
  629. return err
  630. }
  631. func UpdatedScheduleMode(schedule models.XtSchedule, id int64) error {
  632. xtSchedule := models.XtSchedule{}
  633. err := XTWriteDB().Model(&xtSchedule).Where("id = ? and status =1 ", id).Updates(map[string]interface{}{"mode_id": schedule.ModeId}).Error
  634. return err
  635. }
  636. func UpdatedSchedule(schedule models.XtSchedule, patient_id int64, schedule_date int64, schedule_type int64, bed_id int64) error {
  637. xtSchedule := models.XtSchedule{}
  638. 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
  639. return err
  640. }
  641. func GetDialyisSolution(patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  642. prescription := models.DialysisPrescription{}
  643. err := XTReadDB().Where("patient_id = ? and record_date = ? and status = 1", patientid, recorddate).Find(&prescription).Error
  644. if err != nil {
  645. if err == gorm.ErrRecordNotFound {
  646. return nil, err
  647. } else {
  648. return nil, err
  649. }
  650. }
  651. return &prescription, nil
  652. }
  653. func GetPatientScheduleIsExist(startime int64, schedule_type int64, bed_id int64, user_org_id int64) (*models.ScheduleNewPatients, error) {
  654. schedule := models.ScheduleNewPatients{}
  655. 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
  656. if err == gorm.ErrRecordNotFound {
  657. return nil, err
  658. }
  659. if err != nil {
  660. return nil, err
  661. }
  662. return &schedule, nil
  663. }
  664. func CreateDialysisPrescription(prescription *models.DialysisPrescription) error {
  665. err := XTWriteDB().Create(&prescription).Error
  666. return err
  667. }
  668. func CreateDialysisSolution(solution models.DialysisSolution) error {
  669. err := XTWriteDB().Create(&solution).Error
  670. return err
  671. }
  672. func UpdateDialysisPrescriptionOne(prescription models.DialysisPrescription, patientid int64, recordate int64, mode_id int64) error {
  673. 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
  674. return err
  675. }
  676. func GetPatientScheduleListByZone(schedule_date int64, class_tye int64, orgid int64) (schedule []*models.ScheduleTwentyOne, err error) {
  677. db := XTReadDB().Model(&schedule).Where("status = 1")
  678. if schedule_date > 0 {
  679. db = db.Where("schedule_date = ?", schedule_date)
  680. }
  681. if class_tye > 0 {
  682. db = db.Where("schedule_type = ?", class_tye)
  683. }
  684. if orgid > 0 {
  685. db = db.Where("user_org_id = ?", orgid)
  686. }
  687. err = db.Select("partition_id,Count(id) as id,user_org_id").Group("partition_id").Scan(&schedule).Error
  688. return schedule, err
  689. }
  690. func GetMobileScheduleListByScheduleDate(org_id int64, schedule_date int64) (schedule []*models.Search_Schedule, err error) {
  691. db := XTReadDB().Model(&schedule).Where("status= 1")
  692. if org_id > 0 {
  693. db = db.Where("user_org_id = ?", org_id)
  694. }
  695. if schedule_date > 0 {
  696. db = db.Where("schedule_date=?", schedule_date)
  697. }
  698. err = db.Find(&schedule).Error
  699. return schedule, err
  700. }
  701. func GetMobileScheduleListByScheduleDateOne(org_id int64, schedule_date int64) (schedule []*models.Search_Schedule, err error) {
  702. db := XTReadDB().Model(&schedule).Where("status= 1 and dialysis_machine_name=''")
  703. if org_id > 0 {
  704. db = db.Where("user_org_id = ?", org_id)
  705. }
  706. if schedule_date > 0 {
  707. db = db.Where("schedule_date=?", schedule_date)
  708. }
  709. err = db.Find(&schedule).Error
  710. return schedule, err
  711. }
  712. func DeleteStaffScheduleById(id int64, user_org_id int64) (err error) {
  713. schedule := models.StaffSchedule{}
  714. err = XTWriteDB().Model(&schedule).Where("id = ? and user_org_id =? and status=1", id, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
  715. return err
  716. }
  717. func SaveStaffScheduleRemark(schedule models.StaffSchedule) error {
  718. staffSchedule := models.StaffSchedule{}
  719. err := XTWriteDB().Model(&staffSchedule).Where("doctor_id = ? and status= 1 and start_time>=? and end_time<=? and user_org_id = ?", schedule.DoctorId, schedule.StartTime, schedule.EndTime, schedule.UserOrgId).Updates(map[string]interface{}{"remark": schedule.Remark}).Error
  720. return err
  721. }
  722. func UpdateSgjAdminUser(org_id int64, admin_user_id int64, content string) (models.SgjUserAdminRole, error) {
  723. adminRole := models.SgjUserAdminRole{}
  724. err := UserWriteDB().Model(&adminRole).Where("org_id = ? and admin_user_id = ? and status=1", org_id, admin_user_id).Updates(map[string]interface{}{"remark": content}).Error
  725. return adminRole, err
  726. }
  727. func GetStaffScheduleRemark(org_id int64, start_time int64, end_time int64) (models.XtStaffScheduleRemark, error) {
  728. scheduleRemark := models.XtStaffScheduleRemark{}
  729. err := XTReadDB().Where("user_org_id = ? and start_time >=? and end_time<=? and status=1", org_id, start_time, end_time).Find(&scheduleRemark).Error
  730. return scheduleRemark, err
  731. }
  732. func CreateStaffScheduleRemark(remark models.XtStaffScheduleRemark) error {
  733. err := XTWriteDB().Create(&remark).Error
  734. return err
  735. }
  736. func SaveStaffScheduleRemarkOne(remark models.XtStaffScheduleRemark) error {
  737. err := XTWriteDB().Save(&remark).Error
  738. return err
  739. }