integration_service.go 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. "time"
  6. )
  7. func GetIntegrationPatientList(orgID int64, page, limit int64) (patients []*models.VMPatients, total int64, err error) {
  8. //db := MiddleReadDB()
  9. db := readDb.Model(&models.VMPatients{}).Where("status=1")
  10. if orgID > 0 {
  11. db = db.Where("user_org_id=?", orgID)
  12. }
  13. offset := (page - 1) * limit
  14. err = db.Preload("VMHisPatients", func(db *gorm.DB) *gorm.DB {
  15. return readMiddleDb.Model(&models.VMHisPatients{}).Where("status = 1 AND user_org_id = ?", orgID)
  16. }).Preload("Contagions", "status = 1").Group("id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
  17. return
  18. }
  19. func UpdatePatientsHis(org_id int64, his_user_id string, id int64) (err error) {
  20. db := MiddleWriteDB()
  21. err = db.Model(&models.HisPatients{}).Where("user_org_id = ? AND id = ?", org_id, id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "his_user_id": his_user_id}).Error
  22. return
  23. }
  24. func CreatePatientsHis(patient *models.HisPatients) (err error) {
  25. db := MiddleWriteDB()
  26. err = db.Save(&patient).Error
  27. return
  28. }
  29. func FindVMPatientById(orgID int64, id int64) (patient models.VMPatients, err error) {
  30. db := XTReadDB()
  31. err = db.Model(&models.VMPatients{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
  32. return
  33. }
  34. func FindHisPatientByHisId(orgID int64, his_user_id string) (total int64, err error) {
  35. db := MiddleReadDB()
  36. err = db.Model(&models.HisPatients{}).Where("his_user_id = ? and user_org_id=? and status=1", his_user_id, orgID).Count(&total).Error
  37. return
  38. }
  39. func GetAdminUsers(orgID int64, appID int64, page int, limit int) (admins []*models.VMUserAdminRole, total int64, err error) {
  40. db := readUserDb.Model(&models.VMUserAdminRole{}).Where("status=1")
  41. if orgID > 0 {
  42. db = db.Where("org_id = ? AND app_id = ?", orgID, appID)
  43. }
  44. offset := (page - 1) * limit
  45. err = db.Preload("HisUserAdminRole", func(db *gorm.DB) *gorm.DB {
  46. return readMiddleDb.Model(&models.HisUserAdminRole{}).Where("status = 1 AND org_id = ? AND app_id = ?", orgID, appID)
  47. }).Preload("VMUserAdmin", "status = 1").Preload("VMUserRole", "status = 1 AND org_id = ? AND app_id = ?", orgID, appID).Count(&total).Offset(offset).Limit(limit).Find(&admins).Error
  48. return
  49. }
  50. func UpdateAdminsHis(org_id int64, his_user_id string, id int64) (err error) {
  51. db := MiddleWriteDB()
  52. err = db.Model(&models.HisUserAdminRole{}).Where("org_id = ? AND id = ?", org_id, id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "his_user_id": his_user_id}).Error
  53. return
  54. }
  55. func CreateAdminsHis(admin *models.HisUserAdminRole) (err error) {
  56. db := MiddleWriteDB()
  57. err = db.Save(&admin).Error
  58. return
  59. }
  60. func FindVMAdminRoleById(orgID int64, id int64, app_id int64) (admin models.VMUserAdminRole, err error) {
  61. db := UserReadDB()
  62. err = db.Model(&models.VMUserAdminRole{}).Where("admin_user_id = ? and org_id=? and app_id = ? and status=1", id, orgID, app_id).First(&admin).Error
  63. return
  64. }
  65. func FindHisAdminByHisId(orgID int64, his_user_id string, app_id int64) (total int64, err error) {
  66. db := MiddleReadDB()
  67. err = db.Model(&models.HisUserAdminRole{}).Where("his_user_id = ? and org_id=? and app_id = ? and status=1", his_user_id, orgID, app_id).Count(&total).Error
  68. return
  69. }