x12edi 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README.md +5 -1
  2. data/lib/x12edi.rb +104 -28
  3. data/lib/x12edi/version.rb +1 -1
  4. metadata +3 -3
data/README.md CHANGED
@@ -9,6 +9,10 @@ data = File.read('test/835.edi')
9
9
 
10
10
  x12edi = X12edi::EightThirtyFive.new(data)
11
11
 
12
- x12edi.to_h # => { payer_name: "name of payer", ...}
12
+ x12edi.payer # => { ... }
13
+
14
+ x12edi.payee # => { ... }
15
+
16
+ x12edi.claims # => [{..claim 1...}, {...claim 2...}]
13
17
  ```
14
18
 
@@ -37,38 +37,114 @@ module X12edi
37
37
  # ...,
38
38
  # }
39
39
  class EightThirtyFive < Base
40
- def to_h
41
- results = {}
42
-
43
- parser.first
44
- .flatmap{|m| m.find(:GS) }
45
- .tap do |m|
46
- el(m, 2) { |e| results[:gateway] = e }
47
- end
48
- .flatmap{|m| m.find(:ST) }
49
- .tap do |m|
50
- el(m.find(:N1, "PR"), 2) {|e| results[:payer_name] = e }
51
- el(m.find(:N1, "PE"), 2) {|e| results[:payee_name] = e }
40
+ def payer
41
+ h = {}
42
+ begin
43
+ parser.first.flatmap do |isa|
44
+ isa.iterate(:GS) do |gs|
45
+ gs.iterate(:ST) do |st|
46
+ st.iterate(:N1, "PR") do |n1|
47
+ el(n1, 1, 2, 3, 4) do |a, b, c, d|
48
+ h[:entity_id_code] = a
49
+ h[:name] = b
50
+ h[:id_code_qualifier] = c
51
+ h[:id_code] = d
52
+ end
53
+ el(n1.find(:N4), 1, 2, 3) do |a, b, c|
54
+ h[:city_name] = a
55
+ h[:state_or_provence] = b
56
+ h[:postal_code] = c
57
+ end
58
+ end
59
+ end
60
+ end
52
61
  end
53
- .flatmap{|m| m.find(:LX) }
54
- .flatmap{|m| m.find(:CLP) }
55
- .flatmap{|m| m.find(:NM1, "QC") }
56
- .tap do |m|
57
- el(m, 3, 4) {|l,f| results[:patient] = "#{l}, #{f}"}
58
- end
59
- .flatmap { |m| m.find(:PER) }
60
- .tap do |m|
61
- el(m, 2, 4) { |a,b| results[:payer_contact] = "Name: #{a}, Phone: #{b}"}
62
+ rescue
63
+ end
64
+ h
65
+ end
66
+
67
+ def payee
68
+ h = {}
69
+ begin
70
+ parser.first.flatmap do |isa|
71
+ isa.iterate(:GS) do |gs|
72
+ gs.iterate(:ST) do |st|
73
+ st.iterate(:N1, "PE") do |n1|
74
+ el(n1, 1, 2, 3, 4) do |a, b, c, d|
75
+ h[:entity_id_code] = a
76
+ h[:name] = b
77
+ h[:id_code_qualifier] = c
78
+ h[:id_code] = d
79
+ end
80
+ el(n1.find(:N4), 1, 2, 3) do |a, b, c|
81
+ h[:city_name] = a
82
+ h[:state_or_provence] = b
83
+ h[:postal_code] = c
84
+ end
85
+ end
86
+ end
87
+ end
62
88
  end
63
- .flatmap { |m| m.find(:AMT) }
64
- .tap do |m|
65
- el(m, 1, 2) { |a,b|
66
- results[:amount_currency] = a
67
- results[:amount_amount] = b.to_f
68
- }
89
+ rescue
90
+ end
91
+ h
92
+ end
93
+
94
+ def claims
95
+ h = {}
96
+
97
+ begin
98
+ parser.first.flatmap do |isa|
99
+ isa.iterate(:GS) do |gs|
100
+ gs.iterate(:ST) do |st|
101
+ st.iterate(:LX) do |lx|
102
+ h[:claims] = []
103
+ lx.iterate(:CLP) do |clp|
104
+ claim = {}
105
+
106
+ begin
107
+ el(clp.find(:CLP), 1, 2, 3, 4) do |a,b,c,d|
108
+ claim[:submitter_identifier] = a
109
+ claim[:status_code] = b
110
+ claim[:amount_submitted] = c # submitted amount
111
+ claim[:amount_paid] = d # amount paid in this claim
112
+ end
113
+ rescue => e
114
+ claim[:ERROR] = e.message
115
+ end
116
+
117
+ # Patient
118
+ el(clp.find(:NM1), 1,2,3,4,5,6,7,8,9) do |a,b,c,d,e,f,g,h,i|
119
+ claim[:entity_identifier_code] = a
120
+ claim[:entity_type_qualifier] = b
121
+ claim[:last_name] = c
122
+ claim[:first_name] = d
123
+ claim[:middle_name] = e
124
+ claim[:name_prefix] = f
125
+ claim[:name_suffix] = g
126
+ claim[:identification_code_qualifier] = h
127
+ claim[:identification_code] = i
128
+ end
129
+
130
+ h[:claims] << claim
131
+ end
132
+ end
133
+ end
134
+ end
69
135
  end
136
+ rescue => e
137
+ h[:ERROR] = e.message
138
+ end
70
139
 
71
- results
140
+ h
72
141
  end
73
142
  end
74
143
  end
144
+
145
+ # require 'awesome_print'
146
+ # file_path = "./Sample_835_5010_Medicare.txt"
147
+ # x12 = X12edi::EightThirtyFive.new(File.read(file_path))
148
+ # ap x12.claims
149
+ # ap x12.payer
150
+ # ap x12.payee
@@ -1,3 +1,3 @@
1
1
  module X12edi
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: x12edi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-09 00:00:00.000000000 Z
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stupidedi
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 1.8.23
98
+ rubygems_version: 1.8.25
99
99
  signing_key:
100
100
  specification_version: 3
101
101
  summary: DSL for working with X12 EDI in Ruby.