]> Creatis software - gdcm.git/blobdiff - src/gdcmDicomDir.cxx
* string error fix
[gdcm.git] / src / gdcmDicomDir.cxx
index fd83573bd5178f14855e3f401b1dc2ea93177a3b..9145817176fed5f65f028c9f21af06b5c0dd2ffc 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/05 01:37:08 $
-  Version:   $Revision: 1.128 $
+  Date:      $Date: 2005/03/09 19:29:38 $
+  Version:   $Revision: 1.136 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 #else
 #   include <unistd.h>
 #endif
-
+// ----------------------------------------------------------------------------
+//         Note for future developpers
+// ----------------------------------------------------------------------------
+//
+//  Dicom PS 3.3 describes the relationship between Directory Records, as follow
+//    (see also PS 4.3, 2004, page 50 for Entity-Relationship model)
+//
+//  Directory Record Type      Directory Record Types which may be included
+//                                in the next lower-level directory Entity
+//
+// (Root directory Entity)     PATIENT
+//
+// PATIENT                     STUDY
+//
+// STUDY                       SERIES, VISIT, RESULTS, STUDY COMPONENT
+//
+// SERIES                      IMAGE, OVERLAYS, MODALITY LUT, VOI LUT,
+//                             CURVE, STORED PRINT, RT DOSE, RT STRUCTURE SET
+//                             RT PLAN, RT TREAT RECORD, PRESENTATION, WAVEFORM,
+//                             SR DOCUMENT, KEY OBJECT DOC, SPECTROSCOPY,
+//                             RAW DATA, REGISTRATION, FIDUCIAL
+// IMAGE
+// OVERLAY
+// MODALITY LUT
+// VOI LUT
+// CURVE
+// STORED PRINT
+// RT DOSE
+// RT STRUCTURE SET
+// RT PLAN
+// RT TREAT RECORD
+// PRESENTATION
+// WAVEFORM
+// SR DOCUMENT
+// KEY OBJECT DOC
+// SPECTROSCOPY
+// RAW DATA
+// REGISTRATION
+// FIDUCIAL
+// 
+// ----------------------
+// The current gdcm version only deals with :
+//
+// (Root directory Entity)     PATIENT
+// PATIENT                     STUDY
+// STUDY                       SERIES 
+// SERIES                      IMAGE
+// IMAGE                       /
+//
+// DicomDir::CreateDicomDir will have to be completed
+// Treelike structure management will have to be upgraded
+// ----------------------------------------------------------------------------
+    
 namespace gdcm 
 {
 //-----------------------------------------------------------------------------
@@ -112,11 +164,12 @@ DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
          gdcmWarningMacro( "Parse directory and create the DicomDir");
          ParseDirectory();
       }
+      /*
       else
       {
-         /// \todo if parseDir == false, it should be tagged as an error
-         // NO ! user may just call ParseDirectory() *after* constructor
+         //  user may just call ParseDirectory() *after* constructor
       }
+      */
    }
    // Only if user passed a DICOMDIR
    // ------------------------------
@@ -128,8 +181,6 @@ DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
       {
          gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
                           << " in file " << fileName);
-         /// \todo FIXME : what do we do when the parsed file IS NOT a
-         ///       DICOMDIR file ?         
       }
       else
          CreateDicomDir();
@@ -376,9 +427,6 @@ void DicomDir::SetEndMethodArgDelete( DicomDir::Method *method )
  * \brief    writes on disc a DICOMDIR
  * \ warning does NOT add the missing elements in the header :
  *           it's up to the user doing it !
- * \todo : to be re-written using the DICOMDIR tree-like structure
- *         *not* the chained list
- *         (does NOT exist if the DICOMDIR is user-forged !)
  * @param  fileName file to be written to 
  * @return false only when fail to open
  */
@@ -399,7 +447,7 @@ bool DicomDir::WriteDicomDir(std::string const &fileName)
 
    char filePreamble[128];
    memset(filePreamble, 0, 128);
-   fp->write(filePreamble, 128); //FIXME
+   fp->write(filePreamble, 128);
    binary_write( *fp, "DICM");
  
    DicomDirMeta *ptrMeta = GetMeta();
@@ -430,6 +478,44 @@ bool DicomDir::WriteDicomDir(std::string const &fileName)
    return true;
 }
 
+/**
+ * \brief    Anonymize a DICOMDIR
+ * @return true 
+ */
+bool DicomDir::AnonymizeDicomDir() 
+{
+   ValEntry *v;
+   // Something clever to be found to forge the Patient names
+   std::ostringstream s;
+   int i = 1;
+   for(ListDicomDirPatient::iterator cc = Patients.begin();
+                                     cc!= Patients.end();
+                                   ++cc)
+   {
+      s << i;
+      v = (*cc)->GetValEntry(0x0010, 0x0010) ; // Patient's Name
+      if (v)
+      {
+         v->SetValue(s.str());
+      }
+
+      v = (*cc)->GetValEntry(0x0010, 0x0020) ; // Patient ID
+      if (v)
+      {
+         v->SetValue(" ");
+      }
+
+      v = (*cc)->GetValEntry(0x0010, 0x0030) ; // Patient's BirthDate
+      if (v)
+      {
+         v->SetValue(" ");
+      }
+      s << "";
+      i++;
+   }
+   return true;
+}
 //-----------------------------------------------------------------------------
 // Protected
 /**
@@ -569,7 +655,6 @@ void DicomDir::CreateDicomDir()
    if ( !e )
    {
       gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
-      /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ? 
       return;         
    }
    
@@ -596,7 +681,7 @@ void DicomDir::CreateDicomDir()
       }
       else
       {
-         gdcmWarningMacro( "Not a ValEntry.");
+         gdcmWarningMacro( "(0004,1430) not a ValEntry ?!?");
          continue;
       }
 
@@ -732,7 +817,7 @@ bool DicomDir::AddImageToEnd(DicomDirImage *dd)
  * @param   path path of the root directory
  * @param   list chained list of Headers
  */
-void DicomDir::SetElements(std::string const & path, VectDocument const &list)
+void DicomDir::SetElements(std::string const &path, VectDocument const &list)
 {
    ClearEntry();
    ClearPatient();
@@ -747,7 +832,8 @@ void DicomDir::SetElements(std::string const & path, VectDocument const &list)
 
    bool first = true;
    for( VectDocument::const_iterator it = list.begin();
-                                     it != list.end(); ++it )
+                                     it != list.end(); 
+                                   ++it )
    {
       // get the current file characteristics
       patCurName         = (*it)->GetEntryValue(0x0010,0x0010);
@@ -776,7 +862,6 @@ void DicomDir::SetElements(std::string const & path, VectDocument const &list)
          || first )
       {
          SetElement(path, GDCM_DICOMDIR_SERIE, *it);
-         first = true;
       }
       
       // Always Deal with 'IMAGE' Elements  
@@ -803,7 +888,7 @@ void DicomDir::SetElements(std::string const & path, VectDocument const &list)
 void DicomDir::SetElement(std::string const &path, DicomDirType type,
                           Document *header)
 {
-   ListDicomDirElem elemList; //FIXME this is going to be a by copy operation
+   ListDicomDirElem elemList;
    ListDicomDirElem::const_iterator it;
    uint16_t tmpGr, tmpEl;
    DictEntry *dictEntry;
@@ -869,10 +954,10 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type,
    // imageElem 0008 1150 "" // Referenced SOP Class UID    : to be set/forged later
    // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
    // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
-   // for all the relevant elements found in their own spot of the DicomDir.dic
-
    // FIXME : troubles found when it's a SeqEntry
 
+   // for all the relevant elements found in their own spot of the DicomDir.dic
    for( it = elemList.begin(); it != elemList.end(); ++it)
    {
       tmpGr     = it->Group;