MAGVUID1 ;WOIFO/RRB - DICOM UID Generator ; 19 Sep 2011 6:10 PM
 ;;3.0;IMAGING;**118**;Mar 19, 2002;Build 4525;May 01, 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
 ;
 ;
STUDY(UID,SITE,ID) ; generate a Study uid
 N TYPE
 S UID=$$UID(4,SITE,ID)
 Q
 ;
SERIES(UID,SITE,ID) ; generate a Series uid
 N TYPE
 S UID=$$UID(7,SITE,ID)
 Q
 ;
SOP(UID,SITE,ID) ; generate a SOP uid
 N TYPE
 S UID=$$UID(8,SITE,ID)
 Q
 ;
 ;
UID(TYPE,SITE,NUMBER) ; generate a UID
 N X,I,UID
 S X=""
 F I=1:1:$L(SITE) S X=X_$S($E(SITE,I)?1N:$E(SITE,I),1:$A(SITE,I))
 S UID=$G(^MAGD(2006.15,1,"UID ROOT"))_".1."_TYPE_"."_X
 I $D(NUMBER) S UID=UID_"."_NUMBER
 ; Remove leading 0s from UID components
 F I=1:1:$L(UID,".") S $P(UID,".",I)=+$P(UID,".",I)
 I $L(UID)>64 S UID="-3~Generated UID > 64 Characters"  ; fatal error
 ;
 Q UID
 ;
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGVUID1   1796     printed  Sep 23, 2025@19:46:54                                                                                                                                                                                                    Page 2
MAGVUID1  ;WOIFO/RRB - DICOM UID Generator ; 19 Sep 2011 6:10 PM
 +1       ;;3.0;IMAGING;**118**;Mar 19, 2002;Build 4525;May 01, 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      ;
 +19      ;
STUDY(UID,SITE,ID) ; generate a Study uid
 +1        NEW TYPE
 +2        SET UID=$$UID(4,SITE,ID)
 +3        QUIT 
 +4       ;
SERIES(UID,SITE,ID) ; generate a Series uid
 +1        NEW TYPE
 +2        SET UID=$$UID(7,SITE,ID)
 +3        QUIT 
 +4       ;
SOP(UID,SITE,ID) ; generate a SOP uid
 +1        NEW TYPE
 +2        SET UID=$$UID(8,SITE,ID)
 +3        QUIT 
 +4       ;
 +5       ;
UID(TYPE,SITE,NUMBER) ; generate a UID
 +1        NEW X,I,UID
 +2        SET X=""
 +3        FOR I=1:1:$LENGTH(SITE)
               SET X=X_$SELECT($EXTRACT(SITE,I)?1N:$EXTRACT(SITE,I),1:$ASCII(SITE,I))
 +4        SET UID=$GET(^MAGD(2006.15,1,"UID ROOT"))_".1."_TYPE_"."_X
 +5        IF $DATA(NUMBER)
               SET UID=UID_"."_NUMBER
 +6       ; Remove leading 0s from UID components
 +7        FOR I=1:1:$LENGTH(UID,".")
               SET $PIECE(UID,".",I)=+$PIECE(UID,".",I)
 +8       ; fatal error
           IF $LENGTH(UID)>64
               SET UID="-3~Generated UID > 64 Characters"
 +9       ;
 +10       QUIT UID
 +11      ;