How to implement business service that always returns CE (HL7 commit error)?

I want to test automatically that HL7 business operation works correctly in error conditions. One is to test CE acknowledgement. I have planned to implement test production which includes business services for different situations (AA, AE, CA, CE, timeout, late response etc).

How should I implement HL7 business service that always returns CE (commit error)? I have tried but it keeps returning "AA".

  • + 1
  • 0
  • 110
  • 0
  • 2

Answers

Hello Lassi,

You should create a new Business Service class extending the HL7 Business Service of your election (TCP, HTTP, etc) and after overwrite this method:

method OnConstructReply(Output pReplyDoc As EnsLib.EDI.Document, pOriginalDoc As EnsLib.EDI.Document, ByRef pReplyCode As %String, ByRef pSC As %Status, pEarlyAck As %Boolean) as %Status

Override this method to construct a customized reply document. Inputs are the original document and the reply code and the status code that the framework produced in processing the original document. If you change the status code but do not construct a reply document, the framework will use the new value to construct a standard reply document. 
If you construct a non-HL7 object it must still have a property called 'Envelope'. Piece:2 of this value will be written verbatim.

Consider this example (I didn't test it):

method OnConstructReply(Output pReplyDoc As EnsLib.EDI.Document, pOriginalDoc As EnsLib.EDI.Document, ByRef pReplyCode As %String, ByRef pSC As %Status, pEarlyAck As %Boolean) as %Status

{

    Set pReplyDoc=pOriginalDoc.NewReplyDocument(,..LocalFacilityApplication)
    Set pReplyDoc.Source=pOriginalDoc.%Id()
    Do:..#UseOriginalControlId pReplyDoc.SetValueAt(pOriginalDoc.GetValueAt("1:10"),"1:10") ; copy the control id to the ack control id
    Set tAckMSA=##class(EnsLib.HL7.Segment).%New($LB("",1))
    Set tAckMSA.Separators=pReplyDoc.Separators
    Do tAckMSA.SetValueAt("MSA",0)
    Do tAckMSA.SetValueAt("CE",1)
    Do tAckMSA.SetValueAt(pOriginalDoc.GetValueAt("1:10"),2)
    Do:$G($$$ExpectedSequenceNumber) tAckMSA.SetValueAt($$$ExpectedSequenceNumber,4)
    Do pReplyDoc.AppendSegment(tAckMSA)
    Set pReplyDoc.IsMutable=0
    Quit $$$OK

}

Hi Lassi

Probably you are getting "AA" because the Ack mode of the Business Service is set  to "Immediate". 

One way to do this, is to configure your business Service to send the incoming HL7 message to a business process that constructs the acknowledgement according to your requirements ,and sends the acknowledgement back to the business service as response. 

In this case, your Business Service Ack mode has to be "Application".

Here is a sample Business Process that could do something like this. 

Class dev.process.ackProc Extends Ens.BusinessProcess [ ClassType = persistent ]
{
Method OnRequest(pRequest As EnsLib.HL7.Message, Output Ack As EnsLib.HL7.Message) As %Status
{
SET sc=$$$OK
SET Ack=##class(EnsLib.HL7.Message).%New()
SET Ack.DocType="2.5:ACK"
SET sc=Ack.SetValueAt("ENSEMBLE","MSH:3")
SET sc=Ack.SetValueAt(pRequest.FindSegmentValues("MSH:3"),"MSH:6")
SET sc=Ack.SetValueAt("ACK","MSH:9.1")
SET sc=Ack.SetValueAt(pRequest.FindSegmentValues("MSH:9.2"),"MSH:9.2")
SET sc=Ack.SetValueAt($REPLACE($ZTIMESTAMP,",",""),"MSH:10")
SET sc=Ack.SetValueAt("CE","MSA:1")
Quit sc
}
}

I hope it helps.

Regards

Stelios