rest

package
v0.0.0-...-692df37 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package rest provides a FHIR REST API.

Capabilities are detected by type assertion, a generated CapabilityStatement is served at the "/metadata" endpoint.

Following interactions are currently supported:

  • read
  • search (parameters are passed down to the supplied backend implementation)

Base URL and routes

You have to pass a base URL using the config. This base URL is only used for building response Bundles. For supported interactions, the returned http.Handler has sub-routes installed. These are always installed at the root of this handler. The base URL from the config is not used.

Currently, installed patterns are:

  • capabilities: "GET /metadata"
  • read: "GET /{type}/{id}"
  • search: "GET /{type}/"

If you do not want your FHIR handlers installed at the root, use something like

mux.Handle("/path/", http.StripPrefix("/path", serverHandler)

This allows you to implement multiple FHIR REST APIs on the same HTTP server (e.g. for multi-tenancy scenarios).

Pagination

Cursor-based pagination can be implemented by the backend. Therefor the parameters "_count" and "_cursor" are passed down to the backend.

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Timezone:      time.Now().Location().String(),
	Date:          time.Now().Format(time.RFC3339),
	MaxCount:      500,
	DefaultCount:  500,
	DefaultFormat: FormatJSON,
}

DefaultConfig sets reasonable defaults that can be used by the package user.

Functions

func CapabilityStatement

func CapabilityStatement[R model.Release](
	baseURL *url.URL,
	capabilities capabilities.Capabilities,
	date time.Time,
) basic.CapabilityStatement

CapabilityStatement building from provided capabilities.

func NewRequestContextSlogHandler

func NewRequestContextSlogHandler(h slog.Handler) slog.Handler

func NewServer

func NewServer[R model.Release](backend any, config Config) (http.Handler, error)

NewServer returns a http.Handler that serves the supplied backend.

func SearchBundle

func SearchBundle(
	resourceType string,
	result search.Result,
	usedOptions search.Options,
	searchCapabilities search.Capabilities,
	baseURL *url.URL,
) (basic.Bundle, capabilities.FHIRError)

SearchBundle creates a new search bundle from the given resources and parameters.

The REST server uses cursor based pagination. If the search results contains a `Next` cursor, a 'next' bundle link entry will be set.

Types

type Config

type Config struct {
	// Base path of the FHIR server, used e.g. for building bundles.
	Base *url.URL `json:"base"`
	// Timezone used for parsing date parameters without timezones.
	// Defaults to current server timezone.
	Timezone string `json:"timezone"`
	// Date of last capability change, used for building the CapabilityStatement.
	// Defaults to current time.
	Date string `json:"date"`
	// MaxCount of search bundle entries.
	// Defaults to 500.
	MaxCount int `json:"maxCount"`
	// DefaultCount of search bundle entries.
	// Defaults to 500.
	DefaultCount int `json:"defaultCount"`
	// DefaultFormat of the server.
	// Defaults to JSON.
	DefaultFormat Format `json:"defaultFormat"`
}

func (Config) MarshalJSON

func (c Config) MarshalJSON() ([]byte, error)

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(b []byte) error

type Format

type Format string
const (
	FormatJSON Format = "application/fhir+json"
	FormatXML  Format = "application/fhir+xml"
)

type MissingIdError

type MissingIdError struct {
	ResourceType string
}

MissingIdError indicates that a bundle entry is missing an id.

func (MissingIdError) Error

func (e MissingIdError) Error() string

func (MissingIdError) OperationOutcome

func (e MissingIdError) OperationOutcome() model.Resource

func (MissingIdError) StatusCode

func (e MissingIdError) StatusCode() int

type RequestContext

type RequestContext map[string]string

Jump to

Keyboard shortcuts

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