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

MAGGA03Q.m

Go to the documentation of this file.
  1. MAGGA03Q ;WOIFO/GEK/BNT/NST/JSL - TASK IMAGE STATISTICS ; 07 Oct 2010 9:48 PM
  1. ;;3.0;IMAGING;**117,122**;Mar 19, 2002;Build 92;Aug 02, 2012
  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. ;P122 gek Fix the issue of not being able to Re-Run a report that
  1. ; was previously canceled while it was still running.
  1. Q
  1. ;
  1. ;***** RETURNS VARIOUS IMAGE STATISTICS DATA
  1. ; RPC: MAGG IMAGE STATISTICS QUE
  1. ;
  1. ; .MAGRY 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. ; [MQUE] Flags for tasking reports and action on previously
  1. ; tasked reports.
  1. ; Q (Default) Queue a new report task or return the status of
  1. ; In Progress for a running report. If previously
  1. ; ran task is complete, then return report data.
  1. ; R Stop and Requeue a running report with the
  1. ; same parameters. Existing data collected is removed
  1. ; from temporary storage.
  1. ; D Stop a running or completed report and delete the data.
  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 QUE IMAGE STATISTICS remote procedure for details.
  1. ;
  1. ; Notes
  1. ; =====
  1. ;
  1. ; Temporary global nodes ^TMP("MAGGA03Q",$J) and ^XTMP("MAGGA03Q,DUZ")
  1. ; are used by this procedure.
  1. ;
  1. STATS(MAGRY,FLAGS,FROMDATE,TODATE,MQUE) ; RPC [MAGG IMAGE STATISTICS QUE]
  1. N MOTH,MERR,MAGXTN,MAGRES,MTDESC,X,Y,RC
  1. S MAGRY=$NA(^TMP("MAGGA03Q",$J))
  1. K @MAGRY
  1. S (RC,MERR)=0
  1. D CLEAR^MAGUERR(1)
  1. ;
  1. ;--- Validate FLAGS Parameters
  1. S FLAGS=$G(FLAGS) I $TR(FLAGS,"CDESU")'="" D IPVE^MAGUERR("FLAGS") S MERR=1
  1. ;--- Missing required flag(s)
  1. I $TR(FLAGS,"DE")=FLAGS D ERROR^MAGUERR(-6,,"D,E") S MERR=1
  1. I $TR(FLAGS,"SU")=FLAGS D ERROR^MAGUERR(-6,,"S,U") S MERR=1
  1. ;
  1. ;--- Validate Date Range
  1. S:$$DTRANGE^MAGUTL03(.FROMDATE,.TODATE)<0 MERR=1
  1. ;
  1. ;--- Validate TaskMan Queing parameters
  1. S MQUE=$G(MQUE) I MQUE="" S MQUE="Q"
  1. I $TR(MQUE,"QRD")'="" D IPVE^MAGUERR("MQUE") S MERR=1
  1. ;
  1. ;--- Check if error occurred and quit if so
  1. I MERR D ERROR^MAGUERR(-30) S RC=$$FIRSTERR^MAGUERR1()
  1. I RC<0 D RPCERRS^MAGUERR1(.MAGRY,RC) Q
  1. ;
  1. ;--- Create unique XTMP node
  1. S MAGXTN=$$TNODE(FLAGS,FROMDATE,TODATE)
  1. ;
  1. ;--- Resolve previously tasked report
  1. I $D(^XTMP(MAGXTN,0)) D RESOLVE(.RC,MAGXTN,MQUE)
  1. ;--- If 1 is returned then the report is in progress
  1. I +RC=1 M @MAGRY@(0)=RC Q
  1. ;--- If 2 is returned then the report is complete and is returned
  1. I +RC=2 M @MAGRY@(0)=^XTMP(MAGXTN,"R",0) Q
  1. ;
  1. ;--- Create the TaskMan parameters and queue the report
  1. S MTDESC="Imaging Statistics: "_FLAGS_" "_FROMDATE_" to "_TODATE
  1. S MOTH("ZTDTH")=$H
  1. ; p117 T5: To enable a complete list of reports to be displayed
  1. ; in the Client Report list. If this "I" node isn't set, the report
  1. ; will not show up in list until it is run. Could be minutes.
  1. ; Added a new status to the Delphi Window : 'Queuing'.
  1. ; 'Queuing' status will account for the time between the Task being
  1. ; created and the job being run. The Queuing below isn't used. It
  1. ; is replaced with the TaskMan Task number later.
  1. ; Delphi uses $p(3) = '' (start time) to determine 'Queuing', and not Running.
  1. S ^XTMP(MAGXTN,"I",0)="Queuing"_U_$G(DUZ)_U_U
  1. ;
  1. S MAGRES=$$NODEV^XUTMDEVQ("TASK^MAGGA03Q",MTDESC,"FLAGS;FROMDATE;TODATE;MAGXTN",.MOTH)
  1. ;--- Save thru date ^ create date ^ Task Number
  1. S ^XTMP(MAGXTN,0)=$$FMADD^XLFDT(DT,1)_U_DT_U_MAGRES
  1. ;--- Save user cross reference node for report lookup by user
  1. S ^XTMP("MAGGA03Q",DUZ,MAGXTN)=""
  1. ;--- Return successful queued report notification with Task ID
  1. S @MAGRY@(0)="1^Report Queued on Task ID: "_MAGRES
  1. Q
  1. ;
  1. TASK ;
  1. N MAGXTN,MAGRES
  1. S MAGXTN=$$TNODE(FLAGS,FROMDATE,TODATE)
  1. ;--- Save Internal Data as follows
  1. ;--- ^XTMP($$TNODE,"I",0)=Task Number^User ID^Start Date/Time^Complete Date/Time
  1. S ^XTMP(MAGXTN,"I",0)=$G(ZTSK)_U_$G(DUZ)_U_$$NOW^XLFDT_U
  1. ;--- Collect Report Data from Imaging API
  1. D IMGQUERY^MAGGA03(.MAGRES,FLAGS,FROMDATE,TODATE) ; GEK BOOKMARK 1
  1. ;P122 gek
  1. ; If the variable ZSTOP = '1', then the TASK/Report was stopped,
  1. ; or if the Report's User Index: ^XTMP("MAGGAO3Q",DUZ,MAGXTN)
  1. ; does not exist, the report was stopped.
  1. ; We only save report Data if report was not Stopped.
  1. ; This Fixes the issue of not being able to Re-Run a report that
  1. ; was previously canceled while it was still running.
  1. ;
  1. I '$G(ZTSTOP),($D(^XTMP("MAGGA03Q",DUZ,MAGXTN))) D
  1. . ;--- Save Completed date/time of Report
  1. . S $P(^XTMP(MAGXTN,"I",0),U,4)=$$NOW^XLFDT
  1. . ;--- Update the Save Through date to midnight
  1. . S $P(^XTMP(MAGXTN,0),U,1)=$$FMADD^XLFDT($$DT^XLFDT(),1)
  1. . ;--- Save Report Data in temporary storage
  1. . M ^XTMP(MAGXTN,"R")=@MAGRES
  1. . Q
  1. Q
  1. ;
  1. ; Returns status of existing report based on MQUE flag
  1. RESOLVE(RY,MAGXTN,MQUE) ;
  1. ; if task is finished, then return the data.
  1. ; Q flag will return a completed report or an In Progress status if still running
  1. I MQUE="Q" D Q
  1. . S X=$P($G(^XTMP(MAGXTN,"I",0)),U,4)
  1. . ;/p117 T5 gek- add $G above to stop <undef>.
  1. . ; Occurred rarely (pre T5) when report is Re-Run. CodeCR731
  1. . I X="" S RY="1^In Progress" Q
  1. . S RY="2^Report Complete"
  1. . M @MAGRY=^XTMP(MAGXTN,"R")
  1. . Q
  1. ; R flag will Stop and Requeue a running report with same parameters
  1. I MQUE="R" D Q
  1. . N MAGSTP,ZTSK
  1. . S ZTSK=$$GETTASK(MAGXTN)
  1. . ; Try to stop the task if it's currently running
  1. . S MAGSTP=$$ASKSTOP^%ZTLOAD(ZTSK)
  1. . I 'MAGSTP S RY="1^Report cannot be stopped. Try again later" Q
  1. . ;
  1. . D STAT^%ZTLOAD
  1. . I 'ZTSK(0) S RY="0^Task is undefined" D Q
  1. . . ;Kill Report Data and Report's User Index
  1. . . K ^XTMP(MAGXTN),^XTMP("MAGGA03Q",DUZ,MAGXTN)
  1. . . S RY="0^Okay to retask"
  1. . . Q
  1. . I ZTSK(1)<3 S RY="1^Task In Progress : "_ZTSK Q
  1. . ;I ZTSK(1) is either 4 or 5, both mean not a running task. Inactive. problem
  1. . ;Kill Report Data and Report's User Index
  1. . K ^XTMP(MAGXTN),^XTMP("MAGGA03Q",DUZ,MAGXTN)
  1. . S RY="0^Okay to retask"
  1. . Q
  1. ; D flag will delete a previously ran report and stop a currently running task
  1. I MQUE="D" D Q
  1. . N MAGSTP,ZTSK
  1. . S ZTSK=$$GETTASK(MAGXTN)
  1. . S MAGSTP=$$ASKSTOP^%ZTLOAD(ZTSK)
  1. . I 'MAGSTP S RY="1^Report cannot be stopped. Try again later" Q
  1. . ;Kill Report Data and Report's User Index
  1. . K ^XTMP(MAGXTN),^XTMP("MAGGA03Q",DUZ,MAGXTN)
  1. . S RY="1^Report data deleted"
  1. Q
  1. ;
  1. ;***** RETURNS VARIOUS IMAGE STATISTICS DATA
  1. ; RPC: MAGG IMAGE STATISTICS BY USER
  1. ;
  1. ; Return all statistics reports previously tasked for a user
  1. ;
  1. ; .MAGRY Reference to a local variable where the results
  1. ; are returned to.
  1. ;
  1. ; MAGDUZ Internal ID of a user that has previously queued an Image Statistics
  1. ; Report.
  1. ; The default value is the current user DUZ.
  1. ;
  1. ; Return Values
  1. ; =============
  1. ;
  1. ; MAGRY(0) - ^01: 1 Successful execution of the remote procedure
  1. ; 0 An error occurred during the execution of the remote procedure
  1. ;
  1. ; ^02: The number of reports identified for the user
  1. ;
  1. ; MAGRY(1..n) ^01: report FLAGS parameter
  1. ; ^02: report FROMDATE parameter
  1. ; ^03: report TODATE parameter
  1. ; ^04: report REPORT START DATE/TIME parameter
  1. ; ^05: report REPORT COMPLETE DATE/TIEM parameter
  1. ;
  1. ; e.g.
  1. ; 0)=1^5 Reports found for user IMAGING,USER
  1. ; 1)=CDE^2900613^3100503^3100505.09053^3100505.09053
  1. ;
  1. GETUSRPT(MAGRY,MAGDUZ) ; RPC [MAGG IMAGE STATISTICS BY USER]
  1. N MAGX,MAGCNT
  1. N MAGINF ; XTMP node information.
  1. I MAGDUZ="" S MAGDUZ=DUZ
  1. ;--- Delete yesterdays temp data in ^XTMP
  1. D CLEARTMP(MAGDUZ)
  1. ;
  1. S MAGRY=$NA(^TMP("MAGGUSRPT",$J)),(MAGX,MAGCNT)=0
  1. K @MAGRY
  1. F S MAGX=$O(^XTMP("MAGGA03Q",MAGDUZ,MAGX)) Q:MAGX="" D
  1. . I '$D(^XTMP(MAGX,"I",0)) Q
  1. . S MAGCNT=MAGCNT+1
  1. . S MAGINF=$G(^XTMP(MAGX,"I",0))
  1. . ; Status of 'Queuing' is now set from the Delphi App, if the start time is '' (null).
  1. . ; Do not change next line. Any change causes list entries to not be displayed.
  1. . S @MAGRY@(MAGCNT)=$P(MAGX,"-",3)_U_$P(MAGX,"-",4)_U_$P(MAGX,"-",5)_U_$P(MAGINF,U,3)_U_$P(MAGINF,U,4)
  1. S @MAGRY@(0)="1^"_MAGCNT_$S(MAGCNT>1:" Reports ",1:" Report ")_"found for user "_$$GET1^DIQ(200,MAGDUZ_",",.01)
  1. Q
  1. ;
  1. ; Get unique XTMP node
  1. ; Namespace + User id + Flags + From Date + To Date
  1. TNODE(FLAG,FROMDT,TODT) ;
  1. ;/p117 T5 GEK THIS IS 'maggaO3q' (LETTER 'O') It should be 'magga03q' (Zero)
  1. ;Q "MAGGAO3Q"_"-"_DUZ_"-"_FLAG_"-"_FROMDT_"-"_TODT ; this had letter 'o'
  1. Q "MAGGA03Q"_"-"_DUZ_"-"_FLAG_"-"_FROMDT_"-"_TODT ; this is Zero
  1. ;
  1. ; Returns the Task Number from XTMP global
  1. ; TNODE = Value created in $$TNODE
  1. GETTASK(TNODE) ;
  1. Q $S('$D(^XTMP(TNODE,0)):0,1:+$P(^XTMP(TNODE,0),U,3))
  1. ;
  1. ; Delete temp data from yesterday
  1. ;
  1. CLEARTMP(MAGDUZ) ; Delete temp data from yesterday
  1. N MAGDAT,MAGXTN
  1. S MAGXTN=""
  1. F S MAGXTN=$O(^XTMP("MAGGA03Q",MAGDUZ,MAGXTN)) Q:MAGXTN="" D
  1. . S MAGDAT=$P($G(^XTMP(MAGXTN,0)),U,2)
  1. . I MAGDAT<DT D ; delete all data if created date is before today
  1. . . N MAGSTP,ZTSK
  1. . . S ZTSK=$$GETTASK(MAGXTN)
  1. . . ; Try to stop the task if it's currently running
  1. . . S MAGSTP=$$ASKSTOP^%ZTLOAD(ZTSK)
  1. . . I 'MAGSTP Q ; Report cannot be stopped
  1. . . K ^XTMP(MAGXTN),^XTMP("MAGGA03Q",$P(MAGXTN,"-",2),MAGXTN)
  1. . . Q
  1. . Q
  1. Q
  1. ;***** CLNXTMP
  1. ; Clean XTMP nodes.
  1. ; Due to an error (rare), there may be some orphaned
  1. ; report data in the XTMP global. This routine will
  1. ; clear out any orphaned XTMP nodes for the MAGGA03Q
  1. ; and MAGGAO3Q nodes of the QA Statistics Reports.
  1. ; It won't hurt valid reports. Valid reports are pointed
  1. ; to from the XTMP("MAGGA03Q",DUZ,xxxx) cross reference.
  1. CLNXTMP ;
  1. ; 0 = zero O = letter O
  1. ; make a list of the valid XTMP Nodes for Reports. These are referenced by the
  1. ; cross ref : XTMP('MAGGA03Q',duz,xnode)
  1. N MAGXTN,MAGDUZ,MWIN
  1. S MAGDUZ=""
  1. K ^TMP($J,"MAGXTMP")
  1. ; for all users, save reference to their Report Nodes.
  1. F S MAGDUZ=$O(^XTMP("MAGGA03Q",MAGDUZ)) Q:MAGDUZ="" D
  1. . S MAGXTN=""
  1. . F S MAGXTN=$O(^XTMP("MAGGA03Q",MAGDUZ,MAGXTN)) Q:MAGXTN="" D
  1. . . S ^TMP($J,"MAGXTMP",MAGXTN)="" ; save list of valid XTMP Nodes.
  1. . . Q
  1. . Q
  1. ; The orphaned XTMP Node used 'O' (letter), and '0' (Zero)
  1. ; We'll delete any nodes that aren't referenced by
  1. ; the cross Ref : XTMP('MAGGA03Q',duz,xnode)
  1. N XNODE,TNODE,DONE
  1. S DONE=0
  1. F XNODE="MAGGAO3Q","MAGGA03Q" D
  1. . S TNODE=XNODE
  1. . S DONE=0
  1. . F S XNODE=$O(^XTMP(XNODE)) D Q:DONE
  1. . . I $E(XNODE,1,8)'=TNODE S DONE=1 Q ; Quit if node is beyond QA Report Nodes.
  1. . . I $D(^TMP($J,"MAGXTMP",XNODE)) Q ; This is Valid, we won't delete.
  1. . . ; kill the orphaned node.
  1. . . K ^XTMP(XNODE)
  1. . . Q
  1. . Q
  1. K ^TMP($J,"MAGXTMP") ; clean up
  1. Q