1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2005/08/19 13:15:05 $
7 Version: $Revision: 1.153 $
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
108 // DicomDir::CreateDicomDir will have to be completed
109 // Treelike structure management will have to be upgraded
110 // ----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
115 // Constructor / Destructor
117 * \brief Constructor : creates an empty DicomDir
122 Initialize(); // sets all private fields to NULL
127 #ifndef GDCM_LEGACY_REMOVE
129 * \brief Constructor Parses recursively the directory and creates the DicomDir
130 * or uses an already built DICOMDIR, depending on 'parseDir' value.
131 * @param fileName name
132 * - of the root directory (parseDir = true)
133 * - of the DICOMDIR (parseDir = false)
134 * @param parseDir boolean
135 * - true if user passed an entry point
136 * and wants to explore recursively the directories
137 * - false if user passed an already built DICOMDIR file
138 * and wants to use it
139 * @deprecated use : new DicomDir() + [ SetLoadMode(lm) + ] SetDirectoryName(name)
140 * or : new DicomDir() + SetFileName(name)
142 DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
145 // At this step, Document constructor is already executed,
146 // whatever user passed (either a root directory or a DICOMDIR)
147 // and whatever the value of parseDir was.
148 // (nothing is cheked in Document constructor, to avoid overhead)
151 SetLoadMode (0x00000000); // concerns only dicom files
152 SetFileName( fileName );
158 * \brief Canonical destructor
160 DicomDir::~DicomDir()
162 SetStartMethod(NULL);
163 SetProgressMethod(NULL);
173 //-----------------------------------------------------------------------------
177 * \brief Loader. use SetFileName(fn)
178 * or SetLoadMode(lm) + SetDirectoryName(dn) before !
179 * @return false if file cannot be open or no swap info was found,
180 * or no tag was found.
182 bool DicomDir::Load( )
184 // We should clean out anything that already exists.
185 Initialize(); // sets all private fields to NULL
189 if ( ! this->Document::Load( ) )
192 return DoTheLoadingJob( );
195 #ifndef GDCM_LEGACY_REMOVE
197 * \brief Loader. (DEPRECATED : kept not to break the API)
198 * @param fileName file to be open for parsing
199 * @return false if file cannot be open or no swap info was found,
200 * or no tag was found.
201 * @deprecated use SetFileName(n) + Load() instead
203 bool DicomDir::Load(std::string const &fileName )
205 // We should clean out anything that already exists.
206 Initialize(); // sets all private fields to NULL
208 SetFileName( fileName );
211 if ( ! this->Document::Load( ) )
214 return DoTheLoadingJob( );
217 /// DEPRECATED : use SetDirectoryName(dname) instead
218 void DicomDir::SetParseDir(bool parseDir)
225 * \brief Does the Loading Job (internal use only)
226 * @return false if file cannot be open or no swap info was found,
227 * or no tag was found.
229 bool DicomDir::DoTheLoadingJob( )
231 // We should clean out anything that already exists.
232 Initialize(); // sets all private fields to NULL
236 // Only if user passed a DICOMDIR
237 // ------------------------------
243 if (!Document::Load() )
248 if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
250 gdcmWarningMacro( "Entry HT empty for file: "<< GetFileName());
253 // Directory record sequence
254 DocEntry *e = GetDocEntry(0x0004, 0x1220);
257 gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
258 << " in file " << GetFileName());
266 // Only if user passed a root directory
267 // ------------------------------------
268 if ( GetFileName() == "." )
270 // user passed '.' as Name
271 // we get current directory name
273 getcwd(dummy, (size_t)1000);
274 SetFileName( dummy ); // will be converted into a string
277 gdcmWarningMacro( "Parse directory and create the DicomDir : "
285 * \brief This predicate, based on hopefully reasonable heuristics,
286 * decides whether or not the current document was properly parsed
287 * and contains the mandatory information for being considered as
288 * a well formed and usable DicomDir.
289 * @return true when Document is the one of a reasonable DicomDir,
292 bool DicomDir::IsReadable()
294 if ( Filetype == Unknown )
296 gdcmWarningMacro( "Wrong filetype");
301 gdcmWarningMacro( "Meta Elements missing in DicomDir");
304 if ( Patients.size() <= 0 )
306 gdcmWarningMacro( "NO Patient in DicomDir");
314 * \brief adds *the* Meta to a partially created DICOMDIR
316 DicomDirMeta *DicomDir::NewMeta()
321 DocEntry *entry = GetFirstEntry();
324 MetaElems = new DicomDirMeta(true); // true = empty
326 entry = GetFirstEntry();
329 if ( dynamic_cast<SeqEntry *>(entry) )
332 RemoveEntryNoDestroy(entry);
333 MetaElems->AddEntry(entry);
335 entry = GetFirstEntry();
338 else // after root directory parsing
340 MetaElems = new DicomDirMeta(false); // false = not empty
342 MetaElems->SetSQItemNumber(0); // To avoid further missprinting
347 * \brief adds a new Patient (with the basic elements) to a partially created
350 DicomDirPatient *DicomDir::NewPatient()
352 DicomDirPatient *p = new DicomDirPatient();
353 AddPatientToEnd( p );
358 * \brief Remove all Patients
360 void DicomDir::ClearPatient()
362 for(ListDicomDirPatient::iterator cc = Patients.begin();
372 * \brief Get the first entry while visiting the DicomDirPatients
373 * \return The first DicomDirPatient if found, otherwhise NULL
375 DicomDirPatient *DicomDir::GetFirstPatient()
377 ItPatient = Patients.begin();
378 if ( ItPatient != Patients.end() )
384 * \brief Get the next entry while visiting the DicomDirPatients
385 * \note : meaningfull only if GetFirstEntry already called
386 * \return The next DicomDirPatient if found, otherwhise NULL
388 DicomDirPatient *DicomDir::GetNextPatient()
390 gdcmAssertMacro (ItPatient != Patients.end());
393 if ( ItPatient != Patients.end() )
399 * \brief fills the whole structure, starting from a root Directory
401 void DicomDir::ParseDirectory()
403 CreateDicomDirChainedList( GetFileName() );
408 * \brief Set the start method to call when the parsing of the
410 * @param method Method to call
411 * @param arg Argument to pass to the method
412 * @param argDelete Argument
413 * \warning In python : the arg parameter isn't considered
415 void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg,
416 DicomDir::Method *argDelete )
418 if ( StartArg && StartMethodArgDelete )
420 StartMethodArgDelete( StartArg );
423 StartMethod = method;
425 StartMethodArgDelete = argDelete;
430 * \brief Set the progress method to call when the parsing of the
432 * @param method Method to call
433 * @param arg Argument to pass to the method
434 * @param argDelete Argument
435 * \warning In python : the arg parameter isn't considered
437 void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg,
438 DicomDir::Method *argDelete )
440 if ( ProgressArg && ProgressMethodArgDelete )
442 ProgressMethodArgDelete( ProgressArg );
445 ProgressMethod = method;
447 ProgressMethodArgDelete = argDelete;
451 * \brief Set the end method to call when the parsing of the directory ends
452 * @param method Method to call
453 * @param arg Argument to pass to the method
454 * @param argDelete Argument
455 * \warning In python : the arg parameter isn't considered
457 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg,
458 DicomDir::Method *argDelete )
460 if ( EndArg && EndMethodArgDelete )
462 EndMethodArgDelete( EndArg );
467 EndMethodArgDelete = argDelete;
471 * \brief Set the method to delete the argument
472 * The argument is destroyed when the method is changed or when the
474 * @param method Method to call to delete the argument
476 void DicomDir::SetStartMethodArgDelete( DicomDir::Method *method )
478 StartMethodArgDelete = method;
482 * \brief Set the method to delete the argument
483 * The argument is destroyed when the method is changed or when the
485 * @param method Method to call to delete the argument
487 void DicomDir::SetProgressMethodArgDelete( DicomDir::Method *method )
489 ProgressMethodArgDelete = method;
493 * \brief Set the method to delete the argument
494 * The argument is destroyed when the method is changed or when
495 * the class is destroyed
496 * @param method Method to call to delete the argument
498 void DicomDir::SetEndMethodArgDelete( DicomDir::Method *method )
500 EndMethodArgDelete = method;
504 * \brief writes on disc a DICOMDIR
505 * \ warning does NOT add the missing elements in the header :
506 * it's up to the user doing it !
507 * @param fileName file to be written to
508 * @return false only when fail to open
511 bool DicomDir::WriteDicomDir(std::string const &fileName)
514 uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
515 uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
517 std::ofstream *fp = new std::ofstream(fileName.c_str(),
518 std::ios::out | std::ios::binary);
521 gdcmWarningMacro("Failed to open(write) File: " << fileName.c_str());
525 char filePreamble[128];
526 memset(filePreamble, 0, 128);
527 fp->write(filePreamble, 128);
528 binary_write( *fp, "DICM");
530 DicomDirMeta *ptrMeta = GetMeta();
531 ptrMeta->WriteContent(fp, ExplicitVR);
533 // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
536 binary_write(*fp, sq[i]);
539 for(ListDicomDirPatient::iterator cc = Patients.begin();
540 cc != Patients.end();
543 (*cc)->WriteContent( fp, ExplicitVR );
546 // force writing Sequence Delimitation Item
549 binary_write(*fp, sqt[i]); // fffe e0dd ffff ffff
559 * \brief Anonymize a DICOMDIR
563 bool DicomDir::AnonymizeDicomDir()
566 // Something clever to be found to forge the Patient names
567 std::ostringstream s;
569 for(ListDicomDirPatient::iterator cc = Patients.begin();
574 v = (*cc)->GetValEntry(0x0010, 0x0010) ; // Patient's Name
577 v->SetValue(s.str());
580 v = (*cc)->GetValEntry(0x0010, 0x0020) ; // Patient ID
586 v = (*cc)->GetValEntry(0x0010, 0x0030) ; // Patient's BirthDate
597 //-----------------------------------------------------------------------------
600 * \brief create a Document-like chained list from a root Directory
601 * @param path entry point of the tree-like structure
603 void DicomDir::CreateDicomDirChainedList(std::string const &path)
606 DirList dirList(path,1); // gets recursively the file list
607 unsigned int count = 0;
611 DirListType fileList = dirList.GetFilenames();
613 for( DirListType::iterator it = fileList.begin();
614 it != fileList.end();
617 Progress = (float)(count+1)/(float)fileList.size();
618 CallProgressMethod();
625 f->SetLoadMode(LoadMode); // we allow user not to load Sequences, or Shadow
627 f->SetFileName( it->c_str() );
628 /*int res = */f->Load( );
632 // gdcmWarningMacro( "Failure in new gdcm::File " << it->c_str() );
636 if ( f->IsReadable() )
638 // Add the file to the chained list:
640 gdcmWarningMacro( "Readable " << it->c_str() );
648 // sorts Patient/Study/Serie/
649 std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
651 std::string tmp = dirList.GetDirName();
652 //for each File of the chained list, add/update the Patient/Study/Serie/Image info
653 SetElements(tmp, list);
656 for(VectDocument::iterator itDoc=list.begin();
660 delete dynamic_cast<File *>(*itDoc);
665 * \brief CallStartMethod
667 void DicomDir::CallStartMethod()
673 StartMethod( StartArg );
678 * \brief CallProgressMethod
680 void DicomDir::CallProgressMethod()
682 if ( ProgressMethod )
684 ProgressMethod( ProgressArg );
689 * \brief CallEndMethod
691 void DicomDir::CallEndMethod()
700 //-----------------------------------------------------------------------------
703 * \brief Sets all fields to NULL
705 void DicomDir::Initialize()
708 ProgressMethod = NULL;
710 StartMethodArgDelete = NULL;
711 ProgressMethodArgDelete = NULL;
712 EndMethodArgDelete = NULL;
724 * \brief create a 'gdcm::DicomDir' from a DICOMDIR Header
726 void DicomDir::CreateDicomDir()
728 // The SeqEntries of "Directory Record Sequence" are parsed.
729 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
730 // 1 - we save the beginning iterator
731 // 2 - we continue to parse
732 // 3 - we find an other tag
733 // + we create the object for the precedent tag
736 // Directory record sequence
737 DocEntry *e = GetDocEntry(0x0004, 0x1220);
740 gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
744 SeqEntry *s = dynamic_cast<SeqEntry *>(e);
747 gdcmWarningMacro( "Element (0004,1220) is not a Sequence ?!?");
757 SQItem *tmpSI=s->GetFirstSQItem();
760 d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
761 if ( ValEntry* valEntry = dynamic_cast<ValEntry *>(d) )
763 v = valEntry->GetValue();
767 gdcmWarningMacro( "(0004,1430) not a ValEntry ?!?");
771 // A decent DICOMDIR has much more images than series,
772 // more series than studies, and so on.
773 // This is the right order to preform the tests
777 si = new DicomDirImage(true);
778 if ( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
782 gdcmErrorMacro( "Add AddImageToEnd failed");
785 else if ( v == "SERIES" )
787 si = new DicomDirSerie(true);
788 if ( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
792 gdcmErrorMacro( "Add AddSerieToEnd failed");
795 else if ( v == "VISIT " )
797 si = new DicomDirVisit(true);
798 if ( !AddVisitToEnd( static_cast<DicomDirVisit *>(si)) )
802 gdcmErrorMacro( "Add AddVisitToEnd failed");
805 else if ( v == "STUDY " )
807 si = new DicomDirStudy(true);
808 if ( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
812 gdcmErrorMacro( "Add AddStudyToEnd failed");
815 else if ( v == "PATIENT " )
817 si = new DicomDirPatient(true);
818 if ( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
822 gdcmErrorMacro( "Add PatientToEnd failed");
827 // It was neither a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
828 // nor an 'IMAGE' SQItem. Skip to next item.
829 gdcmWarningMacro( " -------------------------------------------"
830 << "a non PATIENT/STUDY/SERIE/IMAGE SQItem was found : "
833 // FIXME : deal with other item types !
834 tmpSI=s->GetNextSQItem(); // To avoid infinite loop
838 //MoveSQItem(si,tmpSI); // Old code : Copies each Entry
839 // -and then removes the source-
840 si->MoveObject(tmpSI); // New code : Copies the List
842 tmpSI=s->GetNextSQItem();
848 * \brief AddPatientToEnd
849 * @param dd SQ Item to enqueue to the DicomPatient chained List
851 bool DicomDir::AddPatientToEnd(DicomDirPatient *dd)
853 Patients.push_back(dd);
858 * \brief AddStudyToEnd
859 * @param dd SQ Item to enqueue to the DicomDirStudy chained List
861 bool DicomDir::AddStudyToEnd(DicomDirStudy *dd)
863 if ( Patients.size() > 0 )
865 ListDicomDirPatient::iterator itp = Patients.end();
867 (*itp)->AddStudy(dd);
874 * \brief AddSerieToEnd
875 * @param dd SQ Item to enqueue to the DicomDirSerie chained List
877 bool DicomDir::AddSerieToEnd(DicomDirSerie *dd)
879 if ( Patients.size() > 0 )
881 ListDicomDirPatient::iterator itp = Patients.end();
884 DicomDirStudy *study = (*itp)->GetLastStudy();
895 * \brief AddVisitToEnd
896 * @param dd SQ Item to enqueue to the DicomDirVisit chained List
898 bool DicomDir::AddVisitToEnd(DicomDirVisit *dd)
900 if ( Patients.size() > 0 )
902 ListDicomDirPatient::iterator itp = Patients.end();
905 DicomDirStudy *study = (*itp)->GetLastStudy();
915 * \brief AddImageToEnd
916 * @param dd SQ Item to enqueue to the DicomDirImage chained List
918 bool DicomDir::AddImageToEnd(DicomDirImage *dd)
920 if ( Patients.size() > 0 )
922 ListDicomDirPatient::iterator itp = Patients.end();
925 DicomDirStudy *study = (*itp)->GetLastStudy();
928 DicomDirSerie *serie = study->GetLastSerie();
940 * \brief for each Header of the chained list,
941 * add/update the Patient/Study/Serie/Image info
942 * @param path path of the root directory
943 * @param list chained list of Headers
945 void DicomDir::SetElements(std::string const &path, VectDocument const &list)
950 std::string patPrevName = "", patPrevID = "";
951 std::string studPrevInstanceUID = "", studPrevID = "";
952 std::string serPrevInstanceUID = "", serPrevID = "";
954 std::string patCurName, patCurID;
955 std::string studCurInstanceUID, studCurID;
956 std::string serCurInstanceUID, serCurID;
959 for( VectDocument::const_iterator it = list.begin();
963 // get the current file characteristics
964 patCurName = (*it)->GetEntryValue(0x0010,0x0010);
965 patCurID = (*it)->GetEntryValue(0x0010,0x0011);
966 studCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000d);
967 studCurID = (*it)->GetEntryValue(0x0020,0x0010);
968 serCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000e);
969 serCurID = (*it)->GetEntryValue(0x0020,0x0011);
971 if ( patCurName != patPrevName || patCurID != patPrevID || first )
973 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
977 // if new Study, deal with 'STUDY' Elements
978 if ( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID
981 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
985 // if new Serie, deal with 'SERIE' Elements
986 if ( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
989 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
992 // Always Deal with 'IMAGE' Elements
993 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
995 patPrevName = patCurName;
996 patPrevID = patCurID;
997 studPrevInstanceUID = studCurInstanceUID;
998 studPrevID = studCurID;
999 serPrevInstanceUID = serCurInstanceUID;
1000 serPrevID = serCurID;
1006 * \brief adds to the HTable
1007 * the Entries (Dicom Elements) corresponding to the given type
1008 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
1009 * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
1010 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
1011 * @param header Header of the current file
1013 void DicomDir::SetElement(std::string const &path, DicomDirType type,
1016 ListDicomDirElem elemList;
1017 ListDicomDirElem::const_iterator it;
1018 uint16_t tmpGr, tmpEl;
1019 DictEntry *dictEntry;
1026 case GDCM_DICOMDIR_IMAGE:
1027 elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
1028 si = new DicomDirImage(true);
1029 if ( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
1032 gdcmErrorMacro( "Add ImageToEnd failed");
1035 case GDCM_DICOMDIR_SERIE:
1036 elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
1037 si = new DicomDirSerie(true);
1038 if ( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
1041 gdcmErrorMacro( "Add SerieToEnd failed");
1044 case GDCM_DICOMDIR_STUDY:
1045 elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
1046 si = new DicomDirStudy(true);
1047 if ( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
1050 gdcmErrorMacro( "Add StudyToEnd failed");
1053 case GDCM_DICOMDIR_PATIENT:
1054 elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
1055 si = new DicomDirPatient(true);
1056 if ( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
1059 gdcmErrorMacro( "Add PatientToEnd failed");
1062 case GDCM_DICOMDIR_META:
1063 elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
1064 si = new DicomDirMeta(true);
1068 gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
1070 MetaElems = static_cast<DicomDirMeta *>(si);
1075 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
1076 // to avoid further troubles
1077 // imageElem 0008 1140 "" // Referenced Image Sequence
1078 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
1079 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
1080 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
1081 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
1083 // FIXME : troubles found when it's a SeqEntry
1085 // for all the relevant elements found in their own spot of the DicomDir.dic
1086 for( it = elemList.begin(); it != elemList.end(); ++it)
1090 dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
1092 entry = new ValEntry( dictEntry ); // Be sure it's never a BinEntry !
1094 entry->SetOffset(0); // just to avoid further missprinting
1098 // NULL when we Build Up (ex nihilo) a DICOMDIR
1099 // or when we add the META elems
1100 val = header->GetEntryValue(tmpGr, tmpEl);
1107 if ( val == GDCM_UNFOUND)
1109 if ( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
1111 // force to the *end* File Name
1112 val = Util::GetName( path );
1114 else if ( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
1116 if ( header->GetFileName().substr(0, path.length()) != path )
1118 gdcmWarningMacro( "The base path of file name is incorrect");
1119 val = header->GetFileName();
1123 val = &(header->GetFileName().c_str()[path.length()]);
1133 if ( header->GetEntryLength(tmpGr,tmpEl) == 0 )
1137 entry->SetValue( val ); // troubles expected when vr=SQ ...
1139 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
1141 gdcmWarningMacro("GDCM_DICOMDIR_META ?!? should never print that");
1143 si->AddEntry(entry);
1148 * \brief Move the content of the source SQItem to the destination SQItem
1149 * Only DocEntry's are moved
1150 * @param dst destination SQItem
1151 * @param src source SQItem
1153 void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src)
1157 entry = src->GetFirstEntry();
1160 src->RemoveEntryNoDestroy(entry);
1161 dst->AddEntry(entry);
1162 // we destroyed -> the current iterator is not longer valid
1163 entry = src->GetFirstEntry();
1168 * \brief compares two files
1170 bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
1172 return *header1 < *header2;
1175 //-----------------------------------------------------------------------------
1178 * \brief Canonical Printer
1179 * @param os ostream we want to print in
1180 * @param indent Indentation string to be prepended during printing
1182 void DicomDir::Print(std::ostream &os, std::string const & )
1186 MetaElems->SetPrintLevel(PrintLevel);
1187 MetaElems->Print(os);
1189 for(ListDicomDirPatient::iterator cc = Patients.begin();
1190 cc != Patients.end();
1193 (*cc)->SetPrintLevel(PrintLevel);
1198 //-----------------------------------------------------------------------------
1199 } // end namespace gdcm