Question
· Feb 8, 2019

How to get the length of A Segment In HL7

I am trying to get the values of a PID:3 segment to an  array but I will need to know the length of the segment to process .

set o = ##class(EnsLib.HL7.Message).%OpenId(458)

w o.GetValueAt("PID:3")

w o.GetValueAt("PID:3").SegCount  This throws an error any help appreciated

Discussion (4)3
Log in or sign up to continue

Are you looking for the number of repetitions/components, or the string length for the PID:3 field?

To get the number of repetitions:

JEFF > w msg.GetValueAt("PID:3(*)")

2

To get the number of components in the first repetition:

JEFF > w msg.GetValueAt("PID:3(1).*")

6

To get the string length of the entire field:

JEFF > w $LENGTH(msg.GetValueAt("PID:3"))

46

Hi Thembalani,

The property SegCount will only show you on the message level how many "lines" the message has. Ex (MSH,PID,PV1) = 3

If you want the individual pieces in the message you will have to first get to the segment correctly, this is dependent on the version of HL7 you're using. My exampe is from 2.6

>w o.GetValueAt("PIDgrpgrp(1).PIDgrp.PID:PatientIdentifierList()")
6107145310089^^^^NNZAF
 

You can then piece it out on "^"

>w $L(o.GetValueAt("PIDgrpgrp(1).PIDgrp.PID:PatientIdentifierList()"),"^")
5
 

Hope this helps