MAGDSTAD ;WOIFO/PMK - Q/R Retrieve of DICOM images from PACS to VistA ; Sep 10, 2020@10:46:09
 ;;3.0;IMAGING;**231**;5-May-2007;Build 9
 ;; 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
 ;
 ; Second Step, get study info from PACS.
 ; 
 ; Issue a PACS Study Root Study Level query (C-FIND) using the
 ; the Study Instance UID (0020,000D) as the key.
 ; Request the following return data attributes:
 ;   a. Number of Study Related Series (0020,1206)
 ;   b. Number of Study Related Instances (0020,1208)
 ;   c. Series Instance UID(s) (0020,000E)
 ;
 ; If the study cannot be found on the PACS, then return error.
 ;
STUDY(PACSSTUDYUID) ; get the study information
 N COUNT,I,RETURN,X
 S RETURN=0
 K ^TMP("MAG",$J,"Q/R QUERY")
 S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"STUDY INSTANCE UID(0001)")=PACSSTUDYUID
 S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"QUERY USER APPLICATION")=$$QRSCP^MAGDSTA8
 S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"QUERY LEVEL")="STUDY"
 S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"ROOT")="STUDY"
 D SOPUIDQ^MAGDSTV1 ; C-FIND
 I $D(^XTMP(MAGXTMP,HOSTNAME,$J,QRSTACK,"MESSAGE","MSG")) D
 . S X=$G(^XTMP(MAGXTMP,HOSTNAME,$J,QRSTACK,"MESSAGE","MSG",2))
 . I X="No matching PATIENT/STUDY was found" S RETURN=-1  ; study not found
 . E  S RETURN=-2 ; other errors, also just in case the message changes
 . Q
 Q RETURN
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGDSTAD   2294     printed  Sep 23, 2025@19:38:01                                                                                                                                                                                                    Page 2
MAGDSTAD  ;WOIFO/PMK - Q/R Retrieve of DICOM images from PACS to VistA ; Sep 10, 2020@10:46:09
 +1       ;;3.0;IMAGING;**231**;5-May-2007;Build 9
 +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      ;
 +19      ; Second Step, get study info from PACS.
 +20      ; 
 +21      ; Issue a PACS Study Root Study Level query (C-FIND) using the
 +22      ; the Study Instance UID (0020,000D) as the key.
 +23      ; Request the following return data attributes:
 +24      ;   a. Number of Study Related Series (0020,1206)
 +25      ;   b. Number of Study Related Instances (0020,1208)
 +26      ;   c. Series Instance UID(s) (0020,000E)
 +27      ;
 +28      ; If the study cannot be found on the PACS, then return error.
 +29      ;
STUDY(PACSSTUDYUID) ; get the study information
 +1        NEW COUNT,I,RETURN,X
 +2        SET RETURN=0
 +3        KILL ^TMP("MAG",$JOB,"Q/R QUERY")
 +4        SET ^TMP("MAG",$JOB,"Q/R QUERY",QRSTACK,"STUDY INSTANCE UID(0001)")=PACSSTUDYUID
 +5        SET ^TMP("MAG",$JOB,"Q/R QUERY",QRSTACK,"QUERY USER APPLICATION")=$$QRSCP^MAGDSTA8
 +6        SET ^TMP("MAG",$JOB,"Q/R QUERY",QRSTACK,"QUERY LEVEL")="STUDY"
 +7        SET ^TMP("MAG",$JOB,"Q/R QUERY",QRSTACK,"ROOT")="STUDY"
 +8       ; C-FIND
           DO SOPUIDQ^MAGDSTV1
 +9        IF $DATA(^XTMP(MAGXTMP,HOSTNAME,$JOB,QRSTACK,"MESSAGE","MSG"))
               Begin DoDot:1
 +10               SET X=$GET(^XTMP(MAGXTMP,HOSTNAME,$JOB,QRSTACK,"MESSAGE","MSG",2))
 +11      ; study not found
                   IF X="No matching PATIENT/STUDY was found"
                       SET RETURN=-1
 +12      ; other errors, also just in case the message changes
                  IF '$TEST
                       SET RETURN=-2
 +13               QUIT 
               End DoDot:1
 +14       QUIT RETURN