1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2005/07/23 01:59:21 $
7 Version: $Revision: 1.152 $
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
126 #ifndef GDCM_LEGACY_REMOVE
128 * \brief Constructor Parses recursively the directory and creates the DicomDir
129 * or uses an already built DICOMDIR, depending on 'parseDir' value.
130 * @param fileName name
131 * - of the root directory (parseDir = true)
132 * - of the DICOMDIR (parseDir = false)
133 * @param parseDir boolean
134 * - true if user passed an entry point
135 * and wants to explore recursively the directories
136 * - false if user passed an already built DICOMDIR file
137 * and wants to use it
138 * @deprecated use : new DicomDir() + [ SetLoadMode(lm) + ] SetDirectoryName(name)
139 * or : new DicomDir() + SetFileName(name)
141 DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
144 // At this step, Document constructor is already executed,
145 // whatever user passed (either a root directory or a DICOMDIR)
146 // and whatever the value of parseDir was.
147 // (nothing is cheked in Document constructor, to avoid overhead)
150 SetLoadMode (0x00000000); // concerns only dicom files
151 SetFileName( fileName );
157 * \brief Canonical destructor
159 DicomDir::~DicomDir()
161 SetStartMethod(NULL);
162 SetProgressMethod(NULL);
172 //-----------------------------------------------------------------------------
176 * \brief Loader. use SetFileName(fn)
177 * or SetLoadMode(lm) + SetDirectoryName(dn) before !
178 * @return false if file cannot be open or no swap info was found,
179 * or no tag was found.
181 bool DicomDir::Load( )
183 // We should clean out anything that already exists.
184 Initialize(); // sets all private fields to NULL
188 if ( ! this->Document::Load( ) )
191 return DoTheLoadingJob( );
194 #ifndef GDCM_LEGACY_REMOVE
196 * \brief Loader. (DEPRECATED : kept not to break the API)
197 * @param fileName file to be open for parsing
198 * @return false if file cannot be open or no swap info was found,
199 * or no tag was found.
200 * @deprecated use SetFileName(n) + Load() instead
202 bool DicomDir::Load(std::string const &fileName )
204 // We should clean out anything that already exists.
205 Initialize(); // sets all private fields to NULL
207 SetFileName( fileName );
210 if ( ! this->Document::Load( ) )
213 return DoTheLoadingJob( );
216 /// DEPRECATED : use SetDirectoryName(dname) instead
217 void DicomDir::SetParseDir(bool parseDir)
224 * \brief Does the Loading Job (internal use only)
225 * @return false if file cannot be open or no swap info was found,
226 * or no tag was found.
228 bool DicomDir::DoTheLoadingJob( )
230 // We should clean out anything that already exists.
231 Initialize(); // sets all private fields to NULL
235 // Only if user passed a DICOMDIR
236 // ------------------------------
242 if (!Document::Load() )
247 if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
249 gdcmWarningMacro( "Entry HT empty for file: "<< GetFileName());
252 // Directory record sequence
253 DocEntry *e = GetDocEntry(0x0004, 0x1220);
256 gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
257 << " in file " << GetFileName());
265 // Only if user passed a root directory
266 // ------------------------------------
267 if ( GetFileName() == "." )
269 // user passed '.' as Name
270 // we get current directory name
272 getcwd(dummy, (size_t)1000);
273 SetFileName( dummy ); // will be converted into a string
276 gdcmWarningMacro( "Parse directory and create the DicomDir : "
284 * \brief This predicate, based on hopefully reasonable heuristics,
285 * decides whether or not the current document was properly parsed
286 * and contains the mandatory information for being considered as
287 * a well formed and usable DicomDir.
288 * @return true when Document is the one of a reasonable DicomDir,
291 bool DicomDir::IsReadable()
293 if ( Filetype == Unknown )
295 gdcmWarningMacro( "Wrong filetype");
300 gdcmWarningMacro( "Meta Elements missing in DicomDir");
303 if ( Patients.size() <= 0 )
305 gdcmWarningMacro( "NO Patient in DicomDir");
313 * \brief adds *the* Meta to a partially created DICOMDIR
315 DicomDirMeta *DicomDir::NewMeta()
320 DocEntry *entry = GetFirstEntry();
323 MetaElems = new DicomDirMeta(true); // true = empty
325 entry = GetFirstEntry();
328 if ( dynamic_cast<SeqEntry *>(entry) )
331 RemoveEntryNoDestroy(entry);
332 MetaElems->AddEntry(entry);
334 entry = GetFirstEntry();
337 else // after root directory parsing
339 MetaElems = new DicomDirMeta(false); // false = not empty
341 MetaElems->SetSQItemNumber(0); // To avoid further missprinting
346 * \brief adds a new Patient (with the basic elements) to a partially created
349 DicomDirPatient *DicomDir::NewPatient()
351 DicomDirPatient *p = new DicomDirPatient();
352 AddPatientToEnd( p );
357 * \brief Remove all Patients
359 void DicomDir::ClearPatient()
361 for(ListDicomDirPatient::iterator cc = Patients.begin();
371 * \brief Get the first entry while visiting the DicomDirPatients
372 * \return The first DicomDirPatient if found, otherwhise NULL
374 DicomDirPatient *DicomDir::GetFirstPatient()
376 ItPatient = Patients.begin();
377 if ( ItPatient != Patients.end() )
383 * \brief Get the next entry while visiting the DicomDirPatients
384 * \note : meaningfull only if GetFirstEntry already called
385 * \return The next DicomDirPatient if found, otherwhise NULL
387 DicomDirPatient *DicomDir::GetNextPatient()
389 gdcmAssertMacro (ItPatient != Patients.end());
392 if ( ItPatient != Patients.end() )
398 * \brief fills the whole structure, starting from a root Directory
400 void DicomDir::ParseDirectory()
402 CreateDicomDirChainedList( GetFileName() );
407 * \brief Set the start method to call when the parsing of the
409 * @param method Method to call
410 * @param arg Argument to pass to the method
411 * @param argDelete Argument
412 * \warning In python : the arg parameter isn't considered
414 void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg,
415 DicomDir::Method *argDelete )
417 if ( StartArg && StartMethodArgDelete )
419 StartMethodArgDelete( StartArg );
422 StartMethod = method;
424 StartMethodArgDelete = argDelete;
429 * \brief Set the progress method to call when the parsing of the
431 * @param method Method to call
432 * @param arg Argument to pass to the method
433 * @param argDelete Argument
434 * \warning In python : the arg parameter isn't considered
436 void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg,
437 DicomDir::Method *argDelete )
439 if ( ProgressArg && ProgressMethodArgDelete )
441 ProgressMethodArgDelete( ProgressArg );
444 ProgressMethod = method;
446 ProgressMethodArgDelete = argDelete;
450 * \brief Set the end method to call when the parsing of the directory ends
451 * @param method Method to call
452 * @param arg Argument to pass to the method
453 * @param argDelete Argument
454 * \warning In python : the arg parameter isn't considered
456 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg,
457 DicomDir::Method *argDelete )
459 if ( EndArg && EndMethodArgDelete )
461 EndMethodArgDelete( EndArg );
466 EndMethodArgDelete = argDelete;
470 * \brief Set the method to delete the argument
471 * The argument is destroyed when the method is changed or when the
473 * @param method Method to call to delete the argument
475 void DicomDir::SetStartMethodArgDelete( DicomDir::Method *method )
477 StartMethodArgDelete = method;
481 * \brief Set the method to delete the argument
482 * The argument is destroyed when the method is changed or when the
484 * @param method Method to call to delete the argument
486 void DicomDir::SetProgressMethodArgDelete( DicomDir::Method *method )
488 ProgressMethodArgDelete = method;
492 * \brief Set the method to delete the argument
493 * The argument is destroyed when the method is changed or when
494 * the class is destroyed
495 * @param method Method to call to delete the argument
497 void DicomDir::SetEndMethodArgDelete( DicomDir::Method *method )
499 EndMethodArgDelete = method;
503 * \brief writes on disc a DICOMDIR
504 * \ warning does NOT add the missing elements in the header :
505 * it's up to the user doing it !
506 * @param fileName file to be written to
507 * @return false only when fail to open
510 bool DicomDir::WriteDicomDir(std::string const &fileName)
513 uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
514 uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
516 std::ofstream *fp = new std::ofstream(fileName.c_str(),
517 std::ios::out | std::ios::binary);
520 gdcmWarningMacro("Failed to open(write) File: " << fileName.c_str());
524 char filePreamble[128];
525 memset(filePreamble, 0, 128);
526 fp->write(filePreamble, 128);
527 binary_write( *fp, "DICM");
529 DicomDirMeta *ptrMeta = GetMeta();
530 ptrMeta->WriteContent(fp, ExplicitVR);
532 // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
535 binary_write(*fp, sq[i]);
538 for(ListDicomDirPatient::iterator cc = Patients.begin();
539 cc != Patients.end();
542 (*cc)->WriteContent( fp, ExplicitVR );
545 // force writing Sequence Delimitation Item
548 binary_write(*fp, sqt[i]); // fffe e0dd ffff ffff
558 * \brief Anonymize a DICOMDIR
562 bool DicomDir::AnonymizeDicomDir()
565 // Something clever to be found to forge the Patient names
566 std::ostringstream s;
568 for(ListDicomDirPatient::iterator cc = Patients.begin();
573 v = (*cc)->GetValEntry(0x0010, 0x0010) ; // Patient's Name
576 v->SetValue(s.str());
579 v = (*cc)->GetValEntry(0x0010, 0x0020) ; // Patient ID
585 v = (*cc)->GetValEntry(0x0010, 0x0030) ; // Patient's BirthDate
596 //-----------------------------------------------------------------------------
599 * \brief create a Document-like chained list from a root Directory
600 * @param path entry point of the tree-like structure
602 void DicomDir::CreateDicomDirChainedList(std::string const &path)
605 DirList dirList(path,1); // gets recursively the file list
606 unsigned int count = 0;
610 DirListType fileList = dirList.GetFilenames();
612 for( DirListType::iterator it = fileList.begin();
613 it != fileList.end();
616 Progress = (float)(count+1)/(float)fileList.size();
617 CallProgressMethod();
624 f->SetLoadMode(LoadMode); // we allow user not to load Sequences, or Shadow
626 f->SetFileName( it->c_str() );
627 /*int res = */f->Load( );
631 // gdcmWarningMacro( "Failure in new gdcm::File " << it->c_str() );
635 if ( f->IsReadable() )
637 // Add the file to the chained list:
639 gdcmWarningMacro( "Readable " << it->c_str() );
647 // sorts Patient/Study/Serie/
648 std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
650 std::string tmp = dirList.GetDirName();
651 //for each File of the chained list, add/update the Patient/Study/Serie/Image info
652 SetElements(tmp, list);
655 for(VectDocument::iterator itDoc=list.begin();
659 delete dynamic_cast<File *>(*itDoc);
664 * \brief CallStartMethod
666 void DicomDir::CallStartMethod()
672 StartMethod( StartArg );
677 * \brief CallProgressMethod
679 void DicomDir::CallProgressMethod()
681 if ( ProgressMethod )
683 ProgressMethod( ProgressArg );
688 * \brief CallEndMethod
690 void DicomDir::CallEndMethod()
699 //-----------------------------------------------------------------------------
702 * \brief Sets all fields to NULL
704 void DicomDir::Initialize()
707 ProgressMethod = NULL;
709 StartMethodArgDelete = NULL;
710 ProgressMethodArgDelete = NULL;
711 EndMethodArgDelete = NULL;
723 * \brief create a 'gdcm::DicomDir' from a DICOMDIR Header
725 void DicomDir::CreateDicomDir()
727 // The SeqEntries of "Directory Record Sequence" are parsed.
728 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
729 // 1 - we save the beginning iterator
730 // 2 - we continue to parse
731 // 3 - we find an other tag
732 // + we create the object for the precedent tag
735 // Directory record sequence
736 DocEntry *e = GetDocEntry(0x0004, 0x1220);
739 gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
743 SeqEntry *s = dynamic_cast<SeqEntry *>(e);
746 gdcmWarningMacro( "Element (0004,1220) is not a Sequence ?!?");
756 SQItem *tmpSI=s->GetFirstSQItem();
759 d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
760 if ( ValEntry* valEntry = dynamic_cast<ValEntry *>(d) )
762 v = valEntry->GetValue();
766 gdcmWarningMacro( "(0004,1430) not a ValEntry ?!?");
770 // A decent DICOMDIR has much more images than series,
771 // more series than studies, and so on.
772 // This is the right order to preform the tests
776 si = new DicomDirImage(true);
777 if ( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
781 gdcmErrorMacro( "Add AddImageToEnd failed");
784 else if ( v == "SERIES" )
786 si = new DicomDirSerie(true);
787 if ( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
791 gdcmErrorMacro( "Add AddSerieToEnd failed");
794 else if ( v == "VISIT " )
796 si = new DicomDirVisit(true);
797 if ( !AddVisitToEnd( static_cast<DicomDirVisit *>(si)) )
801 gdcmErrorMacro( "Add AddVisitToEnd failed");
804 else if ( v == "STUDY " )
806 si = new DicomDirStudy(true);
807 if ( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
811 gdcmErrorMacro( "Add AddStudyToEnd failed");
814 else if ( v == "PATIENT " )
816 si = new DicomDirPatient(true);
817 if ( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
821 gdcmErrorMacro( "Add PatientToEnd failed");
826 // It was neither a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
827 // nor an 'IMAGE' SQItem. Skip to next item.
828 gdcmWarningMacro( " -------------------------------------------"
829 << "a non PATIENT/STUDY/SERIE/IMAGE SQItem was found : "
832 // FIXME : deal with other item types !
833 tmpSI=s->GetNextSQItem(); // To avoid infinite loop
837 //MoveSQItem(si,tmpSI); // Old code : Copies each Entry
838 // -and then removes the source-
839 si->MoveObject(tmpSI); // New code : Copies the List
841 tmpSI=s->GetNextSQItem();
847 * \brief AddPatientToEnd
848 * @param dd SQ Item to enqueue to the DicomPatient chained List
850 bool DicomDir::AddPatientToEnd(DicomDirPatient *dd)
852 Patients.push_back(dd);
857 * \brief AddStudyToEnd
858 * @param dd SQ Item to enqueue to the DicomDirStudy chained List
860 bool DicomDir::AddStudyToEnd(DicomDirStudy *dd)
862 if ( Patients.size() > 0 )
864 ListDicomDirPatient::iterator itp = Patients.end();
866 (*itp)->AddStudy(dd);
873 * \brief AddSerieToEnd
874 * @param dd SQ Item to enqueue to the DicomDirSerie chained List
876 bool DicomDir::AddSerieToEnd(DicomDirSerie *dd)
878 if ( Patients.size() > 0 )
880 ListDicomDirPatient::iterator itp = Patients.end();
883 DicomDirStudy *study = (*itp)->GetLastStudy();
894 * \brief AddVisitToEnd
895 * @param dd SQ Item to enqueue to the DicomDirVisit chained List
897 bool DicomDir::AddVisitToEnd(DicomDirVisit *dd)
899 if ( Patients.size() > 0 )
901 ListDicomDirPatient::iterator itp = Patients.end();
904 DicomDirStudy *study = (*itp)->GetLastStudy();
914 * \brief AddImageToEnd
915 * @param dd SQ Item to enqueue to the DicomDirImage chained List
917 bool DicomDir::AddImageToEnd(DicomDirImage *dd)
919 if ( Patients.size() > 0 )
921 ListDicomDirPatient::iterator itp = Patients.end();
924 DicomDirStudy *study = (*itp)->GetLastStudy();
927 DicomDirSerie *serie = study->GetLastSerie();
939 * \brief for each Header of the chained list,
940 * add/update the Patient/Study/Serie/Image info
941 * @param path path of the root directory
942 * @param list chained list of Headers
944 void DicomDir::SetElements(std::string const &path, VectDocument const &list)
949 std::string patPrevName = "", patPrevID = "";
950 std::string studPrevInstanceUID = "", studPrevID = "";
951 std::string serPrevInstanceUID = "", serPrevID = "";
953 std::string patCurName, patCurID;
954 std::string studCurInstanceUID, studCurID;
955 std::string serCurInstanceUID, serCurID;
958 for( VectDocument::const_iterator it = list.begin();
962 // get the current file characteristics
963 patCurName = (*it)->GetEntryValue(0x0010,0x0010);
964 patCurID = (*it)->GetEntryValue(0x0010,0x0011);
965 studCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000d);
966 studCurID = (*it)->GetEntryValue(0x0020,0x0010);
967 serCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000e);
968 serCurID = (*it)->GetEntryValue(0x0020,0x0011);
970 if ( patCurName != patPrevName || patCurID != patPrevID || first )
972 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
976 // if new Study, deal with 'STUDY' Elements
977 if ( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID
980 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
984 // if new Serie, deal with 'SERIE' Elements
985 if ( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
988 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
991 // Always Deal with 'IMAGE' Elements
992 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
994 patPrevName = patCurName;
995 patPrevID = patCurID;
996 studPrevInstanceUID = studCurInstanceUID;
997 studPrevID = studCurID;
998 serPrevInstanceUID = serCurInstanceUID;
999 serPrevID = serCurID;
1005 * \brief adds to the HTable
1006 * the Entries (Dicom Elements) corresponding to the given type
1007 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
1008 * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
1009 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
1010 * @param header Header of the current file
1012 void DicomDir::SetElement(std::string const &path, DicomDirType type,
1015 ListDicomDirElem elemList;
1016 ListDicomDirElem::const_iterator it;
1017 uint16_t tmpGr, tmpEl;
1018 DictEntry *dictEntry;
1025 case GDCM_DICOMDIR_IMAGE:
1026 elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
1027 si = new DicomDirImage(true);
1028 if ( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
1031 gdcmErrorMacro( "Add ImageToEnd failed");
1034 case GDCM_DICOMDIR_SERIE:
1035 elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
1036 si = new DicomDirSerie(true);
1037 if ( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
1040 gdcmErrorMacro( "Add SerieToEnd failed");
1043 case GDCM_DICOMDIR_STUDY:
1044 elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
1045 si = new DicomDirStudy(true);
1046 if ( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
1049 gdcmErrorMacro( "Add StudyToEnd failed");
1052 case GDCM_DICOMDIR_PATIENT:
1053 elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
1054 si = new DicomDirPatient(true);
1055 if ( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
1058 gdcmErrorMacro( "Add PatientToEnd failed");
1061 case GDCM_DICOMDIR_META:
1062 elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
1063 si = new DicomDirMeta(true);
1067 gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
1069 MetaElems = static_cast<DicomDirMeta *>(si);
1074 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
1075 // to avoid further troubles
1076 // imageElem 0008 1140 "" // Referenced Image Sequence
1077 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
1078 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
1079 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
1080 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
1082 // FIXME : troubles found when it's a SeqEntry
1084 // for all the relevant elements found in their own spot of the DicomDir.dic
1085 for( it = elemList.begin(); it != elemList.end(); ++it)
1089 dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
1091 entry = new ValEntry( dictEntry ); // Be sure it's never a BinEntry !
1093 entry->SetOffset(0); // just to avoid further missprinting
1097 // NULL when we Build Up (ex nihilo) a DICOMDIR
1098 // or when we add the META elems
1099 val = header->GetEntryValue(tmpGr, tmpEl);
1106 if ( val == GDCM_UNFOUND)
1108 if ( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
1110 // force to the *end* File Name
1111 val = Util::GetName( path );
1113 else if ( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
1115 if ( header->GetFileName().substr(0, path.length()) != path )
1117 gdcmWarningMacro( "The base path of file name is incorrect");
1118 val = header->GetFileName();
1122 val = &(header->GetFileName().c_str()[path.length()]);
1132 if ( header->GetEntryLength(tmpGr,tmpEl) == 0 )
1136 entry->SetValue( val ); // troubles expected when vr=SQ ...
1138 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
1140 gdcmWarningMacro("GDCM_DICOMDIR_META ?!? should never print that");
1142 si->AddEntry(entry);
1147 * \brief Move the content of the source SQItem to the destination SQItem
1148 * Only DocEntry's are moved
1149 * @param dst destination SQItem
1150 * @param src source SQItem
1152 void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src)
1156 entry = src->GetFirstEntry();
1159 src->RemoveEntryNoDestroy(entry);
1160 dst->AddEntry(entry);
1161 // we destroyed -> the current iterator is not longer valid
1162 entry = src->GetFirstEntry();
1167 * \brief compares two files
1169 bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
1171 return *header1 < *header2;
1174 //-----------------------------------------------------------------------------
1177 * \brief Canonical Printer
1178 * @param os ostream we want to print in
1179 * @param indent Indentation string to be prepended during printing
1181 void DicomDir::Print(std::ostream &os, std::string const & )
1185 MetaElems->SetPrintLevel(PrintLevel);
1186 MetaElems->Print(os);
1188 for(ListDicomDirPatient::iterator cc = Patients.begin();
1189 cc != Patients.end();
1192 (*cc)->SetPrintLevel(PrintLevel);
1197 //-----------------------------------------------------------------------------
1198 } // end namespace gdcm