maintenance: title: Function MLM used to insert a row into the reportable info message queue ;; mlmname: STD_FUNC_INSERT_REPORTABLE_SURVEILLANCE;; arden: version 2.5;; version: 18.4;; institution: Allscripts, Standard MLM;; author: Allscripts Healthcare Solutions, Inc.;; specialist: ;; date: 2018-10-26;; validation: testing;; /* P r o p r i e t a r y N o t i c e */ /* Unpublished (c) 2013 - 2018 Allscripts Healthcare, LLC. and/or its affiliates. All Rights Reserved. P r o p r i e t a r y N o t i c e: This software has been provided pursuant to a License Agreement, with Allscripts Healthcare, LLC. and/or its affiliates, containing restrictions on its use. This software contains valuable trade secrets and proprietary information of Allscripts Healthcare, LLC. and/or its affiliates and is protected by trade secret and copyright law. This software may not be copied or distributed in any form or medium, disclosed to any third parties, or used in any manner not provided for in said License Agreement except with prior written authorization from Allscripts Healthcare, LLC. and/or its affiliates. Notice to U.S. Government Users: This software is {{{SINGLE-QUOTE}}}Commercial Computer Software{{{SINGLE-QUOTE}}}. All product names are the trademarks or registered trademarks of Allscripts Healthcare, LLC. and/or its affiliates. */ /* P r o p r i e t a r y N o t i c e */ library: purpose: This is a standard function MLM that is used by all other reportable result/Bio-surveillance MLMs. It takes the parameter values passed in, validates them and then creates a SQL call to insert a row into the SXAReportableInfoMsgQueue table. This MLM will return the Xml document generated is successful and NULL if there was nothing to be written. ;; explanation: 3 parameters are passed to this procedure: Message Queue Type - This specifies what type of message is being processed. Valid values are 0,"ReportableResults" or 1,"Biosurveillance" or 2,"Case Notification" or 3,"SendLabResults". If invalid or set to NULL it will be defaulted to "ReportableResults". Reportable Object List - The objects that need to be reported. This can either be a single ReportableType object or a list of these objects. Write To Database - A boolean flag, if true an entry will be written to the database. Generally a value of false is passed when testing this MLM from the editor. The reportable Object list will contain objects defined by this structure: ReportableType := OBJECT [ ParentKey, // Document, Order or Visit GUID (Single) ChildKeys, // Observation, Result or HealthIssue GUID (Single, list or NULL) ObjectType, // "result", "observation", "healthissue", "visit", "subject", "notification", "messageprofileid" Reason ]; This object must be defined in the calling MLM and populated based on the business rules of that MLM. ParentKey - This is the GUID for an Order or Document that is the parent for the childKeys. An order will have Result children while a Document will have Observation children. ChildKeys - This property contains either Result or Observation GUIDs depending on the type of the ParentKey. It can contain either a single GUID or list of GUIDs. If a list the GUIDs are all assumed to be of the same type. If NULL, the code will assume that all result items are to be included. A tag in the outgoing message is set so that it is not necessary to actually retrieve all the GUIDs. ObjectType - If the Parent object is a Document then this value must be "observation". If the parent object is an Order then this value must be "result". Reason - This is a coded value that can be included into the parent element. For reportable results this will be the diagnostic code: ^^ 413.9^Angina^ICD9 For Bio Surveillance messages the reason code is only required for the visit object and is the HL7 message type. ;; keywords: Biosurveillance ;; knowledge: type: data-driven;; data: ( MsgQueueType, ReportableObjectList, // Single item or list writeToDatabase ) := ARGUMENT; log_execution_info := false; // Set default values parentKeyType := "Order"; childKeyType := "Result"; parentKeyAttrib := "Results"; xmlDoc := null; returnStatus := false; errorMessage := ""; fatal_error := false; if (writeToDatabase is NULL) then writeToDatabase := true; endif; // Sanity check on MsgQueueType, defaults to ReportableResult // If all else fails if ( MsgQueueType is not NULL ) then if ( MsgQueueType is not number ) then if ( MsgQueueType = "BioSurveillance" ) then MsgQueueType := 1; elseif ( MsgQueueType = "ReportableResult" ) then MsgQueueType := 0; elseif ( MsgQueueType = "CaseNotification" ) then MsgQueueType := 2; elseif ( MsgQueueType = "SendLabResults" ) then MsgQueueType := 3; else MsgQueueType := 0; endif; endif; else MsgQueueType := 0; endif; if ( MsgQueueType is 2 ) then error_message := "Invalid MsgQueueType value - CaseNotification no longer supported"; fatal_error := true; endif; if not fatal_error then userID := read last { UserInfo: IDCode }; // If not a list, turn it into one. if (not ReportableObjectList is list) then ReportableObjectList := ,ReportableObjectList; endif; // Make sure there is at least one reportable // object. if exists ReportableObjectList then // Build Xml xmlDoc := ""; for obj in ReportableObjectList do if ( obj.ParentKey is not NULL ) then if ( obj.ObjectType = "result") then parentKeyType := "Order"; parentKeyAttrib := "Results"; childKeyType := "Result"; elseif ( obj.ObjectType = "observation") then parentKeyType := "Document"; parentKeyAttrib := "ObsItems"; childKeyType := "ObsItem"; elseif (obj.ObjectType = "healthissue") then parentKeyType := "HealthIssue"; parentKeyAttrib := "Diagnosis"; childKeyType := "DG1"; elseif (obj.ObjectType = "procedure") then parentKeyType := "HealthIssue"; parentKeyAttrib := "Diagnosis"; childKeyType := "PR1"; elseif (obj.ObjectType = "visit") then parentKeyType := "Visit"; parentKeyAttrib := null; childKeyType := null; elseif (obj.ObjectType = "subject") then parentKeyType := "Subject"; parentKeyAttrib := null; childKeyType := null; elseif (obj.ObjectType = "notification") then parentKeyType := "Notification"; parentKeyAttrib := null; childKeyType := null; elseif (obj.ObjectType = "messageprofileid") then parentKeyType := "MessageProfileId"; parentKeyAttrib := null; childKeyType := null; elseif (obj.ObjectType = "resultstatus") then parentKeyType := "ResultStatus"; parentKeyAttrib := null; childKeyType := null; else parentKeyType := obj.ObjectType; parentKeyAttrib := null; childKeyType := null; endif; xmlDoc := xmlDoc || "<" || parentKeyType || " Key={{{SINGLE-QUOTE}}}" || obj.ParentKey || "{{{SINGLE-QUOTE}}}"; if ( obj.Reason is Not NULL ) then if ( obj.ObjectType = "visit") then xmlDoc := xmlDoc || " Event={{{SINGLE-QUOTE}}}" || xml(obj.Reason) ||"{{{SINGLE-QUOTE}}} "; elseif ( obj.ObjectType in( "subject", "notification", "resultstatus" ) ) then xmlDoc := xmlDoc || " Type={{{SINGLE-QUOTE}}}" || xml(obj.Reason) ||"{{{SINGLE-QUOTE}}} "; elseif ( obj.ObjectType = "messageprofileid" ) then xmlDoc := xmlDoc || " ID={{{SINGLE-QUOTE}}}" || xml(obj.Reason) ||"{{{SINGLE-QUOTE}}} "; elseif( obj.ObjectType in("result", "observation", "healthissue") ) then xmlDoc := xmlDoc || " Reason={{{SINGLE-QUOTE}}}" || xml(obj.Reason) ||"{{{SINGLE-QUOTE}}} "; else xmlDoc := xmlDoc || " Value={{{SINGLE-QUOTE}}}" || xml(obj.Reason) ||"{{{SINGLE-QUOTE}}} "; endif; endif; // Visit, Subject, Notification, and MessageProfileId nodes do not have any children if ( parentKeyAttrib is not null ) then if ( obj.ChildKeys is NULL ) then xmlDoc := xmlDoc || " " || parentKeyAttrib || "={{{SINGLE-QUOTE}}}All{{{SINGLE-QUOTE}}} >"; else xmlDoc := xmlDoc || " " || parentKeyAttrib || "={{{SINGLE-QUOTE}}}Selected{{{SINGLE-QUOTE}}} >"; if ( obj.ChildKeys is NOT list) then obj.ChildKeys := ,obj.ChildKeys; // If not a list make a list endif; for child in obj.ChildKeys do if ( child <> "" AND child is not null ) then if ( (child as number) is number) then keyAttribute := "Key"; else keyAttribute := "Type"; endif; xmlDoc := xmlDoc || "<" || childKeyType || " " || keyAttribute ||"={{{SINGLE-QUOTE}}}" || child || "{{{SINGLE-QUOTE}}} />"; endif; enddo; endif; else xmlDoc := xmlDoc || ">"; endif; xmlDoc := xmlDoc || ""; endif; enddo; if ( xmlDoc <> "" ) then xmlDoc := "" || xmlDoc || ""; // Build SQL Insert logic if ( writeToDatabase ) then result := read last { "execute SXAReportableInfoMsgQueueInsPr " || " @ReportableInfoXml = " || SQL(xmlDoc) || ", @MsgQueueType = " || SQL(MsgQueueType) || ", @CreatedBy = " || SQL(userID) }; endif; returnStatus := true; endif; endif; endif; ;; priority: 50 ;; evoke: ;; logic: conclude returnStatus; ;; action: if ( xmlDoc = "" ) then xmlDoc := null; endif; if fatal_error then return error_message; else return xmlDoc; endif; ;; Urgency: 50;; end: