51. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 7/10/2017 1:01:43 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

51.1 Files compared

# Location File Last Modified
1 C:\AraxisMergeCompare\Pri_un\IV-ehmp_cif\ImagingCommon\main\src\java\gov\va\med\imaging ImageURN.java Thu Jun 29 17:23:00 2017 UTC
2 C:\AraxisMergeCompare\Pri_re\IV-ehmp_cif\ImagingCommon\main\src\java\gov\va\med\imaging ImageURN.java Thu Jul 6 15:02:23 2017 UTC

51.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 1682
Changed 1 2
Inserted 0 0
Removed 0 0

51.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

51.4 Active regular expressions

No regular expressions were active.

51.5 Comparison detail

  1   package go v.va.med.i maging;
  2  
  3   import gov .va.med.*;
  4   import gov .va.med.ex ceptions.G lobalArtif actIdentif ierFormatE xception;
  5   import gov .va.med.im aging.exce ptions.Ima geURNForma tException ;
  6   import gov .va.med.im aging.exce ptions.URN FormatExce ption;
  7   import gov .va.med.im aging.exch ange.utili ty.Base32C onversionU tility;
  8   import jav a.io.Seria lizable;
  9   import jav a.util.log ging.Logge r;
  10   import jav a.util.reg ex.Matcher ;
  11   import jav a.util.reg ex.Pattern ;
  12  
  13   /**
  14    * 
  15    * @author         
BECKEC
  16    *
  17    * Defines  the synta x of a URN  used to i dentify VA  images to  the outsi de world.
  18    * An Imag eURN is de fined to b e in the f ollowing f ormat:
  19    * "urn" +  ":" + "va image" + " :" + <site -id> + "-"  + <assign ed-id> + " -" + <stud yId> + "-"  + <patien tId> [+ "- " + <modal ity>]
  20    * where:
  21    *   <site -id> is ei ther the s ite from w hich the i mage origi nated or t he string  "va-imagin g"
  22    *   <assi gned-id> i s the perm anent, imm utable ID  as assigne d by the o riginating  site or a  
  23    *   VA-do main uniqu e ID (an I maging GUI D).
  24    *   <stud yId> is th e study IE N in VistA
  25    *   <imag eIcn> is t he unique  VA identif ier for th e patient
  26    *   <moda lity> is t he modalit y of the i mage
  27    *   
  28    * notes:
  29    *   Exter nally, the  site-id s hould not  be interpr eted as a  location c omponent.   It should  be 
  30    *   inter preted as  no more th an a speci fier in a  GUID (i.e.  just a co mponent th at restric ts 
  31    *   the r equired do main of un iqueness).   Initiall y and inte rnally to  the VA onl y, it may 
  32    *   be us ed as a lo cation hin t.  Extern al code th at relies  on the sit e ID as a  location
  33    *   may c ease funct ioning wit hout warni ng.
  34    *
  35    *   Image URN follow s the synt ax of a UR N as defin ed in W3C  RFC2141 wi th the fol lowing add itional
  36    *   rules  on the na mespace sp ecific str ing:
  37    *   The c haracter ' -' is a re served cha racter, us ed to deli mit portio ns of the  namespace
  38    *   speci fic string .  Specifi cally it i s used to  delimit th e originat ing site I D from the
  39    *   site- assigned i mage ID.
  40    *   The n amespace s pecific st ring must  consist of  uppercase , lowercas e and nume ric charac ters
  41    *   with  a '-' some where in t he middle.
  42    *   
  43    *   @see  http://www .ietf.org/ rfc/rfc214 1.txt
  44    *   
  45    * NOTE: b oth this c lass and D ocumentURN  MUST impl ement Glob alArtifact Identifier
  46    * 
  47   */
  48   @URNType(n amespace=" vaimage")
  49   public cla ss ImageUR
  50   extends Ab stractImag ingURN
  51   implements  Serializa ble, Globa lArtifactI dentifier
  52   {
  53           pr ivate stat ic final l ong serial VersionUID  = 1L;
  54           pu blic stati c final St ring NAMES PACE = "va image";
  55           pu blic stati c final We llKnownOID  DEFAULT_H OME_COMMUN ITY_ID = W ellKnownOI D.VA_RADIO LOGY_IMAGE ;
  56           
  57           pr ivate stat ic Namespa ceIdentifi er namespa ceIdentifi er = null;
  58           pu blic stati c synchron ized Names paceIdenti fier getMa nagedNames pace()
  59           {
  60                    if(n amespaceId entifier = = null)
  61                             namesp aceIdentif ier = new  NamespaceI dentifier( NAMESPACE) ;
  62                    retu rn namespa ceIdentifi er;
  63           }
  64           
  65           //  the addit ional plus  '+' makes  the compo nent regul ar express ions into  possessive  quantifie rs
  66           //  and there by improve s performa nce (to th e point of  usability )
  67           //  see http: //www.regu lar-expres sions.info /possessiv e.html for  an explan ation
  68           pr ivate stat ic final S tring name spaceSpeci ficStringR egex = 
  69                    "([^ -]+)" +                                                                   //  the site  ID
  70                    URN. namespaceS pecificStr ingDelimit er +
  71                    "([^ -]+)" +                                                                            // t he image I
  72                    URN. namespaceS pecificStr ingDelimit er +
  73                    "([^ -]+)" +                                                                            // t he group o r study ID  
  74                    URN. namespaceS pecificStr ingDelimit er + 
  75                    "([^ -]+)" +                                                                            // t he patient  ID 
  76                    "(?: " + URN.na mespaceSpe cificStrin gDelimiter  + ")?" + 
  77                    "([^ -]+)?";                                                                            // t he optiona l modality
  78           pr ivate stat ic final P attern nam espaceSpec ificString Pattern =  Pattern.co mpile(name spaceSpeci ficStringR egex);
  79           pr ivate stat ic final i nt SITE_ID _GROUP = 1 ;
  80           pr ivate stat ic final i nt INSTANC E_ID_GROUP  = 2;
  81           pr ivate stat ic final i nt GROUP_I D_GROUP =  3;
  82           pr ivate stat ic final i nt PATIENT _ID_GROUP  = 4;
  83           pr ivate stat ic final i nt MODALIT Y_GROUP =  5;
  84           
  85           pu blic stati c final in t ADDITION AL_IDENTIF IER_PATIEN T_IDENTIFI ER_TYPE_IN DEX = 0;
  86  
  87           st atic
  88           {
  89                    Syst em.out.pri ntln("Imag eURN NSS r egular exp ression is  '" + name spaceSpeci ficStringR egex + "'. ");
  90           }
  91           
  92           /* *
  93            *  
  94            *  @param or iginatingS iteId - if  the site  ID is '200 ' then the  returned  instance w ill be
  95            *                               a  BhieImageU RN
  96            *  @param as signedId
  97            *  @param st udyId
  98            *  @param pa tientIcn
  99            *  @return
  100            *  @throws U RNFormatEx ception
  101            * /
  102           pu blic stati c ImageURN  create(
  103                    Stri ng origina tingSiteId
  104                    Stri ng assigne dId, 
  105                    Stri ng studyId
  106                    Stri ng patient Icn)
  107           th rows URNFo rmatExcept ion
  108           {
  109                    if(B hieImageUR N.DEFAULT_ REPOSITORY _ID.equals (originati ngSiteId))
  110                             return  BhieImage URN.create (assignedI d, studyId , patientI cn);
  111                    else
  112                             return  create(or iginatingS iteId, ass ignedId, s tudyId, pa tientIcn,  null);
  113           }
  114  
  115           /* *
  116            *  
  117            *  @param or iginatingS iteId - if  the site  ID is '200 ' then the  returned  instance w ill be
  118            *                               a  BhieImageU RN
  119            *  @param as signedId
  120            *  @param st udyId
  121            *  @param pa tientIcn
  122            *  @param im ageModalit y
  123            *  @return
  124            *  @throws I mageURNFor matExcepti on
  125            * /
  126           pu blic stati c ImageURN  create(
  127                    Stri ng origina tingSiteId
  128                    Stri ng assigne dId, 
  129                    Stri ng studyId ,
  130                    Stri ng patient Icn, 
  131                    Stri ng imageMo dality) 
  132           th rows URNFo rmatExcept ion
  133           {
  134                    if(B hieImageUR N.DEFAULT_ REPOSITORY _ID.equals (originati ngSiteId))
  135                             return  BhieImage URN.create (originati ngSiteId,  assignedId , studyId,  patientIc n, imageMo dality);
  136                    else
  137                             return  new Image URN(origin atingSiteI d, assigne dId, study Id, patien tIcn, imag eModality) ;         
  138           }
  139           
  140  
  141           /* *
  142            *  Create a  DocumentUR N instance  from an I mageURN.
  143            *  This prov ide the tr anslation  within the  datasourc e, using t he same
  144            *  RPCs as i mage retri eval and p resenting  results in  Document  semantics.
  145            *  @param do cumentUrn
  146            *  @return
  147            *  @throws U RNFormatEx ception
  148            * /
  149           pu blic stati c ImageURN  create(Do cumentURN  documentUr n)
  150           th rows URNFo rmatExcept ion
  151           {
  152                    retu rn create(
  153                             docume ntUrn.getO riginating SiteId(),
  154                             docume ntUrn.getD ocumentId( ),
  155                             docume ntUrn.getD ocumentSet Id(), 
  156                             docume ntUrn.getP atientId()
  157                    );
  158           }
  159           
  160           /* *
  161            *  
  162            *  @param ur nComponent s
  163            *  @return
  164            *  @throws U RNFormatEx ception
  165            * /
  166           pu blic stati c ImageURN  create(UR NComponent s urnCompo nents, SER IALIZATION _FORMAT se rializatio nFormat) 
  167           th rows URNFo rmatExcept ion
  168           {
  169                    Imag eURN image Urn = null ;
  170  
  171                    // i f this pro bably a BH IE Image U RN
  172                    if(  BhieImageU RN.getMana gedNamespa ce().equal s(urnCompo nents.getN amespaceId entifier() ) ||
  173                             (Image URN.getMan agedNamesp ace().equa ls(urnComp onents.get NamespaceI dentifier( )) &&
  174                              urnCo mponents.g etNamespac eSpecificS tring().st artsWith(B hieImageUR N.DEFAULT_ REPOSITORY _ID + URN. namespaceS pecificStr ingDelimit er))
  175                    )
  176                    {
  177                             imageU rn =  Bhie ImageURN.c reate(urnC omponents,  serializa tionFormat );
  178                    }
  179                    else
  180                    {
  181                             imageU rn = new I mageURN(ur nComponent s, seriali zationForm at);
  182                             
  183                             if( !I mageURN.ge tManagedNa mespace(). equals(urn Components .getNamesp aceIdentif ier()) )
  184                                      throw ne w URNForma tException ("The name space '" +  urnCompon ents.getNa mespaceIde ntifier(). toString()  + "' is n ot valid f or an Imag eURN.");
  185                             if( im ageUrn.get GroupId()  == null )
  186                                      throw ne w URNForma tException ("The grou p ID is nu ll, which  is not val id for an  ImageURN." );
  187                             if( im ageUrn.get InstanceId () == null  )
  188                                      throw ne w URNForma tException ("The grou p ID is nu ll, which  is not val id for an  ImageURN." );
  189                             
  190                             // JMW  1/3/13 P1 30 - Image URNs can n ow contain  additiona l identifi ers to hol d the Pati entIdentif ierType                   
  191                             //if(u rnComponen ts.getAddi tionalIden tifers() ! = null &&  urnCompone nts.getAdd itionalIde ntifers(). length > 0 )
  192                             //       throw ne w URNForma tException ("The urn  components  include a dditional  identifier s, which i s not vali d for an I mageURN.") ;
  193                             
  194                                      
  195                             // Mos t of the t ime a Bhie ImageURN w ill fail t o parse co rrectly wh en treated  as an Ima geURN
  196                             // and  an except ion will b e thrown a lready.
  197                             // On  the off ch ance that  does not h appen then  this will  catch it
  198                             if( Bh ieImageURN .DEFAULT_R EPOSITORY_ ID.equals( imageUrn.g etOriginat ingSiteId( )) )
  199                                      imageUrn  =  BhieIm ageURN.cre ate(urnCom ponents, s erializati onFormat);
  200                    }                 
  201                    retu rn imageUr n;
  202           }
  203           
  204   //      /* *
  205   //       *  
  206   //       *  @param ur nComponent s
  207   //       *  @return
  208   //       *  @throws U RNFormatEx ception
  209   //       * /
  210   //      pu blic stati c ImageURN  createFro mBase32(UR NComponent s urnCompo nents) 
  211   //      th rows URNFo rmatExcept ion 
  212   //      {
  213   //               Imag eURN image Urn = null ;
  214   //               try
  215   //               {
  216   //                        imageU rn = new I mageURN(ur nComponent s, SERIALI ZATION_FOR MAT.PATCH8 3_VFTP);
  217   //                        
  218   //                        if( !I mageURN.ge tManagedNa mespace(). equals(urn Components .getNamesp aceIdentif ier()) )
  219   //                                 throw ne w URNForma tException ("The name space '" +  urnCompon ents.getNa mespaceIde ntifier(). toString()  + "' is n ot valid f or an Imag eURN.");
  220   //                        if( im ageUrn.get GroupId()  == null )
  221   //                                 throw ne w URNForma tException ("The grou p ID is nu ll, which  is not val id for an  ImageURN." );
  222   //                        if( im ageUrn.get InstanceId () == null  )
  223   //                                 throw ne w URNForma tException ("The grou p ID is nu ll, which  is not val id for an  ImageURN." );
  224   //                        if(urn Components .getAdditi onalIdenti fers() !=  null && ur nComponent s.getAddit ionalIdent ifers().le ngth > 0)
  225   //                                 throw ne w URNForma tException ("The urn  components  include a dditional  identifier s, which i s not vali d for an I mageURN.") ;
  226   //                                 
  227   //                        // Mos t of the t ime a Bhie ImageURN w ill fail t o parse co rrectly wh en treated  as an Ima geURN
  228   //                        // and  an except ion will b e thrown a lready.
  229   //                        // On  the off ch ance that  does not h appen then  this will  catch it
  230   //                        if( Bh ieImageURN .DEFAULT_R EPOSITORY_ ID.equals( imageUrn.g etOriginat ingSiteId( )) )
  231   //                                 throw ne w URNForma tException ("The orig inating Si te indicat es a DoD s ite, this  error shou ld be caug ht by a fa ctory meth od and a B hieImageUR N created  instead.") ;
  232   //               }
  233   //               catc h(URNForma tException  urnfX)
  234   //               {
  235   //                        // if  the image  URN origin ating Site  ID is sit e 200 then  this is r eally a BH IE URN,
  236   //                        // Cli nicalDispl ay does no t recogniz e anything  but VA UR Ns, this k ludge insu lates
  237   //                        // the  rest of t he system  from that.
  238   //                        imageU rn =  Bhie ImageURN.c reateFromB ase32(urnC omponents) ;
  239   //               }
  240   //               
  241   //               retu rn imageUr n;
  242   //      }
  243           
  244  
  245           /* *
  246            *  
  247            * /
  248           pu blic stati c ImageURN  createFro mGlobalArt ifactIdent ifiers(
  249                    Stri ng homeCom munityId, 
  250                    Stri ng reposit oryId,
  251                    Stri ng documen tId) 
  252           th rows URNFo rmatExcept ion
  253           {
  254                    retu rn createF romGlobalA rtifactIde ntifiers(  homeCommun ityId, rep ositoryId,  documentI d, (String [])null);
  255           }
  256           
  257           /* *
  258            *  
  259            *  @param ho meCommunit yId
  260            *  @param re positoryId
  261            *  @param do cumentId
  262            *  @return
  263            *  @throws U RNFormatEx ception
  264            * /
  265           pu blic stati c ImageURN  createFro mGlobalArt ifactIdent ifiers(
  266                    Stri ng homeCom munityId, 
  267                    Stri ng reposit oryId, 
  268                    Stri ng documen tId,
  269                    Stri ng... addi tionalIden tifiers)
  270           th rows URNFo rmatExcept ion
  271           {
  272                    if(  BhieImageU RN.isAppli cableHomeC ommunityId (homeCommu nityId, re positoryId , document Id) )
  273                             return  BhieImage URN.create FromGlobal ArtifactId entifiers( homeCommun ityId, rep ositoryId,  documentI d);
  274                    else  if( Image URN.isAppl icableHome CommunityI d(homeComm unityId, r epositoryI d, documen tId) )
  275                             return  new Image URN( repos itoryId, d ocumentId  );
  276                    else
  277                             throw  new URNFor matExcepti on("Home c ommunity I D '" + hom eCommunity Id + "' ca nnot be us ed to crea te an Imag eURN or it s derivati ves.");
  278           }
  279  
  280           /* *
  281            *  Required  static met hod, must  return TRU E when thi s class ca n represen
  282            *  a global  artifact I D with the  given hom e communit y ID.
  283            *  
  284            *  @param ho meCommunit yId
  285            *  @param re positoryId  
  286            *  @param do cumentId 
  287            *  @return
  288            * /
  289           pu blic stati c boolean  isApplicab leHomeComm unityId(St ring homeC ommunityId , String r epositoryI d, String  documentId )
  290           {
  291                    retu rn 
  292                             ImageU RN.NAMESPA CE.equalsI gnoreCase( homeCommun ityId) ||
  293                             WellKn ownOID.VA_ RADIOLOGY_ IMAGE.isAp plicable(h omeCommuni tyId);
  294           }
  295           
  296           
  297           pu blic stati c Matcher  getNamespa ceSpecific StringMatc her(CharSe quence inp ut)
  298           {
  299                    retu rn ImageUR N.namespac eSpecificS tringPatte rn.matcher (input);
  300           }
  301           
  302           //  ========= ========== ========== ========== ========== ========== ========== ========== ========
  303           //  Instance  Members
  304           //  ========= ========== ========== ========== ========== ========== ========== ========== ========
  305           pr otected St ring origi natingSite Id;
  306           pr otected St ring insta nceId;
  307           pr otected St ring group Id;
  308           pr otected St ring patie ntId;
  309           pr otected St ring image Modality;
  310           
  311           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ==========
  312           //  Instance  Constructo rs
  313           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ==========
  314           
  315           /* *
  316            *  Provided  only as a  pass throu gh for der ived class es.
  317            *  
  318            *  @param ni d
  319            *  @throws U RNFormatEx ception
  320            * /
  321           pr otected Im ageURN(Nam espaceIden tifier nid
  322           th rows URNFo rmatExcept ion
  323           {
  324                    supe r(nid);
  325           }
  326           
  327           /* *
  328            *  Provided  only as a  pass throu gh for der ived class es.
  329            *  
  330            * /
  331           pr otected Im ageURN(
  332                    Name spaceIdent ifier name spaceIdent ifier, 
  333                    Stri ng namespa ceSpecific String, 
  334                    Stri ng... addi tionalIden tifiers) 
  335           th rows URNFo rmatExcept ion
  336           {
  337                    supe r(namespac eIdentifie r, namespa ceSpecific String, ad ditionalId entifiers) ;
  338           }
  339           
  340           /* *
  341            *  Used dire ctly and a  pass thro ugh for de rived clas ses.
  342            *  The const ructor cal led by the  URN class  when a UR N derived  class
  343            *  is being  created fr om a Strin g represen tation.
  344            *  
  345            *  @param co mponents
  346            *  @throws U RNFormatEx ception
  347            * /
  348           pr otected Im ageURN(URN Components  urnCompon ents, SERI ALIZATION_ FORMAT ser ialFormat)  
  349           th rows URNFo rmatExcept ion
  350           {
  351                    supe r(urnCompo nents, ser ialFormat) ;
  352           }
  353  
  354           /* *
  355            *  
  356            *  @param or iginatingS iteId
  357            *  @param im ageId
  358            *  @param st udyId
  359            *  @param pa tientIcn
  360            *  @param im ageModalit y
  361            *  @throws U RNFormatEx ception
  362            * /
  363           pr ivate Imag eURN(
  364                    Stri ng origina tingSiteId
  365                    Stri ng assigne dId, 
  366                    Stri ng studyId
  367                    Stri ng patient Id, 
  368                    Stri ng imageMo dality) 
  369           th rows URNFo rmatExcept ion 
  370           {
  371                    supe r(ImageURN .getManage dNamespace ());
  372                    
  373                    orig inatingSit eId = URN. RFC2141_ES CAPING.esc apeIllegal Characters (originati ngSiteId);
  374                    assi gnedId = U RN.RFC2141 _ESCAPING. escapeIlle galCharact ers(assign edId);
  375                    stud yId = URN. RFC2141_ES CAPING.esc apeIllegal Characters (studyId);
  376                    pati entId = UR N.RFC2141_ ESCAPING.e scapeIlleg alCharacte rs(patient Id);
  377                    imag eModality  = URN.RFC2 141_ESCAPI NG.escapeI llegalChar acters(ima geModality );
  378                    
  379                    if(  !AbstractI magingURN. siteIdPatt ern.matche r(originat ingSiteId) .matches()  )
  380                             throw  new URNFor matExcepti on("The si te ID '" +  originati ngSiteId +  "' does n ot match t he pattern  '" + Abst ractImagin gURN.siteI dPattern.p attern());
  381                    this .originati ngSiteId =  originati ngSiteId;
  382                    
  383                    if(  !AbstractI magingURN. imageIdPat tern.match er(assigne dId).match es() )
  384                             throw  new URNFor matExcepti on("The im age ID '"  + assigned Id + "' do es not mat ch the pat tern '" +  AbstractIm agingURN.i mageIdPatt ern.patter n());
  385                    this .instanceI d = assign edId;
  386                    
  387                    if(  !AbstractI magingURN. groupIdPat tern.match er(studyId ).matches( ) )
  388                             throw  new URNFor matExcepti on("The gr oup ID '"  + studyId  + "' does  not match  the patter n '" + Abs tractImagi ngURN.grou pIdPattern .pattern() );
  389                    this .groupId =  studyId;
  390                    
  391                    if(  !AbstractI magingURN. patientIdP attern.mat cher(patie ntId).matc hes() )
  392                             throw  new URNFor matExcepti on("The pa tient ID ' " + patien tId + "' d oes not ma tch the pa ttern '" +  AbstractI magingURN. patientIdP attern.pat tern());
  393                    this .patientId  = patient Id;
  394                    
  395                    if(i mageModali ty != null  && imageM odality.le ngth() <=  0)
  396                             imageM odality =  null;
  397                    if(  imageModal ity != nul l && !Abst ractImagin gURN.modal ityPattern .matcher(i mageModali ty).matche s() )
  398                             throw  new URNFor matExcepti on("The mo dality '"  + imageMod ality + "'  does not  match the  pattern '"  + Abstrac tImagingUR N.modality Pattern.pa ttern());
  399                    
  400                    this .imageModa lity = ima geModality ;
  401           }
  402           
  403           /* *
  404            *  Construct or from th e GAI (IHE ) identifi ers
  405            *  
  406            *  @param re positoryUn iqueId
  407            *  @param do cumentId
  408            *  @throws U RNFormatEx ception 
  409            * /
  410           pr ivate Imag eURN(Strin g reposito ryUniqueId , String a ssignedId)  
  411           th rows URNFo rmatExcept ion
  412           {
  413                    supe r(ImageURN .getManage dNamespace ());
  414                    repo sitoryUniq ueId = URN .RFC2141_E SCAPING.es capeIllega lCharacter s(reposito ryUniqueId );
  415                    assi gnedId = U RN.RFC2141 _ESCAPING. escapeIlle galCharact ers(assign edId);
  416                    
  417                    try
  418                    {
  419                             parseD ocumentUni queIdIntoF ields(assi gnedId);
  420                             this.o riginating SiteId = r epositoryU niqueId;
  421                    }
  422                    catc h (GlobalA rtifactIde ntifierFor matExcepti on x)
  423                    {
  424                             throw  new URNFor matExcepti on(x);
  425                    }
  426           }
  427           
  428           /* *
  429            *  Override  the do-not hing versi on of this  method to  parse the
  430            *  namespace  specific  portion an d find the  component  parts.
  431            *  
  432            *  @param na mespaceSpe cificStrin g
  433            *  @throws I mageURNFor matExcepti on 
  434            * /
  435           @O verride
  436           pu blic void  parseNames paceSpecif icString(N amespaceId entifier n amespace,  String nam espaceSpec ificString , SERIALIZ ATION_FORM AT seriali zationForm at)
  437           th rows URNFo rmatExcept ion
  438           {
  439                    if(n amespaceSp ecificStri ng == null )
  440                             throw  new URNFor matExcepti on("The na mespace sp ecific str ing for a( n) " + thi s.getClass ().getSimp leName() +  " cannot  be null.") ;
  441                    
  442                    Matc her nssMat cher = nam espaceSpec ificString Pattern.ma tcher(name spaceSpeci ficString) ;
  443                    
  444                    if(!  nssMatche r.matches( ))
  445                    {
  446                             String  msg = "Na mespace sp ecific str ing '" + n amespaceSp ecificStri ng + "' is  not valid .";
  447                             Logger .getAnonym ousLogger( ).warning( msg);
  448                             throw  new ImageU RNFormatEx ception(ms g);
  449                    }
  450           
  451                    this .originati ngSiteId =  nssMatche r.group(SI TE_ID_GROU P).trim();
  452                    Stri ng tmpInst anceId = n ssMatcher. group(INST ANCE_ID_GR OUP).trim( );
  453                    Stri ng tmpGrou pId = nssM atcher.gro up(GROUP_I D_GROUP).t rim();
  454  
  455                    swit ch(seriali zationForm at)
  456                    {
  457                    case  PATCH83_V FTP:
  458                             setGro upId( Base 32Conversi onUtility. base32Deco de(tmpGrou pId) );
  459                             setIns tanceId( B ase32Conve rsionUtili ty.base32D ecode(tmpI nstanceId)  );
  460                             break;
  461                    case  RFC2141:
  462                             this.g roupId = t mpGroupId;
  463                             this.i nstanceId  = tmpInsta nceId;
  464                             break;
  465                    case  VFTP:
  466                             this.g roupId = t mpGroupId;
  467                             this.i nstanceId  = tmpInsta nceId;
  468                             break;
  469                    case  RAW:
  470                             this.g roupId = t mpGroupId;
  471                             this.i nstanceId  = tmpInsta nceId;
  472                             break;
  473                    case  CDTP:
  474                             this.g roupId = U RN.FILENAM E_TO_RFC21 41_ESCAPIN G.escapeIl legalChara cters(tmpG roupId);
  475                             this.i nstanceId  = URN.FILE NAME_TO_RF C2141_ESCA PING.escap eIllegalCh aracters(t mpInstance Id);
  476                             break;
  477                    case  NATIVE:
  478                             setGro upId(tmpGr oupId);
  479                             setIns tanceId(tm pInstanceI d);
  480                             break;
  481                    }
  482  
  483                    this .patientId  = URN.RFC 2141_ESCAP ING.escape IllegalCha racters( n ssMatcher. group(PATI ENT_ID_GRO UP).trim()  );
  484                    if(n ssMatcher. group(MODA LITY_GROUP ) != null)
  485                             this.i mageModali ty = URN.R FC2141_ESC APING.esca peIllegalC haracters(  
  486                                      nssMatch er.group(M ODALITY_GR OUP).trim( ).length()  > 0 ? nss Matcher.gr oup(MODALI TY_GROUP). trim() : n ull );
  487                    else
  488                             this.i mageModali ty = null;
  489           }
  490           
  491           @O verride
  492           pu blic Strin g getHomeC ommunityId ()
  493           {
  494                    // I mages are  always in  the VA com munity
  495                    retu rn WellKno wnOID.VA_R ADIOLOGY_I MAGE.getCa nonicalVal ue().toStr ing();
  496           }
  497  
  498           @O verride
  499           pu blic Names paceIdenti fier getNa mespaceIde ntifier()
  500           {
  501                    retu rn ImageUR N.getManag edNamespac e();
  502           }
  503           
  504           @O verride
  505           pu blic Strin g getOrigi natingSite Id()
  506           {
  507                    retu rn this.or iginatingS iteId;
  508           }
  509  
  510           pu blic Strin g getImage Id(){retur n this.get InstanceId ();}
  511           pu blic Strin g getInsta nceId()
  512           {
  513                    retu rn RFC2141 _ESCAPING. unescapeIl legalChara cters(this .instanceI d);
  514           }
  515  
  516           pu blic void  setInstanc eId(String  instanceI d)
  517           {
  518                    this .instanceI d = RFC214 1_ESCAPING .escapeIll egalCharac ters(insta nceId);
  519           }
  520  
  521           pu blic Strin g getStudy Id(){retur n getGroup Id();}
  522           /* *
  523            *  The study  ID may ha ve escape  sequences  in it if t hey were i ncluded
  524            *  in the st ring from  which the  URN was co nstructed.
  525            *  Unescape  the string  to get th e original  value.
  526            *  
  527            *  @return
  528            * /
  529           pu blic Strin g getGroup Id()
  530           {
  531                    retu rn this.gr oupId == n ull ? null  : URN.RFC 2141_ESCAP ING.unesca peIllegalC haracters( this.group Id);
  532           }
  533           pu blic void  setStudyId (String gr oupId){set GroupId(gr oupId);}
  534           pu blic void  setGroupId (String gr oupId)
  535           {
  536                    this .groupId =  RFC2141_E SCAPING.es capeIllega lCharacter s(groupId) ;
  537           }
  538  
  539           @O verride
  540           pu blic Strin g getPatie ntId()
  541           {
  542                    retu rn RFC2141 _ESCAPING. unescapeIl legalChara cters(this .patientId );
  543           }
  544           
  545           pu blic void  setPatient Id(String  patientId)
  546           {
  547                    this .patientId  = RFC2141 _ESCAPING. escapeIlle galCharact ers(patien tId);
  548           }
  549  
  550           pu blic Strin g getImage Modality()
  551           {
  552                    retu rn this.im ageModalit y == null  ? null : R FC2141_ESC APING.unes capeIllega lCharacter s(this.ima geModality );
  553           }
  554           pu blic void  setImageMo dality(Str ing imageM odality)
  555           {
  556                    this .imageModa lity = RFC 2141_ESCAP ING.escape IllegalCha racters(im ageModalit y);
  557           }
  558           
  559           //  ========= ========== ========== ========== ========== ========== ========== ======
  560           //  Generated  hashCode( ) and equa ls(), the  modality s hould not  be include d
  561           //  in the co mparison.
  562           //  Modified  equals() t o exclude  super.equa ls()
  563           //  ========= ========== ========== ========== ========== ========== ========== ======
  564  
  565           /* *
  566            *  
  567            * /
  568           @O verride
  569           pu blic int h ashCode()
  570           {
  571                    fina l int prim e = 31;
  572                    int  result = s uper.hashC ode();
  573                    resu lt = prime  * result  + ((this.g roupId ==  null) ? 0  : this.gro upId.hashC ode());
  574                    resu lt = prime  * result  + ((this.i nstanceId  == null) ?  0 : this. instanceId .hashCode( ));
  575                    resu lt = prime  * result  + ((this.o riginating SiteId ==  null) ? 0  : this.ori ginatingSi teId.hashC ode());
  576                    resu lt = prime  * result  + ((this.p atientId = = null) ?  0 : this.p atientId.h ashCode()) ;
  577                    retu rn result;
  578           }
  579  
  580           /* *
  581            *  
  582            *       Modi fied equal s() to exc lude super .equals()
  583            * /
  584           @O verride
  585           pu blic boole an equals( Object obj )
  586           {
  587                    if ( this == ob j)
  588                             return  true;
  589                    if ( getClass()  != obj.ge tClass())
  590                             return  false;
  591                    Imag eURN other  = (ImageU RN) obj;
  592                    if ( this.group Id == null )
  593                    {
  594                             if (ot her.groupI d != null)
  595                                      return f alse;
  596                    }
  597                    else  if (!this .groupId.e quals(othe r.groupId) )
  598                             return  false;
  599                    if ( this.insta nceId == n ull)
  600                    {
  601                             if (ot her.instan ceId != nu ll)
  602                                      return f alse;
  603                    }
  604                    else  if (!this .instanceI d.equals(o ther.insta nceId))
  605                             return  false;
  606                    if ( this.origi natingSite Id == null )
  607                    {
  608                             if (ot her.origin atingSiteI d != null)
  609                                      return f alse;
  610                    }
  611                    else  if (!this .originati ngSiteId.e quals(othe r.originat ingSiteId) )
  612                             return  false;
  613                    if ( this.patie ntId == nu ll)
  614                    {
  615                             if (ot her.patien tId != nul l)
  616                                      return f alse;
  617                    }
  618                    else  if (!this .patientId .equals(ot her.patien tId))
  619                             return  false;
  620                    retu rn true;
  621           }
  622  
  623           //  ========= ========== ========== ========== ========== ========== ========== ======
  624           //  Serializa tion forma ts
  625           //  ========= ========== ========== ========== ========== ========== ========== ======
  626           
  627           /* *
  628            *  Stringifi ed into th e Patch83  VFTP forma t,
  629            *  i.e. urn: vaimage:20 0-<base32  encoded in stance ID> -<base32 e ncoded gro up ID>-<pa tient ICN> -<modality >
  630            *  The insta nce ID and  group ID  are base 3 2 encoded,
  631            *  the patie nt ICN and  modality,  if it exi sts, are n ot BASE32  encoded 
  632            *  the names pace is "v aimage" an
  633            *  the site  ID is the  originatin g site ID.
  634            *  
  635            *  @see gov. va.med.URN #toStringP atch83VFTP ()
  636            * /
  637           @O verride
  638           pr otected St ring toStr ingPatch83 VFTP()
  639           {
  640                    Stri ngBuilder  ahnold = n ew StringB uilder();
  641                    
  642                    // b uild the s cheme iden tifier
  643                    ahno ld.append( urnSchemaI dentifier) ;
  644                    ahno ld.append( urnCompone ntDelimite r);
  645  
  646                    // b uild the n amespace i dentifier
  647                    ahno ld.append( ImageURN.g etManagedN amespace() .toString( ));
  648                    ahno ld.append( urnCompone ntDelimite r);
  649                    ahno ld.append( getOrigina tingSiteId ());
  650                    ahno ld.append( URN.namesp aceSpecifi cStringDel imiter);
  651                    ahno ld.append(  SERIALIZA TION_FORMA T.PATCH83_ VFTP.seria lize(this. getInstanc eId()) );
  652                    ahno ld.append( URN.namesp aceSpecifi cStringDel imiter);
  653                    ahno ld.append(  SERIALIZA TION_FORMA T.PATCH83_ VFTP.seria lize(this. getGroupId ()) );
  654                    if(g etPatientI d() != nul l)
  655                    {
  656                             ahnold .append(UR N.namespac eSpecificS tringDelim iter);
  657                             ahnold .append( g etPatientI d() );
  658                    }
  659                    if(g etImageMod ality() !=  null && g etImageMod ality().le ngth() > 0 )
  660                    {
  661                             ahnold .append(UR N.namespac eSpecificS tringDelim iter);
  662                             ahnold .append( t his.getIma geModality () );
  663                    }
  664                    retu rn ahnold. toString() ;
  665           }
  666  
  667           /* *
  668            *  
  669            * /
  670           @O verride
  671           pu blic Strin g getNames paceSpecif icString(S ERIALIZATI ON_FORMAT  serializat ionFormat)
  672           {
  673                    seri alizationF ormat = se rializatio nFormat ==  null ? SE RIALIZATIO N_FORMAT.R FC2141 : s erializati onFormat;
  674                    Stri ngBuilder  ahnold = n ew StringB uilder();
  675                    
  676                    // b uild the n amespace s pecific st ring
  677                    ahno ld.append(  this.getO riginating SiteId() ) ;
  678                    ahno ld.append( URN.namesp aceSpecifi cStringDel imiter);
  679                    ahno ld.append(  this.getI nstanceId( ) );
  680                    ahno ld.append( URN.namesp aceSpecifi cStringDel imiter);
  681                    ahno ld.append(  serializa tionFormat .serialize (this.getG roupId())  );
  682                    ahno ld.append( URN.namesp aceSpecifi cStringDel imiter);
  683                    ahno ld.append(  this.getP atientId()  );
  684                    if(g etImageMod ality() !=  null)           // i f no modal ity, leave  it off, n o "null"
  685                    {
  686                             ahnold .append(UR N.namespac eSpecificS tringDelim iter);
  687                             ahnold .append(ge tImageModa lity());
  688                    }
  689                    
  690                    retu rn ahnold. toString() ;
  691           }
  692           
  693           //  ========= ========== ========== ========== ========== ========== ========== ========== ======
  694           //  Global Ar tifact Ide ntifier Im plementati on
  695           //  ========= ========== ========== ========== ========== ========== ========== ========== ======
  696           
  697           /* *
  698            *  A special  implement ation of . equals() t his is use d with oth er
  699            *  GlobalArt ifactIdent ifier real izations.
  700            *  
  701            *  @param th at
  702            *  @return
  703            * /
  704           pu blic boole an equalsG lobalArtif actIdentif ier(Global ArtifactId entifier t hat)
  705           {
  706                    retu rn GlobalA rtifactIde ntifierImp l.equalsGl obalArtifa ctIdentifi er(this, t hat);
  707           }
  708  
  709           @O verride
  710           pu blic boole an isEquiv alent(Rout ingToken t hat)
  711           {
  712                    retu rn Routing TokenImpl. isEquivale nt(this, t hat);
  713           }
  714  
  715           @O verride
  716           pu blic boole an isInclu ding(Routi ngToken th at)
  717           {
  718                    retu rn Routing TokenImpl. isIncludin g(this, th at);
  719           }
  720           
  721           //  formattin g of the d ocument un ique ID, u sed for Gl obalArtifa ctIdentifi er support
  722           pr ivate stat ic final S tring docu mentUnique IdRegex =
  723                    "("  + IMAGEID_ REGEX + ") " +
  724                    URN. namespaceS pecificStr ingDelimit er +
  725                    "("  + GROUPID_ REGEX + ") " +
  726                    URN. namespaceS pecificStr ingDelimit er + 
  727                    "("  + PATIENTI D_REGEX +  ")";
  728           pr ivate stat ic final P attern doc umentUniqu eIdPattern  = Pattern .compile(d ocumentUni queIdRegex );
  729           pr ivate stat ic final i nt DOCUMEN TUNIQUEID_ DOCUMENT_I D_GROUP =  1;
  730           pr ivate stat ic final i nt DOCUMEN TUNIQUEID_ GROUP_ID_G ROUP = 3;
  731           pr ivate stat ic final i nt DOCUMEN TUNIQUEID_ PATIENT_ID _GROUP = 5 ;
  732           
  733           @O verride
  734           pu blic Strin g getDocum entUniqueI d()
  735           {
  736                    retu rn buildDo cumentUniq ueId( getI nstanceId( ), getStud yId(), get PatientId( ) );
  737           }
  738           
  739           pr ivate void  parseDocu mentUnique IdIntoFiel ds(String  documentId )
  740           th rows Globa lArtifactI dentifierF ormatExcep tion
  741           {
  742                    Stri ng[] compo nents = pa rseDocumen tUniqueId( documentId );
  743                    inst anceId = c omponents[ 0];
  744                    grou pId = comp onents[1];
  745                    pati entId = co mponents[2 ];
  746           }
  747           
  748           /* *
  749            *  This meth od and par seUniqueId () are dec lared stat ic to make  testing e asier.
  750            *  These two  methods a re reflexi ve, so par seUniqueID ( buildDoc umentUniqu eId(A,B,C)  ) = {A,B, C}
  751            *  @param in stanceId
  752            *  @param st udyId
  753            *  @param pa tientId
  754            *  @return
  755            * /
  756           pu blic stati c String b uildDocume ntUniqueId (String in stanceId,  String stu dyId, Stri ng patient Id)
  757           {
  758                    retu rn 
  759                             instan ceId +
  760                             URN.na mespaceSpe cificStrin gDelimiter  +
  761                             studyI d + 
  762                             URN.na mespaceSpe cificStrin gDelimiter  +
  763                             patien tId;
  764           }
  765           
  766           pu blic stati c String[]  parseDocu mentUnique Id(String  documentId )
  767           th rows Globa lArtifactI dentifierF ormatExcep tion
  768           {
  769                    Matc her matche r = ImageU RN.documen tUniqueIdP attern.mat cher(docum entId);
  770                    if(! matcher.ma tches())
  771                             throw  new Global ArtifactId entifierFo rmatExcept ion("'" +  documentId  + "' is n ot a valid  document  identifier  for type  'ImageURN' .");
  772                    
  773                    retu rn new Str ing[]{
  774                             matche r.group(DO CUMENTUNIQ UEID_DOCUM ENT_ID_GRO UP),
  775                             matche r.group(DO CUMENTUNIQ UEID_GROUP _ID_GROUP)
  776                             matche r.group(DO CUMENTUNIQ UEID_PATIE NT_ID_GROU P)};
  777                    
  778           }
  779  
  780           @O verride
  781           pu blic int c ompareTo(G lobalArtif actIdentif ier o)
  782           {
  783                    retu rn GlobalA rtifactIde ntifierImp l.compareT o(this, o) ;
  784           }
  785  
  786           @O verride
  787           pu blic Strin g getImagi ngIdentifi er()
  788           {
  789                    retu rn getImag eId();
  790           }
  791  
  792           @O verride
  793           pu blic Strin g getRepos itoryUniqu eId()
  794           {
  795                    retu rn this.or iginatingS iteId;
  796           }
  797           
  798           @O verride
  799           pu blic Image URN clone(
  800           th rows Clone NotSupport edExceptio n
  801           {
  802                    try
  803                    {
  804                             return  create(ge tOriginati ngSiteId() , getImage Id(), getS tudyId(),  getPatient Id(), getI mageModali ty());
  805                    } 
  806                    catc h (URNForm atExceptio n e)
  807                    {
  808                             throw  new CloneN otSupporte dException (e.getMess age());
  809                    }
  810           }
  811           
  812           pu blic Study URN getPar entStudyUR N() 
  813           th rows URNFo rmatExcept ion
  814           {
  815                    Stud yURN study Urn =
  816                                      StudyURN Factory.cr eate(getOr iginatingS iteId(), g etStudyId( ), getPati entId(), S tudyURN.cl ass);
  817                    stud yUrn.setPa tientIdent ifierTypeI fNecessary (getPatien tIdentifie rType());
  818                    retu rn studyUr n;
  819           }
  820  
  821           @O verride
  822           pr otected in t getPatie ntIdentifi erTypeAddi tionalIden tifierInde x()
  823           {
  824                    retu rn ADDITIO NAL_IDENTI FIER_PATIE NT_IDENTIF IER_TYPE_I NDEX;
  825           }
  826           
  827           pu blic Image URN cloneW ithNewSite (String ne wOriginati ngSiteId)
  828           th rows Clone NotSupport edExceptio n
  829           {
  830                    try
  831                    {
  832                             ImageU RN urn = c reate(newO riginating SiteId, ge tImageId() , getStudy Id(), getP atientId() , getImage Modality() );
  833                             urn.se tPatientId entifierTy peIfNecess ary(this.g etPatientI dentifierT ype());
  834                             return  urn;
  835                    } 
  836                    catc h (URNForm atExceptio n e)
  837                    {
  838                             throw  new CloneN otSupporte dException (e.getMess age());
  839                    }
  840           }
  841  
  842   }