generator

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package generator provides code generation tools for creating version-specific HL7v2 Go structures from schema specifications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommentLines

func CommentLines(s string) string

CommentLines formats a multi-line string into Go comment lines prefixed with //.

func PackageName

func PackageName(ver string) string

PackageName converts a version string like "v2.5.1" into a Go package name like "v251".

func SanitizeIdentifier

func SanitizeIdentifier(s string) string

SanitizeIdentifier cleans and formats a raw string into a valid exported Go identifier.

Types

type DatatypeFieldModel

type DatatypeFieldModel struct {
	GoName      string
	GoType      string
	Tag         string
	ParamType   string
	InitExpr    string
	MethodName  string
	IsRequired  bool
	IsPrimitive bool
	IsSlice     bool
}

DatatypeFieldModel holds template data for a field within a data type.

type DatatypeModel

type DatatypeModel struct {
	ID          string
	Name        string
	Description string
	IsPrimitive bool
	Fields      []DatatypeFieldModel
}

DatatypeModel holds template data for an HL7v2 data type definition.

type DatatypesFileData

type DatatypesFileData struct {
	PackageName         string
	Datatypes           []DatatypeModel
	HasComplexDatatypes bool
}

DatatypesFileData holds template rendering data for a datatypes.go file.

type Deduper

type Deduper struct {
	// contains filtered or unexported fields
}

Deduper tracks generated struct field and type names to avoid name collisions.

func NewDeduper

func NewDeduper() *Deduper

NewDeduper creates a new Deduper instance.

func (*Deduper) Name

func (d *Deduper) Name(raw string) string

Name generates a sanitized, unique Go identifier for a raw string name.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator handles code generation for a specific HL7v2 version schema.

func New

func New(ver string, opts ...Option) (*Generator, error)

New creates a new Generator for the specified HL7v2 version string and options.

func (*Generator) GenerateAll

func (g *Generator) GenerateAll(outputBase string) error

GenerateAll generates all Go source files for the configured version under outputBase.

func (*Generator) GenerateDatatypes

func (g *Generator) GenerateDatatypes(targetDir, pkgName string) error

GenerateDatatypes generates the datatypes.go file for a target directory and package.

func (*Generator) GenerateMessageTests

func (g *Generator) GenerateMessageTests(targetDir, pkgName string) error

GenerateMessageTests generates the messages_test.go file for a target directory and package.

func (*Generator) GenerateMessages

func (g *Generator) GenerateMessages(targetDir, pkgName string) error

GenerateMessages generates the messages.go file for a target directory and package.

func (*Generator) GenerateRegistry

func (g *Generator) GenerateRegistry(targetDir, pkgName string) error

GenerateRegistry generates the registry.go file for a target directory and package.

func (*Generator) GenerateSegments

func (g *Generator) GenerateSegments(targetDir, pkgName string) error

GenerateSegments generates the segments.go file for a target directory and package.

func (*Generator) GenerateTables

func (g *Generator) GenerateTables(targetDir, pkgName string) error

GenerateTables generates the tables.go file for a target directory and package.

type GroupModel

type GroupModel struct {
	StructName string
	Fields     []MessageFieldModel
}

GroupModel holds template data for a message group structure.

type MSHInitModel

type MSHInitModel struct {
	FieldSeparatorName     string
	EncodingCharactersName string
	DateTimeName           string
	DateTimeExpr           string
	MessageTypeName        string
	MessageTypeParamType   string
	MessageControlIDName   string
	ProcessingIDName       string
	ProcessingIDExpr       string
	VersionIDName          string
	VersionIDExpr          string
}

MSHInitModel holds template data for MSH segment initialization logic.

type MessageFieldModel

type MessageFieldModel struct {
	GoName     string
	GoType     string
	Tag        string
	IsSlice    bool
	IsRequired bool
	ElemType   string
	MethodName string
}

MessageFieldModel holds template data for a field within a message.

type MessageModel

type MessageModel struct {
	ID          string
	Name        string
	Description string
	Groups      []GroupModel
	Fields      []MessageFieldModel
	MSHInitExpr string
}

MessageModel holds template data for an HL7v2 message definition.

type MessageTestsFileData

type MessageTestsFileData struct {
	PackageName string
	Version     string
}

MessageTestsFileData holds template rendering data for a messages_test.go file.

type MessagesFileData

type MessagesFileData struct {
	PackageName string
	Messages    []MessageModel
}

MessagesFileData holds template rendering data for a messages.go file.

type Option

type Option func(*Options)

Option defines a functional option for configuring Options.

func WithTemplate

func WithTemplate(t SpecType, templ ...*template.Template) Option

WithTemplate returns an Option that adds custom templates for a SpecType.

type Options

type Options struct {
	Templates map[SpecType][]*template.Template
}

Options configures code generation parameters.

func NewOptions

func NewOptions(opts ...Option) *Options

NewOptions constructs an Options instance by applying option functions.

type ParamDeduper

type ParamDeduper struct {
	// contains filtered or unexported fields
}

ParamDeduper manages parameter name deduplication.

func NewParamDeduper

func NewParamDeduper() *ParamDeduper

NewParamDeduper creates a new ParamDeduper instance.

func (*ParamDeduper) Name

func (d *ParamDeduper) Name(raw string) string

Name returns a unique parameter name by appending a numeric suffix if repeated.

type RegistryFileData

type RegistryFileData struct {
	PackageName string
	VersionEnum string
}

RegistryFileData holds template rendering data for a registry.go file.

type SegmentFieldModel

type SegmentFieldModel struct {
	GoName      string
	GoType      string
	Tag         string
	IsSlice     bool
	IsPrimitive bool
	IsRequired  bool
	ElemType    string
	MethodName  string
}

SegmentFieldModel holds template data for a field within a segment.

type SegmentModel

type SegmentModel struct {
	ID          string
	Name        string
	Description string
	Fields      []SegmentFieldModel
	IsMSH       bool
	MSHInit     MSHInitModel
}

SegmentModel holds template data for an HL7v2 segment definition.

type SegmentsFileData

type SegmentsFileData struct {
	PackageName string
	Segments    []SegmentModel
}

SegmentsFileData holds template rendering data for a segments.go file.

type SpecType

type SpecType int

SpecType represents the type of HL7v2 schema specification entity.

const (
	// SpecTypeUnknown indicates an unspecified schema entity type.
	SpecTypeUnknown SpecType = iota
	// SpecTypeDatatype indicates a data type schema entity.
	SpecTypeDatatype
	// SpecTypeTable indicates a table schema entity.
	SpecTypeTable
	// SpecTypeSegment indicates a segment schema entity.
	SpecTypeSegment
	// SpecTypeMessage indicates a message schema entity.
	SpecTypeMessage
)

type TableEntryModel

type TableEntryModel struct {
	ConstName          string
	Value              string
	Description        string
	DescriptionEscaped string
	Comment            string
}

TableEntryModel holds template data for an entry within a table.

type TableModel

type TableModel struct {
	ID          string
	TypeName    string
	Name        string
	Description string
	Entries     []TableEntryModel
}

TableModel holds template data for an HL7v2 table definition.

type TablesFileData

type TablesFileData struct {
	PackageName string
	Tables      []TableModel
	HasIS       bool
	HasID       bool
	HasST       bool
	HasCE       bool
	HasCWE      bool
	HasCNE      bool
}

TablesFileData holds template rendering data for a tables.go file.

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template wraps a parsed text template associated with a SpecType.

func NewTemplate

func NewTemplate(typ SpecType, t *template.Template, output string) *Template

NewTemplate creates a new Template instance for a SpecType and output name.

func ParseTemplate

func ParseTemplate(typ SpecType, name, content, output string) (*Template, error)

ParseTemplate parses a template content string and returns a new Template.

func ReadTemplate

func ReadTemplate(typ SpecType, path, output string) (*Template, error)

ReadTemplate reads and parses a template file from disk.

func ReadTemplateFS

func ReadTemplateFS(typ SpecType, fs fs.FS, output string) (*Template, error)

ReadTemplateFS reads and parses a template file from a filesystem.

Jump to

Keyboard shortcuts

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