1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2004/08/27 15:48:44 $
7 Version: $Revision: 1.65 $
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.htm 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 =========================================================================*/
21 #include <sys/types.h>
29 #include "gdcmDicomDir.h"
30 #include "gdcmDicomDirStudy.h"
31 #include "gdcmDicomDirSerie.h"
32 #include "gdcmDicomDirImage.h"
33 #include "gdcmDirList.h"
35 #include "gdcmDebug.h"
36 #include "gdcmGlobal.h"
37 #include "gdcmHeader.h"
38 #include "gdcmSeqEntry.h"
39 #include "gdcmSQItem.h"
40 #include "gdcmValEntry.h"
42 //-----------------------------------------------------------------------------
43 // For full DICOMDIR description, see:
44 // PS 3.3-2003, pages 731-750
45 //-----------------------------------------------------------------------------
46 // Constructor / Destructor
49 * \ingroup gdcmDicomDir
50 * \brief Constructor : creates an empty gdcmDicomDir
52 gdcmDicomDir::gdcmDicomDir()
55 Initialize(); // sets all private fields to NULL
57 std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...
58 SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements
63 * \brief Constructor Parses recursively the directory and creates the DicomDir
64 * or uses an already built DICOMDIR, depending on 'parseDir' value.
65 * @param FileName name
66 * - of the root directory (parseDir = true)
67 * - of the DICOMDIR (parseDir = false)
68 * @param parseDir boolean
69 * - true if user passed an entry point
70 * and wants to explore recursively the directories
71 * - false if user passed an already built DICOMDIR file
74 gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir ):
75 gdcmDocument( fileName )
77 // que l'on ai passe un root directory ou un DICOMDIR
78 // et quelle que soit la valeur de parseDir,
79 // on a deja lance gdcmDocument
80 Initialize(); // sets all private fields to NULL
82 // gdcmDocument already executed
83 // if user passed a root directory, sure we didn't get anything
85 if ( TagHT.begin() == TagHT.end() ) // when user passed a Directory to parse
87 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry HT empty");
89 if ( fileName.size() == 1 && fileName[0] == '.' )
91 // user passed '.' as Name
92 // we get current directory name
93 char* dummy = new char[1000];
94 getcwd(dummy, (size_t)1000);
95 SetFileName( dummy ); // will be converted into a string
96 delete[] dummy; // no longer needed
99 if ( parseDir ) // user asked for a recursive parsing of a root directory
101 metaElems = NewMeta();
103 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory"
104 " and create the DicomDir");
109 /// \todo if parseDir == false, it should be tagged as an error
110 // NON ! il suffit d'appeler ParseDirectory()
111 // apres le constructeur
114 else // Only if user passed a DICOMDIR
116 // Directory record sequence
117 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
120 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
121 " sequence (0x0004,0x1220)");
122 /// \todo FIXME : what do we do when the parsed file IS NOT a
130 * \brief Canonical destructor
132 gdcmDicomDir::~gdcmDicomDir()
134 SetStartMethod(NULL);
135 SetProgressMethod(NULL);
137 for(ListDicomDirPatient::iterator cc = patients.begin();
149 //-----------------------------------------------------------------------------
152 * \brief Canonical Printer
154 void gdcmDicomDir::Print(std::ostream &os)
158 metaElems->SetPrintLevel(PrintLevel);
159 metaElems->Print(os);
161 for(ListDicomDirPatient::iterator cc = patients.begin();
162 cc != patients.end();
165 (*cc)->SetPrintLevel( PrintLevel );
170 //-----------------------------------------------------------------------------
173 * \brief This predicate, based on hopefully reasonable heuristics,
174 * decides whether or not the current header was properly parsed
175 * and contains the mandatory information for being considered as
176 * a well formed and usable DicomDir.
177 * @return true when gdcmDocument is the one of a reasonable DicomDir,
180 bool gdcmDicomDir::IsReadable()
182 if( !gdcmDocument::IsReadable() )
190 if( patients.size() <= 0 )
199 * \brief Sets all fields to NULL
202 void gdcmDicomDir::Initialize()
205 progressMethod = NULL;
207 startMethodArgDelete = NULL;
208 progressMethodArgDelete = NULL;
209 endMethodArgDelete = NULL;
222 * \ingroup gdcmDicomDir
223 * \brief fills the whole structure, starting from a root Directory
225 void gdcmDicomDir::ParseDirectory()
227 CreateDicomDirChainedList( GetFileName() );
232 * \ingroup gdcmDicomDir
233 * \brief Set the start method to call when the parsing of the directory starts
234 * @param method Method to call
235 * @param arg Argument to pass to the method
236 * @param argDelete Argument
237 * \warning In python : the arg parameter isn't considered
239 void gdcmDicomDir::SetStartMethod(gdcmMethod *method, void *arg,
240 gdcmMethod *argDelete )
242 if( startArg && startMethodArgDelete )
244 startMethodArgDelete( startArg );
247 startMethod = method;
249 startMethodArgDelete = argDelete;
253 * \ingroup gdcmDicomDir
254 * \brief Set the method to delete the argument
255 * The argument is destroyed when the method is changed or when the
257 * @param method Method to call to delete the argument
259 void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod *method)
261 startMethodArgDelete = method;
265 * \ingroup gdcmDicomDir
266 * \brief Set the progress method to call when the parsing of the directory progress
267 * @param method Method to call
268 * @param arg Argument to pass to the method
269 * @param argDelete Argument
270 * \warning In python : the arg parameter isn't considered
272 void gdcmDicomDir::SetProgressMethod(gdcmMethod *method, void *arg,
273 gdcmMethod *argDelete )
275 if( progressArg && progressMethodArgDelete )
277 progressMethodArgDelete( progressArg );
280 progressMethod = method;
282 progressMethodArgDelete = argDelete;
286 * \ingroup gdcmDicomDir
287 * \brief Set the method to delete the argument
288 * The argument is destroyed when the method is changed or when the
290 * @param method Method to call to delete the argument
292 void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod *method)
294 progressMethodArgDelete = method;
298 * \ingroup gdcmDicomDir
299 * \brief Set the end method to call when the parsing of the directory ends
300 * @param method Method to call
301 * @param arg Argument to pass to the method
302 * @param argDelete Argument
303 * \warning In python : the arg parameter isn't considered
305 void gdcmDicomDir::SetEndMethod(gdcmMethod *method, void *arg,
306 gdcmMethod *argDelete )
308 if( endArg && endMethodArgDelete )
310 endMethodArgDelete( endArg );
315 endMethodArgDelete = argDelete;
319 * \ingroup gdcmDicomDir
320 * \brief Set the method to delete the argument
321 * The argument is destroyed when the method is changed or when the class
323 * @param method Method to call to delete the argument
325 void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod *method)
327 endMethodArgDelete = method;
331 * \ingroup gdcmDicomDir
332 * \brief writes on disc a DICOMDIR
333 * \ warning does NOT add the missing elements in the header :
334 * it's up to the user doing it !
335 * \todo : to be re-written using the DICOMDIR tree-like structure
336 * *not* the chained list
337 * (does NOT exist if the DICOMDIR is user-forged !)
338 * @param fileName file to be written to
339 * @return false only when fail to open
342 bool gdcmDicomDir::Write(std::string const & fileName)
344 uint16_t sq[5] = { 0x0004, 0x1220, 0x0000, 0xffff, 0xffff };
345 uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
347 FILE * fp = fopen(fileName.c_str(), "wb");
350 printf("Failed to open(write) File [%s] \n", fileName.c_str());
354 uint8_t* filePreamble = new uint8_t[128];
355 memset(filePreamble, 0, 128);
356 fwrite(filePreamble,128,1,fp);
357 fwrite("DICM",4,1,fp);
358 delete[] filePreamble;
360 // UpdateDirectoryRecordSequenceLength(); // TODO (if *really* usefull)
362 gdcmDicomDirMeta *ptrMeta = GetDicomDirMeta();
363 ptrMeta->Write(fp, gdcmExplicitVR);
365 // force writing 0004|1220 [SQ ], that CANNOT exist within gdcmDicomDirMeta
366 fwrite(&sq[0],4,1,fp); // 0004 1220
367 //fwrite("SQ" ,2,1,fp); // SQ // VR no written for 'No length' Sequences !
368 //fwrite(&sq[2],6,1,fp); // 00 ffffffff
369 fwrite(&sq[3],4,1,fp); // ffffffff
371 for(ListDicomDirPatient::iterator cc = patients.begin();cc!=patients.end();++cc)
373 (*cc)->Write( fp, gdcmExplicitVR );
376 // force writing Sequence Delimitation Item
377 fwrite(&sqt[0],8,1,fp); // fffe e0dd ffff ffff
383 //-----------------------------------------------------------------------------
387 * \ingroup gdcmDicomDir
388 * \brief create a gdcmDocument-like chained list from a root Directory
389 * @param path entry point of the tree-like structure
391 void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path)
394 gdcmDirList fileList(path,1); // gets recursively the file list
395 unsigned int count = 0;
402 for( gdcmDirList::iterator it = fileList.begin();
403 it != fileList.end();
406 progress = (float)(count+1)/(float)fileList.size();
407 CallProgressMethod();
413 header = new gdcmHeader( it->c_str() );
417 "gdcmDicomDir::CreateDicomDirChainedList: "
418 "failure in new Header ",
421 if( header->IsReadable() )
423 // Add the file header to the chained list:
424 list.push_back(header);
426 "gdcmDicomDir::CreateDicomDirChainedList: readable ",
436 // sorts Patient/Study/Serie/
437 std::sort(list.begin(), list.end(), gdcmDicomDir::HeaderLessThan );
439 std::string tmp = fileList.GetDirName();
441 //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
442 SetElements(tmp, list);
447 * \ingroup gdcmDicomDir
448 * \brief adds *the* Meta to a partially created DICOMDIR
451 gdcmDicomDirMeta * gdcmDicomDir::NewMeta()
453 gdcmDicomDirMeta *m = new gdcmDicomDirMeta( &TagHT );
455 if ( TagHT.begin() != TagHT.end() ) // after Document Parsing
457 TagDocEntryHT::iterator lastOneButSequence = TagHT.end();
458 lastOneButSequence --;
459 // This works because ALL the 'out of Sequence' Tags belong to Meta Elems
460 // (we skip 0004|1220 [Directory record sequence] )
461 for ( TagDocEntryHT::iterator cc = TagHT.begin();
462 cc != lastOneButSequence;
465 m->AddDocEntry( cc->second );
468 else // after root directory parsing
470 //cout << "gdcmDicomDir::NewMeta avec FillObject" << endl;
471 std::list<gdcmElement> elemList;
472 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
473 m->FillObject(elemList);
474 // we create the Sequence manually
475 //gdcmSeqEntry *se =NewSeqEntryByNumber(0x0004, 0x1220); // NOT YET!
478 m->SetSQItemNumber(0); // To avoid further missprinting
484 * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
486 gdcmDicomDirPatient * gdcmDicomDir::NewPatient()
488 std::list<gdcmElement>::iterator it;
489 uint16_t tmpGr,tmpEl;
490 gdcmDictEntry *dictEntry;
493 std::list<gdcmElement> elemList;
494 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
495 // Looks nice, but gdcmDicomDir IS NOT a gdcmObject ...
496 // gdcmDicomDirPatient *p = new gdcmDicomDirPatient(ptagHT);
497 // FillObject(elemList);
498 // patients.push_front( p );
500 /// \todo TODO : find a trick to use FillObject !!!
502 gdcmSQItem *s = new gdcmSQItem(0);
504 // for all the DicomDirPatient Elements
505 for( it = elemList.begin(); it != elemList.end(); ++it )
509 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
510 entry = new gdcmValEntry( dictEntry );
511 entry->SetOffset(0); // just to avoid further missprinting
512 entry->SetValue( it->value );
514 // dealing with value length ...
516 if( dictEntry->GetGroup() == 0xfffe)
518 entry->SetLength(entry->GetValue().length());
520 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
522 entry->SetLength( 4 );
524 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
528 else if( dictEntry->GetVR() == "SQ" )
530 entry->SetLength( 0xffffffff );
534 entry->SetLength( entry->GetValue().length() );
536 s->AddDocEntry( entry );
539 gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &TagHT);
540 patients.push_front( p );
546 * \brief adds to the HTable
547 * the gdcmEntries (Dicom Elements) corresponding to the given type
548 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
549 * @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT,
550 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
551 * @param header gdcmHeader of the current file
553 void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
554 gdcmDocument *header)
556 std::list<gdcmElement> elemList;
557 std::list<gdcmElement>::iterator it;
558 uint16_t tmpGr, tmpEl;
559 gdcmDictEntry *dictEntry;
562 gdcmSQItem *si = new gdcmSQItem(0); // all the items will be at level 1
565 case GDCM_DICOMDIR_IMAGE:
566 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
569 case GDCM_DICOMDIR_SERIE:
570 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements();
573 case GDCM_DICOMDIR_STUDY:
574 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
577 case GDCM_DICOMDIR_PATIENT:
578 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
581 case GDCM_DICOMDIR_META:
582 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
583 // add already done ?
589 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
590 // to avoid further troubles
591 // imageElem 0008 1140 "" // Referenced Image Sequence
592 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
593 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
594 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
595 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
596 // for all the relevant elements found in their own spot of the DicomDir.dic
597 // FIXME : troubles found when it's a SeqEntry
599 for( it = elemList.begin(); it != elemList.end(); ++it)
603 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
605 entry = new gdcmValEntry( dictEntry ); // Be sure it's never a BinEntry !
607 entry->SetOffset(0); // just to avoid further missprinting
608 entry->SetLength(0); // just to avoid further missprinting
610 if( header ) // NULL when we Build Up (ex nihilo) a DICOMDIR
611 // or when we add the META elems
612 val = header->GetEntryByNumber(tmpGr, tmpEl);
616 if( val == GDCM_UNFOUND)
618 if( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
620 // force to the *end* File Name
621 val = GetName( path );
623 else if( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
625 if( header->GetFileName().substr(0, path.length()) != path )
627 dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path"
628 " of file name is incorrect");
629 val = header->GetFileName();
632 val = &(header->GetFileName().c_str()[path.length()]);
639 if ( header->GetEntryLengthByNumber(tmpGr,tmpEl) == 0 )
643 // GDCM_UNFOUND or not !
645 entry->SetValue( val ); // troubles expected when vr=SQ ...
649 if( dictEntry->GetGroup() == 0xfffe )
651 entry->SetLength( entry->GetValue().length() ); // FIXME
653 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
657 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
661 else if( dictEntry->GetVR() == "SQ" )
663 entry->SetLength( 0xffffffff );
667 entry->SetLength( entry->GetValue().length() );
671 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
673 std::cout << " special Treatment for GDCM_DICOMDIR_META" << std::endl;
674 entry->Print(); // just to see
680 case GDCM_DICOMDIR_IMAGE:
681 AddDicomDirImageToEnd(si);
684 case GDCM_DICOMDIR_SERIE:
685 AddDicomDirSerieToEnd(si);
688 case GDCM_DICOMDIR_STUDY:
689 AddDicomDirStudyToEnd(si);
692 case GDCM_DICOMDIR_PATIENT:
693 AddDicomDirPatientToEnd(si);
699 //int count=1; // find a trick to increment
700 //s->AddEntry(si, count); // Seg Faults
705 * \brief CallStartMethod
707 void gdcmDicomDir::CallStartMethod()
713 startMethod( startArg );
718 * \ingroup gdcmDicomDir
719 * \brief CallProgressMethod
721 void gdcmDicomDir::CallProgressMethod()
725 progressMethod( progressArg );
730 * \ingroup gdcmDicomDir
731 * \brief CallEndMethod
733 void gdcmDicomDir::CallEndMethod()
742 //-----------------------------------------------------------------------------
745 * \ingroup gdcmDicomDir
746 * \brief create a 'gdcmDicomDir' from a DICOMDIR gdcmHeader
748 void gdcmDicomDir::CreateDicomDir()
750 // The list is parsed.
751 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
752 // 1 - we save the beginning iterator
753 // 2 - we continue to parse
754 // 3 - we find an other tag
755 // + we create the object for the precedent tag
758 // Directory record sequence
759 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
762 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
763 " sequence (0x0004,0x1220)");
764 /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?
768 gdcmSeqEntry* s = dynamic_cast<gdcmSeqEntry*>(e);
771 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: no SeqEntry present");
772 // useless : (0x0004,0x1220) IS a Sequence !
776 gdcmDicomDirType type = gdcmDicomDir::GDCM_DICOMDIR_META;
777 metaElems = NewMeta();
779 ListSQItem listItems = s->GetSQItems();
783 for( ListSQItem::iterator i = listItems.begin();
784 i !=listItems.end(); ++i )
786 d = (*i)->GetDocEntryByNumber(0x0004, 0x1430); // Directory Record Type
787 if ( gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(d) )
789 v = ValEntry->GetValue();
793 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: not a ValEntry.");
797 if( v == "PATIENT " )
799 AddDicomDirPatientToEnd( *i );
800 type = gdcmDicomDir::GDCM_DICOMDIR_PATIENT;
802 else if( v == "STUDY " )
804 AddDicomDirStudyToEnd( *i );
805 type = gdcmDicomDir::GDCM_DICOMDIR_STUDY;
807 else if( v == "SERIES" )
809 AddDicomDirSerieToEnd( *i );
810 type = gdcmDicomDir::GDCM_DICOMDIR_SERIE;
812 else if( v == "IMAGE " )
814 AddDicomDirImageToEnd( *i );
815 type = gdcmDicomDir::GDCM_DICOMDIR_IMAGE;
819 // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
820 // neither an 'IMAGE' SQItem. Skip to next item.
827 * \ingroup gdcmDicomDir
828 * \brief Well ... there is only one occurence
830 void gdcmDicomDir::AddDicomDirMeta()
836 metaElems = new gdcmDicomDirMeta( &TagHT );
840 * \ingroup gdcmDicomDir
841 * \brief AddDicomDirPatientToEnd
842 * @param s SQ Item to enqueue to the DicomPatient chained List
844 void gdcmDicomDir::AddDicomDirPatientToEnd(gdcmSQItem *s)
846 patients.push_back(new gdcmDicomDirPatient(s, &TagHT));
850 * \ingroup gdcmDicomDir
851 * \brief AddDicomDirStudyToEnd
852 * @param s SQ Item to enqueue to the DicomDirStudy chained List
854 void gdcmDicomDir::AddDicomDirStudyToEnd(gdcmSQItem *s)
856 if( patients.size() > 0 )
858 ListDicomDirPatient::iterator itp = patients.end();
860 (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(s, &TagHT));
865 * \ingroup gdcmDicomDir
866 * \brief AddDicomDirSerieToEnd
867 * @param s SQ Item to enqueue to the DicomDirSerie chained List
869 void gdcmDicomDir::AddDicomDirSerieToEnd(gdcmSQItem *s)
871 if( patients.size() > 0 )
873 ListDicomDirPatient::iterator itp = patients.end();
876 if( (*itp)->GetDicomDirStudies().size() > 0 )
878 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
880 (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(s, &TagHT));
886 * \ingroup gdcmDicomDir
887 * \brief AddDicomDirImageToEnd
888 * @param s SQ Item to enqueue to the DicomDirImage chained List
890 void gdcmDicomDir::AddDicomDirImageToEnd(gdcmSQItem *s)
892 if( patients.size() > 0 )
894 ListDicomDirPatient::iterator itp = patients.end();
897 if( (*itp)->GetDicomDirStudies().size() > 0 )
899 ListDicomDirStudy::iterator itst = (*itp)->GetDicomDirStudies().end();
902 if( (*itst)->GetDicomDirSeries().size() > 0 )
904 ListDicomDirSerie::iterator its = (*itst)->GetDicomDirSeries().end();
906 (*its)->AddDicomDirImage(new gdcmDicomDirImage(s, &TagHT));
913 * \ingroup gdcmDicomDir
914 * \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info
915 * @param path path of the root directory
916 * @param list chained list of Headers
918 void gdcmDicomDir::SetElements(std::string &path, VectDocument &list)
920 std::string patPrevName = "", patPrevID = "";
921 std::string studPrevInstanceUID = "", studPrevID = "";
922 std::string serPrevInstanceUID = "", serPrevID = "";
924 std::string patCurName, patCurID;
925 std::string studCurInstanceUID, studCurID;
926 std::string serCurInstanceUID, serCurID;
928 //SetElement( path, GDCM_DICOMDIR_META,NULL); // already done (NewMeta)
930 for( VectDocument::iterator it = list.begin();
931 it != list.end(); ++it )
933 // get the current file characteristics
934 patCurName = (*it)->GetEntryByNumber(0x0010,0x0010);
935 patCurID = (*it)->GetEntryByNumber(0x0010,0x0011);
936 studCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000d);
937 studCurID = (*it)->GetEntryByNumber(0x0020,0x0010);
938 serCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000e);
939 serCurID = (*it)->GetEntryByNumber(0x0020,0x0011);
941 if( patCurName != patPrevName || patCurID != patPrevID)
943 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
946 // if new Study Deal with 'STUDY' Elements
947 if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID )
949 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
952 // if new Serie Deal with 'SERIE' Elements
953 if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID )
955 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
958 // Always Deal with 'IMAGE' Elements
959 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
961 patPrevName = patCurName;
962 patPrevID = patCurID;
963 studPrevInstanceUID = studCurInstanceUID;
964 studPrevID = studCurID;
965 serPrevInstanceUID = serCurInstanceUID;
966 serPrevID = serCurID;
971 * \ingroup gdcmDicomDir
972 * \brief compares two dgcmHeaders
974 bool gdcmDicomDir::HeaderLessThan(gdcmDocument *header1, gdcmDocument *header2)
976 return *header1 < *header2;
980 * \brief Sets the accurate value for the (0x0004,0x1220) element of a DICOMDIR
982 void gdcmDicomDir::UpdateDirectoryRecordSequenceLength()
985 /// \todo FIXME : to go on compiling
987 /// to be re written !
989 /// ListTag::iterator it;
992 /// for(it=listEntries.begin();it!=listEntries.end();++it) {
993 /// gr = (*it)->GetGroup();
994 /// el = (*it)->GetElement();
995 /// vr = (*it)->GetVR();
996 /// if (gr !=0xfffe) {
997 /// if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) {
998 /// offset += 4; // explicit VR AND OB, OW, SQ : 4 more bytes
1000 /// offset += 2 + 2 + 4 + (*it)->GetLength();
1002 /// offset += 4; // delimiters don't have a value.
1005 /// //bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
1006 /// SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
1011 //-----------------------------------------------------------------------------