]> Creatis software - gdcm.git/blobdiff - Example/AnonymizeDicomDir.cxx
Fix mistypings
[gdcm.git] / Example / AnonymizeDicomDir.cxx
index 47915d81559acc939d47c63382d39c8d0873beb1..33cca00a7b0a64f3e36a8a00f187c03fb6116f2d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: AnonymizeDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/07/12 14:56:48 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2007/11/08 10:40:39 $
+  Version:   $Revision: 1.12 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -22,7 +22,7 @@
 
 #include "gdcmSQItem.h"
 #include "gdcmSeqEntry.h"
-#include "gdcmValEntry.h"
+#include "gdcmDataEntry.h"
 
 #include "gdcmDocument.h"
 #include "gdcmFile.h"
  * \brief AnonymizeDicomDir
  */
 
-void AnoNoLoad(gdcm::SQItem *s, std::fstream *fp, 
+void AnoNoLoad(GDCM_NAME_SPACE::SQItem *s, std::fstream *fp, 
                uint16_t group, uint16_t elem, 
                std::string val);
 
-void AnoNoLoad(gdcm::SQItem *s, std::fstream *fp, 
+void AnoNoLoad(GDCM_NAME_SPACE::SQItem *s, std::fstream *fp, 
                uint16_t group, uint16_t elem, 
                std::string val)
 {
-   gdcm::DocEntry *d;
+   GDCM_NAME_SPACE::DocEntry *d;
    uint32_t offset;
    uint32_t lgth;
    uint32_t valLgth = 0;
@@ -55,7 +55,7 @@ void AnoNoLoad(gdcm::SQItem *s, std::fstream *fp,
    if ( d == NULL)
       return;
 
-   if ( ! dynamic_cast<gdcm::ValEntry *>(d) )
+   if ( ! dynamic_cast<GDCM_NAME_SPACE::DataEntry *>(d) )
       return;
 
    offset = d->GetOffset();
@@ -75,18 +75,18 @@ int main(int argc, char *argv[])
 { 
 
    START_USAGE(usage)
-   " \n AnonymizeDicomDir :\n",
-   " Anonymize a gdcm-readable DICOMDIR ",
-   "           even when some 'Objects' are not yet taken into account",
-   "           Warning : the DICOMDIR is overwritten",
-   " usage: AnonymizeDicomDir filein=dicomDirName [debug] ",
-   "        debug    : user wants to run the program in 'debug mode' ",
+   " \n AnonymizeDicomDir :\n                                              ",
+   " Anonymize a gdcm-readable DICOMDIR                                    ",
+   "           even when some 'Objects' are not yet taken into account     ",
+   "           Warning : the DICOMDIR is overwritten                       ",
+   " usage: AnonymizeDicomDir filein=dicomDirName [debug]                  ",
+   "        debug    : developper wants to run the program in 'debug mode' ",
    FINISH_USAGE
 
    // ----- Initialize Arguments Manager ------   
-   gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
+   GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
   
-   if (am->ArgMgrDefined("usage")) 
+   if (argc == 1 || am->ArgMgrDefined("usage")) 
    {
       am->ArgMgrUsage(usage); // Display 'usage'
       delete am;
@@ -95,12 +95,19 @@ int main(int argc, char *argv[])
  
    char *fileName  = am->ArgMgrWantString("filein",usage); 
 
+   // if unused Param we give up
+   if ( am->ArgMgrPrintUnusedLabels() )
+   { 
+      am->ArgMgrUsage(usage);
+      delete am;
+      return 0;
+   }
    delete am;  // --- we don't need Argument Manager any longer ---
 
 
    //   Read the input DICOMDIR
-   gdcm::File *f;
-   f = new gdcm::File( );
+   GDCM_NAME_SPACE::File *f;
+   f = GDCM_NAME_SPACE::File::New( );
    f->SetLoadMode(0);
    f->SetFileName( fileName );
    bool res = f->Load();  
@@ -112,42 +119,44 @@ int main(int argc, char *argv[])
    std::cout << " ... is readable " << std::endl;
 
    // Look for Directory record sequence
-   gdcm::DocEntry *e = f->GetDocEntry(0x0004, 0x1220);
+   GDCM_NAME_SPACE::DocEntry *e = f->GetDocEntry(0x0004, 0x1220);
    if ( !e )
    {
       std::cout << "No Directory Record Sequence (0004,1220) found" <<std::endl;;
-      delete f;
+      f->Delete();
       return 0;
    }
    
-   gdcm::SeqEntry *s = dynamic_cast<gdcm::SeqEntry *>(e);
+   GDCM_NAME_SPACE::SeqEntry *s = dynamic_cast<GDCM_NAME_SPACE::SeqEntry *>(e);
    if ( !s )
    {
       std::cout << "Element (0004,1220) is not a Sequence ?!?" <<std::endl;
-      delete f;
+      f->Delete();
       return 0;
    }
 
    // Open the file LTTG (aka ALAP)
    std::fstream *fp = new std::fstream(fileName, 
                               std::ios::in | std::ios::out | std::ios::binary);
-   gdcm::DocEntry *d;
+   GDCM_NAME_SPACE::DocEntry *d;
    std::string v;
 
    int patientNumber = 0;
+
    std::ostringstream oss;
 
-   gdcm::SQItem *tmpSI=s->GetFirstSQItem();  // For all the SQItems
+   GDCM_NAME_SPACE::SQItem *tmpSI=s->GetFirstSQItem();  // For all the SQItems
    while(tmpSI)
    {
       d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
-      if ( gdcm::ValEntry* valEntry = dynamic_cast<gdcm::ValEntry *>(d) )
+      if ( GDCM_NAME_SPACE::DataEntry *dataEntry =
+      dynamic_cast<GDCM_NAME_SPACE::DataEntry *>(d) )
       {
-         v = valEntry->GetValue();
+         v = dataEntry->GetString();
       }
       else
       {
-         std::cout << "(0004,1430) not a ValEntry ?!?" << std::endl;
+         std::cout << "(0004,1430) not a DataEntry ?!?" << std::endl;
          continue;
       }
 
@@ -157,7 +166,7 @@ int main(int argc, char *argv[])
          continue;
       }
 
-      oss << patientNumber;      
+      oss << "P^" << patientNumber;      
 
       //   Overwrite the sensitive Entries
 
@@ -166,7 +175,7 @@ int main(int argc, char *argv[])
       // Patient's ID
       AnoNoLoad(tmpSI, fp, 0x0010, 0x0020, oss.str());
       // Patient's Birth Date
-      AnoNoLoad(tmpSI, fp, 0x0010, 0x0030, oss.str());
+      AnoNoLoad(tmpSI, fp, 0x0010, 0x0030, "11111111");
      // Telephone
       AnoNoLoad(tmpSI, fp, 0x0010, 0x2154, oss.str()); 
 
@@ -181,7 +190,8 @@ int main(int argc, char *argv[])
 
    fp->close();
 
-   delete f;
+   delete fp;
+   f->Delete();
    return 0;
 }