1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2005/11/07 10:14:44 $
7 Version: $Revision: 1.172 $
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
128 * \brief Canonical destructor
130 DicomDir::~DicomDir()
132 SetStartMethod(NULL,NULL,NULL);
133 SetProgressMethod(NULL,NULL,NULL);
134 SetEndMethod(NULL,NULL,NULL);
143 //-----------------------------------------------------------------------------
147 * \brief Loader. use SetFileName(fn)
148 * or SetLoadMode(lm) + SetDirectoryName(dn) before !
149 * @return false if file cannot be open or no swap info was found,
150 * or no tag was found.
152 bool DicomDir::Load( )
156 if ( ! this->Document::Load( ) )
159 return DoTheLoadingJob( );
162 #ifndef GDCM_LEGACY_REMOVE
164 * \ brief Loader. (DEPRECATED : kept not to break the API)
165 * @ param fileName file to be open for parsing
166 * @ return false if file cannot be open or no swap info was found,
167 * or no tag was found.
168 * @ deprecated use SetFileName(n) + Load() instead
170 bool DicomDir::Load(std::string const &fileName )
172 SetFileName(fileName);
176 /// DEPRECATED : use SetDirectoryName(dname) instead
178 * \brief Loader. (DEPRECATED : kept not to break the API)
179 * @param paseDir Parse Dir
180 * @deprecated use SetDirectoryName(dname) instead
182 void DicomDir::SetParseDir(bool parseDir)
189 * \brief Does the Loading Job (internal use only)
190 * @return false if file cannot be open or no swap info was found,
191 * or no tag was found.
193 bool DicomDir::DoTheLoadingJob( )
200 // Only if user passed a DICOMDIR
201 // ------------------------------
203 if (!Document::Load() )
208 if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
210 gdcmWarningMacro( "Entry HT empty for file: "<< GetFileName());
213 // Directory record sequence
214 DocEntry *e = GetDocEntry(0x0004, 0x1220);
217 gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
218 << " in file " << GetFileName());
226 // Only if user passed a root directory
227 // ------------------------------------
228 if ( GetFileName() == "." )
230 // user passed '.' as Name
231 // we get current directory name
233 const char *cwd = getcwd(buf, 2048);
236 SetFileName( buf ); // will be converted into a string
240 gdcmErrorMacro( "Path was too long to fit on 2048 bytes" );
244 gdcmDebugMacro( "Parse directory and create the DicomDir : "
252 * \brief This predicate, based on hopefully reasonable heuristics,
253 * decides whether or not the current document was properly parsed
254 * and contains the mandatory information for being considered as
255 * a well formed and usable DicomDir.
256 * @return true when Document is the one of a reasonable DicomDir,
259 bool DicomDir::IsReadable()
261 if ( Filetype == Unknown )
263 gdcmErrorMacro( "Wrong filetype for " << GetFileName());
268 gdcmWarningMacro( "Meta Elements missing in DicomDir");
271 if ( Patients.size() <= 0 )
273 gdcmWarningMacro( "NO Patient in DicomDir");
281 * \brief adds *the* Meta to a partially created DICOMDIR
283 DicomDirMeta *DicomDir::NewMeta()
288 DocEntry *entry = GetFirstEntry();
291 MetaElems = DicomDirMeta::New(true); // true = empty
293 entry = GetFirstEntry();
296 if ( dynamic_cast<SeqEntry *>(entry) )
299 MetaElems->AddEntry(entry);
302 entry = GetFirstEntry();
305 else // after root directory parsing
307 MetaElems = DicomDirMeta::New(false); // false = not empty
309 MetaElems->SetSQItemNumber(0); // To avoid further missprinting
314 * \brief adds a new Patient (with the basic elements) to a partially created
317 DicomDirPatient *DicomDir::NewPatient()
319 DicomDirPatient *dd = DicomDirPatient::New();
320 AddPatientToEnd( dd );
325 * \brief Remove all Patients
327 void DicomDir::ClearPatient()
329 for(ListDicomDirPatient::iterator cc = Patients.begin();
339 * \brief Get the first entry while visiting the DicomDirPatients
340 * \return The first DicomDirPatient if found, otherwhise NULL
342 DicomDirPatient *DicomDir::GetFirstPatient()
344 ItPatient = Patients.begin();
345 if ( ItPatient != Patients.end() )
351 * \brief Get the next entry while visiting the DicomDirPatients
352 * \note : meaningfull only if GetFirstEntry already called
353 * \return The next DicomDirPatient if found, otherwhise NULL
355 DicomDirPatient *DicomDir::GetNextPatient()
357 gdcmAssertMacro (ItPatient != Patients.end());
360 if ( ItPatient != Patients.end() )
366 * \brief fills the whole structure, starting from a root Directory
368 void DicomDir::ParseDirectory()
370 CreateDicomDirChainedList( GetFileName() );
374 void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg )
376 SetStartMethod(method,arg,NULL);
379 void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg )
381 SetProgressMethod(method,arg,NULL);
384 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg )
386 SetEndMethod(method,arg,NULL);
390 * \brief Set the start method to call when the parsing of the
392 * @param method Method to call
393 * @param arg Argument to pass to the method
394 * @param argDelete Argument
395 * \warning In python : the arg parameter isn't considered
397 void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg,
398 DicomDir::Method *argDelete )
400 if ( StartArg && StartMethodArgDelete )
402 StartMethodArgDelete( StartArg );
405 StartMethod = method;
407 StartMethodArgDelete = argDelete;
412 * \brief Set the progress method to call when the parsing of the
414 * @param method Method to call
415 * @param arg Argument to pass to the method
416 * @param argDelete Argument
417 * \warning In python : the arg parameter isn't considered
419 void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg,
420 DicomDir::Method *argDelete )
422 if ( ProgressArg && ProgressMethodArgDelete )
424 ProgressMethodArgDelete( ProgressArg );
427 ProgressMethod = method;
429 ProgressMethodArgDelete = argDelete;
433 * \brief Set the end method to call when the parsing of the directory ends
434 * @param method Method to call
435 * @param arg Argument to pass to the method
436 * @param argDelete Argument
437 * \warning In python : the arg parameter isn't considered
439 void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg,
440 DicomDir::Method *argDelete )
442 if ( EndArg && EndMethodArgDelete )
444 EndMethodArgDelete( EndArg );
449 EndMethodArgDelete = argDelete;
453 * \brief Set the method to delete the argument
454 * The argument is destroyed when the method is changed or when the
456 * @param method Method to call to delete the argument
458 void DicomDir::SetStartMethodArgDelete( DicomDir::Method *method )
460 StartMethodArgDelete = method;
464 * \brief Set the method to delete the argument
465 * The argument is destroyed when the method is changed or when the
467 * @param method Method to call to delete the argument
469 void DicomDir::SetProgressMethodArgDelete( DicomDir::Method *method )
471 ProgressMethodArgDelete = method;
475 * \brief Set the method to delete the argument
476 * The argument is destroyed when the method is changed or when
477 * the class is destroyed
478 * @param method Method to call to delete the argument
480 void DicomDir::SetEndMethodArgDelete( DicomDir::Method *method )
482 EndMethodArgDelete = method;
486 * \brief writes on disc a DICOMDIR
487 * \ warning does NOT add the missing elements in the header :
488 * it's up to the user doing it !
489 * @param fileName file to be written to
490 * @return false only when fail to open
493 bool DicomDir::Write(std::string const &fileName)
496 uint16_t sq[6] = { 0x0004, 0x1220, 0x5153, 0x0000, 0xffff, 0xffff };
497 uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
499 std::ofstream *fp = new std::ofstream(fileName.c_str(),
500 std::ios::out | std::ios::binary);
503 gdcmWarningMacro("Failed to open(write) File: " << fileName.c_str());
507 char filePreamble[128];
508 memset(filePreamble, 0, 128);
509 fp->write(filePreamble, 128);
510 binary_write( *fp, "DICM");
512 DicomDirMeta *ptrMeta = GetMeta();
513 ptrMeta->WriteContent(fp, ExplicitVR);
515 // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
518 binary_write(*fp, sq[i]);
521 for(ListDicomDirPatient::iterator cc = Patients.begin();
522 cc != Patients.end();
525 (*cc)->WriteContent( fp, ExplicitVR );
528 // force writing Sequence Delimitation Item
531 binary_write(*fp, sqt[i]); // fffe e0dd ffff ffff
541 * \brief Anonymize a DICOMDIR
545 bool DicomDir::Anonymize()
548 // Something clever to be found to forge the Patient names
549 std::ostringstream s;
551 for(ListDicomDirPatient::iterator cc = Patients.begin();
556 v = (*cc)->GetDataEntry(0x0010, 0x0010) ; // Patient's Name
559 v->SetString(s.str());
562 v = (*cc)->GetDataEntry(0x0010, 0x0020) ; // Patient ID
568 v = (*cc)->GetDataEntry(0x0010, 0x0030) ; // Patient's BirthDate
579 //-----------------------------------------------------------------------------
582 * \brief create a Document-like chained list from a root Directory
583 * @param path entry point of the tree-like structure
585 void DicomDir::CreateDicomDirChainedList(std::string const &path)
588 DirList dirList(path,1); // gets recursively the file list
589 unsigned int count = 0;
593 DirListType fileList = dirList.GetFilenames();
595 for( DirListType::iterator it = fileList.begin();
596 it != fileList.end();
599 Progress = (float)(count+1)/(float)fileList.size();
600 CallProgressMethod();
607 f->SetLoadMode(LoadMode); // we allow user not to load Sequences,
608 // or Shadow groups, or ......
609 f->SetFileName( it->c_str() );
612 if ( f->IsReadable() )
614 // Add the file to the chained list:
616 gdcmDebugMacro( "Readable " << it->c_str() );
624 // sorts Patient/Study/Serie/
625 std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
627 std::string tmp = dirList.GetDirName();
628 //for each File of the chained list, add/update the Patient/Study/Serie/Image info
629 SetElements(tmp, list);
632 for(VectDocument::iterator itDoc=list.begin();
636 dynamic_cast<File *>(*itDoc)->Delete();
641 * \brief CallStartMethod
643 void DicomDir::CallStartMethod()
649 StartMethod( StartArg );
654 * \brief CallProgressMethod
656 void DicomDir::CallProgressMethod()
658 if ( ProgressMethod )
660 ProgressMethod( ProgressArg );
665 * \brief CallEndMethod
667 void DicomDir::CallEndMethod()
676 //-----------------------------------------------------------------------------
679 * \brief Sets all fields to NULL
681 void DicomDir::Initialize()
684 ProgressMethod = NULL;
686 StartMethodArgDelete = NULL;
687 ProgressMethodArgDelete = NULL;
688 EndMethodArgDelete = NULL;
700 * \brief create a 'gdcm::DicomDir' from a DICOMDIR Header
702 void DicomDir::CreateDicomDir()
704 // The SeqEntries of "Directory Record Sequence" are parsed.
705 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
706 // 1 - we save the beginning iterator
707 // 2 - we continue to parse
708 // 3 - we find an other tag
709 // + we create the object for the precedent tag
711 gdcmDebugMacro("Create DicomDir");
713 // Directory record sequence
714 DocEntry *e = GetDocEntry(0x0004, 0x1220);
717 gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
721 SeqEntry *s = dynamic_cast<SeqEntry *>(e);
724 gdcmWarningMacro( "Element (0004,1220) is not a Sequence ?!?");
734 SQItem *tmpSI=s->GetFirstSQItem();
737 d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
738 if ( DataEntry *dataEntry = dynamic_cast<DataEntry *>(d) )
740 v = dataEntry->GetString();
744 gdcmWarningMacro( "(0004,1430) not a DataEntry ?!?");
748 // A decent DICOMDIR has much more images than series,
749 // more series than studies, and so on.
750 // This is the right order to preform the tests
754 si = DicomDirImage::New(true);
755 if ( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
759 gdcmErrorMacro( "Add AddImageToEnd failed");
762 else if ( v == "SERIES" )
764 si = DicomDirSerie::New(true);
765 if ( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
769 gdcmErrorMacro( "Add AddSerieToEnd failed");
772 else if ( v == "VISIT " )
774 si = DicomDirVisit::New(true);
775 if ( !AddVisitToEnd( static_cast<DicomDirVisit *>(si)) )
779 gdcmErrorMacro( "Add AddVisitToEnd failed");
782 else if ( v == "STUDY " )
784 si = DicomDirStudy::New(true);
785 if ( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
789 gdcmErrorMacro( "Add AddStudyToEnd failed");
792 else if ( v == "PATIENT " )
794 si = DicomDirPatient::New(true);
795 if ( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
799 gdcmErrorMacro( "Add PatientToEnd failed");
804 // It was neither a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
805 // nor an 'IMAGE' SQItem. Skip to next item.
806 gdcmDebugMacro( " -------------------------------------------"
807 << "a non PATIENT/STUDY/SERIE/IMAGE SQItem was found : "
810 // FIXME : deal with other item types !
811 tmpSI=s->GetNextSQItem(); // To avoid infinite loop
815 si->MoveObject(tmpSI); // New code : Copies the List
817 tmpSI=s->GetNextSQItem();
823 * \brief AddPatientToEnd
824 * @param dd SQ Item to enqueue to the DicomPatient chained List
826 bool DicomDir::AddPatientToEnd(DicomDirPatient *dd)
828 Patients.push_back(dd);
833 * \brief AddStudyToEnd
834 * @param dd SQ Item to enqueue to the DicomDirStudy chained List
836 bool DicomDir::AddStudyToEnd(DicomDirStudy *dd)
838 if ( Patients.size() > 0 )
840 ListDicomDirPatient::iterator itp = Patients.end();
842 (*itp)->AddStudy(dd);
849 * \brief AddSerieToEnd
850 * @param dd SQ Item to enqueue to the DicomDirSerie chained List
852 bool DicomDir::AddSerieToEnd(DicomDirSerie *dd)
854 if ( Patients.size() > 0 )
856 ListDicomDirPatient::iterator itp = Patients.end();
859 DicomDirStudy *study = (*itp)->GetLastStudy();
870 * \brief AddVisitToEnd
871 * @param dd SQ Item to enqueue to the DicomDirVisit chained List
873 bool DicomDir::AddVisitToEnd(DicomDirVisit *dd)
875 if ( Patients.size() > 0 )
877 ListDicomDirPatient::iterator itp = Patients.end();
880 DicomDirStudy *study = (*itp)->GetLastStudy();
890 * \brief AddImageToEnd
891 * @param dd SQ Item to enqueue to the DicomDirImage chained List
893 bool DicomDir::AddImageToEnd(DicomDirImage *dd)
895 if ( Patients.size() > 0 )
897 ListDicomDirPatient::iterator itp = Patients.end();
900 DicomDirStudy *study = (*itp)->GetLastStudy();
903 DicomDirSerie *serie = study->GetLastSerie();
915 * \brief for each Header of the chained list,
916 * add/update the Patient/Study/Serie/Image info
917 * @param path path of the root directory
918 * @param list chained list of Headers
920 void DicomDir::SetElements(std::string const &path, VectDocument const &list)
925 std::string patPrevName = "", patPrevID = "";
926 std::string studPrevInstanceUID = "", studPrevID = "";
927 std::string serPrevInstanceUID = "", serPrevID = "";
929 std::string patCurName, patCurID;
930 std::string studCurInstanceUID, studCurID;
931 std::string serCurInstanceUID, serCurID;
934 for( VectDocument::const_iterator it = list.begin();
938 // get the current file characteristics
939 patCurName = (*it)->GetEntryString(0x0010,0x0010);
940 patCurID = (*it)->GetEntryString(0x0010,0x0011);
941 studCurInstanceUID = (*it)->GetEntryString(0x0020,0x000d);
942 studCurID = (*it)->GetEntryString(0x0020,0x0010);
943 serCurInstanceUID = (*it)->GetEntryString(0x0020,0x000e);
944 serCurID = (*it)->GetEntryString(0x0020,0x0011);
946 if ( patCurName != patPrevName || patCurID != patPrevID || first )
948 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
952 // if new Study, deal with 'STUDY' Elements
953 if ( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID
956 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
960 // if new Serie, deal with 'SERIE' Elements
961 if ( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
964 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
967 // Always Deal with 'IMAGE' Elements
968 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
970 patPrevName = patCurName;
971 patPrevID = patCurID;
972 studPrevInstanceUID = studCurInstanceUID;
973 studPrevID = studCurID;
974 serPrevInstanceUID = serCurInstanceUID;
975 serPrevID = serCurID;
981 * \brief adds to the HTable
982 * the Entries (Dicom Elements) corresponding to the given type
983 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
984 * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
985 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
986 * @param header Header of the current file
988 void DicomDir::SetElement(std::string const &path, DicomDirType type,
991 ListDicomDirElem elemList;
992 ListDicomDirElem::const_iterator it;
993 uint16_t tmpGr, tmpEl;
994 DictEntry *dictEntry;
1001 case GDCM_DICOMDIR_IMAGE:
1002 elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
1003 si = DicomDirImage::New(true);
1004 if ( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
1007 gdcmErrorMacro( "Add ImageToEnd failed");
1010 case GDCM_DICOMDIR_SERIE:
1011 elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
1012 si = DicomDirSerie::New(true);
1013 if ( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
1016 gdcmErrorMacro( "Add SerieToEnd failed");
1019 case GDCM_DICOMDIR_STUDY:
1020 elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
1021 si = DicomDirStudy::New(true);
1022 if ( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
1025 gdcmErrorMacro( "Add StudyToEnd failed");
1028 case GDCM_DICOMDIR_PATIENT:
1029 elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
1030 si = DicomDirPatient::New(true);
1031 if ( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
1034 gdcmErrorMacro( "Add PatientToEnd failed");
1037 case GDCM_DICOMDIR_META:
1040 MetaElems->Delete();
1041 gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
1043 elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
1044 MetaElems = DicomDirMeta::New(true);
1051 // FIXME : troubles found when it's a SeqEntry
1053 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
1054 // to avoid further troubles
1055 // imageElem 0008 1140 "" // Referenced Image Sequence
1056 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
1057 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
1058 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
1059 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
1061 std::string referencedVal;
1062 // for all the relevant elements found in their own spot of the DicomDir.dic
1063 for( it = elemList.begin(); it != elemList.end(); ++it)
1067 dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
1069 entry = DataEntry::New( dictEntry );
1070 entry->SetOffset(0); // just to avoid further missprinting
1074 // NULL when we Build Up (ex nihilo) a DICOMDIR
1075 // or when we add the META elems
1077 val = header->GetEntryString(tmpGr, tmpEl);
1084 if ( val == GDCM_UNFOUND)
1086 if ( tmpGr == 0x0004 ) // never present in File !
1090 case 0x1130: // File-set ID
1091 // force to the *end* File Name
1092 val = Util::GetName( path );
1095 case 0x1500: // Only used for image
1096 if ( header->GetFileName().substr(0, path.length()) != path )
1098 gdcmWarningMacro( "The base path of file name is incorrect");
1099 val = header->GetFileName();
1103 val = &(header->GetFileName().c_str()[path.length()+1]);
1107 case 0x1510: // Referenced SOP Class UID in File
1108 referencedVal = header->GetEntryString(0x0008, 0x0016);
1109 // FIXME : probabely something to check
1110 val = referencedVal;
1113 case 0x1511: // Referenced SOP Instance UID in File
1114 referencedVal = header->GetEntryString(0x0008, 0x0018);
1115 // FIXME : probabely something to check
1116 val = referencedVal;
1119 case 0x1512: // Referenced Transfer Syntax UID in File
1120 referencedVal = header->GetEntryString(0x0002, 0x0010);
1121 // FIXME : probabely something to check
1122 val = referencedVal;
1132 if ( header->GetEntryLength(tmpGr,tmpEl) == 0 )
1136 /* FIX later the pb of creating the 'Implementation Version Name'!
1138 if (val == GDCM_UNFOUND)
1141 if ( tmpGr == 0x0002 && tmpEl == 0x0013)
1143 // 'Implementation Version Name'
1144 std::string val = "GDCM ";
1145 val += Util::GetVersion();
1148 entry->SetString( val ); // troubles expected when vr=SQ ...
1150 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
1152 gdcmDebugMacro("GDCM_DICOMDIR_META ?!? should never print that");
1154 si->AddEntry(entry);
1160 * \brief Move the content of the source SQItem to the destination SQItem
1161 * Only DocEntry's are moved
1162 * @param dst destination SQItem
1163 * @param src source SQItem
1165 void DicomDir::MoveSQItem(DocEntrySet *dst,DocEntrySet *src)
1169 entry = src->GetFirstEntry();
1172 src->RemoveEntry(entry);
1173 dst->AddEntry(entry);
1174 // we destroyed -> the current iterator is not longer valid
1175 entry = src->GetFirstEntry();
1180 * \brief compares two files
1182 bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
1184 return *header1 < *header2;
1187 //-----------------------------------------------------------------------------
1190 * \brief Canonical Printer
1191 * @param os ostream we want to print in
1192 * @param indent Indentation string to be prepended during printing
1194 void DicomDir::Print(std::ostream &os, std::string const & )
1198 MetaElems->SetPrintLevel(PrintLevel);
1199 MetaElems->Print(os);
1201 for(ListDicomDirPatient::iterator cc = Patients.begin();
1202 cc != Patients.end();
1205 (*cc)->SetPrintLevel(PrintLevel);
1210 //-----------------------------------------------------------------------------
1211 } // end namespace gdcm