1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2005/07/19 15:19:26 $
7 Version: $Revision: 1.149 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 //-----------------------------------------------------------------------------
20 // For full DICOMDIR description, see:
21 // PS 3.3-2003, pages 731-750
22 //-----------------------------------------------------------------------------
23 #include "gdcmDicomDir.h"
24 #include "gdcmDicomDirObject.h"
25 #include "gdcmDicomDirStudy.h"
26 #include "gdcmDicomDirSerie.h"
27 #include "gdcmDicomDirVisit.h"
28 #include "gdcmDicomDirImage.h"
29 #include "gdcmDicomDirPatient.h"
30 #include "gdcmDicomDirMeta.h"
31 #include "gdcmDicomDirElement.h"
32 #include "gdcmDirList.h"
34 #include "gdcmDebug.h"
35 #include "gdcmGlobal.h"
37 #include "gdcmSeqEntry.h"
38 #include "gdcmSQItem.h"
39 #include "gdcmValEntry.h"
44 #include <sys/types.h>
47 # define getcwd _getcwd
50 #if defined(_MSC_VER) || defined(__BORLANDC__)
55 // ----------------------------------------------------------------------------
56 // Note for future developpers
57 // ----------------------------------------------------------------------------
59 // Dicom PS 3.3 describes the relationship between Directory Records, as follow
60 // (see also PS 4.3, 2004, page 50 for Entity-Relationship model)
62 // Directory Record Type Directory Record Types which may be included
63 // in the next lower-level directory Entity
65 // (Root directory Entity) PATIENT, TOPIC, PRIVATE
67 // PATIENT STUDY, PRIVATE
69 // STUDY SERIES, VISIT, RESULTS, STUDY COMPONENT, PRIVATE
71 // SERIES IMAGE, OVERLAYS, MODALITY LUT, VOI LUT,
72 // CURVE, STORED PRINT, RT DOSE, RT STRUCTURE SET
73 // RT PLAN, RT TREAT RECORD, PRESENTATION, WAVEFORM,
74 // SR DOCUMENT, KEY OBJECT DOC, SPECTROSCOPY,
75 // RAW DATA, REGISTRATION, FIDUCIAL, PRIVATE,
98 // ----------------------
99 // The current gdcm version only deals with :
101 // (Root directory Entity) PATIENT
107 // DicomDir::CreateDicomDir will have to be completed
108 // Treelike structure management will have to be upgraded
109 // ----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
114 // Constructor / Destructor
116 * \brief Constructor : creates an empty DicomDir
121 Initialize(); // sets all private fields to NULL
127 * \brief Constructor Parses recursively the directory and creates the DicomDir
128 * or uses an already built DICOMDIR, depending on 'parseDir' value.
129 * @param fileName name
130 * - of the root directory (parseDir = true)
131 * - of the DICOMDIR (parseDir = false)
132 * @param parseDir boolean
133 * - true if user passed an entry point
134 * and wants to explore recursively the directories
135 * - false if user passed an already built DICOMDIR file
136 * and wants to use it
138 DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
141 // At this step, Document constructor is already executed,
142 // whatever user passed (either a root directory or a DICOMDIR)
143 // and whatever the value of parseDir was.
144 // (nothing is cheked in Document constructor, to avoid overhead)
147 SetLoadMode (0x00000000); // concerns only dicom files
152 * \brief Canonical destructor
154 DicomDir::~DicomDir()
156 SetStartMethod(NULL);
157 SetProgressMethod(NULL);
167 //-----------------------------------------------------------------------------
171 * \brief Loader. use SetLoadMode(), SetFileName() before !
172 * @return false if file cannot be open or no swap info was found,
173 * or no tag was found.
175 bool DicomDir::Load( )
177 // We should clean out anything that already exists.
178 Initialize(); // sets all private fields to NULL
182 if ( ! this->Document::Load( ) )
185 return DoTheLoadingJob( );
189 * \brief Loader. (DEPRECATED : not to break the API)
190 * @param fileName file to be open for parsing
191 * @return false if file cannot be open or no swap info was found,
192 * or no tag was found.
194 bool DicomDir::Load(std::string const &fileName )
196 // We should clean out anything that already exists.
197 Initialize(); // sets all private fields to NULL
199 SetFileName( fileName );
202 if ( ! this->Document::Load( ) )
205 return DoTheLoadingJob( );
209 * \brief Does the Loading Job (internal use only)
210 * @return false if file cannot be open or no swap info was found,
211 * or no tag was found.
213 bool DicomDir::DoTheLoadingJob( )
215 // We should clean out anything that already exists.
216 Initialize(); // sets all private fields to NULL
220 // Only if user passed a DICOMDIR
221 // ------------------------------
227 if (!Document::Load() )
232 if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
234 gdcmWarningMacro( "Entry HT empty for file: "<< GetFileName());
237 // Directory record sequence
238 DocEntry *e = GetDocEntry(0x0004, 0x1220);
241 gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
242 << " in file " << GetFileName());
250 // Only if user passed a root directory
251 // ------------------------------------
252 if ( GetFileName() == "." )
254 // user passed '.' as Name
255 // we get current directory name
257 getcwd(dummy, (size_t)1000);
258 SetFileName( dummy ); // will be converted into a string
261 gdcmWarningMacro( "Parse directory and create the DicomDir : "
269 * \brief This predicate, based on hopefully reasonable heuristics,
270 * decides whether or not the current document was properly parsed
271 * and contains the mandatory information for being considered as
272 * a well formed and usable DicomDir.
273 * @return true when Document is the one of a reasonable DicomDir,
276 bool DicomDir::IsReadable()
278 if ( Filetype == Unknown )
280 gdcmWarningMacro( "Wrong filetype");
285 gdcmWarningMacro( "Meta Elements missing in DicomDir");
288 if ( Patients.size() <= 0 )
290 gdcmWarningMacro( "NO Patient in DicomDir");
298 * \brief adds *the* Meta to a partially created DICOMDIR
300 DicomDirMeta *DicomDir::NewMeta()
305 DocEntry *entry = GetFirstEntry();
308 MetaElems = new DicomDirMeta(true); // true = empty
310 entry = GetFirstEntry();
313 if ( dynamic_cast<SeqEntry *>(entry) )
316 RemoveEntryNoDestroy(entry);
317 MetaElems->AddEntry(entry);
319 entry = GetFirstEntry();
322 else // after root directory parsing
324 MetaElems = new DicomDirMeta(false); // false = not empty
326 MetaElems->SetSQItemNumber(0); // To avoid further missprinting
331 * \brief adds a new Patient (with the basic elements) to a partially created
334 DicomDirPatient *DicomDir::NewPatient()
336 DicomDirPatient *p = new DicomDirPatient();
337 AddPatientToEnd( p );
342 * \brief Remove all Patients
344 void DicomDir::ClearPatient()
346 for(ListDicomDirPatient::iterator cc = Patients.begin();
356 * \brief Get the first entry while visiting the DicomDirPatients
357 * \return The first DicomDirPatient if found, otherwhise NULL
359 DicomDirPatient *DicomDir::GetFirstPatient()
361 ItPatient = Patients.begin();
362 if ( ItPatient != Patients.end() )
368 * \brief Get the next entry while visiting the DicomDirPatients
369 * \note : meaningfull only if GetFirstEntry already called
370 * \return The next DicomDirPatient if found, otherwhise NULL
372 DicomDirPatient *DicomDir::GetNextPatient()
374 gdcmAssertMacro (ItPatient != Patients.end());
377 if ( ItPatient != Patients.end() )
383 * \brief fills the whole structure, starting from a root Directory
385 void DicomDir::ParseDirectory()
387 CreateDicomDirChainedList( GetFileName() );
392 * \brief Set the start method to call when the parsing of the
394 * @param method Method to call
395 * @param arg Argument to pass to the method
396 * @param argDelete Argument
397 * \warning In python : the arg parameter isn't considered
399 void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg,
400 DicomDir::Method *argDelete )
402 if ( StartArg && StartMethodArgDelete )
404 StartMethodArgDelete( StartArg );
407 StartMethod = method;
409 StartMethodArgDelete = argDelete;
414 * \brief Set the progress method to call when the parsing of the
416 * @param method Method to call
417 * @param arg Argument to pass to the method
418 * @param argDelete Argument
419 * \warning In python : the arg parameter isn't considered
421 void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg,
422 DicomDir::Method *argDelete )
424 if ( ProgressArg && ProgressMethodArgDelete )
426 ProgressMethodArgDelete( ProgressArg );
429 ProgressMethod = method;
431 ProgressMethodArgDelete = argDelete;
435 * \brief Set the end method to call when the parsing of the directory ends
436 * @param method Method to call
437 * @param arg Argument to pass to the method
438 * @param argDelete Argument
439 * \warning In python : the arg parameter isn't considered
441 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg,
442 DicomDir::Method *argDelete )
444 if ( EndArg && EndMethodArgDelete )
446 EndMethodArgDelete( EndArg );
451 EndMethodArgDelete = argDelete;
455 * \brief Set the method to delete the argument
456 * The argument is destroyed when the method is changed or when the
458 * @param method Method to call to delete the argument
460 void DicomDir::SetStartMethodArgDelete( DicomDir::Method *method )
462 StartMethodArgDelete = method;
466 * \brief Set the method to delete the argument
467 * The argument is destroyed when the method is changed or when the
469 * @param method Method to call to delete the argument
471 void DicomDir::SetProgressMethodArgDelete( DicomDir::Method *method )
473 ProgressMethodArgDelete = method;
477 * \brief Set the method to delete the argument
478 * The argument is destroyed when the method is changed or when
479 * the class is destroyed
480 * @param method Method to call to delete the argument
482 void DicomDir::SetEndMethodArgDelete( DicomDir::Method *method )
484 EndMethodArgDelete = method;
488 * \brief writes on disc a DICOMDIR
489 * \ warning does NOT add the missing elements in the header :
490 * it's up to the user doing it !
491 * @param fileName file to be written to
492 * @return false only when fail to open
495 bool DicomDir::WriteDicomDir(std::string const &fileName)
498 uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
499 uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
501 std::ofstream *fp = new std::ofstream(fileName.c_str(),
502 std::ios::out | std::ios::binary);
505 gdcmWarningMacro("Failed to open(write) File: " << fileName.c_str());
509 char filePreamble[128];
510 memset(filePreamble, 0, 128);
511 fp->write(filePreamble, 128);
512 binary_write( *fp, "DICM");
514 DicomDirMeta *ptrMeta = GetMeta();
515 ptrMeta->WriteContent(fp, ExplicitVR);
517 // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
520 binary_write(*fp, sq[i]);
523 for(ListDicomDirPatient::iterator cc = Patients.begin();
524 cc != Patients.end();
527 (*cc)->WriteContent( fp, ExplicitVR );
530 // force writing Sequence Delimitation Item
533 binary_write(*fp, sqt[i]); // fffe e0dd ffff ffff
543 * \brief Anonymize a DICOMDIR
547 bool DicomDir::AnonymizeDicomDir()
550 // Something clever to be found to forge the Patient names
551 std::ostringstream s;
553 for(ListDicomDirPatient::iterator cc = Patients.begin();
558 v = (*cc)->GetValEntry(0x0010, 0x0010) ; // Patient's Name
561 v->SetValue(s.str());
564 v = (*cc)->GetValEntry(0x0010, 0x0020) ; // Patient ID
570 v = (*cc)->GetValEntry(0x0010, 0x0030) ; // Patient's BirthDate
581 //-----------------------------------------------------------------------------
584 * \brief create a Document-like chained list from a root Directory
585 * @param path entry point of the tree-like structure
587 void DicomDir::CreateDicomDirChainedList(std::string const &path)
590 DirList dirList(path,1); // gets recursively the file list
591 unsigned int count = 0;
595 DirListType fileList = dirList.GetFilenames();
597 for( DirListType::iterator it = fileList.begin();
598 it != fileList.end();
601 Progress = (float)(count+1)/(float)fileList.size();
602 CallProgressMethod();
609 f->SetLoadMode(LoadMode); // we allow user not to load Sequences, or Shadow
611 f->SetFileName( it->c_str() );
612 /*int res = */f->Load( );
616 // gdcmWarningMacro( "Failure in new gdcm::File " << it->c_str() );
620 if ( f->IsReadable() )
622 // Add the file to the chained list:
624 gdcmWarningMacro( "Readable " << it->c_str() );
632 // sorts Patient/Study/Serie/
633 std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
635 std::string tmp = dirList.GetDirName();
636 //for each File of the chained list, add/update the Patient/Study/Serie/Image info
637 SetElements(tmp, list);
640 for(VectDocument::iterator itDoc=list.begin();
644 delete dynamic_cast<File *>(*itDoc);
649 * \brief CallStartMethod
651 void DicomDir::CallStartMethod()
657 StartMethod( StartArg );
662 * \brief CallProgressMethod
664 void DicomDir::CallProgressMethod()
666 if ( ProgressMethod )
668 ProgressMethod( ProgressArg );
673 * \brief CallEndMethod
675 void DicomDir::CallEndMethod()
684 //-----------------------------------------------------------------------------
687 * \brief Sets all fields to NULL
689 void DicomDir::Initialize()
692 ProgressMethod = NULL;
694 StartMethodArgDelete = NULL;
695 ProgressMethodArgDelete = NULL;
696 EndMethodArgDelete = NULL;
708 * \brief create a 'gdcm::DicomDir' from a DICOMDIR Header
710 void DicomDir::CreateDicomDir()
712 // The SeqEntries of "Directory Record Sequence" are parsed.
713 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
714 // 1 - we save the beginning iterator
715 // 2 - we continue to parse
716 // 3 - we find an other tag
717 // + we create the object for the precedent tag
720 // Directory record sequence
721 DocEntry *e = GetDocEntry(0x0004, 0x1220);
724 gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
728 SeqEntry *s = dynamic_cast<SeqEntry *>(e);
731 gdcmWarningMacro( "Element (0004,1220) is not a Sequence ?!?");
741 SQItem *tmpSI=s->GetFirstSQItem();
744 d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
745 if ( ValEntry* valEntry = dynamic_cast<ValEntry *>(d) )
747 v = valEntry->GetValue();
751 gdcmWarningMacro( "(0004,1430) not a ValEntry ?!?");
755 // A decent DICOMDIR has much more images than series,
756 // more series than studies, and so on.
757 // This is the right order to preform the tests
761 si = new DicomDirImage(true);
762 if ( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
766 gdcmErrorMacro( "Add AddImageToEnd failed");
769 else if ( v == "SERIES" )
771 si = new DicomDirSerie(true);
772 if ( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
776 gdcmErrorMacro( "Add AddSerieToEnd failed");
779 else if ( v == "VISIT " )
781 si = new DicomDirVisit(true);
782 if ( !AddVisitToEnd( static_cast<DicomDirVisit *>(si)) )
786 gdcmErrorMacro( "Add AddVisitToEnd failed");
789 else if ( v == "STUDY " )
791 si = new DicomDirStudy(true);
792 if ( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
796 gdcmErrorMacro( "Add AddStudyToEnd failed");
799 else if ( v == "PATIENT " )
801 si = new DicomDirPatient(true);
802 if ( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
806 gdcmErrorMacro( "Add PatientToEnd failed");
811 // It was neither a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
812 // nor an 'IMAGE' SQItem. Skip to next item.
813 gdcmWarningMacro( " -------------------------------------------"
814 << "a non PATIENT/STUDY/SERIE/IMAGE SQItem was found : "
817 // FIXME : deal with other item types !
818 tmpSI=s->GetNextSQItem(); // To avoid infinite loop
822 //MoveSQItem(si,tmpSI); // Old code : Copies each Entry
823 // -and then removes the source-
824 si->MoveObject(tmpSI); // New code : Copies the List
826 tmpSI=s->GetNextSQItem();
832 * \brief AddPatientToEnd
833 * @param dd SQ Item to enqueue to the DicomPatient chained List
835 bool DicomDir::AddPatientToEnd(DicomDirPatient *dd)
837 Patients.push_back(dd);
842 * \brief AddStudyToEnd
843 * @param dd SQ Item to enqueue to the DicomDirStudy chained List
845 bool DicomDir::AddStudyToEnd(DicomDirStudy *dd)
847 if ( Patients.size() > 0 )
849 ListDicomDirPatient::iterator itp = Patients.end();
851 (*itp)->AddStudy(dd);
858 * \brief AddSerieToEnd
859 * @param dd SQ Item to enqueue to the DicomDirSerie chained List
861 bool DicomDir::AddSerieToEnd(DicomDirSerie *dd)
863 if ( Patients.size() > 0 )
865 ListDicomDirPatient::iterator itp = Patients.end();
868 DicomDirStudy *study = (*itp)->GetLastStudy();
879 * \brief AddVisitToEnd
880 * @param dd SQ Item to enqueue to the DicomDirVisit chained List
882 bool DicomDir::AddVisitToEnd(DicomDirVisit *dd)
884 if ( Patients.size() > 0 )
886 ListDicomDirPatient::iterator itp = Patients.end();
889 DicomDirStudy *study = (*itp)->GetLastStudy();
899 * \brief AddImageToEnd
900 * @param dd SQ Item to enqueue to the DicomDirImage chained List
902 bool DicomDir::AddImageToEnd(DicomDirImage *dd)
904 if ( Patients.size() > 0 )
906 ListDicomDirPatient::iterator itp = Patients.end();
909 DicomDirStudy *study = (*itp)->GetLastStudy();
912 DicomDirSerie *serie = study->GetLastSerie();
924 * \brief for each Header of the chained list,
925 * add/update the Patient/Study/Serie/Image info
926 * @param path path of the root directory
927 * @param list chained list of Headers
929 void DicomDir::SetElements(std::string const &path, VectDocument const &list)
934 std::string patPrevName = "", patPrevID = "";
935 std::string studPrevInstanceUID = "", studPrevID = "";
936 std::string serPrevInstanceUID = "", serPrevID = "";
938 std::string patCurName, patCurID;
939 std::string studCurInstanceUID, studCurID;
940 std::string serCurInstanceUID, serCurID;
943 for( VectDocument::const_iterator it = list.begin();
947 // get the current file characteristics
948 patCurName = (*it)->GetEntryValue(0x0010,0x0010);
949 patCurID = (*it)->GetEntryValue(0x0010,0x0011);
950 studCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000d);
951 studCurID = (*it)->GetEntryValue(0x0020,0x0010);
952 serCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000e);
953 serCurID = (*it)->GetEntryValue(0x0020,0x0011);
955 if ( patCurName != patPrevName || patCurID != patPrevID || first )
957 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
961 // if new Study, deal with 'STUDY' Elements
962 if ( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID
965 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
969 // if new Serie, deal with 'SERIE' Elements
970 if ( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
973 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
976 // Always Deal with 'IMAGE' Elements
977 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
979 patPrevName = patCurName;
980 patPrevID = patCurID;
981 studPrevInstanceUID = studCurInstanceUID;
982 studPrevID = studCurID;
983 serPrevInstanceUID = serCurInstanceUID;
984 serPrevID = serCurID;
990 * \brief adds to the HTable
991 * the Entries (Dicom Elements) corresponding to the given type
992 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
993 * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
994 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
995 * @param header Header of the current file
997 void DicomDir::SetElement(std::string const &path, DicomDirType type,
1000 ListDicomDirElem elemList;
1001 ListDicomDirElem::const_iterator it;
1002 uint16_t tmpGr, tmpEl;
1003 DictEntry *dictEntry;
1010 case GDCM_DICOMDIR_IMAGE:
1011 elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
1012 si = new DicomDirImage(true);
1013 if ( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
1016 gdcmErrorMacro( "Add ImageToEnd failed");
1019 case GDCM_DICOMDIR_SERIE:
1020 elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
1021 si = new DicomDirSerie(true);
1022 if ( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
1025 gdcmErrorMacro( "Add SerieToEnd failed");
1028 case GDCM_DICOMDIR_STUDY:
1029 elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
1030 si = new DicomDirStudy(true);
1031 if ( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
1034 gdcmErrorMacro( "Add StudyToEnd failed");
1037 case GDCM_DICOMDIR_PATIENT:
1038 elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
1039 si = new DicomDirPatient(true);
1040 if ( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
1043 gdcmErrorMacro( "Add PatientToEnd failed");
1046 case GDCM_DICOMDIR_META:
1047 elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
1048 si = new DicomDirMeta(true);
1052 gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
1054 MetaElems = static_cast<DicomDirMeta *>(si);
1059 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
1060 // to avoid further troubles
1061 // imageElem 0008 1140 "" // Referenced Image Sequence
1062 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
1063 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
1064 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
1065 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
1067 // FIXME : troubles found when it's a SeqEntry
1069 // for all the relevant elements found in their own spot of the DicomDir.dic
1070 for( it = elemList.begin(); it != elemList.end(); ++it)
1074 dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
1076 entry = new ValEntry( dictEntry ); // Be sure it's never a BinEntry !
1078 entry->SetOffset(0); // just to avoid further missprinting
1082 // NULL when we Build Up (ex nihilo) a DICOMDIR
1083 // or when we add the META elems
1084 val = header->GetEntryValue(tmpGr, tmpEl);
1091 if ( val == GDCM_UNFOUND)
1093 if ( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
1095 // force to the *end* File Name
1096 val = Util::GetName( path );
1098 else if ( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
1100 if ( header->GetFileName().substr(0, path.length()) != path )
1102 gdcmWarningMacro( "The base path of file name is incorrect");
1103 val = header->GetFileName();
1107 val = &(header->GetFileName().c_str()[path.length()]);
1117 if ( header->GetEntryLength(tmpGr,tmpEl) == 0 )
1121 entry->SetValue( val ); // troubles expected when vr=SQ ...
1123 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
1125 gdcmWarningMacro("GDCM_DICOMDIR_META ?!? should never print that");
1127 si->AddEntry(entry);
1132 * \brief Move the content of the source SQItem to the destination SQItem
1133 * Only DocEntry's are moved
1134 * @param dst destination SQItem
1135 * @param src source SQItem
1137 void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src)
1141 entry = src->GetFirstEntry();
1144 src->RemoveEntryNoDestroy(entry);
1145 dst->AddEntry(entry);
1146 // we destroyed -> the current iterator is not longer valid
1147 entry = src->GetFirstEntry();
1152 * \brief compares two files
1154 bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
1156 return *header1 < *header2;
1159 //-----------------------------------------------------------------------------
1162 * \brief Canonical Printer
1163 * @param os ostream we want to print in
1164 * @param indent Indentation string to be prepended during printing
1166 void DicomDir::Print(std::ostream &os, std::string const & )
1170 MetaElems->SetPrintLevel(PrintLevel);
1171 MetaElems->Print(os);
1173 for(ListDicomDirPatient::iterator cc = Patients.begin();
1174 cc != Patients.end();
1177 (*cc)->SetPrintLevel(PrintLevel);
1182 //-----------------------------------------------------------------------------
1183 } // end namespace gdcm