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

MAGGA03.m

Go to the documentation of this file.
  1. MAGGA03 ;WOIFO/SG - REMOTE PROCEDURES FOR IMAGE QUERIES ; 5/8/09 10:10am
  1. ;;3.0;IMAGING;**93**;Dec 02, 2009;Build 163
  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. ;; | |
  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. ;
  1. ;***** RETURNS VARIOUS IMAGE STATISTICS DATA
  1. ; RPC: MAGG IMAGE STATISTICS
  1. ;
  1. ; .MAGRESULTS Reference to a local variable where the results
  1. ; are returned to.
  1. ;
  1. ; FLAGS Flags that control the execution (can be combined):
  1. ;
  1. ; C Capture date range. If this flag is provided,
  1. ; then the remote procedure uses values of the
  1. ; FROMDATE and TODATE parameters to select images
  1. ; that were captured in this date range.
  1. ;
  1. ; Otherwise, values of those parameters are
  1. ; treated as the date range when procedures were
  1. ; performed.
  1. ;
  1. ; D Include only deleted images (file #2005.1)
  1. ; E Include only existing images (file #2005)
  1. ;
  1. ; S Return image counts grouped by status
  1. ; U Return image counts grouped by users and status
  1. ;
  1. ; If neither 'E' nor 'D' flag is provided, then an
  1. ; error (-6) is returned.
  1. ;
  1. ; If neither 'S' nor 'U' flag is provided, then an
  1. ; error (-6) is returned.
  1. ;
  1. ; [FROMDATE] Date range for image selection. Dates can be in
  1. ; [TODATE] internal or external FileMan format. If a date
  1. ; parameter is not defined or empty, then the date
  1. ; range remains open on the corresponding side.
  1. ;
  1. ; Time parts of parameter values are ignored and both
  1. ; ends of the date range are included in the search.
  1. ; For example, in order to search images for May 21,
  1. ; 2008, the inernal value of both parameters should
  1. ; be 3080521.
  1. ;
  1. ; If the FROMDATE is after the TODATE, then values of
  1. ; the parameters are swapped.
  1. ;
  1. ; Return Values
  1. ; =============
  1. ;
  1. ; Zero value of the 1st '^'-piece of the @MAGRESULTS@(0) indicates an
  1. ; error during execution of the procedure. In this case, the array
  1. ; is formatted as described in the comments to the RPCERRS^MAGUERR1.
  1. ;
  1. ; Otherwise, the array contains the requested data. See description
  1. ; of the MAGG IMAGE STATISTICS remote procedure for details.
  1. ;
  1. ; Notes
  1. ; =====
  1. ;
  1. ; Temporary global nodes ^TMP("MAGGA03",$J) and ^TMP("MAGGA03A,$J")
  1. ; are used by this procedure.
  1. ;
  1. IMGQUERY(MAGRESULTS,FLAGS,FROMDATE,TODATE) ;RPC [MAGG IMAGE STATISTICS]
  1. N RC
  1. S MAGRESULTS=$NA(^TMP("MAGGA03",$J))
  1. K ^TMP("MAGGA03A",$J),@MAGRESULTS
  1. S (@MAGRESULTS@(0),RC)=0
  1. D CLEAR^MAGUERR(1)
  1. ;
  1. D
  1. . N MAGDATA ; Data for the image query callback function
  1. . N MAGSTCACHE ; Local cache for image status descriptions
  1. . N EDT,ERROR,QF
  1. . ;
  1. . ;=== Validate parameters
  1. . S FLAGS=$G(FLAGS),ERROR=0
  1. . ;--- Unknown/Unsupported flag(s)
  1. . I $TR(FLAGS,"CDESU")'="" D IPVE^MAGUERR("FLAGS") S ERROR=1
  1. . ;--- Missing required flag(s)
  1. . I $TR(FLAGS,"DE")=FLAGS D ERROR^MAGUERR(-6,,"D,E") S ERROR=1
  1. . I $TR(FLAGS,"SU")=FLAGS D ERROR^MAGUERR(-6,,"S,U") S ERROR=1
  1. . ;--- Date range
  1. . S:$$DTRANGE^MAGUTL03(.FROMDATE,.TODATE)<0 ERROR=1
  1. . ;--- Abort in case of error(s)
  1. . I ERROR D ERROR^MAGUERR(-30) S RC=$$FIRSTERR^MAGUERR1() Q
  1. . ;
  1. . ;=== Query the image file(s)
  1. . S EDT=$S(TODATE<9999999:$$FMADD^XLFDT(TODATE,1),1:TODATE)
  1. . ;--- Pass the original flags to the callback function
  1. . S MAGDATA("FLAGS")=FLAGS
  1. . ;--- Remove flags that are not supported by the $$QUERY^MAGGI13
  1. . S QF=$$TRFLAGS^MAGUTL05(FLAGS,"CDE")
  1. . ;--- Execute the query
  1. . S RC=$$QUERY^MAGGI13("$$QRYCBK^MAGGA03A",QF,.MAGDATA,FROMDATE,EDT)
  1. . Q:RC<0
  1. . ;
  1. . ;=== Calculate image counts and store them to the result array
  1. . I FLAGS["S" S RC=$$SECTIONS(MAGRESULTS) Q:RC<0
  1. . I FLAGS["U" S RC=$$SECTIONU(MAGRESULTS) Q:RC<0
  1. . Q
  1. ;
  1. ;=== Cleanup
  1. K ^TMP("MAGGA03A",$J)
  1. I RC<0 D RPCERRS^MAGUERR1(.MAGRESULTS,RC) Q
  1. S @MAGRESULTS@(0)="1^Ok"
  1. Q
  1. ;
  1. ;+++++ APPENDS IMAGE COUNTS BY STATUS TO THE RESULT ARRAY
  1. ;
  1. ; MAGRESULTS Name of the global node where the results
  1. ; are returned to.
  1. ;
  1. ; Input Variables
  1. ; ===============
  1. ; ^TMP("MAGGA03A",$J,"S",...)
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; <0 Error descriptor (see the $$ERROR^MAGUERR)
  1. ; 0 Success
  1. ;
  1. SECTIONS(MAGRESULTS) ;
  1. N BASE,CNT,I,SCNT,STC,TMP,SVPCT
  1. ;--- Reserve the spot for the section header
  1. S (BASE,CNT)=$O(@MAGRESULTS@(""),-1)+1,SCNT=0
  1. ;--- Store counts for each status and calculate the totals
  1. S STC=""
  1. F S STC=$O(^TMP("MAGGA03A",$J,"S",STC)) Q:STC="" D
  1. . S SCNT=SCNT+1,TMP=^TMP("MAGGA03A",$J,"S",STC)
  1. . S CNT=CNT+1,@MAGRESULTS@(CNT)="S^"_SCNT_U_U_$$STATUS(STC)_U_TMP
  1. . F I=1,2 S SCNT(I)=$G(SCNT(I))+$P(TMP,U,I)
  1. . Q
  1. ;--- Store the header of the "S"-section
  1. S TMP="S^^"_SCNT_"^^Totals"
  1. S SVPCT=$S($G(SCNT(1)):$J($G(^TMP("MAGGA03A",$J,"S",2))/SCNT(1)*100,0,2),1:"") ; 2 - QA Reviewed
  1. S @MAGRESULTS@(BASE)=TMP_U_$G(SCNT(1))_U_$G(SCNT(2))_U_SVPCT
  1. Q 0
  1. ;
  1. ;+++++ APPENDS IMAGE COUNTS BY USERS AND STATUS TO THE RESULT ARRAY
  1. ;
  1. ; MAGRESULTS Name of the global node where the results
  1. ; are returned to.
  1. ;
  1. ; Input Variables
  1. ; ===============
  1. ; ^TMP("MAGGA03A",$J,"U",...)
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; <0 Error descriptor (see the $$ERROR^MAGUERR)
  1. ; 0 Success
  1. ;
  1. SECTIONU(MAGRESULTS) ;
  1. N BASE,CNT,I,IEN,NAME,STC,TMP,UCNT,UPTR,USCNT,UVPCT,UVCNT,NAMESRT
  1. ;=== Reserve the spot for the section header
  1. S (BASE,CNT)=$O(@MAGRESULTS@(""),-1)+1,UCNT=0
  1. ;=== Store counts for each user and calculate the totals
  1. K ^TMP("MAGGA03A.NAME",$J)
  1. S IEN=""
  1. F S IEN=$O(^TMP("MAGGA03A",$J,"U",IEN)) Q:IEN="" D
  1. . ;--- Get the user's name
  1. . S NAME=""
  1. . I IEN>0 D
  1. . . S NAME=$$NAME^XUSER(IEN,"F")
  1. . . S:NAME="" NAME="Invalid User IEN: "_IEN
  1. . . Q
  1. . S NAMESRT=NAME_"~"_IEN
  1. . S ^TMP("MAGGA03A.NAME",$J,NAMESRT)=IEN
  1. . Q
  1. S NAMESRT=""
  1. S UVCNT=0
  1. F S NAMESRT=$O(^TMP("MAGGA03A.NAME",$J,NAMESRT)) Q:NAMESRT="" D
  1. . S NAME=$P(NAMESRT,"~")
  1. . S IEN=^TMP("MAGGA03A.NAME",$J,NAMESRT)
  1. . ;--- Reserve the spot for the the "U"-item
  1. . S UCNT=UCNT+1,(CNT,UPTR)=CNT+1
  1. . K USCNT S USCNT=0
  1. . ;--- Process the user's counts (by status)
  1. . S STC=""
  1. . F S STC=$O(^TMP("MAGGA03A",$J,"U",IEN,STC)) Q:STC="" D
  1. . . S USCNT=USCNT+1,TMP=^TMP("MAGGA03A",$J,"U",IEN,STC)
  1. . . S CNT=CNT+1,@MAGRESULTS@(CNT)="US^"_USCNT_U_U_$$STATUS(STC)_U_TMP
  1. . . F I=1,2 S USCNT(I)=$G(USCNT(I))+$P(TMP,U,I)
  1. . . Q
  1. . ;--- Calculate verification percentage
  1. . I $G(USCNT(1))>0 D
  1. . . S TMP=+$G(^TMP("MAGGA03A",$J,"U",IEN,2))
  1. . . S UVPCT=+$J(TMP/USCNT(1)*100,0,2)
  1. . . S UVCNT=UVCNT+TMP
  1. . . Q
  1. . E S UVPCT=""
  1. . ;
  1. . ;--- Store the "U"-item
  1. . S TMP="U^"_UCNT_U_USCNT_U_$S(IEN>0:IEN,1:"")_U_NAME
  1. . S @MAGRESULTS@(UPTR)=TMP_U_$G(USCNT(1))_U_$G(USCNT(2))_U_UVPCT
  1. . F I=1,2 S UCNT(I)=$G(UCNT(I))+$G(USCNT(I))
  1. . Q
  1. ;=== Store the header of the "U"-section
  1. S TMP="U^^"_UCNT_"^^Totals"
  1. 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:"")
  1. K ^TMP("MAGGA03A.NAME",$J)
  1. Q 0
  1. ;
  1. ;+++++ RETURNS THE STATUS CODE AND DESCRIPTION
  1. ;
  1. ; STC Image status code
  1. ;
  1. ; Input Variables
  1. ; ===============
  1. ; MAGSTCACHE
  1. ;
  1. ; Output Variables
  1. ; ================
  1. ; MAGSTCACHE
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; StatusCode^StatusDescription
  1. ;
  1. STATUS(STC) ;
  1. Q:STC'>0 U
  1. S:'$D(MAGSTCACHE(STC)) MAGSTCACHE(STC)=STC_U_$$IMGSTDSC^MAGGI11(STC)
  1. Q MAGSTCACHE(STC)