Documentation
¶
Index ¶
- Variables
- func AppendInto(ext fhir.Extendable, extensions ...*dtpb.Extension)
- func Clear(ext fhir.Extendable)
- func FromElement(uri string, element fhir.Element) (*dtpb.Extension, error)
- func New[T ValueX](uri string, element T) *dtpb.Extension
- func Overwrite(ext fhir.Extendable, extensions ...*dtpb.Extension)
- func SetByURL[T ValueX](ext fhir.Extendable, url string, values ...T)
- func Unwrap(extension *dtpb.Extension) fhir.Element
- func Upsert(ext fhir.Extendable, extension *dtpb.Extension)
- type ValueX
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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...
Types ¶
type ValueX ¶
type ValueX interface { fhir.Element *dtpb.Base64Binary | *dtpb.Boolean | *dtpb.Canonical | *dtpb.Code | *dtpb.Date | *dtpb.DateTime | *dtpb.Decimal | *dtpb.Id | *dtpb.Instant | *dtpb.Integer | *dtpb.Markdown | *dtpb.Oid | *dtpb.PositiveInt | *dtpb.String | *dtpb.Time | *dtpb.UnsignedInt | *dtpb.Uri | *dtpb.Url | *dtpb.Uuid | *dtpb.Address | *dtpb.Age | *dtpb.Annotation | *dtpb.Attachment | *dtpb.CodeableConcept | *dtpb.Coding | *dtpb.ContactPoint | *dtpb.Count | *dtpb.Distance | *dtpb.Duration | *dtpb.HumanName | *dtpb.Identifier | *dtpb.Money | *dtpb.Period | *dtpb.Quantity | *dtpb.Range | *dtpb.Ratio | *dtpb.Reference | *dtpb.SampledData | *dtpb.Signature | *dtpb.Timing | *dtpb.ContactDetail | *dtpb.Contributor | *dtpb.DataRequirement | *dtpb.Expression | *dtpb.ParameterDefinition | *dtpb.RelatedArtifact | *dtpb.TriggerDefinition | *dtpb.UsageContext | *dtpb.Dosage }
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