Documentation ¶
Overview ¶
Package fhirconv provides conversion utilities to Go-native types from FHIR R4 Elements.
Index ¶
- Variables
- func DateTimeToString(val *dtpb.DateTime) string
- func DateTimeToTime(dt *dtpb.DateTime) (time.Time, error)
- func DateToString(val *dtpb.Date) string
- func DateToTime(dt *dtpb.Date) (time.Time, error)
- func DurationToDuration(d *dtpb.Duration) (time.Duration, error)
- func InstantToString(val *dtpb.Instant) string
- func InstantToTime(dt *dtpb.Instant) (time.Time, error)
- func MustConvertToInteger[To constraints.Integer, From integerType](v From) To
- func TimeToDuration(dt *dtpb.Time) time.Duration
- func TimeToString(val *dtpb.Time) string
- func ToInt[From integerType](v From) (int, error)
- func ToInt16[From integerType](v From) (int16, error)
- func ToInt32[From integerType](v From) (int32, error)
- func ToInt64[From integerType](v From) (int64, error)
- func ToInt8[From integerType](v From) (int8, error)
- func ToInteger[To constraints.Integer, From integerType](v From) (To, error)
- func ToString[T fhir.PrimitiveType](val T) string
- func ToUint[From integerType](v From) (uint, error)
- func ToUint16[From integerType](v From) (uint16, error)
- func ToUint32[From integerType](v From) (uint32, error)
- func ToUint64[From integerType](v From) (uint64, error)
- func ToUint8[From integerType](v From) (uint8, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrIntegerTruncated is an error raised when an integer truncation occurs // during integer conversion ErrIntegerTruncated = errors.New("integer truncation") )
Functions ¶
func DateTimeToString ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 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.
Types ¶
This section is empty.