1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2004/07/17 22:36:55 $
7 Version: $Revision: 1.56 $
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>
30 #include "gdcmDicomDir.h"
31 #include "gdcmDicomDirStudy.h"
32 #include "gdcmDicomDirSerie.h"
33 #include "gdcmDicomDirImage.h"
34 #include "gdcmDirList.h"
36 #include "gdcmDebug.h"
37 #include "gdcmGlobal.h"
38 #include "gdcmHeader.h"
39 #include "gdcmSeqEntry.h"
40 #include "gdcmSQItem.h"
41 #include "gdcmValEntry.h"
43 //-----------------------------------------------------------------------------
44 // For full DICOMDIR description, see:
45 // PS 3.3-2003, pages 731-750
46 //-----------------------------------------------------------------------------
47 // Constructor / Destructor
49 void gdcmDicomDir::Initialize()
52 progressMethod = NULL;
54 startMethodArgDelete = NULL;
55 progressMethodArgDelete = NULL;
56 endMethodArgDelete = NULL;
64 metaElems = (gdcmDicomDirMeta *)0;
69 * \brief Constructor Parses recursively the directory and creates the DicomDir
70 * or uses an already built DICOMDIR, depending on 'parseDir' value.
71 * @param FileName name
72 * - of the root directory (parseDir = true)
73 * - of the DICOMDIR (parseDir = false)
74 * @param parseDir boolean
75 * - true if user passed an entry point
76 * and wants to explore recursively the directories
77 * - false if user passed an already built DICOMDIR file
79 * @param exception_on_error whether we want to throw an exception or not
81 gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir,
82 bool exception_on_error):
83 gdcmDocument( fileName, exception_on_error, true) // true : enable SeQuences
85 // que l'on ai passe un root directory ou un DICOMDIR
86 // et quelle que soit la valeur de parseDir,
87 // on a deja lance gdcmDocument
90 // gdcmDocument already executed
91 // if user passed a root directory, sure we didn't get anything
93 if( GetEntry().begin() == GetEntry().end() )
95 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry HT empty");
97 if( fileName.size() == 1 && fileName[0] == '.' )
99 // user passed '.' as Name
100 // we get current directory name
101 char* dummy = new char[1000];
102 getcwd(dummy, (size_t)1000);
103 SetFileName( dummy ); // will be converted into a string
104 delete[] dummy; // no longer needed
109 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory"
110 " and create the DicomDir");
115 /// \todo if parseDir == false, it should be tagged as an error
120 // Directory record sequence
121 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
124 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
125 " sequence (0x0004,0x1220)");
126 /// \todo FIXME : what do we do when the parsed file IS NOT a
134 * \ingroup gdcmDicomDir
135 * \brief Constructor : creates an empty gdcmDicomDir
136 * @param exception_on_error whether we want to throw an exception or not
138 gdcmDicomDir::gdcmDicomDir(bool exception_on_error):
139 gdcmDocument( exception_on_error )
143 std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...
144 SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements
149 * \brief Canonical destructor
151 gdcmDicomDir::~gdcmDicomDir()
153 SetStartMethod(NULL);
154 SetProgressMethod(NULL);
162 for(ListDicomDirPatient::iterator cc = patients.begin();
170 //-----------------------------------------------------------------------------
173 * \brief Canonical Printer
175 void gdcmDicomDir::Print(std::ostream &os)
179 metaElems->SetPrintLevel(printLevel);
180 metaElems->Print(os);
182 for(ListDicomDirPatient::iterator cc = patients.begin();
183 cc != patients.end();
186 (*cc)->SetPrintLevel( printLevel );
191 //-----------------------------------------------------------------------------
194 * \brief This predicate, based on hopefully reasonable heuristics,
195 * decides whether or not the current header was properly parsed
196 * and contains the mandatory information for being considered as
197 * a well formed and usable DicomDir.
198 * @return true when gdcmDocument is the one of a reasonable DicomDir,
201 bool gdcmDicomDir::IsReadable()
203 if( !gdcmDocument::IsReadable() )
211 if( patients.size() <= 0 )
220 * \ingroup gdcmDicomDir
221 * \brief fills the whole structure, starting from a root Directory
223 void gdcmDicomDir::ParseDirectory()
225 CreateDicomDirChainedList( GetFileName() );
230 * \ingroup gdcmDicomDir
231 * \brief Set the start method to call when the parsing of the directory starts
232 * @param method Method to call
233 * @param arg Argument to pass to the method
234 * @param argDelete Argument
235 * \warning In python : the arg parameter isn't considered
237 void gdcmDicomDir::SetStartMethod(gdcmMethod *method, void *arg,
238 gdcmMethod *argDelete )
240 if( startArg && startMethodArgDelete )
242 startMethodArgDelete( startArg );
245 startMethod = method;
247 startMethodArgDelete = argDelete;
251 * \ingroup gdcmDicomDir
252 * \brief Set the method to delete the argument
253 * The argument is destroyed when the method is changed or when the
255 * @param method Method to call to delete the argument
257 void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod *method)
259 startMethodArgDelete = method;
263 * \ingroup gdcmDicomDir
264 * \brief Set the progress method to call when the parsing of the directory progress
265 * @param method Method to call
266 * @param arg Argument to pass to the method
267 * @param argDelete Argument
268 * \warning In python : the arg parameter isn't considered
270 void gdcmDicomDir::SetProgressMethod(gdcmMethod *method, void *arg,
271 gdcmMethod *argDelete )
273 if( progressArg && progressMethodArgDelete )
275 progressMethodArgDelete( progressArg );
278 progressMethod = method;
280 progressMethodArgDelete = argDelete;
284 * \ingroup gdcmDicomDir
285 * \brief Set the method to delete the argument
286 * The argument is destroyed when the method is changed or when the
288 * @param method Method to call to delete the argument
290 void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod *method)
292 progressMethodArgDelete = method;
296 * \ingroup gdcmDicomDir
297 * \brief Set the end method to call when the parsing of the directory ends
298 * @param method Method to call
299 * @param arg Argument to pass to the method
300 * @param argDelete Argument
301 * \warning In python : the arg parameter isn't considered
303 void gdcmDicomDir::SetEndMethod(gdcmMethod *method, void *arg,
304 gdcmMethod *argDelete )
306 if( endArg && endMethodArgDelete )
308 endMethodArgDelete( endArg );
313 endMethodArgDelete = argDelete;
317 * \ingroup gdcmDicomDir
318 * \brief Set the method to delete the argument
319 * The argument is destroyed when the method is changed or when the class
321 * @param method Method to call to delete the argument
323 void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod *method)
325 endMethodArgDelete = method;
329 * \ingroup gdcmDicomDir
330 * \brief writes on disc a DICOMDIR
331 * \ warning does NOT add the missing elements in the header :
332 * it's up to the user doing it !
333 * \todo : to be re-written using the DICOMDIR tree-like structure
334 * *not* the chained list
335 * (does NOT exist if the DICOMDIR is user-forged !)
336 * @param fileName file to be written to
337 * @return false only when fail to open
340 bool gdcmDicomDir::Write(std::string const & fileName)
344 fp1 = fopen(fileName.c_str(), "wb");
347 printf("Failed to open(write) File [%s] \n", fileName.c_str());
351 char * filePreamble = new char[128];
352 fwrite(filePreamble,128,1,fp1);
353 fwrite("DICM",4,1,fp1);
354 delete[] filePreamble;
355 UpdateDirectoryRecordSequenceLength();
363 * \brief Writes in a file using the tree-like structure.
364 * @param _fp already open file pointer
367 void gdcmDicomDir::WriteEntries(FILE *) //_fp
369 /// \todo (?) tester les echecs en ecriture
370 /// (apres chaque fwrite, dans le WriteEntry)
373 /* TODO : to go on compiling
375 gdcmDicomDirMeta *ptrMeta;
376 ListDicomDirPatient::iterator itPatient;
377 ListDicomDirStudy::iterator itStudy;
378 ListDicomDirSerie::iterator itSerie;
379 ListDicomDirImage::iterator itImage;
382 ptrMeta= GetDicomDirMeta();
383 for(i=ptrMeta->debut();i!=ptrMeta->fin();++i) {
384 WriteEntry(*i,_fp, gdcmExplicitVR);
387 itPatient = GetDicomDirPatients().begin();
388 while ( itPatient != GetDicomDirPatients().end() ) {
389 for(i=(*itPatient)->debut();i!=(*itPatient)->fin();++i) {
390 WriteEntry(*i,_fp, gdcmExplicitVR);
392 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
393 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) {
394 for(i=(*itStudy)->debut();i!=(*itStudy)->fin();++i) {
395 WriteEntry(*i,_fp, gdcmExplicitVR);
397 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
398 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) {
399 for(i=(*itSerie)->debut();i!=(*itSerie)->fin();++i) {
400 WriteEntry(*i,_fp, gdcmExplicitVR);
402 itImage = ((*itSerie)->GetDicomDirImages()).begin();
403 while (itImage != (*itSerie)->GetDicomDirImages().end() ) {
404 for(i=(*itImage)->debut();i!=(*itImage)->fin();++i) {
405 WriteEntry(*i,_fp, gdcmExplicitVR);
418 //-----------------------------------------------------------------------------
422 * \ingroup gdcmDicomDir
423 * \brief create a gdcmDocument-like chained list from a root Directory
424 * @param path entry point of the tree-like structure
426 void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path)
429 gdcmDirList fileList(path,1); // gets recursively the file list
430 unsigned int count = 0;
437 for( gdcmDirList::iterator it = fileList.begin();
438 it != fileList.end();
441 progress = (float)(count+1)/(float)fileList.size();
442 CallProgressMethod();
448 header = new gdcmHeader(it->c_str(),false,true);
450 std::cout << "echec new Header " << it->c_str() << std::endl; // JPR
452 if(header->IsReadable()) {
453 list.push_back(header); // adds the file header to the chained list
454 std::cout << "readable : " <<it->c_str() << std::endl; // JPR
463 // sorts Patient/Study/Serie/
464 std::sort(list.begin(), list.end(), gdcmDicomDir::HeaderLessThan );
466 std::string tmp = fileList.GetDirName();
468 //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
469 SetElements(tmp, list);
475 * \ingroup gdcmDicomDir
476 * \brief adds *the* Meta to a partially created DICOMDIR
479 /// \todo FIXME : Heuuuuu ! Il prend les Entries du Document deja parse,
480 /// il ne fabrique rien !
482 gdcmDicomDirMeta * gdcmDicomDir::NewMeta()
484 gdcmDicomDirMeta *m = new gdcmDicomDirMeta( &tagHT );
485 for ( TagDocEntryHT::iterator cc = tagHT.begin();
486 cc != tagHT.end(); ++cc)
488 m->AddDocEntry( cc->second );
495 * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
497 gdcmDicomDirPatient * gdcmDicomDir::NewPatient()
499 std::list<gdcmElement>::iterator it;
500 uint16_t tmpGr,tmpEl;
501 gdcmDictEntry *dictEntry;
504 gdcmSQItem *s = new gdcmSQItem(0);
506 std::list<gdcmElement> elemList =
507 gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
509 /// \todo TODO : use FillObject !!!
511 // for all the DicomDirPatient Elements
513 for( it = elemList.begin(); it != elemList.end(); ++it )
517 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
518 entry = new gdcmValEntry( dictEntry );
519 entry->SetOffset(0); // just to avoid further missprinting
520 entry->SetValue( it->value );
522 // dealing with value length ...
524 if( dictEntry->GetGroup() == 0xfffe)
526 entry->SetLength(entry->GetValue().length());
528 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
530 entry->SetLength( 4 );
532 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
536 else if( dictEntry->GetVR() == "SQ" )
538 entry->SetLength( 0xffffffff );
542 entry->SetLength( entry->GetValue().length() );
544 s->AddDocEntry( entry );
547 gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &tagHT);
548 patients.push_front( p );
554 * \brief adds to the HTable
555 * the gdcmEntries (Dicom Elements) corresponding to the given type
556 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
557 * @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT,
558 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
559 * @param header gdcmHeader of the current file
561 void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
562 gdcmDocument *header)
564 std::list<gdcmElement> elemList;
565 std::list<gdcmElement>::iterator it;
566 uint16_t tmpGr, tmpEl;
567 gdcmDictEntry *dictEntry;
573 case GDCM_DICOMDIR_PATIENT:
574 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
576 case GDCM_DICOMDIR_STUDY:
577 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
579 case GDCM_DICOMDIR_SERIE:
580 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements();
582 case GDCM_DICOMDIR_IMAGE:
583 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
585 case GDCM_DICOMDIR_META:
586 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
592 for( it = elemList.begin(); it != elemList.end(); ++it)
596 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
597 entry = new gdcmValEntry( dictEntry ); // Be sure it's never a BinEntry !
599 entry->SetOffset(0); // just to avoid further missprinting
603 val = header->GetEntryByNumber(tmpGr, tmpEl);
610 if( val == GDCM_UNFOUND)
612 if( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
614 // force to the *end* File Name
615 val = GetName( path );
617 else if( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
619 if( header->GetFileName().substr(0, path.length()) != path )
621 dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path"
622 " of file name is incorrect");
623 val = header->GetFileName();
627 val = &(header->GetFileName().c_str()[path.length()]);
637 if ( header->GetEntryLengthByNumber(tmpGr,tmpEl) == 0 )
643 entry->SetValue( val );
647 if( dictEntry->GetGroup() == 0xfffe )
649 entry->SetLength( entry->GetValue().length() );
651 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
655 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
659 else if( dictEntry->GetVR() == "SQ" )
661 entry->SetLength( 0xffffffff );
665 entry->SetLength( entry->GetValue().length() );
668 //AddDocEntry(entry); // both in H Table and in chained list
669 tagHT[entry->GetKey()] = entry; // FIXME : use a SEQUENCE !
674 * \brief CallStartMethod
676 void gdcmDicomDir::CallStartMethod()
682 startMethod( startArg );
687 * \ingroup gdcmDicomDir
688 * \brief CallProgressMethod
690 void gdcmDicomDir::CallProgressMethod()
694 progressMethod( progressArg );
699 * \ingroup gdcmDicomDir
700 * \brief CallEndMethod
702 void gdcmDicomDir::CallEndMethod()
711 //-----------------------------------------------------------------------------
714 * \ingroup gdcmDicomDir
715 * \brief create a 'gdcmDicomDir' from a DICOMDIR gdcmHeader
717 void gdcmDicomDir::CreateDicomDir()
719 // The list is parsed.
720 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
721 // 1 - we save the beginning iterator
722 // 2 - we continue to parse
723 // 3 - we find an other tag
724 // + we create the object for the precedent tag
727 gdcmDicomDirType type = gdcmDicomDir::GDCM_DICOMDIR_META;
729 // Directory record sequence
730 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
733 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
734 " sequence (0x0004,0x1220)");
735 /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?
739 gdcmSeqEntry* s = dynamic_cast<gdcmSeqEntry*>(e);
742 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: no SeqEntry present");
746 ListSQItem listItems = s->GetSQItems();
747 gdcmDicomDirMeta *m = new gdcmDicomDirMeta(&tagHT);
752 for( ListSQItem::iterator i = listItems.begin();
753 i !=listItems.end(); ++i )
755 d = (*i)->GetDocEntryByNumber(0x0004, 0x1430); // Directory Record Type
756 if ( gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(d) )
758 v = ValEntry->GetValue();
762 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: not a ValEntry.");
766 if( v == "PATIENT " )
768 AddDicomDirPatientToEnd( *i );
769 //AddObjectToEnd(type,*i);
770 type = gdcmDicomDir::GDCM_DICOMDIR_PATIENT;
772 else if( v == "STUDY " )
774 AddDicomDirStudyToEnd( *i );
775 // AddObjectToEnd(type,*i);
776 type = gdcmDicomDir::GDCM_DICOMDIR_STUDY;
778 else if( v == "SERIES" )
780 AddDicomDirSerieToEnd( *i );
781 // AddObjectToEnd(type,*i);
782 type = gdcmDicomDir::GDCM_DICOMDIR_SERIE;
784 else if( v == "IMAGE " )
786 AddDicomDirImageToEnd( *i );
787 // AddObjectToEnd(type,*i);
788 type = gdcmDicomDir::GDCM_DICOMDIR_IMAGE;
792 // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
793 // neither an 'IMAGE' SQItem. Skip to next item.
800 * \ingroup gdcmDicomDir
801 * \brief AddObjectToEnd
803 * @param begin iterator on the first DocEntry within the chained List
804 * @param end iterator on the last DocEntry within the chained List
809 /*void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,gdcmSQItem *s)
816 case gdcmDicomDir::GDCM_DICOMDIR_META:
819 case gdcmDicomDir::GDCM_DICOMDIR_PATIENT:
820 AddDicomDirPatientToEnd(s);
822 case gdcmDicomDir::GDCM_DICOMDIR_STUDY:
823 AddDicomDirStudyToEnd(s);
825 case gdcmDicomDir::GDCM_DICOMDIR_SERIE:
826 AddDicomDirSerieToEnd(s);
828 case gdcmDicomDir::GDCM_DICOMDIR_IMAGE:
829 AddDicomDirImageToEnd(s);
831 case gdcmDicomDir::GDCM_DICOMDIR_NONE:
832 AddDicomDirImageToEnd(s); //FIXME
840 * \ingroup gdcmDicomDir
841 * \brief Well ... there is only one occurence
843 void gdcmDicomDir::AddDicomDirMeta()
849 metaElems = new gdcmDicomDirMeta( &tagHT );
853 * \ingroup gdcmDicomDir
854 * \brief AddDicomDirPatientToEnd
855 * @param s SQ Item to enqueue to the DicomPatient chained List
857 void gdcmDicomDir::AddDicomDirPatientToEnd(gdcmSQItem *s)
859 patients.push_back(new gdcmDicomDirPatient(s, &tagHT));
863 * \ingroup gdcmDicomDir
864 * \brief AddDicomDirStudyToEnd
865 * @param s SQ Item to enqueue to the DicomDirStudy chained List
867 void gdcmDicomDir::AddDicomDirStudyToEnd(gdcmSQItem *s)
869 if( patients.size() > 0 )
871 ListDicomDirPatient::iterator itp = patients.end();
873 (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(s, &tagHT));
878 * \ingroup gdcmDicomDir
879 * \brief AddDicomDirSerieToEnd
880 * @param s SQ Item to enqueue to the DicomDirSerie chained List
882 void gdcmDicomDir::AddDicomDirSerieToEnd(gdcmSQItem *s)
884 if( patients.size() > 0 )
886 ListDicomDirPatient::iterator itp = patients.end();
889 if( (*itp)->GetDicomDirStudies().size() > 0 )
891 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
893 (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(s, &tagHT));
899 * \ingroup gdcmDicomDir
900 * \brief AddDicomDirImageToEnd
901 * @param s SQ Item to enqueue to the DicomDirImage chained List
903 void gdcmDicomDir::AddDicomDirImageToEnd(gdcmSQItem *s)
905 if( patients.size() > 0 )
907 ListDicomDirPatient::iterator itp = patients.end();
910 if( (*itp)->GetDicomDirStudies().size() > 0 )
912 ListDicomDirStudy::iterator itst = (*itp)->GetDicomDirStudies().end();
915 if( (*itst)->GetDicomDirSeries().size() > 0 )
917 ListDicomDirSerie::iterator its = (*itst)->GetDicomDirSeries().end();
919 (*its)->AddDicomDirImage(new gdcmDicomDirImage(s, &tagHT));
926 * \ingroup gdcmDicomDir
927 * \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info
928 * @param path path of the root directory
929 * @param list chained list of Headers
931 void gdcmDicomDir::SetElements(std::string &path, VectDocument &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;
941 SetElement( path, GDCM_DICOMDIR_META,NULL);
943 for( VectDocument::iterator it = list.begin();
944 it != list.end(); ++it )
946 // get the current file characteristics
947 patCurName = (*it)->GetEntryByNumber(0x0010,0x0010);
948 patCurID = (*it)->GetEntryByNumber(0x0010,0x0011);
949 studCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000d);
950 studCurID = (*it)->GetEntryByNumber(0x0020,0x0010);
951 serCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000e);
952 serCurID = (*it)->GetEntryByNumber(0x0020,0x0011);
954 if( patCurName != patPrevName || patCurID != patPrevID)
956 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
959 // if new Study Deal with 'STUDY' Elements
960 if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID )
962 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
965 // if new Serie Deal with 'SERIE' Elements
966 if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID )
968 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
971 // Always Deal with 'IMAGE' Elements
972 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
974 patPrevName = patCurName;
975 patPrevID = patCurID;
976 studPrevInstanceUID = studCurInstanceUID;
977 studPrevID = studCurID;
978 serPrevInstanceUID = serCurInstanceUID;
979 serPrevID = serCurID;
984 * \ingroup gdcmDicomDir
985 * \brief compares two dgcmHeaders
987 bool gdcmDicomDir::HeaderLessThan(gdcmDocument *header1, gdcmDocument *header2)
989 return *header1 < *header2;
993 * \brief Sets the accurate value for the (0x0004,0x1220) element of a DICOMDIR
995 void gdcmDicomDir::UpdateDirectoryRecordSequenceLength()
998 /// \todo FIXME : to go on compiling
1000 /// to be re written !
1002 /// ListTag::iterator it;
1003 /// uint16_t gr, el;
1005 /// for(it=listEntries.begin();it!=listEntries.end();++it) {
1006 /// gr = (*it)->GetGroup();
1007 /// el = (*it)->GetElement();
1008 /// vr = (*it)->GetVR();
1009 /// if (gr !=0xfffe) {
1010 /// if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) {
1011 /// offset += 4; // explicit VR AND OB, OW, SQ : 4 more bytes
1013 /// offset += 2 + 2 + 4 + (*it)->GetLength();
1015 /// offset += 4; // delimiters don't have a value.
1018 /// //bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
1019 /// SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
1024 //-----------------------------------------------------------------------------