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

MAGVGUID.m

Go to the documentation of this file.
  1. MAGVGUID ;WOIFO/RRB,DAC,JSJ - Duplicate DICOM Study, Series, & SOP Instance UID Checks ; Jul 14, 2021@10:02:27:59
  1. ;;3.0;IMAGING;**118,138,162,262,307**;Mar 19, 2002;Build 28
  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. ; Reference to ^RA(74 in ICR #1171
  1. ; Reference to ^RA(70 in ICR #1172
  1. ; Reference to GET1^DIQ in ICR #2056
  1. Q
  1. ;
  1. ; check for duplicate SOP Instance UID
  1. SOP(DFN,ACNUMB,STUDYUID,SERIESUID,SOPUID) ;
  1. N MAGIEN ;--- ien of 2005 DICOM object
  1. N DUPSOP ;--- -1 = Error, 1 = Duplicate UID, 2 = RESEND
  1. ;
  1. ; is there a DICOM object on file with this SOP Instance UID?
  1. I '$O(^MAG(2005,"P",SOPUID,0)) Q 0 ; nope
  1. ;
  1. ; is the same DICOM object already on file?
  1. ; there might be multiples and we have to check each one
  1. S MAGIEN=0,DUPSOP=0
  1. F S MAGIEN=$O(^MAG(2005,"P",SOPUID,MAGIEN)) Q:MAGIEN="" D Q:DUPSOP
  1. . S DUPSOP=$$SAMEIMG(MAGIEN,DFN,STUDYUID,SERIESUID)
  1. . Q
  1. S DUPSOP=$S(DUPSOP=0:2,1:DUPSOP)
  1. Q DUPSOP
  1. ;
  1. SAMEIMG(MAGIEN,DFN,STUDYUID,SERIESUID) ; check DFN and study & series UIDs
  1. N MAG0 ;----- 0-node of file 2005
  1. N MAGDFN ;--- DFN of designated image
  1. N MAGGROUP ;- pointer to the image group
  1. N MAGPTR,MAGACN
  1. N OLDSTUDY,OLDSERIES ; UIDs of the original series or study
  1. ; check for defined arguments
  1. Q:$G(MAGIEN)="" -1
  1. Q:$G(DFN)="" -1
  1. Q:$G(STUDYUID)="" -1
  1. Q:$G(SERIESUID)="" -1
  1. S MAG0=$G(^MAG(2005,MAGIEN,0)) Q:MAG0="" -1 ; no 0-node
  1. S MAGDFN=$P(MAG0,"^",7) Q:DFN'=MAGDFN 1 ; different patient
  1. S MAGGROUP=$P(MAG0,"^",10)
  1. ; P162 DAC - Accession Number Check producing duplicates instread of resends
  1. S OLDSTUDY=$S(MAGGROUP:$P($G(^MAG(2005,MAGGROUP,"PACS")),"^",1),1:"")
  1. I $L(OLDSTUDY),OLDSTUDY'=STUDYUID Q 1 ; different study instance UIDs
  1. S OLDSERIES=$G(^MAG(2005,MAGIEN,"SERIESUID"))
  1. I $L(OLDSERIES),OLDSERIES'=SERIESUID Q 1 ; different series instance UIDs
  1. Q 0
  1. ;
  1. ; check for duplicate Series Instance UID
  1. SERIES(DFN,ACNUMB,STUDYUID,SERIESUID) ;
  1. N MAG0 ;----- 0-node of file 2005
  1. N MAGACN ;--- accession number of 2005 DICOM object
  1. N MAGIEN ;--- ien of 2005 DICOM object
  1. N MAGIENG ;-- ien of 2005 DICOM object in group file (2005.04)
  1. N MAGDFN ;--- DFN of designated image
  1. N MAGGROUP ;- pointer to the image group
  1. N MAGSTUID ;- study instance uid of 2005 DICOM object
  1. N DUPSERIES
  1. N I,X
  1. ;
  1. ; is there a DICOM object on file with this Series Instance UID?
  1. I '$O(^MAG(2005,"SERIESUID",SERIESUID,0)) Q 0 ; nope
  1. ;
  1. K ^TMP("MAG",$J,"SERIES UID")
  1. ;
  1. ; First pass - get the list of DICOM objects for this series
  1. ;
  1. S MAGIEN=0
  1. F S MAGIEN=$O(^MAG(2005,"SERIESUID",SERIESUID,MAGIEN)) Q:MAGIEN="" D
  1. . S ^TMP("MAG",$J,"SERIES UID",MAGIEN)=""
  1. . Q
  1. ;
  1. ; Second pass - for each DICOM object on file, do the following steps
  1. ; 1) look up the group and get DFN, ACNUMB, Study Instance UID
  1. ; 2) record this information for the first DICOM object in each group
  1. ; 3) skip other DICOM objects in same group - redundant information
  1. ;
  1. S MAGIEN=0
  1. F S MAGIEN=$O(^TMP("MAG",$J,"SERIES UID",MAGIEN)) Q:'MAGIEN S X=^(MAGIEN) D
  1. . Q:X?1"SKIP".E ; skip DICOM objects in groups that were already processed
  1. . S MAG0=$G(^MAG(2005,MAGIEN,0)) Q:MAG0=""
  1. . S MAGDFN=$P(MAG0,"^",7),MAGGROUP=$P(MAG0,"^",10)
  1. . S MAGSTUID=$P($G(^MAG(2005,MAGGROUP,"PACS")),"^",1)
  1. . ; P262 DAC - Added 2nd ACNUMB parameter
  1. . S MAGACN=$$GETACN(MAGIEN,ACNUMB)
  1. . S X=MAGDFN_"^"_MAGACN_"^"_MAGSTUID
  1. . S ^TMP("MAG",$J,"SERIES UID",MAGIEN)=X
  1. . ; go through the object group file (2005.04) and remove redundancies
  1. . S I=0 F S I=$O(^MAG(2005,MAGGROUP,1,I)) Q:'I S X=^(I,0) D
  1. . . S MAGIENG=$P(X,"^",1) Q:MAGIENG=MAGIEN ; keep first object
  1. . . I $D(^TMP("MAG",$J,"SERIES UID",MAGIENG)) S ^(MAGIENG)="SKIP-"_MAGIEN
  1. . . Q
  1. . Q
  1. ;
  1. ; Third pass - check remaining entries in ^TMP for duplicates
  1. ;
  1. S MAGIEN="",DUPSERIES=0
  1. F S MAGIEN=$O(^TMP("MAG",$J,"SERIES UID",MAGIEN)) Q:MAGIEN="" D Q:DUPSERIES
  1. . S X=^TMP("MAG",$J,"SERIES UID",MAGIEN)
  1. . Q:X["SKIP"
  1. . S MAGDFN=$P(X,"^",1),MAGACN=$P(X,"^",2),MAGSTUID=$P(X,"^",3)
  1. . S DUPSERIES=1
  1. . I DFN=MAGDFN,ACNUMB=MAGACN,STUDYUID=MAGSTUID S DUPSERIES=0
  1. . Q
  1. ;
  1. Q DUPSERIES
  1. ;
  1. ; check for duplicate Study Instance UID
  1. STUDY(DFN,ACNUMB,STUDYUID) ;
  1. N HIT ;------ switch
  1. N MAGIEN ;--- ien of 2005 DICOM object
  1. ;
  1. ; is there a DICOM object on file with this Study Instance UID?
  1. I '$O(^MAG(2005,"P",STUDYUID,0)) Q 0 ; nope
  1. ;
  1. ; is the same DICOM object already on file?
  1. ; there might be multiples and we have to check each one
  1. S (HIT,MAGIEN)=0
  1. F S MAGIEN=$O(^MAG(2005,"P",STUDYUID,MAGIEN)) Q:MAGIEN="" D Q:HIT
  1. . S HIT=$$SAMESTDY(MAGIEN,DFN,ACNUMB)
  1. . Q
  1. ;
  1. Q HIT
  1. ;
  1. SAMESTDY(MAGIEN,DFN,ACNUMB) ;
  1. N MAG0 ; 0-node and 2-node of file 2005
  1. N MAGDFN ; DFN of designated image
  1. S MAG0=$G(^MAG(2005,MAGIEN,0)) Q:MAG0="" -1 ; no 0-node
  1. S MAGDFN=$P(MAG0,"^",7) Q:DFN'=MAGDFN 1 ; different patient
  1. ; P262 - Added 2nd ACNUMB parameter
  1. I ACNUMB'=$$GETACN(MAGIEN,ACNUMB) Q 1 ; different accession
  1. Q 0
  1. ;
  1. GETACN(MAGIEN,ACNUMB) ; P262 DAC - Added 2nd ACNUMB parameter - return the accession number of a study
  1. N ACNUMBVAH ; VA HIS accession number
  1. N DATETIME ; Accession DateTime
  1. N MAG2 ; 2-node of file 2005
  1. N RARPT0 ; 0-node of ^RARPT
  1. N RADPT0 ; 0-node of ^RADPT
  1. N REVDT ;
  1. N ROOT,POINTER ; parent data file root and pointer
  1. S MAG2=$G(^MAG(2005,MAGIEN,2)) Q:MAG2="" "" ; no 2-node
  1. S ROOT=$P(MAG2,"^",6),POINTER=$P(MAG2,"^",7)
  1. S ACNUMBVAH="" ; P262 DAC - Predfine as null
  1. I ROOT=74 D
  1. . S RARPT0=$G(^RARPT(POINTER,0)),DATETIME=$P(RARPT0,"^",3)
  1. . S REVDT=9999999.9999-DATETIME
  1. . ; P262 DAC - Added IDX to loop through multiple file entries for the same date/time
  1. . N IDX S IDX=""
  1. . F D I ($G(ACNUMB)=$G(ACNUMBVAH))!(IDX="") Q
  1. . . S IDX=$O(^RADPT(DFN,"DT",REVDT,"P",IDX))
  1. . . Q:IDX=""
  1. . . S RADPT0=$G(^RADPT(DFN,"DT",REVDT,"P",IDX,0))
  1. . . S ACNUMBVAH=$P(RADPT0,"^",31)
  1. . . I ACNUMBVAH="" S ACNUMBVAH=$P(RARPT0,"^",1)
  1. . . ; if mismatch check accession cross reference for OTHER CASE# ;P307
  1. . . I (ACNUMBVAH'=ACNUMB),$D(^RARPT(POINTER,1,"B",ACNUMB)) S ACNUMBVAH=ACNUMB ; acc found as OTHER CASE#, set the return value ;P307
  1. . . Q
  1. . Q
  1. E I ROOT=8925 S ACNUMBVAH=$$GMRCACN^MAGDFCNV(+$$GET1^DIQ(8925,POINTER,1405,"I"))
  1. E I ROOT=2006.5839 S ACNUMBVAH=$$GMRCACN^MAGDFCNV(POINTER)
  1. E S ACNUMBVAH=""
  1. Q ACNUMBVAH
  1. ;