|
3 | 3 | require "spec_helper" |
4 | 4 |
|
5 | 5 | describe HL7::Message::Segment::MSH do |
6 | | - context "general" do |
7 | | - before :all do |
8 | | - @base = "MSH|^~\\&||ABCHS||AUSDHSV|20070101112951||ADT^A04^ADT_A01|12334456778890|P|2.5|||NE|NE|AU|ASCII|ENGLISH|||AN ORG|||RECNET.ORG" |
| 6 | + describe "segment parsing" do |
| 7 | + let(:segment_string) do |
| 8 | + "MSH|^~\\&||ABCHS||AUSDHSV|20070101112951||ADT^A04^ADT_A01|12334456778890|P|2.5|||NE|NE|AU|ASCII|ENGLISH|||AN ORG|||RECNET.ORG" |
9 | 9 | end |
| 10 | + let(:filled_msh) { HL7::Message::Segment::MSH.new(segment_string) } |
10 | 11 |
|
11 | | - it "allows access to an MSH segment" do |
12 | | - msh = HL7::Message::Segment::MSH.new @base |
13 | | - msh.enc_chars = '^~\\&' |
14 | | - expect(msh.version_id).to eq "2.5" |
15 | | - expect(msh.country_code).to eq "AU" |
16 | | - expect(msh.charset).to eq "ASCII" |
17 | | - expect(msh.sending_responsible_org).to eq "AN ORG" |
18 | | - expect(msh.receiving_network_address).to eq "RECNET.ORG" |
| 12 | + it "allows access to an MSH segment's attributes by their getters" do |
| 13 | + expect(filled_msh.enc_chars).to eq("^~\\&") |
| 14 | + expect(filled_msh.sending_app).to eq("") |
| 15 | + expect(filled_msh.sending_facility).to eq("ABCHS") |
| 16 | + expect(filled_msh.recv_app).to eq("") |
| 17 | + expect(filled_msh.recv_facility).to eq("AUSDHSV") |
| 18 | + expect(filled_msh.time).to eq("20070101112951") |
| 19 | + expect(filled_msh.security).to eq("") |
| 20 | + expect(filled_msh.message_type).to eq("ADT^A04^ADT_A01") |
| 21 | + expect(filled_msh.message_control_id).to eq("12334456778890") |
| 22 | + expect(filled_msh.processing_id).to eq("P") |
| 23 | + expect(filled_msh.version_id).to eq("2.5") |
| 24 | + expect(filled_msh.seq).to eq("") |
| 25 | + expect(filled_msh.continue_ptr).to eq("") |
| 26 | + expect(filled_msh.accept_ack_type).to eq("NE") |
| 27 | + expect(filled_msh.app_ack_type).to eq("NE") |
| 28 | + expect(filled_msh.country_code).to eq("AU") |
| 29 | + expect(filled_msh.charset).to eq("ASCII") |
| 30 | + expect(filled_msh.principal_language_of_message).to eq("ENGLISH") |
| 31 | + expect(filled_msh.alternate_character_set_handling_scheme).to eq("") |
| 32 | + expect(filled_msh.message_profile_identifier).to eq("") |
| 33 | + expect(filled_msh.sending_responsible_org).to eq("AN ORG") |
| 34 | + expect(filled_msh.receiving_responsible_org).to eq("") |
| 35 | + expect(filled_msh.sending_network_address).to eq("") |
| 36 | + expect(filled_msh.receiving_network_address).to eq("RECNET.ORG") |
19 | 37 | end |
20 | 38 |
|
21 | | - it "allows creation of an MSH segment" do |
22 | | - msh = HL7::Message::Segment::MSH.new |
23 | | - msh.sending_facility = "A Facility" |
24 | | - expect(msh.sending_facility).to eq "A Facility" |
25 | | - msh.time = DateTime.iso8601("20010203T040506") |
26 | | - expect(msh.time).to eq "20010203040506" |
| 39 | + it "allows access to an MSH segment's attributes by their index" do |
| 40 | + expect(filled_msh[2]).to eq("^~\\&") |
| 41 | + expect(filled_msh[3]).to eq("") |
| 42 | + expect(filled_msh[4]).to eq("ABCHS") |
| 43 | + expect(filled_msh[5]).to eq("") |
| 44 | + expect(filled_msh[6]).to eq("AUSDHSV") |
| 45 | + expect(filled_msh[7]).to eq("20070101112951") |
| 46 | + expect(filled_msh[8]).to eq("") |
| 47 | + expect(filled_msh[9]).to eq("ADT^A04^ADT_A01") |
| 48 | + expect(filled_msh[10]).to eq("12334456778890") |
| 49 | + expect(filled_msh[11]).to eq("P") |
| 50 | + expect(filled_msh[12]).to eq("2.5") |
| 51 | + expect(filled_msh[13]).to eq("") |
| 52 | + expect(filled_msh[14]).to eq("") |
| 53 | + expect(filled_msh[15]).to eq("NE") |
| 54 | + expect(filled_msh[16]).to eq("NE") |
| 55 | + expect(filled_msh[17]).to eq("AU") |
| 56 | + expect(filled_msh[18]).to eq("ASCII") |
| 57 | + expect(filled_msh[19]).to eq("ENGLISH") |
| 58 | + expect(filled_msh[20]).to eq("") |
| 59 | + expect(filled_msh[21]).to eq("") |
| 60 | + expect(filled_msh[22]).to eq("AN ORG") |
| 61 | + expect(filled_msh[23]).to eq("") |
| 62 | + expect(filled_msh[24]).to eq("") |
| 63 | + expect(filled_msh[25]).to eq("RECNET.ORG") |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + describe "segment creation" do |
| 68 | + let(:msh) { HL7::Message::Segment::MSH.new } |
| 69 | + let(:expected_msh_string) do |
| 70 | + "MSH|^~\\&||ABCHS||AUSDHSV|20070101112951||ADT^A04^ADT_A01|12334456778890|P|2.5|||NE|NE|AU|ASCII|ENGLISH|||AN ORG|||RECNET.ORG" |
| 71 | + end |
| 72 | + |
| 73 | + before do |
| 74 | + msh.enc_chars = "^~\\&" |
| 75 | + msh.sending_app = "" |
| 76 | + msh.sending_facility = "ABCHS" |
| 77 | + msh.recv_app = "" |
| 78 | + msh.recv_facility = "AUSDHSV" |
| 79 | + msh.time = "20070101112951" |
| 80 | + msh.security = "" |
| 81 | + msh.message_type = "ADT^A04^ADT_A01" |
| 82 | + msh.message_control_id = "12334456778890" |
| 83 | + msh.processing_id = "P" |
| 84 | + msh.version_id = "2.5" |
| 85 | + msh.seq = "" |
| 86 | + msh.continue_ptr = "" |
| 87 | + msh.accept_ack_type = "NE" |
| 88 | + msh.app_ack_type = "NE" |
| 89 | + msh.country_code = "AU" |
| 90 | + msh.charset = "ASCII" |
| 91 | + msh.principal_language_of_message = "ENGLISH" |
| 92 | + msh.alternate_character_set_handling_scheme = "" |
| 93 | + msh.message_profile_identifier = "" |
| 94 | + msh.sending_responsible_org = "AN ORG" |
| 95 | + msh.receiving_responsible_org = "" |
| 96 | + msh.sending_network_address = "" |
| 97 | + msh.receiving_network_address = "RECNET.ORG" |
| 98 | + end |
| 99 | + |
| 100 | + it "serializes an MSH segment" do |
| 101 | + expect(msh.to_s).to eq(expected_msh_string) |
27 | 102 | end |
28 | 103 | end |
29 | 104 | end |
0 commit comments