MAGDQR73 ;WOIFO/MLH/PMK - Imaging RPCs for Query/Retrieve - acc# scan for consult recs (old DB) ; Jun 16, 2020@14:06:52
 ;;3.0;IMAGING;**118,138,231**;Mar 19, 2002;Build 9;Sep 03, 2013
 ;; 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
 ; called from MAGDQR07
 ;
ACCCON(REQ,T,P,ACC) ; scan old structure for Consult Related Images
 N TMPQ,ACCNUM,GMRCIEN,I,D0,MAGDFN,IMAGE,X,RESULT
 S TMPQ=$NA(^TMP("MAG",$J,"QR")) K @TMPQ@(5)
 S (ACCNUM,GMRCIEN)=REQ(T,P)
 S X=$$GMRCIEN^MAGDFCNV(ACCNUM) I X S GMRCIEN=X
 ; For the time being, we can only do this:
 S:GMRCIEN @TMPQ@(5,GMRCIEN)=""
 S I=$$MATCHD^MAGDQR03(GMRCIEN,"^GMR(123,LOOP)","@TMPQ@(5,LOOP)")
 S D0="" F  S D0=$O(^TMP("MAG",$J,"QR",5,D0)) Q:D0=""  D
 . S MAGDFN=$$GET1^DIQ(123,D0,.02,"I") Q:'MAGDFN  ; No Patient IEN
 . Q:$$GET1^DIQ(123,D0,8)="CANCELLED"
 . I $O(^MAG(2006.5839,"C",123,D0,0)) D  ; 1+ studies assoc w/consult - P231 PMK 6/16/2020
 . . S IMAGE=0
 . . F  S IMAGE=$O(^MAG(2006.5839,"C",123,D0,IMAGE)) Q:'IMAGE  D
 . . . S X=$G(^MAG(2006.5839,IMAGE,0)) Q:X=""
 . . . S X=MAGDFN_"^"_$P(X,"^",1)_"^"_$P(X,"^",2)_"^"_$P(X,"^",3)_"^"_GMRCIEN
 . . . S @TMPQ@(6,"C^"_X)="",ACC=1
 . . . Q
 . . Q
 . D  ; Also find images in ^TIU - P231 PMK 6/16/2020
 . . D TIUALL^MAGDGMRC(D0,.RESULT)
 . . S I="" F  S I=$O(RESULT(I)) Q:I=""  D
 . . . S X=MAGDFN_"^8925^"_$P(RESULT(I),"^",1)_"^"_$P(RESULT(I),"^",3)_"^"_$P(RESULT(I),"^",2)
 . . . S @TMPQ@(6,"C^"_X)="",ACC=1
 . . . Q
 . . Q
 . Q
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGDQR73   2422     printed  Sep 23, 2025@19:37:20                                                                                                                                                                                                    Page 2
MAGDQR73  ;WOIFO/MLH/PMK - Imaging RPCs for Query/Retrieve - acc# scan for consult recs (old DB) ; Jun 16, 2020@14:06:52
 +1       ;;3.0;IMAGING;**118,138,231**;Mar 19, 2002;Build 9;Sep 03, 2013
 +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 
 +18      ; called from MAGDQR07
 +19      ;
ACCCON(REQ,T,P,ACC) ; scan old structure for Consult Related Images
 +1        NEW TMPQ,ACCNUM,GMRCIEN,I,D0,MAGDFN,IMAGE,X,RESULT
 +2        SET TMPQ=$NAME(^TMP("MAG",$JOB,"QR"))
           KILL @TMPQ@(5)
 +3        SET (ACCNUM,GMRCIEN)=REQ(T,P)
 +4        SET X=$$GMRCIEN^MAGDFCNV(ACCNUM)
           IF X
               SET GMRCIEN=X
 +5       ; For the time being, we can only do this:
 +6        if GMRCIEN
               SET @TMPQ@(5,GMRCIEN)=""
 +7        SET I=$$MATCHD^MAGDQR03(GMRCIEN,"^GMR(123,LOOP)","@TMPQ@(5,LOOP)")
 +8        SET D0=""
           FOR 
               SET D0=$ORDER(^TMP("MAG",$JOB,"QR",5,D0))
               if D0=""
                   QUIT 
               Begin DoDot:1
 +9       ; No Patient IEN
                   SET MAGDFN=$$GET1^DIQ(123,D0,.02,"I")
                   if 'MAGDFN
                       QUIT 
 +10               if $$GET1^DIQ(123,D0,8)="CANCELLED"
                       QUIT 
 +11      ; 1+ studies assoc w/consult - P231 PMK 6/16/2020
                   IF $ORDER(^MAG(2006.5839,"C",123,D0,0))
                       Begin DoDot:2
 +12                       SET IMAGE=0
 +13                       FOR 
                               SET IMAGE=$ORDER(^MAG(2006.5839,"C",123,D0,IMAGE))
                               if 'IMAGE
                                   QUIT 
                               Begin DoDot:3
 +14                               SET X=$GET(^MAG(2006.5839,IMAGE,0))
                                   if X=""
                                       QUIT 
 +15                               SET X=MAGDFN_"^"_$PIECE(X,"^",1)_"^"_$PIECE(X,"^",2)_"^"_$PIECE(X,"^",3)_"^"_GMRCIEN
 +16                               SET @TMPQ@(6,"C^"_X)=""
                                   SET ACC=1
 +17                               QUIT 
                               End DoDot:3
 +18                       QUIT 
                       End DoDot:2
 +19      ; Also find images in ^TIU - P231 PMK 6/16/2020
                   Begin DoDot:2
 +20                   DO TIUALL^MAGDGMRC(D0,.RESULT)
 +21                   SET I=""
                       FOR 
                           SET I=$ORDER(RESULT(I))
                           if I=""
                               QUIT 
                           Begin DoDot:3
 +22                           SET X=MAGDFN_"^8925^"_$PIECE(RESULT(I),"^",1)_"^"_$PIECE(RESULT(I),"^",3)_"^"_$PIECE(RESULT(I),"^",2)
 +23                           SET @TMPQ@(6,"C^"_X)=""
                               SET ACC=1
 +24                           QUIT 
                           End DoDot:3
 +25                   QUIT 
                   End DoDot:2
 +26               QUIT 
               End DoDot:1
 +27       QUIT