Class: Editrix::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/editrix.rb

Instance Method Summary collapse

Constructor Details

#initialize(raw_271) ⇒ Parser

Returns a new instance of Parser.



8
9
10
# File 'lib/editrix.rb', line 8

def initialize(raw_271)
  @raw_271 = raw_271
end

Instance Method Details

#parseObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/editrix.rb', line 12

def parse
  array_271 = @raw_271.split("~")   # Traversal array for split 271 segments
  @hash_271 = {}                    # Final hash for the entire decoded 271
  l_count = 0                       # Loop Segment counter
  dtp_count = 0                     # DTP segment counter
  ref_count = 0                     # REF segment counter
  hsd_count = 0                     # HSD segment counter
  per_count = 0                     # PER segment counter
  aaa_count = 0                     # AAA segment counter
  msg_count = 0                     # MSG segment counter
  trn_count = 0                     # TRN segment counter
  loop_secondary_count = 0          # loop counter

  loop_alpha = "@"
  loop_num = 2000
  ls_flag = false


  array_271.each do |each|             # Iterating through each 271 segment begins...

    # Declaration of individual segment hashes
    isa = {}
    gs  = {}
    st  = {}
    bht = {}
    hl  = {}
    trn = {}
    nm1 = {}
    n3  = {}
    n4  = {}
    dmg = {}
    ins = {}
    hi  = {}
    dtp = {}
    mpi = {}
    eb  = {}
    hsd = {}
    ref = {}
    per = {}
    aaa = {}
    prv = {}
    msg = {}
    iii = {}
    ls  = {}
    le  = {}
    se  = {}
    ge  = {}
    iea = {}


      # Hash for ISA - Interchange Control Header begins -----------------------------------------------------------------
    if each.start_with?("ISA")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        isa["ISA%02d" % i] = segment_values[i]
      end
      @hash_271["ISA"] = isa
      # Hash for ISA - Interchange Control Header ends -------------------------------------------------------------------



      # Hash for GS - Functional Group Header begins ---------------------------------------------------------------------
    elsif each.start_with?("GS")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        gs["GS%02d" % i] = segment_values[i]
      end
      @hash_271["GS"] = gs
      # Hash for GS - Functional Group Header ends -----------------------------------------------------------------------



      # Hash for ST - Transaction Set Header begins ----------------------------------------------------------------------
    elsif each.start_with?("ST")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        st["ST%02d" % i] = segment_values[i]
      end
      @hash_271["ST"] = st
      # Hash for ST - Transaction Set Header ends ------------------------------------------------------------------------



      # Hash for BHT - Beginning Of Hierarchical Transaction begins ------------------------------------------------------
    elsif each.start_with?("BHT")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        bht["BHT%02d" % i] = segment_values[i]
      end
      @hash_271["BHT"] = bht
      # Hash for BHT - Beginning Of Hierarchical Transaction ends --------------------------------------------------------



      # Hash for HL - Hierarchical Level begins --------------------------------------------------------------------------
    elsif each.start_with?("HL")
      loop_num = 2000
      loop_alpha.next!
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        hl["HL%02d" % i] = segment_values[i]
      end
      @hash_271["#{loop_num.to_s+loop_alpha}.HL"] = hl
      # Hash for HL - Hierarchical Level ends ----------------------------------------------------------------------------



      # Hash for TRN - Trace begins --------------------------------------------------------------------------------------
    elsif each.start_with?("TRN")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        trn["TRN%02d" % i] = segment_values[i]
      end
      trn_count += 1
      @hash_271["#{loop_num.to_s+loop_alpha}.TRN#{trn_count}"] = trn
      # Hash for TRN - Trace ends ----------------------------------------------------------------------------------------



      # Hash for NM1 - Individual or Organization Name begins ------------------------------------------------------------
    elsif each.start_with?("NM1")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        nm1["NM1%02d" % i] = segment_values[i]
      end
      loop_num = 2100
      if ls_flag == true
        @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.2120C#{l_count}.NM1"] = nm1
      else
        @hash_271["#{loop_num.to_s+loop_alpha}.NM1"] = nm1
      end
      # loop_secondary_count = 0
      # Hash for NM1 - Individual or Organization Name ends --------------------------------------------------------------



      # Hash for N3 - Party Location begins ------------------------------------------------------------------------------
    elsif each.start_with?("N3")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        n3["N3%02d" % i] = segment_values[i]
      end
      if ls_flag == true
        @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.2120C#{l_count}.N3"] = n3
      else
        @hash_271["#{loop_num.to_s+loop_alpha}.N3"] = n3
      end

      # Hash for N3 - Party Location ends --------------------------------------------------------------------------------



      # Hash for N4 - Geographic Location begins -------------------------------------------------------------------------
    elsif each.start_with?("N4")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        n4["N4%02d" % i] = segment_values[i]
      end
      if l_count != 0
        @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.2120C#{l_count}.N4"] = n4
      else
        @hash_271["#{loop_num.to_s+loop_alpha}.N4"] = n4
      end

      # Hash for N4 - Geographic Location ends ---------------------------------------------------------------------------



      # Hash for DMG - Demographic Information begins --------------------------------------------------------------------
    elsif each.start_with?("DMG")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        dmg["DMG%02d" % i] = segment_values[i]
      end
      @hash_271["#{loop_num.to_s+loop_alpha}.DMG"] = dmg
      # Hash for DMG - Demographic Information ends ----------------------------------------------------------------------



      # Hash for INS - Insured Benefit begins ----------------------------------------------------------------------------
    elsif each.start_with?("INS")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        ins["INS%02d" % i] = segment_values[i]
      end
      @hash_271["#{loop_num.to_s+loop_alpha}.INS"] = ins
      # Hash for INS - Insured Benefit ends ------------------------------------------------------------------------------



      # Hash for HI - Healthcare Information codes begin -----------------------------------------------------------------
    elsif each.start_with?("HI")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        hi["HI%02d" % i] = segment_values[i]
      end
      @hash_271["#{loop_num.to_s+loop_alpha}.HI"] = hi
      # Hash for HI - Healthcare Information codes end -------------------------------------------------------------------



      # Hash for DTP - Date or Time or Period begins ---------------------------------------------------------------------
    elsif each.start_with?("DTP")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        dtp["DTP%02d" % i] = segment_values[i]
      end
      dtp_count += 1
      if loop_secondary_count != 0
        @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.DTP#{dtp_count}"] = dtp
      else
        @hash_271["#{loop_num.to_s+loop_alpha}.DTP#{dtp_count}"] = dtp
      end
      # Hash for DTP - Date or Time or Period ends -----------------------------------------------------------------------



      # Hash for MPI - Military Personnel Information begins -------------------------------------------------------------
    elsif each.start_with?("MPI")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        mpi["MPI%02d" % i] = segment_values[i]
      end
      @hash_271["#{loop_num.to_s+loop_alpha}.MPI"] = mpi
      # Hash for MPI - Military Personnel Information ends ---------------------------------------------------------------



      # Hash for EB - Eligibility or Benefit Information Begins ----------------------------------------------------------
    elsif each.start_with?("EB")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        eb["EB%02d" % i] = segment_values[i]
      end
      loop_num = 2110
      loop_secondary_count += 1
      @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.EB"] = eb

      # Resetting counter variable for each eligibility loop
      dtp_count = 0
      hsd_count = 0
      ref_count = 0
      aaa_count = 0
      msg_count = 0
      per_count = 0
      l_count = 0
      # Hash for EB - Eligibility or Benefit Information ends ------------------------------------------------------------



      # Hash for HSD - Healthcare Services Delivery begins ---------------------------------------------------------------
    elsif each.start_with?("HSD")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        hsd["HSD%02d" % i] = segment_values[i]
      end
      hsd_count += 1
      @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.HSD#{hsd_count}"] = hsd
      # Hash for HSD - Healthcare Services Delivery ends -----------------------------------------------------------------



      # Hash for REF - Reference Information begins ----------------------------------------------------------------------
    elsif each.start_with?("REF")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        ref["REF%02d" % i] = segment_values[i]
      end
      ref_count += 1
      if loop_secondary_count != 0
        @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.REF#{ref_count}"] = ref
      else
        @hash_271["#{loop_num.to_s+loop_alpha}.REF#{ref_count}"] = ref
      end
      # Hash for REF - Reference Information ends ------------------------------------------------------------------------



      # Hash for PER - Administrative Communications Contact begins ------------------------------------------------------
    elsif each.start_with?("PER")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        per["PER%02d" % i] = segment_values[i]
      end
      per_count += 1
      if ls_flag == true
        @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.2120C#{l_count}.PER#{per_count}"] = per
      else
        @hash_271["#{loop_num.to_s+loop_alpha}.PER#{per_count}"] = per
      end
      # Hash for PER - Administrative Communications Contact ends --------------------------------------------------------



      # Hash for AAA - Request Validation begins -------------------------------------------------------------------------
    elsif each.start_with?("AAA")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        aaa["AAA%02d" % i] = segment_values[i]
      end
      aaa_count += 1
      if loop_secondary_count != 0
        @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.AAA#{aaa_count}"] = aaa
      else
        @hash_271["#{loop_num.to_s+loop_alpha}.AAA#{aaa_count}"] = aaa
      end
      # Hash for AAA - Request Validation ends ---------------------------------------------------------------------------


      # Hash for PRV - Provider Information begins -----------------------------------------------------------------------
    elsif each.start_with?("PRV")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        prv["PRV%02d" % i] = segment_values[i]
      end
      if ls_flag == true
        @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.2120C#{l_count}.PRV"] = prv
      else
        if loop_secondary_count != 0
          @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.PRV"] = prv
        else
          @hash_271["#{loop_num.to_s+loop_alpha}.PRV"] = prv
        end
      end
      # Hash for PRV - Provider Information ends -------------------------------------------------------------------------



      # Hash for MSG - Message Text begins -------------------------------------------------------------------------------
    elsif each.start_with?("MSG")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        msg["MSG%02d" % i] = segment_values[i]
      end
      msg_count += 1
      @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.MSG#{msg_count}"] = msg
      # Hash for MSG - Message Text ends ---------------------------------------------------------------------------------



      # Hash for III - Information begins --------------------------------------------------------------------------------
    elsif each.start_with?("III")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        iii["III%02d" % i] = segment_values[i]
      end
      if l_count != 0
        @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.2115C.III#{l_count}"] = iii
      else
        @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.2115C.III"] = iii
      end
      # Hash for III - Information ends ----------------------------------------------------------------------------------



      # Hash for LS - Loop Header begins ---------------------------------------------------------------------------------
    elsif each.start_with?("LS")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        ls["LS%02d" % i] = segment_values[i]
      end
      l_count += 1
      @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.LS#{l_count}"] = ls
      ls_flag = true
      # Hash for LS - Loop Header ends -----------------------------------------------------------------------------------



      # Hash for LE - Loop Trailer begins --------------------------------------------------------------------------------
    elsif each.start_with?("LE")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        le["LE%02d" % i] = segment_values[i]
      end
      @hash_271["#{loop_num.to_s+loop_alpha}.#{loop_secondary_count}.LE#{l_count}"] = le
      ls_flag = false
      # Hash for LE - Loop Trailer ends ----------------------------------------------------------------------------------



      # Hash for SE - Transaction Set Trailer begins ---------------------------------------------------------------------
    elsif each.start_with?("SE")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        se["SE%02d" % i] = segment_values[i]
      end
      @hash_271["SE"] = se
      # Hash for SE - Transaction Set Trailer ends -----------------------------------------------------------------------



      # Hash for GE - Functional Group Trailer begins --------------------------------------------------------------------
    elsif each.start_with?("GE")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        ge["GE%02d" % i] = segment_values[i]
      end
      @hash_271["GE"] = ge
      # Hash for GE - Functional Group Trailer ends ----------------------------------------------------------------------



      # Hash for IEA - Interchange Control Trailer begins ----------------------------------------------------------------
    elsif each.start_with?("IEA")
      segment_values = each.split("*")
      (1..segment_values.length-1).each do |i|
        iea["IEA%02d" % i] = segment_values[i]
      end
      @hash_271["IEA"] = iea
      # Hash for IEA - Interchange Control Trailer ends ------------------------------------------------------------------
    end
    end   #---------------------------------------- Iterating through each 271 segment ends...
end

#prettyResultObject



430
431
432
# File 'lib/editrix.rb', line 430

def prettyResult
  JSON.generate(@hash_271)
end

#resultObject



426
427
428
# File 'lib/editrix.rb', line 426

def result
  @hash_271
end