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

MAGGI13.m

Go to the documentation of this file.
  1. MAGGI13 ;WOIFO/SG/BNT/NST/GEK/JSL - IMAGE FILE API (QUERY) ; 21 Jul 2010 11:05 AM
  1. ;;3.0;IMAGING;**93,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 : Stop Timeout error from QA Review window.
  1. ; Modified tag : QUERY, to now use ADTDUZ Cross reference
  1. ; when searching for images captured by a User.
  1. ; Remedy _<todo, get remedy ticket>
  1. Q
  1. ;
  1. ;+++++ RETURNS INVERTED/REVERSED DATE/TIME (FILEMAN)
  1. INVDT(DATETIME) ;
  1. Q 9999999.9999-DATETIME
  1. ;
  1. ;##### $ORDER BOTH #2005 AND #2005.1 FILES AT THE SAME TIME
  1. ;
  1. ; NODE Name of a node in file #2005 or #2005.1 (it does
  1. ; not matter in which one if the BOTH parameter is
  1. ; not zero). The last subscript can be empty string.
  1. ;
  1. ; [DIR] Browsing direction:
  1. ; $G(DIR)'<0 forward
  1. ; DIR<0 backward
  1. ;
  1. ; [BOTH] If this parameter is defined and not zero, then
  1. ; the MAGORD browses subscripts of IMAGE (#2005) and
  1. ; IMAGE AUDIT (2005.1) files at the same time (as if
  1. ; the nodes were merged into a single array).
  1. ; Otherwise, it works as the $ORDER function.
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; "" No more records
  1. ; Next/previous subscript (in #2005, #2005.1, or both)
  1. ;
  1. ; Notes
  1. ; =====
  1. ;
  1. ; This function relies on the fact that there are no records with
  1. ; the same IENs in the files #2005 and #2005.1.
  1. ;
  1. MAGORD(NODE,DIR,BOTH) ;
  1. Q:NODE'?1"^MAG(2005".1".1"1","1.E1")" ""
  1. N FILE,LST,PI,SUBS,TRAIL
  1. S DIR=$S($G(DIR)<0:-1,1:1)
  1. Q:'$G(BOTH) $O(@NODE,DIR)
  1. ;--- Find subscripts in both files that follow the @NODE
  1. S TRAIL=","_$P(NODE,",",2,999)
  1. F FILE=2005,2005.1 D
  1. . S PI="^MAG("_FILE_TRAIL,SUBS=$O(@PI,DIR)
  1. . S:SUBS'="" LST(SUBS,FILE)=""
  1. . Q
  1. ;--- Return one of the subscripts according to the direction
  1. Q $O(LST(""),DIR)
  1. ;
  1. ;+++++ CHECKS THE PATIENT REFERENCE
  1. ;
  1. ; IMGIEN Internal entry number of the image entry
  1. ;
  1. ; DFN Patient IEN (DFN)
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; 0 Skip the image entry (different patient or error)
  1. ; 1 Process the image entry
  1. ;
  1. PTCHK(IMGIEN,DFN) ;
  1. N NODE S NODE=$$NODE^MAGGI11(IMGIEN)
  1. Q $S(NODE'="":$P($G(@NODE@(0)),U,7)=DFN,1:0)
  1. ;
  1. ;##### BROWSES IMAGES AND CALLS THE CALLBACK FUNCTION
  1. ;
  1. ; CALLBACK Full name of the callback function ($$TAG^ROUTINE)
  1. ; that is called for each preselected image.
  1. ;
  1. ; SINCE ENTRIES THAT ARE NOT MARKED AS DELETED CAN
  1. ; REFERENCE DELETED "CHILDREN", SUCH ENTRIES ARE PASSED
  1. ; TO THE CALLBACK FUNCTION EVEN IF ONLY DELETED IMAGES
  1. ; ARE REQUESTED! THEREFORE, THE FUNCTION MUST PERFORM
  1. ; ADDITIONAL SCREENING BY CHECKING THE "CHILD" ENTRIES.
  1. ;
  1. ; The function should accept 3 parameters:
  1. ;
  1. ; IMGIEN IEN of the image record
  1. ; (file #2005 or #2005.1)
  1. ;
  1. ; FLAGS Value of the FLAGS parameter of the
  1. ; $$QUERY function (see below).
  1. ;
  1. ; .DATA Reference to the local array passed via
  1. ; the MAG8DATA parameter of the $$QUERY
  1. ; function (see below).
  1. ;
  1. ; Non-zero result values of the callback function
  1. ; terminate the query:
  1. ;
  1. ; <0 Error descriptor (see the $$ERROR^MAGUERR)
  1. ; 0 Continue
  1. ; >0 Terminate the query (e.g. if maximum number of
  1. ; returned records has been reached)
  1. ;
  1. ; See the source code of the IMGQUERY^MAGGA03 and
  1. ; $$QRYCBK^MAGGA03 for an example.
  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. ; MAG8FROM and MAG8TO parameters to select images
  1. ; that were captured in this date range (see the
  1. ; DATE/TIME IMAGE SAVED field (7) and the "AD"
  1. ; cross-reference).
  1. ;
  1. ; Otherwise, values of those parameters are
  1. ; treated as the date range when procedures were
  1. ; performed (see the PROCEDURE/EXAM DATE/TIME
  1. ; field (15) and cross-references "APDTPX" and
  1. ; "APDT").
  1. ;
  1. ; G Include Group Images in the list of images returned.
  1. ; If any image in a group has an image that matches the
  1. ; status provided in the search criteria then
  1. ; the group will be returned.
  1. ;
  1. ; If the G flag is not set then only the status of the
  1. ; Group entry will be checked and the group will be
  1. ; returned if it passes.
  1. ;
  1. ; D Include only deleted images (file #2005.1)
  1. ;
  1. ; E Include only existing images (file #2005)
  1. ;
  1. ; If neither 'E' nor 'D' flag is provided, then an
  1. ; error code is returned.
  1. ;
  1. ; [.MAG8DATA] Reference to a local array that is passed to the
  1. ; callback function (by reference) "as is"
  1. ;
  1. ; [MAG8FROM] Date/time range for image selection. Parameter
  1. ; [MAG8TO] values should be valid date/times in internal or
  1. ; external FileMan format. If a parameter is not
  1. ; defined or empty, then the range remains open on
  1. ; the corresponding side.
  1. ;
  1. ; The beginning of the date/time range is included
  1. ; the search but the end is not! For example, if you
  1. ; need images for October 15, 2007, the internal
  1. ; parameter values should be 3071015 and 3071016.
  1. ;
  1. ; If the MAG8FROM is after the MAG8TO, then values
  1. ; of the parameters are swapped.
  1. ;
  1. ; [DFN] Patient IEN (DFN). If this parameter is defined and
  1. ; greater than 0, then only images associated with this
  1. ; patient are processed.
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; <0 Error descriptor (see the $$ERROR^MAGUERR)
  1. ; 0 All appropriate image records have been processed
  1. ; >0 Value returned by the callback function when it
  1. ; terminated the query
  1. ;
  1. ; Notes
  1. ; =====
  1. ;
  1. ; Temporary global node ^TMP($J,"MAGGI13") is used by this function.
  1. ;
  1. QUERY(CALLBACK,FLAGS,MAG8DATA,MAG8FROM,MAG8TO,DFN) ;
  1. N MAG8BOTH,MAG8CALL,MAG8DT,MAG8IEN,MAG8RC,MAG8ROOT,MAG8XREF,TMP
  1. ;P122
  1. N MAG8APP,MAG8DUZ,MAG8SITE,BOTHAPP
  1. ;
  1. S FLAGS=$G(FLAGS)
  1. ;=== Validate parameters
  1. Q:'(CALLBACK?2"$"1.8UN1"^MAG"1.5UN) $$IPVE^MAGUERR("CALLBACK")
  1. ;--- If a patient IEN is provided, it must be valid
  1. I $G(DFN)>0,'$$VALDFN^MAGUTL05(DFN,.TMP) D STORE^MAGUERR(TMP) Q TMP
  1. ;--- Unknown/Unsupported flag(s)
  1. Q:$TR(FLAGS,"CDEG")'="" $$IPVE^MAGUERR("FLAGS")
  1. ;--- Missing required flag
  1. Q:$TR(FLAGS,"DE")=FLAGS $$ERROR^MAGUERR(-6,,"D,E")
  1. ;
  1. ;=== The expression in the following line does not look like
  1. ; (FLAGS["E")&(FLAGS["D") because a group header that is
  1. ;=== not marked as deleted can reference deleted "children".
  1. S MAG8BOTH=(FLAGS["D")
  1. S TMP=$S(FLAGS["E":2005,1:2005.1),MAG8ROOT=$NA(^MAG(TMP))
  1. S TMP=$$DDQ^MAGUTL05(FLAGS)
  1. S MAG8CALL="S MAG8RC="_CALLBACK_"(MAG8IEN,"_TMP_",.MAG8DATA)"
  1. S MAG8RC=0
  1. ;P122 set a variable (MAG8DUZ) to $Order through the Cross Ref.
  1. S MAG8DUZ=+$P($G(MAG8DATA("SAVEDBY")),"^",1)
  1. ;=== Return images in the capture date range captured by a User MAG8DUZ
  1. ; This call is made by the QA Review window. Looking for a list of images
  1. ; captured by a certain user in a certain date range.
  1. I (FLAGS["C"),(MAG8DUZ) D Q MAG8RC
  1. . ;--- Modify the callback to check for patient
  1. . S:$G(DFN)>0 $E(MAG8CALL,1)="S:$$PTCHK(MAG8IEN,"_DFN_")"
  1. . ;---
  1. . ; ATDUZ may be used by more than QA Review, can't Force MAG8BOTH
  1. . ; to '0', Deleted Images may be wanted by other functions.
  1. . ;- S MAG8BOTH=0
  1. . ; Loop through both Capture Application nodes of ADTDUZ
  1. . F MAG8APP="C","I" D
  1. . . S MAG8XREF=$NA(@MAG8ROOT@("ADTDUZ",MAG8APP))
  1. . . S MAG8DT=MAG8TO
  1. . . F S MAG8DT=$$MAGORD($NA(@MAG8XREF@(MAG8DT)),-1,MAG8BOTH) Q:(MAG8DT="")!(MAG8DT<MAG8FROM) D Q:MAG8RC
  1. . . . S MAG8SITE=""
  1. . . . F S MAG8SITE=$$MAGORD($NA(@MAG8XREF@(MAG8DT,MAG8DUZ,MAG8SITE)),-1,MAG8BOTH) Q:(MAG8SITE="") D
  1. . . . . S MAG8IEN=""
  1. . . . . F D Q:(MAG8IEN="")!MAG8RC X MAG8CALL Q:MAG8RC
  1. . . . . . S MAG8IEN=$$MAGORD($NA(@MAG8XREF@(MAG8DT,MAG8DUZ,MAG8SITE,MAG8IEN)),-1,MAG8BOTH)
  1. . . . . . I $D(ZTQUEUED),$$S^%ZTLOAD S MAG8RC="1^Task asked to stop",ZTSTOP=1
  1. . . . . . Q
  1. . . . . Q
  1. . . Q
  1. . Q
  1. ;=== Browse images in the capture date range
  1. I FLAGS["C" D Q MAG8RC
  1. . ;--- Modify the callback to check for patient
  1. . S:$G(DFN)>0 $E(MAG8CALL,1)="S:$$PTCHK(MAG8IEN,"_DFN_")"
  1. . ;---
  1. . S MAG8XREF=$NA(@MAG8ROOT@("AD"))
  1. . S MAG8DT=MAG8TO
  1. . F S MAG8DT=$$MAGORD($NA(@MAG8XREF@(MAG8DT)),-1,MAG8BOTH) Q:(MAG8DT="")!(MAG8DT<MAG8FROM) D Q:MAG8RC
  1. . . S MAG8IEN=""
  1. . . F D Q:(MAG8IEN="")!MAG8RC X MAG8CALL Q:MAG8RC
  1. . . . S MAG8IEN=$$MAGORD($NA(@MAG8XREF@(MAG8DT,MAG8IEN)),-1,MAG8BOTH)
  1. . . . I $D(ZTQUEUED),$$S^%ZTLOAD S MAG8RC="1^Task asked to stop",ZTSTOP=1
  1. . . . Q
  1. . . Q
  1. . Q
  1. ;
  1. ;=== Browse images in the procedure date range; single patient
  1. I $G(DFN)>0 D Q MAG8RC
  1. . N MAG8DT1,MAG8DT2,MAG8PRX,MAG8TMP
  1. . S MAG8XREF=$NA(@MAG8ROOT@("APDTPX",+DFN))
  1. . S MAG8TMP=$NA(^TMP("MAGGI13",$J))
  1. . ;--- "Invert" the dates
  1. . S MAG8DT1=$$INVDT(MAG8TO),MAG8DT2=$$INVDT(MAG8FROM)
  1. . ;---
  1. . S MAG8DT=MAG8DT1
  1. . F S MAG8DT=$$MAGORD($NA(@MAG8XREF@(MAG8DT)),1,MAG8BOTH) Q:(MAG8DT="")!(MAG8DT>MAG8DT2) D Q:MAG8RC
  1. . . K @MAG8TMP
  1. . . I $D(ZTQUEUED),$$S^%ZTLOAD S MAG8RC="1^Task asked to stop",ZTSTOP=1 Q
  1. . . ;--- Merge IEN lists from both files
  1. . . S MAG8PRX=""
  1. . . F S MAG8PRX=$$MAGORD($NA(@MAG8XREF@(MAG8DT,MAG8PRX)),1,MAG8BOTH) Q:MAG8PRX="" D
  1. . . . S MAG8IEN=""
  1. . . . F S MAG8IEN=$$MAGORD($NA(@MAG8XREF@(MAG8DT,MAG8PRX,MAG8IEN)),1,MAG8BOTH) Q:MAG8IEN="" D
  1. . . . . S @MAG8TMP@(MAG8IEN)=""
  1. . . . . Q
  1. . . ;--- Browse the list and select the images
  1. . . S MAG8IEN=""
  1. . . F D Q:(MAG8IEN'>0)!MAG8RC X MAG8CALL Q:MAG8RC
  1. . . . S MAG8IEN=$O(@MAG8TMP@(MAG8IEN),-1)
  1. . . . I $D(ZTQUEUED),$$S^%ZTLOAD S MAG8RC="1^Task asked to stop",ZTSTOP=1
  1. . . . Q
  1. . . Q
  1. . ;---
  1. . K @MAG8TMP
  1. . Q
  1. ;
  1. ;=== Browse images in the procedure date range; all patients
  1. S MAG8XREF=$NA(@MAG8ROOT@("APDT"))
  1. S MAG8DT=MAG8TO
  1. F S MAG8DT=$$MAGORD($NA(@MAG8XREF@(MAG8DT)),-1,MAG8BOTH) Q:(MAG8DT="")!(MAG8DT<MAG8FROM) D Q:MAG8RC
  1. . S MAG8IEN=""
  1. . F D Q:(MAG8IEN="")!MAG8RC X MAG8CALL Q:MAG8RC
  1. . . S MAG8IEN=$$MAGORD($NA(@MAG8XREF@(MAG8DT,MAG8IEN)),-1,MAG8BOTH)
  1. . . I $D(ZTQUEUED),$$S^%ZTLOAD S MAG8RC="1^Task asked to stop",ZTSTOP=1
  1. . . Q
  1. . Q
  1. ;---
  1. Q MAG8RC