1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2007/03/23 15:30:15 $
7 Version: $Revision: 1.190 $
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 "gdcmDicomDirPrivate.h"
30 #include "gdcmDicomDirPatient.h"
31 #include "gdcmDicomDirMeta.h"
32 #include "gdcmDicomDirElement.h"
33 #include "gdcmDirList.h"
35 #include "gdcmDebug.h"
36 #include "gdcmGlobal.h"
38 #include "gdcmSeqEntry.h"
39 #include "gdcmSQItem.h"
40 #include "gdcmDataEntry.h"
41 #include "gdcmCommandManager.h"
46 #include <sys/types.h>
49 # define getcwd _getcwd
52 #if defined(_MSC_VER) || defined(__BORLANDC__)
58 #if defined(__BORLANDC__)
59 #include <mem.h> // for memset
62 // ----------------------------------------------------------------------------
63 // Note for future developpers
64 // ----------------------------------------------------------------------------
66 // Dicom PS 3.3 describes the relationship between Directory Records, as follow
67 // (see also PS 4.3, 2004, page 50 for Entity-Relationship model)
69 // Directory Record Type Directory Record Types which may be included
70 // in the next lower-level directory Entity
72 // (Root directory Entity) PATIENT, TOPIC, PRIVATE
74 // PATIENT STUDY, PRIVATE
76 // STUDY SERIES, VISIT, RESULTS, STUDY COMPONENT, PRIVATE
78 // SERIES IMAGE, OVERLAYS, MODALITY LUT, VOI LUT,
79 // CURVE, STORED PRINT, RT DOSE, RT STRUCTURE SET
80 // RT PLAN, RT TREAT RECORD, PRESENTATION, WAVEFORM,
81 // SR DOCUMENT, KEY OBJECT DOC, SPECTROSCOPY,
82 // RAW DATA, REGISTRATION, FIDUCIAL, PRIVATE,
105 // ----------------------
106 // The current gdcm version only deals with :
108 // (Root directory Entity) PATIENT
115 // DicomDir::CreateDicomDir will have to be completed
116 // Treelike structure management will have to be upgraded
117 // ----------------------------------------------------------------------------
121 //-----------------------------------------------------------------------------
122 // Constructor / Destructor
124 * \brief Constructor : creates an empty DicomDir
128 Initialize(); // sets all private fields to NULL
133 //#ifndef GDCM_LEGACY_REMOVE
135 * \brief Constructor Parses recursively the directory and creates the DicomDir
136 * or uses an already built DICOMDIR, depending on 'parseDir' value.
137 * @param fileName name
138 * - of the root directory (parseDir = true)
139 * - of the DICOMDIR (parseDir = false)
140 * @param parseDir boolean
141 * - true if user passed an entry point
142 * and wants to explore recursively the directories
143 * - false if user passed an already built DICOMDIR file
144 * and wants to use it
145 * @deprecated use : new DicomDir() + [ SetLoadMode(lm) + ] SetDirectoryName(name)
146 * or : new DicomDir() + SetFileName(name)
149 DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
152 // At this step, Document constructor is already executed,
153 // whatever user passed (either a root directory or a DICOMDIR)
154 // and whatever the value of parseDir was.
155 // (nothing is cheked in Document constructor, to avoid overhead)
158 SetLoadMode (LD_ALL); // concerns only dicom files
159 SetFileName( fileName );
166 * \brief Canonical destructor
168 DicomDir::~DicomDir()
177 //-----------------------------------------------------------------------------
181 * \brief Loader. use SetFileName(fn)
182 * or SetLoadMode(lm) + SetDirectoryName(dn) before !
183 * @return false if file cannot be open or no swap info was found,
184 * or no tag was found.
186 bool DicomDir::Load( )
190 if ( ! this->Document::Load( ) )
193 return DoTheLoadingJob( );
195 //#ifndef GDCM_LEGACY_REMOVE
197 * \brief Loader. (DEPRECATED : kept not to break the API)
198 * @param fileName file to be open for parsing
199 * @return false if file cannot be open or no swap info was found,
200 * or no tag was found.
201 * @deprecated use SetFileName(n) + Load() instead
204 bool DicomDir::Load(std::string const &fileName )
206 // We should clean out anything that already exists.
207 Initialize(); // sets all private fields to NULL
209 SetFileName( fileName );
212 if ( ! this->Document::Load( ) )
215 return DoTheLoadingJob( );
221 * \brief Does the Loading Job (internal use only)
222 * @return false if file cannot be open or no swap info was found,
223 * or no tag was found.
225 bool DicomDir::DoTheLoadingJob( )
232 // Only if user passed a DICOMDIR
233 // ------------------------------
235 if (!Document::Load() )
240 if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
242 gdcmWarningMacro( "Entry HT empty for file: "<< GetFileName());
245 // Directory record sequence
246 DocEntry *e = GetDocEntry(0x0004, 0x1220);
249 gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
250 << " in file " << GetFileName());
258 // Only if user passed a root directory
259 // ------------------------------------
260 if ( GetFileName() == "." )
262 // user passed '.' as Name
263 // we get current directory name
265 const char *cwd = getcwd(buf, 2048);
268 SetFileName( buf ); // will be converted into a string
272 gdcmErrorMacro( "Path was too long to fit on 2048 bytes" );
276 gdcmDebugMacro( "Parse directory and create the DicomDir : "
284 * \brief This predicate, based on hopefully reasonable heuristics,
285 * decides whether or not the current document was properly parsed
286 * and contains the mandatory information for being considered as
287 * a well formed and usable DicomDir.
288 * @return true when Document is the one of a reasonable DicomDir,
291 bool DicomDir::IsReadable()
293 if ( Filetype == Unknown )
295 gdcmErrorMacro( "Wrong filetype for " << GetFileName());
300 gdcmWarningMacro( "Meta Elements missing in DicomDir");
303 if ( Patients.size() <= 0 )
305 gdcmWarningMacro( "NO Patient in DicomDir");
313 * \brief adds *the* Meta to a partially created DICOMDIR
315 DicomDirMeta *DicomDir::NewMeta()
320 DocEntry *entry = GetFirstEntry();
323 MetaElems = DicomDirMeta::New(true); // true = empty
325 entry = GetFirstEntry();
328 if ( dynamic_cast<SeqEntry *>(entry) )
331 MetaElems->AddEntry(entry);
334 entry = GetFirstEntry();
337 else // after root directory parsing
339 MetaElems = DicomDirMeta::New(false); // false = not empty
341 MetaElems->SetSQItemNumber(0); // To avoid further missprinting
346 * \brief adds a new Patient (with the basic elements) to a partially created
349 DicomDirPatient *DicomDir::NewPatient()
351 DicomDirPatient *dd = DicomDirPatient::New();
352 AddPatientToEnd( dd );
357 * \brief Remove all Patients
359 void DicomDir::ClearPatient()
361 for(ListDicomDirPatient::iterator cc = Patients.begin();
371 * \brief Get the first entry while visiting the DicomDirPatients
372 * \return The first DicomDirPatient if found, otherwhise NULL
374 DicomDirPatient *DicomDir::GetFirstPatient()
376 ItPatient = Patients.begin();
377 if ( ItPatient != Patients.end() )
383 * \brief Get the next entry while visiting the DicomDirPatients
384 * \note : meaningfull only if GetFirstEntry already called
385 * \return The next DicomDirPatient if found, otherwhise NULL
387 DicomDirPatient *DicomDir::GetNextPatient()
389 gdcmAssertMacro (ItPatient != Patients.end());
392 if ( ItPatient != Patients.end() )
398 * \brief fills the whole structure, starting from a root Directory
400 void DicomDir::ParseDirectory()
402 CreateDicomDirChainedList( GetFileName() );
407 * \brief writes on disc a DICOMDIR
408 * \ warning does NOT add the missing elements in the header :
409 * it's up to the user doing it !
410 * @param fileName file to be written to
411 * @return false only when fail to open
414 bool DicomDir::Write(std::string const &fileName)
417 uint16_t sq[6] = { 0x0004, 0x1220, 0x5153, 0x0000, 0xffff, 0xffff };
418 uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0x0000, 0x0000 };
420 std::ofstream *fp = new std::ofstream(fileName.c_str(),
421 std::ios::out | std::ios::binary);
424 gdcmWarningMacro("Failed to open(write) File: " << fileName.c_str());
428 char filePreamble[128];
429 memset(filePreamble, 0, 128);
430 fp->write(filePreamble, 128);
431 binary_write( *fp, "DICM");
433 DicomDirMeta *ptrMeta = GetMeta();
434 ptrMeta->WriteContent(fp, ExplicitVR);
436 // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
439 binary_write(*fp, sq[i]);
442 for(ListDicomDirPatient::iterator cc = Patients.begin();
443 cc != Patients.end();
446 (*cc)->WriteContent( fp, ExplicitVR );
449 // force writing Sequence Delimitation Item
452 binary_write(*fp, sqt[i]); // fffe e0dd 0000 0000
462 * \brief Anonymize a DICOMDIR
466 bool DicomDir::Anonymize()
469 // Something clever to be found to forge the Patient names
470 std::ostringstream s;
472 for(ListDicomDirPatient::iterator cc = Patients.begin();
477 v = (*cc)->GetDataEntry(0x0010, 0x0010) ; // Patient's Name
480 v->SetString(s.str());
483 v = (*cc)->GetDataEntry(0x0010, 0x0020) ; // Patient ID
489 v = (*cc)->GetDataEntry(0x0010, 0x0030) ; // Patient's BirthDate
501 * \brief Copies all the attributes from an other DocEntrySet
502 * @param set entry to copy from
503 * @remarks The contained DocEntries are not copied, only referenced
505 void DicomDir::Copy(DocEntrySet *set)
507 // Remove all previous childs
512 DicomDir *dd = dynamic_cast<DicomDir *>(set);
516 MetaElems->Unregister();
517 MetaElems = dd->MetaElems;
519 MetaElems->Register();
521 Patients = dd->Patients;
522 for(ItPatient = Patients.begin();ItPatient != Patients.end();++ItPatient)
523 (*ItPatient)->Register();
527 //-----------------------------------------------------------------------------
530 * \brief create a Document-like chained list from a root Directory
531 * @param path entry point of the tree-like structure
533 void DicomDir::CreateDicomDirChainedList(std::string const &path)
536 DirList dirList(path,1); // gets recursively the file list
537 unsigned int count = 0;
541 DirListType fileList = dirList.GetFilenames();
542 unsigned int nbFile = fileList.size();
543 for( DirListType::iterator it = fileList.begin();
544 it != fileList.end();
547 Progress = (float)(count+1)/(float)nbFile;
548 CallProgressMethod();
555 f->SetLoadMode(LoadMode); // we allow user not to load Sequences,
556 // or Shadow groups, or ......
557 f->SetFileName( it->c_str() );
560 if ( f->IsReadable() )
562 // Add the file to the chained list:
564 gdcmDebugMacro( "Readable " << it->c_str() );
572 // sorts Patient/Study/Serie/
573 std::sort(list.begin(), list.end(), DicomDir::HeaderLessThan );
575 std::string tmp = dirList.GetDirName();
576 //for each File of the chained list, add/update the Patient/Study/Serie/Image info
577 SetElements(tmp, list);
580 for(VectDocument::iterator itDoc=list.begin();
584 dynamic_cast<File *>(*itDoc)->Delete();
589 //-----------------------------------------------------------------------------
592 * \brief Sets all fields to NULL
594 void DicomDir::Initialize()
603 * \brief create a 'gdcm::DicomDir' from a DICOMDIR Header
605 void DicomDir::CreateDicomDir()
607 // The SeqEntries of "Directory Record Sequence" are parsed.
608 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
609 // 1 - we save the beginning iterator
610 // 2 - we continue to parse
611 // 3 - we find an other tag
612 // + we create the object for the precedent tag
614 gdcmDebugMacro("Create DicomDir");
616 // Directory record sequence
617 DocEntry *e = GetDocEntry(0x0004, 0x1220);
620 gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
624 SeqEntry *s = dynamic_cast<SeqEntry *>(e);
627 gdcmWarningMacro( "Element (0004,1220) is not a Sequence ?!?");
637 SQItem *tmpSI=s->GetFirstSQItem();
640 d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
641 if ( DataEntry *dataEntry = dynamic_cast<DataEntry *>(d) )
643 v = dataEntry->GetString();
647 gdcmWarningMacro( "(0004,1430) not a DataEntry ?!?");
651 // A decent DICOMDIR has much more images than series,
652 // more series than studies, and so on.
653 // This is the right order to perform the tests
657 si = DicomDirImage::New(true);
658 if ( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
662 gdcmErrorMacro( "Add AddImageToEnd failed");
665 else if ( v == "SERIES" )
667 si = DicomDirSerie::New(true);
668 if ( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
672 gdcmErrorMacro( "Add AddSerieToEnd failed");
675 else if ( v == "VISIT " )
677 si = DicomDirVisit::New(true);
678 if ( !AddVisitToEnd( static_cast<DicomDirVisit *>(si)) )
682 gdcmErrorMacro( "Add AddVisitToEnd failed");
685 else if ( v == "STUDY " )
687 si = DicomDirStudy::New(true);
688 if ( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
692 gdcmErrorMacro( "Add AddStudyToEnd failed");
695 else if ( v == "PATIENT " )
697 si = DicomDirPatient::New(true);
698 if ( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
702 gdcmErrorMacro( "Add PatientToEnd failed");
705 /// \to do : deal with PRIVATE (not so easy, since PRIVATE appears
706 /// at defferent levels ?!? )
708 else if ( v == "PRIVATE " ) // for SIEMENS 'CSA Non Image'
711 gdcmWarningMacro( " -------------------------------------------"
712 << "a PRIVATE SQItem was found : " << v);
713 si = DicomDirPrivate::New(true);
714 if ( !AddPrivateToEnd( static_cast<DicomDirPrivate *>(si)) )
718 gdcmErrorMacro( "Add PrivateToEnd failed");
723 // It was neither a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
724 // nor an 'IMAGE' SQItem. Skip to next item.
725 gdcmWarningMacro( " -------------------------------------------"
726 << "a non PATIENT/STUDY/SERIE/IMAGE SQItem was found : "
729 // FIXME : deal with other item types !
730 tmpSI=s->GetNextSQItem(); // To avoid infinite loop
736 tmpSI=s->GetNextSQItem();
742 * \brief AddPatientToEnd
743 * @param dd SQ Item to enqueue to the DicomPatient chained List
745 bool DicomDir::AddPatientToEnd(DicomDirPatient *dd)
747 Patients.push_back(dd);
752 * \brief AddStudyToEnd
753 * @param dd SQ Item to enqueue to the DicomDirStudy chained List
755 bool DicomDir::AddStudyToEnd(DicomDirStudy *dd)
757 if ( Patients.size() > 0 )
759 ListDicomDirPatient::iterator itp = Patients.end();
761 (*itp)->AddStudy(dd);
768 * \brief AddSerieToEnd
769 * @param dd SQ Item to enqueue to the DicomDirSerie chained List
771 bool DicomDir::AddSerieToEnd(DicomDirSerie *dd)
773 if ( Patients.size() > 0 )
775 ListDicomDirPatient::iterator itp = Patients.end();
778 DicomDirStudy *study = (*itp)->GetLastStudy();
789 * \brief AddVisitToEnd
790 * @param dd SQ Item to enqueue to the DicomDirVisit chained List
792 bool DicomDir::AddVisitToEnd(DicomDirVisit *dd)
794 if ( Patients.size() > 0 )
796 ListDicomDirPatient::iterator itp = Patients.end();
799 DicomDirStudy *study = (*itp)->GetLastStudy();
809 * \brief AddImageToEnd
810 * @param dd SQ Item to enqueue to the DicomDirImage chained List
812 bool DicomDir::AddImageToEnd(DicomDirImage *dd)
814 if ( Patients.size() > 0 )
816 ListDicomDirPatient::iterator itp = Patients.end();
819 DicomDirStudy *study = (*itp)->GetLastStudy();
822 DicomDirSerie *serie = study->GetLastSerie();
834 * \brief AddPrivateToEnd
835 * @param dd SQ Item to enqueue to the DicomDirPrivate chained List
836 * (checked for SIEMENS 'CSA non image')
838 bool DicomDir::AddPrivateToEnd(DicomDirPrivate *dd)
840 if ( Patients.size() > 0 )
842 ListDicomDirPatient::iterator itp = Patients.end();
845 DicomDirStudy *study = (*itp)->GetLastStudy();
848 DicomDirSerie *serie = study->GetLastSerie();
851 serie->AddPrivate(dd);
860 * \brief for each Header of the chained list,
861 * add/update the Patient/Study/Serie/Image info
862 * @param path path of the root directory
863 * @param list chained list of Headers
865 void DicomDir::SetElements(std::string const &path, VectDocument const &list)
870 std::string patPrevName = "", patPrevID = "";
871 std::string studPrevInstanceUID = "", studPrevID = "";
872 std::string serPrevInstanceUID = "", serPrevID = "";
874 std::string patCurName, patCurID;
875 std::string studCurInstanceUID, studCurID;
876 std::string serCurInstanceUID, serCurID;
879 for( VectDocument::const_iterator it = list.begin();
883 // get the current file characteristics
884 patCurName = (*it)->GetEntryString(0x0010,0x0010);
885 patCurID = (*it)->GetEntryString(0x0010,0x0011);
886 studCurInstanceUID = (*it)->GetEntryString(0x0020,0x000d);
887 studCurID = (*it)->GetEntryString(0x0020,0x0010);
888 serCurInstanceUID = (*it)->GetEntryString(0x0020,0x000e);
889 serCurID = (*it)->GetEntryString(0x0020,0x0011);
891 if ( patCurName != patPrevName || patCurID != patPrevID || first )
893 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
897 // if new Study, deal with 'STUDY' Elements
898 if ( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID
901 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
905 // if new Serie, deal with 'SERIE' Elements
906 if ( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
909 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
912 // Always Deal with 'IMAGE' Elements
913 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
915 patPrevName = patCurName;
916 patPrevID = patCurID;
917 studPrevInstanceUID = studCurInstanceUID;
918 studPrevID = studCurID;
919 serPrevInstanceUID = serCurInstanceUID;
920 serPrevID = serCurID;
926 * \brief adds to the HTable
927 * the Entries (Dicom Elements) corresponding to the given type
928 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
929 * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
930 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
931 * @param header Header of the current file
933 void DicomDir::SetElement(std::string const &path, DicomDirType type,
936 ListDicomDirElem elemList;
937 ListDicomDirElem::const_iterator it;
938 uint16_t tmpGr, tmpEl;
939 //DictEntry *dictEntry;
946 case GDCM_DICOMDIR_IMAGE:
947 elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
948 si = DicomDirImage::New(true);
949 if ( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
952 gdcmErrorMacro( "Add ImageToEnd failed");
955 case GDCM_DICOMDIR_SERIE:
956 elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
957 si = DicomDirSerie::New(true);
958 if ( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
961 gdcmErrorMacro( "Add SerieToEnd failed");
964 case GDCM_DICOMDIR_STUDY:
965 elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
966 si = DicomDirStudy::New(true);
967 if ( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
970 gdcmErrorMacro( "Add StudyToEnd failed");
973 case GDCM_DICOMDIR_PATIENT:
974 elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
975 si = DicomDirPatient::New(true);
976 if ( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
979 gdcmErrorMacro( "Add PatientToEnd failed");
982 case GDCM_DICOMDIR_META:
986 gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
988 elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
989 MetaElems = DicomDirMeta::New(true);
996 // FIXME : troubles found when it's a SeqEntry
998 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
999 // to avoid further troubles
1000 // imageElem 0008 1140 "" // Referenced Image Sequence
1001 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
1002 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
1003 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
1004 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
1006 std::string referencedVal;
1007 // for all the relevant elements found in their own spot of the DicomDir.dic
1008 for( it = elemList.begin(); it != elemList.end(); ++it)
1012 //dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
1013 //entry = DataEntry::New( dictEntry );
1015 entry = DataEntry::New(tmpGr, tmpEl, GDCM_VRUNKNOWN); /// \todo : modify dicomelements file, to store VR
1016 entry->SetOffset(0); // just to avoid further missprinting
1020 // NULL when we Build Up (ex nihilo) a DICOMDIR
1021 // or when we add the META elems
1022 val = header->GetEntryString(tmpGr, tmpEl);
1029 if ( val == GDCM_UNFOUND)
1031 if ( tmpGr == 0x0004 ) // never present in File !
1035 case 0x1130: // File-set ID
1036 // force to the *end* File Name
1037 val = Util::GetName( path );
1040 case 0x1500: // Only used for image
1041 if ( header->GetFileName().substr(0, path.length()) != path )
1043 gdcmWarningMacro( "The base path of file name is incorrect");
1044 val = header->GetFileName();
1048 // avoid the first '/' in File name !
1049 if ( header->GetFileName().c_str()[path.length()]
1050 == GDCM_FILESEPARATOR )
1051 val = &(header->GetFileName().c_str()[path.length()+1]);
1053 val = &(header->GetFileName().c_str()[path.length()]);
1057 case 0x1510: // Referenced SOP Class UID in File
1058 referencedVal = header->GetEntryString(0x0008, 0x0016);
1059 // FIXME : probabely something to check
1060 val = referencedVal;
1063 case 0x1511: // Referenced SOP Instance UID in File
1064 referencedVal = header->GetEntryString(0x0008, 0x0018);
1065 // FIXME : probabely something to check
1066 val = referencedVal;
1069 case 0x1512: // Referenced Transfer Syntax UID in File
1070 referencedVal = header->GetEntryString(0x0002, 0x0010);
1071 // FIXME : probabely something to check
1072 val = referencedVal;
1081 // If the entry is not found in the Header, don't write its 'value' in the DICOMDIR !
1088 if ( header->GetEntryLength(tmpGr,tmpEl) == 0 )
1091 // Don't polute the DICOMDIR with empty fields
1100 /* FIX later the pb of creating the 'Implementation Version Name'!
1102 if (val == GDCM_UNFOUND)
1105 if ( tmpGr == 0x0002 && tmpEl == 0x0013)
1107 // 'Implementation Version Name'
1108 std::string val = "GDCM ";
1109 val += Util::GetVersion();
1113 entry->SetString( val ); // troubles expected when vr=SQ ...
1115 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
1117 gdcmDebugMacro("GDCM_DICOMDIR_META ?!? should never print that");
1120 si->AddEntry(entry);
1126 * \brief Move the content of the source SQItem to the destination SQItem
1127 * Only DocEntry's are moved
1128 * @param dst destination SQItem
1129 * @param src source SQItem
1131 void DicomDir::MoveSQItem(DocEntrySet *dst, DocEntrySet *src)
1134 // todo : rewrite the whole stuff, without using RemoveEntry an AddEntry,
1136 entry = src->GetFirstEntry();
1139 dst->AddEntry(entry); // use it, *before* removing it!
1140 src->RemoveEntry(entry);
1141 // we destroyed -> the current iterator is not longer valid
1142 entry = src->GetFirstEntry();
1147 * \brief compares two files
1149 bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
1151 return *header1 < *header2;
1154 //-----------------------------------------------------------------------------
1157 * \brief Canonical Printer
1158 * @param os ostream we want to print in
1159 * @param indent Indentation string to be prepended during printing
1161 void DicomDir::Print(std::ostream &os, std::string const & )
1165 MetaElems->SetPrintLevel(PrintLevel);
1166 MetaElems->Print(os);
1168 for(ListDicomDirPatient::iterator cc = Patients.begin();
1169 cc != Patients.end();
1172 (*cc)->SetPrintLevel(PrintLevel);
1177 //-----------------------------------------------------------------------------
1178 } // end namespace gdcm