]> Creatis software - gdcm.git/blobdiff - Example/AnonymizeMultiPatient.cxx
Now user can ask for making a DICOMDIR after anonymization.
[gdcm.git] / Example / AnonymizeMultiPatient.cxx
index 39164b6dfa51babb003af8b18f6cf3fdd10222fa..6d8d6848955056676f7b1cab4a6a25224b18d793 100755 (executable)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: AnonymizeMultiPatient.cxx,v $
   Language:  C++
-  Date:      $Date: 2006/06/07 12:22:50 $
-  Version:   $Revision: 1.4 $
+  Date:      $Date: 2007/11/09 17:23:48 $
+  Version:   $Revision: 1.6 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -44,11 +44,13 @@ int main(int argc, char *argv[])
    START_USAGE(usage)
    " \n AnonymizeMultiPatient :\n                                             ",
    " AnonymizeMultiPatient a full gdcm-readable Dicom image                   ",
+   "         optionnaly, creates the DICOMDIR                                 ",
    "         Warning : the image is OVERWRITTEN                               ",
    "                   to preserve image integrity, use a copy.               ",
-   " usage: AnonymizeMultiPatient dirin=inputDirectoryName                    ",
+   " usage: AnonymizeMultiPatient dirin=inputDirectoryName  dicomdir          ",
    "       listOfElementsToRubOut : group-elem,g2-e2,... (in hexa, no space)  ",
    "                                of extra Elements to rub out              ",
+   "       dicomdir   : user wants to generate a DICOMDIR                     ",
    "       noshadowseq: user doesn't want to load Private Sequences           ",
    "       noshadow   : user doesn't want to load Private groups (odd number) ",
    "       noseq      : user doesn't want to load Sequences                   ",
@@ -59,7 +61,7 @@ int main(int argc, char *argv[])
 
 
    // ----- Initialize Arguments Manager ------   
-   gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
+   GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
   
    if (argc == 1 || am->ArgMgrDefined("usage")) 
    {
@@ -75,22 +77,23 @@ int main(int argc, char *argv[])
    }
    
    std::string dirName = name;
-   int verbose  = am->ArgMgrDefined("verbose");
+   
+   bool verbose  = ( 0 != am->ArgMgrDefined("verbose") ); 
+   bool dicomdir = ( 0 != am->ArgMgrDefined("dicomdir") );
    
    if (am->ArgMgrDefined("debug"))
-      gdcm::Debug::DebugOn();
+      GDCM_NAME_SPACE::Debug::DebugOn();
 
-   int loadMode = gdcm::LD_ALL;
+   int loadMode = GDCM_NAME_SPACE::LD_ALL;
  
    if ( am->ArgMgrDefined("noshadowseq") )
-      loadMode |= gdcm::LD_NOSHADOWSEQ;
+      loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
    else 
    {
       if ( am->ArgMgrDefined("noshadow") )
-         loadMode |= gdcm::LD_NOSHADOW;
+         loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
       if ( am->ArgMgrDefined("noseq") )
-         loadMode |= gdcm::LD_NOSEQ;
+         loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
    }
 
 
@@ -113,11 +116,11 @@ int main(int argc, char *argv[])
 
    // ----- Begin Processing -----
 
-   gdcm::DicomDir *dcmdir;
+   GDCM_NAME_SPACE::DicomDir *dcmdir;
 
    // we ask for Directory parsing
 
-   dcmdir = gdcm::DicomDir::New( );
+   dcmdir = GDCM_NAME_SPACE::DicomDir::New( );
    dcmdir->SetLoadMode(loadMode);
    dcmdir->SetDirectoryName(dirName);
    dcmdir->Load();
@@ -135,24 +138,31 @@ int main(int argc, char *argv[])
       return 1;
    }
 
-   gdcm::DicomDirPatient *pa;
-   gdcm::DicomDirStudy *st;
-   gdcm::DicomDirSerie *se;
-   gdcm::DicomDirImage *im;
+   GDCM_NAME_SPACE::DicomDirPatient *pa;
+   GDCM_NAME_SPACE::DicomDirStudy *st;
+   GDCM_NAME_SPACE::DicomDirSerie *se;
+   GDCM_NAME_SPACE::DicomDirImage *im;
 
-   std::string codedName; 
+   std::string codedName;
+   std::string codedID;
    std::string fullFileName;
    std::string patName;
-      
-   gdcm::File *f;
+   std::string patID;
+        
+   GDCM_NAME_SPACE::File *f;
   
    pa = dcmdir->GetFirstPatient(); 
    while ( pa )
    {  // on degouline les PATIENT du DICOMDIR
       patName = pa->GetEntryString(0x0010, 0x0010);
-      codedName = "g^" + gdcm::Util::ConvertToMD5(patName);
-      if (verbose)
-         std::cout << patName << " --> " << codedName << std::endl;         
+      codedName = "g^" + GDCM_NAME_SPACE::Util::ConvertToMD5(patName);
+      patID = pa->GetEntryString(0x0010, 0x0020);
+      codedID = GDCM_NAME_SPACE::Util::ConvertToMD5(patID);
+      
+      if (verbose) {
+         std::cout << "[" << patName << "] --> [" << codedName << "]" << std::endl;
+         std::cout << "[" << patID   << "] --> [" << codedID   << "]"  << std::endl;                 
+      } 
       st = pa->GetFirstStudy();
       while ( st ) 
       { // on degouline les STUDY de ce patient
@@ -163,12 +173,12 @@ int main(int argc, char *argv[])
             while ( im ) 
             { // on degouline les Images de cette serie       
                fullFileName = dirName;
-               fullFileName +=  gdcm::GDCM_FILESEPARATOR;
+               fullFileName +=  GDCM_NAME_SPACE::GDCM_FILESEPARATOR;
                fullFileName += im->GetEntryString(0x0004, 0x1500);
                if (verbose)
                   std::cout << "FileName " << fullFileName << std::endl;
 
-               f = gdcm::File::New( );
+               f = GDCM_NAME_SPACE::File::New( );
                f->SetLoadMode(loadMode);
                f->SetFileName( fullFileName );
                if ( !f->Load() )
@@ -188,7 +198,8 @@ int main(int argc, char *argv[])
                f->AddAnonymizeElement( 0x0010, 0x0010, codedName ); 
     
                // Patient's ID
-               f->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
+               //f->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
+               f->AddAnonymizeElement( 0x0010, 0x0020,codedID );
                // Patient's Birthdate
                f->AddAnonymizeElement( 0x0010, 0x0030,"11111111" );
                // Patient's Adress
@@ -214,7 +225,7 @@ int main(int argc, char *argv[])
               // 
               //      Overwrite the file
               // 
-              // The gdcm::File remains untouched in memory    
+              // The GDCM_NAME_SPACE::File remains untouched in memory    
    
               f->AnonymizeNoLoad();     
 
@@ -230,6 +241,11 @@ int main(int argc, char *argv[])
      pa = dcmdir->GetNextPatient();    
    }
 
+   if (dicomdir)
+   {
+      dcmdir->Write("DICOMDIR");   
+   }
+
    dcmdir->Delete();        
    return 0;