MAGGA03 ;WOIFO/SG - REMOTE PROCEDURES FOR IMAGE QUERIES ; 5/8/09 10:10am
;;3.0;IMAGING;**93**;Dec 02, 2009;Build 163
;; 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
;
;***** RETURNS VARIOUS IMAGE STATISTICS DATA
; RPC: MAGG IMAGE STATISTICS
;
; .MAGRESULTS Reference to a local variable where the results
; are returned to.
;
; FLAGS Flags that control the execution (can be combined):
;
; C Capture date range. If this flag is provided,
; then the remote procedure uses values of the
; FROMDATE and TODATE parameters to select images
; that were captured in this date range.
;
; Otherwise, values of those parameters are
; treated as the date range when procedures were
; performed.
;
; D Include only deleted images (file #2005.1)
; E Include only existing images (file #2005)
;
; S Return image counts grouped by status
; U Return image counts grouped by users and status
;
; If neither 'E' nor 'D' flag is provided, then an
; error (-6) is returned.
;
; If neither 'S' nor 'U' flag is provided, then an
; error (-6) is returned.
;
; [FROMDATE] Date range for image selection. Dates can be in
; [TODATE] internal or external FileMan format. If a date
; parameter is not defined or empty, then the date
; range remains open on the corresponding side.
;
; Time parts of parameter values are ignored and both
; ends of the date range are included in the search.
; For example, in order to search images for May 21,
; 2008, the inernal value of both parameters should
; be 3080521.
;
; If the FROMDATE is after the TODATE, then values of
; the parameters are swapped.
;
; Return Values
; =============
;
; Zero value of the 1st '^'-piece of the @MAGRESULTS@(0) indicates an
; error during execution of the procedure. In this case, the array
; is formatted as described in the comments to the RPCERRS^MAGUERR1.
;
; Otherwise, the array contains the requested data. See description
; of the MAGG IMAGE STATISTICS remote procedure for details.
;
; Notes
; =====
;
; Temporary global nodes ^TMP("MAGGA03",$J) and ^TMP("MAGGA03A,$J")
; are used by this procedure.
;
IMGQUERY(MAGRESULTS,FLAGS,FROMDATE,TODATE) ;RPC [MAGG IMAGE STATISTICS]
N RC
S MAGRESULTS=$NA(^TMP("MAGGA03",$J))
K ^TMP("MAGGA03A",$J),@MAGRESULTS
S (@MAGRESULTS@(0),RC)=0
D CLEAR^MAGUERR(1)
;
D
. N MAGDATA ; Data for the image query callback function
. N MAGSTCACHE ; Local cache for image status descriptions
. N EDT,ERROR,QF
. ;
. ;=== Validate parameters
. S FLAGS=$G(FLAGS),ERROR=0
. ;--- Unknown/Unsupported flag(s)
. I $TR(FLAGS,"CDESU")'="" D IPVE^MAGUERR("FLAGS") S ERROR=1
. ;--- Missing required flag(s)
. I $TR(FLAGS,"DE")=FLAGS D ERROR^MAGUERR(-6,,"D,E") S ERROR=1
. I $TR(FLAGS,"SU")=FLAGS D ERROR^MAGUERR(-6,,"S,U") S ERROR=1
. ;--- Date range
. S:$$DTRANGE^MAGUTL03(.FROMDATE,.TODATE)<0 ERROR=1
. ;--- Abort in case of error(s)
. I ERROR D ERROR^MAGUERR(-30) S RC=$$FIRSTERR^MAGUERR1() Q
. ;
. ;=== Query the image file(s)
. S EDT=$S(TODATE<9999999:$$FMADD^XLFDT(TODATE,1),1:TODATE)
. ;--- Pass the original flags to the callback function
. S MAGDATA("FLAGS")=FLAGS
. ;--- Remove flags that are not supported by the $$QUERY^MAGGI13
. S QF=$$TRFLAGS^MAGUTL05(FLAGS,"CDE")
. ;--- Execute the query
. S RC=$$QUERY^MAGGI13("$$QRYCBK^MAGGA03A",QF,.MAGDATA,FROMDATE,EDT)
. Q:RC<0
. ;
. ;=== Calculate image counts and store them to the result array
. I FLAGS["S" S RC=$$SECTIONS(MAGRESULTS) Q:RC<0
. I FLAGS["U" S RC=$$SECTIONU(MAGRESULTS) Q:RC<0
. Q
;
;=== Cleanup
K ^TMP("MAGGA03A",$J)
I RC<0 D RPCERRS^MAGUERR1(.MAGRESULTS,RC) Q
S @MAGRESULTS@(0)="1^Ok"
Q
;
;+++++ APPENDS IMAGE COUNTS BY STATUS TO THE RESULT ARRAY
;
; MAGRESULTS Name of the global node where the results
; are returned to.
;
; Input Variables
; ===============
; ^TMP("MAGGA03A",$J,"S",...)
;
; Return Values
; =============
; <0 Error descriptor (see the $$ERROR^MAGUERR)
; 0 Success
;
SECTIONS(MAGRESULTS) ;
N BASE,CNT,I,SCNT,STC,TMP,SVPCT
;--- Reserve the spot for the section header
S (BASE,CNT)=$O(@MAGRESULTS@(""),-1)+1,SCNT=0
;--- Store counts for each status and calculate the totals
S STC=""
F S STC=$O(^TMP("MAGGA03A",$J,"S",STC)) Q:STC="" D
. S SCNT=SCNT+1,TMP=^TMP("MAGGA03A",$J,"S",STC)
. S CNT=CNT+1,@MAGRESULTS@(CNT)="S^"_SCNT_U_U_$$STATUS(STC)_U_TMP
. F I=1,2 S SCNT(I)=$G(SCNT(I))+$P(TMP,U,I)
. Q
;--- Store the header of the "S"-section
S TMP="S^^"_SCNT_"^^Totals"
S SVPCT=$S($G(SCNT(1)):$J($G(^TMP("MAGGA03A",$J,"S",2))/SCNT(1)*100,0,2),1:"") ; 2 - QA Reviewed
S @MAGRESULTS@(BASE)=TMP_U_$G(SCNT(1))_U_$G(SCNT(2))_U_SVPCT
Q 0
;
;+++++ APPENDS IMAGE COUNTS BY USERS AND STATUS TO THE RESULT ARRAY
;
; MAGRESULTS Name of the global node where the results
; are returned to.
;
; Input Variables
; ===============
; ^TMP("MAGGA03A",$J,"U",...)
;
; Return Values
; =============
; <0 Error descriptor (see the $$ERROR^MAGUERR)
; 0 Success
;
SECTIONU(MAGRESULTS) ;
N BASE,CNT,I,IEN,NAME,STC,TMP,UCNT,UPTR,USCNT,UVPCT,UVCNT,NAMESRT
;=== Reserve the spot for the section header
S (BASE,CNT)=$O(@MAGRESULTS@(""),-1)+1,UCNT=0
;=== Store counts for each user and calculate the totals
K ^TMP("MAGGA03A.NAME",$J)
S IEN=""
F S IEN=$O(^TMP("MAGGA03A",$J,"U",IEN)) Q:IEN="" D
. ;--- Get the user's name
. S NAME=""
. I IEN>0 D
. . S NAME=$$NAME^XUSER(IEN,"F")
. . S:NAME="" NAME="Invalid User IEN: "_IEN
. . Q
. S NAMESRT=NAME_"~"_IEN
. S ^TMP("MAGGA03A.NAME",$J,NAMESRT)=IEN
. Q
S NAMESRT=""
S UVCNT=0
F S NAMESRT=$O(^TMP("MAGGA03A.NAME",$J,NAMESRT)) Q:NAMESRT="" D
. S NAME=$P(NAMESRT,"~")
. S IEN=^TMP("MAGGA03A.NAME",$J,NAMESRT)
. ;--- Reserve the spot for the the "U"-item
. S UCNT=UCNT+1,(CNT,UPTR)=CNT+1
. K USCNT S USCNT=0
. ;--- Process the user's counts (by status)
. S STC=""
. F S STC=$O(^TMP("MAGGA03A",$J,"U",IEN,STC)) Q:STC="" D
. . S USCNT=USCNT+1,TMP=^TMP("MAGGA03A",$J,"U",IEN,STC)
. . S CNT=CNT+1,@MAGRESULTS@(CNT)="US^"_USCNT_U_U_$$STATUS(STC)_U_TMP
. . F I=1,2 S USCNT(I)=$G(USCNT(I))+$P(TMP,U,I)
. . Q
. ;--- Calculate verification percentage
. I $G(USCNT(1))>0 D
. . S TMP=+$G(^TMP("MAGGA03A",$J,"U",IEN,2))
. . S UVPCT=+$J(TMP/USCNT(1)*100,0,2)
. . S UVCNT=UVCNT+TMP
. . Q
. E S UVPCT=""
. ;
. ;--- Store the "U"-item
. S TMP="U^"_UCNT_U_USCNT_U_$S(IEN>0:IEN,1:"")_U_NAME
. S @MAGRESULTS@(UPTR)=TMP_U_$G(USCNT(1))_U_$G(USCNT(2))_U_UVPCT
. F I=1,2 S UCNT(I)=$G(UCNT(I))+$G(USCNT(I))
. Q
;=== Store the header of the "U"-section
S TMP="U^^"_UCNT_"^^Totals"
S @MAGRESULTS@(BASE)=TMP_U_$G(UCNT(1))_U_$G(UCNT(2))_U_$S($G(UCNT(1)):$J(UVCNT/UCNT(1)*100,0,2),1:"")
K ^TMP("MAGGA03A.NAME",$J)
Q 0
;
;+++++ RETURNS THE STATUS CODE AND DESCRIPTION
;
; STC Image status code
;
; Input Variables
; ===============
; MAGSTCACHE
;
; Output Variables
; ================
; MAGSTCACHE
;
; Return Values
; =============
; StatusCode^StatusDescription
;
STATUS(STC) ;
Q:STC'>0 U
S:'$D(MAGSTCACHE(STC)) MAGSTCACHE(STC)=STC_U_$$IMGSTDSC^MAGGI11(STC)
Q MAGSTCACHE(STC)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGGA03 8859 printed Sep 11, 2024@02:22:18 Page 2
MAGGA03 ;WOIFO/SG - REMOTE PROCEDURES FOR IMAGE QUERIES ; 5/8/09 10:10am
+1 ;;3.0;IMAGING;**93**;Dec 02, 2009;Build 163
+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 ;; | |
+11 ;; | The Food and Drug Administration classifies this software as |
+12 ;; | a medical device. As such, it may not be changed in any way. |
+13 ;; | Modifications to this software may result in an adulterated |
+14 ;; | medical device under 21CFR820, the use of which is considered |
+15 ;; | to be a violation of US Federal Statutes. |
+16 ;; +---------------------------------------------------------------+
+17 ;;
+18 QUIT
+19 ;
+20 ;***** RETURNS VARIOUS IMAGE STATISTICS DATA
+21 ; RPC: MAGG IMAGE STATISTICS
+22 ;
+23 ; .MAGRESULTS Reference to a local variable where the results
+24 ; are returned to.
+25 ;
+26 ; FLAGS Flags that control the execution (can be combined):
+27 ;
+28 ; C Capture date range. If this flag is provided,
+29 ; then the remote procedure uses values of the
+30 ; FROMDATE and TODATE parameters to select images
+31 ; that were captured in this date range.
+32 ;
+33 ; Otherwise, values of those parameters are
+34 ; treated as the date range when procedures were
+35 ; performed.
+36 ;
+37 ; D Include only deleted images (file #2005.1)
+38 ; E Include only existing images (file #2005)
+39 ;
+40 ; S Return image counts grouped by status
+41 ; U Return image counts grouped by users and status
+42 ;
+43 ; If neither 'E' nor 'D' flag is provided, then an
+44 ; error (-6) is returned.
+45 ;
+46 ; If neither 'S' nor 'U' flag is provided, then an
+47 ; error (-6) is returned.
+48 ;
+49 ; [FROMDATE] Date range for image selection. Dates can be in
+50 ; [TODATE] internal or external FileMan format. If a date
+51 ; parameter is not defined or empty, then the date
+52 ; range remains open on the corresponding side.
+53 ;
+54 ; Time parts of parameter values are ignored and both
+55 ; ends of the date range are included in the search.
+56 ; For example, in order to search images for May 21,
+57 ; 2008, the inernal value of both parameters should
+58 ; be 3080521.
+59 ;
+60 ; If the FROMDATE is after the TODATE, then values of
+61 ; the parameters are swapped.
+62 ;
+63 ; Return Values
+64 ; =============
+65 ;
+66 ; Zero value of the 1st '^'-piece of the @MAGRESULTS@(0) indicates an
+67 ; error during execution of the procedure. In this case, the array
+68 ; is formatted as described in the comments to the RPCERRS^MAGUERR1.
+69 ;
+70 ; Otherwise, the array contains the requested data. See description
+71 ; of the MAGG IMAGE STATISTICS remote procedure for details.
+72 ;
+73 ; Notes
+74 ; =====
+75 ;
+76 ; Temporary global nodes ^TMP("MAGGA03",$J) and ^TMP("MAGGA03A,$J")
+77 ; are used by this procedure.
+78 ;
IMGQUERY(MAGRESULTS,FLAGS,FROMDATE,TODATE) ;RPC [MAGG IMAGE STATISTICS]
+1 NEW RC
+2 SET MAGRESULTS=$NAME(^TMP("MAGGA03",$JOB))
+3 KILL ^TMP("MAGGA03A",$JOB),@MAGRESULTS
+4 SET (@MAGRESULTS@(0),RC)=0
+5 DO CLEAR^MAGUERR(1)
+6 ;
+7 Begin DoDot:1
+8 ; Data for the image query callback function
NEW MAGDATA
+9 ; Local cache for image status descriptions
NEW MAGSTCACHE
+10 NEW EDT,ERROR,QF
+11 ;
+12 ;=== Validate parameters
+13 SET FLAGS=$GET(FLAGS)
SET ERROR=0
+14 ;--- Unknown/Unsupported flag(s)
+15 IF $TRANSLATE(FLAGS,"CDESU")'=""
DO IPVE^MAGUERR("FLAGS")
SET ERROR=1
+16 ;--- Missing required flag(s)
+17 IF $TRANSLATE(FLAGS,"DE")=FLAGS
DO ERROR^MAGUERR(-6,,"D,E")
SET ERROR=1
+18 IF $TRANSLATE(FLAGS,"SU")=FLAGS
DO ERROR^MAGUERR(-6,,"S,U")
SET ERROR=1
+19 ;--- Date range
+20 if $$DTRANGE^MAGUTL03(.FROMDATE,.TODATE)<0
SET ERROR=1
+21 ;--- Abort in case of error(s)
+22 IF ERROR
DO ERROR^MAGUERR(-30)
SET RC=$$FIRSTERR^MAGUERR1()
QUIT
+23 ;
+24 ;=== Query the image file(s)
+25 SET EDT=$SELECT(TODATE<9999999:$$FMADD^XLFDT(TODATE,1),1:TODATE)
+26 ;--- Pass the original flags to the callback function
+27 SET MAGDATA("FLAGS")=FLAGS
+28 ;--- Remove flags that are not supported by the $$QUERY^MAGGI13
+29 SET QF=$$TRFLAGS^MAGUTL05(FLAGS,"CDE")
+30 ;--- Execute the query
+31 SET RC=$$QUERY^MAGGI13("$$QRYCBK^MAGGA03A",QF,.MAGDATA,FROMDATE,EDT)
+32 if RC<0
QUIT
+33 ;
+34 ;=== Calculate image counts and store them to the result array
+35 IF FLAGS["S"
SET RC=$$SECTIONS(MAGRESULTS)
if RC<0
QUIT
+36 IF FLAGS["U"
SET RC=$$SECTIONU(MAGRESULTS)
if RC<0
QUIT
+37 QUIT
End DoDot:1
+38 ;
+39 ;=== Cleanup
+40 KILL ^TMP("MAGGA03A",$JOB)
+41 IF RC<0
DO RPCERRS^MAGUERR1(.MAGRESULTS,RC)
QUIT
+42 SET @MAGRESULTS@(0)="1^Ok"
+43 QUIT
+44 ;
+45 ;+++++ APPENDS IMAGE COUNTS BY STATUS TO THE RESULT ARRAY
+46 ;
+47 ; MAGRESULTS Name of the global node where the results
+48 ; are returned to.
+49 ;
+50 ; Input Variables
+51 ; ===============
+52 ; ^TMP("MAGGA03A",$J,"S",...)
+53 ;
+54 ; Return Values
+55 ; =============
+56 ; <0 Error descriptor (see the $$ERROR^MAGUERR)
+57 ; 0 Success
+58 ;
SECTIONS(MAGRESULTS) ;
+1 NEW BASE,CNT,I,SCNT,STC,TMP,SVPCT
+2 ;--- Reserve the spot for the section header
+3 SET (BASE,CNT)=$ORDER(@MAGRESULTS@(""),-1)+1
SET SCNT=0
+4 ;--- Store counts for each status and calculate the totals
+5 SET STC=""
+6 FOR
SET STC=$ORDER(^TMP("MAGGA03A",$JOB,"S",STC))
if STC=""
QUIT
Begin DoDot:1
+7 SET SCNT=SCNT+1
SET TMP=^TMP("MAGGA03A",$JOB,"S",STC)
+8 SET CNT=CNT+1
SET @MAGRESULTS@(CNT)="S^"_SCNT_U_U_$$STATUS(STC)_U_TMP
+9 FOR I=1,2
SET SCNT(I)=$GET(SCNT(I))+$PIECE(TMP,U,I)
+10 QUIT
End DoDot:1
+11 ;--- Store the header of the "S"-section
+12 SET TMP="S^^"_SCNT_"^^Totals"
+13 ; 2 - QA Reviewed
SET SVPCT=$SELECT($GET(SCNT(1)):$JUSTIFY($GET(^TMP("MAGGA03A",$JOB,"S",2))/SCNT(1)*100,0,2),1:"")
+14 SET @MAGRESULTS@(BASE)=TMP_U_$GET(SCNT(1))_U_$GET(SCNT(2))_U_SVPCT
+15 QUIT 0
+16 ;
+17 ;+++++ APPENDS IMAGE COUNTS BY USERS AND STATUS TO THE RESULT ARRAY
+18 ;
+19 ; MAGRESULTS Name of the global node where the results
+20 ; are returned to.
+21 ;
+22 ; Input Variables
+23 ; ===============
+24 ; ^TMP("MAGGA03A",$J,"U",...)
+25 ;
+26 ; Return Values
+27 ; =============
+28 ; <0 Error descriptor (see the $$ERROR^MAGUERR)
+29 ; 0 Success
+30 ;
SECTIONU(MAGRESULTS) ;
+1 NEW BASE,CNT,I,IEN,NAME,STC,TMP,UCNT,UPTR,USCNT,UVPCT,UVCNT,NAMESRT
+2 ;=== Reserve the spot for the section header
+3 SET (BASE,CNT)=$ORDER(@MAGRESULTS@(""),-1)+1
SET UCNT=0
+4 ;=== Store counts for each user and calculate the totals
+5 KILL ^TMP("MAGGA03A.NAME",$JOB)
+6 SET IEN=""
+7 FOR
SET IEN=$ORDER(^TMP("MAGGA03A",$JOB,"U",IEN))
if IEN=""
QUIT
Begin DoDot:1
+8 ;--- Get the user's name
+9 SET NAME=""
+10 IF IEN>0
Begin DoDot:2
+11 SET NAME=$$NAME^XUSER(IEN,"F")
+12 if NAME=""
SET NAME="Invalid User IEN: "_IEN
+13 QUIT
End DoDot:2
+14 SET NAMESRT=NAME_"~"_IEN
+15 SET ^TMP("MAGGA03A.NAME",$JOB,NAMESRT)=IEN
+16 QUIT
End DoDot:1
+17 SET NAMESRT=""
+18 SET UVCNT=0
+19 FOR
SET NAMESRT=$ORDER(^TMP("MAGGA03A.NAME",$JOB,NAMESRT))
if NAMESRT=""
QUIT
Begin DoDot:1
+20 SET NAME=$PIECE(NAMESRT,"~")
+21 SET IEN=^TMP("MAGGA03A.NAME",$JOB,NAMESRT)
+22 ;--- Reserve the spot for the the "U"-item
+23 SET UCNT=UCNT+1
SET (CNT,UPTR)=CNT+1
+24 KILL USCNT
SET USCNT=0
+25 ;--- Process the user's counts (by status)
+26 SET STC=""
+27 FOR
SET STC=$ORDER(^TMP("MAGGA03A",$JOB,"U",IEN,STC))
if STC=""
QUIT
Begin DoDot:2
+28 SET USCNT=USCNT+1
SET TMP=^TMP("MAGGA03A",$JOB,"U",IEN,STC)
+29 SET CNT=CNT+1
SET @MAGRESULTS@(CNT)="US^"_USCNT_U_U_$$STATUS(STC)_U_TMP
+30 FOR I=1,2
SET USCNT(I)=$GET(USCNT(I))+$PIECE(TMP,U,I)
+31 QUIT
End DoDot:2
+32 ;--- Calculate verification percentage
+33 IF $GET(USCNT(1))>0
Begin DoDot:2
+34 SET TMP=+$GET(^TMP("MAGGA03A",$JOB,"U",IEN,2))
+35 SET UVPCT=+$JUSTIFY(TMP/USCNT(1)*100,0,2)
+36 SET UVCNT=UVCNT+TMP
+37 QUIT
End DoDot:2
+38 IF '$TEST
SET UVPCT=""
+39 ;
+40 ;--- Store the "U"-item
+41 SET TMP="U^"_UCNT_U_USCNT_U_$SELECT(IEN>0:IEN,1:"")_U_NAME
+42 SET @MAGRESULTS@(UPTR)=TMP_U_$GET(USCNT(1))_U_$GET(USCNT(2))_U_UVPCT
+43 FOR I=1,2
SET UCNT(I)=$GET(UCNT(I))+$GET(USCNT(I))
+44 QUIT
End DoDot:1
+45 ;=== Store the header of the "U"-section
+46 SET TMP="U^^"_UCNT_"^^Totals"
+47 SET @MAGRESULTS@(BASE)=TMP_U_$GET(UCNT(1))_U_$GET(UCNT(2))_U_$SELECT($GET(UCNT(1)):$JUSTIFY(UVCNT/UCNT(1)*100,0,2),1:"")
+48 KILL ^TMP("MAGGA03A.NAME",$JOB)
+49 QUIT 0
+50 ;
+51 ;+++++ RETURNS THE STATUS CODE AND DESCRIPTION
+52 ;
+53 ; STC Image status code
+54 ;
+55 ; Input Variables
+56 ; ===============
+57 ; MAGSTCACHE
+58 ;
+59 ; Output Variables
+60 ; ================
+61 ; MAGSTCACHE
+62 ;
+63 ; Return Values
+64 ; =============
+65 ; StatusCode^StatusDescription
+66 ;
STATUS(STC) ;
+1 if STC'>0
QUIT U
+2 if '$DATA(MAGSTCACHE(STC))
SET MAGSTCACHE(STC)=STC_U_$$IMGSTDSC^MAGGI11(STC)
+3 QUIT MAGSTCACHE(STC)