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

MAGNUID1.m

Go to the documentation of this file.
  1. MAGNUID1 ;WOIFO/NST - DICOM UID generator ; 15 Oct 2010 12:45 AM
  1. ;;3.0;IMAGING;**106**;Mar 19, 2002;Build 2002;Feb 28, 2011
  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. Q
  1. ;
  1. ;***** Generates a new DICOM UID
  1. ;
  1. ; RPC: N/A
  1. ;
  1. ; Input Parameters
  1. ; ================
  1. ; SITE - VistA Station Number field #99 in INSTITUTION file (#4)
  1. ; SUBROOT - (Optional) A number, Default value is 0.
  1. ; (e.g. 106, 4, 7, 8, or 106.4
  1. ; 4 - STUDY UID,
  1. ; 7 - SERIES UID,
  1. ; 8 - SOP INSTANCE UID,
  1. ; 106.4 - patch 106 STUDY UID.
  1. ; ROOTOWNER - (Optional) Name of the DICOM root owner.
  1. ; Default value is "Veterans' Administration".
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; if error MAGRY = 0^Error message
  1. ; if success MAGRY = 1^New DICOM UID
  1. ;
  1. NEWUID(MAGRY,SITE,SUBROOT,ROOTOWNER) ; Generates a new DICOM UID
  1. N ROOT,DTSTAMP,UNISITE,LASTCNT,CNT
  1. N ROOTIEN,UID,LASTUPDATE,X
  1. N MAGRESA,MAGNFDA,MAGNXE
  1. ;
  1. I SITE="" S MAGRY="0^Station number is blank" Q ; fatal error
  1. S:$G(SUBROOT)="" SUBROOT=0
  1. S:$G(ROOTOWNER)="" ROOTOWNER="Veterans' Administration" ; VA is a default root owner
  1. S ROOTIEN=$$FIND1^DIC(2006.15,"","BX",ROOTOWNER)
  1. I ROOTIEN'>0 S MAGRY="0^Root UID is not found" Q ; fatal error
  1. ;
  1. S ROOT=$P($G(^MAGD(2006.15,ROOTIEN,"UID ROOT")),"^",1)
  1. I ROOT="" S MAGRY="0^DICOM root is missing." Q
  1. S DTSTAMP=$$DATETIME()
  1. S UNISITE=$$CONVS2N(SITE)
  1. I UNISITE'>0 S MAGRY="0^Cannot convert SITE NUMBER to numeric value" Q
  1. L +^MAGD(2006.15,ROOTIEN,1):1E9 ; Lock
  1. S X=$G(^MAGD(2006.15,ROOTIEN,1))
  1. S LASTUPDATE=$P(X,"^",1)
  1. S LASTCNT=$P(X,"^",2)
  1. ;
  1. S CNT=LASTCNT+1 ; Increment the TICK
  1. I (LASTUPDATE\1)'=(DTSTAMP\1) S CNT=1 ; Reset the TICK. New day - new beginning
  1. ;
  1. I (LASTUPDATE=DTSTAMP),(LASTCNT'<CNT) D Q
  1. . S MAGRY="0^Last UID tick is greater than the new one"
  1. . L -^MAGD(2006.15,ROOTIEN,1) ; Unlock
  1. . Q
  1. I LASTUPDATE>DTSTAMP D Q
  1. . S MAGRY="0^Last UID datetime stamp is greater than the new one"
  1. . L -^MAGD(2006.15,ROOTIEN,1) ; Unlock
  1. . Q
  1. ;
  1. K MAGNFDA
  1. S MAGNFDA(2006.15,ROOTIEN_",",2)=DTSTAMP
  1. S MAGNFDA(2006.15,ROOTIEN_",",3)=CNT
  1. D UPDATE^DIE("","MAGNFDA","","MAGNXE")
  1. L -^MAGD(2006.15,ROOTIEN,1) ; Unlock
  1. ;
  1. I $D(MAGNXE("DIERR","E")) D Q
  1. . D MSG^DIALOG("A",.MAGRESA,245,5,"MAGNXE")
  1. . S MAGRY="0^"_MAGRESA(1)
  1. . Q
  1. ;
  1. S UID=ROOT_"."_SUBROOT_"."_UNISITE_"."_DTSTAMP_"."_CNT
  1. I $L(UID)>64 S MAGRY="0^Generated UID is greater than 64 characters" Q
  1. S MAGRY="1^"_UID
  1. Q
  1. ;
  1. DATETIME() ; Get Date time
  1. Q $$NOW^XLFDT
  1. ;
  1. CONVS2N(STRTOCNV) ; Convert a string to a unique number
  1. ; The string should include characters from "0" to "Z"
  1. ; If other character is found -1 will be return
  1. ; Before the conversion all characters are converted to upper case
  1. N I,X,RESULT,FACTOR,ERR
  1. S ERR=0
  1. S RESULT=""
  1. S FACTOR=1
  1. S STRTOCNV=$$UP^XLFSTR(STRTOCNV) ; All upper case
  1. ; Start with the last character
  1. F I=$L(STRTOCNV):-1:1 D Q:ERR
  1. . S X=$A($E(STRTOCNV,I))-48 ; offset the ASCII number with 48. "0" is 0, "Z" is 42
  1. . I (X<0)!(X>42) S ERR=1 Q
  1. . S RESULT=RESULT+(FACTOR*X)
  1. . S FACTOR=FACTOR*43 ; 43 is the number of characters between "0" and "Z"
  1. . Q
  1. Q:ERR -1 ; a character is not in the "0"-"Z" range
  1. Q RESULT