MAGVAQ01 ;WOIFO/NST - Utilities for RPC calls ; 28 Feb 2013 9:58 AM
;;3.0;IMAGING;**118**;Mar 19, 2002;Build 4525;May 01, 2013
;; Per VHA Directive 2004-038, this routine should not be modified.
;; +---------------------------------------------------------------+
;; | Property of the US Government. |
;; | No permission to copy or redistribute this software is given. |
;; | Use of unreleased versions of this software requires the user |
;; | to execute a written test agreement with the VistA Imaging |
;; | Development Office of the Department of Veterans Affairs, |
;; | telephone (301) 734-0100. |
;; | The Food and Drug Administration classifies this software as |
;; | a medical device. As such, it may not be changed in any way. |
;; | Modifications to this software may result in an adulterated |
;; | medical device under 21CFR820, the use of which is considered |
;; | to be a violation of US Federal Statutes. |
;; +---------------------------------------------------------------+
;;
Q
;***** Add a record to QUEUE file (#2006.927)
;
; RPC: MAGVA CREATE QUEUE
;
; Input Parameters
; ================
;
; MAGPARAM("NAME")
; MAGPARAM("ACTIVE") = 0/1
; MAGPARAM("QUEUE TYPE")
; MAGPARAM("NUM RETRIES")
; MAGPARAM("RETRY DELAY IN SECONDS")
; MAGPARAM("TRIGGER DELAY IN SECONDS")
;
; Return Values
; =============
; if error MAGRY = Failure status ^ Error message^
; if success MAGRY = Success status ^^IEN - IEN of the new record
;
ADDQUEUE(MAGRY,MAGPARAM) ; RPC [MAGVA CREATE QUEUE]
N MAGWP
K MAGRY
; Add the record
D ADDRCD^MAGVAF01(.MAGRY,2006.927,.MAGPARAM,.MAGWP)
Q
;
;***** Returns all records in QUEUE file (#2006.927)
;
; RPC: MAGVA GET ALL QUEUES
;
; if error found during execution
; MAGRY(0) = Failure status ^ "Error getting the list"
; if success
; MAGRY(0) = Success status ^^#CNT - where #CNT is a number of records returned
; MAGRY(1) = "^" delimited string with all field names in Queue
; MAGRY(2..n) = "^" delimited string with values of fields listed in MAGRY(1)
;
GETQUEUE(MAGRY) ; RPC [MAGVA GET ALL QUEUES]
D GALLLST^MAGVAF03(.MAGRY,2006.927,"")
;
;***** Add a record to QUEUE MESSAGE file (#2006.928)
;
; RPC:MAGVA ENQUEUE Q MSG
;
; Input Parameters
; ================
;
; MAGPARAM("EXPIRATION DATE/TIME")
; MAGPARAM("EARLIEST DELIVERY DATE/TIME")
; MAGPARAM("PRIORITY")
; MAGPARAM("QUEUE") = Pointer to QUEUE file (#2006.927)
; MAGPARAM("MESSAGE GROUP ID") = value of the field "MESSAGE GROUP ID"
; in QUEUE file (#2006.927) or "*" or ""
; MAGMSG(1..n)= MESSAGE
;
; Return Values
; =============
; if error MAGRY = Failure status ^ Error message^
; if success MAGRY = Success status ^^IEN - IEN of the new record
;
ADDQM(MAGRY,MAGPARAM,MAGMSG) ; RPC [MAGVA ENQUEUE Q MSG]
; build MAGMSG first - workaround for Old broker listener
N L,LL
S L="MAGMSG",LL=0
K MAGMSG
F S L=$O(MAGPARAM(L)) Q:(L="")!($E(L,1,6)'="MAGMSG") S LL=LL+1,MAGMSG(LL)=MAGPARAM(L) K MAGPARAM(L)
;
N FILE,FILEQM,IENS,FLD,ISACTIVE
N MAGWP
K MAGRY
; Check if the queue exist and it is active
S IEN=$G(MAGPARAM("QUEUE"))
; Check for QUEUE
I IEN="" S MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Input parameter QUEUE is required." Q ; Error getting the IEN
; Check if queue is active
S FILE=2006.927 ; Queue file
S IENS=IEN_","
S FLD=$$GETFLDID^MAGVAF01(FILE,"ACTIVE")
S ISACTIVE=$$GET1^DIQ(FILE,IENS,FLD,"I") ; get ACTIVE value
I 'ISACTIVE S MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"The queue is inactive" Q
;
S MAGPARAM("EXPIRATION DATE/TIME")=$$IDF2FM^MAGVAF01($G(MAGPARAM("EXPIRATION DATE/TIME")))
S MAGPARAM("EARLIEST DELIVERY DATE/TIME")=$$IDF2FM^MAGVAF01($G(MAGPARAM("EARLIEST DELIVERY DATE/TIME")))
S MAGPARAM("ENQUEUED DATE/TIME")=$$NOW^XLFDT
M MAGWP("MESSAGE")=MAGMSG
S FILEQM=2006.928
D ADDRCD^MAGVAF01(.MAGRY,FILEQM,.MAGPARAM,.MAGWP) ; add the record
Q
;
;***** Find, return and remove a queue message from the QUEUE MESSAGE file (#2006.928)
; by QUEUE - IEN of record in QUEUE file (#2006.927)
; and by MESSAGE GROUP ID.
; If "MESSAGE GROUP ID" equals "*" it ignores "MESSAGE GROUP ID".
; If "MESSAGE GROUP ID" equals "" it looks only at queue messages with blank "MESSAGE GROUP ID".
; Otherwise looks at queue messages with MESSAGE GROUP ID
;
; RPC:MAGVA DEQUEUE Q MSG
;
; Input Parameters
;
; MAGPARAM("QUEUE") = IEN in QUEUE file (#2006.927)
; MAGPARAM("MESSAGE GROUP ID") = value of the field "MESSAGE GROUP ID"
; in QUEUE file (#2006.927) or "*" or ""
;
; if MAGPARAM("MESSAGE GROUP ID") = "*" return oldest
;
; Return Values
; =============
; if error MAGRY(0) = Failure status ^ Error message
; if success MAGRY(0) = Success status ^^IEN
; MAGRY(1..n) = The QUEUE MESSAGE
;
; if IEN equals 0 that means nothing was found
; ;
DEQM(MAGRY,MAGPARAM) ; RPC [MAGVA DEQUEUE Q MSG]
K MAGRY
D FINDQM^MAGVAQ01(.MAGRY,.MAGPARAM,"D")
Q
;
;***** Get a queue message from the QUEUE MESSAGE file (#2006.928)
; by QUEUE - IEN of record in QUEUE file (#2006.927)
; and by MESSAGE GROUP ID.
; If "MESSAGE GROUP ID" equals "*" it ignores "MESSAGE GROUP ID".
; If "MESSAGE GROUP ID" equals "" it looks only at queue messages with blank "MESSAGE GROUP ID".
; Otherwise looks at queue messages with MESSAGE GROUP ID
;
; RPC:MAGVA PEEK Q MSG
;
; Input Parameters
;
; MAGPARAM("QUEUE") = IEN in QUEUE file (#2006.927)
; MAGPARAM("MESSAGE GROUP ID") = value of the field "MESSAGE GROUP ID"
; in QUEUE file (#2006.927) or "*" or ""
;
; Return Values
; =============
; if error MAGRY(0) = Failure status ^ Error message
; if success MAGRY(0) = Success status ^^IEN
; MAGRY(1..n) = The QUEUE MESSAGE
;
; if IEN equals 0 that means nothing was found
;
PEEKQM(MAGRY,MAGPARAM) ; RPC [MAGVA PEEK Q MSG]
K MAGRY
D FINDQM^MAGVAQ01(.MAGRY,.MAGPARAM,"")
Q
;
;+++++ Find, return and remove a queue message from the QUEUE MESSAGE file (#2006.928)
; by QUEUE - IEN of record in QUEUE file (#2006.927)
; The message will have the EARLIEST DELIVERY DATE/TIME equals NULL or the EARLIEST DELIVERY DATE/TIME less than
; current date/time
; and the EXPIRATION DATE/TIME equals NULL or the EXPIRATION DATE/TIME greater than current date/time.
;
; Delete the message if the flag is set
;
; Input Parameters
; ================
;
; MAGPARAM("QUEUE") = IEN in QUEUE file (#2006.927)
; MAGPARAM("MESSAGE GROUP ID") = value of the field "MESSAGE GROUP ID"
; in QUEUE file (#2006.927) or "*" or ""
; FLAGS = [D] delete the message from QUEUE MESSAGE file (#2006.928)
;
; Return Values
; =============
; if error MAGRY(0) = Failure status ^ Error message
; if success MAGRY(0) = Success status ^^IEN
; MAGRY(1..n) = The QUEUE MESSAGE
;
; if IEN equals 0 that means nothing was found
;
FINDQM(MAGRY,MAGPARAM,FLAGS) ;
N MAGDT,IEN,FILE,FLDMINDT,FLDEXPDT
N ERRMSG,FOUND
N QUEUEIEN,MSGGRPID
S QUEUEIEN=$G(MAGPARAM("QUEUE"))
S MSGGRPID=$G(MAGPARAM("MESSAGE GROUP ID"))
S FILE=2006.928 ; Queue Message file
S FLDMINDT=$$GETFLDID^MAGVAF01(FILE,"EARLIEST DELIVERY DATE/TIME")
S FLDEXPDT=$$GETFLDID^MAGVAF01(FILE,"EXPIRATION DATE/TIME")
; Check for QUEUE
I QUEUEIEN="" S MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Input parameter QUEUE is required." Q ; Error getting the IEN
S FOUND=0
S ERRMSG=""
I MSGGRPID="*" D
. ; Use ENQDT index to loop through the queue and enqueued dates
. ; For each IEN found check if the EARLIEST DELIVERY DATE/TIME is NULL OR the EARLIEST DELIVERY DATE/TIME < NOW)
. ; and (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW) then quit and return the IEN
. S MAGDT=""
. S FOUND=0 ; If an eligible Queue message was found. IEN will be set to this record
. F Q:(ERRMSG'="")!FOUND S MAGDT=$O(^MAGV(FILE,"ENQDT",QUEUEIEN,MAGDT)) Q:MAGDT="" D
. . S IEN=""
. . F Q:(ERRMSG'="")!FOUND S IEN=$O(^MAGV(FILE,"ENQDT",QUEUEIEN,MAGDT,IEN)) Q:IEN="" D
. . . S FOUND=$$CHECKQM^MAGVAQ01(.ERRMSG,FILE,IEN,FLDMINDT,FLDEXPDT) ; see if we meet the criteria
. . . I ERRMSG'="" S MAGRY(0)=ERRMSG
. . . Q
. . Q
. Q
;
I MSGGRPID="" D
. ; Use ENQBLDT index to loop through the queue and enqueued dates
. ; For each IEN found check if the EARLIEST DELIVERY DATE/TIME is NULL OR the EARLIEST DELIVERY DATE/TIME < NOW)
. ; and (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW) then quit and return the IEN
. S MAGDT=""
. S FOUND=0 ; If an eligible Queue message was found. IEN will be set to this record
. F Q:(ERRMSG'="")!FOUND S MAGDT=$O(^MAGV(FILE,"ENQBLDT",QUEUEIEN,MAGDT)) Q:MAGDT="" D
. . S IEN=""
. . F Q:(ERRMSG'="")!FOUND S IEN=$O(^MAGV(FILE,"ENQBLDT",QUEUEIEN,MAGDT,IEN)) Q:IEN="" D
. . . S FOUND=$$CHECKQM^MAGVAQ01(.ERRMSG,FILE,IEN,FLDMINDT,FLDEXPDT) ; see if we meet the criteria
. . . I ERRMSG'="" S MAGRY(0)=ERRMSG
. . . Q
. . Q
. Q
;
I (MSGGRPID'=""),(MSGGRPID'="*") D
. ; Use ENQPLDT index to loop through the queue, place and enqueued dates
. ; For each IEN found check if the EARLIEST DELIVERY DATE/TIME is NULL OR the EARLIEST DELIVERY DATE/TIME < NOW)
. ; and (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW) then quit and return the IEN
. S MAGDT=""
. S FOUND=0 ; If an eligible Queue message was found. IEN will be set to this record
. F Q:(ERRMSG'="")!FOUND S MAGDT=$O(^MAGV(FILE,"ENQPLDT",QUEUEIEN,MSGGRPID,MAGDT)) Q:MAGDT="" D
. . S IEN=""
. . F Q:(ERRMSG'="")!FOUND S IEN=$O(^MAGV(FILE,"ENQPLDT",QUEUEIEN,MSGGRPID,MAGDT,IEN)) Q:IEN="" D
. . . S FOUND=$$CHECKQM^MAGVAQ01(.ERRMSG,FILE,IEN,FLDMINDT,FLDEXPDT) ; see if we meet the criteria
. . . I ERRMSG'="" S MAGRY(0)=ERRMSG
. . . Q
. . Q
. Q
I ERRMSG'="" Q ; Quit - Found error getting values
;
I 'FOUND S MAGRY(0)=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_0 Q
;
; Get the message and delete it from the queue if the flag is set
;
D GXMLBYPK^MAGVAF03(.MAGRY,FILE,IEN,0)
I '$$ISOK^MAGVAF02(MAGRY(0)) Q ; Check for error and quit if we have one
;
; Delete the message from QUEUE MESSAGE file (#2006.928)
I FLAGS["D" D
. N DA,DIK
. S DIK=$$GETFILGL^MAGVAF01(FILE)
. S DA=IEN
. D ^DIK
. Q
S MAGRY(0)=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_IEN
Q
;
; ++++ Returns 1 if it meets the criteria, if not returns 0
; Check if (the EARLIEST DELIVERY DATE/TIME is NULL or the EARLIEST DELIVERY DATE/TIME < NOW)
; and (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW)
;
; Input Parameters
; ================
; FILE = QUEUE MESSAGE file (#2006.928)
; IEN = IEN in QUEUE MESSAGE file (#2006.928)
; FLDMINDT = EARLIEST DELIVERY DATE/TIME field number in QUEUE MESSAGE file (#2006.928)
; FLDEXPDT = EXPIRATION DATE/TIME field number in QUEUE MESSAGE file (#2006.928)
;
; Return Values
; =============
; if error ERRMSG = Failure status ^ Error message^
;
CHECKQM(ERRMSG,FILE,IEN,FLDMINDT,FLDEXPDT) ; Returns 1 if it meets the criteria, if not returns 0
N ERR,FIELDS,OUT,IENS,MAGRESA,FOUND
N NOW
S FOUND=0
S FIELDS=FLDMINDT_";"_FLDEXPDT
S IENS=IEN_","
D GETS^DIQ(FILE,IENS,FIELDS,"I","OUT","ERR") ; get EARLIEST DELIVERY DATE/TIME and EXPIRATION DATE/TIME values
I $D(ERR("DIERR")) D Q 0
. D MSG^DIALOG("A",.MAGRESA,245,5,"ERR")
. S ERRMSG=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting values: "_MAGRESA(1) Q ; Error getting the values
. Q
;
; Get the oldest QUEUE MESSAGE where
; (the EARLIEST DELIVERY DATE/TIME is NULL OR the EARLIEST DELIVERY DATE/TIME < NOW)
; AND (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW)
;
S NOW=$$NOW^XLFDT
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
Q FOUND
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGVAQ01 12557 printed Dec 13, 2024@02:09:27 Page 2
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
+2 ;; Per VHA Directive 2004-038, this routine should not be modified.
+3 ;; +---------------------------------------------------------------+
+4 ;; | Property of the US Government. |
+5 ;; | No permission to copy or redistribute this software is given. |
+6 ;; | Use of unreleased versions of this software requires the user |
+7 ;; | to execute a written test agreement with the VistA Imaging |
+8 ;; | Development Office of the Department of Veterans Affairs, |
+9 ;; | telephone (301) 734-0100. |
+10 ;; | The Food and Drug Administration classifies this software as |
+11 ;; | a medical device. As such, it may not be changed in any way. |
+12 ;; | Modifications to this software may result in an adulterated |
+13 ;; | medical device under 21CFR820, the use of which is considered |
+14 ;; | to be a violation of US Federal Statutes. |
+15 ;; +---------------------------------------------------------------+
+16 ;;
+17 QUIT
+18 ;***** Add a record to QUEUE file (#2006.927)
+19 ;
+20 ; RPC: MAGVA CREATE QUEUE
+21 ;
+22 ; Input Parameters
+23 ; ================
+24 ;
+25 ; MAGPARAM("NAME")
+26 ; MAGPARAM("ACTIVE") = 0/1
+27 ; MAGPARAM("QUEUE TYPE")
+28 ; MAGPARAM("NUM RETRIES")
+29 ; MAGPARAM("RETRY DELAY IN SECONDS")
+30 ; MAGPARAM("TRIGGER DELAY IN SECONDS")
+31 ;
+32 ; Return Values
+33 ; =============
+34 ; if error MAGRY = Failure status ^ Error message^
+35 ; if success MAGRY = Success status ^^IEN - IEN of the new record
+36 ;
ADDQUEUE(MAGRY,MAGPARAM) ; RPC [MAGVA CREATE QUEUE]
+1 NEW MAGWP
+2 KILL MAGRY
+3 ; Add the record
+4 DO ADDRCD^MAGVAF01(.MAGRY,2006.927,.MAGPARAM,.MAGWP)
+5 QUIT
+6 ;
+7 ;***** Returns all records in QUEUE file (#2006.927)
+8 ;
+9 ; RPC: MAGVA GET ALL QUEUES
+10 ;
+11 ; if error found during execution
+12 ; MAGRY(0) = Failure status ^ "Error getting the list"
+13 ; if success
+14 ; MAGRY(0) = Success status ^^#CNT - where #CNT is a number of records returned
+15 ; MAGRY(1) = "^" delimited string with all field names in Queue
+16 ; MAGRY(2..n) = "^" delimited string with values of fields listed in MAGRY(1)
+17 ;
GETQUEUE(MAGRY) ; RPC [MAGVA GET ALL QUEUES]
+1 DO GALLLST^MAGVAF03(.MAGRY,2006.927,"")
+2 ;
+3 ;***** Add a record to QUEUE MESSAGE file (#2006.928)
+4 ;
+5 ; RPC:MAGVA ENQUEUE Q MSG
+6 ;
+7 ; Input Parameters
+8 ; ================
+9 ;
+10 ; MAGPARAM("EXPIRATION DATE/TIME")
+11 ; MAGPARAM("EARLIEST DELIVERY DATE/TIME")
+12 ; MAGPARAM("PRIORITY")
+13 ; MAGPARAM("QUEUE") = Pointer to QUEUE file (#2006.927)
+14 ; MAGPARAM("MESSAGE GROUP ID") = value of the field "MESSAGE GROUP ID"
+15 ; in QUEUE file (#2006.927) or "*" or ""
+16 ; MAGMSG(1..n)= MESSAGE
+17 ;
+18 ; Return Values
+19 ; =============
+20 ; if error MAGRY = Failure status ^ Error message^
+21 ; if success MAGRY = Success status ^^IEN - IEN of the new record
+22 ;
ADDQM(MAGRY,MAGPARAM,MAGMSG) ; RPC [MAGVA ENQUEUE Q MSG]
+1 ; build MAGMSG first - workaround for Old broker listener
+2 NEW L,LL
+3 SET L="MAGMSG"
SET LL=0
+4 KILL MAGMSG
+5 FOR
SET L=$ORDER(MAGPARAM(L))
if (L="")!($EXTRACT(L,1,6)'="MAGMSG")
QUIT
SET LL=LL+1
SET MAGMSG(LL)=MAGPARAM(L)
KILL MAGPARAM(L)
+6 ;
+7 NEW FILE,FILEQM,IENS,FLD,ISACTIVE
+8 NEW MAGWP
+9 KILL MAGRY
+10 ; Check if the queue exist and it is active
+11 SET IEN=$GET(MAGPARAM("QUEUE"))
+12 ; Check for QUEUE
+13 ; Error getting the IEN
IF IEN=""
SET MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Input parameter QUEUE is required."
QUIT
+14 ; Check if queue is active
+15 ; Queue file
SET FILE=2006.927
+16 SET IENS=IEN_","
+17 SET FLD=$$GETFLDID^MAGVAF01(FILE,"ACTIVE")
+18 ; get ACTIVE value
SET ISACTIVE=$$GET1^DIQ(FILE,IENS,FLD,"I")
+19 IF 'ISACTIVE
SET MAGRY=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"The queue is inactive"
QUIT
+20 ;
+21 SET MAGPARAM("EXPIRATION DATE/TIME")=$$IDF2FM^MAGVAF01($GET(MAGPARAM("EXPIRATION DATE/TIME")))
+22 SET MAGPARAM("EARLIEST DELIVERY DATE/TIME")=$$IDF2FM^MAGVAF01($GET(MAGPARAM("EARLIEST DELIVERY DATE/TIME")))
+23 SET MAGPARAM("ENQUEUED DATE/TIME")=$$NOW^XLFDT
+24 MERGE MAGWP("MESSAGE")=MAGMSG
+25 SET FILEQM=2006.928
+26 ; add the record
DO ADDRCD^MAGVAF01(.MAGRY,FILEQM,.MAGPARAM,.MAGWP)
+27 QUIT
+28 ;
+29 ;***** Find, return and remove a queue message from the QUEUE MESSAGE file (#2006.928)
+30 ; by QUEUE - IEN of record in QUEUE file (#2006.927)
+31 ; and by MESSAGE GROUP ID.
+32 ; If "MESSAGE GROUP ID" equals "*" it ignores "MESSAGE GROUP ID".
+33 ; If "MESSAGE GROUP ID" equals "" it looks only at queue messages with blank "MESSAGE GROUP ID".
+34 ; Otherwise looks at queue messages with MESSAGE GROUP ID
+35 ;
+36 ; RPC:MAGVA DEQUEUE Q MSG
+37 ;
+38 ; Input Parameters
+39 ;
+40 ; MAGPARAM("QUEUE") = IEN in QUEUE file (#2006.927)
+41 ; MAGPARAM("MESSAGE GROUP ID") = value of the field "MESSAGE GROUP ID"
+42 ; in QUEUE file (#2006.927) or "*" or ""
+43 ;
+44 ; if MAGPARAM("MESSAGE GROUP ID") = "*" return oldest
+45 ;
+46 ; Return Values
+47 ; =============
+48 ; if error MAGRY(0) = Failure status ^ Error message
+49 ; if success MAGRY(0) = Success status ^^IEN
+50 ; MAGRY(1..n) = The QUEUE MESSAGE
+51 ;
+52 ; if IEN equals 0 that means nothing was found
+53 ; ;
DEQM(MAGRY,MAGPARAM) ; RPC [MAGVA DEQUEUE Q MSG]
+1 KILL MAGRY
+2 DO FINDQM^MAGVAQ01(.MAGRY,.MAGPARAM,"D")
+3 QUIT
+4 ;
+5 ;***** Get a queue message from the QUEUE MESSAGE file (#2006.928)
+6 ; by QUEUE - IEN of record in QUEUE file (#2006.927)
+7 ; and by MESSAGE GROUP ID.
+8 ; If "MESSAGE GROUP ID" equals "*" it ignores "MESSAGE GROUP ID".
+9 ; If "MESSAGE GROUP ID" equals "" it looks only at queue messages with blank "MESSAGE GROUP ID".
+10 ; Otherwise looks at queue messages with MESSAGE GROUP ID
+11 ;
+12 ; RPC:MAGVA PEEK Q MSG
+13 ;
+14 ; Input Parameters
+15 ;
+16 ; MAGPARAM("QUEUE") = IEN in QUEUE file (#2006.927)
+17 ; MAGPARAM("MESSAGE GROUP ID") = value of the field "MESSAGE GROUP ID"
+18 ; in QUEUE file (#2006.927) or "*" or ""
+19 ;
+20 ; Return Values
+21 ; =============
+22 ; if error MAGRY(0) = Failure status ^ Error message
+23 ; if success MAGRY(0) = Success status ^^IEN
+24 ; MAGRY(1..n) = The QUEUE MESSAGE
+25 ;
+26 ; if IEN equals 0 that means nothing was found
+27 ;
PEEKQM(MAGRY,MAGPARAM) ; RPC [MAGVA PEEK Q MSG]
+1 KILL MAGRY
+2 DO FINDQM^MAGVAQ01(.MAGRY,.MAGPARAM,"")
+3 QUIT
+4 ;
+5 ;+++++ Find, return and remove a queue message from the QUEUE MESSAGE file (#2006.928)
+6 ; by QUEUE - IEN of record in QUEUE file (#2006.927)
+7 ; The message will have the EARLIEST DELIVERY DATE/TIME equals NULL or the EARLIEST DELIVERY DATE/TIME less than
+8 ; current date/time
+9 ; and the EXPIRATION DATE/TIME equals NULL or the EXPIRATION DATE/TIME greater than current date/time.
+10 ;
+11 ; Delete the message if the flag is set
+12 ;
+13 ; Input Parameters
+14 ; ================
+15 ;
+16 ; MAGPARAM("QUEUE") = IEN in QUEUE file (#2006.927)
+17 ; MAGPARAM("MESSAGE GROUP ID") = value of the field "MESSAGE GROUP ID"
+18 ; in QUEUE file (#2006.927) or "*" or ""
+19 ; FLAGS = [D] delete the message from QUEUE MESSAGE file (#2006.928)
+20 ;
+21 ; Return Values
+22 ; =============
+23 ; if error MAGRY(0) = Failure status ^ Error message
+24 ; if success MAGRY(0) = Success status ^^IEN
+25 ; MAGRY(1..n) = The QUEUE MESSAGE
+26 ;
+27 ; if IEN equals 0 that means nothing was found
+28 ;
FINDQM(MAGRY,MAGPARAM,FLAGS) ;
+1 NEW MAGDT,IEN,FILE,FLDMINDT,FLDEXPDT
+2 NEW ERRMSG,FOUND
+3 NEW QUEUEIEN,MSGGRPID
+4 SET QUEUEIEN=$GET(MAGPARAM("QUEUE"))
+5 SET MSGGRPID=$GET(MAGPARAM("MESSAGE GROUP ID"))
+6 ; Queue Message file
SET FILE=2006.928
+7 SET FLDMINDT=$$GETFLDID^MAGVAF01(FILE,"EARLIEST DELIVERY DATE/TIME")
+8 SET FLDEXPDT=$$GETFLDID^MAGVAF01(FILE,"EXPIRATION DATE/TIME")
+9 ; Check for QUEUE
+10 ; Error getting the IEN
IF QUEUEIEN=""
SET MAGRY(0)=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Input parameter QUEUE is required."
QUIT
+11 SET FOUND=0
+12 SET ERRMSG=""
+13 IF MSGGRPID="*"
Begin DoDot:1
+14 ; Use ENQDT index to loop through the queue and enqueued dates
+15 ; For each IEN found check if the EARLIEST DELIVERY DATE/TIME is NULL OR the EARLIEST DELIVERY DATE/TIME < NOW)
+16 ; and (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW) then quit and return the IEN
+17 SET MAGDT=""
+18 ; If an eligible Queue message was found. IEN will be set to this record
SET FOUND=0
+19 FOR
if (ERRMSG'="")!FOUND
QUIT
SET MAGDT=$ORDER(^MAGV(FILE,"ENQDT",QUEUEIEN,MAGDT))
if MAGDT=""
QUIT
Begin DoDot:2
+20 SET IEN=""
+21 FOR
if (ERRMSG'="")!FOUND
QUIT
SET IEN=$ORDER(^MAGV(FILE,"ENQDT",QUEUEIEN,MAGDT,IEN))
if IEN=""
QUIT
Begin DoDot:3
+22 ; see if we meet the criteria
SET FOUND=$$CHECKQM^MAGVAQ01(.ERRMSG,FILE,IEN,FLDMINDT,FLDEXPDT)
+23 IF ERRMSG'=""
SET MAGRY(0)=ERRMSG
+24 QUIT
End DoDot:3
+25 QUIT
End DoDot:2
+26 QUIT
End DoDot:1
+27 ;
+28 IF MSGGRPID=""
Begin DoDot:1
+29 ; Use ENQBLDT index to loop through the queue and enqueued dates
+30 ; For each IEN found check if the EARLIEST DELIVERY DATE/TIME is NULL OR the EARLIEST DELIVERY DATE/TIME < NOW)
+31 ; and (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW) then quit and return the IEN
+32 SET MAGDT=""
+33 ; If an eligible Queue message was found. IEN will be set to this record
SET FOUND=0
+34 FOR
if (ERRMSG'="")!FOUND
QUIT
SET MAGDT=$ORDER(^MAGV(FILE,"ENQBLDT",QUEUEIEN,MAGDT))
if MAGDT=""
QUIT
Begin DoDot:2
+35 SET IEN=""
+36 FOR
if (ERRMSG'="")!FOUND
QUIT
SET IEN=$ORDER(^MAGV(FILE,"ENQBLDT",QUEUEIEN,MAGDT,IEN))
if IEN=""
QUIT
Begin DoDot:3
+37 ; see if we meet the criteria
SET FOUND=$$CHECKQM^MAGVAQ01(.ERRMSG,FILE,IEN,FLDMINDT,FLDEXPDT)
+38 IF ERRMSG'=""
SET MAGRY(0)=ERRMSG
+39 QUIT
End DoDot:3
+40 QUIT
End DoDot:2
+41 QUIT
End DoDot:1
+42 ;
+43 IF (MSGGRPID'="")
IF (MSGGRPID'="*")
Begin DoDot:1
+44 ; Use ENQPLDT index to loop through the queue, place and enqueued dates
+45 ; For each IEN found check if the EARLIEST DELIVERY DATE/TIME is NULL OR the EARLIEST DELIVERY DATE/TIME < NOW)
+46 ; and (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW) then quit and return the IEN
+47 SET MAGDT=""
+48 ; If an eligible Queue message was found. IEN will be set to this record
SET FOUND=0
+49 FOR
if (ERRMSG'="")!FOUND
QUIT
SET MAGDT=$ORDER(^MAGV(FILE,"ENQPLDT",QUEUEIEN,MSGGRPID,MAGDT))
if MAGDT=""
QUIT
Begin DoDot:2
+50 SET IEN=""
+51 FOR
if (ERRMSG'="")!FOUND
QUIT
SET IEN=$ORDER(^MAGV(FILE,"ENQPLDT",QUEUEIEN,MSGGRPID,MAGDT,IEN))
if IEN=""
QUIT
Begin DoDot:3
+52 ; see if we meet the criteria
SET FOUND=$$CHECKQM^MAGVAQ01(.ERRMSG,FILE,IEN,FLDMINDT,FLDEXPDT)
+53 IF ERRMSG'=""
SET MAGRY(0)=ERRMSG
+54 QUIT
End DoDot:3
+55 QUIT
End DoDot:2
+56 QUIT
End DoDot:1
+57 ; Quit - Found error getting values
IF ERRMSG'=""
QUIT
+58 ;
+59 IF 'FOUND
SET MAGRY(0)=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_0
QUIT
+60 ;
+61 ; Get the message and delete it from the queue if the flag is set
+62 ;
+63 DO GXMLBYPK^MAGVAF03(.MAGRY,FILE,IEN,0)
+64 ; Check for error and quit if we have one
IF '$$ISOK^MAGVAF02(MAGRY(0))
QUIT
+65 ;
+66 ; Delete the message from QUEUE MESSAGE file (#2006.928)
+67 IF FLAGS["D"
Begin DoDot:1
+68 NEW DA,DIK
+69 SET DIK=$$GETFILGL^MAGVAF01(FILE)
+70 SET DA=IEN
+71 DO ^DIK
+72 QUIT
End DoDot:1
+73 SET MAGRY(0)=$$OK^MAGVAF02()_$$RESDEL^MAGVAF02()_$$RESDEL^MAGVAF02()_IEN
+74 QUIT
+75 ;
+76 ; ++++ Returns 1 if it meets the criteria, if not returns 0
+77 ; Check if (the EARLIEST DELIVERY DATE/TIME is NULL or the EARLIEST DELIVERY DATE/TIME < NOW)
+78 ; and (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW)
+79 ;
+80 ; Input Parameters
+81 ; ================
+82 ; FILE = QUEUE MESSAGE file (#2006.928)
+83 ; IEN = IEN in QUEUE MESSAGE file (#2006.928)
+84 ; FLDMINDT = EARLIEST DELIVERY DATE/TIME field number in QUEUE MESSAGE file (#2006.928)
+85 ; FLDEXPDT = EXPIRATION DATE/TIME field number in QUEUE MESSAGE file (#2006.928)
+86 ;
+87 ; Return Values
+88 ; =============
+89 ; if error ERRMSG = Failure status ^ Error message^
+90 ;
CHECKQM(ERRMSG,FILE,IEN,FLDMINDT,FLDEXPDT) ; Returns 1 if it meets the criteria, if not returns 0
+1 NEW ERR,FIELDS,OUT,IENS,MAGRESA,FOUND
+2 NEW NOW
+3 SET FOUND=0
+4 SET FIELDS=FLDMINDT_";"_FLDEXPDT
+5 SET IENS=IEN_","
+6 ; get EARLIEST DELIVERY DATE/TIME and EXPIRATION DATE/TIME values
DO GETS^DIQ(FILE,IENS,FIELDS,"I","OUT","ERR")
+7 IF $DATA(ERR("DIERR"))
Begin DoDot:1
+8 DO MSG^DIALOG("A",.MAGRESA,245,5,"ERR")
+9 ; Error getting the values
SET ERRMSG=$$FAILED^MAGVAF02()_$$RESDEL^MAGVAF02()_"Error getting values: "_MAGRESA(1)
QUIT
+10 QUIT
End DoDot:1
QUIT 0
+11 ;
+12 ; Get the oldest QUEUE MESSAGE where
+13 ; (the EARLIEST DELIVERY DATE/TIME is NULL OR the EARLIEST DELIVERY DATE/TIME < NOW)
+14 ; AND (the EXPIRATION DATE/TIME is NULL OR the EXPIRATION DATE/TIME > NOW)
+15 ;
+16 SET NOW=$$NOW^XLFDT
+17 IF ((OUT(FILE,IENS,FLDMINDT,"I")="")!(OUT(FILE,IENS,FLDMINDT,"I")<NOW))&((OUT(FILE,IENS,FLDEXPDT,"I")="")!(OUT(FILE,IENS,FLDEXPDT,"I")>NOW))
SET FOUND=1
+18 QUIT FOUND