Julian Matthews · Nov 20, 2019

Using BP to create multiple messages from a single HL7

Hi all.

I'm currently working with a system needing results from a lab system, and they can only accept a single OBR per R01 message.

The R01s from the source have multiple OBRs, so I need to be able to send a message per OBR.

I found a similar post where the example was using a BPL, however there's some additional trickery processing that I already have working within an ObjectScript Business Process and would like to avoid trying to recreate in a BPL.

Any sample code will be greatly received smiley

1 1 4 412
Log in or sign up to continue

I think this would be much easier with BPL/DTL. Why not have your ObjectScript Business Process do its thing, then hand the result to a BPL to loop over OBRs and break it into multiple messages? Or put the BPL first, if your 'trickery' should happen to each generated message individually.


Hi Steve.

The main reason is that I'm trying to reduce the footprint within our Ensemble/interoperability production. However, I'm not too proud to rule it out if I am stuck for other options.

I've done something similar with COS, but in my case it was the ORC group that was repeating:

Class HICG.Process.MultiORC Extends Ens.BusinessProcess [ ClassType = persistent ]
Property TargetConfigNames As %String(MAXLEN = 1000);
Parameter SETTINGS = "TargetConfigNames:Basic:selector?multiSelect=1&context={Ens.ContextSearch/ProductionItems?targets=1&productionName=@productionId}";
Method OnRequest(pRequest As EnsLib.HL7.Message, Output pResponse As Ens.Response) As %Status
    Set tORCcnt = pRequest.GetValueAt("PIDgrpgrp(1).ORCgrp(*)")
    For i=1:1:tORCcnt
        Set tMsg = ##class(EnsLib.HL7.Message).%New()
        Set tMsg.DocType = pRequest.DocType
        // Keep MSH:10 unique
        Set tMsgCtrl = pRequest.GetValueAt("MSH:10")_"."_i
        Do tMsg.SetValueAt(pRequest.GetValueAt("MSH"),"MSH")
        Do tMsg.SetValueAt(tMsgCtrl,"MSH:10")
        Do tMsg.SetValueAt(pRequest.GetValueAt("PIDgrpgrp(1).PIDgrp.PID"),"PIDgrpgrp(1).PIDgrp.PID")
        Do tMsg.SetValueAt(pRequest.GetValueAt("PIDgrpgrp(1).PIDgrp.PV1grp.PV1"),"PIDgrpgrp(1).PIDgrp.PV1grp.PV1")
        Do tMsg.SetValueAt(pRequest.GetValueAt("PIDgrpgrp(1).ORCgrp("_i_").ORC"),"PIDgrpgrp(1).ORCgrp(1).ORC")
        Do tMsg.SetValueAt(pRequest.GetValueAt("PIDgrpgrp(1).ORCgrp("_i_").OBR"),"PIDgrpgrp(1).ORCgrp(1).OBR")
        Set tOBXcnt = pRequest.GetValueAt("PIDgrpgrp(1).ORCgrp("_i_").OBXgrp(*)")
        For j=1:1:tOBXcnt
            Do tMsg.SetValueAt(pRequest.GetValueAt("PIDgrpgrp(1).ORCgrp("_i_").OBXgrp("_j_").OBX"),"PIDgrpgrp(1).ORCgrp(1).OBXgrp("_j_").OBX")
        Set tSC = tMsg.%Save()
        For iTarget=1:1:$L(..TargetConfigNames, ",")
            Set tTarget=$ZStrip($P(..TargetConfigNames,",",iTarget),"<>W")
            Set tSC1 = ..SendRequestAsync(tTarget,tMsg)
            Set:$$$ISERR(tSC1) tSC=$$$ADDSC(tSC,tSC1)
    Return tSC

Great work. Happened to have noticed it's needed to un-handle the response at least in the new IRIS versions: 

/// Un-handle a 'Response'
Method OnResponse(request As %Library.Persistent, ByRef response As %Library.Persistent, callrequest As %Library.Persistent, callresponse As %Library.Persistent, pCompletionKey As %String) As %Status
// Subclass responsibility
Quit $$$OK //$$$EnsError($$$NotImplemented)