Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: MAGVAQ01

MAGVAQ01.m

Go to the documentation of this file.
  1. MAGVAQ01 ;WOIFO/NST - Utilities for RPC calls ; 28 Feb 2013 9:58 AM
  1. ;;3.0;IMAGING;**118**;Mar 19, 2002;Build 4525;May 01, 2013
  1. ;; Per VHA Directive 2004-038, this routine should not be modified.
  1. ;; +---------------------------------------------------------------+
  1. ;; | Property of the US Government. |
  1. ;; | No permission to copy or redistribute this software is given. |
  1. ;; | Use of unreleased versions of this software requires the user |
  1. ;; | to execute a written test agreement with the VistA Imaging |
  1. ;; | Development Office of the Department of Veterans Affairs, |
  1. ;; | telephone (301) 734-0100. |
  1. ;; | The Food and Drug Administration classifies this software as |
  1. ;; | a medical device. As such, it may not be changed in any way. |
  1. ;; | Modifications to this software may result in an adulterated |
  1. ;; | medical device under 21CFR820, the use of which is considered |
  1. ;; | to be a violation of US Federal Statutes. |
  1. ;; +---------------------------------------------------------------+
  1. ;;
  1. Q
  1. ;***** Add a record to QUEUE file (#2006.927)
  1. ;
  1. ; RPC: MAGVA CREATE QUEUE
  1. ;
  1. ; Input Parameters
  1. ; ================
  1. ;
  1. ; MAGPARAM("NAME")
  1. ; MAGPARAM("ACTIVE") = 0/1
  1. ; MAGPARAM("QUEUE TYPE")
  1. ; MAGPARAM("NUM RETRIES")
  1. ; MAGPARAM("RETRY DELAY IN SECONDS")
  1. ; MAGPARAM("TRIGGER DELAY IN SECONDS")
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; if error MAGRY = Failure status ^ Error message^
  1. ; if success MAGRY = Success status ^^IEN - IEN of the new record
  1. ;
  1. ADDQUEUE(MAGRY,MAGPARAM) ; RPC [MAGVA CREATE QUEUE]
  1. N MAGWP
  1. K MAGRY
  1. ; Add the record
  1. D ADDRCD^MAGVAF01(.MAGRY,2006.927,.MAGPARAM,.MAGWP)
  1. Q
  1. ;
  1. ;***** Returns all records in QUEUE file (#2006.927)
  1. ;
  1. ; RPC: MAGVA GET ALL QUEUES
  1. ;
  1. ; if error found during execution
  1. ; MAGRY(0) = Failure status ^ "Error getting the list"
  1. ; if success
  1. ; MAGRY(0) = Success status ^^#CNT - where #CNT is a number of records returned
  1. ; MAGRY(1) = "^" delimited string with all field names in Queue
  1. ; MAGRY(2..n) = "^" delimited string with values of fields listed in MAGRY(1)
  1. ;
  1. GETQUEUE(MAGRY) ; RPC [MAGVA GET ALL QUEUES]
  1. D GALLLST^MAGVAF03(.MAGRY,2006.927,"")
  1. ;
  1. ;***** Add a record to QUEUE MESSAGE file (#2006.928)
  1. ;
  1. ; RPC:MAGVA ENQUEUE Q MSG
  1. ;
  1. ; Input Parameters
  1. ; ================
  1. ;
  1. ; MAGPARAM("EXPIRATION DATE/TIME")
  1. ; MAGPARAM("EARLIEST DELIVERY DATE/TIME")
  1. ; MAGPARAM("PRIORITY")
  1. ; MAGPARAM("QUEUE") = Pointer to QUEUE file (#2006.927)
  1. ; MAGPARAM("MESSAGE GROUP ID") = value of the field "MESSAGE GROUP ID"
  1. ; in QUEUE file (#2006.927) or "*" or ""
  1. ; MAGMSG(1..n)= MESSAGE
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; if error MAGRY = Failure status ^ Error message^
  1. ; if success MAGRY = Success status ^^IEN - IEN of the new record
  1. ;
  1. ADDQM(MAGRY,MAGPARAM,MAGMSG) ; RPC [MAGVA ENQUEUE Q MSG]
  1. ; build MAGMSG first - workaround for Old broker listener
  1. N L,LL
  1. S L="MAGMSG",LL=0
  1. K MAGMSG
  1. F S L=$O(MAGPARAM(L)) Q:(L="")!($E(L,1,6)'="MAGMSG") S LL=LL+1,MAGMSG(LL)=MAGPARAM(L) K MAGPARAM(L)
  1. ;
  1. N FILE,FILEQM,IENS,FLD,ISACTIVE
  1. N MAGWP
  1. K MAGRY
  1. ; Check if the queue exist and it is active
  1. S IEN=$G(MAGPARAM("QUEUE"))
  1. ; Check for QUEUE
  1. I IEN="" S MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Input parameter QUEUE is required." Q ; Error getting the IEN
  1. ; Check if queue is active
  1. S FILE=2006.927 ; Queue file
  1. S IENS=IEN_","
  1. S FLD=$$GETFLDID^MAGVAF01(FILE,"ACTIVE")
  1. S ISACTIVE=$$GET1^DIQ(FILE,IENS,FLD,"I") ; get ACTIVE value
  1. I 'ISACTIVE S MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"The queue is inactive" Q
  1. ;
  1. S MAGPARAM("EXPIRATION DATE/TIME")=$$IDF2FM^MAGVAF01($G(MAGPARAM("EXPIRATION DATE/TIME")))
  1. S MAGPARAM("EARLIEST DELIVERY DATE/TIME")=$$IDF2FM^MAGVAF01($G(MAGPARAM("EARLIEST DELIVERY DATE/TIME")))
  1. S MAGPARAM("ENQUEUED DATE/TIME")=$$NOW^XLFDT
  1. M MAGWP("MESSAGE")=MAGMSG
  1. S FILEQM=2006.928
  1. D ADDRCD^MAGVAF01(.MAGRY,FILEQM,.MAGPARAM,.MAGWP) ; add the record
  1. Q
  1. ;
  1. ;***** Find, return and remove a queue message from the QUEUE MESSAGE file (#2006.928)
  1. ; by QUEUE - IEN of record in QUEUE file (#2006.927)
  1. ; and by MESSAGE GROUP ID.
  1. ; If "MESSAGE GROUP ID" equals "*" it ignores "MESSAGE GROUP ID".
  1. ; If "MESSAGE GROUP ID" equals "" it looks only at queue messages with blank "MESSAGE GROUP ID".
  1. ; Otherwise looks at queue messages with MESSAGE GROUP ID
  1. ;
  1. ; RPC:MAGVA DEQUEUE Q MSG
  1. ;
  1. ; Input Parameters
  1. ;
  1. ; MAGPARAM("QUEUE") = IEN in QUEUE file (#2006.927)
  1. ; MAGPARAM("MESSAGE GROUP ID") = value of the field "MESSAGE GROUP ID"
  1. ; in QUEUE file (#2006.927) or "*" or ""
  1. ;
  1. ; if MAGPARAM("MESSAGE GROUP ID") = "*" return oldest
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; if error MAGRY(0) = Failure status ^ Error message
  1. ; if success MAGRY(0) = Success status ^^IEN
  1. ; MAGRY(1..n) = The QUEUE MESSAGE
  1. ;
  1. ; if IEN equals 0 that means nothing was found
  1. ; ;
  1. DEQM(MAGRY,MAGPARAM) ; RPC [MAGVA DEQUEUE Q MSG]
  1. K MAGRY
  1. D FINDQM^MAGVAQ01(.MAGRY,.MAGPARAM,"D")
  1. Q
  1. ;
  1. ;***** Get a queue message from the QUEUE MESSAGE file (#2006.928)
  1. ; by QUEUE - IEN of record in QUEUE file (#2006.927)
  1. ; and by MESSAGE GROUP ID.
  1. ; If "MESSAGE GROUP ID" equals "*" it ignores "MESSAGE GROUP ID".
  1. ; If "MESSAGE GROUP ID" equals "" it looks only at queue messages with blank "MESSAGE GROUP ID".
  1. ; Otherwise looks at queue messages with MESSAGE GROUP ID
  1. ;
  1. ; RPC:MAGVA PEEK Q MSG
  1. ;
  1. ; Input Parameters
  1. ;
  1. ; MAGPARAM("QUEUE") = IEN in QUEUE file (#2006.927)
  1. ; MAGPARAM("MESSAGE GROUP ID") = value of the field "MESSAGE GROUP ID"
  1. ; in QUEUE file (#2006.927) or "*" or ""
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; if error MAGRY(0) = Failure status ^ Error message
  1. ; if success MAGRY(0) = Success status ^^IEN
  1. ; MAGRY(1..n) = The QUEUE MESSAGE
  1. ;
  1. ; if IEN equals 0 that means nothing was found
  1. ;
  1. PEEKQM(MAGRY,MAGPARAM) ; RPC [MAGVA PEEK Q MSG]
  1. K MAGRY
  1. D FINDQM^MAGVAQ01(.MAGRY,.MAGPARAM,"")
  1. Q
  1. ;
  1. ;+++++ Find, return and remove a queue message from the QUEUE MESSAGE file (#2006.928)
  1. ; by QUEUE - IEN of record in QUEUE file (#2006.927)
  1. ; The message will have the EARLIEST DELIVERY DATE/TIME equals NULL or the EARLIEST DELIVERY DATE/TIME less than
  1. ; current date/time
  1. ; and the EXPIRATION DATE/TIME equals NULL or the EXPIRATION DATE/TIME greater than current date/time.
  1. ;
  1. ; Delete the message if the flag is set
  1. ;
  1. ; Input Parameters
  1. ; ================
  1. ;
  1. ; MAGPARAM("QUEUE") = IEN in QUEUE file (#2006.927)
  1. ; MAGPARAM("MESSAGE GROUP ID") = value of the field "MESSAGE GROUP ID"
  1. ; in QUEUE file (#2006.927) or "*" or ""
  1. ; FLAGS = [D] delete the message from QUEUE MESSAGE file (#2006.928)
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; if error MAGRY(0) = Failure status ^ Error message
  1. ; if success MAGRY(0) = Success status ^^IEN
  1. ; MAGRY(1..n) = The QUEUE MESSAGE
  1. ;
  1. ; if IEN equals 0 that means nothing was found
  1. ;
  1. FINDQM(MAGRY,MAGPARAM,FLAGS) ;
  1. N MAGDT,IEN,FILE,FLDMINDT,FLDEXPDT
  1. N ERRMSG,FOUND
  1. N QUEUEIEN,MSGGRPID
  1. S QUEUEIEN=$G(MAGPARAM("QUEUE"))
  1. S MSGGRPID=$G(MAGPARAM("MESSAGE GROUP ID"))
  1. S FILE=2006.928 ; Queue Message file
  1. S FLDMINDT=$$GETFLDID^MAGVAF01(FILE,"EARLIEST DELIVERY DATE/TIME")
  1. S FLDEXPDT=$$GETFLDID^MAGVAF01(FILE,"EXPIRATION DATE/TIME")
  1. ; Check for QUEUE
  1. I QUEUEIEN="" S MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Input parameter QUEUE is required." Q ; Error getting the IEN
  1. S FOUND=0
  1. S ERRMSG=""
  1. I MSGGRPID="*" D
  1. . ; Use ENQDT index to loop through the queue and enqueued dates
  1. . ; For each IEN found check if the EARLIEST DELIVERY DATE/TIME is NULL OR the EARLIEST DELIVERY DATE/TIME < NOW)
  1. . ; and (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW) then quit and return the IEN
  1. . S MAGDT=""
  1. . S FOUND=0 ; If an eligible Queue message was found. IEN will be set to this record
  1. . F Q:(ERRMSG'="")!FOUND S MAGDT=$O(^MAGV(FILE,"ENQDT",QUEUEIEN,MAGDT)) Q:MAGDT="" D
  1. . . S IEN=""
  1. . . F Q:(ERRMSG'="")!FOUND S IEN=$O(^MAGV(FILE,"ENQDT",QUEUEIEN,MAGDT,IEN)) Q:IEN="" D
  1. . . . S FOUND=$$CHECKQM^MAGVAQ01(.ERRMSG,FILE,IEN,FLDMINDT,FLDEXPDT) ; see if we meet the criteria
  1. . . . I ERRMSG'="" S MAGRY(0)=ERRMSG
  1. . . . Q
  1. . . Q
  1. . Q
  1. ;
  1. I MSGGRPID="" D
  1. . ; Use ENQBLDT index to loop through the queue and enqueued dates
  1. . ; For each IEN found check if the EARLIEST DELIVERY DATE/TIME is NULL OR the EARLIEST DELIVERY DATE/TIME < NOW)
  1. . ; and (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW) then quit and return the IEN
  1. . S MAGDT=""
  1. . S FOUND=0 ; If an eligible Queue message was found. IEN will be set to this record
  1. . F Q:(ERRMSG'="")!FOUND S MAGDT=$O(^MAGV(FILE,"ENQBLDT",QUEUEIEN,MAGDT)) Q:MAGDT="" D
  1. . . S IEN=""
  1. . . F Q:(ERRMSG'="")!FOUND S IEN=$O(^MAGV(FILE,"ENQBLDT",QUEUEIEN,MAGDT,IEN)) Q:IEN="" D
  1. . . . S FOUND=$$CHECKQM^MAGVAQ01(.ERRMSG,FILE,IEN,FLDMINDT,FLDEXPDT) ; see if we meet the criteria
  1. . . . I ERRMSG'="" S MAGRY(0)=ERRMSG
  1. . . . Q
  1. . . Q
  1. . Q
  1. ;
  1. I (MSGGRPID'=""),(MSGGRPID'="*") D
  1. . ; Use ENQPLDT index to loop through the queue, place and enqueued dates
  1. . ; For each IEN found check if the EARLIEST DELIVERY DATE/TIME is NULL OR the EARLIEST DELIVERY DATE/TIME < NOW)
  1. . ; and (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW) then quit and return the IEN
  1. . S MAGDT=""
  1. . S FOUND=0 ; If an eligible Queue message was found. IEN will be set to this record
  1. . F Q:(ERRMSG'="")!FOUND S MAGDT=$O(^MAGV(FILE,"ENQPLDT",QUEUEIEN,MSGGRPID,MAGDT)) Q:MAGDT="" D
  1. . . S IEN=""
  1. . . F Q:(ERRMSG'="")!FOUND S IEN=$O(^MAGV(FILE,"ENQPLDT",QUEUEIEN,MSGGRPID,MAGDT,IEN)) Q:IEN="" D
  1. . . . S FOUND=$$CHECKQM^MAGVAQ01(.ERRMSG,FILE,IEN,FLDMINDT,FLDEXPDT) ; see if we meet the criteria
  1. . . . I ERRMSG'="" S MAGRY(0)=ERRMSG
  1. . . . Q
  1. . . Q
  1. . Q
  1. I ERRMSG'="" Q ; Quit - Found error getting values
  1. ;
  1. I 'FOUND S MAGRY(0)=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_0 Q
  1. ;
  1. ; Get the message and delete it from the queue if the flag is set
  1. ;
  1. D GXMLBYPK^MAGVAF03(.MAGRY,FILE,IEN,0)
  1. I '$$ISOK^MAGVAF02(MAGRY(0)) Q ; Check for error and quit if we have one
  1. ;
  1. ; Delete the message from QUEUE MESSAGE file (#2006.928)
  1. I FLAGS["D" D
  1. . N DA,DIK
  1. . S DIK=$$GETFILGL^MAGVAF01(FILE)
  1. . S DA=IEN
  1. . D ^DIK
  1. . Q
  1. S MAGRY(0)=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_IEN
  1. Q
  1. ;
  1. ; ++++ Returns 1 if it meets the criteria, if not returns 0
  1. ; Check if (the EARLIEST DELIVERY DATE/TIME is NULL or the EARLIEST DELIVERY DATE/TIME < NOW)
  1. ; and (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW)
  1. ;
  1. ; Input Parameters
  1. ; ================
  1. ; FILE = QUEUE MESSAGE file (#2006.928)
  1. ; IEN = IEN in QUEUE MESSAGE file (#2006.928)
  1. ; FLDMINDT = EARLIEST DELIVERY DATE/TIME field number in QUEUE MESSAGE file (#2006.928)
  1. ; FLDEXPDT = EXPIRATION DATE/TIME field number in QUEUE MESSAGE file (#2006.928)
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; if error ERRMSG = Failure status ^ Error message^
  1. ;
  1. CHECKQM(ERRMSG,FILE,IEN,FLDMINDT,FLDEXPDT) ; Returns 1 if it meets the criteria, if not returns 0
  1. N ERR,FIELDS,OUT,IENS,MAGRESA,FOUND
  1. N NOW
  1. S FOUND=0
  1. S FIELDS=FLDMINDT_";"_FLDEXPDT
  1. S IENS=IEN_","
  1. D GETS^DIQ(FILE,IENS,FIELDS,"I","OUT","ERR") ; get EARLIEST DELIVERY DATE/TIME and EXPIRATION DATE/TIME values
  1. I $D(ERR("DIERR")) D Q 0
  1. . D MSG^DIALOG("A",.MAGRESA,245,5,"ERR")
  1. . S ERRMSG=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting values: "_MAGRESA(1) Q ; Error getting the values
  1. . Q
  1. ;
  1. ; Get the oldest QUEUE MESSAGE where
  1. ; (the EARLIEST DELIVERY DATE/TIME is NULL OR the EARLIEST DELIVERY DATE/TIME < NOW)
  1. ; AND (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW)
  1. ;
  1. S NOW=$$NOW^XLFDT
  1. I ((OUT(FILE,IENS,FLDMINDT,"I")="")!(OUT(FILE,IENS,FLDMINDT,"I")<NOW))&((OUT(FILE,IENS,FLDEXPDT,"I")="")!(OUT(FILE,IENS,FLDEXPDT,"I")>NOW)) S FOUND=1
  1. Q FOUND