doctor_schedule_service.go 38KB

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