0

In regards to HL7 pipe-delimited data, how exactly do the encoding characters (|^~\&) work?

Is the following example of fields, field repetitions, components and their sub-components correct when parsing raw HL7 data?

PID|1||||||||||||1234567890^somedata&moredata^TESTEMAIL@GMAIL.COM~0987654321

Field (|): 
PID13 = 1234567890^somedata&moredata^TESTEMAIL@GMAIL.COM~0987654321

Field repetition (~): 
PID13~1 = 1234567890^somedata&moredata^TESTEMAIL@GMAIL.COM
PID13~2 = 0987654321 

Component (^):
PID13.1 = 1234567890
PID13.2 = somedata&moredata
PID13.3 = TESTEMAIL@GMAIL.COM

Sub-component (&):
PID13.2.1 = somedata
PID13.2.2 = moredata
PID13.3.1 = TESTEMAIL@GMAIL.COM
PID13.3.2 = 
Reynel
  • 43
  • 4
  • 2
    Would we agree with what? Is what the consensus? This question appears to be polling for opinions. –  Mar 19 '18 at 22:17
  • HL7 is considered a standard in the healthcare industry, and yet not everyone follows it to the T. My question is geared towards those with experience with the HL7 standard, where it is known that formats and data is handled differently across different systems. This is not just a matter of opinion, I'm simply asking what have others come across in regards to these separators. What seems to be "standard" for such characters. – Reynel Mar 20 '18 at 13:07
  • If every answer is equally valid, then this question is off-topic for Stack Overflow. [help/dont-ask] –  Mar 20 '18 at 13:12
  • That's not necessarily true though. Some answers would outweigh others based on use-case and frequency used. 90% of the industry might be following one way while 10% do not, that difference if it exists is significant. I believe there is only one standard protocol to follow with field separators but I've heard countering statements and am interested in seeing what the community thinks. – Reynel Mar 20 '18 at 13:28
  • @Amy and others that may have downvoted this question, please reconsider. HL7 is a very flexible format (unfortunately). This question is legit. In fact, everyone who has learned HL7 had to figure out the meanings of `|^~\&`. Technically, each message can pick different values for each of those, but in practice, those are the ones used by "all" HL7 messages in the wild. I'll try to provide an answer. – daveloyall May 30 '18 at 20:50
  • @Nick Hatt's answer is sufficient, thought I edited it a little to match the common syntax for addressing individual HL7 fields. – daveloyall May 30 '18 at 20:55
  • 1
    @daveloyall In light that the question was edited so it isn't polling for opinions, I've removed my downvote. My downvote was never about the question not being "legit". –  May 30 '18 at 21:22

1 Answers1

3

Without understanding the left-hand side structure you're trying to assign stuff to, it's impossible to tell you if you're doing it right.

There is however one right way to parse the segment/field in question.

Here's a link to the specs I reference here

From section 2.5.3 of the HL7v2.7 Standard:

Each field is assigned a data type that defines the value domain of the field – the possible values that it may take.

If you pull up section 3.4.2.13 (PID-13) you'll see a breakdown of each component and subcomponent. Technically, the meaning of subcomponents and components can vary by field, but mostly they just vary by data type.

In your example, you don't treat the repetitions as separate instances of XTN data types. I would re-write using array syntax as so:

Field repetition (~): 
PID13[0] = 1234567890^somedata&moredata^TESTEMAIL@GMAIL.COM
PID13[1] = 0987654321 

Component (^):
PID13[0].1 = 1234567890
PID13[0].2 = somedata&moredata
PID13[0].3 = TESTEMAIL@GMAIL.COM

Sub-component (&):
PID13[0].2.1 = somedata
PID13[0].2.2 = moredata

The psuedo-code in the same specification section 2.6.1 may be helpful as well

foreach occurrence in ( occurrences_of( field ) ) {
  construct_occurrence( occurrence );
  if not last ( populated occurrence ) insert repetition_separator;
    /* e.g., ~ */
}

It's important to remember that those different subcomponents have different meaning because PID-13 is a XTN type.

PID-13 is a problematic example because historically, the order of PID-13 mattered. The first repetition was "primary". Over time the field has also become the landing place for e-mail addresses, pager numbers, etc. So good luck trying to make sense out of real-world data.

Nick Hatt
  • 357
  • 1
  • 7
  • This is exactly what I needed, thank you! Left-hand structure I am assigning to in my example is simply for identification purposes, as in identifying each field/component/sub-components and field repeaters. However, your example is much clearer :) – Reynel Mar 21 '18 at 22:29