MAGGA03A ;WOIFO/SG - CALLBACK FOR IMAGE QUERIES ; 3/9/09 12:50pm
 ;;3.0;IMAGING;**93,151**;Mar 19, 2002;Build 21;Dec 19, 2016
 ;; 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
 ;
 ;+++++ CALLBACK FUNCTION FOR IMAGE QUERIES
 ;
 ; IMGIEN        IEN of the image record (file #2005 or #2005.1)
 ;
 ; FLAGS         Flags that control the execution
 ;
 ; .DATA         Reference to a local array passed via the MAG8DATA
 ;               parameter of the $$QUERY^MAGGI13 function.
 ; DATA(
 ;   "FLAGS")    Original control flags passed into the
 ;               $$IMGQUERY^MAGGA03 function.
 ;
 ; Return Values
 ; =============
 ;           <0  Error descriptor (see the $$ERROR^MAGUERR)
 ;            0  Continue
 ;           >0  Terminate the query
 ;
 ; This function accumulates the data in the ^TMP($J,"MAGGA03A")
 ; global node:
 ;
 ; ^TMP($J,"MAGGA03A",
 ;
 ;   "S",StatusCode)     Image counts
 ;                         ^01: Number of image entries
 ;                         ^02: Number of images/pages
 ;
 ;   "U",UserIEN,
 ;     StatusCode)       Image counts
 ;                         ^01: Number of image entries
 ;                         ^02: Number of images/pages
 ;
QRYCBK(IMGIEN,FLAGS,DATA) ;
 N FD,FE,GROUP,GRPCNTS,IMGNODE,IMGNP,RC,SKIP,TMP
 ;=== Skip "child" (RC>0) and invalid (RC<0) image entries
 S RC=$$GRPIEN^MAGGI12(IMGIEN)  Q:RC 0
 ;
 ;=== Initialize variables
 S FD=(FLAGS["D"),FE=(FLAGS["E")
 S GROUP=$$ISGRP^MAGGI11(IMGIEN)
 ;
 ;=== Perform additional screening according to the image counts
 S TMP=$$TRFLAGS^MAGUTL05(DATA("FLAGS"),"SU")
 S GRPCNTS=$$GRPCT^MAGGI14(IMGIEN,"P"_TMP,.GRPCNTS)
 S SKIP=0  D  Q:SKIP 0
 . ;--- Check if the image entry references "child" images of
 . ;    requested kind(s). Also, safeguard against a wrong object
 . ;--- type in the group header.
 . I $P(GRPCNTS,U,1)>0  S GROUP=1  Q:FE  ; Existing "child" entries
 . I $P(GRPCNTS,U,2)>0  S GROUP=1  Q:FD  ; Deleted "child" entries
 . ;--- Skip group headers that do not reference
 . ;--- any "child" images of requested kind(s)
 . I GROUP  S SKIP=1  Q
 . ;--- If existing images are not requested, then
 . ;--- skip existing standalone image entries
 . I 'FE,'$$ISDEL^MAGGI11(IMGIEN)  S SKIP=1  Q
 . ;--- Get the number of pages from the standalone image entry
 . S IMGNODE=$$NODE^MAGGI11(IMGIEN)  Q:IMGNODE=""
 . ;P151 - Skip if this image was captured by Dicom Gateway.
 . S CAPP=$P($G(@IMGNODE@(2)),U,12) I (CAPP="D") S SKIP=1 Q
 . S IMGNP=+$P($G(@IMGNODE@(100)),U,10)
 . Q
 ;
 ;=== Image counts (grouped by status)
 I DATA("FLAGS")["S"  D
 . N OLDCNT,STC
 . ;--- Standalone image entry
 . I 'GROUP  D  Q
 . . S STC=+$$IMGST^MAGGI11(IMGIEN)
 . . S TMP=$G(^TMP("MAGGA03A",$J,"S",STC))
 . . S $P(TMP,U,1)=$P(TMP,U,1)+1
 . . S $P(TMP,U,2)=$P(TMP,U,2)+$S($G(IMGNP)>0:IMGNP,1:1)
 . . S ^TMP("MAGGA03A",$J,"S",STC)=TMP
 . . Q
 . ;--- Image group
 . S STC=""
 . F  S STC=$O(GRPCNTS("S",STC))  Q:STC=""  D
 . . S TMP=$G(^TMP("MAGGA03A",$J,"S",STC)),OLDCNT=+TMP
 . . D:FE
 . . . S $P(TMP,U,1)=$P(TMP,U,1)+$P(GRPCNTS("S",STC),U,1)
 . . . S $P(TMP,U,2)=$P(TMP,U,2)+$P(GRPCNTS("S",STC),U,3)
 . . . Q
 . . D:FD
 . . . S $P(TMP,U,1)=$P(TMP,U,1)+$P(GRPCNTS("S",STC),U,2)
 . . . S $P(TMP,U,2)=$P(TMP,U,2)+$P(GRPCNTS("S",STC),U,4)
 . . . Q
 . . S:+TMP'=OLDCNT ^TMP("MAGGA03A",$J,"S",STC)=TMP
 . . Q
 . Q
 ;
 ;=== Image capture users
 I DATA("FLAGS")["U"  D
 . N CNT,STC,USRIEN
 . ;--- Standalone image entry
 . I 'GROUP  D  Q
 . . S USRIEN=$S($G(IMGNODE)'="":+$P($G(@IMGNODE@(2)),U,2),1:0)
 . . I USRIEN=0 S USRIEN=".5" ;150 - Put Postmaster, this will stop <undefined> 
 . . S STC=+$$IMGST^MAGGI11(IMGIEN)
 . . S TMP=$G(^TMP("MAGGA03A",$J,"U",USRIEN,STC))
 . . S $P(TMP,U,1)=$P(TMP,U,1)+1
 . . S $P(TMP,U,2)=$P(TMP,U,2)+$S($G(IMGNP)>0:IMGNP,1:1)
 . . S ^TMP("MAGGA03A",$J,"U",USRIEN,STC)=TMP
 . . Q
 . ;--- Image group
 . S USRIEN=""
 . F  S USRIEN=$O(GRPCNTS("U",USRIEN))  Q:USRIEN=""  D
 . . S STC=""
 . . F  S STC=$O(GRPCNTS("U",USRIEN,STC))  Q:STC=""  D
 . . . S TMP=$G(^TMP("MAGGA03A",$J,"U",USRIEN,STC)),OLDCNT=+TMP
 . . . D:FE
 . . . . S $P(TMP,U,1)=$P(TMP,U,1)+$P(GRPCNTS("U",USRIEN,STC),U,1)
 . . . . S $P(TMP,U,2)=$P(TMP,U,2)+$P(GRPCNTS("U",USRIEN,STC),U,3)
 . . . . Q
 . . . D:FD
 . . . . S $P(TMP,U,1)=$P(TMP,U,1)+$P(GRPCNTS("U",USRIEN,STC),U,2)
 . . . . S $P(TMP,U,2)=$P(TMP,U,2)+$P(GRPCNTS("U",USRIEN,STC),U,4)
 . . . . Q
 . . . S:+TMP'=OLDCNT ^TMP("MAGGA03A",$J,"U",USRIEN,STC)=TMP
 . . . Q
 . . Q
 . Q
 ;
 ;===
 Q 0
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGGA03A   5576     printed  Sep 23, 2025@19:38:32                                                                                                                                                                                                    Page 2
MAGGA03A  ;WOIFO/SG - CALLBACK FOR IMAGE QUERIES ; 3/9/09 12:50pm
 +1       ;;3.0;IMAGING;**93,151**;Mar 19, 2002;Build 21;Dec 19, 2016
 +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      ;+++++ CALLBACK FUNCTION FOR IMAGE QUERIES
 +21      ;
 +22      ; IMGIEN        IEN of the image record (file #2005 or #2005.1)
 +23      ;
 +24      ; FLAGS         Flags that control the execution
 +25      ;
 +26      ; .DATA         Reference to a local array passed via the MAG8DATA
 +27      ;               parameter of the $$QUERY^MAGGI13 function.
 +28      ; DATA(
 +29      ;   "FLAGS")    Original control flags passed into the
 +30      ;               $$IMGQUERY^MAGGA03 function.
 +31      ;
 +32      ; Return Values
 +33      ; =============
 +34      ;           <0  Error descriptor (see the $$ERROR^MAGUERR)
 +35      ;            0  Continue
 +36      ;           >0  Terminate the query
 +37      ;
 +38      ; This function accumulates the data in the ^TMP($J,"MAGGA03A")
 +39      ; global node:
 +40      ;
 +41      ; ^TMP($J,"MAGGA03A",
 +42      ;
 +43      ;   "S",StatusCode)     Image counts
 +44      ;                         ^01: Number of image entries
 +45      ;                         ^02: Number of images/pages
 +46      ;
 +47      ;   "U",UserIEN,
 +48      ;     StatusCode)       Image counts
 +49      ;                         ^01: Number of image entries
 +50      ;                         ^02: Number of images/pages
 +51      ;
QRYCBK(IMGIEN,FLAGS,DATA) ;
 +1        NEW FD,FE,GROUP,GRPCNTS,IMGNODE,IMGNP,RC,SKIP,TMP
 +2       ;=== Skip "child" (RC>0) and invalid (RC<0) image entries
 +3        SET RC=$$GRPIEN^MAGGI12(IMGIEN)
           if RC
               QUIT 0
 +4       ;
 +5       ;=== Initialize variables
 +6        SET FD=(FLAGS["D")
           SET FE=(FLAGS["E")
 +7        SET GROUP=$$ISGRP^MAGGI11(IMGIEN)
 +8       ;
 +9       ;=== Perform additional screening according to the image counts
 +10       SET TMP=$$TRFLAGS^MAGUTL05(DATA("FLAGS"),"SU")
 +11       SET GRPCNTS=$$GRPCT^MAGGI14(IMGIEN,"P"_TMP,.GRPCNTS)
 +12       SET SKIP=0
           Begin DoDot:1
 +13      ;--- Check if the image entry references "child" images of
 +14      ;    requested kind(s). Also, safeguard against a wrong object
 +15      ;--- type in the group header.
 +16      ; Existing "child" entries
               IF $PIECE(GRPCNTS,U,1)>0
                   SET GROUP=1
                   if FE
                       QUIT 
 +17      ; Deleted "child" entries
               IF $PIECE(GRPCNTS,U,2)>0
                   SET GROUP=1
                   if FD
                       QUIT 
 +18      ;--- Skip group headers that do not reference
 +19      ;--- any "child" images of requested kind(s)
 +20           IF GROUP
                   SET SKIP=1
                   QUIT 
 +21      ;--- If existing images are not requested, then
 +22      ;--- skip existing standalone image entries
 +23           IF 'FE
                   IF '$$ISDEL^MAGGI11(IMGIEN)
                       SET SKIP=1
                       QUIT 
 +24      ;--- Get the number of pages from the standalone image entry
 +25           SET IMGNODE=$$NODE^MAGGI11(IMGIEN)
               if IMGNODE=""
                   QUIT 
 +26      ;P151 - Skip if this image was captured by Dicom Gateway.
 +27           SET CAPP=$PIECE($GET(@IMGNODE@(2)),U,12)
               IF (CAPP="D")
                   SET SKIP=1
                   QUIT 
 +28           SET IMGNP=+$PIECE($GET(@IMGNODE@(100)),U,10)
 +29           QUIT 
           End DoDot:1
           if SKIP
               QUIT 0
 +30      ;
 +31      ;=== Image counts (grouped by status)
 +32       IF DATA("FLAGS")["S"
               Begin DoDot:1
 +33               NEW OLDCNT,STC
 +34      ;--- Standalone image entry
 +35               IF 'GROUP
                       Begin DoDot:2
 +36                       SET STC=+$$IMGST^MAGGI11(IMGIEN)
 +37                       SET TMP=$GET(^TMP("MAGGA03A",$JOB,"S",STC))
 +38                       SET $PIECE(TMP,U,1)=$PIECE(TMP,U,1)+1
 +39                       SET $PIECE(TMP,U,2)=$PIECE(TMP,U,2)+$SELECT($GET(IMGNP)>0:IMGNP,1:1)
 +40                       SET ^TMP("MAGGA03A",$JOB,"S",STC)=TMP
 +41                       QUIT 
                       End DoDot:2
                       QUIT 
 +42      ;--- Image group
 +43               SET STC=""
 +44               FOR 
                       SET STC=$ORDER(GRPCNTS("S",STC))
                       if STC=""
                           QUIT 
                       Begin DoDot:2
 +45                       SET TMP=$GET(^TMP("MAGGA03A",$JOB,"S",STC))
                           SET OLDCNT=+TMP
 +46                       if FE
                               Begin DoDot:3
 +47                               SET $PIECE(TMP,U,1)=$PIECE(TMP,U,1)+$PIECE(GRPCNTS("S",STC),U,1)
 +48                               SET $PIECE(TMP,U,2)=$PIECE(TMP,U,2)+$PIECE(GRPCNTS("S",STC),U,3)
 +49                               QUIT 
                               End DoDot:3
 +50                       if FD
                               Begin DoDot:3
 +51                               SET $PIECE(TMP,U,1)=$PIECE(TMP,U,1)+$PIECE(GRPCNTS("S",STC),U,2)
 +52                               SET $PIECE(TMP,U,2)=$PIECE(TMP,U,2)+$PIECE(GRPCNTS("S",STC),U,4)
 +53                               QUIT 
                               End DoDot:3
 +54                       if +TMP'=OLDCNT
                               SET ^TMP("MAGGA03A",$JOB,"S",STC)=TMP
 +55                       QUIT 
                       End DoDot:2
 +56               QUIT 
               End DoDot:1
 +57      ;
 +58      ;=== Image capture users
 +59       IF DATA("FLAGS")["U"
               Begin DoDot:1
 +60               NEW CNT,STC,USRIEN
 +61      ;--- Standalone image entry
 +62               IF 'GROUP
                       Begin DoDot:2
 +63                       SET USRIEN=$SELECT($GET(IMGNODE)'="":+$PIECE($GET(@IMGNODE@(2)),U,2),1:0)
 +64      ;150 - Put Postmaster, this will stop <undefined> 
                           IF USRIEN=0
                               SET USRIEN=".5"
 +65                       SET STC=+$$IMGST^MAGGI11(IMGIEN)
 +66                       SET TMP=$GET(^TMP("MAGGA03A",$JOB,"U",USRIEN,STC))
 +67                       SET $PIECE(TMP,U,1)=$PIECE(TMP,U,1)+1
 +68                       SET $PIECE(TMP,U,2)=$PIECE(TMP,U,2)+$SELECT($GET(IMGNP)>0:IMGNP,1:1)
 +69                       SET ^TMP("MAGGA03A",$JOB,"U",USRIEN,STC)=TMP
 +70                       QUIT 
                       End DoDot:2
                       QUIT 
 +71      ;--- Image group
 +72               SET USRIEN=""
 +73               FOR 
                       SET USRIEN=$ORDER(GRPCNTS("U",USRIEN))
                       if USRIEN=""
                           QUIT 
                       Begin DoDot:2
 +74                       SET STC=""
 +75                       FOR 
                               SET STC=$ORDER(GRPCNTS("U",USRIEN,STC))
                               if STC=""
                                   QUIT 
                               Begin DoDot:3
 +76                               SET TMP=$GET(^TMP("MAGGA03A",$JOB,"U",USRIEN,STC))
                                   SET OLDCNT=+TMP
 +77                               if FE
                                       Begin DoDot:4
 +78                                       SET $PIECE(TMP,U,1)=$PIECE(TMP,U,1)+$PIECE(GRPCNTS("U",USRIEN,STC),U,1)
 +79                                       SET $PIECE(TMP,U,2)=$PIECE(TMP,U,2)+$PIECE(GRPCNTS("U",USRIEN,STC),U,3)
 +80                                       QUIT 
                                       End DoDot:4
 +81                               if FD
                                       Begin DoDot:4
 +82                                       SET $PIECE(TMP,U,1)=$PIECE(TMP,U,1)+$PIECE(GRPCNTS("U",USRIEN,STC),U,2)
 +83                                       SET $PIECE(TMP,U,2)=$PIECE(TMP,U,2)+$PIECE(GRPCNTS("U",USRIEN,STC),U,4)
 +84                                       QUIT 
                                       End DoDot:4
 +85                               if +TMP'=OLDCNT
                                       SET ^TMP("MAGGA03A",$JOB,"U",USRIEN,STC)=TMP
 +86                               QUIT 
                               End DoDot:3
 +87                       QUIT 
                       End DoDot:2
 +88               QUIT 
               End DoDot:1
 +89      ;
 +90      ;===
 +91       QUIT 0