1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2005/07/08 19:07:12 $
7 Version: $Revision: 1.146 $
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 "gdcmDicomDirStudy.h"
25 #include "gdcmDicomDirSerie.h"
26 #include "gdcmDicomDirVisit.h"
27 #include "gdcmDicomDirImage.h"
28 #include "gdcmDicomDirPatient.h"
29 #include "gdcmDicomDirMeta.h"
30 #include "gdcmDicomDirElement.h"
31 #include "gdcmDirList.h"
33 #include "gdcmDebug.h"
34 #include "gdcmGlobal.h"
36 #include "gdcmSeqEntry.h"
37 #include "gdcmSQItem.h"
38 #include "gdcmValEntry.h"
43 #include <sys/types.h>
46 # define getcwd _getcwd
49 #if defined(_MSC_VER) || defined(__BORLANDC__)
54 // ----------------------------------------------------------------------------
55 // Note for future developpers
56 // ----------------------------------------------------------------------------
58 // Dicom PS 3.3 describes the relationship between Directory Records, as follow
59 // (see also PS 4.3, 2004, page 50 for Entity-Relationship model)
61 // Directory Record Type Directory Record Types which may be included
62 // in the next lower-level directory Entity
64 // (Root directory Entity) PATIENT, TOPIC, PRIVATE
66 // PATIENT STUDY, PRIVATE
68 // STUDY SERIES, VISIT, RESULTS, STUDY COMPONENT, PRIVATE
70 // SERIES IMAGE, OVERLAYS, MODALITY LUT, VOI LUT,
71 // CURVE, STORED PRINT, RT DOSE, RT STRUCTURE SET
72 // RT PLAN, RT TREAT RECORD, PRESENTATION, WAVEFORM,
73 // SR DOCUMENT, KEY OBJECT DOC, SPECTROSCOPY,
74 // RAW DATA, REGISTRATION, FIDUCIAL, PRIVATE,
97 // ----------------------
98 // The current gdcm version only deals with :
100 // (Root directory Entity) PATIENT
106 // DicomDir::CreateDicomDir will have to be completed
107 // Treelike structure management will have to be upgraded
108 // ----------------------------------------------------------------------------
112 //-----------------------------------------------------------------------------
113 // Constructor / Destructor
115 * \brief Constructor : creates an empty DicomDir
120 Initialize(); // sets all private fields to NULL
126 * \brief Constructor Parses recursively the directory and creates the DicomDir
127 * or uses an already built DICOMDIR, depending on 'parseDir' value.
128 * @param fileName name
129 * - of the root directory (parseDir = true)
130 * - of the DICOMDIR (parseDir = false)
131 * @param parseDir boolean
132 * - true if user passed an entry point
133 * and wants to explore recursively the directories
134 * - false if user passed an already built DICOMDIR file
135 * and wants to use it
137 DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
140 // At this step, Document constructor is already executed,
141 // whatever user passed (either a root directory or a DICOMDIR)
142 // and whatever the value of parseDir was.
143 // (nothing is cheked in Document constructor, to avoid overhead)
146 SetLoadMode (0x00000000); // concerns only dicom files
151 * \brief Canonical destructor
153 DicomDir::~DicomDir()
155 SetStartMethod(NULL);
156 SetProgressMethod(NULL);
166 //-----------------------------------------------------------------------------
170 * \brief Loader. use SetLoadMode(), SetFileName() before !
171 * @return false if file cannot be open or no swap info was found,
172 * or no tag was found.
174 bool DicomDir::Load( )
176 // We should clean out anything that already exists.
177 Initialize(); // sets all private fields to NULL
181 if ( ! this->Document::Load( ) )
184 return DoTheLoadingJob( );
188 * \brief Loader. (DEPRECATED : not to break the API)
189 * @param fileName file to be open for parsing
190 * @return false if file cannot be open or no swap info was found,
191 * or no tag was found.
193 bool DicomDir::Load(std::string const &fileName )
195 // We should clean out anything that already exists.
196 Initialize(); // sets all private fields to NULL
198 SetFileName( fileName );
201 if ( ! this->Document::Load( ) )
204 return DoTheLoadingJob( );
208 * \brief Does the Loading Job (internal use only)
209 * @return false if file cannot be open or no swap info was found,
210 * or no tag was found.
212 bool DicomDir::DoTheLoadingJob( )
214 // We should clean out anything that already exists.
215 Initialize(); // sets all private fields to NULL
219 // Only if user passed a DICOMDIR
220 // ------------------------------
226 if (!Document::Load() )
231 if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
233 gdcmWarningMacro( "Entry HT empty for file: "<< GetFileName());
236 // Directory record sequence
237 DocEntry *e = GetDocEntry(0x0004, 0x1220);
240 gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
241 << " in file " << GetFileName());
249 // Only if user passed a root directory
250 // ------------------------------------
251 if ( GetFileName() == "." )
253 // user passed '.' as Name
254 // we get current directory name
256 getcwd(dummy, (size_t)1000);
257 SetFileName( dummy ); // will be converted into a string
260 gdcmWarningMacro( "Parse directory and create the DicomDir : "
268 * \brief This predicate, based on hopefully reasonable heuristics,
269 * decides whether or not the current document was properly parsed
270 * and contains the mandatory information for being considered as
271 * a well formed and usable DicomDir.
272 * @return true when Document is the one of a reasonable DicomDir,
275 bool DicomDir::IsReadable()
277 if ( Filetype == Unknown )
279 gdcmWarningMacro( "Wrong filetype");
284 gdcmWarningMacro( "Meta Elements missing in DicomDir");
287 if ( Patients.size() <= 0 )
289 gdcmWarningMacro( "NO Patient in DicomDir");
297 * \brief adds *the* Meta to a partially created DICOMDIR
299 DicomDirMeta *DicomDir::NewMeta()
304 DocEntry *entry = GetFirstEntry();
307 MetaElems = new DicomDirMeta(true); // true = empty
309 entry = GetFirstEntry();
312 if ( dynamic_cast<SeqEntry *>(entry) )
315 RemoveEntryNoDestroy(entry);
316 MetaElems->AddEntry(entry);
318 entry = GetFirstEntry();
321 else // after root directory parsing
323 MetaElems = new DicomDirMeta(false); // false = not empty
325 MetaElems->SetSQItemNumber(0); // To avoid further missprinting
330 * \brief adds a new Patient (with the basic elements) to a partially created
333 DicomDirPatient *DicomDir::NewPatient()
335 DicomDirPatient *p = new DicomDirPatient();
336 AddPatientToEnd( p );
341 * \brief Remove all Patients
343 void DicomDir::ClearPatient()
345 for(ListDicomDirPatient::iterator cc = Patients.begin();
355 * \brief Get the first entry while visiting the DicomDirPatients
356 * \return The first DicomDirPatient if found, otherwhise NULL
358 DicomDirPatient *DicomDir::GetFirstPatient()
360 ItPatient = Patients.begin();
361 if ( ItPatient != Patients.end() )
367 * \brief Get the next entry while visiting the DicomDirPatients
368 * \note : meaningfull only if GetFirstEntry already called
369 * \return The next DicomDirPatient if found, otherwhise NULL
371 DicomDirPatient *DicomDir::GetNextPatient()
373 gdcmAssertMacro (ItPatient != Patients.end());
376 if ( ItPatient != Patients.end() )
382 * \brief fills the whole structure, starting from a root Directory
384 void DicomDir::ParseDirectory()
386 CreateDicomDirChainedList( GetFileName() );
391 * \brief Set the start method to call when the parsing of the
393 * @param method Method to call
394 * @param arg Argument to pass to the method
395 * @param argDelete Argument
396 * \warning In python : the arg parameter isn't considered
398 void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg,
399 DicomDir::Method *argDelete )
401 if ( StartArg && StartMethodArgDelete )
403 StartMethodArgDelete( StartArg );
406 StartMethod = method;
408 StartMethodArgDelete = argDelete;
413 * \brief Set the progress method to call when the parsing of the
415 * @param method Method to call
416 * @param arg Argument to pass to the method
417 * @param argDelete Argument
418 * \warning In python : the arg parameter isn't considered
420 void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg,
421 DicomDir::Method *argDelete )
423 if ( ProgressArg && ProgressMethodArgDelete )
425 ProgressMethodArgDelete( ProgressArg );
428 ProgressMethod = method;
430 ProgressMethodArgDelete = argDelete;
434 * \brief Set the end method to call when the parsing of the directory ends
435 * @param method Method to call
436 * @param arg Argument to pass to the method
437 * @param argDelete Argument
438 * \warning In python : the arg parameter isn't considered
440 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg,
441 DicomDir::Method *argDelete )
443 if ( EndArg && EndMethodArgDelete )
445 EndMethodArgDelete( EndArg );
450 EndMethodArgDelete = argDelete;
454 * \brief Set the method to delete the argument
455 * The argument is destroyed when the method is changed or when the
457 * @param method Method to call to delete the argument
459 void DicomDir::SetStartMethodArgDelete( DicomDir::Method *method )
461 StartMethodArgDelete = method;
465 * \brief Set the method to delete the argument
466 * The argument is destroyed when the method is changed or when the
468 * @param method Method to call to delete the argument
470 void DicomDir::SetProgressMethodArgDelete( DicomDir::Method *method )
472 ProgressMethodArgDelete = method;
476 * \brief Set the method to delete the argument
477 * The argument is destroyed when the method is changed or when
478 * the class is destroyed
479 * @param method Method to call to delete the argument
481 void DicomDir::SetEndMethodArgDelete( DicomDir::Method *method )
483 EndMethodArgDelete = method;
487 * \brief writes on disc a DICOMDIR
488 * \ warning does NOT add the missing elements in the header :
489 * it's up to the user doing it !
490 * @param fileName file to be written to
491 * @return false only when fail to open
494 bool DicomDir::WriteDicomDir(std::string const &fileName)
497 uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
498 uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
500 std::ofstream *fp = new std::ofstream(fileName.c_str(),
501 std::ios::out | std::ios::binary);
504 gdcmWarningMacro("Failed to open(write) File: " << fileName.c_str());
508 char filePreamble[128];
509 memset(filePreamble, 0, 128);
510 fp->write(filePreamble, 128);
511 binary_write( *fp, "DICM");
513 DicomDirMeta *ptrMeta = GetMeta();
514 ptrMeta->WriteContent(fp, ExplicitVR);
516 // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
519 binary_write(*fp, sq[i]);
522 for(ListDicomDirPatient::iterator cc = Patients.begin();
523 cc != Patients.end();
526 (*cc)->WriteContent( fp, ExplicitVR );
529 // force writing Sequence Delimitation Item
532 binary_write(*fp, sqt[i]); // fffe e0dd ffff ffff
542 * \brief Anonymize a DICOMDIR
546 bool DicomDir::AnonymizeDicomDir()
549 // Something clever to be found to forge the Patient names
550 std::ostringstream s;
552 for(ListDicomDirPatient::iterator cc = Patients.begin();
557 v = (*cc)->GetValEntry(0x0010, 0x0010) ; // Patient's Name
560 v->SetValue(s.str());
563 v = (*cc)->GetValEntry(0x0010, 0x0020) ; // Patient ID
569 v = (*cc)->GetValEntry(0x0010, 0x0030) ; // Patient's BirthDate
580 //-----------------------------------------------------------------------------
583 * \brief create a Document-like chained list from a root Directory
584 * @param path entry point of the tree-like structure
586 void DicomDir::CreateDicomDirChainedList(std::string const &path)
589 DirList dirList(path,1); // gets recursively the file list
590 unsigned int count = 0;
594 DirListType fileList = dirList.GetFilenames();
596 for( DirListType::iterator it = fileList.begin();
597 it != fileList.end();
600 Progress = (float)(count+1)/(float)fileList.size();
601 CallProgressMethod();
608 f->SetLoadMode(LoadMode); // we allow user not to load Sequences...
609 f->Load( it->c_str() );
613 // gdcmWarningMacro( "Failure in new gdcm::File " << it->c_str() );
617 if ( f->IsReadable() )
619 // Add the file to the chained list:
621 gdcmWarningMacro( "Readable " << it->c_str() );
629 // sorts Patient/Study/Serie/
630 std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
632 std::string tmp = dirList.GetDirName();
633 //for each File of the chained list, add/update the Patient/Study/Serie/Image info
634 SetElements(tmp, list);
637 for(VectDocument::iterator itDoc=list.begin();
641 delete dynamic_cast<File *>(*itDoc);
646 * \brief CallStartMethod
648 void DicomDir::CallStartMethod()
654 StartMethod( StartArg );
659 * \brief CallProgressMethod
661 void DicomDir::CallProgressMethod()
663 if ( ProgressMethod )
665 ProgressMethod( ProgressArg );
670 * \brief CallEndMethod
672 void DicomDir::CallEndMethod()
681 //-----------------------------------------------------------------------------
684 * \brief Sets all fields to NULL
686 void DicomDir::Initialize()
689 ProgressMethod = NULL;
691 StartMethodArgDelete = NULL;
692 ProgressMethodArgDelete = NULL;
693 EndMethodArgDelete = NULL;
705 * \brief create a 'gdcm::DicomDir' from a DICOMDIR Header
707 void DicomDir::CreateDicomDir()
709 // The SeqEntries of "Directory Record Sequence" are parsed.
710 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
711 // 1 - we save the beginning iterator
712 // 2 - we continue to parse
713 // 3 - we find an other tag
714 // + we create the object for the precedent tag
717 // Directory record sequence
718 DocEntry *e = GetDocEntry(0x0004, 0x1220);
721 gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
725 SeqEntry *s = dynamic_cast<SeqEntry *>(e);
728 gdcmWarningMacro( "Element (0004,1220) is not a Sequence ?!?");
738 SQItem *tmpSI=s->GetFirstSQItem();
741 d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
742 if ( ValEntry* valEntry = dynamic_cast<ValEntry *>(d) )
744 v = valEntry->GetValue();
748 gdcmWarningMacro( "(0004,1430) not a ValEntry ?!?");
752 // A decent DICOMDIR has much more images than series,
753 // more series than studies, and so on.
754 // This is the right order to preform the tests
758 si = new DicomDirImage(true);
759 if ( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
763 gdcmErrorMacro( "Add AddImageToEnd failed");
766 else if ( v == "SERIES" )
768 si = new DicomDirSerie(true);
769 if ( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
773 gdcmErrorMacro( "Add AddSerieToEnd failed");
776 else if ( v == "VISIT " )
778 si = new DicomDirVisit(true);
779 if ( !AddVisitToEnd( static_cast<DicomDirVisit *>(si)) )
783 gdcmErrorMacro( "Add AddVisitToEnd failed");
786 else if ( v == "STUDY " )
788 si = new DicomDirStudy(true);
789 if ( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
793 gdcmErrorMacro( "Add AddStudyToEnd failed");
796 else if ( v == "PATIENT " )
798 si = new DicomDirPatient(true);
799 if ( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
803 gdcmErrorMacro( "Add PatientToEnd failed");
808 // It was neither a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
809 // nor an 'IMAGE' SQItem. Skip to next item.
810 gdcmWarningMacro( " -------------------------------------------"
811 << "a non PATIENT/STUDY/SERIE/IMAGE SQItem was found : "
814 // FIXME : deal with other item types !
815 tmpSI=s->GetNextSQItem(); // To avoid infinite loop
819 MoveSQItem(si,tmpSI);
821 tmpSI=s->GetNextSQItem();
827 * \brief AddPatientToEnd
828 * @param dd SQ Item to enqueue to the DicomPatient chained List
830 bool DicomDir::AddPatientToEnd(DicomDirPatient *dd)
832 Patients.push_back(dd);
837 * \brief AddStudyToEnd
838 * @param dd SQ Item to enqueue to the DicomDirStudy chained List
840 bool DicomDir::AddStudyToEnd(DicomDirStudy *dd)
842 if ( Patients.size() > 0 )
844 ListDicomDirPatient::iterator itp = Patients.end();
846 (*itp)->AddStudy(dd);
853 * \brief AddSerieToEnd
854 * @param dd SQ Item to enqueue to the DicomDirSerie chained List
856 bool DicomDir::AddSerieToEnd(DicomDirSerie *dd)
858 if ( Patients.size() > 0 )
860 ListDicomDirPatient::iterator itp = Patients.end();
863 DicomDirStudy *study = (*itp)->GetLastStudy();
874 * \brief AddVisitToEnd
875 * @param dd SQ Item to enqueue to the DicomDirVisit chained List
877 bool DicomDir::AddVisitToEnd(DicomDirVisit *dd)
879 if ( Patients.size() > 0 )
881 ListDicomDirPatient::iterator itp = Patients.end();
884 DicomDirStudy *study = (*itp)->GetLastStudy();
894 * \brief AddImageToEnd
895 * @param dd SQ Item to enqueue to the DicomDirImage chained List
897 bool DicomDir::AddImageToEnd(DicomDirImage *dd)
899 if ( Patients.size() > 0 )
901 ListDicomDirPatient::iterator itp = Patients.end();
904 DicomDirStudy *study = (*itp)->GetLastStudy();
907 DicomDirSerie *serie = study->GetLastSerie();
919 * \brief for each Header of the chained list,
920 * add/update the Patient/Study/Serie/Image info
921 * @param path path of the root directory
922 * @param list chained list of Headers
924 void DicomDir::SetElements(std::string const &path, VectDocument const &list)
929 std::string patPrevName = "", patPrevID = "";
930 std::string studPrevInstanceUID = "", studPrevID = "";
931 std::string serPrevInstanceUID = "", serPrevID = "";
933 std::string patCurName, patCurID;
934 std::string studCurInstanceUID, studCurID;
935 std::string serCurInstanceUID, serCurID;
938 for( VectDocument::const_iterator it = list.begin();
942 // get the current file characteristics
943 patCurName = (*it)->GetEntryValue(0x0010,0x0010);
944 patCurID = (*it)->GetEntryValue(0x0010,0x0011);
945 studCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000d);
946 studCurID = (*it)->GetEntryValue(0x0020,0x0010);
947 serCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000e);
948 serCurID = (*it)->GetEntryValue(0x0020,0x0011);
950 if ( patCurName != patPrevName || patCurID != patPrevID || first )
952 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
956 // if new Study, deal with 'STUDY' Elements
957 if ( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID
960 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
964 // if new Serie, deal with 'SERIE' Elements
965 if ( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
968 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
971 // Always Deal with 'IMAGE' Elements
972 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
974 patPrevName = patCurName;
975 patPrevID = patCurID;
976 studPrevInstanceUID = studCurInstanceUID;
977 studPrevID = studCurID;
978 serPrevInstanceUID = serCurInstanceUID;
979 serPrevID = serCurID;
985 * \brief adds to the HTable
986 * the Entries (Dicom Elements) corresponding to the given type
987 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
988 * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
989 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
990 * @param header Header of the current file
992 void DicomDir::SetElement(std::string const &path, DicomDirType type,
995 ListDicomDirElem elemList;
996 ListDicomDirElem::const_iterator it;
997 uint16_t tmpGr, tmpEl;
998 DictEntry *dictEntry;
1005 case GDCM_DICOMDIR_IMAGE:
1006 elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
1007 si = new DicomDirImage(true);
1008 if ( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
1011 gdcmErrorMacro( "Add ImageToEnd failed");
1014 case GDCM_DICOMDIR_SERIE:
1015 elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
1016 si = new DicomDirSerie(true);
1017 if ( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
1020 gdcmErrorMacro( "Add SerieToEnd failed");
1023 case GDCM_DICOMDIR_STUDY:
1024 elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
1025 si = new DicomDirStudy(true);
1026 if ( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
1029 gdcmErrorMacro( "Add StudyToEnd failed");
1032 case GDCM_DICOMDIR_PATIENT:
1033 elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
1034 si = new DicomDirPatient(true);
1035 if ( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
1038 gdcmErrorMacro( "Add PatientToEnd failed");
1041 case GDCM_DICOMDIR_META:
1042 elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
1043 si = new DicomDirMeta(true);
1047 gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
1049 MetaElems = static_cast<DicomDirMeta *>(si);
1054 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
1055 // to avoid further troubles
1056 // imageElem 0008 1140 "" // Referenced Image Sequence
1057 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
1058 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
1059 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
1060 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
1062 // FIXME : troubles found when it's a SeqEntry
1064 // for all the relevant elements found in their own spot of the DicomDir.dic
1065 for( it = elemList.begin(); it != elemList.end(); ++it)
1069 dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
1071 entry = new ValEntry( dictEntry ); // Be sure it's never a BinEntry !
1073 entry->SetOffset(0); // just to avoid further missprinting
1077 // NULL when we Build Up (ex nihilo) a DICOMDIR
1078 // or when we add the META elems
1079 val = header->GetEntryValue(tmpGr, tmpEl);
1086 if ( val == GDCM_UNFOUND)
1088 if ( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
1090 // force to the *end* File Name
1091 val = Util::GetName( path );
1093 else if ( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
1095 if ( header->GetFileName().substr(0, path.length()) != path )
1097 gdcmWarningMacro( "The base path of file name is incorrect");
1098 val = header->GetFileName();
1102 val = &(header->GetFileName().c_str()[path.length()]);
1112 if ( header->GetEntryLength(tmpGr,tmpEl) == 0 )
1116 entry->SetValue( val ); // troubles expected when vr=SQ ...
1118 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
1120 gdcmWarningMacro("GDCM_DICOMDIR_META ?!? should never print that");
1122 si->AddEntry(entry);
1127 * \brief Move the content of the source SQItem to the destination SQItem
1128 * Only DocEntry's are moved
1129 * @param dst destination SQItem
1130 * @param src source SQItem
1132 void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src)
1136 entry = src->GetFirstEntry();
1139 src->RemoveEntryNoDestroy(entry);
1140 dst->AddEntry(entry);
1141 // we destroyed -> the current iterator is not longer valid
1142 entry = src->GetFirstEntry();
1147 * \brief compares two files
1149 bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
1151 return *header1 < *header2;
1154 //-----------------------------------------------------------------------------
1157 * \brief Canonical Printer
1158 * @param os ostream we want to print in
1159 * @param indent Indentation string to be prepended during printing
1161 void DicomDir::Print(std::ostream &os, std::string const & )
1165 MetaElems->SetPrintLevel(PrintLevel);
1166 MetaElems->Print(os);
1168 for(ListDicomDirPatient::iterator cc = Patients.begin();
1169 cc != Patients.end();
1172 (*cc)->SetPrintLevel(PrintLevel);
1177 //-----------------------------------------------------------------------------
1178 } // end namespace gdcm