<DaveL>
When a message arrives with file and batch headers, you can process it
in a number of different ways. The most common are to either select the
BatchHandling setting as "Individual" or "WholeBatch".
The former passes on the message without any headers as separate HL7
messages. It sounds as if you want "WholeBatch" so the message is passed
to the routing engine as a single batch.
The problem then comes with the Data Transformation. You have probably
defined one graphically with the DTL editor but you can't apply that
directly to your batch, you have to do a little extra work.
If the BS receives a batch (FHS, BHS etc.) it will create an outer HL7
Message for the FHS. This will have one or more child Messages for the
BHS groups and each will normally have many child objects for the
payload of the batch.
If you look at the message content in the message browser you can click
through and see each.
In your case, you need a data transformation that navigates through the
batch headers and calls the appropriate DTL for each of the 'real' HL7
messages.
Below is a sample of code I put together recently to do exactly that. As
always this is just a sample that you can use for education. It creates
a new batch and copies the values of the headers and trailers from the
source.
Almost identical code works for X12 batches.
Also, you can add a condition to decide which DTL to invoke based on the
document type, so you can use this batch transform as a general
mechanism for many batches.
I haven't bothered with any of the total fields in the trailer segments
but that should be easy enough to figure out.
<beware of linefeeds added by email>
Dave
///
Class HL7DEMO.BatchTransform Extends Ens.DataTransform [ ProcedureBlock
]
{
ClassMethod Transform(source As EnsLib.HL7.Message, ByRef target As
EnsLib.HL7.Message) As %Status
{
Set $ZT="Trap",tSC=$$$OK
do {
//this sample code makes no attempt at error checking and
assumes that every batch has exactly
//three segments and only one child
set target=##class(EnsLib.HL7.Message).%New()
set tSC=target.CopyValues(source,1,1,"set","")
set target.DocType=source.DocType
//we need to save the parent, because the parent id is
written into the child.
set tSC=target.%Save()
if source.ChildCount {
set bhs=source.NextChild()
set bhs2=##class(EnsLib.HL7.Message).%New()
set tSC=bhs2.CopyValues(bhs,1,1,"set","")
set bhs2.DocType="2.3:BHS"
//we need to save the parent, because the parent
id is written into the child.
set tSC=bhs2.%Save()
set hl7=""
for j=1:1:bhs.ChildCount {
break
set hl7=bhs.NextChild(.hl7)
continue:'$IsObject(hl7)
//call the appropriate message transform
here. In this case I only call the one provided
//but it could be a case statement
set
tSC=##class(HL7FileProduction.DTLs.DFTDTL).Transform(hl7,.hl72)
set tSC=hl72.%Save()
set tSC=bhs2.AddChild(2,hl72)
//add additional save DRL 3/6/2008t
set tSC=hl72.%Save()
}
set tSC=bhs2.CopyValues(bhs,2,2,"set","")
set tSC=bhs2.CopyValues(bhs,3,3,"set","")
set tSC=target.CopyValues(source,2,2,"set","")
set tSC=target.AddChild(2,bhs2)
}
set tSC=target.CopyValues(source,3,3,"set","")
set tSC=hl72.%Save()
set tSC=bhs2.%Save()
} while (0)
Exit
Quit tSC
Trap
Set $ZT="",tSC=$$$EnsSystemError
Goto Exit
}
}
</DaveL>
--Jill