diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38f4a611..2ce828cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,7 @@ env: OPENCONCEPTLAB_API_URL: ${{ secrets.OPENCONCEPTLAB_API_URL }} JWT_KEY: ${{ secrets.JWT_KEY }} CLOUD_HEALTH_FHIRSTORE_ID: ${{ secrets.CLOUD_HEALTH_FHIRSTORE_ID }} + CLOUD_HEALTH_DATASET_LOCATION: ${{ secrets.CLOUD_HEALTH_DATASET_LOCATION }} SENTRY_DSN: ${{ secrets.SENTRY_DSN }} SAVANNAH_ADMIN_EMAIL: ${{ secrets.SAVANNAH_ADMIN_EMAIL }} AUTHSERVER_ENDPOINT: ${{ secrets.AUTHSERVER_ENDPOINT }} diff --git a/.github/workflows/staging_multitenant.yaml b/.github/workflows/staging_multitenant.yaml index 2ed71ccb..0ee34bd4 100644 --- a/.github/workflows/staging_multitenant.yaml +++ b/.github/workflows/staging_multitenant.yaml @@ -48,6 +48,7 @@ jobs: CLOUD_HEALTH_PUBSUB_TOPIC=${{ secrets.CLOUD_HEALTH_PUBSUB_TOPIC }} CLOUD_HEALTH_DATASET_ID=${{ secrets.CLOUD_HEALTH_DATASET_ID }} CLOUD_HEALTH_FHIRSTORE_ID=${{ secrets.CLOUD_HEALTH_FHIRSTORE_ID }} + CLOUD_HEALTH_DATASET_LOCATION=${{ secrets.CLOUD_HEALTH_DATASET_LOCATION }} OPENCONCEPTLAB_TOKEN=${{ secrets.OPENCONCEPTLAB_TOKEN }} SERVICE_HOST=${{ secrets.SERVICE_HOST }} OPENCONCEPTLAB_API_URL=${{ secrets.OPENCONCEPTLAB_API_URL }} diff --git a/pkg/clinical/application/common/testutils/testhelpers.go b/pkg/clinical/application/common/testutils/testhelpers.go index 8dd48da9..c94e5aff 100644 --- a/pkg/clinical/application/common/testutils/testhelpers.go +++ b/pkg/clinical/application/common/testutils/testhelpers.go @@ -2,6 +2,7 @@ package testutils import ( "context" + "log" "github.com/savannahghi/clinical/pkg/clinical/application/extensions" "github.com/savannahghi/clinical/pkg/clinical/infrastructure" @@ -9,13 +10,26 @@ import ( dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset" "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/openconceptlab" "github.com/savannahghi/clinical/pkg/clinical/usecases" + "github.com/savannahghi/serverutils" + "google.golang.org/api/healthcare/v1" ) // InitializeTestService sets up the structure that will be used by the usecase layer for // integration tests func InitializeTestService(ctx context.Context) (usecases.Interactor, error) { + project := serverutils.MustGetEnvVar(serverutils.GoogleCloudProjectIDEnvVarName) + _ = serverutils.MustGetEnvVar("CLOUD_HEALTH_PUBSUB_TOPIC") + datasetID := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_ID") + datasetLocation := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_LOCATION") + fhirStoreID := serverutils.MustGetEnvVar("CLOUD_HEALTH_FHIRSTORE_ID") + hsv, err := healthcare.NewService(ctx) + if err != nil { + log.Panicf("unable to initialize new Google Cloud Healthcare Service: %s", err) + } + + repo := dataset.NewFHIRRepository(ctx, hsv, project, datasetID, datasetLocation, fhirStoreID) + baseExtension := extensions.NewBaseExtensionImpl() - repo := dataset.NewFHIRRepository(ctx) fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL() diff --git a/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset.go index e7e708dc..3a57a21a 100644 --- a/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset.go +++ b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset.go @@ -19,7 +19,6 @@ import ( // constants used to configure the Google Cloud Healthcare API const ( - DatasetLocation = "europe-west4" baseFHIRURL = "https://healthcare.googleapis.com/v1" defaultTimeoutSeconds = 10 ) @@ -29,24 +28,22 @@ const ( type Repository struct { healthcareService *healthcare.Service projectID, location, datasetID, fhirStoreID string + parent string + datasetName string + fhirStoreName string } // NewFHIRRepository initializes a FHIR repository -func NewFHIRRepository(ctx context.Context) *Repository { - project := serverutils.MustGetEnvVar(serverutils.GoogleCloudProjectIDEnvVarName) - _ = serverutils.MustGetEnvVar("CLOUD_HEALTH_PUBSUB_TOPIC") - dataset := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_ID") - fhirStore := serverutils.MustGetEnvVar("CLOUD_HEALTH_FHIRSTORE_ID") - hsv, err := healthcare.NewService(ctx) - if err != nil { - log.Panicf("unable to initialize new Google Cloud Healthcare Service: %s", err) - } +func NewFHIRRepository(ctx context.Context, hsv *healthcare.Service, projectID, datasetID, datasetLocation, fhirStoreID string) *Repository { return &Repository{ healthcareService: hsv, - projectID: project, - location: DatasetLocation, - datasetID: dataset, - fhirStoreID: fhirStore, + projectID: projectID, + location: datasetLocation, + datasetID: datasetID, + fhirStoreID: fhirStoreID, + parent: fmt.Sprintf("projects/%s/locations/%s", projectID, datasetLocation), + datasetName: fmt.Sprintf("projects/%s/locations/%s/datasets/%s", projectID, datasetLocation, datasetID), + fhirStoreName: fmt.Sprintf("projects/%s/locations/%s/datasets/%s/fhirStores/%s", projectID, datasetLocation, datasetID, fhirStoreID), } } @@ -54,8 +51,7 @@ func NewFHIRRepository(ctx context.Context) *Repository { func (fr Repository) CreateDataset() (*healthcare.Operation, error) { fr.checkPreconditions() datasetsService := fr.healthcareService.Projects.Locations.Datasets - parent := fmt.Sprintf("projects/%s/locations/%s", fr.projectID, fr.location) - resp, err := datasetsService.Create(parent, &healthcare.Dataset{}).DatasetId(fr.datasetID).Do() + resp, err := datasetsService.Create(fr.parent, &healthcare.Dataset{}).DatasetId(fr.datasetID).Do() if err != nil { return nil, fmt.Errorf("create Data Set: %w", err) } @@ -66,15 +62,14 @@ func (fr Repository) CreateDataset() (*healthcare.Operation, error) { func (fr Repository) GetDataset() (*healthcare.Dataset, error) { fr.checkPreconditions() datasetsService := fr.healthcareService.Projects.Locations.Datasets - name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s", fr.projectID, fr.location, fr.datasetID) - resp, err := datasetsService.Get(name).Do() + resp, err := datasetsService.Get(fr.datasetName).Do() if err != nil { return nil, fmt.Errorf("get Data Set: %w", err) } return resp, nil } -// CreateFHIRStore creates an FHIR store. +// CreateFHIRStore creates a FHIR store. func (fr Repository) CreateFHIRStore() (*healthcare.FhirStore, error) { fr.checkPreconditions() storesService := fr.healthcareService.Projects.Locations.Datasets.FhirStores @@ -84,8 +79,7 @@ func (fr Repository) CreateFHIRStore() (*healthcare.FhirStore, error) { EnableUpdateCreate: true, Version: "R4", } - parent := fmt.Sprintf("projects/%s/locations/%s/datasets/%s", fr.projectID, fr.location, fr.datasetID) - resp, err := storesService.Create(parent, store).FhirStoreId(fr.fhirStoreID).Do() + resp, err := storesService.Create(fr.datasetName, store).FhirStoreId(fr.fhirStoreID).Do() if err != nil { return nil, fmt.Errorf("create FHIR Store: %w", err) } @@ -96,10 +90,7 @@ func (fr Repository) CreateFHIRStore() (*healthcare.FhirStore, error) { func (fr Repository) GetFHIRStore() (*healthcare.FhirStore, error) { fr.checkPreconditions() storesService := fr.healthcareService.Projects.Locations.Datasets.FhirStores - name := fmt.Sprintf( - "projects/%s/locations/%s/datasets/%s/fhirStores/%s", - fr.projectID, fr.location, fr.datasetID, fr.fhirStoreID) - store, err := storesService.Get(name).Do() + store, err := storesService.Get(fr.fhirStoreName).Do() if err != nil { return nil, fmt.Errorf("get FHIR Store: %w", err) } @@ -148,12 +139,7 @@ func (fr Repository) CreateFHIRResource(resourceType string, payload map[string] return nil, fmt.Errorf("json.Encode: %w", err) } - parent := fmt.Sprintf( - "projects/%s/locations/%s/datasets/%s/fhirStores/%s", - fr.projectID, fr.location, fr.datasetID, fr.fhirStoreID) - call := fhirService.Create( - parent, resourceType, bytes.NewReader(jsonPayload)) - + call := fhirService.Create(fr.fhirStoreName, resourceType, bytes.NewReader(jsonPayload)) call.Header().Set("Content-Type", "application/fhir+json;charset=utf-8") resp, err := call.Do() if err != nil { @@ -183,11 +169,8 @@ func (fr Repository) DeleteFHIRResource(resourceType, fhirResourceID string) ([] fr.checkPreconditions() fhirService := fr.healthcareService.Projects.Locations.Datasets.FhirStores.Fhir - name := fmt.Sprintf( - "projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s", - fr.projectID, fr.location, fr.datasetID, fr.fhirStoreID, - resourceType, fhirResourceID) - resp, err := fhirService.Delete(name).Do() + fhirResource := fmt.Sprintf("%s/fhir/%s/%s", fr.fhirStoreName, resourceType, fhirResourceID) + resp, err := fhirService.Delete(fhirResource).Do() if err != nil { return nil, fmt.Errorf("delete: %w", err) } @@ -229,12 +212,8 @@ func (fr Repository) PatchFHIRResource( if err != nil { return nil, fmt.Errorf("json.Encode: %w", err) } - name := fmt.Sprintf( - "projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s", - fr.projectID, fr.location, fr.datasetID, fr.fhirStoreID, - resourceType, fhirResourceID) - - call := fhirService.Patch(name, bytes.NewReader(jsonPayload)) + fhirResource := fmt.Sprintf("%s/fhir/%s/%s", fr.fhirStoreName, resourceType, fhirResourceID) + call := fhirService.Patch(fhirResource, bytes.NewReader(jsonPayload)) call.Header().Set("Content-Type", "application/json-patch+json") resp, err := call.Do() if err != nil { @@ -270,11 +249,8 @@ func (fr Repository) UpdateFHIRResource( if serverutils.IsDebug() { log.Printf("FHIR Update payload: %s", string(jsonPayload)) } - name := fmt.Sprintf( - "projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s", - fr.projectID, fr.location, fr.datasetID, fr.fhirStoreID, - resourceType, fhirResourceID) - call := fhirService.Update(name, bytes.NewReader(jsonPayload)) + fhirResource := fmt.Sprintf("%s/fhir/%s/%s", fr.fhirStoreName, resourceType, fhirResourceID) + call := fhirService.Update(fhirResource, bytes.NewReader(jsonPayload)) call.Header().Set("Content-Type", "application/fhir+json;charset=utf-8") resp, err := call.Do() if err != nil { @@ -298,16 +274,8 @@ func (fr Repository) UpdateFHIRResource( // patient compartment. func (fr Repository) GetFHIRPatientAllData(fhirResourceID string) ([]byte, error) { fhirService := fr.healthcareService.Projects.Locations.Datasets.FhirStores.Fhir - name := fmt.Sprintf( - "projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/Patient/%s", - fr.projectID, - fr.location, - fr.datasetID, - fr.fhirStoreID, - fhirResourceID, - ) - - resp, err := fhirService.PatientEverything(name).Do() + patientResource := fmt.Sprintf("%s/fhir/Patient/%s", fr.fhirStoreName, fhirResourceID) + resp, err := fhirService.PatientEverything(patientResource).Do() if err != nil { return nil, fmt.Errorf("PatientAllData: %w", err) } @@ -332,11 +300,8 @@ func (fr Repository) GetFHIRPatientAllData(fhirResourceID string) ([]byte, error func (fr Repository) GetFHIRResource(resourceType, fhirResourceID string) ([]byte, error) { fr.checkPreconditions() fhirService := fr.healthcareService.Projects.Locations.Datasets.FhirStores.Fhir - name := fmt.Sprintf( - "projects/%s/locations/%s/datasets/%s/fhirStores/%s/fhir/%s/%s", - fr.projectID, fr.location, fr.datasetID, fr.fhirStoreID, - resourceType, fhirResourceID) - call := fhirService.Read(name) + fhirResource := fmt.Sprintf("%s/fhir/%s/%s", fr.fhirStoreName, resourceType, fhirResourceID) + call := fhirService.Read(fhirResource) call.Header().Set("Content-Type", "application/fhir+json;charset=utf-8") resp, err := call.Do() if err != nil { diff --git a/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset_test.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset_test.go deleted file mode 100644 index 7f377158..00000000 --- a/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset_test.go +++ /dev/null @@ -1,167 +0,0 @@ -package fhirdataset_test - -import ( - "context" - "log" - "os" - "strings" - "testing" - - dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset" - "github.com/tj/assert" -) - -func TestMain(m *testing.M) { - log.Printf("Setting tests up ...") - envOriginalValue := os.Getenv("ENVIRONMENT") - os.Setenv("ENVIRONMENT", "staging") - debugEnvValue := os.Getenv("DEBUG") - os.Setenv("DEBUG", "true") - os.Setenv("REPOSITORY", "firebase") - collectionEnvValue := os.Getenv("ROOT_COLLECTION_SUFFIX") - os.Setenv("CLOUD_HEALTH_PUBSUB_TOPIC", "pubtopic") - os.Setenv("CLOUD_HEALTH_DATASET_ID", "datasetid") - os.Setenv("CLOUD_HEALTH_FHIRSTORE_ID", "fhirid") - - // do clean up - log.Printf("Running tests ...") - code := m.Run() - - log.Printf("Tearing tests down ...") - - // restore environment varibles to original values - os.Setenv(envOriginalValue, "ENVIRONMENT") - os.Setenv("DEBUG", debugEnvValue) - os.Setenv("ROOT_COLLECTION_SUFFIX", collectionEnvValue) - - os.Exit(code) -} - -func TestRepository_CreateDataset(t *testing.T) { - - tests := []struct { - name string - wantNil bool - wantErr bool - }{ - { - name: "valid dataset create", - wantNil: false, - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - fr := dataset.NewFHIRRepository(context.Background()) - got, err := fr.CreateDataset() - if !tt.wantErr && err != nil { - if !strings.Contains( - err.Error(), - "googleapi: Error 409: already exists", - ) { - t.Errorf("unexpected error: %v", err) - return - } - } - if !tt.wantNil && err == nil && got == nil { - t.Errorf("got nil dataset") - return - } - }) - } -} - -func TestRepository_GetDataset(t *testing.T) { - - tests := []struct { - name string - wantNil bool - wantErr bool - }{ - { - name: "default case", - wantNil: false, - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - fr := dataset.NewFHIRRepository(context.Background()) - got, err := fr.GetDataset() - if !tt.wantErr && err != nil { - if !strings.Contains( - err.Error(), - "googleapi: Error 404: does not exist exists", - ) { - t.Errorf("unexpected error: %v", err) - return - } - assert.NotNil(t, got) - } - if !tt.wantNil && err == nil && got == nil { - t.Errorf("got nil dataset") - return - } - }) - } -} - -func TestRepository_GetFHIRStore(t *testing.T) { - - tests := []struct { - name string - wantErr bool - }{ - { - name: "default case", - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - fr := dataset.NewFHIRRepository(context.Background()) - - got, err := fr.GetFHIRStore() - if (err != nil) != tt.wantErr { - t.Errorf("Service.GetFHIRStore() error = %v, wantErr %v", err, tt.wantErr) - return - } - assert.NotNil(t, got) - }) - } -} - -func TestRepository_CreateFHIRStore(t *testing.T) { - - tests := []struct { - name string - wantNil bool - wantErr bool - }{ - { - name: "valid fhir store create", - wantNil: false, - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - fr := dataset.NewFHIRRepository(context.Background()) - - got, err := fr.CreateFHIRStore() - if !tt.wantErr && err != nil { - if !strings.Contains( - err.Error(), - "googleapi: Error 409: already exists", - ) { - t.Errorf("unexpected error: %v", err) - return - } - } - if !tt.wantNil && err == nil && got == nil { - t.Errorf("got nil fhir store") - return - } - }) - } -} diff --git a/pkg/clinical/infrastructure/services/pubsub/service_test.go b/pkg/clinical/infrastructure/services/pubsub/service_test.go index 1ed34d16..9c1c6ccf 100644 --- a/pkg/clinical/infrastructure/services/pubsub/service_test.go +++ b/pkg/clinical/infrastructure/services/pubsub/service_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "log" "testing" "cloud.google.com/go/pubsub" @@ -15,6 +16,7 @@ import ( pubsubmessaging "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/pubsub" "github.com/savannahghi/clinical/pkg/clinical/usecases" "github.com/savannahghi/serverutils" + "google.golang.org/api/healthcare/v1" ) func InitializeTestPubSub(t *testing.T) (*pubsubmessaging.ServicePubSubMessaging, error) { @@ -32,10 +34,20 @@ func InitializeTestPubSub(t *testing.T) (*pubsubmessaging.ServicePubSubMessaging if err != nil { return nil, fmt.Errorf("unable to initialize pubsub client: %w", err) } + project := serverutils.MustGetEnvVar(serverutils.GoogleCloudProjectIDEnvVarName) + _ = serverutils.MustGetEnvVar("CLOUD_HEALTH_PUBSUB_TOPIC") + datasetID := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_ID") + datasetLocation := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_LOCATION") + fhirStoreID := serverutils.MustGetEnvVar("CLOUD_HEALTH_FHIRSTORE_ID") + hsv, err := healthcare.NewService(ctx) + if err != nil { + log.Panicf("unable to initialize new Google Cloud Healthcare Service: %s", err) + } + + repo := dataset.NewFHIRRepository(ctx, hsv, project, datasetID, datasetLocation, fhirStoreID) // Initialize base (common) extension baseExtension := extensions.NewBaseExtensionImpl() - repo := dataset.NewFHIRRepository(ctx) fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL() diff --git a/pkg/clinical/presentation/config.go b/pkg/clinical/presentation/config.go index 59be1c36..6c527eae 100644 --- a/pkg/clinical/presentation/config.go +++ b/pkg/clinical/presentation/config.go @@ -3,6 +3,7 @@ package presentation import ( "context" "fmt" + "log" "net/http" "time" @@ -15,7 +16,7 @@ import ( "github.com/savannahghi/clinical/pkg/clinical/application/extensions" "github.com/savannahghi/clinical/pkg/clinical/infrastructure" fhir "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare" - dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset" + "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset" "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/openconceptlab" pubsubmessaging "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/pubsub" "github.com/savannahghi/clinical/pkg/clinical/presentation/graph" @@ -23,6 +24,7 @@ import ( "github.com/savannahghi/clinical/pkg/clinical/presentation/rest" "github.com/savannahghi/clinical/pkg/clinical/usecases" "github.com/savannahghi/serverutils" + "google.golang.org/api/healthcare/v1" ) // ClinicalAllowedOrigins is a list of CORS origins allowed to interact with @@ -110,7 +112,17 @@ func Router(ctx context.Context) (*gin.Engine, error) { return nil, fmt.Errorf("unable to initialize pubsub client: %w", err) } - repo := dataset.NewFHIRRepository(ctx) + project := serverutils.MustGetEnvVar(serverutils.GoogleCloudProjectIDEnvVarName) + _ = serverutils.MustGetEnvVar("CLOUD_HEALTH_PUBSUB_TOPIC") + datasetID := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_ID") + datasetLocation := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_LOCATION") + fhirStoreID := serverutils.MustGetEnvVar("CLOUD_HEALTH_FHIRSTORE_ID") + hsv, err := healthcare.NewService(ctx) + if err != nil { + log.Panicf("unable to initialize new Google Cloud Healthcare Service: %s", err) + } + + repo := fhirdataset.NewFHIRRepository(ctx, hsv, project, datasetID, datasetLocation, fhirStoreID) fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL() diff --git a/pkg/clinical/usecases/config_test.go b/pkg/clinical/usecases/config_test.go index 6349131a..0457721b 100644 --- a/pkg/clinical/usecases/config_test.go +++ b/pkg/clinical/usecases/config_test.go @@ -15,7 +15,9 @@ import ( "github.com/savannahghi/clinical/pkg/clinical/presentation/interactor" "github.com/savannahghi/clinical/pkg/clinical/usecases" oclMock "github.com/savannahghi/clinical/pkg/clinical/usecases/ocl/mock" + "github.com/savannahghi/serverutils" log "github.com/sirupsen/logrus" + "google.golang.org/api/healthcare/v1" ) var ( @@ -76,8 +78,19 @@ func InitializeTestService(ctx context.Context, infra infrastructure.Infrastruct } func InitializeTestInfrastructure(ctx context.Context) (infrastructure.Infrastructure, error) { + project := serverutils.MustGetEnvVar(serverutils.GoogleCloudProjectIDEnvVarName) + _ = serverutils.MustGetEnvVar("CLOUD_HEALTH_PUBSUB_TOPIC") + datasetID := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_ID") + datasetLocation := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_LOCATION") + fhirStoreID := serverutils.MustGetEnvVar("CLOUD_HEALTH_FHIRSTORE_ID") + hsv, err := healthcare.NewService(ctx) + if err != nil { + log.Panicf("unable to initialize new Google Cloud Healthcare Service: %s", err) + } + + repo := dataset.NewFHIRRepository(ctx, hsv, project, datasetID, datasetLocation, fhirStoreID) + baseExtension := extensions.NewBaseExtensionImpl() - repo := dataset.NewFHIRRepository(ctx) fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL() diff --git a/pkg/clinical/usecases/ocl/ocl_test.go b/pkg/clinical/usecases/ocl/ocl_test.go index db4cfb6e..62681352 100644 --- a/pkg/clinical/usecases/ocl/ocl_test.go +++ b/pkg/clinical/usecases/ocl/ocl_test.go @@ -12,7 +12,9 @@ import ( dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset" "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/openconceptlab" "github.com/savannahghi/clinical/pkg/clinical/presentation/interactor" + "github.com/savannahghi/serverutils" "github.com/stretchr/testify/assert" + "google.golang.org/api/healthcare/v1" ) var ( @@ -48,8 +50,19 @@ func TestMain(m *testing.M) { } func InitializeTestService(ctx context.Context) (interactor.Usecases, error) { + project := serverutils.MustGetEnvVar(serverutils.GoogleCloudProjectIDEnvVarName) + _ = serverutils.MustGetEnvVar("CLOUD_HEALTH_PUBSUB_TOPIC") + datasetID := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_ID") + datasetLocation := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_LOCATION") + fhirStoreID := serverutils.MustGetEnvVar("CLOUD_HEALTH_FHIRSTORE_ID") + hsv, err := healthcare.NewService(ctx) + if err != nil { + log.Panicf("unable to initialize new Google Cloud Healthcare Service: %s", err) + } + + repo := dataset.NewFHIRRepository(ctx, hsv, project, datasetID, datasetLocation, fhirStoreID) + baseExtension := extensions.NewBaseExtensionImpl() - repo := dataset.NewFHIRRepository(ctx) fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL() @@ -62,8 +75,19 @@ func InitializeTestService(ctx context.Context) (interactor.Usecases, error) { } func InitializeTestInfrastructure(ctx context.Context) (infrastructure.Infrastructure, error) { + project := serverutils.MustGetEnvVar(serverutils.GoogleCloudProjectIDEnvVarName) + _ = serverutils.MustGetEnvVar("CLOUD_HEALTH_PUBSUB_TOPIC") + datasetID := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_ID") + datasetLocation := serverutils.MustGetEnvVar("CLOUD_HEALTH_DATASET_LOCATION") + fhirStoreID := serverutils.MustGetEnvVar("CLOUD_HEALTH_FHIRSTORE_ID") + hsv, err := healthcare.NewService(ctx) + if err != nil { + log.Panicf("unable to initialize new Google Cloud Healthcare Service: %s", err) + } + + repo := dataset.NewFHIRRepository(ctx, hsv, project, datasetID, datasetLocation, fhirStoreID) + baseExtension := extensions.NewBaseExtensionImpl() - repo := dataset.NewFHIRRepository(ctx) fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL()