1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2005/10/21 16:02:01 $
7 Version: $Revision: 1.164 $
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 "gdcmDataEntry.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 (LD_ALL); // concerns only dicom files
152 SetFileName( fileName );
158 * \brief Canonical destructor
160 DicomDir::~DicomDir()
162 SetStartMethod(NULL,NULL,NULL);
163 SetProgressMethod(NULL,NULL,NULL);
164 SetEndMethod(NULL,NULL,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( )
186 if ( ! this->Document::Load( ) )
189 return DoTheLoadingJob( );
192 #ifndef GDCM_LEGACY_REMOVE
194 * \ brief Loader. (DEPRECATED : kept not to break the API)
195 * @ param fileName file to be open for parsing
196 * @ return false if file cannot be open or no swap info was found,
197 * or no tag was found.
198 * @ deprecated use SetFileName(n) + Load() instead
200 bool DicomDir::Load(std::string const &fileName )
202 SetFileName(fileName);
206 /// DEPRECATED : use SetDirectoryName(dname) instead
208 * \brief Loader. (DEPRECATED : kept not to break the API)
209 * @param paseDir Parse Dir
210 * @deprecated use SetDirectoryName(dname) instead
212 void DicomDir::SetParseDir(bool parseDir)
219 * \brief Does the Loading Job (internal use only)
220 * @return false if file cannot be open or no swap info was found,
221 * or no tag was found.
223 bool DicomDir::DoTheLoadingJob( )
230 // Only if user passed a DICOMDIR
231 // ------------------------------
233 if (!Document::Load() )
238 if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
240 gdcmWarningMacro( "Entry HT empty for file: "<< GetFileName());
243 // Directory record sequence
244 DocEntry *e = GetDocEntry(0x0004, 0x1220);
247 gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
248 << " in file " << GetFileName());
256 // Only if user passed a root directory
257 // ------------------------------------
258 if ( GetFileName() == "." )
260 // user passed '.' as Name
261 // we get current directory name
263 getcwd(dummy, (size_t)1000);
264 SetFileName( dummy ); // will be converted into a string
267 gdcmWarningMacro( "Parse directory and create the DicomDir : "
275 * \brief This predicate, based on hopefully reasonable heuristics,
276 * decides whether or not the current document was properly parsed
277 * and contains the mandatory information for being considered as
278 * a well formed and usable DicomDir.
279 * @return true when Document is the one of a reasonable DicomDir,
282 bool DicomDir::IsReadable()
284 if ( Filetype == Unknown )
286 gdcmWarningMacro( "Wrong filetype");
291 gdcmWarningMacro( "Meta Elements missing in DicomDir");
294 if ( Patients.size() <= 0 )
296 gdcmWarningMacro( "NO Patient in DicomDir");
304 * \brief adds *the* Meta to a partially created DICOMDIR
306 DicomDirMeta *DicomDir::NewMeta()
311 DocEntry *entry = GetFirstEntry();
314 MetaElems = new DicomDirMeta(true); // true = empty
316 entry = GetFirstEntry();
319 if ( dynamic_cast<SeqEntry *>(entry) )
322 RemoveEntryNoDestroy(entry);
323 MetaElems->AddEntry(entry);
325 entry = GetFirstEntry();
328 else // after root directory parsing
330 MetaElems = new DicomDirMeta(false); // false = not empty
332 MetaElems->SetSQItemNumber(0); // To avoid further missprinting
337 * \brief adds a new Patient (with the basic elements) to a partially created
340 DicomDirPatient *DicomDir::NewPatient()
342 DicomDirPatient *p = new DicomDirPatient();
343 AddPatientToEnd( p );
348 * \brief Remove all Patients
350 void DicomDir::ClearPatient()
352 for(ListDicomDirPatient::iterator cc = Patients.begin();
362 * \brief Get the first entry while visiting the DicomDirPatients
363 * \return The first DicomDirPatient if found, otherwhise NULL
365 DicomDirPatient *DicomDir::GetFirstPatient()
367 ItPatient = Patients.begin();
368 if ( ItPatient != Patients.end() )
374 * \brief Get the next entry while visiting the DicomDirPatients
375 * \note : meaningfull only if GetFirstEntry already called
376 * \return The next DicomDirPatient if found, otherwhise NULL
378 DicomDirPatient *DicomDir::GetNextPatient()
380 gdcmAssertMacro (ItPatient != Patients.end());
383 if ( ItPatient != Patients.end() )
389 * \brief fills the whole structure, starting from a root Directory
391 void DicomDir::ParseDirectory()
393 CreateDicomDirChainedList( GetFileName() );
397 void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg )
399 SetStartMethod(method,arg,NULL);
402 void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg )
404 SetProgressMethod(method,arg,NULL);
407 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg )
409 SetEndMethod(method,arg,NULL);
413 * \brief Set the start 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::SetStartMethod( DicomDir::Method *method, void *arg,
421 DicomDir::Method *argDelete )
423 if ( StartArg && StartMethodArgDelete )
425 StartMethodArgDelete( StartArg );
428 StartMethod = method;
430 StartMethodArgDelete = argDelete;
435 * \brief Set the progress method to call when the parsing of the
437 * @param method Method to call
438 * @param arg Argument to pass to the method
439 * @param argDelete Argument
440 * \warning In python : the arg parameter isn't considered
442 void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg,
443 DicomDir::Method *argDelete )
445 if ( ProgressArg && ProgressMethodArgDelete )
447 ProgressMethodArgDelete( ProgressArg );
450 ProgressMethod = method;
452 ProgressMethodArgDelete = argDelete;
456 * \brief Set the end method to call when the parsing of the directory ends
457 * @param method Method to call
458 * @param arg Argument to pass to the method
459 * @param argDelete Argument
460 * \warning In python : the arg parameter isn't considered
462 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg,
463 DicomDir::Method *argDelete )
465 if ( EndArg && EndMethodArgDelete )
467 EndMethodArgDelete( EndArg );
472 EndMethodArgDelete = argDelete;
476 * \brief Set the method to delete the argument
477 * The argument is destroyed when the method is changed or when the
479 * @param method Method to call to delete the argument
481 void DicomDir::SetStartMethodArgDelete( DicomDir::Method *method )
483 StartMethodArgDelete = method;
487 * \brief Set the method to delete the argument
488 * The argument is destroyed when the method is changed or when the
490 * @param method Method to call to delete the argument
492 void DicomDir::SetProgressMethodArgDelete( DicomDir::Method *method )
494 ProgressMethodArgDelete = method;
498 * \brief Set the method to delete the argument
499 * The argument is destroyed when the method is changed or when
500 * the class is destroyed
501 * @param method Method to call to delete the argument
503 void DicomDir::SetEndMethodArgDelete( DicomDir::Method *method )
505 EndMethodArgDelete = method;
509 * \brief writes on disc a DICOMDIR
510 * \ warning does NOT add the missing elements in the header :
511 * it's up to the user doing it !
512 * @param fileName file to be written to
513 * @return false only when fail to open
516 bool DicomDir::Write(std::string const &fileName)
519 uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
520 uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
522 std::ofstream *fp = new std::ofstream(fileName.c_str(),
523 std::ios::out | std::ios::binary);
526 gdcmWarningMacro("Failed to open(write) File: " << fileName.c_str());
530 char filePreamble[128];
531 memset(filePreamble, 0, 128);
532 fp->write(filePreamble, 128);
533 binary_write( *fp, "DICM");
535 DicomDirMeta *ptrMeta = GetMeta();
536 ptrMeta->WriteContent(fp, ExplicitVR);
538 // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
541 binary_write(*fp, sq[i]);
544 for(ListDicomDirPatient::iterator cc = Patients.begin();
545 cc != Patients.end();
548 (*cc)->WriteContent( fp, ExplicitVR );
551 // force writing Sequence Delimitation Item
554 binary_write(*fp, sqt[i]); // fffe e0dd ffff ffff
564 * \brief Anonymize a DICOMDIR
568 bool DicomDir::Anonymize()
571 // Something clever to be found to forge the Patient names
572 std::ostringstream s;
574 for(ListDicomDirPatient::iterator cc = Patients.begin();
579 v = (*cc)->GetDataEntry(0x0010, 0x0010) ; // Patient's Name
582 v->SetString(s.str());
585 v = (*cc)->GetDataEntry(0x0010, 0x0020) ; // Patient ID
591 v = (*cc)->GetDataEntry(0x0010, 0x0030) ; // Patient's BirthDate
602 //-----------------------------------------------------------------------------
605 * \brief create a Document-like chained list from a root Directory
606 * @param path entry point of the tree-like structure
608 void DicomDir::CreateDicomDirChainedList(std::string const &path)
611 DirList dirList(path,1); // gets recursively the file list
612 unsigned int count = 0;
616 DirListType fileList = dirList.GetFilenames();
618 for( DirListType::iterator it = fileList.begin();
619 it != fileList.end();
622 Progress = (float)(count+1)/(float)fileList.size();
623 CallProgressMethod();
630 f->SetLoadMode(LoadMode); // we allow user not to load Sequences, or Shadow
632 f->SetFileName( it->c_str() );
633 /*int res = */f->Load( );
637 // gdcmWarningMacro( "Failure in new gdcm::File " << it->c_str() );
641 if ( f->IsReadable() )
643 // Add the file to the chained list:
645 gdcmWarningMacro( "Readable " << it->c_str() );
653 // sorts Patient/Study/Serie/
654 std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
656 std::string tmp = dirList.GetDirName();
657 //for each File of the chained list, add/update the Patient/Study/Serie/Image info
658 SetElements(tmp, list);
661 for(VectDocument::iterator itDoc=list.begin();
665 delete dynamic_cast<File *>(*itDoc);
670 * \brief CallStartMethod
672 void DicomDir::CallStartMethod()
678 StartMethod( StartArg );
683 * \brief CallProgressMethod
685 void DicomDir::CallProgressMethod()
687 if ( ProgressMethod )
689 ProgressMethod( ProgressArg );
694 * \brief CallEndMethod
696 void DicomDir::CallEndMethod()
705 //-----------------------------------------------------------------------------
708 * \brief Sets all fields to NULL
710 void DicomDir::Initialize()
713 ProgressMethod = NULL;
715 StartMethodArgDelete = NULL;
716 ProgressMethodArgDelete = NULL;
717 EndMethodArgDelete = NULL;
729 * \brief create a 'gdcm::DicomDir' from a DICOMDIR Header
731 void DicomDir::CreateDicomDir()
733 // The SeqEntries of "Directory Record Sequence" are parsed.
734 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
735 // 1 - we save the beginning iterator
736 // 2 - we continue to parse
737 // 3 - we find an other tag
738 // + we create the object for the precedent tag
741 // Directory record sequence
742 DocEntry *e = GetDocEntry(0x0004, 0x1220);
745 gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
749 SeqEntry *s = dynamic_cast<SeqEntry *>(e);
752 gdcmWarningMacro( "Element (0004,1220) is not a Sequence ?!?");
762 SQItem *tmpSI=s->GetFirstSQItem();
765 d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
766 if ( DataEntry *dataEntry = dynamic_cast<DataEntry *>(d) )
768 v = dataEntry->GetString();
772 gdcmWarningMacro( "(0004,1430) not a DataEntry ?!?");
776 // A decent DICOMDIR has much more images than series,
777 // more series than studies, and so on.
778 // This is the right order to preform the tests
782 si = new DicomDirImage(true);
783 if ( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
787 gdcmErrorMacro( "Add AddImageToEnd failed");
790 else if ( v == "SERIES" )
792 si = new DicomDirSerie(true);
793 if ( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
797 gdcmErrorMacro( "Add AddSerieToEnd failed");
800 else if ( v == "VISIT " )
802 si = new DicomDirVisit(true);
803 if ( !AddVisitToEnd( static_cast<DicomDirVisit *>(si)) )
807 gdcmErrorMacro( "Add AddVisitToEnd failed");
810 else if ( v == "STUDY " )
812 si = new DicomDirStudy(true);
813 if ( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
817 gdcmErrorMacro( "Add AddStudyToEnd failed");
820 else if ( v == "PATIENT " )
822 si = new DicomDirPatient(true);
823 if ( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
827 gdcmErrorMacro( "Add PatientToEnd failed");
832 // It was neither a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
833 // nor an 'IMAGE' SQItem. Skip to next item.
834 gdcmWarningMacro( " -------------------------------------------"
835 << "a non PATIENT/STUDY/SERIE/IMAGE SQItem was found : "
838 // FIXME : deal with other item types !
839 tmpSI=s->GetNextSQItem(); // To avoid infinite loop
843 si->MoveObject(tmpSI); // New code : Copies the List
845 tmpSI=s->GetNextSQItem();
851 * \brief AddPatientToEnd
852 * @param dd SQ Item to enqueue to the DicomPatient chained List
854 bool DicomDir::AddPatientToEnd(DicomDirPatient *dd)
856 Patients.push_back(dd);
861 * \brief AddStudyToEnd
862 * @param dd SQ Item to enqueue to the DicomDirStudy chained List
864 bool DicomDir::AddStudyToEnd(DicomDirStudy *dd)
866 if ( Patients.size() > 0 )
868 ListDicomDirPatient::iterator itp = Patients.end();
870 (*itp)->AddStudy(dd);
877 * \brief AddSerieToEnd
878 * @param dd SQ Item to enqueue to the DicomDirSerie chained List
880 bool DicomDir::AddSerieToEnd(DicomDirSerie *dd)
882 if ( Patients.size() > 0 )
884 ListDicomDirPatient::iterator itp = Patients.end();
887 DicomDirStudy *study = (*itp)->GetLastStudy();
898 * \brief AddVisitToEnd
899 * @param dd SQ Item to enqueue to the DicomDirVisit chained List
901 bool DicomDir::AddVisitToEnd(DicomDirVisit *dd)
903 if ( Patients.size() > 0 )
905 ListDicomDirPatient::iterator itp = Patients.end();
908 DicomDirStudy *study = (*itp)->GetLastStudy();
918 * \brief AddImageToEnd
919 * @param dd SQ Item to enqueue to the DicomDirImage chained List
921 bool DicomDir::AddImageToEnd(DicomDirImage *dd)
923 if ( Patients.size() > 0 )
925 ListDicomDirPatient::iterator itp = Patients.end();
928 DicomDirStudy *study = (*itp)->GetLastStudy();
931 DicomDirSerie *serie = study->GetLastSerie();
943 * \brief for each Header of the chained list,
944 * add/update the Patient/Study/Serie/Image info
945 * @param path path of the root directory
946 * @param list chained list of Headers
948 void DicomDir::SetElements(std::string const &path, VectDocument const &list)
953 std::string patPrevName = "", patPrevID = "";
954 std::string studPrevInstanceUID = "", studPrevID = "";
955 std::string serPrevInstanceUID = "", serPrevID = "";
957 std::string patCurName, patCurID;
958 std::string studCurInstanceUID, studCurID;
959 std::string serCurInstanceUID, serCurID;
962 for( VectDocument::const_iterator it = list.begin();
966 // get the current file characteristics
967 patCurName = (*it)->GetEntryString(0x0010,0x0010);
968 patCurID = (*it)->GetEntryString(0x0010,0x0011);
969 studCurInstanceUID = (*it)->GetEntryString(0x0020,0x000d);
970 studCurID = (*it)->GetEntryString(0x0020,0x0010);
971 serCurInstanceUID = (*it)->GetEntryString(0x0020,0x000e);
972 serCurID = (*it)->GetEntryString(0x0020,0x0011);
974 if ( patCurName != patPrevName || patCurID != patPrevID || first )
976 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
980 // if new Study, deal with 'STUDY' Elements
981 if ( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID
984 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
988 // if new Serie, deal with 'SERIE' Elements
989 if ( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
992 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
995 // Always Deal with 'IMAGE' Elements
996 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
998 patPrevName = patCurName;
999 patPrevID = patCurID;
1000 studPrevInstanceUID = studCurInstanceUID;
1001 studPrevID = studCurID;
1002 serPrevInstanceUID = serCurInstanceUID;
1003 serPrevID = serCurID;
1009 * \brief adds to the HTable
1010 * the Entries (Dicom Elements) corresponding to the given type
1011 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
1012 * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
1013 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
1014 * @param header Header of the current file
1016 void DicomDir::SetElement(std::string const &path, DicomDirType type,
1019 ListDicomDirElem elemList;
1020 ListDicomDirElem::const_iterator it;
1021 uint16_t tmpGr, tmpEl;
1022 DictEntry *dictEntry;
1029 case GDCM_DICOMDIR_IMAGE:
1030 elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
1031 si = new DicomDirImage(true);
1032 if ( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
1035 gdcmErrorMacro( "Add ImageToEnd failed");
1038 case GDCM_DICOMDIR_SERIE:
1039 elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
1040 si = new DicomDirSerie(true);
1041 if ( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
1044 gdcmErrorMacro( "Add SerieToEnd failed");
1047 case GDCM_DICOMDIR_STUDY:
1048 elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
1049 si = new DicomDirStudy(true);
1050 if ( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
1053 gdcmErrorMacro( "Add StudyToEnd failed");
1056 case GDCM_DICOMDIR_PATIENT:
1057 elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
1058 si = new DicomDirPatient(true);
1059 if ( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
1062 gdcmErrorMacro( "Add PatientToEnd failed");
1065 case GDCM_DICOMDIR_META:
1069 gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
1071 elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
1072 MetaElems = new DicomDirMeta(true);
1078 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
1079 // to avoid further troubles
1080 // imageElem 0008 1140 "" // Referenced Image Sequence
1081 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
1082 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
1083 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
1084 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
1086 // FIXME : troubles found when it's a SeqEntry
1088 // for all the relevant elements found in their own spot of the DicomDir.dic
1089 for( it = elemList.begin(); it != elemList.end(); ++it)
1093 dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
1095 entry = new DataEntry( dictEntry ); // Be sure it's never a DataEntry !
1097 entry->SetOffset(0); // just to avoid further missprinting
1101 // NULL when we Build Up (ex nihilo) a DICOMDIR
1102 // or when we add the META elems
1103 val = header->GetEntryString(tmpGr, tmpEl);
1110 if ( val == GDCM_UNFOUND)
1112 if ( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
1114 // force to the *end* File Name
1115 val = Util::GetName( path );
1117 else if ( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
1119 if ( header->GetFileName().substr(0, path.length()) != path )
1121 gdcmWarningMacro( "The base path of file name is incorrect");
1122 val = header->GetFileName();
1126 val = &(header->GetFileName().c_str()[path.length()]);
1136 if ( header->GetEntryLength(tmpGr,tmpEl) == 0 )
1140 entry->SetString( val ); // troubles expected when vr=SQ ...
1142 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
1144 gdcmWarningMacro("GDCM_DICOMDIR_META ?!? should never print that");
1146 si->AddEntry(entry);
1151 * \brief Move the content of the source SQItem to the destination SQItem
1152 * Only DocEntry's are moved
1153 * @param dst destination SQItem
1154 * @param src source SQItem
1156 void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src)
1160 entry = src->GetFirstEntry();
1163 src->RemoveEntryNoDestroy(entry);
1164 dst->AddEntry(entry);
1165 // we destroyed -> the current iterator is not longer valid
1166 entry = src->GetFirstEntry();
1171 * \brief compares two files
1173 bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
1175 return *header1 < *header2;
1178 //-----------------------------------------------------------------------------
1181 * \brief Canonical Printer
1182 * @param os ostream we want to print in
1183 * @param indent Indentation string to be prepended during printing
1185 void DicomDir::Print(std::ostream &os, std::string const & )
1189 MetaElems->SetPrintLevel(PrintLevel);
1190 MetaElems->Print(os);
1192 for(ListDicomDirPatient::iterator cc = Patients.begin();
1193 cc != Patients.end();
1196 (*cc)->SetPrintLevel(PrintLevel);
1201 //-----------------------------------------------------------------------------
1202 } // end namespace gdcm