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

Answers

If your PID:3 is not defined in your schema as a repeating field, you can obtain a $LIST with:

JEFF > Set tLst = $LISTFROMSTRING(msg.GetValueAt("PID:3"),"^")

JEFF > w $LISTGET(tLst,1)

043622

JEFF > zw tLst

tLst=$lb("043622","","","ZZMC","MR","ZZMC")

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

Comments

$LENGTH(pRequest.GetValueAt("PID:3") please note this does not give me list length rather it take the PID as a string and give me the length of the string I need to able to extract the individual values in  the segment that's the length I need