How To Set OBX ObservationValue (RP) Value With Special Characters #666
-
Hi! public void CreateOBXSegment(HL7Request request)
{
var obx = _hl7Message.GetORDER().ORDER_DETAIL.AddOBSERVATION().OBX;
obx.SetIDOBX.Value = request.OBXID;
obx.ValueType.Value = request.OBXValueType;
obx.ObservationIdentifier.Identifier.Value = request.OBXObservationIdentifier;
// Set the observation value based on the value type
IType observationValue = null;
switch (request.OBXValueType)
{
case "ST": // String Data
observationValue = new ST(_hl7Message);
((ST)observationValue).Value = request.OBXObservationValue;
break;
case "NM": // Numeric
observationValue = new NM(_hl7Message);
((NM)observationValue).Value = request.OBXObservationValue;
break;
case "CE": // Coded Element
observationValue = new CE(_hl7Message);
((CE)observationValue).Identifier.Value = request.OBXObservationValue;
break;
case "RP": // Reference Pointer
observationValue = new RP(_hl7Message);
((RP)observationValue).Pointer.Value = request.OBXObservationValue;
break;
// Add more cases as needed for other data types
default:
observationValue = new ST(_hl7Message);
((ST)observationValue).Value = request.OBXObservationValue;
break;
}
obx.GetObservationValue(0).Data = observationValue;
obx.ObservationResultStatus.Value = request.OBXObservationResultStatus;
}
but when I parse the IMessage object to write it to file the '&' character is being replaced with '\T' and results in the following output:
What can I do to fix this? Or how can I unescape the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Can you provide example code where you are writing to a file? |
Beta Was this translation helpful? Give feedback.
-
Hi. Sorry for the late reply. I'm writing the message object to file using the method below: public override bool Send(string RefNo, IMessage msg)
{
try
{
string path = outputDir + GetFileName(RefNo, msg);
//using (StreamWriter sw = new StreamWriter(File.OpenWrite(path), System.Text.Encoding.ASCII))
using (StreamWriter sw = new StreamWriter(File.OpenWrite(path)))
{
PipeParser parser = new PipeParser();
string encodedMessage = parser.Encode(msg);
sw.Write(encodedMessage);
//sw.Write(parser.Encode(msg));
}
}
catch (IOException)
{
return false;
}
return true;
} |
Beta Was this translation helpful? Give feedback.
@amzinyama what you are seeing in your file is normal, the encoder is escaping special characters, when the message is decoded again the escaping is unescaped again.
https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=EHL72_escape_sequences