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,37 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe 'dynamic segment definition' do
5
+ context 'general' do
6
+ it 'accepts a block with a parameter' do
7
+ seg = HL7::Message::Segment.new do |s|
8
+ s.e0 = "MSK"
9
+ s.e1 = "1234"
10
+ s.e2 = "5678"
11
+ end
12
+
13
+ expect(seg.to_s).to eq "MSK|1234|5678"
14
+ end
15
+
16
+ it 'accepts a block without a parameter' do
17
+ seg = HL7::Message::Segment.new do
18
+ e0 "MSK"
19
+ e1 "1234"
20
+ e2 "5678"
21
+ end
22
+
23
+ expect(seg.to_s).to eq "MSK|1234|5678"
24
+ end
25
+
26
+ it "doesn't pollute the caller namespace" do
27
+ seg = HL7::Message::Segment.new do |s|
28
+ s.e0 = "MSK"
29
+ s.e1 = "1234"
30
+ s.e2 = "5678"
31
+ end
32
+
33
+ expect { e3 "TEST" }.to raise_error(NoMethodError)
34
+ expect(seg.to_s).to eq "MSK|1234|5678"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::ERR do
5
+ context 'general' do
6
+ before :all do
7
+ @base_err = 'ERR||OBR^1|100^Segment sequence error^HL70357|E|||Missing required OBR segment|Email help desk for further information on this error||||^NET^Internet^helpdesk@hl7.org'
8
+ end
9
+
10
+ it 'creates an ERR segment' do
11
+ expect do
12
+ err = HL7::Message::Segment::ERR.new( @base_err )
13
+ expect(err).not_to be_nil
14
+ expect(err.to_s).to eq @base_err
15
+ end.not_to raise_error
16
+ end
17
+
18
+ it 'allows access to an ERR segment' do
19
+ expect do
20
+ err = HL7::Message::Segment::ERR.new( @base_err )
21
+ expect(err.severity).to eq 'E'
22
+ expect(err.error_location).to eq 'OBR^1'
23
+ end.not_to raise_error
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::EVN do
5
+ context 'general' do
6
+ before :all do
7
+ @base = "EVN|A04|20060705000000"
8
+ end
9
+
10
+ it 'allows access to an EVN segment' do
11
+ evn = HL7::Message::Segment::EVN.new @base
12
+ expect(evn.type_code).to eq "A04"
13
+ end
14
+
15
+ it 'allows creation of an EVN segment' do
16
+ evn = HL7::Message::Segment::EVN.new
17
+ evn.event_facility="A Facility"
18
+ expect(evn.event_facility).to eq 'A Facility'
19
+ evn.recorded_date = Date.new 2001,2,3
20
+ expect(evn.recorded_date).to eq "20010203"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::FT1 do
5
+ context 'general' do
6
+ before :all do
7
+ @base_ft1 = 'FT1|1|||20180705|20180705|||Description||1||||||123456^The Location|||R45.82^Worries~H18.892^Other specified disorders of cornea|1043312457^Provider^Testing^^^^|1043312457^Provider^Testing^^^^||||99392^HEART FAILURE COMPOSITE|'
8
+ end
9
+
10
+ it 'creates an FT1 segment' do
11
+ expect do
12
+ ft1 = HL7::Message::Segment::FT1.new( @base_ft1 )
13
+ expect(ft1).not_to be_nil
14
+ expect(ft1.to_s).to eq @base_ft1
15
+ end.not_to raise_error
16
+ end
17
+
18
+ it 'allows access to an FT1 segment' do
19
+ expect do
20
+ ft1 = HL7::Message::Segment::FT1.new( @base_ft1 )
21
+ expect(ft1.set_id).to eq '1'
22
+ expect(ft1.date_of_service).to eq '20180705'
23
+ expect(ft1.transaction_posting_date).to eq '20180705'
24
+ expect(ft1.transaction_description).to eq 'Description'
25
+ expect(ft1.transaction_quantity).to eq '1'
26
+ expect(ft1.assigned_patient_location).to eq '123456^The Location'
27
+ expect(ft1.diagnosis_code).to eq 'R45.82^Worries~H18.892^Other specified disorders of cornea'
28
+ expect(ft1.performed_by_provider).to eq '1043312457^Provider^Testing^^^^'
29
+ expect(ft1.ordering_provider).to eq '1043312457^Provider^Testing^^^^'
30
+ expect(ft1.procedure_code).to eq '99392^HEART FAILURE COMPOSITE'
31
+
32
+ end.not_to raise_error
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe HL7::Message::Segment::FTS do
4
+ context 'general' do
5
+ before :all do
6
+ base_string = 'FTS||End of File'
7
+ @fts = HL7::Message::Segment::FTS.new(base_string)
8
+ end
9
+
10
+ it 'creates an FTS segment' do
11
+ expect(@fts).to_not be_nil
12
+ end
13
+
14
+ it 'allows access to an FTS segment' do
15
+ expect(@fts.file_batch_count).to eq('')
16
+ expect(@fts.file_trailer_comment).to eq('End of File')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::GT1 do
5
+ context 'general' do
6
+ before :all do
7
+ @base_gt1 = 'GT1||440|Crusher^Beverly||1003 Elm Street^^Enterprise^MD^29433|(330)644-1234^^^bcrusher@ufp.net^^330^6441234| |19600411000000|F||18|339-33-6657||||||||F||||||||||M'
8
+ end
9
+
10
+ it 'creates an GT1 segment' do
11
+ expect do
12
+ gt1 = HL7::Message::Segment::GT1.new( @base_gt1 )
13
+ expect(gt1).not_to be_nil
14
+ expect(gt1.to_s).to eq @base_gt1
15
+ end.not_to raise_error
16
+ end
17
+
18
+ it 'allows access to an GT1 segment' do
19
+ expect do
20
+ gt1 = HL7::Message::Segment::GT1.new( @base_gt1 )
21
+ expect(gt1.guarantor_number).to eq '440'
22
+ expect(gt1.guarantor_name).to eq 'Crusher^Beverly'
23
+ expect(gt1.guarantor_address).to eq '1003 Elm Street^^Enterprise^MD^29433'
24
+ expect(gt1.guarantor_date_of_birth).to eq '19600411000000'
25
+ expect(gt1.guarantor_sex).to eq 'F'
26
+ expect(gt1.guarantor_relationship).to eq '18'
27
+ expect(gt1.guarantor_ssn).to eq '339-33-6657'
28
+ expect(gt1.guarantor_employment_status).to eq 'F'
29
+ end.not_to raise_error
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::IN1 do
5
+ context 'general' do
6
+ before :all do
7
+ @base_in1 = 'IN1|1||752|ACORDIA NATIONAL||||A|GRP|||||||SMITH^JOHN|19|19700102||||||||||||||||||WC23732763278A|||||||||||||||||X'
8
+ end
9
+
10
+ it 'creates an IN1 segment' do
11
+ expect do
12
+ in1 = HL7::Message::Segment::IN1.new( @base_in1 )
13
+ expect(in1).not_to be_nil
14
+ expect(in1.to_s).to eq @base_in1
15
+ end.not_to raise_error
16
+ end
17
+
18
+ it 'allows access to an IN1 segment' do
19
+ expect do
20
+ in1 = HL7::Message::Segment::IN1.new( @base_in1 )
21
+ expect(in1.set_id).to eq '1'
22
+ expect(in1.insurance_company_id).to eq '752'
23
+ expect(in1.insurance_company_name).to eq 'ACORDIA NATIONAL'
24
+ expect(in1.group_number).to eq 'A'
25
+ expect(in1.group_name).to eq 'GRP'
26
+ expect(in1.name_of_insured).to eq 'SMITH^JOHN'
27
+ expect(in1.insureds_relationship_to_patient).to eq '19'
28
+ expect(in1.insureds_date_of_birth).to eq '19700102'
29
+ expect(in1.policy_number).to eq 'WC23732763278A'
30
+ expect(in1.vip_indicator).to eq 'X'
31
+ end.not_to raise_error
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe HL7::Message do
4
+ describe "#correction?" do
5
+ let(:hl7) { HL7::Message.new data }
6
+ subject { hl7.correction? }
7
+
8
+ context "when is a correction" do
9
+ let(:data) {
10
+ [
11
+ 'OBR|1|A241Z^LAB||123456^A TEST^L|||201508181431||1234||||None|201502181432||||OMG123||||20150818143300', # "F" final
12
+ 'OBX|1|ST|123456^AA OBSERVATION^L^4567890^FIRST OBSERVATION^LN||42|ug/dL^Micrograms per Deciliter^UCUM|<10 ug/dL|H|||F||||OMG',
13
+ 'NTE|1||SOME',
14
+ 'NTE|2||THOUGHTS',
15
+ 'OBR|2|A241Z^LAB||123456^A TEST^L|||201508181431||1234||||None|201502181432||||OMG123||||20150818143300', # "C" corrected
16
+ 'OBX|1|ST|123456^AA OBSERVATION^L^4567890^FIRST OBSERVATION^LN||42|ug/dL^Micrograms per Deciliter^UCUM|<10 ug/dL|H|||C||||OMG',
17
+ 'NTE|1||SOME',
18
+ 'NTE|2||THOUGHTS',
19
+ ].join("\r")
20
+ }
21
+
22
+ it { is_expected.to be true }
23
+ end
24
+
25
+ context "when is not a correction" do
26
+ let(:data) {
27
+ [
28
+ 'OBR|1|A241Z^LAB||123456^A TEST^L|||201508181431||1234||||None|201502181432||||OMG123||||20150818143300', # "F" final
29
+ 'OBX|1|ST|123456^AA OBSERVATION^L^4567890^FIRST OBSERVATION^LN||42|ug/dL^Micrograms per Deciliter^UCUM|<10 ug/dL|H|||F||||OMG',
30
+ 'NTE|1||SOME',
31
+ 'NTE|2||THOUGHTS',
32
+ 'OBR|2|A241Z^LAB||123456^A TEST^L|||201508181431||1234||||None|201502181432||||OMG123||||20150818143300', # "F" final
33
+ 'OBX|1|ST|123456^AA OBSERVATION^L^4567890^FIRST OBSERVATION^LN||42|ug/dL^Micrograms per Deciliter^UCUM|<10 ug/dL|H|||F||||OMG',
34
+ 'NTE|1||SOME',
35
+ 'NTE|2||THOUGHTS',
36
+ ].join("\r")
37
+ }
38
+
39
+ it { is_expected.to be false }
40
+ end
41
+
42
+ context "when there are no results (OBX) segments" do
43
+ let(:data) {
44
+ [
45
+ 'OBR|1|A241Z^LAB||123456^A TEST^L|||201508181431||1234||||None|201502181432||||OMG123||||20150818143300',
46
+ 'OBR|2|A241Z^LAB||123456^A TEST^L|||201508181431||1234||||None|201502181432||||OMG123||||20150818143300'
47
+ ].join("\r")
48
+ }
49
+
50
+ it { is_expected.to be false }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe "HL7 Messages" do
4
+ it 'processes multiple known messages without failing' do
5
+ expect do
6
+ HL7MESSAGES.each_pair do |key, hl7|
7
+ HL7::Message.new(hl7)
8
+ end
9
+ end.not_to raise_exception
10
+ end
11
+
12
+ describe 'MFN M13 Messages' do
13
+ it "extracts the MSH" do
14
+ expect(HL7::Message.new(HL7MESSAGES[:mfn_m13])[:MSH].sending_app).to eq 'HL7REG'
15
+ end
16
+ it 'extracts the MFI' do
17
+ expect(HL7::Message.new(HL7MESSAGES[:mfn_m13])[:MFI].master_file_identifier).to eq 'HL70006^RELIGION^HL70175'
18
+ end
19
+ it 'extracts the MFE' do
20
+ expect(HL7::Message.new(HL7MESSAGES[:mfn_m13])[:MFE][0].mfn_control_id).to eq '6772333'
21
+ expect(HL7::Message.new(HL7MESSAGES[:mfn_m13])[:MFE][1].mfn_control_id).to eq '6772334'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::MFE do
5
+ context 'general' do
6
+ before :all do
7
+ @base_sft = 'MFE|MAD|6772331|200106290500|BUD^Buddhist^HL70006|CE'
8
+ end
9
+
10
+ it 'creates an MFE segment' do
11
+ expect do
12
+ sft = HL7::Message::Segment::MFE.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 MFE segment' do
19
+ expect do
20
+ sft = HL7::Message::Segment::MFE.new( @base_sft )
21
+ expect(sft.record_level_event_code).to eq 'MAD'
22
+ expect(sft.mfn_control_id).to eq '6772331'
23
+ expect(sft.primary_key_value).to eq 'BUD^Buddhist^HL70006'
24
+ expect(sft.primary_key_value_type).to eq 'CE'
25
+ end.not_to raise_error
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::MFI do
5
+ context 'general' do
6
+ before :all do
7
+ @base_sft = 'MFI|HL70006^RELIGION^HL70175|TEST|UPD|||AL'
8
+ end
9
+
10
+ it 'creates an MFI segment' do
11
+ expect do
12
+ sft = described_class.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 MFI segment' do
19
+ expect do
20
+ sft = described_class.new( @base_sft )
21
+ expect(sft.master_file_identifier).to eq 'HL70006^RELIGION^HL70175'
22
+ expect(sft.master_file_application_identifier).to eq 'TEST'
23
+ expect(sft.file_level_event_code).to eq 'UPD'
24
+ expect(sft.response_level_code).to eq 'AL'
25
+ end.not_to raise_error
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: UTF-8
2
+ $: << '../lib'
3
+ require 'ruby-hl7'
4
+
5
+ describe HL7::Message::Segment::MSA do
6
+ context 'general' do
7
+ before :all do
8
+ @base_msa = "MSA|AR|ZZ9380 ERR"
9
+ end
10
+
11
+ it 'creates an MSA segment' do
12
+ expect do
13
+ msa = HL7::Message::Segment::MSA.new( @base_msa )
14
+ expect(msa).not_to be_nil
15
+ expect(msa.to_s).to eq @base_msa
16
+ end.not_to raise_error
17
+ end
18
+
19
+ it 'allows access to an MSA segment' do
20
+ expect do
21
+ msa = HL7::Message::Segment::MSA.new( @base_msa )
22
+ expect(msa.ack_code).to eq "AR"
23
+ expect(msa.control_id).to eq "ZZ9380 ERR"
24
+ end.not_to raise_error
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::MSH do
5
+ context 'general' do
6
+ before :all do
7
+ @base = "MSH|^~\\&||ABCHS||AUSDHSV|20070101112951||ADT^A04^ADT_A01|12334456778890|P|2.5|||NE|NE|AU|ASCII|ENGLISH|||AN ORG|||RECNET.ORG"
8
+ end
9
+
10
+ it 'allows access to an MSH segment' do
11
+ msh = HL7::Message::Segment::MSH.new @base
12
+ msh.enc_chars='^~\\&'
13
+ expect(msh.version_id).to eq '2.5'
14
+ expect(msh.country_code).to eq 'AU'
15
+ expect(msh.charset).to eq 'ASCII'
16
+ expect(msh.sending_responsible_org).to eq 'AN ORG'
17
+ expect(msh.receiving_network_address).to eq 'RECNET.ORG'
18
+ end
19
+
20
+ it 'allows creation of an MSH segment' do
21
+ msh = HL7::Message::Segment::MSH.new
22
+ msh.sending_facility="A Facility"
23
+ expect(msh.sending_facility).to eq 'A Facility'
24
+ msh.time = DateTime.iso8601('20010203T040506')
25
+ expect(msh.time).to eq '20010203040506'
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::NK1 do
5
+ context 'general' do
6
+ before :all do
7
+ @base_nk1 = 'NK1|1|Mum^Martha^M^^^^L|MTH^Mother^HL70063^^^^2.5.1| 444 Home Street^Apt B^Ann Arbor^MI^99999^USA^H|^PRN^PH^^1^555^5552006'
8
+ end
9
+
10
+ it 'creates an NK1 segment' do
11
+ expect do
12
+ nk1 = HL7::Message::Segment::NK1.new( @base_nk1 )
13
+ expect(nk1).not_to be_nil
14
+ expect(nk1.to_s).to eq @base_nk1
15
+ end.not_to raise_error
16
+ end
17
+
18
+ it 'allows access to an NK1 segment' do
19
+ expect do
20
+ nk1 = HL7::Message::Segment::NK1.new( @base_nk1 )
21
+ expect(nk1.name).to eq 'Mum^Martha^M^^^^L'
22
+ expect(nk1.phone_number).to eq '^PRN^PH^^1^555^5552006'
23
+ end.not_to raise_error
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::OBR do
5
+ context 'general' do
6
+ before :all do
7
+ @base = "OBR|2|^USSSA|0000000567^USSSA|37956^CT ABDOMEN^LN|||199405021550|||||||||||||0000763||||NMR|P||||||R/O TUMOR|202300&BAKER&MARK&E|||01&LOCHLEAR&JUDY|||||||||||||||123"
8
+ @obr = HL7::Message::Segment::OBR.new @base
9
+ end
10
+
11
+ it 'allows access to an OBR segment' do
12
+ expect(@obr.to_s).to eq @base
13
+ expect(@obr.e1).to eq "2"
14
+ expect(@obr.set_id).to eq "2"
15
+ expect(@obr.placer_order_number).to eq "^USSSA"
16
+ expect(@obr.filler_order_number).to eq "0000000567^USSSA"
17
+ expect(@obr.universal_service_id).to eq "37956^CT ABDOMEN^LN"
18
+ end
19
+
20
+ it 'allows modification of an OBR segment' do
21
+ @obr.set_id = 1
22
+ expect(@obr.set_id).to eq "1"
23
+ @obr.placer_order_number = "^DMCRES"
24
+ expect(@obr.placer_order_number).to eq "^DMCRES"
25
+ end
26
+
27
+ it 'supports the diagnostic_serv_sect_id method' do
28
+ expect(@obr).to respond_to(:diagnostic_serv_sect_id)
29
+ expect(@obr.diagnostic_serv_sect_id).to eq "NMR"
30
+ end
31
+
32
+ it 'supports the result_status method' do
33
+ expect(@obr).to respond_to(:result_status)
34
+ expect(@obr.result_status).to eq "P"
35
+ end
36
+
37
+ it 'supports the reason_for_study method' do
38
+ expect(@obr.reason_for_study).to eq "R/O TUMOR"
39
+ end
40
+
41
+ it 'supports the parent_universal_service_identifier method' do
42
+ expect(@obr.parent_universal_service_identifier).to eq "123"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,68 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe HL7::Message::Segment::OBX do
5
+ context 'general' do
6
+ before :all do
7
+ @base = "OBX|1|NM|30341-2^Erythrocyte sedimentation rate^LN^815117^ESR^99USI^^^Erythrocyte sedimentation rate||10|mm/h^millimeter per hour^UCUM|0 to 17|N|0.1||F|||20110331140551-0800||Observer|||20110331150551-0800|^A Site|||Century Hospital^^^^^NIST-AA-1&2.16.840.1.113883.3.72.5.30.1&ISO^XX^^^987|2070 Test Park^^Los Angeles^CA^90067^USA^B^^06037|2343242^Knowsalot^Phil^J.^III^Dr.^^^NIST-AA-1&2.16.840.1.113883.3.72.5.30.1&ISO^L^^^DN"
8
+ end
9
+
10
+ it 'allows access to an OBX segment' do
11
+ obx = HL7::Message::Segment::OBX.new @base
12
+ expect(obx.set_id).to eq "1"
13
+ expect(obx.value_type).to eq "NM"
14
+ expect(obx.observation_id).to eq "30341-2^Erythrocyte sedimentation rate^LN^815117^ESR^99USI^^^Erythrocyte sedimentation rate"
15
+ expect(obx.observation_sub_id).to eq ""
16
+ expect(obx.observation_value).to eq "10"
17
+ expect(obx.units).to eq "mm/h^millimeter per hour^UCUM"
18
+ expect(obx.references_range).to eq "0 to 17"
19
+ expect(obx.abnormal_flags).to eq "N"
20
+ expect(obx.probability).to eq "0.1"
21
+ expect(obx.nature_of_abnormal_test).to eq ""
22
+ expect(obx.observation_result_status).to eq "F"
23
+ expect(obx.effective_date_of_reference_range).to eq ""
24
+ expect(obx.user_defined_access_checks).to eq ""
25
+ expect(obx.observation_date).to eq "20110331140551-0800"
26
+ expect(obx.producer_id).to eq ""
27
+ expect(obx.responsible_observer).to eq "Observer"
28
+ expect(obx.observation_site).to eq '^A Site'
29
+ expect(obx.observation_method).to eq ""
30
+ expect(obx.equipment_instance_id).to eq ""
31
+ expect(obx.analysis_date).to eq "20110331150551-0800"
32
+ expect(obx.performing_organization_name).to eq "Century Hospital^^^^^NIST-AA-1&2.16.840.1.113883.3.72.5.30.1&ISO^XX^^^987"
33
+ expect(obx.performing_organization_address).to eq "2070 Test Park^^Los Angeles^CA^90067^USA^B^^06037"
34
+ expect(obx.performing_organization_medical_director).to eq "2343242^Knowsalot^Phil^J.^III^Dr.^^^NIST-AA-1&2.16.840.1.113883.3.72.5.30.1&ISO^L^^^DN"
35
+ end
36
+
37
+ it 'allows creation of an OBX segment' do
38
+ expect do
39
+ obx = HL7::Message::Segment::OBX.new
40
+ obx.value_type = "TESTIES"
41
+ obx.observation_id = "HR"
42
+ obx.observation_sub_id = "2"
43
+ obx.observation_value = "SOMETHING HAPPENned"
44
+ end.not_to raise_error
45
+ end
46
+
47
+ describe "#correction?" do
48
+ let(:obx) { HL7::Message::Segment::OBX.new data }
49
+ subject { obx.correction? }
50
+
51
+ context "when is a correction" do
52
+ let(:data) {
53
+ 'OBX|1|ST|123456^AA OBSERVATION^L^4567890^FIRST OBSERVATION^LN||42|ug/dL^Micrograms per Deciliter^UCUM|<10 ug/dL|H|||C||||OMG'
54
+ }
55
+
56
+ it { is_expected.to be true }
57
+ end
58
+
59
+ context "when is not a correction" do
60
+ let(:data) {
61
+ 'OBX|1|ST|123456^AA OBSERVATION^L^4567890^FIRST OBSERVATION^LN||42|ug/dL^Micrograms per Deciliter^UCUM|<10 ug/dL|H|||F||||OMG'
62
+ }
63
+
64
+ it { is_expected.to be false }
65
+ end
66
+ end
67
+ end
68
+ end
@@ -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
+ expect do
13
+ orc = HL7::Message::Segment::ORC.new( @base_orc )
14
+ expect(orc).not_to be_nil
15
+ expect(orc.to_s).to eq @base_orc
16
+ end.not_to raise_error
17
+ end
18
+
19
+ it 'allows access to an ORC segment' do
20
+ orc = HL7::Message::Segment::ORC.new( @base_orc )
21
+ expect(orc.ordering_provider).to eq '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
+ expect(orc.call_back_phone_number).to eq '^WPN^PH^^1^555^5551005'
23
+ expect(orc.ordering_facility_name).to eq 'Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234'
24
+ expect(orc.parent_universal_service_identifier).to eq '7844'
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,78 @@
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||AA||||||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
+ expect 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.not_to raise_error
19
+
20
+ expect do
21
+ ["TEST", "A", 1, 2].each do |x|
22
+ pid.admin_sex = x
23
+ end
24
+ end.to raise_error(HL7::InvalidDataError)
25
+ end
26
+
27
+ it "sets values correctly" do
28
+ pid = HL7::Message::Segment::PID.new @base
29
+ expect(pid.set_id).to eq "1"
30
+ expect(pid.patient_id).to eq ""
31
+ expect(pid.patient_id_list).to eq "333"
32
+ expect(pid.alt_patient_id).to eq ""
33
+ expect(pid.patient_name).to eq "LastName^FirstName^MiddleInitial^SR^NickName"
34
+ expect(pid.mother_maiden_name).to eq ""
35
+ expect(pid.patient_dob).to eq "19760228"
36
+ expect(pid.admin_sex).to eq "F"
37
+ expect(pid.patient_alias).to eq ""
38
+ expect(pid.race).to eq "2106-3^White^HL70005^CAUC^Caucasian^L"
39
+ expect(pid.address).to eq ""
40
+ expect(pid.county_code).to eq "AA"
41
+ expect(pid.phone_home).to eq ""
42
+ expect(pid.phone_business).to eq ""
43
+ expect(pid.primary_language).to eq ""
44
+ expect(pid.marital_status).to eq ""
45
+ expect(pid.religion).to eq ""
46
+ expect(pid.account_number).to eq "555.55"
47
+ expect(pid.social_security_num).to eq "012345678"
48
+ expect(pid.driver_license_num).to eq ""
49
+ expect(pid.mothers_id).to eq ""
50
+ expect(pid.ethnic_group).to eq ""
51
+ expect(pid.birthplace).to eq ""
52
+ expect(pid.multi_birth).to eq ""
53
+ expect(pid.birth_order).to eq ""
54
+ expect(pid.citizenship).to eq ""
55
+ expect(pid.vet_status).to eq ""
56
+ expect(pid.nationality).to eq ""
57
+ expect(pid.death_date).to eq "201011110924-0700"
58
+ expect(pid.death_indicator).to eq "Y"
59
+ expect(pid.id_unknown_indicator).to eq ""
60
+ expect(pid.id_readability_code).to eq ""
61
+ expect(pid.last_update_date).to eq ""
62
+ expect(pid.last_update_facility).to eq ""
63
+ expect(pid.species_code).to eq ""
64
+ expect(pid.breed_code).to eq ""
65
+ expect(pid.strain).to eq ""
66
+ expect(pid.production_class_code).to eq ""
67
+ expect(pid.tribal_citizenship).to eq ""
68
+ end
69
+
70
+ it "aliases the county_code field as country_code for backwards compatibility" do
71
+ pid = HL7::Message::Segment::PID.new @base
72
+ expect(pid.country_code).to eq "AA"
73
+
74
+ pid.country_code = "ZZ"
75
+ expect(pid.country_code).to eq "ZZ"
76
+ end
77
+ end
78
+ end