fhirconv

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package fhirconv provides conversion utilities to Go-native types from FHIR R4 Elements.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIntegerTruncated is an error raised when an integer truncation occurs
	// during integer conversion
	ErrIntegerTruncated = errors.New("integer truncation")
)

Functions

func DateTimeToString

func DateTimeToString(val *dtpb.DateTime) string

DateTimeToString converts the FHIR DateTime element into its string reprsentation as defined in http://hl7.org/fhir/R4/datatypes.html#datetime.

The level of precision in the output is equivalent to the precision defined in the input DateTime proto.

func DateTimeToTime

func DateTimeToTime(dt *dtpb.DateTime) (time.Time, error)

DateTimeToTime converts a FHIR DateTime element into a Go time.Time value.

This function will only error if the TimeZone field is invalid.

Note: the error that can be returned from this function is unlikely to actually occur in practice. FHIR Timezones are always required to be specified in the form `+zz:zz` or `-zz:zz` -- and the JSON conversion translates this into exactly this form, an empty string, or "UTC" in some cases. These are all valid locations and should never fail as a result.

func DateToString

func DateToString(val *dtpb.Date) string

DateToString converts the FHIR Date element into its string reprsentation as defined in http://hl7.org/fhir/R4/datatypes.html#date.

The level of precision in the output is equivalent to the precision defined in the input Date proto.

func DateToTime

func DateToTime(dt *dtpb.Date) (time.Time, error)

DateToTime converts a FHIR Date element into a Go time.Time value.

This function will only error if the TimeZone field is invalid.

Note: the error that can be returned from this function is unlikely to actually occur in practice. FHIR Timezones are always required to be specified in the form `+zz:zz` or `-zz:zz` -- and the JSON conversion translates this into exactly this form, an empty string, or "UTC" in some cases. These are all valid locations and should never fail as a result.

func DurationToDuration

func DurationToDuration(d *dtpb.Duration) (time.Duration, error)

DurationToDuration converts a FHIR Duration element into a Go native time.Duration object.

This function may return an error in the following conditions:

  • The underlying Decimal value is not able to be parsed into a float64
  • The unit is not a valid time unit

func InstantToString

func InstantToString(val *dtpb.Instant) string

InstantToString converts the FHIR Instant element into its string reprsentation as defined in http://hl7.org/fhir/R4/datatypes.html#instant.

The level of precision in the output is equivalent to the precision defined in the input Instant proto.

func InstantToTime

func InstantToTime(dt *dtpb.Instant) (time.Time, error)

InstantToTime converts a FHIR Instant element into a Go time.Time value.

This function will only error if the TimeZone field is invalid.

Note: the error that can be returned from this function is unlikely to actually occur in practice. FHIR Timezones are always required to be specified in the form `+zz:zz` or `-zz:zz` -- and the JSON conversion translates this into exactly this form, an empty string, or "UTC" in some cases. These are all valid locations and should never fail as a result.

func MustConvertToInteger

func MustConvertToInteger[To constraints.Integer, From integerType](v From) To

MustConvertToInteger converts a FHIR Integer type into a Go native integer type.

If the value stored in the integer type cannot fit into the receiver type, this function will panic.

func TimeToDuration

func TimeToDuration(dt *dtpb.Time) time.Duration

TimeToDuration converts a FHIR Time element into a Go time.Duration value.

Despite the name `Time` for the FHIR Element, the time is not actually associated to any real date -- and thus does not correspond to a distinct chronological point, and thus cannot be converted logically into a `time.Time` object.

func TimeToString

func TimeToString(val *dtpb.Time) string

TimeToString converts the FHIR Time element into its string reprsentation as defined in http://hl7.org/fhir/R4/datatypes.html#time.

The level of precision in the output is equivalent to the precision defined in the input Time proto.

func ToInt

func ToInt[From integerType](v From) (int, error)

ToInt converts a FHIR Integer type into a Go native int.

func ToInt16

func ToInt16[From integerType](v From) (int16, error)

ToInt16 converts a FHIR Integer type into a Go native int16.

func ToInt32

func ToInt32[From integerType](v From) (int32, error)

ToInt32 converts a FHIR Integer type into a Go native int32.

func ToInt64

func ToInt64[From integerType](v From) (int64, error)

ToInt64 converts a FHIR Integer type into a Go native int64.

func ToInt8

func ToInt8[From integerType](v From) (int8, error)

ToInt8 converts a FHIR Integer type into a Go native int8.

func ToInteger

func ToInteger[To constraints.Integer, From integerType](v From) (To, error)

ToInteger converts a FHIR Integer type into a Go native integer type.

If the value of the integer does not fit into the receiver integer type, this function will return an ErrIntegerTruncated.

func ToString

func ToString[T fhir.PrimitiveType](val T) string

ToString converts a basic FHIR Primitive into a human-readable string representation.

func ToUint

func ToUint[From integerType](v From) (uint, error)

ToUint converts a FHIR Integer type into a Go native uint.

func ToUint16

func ToUint16[From integerType](v From) (uint16, error)

ToUint16 converts a FHIR Integer type into a Go native uint16.

func ToUint32

func ToUint32[From integerType](v From) (uint32, error)

ToUint32 converts a FHIR Integer type into a Go native uint32.

func ToUint64

func ToUint64[From integerType](v From) (uint64, error)

ToUint64 converts a FHIR Integer type into a Go native uint64.

func ToUint8

func ToUint8[From integerType](v From) (uint8, error)

ToUint8 converts a FHIR Integer type into a Go native uint8.

Types

This section is empty.

Jump to

Keyboard shortcuts

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