Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing bug that prevented access all instances of a repeating segment. Added a helper method on Segment to query if it's empty? #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
8 changes: 6 additions & 2 deletions lib/simple_hl7/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def method_missing(meth, *args, &block)
if meth.to_s =~ /^[a-zA-Z][a-zA-Z0-9]{2}$/
get_named_segment(meth)
elsif meth.to_s =~ /^[a-zA-Z][a-zA-Z0-9]{2}_all$/
seg_name = meth[0..3]
seg_name = meth[0...3]
all_segments(seg_name)
else
super
Expand Down Expand Up @@ -83,10 +83,14 @@ def append_segment(segment)
segment
end

def has_segment?(name)
@segments.any?{|segment| segment.name == name.upcase}
end

private

def all_segments(name)
@segments.select {|seg| seg.name == name}
@segments.select {|seg| seg.name == name.upcase}
end


Expand Down
4 changes: 4 additions & 0 deletions lib/simple_hl7/segment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ def name
def to_a
super.insert(0, name)
end

def empty?
@subcomposites.keys.size == 1
end
end
end
13 changes: 13 additions & 0 deletions spec/simple_hl7/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,22 @@ module SimpleHL7
msg.msh[6].to_s.should == "accountid"
msg.pid[5].to_s.should == "User"
msg.pid[5][2].to_s.should == "Test"
msg.has_segment?("al1").should be_falsey
end

end

describe "repeating segments accessed by calling method with segment name followed by '_all' e.g. al1_all for allergy segments" do
it "provides access to repeating segments" do
hl7_msg = File.read("#{File.expand_path File.dirname(__FILE__)}/sample_message_with_repeating_segments.hl7")
msg = Message.parse(hl7_msg, segment_separator: "\n")
msg.al1_all.size.should == 3
msg.al1_all[1][3][2].to_s.match(/Nitrostat/).should be_truthy
msg.al1_all[2][3][2].to_s.match(/iodine/).should be_truthy
msg.al1[3][2].to_s.match(/nitroglycerin/).should be_truthy
end
end

describe "#parse_llp" do
it "properly parses a llp string" do
msg = Message.parse_llp("\x0bMSH|^~\\&||||accountid\rPID|||||User^Test~Repeat\x1c\r")
Expand Down
16 changes: 16 additions & 0 deletions spec/simple_hl7/sample_message_with_repeating_segments.hl7
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
MSH|^~\&|HNAM|MCH|CARINGLY|CARINGLY|20211201142018||ADT^A08|Q246327519T316598917X0|P|2.3||||||8859/1
EVN|A08|20211201142017|||1^SYSTEM^SYSTEM^^^^^^PERSONNEL PRIMARY IDENTIFIER^Personnel^^^Personnel Primary Identifier~CERNSYSTEM^SYSTEM^SYSTEM^^^^^^External Id^Personnel^^^External Identifier
PID|1|306845^^^MLKCH MRN^MRN|306845^^^MLKCH MRN^MRN~X0000100275^^^Community MRN^Community MRN|^0^^CONSUMER_MESSAGING^Messaging|ZZZTEST^EDUSACS^^^^^Current||19700319|Male||American Indian or Alaska Native|48 none^^New Baltimore^MI^48047^US^Home^^[email protected]^^^^^^E-mail||(999)988-8888^Home^Tel||English|Unknown||907735^^^MLKCH FIN^FIN NBR|||||||0
PD1|||||||No, info not provided
NK1|1|TESTING^AUUNT^^^^^Current|||(586)544-4444^Home^Tel||Emergency Contact
NK1|2|TESTING^AUUNT^^^^^Current|||(586)544-4444^Home^Tel||Support Person
PV1|1|Emergency|ED^ED16^A^MLK^^Bed(s)^MLK|Emergency|||1619954633^Brown^Eric^^MD^Physician^^^NPI^Personnel^^^National Provider Identifier~FB6005450^Brown^Eric^^MD^Physician^^^DEA^Personnel^^^DOCDEA~A72839^Brown^Eric^^MD^Physician^^^Provider State License Number^Personnel^^^LICENSENBR~EGO^Brown^Eric^^MD^Physician^^^Billing Group^Personnel^^^OTHER~6050081358012^Brown^Eric^^MD^Physician^^^SureScripts Prescriber Index^Personnel^^^SureScripts Prescriber Index||2754578955^MLKCHTest^Physician Primary Care^^^^^^NPI^Personnel^^^National Provider Identifier~PHYSPRIMCARE01^MLKCHTest^Physician Primary Care^^^^^^PROVIDER_MESSAGING^Personnel^^^Messaging|Emergency Medicine||||Clinic Referral|||1619954633^Brown^Eric^^MD^Physician^^^NPI^Personnel^^^National Provider Identifier~FB6005450^Brown^Eric^^MD^Physician^^^DEA^Personnel^^^DOCDEA~A72839^Brown^Eric^^MD^Physician^^^Provider State License Number^Personnel^^^LICENSENBR~EGO^Brown^Eric^^MD^Physician^^^Billing Group^Personnel^^^OTHER~6050081358012^Brown^Eric^^MD^Physician^^^SureScripts Prescriber Index^Personnel^^^SureScripts Prescriber Index|Emergency||Self Pay|||||||||||||||||||MLK||Active|||20210706065235||||||||6914424^Pierce^Troy^^^^^Other~DCHAVIRA^Chavira^Daniel^^^^^PRIMARY_CONTACT
PV2|||^pain|||||||0|||||||||||Yes||^^589723|||||||Not Started
DG1|1|ICD10-CM|I10|Hypertension|20211201122500|Discharge|||||||||1
GT1|1|306845^^^MLKCH MRN^MRN~100275^^^Community MRN^Community MRN~100275^^^Community MRN^Community MRN~306845^^^MLKCH MRN^MRN|ZZZTEST^EDUSACS^^^^^Current||48 none^^New Baltimore^MI^48047^US^Home^^[email protected]^^^^^^E-mail|(999)988-8888^Home^Tel||19700319|Male|Default Guarantor|SELF|||||Unknown||||Unknown|||||||||605846
IN1|1|1607851^SELF PAY^^^SELF PAY|1455518|Self Pay|TBD^^^^^US^Business||(000)000-0000^Business^^^^^^0|||605846|Unknown|20210706000000|<maximum>||Self|ZZZTEST^EDUSACS^^^^^Current|SELF|19700319|48 none^^New Baltimore^MI^48047^US^Home^^[email protected]^^^^^^E-mail|Yes||1|||||||||||||Self Pay|||||||Unknown|Male
IN2|||^Unknown||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||(999)988-8888^Home^Tel|(000)000-0000||||||||SELF
AL1|1|Drug|d00321^nitroglycerin^Multum Drug|Severe
AL1|2|Drug|d00321^Nitrostat^Multum Drug|Severe
NTE|1||pt states experiences difficulty breathing with nitrostat (doesn't tolerate NGT ointment, PO spray either)
AL1|3|Drug|402^contrast media (iodine-based)^Multum Allergy [email protected]:daya/simple_hl7.gitory|Moderate|Itching