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.
@@ -0,0 +1,27 @@
1
+ # encoding: UTF-8
2
+ $: << '../lib'
3
+ require 'ruby-hl7'
4
+
5
+ describe HL7::Message::Segment::ORC do
6
+ context 'general' do
7
+ before :all do
8
+ @base_orc = 'ORC|RE|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|||||||||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD||^WPN^PH^^1^555^5551005|||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1005 Healthcare Drive^^Ann Arbor^MI^99999^USA^B|^WPN^PH^^1^555^5553001|4444 Healthcare Drive^Suite 123^Ann Arbor^MI^99999^USA^B|||||||7844'
9
+ end
10
+
11
+ it 'creates an ORC segment' do
12
+ lambda do
13
+ orc = HL7::Message::Segment::ORC.new( @base_orc )
14
+ orc.should_not be_nil
15
+ orc.to_s.should == @base_orc
16
+ end.should_not raise_error
17
+ end
18
+
19
+ it 'allows access to an ORC segment' do
20
+ orc = HL7::Message::Segment::ORC.new( @base_orc )
21
+ orc.ordering_provider.should == '1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD'
22
+ orc.call_back_phone_number.should == '^WPN^PH^^1^555^5551005'
23
+ orc.ordering_facility_name.should == 'Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234'
24
+ orc.parent_universal_service_identifier.should == '7844'
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,70 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::PID do
5
+ context 'general' do
6
+ before :all do
7
+ @base = "PID|1||333||LastName^FirstName^MiddleInitial^SR^NickName||19760228|F||2106-3^White^HL70005^CAUC^Caucasian^L||||||||555.55|012345678||||||||||201011110924-0700|Y|||||||||"
8
+ end
9
+
10
+ it 'validates the admin_sex element' do
11
+ pid = HL7::Message::Segment::PID.new
12
+ lambda do
13
+ vals = %w[F M O U A N C] + [ nil ]
14
+ vals.each do |x|
15
+ pid.admin_sex = x
16
+ end
17
+ pid.admin_sex = ""
18
+ end.should_not raise_error
19
+
20
+ lambda do
21
+ ["TEST", "A", 1, 2].each do |x|
22
+ pid.admin_sex = x
23
+ end
24
+ end.should raise_error(HL7::InvalidDataError)
25
+ end
26
+
27
+ it "sets values correctly" do
28
+ pid = HL7::Message::Segment::PID.new @base
29
+ pid.set_id.should == "1"
30
+ pid.patient_id.should == ""
31
+ pid.patient_id_list.should == "333"
32
+ pid.alt_patient_id.should == ""
33
+ pid.patient_name.should == "LastName^FirstName^MiddleInitial^SR^NickName"
34
+ pid.mother_maiden_name.should == ""
35
+ pid.patient_dob.should == "19760228"
36
+ pid.admin_sex.should == "F"
37
+ pid.patient_alias.should == ""
38
+ pid.race.should == "2106-3^White^HL70005^CAUC^Caucasian^L"
39
+ pid.address.should == ""
40
+ pid.country_code.should == ""
41
+ pid.phone_home.should == ""
42
+ pid.phone_business.should == ""
43
+ pid.primary_language.should == ""
44
+ pid.marital_status.should == ""
45
+ pid.religion.should == ""
46
+ pid.account_number.should == "555.55"
47
+ pid.social_security_num.should == "012345678"
48
+ pid.driver_license_num.should == ""
49
+ pid.mothers_id.should == ""
50
+ pid.ethnic_group.should == ""
51
+ pid.birthplace.should == ""
52
+ pid.multi_birth.should == ""
53
+ pid.birth_order.should == ""
54
+ pid.citizenship.should == ""
55
+ pid.vet_status.should == ""
56
+ pid.nationality.should == ""
57
+ pid.death_date.should == "201011110924-0700"
58
+ pid.death_indicator.should == "Y"
59
+ pid.id_unknown_indicator.should == ""
60
+ pid.id_readability_code.should == ""
61
+ pid.last_update_date.should == ""
62
+ pid.last_update_facility.should == ""
63
+ pid.species_code.should == ""
64
+ pid.breed_code.should == ""
65
+ pid.strain.should == ""
66
+ pid.production_class_code.should == ""
67
+ pid.tribal_citizenship.should == ""
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::PRD do
5
+ context 'general' do
6
+ let (:base) { 'PRD|RP|LastName^FirstName^MiddleInitial^SR^NickName|444 Home Street^Apt B^Ann Arbor^MI^99999^USA|^^^A Wonderful Clinic|^WPN^PH^^^07^5555555|PH|4796^AUSHICPR|20130109163307+1000|20140109163307+1000' }
7
+ let (:prd) { HL7::Message::Segment::PRD.new base }
8
+
9
+ it 'should set the provider_role' do
10
+ prd.provider_role.should eql 'RP'
11
+ end
12
+
13
+ it 'should set the name' do
14
+ prd.provider_name.should eql 'LastName^FirstName^MiddleInitial^SR^NickName'
15
+ end
16
+
17
+ it 'should set the provider_address' do
18
+ prd.provider_address.should eql '444 Home Street^Apt B^Ann Arbor^MI^99999^USA'
19
+ end
20
+
21
+ it 'should set the provider_location' do
22
+ prd.provider_location.should eql '^^^A Wonderful Clinic'
23
+ end
24
+
25
+ it 'should set provider_communication_information' do
26
+ prd.provider_communication_information.should eql '^WPN^PH^^^07^5555555'
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::PV1 do
5
+ context 'general' do
6
+ before :all do
7
+ @base = "PV1||R|||||||||||||||A|||V02^19900607~H02^19900607"
8
+ end
9
+
10
+ it 'allows access to an PV1 segment' do
11
+ pv1 = HL7::Message::Segment::PV1.new @base
12
+ pv1.patient_class.should == "R"
13
+ end
14
+
15
+ it 'allows creation of an OBX segment' do
16
+ pv1= HL7::Message::Segment::PV1.new
17
+ pv1.referring_doctor="Smith^John"
18
+ pv1.referring_doctor.should == "Smith^John"
19
+ pv1.admit_date = Date.new(2014, 1, 1)
20
+ pv1.admit_date.should == '20140101'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::RF1 do
5
+ context 'general' do
6
+ before :all do
7
+ @base = 'RF1|P^Pending^HL70283|R^Routine^HL70280|GRF^General referral^HL70281|AM^Assume management^HL70282||8094|20060705||20060705||42'
8
+
9
+ end
10
+
11
+ it 'allows access to an RF1 segment' do
12
+ rf1 = HL7::Message::Segment::RF1.new @base
13
+ rf1.referral_status.should == 'P^Pending^HL70283'
14
+ rf1.referral_priority.should == 'R^Routine^HL70280'
15
+ rf1.referral_type.should == 'GRF^General referral^HL70281'
16
+ rf1.referral_disposition.should == 'AM^Assume management^HL70282'
17
+ rf1.originating_referral_identifier.should == '8094'
18
+ rf1.effective_date.should == '20060705'
19
+ rf1.process_date.should == '20060705'
20
+ rf1.external_referral_identifier.should == '42'
21
+ end
22
+
23
+ it 'allows creation of an RF1 segment' do
24
+ rf1 = HL7::Message::Segment::RF1.new
25
+ rf1.expiration_date=Date.new(2058, 12, 1)
26
+ rf1.expiration_date.should == '20581201'
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,92 @@
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
+ msg.to_s.should == @base
26
+ msg.no_block.should == "no_block"
27
+ msg.validating.should == "validated"
28
+ msg.converting.should == "Xconverted"
29
+
30
+ msg.no_block = "NO_BLOCK"
31
+ msg.no_block.should == "NO_BLOCK"
32
+
33
+ msg.validating = "good"
34
+ msg.validating.should == "good"
35
+ msg.validating = "bad"
36
+ msg.validating.should == ""
37
+
38
+ msg.converting = "empty"
39
+ msg.converting.should == "XXempty"
40
+ end
41
+
42
+ it 'is not evaluated on read access by eXXX alias' do
43
+ msg = MockSegment.new(@base)
44
+
45
+ msg.e1.should == "no_block"
46
+ msg.e2.should == "validated"
47
+ msg.e3.should == "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
+ msg.e1.should == "NO_BLOCK"
55
+
56
+ msg.e2 = "good"
57
+ msg.e2.should == "good"
58
+ msg.e2 = "bad"
59
+ msg.e2.should == "bad"
60
+
61
+ msg.e3 = "empty"
62
+ msg.e3.should == "empty"
63
+ end
64
+ end
65
+
66
+ describe '#alias_field' do
67
+ context 'with a valid field' do
68
+ it 'uses alias field names' do
69
+ msg = MockSegment.new(@base)
70
+ msg.no_block.should == "no_block"
71
+ msg.no_block_alias.should == "no_block"
72
+ end
73
+ end
74
+
75
+ context 'with an invalid field' do
76
+
77
+ class MockInvalidSegment < HL7::Message::Segment
78
+ weight 1
79
+ add_field :no_block
80
+ alias_field :no_block_alias, :invalid_field
81
+ add_field :second
82
+ add_field :third
83
+ end
84
+
85
+
86
+ it 'throws an error when the field is invalid' do
87
+ msg = MockInvalidSegment.new(@base)
88
+ lambda{ msg.no_block_alias }.should raise_error
89
+ end
90
+ end
91
+ end
92
+ 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
+ segment_generator.valid_segments_parts?.should 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
+ segment_generator.valid_segments_parts?.should 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
+ segment.accepts?(:OBR).should be true
16
+ segment.child_types.should 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
+ segment_instance.respond_to?(method).should 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
+ segment_instance.respond_to?(:children).should 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,27 @@
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
+ segment.length.should eq 3
9
+ end
10
+ end
11
+
12
+ describe 'is_child_segment?' do
13
+ let(:segment){ HL7::Message::Segment.new "MSA|AR|ZZ9380 ERR" }
14
+ it "return false when is not set" do
15
+ segment.is_child_segment?.should be false
16
+ end
17
+ end
18
+
19
+ describe 'convert_to_ts' do
20
+ let(:time_now){ DateTime.now }
21
+ let(:formated_time){ time_now.strftime('%Y%m%d%H%M%S') }
22
+
23
+ it "should conver to the hl7 time format" do
24
+ HL7::Message::Segment.convert_to_ts(time_now).should eq formated_time
25
+ end
26
+ end
27
+ 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|1|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
+ lambda do
12
+ sft = HL7::Message::Segment::SFT.new( @base_sft )
13
+ sft.should_not be_nil
14
+ sft.to_s.should == @base_sft
15
+ end.should_not raise_error
16
+ end
17
+
18
+ it 'allows access to an SFT segment' do
19
+ lambda do
20
+ sft = HL7::Message::Segment::SFT.new( @base_sft )
21
+ sft.software_product_name.should == 'An Lab System'
22
+ sft.software_install_date.should == '20080817'
23
+ end.should_not raise_error
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
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__)
@@ -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
+ doc.should_not be_nil
15
+ ends = Time.now
16
+ (ends-start).should be < 1
17
+ end
18
+ end
19
+ end