Class: FieldGenerator

Inherits:
BaseFieldGenerator show all
Includes:
Utils
Defined in:
lib/ez7gen/service/2.4/field_generator.rb,
lib/ez7gen/service/2.5/field_generator.rb

Constant Summary collapse

@@REQ_LEN_3_DGTS =

@@UP_TO_3_DGTS = 1000 # up to 3 digits

3
@@RANGE_INDICATOR =

up to 3 digits

'...'
@@HAT =

Component separator, aka hat

'^'
@@SUB =

Subcomponent separator

'&'
@@MONEY_FORMAT_REGEX =

@@MONEY_FORMAT_INDICATORS = [‘Money’, ‘Balance’, ‘Charge’, ‘Adjustment’, ‘Income’, ‘Amount’, ‘Payment’,‘Cost’] @@MONEY_FORMAT_REGEX = /bMoneyb|bBalanceb|bCharge|bAdjustmentb|bIncomeb|bAmountb|bPaymentb|bCostb|bPercentageb/

/\bMoney\b|\bBalance\b|\bCharge|\bAdjustment\b|\bIncome\b|\bAmount\b|\bPayment\b|\bCost\b/
@@PERCENT_FORMAT_REGEX =
/\bPercentage\b|%/
@@INITIALS =
('A'..'Z').to_a
@@GENERAL_TEXT =
'Notes'
@@random =
Random.new

Constants included from Utils

Utils::BASE, Utils::BASE_INDICATOR, Utils::DATA_LOOKUP_MIS, Utils::PRIMARY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#blank?, #get_name_without_base, #get_segment_name, #get_type_by_name, #has_html_encoded_ch?, #is_number?, #num_to_nil, #safe_len, #sample_index

Methods inherited from BaseFieldGenerator

#DTM, #GTS, #SAD

Constructor Details

#initialize(parser, helper_parser = nil) ⇒ FieldGenerator

constructor



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 24

def initialize(parser, helper_parser=nil)
  @pp = parser
  # Coded table value lookup profiler. Only set for custom schemas.
  # Custom schema has types which coming from the base schema but using coded tables from primary schema.
  # Also primary schemas use base type coded tables.
  @hp = helper_parser

  # dirname =  File.join(File.dirname(File.expand_path(__FILE__)),'../../resources/properties.yml')
  propertiesFile = File.expand_path('../../../resources/properties.yml', __FILE__)
  @yml = YAML.load_file propertiesFile
end

Instance Attribute Details

#ppObject

Returns the value of attribute pp.



8
9
10
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 8

def pp
  @pp
end

#ymlObject

Returns the value of attribute yml.



8
9
10
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 8

def yml
  @yml
end

Instance Method Details

#AD(map, force = false) ⇒ Object

Generate HL7 AD (address) data type.



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
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 42

def AD(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # match cities, states and zips
  sample  = @yml['address.states'].sample
  idx = @yml['address.states'].index(sample) #index of random element

  val=[]
  #street address (ST) (ST)
  val << @yml['address.streetNames'].sample
  #other designation (ST)
  val <<''
  #city (ST)
  val << @yml['address.cities'].at(idx)
  #state or province (ST)
  val << @yml['address.states'].at(idx)
  #zip or postal code (ST)
  val << @yml['address.zips'].at(idx)
  #country (ID)
  val << @yml['address.countries'].at(idx)
  # address type (ID)
  # ot5 her geographic designation (ST)

  val.join(@@HAT)
end

#apply_rules(codes, attributes) ⇒ Object

Handle range values specified by ‘…’ sequence, including empty range TODO refactor candidate



1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1463

def apply_rules(codes, attributes)
  #safety check, no codes returns an empty map
return {} if blank?(codes)

  #index of random element
  idx = sample_index(codes.size)
  code = codes[idx][:value]
  description = codes[idx][:description]

  if (code.include?(@@RANGE_INDICATOR))
    code = handle_ranges(code)
  end

  if (code.size > (maxlen = (attributes[:max_length]) ? attributes[:max_length].to_i : code.size))
    #remove all codes wich values violate
  #codes.select! {|it| it[:value].size <= maxlen }
    code, description = handle_length(codes, maxlen)
  end

  # got to have code, get an id, most basic - TODO: verify this.
  # if(Utils.blank?(code))
  #   code, description = ID({},true), ''
  # end
  # return code, description

  # puts code + ', ' + description
  return {:value => code, :description => description}
end

#AUI(map, force = false) ⇒ Object

Authorization information



70
71
72
73
74
75
76
77
78
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 70

def AUI(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # authorization number (ST)
  ST(map, true)
  # date (DT)
  # source (ST)
end

#CCD(map, force = false) ⇒ Object

Charge time



81
82
83
84
85
86
87
88
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 81

def CCD(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

  #<when to charge code (ID)>
  ID(map, force=false)
  # <date/time (TS)>
end

#CCP(map, force = false) ⇒ Object

Channel calibration parameters



91
92
93
94
95
96
97
98
99
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 91

def CCP(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <channel calibration sensitivity correction (NM)>
  NM(map,true)
  # <channel calibration baseline (NM)>
  # <channel calibration time skew (NM)>
end

#CD(map, force = false) ⇒ Object

Channel definition



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 102

def CD(map, force=false)
# check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  #<channel identifier (WVI)>
  WVI(map, force=true)
  #<waveform source (WVS)>
  # <channel sensitivity/units (SCU)>
  #<channel calibration parameters (CCP)>
  # <sampling frequency (NM)>
  # <minimum/maximum data values (NR)>
end

#CE(map, force = false) ⇒ Object

Generate HL7 CE (coded element) data type



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
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 116

def CE(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  if(map[:max_length] && map[:max_length].to_i <3)
    # if CE Element has lenght of 2 or less use only value
    return ID(map, true)
  end

  #TODO: Refactor this method
  if (map[:description] == 'Role Action Reason' || map[:description] == 'Species Code' || map[:description] == 'Breed Code' || map[:description] == 'Production Class Code')
    return '' #Per requirement, PID.35 – PID.38
  end

  val = []
  # CE ce = (CE) map?.fld
  codes = get_coded_map(map)
  if(blank?(codes))
    case map[:description]
      when 'Allergen Code/Mnemonic/Description'
        pair = yml['codes.allergens.icd10'].to_a.sample(1).to_h.first # randomly pick a pair
        val<<pair.first
        val<<pair.last

      else
        # TODO: only for elements that don't have look up table set the id randomly
        # if codetable is empty
        val << ((blank?(map[:codetable])) ? ID(map, true) : '')
    end
  else
    #identifier (ST) (ST)
    val<<codes[:value]
    #text (ST)
    val<<codes[:description]
    #name of coding system (IS)
    #alternate identifier (ST) (ST)
    #alternate text (ST)
    #name of alternate coding system (IS)
  end
  return val.join(@@HAT)
end

#CF(map, force = false) ⇒ Object

Coded element with formatted values



159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 159

def CF(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <identifier (ID)>
  ID(map, true)
  # <formatted text (FT)>
  # <name of coding system (IS)>
  # <alternate identifier (ID)>
  # <alternate formatted text (FT)>
  # <name of alternate coding system (IS)>
end

#CK(map, force = false) ⇒ Object

Composite ID with check digit



173
174
175
176
177
178
179
180
181
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 173

def CK(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  # <ID number (NM)>
  NM(map,true)
  # <check digit (NM)>
  # <code identifying the check digit scheme employed (ID)>
  # < assigning authority (HD)>
end

#CM(map, force = false) ⇒ Object

Composite



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 184

def CM(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

val=[]
# <penalty type (IS)>
val=IS(map,true)
# <penalty amount (NM)>
val<<NM({},true)
val.join(@@HAT)
end

#CNE(map, force = false) ⇒ Object

CNE Coded with no exceptions



201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 201

def CNE(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <identifier (ST)> ^ <text (ST)>
  ST(map, true)
  # <name of coding system (IS)>
  # <alternate identifier(ST)>
  # <alternate text (ST)>
  # <name of alternate coding system (IS)>
  # <coding system version ID (ST)>
  # alternate coding system version ID (ST)>
  # <original text (ST)>
end

#CNN(map, force = false) ⇒ Object

Composite ID number and name (special DT for NDL)



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 217

def CNN(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # ID number (ST) (ST)

  # val << ID(map, true)
  # family name (FN), used for ST
  # val << FN(map, true)
  # given name (ST)
  # val << @yml['person.names.first'].sample
  # second and further given names or initials thereof (ST)
  # val << @@INITIALS.to_a.sample
  # < suffix (e.g., JR or III) (ST)> ^ < prefix (e.g., DR) (ST)>
  # < degree (e.g., MD) (IS)> ^ < source table (IS)>
  PN(map, true)

  # < assigning authority namespace ID (IS)>
  # < assigning authority universal ID (ST)>
  # < assigning authority universal ID type (ID)>
  #  val.join(@@SUB)
end

#CP(map, force = false) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 240

def CP(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

#price (MO)
  MO(map,true)
#price type (ID)
#from value (NM)
#to value (NM)
#range units (CE)
#range type (ID)
end

#CQ(map, force = false) ⇒ Object

Composite quantity with units



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 254

def CQ(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  # val =[]
  # <quantity (NM)>
  NM({},true)

  # val<<NM({},true)
  # <units (CE)>
  # val<<CE(map,true) # Per request with QBP_Q21 issue
  # CE always get values from code table 335, schema does not always specify it.
  # only ID part from CE is used for this data type
  # val<<ID(reset_map_attr(map, :codetable, '335'), true)
  # val<<ID(map,true)
  # val.join(@@HAT)
  # val.join(@@SUB)
end

#CSU(map, force = false) ⇒ Object

Channel sensitivity/units



273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 273

def CSU(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # < channel sensitivity (NM)>
  NM(map,true)
  # < unit of measure identifier (ST)>
  # < unit of measure description (ST)>
  # < unit of measure coding system (IS)>
  # < alternate unit of measure identifier (ST)>
  # < alternate unit of measure description (ST)>
  # < alternate unit of measure coding system (IS)>
end

#CWE(map, force = false) ⇒ Object

Coded with exceptions



288
289
290
291
292
293
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 288

def CWE(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))
# <identifier (ST)>
# <text (ST)> ^ <name of coding system (IS)> ^ <alternate identifier(ST)> ^ <alternate text (ST)> ^ <name of alternate coding system (IS)> ^ <coding system version ID (ST)> ^ alternate coding system version ID (ST)> ^ <original text (ST)>
end

#CX(map, force = false) ⇒ Object

Generate HL7 CX (extended composite ID with check digit) data type.



296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 296

def CX(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

#ID (ST)
ST(reset_map_attr(map, :description, 'Number'), true)
#check digit (ST) (ST)
#code identifying the check digit scheme employed (ID)
#assigning authority (HD)
  #identifier type code (ID) (ID)
#assigning facility (HD)
#effective date (DT) (DT)
#expiration date (DT)
end

#DDI(map, force = false) ⇒ Object

Daily deductible



312
313
314
315
316
317
318
319
320
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 312

def DDI(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # < delay days (NM)>
  # < amount (NM)>
  NM(map,true)
  # < number of days (NM)>
end

#DIN(map, force = false) ⇒ Object

Activation date



323
324
325
326
327
328
329
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 323

def DIN(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  # date	< date (TS)>
  TS(map,true)
  # <institution name (CE)>
end

#DLD(map, force = false) ⇒ Object

Generate HL7 DLD (discharge location) data type. This type consists of the following components=>



332
333
334
335
336
337
338
339
340
341
342
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 332

def DLD(map, force=false)
#check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  val=[]
#discharge location (ID)
val<<ID(map, true)
#effective date (TS)
val<<TS({},true)
val.join(@@HAT)
end

#DLN(map, force = false) ⇒ Object

Generate HHL7 DLN (driver’s license number) data type



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 345

def DLN(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))
  val=[]
# DLN dln = (DLN) map.fld
#Driver´s License Number (ST)
val << generate_length_bound_id(10) # 10 vs 7 Numeric, as for some states in real life
#Issuing State, province, country (IS)
#is(['fld'=>dln.getIssuingStateProvinceCountry(), 'required'=>'R','codetable'=>map.codetable])
#dln.getIssuingStateProvinceCountry().setValue(allStates.get(Math.abs(random.nextInt()%allStates.size())))
  # val << @yml['address.states'].sample # pick a state
  val << IS({:codetable =>'333'},true) # pick a state
#expiration date (DT)
val << DT(reset_map_attr(map, :description, 'End'), true)
  val.join(@@HAT)
end

#DLT(map, force = false) ⇒ Object

Delta check



364
365
366
367
368
369
370
371
372
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 364

def DLT(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  # <range (NR)>
  NR(map,true)
  # <numeric threshold (NM)>
  # <change computation (ST)>
  # <length of time-days (NM)>
end

#DR(map, force = false) ⇒ Object

Generates HL7 DR (date/time range) data type.



375
376
377
378
379
380
381
382
383
384
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 375

def DR(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))
  val=[]
#range start date/time (TS)
val<<TS(map,true)
#range end date/time (TS)
val<<TS(reset_map_attr(map, :description, 'End'), true)
  val.join(@@HAT)
end

#dt(name, attrs) ⇒ Object

base data types [“DT”, “FT”, “ID”, “IS”, “NM”, “SI”, “ST”, “TM”, “TN”, “TX”]



37
38
39
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 37

def dt (dt, attrs)
  self.method(dt).call(attrs)
end

#DT(map, force = false) ⇒ Object

Generates an HL7 DT (date) datatype.



387
388
389
390
391
392
393
394
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 387

def DT(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

  is_year_only = (map[:max_length]) ? map[:max_length].to_i == 4 : false
  # #time of an event (TSComponentOne)
 (is_year_only)?  to_datetime(map).strftime('%Y') : to_datetime(map).strftime('%Y%m%d') #format('YYYYMMdd.SSS')Date.iso8601
end

#DTN(map, force = false) ⇒ Object

Day Type and Number



397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 397

def DTN(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # val=[]
  # # <day type (IS)>
  # val<<IS(map,true)
  # per Galina request: Ensemble limits the length of IN3.11 to 3. So, we need to remove the second component from being populated ...
  IS(map,true)
  # # <number of days (NM)>
  # val<<NM({},true)
  # val.join(@@HAT)
end

#ED(map, force = false) ⇒ Object

Encapsulated data



412
413
414
415
416
417
418
419
420
421
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 412

def ED(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  # <source application (HD) >
  HD(map, true)
  # <type of data (ID)>
  # <data subtype (ID)>
  # <encoding (ID)>
  # <data (ST)>
end

#EI(map, force = false) ⇒ Object

Entity identifier



424
425
426
427
428
429
430
431
432
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 424

def EI(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  # <entity identifier (ST)>
  ST(map,true)
  # <namespace ID (IS)>
  # <universal ID (ST)>
  # < universal ID type (ID)>
end

#EIP(map, force = false) ⇒ Object

Parent order



435
436
437
438
439
440
441
442
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 435

def EIP(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <parent’s placer order number (EI)>
  EI(map,true)
  # <parent’s filler order number (EI)>
end

#ELD(map, force = false) ⇒ Object

Error segment



445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 445

def ELD(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  val = []
  # <segment ID (ST)>
  val<<''
  # <sequence (NM)>
  val<<''
  # <field position (NM)>
  val<<''
  # <code identifying error (CE)>
  val<<CE(map,true)
  val.join(@@HAT)
end

#FC(map, force = false) ⇒ Object

Generates HL7 FC (financial class) data type.



461
462
463
464
465
466
467
468
469
470
471
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 461

def FC(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

  val = []
#Financial Class (IS)
val << IS(map, true)
#Effective Date (TS) (TS)
val << TS(map, true)
  val.join(@@HAT)
end

#FN(map, force = false) ⇒ Object

Generates an HL7 FN (familiy name) data type.



474
475
476
477
478
479
480
481
482
483
484
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 474

def FN(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

#surname (ST)
  @yml['person.names.last'].sample
#own surname prefix (ST)
#own surname (ST)
#surname prefix from partner/spouse (ST)
#surname from partner/spouse (ST)
end

#FT(map, force = false) ⇒ Object

Formatted text data. The FT field is of arbitrary length (up to 64k) and may contain formatting commands enclosed in escape characters.



488
489
490
491
492
493
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 488

def FT(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  ID(map, true)
end

#generate?(map, force = false) ⇒ Boolean

If field are X,W,B (Not Supported, Withdrawn Fields or Backward Compatible) returns false. Conditional © ? For Optional field (O) makes random choice R - Required returns true def autoGenerate?(map, force=false)

Returns:

  • (Boolean)


1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1548

def generate?(map, force=false)
  # return true
  return true if(force)  #forced generation, ignore mappings

  #look up in the mapping
  case map[:required]
    when 'X','W','B' then false;
    when 'R' then true;
    when 'O' then [true,false].sample();
    else  false ;
  end
  # if(['X','W','B'].include?(map[:required]))then return false end
  # if(map[:required] =='R') then return true end
  # if(map[:required] == 'O') then return true end #random boolean
end

#generate_dt(name, attrs, force = false) ⇒ Object



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
# File 'lib/ez7gen/service/2.5/field_generator.rb', line 25

def generate_dt(name, attrs, force=false)
 #check if the field is optional and randomly generate it of skip
 return '' if(!generate?(attrs, force))
 # p "generate_dt : #{name}"

 begin
   # value << method(sub_type[:datatype]).call(sub_type,[true, false].sample)
   dt = method(name).call(attrs, true)
   # p "generate_dt  basic dt: #{name}"

 rescue NameError => e
   # puts e
   # sub_values = dynamic(sub_type[:datatype], sub_type, [true, false].sample)
   dt = generate_dt_by_name(name)

   # TODO :remove trailing empty fields
   #while( blank?(value.last)) do value.pop end
   # value << value.join(@@SUB)

 end
 # puts dt
  # return (dt.is_a?(Array))?dt.join(@@SUB) :dt
  return dt

end

#generate_dt_by_name(name) ⇒ Object

Method to generate field using schema description



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ez7gen/service/2.5/field_generator.rb', line 52

def generate_dt_by_name(name)
  #p "generate_dt_by_name: #{name}, not a basic type"
  $log.info("#{self.class.to_s}:#{__method__.to_s}") {"generate_dt_by_name: #{name}, not a basic type"}

  dt = []
  types = []
  @pp.xml.Export.Document.Category.locate('DataType').select{|it| it.attributes[:name] == name}.first.locate('DataSubType').each{ |it| types << it.attributes}

  # types.slice!(0, types.length/2)
  # TODO: logic to build subtypes 1) look for Reqs, if not build # of sub-types, then build the rest
  for type in types
    # check if field is required
    dt << ((generate?(type)) ? generate_dt(type[:datatype], type) : '')
  end

  # remove trailing empty elements
  while( blank?(dt) and blank?(dt.last)) do
    dt.pop
  end

  return dt
end

#generate_length_bound_id(maxlen, str = @@random.rand(100000000).to_s) ⇒ Object

Returns randomly generated Id of required length, of single digit id



1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1523

def generate_length_bound_id(maxlen, str=@@random.rand(100000000).to_s)
idx = maxlen
  if(maxlen > str.size)
    str = str.ljust(maxlen,'0')
    idx = str.size
  end
  #safe fail
  #this handles case when maxlen is less then 1
  idx = [0,idx-1].max
  return str[0..idx]
end

#get_code_table(attributes) ⇒ Object



1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1450

def get_code_table(attributes)
  codeTable = get_name_without_base(attributes[:codetable])
  codes = @pp.get_code_table(codeTable)
  # Case when we are looking for code values defined in base schema for types
  # which are in custom/primary schema or the othere way around.
  if(@hp && (codes.first == Utils::DATA_LOOKUP_MIS))
    codes = @hp.get_code_table(codeTable)
  end
  return codes
end

#get_coded_map(attributes) ⇒ Object

Values and Description from code table returned as a pair.



1441
1442
1443
1444
1445
1446
1447
1448
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1441

def get_coded_map(attributes)
  codes = get_code_table(attributes)

  # puts codes
  #Apply rules to find a value and description
  #Returns map with code and description
  apply_rules(codes, attributes)
end

#get_coded_value(attributes) ⇒ Object

Value of coded table returned as as single value



1430
1431
1432
1433
1434
1435
1436
1437
1438
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1430

def get_coded_value(attributes)
  codes = get_code_table(attributes)

  # puts codes
  #Apply rules to find a value and description
  map = apply_rules(codes, attributes)
  #Return value only
  return map[:value]
end

#handle_length(codes, maxlen) ⇒ Object



1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1492

def handle_length(codes, maxlen)
idx = codes.find_index { |it| it[:value].size <= maxlen }

  if (!idx)
    code, description = '', ''
  else
    # puts codes
    code = codes[idx][:value]
    description = codes[idx][:description]
  end
  return code, description
end

#handle_ranges(code) ⇒ Object



1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1505

def handle_ranges(code)
  # if (code.include?(@@RANGE_INDICATOR))
ends = code.delete(' ').split('...').map { |it| it }
    if (ends.empty?) # This is indication that codetable does not have any values
      code = ''
    else #Handle range values, build range and pick random value
      # range = ends.first..ends.last
      # code = range.to_a.sample

      # per Galina: Invalid value 'Q8' appears in segment 4:PD1, field 20, repetition 1, component 1, subcomponent 1,
      # but does not appear in code table 2.4:141.
      # I think you had to fix this one before to pull only the first and the last values from each row.
      code = ends.sample
    end
    return code
end

#HD(map, force = false) ⇒ Object

Generates HL7 HD (hierarchic designator) data type



497
498
499
500
501
502
503
504
505
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 497

def HD(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

#namespace ID (IS)
  IS(map, true)
#universal ID (ST)
#universal ID type (ID)
end

#ID(map, force = false) ⇒ Object

Generate HL7 ID, usually using value from code table



509
510
511
512
513
514
515
516
517
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 509

def ID(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  
  #value only
  #Case when max_len overrides requirements
  len = safe_len(map[:max_length], @@REQ_LEN_3_DGTS)
  (!blank?(map[:codetable]))? get_coded_value(map): generate_length_bound_id(len)
end

#IS(map, force = false) ⇒ Object

Generates HL7 IS (namespace id) data type



520
521
522
523
524
525
526
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 520

def IS(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  #TODO: same as ID?
  ID(map,true)
end

#JCC(map, force = false) ⇒ Object

Generates HL7 JCC (job code/class) data type.



530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 530

def JCC(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

val=[]
#job code (IS)
# is(['fld'=>jcc.getComponent(0), 'required'=>'R', 'codetable'=>map.codetable])
  val << IS(map, true)
#job class (IS)
  val << IS(map, true)
  # is(['fld'=>jcc.getComponent(1), 'required'=>'R'])
  val.join(@@HAT)
end

#LA1(map, force = false) ⇒ Object

Location with address information (variant 1)



545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 545

def LA1(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  val =[]
  # <point of care (IS)>
  val<<IS(map,true)
  # <room (IS) >
  val<<IS({:codetable =>'303'},true)
  # <bed (IS)>
  val<<IS({:codetable =>'304'},true)
  # <facility (HD) >
  val<<HD({},true)
  # <location status (IS)
  val<<''
  # <patient location type (IS)>
  val<<''
  # <building (IS)>
  val<<IS({:codetable =>'307'},true)
  # <floor (IS)>
  # <address(AD)>
  val.join(@@HAT)
end

#LA2(map, force = false) ⇒ Object

Location with address information (variant 2)



569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 569

def LA2(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  val =[]
  # <point of care (IS)>
  val<<IS(map,true)
  # <room (IS)
  val<<IS({:codetable =>'303'},true)
  # <bed (IS)>
  val<<IS({:codetable =>'304'},true)
  # <facility (HD) >
  val<<HD({},true)
  # <location status (IS)
  val<<''
  # <patient location type (IS)>
  val<<''
  # <building (IS)>
  val<<IS({:codetable =>'307'},true)
  # <floor (IS)>
  # < street address (ST)>
  # <other designation (ST)>
  # <city (ST)>
  # <state or province (ST)>
  # <zip or postal code (ST)>
  # <country (ID)>
  # <address type (ID)>
  # <other geographic designation (ST)>
  val.join(@@HAT)
end

#MA(map, force = false) ⇒ Object

MA segment



601
602
603
604
605
606
607
608
609
610
611
612
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 601

def MA(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <sample 1 from channel 1 (NM)>
  NM(map,true)
  # <sample 1 from channel 2 (NM)>
  # <sample 1 from channel 3 (NM)>
  # <sample 2 from channel 1 (NM)>
  # <sample 2 from channel 2 (NM)>
  # <sample 2 from channel 3 (NM)>
end

#MO(map, force = false) ⇒ Object

Generates an HL7 MO (money) data type.



616
617
618
619
620
621
622
623
624
625
626
627
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 616

def MO(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))
  # val = []
#quantity (NM)Guarantor Household Annual Income
# val << NM(reset_map_attr(map,:description,'Money'),true)
#val << NM(map,true)
NM(map,true)
#denomination (ID)
  # val << 'USD' # Per request.
  # return val.join(@@SUB)
end

#MOC(map, force = false) ⇒ Object

Charge to practice



630
631
632
633
634
635
636
637
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 630

def MOC(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <dollar amount (MO)>
  MO(map,true)
  # <charge code (CE)>
end

#MOP(map, force = false) ⇒ Object

Money or percentage



640
641
642
643
644
645
646
647
648
649
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 640

def MOP(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  val=[]
  # <money or percentage indicator (IS)>
  val<<IS({:codetable =>'148'},true)
  # <money or percentage quantity (NM)>
  val<<NM({:description =>'Percentage'},true)
  val.join(@@HAT)
end

#MSG(map, force = false) ⇒ Object

MSG segment



652
653
654
655
656
657
658
659
660
661
662
663
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 652

def MSG(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  val=[]
  # <message type (ID)>
  val<<IS({:codetable =>'76'},true)
  # <trigger event (ID)>
  val<<IS({:codetable =>'3'},true)
  # <message structure (ID)>
  val<<IS({:codetable =>'354'},true)
  val.join(@@HAT)
end

#MSH(map, force = false) ⇒ Object

Generates HL7 MSG (Message Type) data type.



666
667
668
669
670
671
672
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 666

def MSH(map, force=false)
  #Message type set while initializing MSH segment, do nothing.

  #message type (ID)
  #trigger event (ID)
  #message structure (ID)
end

#NA(map, force = false) ⇒ Object

Numeric Array



676
677
678
679
680
681
682
683
684
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 676

def NA(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  # <value1 (NM)>
  NM(map,true)
  # <value2 (NM)>
  # <value3 (NM)>
  # <value4 (NM)>
end

#NDL(map, force = false) ⇒ Object

Observing practitioner



687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 687

def NDL(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  # <name (CNN)>
  CNN(map,true)
  # <start date/time (TS)>
  # <end date/time (TS)>
  # <point of care (IS)>
  # <room (IS)>
  # <bed (IS)>
  # <facility (HD)>
  # <location status (IS)>
  # <person location type (IS)>
  # <building (IS)>
  # <floor (IS)>
end

#NM(map, force = false) ⇒ Object

Generates an HL7 NM (numeric) data type. A NM contains a single String value.



705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 705

def NM(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))
  val = 0
  case map[:description]
    when'Guarantor Household Size','Birth Order'
      val = generate_length_bound_id(1)
    when 'Guarantor Household Annual Income'
      val = '%.2f' % generate_length_bound_id(5)
    when @@MONEY_FORMAT_REGEX
      val = '%.2f' % ID(map,true)
    when  @@PERCENT_FORMAT_REGEX
      val = @@random.rand(0..100) # generate proper % value < 100
    else
      val = ID(map,true) # general rule for a number
      if (map[:datatype] == 'CP' || map[:datatype] == 'MO') # money
        val = '%.2f' % val
      end
   end
  # #money
  # if (!Utils.blank?(map[:description]) && @@MONEY_FORMAT_INDICATORS.index{|it| map[:description].include?(it)}) #check for specific numeric for money
	# val = '%.2f' % @@random.rand(@@UP_TO_3_DGTS) #under $1,000
  # else #quantity (NM)
  #   val =  @@random.rand(@@UP_TO_3_DGTS).to_s #under 20
  # end
  return val
end

#NR(map, force = false) ⇒ Object

Numeric Range



735
736
737
738
739
740
741
742
743
744
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 735

def NR(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  val=[]
  # Low Value (NM)
  val=NM(map,true)
  # High Value (NM)
  val<<''
  val.join(@@SUB)
end

#OCD(map, force = false) ⇒ Object

Generates an HL7 OCD (occurence) data type. The code and associated date defining a significant event relating to a bill that may affect payer processing



748
749
750
751
752
753
754
755
756
757
758
759
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 748

def OCD(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))
  val = []
#occurrence code (IS)
  val << IS(map, true)
# is(['fld'=>ocd.getComponent(0), 'required'=>'R', 'codetable'=>map.codetable])
#occurrence date (DT)
#dt(['fld'=>ocd.getComponent(1), 'required'=>'R'])
  val << DT(map, true)
  val.join(@@HAT)
end

#OIP(map, force = false) ⇒ Object

Query input parameter list



954
955
956
957
958
959
960
961
962
963
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 954

def OIP(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <segment field name (ST) >
  # <value1 (ST) & value2 (ST) & value3 (ST) ...>
  #Example: |@PID.5.1^EVANS|
  #TBD
  ''
end

#OSD(map, force = false) ⇒ Object

Order sequence



762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 762

def OSD(map, force=false)
  #check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

  # <sequence/results flag (ID)>
  ID(map, force)
  # <placer order number: entity identifier (ST)>
  # <placer order number: namespace ID (IS)>
  # <filler order number: entity identifier (ST)>
  # <filler order number: namespace ID (IS)>
  # <sequence condition value (ST)>
  # <maximum number of repeats (NM)>
  # <placer order number: universal ID (ST)>
  # <placer order number; universal ID type (ID)>
  # <filler order number: universal ID (ST)>
  # <filler order number: universal ID type (ID)>
end

#OSP(map, force = false) ⇒ Object

Generate an HL7 OSP (occurence span) data type.



781
782
783
784
785
786
787
788
789
790
791
792
793
794
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 781

def OSP(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))
  val = []

#occurrence span code (CE)
  # val << CE(map, true) # Per request with ADT_A05 and ADT_A06 issues
  val << ID(map, true)
#occurrence span start date (DT)
  val << DT({},true)
#occurrence span stop date (DT)
  val << DT(reset_map_attr(map, :description, 'End'), true)
  val.join(@@HAT)
end

#PCF(map, force = false) ⇒ Object

Pre-certification required



797
798
799
800
801
802
803
804
805
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 797

def PCF(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <pre-certification patient type (IS)>
  IS({:codetable =>'150'},true)
  # <pre-certification required>
  # <pre-certification window>
end

#PI(map, force = false) ⇒ Object

Person identifier



808
809
810
811
812
813
814
815
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 808

def PI(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  # <ID number (ST)>
  ST(map,true)
  # <type of ID number>
  # <other qualifying info>
end

#PIP(map, force = false) ⇒ Object

Privileges



818
819
820
821
822
823
824
825
826
827
828
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 818

def PIP(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <privilege (CE)>
  IS(map,true)
  # <privilege class (CE)>
  # <expiration date (DT)>
  # <activation date (DT)>
  # <facility (EI)>
end

#PL(map, force = false) ⇒ Object

Generate an HL7 PL (person location) data type.



832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 832

def PL(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))
  val = []
#point of care (IS)
  val<<IS({:codetable =>'302'},true)
#room (IS)
  val<<IS({:codetable =>'303'},true)
#bed (IS)
  val<<IS({:codetable =>'304'},true)
#facility (HD) (HD)
val << HD({:codetable =>'300'}, true)
#location status (IS)
  val << ''
#person location type (IS)
  val << ''
#building (IS)
  val<<IS({:codetable =>'307'},true)
#floor (IS)
#Location description (ST)
  val.join(@@HAT)
end

#PLN(map, force = false) ⇒ Object

Practitioner ID Numbers



856
857
858
859
860
861
862
863
864
865
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 856

def PLN(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <ID number (ST)>
  ST(map,true)
  # <type of ID number (IS)>
  # <state/other qualifying info (ST)>
  # <expiration date (DT)>
end

#PN(map, force = false) ⇒ Object

Person name



868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 868

def PN(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  val=[]
  # family name (FN)
  val << FN(map, true)
  # given name (ST)
  val << @yml['person.names.first'].sample
  # second and further given names or initials thereof (ST)
  val << @@INITIALS.to_a.sample
  # suffix (e.g., JR or III) (ST)
  # prefix (e.g., DR) (ST)
  # degree (e.g., MD) (IS)
  val.join(@@HAT)
end

#PPN(map, force = false) ⇒ Object

Performing person time stamp



885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 885

def PPN(map, force=false)
  # check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  val = []
  # <ID number (ST)>
  val << ST(map,true)

  # PN will work for the subset of fields used below
  val << PN({},true)
  # <family name (FN)>
  # <given name (ST)>
  # <second and further given names or initials thereof (ST)>
  # <suffix (e.g., JR or III) (ST)>
  # <prefix (e.g., DR) (ST)>
  # <degree (e.g., MD) (IS)>
  # <source table (IS)>
  # <assigning authority (HD)>
  # <name type code(ID)>
  # <identifier check digit (ST)>
  # <code identifying the check digit scheme employed (ID )>
  # <identifier type code (IS)>
  # <assigning facility (HD)>
  # < date/time action performed (TS)>
  # <name representation code (ID)>
  # <name context (CE)>
  # <name validity range (DR)>
  # <name assembly order (ID)>

  val.join(@@HAT)
end

#PR(map, force = false) ⇒ Object

Reference pointer



1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1040

def PR(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <pointer (ST) >
  ST(map,true)
  # < application ID (HD)>
  # <type of data (ID)>
  # <subtype (ID)>
end

#PRL(map, force = false) ⇒ Object

Parent result link



917
918
919
920
921
922
923
924
925
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 917

def PRL(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <OBX-3-observation identifier of parent result (CE)>
  CE(map,true)
  # <OBX-4-sub-ID of parent result(ST)>
  # <part of OBX-5 observation result from parent (TX)see discussion>
end

#PT(map, force = false) ⇒ Object

Generate HL7 S PT (processing type) data type.



928
929
930
931
932
933
934
935
936
937
938
939
940
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 928

def PT(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

#map.maxlen
# PT pt = (PT) map.fld
# Map mp = map.clone()
# mp.fld = pt.getComponent(0)
# mp.required = 'R'
ID(map, true)
#processing ID (ID)
#processing mode (ID)
end

#PTA(map, force = false) ⇒ Object

Processing type



943
944
945
946
947
948
949
950
951
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 943

def PTA(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <processing ID (ID)>
  ID(map, true)
  # <processing mode (ID)>
  # <processing ID (ID)>
end

#QSC(map, force = false) ⇒ Object

QSC Query selection criteria



966
967
968
969
970
971
972
973
974
975
976
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 966

def QSC(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <segment field name(ST)>
  # <relational operator (ID)>
  # <value (ST)> <relational conjunction (ID)>
  # Example: |@PID.5.1^EQ^EVANS|"
  #TBD
  ''
end

#RCD(map, force = false) ⇒ Object

RCD Row column definition



979
980
981
982
983
984
985
986
987
988
989
990
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 979

def RCD(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <segment field name (ST)>
  ST(reset_map_attr(map,:codetable, '440'),true)
  # <HL7 data type (ID)>
  # <maximum column width (NM)>
  # Example: |@PID.5.1^ST^20|"
  #TBD
  # ''
end

#RDT(map, force = false) ⇒ Object

RDF Table row definition



993
994
995
996
997
998
999
1000
1001
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 993

def RDT(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  val = []
  # <parameter class (IS)>
  # randomly generated 3-digit number
  # v << generate_length_bound_id(@@REQ_LEN_3_DGTS)
  ID({},true)
end

#reset_map_attr(map, key, value) ⇒ Object

convention method to modify values of attirbutes



1581
1582
1583
1584
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1581

def reset_map_attr(map, key, value)
  map[key.to_sym]=value
  return map
end

#RFR(map, force = false) ⇒ Object

Reference range



1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1004

def RFR(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <numeric range (NR)>
  NR(map, true)
  # <administrative sex (IS)
  # <age range (NR)>
  # <gestational range (NR)>
  # <species (TX)>
  # <race/subspecies (ST)>
  # <conditions (TX)>
end

#RI(map, force = false) ⇒ Object

Repeat interval



1019
1020
1021
1022
1023
1024
1025
1026
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1019

def RI(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  # <repeat pattern (IS)>
  # IS(map,true)
  IS(reset_map_attr(map, :codetable, '335'), true)
  # <explicit time interval (ST)>
end

#RMC(map, force = false) ⇒ Object

Room coverage



1029
1030
1031
1032
1033
1034
1035
1036
1037
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1029

def RMC(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <room type> (IS)
  IS(map,true)
  # <amount type>
  # <coverage amount>
end

#SCV(map, force = false) ⇒ Object

SCV Scheduling class value pair



1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1064

def SCV(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  val = []
  # <parameter class (IS)>
  val<<''
  # <parameter value (ST)>
  # val<<ST(map,true)
  val<<ST(reset_map_attr(map,:codetable, '294'),true)
  val.join(@@HAT)
end

#SI(map, force = false) ⇒ Object

Generate HL7 SI (sequence ID) data type. A SI contains a single String value.



1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1078

def SI(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

#SI pt = (SI) map.fld
#pt.setValue(generate_length_bound_id((map.max_length)?map.max_length.toInteger():1))
  len = (!blank?(map[:max_length]))?map[:max_length].to_i : 1
  # per Galina: - the set IDs should be max 4 digits, please remove all the zeros.
  len = (len >4 )? 4 :len
  generate_length_bound_id(len)
end

#SN(map, force = false) ⇒ Object

Structured numeric



1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1091

def SN(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return ''  if(!generate?(map, force))
  val = []
  # <comparator (ST)>
  val << ''
  # <num1 (NM)>
  val << NM(map,true)
  # <separator/suffix (ST)>
  # <num2 (NM)>
  val.join(@@HAT)
end

#SPD(map, force = false) ⇒ Object

Specialty



1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1105

def SPD(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <specialty name (ST)>
  ST(map,true)
  # <governing board (ST)>
  # <eligible or certified (ID)>
  # <date of certification (DT)>
end

#SPS(map, force = false) ⇒ Object

Specimen source



1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1117

def SPS(map, force=false)
  #check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

  #<specimen source name or code (CE)>
  CE(map,true)
  # <additives (TX)>
  # <freetext (TX)>
  # <body site (CE)>
  # <site modifier (CE)>
  # <collection modifier method code (CE)>
  # <specimen role (CE)>
end

#SRT(map, force = false) ⇒ Object

Sort order



1132
1133
1134
1135
1136
1137
1138
1139
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1132

def SRT(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <sort-by field (ST)>
  # <sequencing (ID)>
  ID(map,true)
end

#ST(map, force = false) ⇒ Object

Generate HL7 ST (string data) data type. A ST contains a single String value.



1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1142

def ST(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # TODO add provider type ln 840 ROL
  case map[:description]
    when 'Guarantor SSN','Insured’s Social Security Number','Medicare health ins Card Number','Military ID Number', 'Contact Person Social Security Number'
      generate_length_bound_id(9)
    when 'Allergy Reaction Code'
      yml['codes.allergens'].keys.sample()
    when 'Strain'
      #PID.35 – PID.38 should be always blank, as they deal with animals, not humans.
    when 'AGENT ORANGE EXPOSURE LOCATION'
      #ZEL.29 should be 1 digit integer.
      generate_length_bound_id(1)
    else
      #Case when max_len overrides requirements
      len = safe_len(map[:max_length], @@REQ_LEN_3_DGTS)
      (!blank?(map[:codetable]))? get_coded_value(map): generate_length_bound_id(len)
  end

end

#TM(map, force = false) ⇒ Object

An Elementary Data Type Format: HH[MM[SS[.S[S[S]]]]][+/-ZZZZ] EX: 160140.761



1167
1168
1169
1170
1171
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1167

def TM(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  to_datetime(map).strftime('%H%M%S.%L')
end

#TN(map, force = false) ⇒ Object

Generate an HL7 TN (telephone number) data type. A TN contains a single String value.



1174
1175
1176
1177
1178
1179
1180
1181
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1174

def TN(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # TN tn = (TN) map.fld
  # tn.setValue(phones.getAt(Math.abs(random.nextInt()%phones.size())))
  @yml['address.phones'].sample # pick a phone
end

#to_datetime(map) ⇒ Object

Returns DateTime generated with consideration of description string for dates in the future.

Returns:

  • DateTime generated with consideration of description string for dates in the future



1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1565

def to_datetime(map)
  #for Time Stamp one way to figure out if event is in the future of in the past to look for key words in description
  isFutureEvent = !blank?(map[:description])&& map[:description].include?('End') #so 'Role End Date/Time'
  seed = 365 #seed bounds duration of time to a year
  days = @@random.rand(seed)

  if(map[:description]=='Date/Time Of Birth')
    isFutureEvent = false
    years = rand(30..50)
    days = days + 365*years # make a person 30 years old
  end

  (isFutureEvent) ? DateTime.now().next_day(days) : DateTime.now().prev_day(days)
end

#TQ(map, force = false) ⇒ Object

Timing quantity



1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1184

def TQ(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <quantity (CQ)>
  # CQ(reset_map_attr(map, :codetable, '335'), true)
  CQ(map,true)
  # <interval (RI)
  # < duration (ST)>
  # <start date/time (TS)>
  # <end date/time (TS)>
  # <priority (ST)>
  # <condition (ST)>
  # <text (TX)>
  # <conjunction component (ID)>
  # <order sequencing (OSD)>
  # <occurrence duration (CE)>
  # <total occurrences (NM)>
end

#TS(map, force = false) ⇒ Object

Generate HL7 TS (time stamp), within number of weeks in the future or past



1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1205

def TS(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

   #time of an event (TSComponentOne)
  ts = to_datetime(map).strftime('%Y%m%d%H%M%S.%L') #format('YYYYMMDDHHSS.SSS')Date.iso8601
  # TS is lenght sensetive, check max_len and trim appropriate
  if (ts.size > (maxlen = (map[:max_length]) ? map[:max_length].to_i : ts.size))
    # puts ts
    # ts = ts[0,maxlen]
    ts = ts.slice(0...maxlen)
  end
  return ts
end

#TX(map, force = false) ⇒ Object

Generate HL7 TX (text data) data type. A TX contains a single String value.



1221
1222
1223
1224
1225
1226
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1221

def TX(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  # @@GENERAL_TEXT
  ID(map,true)
end

#UVC(map, force = false) ⇒ Object

Generate an HL7 UVC (Value code and amount) data type.



1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1229

def UVC(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))
  val =[]
# UVC uvc = ((UVC)map.fld)
#value code (IS)
  val << IS(map, true)
# is(['fld'=>uvc.getComponent(0), 'required'=>'R', 'codetable'=>map.codetable])
#value amount (NM)
# nm(['fld'=>uvc.getComponent(1), 'required'=>'R'])
  val << NM({},true)# description confuses NM generator
  val.join(@@HAT)
end

#VH(map, force = false) ⇒ Object

Visiting hours



1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1244

def VH(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  val =[]
  # <start day range (ID)>
  val << ID(map,true)
  # <end day range (ID)>
  val << ID(map,true)
  # <start hour range (TM)>
  # <end hour range (TM)>
  val.join(@@HAT)
end

#VID(map, force = false) ⇒ Object

Generate an HL7 VID (version identifier) data type.



1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1259

def VID(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

# VID vid = ((VID)map.fld)
  #version ID (ID)
  ID(map, true)
#id(['fld'=>vid.getComponent(0), 'required'=>'R', 'codetable'=>map.codetable])

#		internationalization code (CE)
#		international version ID (CE)
end

#VR(map, force = false) ⇒ Object

Value qualifier



1273
1274
1275
1276
1277
1278
1279
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1273

def VR(map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  # <first data code value (ST)>
  ST(map,true)
  # <Last data code value (ST)>
end

#WVI(map, force = true) ⇒ Object

Channel identifier



1282
1283
1284
1285
1286
1287
1288
1289
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1282

def WVI(map, force=true)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))

  # <channel number (NM)>
  NM(map, true)
  # <channel name (ST)>
end

#XAD(map, force = false) ⇒ Object

Generate HL7 XAD (extended address)



1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1298

def XAD(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

  # same as address AD
  AD(map,true)
#street address (SAD) (SAD)
#other designation (ST)
#city (ST)
  #state or province (ST)
  #zip or postal code (ST)
  #country (ID)
#address type (ID)
#other geographic designation (ST)
#county/parish code (IS)
#census tract (IS)
#address representation code (ID)
#address validity range (DR)
end

#XCN(map, force = false) ⇒ Object

Generate HL7 XCN (extended composite ID number and name for persons)



1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1319

def XCN(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

  val=[]
# XCN xcn = (XCN) map.fld
# ID number (ST) (ST)
  val << ID(map, true)
# xcn.getIDNumber().setValue(Math.abs(random.nextInt() % 300).toString())

  val << PN(map, true)
# family name (FN)
  # val << FN(map, true)
# given name (ST)
  # val << @yml['person.names.first'].sample
  # second and further given names or initials thereof (ST)
  # val << @@INITIALS.to_a.sample
# suffix (e.g., JR or III) (ST)
# prefix (e.g., DR) (ST)
# degree (e.g., MD) (IS)

# source table (IS)
# assigning authority (HD)
# name type code (ID)
# identifier check digit (ST)
# code identifying the check digit scheme employed (ID)
# identifier type code (IS) (IS)
# assigning facility (HD)
# Name Representation code (ID)
# name context (CE)
# name validity range (DR)
# name assembly order (ID)
  val.join(@@HAT)
end

#XON(map, force = false) ⇒ Object

Generate an HL7 XON (extended composite name and identification number for organizations) data type.



1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1355

def XON(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

# XON xtn = (XON) map.fld
  val=[]
#organization name (ST)
  val << ST(map, true)
# st(['fld'=>xtn.getComponent(0), 'required'=>'R', 'codetable'=>map.codetable])
#organization name type code (IS)
  val << ''
#ID number (NM) (NM)
  val << NM(map, true)
#nm(['fld'=>xtn.getComponent(2), 'required'=>'R'])
#check digit (NM) (ST)
#code identifying the check digit scheme employed (ID)
#assigning authority (HD)
#identifier type code (IS) (IS)
#assigning facility ID (HD)
#Name Representation code (ID)
  val.join(@@HAT)
end

#XPN(map, force = false) ⇒ Object

Generate an HL7 XPN (extended person name) data type. This type consists of the following components=>



1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1379

def XPN(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

  # val=[]
#family name (FN)
  # val << FN(map, true)
# fn(['fld'=> xpn.getComponent(0),'required'=>'R'])
#given name (ST)
  # val << @yml['person.names.first'].sample
  #xpn.givenName.setValue(firstNames.getAt(Math.abs(random.nextInt()%firstNames.size())));
  #xpn.getComponent(1).setValue(firstNames.getAt(Math.abs(random.nextInt()%firstNames.size())))
  #second and further given names or initials thereof (ST)
  # val << @@INITIALS.to_a.sample
  #xpn.secondAndFurtherGivenNamesOrInitialsThereof.setValue('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.getAt(Math.abs(random.nextInt()%26)))
#suffix (e.g., JR or III) (ST)
#prefix (e.g., DR) (ST)
#degree (e.g., MD) (IS)
  PN(map,true)

#name type code (ID)
  # val.join(@@HAT)

end

#XTN(map, force = false) ⇒ Object

Generate HL7 XTN (extended telecommunication number)



1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1405

def XTN(map, force=false)
#check if the field is optional and randomly generate it of skip
return '' if(!generate?(map, force))

#[(999)] 999-9999 [X99999][C any text] (TN)
TN(map, true)
  #xtn.get9999999X99999CAnyText().setValue(phones.getAt(Math.abs(random.nextInt()%phones.size())))
  # telecommunication use code (ID)
  # telecommunication equipment type (ID) (ID)
  # Email address (ST)
  # Country Code (NM)
  # Area/city code (NM)
  # Phone number (NM)
  # Extension (NM)
  # any text (ST)
end