renamed usages of providerId to sourceType
This commit is contained in:
parent
201b5d5df3
commit
360af5adee
|
@ -0,0 +1,14 @@
|
||||||
|
package pkg
|
||||||
|
|
||||||
|
//go:generate stringer -type=SourceType
|
||||||
|
// SourceType contains all the various medical, insurance, health care providers which Fasten can communicate with
|
||||||
|
type SourceType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
SourceTypeAetna SourceType = "aetna"
|
||||||
|
SourceTypeAnthem SourceType = "anthem"
|
||||||
|
SourceTypeCigna SourceType = "cigna"
|
||||||
|
SourceTypeHumana SourceType = "humana"
|
||||||
|
SourceTypeKaiser SourceType = "kaiser"
|
||||||
|
SourceTypeUnitedHealthcare SourceType = "unitedhealthcare"
|
||||||
|
)
|
|
@ -148,37 +148,37 @@ func (sr *sqliteRepository) ListResources(ctx context.Context, sourceResourceTyp
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// ProviderCredentials
|
// Source
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
func (sr *sqliteRepository) CreateSource(ctx context.Context, providerCreds *models.Source) error {
|
func (sr *sqliteRepository) CreateSource(ctx context.Context, sourceCreds *models.Source) error {
|
||||||
providerCreds.UserID = sr.GetCurrentUser(ctx).ID
|
sourceCreds.UserID = sr.GetCurrentUser(ctx).ID
|
||||||
|
|
||||||
if sr.gormClient.WithContext(ctx).Model(&providerCreds).
|
if sr.gormClient.WithContext(ctx).Model(&sourceCreds).
|
||||||
Where(models.Source{
|
Where(models.Source{
|
||||||
UserID: providerCreds.UserID,
|
UserID: sourceCreds.UserID,
|
||||||
ProviderId: providerCreds.ProviderId,
|
SourceType: sourceCreds.SourceType,
|
||||||
PatientId: providerCreds.PatientId}).Updates(&providerCreds).RowsAffected == 0 {
|
PatientId: sourceCreds.PatientId}).Updates(&sourceCreds).RowsAffected == 0 {
|
||||||
return sr.gormClient.WithContext(ctx).Create(&providerCreds).Error
|
return sr.gormClient.WithContext(ctx).Create(&sourceCreds).Error
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sr *sqliteRepository) GetSources(ctx context.Context) ([]models.Source, error) {
|
func (sr *sqliteRepository) GetSources(ctx context.Context) ([]models.Source, error) {
|
||||||
|
|
||||||
var providerCredentials []models.Source
|
var sourceCreds []models.Source
|
||||||
results := sr.gormClient.WithContext(ctx).
|
results := sr.gormClient.WithContext(ctx).
|
||||||
Where(models.Source{UserID: sr.GetCurrentUser(ctx).ID}).
|
Where(models.Source{UserID: sr.GetCurrentUser(ctx).ID}).
|
||||||
Find(&providerCredentials)
|
Find(&sourceCreds)
|
||||||
|
|
||||||
return providerCredentials, results.Error
|
return sourceCreds, results.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (sr *sqliteRepository) GetSource(ctx context.Context, providerId string) (models.Source, error) {
|
//func (sr *sqliteRepository) GetSource(ctx context.Context, providerId string) (models.Source, error) {
|
||||||
//
|
//
|
||||||
// var providerCredentials models.Source
|
// var providerCredentials models.Source
|
||||||
// results := sr.gormClient.WithContext(ctx).
|
// results := sr.gormClient.WithContext(ctx).
|
||||||
// Where(models.Source{UserID: sr.GetCurrentUser().ID, ProviderId: providerId}).
|
// Where(models.Source{UserID: sr.GetCurrentUser().ID, SourceType: providerId}).
|
||||||
// Find(&providerCredentials)
|
// Find(&providerCredentials)
|
||||||
//
|
//
|
||||||
// return providerCredential, results.Error
|
// return providerCredential, results.Error
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package hub
|
package hub
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/config"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/config"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/hub/internal/fhir/aetna"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/hub/internal/fhir/aetna"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/hub/internal/fhir/base"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/hub/internal/fhir/base"
|
||||||
|
@ -12,21 +14,21 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewClient(providerId string, appConfig config.Interface, globalLogger logrus.FieldLogger, credentials models.Source, testHttpClient ...*http.Client) (base.Client, *models.Source, error) {
|
func NewClient(sourceType pkg.SourceType, ctx context.Context, appConfig config.Interface, globalLogger logrus.FieldLogger, credentials models.Source, testHttpClient ...*http.Client) (base.Client, *models.Source, error) {
|
||||||
|
|
||||||
var providerClient base.Client
|
var sourceClient base.Client
|
||||||
var updatedSource *models.Source
|
var updatedSource *models.Source
|
||||||
var err error
|
var err error
|
||||||
switch providerId {
|
switch sourceType {
|
||||||
case "aetna":
|
case pkg.SourceTypeAetna:
|
||||||
providerClient, updatedSource, err = aetna.NewClient(appConfig, globalLogger, credentials, testHttpClient...)
|
sourceClient, updatedSource, err = aetna.NewClient(ctx, appConfig, globalLogger, credentials, testHttpClient...)
|
||||||
case "anthem":
|
case pkg.SourceTypeAnthem:
|
||||||
providerClient, updatedSource, err = cigna.NewClient(appConfig, globalLogger, credentials, testHttpClient...)
|
sourceClient, updatedSource, err = cigna.NewClient(ctx, appConfig, globalLogger, credentials, testHttpClient...)
|
||||||
case "cigna":
|
case pkg.SourceTypeCigna:
|
||||||
providerClient, updatedSource, err = cigna.NewClient(appConfig, globalLogger, credentials, testHttpClient...)
|
sourceClient, updatedSource, err = cigna.NewClient(ctx, appConfig, globalLogger, credentials, testHttpClient...)
|
||||||
default:
|
default:
|
||||||
return nil, updatedSource, errors.New(fmt.Sprintf("Unknown Provider Type: %s", providerId))
|
return nil, updatedSource, errors.New(fmt.Sprintf("Unknown Source Type: %s", sourceType))
|
||||||
}
|
}
|
||||||
|
|
||||||
return providerClient, updatedSource, err
|
return sourceClient, updatedSource, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,8 @@ type AetnaClient struct {
|
||||||
*base.FHIR401Client
|
*base.FHIR401Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(appConfig config.Interface, globalLogger logrus.FieldLogger, source models.Source, testHttpClient ...*http.Client) (base.Client, *models.Source, error) {
|
func NewClient(ctx context.Context, appConfig config.Interface, globalLogger logrus.FieldLogger, source models.Source, testHttpClient ...*http.Client) (base.Client, *models.Source, error) {
|
||||||
baseClient, updatedSource, err := base.NewFHIR401Client(appConfig, globalLogger, source, testHttpClient...)
|
baseClient, updatedSource, err := base.NewFHIR401Client(ctx, appConfig, globalLogger, source, testHttpClient...)
|
||||||
return AetnaClient{
|
return AetnaClient{
|
||||||
baseClient,
|
baseClient,
|
||||||
}, updatedSource, err
|
}, updatedSource, err
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type BaseClient struct {
|
type BaseClient struct {
|
||||||
|
Context context.Context
|
||||||
AppConfig config.Interface
|
AppConfig config.Interface
|
||||||
Logger logrus.FieldLogger
|
Logger logrus.FieldLogger
|
||||||
|
|
||||||
|
@ -21,14 +22,13 @@ type BaseClient struct {
|
||||||
Source models.Source
|
Source models.Source
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBaseClient(appConfig config.Interface, globalLogger logrus.FieldLogger, source models.Source, testHttpClient ...*http.Client) (*BaseClient, *models.Source, error) {
|
func NewBaseClient(ctx context.Context, appConfig config.Interface, globalLogger logrus.FieldLogger, source models.Source, testHttpClient ...*http.Client) (*BaseClient, *models.Source, error) {
|
||||||
var httpClient *http.Client
|
var httpClient *http.Client
|
||||||
var updatedSource *models.Source
|
var updatedSource *models.Source
|
||||||
if len(testHttpClient) == 0 {
|
if len(testHttpClient) == 0 {
|
||||||
//check if we need to refresh the access token
|
//check if we need to refresh the access token
|
||||||
//https://github.com/golang/oauth2/issues/84#issuecomment-520099526
|
//https://github.com/golang/oauth2/issues/84#issuecomment-520099526
|
||||||
// https://chromium.googlesource.com/external/github.com/golang/oauth2/+/8f816d62a2652f705144857bbbcc26f2c166af9e/oauth2.go#239
|
// https://chromium.googlesource.com/external/github.com/golang/oauth2/+/8f816d62a2652f705144857bbbcc26f2c166af9e/oauth2.go#239
|
||||||
ctx := context.Background()
|
|
||||||
conf := &oauth2.Config{
|
conf := &oauth2.Config{
|
||||||
ClientID: source.ClientId,
|
ClientID: source.ClientId,
|
||||||
ClientSecret: "",
|
ClientSecret: "",
|
||||||
|
@ -77,6 +77,7 @@ func NewBaseClient(appConfig config.Interface, globalLogger logrus.FieldLogger,
|
||||||
|
|
||||||
httpClient.Timeout = 10 * time.Second
|
httpClient.Timeout = 10 * time.Second
|
||||||
return &BaseClient{
|
return &BaseClient{
|
||||||
|
Context: ctx,
|
||||||
AppConfig: appConfig,
|
AppConfig: appConfig,
|
||||||
Logger: globalLogger,
|
Logger: globalLogger,
|
||||||
OauthClient: httpClient,
|
OauthClient: httpClient,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package base
|
package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/config"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/config"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
|
||||||
|
@ -16,8 +17,8 @@ type FHIR401Client struct {
|
||||||
*BaseClient
|
*BaseClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFHIR401Client(appConfig config.Interface, globalLogger logrus.FieldLogger, source models.Source, testHttpClient ...*http.Client) (*FHIR401Client, *models.Source, error) {
|
func NewFHIR401Client(ctx context.Context, appConfig config.Interface, globalLogger logrus.FieldLogger, source models.Source, testHttpClient ...*http.Client) (*FHIR401Client, *models.Source, error) {
|
||||||
baseClient, updatedSource, err := NewBaseClient(appConfig, globalLogger, source, testHttpClient...)
|
baseClient, updatedSource, err := NewBaseClient(ctx, appConfig, globalLogger, source, testHttpClient...)
|
||||||
return &FHIR401Client{
|
return &FHIR401Client{
|
||||||
baseClient,
|
baseClient,
|
||||||
}, updatedSource, err
|
}, updatedSource, err
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package base
|
package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/config"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/config"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
|
||||||
|
@ -13,8 +14,8 @@ type FHIR430Client struct {
|
||||||
*BaseClient
|
*BaseClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFHIR430Client(appConfig config.Interface, globalLogger logrus.FieldLogger, source models.Source, testHttpClient ...*http.Client) (*FHIR430Client, *models.Source, error) {
|
func NewFHIR430Client(ctx context.Context, appConfig config.Interface, globalLogger logrus.FieldLogger, source models.Source, testHttpClient ...*http.Client) (*FHIR430Client, *models.Source, error) {
|
||||||
baseClient, updatedSource, err := NewBaseClient(appConfig, globalLogger, source, testHttpClient...)
|
baseClient, updatedSource, err := NewBaseClient(ctx, appConfig, globalLogger, source, testHttpClient...)
|
||||||
return &FHIR430Client{
|
return &FHIR430Client{
|
||||||
baseClient,
|
baseClient,
|
||||||
}, updatedSource, err
|
}, updatedSource, err
|
||||||
|
|
|
@ -14,8 +14,8 @@ type CignaClient struct {
|
||||||
*base.FHIR401Client
|
*base.FHIR401Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(appConfig config.Interface, globalLogger logrus.FieldLogger, source models.Source, testHttpClient ...*http.Client) (base.Client, *models.Source, error) {
|
func NewClient(ctx context.Context, appConfig config.Interface, globalLogger logrus.FieldLogger, source models.Source, testHttpClient ...*http.Client) (base.Client, *models.Source, error) {
|
||||||
baseClient, updatedSource, err := base.NewFHIR401Client(appConfig, globalLogger, source, testHttpClient...)
|
baseClient, updatedSource, err := base.NewFHIR401Client(ctx, appConfig, globalLogger, source, testHttpClient...)
|
||||||
return CignaClient{
|
return CignaClient{
|
||||||
baseClient,
|
baseClient,
|
||||||
}, updatedSource, err
|
}, updatedSource, err
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package cigna
|
package cigna
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
mock_config "github.com/fastenhealth/fastenhealth-onprem/backend/pkg/config/mock"
|
mock_config "github.com/fastenhealth/fastenhealth-onprem/backend/pkg/config/mock"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/database"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/database"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/hub/internal/fhir/base"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/hub/internal/fhir/base"
|
||||||
|
@ -28,8 +29,8 @@ func TestCignaClient_SyncAll(t *testing.T) {
|
||||||
"type": "test",
|
"type": "test",
|
||||||
})
|
})
|
||||||
httpClient := base.OAuthVcrSetup(t, false)
|
httpClient := base.OAuthVcrSetup(t, false)
|
||||||
client, err := NewClient(fakeConfig, testLogger, models.Source{
|
client, _, err := NewClient(context.Background(), fakeConfig, testLogger, models.Source{
|
||||||
ProviderId: "cigna",
|
SourceType: "cigna",
|
||||||
PatientId: "A00000000000005",
|
PatientId: "A00000000000005",
|
||||||
ApiEndpointBaseUrl: "https://p-hi2.digitaledge.cigna.com/PatientAccess/v1-devportal",
|
ApiEndpointBaseUrl: "https://p-hi2.digitaledge.cigna.com/PatientAccess/v1-devportal",
|
||||||
ClientId: "e434426c-2aaf-413a-a39a-8f5f6130f287",
|
ClientId: "e434426c-2aaf-413a-a39a-8f5f6130f287",
|
||||||
|
|
|
@ -7,10 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ModelBase struct {
|
type ModelBase struct {
|
||||||
ID uuid.UUID `gorm:"type:uuid;primary_key;"`
|
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;"`
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
DeletedAt *time.Time `gorm:"index"`
|
DeletedAt *time.Time `json:"deleted_at,omitempty" gorm:"index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//https://medium.com/@the.hasham.ali/how-to-use-uuid-key-type-with-gorm-cc00d4ec7100
|
//https://medium.com/@the.hasham.ali/how-to-use-uuid-key-type-with-gorm-cc00d4ec7100
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "github.com/google/uuid"
|
import (
|
||||||
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
// Source Data/Medical Provider Credentials
|
// Source Data/Medical Provider Credentials
|
||||||
type Source struct {
|
type Source struct {
|
||||||
ModelBase
|
ModelBase
|
||||||
User User `json:"user,omitempty"`
|
User User `json:"user,omitempty"`
|
||||||
UserID uuid.UUID `json:"user_id" gorm:"uniqueIndex:idx_user_provider_patient"`
|
UserID uuid.UUID `json:"user_id" gorm:"uniqueIndex:idx_user_source_patient"`
|
||||||
ProviderId string `json:"provider_id" gorm:"uniqueIndex:idx_user_provider_patient"`
|
SourceType pkg.SourceType `json:"source_type" gorm:"uniqueIndex:idx_user_source_patient"`
|
||||||
PatientId string `json:"patient_id" gorm:"uniqueIndex:idx_user_provider_patient"`
|
PatientId string `json:"patient_id" gorm:"uniqueIndex:idx_user_source_patient"`
|
||||||
|
|
||||||
OauthEndpointBaseUrl string `json:"oauth_endpoint_base_url"`
|
OauthEndpointBaseUrl string `json:"oauth_endpoint_base_url"`
|
||||||
ApiEndpointBaseUrl string `json:"api_endpoint_base_url"`
|
ApiEndpointBaseUrl string `json:"api_endpoint_base_url"`
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/database"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/database"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/hub"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/hub"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
|
||||||
|
@ -14,24 +15,24 @@ func CreateSource(c *gin.Context) {
|
||||||
logger := c.MustGet("LOGGER").(*logrus.Entry)
|
logger := c.MustGet("LOGGER").(*logrus.Entry)
|
||||||
databaseRepo := c.MustGet("REPOSITORY").(database.DatabaseRepository)
|
databaseRepo := c.MustGet("REPOSITORY").(database.DatabaseRepository)
|
||||||
|
|
||||||
providerCred := models.Source{}
|
sourceCred := models.Source{}
|
||||||
if err := c.ShouldBindJSON(&providerCred); err != nil {
|
if err := c.ShouldBindJSON(&sourceCred); err != nil {
|
||||||
logger.Errorln("An error occurred while parsing posted provider credential", err)
|
logger.Errorln("An error occurred while parsing posted source credential", err)
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"success": false})
|
c.JSON(http.StatusBadRequest, gin.H{"success": false})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Infof("Parsed Create Provider Credentials Payload: %v", providerCred)
|
logger.Infof("Parsed Create Source Credentials Payload: %v", sourceCred)
|
||||||
|
|
||||||
err := databaseRepo.CreateSource(c, &providerCred)
|
err := databaseRepo.CreateSource(c, &sourceCred)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorln("An error occurred while storing provider credential", err)
|
logger.Errorln("An error occurred while storing source credential", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// after creating the source, we should do a bulk import
|
// after creating the source, we should do a bulk import
|
||||||
sourceClient, updatedSource, err := hub.NewClient(providerCred.ProviderId, nil, logger, providerCred)
|
sourceClient, updatedSource, err := hub.NewClient(sourceCred.SourceType, c, nil, logger, sourceCred)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorln("An error occurred while initializing hub client using source credential", err)
|
logger.Errorln("An error occurred while initializing hub client using source credential", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
||||||
|
@ -40,7 +41,7 @@ func CreateSource(c *gin.Context) {
|
||||||
if updatedSource != nil {
|
if updatedSource != nil {
|
||||||
err := databaseRepo.CreateSource(c, updatedSource)
|
err := databaseRepo.CreateSource(c, updatedSource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorln("An error occurred while updating provider credential", err)
|
logger.Errorln("An error occurred while updating source credential", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -53,20 +54,20 @@ func CreateSource(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": providerCred})
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": sourceCred})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListSource(c *gin.Context) {
|
func ListSource(c *gin.Context) {
|
||||||
logger := c.MustGet("LOGGER").(*logrus.Entry)
|
logger := c.MustGet("LOGGER").(*logrus.Entry)
|
||||||
databaseRepo := c.MustGet("REPOSITORY").(database.DatabaseRepository)
|
databaseRepo := c.MustGet("REPOSITORY").(database.DatabaseRepository)
|
||||||
|
|
||||||
providerCredentials, err := databaseRepo.GetSources(c)
|
sourceCreds, err := databaseRepo.GetSources(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorln("An error occurred while storing provider credential", err)
|
logger.Errorln("An error occurred while storing source credential", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": providerCredentials})
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": sourceCreds})
|
||||||
}
|
}
|
||||||
|
|
||||||
func RawRequestSource(c *gin.Context) {
|
func RawRequestSource(c *gin.Context) {
|
||||||
|
@ -75,14 +76,14 @@ func RawRequestSource(c *gin.Context) {
|
||||||
|
|
||||||
sources, err := databaseRepo.GetSources(c)
|
sources, err := databaseRepo.GetSources(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorln("An error occurred while storing provider credential", err)
|
logger.Errorln("An error occurred while storing source credential", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var foundSource *models.Source
|
var foundSource *models.Source
|
||||||
for _, source := range sources {
|
for _, source := range sources {
|
||||||
if source.ProviderId == c.Param("sourceType") {
|
if source.SourceType == pkg.SourceType(c.Param("sourceType")) {
|
||||||
foundSource = &source
|
foundSource = &source
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -94,7 +95,7 @@ func RawRequestSource(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
client, updatedSource, err := hub.NewClient(c.Param("sourceType"), nil, logger, *foundSource)
|
client, updatedSource, err := hub.NewClient(pkg.SourceType(c.Param("sourceType")), c, nil, logger, *foundSource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Could not initialize source client", err)
|
logger.Errorf("Could not initialize source client", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
||||||
|
@ -103,7 +104,7 @@ func RawRequestSource(c *gin.Context) {
|
||||||
if updatedSource != nil {
|
if updatedSource != nil {
|
||||||
err := databaseRepo.CreateSource(c, updatedSource)
|
err := databaseRepo.CreateSource(c, updatedSource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorln("An error occurred while updating provider credential", err)
|
logger.Errorln("An error occurred while updating source credential", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
|
|
||||||
export class Patient {
|
export class Patient {
|
||||||
//fields
|
//fields
|
||||||
provider_id: string
|
source_type: string
|
||||||
patient_id: string
|
patient_id: string
|
||||||
|
|
||||||
age: string
|
age: string
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
export class ResourceFhir {
|
||||||
|
user_id?: string
|
||||||
|
source_id: string
|
||||||
|
source_resource_type: string
|
||||||
|
source_resource_id: string
|
||||||
|
payload: any
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
export class Source {
|
export class Source {
|
||||||
user_id?: number
|
user_id?: number
|
||||||
provider_id: string
|
source_type: string
|
||||||
patient_id: string
|
patient_id: string
|
||||||
|
|
||||||
oauth_endpoint_base_url: string
|
oauth_endpoint_base_url: string
|
||||||
|
|
|
@ -49,7 +49,7 @@ export class MedicalSourcesComponent implements OnInit {
|
||||||
for (const sourceId in this.sourceLookup) {
|
for (const sourceId in this.sourceLookup) {
|
||||||
let isConnected = false
|
let isConnected = false
|
||||||
for(const connectedSource of sourceList){
|
for(const connectedSource of sourceList){
|
||||||
if(connectedSource.provider_id == sourceId){
|
if(connectedSource.source_type == sourceId){
|
||||||
this.connectedSourceList.push({"providerId": sourceId, "display": this.sourceLookup[sourceId]["display"]})
|
this.connectedSourceList.push({"providerId": sourceId, "display": this.sourceLookup[sourceId]["display"]})
|
||||||
isConnected = true
|
isConnected = true
|
||||||
break
|
break
|
||||||
|
@ -128,7 +128,7 @@ export class MedicalSourcesComponent implements OnInit {
|
||||||
|
|
||||||
//Create FHIR Client
|
//Create FHIR Client
|
||||||
const sourceCredential: Source = {
|
const sourceCredential: Source = {
|
||||||
provider_id: providerId,
|
source_type: providerId,
|
||||||
oauth_endpoint_base_url: connectData.oauth_endpoint_base_url,
|
oauth_endpoint_base_url: connectData.oauth_endpoint_base_url,
|
||||||
api_endpoint_base_url: connectData.api_endpoint_base_url,
|
api_endpoint_base_url: connectData.api_endpoint_base_url,
|
||||||
client_id: connectData.client_id,
|
client_id: connectData.client_id,
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {map} from 'rxjs/operators';
|
||||||
import {ResponseWrapper} from '../models/response-wrapper';
|
import {ResponseWrapper} from '../models/response-wrapper';
|
||||||
import {Source} from '../models/fasten/source';
|
import {Source} from '../models/fasten/source';
|
||||||
import {User} from '../models/fasten/user';
|
import {User} from '../models/fasten/user';
|
||||||
|
import {ResourceFhir} from '../models/fasten/resource_fhir';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
@ -85,12 +86,12 @@ export class FastenApiService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getResources(resourceType: string, resourceId?: string ): Observable<any[]> {
|
getResources(resourceType: string, resourceId?: string ): Observable<ResourceFhir[]> {
|
||||||
return this._httpClient.get<any>(`${this.getBasePath()}/api/secure/fhir/${resourceType}/${resourceId ? resourceId : ''}`)
|
return this._httpClient.get<any>(`${this.getBasePath()}/api/secure/fhir/${resourceType}/${resourceId ? resourceId : ''}`)
|
||||||
.pipe(
|
.pipe(
|
||||||
map((response: ResponseWrapper) => {
|
map((response: ResponseWrapper) => {
|
||||||
console.log("RESPONSE", response)
|
console.log("RESPONSE", response)
|
||||||
return response.data
|
return response.data as ResourceFhir[]
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue