x12

package module
v0.0.0-...-1bc6f5a Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: MIT Imports: 5 Imported by: 0

README

x12

Go Reference

x12 is a Go library for handling EDI x12 documents.

Features

  • Decoding
  • Validation
  • Encoding (Marshaling)

Contributing

We welcome contributions to x12! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.

License

x12 is released under the MIT License.

$ go run ./examples/basics/basics.go
{
    "Interchange": {
        "Header": {
            "AuthorizationInfoQualifier": "00",
            "AuthorizationInformation": "          ",
            "SecurityInfoQualifier": "00",
            "SecurityInfo": "          ",
            "InterchangeSenderIDQualifier": "08",
            "InterchangeSenderID": "9254110060     ",
            "InterchangeReceiverIDQualifier": "ZZ",
            "InterchangeReceiverID": "123456789      ",
            "InterchangeDate": "041216",
            "InterchangeTime": "0805",
            "InterchangeControlStandardsID": "U",
            "InterchangeControlVersion": "00501",
            "InterchangeControlNumber": "000095071",
            "AcknowledgmentRequested": "0",
            "UsageIndicator": "P",
            "ComponentElementSeparator": "\u003e"
        },
        "FunctionGroups": [
            {
                "Header": {
                    "FunctionalIDCode": "AG",
                    "ApplicationSenderCode": "5137624388",
                    "ApplicationReceiverCode": "123456789",
                    "Date": "20041216",
                    "Time": "0805",
                    "GroupControlNumber": "95071",
                    "ResponsibleAgencyCode": "X",
                    "VersionReleaseIndustryID": "005010"
                },
                "Transactions": [
                    {
                        "Header": {
                            "TransactionSetIDCode": "824",
                            "TransactionSetControlNumber": "021390001"
                        },
                        "Segments": [
                            {
                                "ID": "BGN",
                                "Elements": [
                                    {
                                        "ID": "01",
                                        "Value": "11"
                                    },
                                    {
                                        "ID": "02",
                                        "Value": "FFA.ABCDEF.123456"
                                    },
                                    {
                                        "ID": "03",
                                        "Value": "20020709"
                                    },
                                    {
                                        "ID": "04",
                                        "Value": "0932"
                                    },
                                    {
                                        "ID": "05",
                                        "Value": ""
                                    },
                                    {
                                        "ID": "06",
                                        "Value": "123456789"
                                    },
                                    {
                                        "ID": "07",
                                        "Value": ""
                                    },
                                    {
                                        "ID": "08",
                                        "Value": "WQ"
                                    }
                                ]
                            },
                            {
                                "ID": "N1",
                                "Elements": [
                                    {
                                        "ID": "01",
                                        "Value": "41"
                                    },
                                    {
                                        "ID": "02",
                                        "Value": "ABC INSURANCE"
                                    },
                                    {
                                        "ID": "03",
                                        "Value": "46"
                                    },
                                    {
                                        "ID": "04",
                                        "Value": "111111111"
                                    }
                                ]
                            },
                            {
                                "ID": "PER",
                                "Elements": [
                                    {
                                        "ID": "01",
                                        "Value": "IC"
                                    },
                                    {
                                        "ID": "02",
                                        "Value": "JOHN JOHNSON"
                                    },
                                    {
                                        "ID": "03",
                                        "Value": "TE"
                                    },
                                    {
                                        "ID": "04",
                                        "Value": "8005551212"
                                    },
                                    {
                                        "ID": "05",
                                        "Value": "EX"
                                    },
                                    {
                                        "ID": "06",
                                        "Value": "1439"
                                    }
                                ]
                            },
                            {
                                "ID": "N1",
                                "Elements": [
                                    {
                                        "ID": "01",
                                        "Value": "40"
                                    },
                                    {
                                        "ID": "02",
                                        "Value": "SMITHCO"
                                    },
                                    {
                                        "ID": "03",
                                        "Value": "46"
                                    },
                                    {
                                        "ID": "04",
                                        "Value": "A1234"
                                    }
                                ]
                            },
                            {
                                "ID": "OTI",
                                "Elements": [
                                    {
                                        "ID": "01",
                                        "Value": "TA"
                                    },
                                    {
                                        "ID": "02",
                                        "Value": "TN"
                                    },
                                    {
                                        "ID": "03",
                                        "Value": "NA"
                                    },
                                    {
                                        "ID": "04",
                                        "Value": ""
                                    },
                                    {
                                        "ID": "05",
                                        "Value": ""
                                    },
                                    {
                                        "ID": "06",
                                        "Value": "20020709"
                                    },
                                    {
                                        "ID": "07",
                                        "Value": "0902"
                                    },
                                    {
                                        "ID": "08",
                                        "Value": "2"
                                    },
                                    {
                                        "ID": "09",
                                        "Value": "0001"
                                    },
                                    {
                                        "ID": "10",
                                        "Value": "834"
                                    },
                                    {
                                        "ID": "11",
                                        "Value": "005010X220A1"
                                    }
                                ]
                            }
                        ],
                        "Trailer": {
                            "NumberOfIncludedSegments": "7",
                            "TransactionSetControlNumber": "021390001"
                        }
                    }
                ],
                "Trailer": {
                    "NumberOfIncludedTransactionSets": "1",
                    "GroupControlNumber": "95071"
                }
            }
        ],
        "Trailer": {
            "NumberOfIncludedFunctionalGroups": "1",
            "InterchangeControlNumber": "000095071"
        }
    }
}

Documentation

Overview

Package x12 implements a parser and encoder for the ANSI X12 EDI format.

It focuses on the 5010 version of the format, but is flexible such that it can be used for other versions as well.

Index

Constants

View Source
const (
	// SegmentSeparator is the character that separates segments.
	SegmentSeparator = "~"
	// ElementSeparator is the character that separates elements.
	ElementSeparator = "*"
	// SubElementSeparator is the character that separates sub-elements.
	SubElementSeparator = ":"
)

Variables

View Source
var (
	ErrMissingElement  = errors.New("missing element")
	ErrInvalidFormat   = errors.New("invalid format")
	ErrInvalidArgument = errors.New("invalid argument")
)

Functions

This section is empty.

Types

type DecodeOption

type DecodeOption func(*decodeState)

DecodeOption is a function that can be used to configure the decoder.

func WithRelaxedSegmentIDWhitespace

func WithRelaxedSegmentIDWhitespace() DecodeOption

WithRelaxedSegmentIDWhitespace allows the decoder to accept segment IDs with leading and trailing whitespace.

type Element

type Element struct {
	ID         string
	Value      string
	Components []string `json:",omitempty"`
}

Element is a single element. An element is a single value in a segment.

type FunctionGroup

type FunctionGroup struct {
	Header       *GS
	Transactions []*Transaction
	Trailer      *GE
}

FunctionGroup is a group of transactions.

type GE

type GE struct {
	NumberOfIncludedTransactionSets string
	GroupControlNumber              string
}

GE is the Functional Group Trailer.

type GS

type GS struct {
	FunctionalIDCode         string
	ApplicationSenderCode    string
	ApplicationReceiverCode  string
	Date                     string
	Time                     string
	GroupControlNumber       string
	ResponsibleAgencyCode    string
	VersionReleaseIndustryID string
}

GS is the Functional Group Header.

type IEA

type IEA struct {
	NumberOfIncludedFunctionalGroups string
	InterchangeControlNumber         string
}

IEA is the Interchange Control Trailer.

type ISA

type ISA struct {
	AuthorizationInfoQualifier     string
	AuthorizationInformation       string
	SecurityInfoQualifier          string
	SecurityInfo                   string
	InterchangeSenderIDQualifier   string
	InterchangeSenderID            string
	InterchangeReceiverIDQualifier string
	InterchangeReceiverID          string
	InterchangeDate                string
	InterchangeTime                string
	InterchangeControlStandardsID  string
	InterchangeControlVersion      string
	InterchangeControlNumber       string
	AcknowledgmentRequested        string
	UsageIndicator                 string
	ComponentElementSeparator      string
}

ISA is the Interchange Control Headera.

type Interchange

type Interchange struct {
	Header         *ISA
	FunctionGroups []*FunctionGroup
	Trailer        *IEA
}

Interchange is the envelope for an X12 interchange.

type Marshaler

type Marshaler struct {
	SegmentSeparator    string
	ElementSeparator    string
	SubElementSeparator string

	NewLines bool
}

func (*Marshaler) Marshal

func (m *Marshaler) Marshal(x *X12Document) ([]byte, error)

type SE

type SE struct {
	NumberOfIncludedSegments    string
	TransactionSetControlNumber string
}

SE is the Transaction Set Trailer.

type ST

type ST struct {
	TransactionSetIDCode              string
	TransactionSetControlNumber       string
	ImplementationConventionReference string
}

ST is the Transaction Set Header.

type Segment

type Segment struct {
	ID       string
	Elements []Element
}

Segment is a single segment. A segment is a single line of an X12 document.

type Transaction

type Transaction struct {
	Header   *ST
	Segments []Segment
	Trailer  *SE
}

Transaction is a single transaction.

type X12Document

type X12Document struct {
	Interchange *Interchange

	// EnvelopeAutomaticallyAdded is true if the envelope was automatically added to a decoded document.
	// This may be the case if the document was decoded from a file that did not contain an ISA/IEA envelope.
	EnvelopeAutomaticallyAdded bool
}

X12Document is the root element of an X12 document.

func Decode

func Decode(in io.Reader, opts ...DecodeOption) (*X12Document, error)

Decode decodes an X12 document from an io.Reader

func (*X12Document) Validate

func (doc *X12Document) Validate() error

Validate validates the x12 document

Directories

Path Synopsis
examples
basics command

Jump to

Keyboard shortcuts

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