server

package
v0.0.0-...-cd152e6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2018 License: Apache-2.0 Imports: 26 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Database *mgo.Database

Although we got rid of the global in the fhir package, the ie project still needs it Once ie removes the dependency on the global, this should go away

View Source
var DefaultConfig = Config{
	ServerURL:       "http://localhost:3001",
	IndexConfigPath: "config/indexes.conf",
	DatabaseName:    "fhir",
	Auth:            auth.None(),
}

DefaultConfig is the default server configuration

View Source
var ErrMultipleMatches = errors.New("Multiple Matches")

ErrMultipleMatches indicates that the conditional update query returned multiple matches

View Source
var ErrNotFound = errors.New("Resource Not Found")

ErrNotFound indicates an error

Functions

func AbortNonJSONRequests

func AbortNonJSONRequests(c *gin.Context)

AbortNonJSONRequests is middleware that responds to any request that Accepts a format other than JSON with a 406 Not Acceptable status.

func ConfigureIndexes

func ConfigureIndexes(session *mgo.Session, config Config)

ConfigureIndexes ensures that all indexes listed in the provided indexes.conf file are part of the Mongodb fhir database. If an index does not exist yet ConfigureIndexes creates a new index in the background using mgo.collection.EnsureIndex(). Depending on the size of the collection it may take some time before the index is created. This will block the current thread until the indexing completes, but will not block other connections to the mongo database.

func FHIRBind

func FHIRBind(c *gin.Context, obj interface{}) error

func RegisterController

func RegisterController(name string, e *gin.Engine, m []gin.HandlerFunc, dal DataAccessLayer, config Config)

RegisterController registers the CRUD routes (and middleware) for a FHIR resource

func RegisterRoutes

func RegisterRoutes(e *gin.Engine, config map[string][]gin.HandlerFunc, dal DataAccessLayer, serverConfig Config)

RegisterRoutes registers the routes for each of the FHIR resources

func RequestLoggerHandler

func RequestLoggerHandler(c *gin.Context)

RequestLoggerHandler is a handler intended to be used during debugging to log out the request details including the request headers and the request body. This should not be used in production as it has performance implications.

Types

type AfterRoutes

type AfterRoutes func(*gin.Engine)

type BatchController

type BatchController struct {
	DAL DataAccessLayer
}

BatchController handles FHIR batch operations via input bundles

func NewBatchController

func NewBatchController(dal DataAccessLayer) *BatchController

NewBatchController creates a new BatchController based on the passed in DAL

func (*BatchController) Post

func (b *BatchController) Post(c *gin.Context)

Post processes and incoming batch request

type Config

type Config struct {
	// ServerURL is the full URL for the root of the server. This may be used
	// by other middleware to compute redirect URLs
	ServerURL string
	// Auth determines what, if any authentication and authorization will be used
	// by the FHIR server
	Auth auth.Config
	// IndexConfigPath is the path to an indexes.conf configuration file, specifying
	// what mongo indexes the server should create (or verify) on startup
	IndexConfigPath string
	// DatabaseName is the name of the mongo database used for the fhir database.
	// Typically this will be the DefaultDatabaseName
	DatabaseName string
}

Config is used to hold information about the configuration of the FHIR server.

type DataAccessLayer

type DataAccessLayer interface {
	// Get retrieves a single resource instance identified by its resource type and ID
	Get(id, resourceType string) (result interface{}, err error)
	// Post creates a resource instance, returning its new ID.
	Post(resource interface{}) (id string, err error)
	// PostWithID creates a resource instance with the given ID.
	PostWithID(id string, resource interface{}) error
	// Put creates or updates a resource instance with the given ID.
	Put(id string, resource interface{}) (createdNew bool, err error)
	// ConditionalPut creates or updates a resource based on search criteria.  If the criteria results in zero matches,
	// the resource is created.  If the criteria results in one match, it is updated.  Otherwise, a ErrMultipleMatches
	// error is returned.
	ConditionalPut(query search.Query, resource interface{}) (id string, createdNew bool, err error)
	// Delete removes the resource instance with the given ID.  This operation cannot be undone.
	Delete(id, resourceType string) error
	// ConditionalDelete removes zero or more resources matching the passed in search criteria.  This operation cannot
	// be undone.
	ConditionalDelete(query search.Query) (count int, err error)
	// Search executes a search given the baseURL and searchQuery.
	Search(baseURL url.URL, searchQuery search.Query) (result *models.Bundle, err error)
	// FindIDs executes a search given the searchQuery and returns only the matching IDs.  This function ignores
	// search options that don't make sense in this context: _include, _revinclude, _summary, _elements, _contained,
	// and _containedType.  It honors search options such as _count, _sort, and _offset.
	FindIDs(searchQuery search.Query) (result []string, err error)
}

DataAccessLayer is an interface for the various interactions that can occur on a FHIR data store.

func NewMongoDataAccessLayer

func NewMongoDataAccessLayer(db *mgo.Database) DataAccessLayer

NewMongoDataAccessLayer returns an implementation of DataAccessLayer that is backed by a Mongo database

type FHIRServer

type FHIRServer struct {
	DatabaseHost     string
	Engine           *gin.Engine
	MiddlewareConfig map[string][]gin.HandlerFunc
	AfterRoutes      []AfterRoutes
}

func NewServer

func NewServer(databaseHost string) *FHIRServer

func (*FHIRServer) AddMiddleware

func (f *FHIRServer) AddMiddleware(key string, middleware gin.HandlerFunc)

func (*FHIRServer) Run

func (f *FHIRServer) Run(config Config)

type IndexMap

type IndexMap map[string][]*mgo.Index

IndexMap is a map of index arrays with the collection name as the key. Each index array contains one or more *mgo.Index indexes.

type ResourceController

type ResourceController struct {
	Name string
	DAL  DataAccessLayer
}

ResourceController provides the necessary CRUD handlers for a given resource.

func NewResourceController

func NewResourceController(name string, dal DataAccessLayer) *ResourceController

NewResourceController creates a new resource controller for the passed in resource name and the passed in DataAccessLayer.

func (*ResourceController) ConditionalDeleteHandler

func (rc *ResourceController) ConditionalDeleteHandler(c *gin.Context)

ConditionalDeleteHandler handles requests to delete resources identified by search criteria. All resources matching the search criteria will be deleted.

func (*ResourceController) ConditionalUpdateHandler

func (rc *ResourceController) ConditionalUpdateHandler(c *gin.Context)

ConditionalUpdateHandler handles requests for conditional updates. These requests contain search criteria for the resource to update. If the criteria results in no found resources, a new resource is created. If the criteria results in one found resource, that resource will be updated. Criteria resulting in more than one found resource is considered an error.

func (*ResourceController) CreateHandler

func (rc *ResourceController) CreateHandler(c *gin.Context)

CreateHandler handles requests to create a new resource instance, assigning it a new ID.

func (*ResourceController) DeleteHandler

func (rc *ResourceController) DeleteHandler(c *gin.Context)

DeleteHandler handles requests to delete a resource instance identified by its ID.

func (*ResourceController) IndexHandler

func (rc *ResourceController) IndexHandler(c *gin.Context)

IndexHandler handles requests to list resource instances or search for them.

func (*ResourceController) LoadResource

func (rc *ResourceController) LoadResource(c *gin.Context) (interface{}, error)

LoadResource uses the resource id in the request to get a resource from the DataAccessLayer and store it in the context.

func (*ResourceController) ShowHandler

func (rc *ResourceController) ShowHandler(c *gin.Context)

ShowHandler handles requests to get a particular resource by ID.

func (*ResourceController) UpdateHandler

func (rc *ResourceController) UpdateHandler(c *gin.Context)

UpdateHandler handles requests to update a resource having a given ID. If the resource with that ID does not exist, a new resource is created with that ID.

type ResourcePlusRelatedResources

type ResourcePlusRelatedResources interface {
	GetIncludedAndRevIncludedResources() map[string]interface{}
	GetIncludedResources() map[string]interface{}
	GetRevIncludedResources() map[string]interface{}
}

ResourcePlusRelatedResources is an interface to capture those structs that implement the functions for getting included and rev-included resources

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL