ruby-hl7 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -0
- data/.travis.yml +15 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +37 -0
- data/NOTES.md +53 -0
- data/Rakefile +149 -0
- data/VERSION +1 -0
- data/VERSION.yml +4 -0
- data/examples/proxy_server.rb +26 -0
- data/lib/segment.rb +1 -1
- data/lib/segment_fields.rb +1 -1
- data/lib/segments/obr.rb +2 -2
- data/ruby-hl7.gemspec +44 -0
- data/spec/basic_parsing_spec.rb +320 -0
- data/spec/batch_parsing_spec.rb +52 -0
- data/spec/child_segment_spec.rb +66 -0
- data/spec/core_ext/date_time_spec.rb +43 -0
- data/spec/default_segment_spec.rb +31 -0
- data/spec/dynamic_segment_def_spec.rb +37 -0
- data/spec/err_segment_spec.rb +26 -0
- data/spec/evn_segment_spec.rb +23 -0
- data/spec/msa_segment_spec.rb +27 -0
- data/spec/msh_segment_spec.rb +28 -0
- data/spec/nk1_segment_spec.rb +26 -0
- data/spec/obr_segment_spec.rb +45 -0
- data/spec/obx_segment_spec.rb +46 -0
- data/spec/orc_segment_spec.rb +27 -0
- data/spec/pid_segment_spec.rb +70 -0
- data/spec/prd_segment_spec.rb +29 -0
- data/spec/pv1_segment_spec.rb +23 -0
- data/spec/rf1_segment_spec.rb +29 -0
- data/spec/segment_field_spec.rb +92 -0
- data/spec/segment_generator_spec.rb +32 -0
- data/spec/segment_list_storage_spec.rb +47 -0
- data/spec/segment_spec.rb +27 -0
- data/spec/sft_segment_spec.rb +26 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/speed_parsing_spec.rb +19 -0
- data/spec/spm_segment_spec.rb +26 -0
- metadata +52 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e90514f902634471c8292f6383f505718a4cd80a
|
4
|
+
data.tar.gz: 137b33f12ee152e8fe79a006e0b7c29df2f88313
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6050c616942ab3127d55a6bb9bff1d5b49c1388ed1ae0dc8c215d7ba74105f38f1664bb6df18d206b31be253ec0ef7c3eab3f94027506b6c2975bf076a039d2
|
7
|
+
data.tar.gz: 15f10a47853e8db45a88b852c53d7607e0c2545371f927cfdec0294ac4d53a2c03ab7f137bedfa7c80bc7a3e42b1bb103521cb038f24727b5f8ba4c6d7194cb4
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.2.5)
|
5
|
+
git (1.2.5)
|
6
|
+
json_pure (1.5.0)
|
7
|
+
multi_json (1.5.0)
|
8
|
+
rake (10.0.3)
|
9
|
+
rdoc (3.9.4)
|
10
|
+
rspec (2.99.0)
|
11
|
+
rspec-core (~> 2.99.0)
|
12
|
+
rspec-expectations (~> 2.99.0)
|
13
|
+
rspec-mocks (~> 2.99.0)
|
14
|
+
rspec-core (2.99.2)
|
15
|
+
rspec-expectations (2.99.2)
|
16
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
17
|
+
rspec-mocks (2.99.2)
|
18
|
+
rubyforge (2.0.4)
|
19
|
+
json_pure (>= 1.1.7)
|
20
|
+
simplecov (0.7.1)
|
21
|
+
multi_json (~> 1.0)
|
22
|
+
simplecov-html (~> 0.7.1)
|
23
|
+
simplecov-html (0.7.1)
|
24
|
+
technicalpickles-jeweler (1.2.1)
|
25
|
+
git (>= 1.2.1)
|
26
|
+
rubyforge
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
rake (~> 10.0.3)
|
33
|
+
rdoc
|
34
|
+
rspec (~> 2.99.0)
|
35
|
+
rubyforge
|
36
|
+
simplecov
|
37
|
+
technicalpickles-jeweler
|
data/NOTES.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
## Overview
|
2
|
+
|
3
|
+
**Version 1.1.1**
|
4
|
+
Included in this release:
|
5
|
+
|
6
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/48
|
7
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/44
|
8
|
+
|
9
|
+
**Version 1.1.0**
|
10
|
+
Included in this release:
|
11
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/7
|
12
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/9
|
13
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/10
|
14
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/13
|
15
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/17
|
16
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/18
|
17
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/19
|
18
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/20
|
19
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/21
|
20
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/22
|
21
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/23
|
22
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/24
|
23
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/25
|
24
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/27
|
25
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/28
|
26
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/33
|
27
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/34
|
28
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/35
|
29
|
+
- https://github.com/ruby-hl7/ruby-hl7/pull/41
|
30
|
+
|
31
|
+
Thanks to:
|
32
|
+
@untoldone, @tomsabin, @patricksrobertson, @rojotek, @calebwoods and @jdee
|
33
|
+
|
34
|
+
|
35
|
+
**Version 1.0.3**
|
36
|
+
The ruby-hl7 gem removes some sample messages.
|
37
|
+
|
38
|
+
## Release Date
|
39
|
+
|
40
|
+
January 25, 2011
|
41
|
+
|
42
|
+
## In this release
|
43
|
+
|
44
|
+
* Sample messages from Cerner were removed.
|
45
|
+
* Some gem dependencies were updated.
|
46
|
+
|
47
|
+
### Bug fixes
|
48
|
+
|
49
|
+
There are no bug fixes in this release.
|
50
|
+
|
51
|
+
## Known Issues
|
52
|
+
|
53
|
+
There are currently no known open issues with the ruby-hl7 gem.
|
data/Rakefile
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
# $Id$
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'rdoc/task'
|
5
|
+
require 'rubygems/package_task'
|
6
|
+
require 'rake/contrib/sshpublisher'
|
7
|
+
require 'rbconfig'
|
8
|
+
require 'rubyforge'
|
9
|
+
require 'rspec'
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
require 'simplecov'
|
12
|
+
|
13
|
+
$: << './lib'
|
14
|
+
require 'ruby-hl7'
|
15
|
+
require 'message_parser'
|
16
|
+
require 'message'
|
17
|
+
require 'segment_list_storage'
|
18
|
+
require 'segment_generator'
|
19
|
+
require 'segment'
|
20
|
+
|
21
|
+
full_name = "Ruby-HL7"
|
22
|
+
short_name = full_name.downcase
|
23
|
+
|
24
|
+
# Many of these tasks were garnered from zenspider's Hoe
|
25
|
+
# just forced to work my way
|
26
|
+
|
27
|
+
desc 'Default: Run all examples'
|
28
|
+
task :default => :spec
|
29
|
+
|
30
|
+
if RUBY_VERSION < '1.9.1'
|
31
|
+
begin
|
32
|
+
require 'jeweler'
|
33
|
+
Jeweler::Tasks.new do |s|
|
34
|
+
s.name = short_name
|
35
|
+
s.full_name
|
36
|
+
s.summary = "Ruby HL7 Library"
|
37
|
+
s.authors = ["Mark Guzman"]
|
38
|
+
s.email = "ruby-hl7@googlegroups.com"
|
39
|
+
s.homepage = "http://github.com/ruby-hl7/ruby-hl7"
|
40
|
+
s.description = "A simple library to parse and generate HL7 2.x messages"
|
41
|
+
s.require_path = "lib"
|
42
|
+
s.has_rdoc = true
|
43
|
+
s.rubyforge_project = short_name
|
44
|
+
s.required_ruby_version = '>= 1.8.6'
|
45
|
+
s.extra_rdoc_files = %w[README.rdoc LICENSE]
|
46
|
+
s.files = FileList["{bin,lib,test_data}/**/*"].to_a
|
47
|
+
s.test_files = FileList["{test}/**/test*.rb"].to_a
|
48
|
+
s.add_dependency("rake", ">= #{RAKEVERSION}")
|
49
|
+
s.add_dependency("rubyforge", ">= #{::RubyForge::VERSION}")
|
50
|
+
end
|
51
|
+
rescue LoadError
|
52
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
spec = Gem::Specification.new do |s|
|
58
|
+
s.name = short_name
|
59
|
+
s.full_name
|
60
|
+
s.version = HL7::VERSION
|
61
|
+
s.author = "Mark Guzman"
|
62
|
+
s.email = "ruby-hl7@googlegroups.com"
|
63
|
+
s.homepage = "https://github.com/ruby-hl7/ruby-hl7"
|
64
|
+
s.platform = Gem::Platform::RUBY
|
65
|
+
s.summary = "Ruby HL7 Library"
|
66
|
+
s.rubyforge_project = short_name
|
67
|
+
s.description = "A simple library to parse and generate HL7 2.x messages"
|
68
|
+
s.files = FileList["{bin,lib,test_data}/**/*"].to_a
|
69
|
+
s.require_path = "lib"
|
70
|
+
s.test_files = FileList["{test}/**/test*.rb"].to_a
|
71
|
+
s.has_rdoc = true
|
72
|
+
s.required_ruby_version = '>= 1.8.6'
|
73
|
+
s.extra_rdoc_files = %w[README.rdoc LICENSE]
|
74
|
+
s.add_dependency("rake", ">= #{RAKEVERSION}")
|
75
|
+
s.add_dependency("rubyforge", ">= #{::RubyForge::VERSION}")
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "Run all examples"
|
79
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
80
|
+
spec.pattern = 'spec/**/*.rb'
|
81
|
+
end
|
82
|
+
|
83
|
+
desc "Run all examples with SimpleCov"
|
84
|
+
RSpec::Core::RakeTask.new(:spec_with_simplecov) do |spec|
|
85
|
+
ENV['COVERAGE'] = 'true'
|
86
|
+
spec.pattern = 'spec/**/*.rb'
|
87
|
+
end
|
88
|
+
|
89
|
+
RDoc::Task.new do |rd|
|
90
|
+
rd.main = "README.rdoc"
|
91
|
+
rd.rdoc_files.include("README.rdoc", "LICENSE", "lib/**/*.rb")
|
92
|
+
rd.title = "%s (%s) Documentation" % [ full_name, spec.version ]
|
93
|
+
rd.rdoc_dir = 'doc'
|
94
|
+
end
|
95
|
+
|
96
|
+
Gem::PackageTask.new(spec) do |pkg|
|
97
|
+
pkg.need_tar = true
|
98
|
+
end
|
99
|
+
|
100
|
+
desc 'Clean up all the extras'
|
101
|
+
task :clean => [ :clobber_rdoc, :clobber_package ] do
|
102
|
+
%w[*.gem ri coverage*].each do |pattern|
|
103
|
+
files = Dir[pattern]
|
104
|
+
rm_rf files unless files.empty?
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
namespace :forge do
|
109
|
+
desc 'Publish RDoc to RubyForge'
|
110
|
+
task :publish_docs => [:clean, :rdoc] do
|
111
|
+
config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
|
112
|
+
host = "#{config["username"]}@rubyforge.org"
|
113
|
+
remote_dir = "/var/www/gforge-projects/#{spec.rubyforge_project}"
|
114
|
+
local_dir = 'doc'
|
115
|
+
sh %{rsync -av --delete #{local_dir}/ #{host}:#{remote_dir}}
|
116
|
+
end
|
117
|
+
|
118
|
+
desc 'Package and upload the release to rubyforge.'
|
119
|
+
task :release => [:clean, :package] do |t|
|
120
|
+
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
|
121
|
+
abort "Versions don't match '#{v}' vs '#{spec.version}'" if v != spec.version.to_s
|
122
|
+
pkg = "pkg/#{spec.name}-#{spec.version}"
|
123
|
+
|
124
|
+
if $DEBUG then
|
125
|
+
puts "release_id = rf.add_release #{spec.rubyforge_project.inspect}, #{spec.name.inspect}, #{version.inspect}, \"#{pkg}.tgz\""
|
126
|
+
puts "rf.add_file #{spec.rubyforge_project.inspect}, #{spec.name.inspect}, release_id, \"#{pkg}.gem\""
|
127
|
+
end
|
128
|
+
|
129
|
+
rf = RubyForge.new
|
130
|
+
puts "Logging in"
|
131
|
+
rf.login
|
132
|
+
|
133
|
+
changes = open("NOTES.md").readlines.join("") if File.exists?("NOTES.md")
|
134
|
+
c = rf.userconfig
|
135
|
+
c["release_notes"] = spec.description if spec.description
|
136
|
+
c["release_changes"] = changes if changes
|
137
|
+
c["preformatted"] = true
|
138
|
+
|
139
|
+
files = ["#{pkg}.tgz", "#{pkg}.gem"].compact
|
140
|
+
|
141
|
+
puts "Releasing #{spec.name} v. #{spec.version}"
|
142
|
+
rf.add_release spec.rubyforge_project, spec.name, spec.version.to_s, *files
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
desc 'Install the package as a gem'
|
147
|
+
task :install_gem => [:clean, :package] do
|
148
|
+
sh "sudo gem install pkg/*.gem"
|
149
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.1
|
data/VERSION.yml
ADDED
@@ -0,0 +1,26 @@
|
|
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/lib/segment.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# == Defining a New Segment
|
7
7
|
# class HL7::Message::Segment::NK1 < HL7::Message::Segment
|
8
|
-
#
|
8
|
+
# weight 100 # segments are sorted ascendingly
|
9
9
|
# add_field :something_you_want # assumes :idx=>1
|
10
10
|
# add_field :something_else, :idx=>6 # :idx=>6 and field count=6
|
11
11
|
# add_field :something_more # :idx=>7
|
data/lib/segment_fields.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SegmentFields
|
2
2
|
# class HL7::Message::Segment::NK1 < HL7::Message::Segment
|
3
|
-
#
|
3
|
+
# weight 100 # segments are sorted ascendingly
|
4
4
|
# add_field :something_you_want # assumes :idx=>1
|
5
5
|
# add_field :something_else, :idx=>6 # :idx=>6 and field count=6
|
6
6
|
module HL7::Message::SegmentFields
|
data/lib/segments/obr.rb
CHANGED
@@ -30,8 +30,8 @@ class HL7::Message::Segment::OBR < HL7::Message::Segment
|
|
30
30
|
add_field :order_callback_phone_number
|
31
31
|
add_field :placer_field_1
|
32
32
|
add_field :placer_field_2
|
33
|
-
add_field :
|
34
|
-
add_field :
|
33
|
+
add_field :filler_field_1
|
34
|
+
add_field :filler_field_2
|
35
35
|
add_field :results_status_change_date do |value|
|
36
36
|
convert_to_ts(value)
|
37
37
|
end
|
data/ruby-hl7.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
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
|
@@ -0,0 +1,320 @@
|
|
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
|