If that doesn’t work, then try using the following script instead.
/*************************************************************************
* HL7ValidateSingleInstanceOfIdentifiersUsingKeytype
*
* Written by: Aaron Truskot (GRP-GHS-Standards@hyland.com)
* Hyland Software, Inc.
* Version History:
* 1.0 (2014-03-05) - Initial Release
*
* The HL7ValidateSingleInstanceOfIdentifiersUsingKeytypes script is designed to
* parse through all loose Keywords, SIKGs, and MIKGs looking for multiple instances of the
* configured Keyword Types. This Unity Script should be triggered as a Rule in
* HL7 Sending Workflow Lifecycle. Script fails if multiple instances are found.
*
* NO NEED TO USE THIS SCRIPT IF ALL PATIENT IDENTIFIERS ARE PART OF SIKG.
*
************************************************************************/
namespace HL7ValidateSingleInstanceOfIdentifiersUsingKeytype
{
using System;
using System.Text;
using Hyland.Unity;
using Hyland.Unity.Workflow;
using System.Data;
using System.Collections.Generic;
/// <summary>
/// Simple helper class intended to group a Keyword Type Number with a boolean flag
/// </summary>
public class ValidationKeywordType
{
public int keyNum; // Keyword Type Number
public bool keyFound; // Have we found this Keyword Type on the document?
public ValidationKeywordType(int key)
{
this.keyNum = key;
this.keyFound = false;
}
}
/// <summary>
/// This script is intended to be triggered prior to attempting to send an outbound
/// HL7 message out to downstream systems. It ensures that zero or one instance
/// exists for Keyword Types tied to Chart ID, MRN, and MPI Chart Data Fields.
/// </summary>
public class HL7ValidateSingleInstanceOfIdentifiersUsingKeytype : Hyland.Unity.IWorkflowScript
{
#region IWorkflowScript
/// <summary>
/// Implementation of <see cref="IWorkflowScript.OnWorkflowScriptExecute" />.
/// <seealso cref="IWorkflowScript" />
/// </summary>
/// <param name="app">OnBase Session</param>
/// <param name="args">Arguments passed from Workflow</param>
public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
{
bool scriptResult = false; // Fail unless script completes sucessfully
List<ValidationKeywordType> validationKeywordTypes = new List<ValidationKeywordType>();
/************************************************************************
* User Configured Settings Section
************************************************************************/
/* Set diagLevel variable to one of the following:
* Diagnostics.DiagnosticsLevel.Verbose
* Diagnostics.DiagnosticsLevel.Info
* Diagnostics.DiagnosticsLevel.Warning
* Diagnostics.DiagnosticsLevel.Error
*
* Verbose is excellent for initial testing and troubleshooting.
* The variable should be set to Error in production environments.
*/
Diagnostics.DiagnosticsLevel diagLevel = Diagnostics.DiagnosticsLevel.Error;
// Add Keyword Type Numbers to validate. One row per Keyword Type
// ex:
// validationKeywordTypes.Add(new ValidationKeywordType(101));
// validationKeywordTypes.Add(new ValidationKeywordType(102));
validationKeywordTypes.Add(new ValidationKeywordType(###)); // CSN
validationKeywordTypes.Add(new ValidationKeywordType(###)); // MRN
validationKeywordTypes.Add(new ValidationKeywordType(###)); // MPI
/************************************************************************
* End of configuration section --- do not modify below this line
************************************************************************/
try
{
app.Diagnostics.Level = diagLevel;
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose,
"[HVV001] Beginning script execution for docID: " + args.Document.ID.ToString());
/************************************************************************
* Check for multiple instances of the Keyword(s)
************************************************************************/
// Loop through all standalone, single instance, and multi instance keyword records
foreach (KeywordRecord keyRecord in args.Document.KeywordRecords)
{
// Loop through all keywords on each keyword record
foreach (Keyword keyword in keyRecord.Keywords)
{
foreach (ValidationKeywordType vkt in validationKeywordTypes)
{
if (keyword.KeywordType.ID == vkt.keyNum)
{
if (vkt.keyFound)
{ // Found more than one instance. Fail.
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error,
"[HVE011] Duplicate instance found for: " + vkt.keyNum + ".");
scriptResult = false;
return;
}
else
{ // Found our first instance of the Keyword
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose,
"[HVV012] First instance found for: " + vkt.keyNum + ".");
vkt.keyFound = true;
break;
}
}
}
}
}
scriptResult = true;
// Done. Ending script after finally logic completes.
}
catch (Exception e)
{
string error = "[HVE002] Exception caught while executing: " + e.Message;
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, error);
}
finally
{
args.ScriptResult = scriptResult;
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, "[HVV003] Script execution complete.");
}
}
#endregion
}
}
In OnBase Studio you must open the Unity Script Project HL7ValidateSingleInstanceofIdentifiers and replace all the current code with what is in the linked script. You also need to update the User Configured Settings Section (lines 85+) to point to the Patient and Visit Level identifiers that you want to check (validate that there is only one instance of each identifier on a document). This is done by updating the ### with your keyword number. Ensure to rebuild, publish (mark as active!), and reset IIS.
validationKeywordTypes.Add(new ValidationKeywordType(###)); // CSN or visit #
validationKeywordTypes.Add(new ValidationKeywordType(###)); // MRN
validationKeywordTypes.Add(new ValidationKeywordType(###)); // MPI