· Oct 27, 2021

How could we find inside PID a specific field?

First of all thanks for your help and time


We would need to find inside PID:3 which one meets the following condition:

PID 3.4.1 = "CAC" and PID 3.5 = "JHN"


We have been investigating how could we do it

We have achieved to get single fields in a call request as follows:




However, how would you recommend us to look for a specific field in PID meets a specific criteria?

How would you find inside PID if there are PID 3.4.1 = "CAC" and PID 3.5 = "JHN" and get its PID 3.1?


Also we have read:



Thanks for your time, and thanks for replying to this question

Discussion (2)1
Log in or sign up to continue

Hey Yone.

Assuming you're only using ObjectScript for this, then way to achieve this would be to take your HL7 as Enslib.HL7.Message, and then loop through the segments to pull out the PID segment, and then loop through PID:3 for a match.

For example:

//loop through HL7 and find PID Segment
set SegCount = request.SegCount
for i=1:1:SegCount{
    set segment = request.GetSegmentAt(i)
    if (segment.Name="PID"){
        //Loop through PID:3
        set numCnt = segment.GetValueAt("3(*)")
        for j=1:1:numCnt{
            set P341=segment.GetValueAt("3("_j_").4.1")
            set P5=segment.GetValueAt("3("_j_").5")
            if (P341="CAC")&&(P5="JHN") {
                $$$TRACE("Match found!")

Alternatively, you could create a DTL with the logic which you can from the ObjectScript, and then have the target in your DTL be something like a string container that you can then grab a result from. However that might be a bit clunky depending on your use case.