Skip to content

Commit

Permalink
define platforms inline.
Browse files Browse the repository at this point in the history
Adding tests to ensure all catalog endpoints have a valid/known platform.
  • Loading branch information
AnalogJ committed Jan 13, 2024
1 parent 9b69e8d commit dc575b5
Show file tree
Hide file tree
Showing 51 changed files with 1,155 additions and 832 deletions.
56 changes: 44 additions & 12 deletions catalog/catalog_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package catalog
package catalog_test

import (
"fmt"
"github.com/fastenhealth/fasten-sources/catalog"
"github.com/fastenhealth/fasten-sources/definitions"
"github.com/fastenhealth/fasten-sources/pkg"
"github.com/fastenhealth/fasten-sources/pkg/models/catalog"
modelsCatalog "github.com/fastenhealth/fasten-sources/pkg/models/catalog"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
"testing"
)

func TestCatalog_GetBrands(t *testing.T) {
//setup
opts := catalog.CatalogQueryOptions{Id: "0000f30d-3987-4539-b743-5c263416a6cf"}
opts := modelsCatalog.CatalogQueryOptions{Id: "0000f30d-3987-4539-b743-5c263416a6cf"}

//test
brands, err := GetBrands(&opts)
brands, err := catalog.GetBrands(&opts)

//assert
require.NoError(t, err)
Expand All @@ -22,21 +25,21 @@ func TestCatalog_GetBrands(t *testing.T) {

func TestCatalog_GetBrands_WithInvalidId(t *testing.T) {
//setup
opts := catalog.CatalogQueryOptions{Id: "1"}
opts := modelsCatalog.CatalogQueryOptions{Id: "1"}

//test
_, err := GetBrands(&opts)
_, err := catalog.GetBrands(&opts)

//assert
require.EqualError(t, err, fmt.Sprintf("brand with id %s not found", opts.Id))
}

func TestCatalog_GetBrands_WithSandboxMode(t *testing.T) {
//setup
opts := catalog.CatalogQueryOptions{LighthouseEnvType: pkg.FastenLighthouseEnvSandbox}
opts := modelsCatalog.CatalogQueryOptions{LighthouseEnvType: pkg.FastenLighthouseEnvSandbox}

//test
brands, err := GetBrands(&opts)
brands, err := catalog.GetBrands(&opts)

//assert
require.NoError(t, err)
Expand All @@ -49,10 +52,10 @@ func TestCatalog_GetBrands_WithSandboxMode(t *testing.T) {

func TestCatalog_GetPortals_WithSandboxMode(t *testing.T) {
//setup
opts := catalog.CatalogQueryOptions{LighthouseEnvType: pkg.FastenLighthouseEnvSandbox}
opts := modelsCatalog.CatalogQueryOptions{LighthouseEnvType: pkg.FastenLighthouseEnvSandbox}

//test
portals, err := GetPortals(&opts)
portals, err := catalog.GetPortals(&opts)

//assert
require.NoError(t, err)
Expand All @@ -65,12 +68,41 @@ func TestCatalog_GetPortals_WithSandboxMode(t *testing.T) {

func TestCatalog_GetEndpoints_WithSandboxMode(t *testing.T) {
//setup
opts := catalog.CatalogQueryOptions{LighthouseEnvType: pkg.FastenLighthouseEnvSandbox}
opts := modelsCatalog.CatalogQueryOptions{LighthouseEnvType: pkg.FastenLighthouseEnvSandbox}

//test
endpoints, err := GetEndpoints(&opts)
endpoints, err := catalog.GetEndpoints(&opts)

//assert
require.NoError(t, err)
require.Len(t, endpoints, 20)
}

func TestCatalog_GetEndpoints_HaveKnownPlatformType(t *testing.T) {
//setup
opts := modelsCatalog.CatalogQueryOptions{}
endpoints, err := catalog.GetEndpoints(&opts)
require.NoError(t, err)

endpointPlatformTypes := map[pkg.PlatformType]bool{}
knownPlatformTypes := pkg.GetPlatformTypes()

//test
for _, endpoint := range endpoints {
endpointPlatformTypes[endpoint.GetPlatformType()] = true
}
foundAllEndpointPlatfromTypes := lo.EveryBy(lo.Keys(endpointPlatformTypes), func(platformType pkg.PlatformType) bool {
return lo.Contains(knownPlatformTypes, platformType)
})

for _, endpointPlatformType := range lo.Keys(endpointPlatformTypes) {
_, err := definitions.GetPlatformDefinition(endpointPlatformType, pkg.FastenLighthouseEnvProduction, map[pkg.PlatformType]string{})
require.NoError(t, err)
}

//assert

require.True(t, len(endpointPlatformTypes) >= 1)
require.True(t, foundAllEndpointPlatfromTypes)

}
114 changes: 57 additions & 57 deletions definitions/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,50 @@
package definitions

import (
"bytes"
"embed"
"fmt"
"github.com/fastenhealth/fasten-sources/catalog"
"github.com/fastenhealth/fasten-sources/definitions/internal/platform"
models "github.com/fastenhealth/fasten-sources/definitions/models"
pkg "github.com/fastenhealth/fasten-sources/pkg"
modelsCatalog "github.com/fastenhealth/fasten-sources/pkg/models/catalog"
"gopkg.in/yaml.v3"
)

//go:embed platform/*.yaml
var platformFs embed.FS

type GetSourceConfigOptions struct {
PlatformType pkg.SourceType
PlatformType pkg.PlatformType

EndpointId string
}

func GetSourceConfig(env pkg.FastenLighthouseEnvType, clientIdLookup map[pkg.SourceType]string, options GetSourceConfigOptions) (models.LighthouseSourceDefinition, error) {
func GetEndpointConfig(
env pkg.FastenLighthouseEnvType,
clientIdLookup map[pkg.PlatformType]string,
options GetSourceConfigOptions,
) (*models.LighthouseEndpointDefinition, error) {

if len(options.PlatformType) > 0 {
if options.PlatformType == pkg.SourceTypeManual {
return models.LighthouseSourceDefinition{PatientAccessEndpoint: &modelsCatalog.PatientAccessEndpoint{PlatformType: string(pkg.SourceTypeManual)}}, nil
} else if options.PlatformType == pkg.SourceTypeFasten {
return models.LighthouseSourceDefinition{PatientAccessEndpoint: &modelsCatalog.PatientAccessEndpoint{PlatformType: string(pkg.SourceTypeFasten)}}, nil
//only manual and fasten can be retrieved directly, all other Endpoint configs are retrieved via the catalog (endpointId -> platformType -> platformDefinition)
if options.PlatformType == pkg.PlatformTypeManual || options.PlatformType == pkg.PlatformTypeFasten {
platformDefinition, err := GetPlatformDefinition(options.PlatformType, env, clientIdLookup)
if err != nil {
return nil, fmt.Errorf("error retrieving platform definition (%s): %w", options.PlatformType, err)
}
return platformDefinition, nil
} else {
return models.LighthouseSourceDefinition{}, fmt.Errorf("unsupported platform type: %s", options.PlatformType)
return nil, fmt.Errorf("unsupported platform type: %s", options.PlatformType)
}
} else if len(options.EndpointId) > 0 {
endpointLookup, err := catalog.GetEndpoints(&modelsCatalog.CatalogQueryOptions{Id: options.EndpointId, LighthouseEnvType: env})
if err != nil {
return models.LighthouseSourceDefinition{}, fmt.Errorf("error retrieving endpoint (%s): %w", options.EndpointId, err)
return nil, fmt.Errorf("error retrieving endpoint (%s): %w", options.EndpointId, err)
}

if len(endpointLookup) > 1 {
return models.LighthouseSourceDefinition{}, fmt.Errorf("error unexpected endpoint lookup length (%d)", len(endpointLookup))
return nil, fmt.Errorf("error unexpected endpoint lookup length (%d)", len(endpointLookup))
}
endpoint := endpointLookup[options.EndpointId]

Expand All @@ -46,62 +58,50 @@ func GetSourceConfig(env pkg.FastenLighthouseEnvType, clientIdLookup map[pkg.Sou

platformDefinition, err := GetPlatformDefinition(platformType, env, clientIdLookup)
if err != nil {
return models.LighthouseSourceDefinition{}, fmt.Errorf("error retrieving platform definition (%s): %w", platformType, err)
return nil, fmt.Errorf("error retrieving platform definition (%s): %w", platformType, err)
}
//TODO: merge endpoint data into platform definition

platformDefinition.PatientAccessEndpoint = &endpoint
platformDefinition.Populate()
platformDefinition.Populate(&endpoint, env, clientIdLookup)

return platformDefinition, err
} else {
return models.LighthouseSourceDefinition{}, fmt.Errorf("PlatformType or EndpointID are required")
return nil, fmt.Errorf("PlatformType or EndpointID are required")
}

}

func GetPlatformDefinition(platformType pkg.SourceType, env pkg.FastenLighthouseEnvType, clientIdLookup map[pkg.SourceType]string) (models.LighthouseSourceDefinition, error) {
switch platformType {
// platform
case pkg.SourceTypeAdvancedmd:
return platform.GetSourceAdvancedmd(env, clientIdLookup)
case pkg.SourceTypeAetna:
return platform.GetSourceAetna(env, clientIdLookup)
case pkg.SourceTypeAllscripts:
return platform.GetSourceAllscripts(env, clientIdLookup)
case pkg.SourceTypeAthena:
return platform.GetSourceAthena(env, clientIdLookup)
case pkg.SourceTypeAnthem:
return platform.GetSourceAnthem(env, clientIdLookup)
case pkg.SourceTypeCareevolution:
return platform.GetSourceCareevolution(env, clientIdLookup)
case pkg.SourceTypeCerner:
return platform.GetSourceCerner(env, clientIdLookup)
case pkg.SourceTypeCigna:
return platform.GetSourceCigna(env, clientIdLookup)
case pkg.SourceTypeEclinicalworks:
return platform.GetSourceEclinicalworks(env, clientIdLookup)
case pkg.SourceTypeEdifecs:
return platform.GetSourceEdifecs(env, clientIdLookup)
case pkg.SourceTypeEpicLegacy:
return platform.GetSourceEpicLegacy(env, clientIdLookup)
case pkg.SourceTypeEpic:
return platform.GetSourceEpic(env, clientIdLookup)
case pkg.SourceTypeMeditech:
return platform.GetSourceMeditech(env, clientIdLookup)
case pkg.SourceTypeNextgen:
return platform.GetSourceNextgen(env, clientIdLookup)
case pkg.SourceTypeVahealth:
return platform.GetSourceVahealth(env, clientIdLookup)
case pkg.SourceTypeBcbsal:
return platform.GetSourceBcbsal(env, clientIdLookup)
case pkg.SourceTypeHumana:
return platform.GetSourceHumana(env, clientIdLookup)
case pkg.SourceTypeMedicare:
return platform.GetSourceMedicare(env, clientIdLookup)
case pkg.SourceTypeUnitedhealthcare:
return platform.GetSourceUnitedhealthcare(env, clientIdLookup)
default:
return models.LighthouseSourceDefinition{}, fmt.Errorf("unsupported platform type: %s", platformType)
func GetPlatformDefinition(platformType pkg.PlatformType, env pkg.FastenLighthouseEnvType, clientIdLookup map[pkg.PlatformType]string) (*models.LighthouseEndpointDefinition, error) {

if platformType == pkg.PlatformTypeManual {
return &models.LighthouseEndpointDefinition{PatientAccessEndpoint: &modelsCatalog.PatientAccessEndpoint{PlatformType: string(pkg.PlatformTypeManual)}}, nil
} else if platformType == pkg.PlatformTypeFasten {
return &models.LighthouseEndpointDefinition{PatientAccessEndpoint: &modelsCatalog.PatientAccessEndpoint{PlatformType: string(pkg.PlatformTypeFasten)}}, nil
}

platformDefinition, err := strictUnmarshalYaml(platformType)

if err != nil {
return nil, fmt.Errorf("error retrieving platform definition (%s): %w", platformType, err)
}

//TODO: set the platform environment specific customizations

return platformDefinition, nil
}

func strictUnmarshalYaml(platformType pkg.PlatformType) (*models.LighthouseEndpointDefinition, error) {
embeddedFilename := fmt.Sprintf("platform/%s.yaml", platformType)

fileBytes, err := platformFs.ReadFile(embeddedFilename)
if err != nil {
return nil, fmt.Errorf("failed to read embedded %s: %w", embeddedFilename, err)
}

var platformDefinition models.LighthouseEndpointDefinition

decoder := yaml.NewDecoder(bytes.NewReader(fileBytes))
decoder.KnownFields(true)
err = decoder.Decode(&platformDefinition)
return &platformDefinition, err
}
21 changes: 21 additions & 0 deletions definitions/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package definitions

import (
"github.com/fastenhealth/fasten-sources/pkg"
"github.com/stretchr/testify/require"
"testing"
)

func TestGetPlatformDefinition(t *testing.T) {
//setup
platformTypes := pkg.GetPlatformTypes()

//test
for _, platformType := range platformTypes {
_, err := GetPlatformDefinition(platformType, pkg.FastenLighthouseEnvSandbox, map[pkg.PlatformType]string{})
//assert
require.NoError(t, err)

}

}
32 changes: 0 additions & 32 deletions definitions/internal/platform/advancedmd.go

This file was deleted.

30 changes: 0 additions & 30 deletions definitions/internal/platform/aetna.go

This file was deleted.

38 changes: 0 additions & 38 deletions definitions/internal/platform/allscripts.go

This file was deleted.

Loading

0 comments on commit dc575b5

Please sign in to comment.