Example: CheckResults HL7
The following code overrides the CheckResults method. The purpose of this code is to examine the effects of running the production. The code does the following:
-
Uses CompareFiles to compare the file output by the production to a reference version of the file. By default, the method looks for the output file in HL7OutputDir. By default, the method compares the output file to a file named <OutputFileName>_Reference.
-
Queries the Business Rule Log table to retrieve the last entry from the routing rule associated with the MsgRouter. The Business Rule Log is stored in Ens_Rule.Log.
-
Verifies that the query returned a result.
-
If the query returned a result, it verifies that the message matched the correct rule and that the rule forwarded the message to the correct target.
Method CheckResults() As %Library.Status
{
Do $$$AssertStatusOK(..CompareFiles("ABC1Out.txt",,,..MainDir))
&SQL(Select TOP 1 ID,ActivityName,ErrorMsg,ReturnValue,Reason
INTO :Id,Act,Msg,Ret,Rea FROM Ens_Rule.Log
WHERE RuleName='Tutorial.TutorialHL7MessageRouterRules'
ORDER BY ID DESC
)
Set r = $$$AssertEquals(SQLCODE, 0, "Rule Log Entry")
if r {
Set r1=$$$AssertEquals(Rea,"rule#1:when#1", "Rule:("_Rea_")")
Set r2=$$$AssertTrue(Ret["TutorialHL7FileOperation","Target: "_Ret)
}
Quit $$$OK
}
All of the auxiliary methods used above are completely described in the class documentation for %UnitTest.TestProductionOpens in a new tab.
CheckResults uses embedded SQL to query the Business Rule Log. To learn more about embedded SQL, read Using Embedded SQL in Using Caché SQL.