From 44c77a8100a56002ec060fe5bc406a73482f2036 Mon Sep 17 00:00:00 2001 From: Salaton Date: Sat, 28 Jan 2023 13:15:58 +0300 Subject: [PATCH] refactor: move `fhirdataset` into cloudhealthcare - Created a folder called `cloudhealthcare` in the infrastructure layer. The folder will hold all implementations that are specific to google cloud healthcare API. --- .github/workflows/ci.yml | 2 +- .../common/testutils/testhelpers.go | 6 +- .../{fhir => cloudhealthcare}/config_test.go | 6 +- .../{fhir => cloudhealthcare}/fhir.go | 35 +++++++- .../fhir_integration_test.go | 0 .../fhir_unit_test.go | 4 +- .../fhirdataset/dataset.go | 0 .../fhirdataset/dataset_test.go | 2 +- .../fhirdataset/dataset_unit_test.go | 0 .../fhirdataset/mock/dataset_mock.go | 0 .../{fhir => cloudhealthcare}/helpers.go | 0 .../mock/fhir_mock.go | 87 ++++++++++++++++++- pkg/clinical/infrastructure/infrastructure.go | 4 - .../services/pubsub/service_test.go | 6 +- pkg/clinical/presentation/config.go | 6 +- pkg/clinical/repository/repository.go | 9 ++ pkg/clinical/usecases/clinical/fhir.go | 6 +- .../usecases/clinical/fhir_unit_test.go | 77 ++++++++-------- pkg/clinical/usecases/clinical/patient.go | 14 +-- .../usecases/clinical/patient_unit_test.go | 25 ++---- pkg/clinical/usecases/config_test.go | 11 +-- pkg/clinical/usecases/ocl/ocl_test.go | 8 +- 22 files changed, 207 insertions(+), 101 deletions(-) rename pkg/clinical/infrastructure/datastore/{fhir => cloudhealthcare}/config_test.go (99%) rename pkg/clinical/infrastructure/datastore/{fhir => cloudhealthcare}/fhir.go (97%) rename pkg/clinical/infrastructure/datastore/{fhir => cloudhealthcare}/fhir_integration_test.go (100%) rename pkg/clinical/infrastructure/datastore/{fhir => cloudhealthcare}/fhir_unit_test.go (99%) rename pkg/clinical/infrastructure/datastore/{ => cloudhealthcare}/fhirdataset/dataset.go (100%) rename pkg/clinical/infrastructure/datastore/{ => cloudhealthcare}/fhirdataset/dataset_test.go (98%) rename pkg/clinical/infrastructure/datastore/{ => cloudhealthcare}/fhirdataset/dataset_unit_test.go (100%) rename pkg/clinical/infrastructure/datastore/{ => cloudhealthcare}/fhirdataset/mock/dataset_mock.go (100%) rename pkg/clinical/infrastructure/datastore/{fhir => cloudhealthcare}/helpers.go (100%) rename pkg/clinical/infrastructure/datastore/{fhir => cloudhealthcare}/mock/fhir_mock.go (91%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc1df415..6c4d956e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: - name: Install Go dependencies run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.37.1 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.1 go get -u github.com/kisielk/errcheck go get -u golang.org/x/lint/golint go install honnef.co/go/tools/cmd/staticcheck@2021.1.2 diff --git a/pkg/clinical/application/common/testutils/testhelpers.go b/pkg/clinical/application/common/testutils/testhelpers.go index ebf36be2..08877455 100644 --- a/pkg/clinical/application/common/testutils/testhelpers.go +++ b/pkg/clinical/application/common/testutils/testhelpers.go @@ -5,8 +5,8 @@ import ( "github.com/savannahghi/clinical/pkg/clinical/application/extensions" "github.com/savannahghi/clinical/pkg/clinical/infrastructure" - "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhir" - dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset" + 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/services/openconceptlab" "github.com/savannahghi/clinical/pkg/clinical/usecases" "github.com/savannahghi/firebasetools" @@ -21,7 +21,7 @@ func InitializeTestService(ctx context.Context) (usecases.Interactor, error) { fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL() - infrastructure := infrastructure.NewInfrastructureInteractor(baseExtension, repo, fhir, ocl) + infrastructure := infrastructure.NewInfrastructureInteractor(baseExtension, fhir, ocl) usecases := usecases.NewUsecasesInteractor(infrastructure) diff --git a/pkg/clinical/infrastructure/datastore/fhir/config_test.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/config_test.go similarity index 99% rename from pkg/clinical/infrastructure/datastore/fhir/config_test.go rename to pkg/clinical/infrastructure/datastore/cloudhealthcare/config_test.go index e2dfe1ac..0b7aebfd 100644 --- a/pkg/clinical/infrastructure/datastore/fhir/config_test.go +++ b/pkg/clinical/infrastructure/datastore/cloudhealthcare/config_test.go @@ -14,8 +14,8 @@ import ( "github.com/savannahghi/clinical/pkg/clinical/application/extensions" "github.com/savannahghi/clinical/pkg/clinical/domain" "github.com/savannahghi/clinical/pkg/clinical/infrastructure" - "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhir" - dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset" + 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/services/openconceptlab" "github.com/savannahghi/clinical/pkg/clinical/presentation/interactor" "github.com/savannahghi/converterandformatter" @@ -82,7 +82,7 @@ func InitializeTestInfrastructure(ctx context.Context) (infrastructure.Infrastru fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL() - return infrastructure.NewInfrastructureInteractor(baseExtension, repo, fhir, ocl), nil + return infrastructure.NewInfrastructureInteractor(baseExtension, fhir, ocl), nil } // func simplePatientRegistration() (*domain.SimplePatientRegistrationInput, error) { diff --git a/pkg/clinical/infrastructure/datastore/fhir/fhir.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go similarity index 97% rename from pkg/clinical/infrastructure/datastore/fhir/fhir.go rename to pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go index c581f89f..74a93d46 100644 --- a/pkg/clinical/infrastructure/datastore/fhir/fhir.go +++ b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go @@ -4,6 +4,8 @@ import ( "context" "encoding/json" "fmt" + "io" + "net/http" "net/url" "time" @@ -12,7 +14,7 @@ import ( "github.com/savannahghi/clinical/pkg/clinical/application/common/helpers" "github.com/savannahghi/clinical/pkg/clinical/application/utils" "github.com/savannahghi/clinical/pkg/clinical/domain" - dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset" + dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset" "github.com/savannahghi/clinical/pkg/clinical/repository" "github.com/savannahghi/converterandformatter" "github.com/savannahghi/scalarutils" @@ -1794,3 +1796,34 @@ func (fh *StoreImpl) SearchFHIRMedicationStatement(ctx context.Context, params m } return &output, nil } + +// CreateFHIRResource creates a FHIR resource +func (fh *StoreImpl) CreateFHIRResource(resourceType string, payload map[string]interface{}) ([]byte, error) { + return fh.Dataset.CreateFHIRResource(resourceType, payload) +} + +// PatchFHIRResource patches a FHIR resource +func (fh *StoreImpl) PatchFHIRResource(resourceType, fhirResourceID string, payload []map[string]interface{}) ([]byte, error) { + return fh.Dataset.PatchFHIRResource(resourceType, fhirResourceID, payload) +} + +// UpdateFHIRResource updates a FHIR resource +func (fh *StoreImpl) UpdateFHIRResource(resourceType, fhirResourceID string, payload map[string]interface{}) ([]byte, error) { + return fh.Dataset.UpdateFHIRResource(resourceType, fhirResourceID, payload) +} + +// POSTRequest is used to manually compose POST requests to the FHIR service +func (fh *StoreImpl) POSTRequest(resourceName string, path string, params url.Values, body io.Reader) ([]byte, error) { + return fh.Dataset.POSTRequest(resourceName, path, params, body) +} + +// GetFHIRResource gets a FHIR resource. +func (fh *StoreImpl) GetFHIRResource(resourceType, fhirResourceID string) ([]byte, error) { + return fh.Dataset.GetFHIRResource(resourceType, fhirResourceID) +} + +// FHIRHeaders composes suitable FHIR headers, with authentication and content +// type already set +func (fh *StoreImpl) FHIRHeaders() (http.Header, error) { + return fh.Dataset.FHIRHeaders() +} diff --git a/pkg/clinical/infrastructure/datastore/fhir/fhir_integration_test.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir_integration_test.go similarity index 100% rename from pkg/clinical/infrastructure/datastore/fhir/fhir_integration_test.go rename to pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir_integration_test.go diff --git a/pkg/clinical/infrastructure/datastore/fhir/fhir_unit_test.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir_unit_test.go similarity index 99% rename from pkg/clinical/infrastructure/datastore/fhir/fhir_unit_test.go rename to pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir_unit_test.go index ec98ad28..e6dceb13 100644 --- a/pkg/clinical/infrastructure/datastore/fhir/fhir_unit_test.go +++ b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir_unit_test.go @@ -10,11 +10,11 @@ import ( "github.com/brianvoe/gofakeit" "github.com/google/uuid" "github.com/savannahghi/clinical/pkg/clinical/domain" - FHIR "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhir" + FHIR "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare" "github.com/savannahghi/scalarutils" "github.com/segmentio/ksuid" - fakeDataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset/mock" + fakeDataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/mock" ) func TestStoreImpl_CreateEpisodeOfCare_Unittest(t *testing.T) { diff --git a/pkg/clinical/infrastructure/datastore/fhirdataset/dataset.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset.go similarity index 100% rename from pkg/clinical/infrastructure/datastore/fhirdataset/dataset.go rename to pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset.go diff --git a/pkg/clinical/infrastructure/datastore/fhirdataset/dataset_test.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset_test.go similarity index 98% rename from pkg/clinical/infrastructure/datastore/fhirdataset/dataset_test.go rename to pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset_test.go index 3d2b7789..c6841598 100644 --- a/pkg/clinical/infrastructure/datastore/fhirdataset/dataset_test.go +++ b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset" + dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset" "github.com/tj/assert" ) diff --git a/pkg/clinical/infrastructure/datastore/fhirdataset/dataset_unit_test.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset_unit_test.go similarity index 100% rename from pkg/clinical/infrastructure/datastore/fhirdataset/dataset_unit_test.go rename to pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/dataset_unit_test.go diff --git a/pkg/clinical/infrastructure/datastore/fhirdataset/mock/dataset_mock.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/mock/dataset_mock.go similarity index 100% rename from pkg/clinical/infrastructure/datastore/fhirdataset/mock/dataset_mock.go rename to pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/mock/dataset_mock.go diff --git a/pkg/clinical/infrastructure/datastore/fhir/helpers.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/helpers.go similarity index 100% rename from pkg/clinical/infrastructure/datastore/fhir/helpers.go rename to pkg/clinical/infrastructure/datastore/cloudhealthcare/helpers.go diff --git a/pkg/clinical/infrastructure/datastore/fhir/mock/fhir_mock.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/mock/fhir_mock.go similarity index 91% rename from pkg/clinical/infrastructure/datastore/fhir/mock/fhir_mock.go rename to pkg/clinical/infrastructure/datastore/cloudhealthcare/mock/fhir_mock.go index 576d6837..d81498f8 100644 --- a/pkg/clinical/infrastructure/datastore/fhir/mock/fhir_mock.go +++ b/pkg/clinical/infrastructure/datastore/cloudhealthcare/mock/fhir_mock.go @@ -2,6 +2,7 @@ package mock import ( "context" + "encoding/json" "fmt" "io" "net/http" @@ -67,6 +68,11 @@ type FHIRMock struct { MockSearchFHIRMedicationStatementFn func(ctx context.Context, params map[string]interface{}) (*domain.FHIRMedicationStatementRelayConnection, error) MockFHIRHeadersFn func() (http.Header, error) MockGetBearerTokenFn func() (string, error) + + MockCreateFHIRResourceFn func(resourceType string, payload map[string]interface{}) ([]byte, error) + MockPatchFHIRResourceFn func(resourceType, fhirResourceID string, payload []map[string]interface{}) ([]byte, error) + MockUpdateFHIRResourceFn func(resourceType, fhirResourceID string, payload map[string]interface{}) ([]byte, error) + MockGetFHIRResourceFn func(resourceType, fhirResourceID string) ([]byte, error) } // NewFHIRMock initializes a new instance of FHIR mock @@ -145,7 +151,17 @@ func NewFHIRMock() *FHIRMock { return &domain.FHIROrganizationRelayConnection{}, nil }, MockPOSTRequestFn: func(resourceName string, path string, params url.Values, body io.Reader) ([]byte, error) { - return []byte("m"), nil + m := map[string]string{ + "resourceType": "Bundle", + "type": "searchset", + "total": "10", + "link": "test", + } + bs, err := json.Marshal(m) + if err != nil { + return nil, fmt.Errorf("unable to marshal map to JSON: %w", err) + } + return bs, nil }, MockSearchEpisodesByParamFn: func(ctx context.Context, searchParams url.Values) ([]*domain.FHIREpisodeOfCare, error) { return []*domain.FHIREpisodeOfCare{}, nil @@ -386,6 +402,55 @@ func NewFHIRMock() *FHIRMock { MockGetBearerTokenFn: func() (string, error) { return fmt.Sprintf("Bearer %s", uuid.NewString()), nil }, + MockCreateFHIRResourceFn: func(resourceType string, payload map[string]interface{}) ([]byte, error) { + m := map[string]interface{}{ + "key": "value", + } + bs, err := json.Marshal(m) + if err != nil { + return nil, fmt.Errorf("unable to marshal map to JSON: %w", err) + } + return bs, nil + }, + MockPatchFHIRResourceFn: func(resourceType, fhirResourceID string, payload []map[string]interface{}) ([]byte, error) { + m := map[string]interface{}{ + "key": "value", + } + bs, err := json.Marshal(m) + if err != nil { + return nil, fmt.Errorf("unable to marshal map to JSON: %w", err) + } + return bs, nil + }, + MockUpdateFHIRResourceFn: func(resourceType, fhirResourceID string, payload map[string]interface{}) ([]byte, error) { + m := map[string]interface{}{ + "key": "value", + } + bs, err := json.Marshal(m) + if err != nil { + return nil, fmt.Errorf("unable to marshal map to JSON: %w", err) + } + return bs, nil + }, + MockGetFHIRResourceFn: func(resourceType, fhirResourceID string) ([]byte, error) { + n := map[string]interface{}{"given": []string{"John"}, "family": []string{"Doe"}} + p := map[string]interface{}{ + "resourceType": "Patient/", + "id": "test-UUID", + "name": []map[string]interface{}{n}, + } + m := map[string]interface{}{ + "resourceType": "Patient/", + "status": "active", + "id": "test-UUID", + "patientRecord": p, + } + bs, err := json.Marshal(m) + if err != nil { + return nil, fmt.Errorf("unable to marshal map to JSON: %w", err) + } + return bs, nil + }, } } @@ -629,3 +694,23 @@ func (fh *FHIRMock) CreateFHIRMedication(ctx context.Context, input domain.FHIRM func (fh *FHIRMock) FHIRHeaders() (http.Header, error) { return fh.MockFHIRHeadersFn() } + +// CreateFHIRResource mocks the implementation for creating a fhir resource +func (fh *FHIRMock) CreateFHIRResource(resourceType string, payload map[string]interface{}) ([]byte, error) { + return fh.MockCreateFHIRResourceFn(resourceType, payload) +} + +// PatchFHIRResource mocks the implementation for patching a fhir resource +func (fh *FHIRMock) PatchFHIRResource(resourceType, fhirResourceID string, payload []map[string]interface{}) ([]byte, error) { + return fh.MockPatchFHIRResourceFn(resourceType, fhirResourceID, payload) +} + +// UpdateFHIRResource mocks the implementation for updating a FHIR resource +func (fh *FHIRMock) UpdateFHIRResource(resourceType, fhirResourceID string, payload map[string]interface{}) ([]byte, error) { + return fh.MockUpdateFHIRResourceFn(resourceType, fhirResourceID, payload) +} + +// GetFHIRResource mocks the implementation of getting a FHIR resource +func (fh *FHIRMock) GetFHIRResource(resourceType, fhirResourceID string) ([]byte, error) { + return fh.MockGetFHIRResourceFn(resourceType, fhirResourceID) +} diff --git a/pkg/clinical/infrastructure/infrastructure.go b/pkg/clinical/infrastructure/infrastructure.go index 82c683ef..1f166462 100644 --- a/pkg/clinical/infrastructure/infrastructure.go +++ b/pkg/clinical/infrastructure/infrastructure.go @@ -3,7 +3,6 @@ package infrastructure import ( "github.com/savannahghi/clinical/pkg/clinical/application/common" "github.com/savannahghi/clinical/pkg/clinical/application/extensions" - dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset" "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/mycarehub" "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/openconceptlab" "github.com/savannahghi/clinical/pkg/clinical/repository" @@ -11,7 +10,6 @@ import ( // Infrastructure ... type Infrastructure struct { - FHIRRepo dataset.FHIRRepository FHIR repository.FHIR OpenConceptLab openconceptlab.ServiceOCL BaseExtension extensions.BaseExtension @@ -21,7 +19,6 @@ type Infrastructure struct { // NewInfrastructureInteractor initializes a new Infrastructure func NewInfrastructureInteractor( ext extensions.BaseExtension, - fhirRepository dataset.FHIRRepository, fhir repository.FHIR, openconceptlab openconceptlab.ServiceOCL, ) Infrastructure { @@ -29,7 +26,6 @@ func NewInfrastructureInteractor( mycarehub := mycarehub.NewServiceMyCareHub(myCareHubClient, ext) return Infrastructure{ - fhirRepository, fhir, openconceptlab, ext, diff --git a/pkg/clinical/infrastructure/services/pubsub/service_test.go b/pkg/clinical/infrastructure/services/pubsub/service_test.go index 571dee8c..04f3fe2e 100644 --- a/pkg/clinical/infrastructure/services/pubsub/service_test.go +++ b/pkg/clinical/infrastructure/services/pubsub/service_test.go @@ -9,8 +9,8 @@ import ( "cloud.google.com/go/pubsub" "github.com/savannahghi/clinical/pkg/clinical/application/extensions" "github.com/savannahghi/clinical/pkg/clinical/infrastructure" - fhir "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhir" - dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset" + 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/services/openconceptlab" pubsubmessaging "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/pubsub" "github.com/savannahghi/clinical/pkg/clinical/usecases" @@ -41,7 +41,7 @@ func InitializeTestPubSub(t *testing.T) (*pubsubmessaging.ServicePubSubMessaging fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL() - infrastructure := infrastructure.NewInfrastructureInteractor(baseExtension, repo, fhir, ocl) + infrastructure := infrastructure.NewInfrastructureInteractor(baseExtension, fhir, ocl) usecases := usecases.NewUsecasesInteractor(infrastructure) oclUseCase := usecases.UseCasesOCL pubSub, err := pubsubmessaging.NewServicePubSubMessaging( diff --git a/pkg/clinical/presentation/config.go b/pkg/clinical/presentation/config.go index c159b715..7e018729 100644 --- a/pkg/clinical/presentation/config.go +++ b/pkg/clinical/presentation/config.go @@ -16,8 +16,8 @@ import ( "github.com/savannahghi/authutils" "github.com/savannahghi/clinical/pkg/clinical/application/extensions" "github.com/savannahghi/clinical/pkg/clinical/infrastructure" - fhir "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhir" - dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset" + 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/services/openconceptlab" pubsubmessaging "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/pubsub" "github.com/savannahghi/clinical/pkg/clinical/presentation/graph" @@ -120,7 +120,7 @@ func Router(ctx context.Context) (*mux.Router, error) { fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL() - infrastructure := infrastructure.NewInfrastructureInteractor(baseExtension, repo, fhir, ocl) + infrastructure := infrastructure.NewInfrastructureInteractor(baseExtension, fhir, ocl) usecases := usecases.NewUsecasesInteractor(infrastructure) h := rest.NewPresentationHandlers(usecases) diff --git a/pkg/clinical/repository/repository.go b/pkg/clinical/repository/repository.go index 1a0c91a0..8b9970f8 100644 --- a/pkg/clinical/repository/repository.go +++ b/pkg/clinical/repository/repository.go @@ -2,6 +2,8 @@ package repository import ( "context" + "io" + "net/http" "net/url" "github.com/savannahghi/clinical/pkg/clinical/domain" @@ -60,4 +62,11 @@ type FHIR interface { CreateFHIRMedicationStatement(ctx context.Context, input domain.FHIRMedicationStatementInput) (*domain.FHIRMedicationStatementRelayPayload, error) CreateFHIRMedication(ctx context.Context, input domain.FHIRMedicationInput) (*domain.FHIRMedicationRelayPayload, error) SearchFHIRMedicationStatement(ctx context.Context, params map[string]interface{}) (*domain.FHIRMedicationStatementRelayConnection, error) + + CreateFHIRResource(resourceType string, payload map[string]interface{}) ([]byte, error) + PatchFHIRResource(resourceType, fhirResourceID string, payload []map[string]interface{}) ([]byte, error) + UpdateFHIRResource(resourceType, fhirResourceID string, payload map[string]interface{}) ([]byte, error) + POSTRequest(resourceName string, path string, params url.Values, body io.Reader) ([]byte, error) + GetFHIRResource(resourceType, fhirResourceID string) ([]byte, error) + FHIRHeaders() (http.Header, error) } diff --git a/pkg/clinical/usecases/clinical/fhir.go b/pkg/clinical/usecases/clinical/fhir.go index 3e26614b..14aef1e3 100644 --- a/pkg/clinical/usecases/clinical/fhir.go +++ b/pkg/clinical/usecases/clinical/fhir.go @@ -221,7 +221,7 @@ func (c *UseCasesClinicalImpl) SearchEpisodesByParam(ctx context.Context, search // - `path` is a sub-path e.g `_search` under a resource // - `params` should be query params, sent as `url.Values` func (c *UseCasesClinicalImpl) POSTRequest(resourceName string, path string, params url.Values, body io.Reader) ([]byte, error) { - return c.infrastructure.FHIRRepo.POSTRequest(resourceName, path, params, body) + return c.infrastructure.FHIR.POSTRequest(resourceName, path, params, body) } // OpenEpisodes returns the IDs of a patient's open episodes @@ -241,7 +241,7 @@ func (c *UseCasesClinicalImpl) HasOpenEpisode( // FHIRHeaders composes suitable FHIR headers, with authentication and content // type already set func (c *UseCasesClinicalImpl) FHIRHeaders() (http.Header, error) { - return c.infrastructure.FHIRRepo.FHIRHeaders() + return c.infrastructure.FHIR.FHIRHeaders() } // CreateFHIREncounter creates a FHIREncounter instance @@ -334,7 +334,7 @@ func (c *UseCasesClinicalImpl) UpgradeEpisode(ctx context.Context, input domain. return nil, fmt.Errorf("unable to turn episode of care input into a map: %v", err) } - _, err = c.infrastructure.FHIRRepo.UpdateFHIRResource( + _, err = c.infrastructure.FHIR.UpdateFHIRResource( "EpisodeOfCare", *episode.ID, payload) if err != nil { utils.ReportErrorToSentry(err) diff --git a/pkg/clinical/usecases/clinical/fhir_unit_test.go b/pkg/clinical/usecases/clinical/fhir_unit_test.go index 26890760..728512d1 100644 --- a/pkg/clinical/usecases/clinical/fhir_unit_test.go +++ b/pkg/clinical/usecases/clinical/fhir_unit_test.go @@ -11,8 +11,7 @@ import ( fakeExtMock "github.com/savannahghi/clinical/pkg/clinical/application/extensions/mock" "github.com/savannahghi/clinical/pkg/clinical/domain" "github.com/savannahghi/clinical/pkg/clinical/infrastructure" - fakeFHIRMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhir/mock" - fakeDatasetMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset/mock" + fakeFHIRMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/mock" fakeOCLMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/openconceptlab/mock" clinicalUsecase "github.com/savannahghi/clinical/pkg/clinical/usecases/clinical" "github.com/savannahghi/scalarutils" @@ -23,11 +22,10 @@ func TestUsecaseImpl_CreateEpisodeOfCare_Unittest(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) UUID := uuid.New().String() @@ -106,11 +104,10 @@ func TestUsecaseStoreImpl_CreateFHIRCondition(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) ID := uuid.New().String() @@ -213,11 +210,11 @@ func TestUsecaseStoreImpl_CreateFHIROrganization_Unittest(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) ID := ksuid.New().String() @@ -292,11 +289,11 @@ func TestUsecaseStoreImpl_FindOrganizationByID_Unittest(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) type args struct { @@ -347,11 +344,11 @@ func TestUsecaseStoreImpl_SearchEpisodesByParam(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) type args struct { @@ -400,11 +397,11 @@ func TestUsecaseStoreImpl_SearchEpisodesByParam(t *testing.T) { func TestUsecaseStoreImpl_SearchFHIREpisodeOfCare(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) type args struct { @@ -456,11 +453,11 @@ func TestUsecaseStoreImpl_SearchFHIREpisodeOfCare(t *testing.T) { func TestUsecaseStoreImpl_OpenEpisodes(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) patientReference := fmt.Sprintf("Patient/%s", ksuid.New().String()) @@ -510,11 +507,11 @@ func TestUsecaseStoreImpl_OpenEpisodes(t *testing.T) { func TestUsecaseStoreImpl_HasOpenEpisode(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) UUID := uuid.New().String() @@ -572,11 +569,11 @@ func TestUsecaseStoreImpl_HasOpenEpisode(t *testing.T) { func TestUsecaseStoreImpl_CreateFHIREncounter(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) input := domain.FHIREncounterInput{} @@ -627,11 +624,11 @@ func TestUsecaseStoreImpl_CreateFHIREncounter(t *testing.T) { func TestUsecaseStoreImpl_GetFHIREpisodeOfCare(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) id := ksuid.New().String() @@ -682,11 +679,11 @@ func TestUsecaseStoreImpl_GetFHIREpisodeOfCare(t *testing.T) { func TestClinicalUseCaseImpl_StartEncounter(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) episodeID := uuid.New().String() @@ -729,11 +726,11 @@ func TestClinicalUseCaseImpl_StartEncounter(t *testing.T) { func TestUsecaseStoreImpl_GetFHIREncounter(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) type args struct { @@ -781,11 +778,11 @@ func TestUsecaseStoreImpl_GetFHIREncounter(t *testing.T) { func TestUsecaseStoreImpl_CreateFHIRServiceRequest(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) UUID := uuid.New().String() @@ -836,11 +833,11 @@ func TestUsecaseStoreImpl_CreateFHIRServiceRequest(t *testing.T) { func TestUsecaseStoreImpl_CreateFHIRAllergyIntolerance(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) UUID := uuid.New().String() @@ -891,11 +888,11 @@ func TestUsecaseStoreImpl_CreateFHIRAllergyIntolerance(t *testing.T) { func TestUsecaseStoreImpl_UpdateFHIRAllergyIntolerance(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) UUID := uuid.New().String() @@ -950,11 +947,11 @@ func TestUsecaseStoreImpl_UpdateFHIRAllergyIntolerance(t *testing.T) { func TestUsecaseStoreImpl_SearchFHIRComposition(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) params := map[string]interface{}{"test": "123"} @@ -1006,11 +1003,11 @@ func TestUsecaseStoreImpl_SearchFHIRComposition(t *testing.T) { func TestUsecaseStoreImpl_CreateFHIRComposition(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) input := domain.FHIRCompositionInput{} @@ -1062,11 +1059,11 @@ func TestUsecaseStoreImpl_CreateFHIRComposition(t *testing.T) { func TestUsecaseStoreImpl_UpdateFHIRComposition(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) UUID := uuid.New().String() @@ -1121,11 +1118,11 @@ func TestUsecaseStoreImpl_UpdateFHIRComposition(t *testing.T) { func TestUsecaseStoreImpl_DeleteFHIRComposition(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) id := ksuid.New().String() diff --git a/pkg/clinical/usecases/clinical/patient.go b/pkg/clinical/usecases/clinical/patient.go index ee9a1ac8..e79d7a67 100644 --- a/pkg/clinical/usecases/clinical/patient.go +++ b/pkg/clinical/usecases/clinical/patient.go @@ -332,7 +332,7 @@ func (c *UseCasesClinicalImpl) PatientSearch(ctx context.Context, search string) params := url.Values{} params.Add("_content", search) // entire doc - bs, err := c.infrastructure.FHIRRepo.POSTRequest("Patient", "_search", params, nil) + bs, err := c.infrastructure.FHIR.POSTRequest("Patient", "_search", params, nil) if err != nil { utils.ReportErrorToSentry(err) return nil, fmt.Errorf("unable to search: %v", err) @@ -601,7 +601,7 @@ func (c *UseCasesClinicalImpl) CreatePatient(ctx context.Context, input domain.F return nil, fmt.Errorf("unable to turn patient input into a map: %v", err) } - data, err := c.infrastructure.FHIRRepo.CreateFHIRResource("Patient", payload) + data, err := c.infrastructure.FHIR.CreateFHIRResource("Patient", payload) if err != nil { utils.ReportErrorToSentry(err) return nil, fmt.Errorf("unable to create/update patient resource: %v", err) @@ -628,7 +628,7 @@ func (c *UseCasesClinicalImpl) FindPatientByID(ctx context.Context, id string) ( return nil, fmt.Errorf("patient ID cannot be empty") } - data, err := c.infrastructure.FHIRRepo.GetFHIRResource("Patient", id) + data, err := c.infrastructure.FHIR.GetFHIRResource("Patient", id) if err != nil { return nil, fmt.Errorf( "unable to get patient with ID %s, err: %v", id, err) @@ -754,7 +754,7 @@ func (c *UseCasesClinicalImpl) UpdatePatient(ctx context.Context, input domain.S patches = append(patches, patch) } - data, err := c.infrastructure.FHIRRepo.PatchFHIRResource("Patient", input.ID, patches) + data, err := c.infrastructure.FHIR.PatchFHIRResource("Patient", input.ID, patches) if err != nil { utils.ReportErrorToSentry(err) return nil, fmt.Errorf("UpdatePatient: %v", err) @@ -856,7 +856,7 @@ func (c *UseCasesClinicalImpl) AddNextOfKin(ctx context.Context, input domain.Si }, } - data, err := c.infrastructure.FHIRRepo.PatchFHIRResource( + data, err := c.infrastructure.FHIR.PatchFHIRResource( "Patient", input.PatientID, patches) if err != nil { utils.ReportErrorToSentry(err) @@ -940,7 +940,7 @@ func (c *UseCasesClinicalImpl) AddNHIF(ctx context.Context, input *domain.Simple }, } - data, err := c.infrastructure.FHIRRepo.PatchFHIRResource( + data, err := c.infrastructure.FHIR.PatchFHIRResource( "Patient", input.PatientID, patches) if err != nil { utils.ReportErrorToSentry(err) @@ -1017,7 +1017,7 @@ func (c *UseCasesClinicalImpl) CreateUpdatePatientExtraInformation( return false, fmt.Errorf("an error occurred: %v", err) } - _, err = c.infrastructure.FHIRRepo.PatchFHIRResource("Patient", input.PatientID, patches) + _, err = c.infrastructure.FHIR.PatchFHIRResource("Patient", input.PatientID, patches) if err != nil { utils.ReportErrorToSentry(err) return false, fmt.Errorf("UpdatePatient: %v", err) diff --git a/pkg/clinical/usecases/clinical/patient_unit_test.go b/pkg/clinical/usecases/clinical/patient_unit_test.go index eef3d5ca..14ad218c 100644 --- a/pkg/clinical/usecases/clinical/patient_unit_test.go +++ b/pkg/clinical/usecases/clinical/patient_unit_test.go @@ -10,8 +10,7 @@ import ( fakeExtMock "github.com/savannahghi/clinical/pkg/clinical/application/extensions/mock" "github.com/savannahghi/clinical/pkg/clinical/domain" "github.com/savannahghi/clinical/pkg/clinical/infrastructure" - fakeFHIRMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhir/mock" - fakeDatasetMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset/mock" + fakeFHIRMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/mock" fakeOCLMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/openconceptlab/mock" clinicalUsecase "github.com/savannahghi/clinical/pkg/clinical/usecases/clinical" "github.com/savannahghi/interserviceclient" @@ -23,11 +22,10 @@ func TestClinicalUseCaseImpl_ProblemSummary_Unittest(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) type args struct { @@ -77,11 +75,10 @@ func TestClinicalUseCaseImpl_VisitSummary_Unittest(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) type args struct { @@ -148,11 +145,10 @@ func TestClinicalUseCaseImpl_PatientSearch_Unittest(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) searchPatient := "Test user" @@ -186,7 +182,7 @@ func TestClinicalUseCaseImpl_PatientSearch_Unittest(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if tt.name == "Sad case" { - FakefhirRepository.MockPOSTRequestFn = func(resourceName, path string, params url.Values, body io.Reader) ([]byte, error) { + Fakefhir.MockPOSTRequestFn = func(resourceName, path string, params url.Values, body io.Reader) ([]byte, error) { return nil, fmt.Errorf("error") } } @@ -204,11 +200,10 @@ func TestClinicalUseCaseImpl_ContactsToContactPointInput_Unittest(t *testing.T) ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) type args struct { @@ -254,11 +249,10 @@ func TestClinicalUseCaseImpl_CreatePatient_Unittest(t *testing.T) { ctx := context.Background() FakeExt := fakeExtMock.NewFakeBaseExtensionMock() - FakefhirRepository := fakeDatasetMock.NewFakeFHIRRepositoryMock() Fakefhir := fakeFHIRMock.NewFHIRMock() Fakeopenconceptlab := fakeOCLMock.NewFakeOCLMock() - n := infrastructure.NewInfrastructureInteractor(FakeExt, FakefhirRepository, Fakefhir, Fakeopenconceptlab) + n := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, Fakeopenconceptlab) m := clinicalUsecase.NewUseCasesClinicalImpl(n) ID := ksuid.New().String() @@ -296,11 +290,6 @@ func TestClinicalUseCaseImpl_CreatePatient_Unittest(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if tt.name == "Sad case" { - FakefhirRepository.MockCreateFHIRResourceFn = func(resourceType string, payload map[string]interface{}) ([]byte, error) { - return nil, fmt.Errorf("error") - } - } _, err := m.CreatePatient(tt.args.ctx, tt.args.input) if (err != nil) != tt.wantErr { t.Errorf("ClinicalUseCaseImpl.CreatePatient() error = %v, wantErr %v", err, tt.wantErr) diff --git a/pkg/clinical/usecases/config_test.go b/pkg/clinical/usecases/config_test.go index 2f774042..99a25fa0 100644 --- a/pkg/clinical/usecases/config_test.go +++ b/pkg/clinical/usecases/config_test.go @@ -8,9 +8,9 @@ import ( "github.com/savannahghi/clinical/pkg/clinical/application/extensions" extensionMock "github.com/savannahghi/clinical/pkg/clinical/application/extensions/mock" "github.com/savannahghi/clinical/pkg/clinical/infrastructure" - "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhir" - dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset" - fhirRepoMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset/mock" + fhir "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare" + dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset" + fhirRepoMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/fhirdataset/mock" "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/openconceptlab" "github.com/savannahghi/clinical/pkg/clinical/presentation/interactor" "github.com/savannahghi/clinical/pkg/clinical/usecases" @@ -84,17 +84,14 @@ func InitializeTestInfrastructure(ctx context.Context) (infrastructure.Infrastru fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL() - return infrastructure.NewInfrastructureInteractor(baseExtension, repo, fhir, ocl), nil + return infrastructure.NewInfrastructureInteractor(baseExtension, fhir, ocl), nil } func InitializeFakeTestlInteractor(ctx context.Context) (usecases.Interactor, error) { - - var fhirRepo dataset.FHIRRepository = &FHIRRepoMock var ocl ocl.UseCasesOCL = &fakeOCL var baseExt extensions.BaseExtension = &fakeBaseExtension infra := func() infrastructure.Infrastructure { return infrastructure.Infrastructure{ - FHIRRepo: fhirRepo, OpenConceptLab: ocl, BaseExtension: baseExt, } diff --git a/pkg/clinical/usecases/ocl/ocl_test.go b/pkg/clinical/usecases/ocl/ocl_test.go index e05f8713..6c9bbe76 100644 --- a/pkg/clinical/usecases/ocl/ocl_test.go +++ b/pkg/clinical/usecases/ocl/ocl_test.go @@ -8,8 +8,8 @@ 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/fhir" - dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset" + 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/services/openconceptlab" "github.com/savannahghi/clinical/pkg/clinical/presentation/interactor" "github.com/savannahghi/firebasetools" @@ -55,7 +55,7 @@ func InitializeTestService(ctx context.Context) (interactor.Usecases, error) { fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL() - infrastructure := infrastructure.NewInfrastructureInteractor(baseExtension, repo, fhir, ocl) + infrastructure := infrastructure.NewInfrastructureInteractor(baseExtension, fhir, ocl) usecases := interactor.NewUsecasesInteractor( infrastructure, @@ -70,7 +70,7 @@ func InitializeTestInfrastructure(ctx context.Context) (infrastructure.Infrastru fhir := fhir.NewFHIRStoreImpl(repo) ocl := openconceptlab.NewServiceOCL() - return infrastructure.NewInfrastructureInteractor(baseExtension, repo, fhir, ocl), nil + return infrastructure.NewInfrastructureInteractor(baseExtension, fhir, ocl), nil } func TestUseCasesImpl_ListConcepts(t *testing.T) {