Efferent-Health/HL7-dotnetcore

How to deal with a VARIES datatype?

Closed this issue · 1 comments

I want to create a 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:

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;

How to deal with such VARIES datatypes? How would I create such a construct for the position OBX.5 to send a document with older message versions?

Hi @olaf-svenson
This library doesn't make any special handling with base64 values. All values are considered strings. If you want to introduce a base64-encoded data into a message, just encode your data as usual, and use it as a regular string.
You can generate the string value with the following snippet

byte[] data = File.ReadAllBytes(filename);   // file containing the binary data
string hl7Value = Convert.ToBase64String(data);  // encode it as a base64-string
message.SetValue(field_locator, hl7Value);  // see SetValue() examples in README