ruby-hl7 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +2 -1
  3. data/lib/message.rb +5 -0
  4. data/lib/ruby-hl7.rb +1 -1
  5. data/lib/segment.rb +6 -0
  6. data/lib/segments/mfe.rb +10 -0
  7. data/lib/segments/mfi.rb +13 -0
  8. data/lib/segments/obx.rb +4 -1
  9. data/lib/segments/sft.rb +0 -6
  10. data/lib/test/hl7_messages.rb +30 -24
  11. metadata +11 -46
  12. data/.gitignore +0 -6
  13. data/.travis.yml +0 -15
  14. data/Gemfile +0 -11
  15. data/Gemfile.lock +0 -37
  16. data/NOTES.md +0 -53
  17. data/Rakefile +0 -149
  18. data/VERSION +0 -1
  19. data/VERSION.yml +0 -4
  20. data/examples/proxy_server.rb +0 -26
  21. data/ruby-hl7.gemspec +0 -44
  22. data/spec/basic_parsing_spec.rb +0 -320
  23. data/spec/batch_parsing_spec.rb +0 -52
  24. data/spec/child_segment_spec.rb +0 -66
  25. data/spec/core_ext/date_time_spec.rb +0 -43
  26. data/spec/default_segment_spec.rb +0 -31
  27. data/spec/dynamic_segment_def_spec.rb +0 -37
  28. data/spec/err_segment_spec.rb +0 -26
  29. data/spec/evn_segment_spec.rb +0 -23
  30. data/spec/msa_segment_spec.rb +0 -27
  31. data/spec/msh_segment_spec.rb +0 -28
  32. data/spec/nk1_segment_spec.rb +0 -26
  33. data/spec/obr_segment_spec.rb +0 -45
  34. data/spec/obx_segment_spec.rb +0 -46
  35. data/spec/orc_segment_spec.rb +0 -27
  36. data/spec/pid_segment_spec.rb +0 -70
  37. data/spec/prd_segment_spec.rb +0 -29
  38. data/spec/pv1_segment_spec.rb +0 -23
  39. data/spec/rf1_segment_spec.rb +0 -29
  40. data/spec/segment_field_spec.rb +0 -92
  41. data/spec/segment_generator_spec.rb +0 -32
  42. data/spec/segment_list_storage_spec.rb +0 -47
  43. data/spec/segment_spec.rb +0 -27
  44. data/spec/sft_segment_spec.rb +0 -26
  45. data/spec/spec_helper.rb +0 -12
  46. data/spec/speed_parsing_spec.rb +0 -19
  47. data/spec/spm_segment_spec.rb +0 -26
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.1.1
@@ -1,4 +0,0 @@
1
- ---
2
- :major: 1
3
- :minor: 1
4
- :patch: 1
@@ -1,26 +0,0 @@
1
- # $Id$
2
- # Ruby-HL7 Proxy Server Example
3
- require 'rubygems'
4
- require 'ruby-hl7'
5
- require 'thread'
6
- require 'socket'
7
-
8
- PORT = 2402
9
- target_ip = "127.0.0.1"
10
- target_port = 5900
11
-
12
- srv = TCPServer.new(PORT)
13
- puts "proxy_server listening on port: %i" % PORT
14
- puts "proxying for: %s:%i" % [ target_ip, target_port ]
15
- while true
16
- sok = srv.accept
17
- Thread.new( sok ) do |my_socket|
18
- raw_inp = my_socket.readlines
19
- msg = HL7::Message.new( raw_input )
20
- puts "forwarding message:\n%s" % msg.to_s
21
- soc = TCPSocket.open( target_ip, target_port )
22
- soc.write msg.to_mllp
23
- soc.close
24
- end
25
- end
26
-
@@ -1,44 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{ruby-hl7}
8
- s.version = "1.1.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Mark Guzman"]
12
- s.date = %q{2014-09-09}
13
- s.description = %q{A simple library to parse and generate HL7 2.x messages}
14
- s.email = %q{ruby-hl7@googlegroups.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
-
20
- s.files = `git ls-files`.split "\n"
21
- s.test_files = `git ls-files -- {spec}/*`.split "\n"
22
- s.homepage = %q{http://github.com/ruby-hl7/ruby-hl7}
23
- s.rdoc_options = ["--charset=UTF-8"]
24
- s.require_paths = ["lib"]
25
- s.required_ruby_version = Gem::Requirement.new(">= 1.8.6")
26
- s.rubyforge_project = %q{ruby-hl7}
27
- s.rubygems_version = %q{1.4.2}
28
- s.summary = %q{Ruby HL7 Library}
29
-
30
- if s.respond_to? :specification_version then
31
- s.specification_version = 3
32
-
33
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
34
- s.add_runtime_dependency(%q<rake>, [">= 10.0.0"])
35
- s.add_runtime_dependency(%q<rubyforge>, [">= 2.0.4"])
36
- else
37
- s.add_dependency(%q<rake>, [">= 10.0.0"])
38
- s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
39
- end
40
- else
41
- s.add_dependency(%q<rake>, [">= 10.0.0"])
42
- s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
43
- end
44
- end
@@ -1,320 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
-
4
- describe HL7::Message do
5
- context 'basic parsing' do
6
- before :all do
7
- @simple_msh_txt = open( './test_data/test.hl7' ).readlines.first
8
- @empty_txt = open( './test_data/empty.hl7' ).readlines.first
9
- @empty_segments_txt = open( './test_data/empty_segments.hl7' ).readlines.first
10
- @base_msh = "MSH|^~\\&|LAB1||DESTINATION||19910127105114||ORU^R03|LAB1003929"
11
- @base_msh_alt_delims = "MSH$@~\\&|LAB1||DESTINATION||19910127105114||ORU^R03|LAB1003929"
12
- end
13
-
14
- it 'parses simple text' do
15
- msg = HL7::Message.new
16
- msg.parse @simple_msh_txt
17
- msg.to_hl7.should == @simple_msh_txt
18
- end
19
-
20
- it 'parses delimiters properly' do
21
- msg = HL7::Message.new( @base_msh )
22
- msg.element_delim.should == "|"
23
- msg.item_delim.should == "^"
24
-
25
- msg = HL7::Message.new( @base_msh_alt_delims )
26
- msg.element_delim.should == "$"
27
- msg.item_delim.should == "@"
28
- end
29
-
30
- it 'parses via the constructor' do
31
- msg = HL7::Message.new( @simple_msh_txt )
32
- msg.to_hl7.should == @simple_msh_txt
33
- end
34
-
35
- it 'parses via the class method' do
36
- msg = HL7::Message.parse( @simple_msh_txt )
37
- msg.to_hl7.should == @simple_msh_txt
38
- end
39
-
40
- it 'only parses String and Enumerable data' do
41
- lambda { msg = HL7::Message.parse :MSHthis_shouldnt_parse_at_all }.should raise_error(HL7::ParseError)
42
- end
43
-
44
- it 'parses empty strings' do
45
- lambda { msg = HL7::Message.new @empty_txt }.should_not raise_error
46
- end
47
-
48
- it 'converts to strings' do
49
- msg = HL7::Message.new
50
- msg.parse @simple_msh_txt
51
- orig = @simple_msh_txt.gsub( /\r/, "\n" )
52
- msg.to_s.should == orig
53
- end
54
-
55
- it 'converts to a string and to HL7' do
56
- msg = HL7::Message.new( @simple_msh_txt )
57
- msg.to_hl7.should_not == msg.to_s
58
- end
59
-
60
- it 'allows access to segments by index' do
61
- msg = HL7::Message.new
62
- msg.parse @simple_msh_txt
63
- msg[0].to_s.should == @base_msh
64
- end
65
-
66
- it 'allows access to segments by name' do
67
- msg = HL7::Message.new
68
- msg.parse @simple_msh_txt
69
- msg["MSH"].to_s.should == @base_msh
70
- end
71
-
72
- it 'allows access to segments by symbol' do
73
- msg = HL7::Message.new
74
- msg.parse @simple_msh_txt
75
- msg[:MSH].to_s.should == @base_msh
76
- end
77
-
78
- it 'inserts segments by index' do
79
- msg = HL7::Message.new
80
- msg.parse @simple_msh_txt
81
- inp = HL7::Message::Segment::Default.new
82
- msg[1] = inp
83
- msg[1].should == inp
84
-
85
- lambda { msg[2] = Class.new }.should raise_error(HL7::Exception)
86
- end
87
-
88
- it 'returns nil when accessing a missing segment' do
89
- msg = HL7::Message.new
90
- msg.parse @simple_msh_txt
91
- lambda { msg[:does_not_exist].should be_nil }.should_not raise_error
92
- end
93
-
94
- it 'inserts segments by name' do
95
- msg = HL7::Message.new
96
- msg.parse @simple_msh_txt
97
- inp = HL7::Message::Segment::NTE.new
98
- msg["NTE"] = inp
99
- msg["NTE"].should == inp
100
- lambda { msg["NTE"] = Class.new }.should raise_error(HL7::Exception)
101
- end
102
-
103
- it 'inserts segments by symbol' do
104
- msg = HL7::Message.new
105
- msg.parse @simple_msh_txt
106
- inp = HL7::Message::Segment::NTE.new
107
- msg[:NTE] = inp
108
- msg[:NTE].should == inp
109
- lambda { msg[:NTE] = Class.new }.should raise_error(HL7::Exception)
110
- end
111
-
112
- it 'allows access to segment elements' do
113
- msg = HL7::Message.new
114
- msg.parse @simple_msh_txt
115
- msg[:MSH].sending_app.should == "LAB1"
116
- end
117
-
118
- it 'allows modification of segment elements' do
119
- msg = HL7::Message.new
120
- msg.parse @simple_msh_txt
121
- msg[:MSH].sending_app = "TEST"
122
- msg[:MSH].sending_app.should == "TEST"
123
- end
124
-
125
- it 'raises NoMethodError when accessing a missing element' do
126
- msg = HL7::Message.new
127
- msg.parse @simple_msh_txt
128
- lambda {msg[:MSH].does_not_really_exist_here}.should raise_error(NoMethodError)
129
- end
130
-
131
- it 'raises NoMethodError when modifying a missing element' do
132
- msg = HL7::Message.new
133
- msg.parse @simple_msh_txt
134
- lambda {msg[:MSH].does_not_really_exist_here="TEST"}.should raise_error(NoMethodError)
135
- end
136
-
137
- it 'permits elements to be accessed via numeric names' do
138
- msg = HL7::Message.new( @simple_msh_txt )
139
- msg[:MSH].e2.should == "LAB1"
140
- msg[:MSH].e3.should be_empty
141
- end
142
-
143
- it 'permits elements to be modified via numeric names' do
144
- msg = HL7::Message.parse( @simple_msh_txt )
145
- msg[:MSH].e2 = "TESTING1234"
146
- msg[:MSH].e2.should == "TESTING1234"
147
- end
148
-
149
- it 'allows appending of segments' do
150
- msg = HL7::Message.new
151
- lambda do
152
- msg << HL7::Message::Segment::MSH.new
153
- msg << HL7::Message::Segment::NTE.new
154
- end.should_not raise_error
155
-
156
- lambda { msg << Class.new }.should raise_error(HL7::Exception)
157
- end
158
-
159
- it 'allows appending of an array of segments' do
160
- msg = HL7::Message.new
161
- lambda do
162
- msg << [HL7::Message::Segment::MSH.new, HL7::Message::Segment::NTE.new]
163
- end.should_not raise_error
164
-
165
- obx = HL7::Message::Segment::OBX.new
166
- lambda do
167
- obx.children << [HL7::Message::Segment::NTE.new, HL7::Message::Segment::NTE.new]
168
- end.should_not raise_error
169
- end
170
-
171
- it 'sorts segments' do
172
- msg = HL7::Message.new
173
- pv1 = HL7::Message::Segment::PV1.new
174
- msg << pv1
175
- msh = HL7::Message::Segment::MSH.new
176
- msg << msh
177
- nte = HL7::Message::Segment::NTE.new
178
- msg << nte
179
- nte2 = HL7::Message::Segment::NTE.new
180
- msg << nte
181
- msh.sending_app = "TEST"
182
-
183
- initial = msg.to_s
184
- sorted = msg.sort
185
- final = sorted.to_s
186
- initial.should_not == final
187
- end
188
-
189
- it 'automatically assigns a set_id to a new segment' do
190
- msg = HL7::Message.new
191
- msh = HL7::Message::Segment::MSH.new
192
- msg << msh
193
- ntea = HL7::Message::Segment::NTE.new
194
- ntea.comment = "first"
195
- msg << ntea
196
- nteb = HL7::Message::Segment::NTE.new
197
- nteb.comment = "second"
198
- msg << nteb
199
- ntec = HL7::Message::Segment::NTE.new
200
- ntec.comment = "third"
201
- msg << ntec
202
- ntea.set_id.should == "1"
203
- nteb.set_id.should == "2"
204
- ntec.set_id.should == "3"
205
- end
206
-
207
- it 'parses Enumerable data' do
208
- test_file = open( './test_data/test.hl7' )
209
- test_file.should_not be_nil
210
-
211
- msg = HL7::Message.new( test_file )
212
- msg.to_hl7.should == @simple_msh_txt
213
- end
214
-
215
- it 'has a to_info method' do
216
- msg = HL7::Message.new( @simple_msh_txt )
217
- msg[1].to_info.should_not be_nil
218
- end
219
-
220
- it 'parses a raw array' do
221
- inp = "NTE|1|ME TOO"
222
- nte = HL7::Message::Segment::NTE.new( inp.split( '|' ) )
223
- nte.to_s.should == inp
224
- end
225
-
226
- it 'produces MLLP output' do
227
- msg = HL7::Message.new( @simple_msh_txt )
228
- expect = "\x0b%s\x1c\r" % msg.to_hl7
229
- msg.to_mllp.should == expect
230
- end
231
-
232
- it 'parses MLLP input' do
233
- raw = "\x0b%s\x1c\r" % @simple_msh_txt
234
- msg = HL7::Message.parse( raw )
235
- msg.should_not be_nil
236
- msg.to_hl7.should == @simple_msh_txt
237
- msg.to_mllp.should == raw
238
- end
239
-
240
- it 'can parse its own MLLP output' do
241
- msg = HL7::Message.parse( @simple_msh_txt )
242
- msg.should_not be_nil
243
- lambda do
244
- post_mllp = HL7::Message.parse( msg.to_mllp )
245
- post_mllp.should_not be_nil
246
- msg.to_hl7.should == post_mllp.to_hl7
247
- end.should_not raise_error
248
- end
249
-
250
- it 'can access child elements' do
251
- obr = HL7::Message::Segment::OBR.new
252
- lambda do
253
- obr.children.should_not be_nil
254
- obr.children.length.should be_zero
255
- end.should_not raise_error
256
- end
257
-
258
- it 'can add child elements' do
259
- obr = HL7::Message::Segment::OBR.new
260
- lambda do
261
- obr.children.length.should be_zero
262
- (1..5).each do |x|
263
- obr.children << HL7::Message::Segment::OBX.new
264
- obr.children.length.should == x
265
- end
266
- end.should_not raise_error
267
- end
268
-
269
- it 'rejects invalid child segments' do
270
- obr = HL7::Message::Segment::OBR.new
271
- lambda { obr.children << Class.new }.should raise_error(HL7::Exception)
272
- end
273
-
274
- it 'supports grouped, sequenced segments' do
275
- #multible obr's with multiple obx's
276
- msg = HL7::Message.parse( @simple_msh_txt )
277
- orig_output = msg.to_hl7
278
- orig_obx_cnt = msg[:OBX].length
279
- (1..10).each do |obr_id|
280
- obr = HL7::Message::Segment::OBR.new
281
- msg << obr
282
- (1..10).each do |obx_id|
283
- obx = HL7::Message::Segment::OBX.new
284
- obr.children << obx
285
- end
286
- end
287
-
288
- msg[:OBR].should_not be_nil
289
- msg[:OBR].length.should == 11
290
- msg[:OBX].should_not be_nil
291
- msg[:OBX].length.should == 102
292
- msg[:OBR][4].children[1].set_id.should == "2"
293
- msg[:OBR][5].children[1].set_id.should == "2"
294
-
295
- final_output = msg.to_hl7
296
- orig_output.should_not == final_output
297
- end
298
-
299
- it "returns each segment's index" do
300
- msg = HL7::Message.parse( @simple_msh_txt )
301
- msg.index("PID").should == 1
302
- msg.index(:PID).should == 1
303
- msg.index("PV1").should == 2
304
- msg.index(:PV1).should == 2
305
- msg.index("TACOBELL").should be_nil
306
- msg.index(nil).should be_nil
307
- msg.index(1).should be_nil
308
- end
309
-
310
- it 'validates the PID#admin_sex element' do
311
- pid = HL7::Message::Segment::PID.new
312
- lambda { pid.admin_sex = "TEST" }.should raise_error(HL7::InvalidDataError)
313
- lambda { pid.admin_sex = "F" }.should_not raise_error
314
- end
315
-
316
- it 'can parse an empty segment' do
317
- lambda { msg = HL7::Message.new @empty_segments_txt }.should_not raise_error
318
- end
319
- end
320
- end
@@ -1,52 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
-
4
- describe HL7::Message do
5
- context 'batch parsing' do
6
- it 'should have a class method HL7::Message.parse_batch' do
7
- HL7::Message.should respond_to(:parse_batch)
8
- end
9
-
10
- it 'should raise an exception when parsing an empty batch' do
11
- # :empty_batch message contains a valid batch envelope with no
12
- # contents
13
- lambda do
14
- HL7::Message.parse_batch HL7MESSAGES[:empty_batch]
15
- end.should raise_exception(HL7::ParseError, 'empty_batch_message')
16
- end
17
-
18
- it 'should raise an exception when parsing a single message as a batch' do
19
- lambda do
20
- HL7::Message.parse_batch HL7MESSAGES[:realm_minimal_message]
21
- end.should raise_exception(HL7::ParseError, 'badly_formed_batch_message')
22
- end
23
-
24
- it 'should yield multiple messages from a valid batch' do
25
- count = 0
26
- HL7::Message.parse_batch(HL7MESSAGES[:realm_batch]) do |m|
27
- count += 1
28
- end
29
- count.should == 2
30
- end
31
- end
32
- end
33
-
34
- describe 'String extension' do
35
- before :all do
36
- @batch_message = HL7MESSAGES[:realm_batch]
37
- @plain_message = HL7MESSAGES[:realm_minimal_message]
38
- end
39
-
40
- it 'should respond_to :hl7_batch?' do
41
- @batch_message.hl7_batch?.should be true
42
- @plain_message.should respond_to(:hl7_batch?)
43
- end
44
-
45
- it 'should return true when passed a batch message' do
46
- @batch_message.should be_an_hl7_batch
47
- end
48
-
49
- it 'should return false when passed a plain message' do
50
- @plain_message.should_not be_an_hl7_batch
51
- end
52
- end