Efferent-Health/HL7-dotnetcore

GetValue and \"\"

Closed this issue · 3 comments

ghust commented

Hi guys,

I'm currently working on an implementation and I'm trying to apply HL7 logic following:;

  • If the value of a field is empty, do nothing with the property
  • If the value of the field is two quotes, clear the property
  • If the value of the field is something else, set the property to the value.

I see that the GetValue doesn't apply this logic, and I'm either wondering how we could fix this or if there's another way to get the desired outcome :)

This is a unit test that demonstrates the behavior:

    public void GetValueShouldReturnQuotesInsteadOfNull()
    {
        // Arrange
        Message message = new Message();
        
        Segment segment = new Segment("OBR", new HL7Encoding());
        segment.AddNewField("\"\"", 1);
        message.AddNewSegment(segment);

        // Act
        var resultingstring = message.GetValue("OBR.1");

        // Assert
        
        Assert.AreEqual("\"\"", resultingstring);
    }
ghust commented

Adding to this:

MessageElement.cs : 12

return _value == Encoding.PresentButNull ? null : _value;

This makes sure that there isn't a way to differentiate between HL7 null and an empty segment, or am I mistaken?

I think this is related to this:

nHapiNET/nHapi#414

Hi @ghust,

If this behavior is not desirable, it can be disabled by setting Encoding.PresentButNull to null before parsing:

var message = new Message(msg);
message.Encoding.PresentButNull = null;
message.ParseMessage();