Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/segments/msh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@ class HL7::Message::Segment::MSH < HL7::Message::Segment
add_field :receiving_responsible_org
add_field :sending_network_address
add_field :receiving_network_address

# NOTE: MSH-1 has a special behaviour and is not included in the HL7 format, hence causing an offset to happen in the fields order
# This overriding of the following getter and setter ensure the order of the fields is respected
def [](index)
@elements[index - 1]
end

def []=(index, value)
@elements[index - 1] = value.to_s
end
end
109 changes: 92 additions & 17 deletions spec/msh_segment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,102 @@
require "spec_helper"

describe HL7::Message::Segment::MSH do
context "general" do
before :all do
@base = "MSH|^~\\&||ABCHS||AUSDHSV|20070101112951||ADT^A04^ADT_A01|12334456778890|P|2.5|||NE|NE|AU|ASCII|ENGLISH|||AN ORG|||RECNET.ORG"
describe "segment parsing" do
let(:segment_string) do
"MSH|^~\\&||ABCHS||AUSDHSV|20070101112951||ADT^A04^ADT_A01|12334456778890|P|2.5|||NE|NE|AU|ASCII|ENGLISH|||AN ORG|||RECNET.ORG"
end
let(:filled_msh) { HL7::Message::Segment::MSH.new(segment_string) }

it "allows access to an MSH segment" do
msh = HL7::Message::Segment::MSH.new @base
msh.enc_chars = '^~\\&'
expect(msh.version_id).to eq "2.5"
expect(msh.country_code).to eq "AU"
expect(msh.charset).to eq "ASCII"
expect(msh.sending_responsible_org).to eq "AN ORG"
expect(msh.receiving_network_address).to eq "RECNET.ORG"
it "allows access to an MSH segment's attributes by their getters" do
expect(filled_msh.enc_chars).to eq("^~\\&")
expect(filled_msh.sending_app).to eq("")
expect(filled_msh.sending_facility).to eq("ABCHS")
expect(filled_msh.recv_app).to eq("")
expect(filled_msh.recv_facility).to eq("AUSDHSV")
expect(filled_msh.time).to eq("20070101112951")
expect(filled_msh.security).to eq("")
expect(filled_msh.message_type).to eq("ADT^A04^ADT_A01")
expect(filled_msh.message_control_id).to eq("12334456778890")
expect(filled_msh.processing_id).to eq("P")
expect(filled_msh.version_id).to eq("2.5")
expect(filled_msh.seq).to eq("")
expect(filled_msh.continue_ptr).to eq("")
expect(filled_msh.accept_ack_type).to eq("NE")
expect(filled_msh.app_ack_type).to eq("NE")
expect(filled_msh.country_code).to eq("AU")
expect(filled_msh.charset).to eq("ASCII")
expect(filled_msh.principal_language_of_message).to eq("ENGLISH")
expect(filled_msh.alternate_character_set_handling_scheme).to eq("")
expect(filled_msh.message_profile_identifier).to eq("")
expect(filled_msh.sending_responsible_org).to eq("AN ORG")
expect(filled_msh.receiving_responsible_org).to eq("")
expect(filled_msh.sending_network_address).to eq("")
expect(filled_msh.receiving_network_address).to eq("RECNET.ORG")
end

it "allows creation of an MSH segment" do
msh = HL7::Message::Segment::MSH.new
msh.sending_facility = "A Facility"
expect(msh.sending_facility).to eq "A Facility"
msh.time = DateTime.iso8601("20010203T040506")
expect(msh.time).to eq "20010203040506"
it "allows access to an MSH segment's attributes by their index" do
expect(filled_msh[2]).to eq("^~\\&")
expect(filled_msh[3]).to eq("")
expect(filled_msh[4]).to eq("ABCHS")
expect(filled_msh[5]).to eq("")
expect(filled_msh[6]).to eq("AUSDHSV")
expect(filled_msh[7]).to eq("20070101112951")
expect(filled_msh[8]).to eq("")
expect(filled_msh[9]).to eq("ADT^A04^ADT_A01")
expect(filled_msh[10]).to eq("12334456778890")
expect(filled_msh[11]).to eq("P")
expect(filled_msh[12]).to eq("2.5")
expect(filled_msh[13]).to eq("")
expect(filled_msh[14]).to eq("")
expect(filled_msh[15]).to eq("NE")
expect(filled_msh[16]).to eq("NE")
expect(filled_msh[17]).to eq("AU")
expect(filled_msh[18]).to eq("ASCII")
expect(filled_msh[19]).to eq("ENGLISH")
expect(filled_msh[20]).to eq("")
expect(filled_msh[21]).to eq("")
expect(filled_msh[22]).to eq("AN ORG")
expect(filled_msh[23]).to eq("")
expect(filled_msh[24]).to eq("")
expect(filled_msh[25]).to eq("RECNET.ORG")
end
end

describe "segment creation" do
let(:msh) { HL7::Message::Segment::MSH.new }
let(:expected_msh_string) do
"MSH|^~\\&||ABCHS||AUSDHSV|20070101112951||ADT^A04^ADT_A01|12334456778890|P|2.5|||NE|NE|AU|ASCII|ENGLISH|||AN ORG|||RECNET.ORG"
end

before do
msh.enc_chars = "^~\\&"
msh.sending_app = ""
msh.sending_facility = "ABCHS"
msh.recv_app = ""
msh.recv_facility = "AUSDHSV"
msh.time = "20070101112951"
msh.security = ""
msh.message_type = "ADT^A04^ADT_A01"
msh.message_control_id = "12334456778890"
msh.processing_id = "P"
msh.version_id = "2.5"
msh.seq = ""
msh.continue_ptr = ""
msh.accept_ack_type = "NE"
msh.app_ack_type = "NE"
msh.country_code = "AU"
msh.charset = "ASCII"
msh.principal_language_of_message = "ENGLISH"
msh.alternate_character_set_handling_scheme = ""
msh.message_profile_identifier = ""
msh.sending_responsible_org = "AN ORG"
msh.receiving_responsible_org = ""
msh.sending_network_address = ""
msh.receiving_network_address = "RECNET.ORG"
end

it "serializes an MSH segment" do
expect(msh.to_s).to eq(expected_msh_string)
end
end
end