· Dec 2, 2021

Is this approach to renaming an output file bad practice, and if so, why?

Hi all, 

I'm trying to output a XML file, mapped from a ORU_R01 2.3 HL7 message, with a file name based of fields in the source HL7 message in the following format, 


To give something like RXR0000000-000000123-20211125105415.xml as the output filename,

I initially tried to extend the EnsLib.XML.Object.Operation.FileOperation class and overwrite the OnMessage() method to allow me to specify the filename but I wasn't able to get that to work with my limited ObjectScript knowledge.

Class ELHTPRODPKG.Operations.XMLFIleOutput.CHC Extends EnsLib.XML.Object.Operation.FileOperation
    Parameter ADAPTER = "EnsLib.File.OutboundAdapter";
    Parameter SETTINGS As %String = "-Filename:Basic";                    // Remove option from UI for this class
    Property Filename As %String(MAXLEN = 1000, MINLEN = 1) [ Required ]; // Removed Initial Expression 
    Method OnMessage(pRequest As %Persistent, Output pResponse As %Persistent) As %Status
        // Create output filename using the class name of the persistent class as the base.
        Set tFilename= "InternalID"_"VisitID"_"EventTimeStamp"_".xml"  
        // Charset processing is done by %XML.Writer.  Disable Charset property of the Adapter.
        Set tCharset=..Adapter.Charset
        Set ..Adapter.Charset=""
        // Output XML document to stream
        Set tSC=..standardOnMessage(pRequest,.tStream)
        // Use the adapter to output the stream
        If $$$ISOK(tSC) 
            Set tSC=..Adapter.PutStream(tFilename,tStream)
        // Restore the adapter Charset
        Set ..Adapter.Charset=tCharset
        $$$sysTRACE("After "_$S(..Adapter.Overwrite:"storing",1:"appending")_" XML document "_pRequest_"/"_pRequest.%Id()_" to file "_tFilename)
        Quit tSC

My plan for that was to add varFilename as %String to the OnMessage() parameters and modify the EnsLib.EDI.XML.Document class to pass the varFilename from the conversion DTL but I wasn't sure if that was the right approach or if that is possible. I wasn't able to get the filename to be overwritten with the test namein the code above either, "InternalIDVisitIDEventTimeStamp.xml"  , instead I was getting names like  "5@EnsLib.EDI.XML.Document.xml_2021-12-02_11.17.51" which I couldn't seem to change.

So instead I've used the OutputToFile() method of EnsLib.EDI.XML.Document in the DTL to do target.OutputToFile("F:\TestDirectories\TestMessageArchive\XML\Out\"_varFilename_".xml")
Which gives me the result I was looking for, then I "discard" the message since it's no longer needed by passing the message back into the rule like this:

To get to the point my question is, Is there anything wrong with this approach?

Specifically I was wondering what implications it might have for logging / error handling / performance, etc, as the message never goes out through an Operation and instead is just discarded despite having the desired file correctly rendered in the correct directory,

I'm quite new to HealthShare and ObjectScript so I'm looking to develop my understanding and implement integrations following best practice so any feedback is appreciated, 


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

I don't have a request of type EnsLib.EDI.XML.Document handy to test, but I do know that setting the Source property of the request (for an HL7 message, at least) to the desired filename will enable you to use the %f formatting token to obtain the Source contents as the filename. This should theoretically allow you to use the unmodified EnsLib.EDI.XML.Operation.FileOperation class ...