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

Why are three segments listed when only one is present in the original message? #29

Open
Stratus3D opened this issue Apr 28, 2014 · 1 comment
Labels

Comments

@Stratus3D
Copy link

For example, I have a normal HL7 message that contains one MSH segment at the beginning. When I parse the message msg[:MSH] is an array of three items.

f = open('example.hl7')
msg = HL7::Message.new(f)
msg[:MSH].class #=> Array
msg[:MSH].length #=> 3

Is there a reason this array contains three instances of HL7::Message::Segment::MSH? Is this a bug or is there a reason for this? I haven't spent a lot of time reading the code so I may be missing something here.

@gthiruva
Copy link

@Stratus3D A message is a collection of segments. In this case, that's msg. When you access msg[:MSH] you're selecting just one particular segment. So, when you calculate the length of just that one segment, you're getting a count of how many fields there are in the MSH segment.

For example, I'm looking at a result message from an immunization registry. So, it's a large message with 113 segments in it:

MSH|^~\&|CIR HL7 Web Service 2.01|NYC DOHMH|CAREDOX|0004Q10|20140529223528-0400||RSP^K11^RSP_K11|20140529223528-0400CIR-WS|T|2.5.1|||NE|NE|||||Z32^CDCPHINVS|
MSA|AA|hxe0P6tTzGBCqlIaWAcUBA|
QAK|QThxe0P6tTzGBCqlIaWAcUBA|OK|
QPD|Z34^Request ImmunizationHistory^HL70471|QThxe0P6tTzGBCqlIaWAcUBA||Mason^Matthew^Thomas^^^^L|Walters^Rebecca^^^^^M|20081025|M|305 BigApple Blvd&Big Apply Blvd&305^7C^NewYork^NY^12345-1234^^P|PRN^212^5551
PID|||777815087^^^^LR||MASON^MATTHEW^THOMAS^^^^L||20081015|M|
...

To count the segments, I apply the length method on the whole message:

[56] pry(main)> res.length
=> 113

And I get the expected 113 segments/lines. But if I select just the header segment, length() will count the number of vertical bar separated fields in :MSH:

[57] pry(main)> res[:MSH].length
=> 22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants