1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2005/10/19 13:15:38 $
7 Version: $Revision: 1.161 $
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 // We should clean out anything that already exists.
203 Initialize(); // sets all private fields to NULL
207 /// DEPRECATED : use SetDirectoryName(dname) instead
209 * \brief Loader. (DEPRECATED : kept not to break the API)
210 * @param paseDir Parse Dir
211 * @deprecated use SetDirectoryName(dname) instead
213 void DicomDir::SetParseDir(bool parseDir)
220 * \brief Does the Loading Job (internal use only)
221 * @return false if file cannot be open or no swap info was found,
222 * or no tag was found.
224 bool DicomDir::DoTheLoadingJob( )
231 // Only if user passed a DICOMDIR
232 // ------------------------------
234 if (!Document::Load() )
239 if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
241 gdcmWarningMacro( "Entry HT empty for file: "<< GetFileName());
244 // Directory record sequence
245 DocEntry *e = GetDocEntry(0x0004, 0x1220);
248 gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
249 << " in file " << GetFileName());
257 // Only if user passed a root directory
258 // ------------------------------------
259 if ( GetFileName() == "." )
261 // user passed '.' as Name
262 // we get current directory name
264 getcwd(dummy, (size_t)1000);
265 SetFileName( dummy ); // will be converted into a string
268 gdcmWarningMacro( "Parse directory and create the DicomDir : "
276 * \brief This predicate, based on hopefully reasonable heuristics,
277 * decides whether or not the current document was properly parsed
278 * and contains the mandatory information for being considered as
279 * a well formed and usable DicomDir.
280 * @return true when Document is the one of a reasonable DicomDir,
283 bool DicomDir::IsReadable()
285 if ( Filetype == Unknown )
287 gdcmWarningMacro( "Wrong filetype");
292 gdcmWarningMacro( "Meta Elements missing in DicomDir");
295 if ( Patients.size() <= 0 )
297 gdcmWarningMacro( "NO Patient in DicomDir");
305 * \brief adds *the* Meta to a partially created DICOMDIR
307 DicomDirMeta *DicomDir::NewMeta()
312 DocEntry *entry = GetFirstEntry();
315 MetaElems = new DicomDirMeta(true); // true = empty
317 entry = GetFirstEntry();
320 if ( dynamic_cast<SeqEntry *>(entry) )
323 RemoveEntryNoDestroy(entry);
324 MetaElems->AddEntry(entry);
326 entry = GetFirstEntry();
329 else // after root directory parsing
331 MetaElems = new DicomDirMeta(false); // false = not empty
333 MetaElems->SetSQItemNumber(0); // To avoid further missprinting
338 * \brief adds a new Patient (with the basic elements) to a partially created
341 DicomDirPatient *DicomDir::NewPatient()
343 DicomDirPatient *p = new DicomDirPatient();
344 AddPatientToEnd( p );
349 * \brief Remove all Patients
351 void DicomDir::ClearPatient()
353 for(ListDicomDirPatient::iterator cc = Patients.begin();
363 * \brief Get the first entry while visiting the DicomDirPatients
364 * \return The first DicomDirPatient if found, otherwhise NULL
366 DicomDirPatient *DicomDir::GetFirstPatient()
368 ItPatient = Patients.begin();
369 if ( ItPatient != Patients.end() )
375 * \brief Get the next entry while visiting the DicomDirPatients
376 * \note : meaningfull only if GetFirstEntry already called
377 * \return The next DicomDirPatient if found, otherwhise NULL
379 DicomDirPatient *DicomDir::GetNextPatient()
381 gdcmAssertMacro (ItPatient != Patients.end());
384 if ( ItPatient != Patients.end() )
390 * \brief fills the whole structure, starting from a root Directory
392 void DicomDir::ParseDirectory()
394 CreateDicomDirChainedList( GetFileName() );
398 void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg )
400 SetStartMethod(method,arg,NULL);
403 void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg )
405 SetProgressMethod(method,arg,NULL);
408 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg )
410 SetEndMethod(method,arg,NULL);
414 * \brief Set the start method to call when the parsing of the
416 * @param method Method to call
417 * @param arg Argument to pass to the method
418 * @param argDelete Argument
419 * \warning In python : the arg parameter isn't considered
421 void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg,
422 DicomDir::Method *argDelete )
424 if ( StartArg && StartMethodArgDelete )
426 StartMethodArgDelete( StartArg );
429 StartMethod = method;
431 StartMethodArgDelete = argDelete;
436 * \brief Set the progress method to call when the parsing of the
438 * @param method Method to call
439 * @param arg Argument to pass to the method
440 * @param argDelete Argument
441 * \warning In python : the arg parameter isn't considered
443 void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg,
444 DicomDir::Method *argDelete )
446 if ( ProgressArg && ProgressMethodArgDelete )
448 ProgressMethodArgDelete( ProgressArg );
451 ProgressMethod = method;
453 ProgressMethodArgDelete = argDelete;
457 * \brief Set the end method to call when the parsing of the directory ends
458 * @param method Method to call
459 * @param arg Argument to pass to the method
460 * @param argDelete Argument
461 * \warning In python : the arg parameter isn't considered
463 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg,
464 DicomDir::Method *argDelete )
466 if ( EndArg && EndMethodArgDelete )
468 EndMethodArgDelete( EndArg );
473 EndMethodArgDelete = argDelete;
477 * \brief Set the method to delete the argument
478 * The argument is destroyed when the method is changed or when the
480 * @param method Method to call to delete the argument
482 void DicomDir::SetStartMethodArgDelete( DicomDir::Method *method )
484 StartMethodArgDelete = method;
488 * \brief Set the method to delete the argument
489 * The argument is destroyed when the method is changed or when the
491 * @param method Method to call to delete the argument
493 void DicomDir::SetProgressMethodArgDelete( DicomDir::Method *method )
495 ProgressMethodArgDelete = method;
499 * \brief Set the method to delete the argument
500 * The argument is destroyed when the method is changed or when
501 * the class is destroyed
502 * @param method Method to call to delete the argument
504 void DicomDir::SetEndMethodArgDelete( DicomDir::Method *method )
506 EndMethodArgDelete = method;
510 * \brief writes on disc a DICOMDIR
511 * \ warning does NOT add the missing elements in the header :
512 * it's up to the user doing it !
513 * @param fileName file to be written to
514 * @return false only when fail to open
517 bool DicomDir::Write(std::string const &fileName)
520 uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
521 uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
523 std::ofstream *fp = new std::ofstream(fileName.c_str(),
524 std::ios::out | std::ios::binary);
527 gdcmWarningMacro("Failed to open(write) File: " << fileName.c_str());
531 char filePreamble[128];
532 memset(filePreamble, 0, 128);
533 fp->write(filePreamble, 128);
534 binary_write( *fp, "DICM");
536 DicomDirMeta *ptrMeta = GetMeta();
537 ptrMeta->WriteContent(fp, ExplicitVR);
539 // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
542 binary_write(*fp, sq[i]);
545 for(ListDicomDirPatient::iterator cc = Patients.begin();
546 cc != Patients.end();
549 (*cc)->WriteContent( fp, ExplicitVR );
552 // force writing Sequence Delimitation Item
555 binary_write(*fp, sqt[i]); // fffe e0dd ffff ffff
565 * \brief Anonymize a DICOMDIR
569 bool DicomDir::Anonymize()
572 // Something clever to be found to forge the Patient names
573 std::ostringstream s;
575 for(ListDicomDirPatient::iterator cc = Patients.begin();
580 v = (*cc)->GetDataEntry(0x0010, 0x0010) ; // Patient's Name
583 v->SetString(s.str());
586 v = (*cc)->GetDataEntry(0x0010, 0x0020) ; // Patient ID
592 v = (*cc)->GetDataEntry(0x0010, 0x0030) ; // Patient's BirthDate
603 //-----------------------------------------------------------------------------
606 * \brief create a Document-like chained list from a root Directory
607 * @param path entry point of the tree-like structure
609 void DicomDir::CreateDicomDirChainedList(std::string const &path)
612 DirList dirList(path,1); // gets recursively the file list
613 unsigned int count = 0;
617 DirListType fileList = dirList.GetFilenames();
619 for( DirListType::iterator it = fileList.begin();
620 it != fileList.end();
623 Progress = (float)(count+1)/(float)fileList.size();
624 CallProgressMethod();
631 f->SetLoadMode(LoadMode); // we allow user not to load Sequences, or Shadow
633 f->SetFileName( it->c_str() );
634 /*int res = */f->Load( );
638 // gdcmWarningMacro( "Failure in new gdcm::File " << it->c_str() );
642 if ( f->IsReadable() )
644 // Add the file to the chained list:
646 gdcmWarningMacro( "Readable " << it->c_str() );
654 // sorts Patient/Study/Serie/
655 std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
657 std::string tmp = dirList.GetDirName();
658 //for each File of the chained list, add/update the Patient/Study/Serie/Image info
659 SetElements(tmp, list);
662 for(VectDocument::iterator itDoc=list.begin();
666 delete dynamic_cast<File *>(*itDoc);
671 * \brief CallStartMethod
673 void DicomDir::CallStartMethod()
679 StartMethod( StartArg );
684 * \brief CallProgressMethod
686 void DicomDir::CallProgressMethod()
688 if ( ProgressMethod )
690 ProgressMethod( ProgressArg );
695 * \brief CallEndMethod
697 void DicomDir::CallEndMethod()
706 //-----------------------------------------------------------------------------
709 * \brief Sets all fields to NULL
711 void DicomDir::Initialize()
714 ProgressMethod = NULL;
716 StartMethodArgDelete = NULL;
717 ProgressMethodArgDelete = NULL;
718 EndMethodArgDelete = NULL;
730 * \brief create a 'gdcm::DicomDir' from a DICOMDIR Header
732 void DicomDir::CreateDicomDir()
734 // The SeqEntries of "Directory Record Sequence" are parsed.
735 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
736 // 1 - we save the beginning iterator
737 // 2 - we continue to parse
738 // 3 - we find an other tag
739 // + we create the object for the precedent tag
742 // Directory record sequence
743 DocEntry *e = GetDocEntry(0x0004, 0x1220);
746 gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
750 SeqEntry *s = dynamic_cast<SeqEntry *>(e);
753 gdcmWarningMacro( "Element (0004,1220) is not a Sequence ?!?");
763 SQItem *tmpSI=s->GetFirstSQItem();
766 d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
767 if ( DataEntry *dataEntry = dynamic_cast<DataEntry *>(d) )
769 v = dataEntry->GetString();
773 gdcmWarningMacro( "(0004,1430) not a DataEntry ?!?");
777 // A decent DICOMDIR has much more images than series,
778 // more series than studies, and so on.
779 // This is the right order to preform the tests
783 si = new DicomDirImage(true);
784 if ( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
788 gdcmErrorMacro( "Add AddImageToEnd failed");
791 else if ( v == "SERIES" )
793 si = new DicomDirSerie(true);
794 if ( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
798 gdcmErrorMacro( "Add AddSerieToEnd failed");
801 else if ( v == "VISIT " )
803 si = new DicomDirVisit(true);
804 if ( !AddVisitToEnd( static_cast<DicomDirVisit *>(si)) )
808 gdcmErrorMacro( "Add AddVisitToEnd failed");
811 else if ( v == "STUDY " )
813 si = new DicomDirStudy(true);
814 if ( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
818 gdcmErrorMacro( "Add AddStudyToEnd failed");
821 else if ( v == "PATIENT " )
823 si = new DicomDirPatient(true);
824 if ( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
828 gdcmErrorMacro( "Add PatientToEnd failed");
833 // It was neither a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
834 // nor an 'IMAGE' SQItem. Skip to next item.
835 gdcmWarningMacro( " -------------------------------------------"
836 << "a non PATIENT/STUDY/SERIE/IMAGE SQItem was found : "
839 // FIXME : deal with other item types !
840 tmpSI=s->GetNextSQItem(); // To avoid infinite loop
844 si->MoveObject(tmpSI); // New code : Copies the List
846 tmpSI=s->GetNextSQItem();
852 * \brief AddPatientToEnd
853 * @param dd SQ Item to enqueue to the DicomPatient chained List
855 bool DicomDir::AddPatientToEnd(DicomDirPatient *dd)
857 Patients.push_back(dd);
862 * \brief AddStudyToEnd
863 * @param dd SQ Item to enqueue to the DicomDirStudy chained List
865 bool DicomDir::AddStudyToEnd(DicomDirStudy *dd)
867 if ( Patients.size() > 0 )
869 ListDicomDirPatient::iterator itp = Patients.end();
871 (*itp)->AddStudy(dd);
878 * \brief AddSerieToEnd
879 * @param dd SQ Item to enqueue to the DicomDirSerie chained List
881 bool DicomDir::AddSerieToEnd(DicomDirSerie *dd)
883 if ( Patients.size() > 0 )
885 ListDicomDirPatient::iterator itp = Patients.end();
888 DicomDirStudy *study = (*itp)->GetLastStudy();
899 * \brief AddVisitToEnd
900 * @param dd SQ Item to enqueue to the DicomDirVisit chained List
902 bool DicomDir::AddVisitToEnd(DicomDirVisit *dd)
904 if ( Patients.size() > 0 )
906 ListDicomDirPatient::iterator itp = Patients.end();
909 DicomDirStudy *study = (*itp)->GetLastStudy();
919 * \brief AddImageToEnd
920 * @param dd SQ Item to enqueue to the DicomDirImage chained List
922 bool DicomDir::AddImageToEnd(DicomDirImage *dd)
924 if ( Patients.size() > 0 )
926 ListDicomDirPatient::iterator itp = Patients.end();
929 DicomDirStudy *study = (*itp)->GetLastStudy();
932 DicomDirSerie *serie = study->GetLastSerie();
944 * \brief for each Header of the chained list,
945 * add/update the Patient/Study/Serie/Image info
946 * @param path path of the root directory
947 * @param list chained list of Headers
949 void DicomDir::SetElements(std::string const &path, VectDocument const &list)
954 std::string patPrevName = "", patPrevID = "";
955 std::string studPrevInstanceUID = "", studPrevID = "";
956 std::string serPrevInstanceUID = "", serPrevID = "";
958 std::string patCurName, patCurID;
959 std::string studCurInstanceUID, studCurID;
960 std::string serCurInstanceUID, serCurID;
963 for( VectDocument::const_iterator it = list.begin();
967 // get the current file characteristics
968 patCurName = (*it)->GetEntryString(0x0010,0x0010);
969 patCurID = (*it)->GetEntryString(0x0010,0x0011);
970 studCurInstanceUID = (*it)->GetEntryString(0x0020,0x000d);
971 studCurID = (*it)->GetEntryString(0x0020,0x0010);
972 serCurInstanceUID = (*it)->GetEntryString(0x0020,0x000e);
973 serCurID = (*it)->GetEntryString(0x0020,0x0011);
975 if ( patCurName != patPrevName || patCurID != patPrevID || first )
977 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
981 // if new Study, deal with 'STUDY' Elements
982 if ( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID
985 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
989 // if new Serie, deal with 'SERIE' Elements
990 if ( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
993 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
996 // Always Deal with 'IMAGE' Elements
997 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
999 patPrevName = patCurName;
1000 patPrevID = patCurID;
1001 studPrevInstanceUID = studCurInstanceUID;
1002 studPrevID = studCurID;
1003 serPrevInstanceUID = serCurInstanceUID;
1004 serPrevID = serCurID;
1010 * \brief adds to the HTable
1011 * the Entries (Dicom Elements) corresponding to the given type
1012 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
1013 * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
1014 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
1015 * @param header Header of the current file
1017 void DicomDir::SetElement(std::string const &path, DicomDirType type,
1020 ListDicomDirElem elemList;
1021 ListDicomDirElem::const_iterator it;
1022 uint16_t tmpGr, tmpEl;
1023 DictEntry *dictEntry;
1030 case GDCM_DICOMDIR_IMAGE:
1031 elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
1032 si = new DicomDirImage(true);
1033 if ( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
1036 gdcmErrorMacro( "Add ImageToEnd failed");
1039 case GDCM_DICOMDIR_SERIE:
1040 elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
1041 si = new DicomDirSerie(true);
1042 if ( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
1045 gdcmErrorMacro( "Add SerieToEnd failed");
1048 case GDCM_DICOMDIR_STUDY:
1049 elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
1050 si = new DicomDirStudy(true);
1051 if ( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
1054 gdcmErrorMacro( "Add StudyToEnd failed");
1057 case GDCM_DICOMDIR_PATIENT:
1058 elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
1059 si = new DicomDirPatient(true);
1060 if ( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
1063 gdcmErrorMacro( "Add PatientToEnd failed");
1066 case GDCM_DICOMDIR_META:
1070 gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
1072 elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
1073 MetaElems = new DicomDirMeta(true);
1079 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
1080 // to avoid further troubles
1081 // imageElem 0008 1140 "" // Referenced Image Sequence
1082 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
1083 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
1084 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
1085 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
1087 // FIXME : troubles found when it's a SeqEntry
1089 // for all the relevant elements found in their own spot of the DicomDir.dic
1090 for( it = elemList.begin(); it != elemList.end(); ++it)
1094 dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
1096 entry = new DataEntry( dictEntry ); // Be sure it's never a DataEntry !
1098 entry->SetOffset(0); // just to avoid further missprinting
1102 // NULL when we Build Up (ex nihilo) a DICOMDIR
1103 // or when we add the META elems
1104 val = header->GetEntryString(tmpGr, tmpEl);
1111 if ( val == GDCM_UNFOUND)
1113 if ( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
1115 // force to the *end* File Name
1116 val = Util::GetName( path );
1118 else if ( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
1120 if ( header->GetFileName().substr(0, path.length()) != path )
1122 gdcmWarningMacro( "The base path of file name is incorrect");
1123 val = header->GetFileName();
1127 val = &(header->GetFileName().c_str()[path.length()]);
1137 if ( header->GetEntryLength(tmpGr,tmpEl) == 0 )
1141 entry->SetString( val ); // troubles expected when vr=SQ ...
1143 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
1145 gdcmWarningMacro("GDCM_DICOMDIR_META ?!? should never print that");
1147 si->AddEntry(entry);
1152 * \brief Move the content of the source SQItem to the destination SQItem
1153 * Only DocEntry's are moved
1154 * @param dst destination SQItem
1155 * @param src source SQItem
1157 void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src)
1161 entry = src->GetFirstEntry();
1164 src->RemoveEntryNoDestroy(entry);
1165 dst->AddEntry(entry);
1166 // we destroyed -> the current iterator is not longer valid
1167 entry = src->GetFirstEntry();
1172 * \brief compares two files
1174 bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
1176 return *header1 < *header2;
1179 //-----------------------------------------------------------------------------
1182 * \brief Canonical Printer
1183 * @param os ostream we want to print in
1184 * @param indent Indentation string to be prepended during printing
1186 void DicomDir::Print(std::ostream &os, std::string const & )
1190 MetaElems->SetPrintLevel(PrintLevel);
1191 MetaElems->Print(os);
1193 for(ListDicomDirPatient::iterator cc = Patients.begin();
1194 cc != Patients.end();
1197 (*cc)->SetPrintLevel(PrintLevel);
1202 //-----------------------------------------------------------------------------
1203 } // end namespace gdcm