integration_service.go 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. "time"
  6. )
  7. func UpdateSysItemIdByID(sysInspection *models.InspectionReference) error {
  8. db := XTWriteDB()
  9. err := db.Model(&models.InspectionReference{}).Update(&sysInspection).Error
  10. return err
  11. }
  12. func GetSysInspectionList(orgID int64) (sysInspection []*models.InspectionReference, ownerInspection []*models.InspectionReference, err error) {
  13. db := XTReadDB()
  14. err = db.Model(&models.InspectionReference{}).Where("org_id= 0 and status=1").Find(&sysInspection).Error
  15. err = db.Model(&models.InspectionReference{}).Where("org_id= ? and status=1", orgID).Find(&ownerInspection).Error
  16. return
  17. }
  18. func GetSyncList(orgID int64, page, limit int64) (patients []*models.MiddleSyncInfo, total int64, err error) {
  19. //db := MiddleReadDB()
  20. db := MiddleReadDB()
  21. offset := (page - 1) * limit
  22. err = db.Model(&models.MiddleSyncInfo{}).Where("org_id=? ", orgID).Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
  23. return
  24. }
  25. func SaveInterface(interfaceinfo *models.MiddleInterface) error {
  26. db := MiddleWriteDB()
  27. if interfaceinfo.ID > 0 {
  28. err := db.Save(&interfaceinfo).Error
  29. return err
  30. } else {
  31. err := db.Create(&interfaceinfo).Error
  32. return err
  33. }
  34. }
  35. func GetInterface(orgID int64) (interfaceinfo models.MiddleInterface, err error) {
  36. db := MiddleReadDB()
  37. err = db.Model(&models.MiddleInterface{}).Where("org_id=? and status=1", orgID).First(&interfaceinfo).Error
  38. return
  39. }
  40. func GetIntegrationPatientList(orgID int64, page, limit int64) (patients []*models.VMPatients, total int64, err error) {
  41. //db := MiddleReadDB()
  42. db := readDb.Model(&models.VMPatients{}).Where("status=1")
  43. if orgID > 0 {
  44. db = db.Where("user_org_id=?", orgID)
  45. }
  46. offset := (page - 1) * limit
  47. err = db.Preload("VMHisPatients", func(db *gorm.DB) *gorm.DB {
  48. return readMiddleDb.Model(&models.VMHisPatients{}).Where("status = 1 AND user_org_id = ?", orgID)
  49. }).Preload("Contagions", "status = 1").Group("id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
  50. return
  51. }
  52. func UpdatePatientsHis(org_id int64, his_user_id string, id int64) (err error) {
  53. db := MiddleWriteDB()
  54. 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
  55. return
  56. }
  57. func CreatePatientsHis(patient *models.HisPatients) (err error) {
  58. db := MiddleWriteDB()
  59. err = db.Save(&patient).Error
  60. return
  61. }
  62. func FindVMPatientById(orgID int64, id int64) (patient models.VMPatients, err error) {
  63. db := XTReadDB()
  64. err = db.Model(&models.VMPatients{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
  65. return
  66. }
  67. func FindHisPatientByHisId(orgID int64, his_user_id string) (total int64, err error) {
  68. db := MiddleReadDB()
  69. err = db.Model(&models.HisPatients{}).Where("his_user_id = ? and user_org_id=? and status=1", his_user_id, orgID).Count(&total).Error
  70. return
  71. }
  72. func GetAdminUsers(orgID int64, appID int64, page int, limit int) (admins []*models.VMUserAdminRole, total int64, err error) {
  73. db := readUserDb.Model(&models.VMUserAdminRole{}).Where("status=1")
  74. if orgID > 0 {
  75. db = db.Where("org_id = ? AND app_id = ?", orgID, appID)
  76. }
  77. offset := (page - 1) * limit
  78. err = db.Preload("HisUserAdminRole", func(db *gorm.DB) *gorm.DB {
  79. return readMiddleDb.Model(&models.HisUserAdminRole{}).Where("status = 1 AND org_id = ? AND app_id = ?", orgID, appID)
  80. }).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
  81. return
  82. }
  83. func UpdateAdminsHis(org_id int64, his_user_id string, id int64) (err error) {
  84. db := MiddleWriteDB()
  85. 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
  86. return
  87. }
  88. func CreateAdminsHis(admin *models.HisUserAdminRole) (err error) {
  89. db := MiddleWriteDB()
  90. err = db.Save(&admin).Error
  91. return
  92. }
  93. func FindVMAdminRoleById(orgID int64, id int64, app_id int64) (admin models.VMUserAdminRole, err error) {
  94. db := UserReadDB()
  95. 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
  96. return
  97. }
  98. func FindHisAdminByHisId(orgID int64, his_user_id string, app_id int64) (total int64, err error) {
  99. db := MiddleReadDB()
  100. 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
  101. return
  102. }