MAGDQR71 ;WOIFO/MLH,NST,PMK - Imaging RPCs for Query/Retrieve - acc# scan (new); Feb 15, 2022@10:26:54
 ;;3.0;IMAGING;**118,305**;Mar 19, 2002;Build 3
 ;; 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 by MAGDQR07
 ;
ACCNEW(REQ,T,P,ACC) ;look in the new database structure
 ; Add patient DFN and Study IEN to ^TMP("MAG",$J,"QR",6) in format
 ; ^TMP("MAG",$J,"QR",6,"N^"_MAGD0_"^"_STUDYIX)
 ;              where MAGD0 is patient DFN
 ;                    STUDYIX is IEN in IMAGE STUDY file (#2005.62)
 ;
 N PROQIX,TMPQ,I,PROBLEM61,V
 S TMPQ=$NA(^TMP("MAG",$J,"QR")) K @TMPQ@(5)
 S I=$$MATCHD^MAGDQR03(REQ(T,P),"^RADPT(""ADC"",LOOP)","@TMPQ@(5,LOOP)")  ; Radiology lookup
 S I=$$MATCHD^MAGDQR03(REQ(T,P),"^RADPT(""ADC1"",LOOP)","@TMPQ@(5,LOOP)")  ; Radiology lookup
 ;
 ; check accession number for inaccessible or artifact not on file - P305 PMK 12/06/2021
 S PROBLEM61=0,PROCIX="" ; procedure level indexed by accession number
 F  S PROCIX=$O(^MAGV(2005.61,"B",ACC,PROCIX)) Q:'PROCIX  D
 . I $$PROBLEM61^MAGDSTA8(PROCIX) S PROBLEM61=1 ; patient not available - quit
 . Q
 I 'PROBLEM61 D
 . S I=$$MATCHD^MAGDQR03(REQ(T,P),"^MAGV(2005.61,""B"",LOOP)","@TMPQ@(5,LOOP)")
 . Q
 ;
 S V="" F  S V=$O(@TMPQ@(5,V)) Q:V=""  D  ; V is an accession number
 . S:$$ADDSTUDY^MAGDQR74(V,$NA(@TMPQ@(6)),"") ACC=1
 . Q
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGDQR71   2293     printed  Sep 23, 2025@19:37:18                                                                                                                                                                                                    Page 2
MAGDQR71  ;WOIFO/MLH,NST,PMK - Imaging RPCs for Query/Retrieve - acc# scan (new); Feb 15, 2022@10:26:54
 +1       ;;3.0;IMAGING;**118,305**;Mar 19, 2002;Build 3
 +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 by MAGDQR07
 +19      ;
ACCNEW(REQ,T,P,ACC) ;look in the new database structure
 +1       ; Add patient DFN and Study IEN to ^TMP("MAG",$J,"QR",6) in format
 +2       ; ^TMP("MAG",$J,"QR",6,"N^"_MAGD0_"^"_STUDYIX)
 +3       ;              where MAGD0 is patient DFN
 +4       ;                    STUDYIX is IEN in IMAGE STUDY file (#2005.62)
 +5       ;
 +6        NEW PROQIX,TMPQ,I,PROBLEM61,V
 +7        SET TMPQ=$NAME(^TMP("MAG",$JOB,"QR"))
           KILL @TMPQ@(5)
 +8       ; Radiology lookup
           SET I=$$MATCHD^MAGDQR03(REQ(T,P),"^RADPT(""ADC"",LOOP)","@TMPQ@(5,LOOP)")
 +9       ; Radiology lookup
           SET I=$$MATCHD^MAGDQR03(REQ(T,P),"^RADPT(""ADC1"",LOOP)","@TMPQ@(5,LOOP)")
 +10      ;
 +11      ; check accession number for inaccessible or artifact not on file - P305 PMK 12/06/2021
 +12      ; procedure level indexed by accession number
           SET PROBLEM61=0
           SET PROCIX=""
 +13       FOR 
               SET PROCIX=$ORDER(^MAGV(2005.61,"B",ACC,PROCIX))
               if 'PROCIX
                   QUIT 
               Begin DoDot:1
 +14      ; patient not available - quit
                   IF $$PROBLEM61^MAGDSTA8(PROCIX)
                       SET PROBLEM61=1
 +15               QUIT 
               End DoDot:1
 +16       IF 'PROBLEM61
               Begin DoDot:1
 +17               SET I=$$MATCHD^MAGDQR03(REQ(T,P),"^MAGV(2005.61,""B"",LOOP)","@TMPQ@(5,LOOP)")
 +18               QUIT 
               End DoDot:1
 +19      ;
 +20      ; V is an accession number
           SET V=""
           FOR 
               SET V=$ORDER(@TMPQ@(5,V))
               if V=""
                   QUIT 
               Begin DoDot:1
 +21               if $$ADDSTUDY^MAGDQR74(V,$NAME(@TMPQ@(6)),"")
                       SET ACC=1
 +22               QUIT 
               End DoDot:1
 +23       QUIT