ruby-hl7 0.1.23 → 0.2.44
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ruby-hl7.rb +128 -36
- data/lib/segments/obr.rb +2 -2
- data/lib/segments/obx.rb +2 -1
- data/lib/segments/pid.rb +2 -2
- data/test/test_basic_parsing.rb +23 -3
- data/test/test_child_segment.rb +54 -0
- data/test/test_default_segment.rb +1 -1
- data/test/test_dynamic_segment_def.rb +42 -0
- data/test/test_msa_segment.rb +1 -1
- data/test/test_obr_segment.rb +1 -1
- data/test/test_obx_segment.rb +1 -1
- data/test/test_pid_segment.rb +2 -1
- data/test/test_speed_parsing.rb +19 -0
- data/test_data/empty.hl7 +0 -0
- data/test_data/empty_segments.hl7 +1 -0
- data/test_data/lotsunknowns.hl7 +2 -0
- data/test_data/obxobr.hl7 +1 -0
- data/test_data/test.hl7 +1 -1
- metadata +12 -5
data/lib/ruby-hl7.rb
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
#
|
10
10
|
# License: BSD
|
11
11
|
#
|
12
|
-
# $Id: ruby-hl7.rb
|
12
|
+
# $Id: ruby-hl7.rb 44 2007-08-05 21:51:28Z segfault $
|
13
13
|
#
|
14
14
|
# == License
|
15
15
|
# see the LICENSE file
|
@@ -19,9 +19,10 @@ require 'rubygems'
|
|
19
19
|
require "stringio"
|
20
20
|
require "date"
|
21
21
|
require 'facets/core/class/cattr'
|
22
|
+
require 'facets/core/proc/bind'
|
22
23
|
|
23
24
|
module HL7 # :nodoc:
|
24
|
-
VERSION = "0.
|
25
|
+
VERSION = "0.2.%s" % "$Rev: 44 $".gsub(/\$Rev:\s+/, '').gsub(/\s*\$$/, '')
|
25
26
|
end
|
26
27
|
|
27
28
|
# Encapsulate HL7 specific exceptions
|
@@ -80,7 +81,7 @@ class HL7::Message
|
|
80
81
|
# setup a new hl7 message
|
81
82
|
# raw_msg:: is an optional object containing an hl7 message
|
82
83
|
# it can either be a string or an Enumerable object
|
83
|
-
def initialize( raw_msg=nil )
|
84
|
+
def initialize( raw_msg=nil, &blk )
|
84
85
|
@segments = []
|
85
86
|
@segments_by_name = {}
|
86
87
|
@item_delim = "^"
|
@@ -88,6 +89,10 @@ class HL7::Message
|
|
88
89
|
@segment_delim = "\r"
|
89
90
|
|
90
91
|
parse( raw_msg ) if raw_msg
|
92
|
+
|
93
|
+
if block_given?
|
94
|
+
blk.call self
|
95
|
+
end
|
91
96
|
end
|
92
97
|
|
93
98
|
# access a segment of the message
|
@@ -100,7 +105,7 @@ class HL7::Message
|
|
100
105
|
ret = @segments[ index ]
|
101
106
|
elsif (index.respond_to? :to_sym)
|
102
107
|
ret = @segments_by_name[ index.to_sym ]
|
103
|
-
ret = ret.first if ret.length == 1
|
108
|
+
ret = ret.first if ret && ret.length == 1
|
104
109
|
end
|
105
110
|
|
106
111
|
ret
|
@@ -117,9 +122,13 @@ class HL7::Message
|
|
117
122
|
|
118
123
|
if index.kind_of?(Range) || index.kind_of?(Fixnum)
|
119
124
|
@segments[ index ] = value
|
120
|
-
|
125
|
+
elsif index.respond_to?(:to_sym)
|
121
126
|
(@segments_by_name[ index.to_sym ] ||= []) << value
|
127
|
+
else
|
128
|
+
raise HL7::Exception.new( "attempting to use an indice that is not a Range, Fixnum or to_sym providing object" )
|
122
129
|
end
|
130
|
+
|
131
|
+
value.segment_parent = self
|
123
132
|
end
|
124
133
|
|
125
134
|
# return the index of the value if it exists, nil otherwise
|
@@ -140,10 +149,11 @@ class HL7::Message
|
|
140
149
|
raise HL7::Exception.new( "attempting to append something other than an HL7 Segment" )
|
141
150
|
end
|
142
151
|
|
152
|
+
value.segment_parent = self unless value.segment_parent
|
143
153
|
(@segments ||= []) << value
|
144
154
|
name = value.class.to_s.gsub("HL7::Message::Segment::", "").to_sym
|
145
155
|
(@segments_by_name[ name ] ||= []) << value
|
146
|
-
sequence_segments # let's auto-set the set-id as we go
|
156
|
+
sequence_segments unless @parsing # let's auto-set the set-id as we go
|
147
157
|
end
|
148
158
|
|
149
159
|
# parse a String or Enumerable object into an HL7::Message if possible
|
@@ -172,15 +182,23 @@ class HL7::Message
|
|
172
182
|
return unless @segments
|
173
183
|
@segments.each { |s| yield s }
|
174
184
|
end
|
185
|
+
|
186
|
+
# return the segment count
|
187
|
+
def length
|
188
|
+
0 unless @segments
|
189
|
+
@segments.length
|
190
|
+
end
|
175
191
|
|
176
192
|
# provide a screen-readable version of the message
|
177
|
-
def to_s
|
178
|
-
@segments.
|
193
|
+
def to_s
|
194
|
+
segs = @segments.collect { |s| s if s.to_s.length > 0 }
|
195
|
+
segs.join( "\n" )
|
179
196
|
end
|
180
197
|
|
181
198
|
# provide a HL7 spec version of the message
|
182
199
|
def to_hl7
|
183
|
-
@segments.
|
200
|
+
segs = @segments.collect { |s| s if s.to_s.length > 0 }
|
201
|
+
segs.join( @segment_delim )
|
184
202
|
end
|
185
203
|
|
186
204
|
# provide the HL7 spec version of the message wrapped in MLLP
|
@@ -233,27 +251,45 @@ class HL7::Message
|
|
233
251
|
def generate_segments( ary )
|
234
252
|
raise HL7::ParseError.new unless ary.length > 0
|
235
253
|
|
254
|
+
@parsing = true
|
255
|
+
last_seg = nil
|
236
256
|
ary.each do |elm|
|
257
|
+
last_seg = generate_segment( elm, last_seg )
|
258
|
+
end
|
259
|
+
@parsing = nil
|
260
|
+
end
|
261
|
+
|
262
|
+
def generate_segment( elm, last_seg )
|
237
263
|
seg_parts = elm.split( @element_delim, -1 )
|
238
264
|
raise HL7::ParseError.new unless seg_parts && (seg_parts.length > 0)
|
239
265
|
|
240
266
|
seg_name = seg_parts[0]
|
241
|
-
|
267
|
+
if HL7::Message::Segment.constants.index(seg_name) # do we have an implementation?
|
242
268
|
kls = eval("HL7::Message::Segment::%s" % seg_name)
|
243
|
-
|
269
|
+
else
|
244
270
|
# we don't have an implementation for this segment
|
245
271
|
# so lets just preserve the data
|
246
272
|
kls = HL7::Message::Segment::Default
|
247
273
|
end
|
248
274
|
new_seg = kls.new( elm )
|
275
|
+
new_seg.segment_parent = self
|
276
|
+
|
277
|
+
if last_seg && last_seg.respond_to?(:children) && last_seg.accepts?( seg_name )
|
278
|
+
last_seg.children << new_seg
|
279
|
+
new_seg.is_child_segment = true
|
280
|
+
return last_seg
|
281
|
+
end
|
282
|
+
|
249
283
|
@segments << new_seg
|
250
284
|
|
251
285
|
# we want to allow segment lookup by name
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
286
|
+
if seg_name && (seg_name.strip.length > 0)
|
287
|
+
seg_sym = seg_name.to_sym
|
288
|
+
@segments_by_name[ seg_sym ] ||= []
|
289
|
+
@segments_by_name[ seg_sym ] << new_seg
|
290
|
+
end
|
256
291
|
|
292
|
+
new_seg
|
257
293
|
end
|
258
294
|
end
|
259
295
|
|
@@ -276,6 +312,7 @@ end
|
|
276
312
|
# # and when seg.block_example is called
|
277
313
|
#
|
278
314
|
class HL7::Message::Segment
|
315
|
+
attr :segment_parent, true
|
279
316
|
attr :element_delim
|
280
317
|
attr :item_delim
|
281
318
|
attr :segment_weight
|
@@ -283,10 +320,11 @@ class HL7::Message::Segment
|
|
283
320
|
# setup a new HL7::Message::Segment
|
284
321
|
# raw_segment:: is an optional String or Array which will be used as the
|
285
322
|
# segment's field data
|
286
|
-
def initialize(raw_segment="")
|
323
|
+
def initialize(raw_segment="", &blk)
|
287
324
|
@segments_by_name = {}
|
288
325
|
@element_delim = '|'
|
289
326
|
@field_total = 0
|
327
|
+
@is_child = false
|
290
328
|
|
291
329
|
if (raw_segment.kind_of? Array)
|
292
330
|
@elements = raw_segment
|
@@ -297,6 +335,27 @@ class HL7::Message::Segment
|
|
297
335
|
@elements << ""
|
298
336
|
end
|
299
337
|
end
|
338
|
+
|
339
|
+
if block_given?
|
340
|
+
callctx = eval( "self", blk )
|
341
|
+
def callctx.__seg__(val=nil)
|
342
|
+
@__seg_val__ ||= val
|
343
|
+
end
|
344
|
+
callctx.__seg__(self)
|
345
|
+
# TODO: find out if this pollutes the calling namespace permanently...
|
346
|
+
|
347
|
+
to_do = <<-END
|
348
|
+
def method_missing( sym, *args, &blk )
|
349
|
+
__seg__.send( sym, args, blk )
|
350
|
+
end
|
351
|
+
END
|
352
|
+
|
353
|
+
eval( to_do, blk )
|
354
|
+
yield self
|
355
|
+
eval( "undef method_missing", blk )
|
356
|
+
#eval( "undef __seg__", blk )
|
357
|
+
#eval( "remove_instance_variable '@__seg_val__'", blk )
|
358
|
+
end
|
300
359
|
end
|
301
360
|
|
302
361
|
def to_info
|
@@ -330,10 +389,17 @@ class HL7::Message::Segment
|
|
330
389
|
if sym.to_s.include?( "=" )
|
331
390
|
write_field( base_sym, args )
|
332
391
|
else
|
333
|
-
|
392
|
+
|
393
|
+
if args.length > 0
|
394
|
+
write_field( base_sym, args )
|
395
|
+
else
|
396
|
+
read_field( base_sym )
|
397
|
+
end
|
398
|
+
|
334
399
|
end
|
335
400
|
end
|
336
401
|
|
402
|
+
# sort-compare two Segments, 0 indicates equality
|
337
403
|
def <=>( other )
|
338
404
|
return nil unless other.kind_of?(HL7::Message::Segment)
|
339
405
|
|
@@ -349,12 +415,29 @@ class HL7::Message::Segment
|
|
349
415
|
self.class.weight
|
350
416
|
end
|
351
417
|
|
418
|
+
|
419
|
+
# return true if the segment has a parent
|
420
|
+
def is_child_segment?
|
421
|
+
(@is_child_segment ||= false)
|
422
|
+
end
|
423
|
+
|
424
|
+
# indicate whether or not the segment has a parent
|
425
|
+
def is_child_segment=(val)
|
426
|
+
@is_child_segment = val
|
427
|
+
end
|
428
|
+
|
429
|
+
# get the length of the segment (number of fields it contains)
|
430
|
+
def length
|
431
|
+
0 unless @elements
|
432
|
+
@elements.length
|
433
|
+
end
|
434
|
+
|
435
|
+
|
352
436
|
private
|
353
437
|
def self.singleton #:nodoc:
|
354
438
|
class << self; self end
|
355
439
|
end
|
356
440
|
|
357
|
-
|
358
441
|
# DSL element to define a segment's sort weight
|
359
442
|
# returns the segment's current weight by default
|
360
443
|
# segments are sorted ascending
|
@@ -374,19 +457,32 @@ class HL7::Message::Segment
|
|
374
457
|
|
375
458
|
# allows a segment to store other segment objects
|
376
459
|
# used to handle associated lists like one OBR to many OBX segments
|
377
|
-
def self.has_children
|
460
|
+
def self.has_children(child_types)
|
461
|
+
@child_types = child_types
|
462
|
+
define_method(:child_types) do
|
463
|
+
@child_types
|
464
|
+
end
|
465
|
+
|
378
466
|
self.class_eval do
|
379
467
|
define_method(:children) do
|
380
468
|
unless @my_children
|
469
|
+
p = self
|
381
470
|
@my_children ||= []
|
382
471
|
@my_children.instance_eval do
|
472
|
+
@parental = p
|
383
473
|
alias :old_append :<<
|
384
474
|
|
385
475
|
def <<(value)
|
386
476
|
unless (value && value.kind_of?(HL7::Message::Segment))
|
387
477
|
raise HL7::Exception.new( "attempting to append non-segment to a segment list" )
|
388
478
|
end
|
389
|
-
|
479
|
+
|
480
|
+
value.segment_parent = @parental
|
481
|
+
k = @parental
|
482
|
+
while (k && k.segment_parent && !k.segment_parent.kind_of?(HL7::Message))
|
483
|
+
k = k.segment_parent
|
484
|
+
end
|
485
|
+
k.segment_parent << value if k && k.segment_parent
|
390
486
|
old_append( value )
|
391
487
|
end
|
392
488
|
end
|
@@ -395,20 +491,12 @@ class HL7::Message::Segment
|
|
395
491
|
@my_children
|
396
492
|
end
|
397
493
|
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
if @my_children
|
402
|
-
@my_children.each do |seg|
|
403
|
-
out << '\r'
|
404
|
-
out << seg.to_s
|
405
|
-
end
|
406
|
-
end
|
407
|
-
out
|
494
|
+
define_method('accepts?') do |t|
|
495
|
+
t = t.to_sym if t && (t.to_s.length > 0) && t.respond_to?(:to_sym)
|
496
|
+
child_types.index t
|
408
497
|
end
|
409
|
-
end
|
410
|
-
|
411
|
-
end
|
498
|
+
end
|
499
|
+
end
|
412
500
|
|
413
501
|
# define a field alias
|
414
502
|
# * options is a hash of parameters
|
@@ -435,8 +523,13 @@ class HL7::Message::Segment
|
|
435
523
|
end
|
436
524
|
|
437
525
|
self.class_eval <<-END
|
438
|
-
def #{name}()
|
439
|
-
|
526
|
+
def #{name}(val=nil)
|
527
|
+
unless val
|
528
|
+
read_field( :#{namesym} )
|
529
|
+
else
|
530
|
+
write_field( :#{namesym}, val )
|
531
|
+
val # this matches existing n= method functionality
|
532
|
+
end
|
440
533
|
end
|
441
534
|
|
442
535
|
def #{name}=(value)
|
@@ -491,7 +584,6 @@ class HL7::Message::Segment
|
|
491
584
|
|
492
585
|
@elements = []
|
493
586
|
|
494
|
-
|
495
587
|
end
|
496
588
|
|
497
589
|
# parse an hl7 formatted date
|
data/lib/segments/obr.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# $Id: obr.rb
|
1
|
+
# $Id: obr.rb 38 2007-06-27 04:56:09Z segfault $
|
2
2
|
require 'ruby-hl7'
|
3
3
|
class HL7::Message::Segment::OBR < HL7::Message::Segment
|
4
4
|
weight 89 # obr.weight-1
|
5
|
-
has_children
|
5
|
+
has_children [:OBX]
|
6
6
|
add_field :name=>:set_id
|
7
7
|
add_field :name=>:placer_order_number
|
8
8
|
add_field :name=>:filler_order_number
|
data/lib/segments/obx.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
# $Id: obx.rb
|
1
|
+
# $Id: obx.rb 38 2007-06-27 04:56:09Z segfault $
|
2
2
|
require 'ruby-hl7'
|
3
3
|
class HL7::Message::Segment::OBX < HL7::Message::Segment
|
4
4
|
weight 90
|
5
|
+
has_children [:NTE]
|
5
6
|
add_field :name=>:set_id
|
6
7
|
add_field :name=>:value_type
|
7
8
|
add_field :name=>:observation_id
|
data/lib/segments/pid.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: pid.rb
|
1
|
+
# $Id: pid.rb 29 2007-05-06 23:13:04Z segfault $
|
2
2
|
require 'ruby-hl7'
|
3
3
|
class HL7::Message::Segment::PID < HL7::Message::Segment
|
4
4
|
weight 1
|
@@ -10,7 +10,7 @@ class HL7::Message::Segment::PID < HL7::Message::Segment
|
|
10
10
|
add_field :name=>:mother_maiden_name
|
11
11
|
add_field :name=>:patient_dob
|
12
12
|
add_field :name=>:admin_sex do |sex|
|
13
|
-
unless /^[FMOUAN]$/.match(sex) || sex == nil
|
13
|
+
unless /^[FMOUAN]$/.match(sex) || sex == nil || sex == ""
|
14
14
|
raise HL7::InvalidDataError.new( "bad administrative sex value (not F|M|O|U|A|N)" )
|
15
15
|
end
|
16
16
|
sex = "" unless sex
|
data/test/test_basic_parsing.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: test_basic_parsing.rb
|
1
|
+
# $Id: test_basic_parsing.rb 41 2007-06-30 08:06:04Z segfault $
|
2
2
|
$: << '../lib'
|
3
3
|
require 'test/unit'
|
4
4
|
require 'ruby-hl7'
|
@@ -6,6 +6,8 @@ require 'ruby-hl7'
|
|
6
6
|
class BasicParsing < Test::Unit::TestCase
|
7
7
|
def setup
|
8
8
|
@simple_msh_txt = open( './test_data/test.hl7' ).readlines.first
|
9
|
+
@empty_txt = open( './test_data/empty.hl7' ).readlines.first
|
10
|
+
@empty_segments_txt = open( './test_data/empty_segments.hl7' ).readlines.first
|
9
11
|
@base_msh = "MSH|^~\\&|LAB1||DESTINATION||19910127105114||ORU^R03|LAB1003929"
|
10
12
|
end
|
11
13
|
|
@@ -31,10 +33,14 @@ class BasicParsing < Test::Unit::TestCase
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
36
|
+
def test_parse_empty
|
37
|
+
msg = HL7::Message.new @empty_txt
|
38
|
+
end
|
39
|
+
|
34
40
|
def test_message_to_string
|
35
41
|
msg = HL7::Message.new
|
36
42
|
msg.parse @simple_msh_txt
|
37
|
-
orig = @simple_msh_txt.gsub( /\r/,
|
43
|
+
orig = @simple_msh_txt.gsub( /\r/, "\n" )
|
38
44
|
assert_equal( orig, msg.to_s )
|
39
45
|
end
|
40
46
|
|
@@ -73,6 +79,14 @@ class BasicParsing < Test::Unit::TestCase
|
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
82
|
+
def test_segment_missing_accessor
|
83
|
+
msg = HL7::Message.new
|
84
|
+
msg.parse @simple_msh_txt
|
85
|
+
assert_nothing_raised do
|
86
|
+
assert_equal( nil, msg[:does_not_exist] )
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
76
90
|
def test_segment_string_mutator
|
77
91
|
msg = HL7::Message.new
|
78
92
|
msg.parse @simple_msh_txt
|
@@ -262,6 +276,7 @@ class BasicParsing < Test::Unit::TestCase
|
|
262
276
|
#multible obr's with multiple obx's
|
263
277
|
msg = HL7::Message.parse( @simple_msh_txt )
|
264
278
|
orig_output = msg.to_hl7
|
279
|
+
orig_obx_cnt = msg[:OBX].length
|
265
280
|
(1..10).each do |obr_id|
|
266
281
|
obr = HL7::Message::Segment::OBR.new
|
267
282
|
msg << obr
|
@@ -274,7 +289,7 @@ class BasicParsing < Test::Unit::TestCase
|
|
274
289
|
assert_not_nil( msg[:OBR] )
|
275
290
|
assert_equal( 11, msg[:OBR].length )
|
276
291
|
assert_not_nil( msg[:OBX] )
|
277
|
-
assert_equal(
|
292
|
+
assert_equal( 102, msg[:OBX].length )
|
278
293
|
assert_equal( "2", msg[:OBR][4].children[1].set_id ) # confirm the id's
|
279
294
|
assert_equal( "2", msg[:OBR][5].children[1].set_id ) # confirm the id's
|
280
295
|
|
@@ -303,4 +318,9 @@ class BasicParsing < Test::Unit::TestCase
|
|
303
318
|
end
|
304
319
|
end
|
305
320
|
|
321
|
+
def test_empty_segment
|
322
|
+
msg = HL7::Message.new @empty_segments_txt
|
323
|
+
|
324
|
+
end
|
325
|
+
|
306
326
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# $Id: test_child_segment.rb 41 2007-06-30 08:06:04Z segfault $
|
2
|
+
$: << '../lib'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ruby-hl7'
|
5
|
+
|
6
|
+
class ChildSegment < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@base = open( './test_data/obxobr.hl7' ).readlines
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_access_children
|
12
|
+
msg = HL7::Message.new @base
|
13
|
+
assert_not_nil msg
|
14
|
+
assert_not_nil msg[:OBR]
|
15
|
+
assert_equal( 3, msg[:OBR].length )
|
16
|
+
assert_not_nil msg[:OBR].first.children
|
17
|
+
assert_equal( 5, msg[:OBR].first.children.length )
|
18
|
+
|
19
|
+
msg[:OBR].first.children.each do |x|
|
20
|
+
assert_not_nil x
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_add_children
|
25
|
+
msg = HL7::Message.new @base
|
26
|
+
assert_not_nil msg
|
27
|
+
assert_not_nil msg[:OBR]
|
28
|
+
ob = HL7::Message::Segment::OBR.new
|
29
|
+
assert_not_nil ob
|
30
|
+
|
31
|
+
msg << ob
|
32
|
+
assert_not_nil ob.children
|
33
|
+
assert_not_nil ob.segment_parent
|
34
|
+
assert_equal(msg, ob.segment_parent)
|
35
|
+
orig_cnt = msg.length
|
36
|
+
|
37
|
+
(1..4).each do |x|
|
38
|
+
m = HL7::Message::Segment::OBX.new
|
39
|
+
m.observation_value = "taco"
|
40
|
+
assert_not_nil m
|
41
|
+
assert_not_nil /taco/.match( m.to_s )
|
42
|
+
ob.children << m
|
43
|
+
assert_equal(x, ob.children.length)
|
44
|
+
assert_not_nil m.segment_parent
|
45
|
+
assert_equal(ob, m.segment_parent)
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_not_equal( @base, msg.to_hl7 )
|
49
|
+
assert_not_equal( orig_cnt, msg.length )
|
50
|
+
text_ver = msg.to_hl7
|
51
|
+
assert_not_nil /taco/.match( text_ver )
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# $Id: test_dynamic_segment_def.rb 40 2007-06-30 01:29:19Z segfault $
|
2
|
+
$: << '../lib'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ruby-hl7'
|
5
|
+
|
6
|
+
class DynamicSegmentDefinition < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_block_definition
|
11
|
+
seg = HL7::Message::Segment.new do |s|
|
12
|
+
s.e0 = "MSK"
|
13
|
+
s.e1 = "1234"
|
14
|
+
s.e2 = "5678"
|
15
|
+
end
|
16
|
+
|
17
|
+
assert_equal( "MSK|1234|5678", seg.to_s )
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_ruby_block_initializer
|
21
|
+
seg = HL7::Message::Segment.new do
|
22
|
+
e0 "MSK"
|
23
|
+
e1 "1234"
|
24
|
+
e2 "5678"
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_equal( "MSK|1234|5678", seg.to_s )
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_shouldnt_pollute_caller_namespace
|
31
|
+
seg = HL7::Message::Segment.new do |s|
|
32
|
+
s.e0 = "MSK"
|
33
|
+
s.e1 = "1234"
|
34
|
+
s.e2 = "5678"
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_raises(NoMethodError) do
|
38
|
+
e3 "TEST"
|
39
|
+
end
|
40
|
+
assert_equal( "MSK|1234|5678", seg.to_s )
|
41
|
+
end
|
42
|
+
end
|
data/test/test_msa_segment.rb
CHANGED
data/test/test_obr_segment.rb
CHANGED
data/test/test_obx_segment.rb
CHANGED
data/test/test_pid_segment.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: test_pid_segment.rb
|
1
|
+
# $Id: test_pid_segment.rb 40 2007-06-30 01:29:19Z segfault $
|
2
2
|
$: << '../lib'
|
3
3
|
require 'test/unit'
|
4
4
|
require 'ruby-hl7'
|
@@ -15,6 +15,7 @@ class PidSegment < Test::Unit::TestCase
|
|
15
15
|
vals.each do |x|
|
16
16
|
pid.admin_sex = x
|
17
17
|
end
|
18
|
+
pid.admin_sex = ""
|
18
19
|
end
|
19
20
|
|
20
21
|
assert_raises( HL7::InvalidDataError ) do
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# $Id$
|
2
|
+
$: << '../lib'
|
3
|
+
require 'time'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'ruby-hl7'
|
6
|
+
|
7
|
+
class SpeedParsing < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@msg = open( "./test_data/lotsunknowns.hl7" ).readlines
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_large_unknown_segments
|
13
|
+
start = Time.now
|
14
|
+
doc = HL7::Message.new @msg
|
15
|
+
assert_not_nil doc
|
16
|
+
ends = Time.now
|
17
|
+
assert ((ends-start) < 1)
|
18
|
+
end
|
19
|
+
end
|
data/test_data/empty.hl7
ADDED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
MSH|^~\&|RADIS1||DMCRES||19940502161633||ORU|19940502161633|D|2.2|964||AL|AL
|
data/test_data/test.hl7
CHANGED
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-hl7
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.2.44
|
7
|
+
date: 2007-08-05 00:00:00 -04:00
|
8
8
|
summary: Ruby HL7 Library
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -44,6 +44,10 @@ files:
|
|
44
44
|
- lib/segments/qrd.rb
|
45
45
|
- lib/segments/qrf.rb
|
46
46
|
- test_data/adt_a01.hl7
|
47
|
+
- test_data/empty.hl7
|
48
|
+
- test_data/empty_segments.hl7
|
49
|
+
- test_data/lotsunknowns.hl7
|
50
|
+
- test_data/obxobr.hl7
|
47
51
|
- test_data/rqi_r04.hl7
|
48
52
|
- test_data/test.hl7
|
49
53
|
- test_data/test2.hl7
|
@@ -51,11 +55,14 @@ files:
|
|
51
55
|
- LICENSE
|
52
56
|
test_files:
|
53
57
|
- test/test_basic_parsing.rb
|
58
|
+
- test/test_child_segment.rb
|
54
59
|
- test/test_default_segment.rb
|
60
|
+
- test/test_dynamic_segment_def.rb
|
55
61
|
- test/test_msa_segment.rb
|
56
62
|
- test/test_obr_segment.rb
|
57
63
|
- test/test_obx_segment.rb
|
58
64
|
- test/test_pid_segment.rb
|
65
|
+
- test/test_speed_parsing.rb
|
59
66
|
rdoc_options: []
|
60
67
|
|
61
68
|
extra_rdoc_files:
|
@@ -84,7 +91,7 @@ dependencies:
|
|
84
91
|
requirements:
|
85
92
|
- - ">="
|
86
93
|
- !ruby/object:Gem::Version
|
87
|
-
version: 0.7.
|
94
|
+
version: 0.7.3
|
88
95
|
version:
|
89
96
|
- !ruby/object:Gem::Dependency
|
90
97
|
name: rubyforge
|
@@ -93,5 +100,5 @@ dependencies:
|
|
93
100
|
requirements:
|
94
101
|
- - ">="
|
95
102
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.4.
|
103
|
+
version: 0.4.3
|
97
104
|
version:
|