NAME

X12::Parser - Perl extension for parsing X12 Transaction files

SYNOPSIS

use X12::Parser;

# Create a parser object my $p = new X12::Parser;

# Parse a file with the transaction specific configuration file $p->parse ( file => '837.txt', conf => 'X12-837P.cf' );

# Step through the file while ( my $loop = $p->get_next_loop ) { my @loop = $p->get_loop_segments ($loop); }

# or use this method instead while ( my ($pos, $loop) = $p->get_next_pos_loop ) { my @loop = $p->get_segments ($pos); }

# or use while ( my ($pos, $level, $loop) = $p->get_next_pos_level_loop ) { my @loop = $p->get_segments ($pos); }

ABSTRACT

X12::Parser package provides a efficient way to parse X12 transaction files. Although this packages is built keeping HIPAA related X12 transactions in mind, it is flexible and can be adapted to any X12 or similar transactions.

DESCRIPTION

The X12::Parser is a token based parser for parsing X12 transaction files. The parsing of transaction files requires the presence of configuration files for the different transaction types.

The following methods are available:

$p = new X12::Parser; This is the object constructor method. It does not take any arguments. It only initializes the members variables required for parsing the transaction file.

$p->parse ( file => '837.txt', conf => 'X12-837P.cf' ); This method takes two arguments. The first argument is the transaction file which needs to be parsed. The second argument specifies the configuration file to be used for parsing the transaction file.

   This package is a generic parser for parsing files which use a
   format similar to the X12 specification. The ability to parse
   different transaction types is provided by means of using different
   configuration files. The configuration files for all the X12 HIPAA
   transactions are provided with this package.

   To create your own configuration file read the X12::Parser::Readme 
   man page.

$p->get_next_loop (); This function returns the next loop name for the transaction file which is being parsed. The loop name is as specified in the cf file.

$p->get_loop_segments ($loop); Pass the loop name returned by get_next_loop() to obtain the segments in this loop. This function is to be used in tandem with the get_next_loop. If not it may return/produce undesired results. get_next_loop() and get_loop_segments() internally keep record of the current loop position, so get_loop_segments will return the current loop segments even if you do not pass the loop name.

$p->get_next_pos_loop (); This function returns the next loop name and the loop position. Note 0 corresponds to the first segment.

$p->get_next_pos_level_loop (); Same as get_next_pos_loop() except that in addition this function returns the level of the loop. The level corresponds to the level of the loop in the loop hierarchy. The top level loop has level 1.

$p->get_segments ($pos); get_segments returns an array of segments in the loop starting at position $pos. If the specified position does not correspond to a loop, the function returns the segment at position $pos.

$p->reset_pos (); Resets the pointer used by get_next_* functions. This causes the get_next_* functions to start parsing again from the begining of the file.

$p->print_tree; prints the transaction file in a tree format.

The configuration files provided with this package and the corresponding transaction type is mentioned below. These are the X12 HIPAA transactions.

            type    configuration file
            ----    ------------------    
        1)   270    270_004010X092.cf
        2)   271    271_004010X092.cf
        3)   276    276_004010X093.cf
        4)   277    277_004010X092.cf
        5)   278    278_004010X094_Req.cf
        6)   278    278_004010X094_Res.cf
        7)   820    820_004010X061.cf
        8)   834    834_004010X095.cf
        9)   835    835_004010X091.cf
        10)  837I   837_004010X096.cf
        11)  837D   837_004010X097.cf
        12)  837P   837_004010X098.cf

These cf files are installed in under the X12/Parser/cf folder.

The sample cf files provided with this package are good to the best of the authors knowledge. However the user should ensure the validity of these files. The user may use them as is at his own risk.

EXPORT

None by default.

SEE ALSO

o For details on Transaction sets refer to: National Electronic Data Interchange Transaction Set Implementation Guide. Implementation guides are available for all the Transaction sets.

o X12::Parser::Readme for more information on the Parser and configuration files.

o X12::Parser::Cf

If you have a mailing list set up for your module, mention it here.

If you have a web site set up for your module, mention it here.

AUTHOR

Prasad Poruporuthan, <pprasadb@planet-save.com<gt>

COPYRIGHT AND LICENSE

Copyright 2003 by Prasad Poruporuthan

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.