1. I would stay away from Modifying the current EnsLib.HL7.SearchTable if at all necessary. Modifying the source code could lead to consequences down the road, especially when you upgrade it might get overwritten. What I did was that I copied the existing code and modified it for our use. That way we can add and remove fields anytime we want.

Class osuwmc.HL7SearchTable Extends (%Persistent, Ens.VDoc.SearchTable) [ ClassType = persistent, CompileAfter = EnsLib.HL7.Message, Inheritance = right, ProcedureBlock, System = 4 ]

{

Parameter DOCCLASS = "EnsLib.HL7.Message";

Parameter EXTENTSIZE = 4000000;

/* Re-declare indices because the superclass is abstract */

Index indexValue On (PropId, PropValue, DocId) [ IdKey, Unique ];

Index indexDocId On (DocId, PropId, PropValue) [ Unique ];

XData SearchSpec [ XMLNamespace = "http://www.intersystems.com/EnsSearchTable" ]

{

<Items>

<Item DocType=""  PropName="MSHTypeName" Unselective="true">{1:9.1}_"_"_{1:9.2}</Item>

<Item DocType=""  PropName="MSHControlID" PropType='String:CaseSensitive' >{1:10}</Item>

<Item DocType=""  PropName="PatientID"   >[PID:2.1]</Item>

<Item DocType=""  PropName="PatientID"   >[PID:3().1]</Item>

<Item DocType=""  PropName="PatientID"   >[PID:4().1]</Item>

<Item DocType=""  PropName="PatientName" >[PID:5()]</Item>

<Item DocType=""  PropName="PatientAcct" >[PID:18.1]</Item>

<Item DocType=""  PropName="Order#"      >[ORC:2.1]</Item>

<Item DocType=""  PropName="Order#"      >[SCH:26.1]</Item>

<Item DocType=""  PropName="Order#"      >[ZOR:1]</Item>

<Item DocType=""  PropName="Accession#"  >[ORC:3.1]</Item>

<Item DocType=""  PropName="SIUVisitType">[AIS():3.1]</Item>

<Item DocType=""  PropName="SIUProvider#">[AIP():3.1]</Item>

</Items>

}

Storage Default

{

<Data name="HL7SearchTableDefaultData">

<Value name="1">

<Value>%%CLASSNAME</Value>

</Value>

</Data>

<DataLocation>^osuwmc.HL7SearchTableD</DataLocation>

<DefaultData>HL7SearchTableDefaultData</DefaultData>

<ExtentSize>4000000</ExtentSize>

<IdLocation>^osuwmc.HL7SearchTableD</IdLocation>

<IndexLocation>^osuwmc.HL7SearchTableI</IndexLocation>

<StreamLocation>^osuwmc.HL7SearchTableS</StreamLocation>

<Type>%Library.CacheStorage</Type>

}

}

I do something similar to what you are trying to do, I Decode the PDF, save the PDF locally, and return a path to the DTL.

Several on the developer community helped me figure this out...

ClassMethod DecodeBase64HL7ToFile(base64 As %Stream.GlobalBinary, Ancillary As %String, FileName As %String) As %String

{

    set ArchDir = "/ensemble/data/transfer/AncillaryPDF/"

    set ArchAncDir = ArchDir_Ancillary_"/"

    set FaxDateDir = ArchAncDir_$PIECE($ZDATE($HOROLOG,7)," ",1)_"-"_$PIECE($ZDATE($HOROLOG,7)," ",2)_"-1/"

    if '##class(%Library.File).DirectoryExists(ArchDir)

    {

        do ##class(%Library.File).CreateDirectory(ArchDir)

    }

    if '##class(%Library.File).DirectoryExists(ArchAncDir)

    {

        do ##class(%Library.File).CreateDirectory(ArchAncDir)

    }

    if '##class(%Library.File).DirectoryExists(FaxDateDir)

    {

        do ##class(%Library.File).CreateDirectory(FaxDateDir)

    }

    

    

    set Oref = ##class(%FileBinaryStream).%New()

    ///$$$LOGINFO(FaxDateDir_FileName)

    set Oref.Filename = FaxDateDir_FileName

    Do base64.Rewind()

    While 'base64.AtEnd {

        set ln = base64.ReadLine()

        set lnDecoded = $system.Encryption.Base64Decode(ln)

        do Oref.Write(lnDecoded)

    }

    Do Oref.%Save()

    set PDFFilePath = FaxDateDir_FileName

    return PDFFilePath

}

We have used Length many times in Routing rules to check to see if Admit/Discharge date exists. We haven't quite used HL7.{PV1:45} to get the field, we let the system spell it out for us... so instead of HL7.{PV1:45} we allow the system to put it in the nomenclature that it knows the field as.. in this case HL7.{PV1:AdmitDateTime.Time}

I figured it out on my own. 

It did not like

<assign value='source.GetFieldStreamRaw(.tStream,"ORCgrp(1).OBRgrp(1).OBXgrp(k1).OBX:ObservationValue(1).AlternateText}",tRemainder)' property='tSC' action='set' />
 

I had to change it to 

<assign value='source.GetFieldStreamRaw(.tStream,"ORCgrp(1).OBRgrp(1).OBXgrp("_k1_").OBX:5.5",.tRemainder)property='tSC' action='set' />

With a little help I have built the following Method to Decode and save off the Encoded pdf but return me the directory that I saved the PDF under....

ClassMethod DecodeBase64HL7ToFile(base64 As %Stream.GlobalBinary, Ancillary As %String, FileName As %String) As %String
{
set ArchDir = "/ensemble/data/transfer/AncillaryPDF/"
set ArchAncDir = ArchDir_Ancillary_"/"
set FaxDateDir = ArchAncDir_$PIECE($ZDATE($HOROLOG,7)," ",1)_"-"_$PIECE($ZDATE($HOROLOG,7)," ",2)_"-1/"
if '##class(%Library.File).DirectoryExists(ArchDir)
{
do ##class(%Library.File).CreateDirectory(ArchDir)
 
}
if '##class(%Library.File).DirectoryExists(ArchAncDir)
{
do ##class(%Library.File).CreateDirectory(ArchAncDir)
 
}
if '##class(%Library.File).DirectoryExists(FaxDateDir)
{
do ##class(%Library.File).CreateDirectory(FaxDateDir)
 
}


set Oref = ##class(%FileBinaryStream).%New()
///$$$LOGINFO(FaxDateDir_FileName)
set Oref.Filename = FaxDateDir_FileName
Do base64.Rewind()

While 'base64.AtEnd {
     set ln = base64.ReadLine()
    set lnDecoded = $system.Encryption.Base64Decode(ln)
do Oref.Write(lnDecoded)
}

Do Oref.%Save()
set PDFFilePath = FaxDateDir_FileName
return PDFFilePath
}