x12 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Chris Parker <chris.p@adelpo.com>, <mrcsparker@gmail.com>
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README ADDED
@@ -0,0 +1,31 @@
1
+ == Ruby EDI X12 Parser
2
+
3
+ == General Information
4
+
5
+ This is a direct port of Prasad Poruporuthan's X12::Parser Perl
6
+ library for Ruby. Being the very first version, and pretty much
7
+ a direct translation, it has more Perlisms than Rubyisms.
8
+
9
+ There is no real documentation right now, or unit tests. If you need
10
+ to use the library, the best resource is:
11
+
12
+ http://search.cpan.org/~prasad/X12/Readme.pod
13
+
14
+ It works pretty much the same way right now.
15
+
16
+ == How you can help
17
+ Read the TODO document. There are some things that this library could use, but
18
+ I am not going to implements any time soon:
19
+ * to_xml output
20
+ * to_yaml output
21
+ * anything else that you can think of.
22
+ I am not looking to map 100% of any of the X12 specifications.
23
+
24
+ Also, I don't have access to the full ANSI X12 documents.
25
+
26
+ == License
27
+ GNU LGPL, http://www.gnu.org/copyleft/lesser.html
28
+
29
+ == Credits
30
+ This code is pretty much directly translated from Prasad Poruporuthan's X12::Parser Perl
31
+ library. The Perl library project is located at http://search.cpan.org/~prasad/X12/
@@ -0,0 +1,91 @@
1
+ require "rake/rdoctask"
2
+ require "rake/testtask"
3
+ require "rake/gempackagetask"
4
+
5
+ X12_VERSION = "0.1.0"
6
+
7
+ begin
8
+ require "rubygems"
9
+ rescue LoadError
10
+ nil
11
+ end
12
+
13
+ task :default => [:test]
14
+
15
+ Rake::TestTask.new do |test|
16
+ test.libs << "test"
17
+ test.test_files = Dir[ "test/*_test.rb" ]
18
+ test.verbose = true
19
+ end
20
+
21
+ spec = Gem::Specification.new do |spec|
22
+ spec.name = "x12"
23
+ spec.version = X12_VERSION
24
+ spec.platform = Gem::Platform::RUBY
25
+ spec.summary = "A generalized Ruby EDI x12 parsing engine."
26
+ spec.files = Dir.glob("{cf,examples,lib,test,bin,util/bench}/**/**/*") +
27
+ ["Rakefile"]
28
+ spec.require_path = "lib"
29
+
30
+ spec.test_files = Dir[ "test/*_test.rb" ]
31
+ spec.has_rdoc = true
32
+ spec.extra_rdoc_files = %w{README LICENSE AUTHORS TODO}
33
+ spec.rdoc_options << '--title' << 'x12 Documentation' <<
34
+ '--main' << 'README' << '-q'
35
+ spec.author = "Chris Parker"
36
+ spec.email = "chris.p@adelpo.com, mrcsparker@gmail.com"
37
+ spec.rubyforge_project = "x12-parser"
38
+ spec.homepage = "http://rubyforge.org/projects/x12-parser/"
39
+ spec.description = <<END_DESC
40
+ EDI x12 is a standard format for parsing and reading
41
+ Invoices, Orders, etc. This library makes that easier.
42
+ END_DESC
43
+ end
44
+
45
+ Rake::RDocTask.new do |rdoc|
46
+ rdoc.rdoc_files.include( "README",
47
+ #"CHANGELOG",
48
+ "AUTHORS", "COPYING",
49
+ "LICENSE", "lib/" )
50
+ rdoc.main = "README"
51
+ rdoc.rdoc_dir = "doc/html"
52
+ rdoc.title = "x12 Documentation"
53
+ end
54
+
55
+ Rake::GemPackageTask.new(spec) do |pkg|
56
+ pkg.need_zip = true
57
+ pkg.need_tar = true
58
+ end
59
+
60
+ task :build_archives => [:package,:rcov,:rdoc] do
61
+ mv "pkg/x12-#{x12_VERSION}.tgz", "pkg/x12-#{x12_VERSION}.tar.gz"
62
+ sh "tar cjvf pkg/x12_coverage-#{x12_VERSION}.tar.bz2 coverage"
63
+ sh "tar cjvf pkg/x12_doc-#{x12_VERSION}.tar.bz2 doc/html"
64
+ cd "pkg"
65
+ sh "tar cjvf x12-#{X12_VERSION}.tar.bz2 x12-#{x12_VERSION}"
66
+ end
67
+
68
+ task :run_benchmarks do
69
+ files = FileList["util/bench/**/**/*.rb"]
70
+ files.sort!
71
+ files.uniq!
72
+ names = files.map { |r| r.sub("util/bench","").split("/").map { |e| e.capitalize } }
73
+ names.map! { |e| e[1..-2].join("::") + " <BENCH: #{e[-1].sub('Bench_','').sub('.rb','')}>" }
74
+ start_time = Time.now
75
+ files.zip(names).each { |f,n|
76
+ puts "\n#{n}\n\n"
77
+ sh "ruby -Ilib #{f}"
78
+ puts "\n"
79
+ }
80
+ end_time = Time.now
81
+ puts "\n** Total Run Time: #{end_time-start_time}s **"
82
+ end
83
+
84
+ begin
85
+ require 'rcov/rcovtask'
86
+ Rcov::RcovTask.new do |t|
87
+ t.test_files = Dir[ "test/*_test.rb" ]
88
+ end
89
+ rescue LoadError
90
+ nil
91
+ end
data/TODO ADDED
@@ -0,0 +1,4 @@
1
+ * Create unit tests
2
+ * Use YAML rather than the current configuration file format.
3
+ * Have the parser understand Header, Detail, and Summary sections of the EDI document.
4
+ * Create a to_csv method that flattens out the EDI X12 data.
@@ -0,0 +1,111 @@
1
+ [LOOPS]
2
+ ISA
3
+ GS
4
+ ST
5
+ 2000A
6
+ 2000B
7
+ 2000C
8
+ 2000D
9
+ SE
10
+ GE
11
+ IEA
12
+
13
+ #--- start of loop details ---#
14
+
15
+ [ISA]
16
+ segment=ISA:::ISA:R:1
17
+
18
+ [GS]
19
+ segment=GS:::GS:R:1
20
+
21
+ #LOOP ID - HEADER
22
+ [ST]
23
+ segment=ST:::Transaction Set Header:R:1
24
+ segment=BHT:::Beginning of Hierarchical Transaction:R:1
25
+
26
+ #LOOP ID - 2000A INFORMATION SOURCE LEVEL >1
27
+ [2000A]
28
+ segment=HL:3:20:Information Source Level:R:1
29
+ loop=2100A
30
+
31
+ #LOOP ID - 2100A INFORMATION SOURCE NAME 1
32
+ [2100A]
33
+ segment=NM1:1:2B,36,GP,P5,PR:Information Source Name:R:1
34
+
35
+ #LOOP ID - 2000B INFORMATION RECEIVER LEVEL >1
36
+ [2000B]
37
+ segment=HL:3:21:Information Receiver Level:R:1
38
+ loop=2100B
39
+
40
+ #LOOP ID - 2100B INFORMATION RECEIVER NAME 1
41
+ [2100B]
42
+ segment=NM1:1:1P,2B,36,80,FA,GP,P5,PR:Information Receiver Name:R:1
43
+ segment=REF:::Information Receiver Additional Identification:S:9
44
+ segment=N3:::Information Receiver Address:S:1
45
+ segment=N4:::Information Receiver City/State/ZIP Code:S:1
46
+ segment=PER:::Information Receiver Contact Information:S:3
47
+ segment=PRV:::Information Receiver Provider Information:S:1
48
+
49
+ #LOOP ID - 2000C SUBSCRIBER LEVEL >1
50
+ [2000C]
51
+ segment=HL:3:22:Subscriber Level:R:1
52
+ segment=TRN:::Subscriber Trace Number:S:2
53
+ loop=2100C
54
+
55
+ #LOOP ID - 2100C SUBSCRIBER NAME 1
56
+ [2100C]
57
+ segment=NM1:1:IL:Subscriber Name:R:1
58
+ segment=REF:::Subscriber Additional Identification:S:9
59
+ segment=N3:::Subscriber Address:S:1
60
+ segment=N4:::Subscriber City/State/ZIP Code:S:1
61
+ segment=PRV:::Provider Information:S:1
62
+ segment=DMG:::Subscriber Demographic Information:S:1
63
+ segment=INS:::Subscriber Relationship:S:1
64
+ segment=DTP:::Subscriber Date:S:2
65
+ loop=2110C
66
+
67
+ #LOOP ID - 2110C SUBSCRIBER ELIGIBILITY OR BENEFIT INQUIRY INFORMATION 99
68
+ [2110C]
69
+ segment=EQ:::Subscriber Eligibility or Benefit Inquiry Information:S:1
70
+ segment=AMT:::Subscriber Spend Down Amount:S:1
71
+ segment=III:::Subscriber Eligibility or Benefit Additional Inquiry Information:S:10
72
+ segment=REF:::Subscriber Additional Information:S:1
73
+ segment=DTP:::Subscriber Eligibility/Benefit Date:S:1
74
+
75
+ #LOOP ID - 2000D DEPENDENT LEVEL >1
76
+ [2000D]
77
+ segment=HL:3:23:Dependent Level:S:1
78
+ segment=TRN:::Dependent Trace Number:S:2
79
+ loop=2100D
80
+
81
+ #LOOP ID - 2100D DEPENDENT NAME 1
82
+ [2100D]
83
+ segment=NM1:1:03:Dependent Name:R:1
84
+ segment=REF:::Dependent Additional Identification:S:9
85
+ segment=N3:::Dependent Address:S:1
86
+ segment=N4:::Dependent City/State/ZIP Code:S:1
87
+ segment=PRV:::Provider Information:S:1
88
+ segment=DMG:::Dependent Demographic Information:S:1
89
+ segment=INS:::Dependent Relationship:S:1
90
+ segment=DTP:::Dependent Date:S:2
91
+ loop=2110D
92
+
93
+ #LOOP ID - 2110D DEPENDENT ELIGIBILITY OR BENEFIT INQUIRY INFORMATION 99
94
+ [2110D]
95
+ segment=EQ:::Dependent Eligibility or Benefit Inquiry Information:R:1
96
+ segment=III:::Dependent Eligibility or Benefit Additional Inquiry Information:S:10
97
+ segment=REF:::Dependent Additional Information:S:1
98
+ segment=DTP:::Dependent Eligibility/Benefit Date:S:1
99
+
100
+ #LOOP ID - TRAILER
101
+ [SE]
102
+ segment=SE:::Transaction Set Trailer:R:1
103
+
104
+ [GE]
105
+ segment=GE:::GE:R:1
106
+
107
+ [IEA]
108
+ segment=IEA:::IEA:R:1
109
+
110
+
111
+
@@ -0,0 +1,120 @@
1
+ [LOOPS]
2
+ ISA
3
+ GS
4
+ ST
5
+ 2000A
6
+ 2000B
7
+ 2000C
8
+ 2000D
9
+ 2000E
10
+ SE
11
+ GE
12
+ IEA
13
+
14
+ #--- start of loop details ---#
15
+
16
+ [ISA]
17
+ segment=ISA:::ISA:R:1
18
+
19
+ [GS]
20
+ segment=GS:::GS:R:1
21
+
22
+ #LOOP ID - HEADER
23
+ [ST]
24
+ segment=ST:::Transaction Set Header:R:1
25
+ segment=BHT:::Beginning of Hierarchical Transaction:R:1
26
+
27
+ #LOOP ID - 2000A INFORMATION SOURCE LEVEL >1
28
+ [2000A]
29
+ segment=HL:3:20:Information Source Level:R:1
30
+ loop=2100A
31
+
32
+ #LOOP ID - 2100A PAYER NAME >1
33
+ [2100A]
34
+ segment=NM1:1:PR:Payer Name:R:1
35
+ segment=PER:::Payer Contact Information:S:1
36
+
37
+ #LOOP ID - 2000B INFORMATION RECEIVER LEVEL >1
38
+ [2000B]
39
+ segment=HL:3:21:Information Receiver Level:R:1
40
+ loop=2100B
41
+
42
+ #LOOP ID - 2100B INFORMATION RECEIVER NAME >1
43
+ [2100B]
44
+ segment=NM1:1:41:Information Receiver Name:R:1
45
+
46
+ #LOOP ID - 2000C SERVICE PROVIDER LEVEL >1
47
+ [2000C]
48
+ segment=HL:3:19:Service Provider Level:R:1
49
+ loop=2100C
50
+
51
+ #LOOP ID - 2100C PROVIDER NAME >1
52
+ [2100C]
53
+ segment=NM1:1:1P:Provider Name:R:1
54
+
55
+ #LOOP ID - 2000D SUBSCRIBER LEVEL >1
56
+ [2000D]
57
+ segment=HL:3:22:Subscriber Level:R:1
58
+ segment=DMG:::Subscriber Demographic Information:S:1
59
+ loop=2100D
60
+ loop=2200D
61
+
62
+ #LOOP ID - 2100D SUBSCRIBER NAME >1
63
+ [2100D]
64
+ segment=NM1:1:IL,QC:Subscriber Name:R:1
65
+
66
+ #LOOP ID - 2200D CLAIM SUBMITTER TRACE NUMBER >1
67
+ [2200D]
68
+ segment=TRN:::Claim Submitter Trace Number:R:1
69
+ segment=REF:::Payer Claim Identification Number:S:1
70
+ segment=REF:::Institutional Bill Type Identification:S:1
71
+ segment=REF:::Medical Record Identification:S:1
72
+ segment=AMT:::Claim Submitted Charges:S:1
73
+ segment=DTP:::Claim Service Date:S:1
74
+ loop=2210D
75
+
76
+ #LOOP ID - 2210D SERVICE LINE INFORMATION >1
77
+ [2210D]
78
+ segment=SVC:::Service Line Information:S:1
79
+ segment=REF:::Service Line Item Identification:S:1
80
+ segment=DTP:::Service Line Date:R:1
81
+
82
+ #LOOP ID - 2000E DEPENDENT LEVEL >1
83
+ [2000E]
84
+ segment=HL:3:23:Dependent Level:S:1
85
+ segment=DMG:::Dependent Demographic Information:R:1
86
+ loop=2100E
87
+ loop=2200E
88
+
89
+ #LOOP ID - 2100E DEPENDENT NAME >1
90
+ [2100E]
91
+ segment=NM1:1:QC:Dependent Name:R:1
92
+
93
+ #LOOP ID - 2200E CLAIM SUBMITTER TRACE NUMBER >1
94
+ [2200E]
95
+ segment=TRN:::Claim Submitter Trace Number:R:1
96
+ segment=REF:::Payer Claim Identification Number:S:1
97
+ segment=REF:::Institutional Bill Type Identification:S:1
98
+ segment=REF:::Medical Record Identification:S:1
99
+ segment=AMT:::Claim Submitted Charges:S:1
100
+ segment=DTP:::Claim Service Date:S:1
101
+ loop=2210E
102
+
103
+ #LOOP ID - 2210E SERVICE LINE INFORMATION >1
104
+ [2210E]
105
+ segment=SVC:::Service Line Information:S:1
106
+ segment=REF:::Service Line Item Identification:S:1
107
+ segment=DTP:::Service Line Date:S:1
108
+
109
+ #LOOP ID - TRAILER
110
+ [SE]
111
+ segment=SE:::Transaction Set Trailer:R:1
112
+
113
+ [GE]
114
+ segment=GE:::GE:R:1
115
+
116
+ [IEA]
117
+ segment=IEA:::IEA:R:1
118
+
119
+
120
+