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;

Add comment

Security code

Share this post
FaceBook  Twitter  


Latest comments