· Sep 6, 2019

Replace Non ASCII Character with value

Hi All


I am writing a class to take a general HL7 replace the non ASCII characters in all the segments to construct another message.  I have the following solution working to an extent however it is inserting \r at the end of the segments that have been transformed.  Firstly is this the correct approach and secondly how do I get rid of \r at the end of the segment that is affected?

Thank you for your help.

ClassMethod Transform(source As EnsLib.HL7.Message, Output target As EnsLib.HL7.Message) As %Status

Set $ZT="Trap",tSC=$$$OK
Do {

Try {

#Dim tMSHin As EnsLib.HL7.Segment
#Dim tSegIn As EnsLib.HL7.Segment
#Dim tSegOut As EnsLib.HL7.Segment
#Dim tmp As EnsLib.HL7.Segment
#Dim tSegString as %String

#Dim NonASCIIChar as %String="©"
#Dim ASCIIChar as %String="(c)"

Set target = ##class(EnsLib.HL7.Message).%New()
Set:source.DocType'="" target.DocType=source.DocType
Set tMSHin = source.GetSegmentAt(1, .tSC)

For = 1:1:tMSHin.Count
Set tSC = target.SetValueAt(tMSHin.GetValueAt(i),"1:"_i)

//get the data lookup characters
//check each segment for each of the character

For = 2:1:source.SegCount 
Set tSegIn = source.GetSegmentAt(i,.tSC)
Set tSegOut = tSegIn.%ConstructClone()

//get all the fields within the segment
set tIndex =0
while $FIND(tSegIn.OutputToString(),"©",tIndex) > 0 {
    set mystr =$Replace(tSegIn.OutputToString(),"©","(C)")
    set tSegOut =##class(EnsLib.HL7.Segment).ImportFromString(mystr,.tSC)
    do tSegIn.SetValueAt(tSegOut,i)
   set tIndex = $FIND(tSegIn.OutputToString(),"©",tIndex)+1
   set tSC = target.AppendSegment(tSegOut)


Catch ex 
Set tSC = ex.AsStatus()


while (0)
Quit tSC
Set $ZT="",tSC=$$$EnsSystemError
Goto Exit


Kind Regards,



Discussion (1)0
Log in or sign up to continue