ruby-hl7 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/configuration.rb +30 -0
- data/lib/core_ext/date_time.rb +19 -15
- data/lib/core_ext/string.rb +2 -0
- data/lib/helpers/time_formatter_helper.rb +42 -0
- data/lib/message.rb +72 -75
- data/lib/message_parser.rb +17 -15
- data/lib/ruby-hl7.rb +26 -16
- data/lib/segment.rb +63 -47
- data/lib/segment_default.rb +6 -4
- data/lib/segment_fields.rb +27 -25
- data/lib/segment_generator.rb +12 -15
- data/lib/segment_list_storage.rb +15 -14
- data/lib/segments/aig.rb +2 -0
- data/lib/segments/ail.rb +2 -0
- data/lib/segments/aip.rb +2 -0
- data/lib/segments/ais.rb +2 -0
- data/lib/segments/dg1.rb +2 -10
- data/lib/segments/err.rb +2 -0
- data/lib/segments/evn.rb +2 -1
- data/lib/segments/ft1.rb +13 -13
- data/lib/segments/fts.rb +2 -0
- data/lib/segments/gt1.rb +4 -6
- data/lib/segments/in1.rb +2 -1
- data/lib/segments/mfe.rb +2 -0
- data/lib/segments/mfi.rb +2 -0
- data/lib/segments/mrg.rb +2 -0
- data/lib/segments/msa.rb +2 -2
- data/lib/segments/msh.rb +3 -2
- data/lib/segments/nk1.rb +48 -8
- data/lib/segments/nte.rb +6 -5
- data/lib/segments/obr.rb +4 -3
- data/lib/segments/obx.rb +2 -1
- data/lib/segments/orc.rb +8 -10
- data/lib/segments/oru.rb +2 -1
- data/lib/segments/pid.rb +19 -10
- data/lib/segments/prd.rb +2 -1
- data/lib/segments/prt.rb +23 -0
- data/lib/segments/pv1.rb +2 -1
- data/lib/segments/pv2.rb +64 -51
- data/lib/segments/qrd.rb +2 -1
- data/lib/segments/qrf.rb +2 -1
- data/lib/segments/rf1.rb +2 -1
- data/lib/segments/rgs.rb +2 -0
- data/lib/segments/rol.rb +22 -0
- data/lib/segments/sch.rb +2 -0
- data/lib/segments/sft.rb +2 -0
- data/lib/segments/spm.rb +2 -0
- data/lib/segments/tq1.rb +2 -0
- data/lib/segments/txa.rb +30 -0
- data/lib/test/hl7_messages.rb +118 -117
- data/lib/version.rb +5 -0
- metadata +18 -165
- data/.gitignore +0 -7
- data/.rubocop.yml +0 -127
- data/.travis.yml +0 -20
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -66
- data/LICENSE +0 -19
- data/NOTES.md +0 -141
- data/README.rdoc +0 -47
- data/Rakefile +0 -76
- data/VERSION +0 -1
- data/VERSION.yml +0 -4
- data/examples/proxy_server.rb +0 -26
- data/ruby-hl7.gemspec +0 -39
- data/spec/ail_segment_spec.rb +0 -28
- data/spec/aip_segment_spec.rb +0 -31
- data/spec/basic_parsing_spec.rb +0 -319
- data/spec/batch_parsing_spec.rb +0 -52
- data/spec/child_segment_spec.rb +0 -66
- data/spec/core_ext/date_time_spec.rb +0 -43
- data/spec/default_segment_spec.rb +0 -31
- data/spec/dg1_spec.rb +0 -42
- data/spec/dynamic_segment_def_spec.rb +0 -37
- data/spec/err_segment_spec.rb +0 -26
- data/spec/evn_segment_spec.rb +0 -23
- data/spec/ft1_segment_spec.rb +0 -35
- data/spec/fts_segment_spec.rb +0 -19
- data/spec/gt1_segment_spec.rb +0 -32
- data/spec/in1_segment_spec.rb +0 -34
- data/spec/message_spec.rb +0 -53
- data/spec/messages_spec.rb +0 -24
- data/spec/mfe_segment_spec.rb +0 -28
- data/spec/mfi_segment_spec.rb +0 -28
- data/spec/msa_segment_spec.rb +0 -27
- data/spec/msh_segment_spec.rb +0 -28
- data/spec/nk1_segment_spec.rb +0 -26
- data/spec/obr_segment_spec.rb +0 -45
- data/spec/obx_segment_spec.rb +0 -68
- data/spec/orc_segment_spec.rb +0 -27
- data/spec/pid_segment_spec.rb +0 -78
- data/spec/prd_segment_spec.rb +0 -29
- data/spec/pv1_segment_spec.rb +0 -23
- data/spec/rf1_segment_spec.rb +0 -29
- data/spec/sch_segment_spec.rb +0 -32
- data/spec/segment_field_spec.rb +0 -110
- data/spec/segment_generator_spec.rb +0 -32
- data/spec/segment_list_storage_spec.rb +0 -47
- data/spec/segment_spec.rb +0 -38
- data/spec/sft_segment_spec.rb +0 -26
- data/spec/spec_helper.rb +0 -13
- data/spec/speed_parsing_spec.rb +0 -19
- data/spec/spm_segment_spec.rb +0 -26
data/Rakefile
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# $Id$
|
2
|
-
require 'rubygems'
|
3
|
-
require 'rake'
|
4
|
-
require 'rdoc/task'
|
5
|
-
require 'rubygems/package_task'
|
6
|
-
require 'rbconfig'
|
7
|
-
require 'rspec'
|
8
|
-
require 'rspec/core/rake_task'
|
9
|
-
require 'simplecov'
|
10
|
-
|
11
|
-
$: << './lib'
|
12
|
-
require 'ruby-hl7'
|
13
|
-
require 'message_parser'
|
14
|
-
require 'message'
|
15
|
-
require 'segment_list_storage'
|
16
|
-
require 'segment_generator'
|
17
|
-
require 'segment'
|
18
|
-
|
19
|
-
full_name = "Ruby-HL7"
|
20
|
-
RAKEVERSION = "12.3.3"
|
21
|
-
|
22
|
-
# Many of these tasks were garnered from zenspider's Hoe
|
23
|
-
# just forced to work my way
|
24
|
-
|
25
|
-
desc 'Default: Run all examples'
|
26
|
-
task :default => :spec
|
27
|
-
|
28
|
-
spec = Gem::Specification.new do |s|
|
29
|
-
s.homepage = "https://github.com/ruby-hl7/ruby-hl7"
|
30
|
-
s.platform = Gem::Platform::RUBY
|
31
|
-
s.summary = "Ruby HL7 Library"
|
32
|
-
s.description = "A simple library to parse and generate HL7 2.x messages"
|
33
|
-
s.files = FileList["{bin,lib,test_data}/**/*"].to_a
|
34
|
-
s.require_path = "lib"
|
35
|
-
s.test_files = FileList["{test}/**/test*.rb"].to_a
|
36
|
-
s.has_rdoc = true
|
37
|
-
s.required_ruby_version = '>= 1.8.6'
|
38
|
-
s.extra_rdoc_files = %w[README.rdoc LICENSE]
|
39
|
-
s.add_dependency("rake", ">= #{RAKEVERSION}")
|
40
|
-
end
|
41
|
-
|
42
|
-
desc "Run all examples"
|
43
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
44
|
-
spec.pattern = 'spec/**/*.rb'
|
45
|
-
spec.ruby_opts = '-w'
|
46
|
-
end
|
47
|
-
|
48
|
-
desc "Run all examples with SimpleCov"
|
49
|
-
RSpec::Core::RakeTask.new(:spec_with_simplecov) do |spec|
|
50
|
-
ENV['COVERAGE'] = 'true'
|
51
|
-
spec.pattern = 'spec/**/*.rb'
|
52
|
-
end
|
53
|
-
|
54
|
-
RDoc::Task.new do |rd|
|
55
|
-
rd.main = "README.rdoc"
|
56
|
-
rd.rdoc_files.include("README.rdoc", "LICENSE", "lib/**/*.rb")
|
57
|
-
rd.title = "%s (%s) Documentation" % [ full_name, spec.version ]
|
58
|
-
rd.rdoc_dir = 'doc'
|
59
|
-
end
|
60
|
-
|
61
|
-
Gem::PackageTask.new(spec) do |pkg|
|
62
|
-
pkg.need_tar = true
|
63
|
-
end
|
64
|
-
|
65
|
-
desc 'Clean up all the extras'
|
66
|
-
task :clean => [ :clobber_rdoc, :clobber_package ] do
|
67
|
-
%w[*.gem ri coverage*].each do |pattern|
|
68
|
-
files = Dir[pattern]
|
69
|
-
rm_rf files unless files.empty?
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
desc 'Install the package as a gem'
|
74
|
-
task :install_gem => [:clean, :package] do
|
75
|
-
sh "sudo gem install pkg/*.gem"
|
76
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.3.2
|
data/VERSION.yml
DELETED
data/examples/proxy_server.rb
DELETED
@@ -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
|
-
|
data/ruby-hl7.gemspec
DELETED
@@ -1,39 +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.3.2"
|
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', '~> 3.12'
|
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
|
data/spec/ail_segment_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
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
|
data/spec/aip_segment_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
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
|
data/spec/basic_parsing_spec.rb
DELETED
@@ -1,319 +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
|
-
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
|
data/spec/batch_parsing_spec.rb
DELETED
@@ -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
|
-
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
|
data/spec/child_segment_spec.rb
DELETED
@@ -1,66 +0,0 @@
|
|
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
|
-
|
@@ -1,43 +0,0 @@
|
|
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
|
-
|