identifier

package
v0.0.0-...-5b88717 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package identifier provides utilities for constructing and working with FHIR R4 Identifier elements.

See: http://hl7.org/fhir/R4/datatypes.html#Identifier

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equivalent

func Equivalent(lhs, rhs *dtpb.Identifier) bool

Equivalent checks if two identifiers are equivalent by comparing the system and values of the identifier.

func FindBySystem

func FindBySystem(identifiers []*dtpb.Identifier, system string) *dtpb.Identifier

FindBySystem searches a slice of identifiers for the first identifier that contains the specified system.

func GenerateIfNoneExist

func GenerateIfNoneExist(identifier *dtpb.Identifier) string

GenerateIfNoneExist takes an Identifier and generates a query appropriate for use in an If-None-Exist header. This is used for FHIR conditional create or other conditional methods.

Untrusted data in Identifiers is escaped both for FHIR and for URL safety.

Returns an empty string if identifier is nil.

This function only accepts a single identifier due to limitations of the GCP FHIR store. Important note: The GCP FHIR store only supports conditional queries on a single identifier, with no modifiers (so identifier=foo is OK, while identifier:exact=foo is invalid). Deviating from this in API v1 will result in an HTTP 400 invalid query error. NB: Deviating from this in API v1beta1 results in silent fallback to non-transactional search, meaning the conditional queries will have race conditions.

Example
package main

import (
	"fmt"

	"github.com/fhir-fli/fhirpath-go/internal/element/identifier"
	dtpb "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/datatypes_go_proto"
)

func main() {
	id := &dtpb.Identifier{
		System: &dtpb.Uri{Value: "http://fake.com"},
		Value:  &dtpb.String{Value: "9efbf82d-7a58-4d14-bec1-63f8fda148a8"},
	}

	header := identifier.GenerateIfNoneExist(id)
	fmt.Printf("If-None-Exist: %v", header)
}
Output:

If-None-Exist: identifier=http%3A%2F%2Ffake.com%7C9efbf82d-7a58-4d14-bec1-63f8fda148a8

func New

func New(value, system string, opts ...Option) *dtpb.Identifier

New constructs a new Identifier object from the given options.

func Official

func Official(value, system string, opts ...Option) *dtpb.Identifier

Official is a convenience constructor for forming an identifier with an "Official" Use-code assigned.

func Old

func Old(value, system string, opts ...Option) *dtpb.Identifier

Old is a convenience constructor for forming an identifier with an "Old" Use-code assigned.

func QueryIdentifier

func QueryIdentifier(id *dtpb.Identifier) string

QueryIdentifier formats an Identifier proto for use in a Search query, escaping FHIR special characters `,|$\` in the input. Use this in a query param as the value with key `identifier`.

Example
package main

import (
	"fmt"

	"github.com/fhir-fli/fhirpath-go/internal/element/identifier"
	dtpb "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/datatypes_go_proto"
)

func main() {
	ident := &dtpb.Identifier{
		System: &dtpb.Uri{Value: "http://fake.com"},
		Value:  &dtpb.String{Value: "b0459744-b74b-441a-aee4-9dd97c80c642"},
	}

	search := identifier.QueryIdentifier(ident)
	fmt.Printf("identifier:exact=%s", search)
}
Output:

identifier:exact=http://fake.com|b0459744-b74b-441a-aee4-9dd97c80c642
Example (Escape)
package main

import (
	"fmt"

	"github.com/fhir-fli/fhirpath-go/internal/element/identifier"
	dtpb "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/datatypes_go_proto"
)

func main() {
	ident := &dtpb.Identifier{
		System: &dtpb.Uri{Value: "http://fake.com"},
		Value:  &dtpb.String{Value: "foo,bar|baz"},
	}

	search := identifier.QueryIdentifier(ident)
	fmt.Printf("identifier:exact=%s", search)
}
Output:

identifier:exact=http://fake.com|foo\,bar\|baz

func QueryString

func QueryString(system string, value string) string

QueryString formats a system and value for use in a Search query, escaping FHIR special characters `,|$\` in the input. Use this in a query param as the value with key `identifier`.

Example
package main

import (
	"fmt"

	"github.com/fhir-fli/fhirpath-go/internal/element/identifier"
)

func main() {
	search := identifier.QueryString("http://fake.com", "1234")
	fmt.Printf("identifier:exact=%s", search)
}
Output:

identifier:exact=http://fake.com|1234
Example (Escape)
package main

import (
	"fmt"

	"github.com/fhir-fli/fhirpath-go/internal/element/identifier"
)

func main() {
	search := identifier.QueryString("http://fake.com", `$foo|bar\baz`)
	fmt.Printf("identifier:exact=%s", search)
}
Output:

identifier:exact=http://fake.com|\$foo\|bar\\baz

func Secondary

func Secondary(value, system string, opts ...Option) *dtpb.Identifier

Secondary is a convenience constructor for forming an identifier with a "Secondary" Use-code assigned.

func Temp

func Temp(value, system string, opts ...Option) *dtpb.Identifier

Temp is a convenience constructor for forming an identifier with a "Temp" Use-code assigned.

func Update

func Update(identifier *dtpb.Identifier, opts ...Option) *dtpb.Identifier

Update modifies an identifier in-place with the given identifier options.

This function returns the input identifier to allow for functional chaining.

func Usual

func Usual(value, system string, opts ...Option) *dtpb.Identifier

Usual is a convenience constructor for forming an identifier with a "Usual" Use-code assigned.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is an abstraction for options to construct or modify Identifier elements.

func IncludeExtensions

func IncludeExtensions(ext ...*dtpb.Extension) Option

IncludeExtensions return an Identifier Option that appends the specified extensions to the Identifier.Extension field.

func WithAssigner

func WithAssigner(assigner *dtpb.Reference) Option

WithAssigner returns an Identifier Option that sets the Identifier.Assigner to the specified assigner reference.

func WithExtensions

func WithExtensions(ext ...*dtpb.Extension) Option

WithExtensions return an Identifier Option that sets the Identifier.Extension field to the specified extensions.

func WithID

func WithID(id string) Option

WithID returns an Identifier Option that sets the Identifier.Id to the specified ID.

func WithPeriod

func WithPeriod(period *dtpb.Period) Option

WithPeriod returns an Identifier Option that sets the Identifier.Period to the specified period.

func WithSystem

func WithSystem(system *dtpb.Uri) Option

WithSystem returns an Identifier Option that sets the Identifier.System to the specified system.

func WithSystemString

func WithSystemString(system string) Option

WithSystemString returns an Identifier Option that sets the Identifier.System to the specified system string.

func WithType

func WithType(ty *dtpb.CodeableConcept) Option

WithType returns an Identifier Option that sets the Identifier.Type to the specified type.

func WithUse

func WithUse(use Use) Option

WithUse returns an Identifier Option that sets the Identifier.Use to the specified use.

func WithValue

func WithValue(value string) Option

WithValue returns an Identifier Option that sets the Identifier.Value to the specified value.

type Use

Use is an alias of the Identifier Use-codes for easier access and readability.

const (
	// UseUsual is an alias of the USUAL Identifier use-code for easier access and
	// readability.
	UseUsual Use = cpb.IdentifierUseCode_USUAL

	// UseOfficial is an alias of the OFFICIAL Identifier use-code for easier access
	// and readability.
	UseOfficial Use = cpb.IdentifierUseCode_OFFICIAL

	// UseTemp is an alias of the TEMP Identifier use-code for easier access and
	// readability.
	UseTemp Use = cpb.IdentifierUseCode_TEMP

	// UseSecondary is an alias of the SECONDARY Identifier use-code for easier
	// access and readability.
	UseSecondary Use = cpb.IdentifierUseCode_SECONDARY

	// UseOld is an alias of the OLD Identifier use-code for easier access and
	// readability.
	UseOld Use = cpb.IdentifierUseCode_OLD
)

Jump to

Keyboard shortcuts

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