extension

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalidValueX = errors.New("invalid extension ValueX type")

ErrInvalidValueX is an error reported if trying to create an Extension from an invalid data-type. Most FHIR Elements are supported, with only a few notable exceptions. See the definition of the ValueX constraint to see which elements are valid inputs.

Functions

func AppendInto

func AppendInto(ext fhir.Extendable, extensions ...*dtpb.Extension)

AppendInto appends extensions into the specified Resource or Element. Unlike most "append" operations, this mutates the source object rather than copying and returning a new changed object. This is done to prevent expensive copy-operations on large FHIR resources that are being extended.

This function can only be called with extendable resources or data-types, and thus does not have any error-cases to surface back to the caller.

This function will panic if ext is nil.

Example
package main

import (
	"fmt"

	dtpb "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/datatypes_go_proto"
	"github.com/google/fhir/go/proto/google/fhir/proto/r4/core/resources/task_go_proto"
	"github.com/verily-src/fhirpath-go/internal/element/extension"
	"github.com/verily-src/fhirpath-go/internal/fhir"
)

func main() {
	const urlBase = "http://example.com/StructureDefinitions"
	task := &task_go_proto.Task{
		Extension: []*dtpb.Extension{
			extension.New(fmt.Sprintf("%v/%v", urlBase, "my-int"), fhir.Integer(42)),
		},
	}

	extension.AppendInto(task,
		extension.New(fmt.Sprintf("%v/%v", urlBase, "my-string"), fhir.String("hello world")),
		extension.New(fmt.Sprintf("%v/%v", urlBase, "my-bool"), fhir.Boolean(true)),
	)
	fmt.Printf("%v extensions in Task!", len(task.GetExtension()))
}
Output:

3 extensions in Task!

func Clear

func Clear(ext fhir.Extendable)

Clear removes all extensions from the specified FHIR Element or Resource.

func FromElement

func FromElement(uri string, element fhir.Element) (*dtpb.Extension, error)

FromElement creates an extension from the specified datatype resource. If the datatype is not a valid input, this function returns an error.

For convenience functions that cannot return an error, see the various `Extension*` functions.

func New

func New[T ValueX](uri string, element T) *dtpb.Extension

New creates an New extension object from a concrete, and legal, extension type. Unlike `FromElement`, this function cannot fail since the type has been checked ot be valid extension type with Go-1.18 constraints.

func Overwrite

func Overwrite(ext fhir.Extendable, extensions ...*dtpb.Extension)

Overwrite modifies a Resource or Element in-place to overwrite all of the extensions in the given object with the provided ones.

This function can only be called with extendable resources or data-types, and thus does not have any error-cases to surface back to the caller.

This function will panic if ext is nil.

Example
package main

import (
	"fmt"

	dtpb "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/datatypes_go_proto"
	"github.com/google/fhir/go/proto/google/fhir/proto/r4/core/resources/task_go_proto"
	"github.com/verily-src/fhirpath-go/internal/element/extension"
	"github.com/verily-src/fhirpath-go/internal/fhir"
)

func main() {
	const urlBase = "https://verily-src.github.io/vhp-hds-vvs-fhir-ig/StructureDefinitions"
	task := &task_go_proto.Task{
		Extension: []*dtpb.Extension{
			extension.New(fmt.Sprintf("%v/%v", urlBase, "my-int"), fhir.Integer(42)),
		},
	}

	extension.Overwrite(task,
		extension.New(fmt.Sprintf("%v/%v", urlBase, "my-string"), fhir.String("hello world")),
		extension.New(fmt.Sprintf("%v/%v", urlBase, "my-bool"), fhir.Boolean(true)),
	)
	fmt.Printf("%v extensions in Task!", len(task.GetExtension()))
}
Output:

2 extensions in Task!

func SetByURL

func SetByURL[T ValueX](ext fhir.Extendable, url string, values ...T)

SetByURL always remove all extensions with url, and creates N extensions with url and values...

func Unwrap

func Unwrap(extension *dtpb.Extension) fhir.Element

Unwrap will return the wrapped Element in this extension, if one exists. If there is none, or if extension is nil, this returns nil.

func Upsert

func Upsert(ext fhir.Extendable, extension *dtpb.Extension)

Upsert always replaces or inserts the extension by the URL.

Types

type ValueX

ValueX is a constraint that enumerates all the valid 'DataType' objects that can be used for extensions. This is used to constrain the `Extension` function so that it cannot fail.

This type is exported so that consumers may also expose the same generic requirements to their clients.

For more information on these types, see the definition of Extension's `value` fields here: https://www.hl7.org/fhir/r4/extensibility.html#Extension

Jump to

Keyboard shortcuts

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