Question
· Apr 20, 2017

Example DTL to extract a base64 encoded file(pdf) from an MDM^T02 OBX segment

Hi,

Can anyone  point me to an example of a DTL & Class method that can pull a base64 encoded PDF out of a MDMT02 message?

This is really asking for two things;

- how to make a DTL that extracts a specific subfield of an HL7 2.3 message into a message of its own,

and

- how to transform an base64 encoded document into its original binary form for writing to a file.

I'd also love to see an example of an HL7 2.n MDM^T02 ==> HL73.ITK2 non-coded CDA

I've seen some snippets in the community Q&A, but I've not been able to find any examples either here, or in the documentation or training materials. 

MSH|^~\&|SystemSystem|XX|||20170315124942.0128||MDM^T02^MDM_T02|123456789||2.4
PID|1||1234567^^^MRN^MRN||Ming^Sample^^^MR||19700104000000.0000|M|||^18 Whitethorn Way^HULL^^HU8 0JF|||||||||||||||||||N
TXA||^Standard||||20170315134920|||t.tester^Test Tester|||1|c05f4f16-c886-42a0-b783-cecbe6a2e4fb|||||||||t.tester&Test Tester^20170315134938
OBX||ED|||^^Pdf^Base64^XXX|||N

Kind regards

Stephen

Discussion (3)2
Log in or sign up to continue

This is what I would do.

Create a custom process and extract the value using GetValueAt and put it into a string container. String containers are handy Ens.Request messages that you can use to move a strings around without needing to create a custom Ens.Request message. Then just send it async to an operation that will decode the base64 and write it to a file. Two lines of code, nice and simple...

Class My.DocExtractor Extends Ens.BusinessProcess [ ClassType = persistent ]
{

Method OnRequest(pRequest As Ens.Request, Output pResponse As Ens.Response) As %Status
{
    Set msg=##class(Ens.StringContainer).%New(pRequest.GetValueAt("OBX(1):5.5"))
    Quit ..SendRequestAsync("FILE OUT",msg,,"Send DOC as Base64 to a file writer")
}

}


To decode the base64 use this method inside your operation.

set decodedString=##class(%SYSTEM.Encryption).Base64Decode(pRequest.StringValue)


Things to consider...

1. You mention the message is 2.3, but the MSH has a 2.4
2. If you set your inbound service to use either of the default schemas for these two then you will have a problem with required EVN and PV1 segments
3. Therefore you will need to create a custom schema and make these optional.
4. The base 64 decode method is limited to a string, so your PDF documents can not be greater than 3.6MB (assuming large string support is on be default).
5. You probably don't want to decode the document into another message too soon, do this just before writing to a file

T02 to ITK should just be a matter of creating a new transform and dragging the OBX(1):5.5 field onto the reflective target field.

I remember the encode / decode limitation was 3.6MB not 1MB, I corrected my original message.

Having built several EDT document solutions in Ensemble (sending thousands of documents a day) I have not had to code around this limitation.

But if you have documents that are bigger then take a look at GetFieldStreamBase64() on the orignal HL7 message. I've not used it, but should be fairly simple to figure out. In which case you can use an Ens.StreamContainer to move the message.

Thinking about it, there is an even simple solution, just send the HL7 message "as is" to the operation and do the extract and decode at the last second.