1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2005/07/12 17:08:12 $
7 Version: $Revision: 1.148 $
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
127 * \brief Constructor Parses recursively the directory and creates the DicomDir
128 * or uses an already built DICOMDIR, depending on 'parseDir' value.
129 * @param fileName name
130 * - of the root directory (parseDir = true)
131 * - of the DICOMDIR (parseDir = false)
132 * @param parseDir boolean
133 * - true if user passed an entry point
134 * and wants to explore recursively the directories
135 * - false if user passed an already built DICOMDIR file
136 * and wants to use it
138 DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
141 // At this step, Document constructor is already executed,
142 // whatever user passed (either a root directory or a DICOMDIR)
143 // and whatever the value of parseDir was.
144 // (nothing is cheked in Document constructor, to avoid overhead)
147 SetLoadMode (0x00000000); // concerns only dicom files
152 * \brief Canonical destructor
154 DicomDir::~DicomDir()
156 SetStartMethod(NULL);
157 SetProgressMethod(NULL);
167 //-----------------------------------------------------------------------------
171 * \brief Loader. use SetLoadMode(), SetFileName() before !
172 * @return false if file cannot be open or no swap info was found,
173 * or no tag was found.
175 bool DicomDir::Load( )
177 // We should clean out anything that already exists.
178 Initialize(); // sets all private fields to NULL
182 if ( ! this->Document::Load( ) )
185 return DoTheLoadingJob( );
189 * \brief Loader. (DEPRECATED : not to break the API)
190 * @param fileName file to be open for parsing
191 * @return false if file cannot be open or no swap info was found,
192 * or no tag was found.
194 bool DicomDir::Load(std::string const &fileName )
196 // We should clean out anything that already exists.
197 Initialize(); // sets all private fields to NULL
199 SetFileName( fileName );
202 if ( ! this->Document::Load( ) )
205 return DoTheLoadingJob( );
209 * \brief Does the Loading Job (internal use only)
210 * @return false if file cannot be open or no swap info was found,
211 * or no tag was found.
213 bool DicomDir::DoTheLoadingJob( )
215 // We should clean out anything that already exists.
216 Initialize(); // sets all private fields to NULL
220 // Only if user passed a DICOMDIR
221 // ------------------------------
227 if (!Document::Load() )
232 if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
234 gdcmWarningMacro( "Entry HT empty for file: "<< GetFileName());
237 // Directory record sequence
238 DocEntry *e = GetDocEntry(0x0004, 0x1220);
241 gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
242 << " in file " << GetFileName());
250 // Only if user passed a root directory
251 // ------------------------------------
252 if ( GetFileName() == "." )
254 // user passed '.' as Name
255 // we get current directory name
257 getcwd(dummy, (size_t)1000);
258 SetFileName( dummy ); // will be converted into a string
261 gdcmWarningMacro( "Parse directory and create the DicomDir : "
269 * \brief This predicate, based on hopefully reasonable heuristics,
270 * decides whether or not the current document was properly parsed
271 * and contains the mandatory information for being considered as
272 * a well formed and usable DicomDir.
273 * @return true when Document is the one of a reasonable DicomDir,
276 bool DicomDir::IsReadable()
278 if ( Filetype == Unknown )
280 gdcmWarningMacro( "Wrong filetype");
285 gdcmWarningMacro( "Meta Elements missing in DicomDir");
288 if ( Patients.size() <= 0 )
290 gdcmWarningMacro( "NO Patient in DicomDir");
298 * \brief adds *the* Meta to a partially created DICOMDIR
300 DicomDirMeta *DicomDir::NewMeta()
305 DocEntry *entry = GetFirstEntry();
308 MetaElems = new DicomDirMeta(true); // true = empty
310 entry = GetFirstEntry();
313 if ( dynamic_cast<SeqEntry *>(entry) )
316 RemoveEntryNoDestroy(entry);
317 MetaElems->AddEntry(entry);
319 entry = GetFirstEntry();
322 else // after root directory parsing
324 MetaElems = new DicomDirMeta(false); // false = not empty
326 MetaElems->SetSQItemNumber(0); // To avoid further missprinting
331 * \brief adds a new Patient (with the basic elements) to a partially created
334 DicomDirPatient *DicomDir::NewPatient()
336 DicomDirPatient *p = new DicomDirPatient();
337 AddPatientToEnd( p );
342 * \brief Remove all Patients
344 void DicomDir::ClearPatient()
346 for(ListDicomDirPatient::iterator cc = Patients.begin();
356 * \brief Get the first entry while visiting the DicomDirPatients
357 * \return The first DicomDirPatient if found, otherwhise NULL
359 DicomDirPatient *DicomDir::GetFirstPatient()
361 ItPatient = Patients.begin();
362 if ( ItPatient != Patients.end() )
368 * \brief Get the next entry while visiting the DicomDirPatients
369 * \note : meaningfull only if GetFirstEntry already called
370 * \return The next DicomDirPatient if found, otherwhise NULL
372 DicomDirPatient *DicomDir::GetNextPatient()
374 gdcmAssertMacro (ItPatient != Patients.end());
377 if ( ItPatient != Patients.end() )
383 * \brief fills the whole structure, starting from a root Directory
385 void DicomDir::ParseDirectory()
387 CreateDicomDirChainedList( GetFileName() );
392 * \brief Set the start method to call when the parsing of the
394 * @param method Method to call
395 * @param arg Argument to pass to the method
396 * @param argDelete Argument
397 * \warning In python : the arg parameter isn't considered
399 void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg,
400 DicomDir::Method *argDelete )
402 if ( StartArg && StartMethodArgDelete )
404 StartMethodArgDelete( StartArg );
407 StartMethod = method;
409 StartMethodArgDelete = argDelete;
414 * \brief Set the progress 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::SetProgressMethod( DicomDir::Method *method, void *arg,
422 DicomDir::Method *argDelete )
424 if ( ProgressArg && ProgressMethodArgDelete )
426 ProgressMethodArgDelete( ProgressArg );
429 ProgressMethod = method;
431 ProgressMethodArgDelete = argDelete;
435 * \brief Set the end method to call when the parsing of the directory ends
436 * @param method Method to call
437 * @param arg Argument to pass to the method
438 * @param argDelete Argument
439 * \warning In python : the arg parameter isn't considered
441 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg,
442 DicomDir::Method *argDelete )
444 if ( EndArg && EndMethodArgDelete )
446 EndMethodArgDelete( EndArg );
451 EndMethodArgDelete = argDelete;
455 * \brief Set the method to delete the argument
456 * The argument is destroyed when the method is changed or when the
458 * @param method Method to call to delete the argument
460 void DicomDir::SetStartMethodArgDelete( DicomDir::Method *method )
462 StartMethodArgDelete = method;
466 * \brief Set the method to delete the argument
467 * The argument is destroyed when the method is changed or when the
469 * @param method Method to call to delete the argument
471 void DicomDir::SetProgressMethodArgDelete( DicomDir::Method *method )
473 ProgressMethodArgDelete = method;
477 * \brief Set the method to delete the argument
478 * The argument is destroyed when the method is changed or when
479 * the class is destroyed
480 * @param method Method to call to delete the argument
482 void DicomDir::SetEndMethodArgDelete( DicomDir::Method *method )
484 EndMethodArgDelete = method;
488 * \brief writes on disc a DICOMDIR
489 * \ warning does NOT add the missing elements in the header :
490 * it's up to the user doing it !
491 * @param fileName file to be written to
492 * @return false only when fail to open
495 bool DicomDir::WriteDicomDir(std::string const &fileName)
498 uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
499 uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
501 std::ofstream *fp = new std::ofstream(fileName.c_str(),
502 std::ios::out | std::ios::binary);
505 gdcmWarningMacro("Failed to open(write) File: " << fileName.c_str());
509 char filePreamble[128];
510 memset(filePreamble, 0, 128);
511 fp->write(filePreamble, 128);
512 binary_write( *fp, "DICM");
514 DicomDirMeta *ptrMeta = GetMeta();
515 ptrMeta->WriteContent(fp, ExplicitVR);
517 // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
520 binary_write(*fp, sq[i]);
523 for(ListDicomDirPatient::iterator cc = Patients.begin();
524 cc != Patients.end();
527 (*cc)->WriteContent( fp, ExplicitVR );
530 // force writing Sequence Delimitation Item
533 binary_write(*fp, sqt[i]); // fffe e0dd ffff ffff
543 * \brief Anonymize a DICOMDIR
547 bool DicomDir::AnonymizeDicomDir()
550 // Something clever to be found to forge the Patient names
551 std::ostringstream s;
553 for(ListDicomDirPatient::iterator cc = Patients.begin();
558 v = (*cc)->GetValEntry(0x0010, 0x0010) ; // Patient's Name
561 v->SetValue(s.str());
564 v = (*cc)->GetValEntry(0x0010, 0x0020) ; // Patient ID
570 v = (*cc)->GetValEntry(0x0010, 0x0030) ; // Patient's BirthDate
581 //-----------------------------------------------------------------------------
584 * \brief create a Document-like chained list from a root Directory
585 * @param path entry point of the tree-like structure
587 void DicomDir::CreateDicomDirChainedList(std::string const &path)
590 DirList dirList(path,1); // gets recursively the file list
591 unsigned int count = 0;
595 DirListType fileList = dirList.GetFilenames();
597 for( DirListType::iterator it = fileList.begin();
598 it != fileList.end();
601 Progress = (float)(count+1)/(float)fileList.size();
602 CallProgressMethod();
609 f->SetLoadMode(LoadMode); // we allow user not to load Sequences, or Shadow
611 f->Load( it->c_str() );
615 // gdcmWarningMacro( "Failure in new gdcm::File " << it->c_str() );
619 if ( f->IsReadable() )
621 // Add the file to the chained list:
623 gdcmWarningMacro( "Readable " << it->c_str() );
631 // sorts Patient/Study/Serie/
632 std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
634 std::string tmp = dirList.GetDirName();
635 //for each File of the chained list, add/update the Patient/Study/Serie/Image info
636 SetElements(tmp, list);
639 for(VectDocument::iterator itDoc=list.begin();
643 delete dynamic_cast<File *>(*itDoc);
648 * \brief CallStartMethod
650 void DicomDir::CallStartMethod()
656 StartMethod( StartArg );
661 * \brief CallProgressMethod
663 void DicomDir::CallProgressMethod()
665 if ( ProgressMethod )
667 ProgressMethod( ProgressArg );
672 * \brief CallEndMethod
674 void DicomDir::CallEndMethod()
683 //-----------------------------------------------------------------------------
686 * \brief Sets all fields to NULL
688 void DicomDir::Initialize()
691 ProgressMethod = NULL;
693 StartMethodArgDelete = NULL;
694 ProgressMethodArgDelete = NULL;
695 EndMethodArgDelete = NULL;
707 * \brief create a 'gdcm::DicomDir' from a DICOMDIR Header
709 void DicomDir::CreateDicomDir()
711 // The SeqEntries of "Directory Record Sequence" are parsed.
712 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
713 // 1 - we save the beginning iterator
714 // 2 - we continue to parse
715 // 3 - we find an other tag
716 // + we create the object for the precedent tag
719 // Directory record sequence
720 DocEntry *e = GetDocEntry(0x0004, 0x1220);
723 gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
727 SeqEntry *s = dynamic_cast<SeqEntry *>(e);
730 gdcmWarningMacro( "Element (0004,1220) is not a Sequence ?!?");
740 SQItem *tmpSI=s->GetFirstSQItem();
743 d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
744 if ( ValEntry* valEntry = dynamic_cast<ValEntry *>(d) )
746 v = valEntry->GetValue();
750 gdcmWarningMacro( "(0004,1430) not a ValEntry ?!?");
754 // A decent DICOMDIR has much more images than series,
755 // more series than studies, and so on.
756 // This is the right order to preform the tests
760 si = new DicomDirImage(true);
761 if ( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
765 gdcmErrorMacro( "Add AddImageToEnd failed");
768 else if ( v == "SERIES" )
770 si = new DicomDirSerie(true);
771 if ( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
775 gdcmErrorMacro( "Add AddSerieToEnd failed");
778 else if ( v == "VISIT " )
780 si = new DicomDirVisit(true);
781 if ( !AddVisitToEnd( static_cast<DicomDirVisit *>(si)) )
785 gdcmErrorMacro( "Add AddVisitToEnd failed");
788 else if ( v == "STUDY " )
790 si = new DicomDirStudy(true);
791 if ( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
795 gdcmErrorMacro( "Add AddStudyToEnd failed");
798 else if ( v == "PATIENT " )
800 si = new DicomDirPatient(true);
801 if ( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
805 gdcmErrorMacro( "Add PatientToEnd failed");
810 // It was neither a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
811 // nor an 'IMAGE' SQItem. Skip to next item.
812 gdcmWarningMacro( " -------------------------------------------"
813 << "a non PATIENT/STUDY/SERIE/IMAGE SQItem was found : "
816 // FIXME : deal with other item types !
817 tmpSI=s->GetNextSQItem(); // To avoid infinite loop
821 //MoveSQItem(si,tmpSI); // Old code : Copies each Entry
822 // -and then removes the source-
823 si->MoveObject(tmpSI); // New code : Copies the List
825 tmpSI=s->GetNextSQItem();
831 * \brief AddPatientToEnd
832 * @param dd SQ Item to enqueue to the DicomPatient chained List
834 bool DicomDir::AddPatientToEnd(DicomDirPatient *dd)
836 Patients.push_back(dd);
841 * \brief AddStudyToEnd
842 * @param dd SQ Item to enqueue to the DicomDirStudy chained List
844 bool DicomDir::AddStudyToEnd(DicomDirStudy *dd)
846 if ( Patients.size() > 0 )
848 ListDicomDirPatient::iterator itp = Patients.end();
850 (*itp)->AddStudy(dd);
857 * \brief AddSerieToEnd
858 * @param dd SQ Item to enqueue to the DicomDirSerie chained List
860 bool DicomDir::AddSerieToEnd(DicomDirSerie *dd)
862 if ( Patients.size() > 0 )
864 ListDicomDirPatient::iterator itp = Patients.end();
867 DicomDirStudy *study = (*itp)->GetLastStudy();
878 * \brief AddVisitToEnd
879 * @param dd SQ Item to enqueue to the DicomDirVisit chained List
881 bool DicomDir::AddVisitToEnd(DicomDirVisit *dd)
883 if ( Patients.size() > 0 )
885 ListDicomDirPatient::iterator itp = Patients.end();
888 DicomDirStudy *study = (*itp)->GetLastStudy();
898 * \brief AddImageToEnd
899 * @param dd SQ Item to enqueue to the DicomDirImage chained List
901 bool DicomDir::AddImageToEnd(DicomDirImage *dd)
903 if ( Patients.size() > 0 )
905 ListDicomDirPatient::iterator itp = Patients.end();
908 DicomDirStudy *study = (*itp)->GetLastStudy();
911 DicomDirSerie *serie = study->GetLastSerie();
923 * \brief for each Header of the chained list,
924 * add/update the Patient/Study/Serie/Image info
925 * @param path path of the root directory
926 * @param list chained list of Headers
928 void DicomDir::SetElements(std::string const &path, VectDocument const &list)
933 std::string patPrevName = "", patPrevID = "";
934 std::string studPrevInstanceUID = "", studPrevID = "";
935 std::string serPrevInstanceUID = "", serPrevID = "";
937 std::string patCurName, patCurID;
938 std::string studCurInstanceUID, studCurID;
939 std::string serCurInstanceUID, serCurID;
942 for( VectDocument::const_iterator it = list.begin();
946 // get the current file characteristics
947 patCurName = (*it)->GetEntryValue(0x0010,0x0010);
948 patCurID = (*it)->GetEntryValue(0x0010,0x0011);
949 studCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000d);
950 studCurID = (*it)->GetEntryValue(0x0020,0x0010);
951 serCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000e);
952 serCurID = (*it)->GetEntryValue(0x0020,0x0011);
954 if ( patCurName != patPrevName || patCurID != patPrevID || first )
956 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
960 // if new Study, deal with 'STUDY' Elements
961 if ( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID
964 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
968 // if new Serie, deal with 'SERIE' Elements
969 if ( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
972 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
975 // Always Deal with 'IMAGE' Elements
976 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
978 patPrevName = patCurName;
979 patPrevID = patCurID;
980 studPrevInstanceUID = studCurInstanceUID;
981 studPrevID = studCurID;
982 serPrevInstanceUID = serCurInstanceUID;
983 serPrevID = serCurID;
989 * \brief adds to the HTable
990 * the Entries (Dicom Elements) corresponding to the given type
991 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
992 * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
993 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
994 * @param header Header of the current file
996 void DicomDir::SetElement(std::string const &path, DicomDirType type,
999 ListDicomDirElem elemList;
1000 ListDicomDirElem::const_iterator it;
1001 uint16_t tmpGr, tmpEl;
1002 DictEntry *dictEntry;
1009 case GDCM_DICOMDIR_IMAGE:
1010 elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
1011 si = new DicomDirImage(true);
1012 if ( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
1015 gdcmErrorMacro( "Add ImageToEnd failed");
1018 case GDCM_DICOMDIR_SERIE:
1019 elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
1020 si = new DicomDirSerie(true);
1021 if ( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
1024 gdcmErrorMacro( "Add SerieToEnd failed");
1027 case GDCM_DICOMDIR_STUDY:
1028 elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
1029 si = new DicomDirStudy(true);
1030 if ( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
1033 gdcmErrorMacro( "Add StudyToEnd failed");
1036 case GDCM_DICOMDIR_PATIENT:
1037 elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
1038 si = new DicomDirPatient(true);
1039 if ( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
1042 gdcmErrorMacro( "Add PatientToEnd failed");
1045 case GDCM_DICOMDIR_META:
1046 elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
1047 si = new DicomDirMeta(true);
1051 gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
1053 MetaElems = static_cast<DicomDirMeta *>(si);
1058 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
1059 // to avoid further troubles
1060 // imageElem 0008 1140 "" // Referenced Image Sequence
1061 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
1062 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
1063 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
1064 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
1066 // FIXME : troubles found when it's a SeqEntry
1068 // for all the relevant elements found in their own spot of the DicomDir.dic
1069 for( it = elemList.begin(); it != elemList.end(); ++it)
1073 dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
1075 entry = new ValEntry( dictEntry ); // Be sure it's never a BinEntry !
1077 entry->SetOffset(0); // just to avoid further missprinting
1081 // NULL when we Build Up (ex nihilo) a DICOMDIR
1082 // or when we add the META elems
1083 val = header->GetEntryValue(tmpGr, tmpEl);
1090 if ( val == GDCM_UNFOUND)
1092 if ( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
1094 // force to the *end* File Name
1095 val = Util::GetName( path );
1097 else if ( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
1099 if ( header->GetFileName().substr(0, path.length()) != path )
1101 gdcmWarningMacro( "The base path of file name is incorrect");
1102 val = header->GetFileName();
1106 val = &(header->GetFileName().c_str()[path.length()]);
1116 if ( header->GetEntryLength(tmpGr,tmpEl) == 0 )
1120 entry->SetValue( val ); // troubles expected when vr=SQ ...
1122 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
1124 gdcmWarningMacro("GDCM_DICOMDIR_META ?!? should never print that");
1126 si->AddEntry(entry);
1131 * \brief Move the content of the source SQItem to the destination SQItem
1132 * Only DocEntry's are moved
1133 * @param dst destination SQItem
1134 * @param src source SQItem
1136 void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src)
1140 entry = src->GetFirstEntry();
1143 src->RemoveEntryNoDestroy(entry);
1144 dst->AddEntry(entry);
1145 // we destroyed -> the current iterator is not longer valid
1146 entry = src->GetFirstEntry();
1151 * \brief compares two files
1153 bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
1155 return *header1 < *header2;
1158 //-----------------------------------------------------------------------------
1161 * \brief Canonical Printer
1162 * @param os ostream we want to print in
1163 * @param indent Indentation string to be prepended during printing
1165 void DicomDir::Print(std::ostream &os, std::string const & )
1169 MetaElems->SetPrintLevel(PrintLevel);
1170 MetaElems->Print(os);
1172 for(ListDicomDirPatient::iterator cc = Patients.begin();
1173 cc != Patients.end();
1176 (*cc)->SetPrintLevel(PrintLevel);
1181 //-----------------------------------------------------------------------------
1182 } // end namespace gdcm