ruby-hl7 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  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 +58 -0
  7. data/NOTES.md +121 -0
  8. data/README.rdoc +5 -0
  9. data/Rakefile +77 -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/pid.rb +13 -1
  15. data/ruby-hl7.gemspec +38 -0
  16. data/spec/ail_segment_spec.rb +28 -0
  17. data/spec/aip_segment_spec.rb +31 -0
  18. data/spec/basic_parsing_spec.rb +319 -0
  19. data/spec/batch_parsing_spec.rb +52 -0
  20. data/spec/child_segment_spec.rb +66 -0
  21. data/spec/core_ext/date_time_spec.rb +43 -0
  22. data/spec/default_segment_spec.rb +31 -0
  23. data/spec/dg1_spec.rb +42 -0
  24. data/spec/dynamic_segment_def_spec.rb +37 -0
  25. data/spec/err_segment_spec.rb +26 -0
  26. data/spec/evn_segment_spec.rb +23 -0
  27. data/spec/fts_segment_spec.rb +19 -0
  28. data/spec/in1_segment_spec.rb +34 -0
  29. data/spec/message_spec.rb +53 -0
  30. data/spec/messages_spec.rb +24 -0
  31. data/spec/mfe_segment_spec.rb +28 -0
  32. data/spec/mfi_segment_spec.rb +28 -0
  33. data/spec/msa_segment_spec.rb +27 -0
  34. data/spec/msh_segment_spec.rb +28 -0
  35. data/spec/nk1_segment_spec.rb +26 -0
  36. data/spec/obr_segment_spec.rb +45 -0
  37. data/spec/obx_segment_spec.rb +68 -0
  38. data/spec/orc_segment_spec.rb +27 -0
  39. data/spec/pid_segment_spec.rb +78 -0
  40. data/spec/prd_segment_spec.rb +29 -0
  41. data/spec/pv1_segment_spec.rb +23 -0
  42. data/spec/rf1_segment_spec.rb +29 -0
  43. data/spec/sch_segment_spec.rb +32 -0
  44. data/spec/segment_field_spec.rb +110 -0
  45. data/spec/segment_generator_spec.rb +32 -0
  46. data/spec/segment_list_storage_spec.rb +47 -0
  47. data/spec/segment_spec.rb +38 -0
  48. data/spec/sft_segment_spec.rb +26 -0
  49. data/spec/spec_helper.rb +13 -0
  50. data/spec/speed_parsing_spec.rb +19 -0
  51. data/spec/spm_segment_spec.rb +26 -0
  52. metadata +117 -13
  53. data/lib/segments/zcf.rb +0 -22
@@ -0,0 +1,32 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::SCH do
5
+ context 'general' do
6
+ before :all do
7
+ @base_sch = 'SCH|||||681|S^SCHEDULED|^BONE DENSITY PB,cf/RH |30^30 MINUTE APPOINTMENT|45|m|^^45^200905260930^200905261015|||||||||polly^^POLLY BRESCOCK|^^^^^^ ||||SCHEDULED'
8
+ end
9
+
10
+ it 'creates an SCH segment' do
11
+ expect do
12
+ sch = HL7::Message::Segment::SCH.new( @base_sch )
13
+ expect(sch).not_to be_nil
14
+ expect(sch.to_s).to eq @base_sch
15
+ end.not_to raise_error
16
+ end
17
+
18
+ it 'allows access to an SCH segment' do
19
+ expect do
20
+ sch = HL7::Message::Segment::SCH.new( @base_sch )
21
+ expect(sch.schedule_id).to eq '681'
22
+ expect(sch.event_reason).to eq 'S^SCHEDULED'
23
+ expect(sch.appointment_reason).to eq '^BONE DENSITY PB,cf/RH '
24
+ expect(sch.appointment_type).to eq '30^30 MINUTE APPOINTMENT'
25
+ expect(sch.appointment_duration).to eq '45'
26
+ expect(sch.appointment_duration_units).to eq 'm'
27
+ expect(sch.entered_by_person).to eq 'polly^^POLLY BRESCOCK'
28
+ expect(sch.filler_status_code).to eq 'SCHEDULED'
29
+ end.not_to raise_error
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,110 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ class MockSegment < HL7::Message::Segment
5
+ weight 1
6
+ add_field :no_block
7
+ alias_field :no_block_alias, :no_block
8
+ add_field :validating do |value|
9
+ value == "bad" ? nil : value
10
+ end
11
+ add_field :converting do |value|
12
+ "X" + value
13
+ end
14
+ end
15
+
16
+ describe HL7::Message::Segment do
17
+ before :all do
18
+ @base = "Mock|no_block|validated|converted"
19
+ end
20
+
21
+ context "block on field definitions" do
22
+ it 'is evaluated on access by field name' do
23
+ msg = MockSegment.new(@base)
24
+
25
+ expect(msg.to_s).to eq @base
26
+ expect(msg.no_block).to eq "no_block"
27
+ expect(msg.validating).to eq "validated"
28
+ expect(msg.converting).to eq "Xconverted"
29
+
30
+ msg.no_block = "NO_BLOCK"
31
+ expect(msg.no_block).to eq "NO_BLOCK"
32
+
33
+ msg.validating = "good"
34
+ expect(msg.validating).to eq "good"
35
+ msg.validating = "bad"
36
+ expect(msg.validating).to eq ""
37
+
38
+ msg.converting = "empty"
39
+ expect(msg.converting).to eq "XXempty"
40
+ end
41
+
42
+ it 'is not evaluated on read access by eXXX alias' do
43
+ msg = MockSegment.new(@base)
44
+
45
+ expect(msg.e1).to eq "no_block"
46
+ expect(msg.e2).to eq "validated"
47
+ expect(msg.e3).to eq "converted"
48
+ end
49
+
50
+ it 'is not evaluated on write access by eXXX alias' do
51
+ msg = MockSegment.new(@base)
52
+
53
+ msg.e1 = "NO_BLOCK"
54
+ expect(msg.e1).to eq "NO_BLOCK"
55
+
56
+ msg.e2 = "good"
57
+ expect(msg.e2).to eq "good"
58
+ msg.e2 = "bad"
59
+ expect(msg.e2).to eq "bad"
60
+
61
+ msg.e3 = "empty"
62
+ expect(msg.e3).to eq "empty"
63
+ end
64
+ end
65
+
66
+ describe '#[]' do
67
+ it 'allows index access to the segment' do
68
+ msg = HL7::Message::Segment.new(@base)
69
+ expect(msg[0]).to eq 'Mock'
70
+ expect(msg[1]).to eq 'no_block'
71
+ expect(msg[2]).to eq 'validated'
72
+ expect(msg[3]).to eq 'converted'
73
+ end
74
+ end
75
+
76
+ describe '#[]=' do
77
+ it 'allows index assignment to the segment' do
78
+ msg = HL7::Message::Segment.new(@base)
79
+ msg[0] = 'Kcom'
80
+ expect(msg[0]).to eq 'Kcom'
81
+ end
82
+ end
83
+
84
+ describe '#alias_field' do
85
+ context 'with a valid field' do
86
+ it 'uses alias field names' do
87
+ msg = MockSegment.new(@base)
88
+ expect(msg.no_block).to eq "no_block"
89
+ expect(msg.no_block_alias).to eq "no_block"
90
+ end
91
+ end
92
+
93
+ context 'with an invalid field' do
94
+
95
+ class MockInvalidSegment < HL7::Message::Segment
96
+ weight 1
97
+ add_field :no_block
98
+ alias_field :no_block_alias, :invalid_field
99
+ add_field :second
100
+ add_field :third
101
+ end
102
+
103
+
104
+ it 'throws an error when the field is invalid' do
105
+ msg = MockInvalidSegment.new(@base)
106
+ expect{ msg.no_block_alias }.to raise_error(HL7::InvalidDataError)
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe HL7::Message::SegmentGenerator do
4
+ describe 'valid_segments_parts?' do
5
+
6
+ let(:element){ "MSH|1|2|3" }
7
+ let(:delimiter){ HL7::Message::Delimiter.new('|', '^', '\r') }
8
+ let(:segment_generator) do
9
+ HL7::Message::SegmentGenerator.new(element, nil, delimiter)
10
+ end
11
+
12
+ it "should return true if @seg_parts is an array of one element or more" do
13
+ expect(segment_generator.valid_segments_parts?).to be true
14
+ end
15
+
16
+ context 'when is empty' do
17
+ it "should return false if empty_segment_is_error is false" do
18
+ segment_generator.seg_parts = nil
19
+ HL7.ParserConfig[:empty_segment_is_error] = false
20
+ expect(segment_generator.valid_segments_parts?).to be false
21
+ end
22
+
23
+ it "should raise an error if empty_segment_is_error is true" do
24
+ HL7.ParserConfig[:empty_segment_is_error] = true
25
+ segment_generator.seg_parts = nil
26
+ expect do
27
+ segment_generator.valid_segments_parts?
28
+ end.to raise_error HL7::EmptySegmentNotAllowed
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ class SegmentNoChildren< HL7::Message::Segment
4
+ end
5
+
6
+ class SegmentWithChildren < HL7::Message::Segment
7
+ has_children [:NTE,:ORC,:SPM]
8
+ end
9
+
10
+ describe HL7::Message::SegmentListStorage do
11
+ describe "self#add_child_type" do
12
+ it "should allow to add a new segment type as child" do
13
+ SegmentWithChildren.add_child_type :OBR
14
+ segment = SegmentWithChildren.new
15
+ expect(segment.accepts?(:OBR)).to be true
16
+ expect(segment.child_types).to include :OBR
17
+ end
18
+ end
19
+
20
+ describe "Adding children has_children and add_child_type" do
21
+ subject do
22
+ segment_instance = segment_class.new
23
+ [:accepts?, :child_types, :children].each do |method|
24
+ expect(segment_instance.respond_to?(method)).to be true
25
+ end
26
+ end
27
+
28
+ context "when child_types is not present" do
29
+ let(:segment_class){ SegmentNoChildren }
30
+
31
+ it "by adding add_child_type should respond to the children methods" do
32
+ segment_instance = segment_class.new
33
+ expect(segment_instance.respond_to?(:children)).to be false
34
+ segment_class.add_child_type(:OBR)
35
+ subject
36
+ end
37
+ end
38
+
39
+ context "when child_types is present" do
40
+ let(:segment_class){ SegmentWithChildren }
41
+
42
+ it "should respond to the children methods" do
43
+ subject
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe HL7::Message::Segment do
4
+ describe 'length' do
5
+
6
+ it "should return the length of the elements" do
7
+ segment = HL7::Message::Segment.new "MSA|AR|ZZ9380 ERR"
8
+ expect(segment.length).to eq 3
9
+ end
10
+ end
11
+
12
+ describe 'enumerable' do
13
+ it 'enumerates over elements' do
14
+ seg = HL7::Message::Segment::Default.new
15
+ segment_count = 0
16
+ seg.each do |s|
17
+ segment_count = segment_count + 1
18
+ end
19
+ expect(segment_count).to eq(seg.length)
20
+ end
21
+ end
22
+
23
+ describe 'is_child_segment?' do
24
+ let(:segment){ HL7::Message::Segment.new "MSA|AR|ZZ9380 ERR" }
25
+ it "return false when is not set" do
26
+ expect(segment.is_child_segment?).to be false
27
+ end
28
+ end
29
+
30
+ describe 'convert_to_ts' do
31
+ let(:time_now){ DateTime.now }
32
+ let(:formated_time){ time_now.strftime('%Y%m%d%H%M%S') }
33
+
34
+ it "should conver to the hl7 time format" do
35
+ expect(HL7::Message::Segment.convert_to_ts(time_now)).to eq formated_time
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::SFT do
5
+ context 'general' do
6
+ before :all do
7
+ @base_sft = 'SFT|Level Seven Healthcare Software, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1.2|An Lab System|56734||20080817'
8
+ end
9
+
10
+ it 'creates an SFT segment' do
11
+ expect do
12
+ sft = HL7::Message::Segment::SFT.new( @base_sft )
13
+ expect(sft).not_to be_nil
14
+ expect(sft.to_s).to eq @base_sft
15
+ end.not_to raise_error
16
+ end
17
+
18
+ it 'allows access to an SFT segment' do
19
+ expect do
20
+ sft = HL7::Message::Segment::SFT.new( @base_sft )
21
+ expect(sft.software_product_name).to eq 'An Lab System'
22
+ expect(sft.software_install_date).to eq '20080817'
23
+ end.not_to raise_error
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ require 'simplecov'
2
+
3
+ if ENV["COVERAGE"]
4
+ SimpleCov.start do
5
+ add_filter "/test/"
6
+ add_filter "/spec/"
7
+ end
8
+ end
9
+
10
+ # ruby-hl7 loads the rest of the files in lib
11
+ require File.expand_path('../../lib/ruby-hl7', __FILE__)
12
+ require File.expand_path('../../lib/test/hl7_messages', __FILE__)
13
+ require 'pry'
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+ require 'time'
4
+
5
+ describe HL7::Message do
6
+ context 'speed parsing' do
7
+ before :all do
8
+ @msg = open( "./test_data/lotsunknowns.hl7" ).readlines
9
+ end
10
+
11
+ it 'parses large, unknown segments rapidly' do
12
+ start = Time.now
13
+ doc = HL7::Message.new @msg
14
+ expect(doc).not_to be_nil
15
+ ends = Time.now
16
+ expect(ends-start).to be < 1
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::SPM do
5
+ context 'general' do
6
+ before :all do
7
+ @base_spm = 'SPM|1|23456&EHR&2.16.840.1.113883.19.3.2.3&ISO^9700122&Lab&2.16.840.1.113883.19.3.1.6&ISO||122554006^Capillary blood specimen^SCT^BLDC^Blood capillary^HL70070^20080131^2.5.1||HEPA^Ammonium heparin^HL70371^^^^2.5.1|CAP^Capillary Specimen^HL70488^^^^2.5.1|181395001^Venous structure of digit^SCT^^^^20080731|||P^Patient^HL60369^^^^2.5.1|50^uL&Micro Liter&UCUM&&&&1.6|||||200808151030-0700|200808151100-0700'
8
+ end
9
+
10
+ it 'creates an SPM segment' do
11
+ expect do
12
+ spm = HL7::Message::Segment::SPM.new( @base_spm )
13
+ expect(spm).not_to be_nil
14
+ expect(spm.to_s).to eq @base_spm
15
+ end.not_to raise_error
16
+ end
17
+
18
+ it 'allows access to an SPM segment' do
19
+ expect do
20
+ spm = HL7::Message::Segment::SPM.new( @base_spm )
21
+ expect(spm.specimen_type).to eq '122554006^Capillary blood specimen^SCT^BLDC^Blood capillary^HL70070^20080131^2.5.1'
22
+ expect(spm.set_id).to eq '1'
23
+ end.not_to raise_error
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -1,53 +1,119 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-hl7
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Guzman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-18 00:00:00.000000000 Z
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '11.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '11.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rubyforge
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.15'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.99'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.99'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
29
85
  requirement: !ruby/object:Gem::Requirement
30
86
  requirements:
31
87
  - - ">="
32
88
  - !ruby/object:Gem::Version
33
- version: 2.0.4
89
+ version: '0'
34
90
  type: :development
35
91
  prerelease: false
36
92
  version_requirements: !ruby/object:Gem::Requirement
37
93
  requirements:
38
94
  - - ">="
39
95
  - !ruby/object:Gem::Version
40
- version: 2.0.4
96
+ version: '0'
41
97
  description: A simple library to parse and generate HL7 2.x messages
42
98
  email: ruby-hl7@googlegroups.com
43
99
  executables: []
44
100
  extensions: []
45
101
  extra_rdoc_files:
46
- - README.rdoc
47
102
  - LICENSE
103
+ - README.rdoc
48
104
  files:
105
+ - ".gitignore"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - Gemfile.lock
49
110
  - LICENSE
111
+ - NOTES.md
50
112
  - README.rdoc
113
+ - Rakefile
114
+ - VERSION
115
+ - VERSION.yml
116
+ - examples/proxy_server.rb
51
117
  - lib/core_ext/date_time.rb
52
118
  - lib/core_ext/string.rb
53
119
  - lib/message.rb
@@ -90,8 +156,44 @@ files:
90
156
  - lib/segments/sft.rb
91
157
  - lib/segments/spm.rb
92
158
  - lib/segments/tq1.rb
93
- - lib/segments/zcf.rb
94
159
  - lib/test/hl7_messages.rb
160
+ - ruby-hl7.gemspec
161
+ - spec/ail_segment_spec.rb
162
+ - spec/aip_segment_spec.rb
163
+ - spec/basic_parsing_spec.rb
164
+ - spec/batch_parsing_spec.rb
165
+ - spec/child_segment_spec.rb
166
+ - spec/core_ext/date_time_spec.rb
167
+ - spec/default_segment_spec.rb
168
+ - spec/dg1_spec.rb
169
+ - spec/dynamic_segment_def_spec.rb
170
+ - spec/err_segment_spec.rb
171
+ - spec/evn_segment_spec.rb
172
+ - spec/fts_segment_spec.rb
173
+ - spec/in1_segment_spec.rb
174
+ - spec/message_spec.rb
175
+ - spec/messages_spec.rb
176
+ - spec/mfe_segment_spec.rb
177
+ - spec/mfi_segment_spec.rb
178
+ - spec/msa_segment_spec.rb
179
+ - spec/msh_segment_spec.rb
180
+ - spec/nk1_segment_spec.rb
181
+ - spec/obr_segment_spec.rb
182
+ - spec/obx_segment_spec.rb
183
+ - spec/orc_segment_spec.rb
184
+ - spec/pid_segment_spec.rb
185
+ - spec/prd_segment_spec.rb
186
+ - spec/pv1_segment_spec.rb
187
+ - spec/rf1_segment_spec.rb
188
+ - spec/sch_segment_spec.rb
189
+ - spec/segment_field_spec.rb
190
+ - spec/segment_generator_spec.rb
191
+ - spec/segment_list_storage_spec.rb
192
+ - spec/segment_spec.rb
193
+ - spec/sft_segment_spec.rb
194
+ - spec/spec_helper.rb
195
+ - spec/speed_parsing_spec.rb
196
+ - spec/spm_segment_spec.rb
95
197
  - test_data/adt_a01.hl7
96
198
  - test_data/cerner/cerner_bordetella.hl7
97
199
  - test_data/cerner/cerner_en.hl7
@@ -122,11 +224,13 @@ files:
122
224
  - test_data/rqi_r04.hl7
123
225
  - test_data/test.hl7
124
226
  - test_data/test2.hl7
125
- homepage: https://github.com/ruby-hl7/ruby-hl7
126
- licenses: []
227
+ homepage: http://github.com/ruby-hl7/ruby-hl7
228
+ licenses:
229
+ - MIT
127
230
  metadata: {}
128
231
  post_install_message:
129
- rdoc_options: []
232
+ rdoc_options:
233
+ - "--charset=UTF-8"
130
234
  require_paths:
131
235
  - lib
132
236
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -141,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
245
  version: '0'
142
246
  requirements: []
143
247
  rubyforge_project: ruby-hl7
144
- rubygems_version: 2.6.11
248
+ rubygems_version: 2.4.5.1
145
249
  signing_key:
146
250
  specification_version: 4
147
251
  summary: Ruby HL7 Library