search

package
v0.0.0-...-ab75ee6 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package search contains types and helpers to work with FHIR Search. You can use these to provide search capabilities for your custom implementation.

Currently, only an API with cursor-based pagination is supported. Parameters for offset based pagination might be added eventually if there is demand.

Example

import "github.com/DAMEDIC/fhir-toolbox-go/capabilities/search"

func (b *myAPI) SearchCapabilitiesObservation() search.Capabilities {
	// return supported search capabilities
	return search.Capabilities{
		Parameters: ParameterDescriptions{
			"_id": {Type: search.TypeToken},
		},
	}
}

func (b *myAPI) SearchObservation(ctx context.Context, options search.Options) (search.Result, error) {
	// return the search result
	return search.Result{ ... }, nil
}

Index

Constants

View Source
const (
	TypeNumber    string = "number"
	TypeDate      string = "date"
	TypeString    string = "string"
	TypeToken     string = "token"
	TypeReference string = "reference"
	TypeComposite string = "composite"
	TypeQuantity  string = "quantity"
	TypeUri       string = "uri"
	TypeSpecial   string = "special"
)
View Source
const (
	// ModifierAbove on reference, token, uri: Tests whether the value in a resource is or subsumes the supplied parameter value (is-a, or hierarchical relationships).
	ModifierAbove string = "above"
	// ModifierBelow on reference, token, uri: Tests whether the value in a resource is or is subsumed by the supplied parameter value (is-a, or hierarchical relationships).
	ModifierBelow string = "below"
	// ModifierCodeText on reference, token: Tests whether the textual display value in a resource (e.g., CodeableConcept.text, Coding.display, or Reference.display) matches the supplied parameter value.
	ModifierCodeText string = "code-text"
	// ModifierContains on string, uri: Tests whether the value in a resource includes the supplied parameter value anywhere within the field being searched.
	ModifierContains string = "contains"
	// ModifierExact on string: Tests whether the value in a resource exactly matches the supplied parameter value (the whole string, including casing and accents).
	ModifierExact string = "exact"
	// ModifierIdentifier on reference: Tests whether the Reference.identifier in a resource (rather than the Reference.reference) matches the supplied parameter value.
	ModifierIdentifier string = "identifier"
	// ModifierInModifier on token: Tests whether the value in a resource is a member of the supplied parameter ValueSet.
	ModifierIn string = "in"
	// ModifierIterate Not allowed anywhere by default: The search parameter indicates an inclusion directive (_include, _revinclude) that is applied to an included resource instead of the matching resource.
	ModifierIterate string = "iterate"
	// ModifierMissing on date, number, quantity, reference, string, token, uri: Tests whether the value in a resource is present (when the supplied parameter value is true) or absent (when the supplied parameter value is false).
	ModifierMissing string = "missing"
	// ModifierNot on token: Tests whether the value in a resource does not match the specified parameter value. Note that this includes resources that have no value for the parameter.
	ModifierNot string = "not"
	// ModifierNotIn on reference, token: Tests whether the value in a resource is not a member of the supplied parameter ValueSet.
	ModifierNotIn string = "not-in"
	// ModifierOfType on token (only Identifier): Tests whether the Identifier value in a resource matches the supplied parameter value.
	ModifierOfType string = "of-type"
	// ModifierText on reference, token: Tests whether the textual value in a resource (e.g., CodeableConcept.text, Coding.display, Identifier.type.text, or Reference.display) matches the supplied parameter value using basic string matching (begins with or is, case-insensitive).
	//
	//on string: The search parameter value should be processed as input to a search with advanced text handling.
	ModifierText string = "text"
	// ModifierTextAdvancedModifier on reference, token: Tests whether the value in a resource matches the supplied parameter value using advanced text handling that searches text associated with the code/value - e.g., CodeableConcept.text, Coding.display, or Identifier.type.text.
	ModifierTextAdvanced string = "text-advanced"
	// ModifierType on reference: Tests whether the value in a resource points to a resource of the supplied parameter type. Note: a concrete ResourceType is specified as the modifier (e.g., not the literal :[type], but a value such as :Patient).
	ModifierType string = "[type]"
)
View Source
const (
	PrefixEqual          string = "eq"
	PrefixNotEqual       string = "ne"
	PrefixGreaterThan    string = "gt"
	PrefixLessThan       string = "lt"
	PrefixGreaterOrEqual string = "ge"
	PrefixLessOrEqual    string = "le"
	PrefixStartsAfter    string = "sa"
	PrefixEndsBefore     string = "eb"
)
View Source
const (
	DateFormatOnlyYear   = "2006"
	DateFormatUpToMonth  = "2006-01"
	DateFormatUpToDay    = "2006-01-02"
	DateFormatHourMinute = "2006-01-02T15:04Z07:00"
	DateFormatFullTime   = "2006-01-02T15:04:05.999999999Z07:00"
)

Format strings for precision aware parsing and encoding.

Variables

Functions

This section is empty.

Types

type AllOf

type AllOf []OneOf

All represents a slice of possible values for a single search parameter where each of the entry has to match.

type Composite

type Composite []string

func (Composite) String

func (c Composite) String() string

type Cursor

type Cursor string

Cursor is used for pagination.

It references where the server shall pick up querying additional results for multi-page queries.

type Date

type Date struct {
	Prefix    string
	Precision DatePrecision
	Value     time.Time
}

func (Date) String

func (d Date) String() string

type DatePrecision

type DatePrecision string

DatePrecision represents the precision of date value.

const (
	PrecisionYear       DatePrecision = "year"
	PrecisionMonth      DatePrecision = "month"
	PrecisionDay        DatePrecision = "day"
	PrecisionHourMinute DatePrecision = "hourMinute"
	PrecisionFullTime   DatePrecision = "time"
)

func ParseDate

func ParseDate(value string, tz *time.Location) (time.Time, DatePrecision, error)

type Number

type Number struct {
	Prefix string
	Value  *apd.Decimal
}

func (Number) String

func (n Number) String() string

type OneOf

type OneOf []Value

OneOf represents a slice of possible values for a single search parameter, where only one of the values has to match.

type Options

type Options struct {
	// Parameters defines the search parameters.
	Parameters map[ParameterKey]AllOf
	// Includes specifies the related resources to include in the search results.
	Includes []string
	// Count defines the maximum number of results to return.
	Count int
	// Cursor allows for pagination of large result sets.
	Cursor Cursor
}

Options represents the parameters passed to a search implementation.

func ParseOptions

func ParseOptions(
	capabilityStatement basic.CapabilityStatement,
	resourceType string,
	resolveSearchParameter func(canonical string) (model.Element, error),
	params url.Values,
	tz *time.Location,
	maxCount, defaultCount int,
	strict bool,
) (Options, error)

ParseOptions parses search options from a url.Values query string.

Only parameters supported by the backing implementation as described by the passed `capabilityStatement` for the given `resourceType` are used.

The `resolveSearchParameter` function is used to resolve SearchParameter resources from their canonical URLs found in the CapabilityStatement.

When `strict` is true, an error is returned if unsupported search parameters are encountered. When `strict` is false, unsupported search parameters are silently ignored.

Result modifying parameters are parsed into separate fields on the Options object. All other parameters are parsed into [options.Parameters].

func (Options) QueryString

func (o Options) QueryString() string

QueryString of the search options.

Search parameters are sorted alphabetically, result modifying parameters like `_include` are appended at the end. The function is deterministic, the same `option` input will always yield the same output.

type Parameter

type Parameter model.Element

Parameter is a placeholder for FHIR version specific SearchParameter.

type ParameterKey

type ParameterKey struct {
	// Name is the name of the search parameter.
	Name string
	// Modifier is an optional modifier that can be applied to the search parameter,
	// such as `exact`, `contains`, `identifier`, etc.
	Modifier string
}

ParameterKey represents a key for a search parameter, consisting of a name and an optional modifier.

func (ParameterKey) MarshalText

func (p ParameterKey) MarshalText() ([]byte, error)

func (ParameterKey) String

func (p ParameterKey) String() string

type Quantity

type Quantity struct {
	Prefix string
	Value  *apd.Decimal
	System *url.URL
	Code   string
}

func (Quantity) String

func (q Quantity) String() string

type Reference

type Reference struct {
	Modifier string
	Id       string
	Type     string
	Url      *url.URL
	Version  string
}

func (Reference) String

func (r Reference) String() string

type Result

type Result[R model.Resource] struct {
	Resources []R
	Included  []model.Resource
	Next      Cursor
}

Result contains the result of a search operation.

type Special

type Special string

Special string contains potential prefixes

func (Special) String

func (s Special) String() string

type String

type String string

func (String) String

func (s String) String() string

type Token

type Token struct {
	// Go URLs can contain URIs
	System *url.URL
	Code   string
}

func (Token) String

func (t Token) String() string

type Uri

type Uri struct {
	// Go URLs can contain URIs
	Value *url.URL
}

func (Uri) String

func (u Uri) String() string

type Value

type Value interface {
	String() string
	// contains filtered or unexported methods
}

Value of a search parameter, determine the concrete type by type assertion.

switch t := value.(type) {
case search.Number:
  // handle search parameter of type number
}

Jump to

Keyboard shortcuts

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