Sidebar

How can I get all of the components or sub-components from an HL7 message node?

0 votes
36 views
asked Jun 29 by ben-s-7515 (11,340 points)

I have a PID segment that looks like this:

PID|1|35707^^^ASD|661&&47984-0510001||Doe^John^||19480203|M|||123 A st^^Clovis^CA^93611||5592925960|5599775096|||||553703122||||||gprackup&Prackup&George|gprackup&Prackup&George^hwinston&Winston&Harry

How do I get all of hte PID-2 components, or the PID-3 subcomponents?  I need to loop them and process them 1 at a time.

1 Answer

0 votes

You can use a wildcard in the component or the sub-component position of the HPath.

NOTE: The wildcard is only available in QIE 5.0.51 or greater.

For example, to get all of the components from the PID-2 field, we can do the following:

var components = message.getAllNodes('PID-2.*');
for (var i = 0; i < components.length; i++) {
   qie.warn(components[i]);
}

The above script will output 4 log lines:
Log 1: 35707
Log 2: {blank}
Log 3: {blank}
Log 4: ASD

You can use a similar node path to get all of the sub-components, for this we will do the following:

var subComponents = message.getAllNodes('PID-3.1.*');
for (var i = 0; i < subComponents.length; i++) {
   qie.warn(subComponents[i]);
}

This script will output 3 log lines:
Log 1: 661
Log 2: {blank}
Log 3: 47984-1510001

NOTE: You cannot use a wildcard for the component and include a sub-component identifier, PID-3.*.1, as this will throw an exception.

answered Jun 29 by ben-s-7515 (11,340 points)
...