Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: MAGDSTAB

MAGDSTAB.m

Go to the documentation of this file.
  1. MAGDSTAB ;WOIFO/PMK - Q/R Retrieve of DICOM images from PACS to VistA ; Mar 04, 2022@14:35:44
  1. ;;3.0;IMAGING;**231,306,305**;Mar 19, 2002;Build 3
  1. ;; Per VHA Directive 2004-038, this routine should not be modified.
  1. ;; +---------------------------------------------------------------+
  1. ;; | Property of the US Government. |
  1. ;; | No permission to copy or redistribute this software is given. |
  1. ;; | Use of unreleased versions of this software requires the user |
  1. ;; | to execute a written test agreement with the VistA Imaging |
  1. ;; | Development Office of the Department of Veterans Affairs, |
  1. ;; | telephone (301) 734-0100. |
  1. ;; | The Food and Drug Administration classifies this software as |
  1. ;; | a medical device. As such, it may not be changed in any way. |
  1. ;; | Modifications to this software may result in an adulterated |
  1. ;; | medical device under 21CFR820, the use of which is considered |
  1. ;; | to be a violation of US Federal Statutes. |
  1. ;; +---------------------------------------------------------------+
  1. ;;
  1. ;
  1. ; Supported IA #10061 reference DEM^VADPT subroutine call
  1. ; Supported IA #2541 reference $$KSP^XUPARAM function call
  1. ; Supported IA #2056 reference $$GET1^DIQ function call
  1. ;
  1. Q
  1. ;
  1. ; QUERY and RETRIEVE are called by MAGDSTAA when
  1. ; there are no images for the study on VistA
  1. ;
  1. ; They is used to retrieve all the images for a study.
  1. ;
  1. ; There are two steps to the process.
  1. ; First, a query is performed to obtain the Study Instance UID
  1. ; Second, the retrieve is performed using the Study Instance UID
  1. ;
  1. ; If it is "query only mode" then, just the first step is done.
  1. ;
  1. ; Study Root Study Level query and retrieve are used,
  1. ; so ALL the images for the study are retrieved.
  1. ;
  1. ; Note: Patient identification information is not used
  1. ;
  1. FINDSUID(ACNUMB,SSN,PACSSTUDYUID,SERIESCOUNT,IMAGECOUNT) ; get study instance uid
  1. N I,L,RETURN
  1. ;
  1. ; check that accession number exists
  1. I $G(ACNUMB)="" Q "-1,No Accession Number" ; nope
  1. ;
  1. K ^TMP("MAG",$J,"Q/R QUERY")
  1. I IMAGINGSERVICE="RADIOLOGY" D ; add accession number prefix to legacy radiology acn's
  1. . S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"ACCESSION NUMBER")=$S($L(ACNUMB,"-")<3:$$ANPREFIX_ACNUMB,1:ACNUMB)
  1. . Q
  1. E S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"ACCESSION NUMBER")=ACNUMB
  1. ;
  1. ; P305 PMK 11/17/2021 - make last four digits optional
  1. ;
  1. I $$ACNLAST4="Y" D ; default is NO
  1. . ; P306 PMK 06/11/2021 - add last four digits of SSN (MRN) to PATIENT ID to make query unique
  1. . ; when there are multiple studies with same accession because of PACS merges
  1. . S L=$L(SSN) ; length of SSN=9; MRN may have a different length
  1. . S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"PATIENT ID")="*"_$E(SSN,L-3,L) ; * + last four digits
  1. . Q
  1. ;
  1. S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"QUERY USER APPLICATION")=$$QRSCP^MAGDSTA8
  1. S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"QUERY LEVEL")="STUDY"
  1. S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"ROOT")="STUDY"
  1. D SOPUIDQ^MAGDSTV1 ; C-FIND
  1. ;
  1. ; Note: There may be multiple study instance UIDs for a study
  1. S (SERIESCOUNT,IMAGECOUNT)=0
  1. F I=1:1 Q:'$D(^XTMP(MAGXTMP,HOSTNAME,$J,QRSTACK,"STUDY",1,I)) D
  1. . ; get PACS Study UIDs
  1. . S PACSSTUDYUID(I)=$G(^XTMP(MAGXTMP,HOSTNAME,$J,QRSTACK,"STUDY",1,I,"STUDYUID"))
  1. . ; get number of study related series and study related sop instances
  1. . S SERIESCOUNT=SERIESCOUNT+$G(^XTMP(MAGXTMP,HOSTNAME,$J,QRSTACK,"STUDY",1,I,"NSTUDYRS"))
  1. . S IMAGECOUNT=IMAGECOUNT+$G(^XTMP(MAGXTMP,HOSTNAME,$J,QRSTACK,"STUDY",1,I,"NSTUDYRI"))
  1. . Q
  1. Q ""
  1. ;
  1. ;
  1. MOVEALL() ; retrieve all the images for the study
  1. N ERROR,I
  1. ;
  1. S ERROR=""
  1. ; Note: There may be multiple study instance UIDs for a study
  1. F I=1:1 Q:'$D(^XTMP(MAGXTMP,HOSTNAME,$J,QRSTACK,"STUDY",1,I)) D Q:ERROR
  1. . ; get the Study Instance UID needed to perform the retrieve
  1. . S STUDYUID=$G(^XTMP(MAGXTMP,HOSTNAME,$J,QRSTACK,"STUDY",1,I,"STUDYUID"))
  1. . S ERROR=$$MOVEALL1(STUDYUID)
  1. . I ERROR Q
  1. . Q
  1. Q ERROR
  1. ;
  1. MOVEALL1(STUDYUID) ; retrieve all the images for the Study Instance UID
  1. ; retrieve the whole study
  1. S STUDYUID=$G(STUDYUID)
  1. I STUDYUID="" Q "-1,No Study UID"
  1. ;
  1. K ^TMP("MAG",$J,"Q/R QUERY")
  1. S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"STUDY INSTANCE UID(0001)")=STUDYUID
  1. S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"QUERY USER APPLICATION")=$$QRSCP^MAGDSTA8
  1. S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"RETRIEVE LEVEL")="STUDY"
  1. S ^TMP("MAG",$J,"Q/R QUERY",QRSTACK,"ROOT")="STUDY"
  1. D SOPUIDR^MAGDSTV1 ; C-MOVE
  1. Q ""
  1. ;
  1. PARM ; set query/retrieve site parameters
  1. N ANPREFIX,IEN,KSITEPAR
  1. S KSITEPAR=$$KSP^XUPARAM("INST")
  1. S IEN=$O(^MAG(2006.1,"B",KSITEPAR,""))
  1. ;
  1. ; get the accession number prefix, if there is one
  1. S ANPREFIX=$$GETANPFX^MAGDSTQ1($$ANPREFIX)
  1. S $P(^MAG(2006.1,IEN,7),"^",3)=ANPREFIX
  1. ;
  1. ; get the patient identifier dash or no dash
  1. S DEFAULT=$$DASHES
  1. I $$YESNO^MAGDSTQ("Include dashes in the DICOM Patient Identifier?",DEFAULT,.X)<0 Q
  1. S $P(^MAG(2006.1,IEN,7),"^",4)=$E(X)
  1. ;
  1. ; get the patient identifier last 4 or no last 4
  1. S DEFAULT=$$ACNLAST4
  1. I $$YESNO^MAGDSTQ("Use LAST 4 in the PID with Accession Number in the automatic query?",DEFAULT,.X)<0 Q
  1. S $P(^MAG(2006.1,IEN,7),"^",7)=$E(X)
  1. ;
  1. ; get the check study division switch
  1. N HELP
  1. S HELP(1)="If there are VistA Imaging file servers at other divisions, answer ""Y""."
  1. S HELP(2)=" Then only studies for this division will be processed,"
  1. S HELP(3)=" and those for the other divisions will be ignored."
  1. S HELP(4)=""
  1. S HELP(5)="If there is only one VistA Imaging file server for all divisions, answer ""N""."
  1. S HELP(6)=" Then all the studies will be processed."
  1. S DEFAULT=$$CHECKDIV
  1. I $$YESNO^MAGDSTQ("Select only studies for the current division for auto compare/retrieve?",DEFAULT,.X,.HELP)<0 Q
  1. S $P(^MAG(2006.1,IEN,8),"^",1)=$E(X)
  1. ;
  1. D CONTINUE^MAGDSTQ
  1. Q
  1. ;
  1. ANPREFIX() ; Get the value of the accession number prefix
  1. N IEN,KSITEPAR
  1. S KSITEPAR=$$KSP^XUPARAM("INST")
  1. S IEN=$O(^MAG(2006.1,"B",KSITEPAR,""))
  1. Q $$GET1^DIQ(2006.1,IEN,206)
  1. ;
  1. DASHES() ; Get the value of the patient identifier dashes
  1. N IEN,KSITPAR
  1. S KSITEPAR=$$KSP^XUPARAM("INST")
  1. S IEN=$O(^MAG(2006.1,"B",KSITEPAR,""))
  1. Q $$GET1^DIQ(2006.1,IEN,207,"I")
  1. ;
  1. ACNLAST4() ; Get the value of the last 4 query key
  1. N IEN,KSITEPAR
  1. S KSITEPAR=$$KSP^XUPARAM("INST")
  1. S IEN=$O(^MAG(2006.1,"B",KSITEPAR,""))
  1. Q $$GET1^DIQ(2006.1,IEN,210,"I")
  1. ;
  1. CHECKDIV() ; Get the value of the check study division switch
  1. N IEN,KSITEPAR
  1. S KSITEPAR=$$KSP^XUPARAM("INST")
  1. S IEN=$O(^MAG(2006.1,"B",KSITEPAR,""))
  1. Q $$GET1^DIQ(2006.1,IEN,211,"I")
  1. ;