types

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package types holds a representation of CQL types and related logic. It is used by both the parser and interpreter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CQLTypeToProto

func CQLTypeToProto(typ IType) (*ctpb.CQLType, error)

CQLTypeToProto returns the generic CQLType proto of the CQL type.

func ToStrings

func ToStrings(ts []IType) string

ToStrings returns a print friendly representation of the types.

Types

type Choice

type Choice struct {
	ChoiceTypes []IType
}

Choice defines the type for a choice type.

func ChoiceFromProto

func ChoiceFromProto(pb *ctpb.ChoiceType) (*Choice, error)

ChoiceFromProto converts a proto to a Choice type.

func (*Choice) Equal

func (c *Choice) Equal(a IType) bool

Equal is a strict equal. X.Equal(Y) is true when X and Y are the exact same types.

func (Choice) MarshalJSON

func (c Choice) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for the Choice type.

func (*Choice) ModelInfoName

func (c *Choice) ModelInfoName() (string, error)

ModelInfoName returns name as the CQL choice type specifier with ChoiceTypes sorted.

func (*Choice) Proto

func (c *Choice) Proto() (*ctpb.ChoiceType, error)

Proto returns the proto representation of the choice type.

func (*Choice) String

func (c *Choice) String() string

String returns the model info based name for the type, and implements fmt.Stringer for easy printing.

type IType

type IType interface {

	// Equal is a strict equal. X.Equal(Y) is true when X and Y are the exact same types.
	Equal(IType) bool

	// String returns a print friendly representation of the type and implements fmt.Stringer.
	String() string

	// ModelInfoName returns the key for this type in the model info.
	//
	// For Named and System types this is the fully qualified name like FHIR.EnrollmentResponseStatus
	// or System.Integer. The name may be split in the XML (namespace="FHIR"
	// name="EnrollmentResponseStatus"), but we use the qualified name.
	//
	// For other types the CQL type specifier syntax is used as the key. For example,
	// Interval<Integer>, Choice<Integer, String> or Tuple { address String }. For Tuple and Choice types
	// we alphabetically sort their inner types.
	ModelInfoName() (string, error)

	// MarshalJSON implements the json.Marshaler interface for the IType.
	MarshalJSON() ([]byte, error)
}

IType is an interface implemented by all CQL Type structs.

func CQLTypeFromProto

func CQLTypeFromProto(pb *ctpb.CQLType) (IType, error)

CQLTypeFromProto converts the generic CQLType proto to a CQL type.

type Interval

type Interval struct {
	PointType IType
}

Interval defines the type for an interval.

func IntervalFromProto

func IntervalFromProto(pb *ctpb.IntervalType) (*Interval, error)

IntervalFromProto converts a proto to an Interval type.

func (*Interval) Equal

func (i *Interval) Equal(a IType) bool

Equal is a strict equal. X.Equal(Y) is true when X and Y are the exact same types.

func (Interval) MarshalJSON

func (i Interval) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for the Interval type.

func (*Interval) ModelInfoName

func (i *Interval) ModelInfoName() (string, error)

ModelInfoName returns name as the CQL interval type specifier.

func (*Interval) Proto

func (i *Interval) Proto() (*ctpb.IntervalType, error)

Proto returns the proto representation of the interval type.

func (*Interval) String

func (i *Interval) String() string

String returns the model info based name for the type, and implements fmt.Stringer for easy printing.

type List

type List struct {
	// The type of the elements in the list.
	ElementType IType
}

List defines the type for a list.

func ListFromProto

func ListFromProto(pb *ctpb.ListType) (*List, error)

ListFromProto converts a proto to a List type.

func (*List) Equal

func (l *List) Equal(a IType) bool

Equal is a strict equal. X.Equal(Y) is true when X and Y are the exact same types.

func (List) MarshalJSON

func (l List) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for the List type.

func (*List) ModelInfoName

func (l *List) ModelInfoName() (string, error)

ModelInfoName returns name as the CQL list type specifier.

func (*List) Proto

func (l *List) Proto() (*ctpb.ListType, error)

Proto returns the proto representation of the list type.

func (*List) String

func (l *List) String() string

String returns the model info based name for the type, and implements fmt.Stringer for easy printing.

type Named

type Named struct {
	// TypeName is the fully qualified name of the type.
	TypeName string
}

Named defines a single type by name. The name refers to a type defined by ModelInfo.

func NamedFromProto

func NamedFromProto(pb *ctpb.NamedType) (*Named, error)

NamedFromProto converts a proto to a Named type.

func (*Named) Equal

func (n *Named) Equal(a IType) bool

Equal is a strict equal. X.Equal(Y) is true when X and Y are the exact same types.

func (Named) MarshalJSON

func (n Named) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for the Named type.

func (*Named) ModelInfoName

func (n *Named) ModelInfoName() (string, error)

ModelInfoName returns the fully qualified type name in the model info convention.

func (*Named) Proto

func (n *Named) Proto() (*ctpb.NamedType, error)

Proto returns the proto representation of the named type.

func (*Named) String

func (n *Named) String() string

String returns the model info based name for the type, and implements fmt.Stringer for easy printing.

type System

type System string

System represents the primitive types defined by CQL (https://cql.hl7.org/09-b-cqlreference.html#types-2).

const (
	// Unset indicates that the parser did not set this Result Type.
	Unset System = "System.UnsetType"
	// Any is a CQL Any Type. It means that the type could be anything including list, interval,
	// named type from ModelInfo or null.
	Any System = "System.Any"
	// String is a CQL String type.
	String System = "System.String"
	// Integer is a CQL Integer type.
	Integer System = "System.Integer"
	// Decimal is a CQL Decimal type.
	Decimal System = "System.Decimal"
	// Long is a CQL Long type.
	Long System = "System.Long"
	// Quantity is a CQL decimal value and unit pair.
	Quantity System = "System.Quantity"
	// Ratio is the type for ratio - two CQL quantities.
	Ratio System = "System.Ratio"
	// Boolean is a CQL Boolean type.
	Boolean System = "System.Boolean"
	// DateTime is the CQL DateTime type.
	DateTime System = "System.DateTime"
	// Date is the CQL Date type.
	Date System = "System.Date"
	// Time is the CQL Time type.
	Time System = "System.Time"
	// ValueSet is the CQL Valueset type.
	ValueSet System = "System.ValueSet"
	// CodeSystem is a CQL CodeSystem which contains external Code definitions.
	CodeSystem System = "System.CodeSystem"
	// Vocabulary is the CQL Vocabulary type which is the parent type of ValueSet and CodeSystem.
	Vocabulary System = "System.Vocabulary"
	// Code is the CQL System Code type (which is distinct from a FHIR code type).
	Code System = "System.Code"
	// Concept is the CQL System Concept type.
	Concept System = "System.Concept"
)

func SystemFromProto

func SystemFromProto(pb *ctpb.SystemType) System

SystemFromProto converts a proto to a System type.

func ToSystem

func ToSystem(s string) System

ToSystem converts a string to a System type returning System.Unsupported if the string cannot be converted to a system type.

func (System) Equal

func (s System) Equal(a IType) bool

Equal is a strict equal. X.Equal(Y) is true when X and Y are the exact same types.

func (System) MarshalJSON

func (s System) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for the System type.

func (System) ModelInfoName

func (s System) ModelInfoName() (string, error)

ModelInfoName returns the fully qualified type name in the model info convention.

func (System) Proto

func (s System) Proto() *ctpb.SystemType

Proto returns the proto representation of the system type.

func (System) String

func (s System) String() string

String returns the model info based name for the type, and implements fmt.Stringer for easy printing.

type Tuple

type Tuple struct {
	// ElementTypes is a map from element name to its type.
	ElementTypes map[string]IType
}

Tuple defines the type for a tuple (aka Structured Value).

func TupleFromProto

func TupleFromProto(pb *ctpb.TupleType) (*Tuple, error)

TupleFromProto converts a proto to a Tuple type.

func (*Tuple) Equal

func (t *Tuple) Equal(a IType) bool

Equal is a strict equal. X.Equal(Y) is true when X and Y are the exact same types.

func (Tuple) MarshalJSON

func (t Tuple) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for the Tuple type.

func (*Tuple) ModelInfoName

func (t *Tuple) ModelInfoName() (string, error)

ModelInfoName returns name as the CQL tuple type specifier with ElementTypes sorted by name.

func (*Tuple) Proto

func (t *Tuple) Proto() (*ctpb.TupleType, error)

Proto returns the proto representation of the tuple type.

func (*Tuple) String

func (t *Tuple) String() string

String returns the model info based name for the type, and implements fmt.Stringer for easy printing.

Jump to

Keyboard shortcuts

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