diff --git a/backend/pkg/database/migrations/20240114092806/source_credential.go b/backend/pkg/database/migrations/20240114092806/source_credential.go index 5625e70a..780236c8 100644 --- a/backend/pkg/database/migrations/20240114092806/source_credential.go +++ b/backend/pkg/database/migrations/20240114092806/source_credential.go @@ -2,6 +2,7 @@ package _0240114092806 import ( "github.com/fastenhealth/fasten-onprem/backend/pkg/models" + sourcesPkg "github.com/fastenhealth/fasten-sources/pkg" "github.com/google/uuid" ) @@ -13,11 +14,12 @@ type SourceCredential struct { Patient string `json:"patient" gorm:"uniqueIndex:idx_user_source_patient"` //New Fields - Display string `json:"display"` - BrandID *uuid.UUID `json:"brand_id"` - PortalID *uuid.UUID `json:"portal_id"` - EndpointID uuid.UUID `json:"endpoint_id"` - PlatformType string `json:"platform_type"` + Display string `json:"display"` + LighthouseEnvType sourcesPkg.FastenLighthouseEnvType `json:"lighthouse_env_type"` + BrandID *uuid.UUID `json:"brand_id"` + PortalID *uuid.UUID `json:"portal_id"` + EndpointID uuid.UUID `json:"endpoint_id"` + PlatformType string `json:"platform_type"` LatestBackgroundJob *models.BackgroundJob `json:"latest_background_job,omitempty"` LatestBackgroundJobID *uuid.UUID `json:"-"` diff --git a/backend/pkg/database/migrations/20240114103850/source_credential.go b/backend/pkg/database/migrations/20240114103850/source_credential.go index f90d34c9..7ebb9346 100644 --- a/backend/pkg/database/migrations/20240114103850/source_credential.go +++ b/backend/pkg/database/migrations/20240114103850/source_credential.go @@ -16,10 +16,11 @@ type SourceCredential struct { EndpointID uuid.UUID `json:"endpoint_id" gorm:"uniqueIndex:idx_user_source_patient"` //New Fields - Display string `json:"display"` - BrandID uuid.UUID `json:"brand_id"` - PortalID uuid.UUID `json:"portal_id"` - PlatformType sourcesPkg.PlatformType `json:"platform_type"` + Display string `json:"display"` + LighthouseEnvType sourcesPkg.FastenLighthouseEnvType `json:"lighthouse_env_type"` + BrandID uuid.UUID `json:"brand_id"` + PortalID uuid.UUID `json:"portal_id"` + PlatformType sourcesPkg.PlatformType `json:"platform_type"` LatestBackgroundJob *models.BackgroundJob `json:"latest_background_job,omitempty"` LatestBackgroundJobID *uuid.UUID `json:"-"` diff --git a/backend/pkg/models/source_credential.go b/backend/pkg/models/source_credential.go index 7235b007..33f5ce89 100644 --- a/backend/pkg/models/source_credential.go +++ b/backend/pkg/models/source_credential.go @@ -27,10 +27,11 @@ type SourceCredential struct { EndpointID uuid.UUID `json:"endpoint_id" gorm:"uniqueIndex:idx_user_source_patient"` //New Fields - Display string `json:"display"` - BrandID uuid.UUID `json:"brand_id"` - PortalID uuid.UUID `json:"portal_id"` - PlatformType sourcesPkg.PlatformType `json:"platform_type"` + Display string `json:"display"` + LighthouseEnvType sourcesPkg.FastenLighthouseEnvType `json:"lighthouse_env_type"` + BrandID uuid.UUID `json:"brand_id"` + PortalID uuid.UUID `json:"portal_id"` + PlatformType sourcesPkg.PlatformType `json:"platform_type"` LatestBackgroundJob *BackgroundJob `json:"latest_background_job,omitempty"` LatestBackgroundJobID *uuid.UUID `json:"-"` diff --git a/backend/pkg/web/handler/background_jobs.go b/backend/pkg/web/handler/background_jobs.go index 02814fb2..3c3a0f84 100644 --- a/backend/pkg/web/handler/background_jobs.go +++ b/backend/pkg/web/handler/background_jobs.go @@ -9,7 +9,6 @@ import ( "github.com/fastenhealth/fasten-onprem/backend/pkg/models" "github.com/fastenhealth/fasten-sources/clients/factory" sourceModels "github.com/fastenhealth/fasten-sources/clients/models" - sourcePkg "github.com/fastenhealth/fasten-sources/pkg" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" "net/http" @@ -36,7 +35,7 @@ func BackgroundJobSyncResources( _sourceCred *models.SourceCredential, ) (sourceModels.SourceClient, sourceModels.UpsertSummary, error) { // after creating the client, we should do a bulk import - sourceClient, err := factory.GetSourceClient(sourcePkg.GetFastenLighthouseEnv(), _backgroundJobContext, _logger, _sourceCred) + sourceClient, err := factory.GetSourceClient(_sourceCred.LighthouseEnvType, _backgroundJobContext, _logger, _sourceCred) if err != nil { resultErr := fmt.Errorf("an error occurred while initializing hub client using source credential: %w", err) _logger.Errorln(resultErr) diff --git a/backend/pkg/web/handler/source.go b/backend/pkg/web/handler/source.go index f91da706..0d5a7bc6 100644 --- a/backend/pkg/web/handler/source.go +++ b/backend/pkg/web/handler/source.go @@ -151,7 +151,7 @@ func CreateManualSource(c *gin.Context) { manualSourceCredential := models.SourceCredential{ PlatformType: sourcePkg.PlatformTypeManual, } - tempSourceClient, err := factory.GetSourceClient(sourcePkg.GetFastenLighthouseEnv(), c, logger, &manualSourceCredential) + tempSourceClient, err := factory.GetSourceClient("", c, logger, &manualSourceCredential) if err != nil { logger.Errorln("An error occurred while initializing hub client using manual source without credentials", err) c.JSON(http.StatusInternalServerError, gin.H{"success": false}) @@ -185,7 +185,7 @@ func CreateManualSource(c *gin.Context) { _databaseRepo database.DatabaseRepository, _sourceCred *models.SourceCredential, ) (sourceModels.SourceClient, sourceModels.UpsertSummary, error) { - manualSourceClient, err := factory.GetSourceClient(sourcePkg.GetFastenLighthouseEnv(), _backgroundJobContext, _logger, _sourceCred) + manualSourceClient, err := factory.GetSourceClient("", _backgroundJobContext, _logger, _sourceCred) if err != nil { resultErr := fmt.Errorf("an error occurred while initializing hub client using manual source with credential: %w", err) logger.Errorln(resultErr) diff --git a/backend/pkg/web/handler/unsafe.go b/backend/pkg/web/handler/unsafe.go index 461315b8..a105d990 100644 --- a/backend/pkg/web/handler/unsafe.go +++ b/backend/pkg/web/handler/unsafe.go @@ -6,7 +6,6 @@ import ( "github.com/fastenhealth/fasten-onprem/backend/pkg/database" "github.com/fastenhealth/fasten-onprem/backend/pkg/models" "github.com/fastenhealth/fasten-sources/clients/factory" - sourcePkg "github.com/fastenhealth/fasten-sources/pkg" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" "net/http" @@ -46,7 +45,7 @@ func UnsafeRequestSource(c *gin.Context) { return } - client, err := factory.GetSourceClient(sourcePkg.GetFastenLighthouseEnv(), c, logger, foundSource) + client, err := factory.GetSourceClient("", c, logger, foundSource) if err != nil { logger.Errorf("Could not initialize source client %v", err) c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": err.Error()}) @@ -140,7 +139,7 @@ func UnsafeSyncResourceNames(c *gin.Context) { return } - client, err := factory.GetSourceClient(sourcePkg.GetFastenLighthouseEnv(), c, logger, foundSource) + client, err := factory.GetSourceClient("", c, logger, foundSource) if err != nil { logger.Errorf("Could not initialize source client %v", err) c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": err.Error()}) diff --git a/frontend/src/app/components/medical-sources-connected/medical-sources-connected.component.ts b/frontend/src/app/components/medical-sources-connected/medical-sources-connected.component.ts index 4feeca53..1c335fe0 100644 --- a/frontend/src/app/components/medical-sources-connected/medical-sources-connected.component.ts +++ b/frontend/src/app/components/medical-sources-connected/medical-sources-connected.component.ts @@ -13,6 +13,7 @@ import {Location} from '@angular/common'; import {EventBusService} from '../../services/event-bus.service'; import {SourceState} from '../../models/fasten/source-state'; import {PatientAccessBrand} from '../../models/patient-access-brands'; +import {environment} from '../../../environments/environment'; @Component({ selector: 'app-medical-sources-connected', @@ -163,6 +164,7 @@ export class MedicalSourcesConnectedComponent implements OnInit { id: expectedSourceStateInfo.reconnect_source_id, display: portalInfo.name, + lighthouse_env_type: environment.lighthouse_api_endpoint_base == 'https://lighthouse.fastenhealth.com/v1' ? 'prod' : 'sandbox', brand_id: expectedSourceStateInfo.brand_id, portal_id: expectedSourceStateInfo.portal_id, endpoint_id: expectedSourceStateInfo.endpoint_id, diff --git a/frontend/src/app/models/fasten/source.ts b/frontend/src/app/models/fasten/source.ts index 8be83176..814143b5 100644 --- a/frontend/src/app/models/fasten/source.ts +++ b/frontend/src/app/models/fasten/source.ts @@ -8,6 +8,7 @@ export class Source { user_id?: number display?: string + lighthouse_env_type?: 'prod' | 'sandbox' brand_id?: string portal_id?: string endpoint_id: string