ruby-hl7 1.2.3 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +7 -0
  3. data/.rubocop.yml +127 -0
  4. data/.travis.yml +20 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +65 -0
  7. data/NOTES.md +151 -0
  8. data/README.rdoc +5 -0
  9. data/Rakefile +76 -0
  10. data/VERSION +1 -0
  11. data/VERSION.yml +4 -0
  12. data/examples/proxy_server.rb +26 -0
  13. data/lib/ruby-hl7.rb +1 -1
  14. data/lib/segments/ft1.rb +63 -0
  15. data/lib/segments/gt1.rb +75 -0
  16. data/lib/segments/pid.rb +13 -1
  17. data/lib/segments/txa.rb +28 -0
  18. data/ruby-hl7.gemspec +39 -0
  19. data/spec/ail_segment_spec.rb +28 -0
  20. data/spec/aip_segment_spec.rb +31 -0
  21. data/spec/basic_parsing_spec.rb +319 -0
  22. data/spec/batch_parsing_spec.rb +52 -0
  23. data/spec/child_segment_spec.rb +66 -0
  24. data/spec/core_ext/date_time_spec.rb +43 -0
  25. data/spec/default_segment_spec.rb +31 -0
  26. data/spec/dg1_spec.rb +42 -0
  27. data/spec/dynamic_segment_def_spec.rb +37 -0
  28. data/spec/err_segment_spec.rb +26 -0
  29. data/spec/evn_segment_spec.rb +23 -0
  30. data/spec/ft1_segment_spec.rb +35 -0
  31. data/spec/fts_segment_spec.rb +19 -0
  32. data/spec/gt1_segment_spec.rb +32 -0
  33. data/spec/in1_segment_spec.rb +34 -0
  34. data/spec/message_spec.rb +53 -0
  35. data/spec/messages_spec.rb +24 -0
  36. data/spec/mfe_segment_spec.rb +28 -0
  37. data/spec/mfi_segment_spec.rb +28 -0
  38. data/spec/msa_segment_spec.rb +27 -0
  39. data/spec/msh_segment_spec.rb +28 -0
  40. data/spec/nk1_segment_spec.rb +26 -0
  41. data/spec/obr_segment_spec.rb +45 -0
  42. data/spec/obx_segment_spec.rb +68 -0
  43. data/spec/orc_segment_spec.rb +27 -0
  44. data/spec/pid_segment_spec.rb +78 -0
  45. data/spec/prd_segment_spec.rb +29 -0
  46. data/spec/pv1_segment_spec.rb +23 -0
  47. data/spec/rf1_segment_spec.rb +29 -0
  48. data/spec/sch_segment_spec.rb +32 -0
  49. data/spec/segment_field_spec.rb +110 -0
  50. data/spec/segment_generator_spec.rb +32 -0
  51. data/spec/segment_list_storage_spec.rb +47 -0
  52. data/spec/segment_spec.rb +38 -0
  53. data/spec/sft_segment_spec.rb +26 -0
  54. data/spec/spec_helper.rb +13 -0
  55. data/spec/speed_parsing_spec.rb +19 -0
  56. data/spec/spm_segment_spec.rb +26 -0
  57. data/spec/txa_segment_spec.rb +72 -0
  58. metadata +155 -18
  59. data/lib/segments/zcf.rb +0 -22
@@ -0,0 +1,28 @@
1
+ class HL7::Message::Segment::TXA < HL7::Message::Segment
2
+ add_field :set_id
3
+ add_field :document_type
4
+ add_field :document_content_presentation
5
+ add_field :activity_date_time
6
+ add_field :primary_activity_provider_code
7
+ add_field :origination_date_time
8
+ add_field :transcription_date_time
9
+ add_field :edit_date_time
10
+ add_field :originator_code
11
+ add_field :assigned_document_authenticator
12
+ add_field :transcriptionist_code
13
+ add_field :unique_document_number
14
+ add_field :parent_document_number
15
+ add_field :placer_order_number
16
+ add_field :filler_order_number
17
+ add_field :unique_document_file_name
18
+ add_field :document_completion_status
19
+ add_field :document_confidentiality_status
20
+ add_field :document_availability_status
21
+ add_field :document_storage_status
22
+ add_field :document_change_reason
23
+ add_field :authentication_person_time_stamp
24
+ add_field :distributed_copies_code
25
+ add_field :folder_assignment
26
+ add_field :document_title
27
+ add_field :agreed_due_date_time
28
+ end
data/ruby-hl7.gemspec ADDED
@@ -0,0 +1,39 @@
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.3.3"
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
+ s.license = "MIT"
30
+
31
+ s.add_development_dependency 'bundler', '~> 1.17'
32
+ s.add_development_dependency 'pry'
33
+ s.add_development_dependency 'rake', '>= 12.3.3'
34
+ s.add_development_dependency 'rdoc', '~> 6.3'
35
+ s.add_development_dependency 'rspec', '>= 3.9.0'
36
+ s.add_development_dependency 'simplecov', '= 0.16.1'
37
+ s.add_development_dependency 'simplecov-html', '~> 0.10.0'
38
+ s.add_development_dependency 'rake-contrib'
39
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::AIL do
5
+ context 'general' do
6
+ before :all do
7
+ @base_ail = 'AIL|1|A|OFFICE^^^OFFICE|^OFFICE^A4'
8
+ end
9
+
10
+ it 'creates an AIL segment' do
11
+ expect do
12
+ ail = HL7::Message::Segment::AIL.new( @base_ail )
13
+ expect(ail).not_to be_nil
14
+ expect(ail.to_s).to eq @base_ail
15
+ end.not_to raise_error
16
+ end
17
+
18
+ it 'allows access to an AIL segment' do
19
+ expect do
20
+ ail = HL7::Message::Segment::AIL.new( @base_ail )
21
+ expect(ail.set_id).to eq '1'
22
+ expect(ail.segment_action_code).to eq 'A'
23
+ expect(ail.location_resource_id).to eq 'OFFICE^^^OFFICE'
24
+ expect(ail.location_type).to eq '^OFFICE^A4'
25
+ end.not_to raise_error
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::AIP do
5
+ context 'general' do
6
+ before :all do
7
+ @base_aip = 'AIP|1|U|JSB^ISON^Kathy^S|D^Doctor||20020108150000|||10|m^Minutes'
8
+ end
9
+
10
+ it 'creates an AIP segment' do
11
+ expect do
12
+ aip = HL7::Message::Segment::AIP.new( @base_aip )
13
+ expect(aip).not_to be_nil
14
+ expect(aip.to_s).to eq @base_aip
15
+ end.not_to raise_error
16
+ end
17
+
18
+ it 'allows access to an AIP segment' do
19
+ expect do
20
+ aip = HL7::Message::Segment::AIP.new( @base_aip )
21
+ expect(aip.set_id).to eq '1'
22
+ expect(aip.segment_action_code).to eq 'U'
23
+ expect(aip.personnel_resource_id).to eq 'JSB^ISON^Kathy^S'
24
+ expect(aip.resource_role).to eq 'D^Doctor'
25
+ expect(aip.start_date_time).to eq '20020108150000'
26
+ expect(aip.duration).to eq '10'
27
+ expect(aip.duration_units).to eq 'm^Minutes'
28
+ end.not_to raise_error
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,319 @@
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
+ expect(msg.to_hl7).to eq @simple_msh_txt
18
+ end
19
+
20
+ it 'parses delimiters properly' do
21
+ msg = HL7::Message.new( @base_msh )
22
+ expect(msg.element_delim).to eq "|"
23
+ expect(msg.item_delim).to eq "^"
24
+
25
+ msg = HL7::Message.new( @base_msh_alt_delims )
26
+ expect(msg.element_delim).to eq "$"
27
+ expect(msg.item_delim).to eq "@"
28
+ end
29
+
30
+ it 'parses via the constructor' do
31
+ msg = HL7::Message.new( @simple_msh_txt )
32
+ expect(msg.to_hl7).to eq @simple_msh_txt
33
+ end
34
+
35
+ it 'parses via the class method' do
36
+ msg = HL7::Message.parse( @simple_msh_txt )
37
+ expect(msg.to_hl7).to eq @simple_msh_txt
38
+ end
39
+
40
+ it 'only parses String and Enumerable data' do
41
+ expect { HL7::Message.parse :MSHthis_shouldnt_parse_at_all }.to raise_error(HL7::ParseError)
42
+ end
43
+
44
+ it 'parses empty strings' do
45
+ expect { HL7::Message.new @empty_txt }.not_to 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
+ expect(msg.to_s).to eq orig
53
+ end
54
+
55
+ it 'converts to a string and to HL7' do
56
+ msg = HL7::Message.new( @simple_msh_txt )
57
+ expect(msg.to_hl7).not_to eq(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
+ expect(msg[0].to_s).to eq @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
+ expect(msg["MSH"].to_s).to eq @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
+ expect(msg[:MSH].to_s).to eq @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
+ expect(msg[1]).to eq inp
84
+
85
+ expect { msg[2] = Class.new }.to 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
+ expect { expect(msg[:does_not_exist]).to be_nil }.not_to 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
+ expect(msg["NTE"]).to eq inp
100
+ expect { msg["NTE"] = Class.new }.to 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
+ expect(msg[:NTE]).to eq inp
109
+ expect { msg[:NTE] = Class.new }.to 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
+ expect(msg[:MSH].sending_app).to eq "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
+ expect(msg[:MSH].sending_app).to eq "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
+ expect {msg[:MSH].does_not_really_exist_here}.to 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
+ expect {msg[:MSH].does_not_really_exist_here="TEST"}.to 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
+ expect(msg[:MSH].e2).to eq "LAB1"
140
+ expect(msg[:MSH].e3).to 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
+ expect(msg[:MSH].e2).to eq "TESTING1234"
147
+ end
148
+
149
+ it 'allows appending of segments' do
150
+ msg = HL7::Message.new
151
+ expect do
152
+ msg << HL7::Message::Segment::MSH.new
153
+ msg << HL7::Message::Segment::NTE.new
154
+ end.not_to raise_error
155
+
156
+ expect { msg << Class.new }.to raise_error(HL7::Exception)
157
+ end
158
+
159
+ it 'allows appending of an array of segments' do
160
+ msg = HL7::Message.new
161
+ expect do
162
+ msg << [HL7::Message::Segment::MSH.new, HL7::Message::Segment::NTE.new]
163
+ end.not_to raise_error
164
+
165
+ obx = HL7::Message::Segment::OBX.new
166
+ expect do
167
+ obx.children << [HL7::Message::Segment::NTE.new, HL7::Message::Segment::NTE.new]
168
+ end.not_to 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 << nte2
181
+ msh.sending_app = "TEST"
182
+
183
+ initial = msg.to_s
184
+ sorted = msg.sort
185
+ final = sorted.to_s
186
+ expect(initial).not_to eq(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
+ expect(ntea.set_id).to eq "1"
203
+ expect(nteb.set_id).to eq "2"
204
+ expect(ntec.set_id).to eq "3"
205
+ end
206
+
207
+ it 'parses Enumerable data' do
208
+ test_file = open( './test_data/test.hl7' )
209
+ expect(test_file).not_to be_nil
210
+
211
+ msg = HL7::Message.new( test_file )
212
+ expect(msg.to_hl7).to eq @simple_msh_txt
213
+ end
214
+
215
+ it 'has a to_info method' do
216
+ msg = HL7::Message.new( @simple_msh_txt )
217
+ expect(msg[1].to_info).not_to 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
+ expect(nte.to_s).to eq 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
+ expect(msg.to_mllp).to eq 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
+ expect(msg).not_to be_nil
236
+ expect(msg.to_hl7).to eq @simple_msh_txt
237
+ expect(msg.to_mllp).to eq raw
238
+ end
239
+
240
+ it 'can parse its own MLLP output' do
241
+ msg = HL7::Message.parse( @simple_msh_txt )
242
+ expect(msg).not_to be_nil
243
+ expect do
244
+ post_mllp = HL7::Message.parse( msg.to_mllp )
245
+ expect(post_mllp).not_to be_nil
246
+ expect(msg.to_hl7).to eq post_mllp.to_hl7
247
+ end.not_to raise_error
248
+ end
249
+
250
+ it 'can access child elements' do
251
+ obr = HL7::Message::Segment::OBR.new
252
+ expect do
253
+ expect(obr.children).not_to be_nil
254
+ expect(obr.children.length).to be_zero
255
+ end.not_to raise_error
256
+ end
257
+
258
+ it 'can add child elements' do
259
+ obr = HL7::Message::Segment::OBR.new
260
+ expect do
261
+ expect(obr.children.length).to be_zero
262
+ (1..5).each do |x|
263
+ obr.children << HL7::Message::Segment::OBX.new
264
+ expect(obr.children.length).to eq x
265
+ end
266
+ end.not_to raise_error
267
+ end
268
+
269
+ it 'rejects invalid child segments' do
270
+ obr = HL7::Message::Segment::OBR.new
271
+ expect { obr.children << Class.new }.to 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
+ (1..10).each do |obr_id|
279
+ obr = HL7::Message::Segment::OBR.new
280
+ msg << obr
281
+ (1..10).each do |obx_id|
282
+ obx = HL7::Message::Segment::OBX.new
283
+ obr.children << obx
284
+ end
285
+ end
286
+
287
+ expect(msg[:OBR]).not_to be_nil
288
+ expect(msg[:OBR].length).to eq 11
289
+ expect(msg[:OBX]).not_to be_nil
290
+ expect(msg[:OBX].length).to eq 102
291
+ expect(msg[:OBR][4].children[1].set_id).to eq "2"
292
+ expect(msg[:OBR][5].children[1].set_id).to eq "2"
293
+
294
+ final_output = msg.to_hl7
295
+ expect(orig_output).not_to eq(final_output)
296
+ end
297
+
298
+ it "returns each segment's index" do
299
+ msg = HL7::Message.parse( @simple_msh_txt )
300
+ expect(msg.index("PID")).to eq 1
301
+ expect(msg.index(:PID)).to eq 1
302
+ expect(msg.index("PV1")).to eq 2
303
+ expect(msg.index(:PV1)).to eq 2
304
+ expect(msg.index("TACOBELL")).to be_nil
305
+ expect(msg.index(nil)).to be_nil
306
+ expect(msg.index(1)).to be_nil
307
+ end
308
+
309
+ it 'validates the PID#admin_sex element' do
310
+ pid = HL7::Message::Segment::PID.new
311
+ expect { pid.admin_sex = "TEST" }.to raise_error(HL7::InvalidDataError)
312
+ expect { pid.admin_sex = "F" }.not_to raise_error
313
+ end
314
+
315
+ it 'can parse an empty segment' do
316
+ expect { HL7::Message.new @empty_segments_txt }.not_to raise_error
317
+ end
318
+ end
319
+ end
@@ -0,0 +1,52 @@
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
+ expect(HL7::Message).to 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
+ expect do
14
+ HL7::Message.parse_batch HL7MESSAGES[:empty_batch]
15
+ end.to 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
+ expect do
20
+ HL7::Message.parse_batch HL7MESSAGES[:realm_minimal_message]
21
+ end.to 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
+ expect(count).to eq 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
+ expect(@batch_message.hl7_batch?).to be true
42
+ expect(@plain_message).to respond_to(:hl7_batch?)
43
+ end
44
+
45
+ it 'should return true when passed a batch message' do
46
+ expect(@batch_message).to be_an_hl7_batch
47
+ end
48
+
49
+ it 'should return false when passed a plain message' do
50
+ expect(@plain_message).not_to be_an_hl7_batch
51
+ end
52
+ end
@@ -0,0 +1,66 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message do
5
+ context 'child segments' do
6
+ before :all do
7
+ @base = open( './test_data/obxobr.hl7' ).readlines
8
+ end
9
+
10
+ it 'allows access to child segments' do
11
+ msg = HL7::Message.new @base
12
+ expect(msg).not_to be_nil
13
+ expect(msg[:OBR]).not_to be_nil
14
+ expect(msg[:OBR].length).to eq 3
15
+ expect(msg[:OBR][0].children).not_to be_nil
16
+ expect(msg[:OBR][0].children.length).to eq 6
17
+ expect(msg[:OBR][1].children).not_to be_nil
18
+ expect(msg[:OBR][1].children.length).to eq 3
19
+ expect(msg[:OBR][2].children).not_to be_nil
20
+ expect(msg[:OBR][2].children.length).to eq 1
21
+ expect(msg[:OBX][0].children).not_to be_nil
22
+ expect(msg[:OBX][0].children.length).to eq 1
23
+
24
+ msg[:OBR][0].children.each do |x|
25
+ expect(x).not_to be_nil
26
+ end
27
+ msg[:OBR][1].children.each do |x|
28
+ expect(x).not_to be_nil
29
+ end
30
+ msg[:OBR][2].children.each do |x|
31
+ expect(x).not_to be_nil
32
+ end
33
+ end
34
+
35
+ it 'allows adding child segments' do
36
+ msg = HL7::Message.new @base
37
+ expect(msg).not_to be_nil
38
+ expect(msg[:OBR]).not_to be_nil
39
+ ob = HL7::Message::Segment::OBR.new
40
+ expect(ob).not_to be_nil
41
+
42
+ msg << ob
43
+ expect(ob.children).not_to be_nil
44
+ expect(ob.segment_parent).not_to be_nil
45
+ expect(ob.segment_parent).to eq msg
46
+ orig_cnt = msg.length
47
+
48
+ (1..4).each do |x|
49
+ m = HL7::Message::Segment::OBX.new
50
+ m.observation_value = "taco"
51
+ expect(m).not_to be_nil
52
+ expect(/taco/.match(m.to_s)).not_to be_nil
53
+ ob.children << m
54
+ expect(ob.children.length).to eq x
55
+ expect(m.segment_parent).not_to be_nil
56
+ expect(m.segment_parent).to eq ob
57
+ end
58
+
59
+ expect(@base).not_to eq msg.to_hl7
60
+ expect(msg.length).not_to eq orig_cnt
61
+ text_ver = msg.to_hl7
62
+ expect(/taco/.match(text_ver)).not_to be_nil
63
+ end
64
+ end
65
+ end
66
+
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Date do
4
+
5
+ subject{ Date.parse('2013-12-02').to_hl7 }
6
+
7
+ it "should respond to the HL7 timestamp" do
8
+ expect(subject).to eq "20131202"
9
+ end
10
+ end
11
+
12
+ describe "to_hl7 for time related classes" do
13
+
14
+ let(:formated_time){ time_now.strftime('%Y%m%d%H%M%S') }
15
+ let(:fraction_3){ "." + sprintf('%06d', time_now.to_time.usec)[0, 3] }
16
+ let(:fraction_9){ "." + sprintf('%06d', time_now.to_time.usec) + ("0" * 3) }
17
+
18
+ shared_examples "a time to_hl7" do
19
+ context "without fraction" do
20
+ it { expect(time_now.to_time.to_hl7).to eq formated_time }
21
+ end
22
+
23
+ context "with_fraction" do
24
+ it { expect(time_now.to_time.to_hl7(3)).to eq formated_time + fraction_3 }
25
+
26
+ it { expect(time_now.to_time.to_hl7(9)).to eq formated_time + fraction_9 }
27
+ end
28
+ end
29
+
30
+ describe Time do
31
+ let(:time_now){ Time.now }
32
+
33
+ it_should_behave_like "a time to_hl7"
34
+ end
35
+
36
+ describe DateTime do
37
+ let(:time_now){ DateTime.now }
38
+
39
+ it_should_behave_like "a time to_hl7"
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::Default do
5
+ context 'general' do
6
+
7
+ before :all do
8
+ @base_msa = "MSA|AR|ZZ9380 ERR"
9
+ end
10
+
11
+ it 'stores an existing segment' do
12
+ seg = HL7::Message::Segment::Default.new( @base_msa )
13
+ expect(seg.to_s).to eq @base_msa
14
+ end
15
+
16
+ it 'converts to a string' do
17
+ seg = HL7::Message::Segment::Default.new( @base_msa )
18
+ expect(seg.to_s).to eq @base_msa
19
+ expect(seg.to_hl7).to eq seg.to_s
20
+ end
21
+
22
+ it 'creates a raw segment' do
23
+ seg = HL7::Message::Segment::Default.new
24
+ seg.e0 = "NK1"
25
+ seg.e1 = "INFO"
26
+ seg.e2 = "MORE INFO"
27
+ seg.e5 = "LAST INFO"
28
+ expect(seg.to_s).to eq "NK1|INFO|MORE INFO|||LAST INFO"
29
+ end
30
+ end
31
+ end
data/spec/dg1_spec.rb ADDED
@@ -0,0 +1,42 @@
1
+ # encoding: UTF-8
2
+ require "spec_helper"
3
+
4
+ describe HL7::Message::Segment::DG1 do
5
+ context "reading" do
6
+ let(:base_string) do
7
+ "DG1|1|I9|71596^OSTEOARTHROS NOS-L/LEG ^I9|OSTEOARTHROS NOS-L/LEG |20170615140551-0800||A|"
8
+ end
9
+ let(:segment){ HL7::Message::Segment::DG1.new(base_string) }
10
+
11
+ it "allows access to an DG1 segment" do
12
+ expect(segment.set_id).to eq("1")
13
+ expect(segment.diagnosis_coding_method).to eq("I9")
14
+ expect(segment.diagnosis_code).to eq("71596^OSTEOARTHROS NOS-L/LEG ^I9")
15
+ expect(segment.diagnosis_description).to eq("OSTEOARTHROS NOS-L/LEG ")
16
+ expect(segment.diagnosis_date_time).to eq("20170615140551-0800")
17
+ expect(segment.diagnosis_type).to eq("")
18
+ expect(segment.major_diagnostic_category).to eq("A")
19
+ expect(segment.diagnosis_related_group).to eq("")
20
+ expect(segment.drg_approval_indicator).to eq(nil)
21
+ expect(segment.drg_grouper_review_code).to eq(nil)
22
+ expect(segment.outlier_type).to eq(nil)
23
+ expect(segment.outlier_days).to eq(nil)
24
+ expect(segment.outlier_cost).to eq(nil)
25
+ expect(segment.grouper_version_and_type).to eq(nil)
26
+ expect(segment.diagnosis_priority).to eq(nil)
27
+ expect(segment.diagnosis_clinician).to eq(nil)
28
+ expect(segment.diagnosis_classification).to eq(nil)
29
+ expect(segment.confidential_indicator).to eq(nil)
30
+ expect(segment.attestation_date_time).to eq(nil)
31
+ end
32
+ end
33
+
34
+ context "creating" do
35
+ let(:segment){ HL7::Message::Segment::DG1.new }
36
+
37
+ it "allows creation of an DGH segment" do
38
+ segment.set_id = "2"
39
+ expect(segment.set_id).to eq("2")
40
+ end
41
+ end
42
+ end