Search code examples
c#.net-corehl7hl7-dotnetcore

How to deal with a VARIES datatype using HL7-dotnetcore?


I want to create a HL7 MDM message and currently have to support v2.3 and v2.6. I want to add a Base64 document to the OBX segment. For version 2.6, I would simply do following:

Segment obxSegment = new Segment("OBX", hl7Encoding);
mdmMessage.AddNewSegment(obxSegment);

// Sequence Id
obxSegment.AddNewField("1", 1);

// Value Type
obxSegment.AddNewField("ED", 2);

// Observation Value
obxSegment.AddNewField("theBase64Document", 5);

But I've seen that version 2.3 requires a more complex setup with a VARIES datatype. I found some pseudo code using the nHapi package (which is not actively maintained anymore)

OBX obx = mdm_message.GetOBX();
obx.SetIDOBX.Value = "1";
obx.ValueType.Value = "ED"; // Encapsulated Data
Varies obx_value = obx.GetObservationValue(0);
ED data = new ED(mdm_message);
data.SourceApplication.NamespaceID.Value = "ID";
data.DataSubtype.Value = type;
data.Encoding.Value = "Base64";
data.Data.Value = file;
obx_value.Data = data;

Does someone know how to deal with such VARIES datatypes using the HL7-dotnetcore package? How would I create such a construct for the position OBX.5 to send a document with older message versions?


Solution

  • Apparently, HL7-dotnetcore does not support this.

    Please refer to the source code on github for AddNewField(Field field, int position = -1) method and the Field class. It does not appear that the datatype is handled there.

    I never used the toolkit, but what I understand is that, the toolkit does not support data types. Toolkit is not as complicated and matured as nHapi. It is simple and intended to be simple. At the end of the day, HL7 message is a string.

    Considering this, you should be able to set the value same way you are doing for other version like below:

    obxSegment.AddNewField("theBase64Document", 5);
    

    This should parse the message correctly.