Reading OBX observation values using NHapi

The observation values in HL7 messages can contain different HL7 types. NHapi uses the Varies class to read these values. In the following example I'll show how to use this Varies class to obtain the values it contains.

The example uses a SIU_12 message.

// Loop through all the patient records in the SUI_12 message
for (int i = 0; i < message.PATIENTRepetitionsUsed; i++)
{
    SIU_S12_PATIENT patient = message.GetPATIENT(i);

    // There can be multiple OBX records in the message
    for (int y = 0; y < patient.OBXRepetitionsUsed; y++)
    {
        OBX obx = patient.GetOBX(y);

        // If needed, filter int the ID of the OBX field
        if (obx.ObservationIdentifier.Identifier.Value == "someID")
        {
            for (int z = 0; z < obx.ObservationValueRepetitionsUsed; z++)
            {
                // The observation value can contain multiple types, in this example
                // we assume that the type CE is used in the observation value
                NHapi.Base.Model.Varies varies = obx.GetObservationValue(z);
                NHapi.Model.V23.Datatype.CE ce = varies.Data as NHapi.Model.V23.Datatype.CE;

                // If the cast was successfull, read the values needed
                if (ce != null)
                {
                    string result;
                    result = ce.AlternateText.Value;
                }
            }
        }
    }
}

Comments  

+1 # Bharat 2014-10-17 08:21
Thanks.
Reply | Report to administrator
0 # James Bateman 2014-11-26 20:05
Bas,

I am using your code (above) except that I am using an ST data value verses CE. I have 21 repeating elements in the OBX5 field of my test message. The code (above) correctly identifies the first repeating element as ST. However, it does not cast the remaining elements as ST. When I look at the "watch" values, it identifies them as "unknown". Any ideas ?

My code is below.

As always, I appreciate your input.

James

NHapi.Model.V23.Message.MDM_T02 mdmMsg = msg as NHapi.Model.V23 .Message.MDM_T0 2;


for (int y = 0; y < mdmMsg.OBXRepet itionsUsed; y++)
{

NHapi.Model.V23 .Segment.OBX obx = mdmMsg.GetOBX(y );

for (int z = 0; z < obx.Observation ValueRepetition sUsed; z++)
{

NHapi.Base.Mode l.Varies varies = obx.GetObservat ionValue(z);
NHapi.Model.V23 .Datatype.ST st = varies.Data as NHapi.Model.V23 .Datatype.ST;


// If the cast was successfull, read the values needed
if (st != null)
{
string result;
result = st.ToString();
}
}
Reply | Report to administrator
0 # James Bateman 2014-11-26 20:57
After my last post, I found this.

corengen.wordpress.com/.../...
Reply | Report to administrator
0 # Bas 2014-11-26 21:37
Hi James!

Good you've found the problem! Too bad it is a bug. Guess you've got to download the forked source code to fixed this. Hopefully the NHapi team will copy this fix soon into the master source code.

Bas
Reply | Report to administrator
0 # James Bateman 2014-11-27 03:15
The forked source code worked.

James
Reply | Report to administrator

Add comment


Security code
Refresh

Share this post
FaceBook  Twitter  

Archives

Latest comments