Sidebar

With an HL7 message, can I get a list of all segments used?

0 votes
1.1K views
asked Mar 11, 2019 by lewis-s-9714 (1,020 points)
I'm working with HL7 messages and I'm trying to get a full list of segments used to sample them and get an idea which mappings will be needed. I want to avoid creating a mapping for every possible segment in every version of HL7 (or looking through them all manually). I see in the reference manual that designating a segment is required unless using the root node, but the root node contains the entire message, not just the segment headers. Can I pull out just a list of segment headers (e.g. MSH, PID, PD1, etc.)?
commented Mar 11, 2019 by lewis-s-9714 (1,020 points)
edited Mar 11, 2019 by lewis-s-9714
-Deleted- Something else was happening with the code previously commented here.

2 Answers

0 votes
 
Best answer

Answering my own question (I'm not as lost as I thought I would be), I found that getting the root node returns an array with an element for each line of the message. I iterated through the array and concatenated the first 3 characters of each line (since all of the segment headers are 3 characters long) and separated the strings with a comma to make it easier to read.

var strList = '';
var hl7Segments = source.getAllNodes('/');
for (var iter = 0; iter < hl7Segments.length; iter++){
   strList+=hl7Segments[iter].substring(0,3)+',';
}
strList = strList.length>0?StringUtils.stripEnd(strList, ','):'';
answered Mar 11, 2019 by lewis-s-9714 (1,020 points)
selected Mar 11, 2019 by lewis-s-9714
0 votes

You can see a list of the segments if you add it as a sample message. Here are the steps:

1. Add as a sample message

2. Create a standard mapping and open the node lookup

3. Expand the Segments

answered Mar 11, 2019 by brandon-w-8204 (33,270 points)
commented Mar 11, 2019 by lewis-s-9714 (1,020 points)
Thank you for your answer! However, the part I didn't mention in the question is that I'm trying to get a large sampling that I can import into SQL Server and do queries on so I can see all of the combinations of headers used by different sources.
...