MAGQBJB ;WOIFO/PMK/RMP - Get an image file to copy to the JukeBox ; 18 Jan 2011 4:55 PM
 ;;3.0;IMAGING;**8,20,39**;Mar 19, 2002;Build 2010;Mar 08, 2011
 ;; 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
ENTRY(RESULT,QPTR) ; entry point from ^MAGQBTM
 ; RESULT=STATUS^IMAGE PTR^FROM FILE^TO FILE^JUKEBOX DEVICE^
 ;   QUEUE PTR^JUKEBOX-NETWORK LOC PTR^QSN^Abstract^BIG
 ; QSN=QUEUE SEQUENCE NUMBER
 N IMGPTR,L,JBDEVICE,FILENAME,FILE,X,JBPTR,SUBDIR
 N MAGFILE,MAGXX,MAGSTORE,MAGFILE2,PERCENT,SIZERTN,MAGDEV,SRCE
 N TOFILE,TOTAL,QNODE,QSN,ZNODE,BNODE,FULL,ABS,BIG,MSG,PLACE,AGG
 S U="^",QNODE=$G(^MAGQUEUE(2006.03,QPTR,0)),(ZNODE,FULL,ABS,BIG,JBPTR,AGG)=""
 S IMGPTR=$P(QNODE,U,7),QSN=+$P(QNODE,U,9),PLACE=$P(QNODE,U,12)
 I $D(^MAG(2005,IMGPTR,0)) D
 . S ZNODE=$G(^MAG(2005,IMGPTR,0))
 . S BNODE=$G(^MAG(2005,IMGPTR,"FBIG"))
 . Q
 E  I $D(^MAG(2005.1,IMGPTR,0)) D
 . S ZNODE=$G(^MAG(2005.1,IMGPTR,0))
 . S BNODE=$G(^MAG(2005.1,IMGPTR,"FBIG"))
 . Q
 I ZNODE="" D  Q  ;RESULT ;!!!!
 . S RESULT="-101^"_QPTR_"^MAG Global Node #"_IMGPTR_" not present"
 S FILE=$P(ZNODE,U,2)
 I FILE="" D  Q  ;RESULT ;!!!
 . I +$P($G(^MAG(2005,IMGPTR,1,0)),U,4)>0 D
 . . S MSG="Image group parent"
 . E  S MSG="Does not have an image file specified"
 . S RESULT="-5"_U_QPTR_U_MSG
 ; Establish the current Jukebox location
 S JBPTR=$$JBPTR^MAGBAPI($$PLACE^MAGBAPI(+$G(DUZ(2))))
 I 'JBPTR D  Q
 . S RESULT="-4"_U_QPTR_U_"The Jukebox Network Location is not set"
 I $P(^MAG(2005.2,JBPTR,0),"^",6)'="1" D  Q
 . S RESULT="-4"_U_QPTR_U_"Jukebox Network Location "_$P(^MAG(2005.2,JBPTR,0),"^",1)_" is set Offline"
 S JBDEVICE=$$JBDEV(JBPTR)
 ; If the current Jukebox write location differs from the FULL/ABstract Worm or the BIG Worm then aggregate
 S AGG=$S($P(ZNODE,U,5)&($P(ZNODE,U,5)'=JBPTR):1,$P(BNODE,U,2)&($P(BNODE,U,2)'=JBPTR):1,1:"")
 ; Check for FULL
 S SRCE=$S($$SLINE(+$P(ZNODE,U,3)):$P(ZNODE,U,3),1:"")
 I 'SRCE,AGG S SRCE=$S($$SLINE(+$P(ZNODE,U,5)):$P(ZNODE,U,5),1:"")
 I SRCE D 
 . S MAGDEV=$P(^MAG(2005.2,SRCE,0),U,2),FULL=MAGDEV_$$DIRHASH^MAGFILEB(FILE,SRCE)_FILE Q 
 ; Check for Abstract
 S SRCE=$S($$SLINE(+$P(ZNODE,U,4)):$P(ZNODE,U,4),1:"")
 I 'SRCE,AGG S SRCE=$S($$SLINE(+$P(ZNODE,U,5)):$P(ZNODE,U,5),1:"")
 I SRCE D 
 . S MAGDEV=$P(^MAG(2005.2,SRCE,0),U,2),ABS=MAGDEV_$$DIRHASH^MAGFILEB(FILE,SRCE)_$P(FILE,".")_".ABS" Q 
 ; Check for Big
 S SRCE=$S($$SLINE(+$P(BNODE,U,1)):$P(BNODE,U,1),1:"")
 I 'SRCE,AGG S SRCE=$S($$SLINE(+$P(BNODE,U,2)):$P(BNODE,U,2),1:"")
 I SRCE D  ; Including logic for P99 alternative BIG file extension.
 . S MAGDEV=$P(^MAG(2005.2,SRCE,0),U,2)
 . S BIG=MAGDEV_$$DIRHASH^MAGFILEB(FILE,SRCE)_$P(FILE,".")_"."_$S($P(BNODE,U,3)="":"BIG",1:$P(BNODE,U,3))
 . Q 
 I FULL="",BIG="",ABS="" D  Q
 . S MSG=$S(('$P(BNODE,U))&('$P(ZNODE,U,4))&('$P(ZNODE,U,4)):"No VistA Cache Source",1:"")
 . S MSG=$S('MSG:"There are no network location references for this image: "_FILE,1:MSG)
 . S RESULT="-11^"_QPTR_"^"_MSG
 . Q
 K MAGFILE1
 S TOFILE=$$WPATH(FILE,JBPTR)_FILE
 S RESULT="1^"_IMGPTR_U_FULL_U_TOFILE_U
 S RESULT=RESULT_JBDEVICE_U_QPTR_U_JBPTR_U_QSN_U_ABS_U_BIG
 Q
WPATH(FILE,CWP) ; Write path of Current Write Platter (CWP)
 Q $P(^MAG(2005.2,CWP,0),"^",2)_$$DIRHASH^MAGFILEB(FILE,CWP)
JBDEV(JBPTR) ; Jukebox Device (drive spec)
 Q $P($G(^MAG(2005.2,JBPTR,0)),"^",2)
SLINE(PTR) ;Check if the share is online
 Q:PTR<1 ""
 Q $S($P($G(^MAG(2005.2,PTR,0)),U,6)=1:1,1:"")
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGQBJB   4389     printed  Sep 23, 2025@19:44:03                                                                                                                                                                                                     Page 2
MAGQBJB   ;WOIFO/PMK/RMP - Get an image file to copy to the JukeBox ; 18 Jan 2011 4:55 PM
 +1       ;;3.0;IMAGING;**8,20,39**;Mar 19, 2002;Build 2010;Mar 08, 2011
 +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      ;; | The Food and Drug Administration classifies this software as  |
 +11      ;; | a medical device.  As such, it may not be changed in any way. |
 +12      ;; | Modifications to this software may result in an adulterated   |
 +13      ;; | medical device under 21CFR820, the use of which is considered |
 +14      ;; | to be a violation of US Federal Statutes.                     |
 +15      ;; +---------------------------------------------------------------+
 +16      ;;
 +17       QUIT 
ENTRY(RESULT,QPTR) ; entry point from ^MAGQBTM
 +1       ; RESULT=STATUS^IMAGE PTR^FROM FILE^TO FILE^JUKEBOX DEVICE^
 +2       ;   QUEUE PTR^JUKEBOX-NETWORK LOC PTR^QSN^Abstract^BIG
 +3       ; QSN=QUEUE SEQUENCE NUMBER
 +4        NEW IMGPTR,L,JBDEVICE,FILENAME,FILE,X,JBPTR,SUBDIR
 +5        NEW MAGFILE,MAGXX,MAGSTORE,MAGFILE2,PERCENT,SIZERTN,MAGDEV,SRCE
 +6        NEW TOFILE,TOTAL,QNODE,QSN,ZNODE,BNODE,FULL,ABS,BIG,MSG,PLACE,AGG
 +7        SET U="^"
           SET QNODE=$GET(^MAGQUEUE(2006.03,QPTR,0))
           SET (ZNODE,FULL,ABS,BIG,JBPTR,AGG)=""
 +8        SET IMGPTR=$PIECE(QNODE,U,7)
           SET QSN=+$PIECE(QNODE,U,9)
           SET PLACE=$PIECE(QNODE,U,12)
 +9        IF $DATA(^MAG(2005,IMGPTR,0))
               Begin DoDot:1
 +10               SET ZNODE=$GET(^MAG(2005,IMGPTR,0))
 +11               SET BNODE=$GET(^MAG(2005,IMGPTR,"FBIG"))
 +12               QUIT 
               End DoDot:1
 +13      IF '$TEST
               IF $DATA(^MAG(2005.1,IMGPTR,0))
                   Begin DoDot:1
 +14                   SET ZNODE=$GET(^MAG(2005.1,IMGPTR,0))
 +15                   SET BNODE=$GET(^MAG(2005.1,IMGPTR,"FBIG"))
 +16                   QUIT 
                   End DoDot:1
 +17      ;RESULT ;!!!!
           IF ZNODE=""
               Begin DoDot:1
 +18               SET RESULT="-101^"_QPTR_"^MAG Global Node #"_IMGPTR_" not present"
               End DoDot:1
               QUIT 
 +19       SET FILE=$PIECE(ZNODE,U,2)
 +20      ;RESULT ;!!!
           IF FILE=""
               Begin DoDot:1
 +21               IF +$PIECE($GET(^MAG(2005,IMGPTR,1,0)),U,4)>0
                       Begin DoDot:2
 +22                       SET MSG="Image group parent"
                       End DoDot:2
 +23              IF '$TEST
                       SET MSG="Does not have an image file specified"
 +24               SET RESULT="-5"_U_QPTR_U_MSG
               End DoDot:1
               QUIT 
 +25      ; Establish the current Jukebox location
 +26       SET JBPTR=$$JBPTR^MAGBAPI($$PLACE^MAGBAPI(+$GET(DUZ(2))))
 +27       IF 'JBPTR
               Begin DoDot:1
 +28               SET RESULT="-4"_U_QPTR_U_"The Jukebox Network Location is not set"
               End DoDot:1
               QUIT 
 +29       IF $PIECE(^MAG(2005.2,JBPTR,0),"^",6)'="1"
               Begin DoDot:1
 +30               SET RESULT="-4"_U_QPTR_U_"Jukebox Network Location "_$PIECE(^MAG(2005.2,JBPTR,0),"^",1)_" is set Offline"
               End DoDot:1
               QUIT 
 +31       SET JBDEVICE=$$JBDEV(JBPTR)
 +32      ; If the current Jukebox write location differs from the FULL/ABstract Worm or the BIG Worm then aggregate
 +33       SET AGG=$SELECT($PIECE(ZNODE,U,5)&($PIECE(ZNODE,U,5)'=JBPTR):1,$PIECE(BNODE,U,2)&($PIECE(BNODE,U,2)'=JBPTR):1,1:"")
 +34      ; Check for FULL
 +35       SET SRCE=$SELECT($$SLINE(+$PIECE(ZNODE,U,3)):$PIECE(ZNODE,U,3),1:"")
 +36       IF 'SRCE
               IF AGG
                   SET SRCE=$SELECT($$SLINE(+$PIECE(ZNODE,U,5)):$PIECE(ZNODE,U,5),1:"")
 +37       IF SRCE
               Begin DoDot:1
 +38               SET MAGDEV=$PIECE(^MAG(2005.2,SRCE,0),U,2)
                   SET FULL=MAGDEV_$$DIRHASH^MAGFILEB(FILE,SRCE)_FILE
                   QUIT 
               End DoDot:1
 +39      ; Check for Abstract
 +40       SET SRCE=$SELECT($$SLINE(+$PIECE(ZNODE,U,4)):$PIECE(ZNODE,U,4),1:"")
 +41       IF 'SRCE
               IF AGG
                   SET SRCE=$SELECT($$SLINE(+$PIECE(ZNODE,U,5)):$PIECE(ZNODE,U,5),1:"")
 +42       IF SRCE
               Begin DoDot:1
 +43               SET MAGDEV=$PIECE(^MAG(2005.2,SRCE,0),U,2)
                   SET ABS=MAGDEV_$$DIRHASH^MAGFILEB(FILE,SRCE)_$PIECE(FILE,".")_".ABS"
                   QUIT 
               End DoDot:1
 +44      ; Check for Big
 +45       SET SRCE=$SELECT($$SLINE(+$PIECE(BNODE,U,1)):$PIECE(BNODE,U,1),1:"")
 +46       IF 'SRCE
               IF AGG
                   SET SRCE=$SELECT($$SLINE(+$PIECE(BNODE,U,2)):$PIECE(BNODE,U,2),1:"")
 +47      ; Including logic for P99 alternative BIG file extension.
           IF SRCE
               Begin DoDot:1
 +48               SET MAGDEV=$PIECE(^MAG(2005.2,SRCE,0),U,2)
 +49               SET BIG=MAGDEV_$$DIRHASH^MAGFILEB(FILE,SRCE)_$PIECE(FILE,".")_"."_$SELECT($PIECE(BNODE,U,3)="":"BIG",1:$PIECE(BNODE,U,3))
 +50               QUIT 
               End DoDot:1
 +51       IF FULL=""
               IF BIG=""
                   IF ABS=""
                       Begin DoDot:1
 +52                       SET MSG=$SELECT(('$PIECE(BNODE,U))&('$PIECE(ZNODE,U,4))&('$PIECE(ZNODE,U,4)):"No VistA Cache Source",1:"")
 +53                       SET MSG=$SELECT('MSG:"There are no network location references for this image: "_FILE,1:MSG)
 +54                       SET RESULT="-11^"_QPTR_"^"_MSG
 +55                       QUIT 
                       End DoDot:1
                       QUIT 
 +56       KILL MAGFILE1
 +57       SET TOFILE=$$WPATH(FILE,JBPTR)_FILE
 +58       SET RESULT="1^"_IMGPTR_U_FULL_U_TOFILE_U
 +59       SET RESULT=RESULT_JBDEVICE_U_QPTR_U_JBPTR_U_QSN_U_ABS_U_BIG
 +60       QUIT 
WPATH(FILE,CWP) ; Write path of Current Write Platter (CWP)
 +1        QUIT $PIECE(^MAG(2005.2,CWP,0),"^",2)_$$DIRHASH^MAGFILEB(FILE,CWP)
JBDEV(JBPTR) ; Jukebox Device (drive spec)
 +1        QUIT $PIECE($GET(^MAG(2005.2,JBPTR,0)),"^",2)
SLINE(PTR) ;Check if the share is online
 +1        if PTR<1
               QUIT ""
 +2        QUIT $SELECT($PIECE($GET(^MAG(2005.2,PTR,0)),U,6)=1:1,1:"")