1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2004/07/27 15:04:10 $
7 Version: $Revision: 1.59 $
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
50 * \ingroup gdcmDicomDir
51 * \brief Constructor : creates an empty gdcmDicomDir
52 * @param exception_on_error whether we want to throw an exception or not
54 gdcmDicomDir::gdcmDicomDir(bool exception_on_error):
55 gdcmDocument( exception_on_error )
59 std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...
60 SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements
65 * \brief Constructor Parses recursively the directory and creates the DicomDir
66 * or uses an already built DICOMDIR, depending on 'parseDir' value.
67 * @param FileName name
68 * - of the root directory (parseDir = true)
69 * - of the DICOMDIR (parseDir = false)
70 * @param parseDir boolean
71 * - true if user passed an entry point
72 * and wants to explore recursively the directories
73 * - false if user passed an already built DICOMDIR file
75 * @param exception_on_error whether we want to throw an exception or not
77 gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir,
78 bool exception_on_error):
79 gdcmDocument( fileName, exception_on_error, true) // true : enable SeQuences
81 // que l'on ai passe un root directory ou un DICOMDIR
82 // et quelle que soit la valeur de parseDir,
83 // on a deja lance gdcmDocument
86 // gdcmDocument already executed
87 // if user passed a root directory, sure we didn't get anything
89 if ( TagHT.begin() == TagHT.end() )
91 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry HT empty");
93 if ( fileName.size() == 1 && fileName[0] == '.' )
95 // user passed '.' as Name
96 // we get current directory name
97 char* dummy = new char[1000];
98 getcwd(dummy, (size_t)1000);
99 std::cout << "Directory to parse : [" << dummy << "]" << std::endl;
100 SetFileName( dummy ); // will be converted into a string
101 delete[] dummy; // no longer needed
106 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory"
107 " and create the DicomDir");
112 /// \todo if parseDir == false, it should be tagged as an error
113 // NON ! il suffit d'appeler ParseDirectory()
114 // apres le constructeur
119 // Directory record sequence
120 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
123 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
124 " sequence (0x0004,0x1220)");
125 /// \todo FIXME : what do we do when the parsed file IS NOT a
133 * \brief Canonical destructor
135 gdcmDicomDir::~gdcmDicomDir()
137 SetStartMethod(NULL);
138 SetProgressMethod(NULL);
146 for(ListDicomDirPatient::iterator cc = patients.begin();
154 //-----------------------------------------------------------------------------
157 * \brief Canonical Printer
159 void gdcmDicomDir::Print(std::ostream &os)
163 metaElems->SetPrintLevel(PrintLevel);
164 metaElems->Print(os);
166 for(ListDicomDirPatient::iterator cc = patients.begin();
167 cc != patients.end();
170 (*cc)->SetPrintLevel( PrintLevel );
175 //-----------------------------------------------------------------------------
178 * \brief This predicate, based on hopefully reasonable heuristics,
179 * decides whether or not the current header was properly parsed
180 * and contains the mandatory information for being considered as
181 * a well formed and usable DicomDir.
182 * @return true when gdcmDocument is the one of a reasonable DicomDir,
185 bool gdcmDicomDir::IsReadable()
187 if( !gdcmDocument::IsReadable() )
195 if( patients.size() <= 0 )
204 * \brief Sets all fields to NULL
207 void gdcmDicomDir::Initialize()
210 progressMethod = NULL;
212 startMethodArgDelete = NULL;
213 progressMethodArgDelete = NULL;
214 endMethodArgDelete = NULL;
222 metaElems = (gdcmDicomDirMeta *)0;
227 * \ingroup gdcmDicomDir
228 * \brief fills the whole structure, starting from a root Directory
230 void gdcmDicomDir::ParseDirectory()
232 CreateDicomDirChainedList( GetFileName() );
237 * \ingroup gdcmDicomDir
238 * \brief Set the start method to call when the parsing of the directory starts
239 * @param method Method to call
240 * @param arg Argument to pass to the method
241 * @param argDelete Argument
242 * \warning In python : the arg parameter isn't considered
244 void gdcmDicomDir::SetStartMethod(gdcmMethod *method, void *arg,
245 gdcmMethod *argDelete )
247 if( startArg && startMethodArgDelete )
249 startMethodArgDelete( startArg );
252 startMethod = method;
254 startMethodArgDelete = argDelete;
258 * \ingroup gdcmDicomDir
259 * \brief Set the method to delete the argument
260 * The argument is destroyed when the method is changed or when the
262 * @param method Method to call to delete the argument
264 void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod *method)
266 startMethodArgDelete = method;
270 * \ingroup gdcmDicomDir
271 * \brief Set the progress method to call when the parsing of the directory progress
272 * @param method Method to call
273 * @param arg Argument to pass to the method
274 * @param argDelete Argument
275 * \warning In python : the arg parameter isn't considered
277 void gdcmDicomDir::SetProgressMethod(gdcmMethod *method, void *arg,
278 gdcmMethod *argDelete )
280 if( progressArg && progressMethodArgDelete )
282 progressMethodArgDelete( progressArg );
285 progressMethod = method;
287 progressMethodArgDelete = argDelete;
291 * \ingroup gdcmDicomDir
292 * \brief Set the method to delete the argument
293 * The argument is destroyed when the method is changed or when the
295 * @param method Method to call to delete the argument
297 void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod *method)
299 progressMethodArgDelete = method;
303 * \ingroup gdcmDicomDir
304 * \brief Set the end method to call when the parsing of the directory ends
305 * @param method Method to call
306 * @param arg Argument to pass to the method
307 * @param argDelete Argument
308 * \warning In python : the arg parameter isn't considered
310 void gdcmDicomDir::SetEndMethod(gdcmMethod *method, void *arg,
311 gdcmMethod *argDelete )
313 if( endArg && endMethodArgDelete )
315 endMethodArgDelete( endArg );
320 endMethodArgDelete = argDelete;
324 * \ingroup gdcmDicomDir
325 * \brief Set the method to delete the argument
326 * The argument is destroyed when the method is changed or when the class
328 * @param method Method to call to delete the argument
330 void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod *method)
332 endMethodArgDelete = method;
336 * \ingroup gdcmDicomDir
337 * \brief writes on disc a DICOMDIR
338 * \ warning does NOT add the missing elements in the header :
339 * it's up to the user doing it !
340 * \todo : to be re-written using the DICOMDIR tree-like structure
341 * *not* the chained list
342 * (does NOT exist if the DICOMDIR is user-forged !)
343 * @param fileName file to be written to
344 * @return false only when fail to open
347 bool gdcmDicomDir::Write(std::string const & fileName)
351 fp1 = fopen(fileName.c_str(), "wb");
354 printf("Failed to open(write) File [%s] \n", fileName.c_str());
358 char * filePreamble = new char[128];
359 fwrite(filePreamble,128,1,fp1);
360 fwrite("DICM",4,1,fp1);
361 delete[] filePreamble;
362 UpdateDirectoryRecordSequenceLength();
370 * \brief Writes in a file using the tree-like structure.
371 * @param _fp already open file pointer
374 void gdcmDicomDir::WriteEntries(FILE *) //_fp
376 /// \todo (?) tester les echecs en ecriture
377 /// (apres chaque fwrite, dans le WriteEntry)
380 /* TODO : to go on compiling
382 gdcmDicomDirMeta *ptrMeta;
383 ListDicomDirPatient::iterator itPatient;
384 ListDicomDirStudy::iterator itStudy;
385 ListDicomDirSerie::iterator itSerie;
386 ListDicomDirImage::iterator itImage;
389 ptrMeta= GetDicomDirMeta();
390 for(i=ptrMeta->debut();i!=ptrMeta->fin();++i) {
391 WriteEntry(*i,_fp, gdcmExplicitVR);
394 itPatient = GetDicomDirPatients().begin();
395 while ( itPatient != GetDicomDirPatients().end() ) {
396 for(i=(*itPatient)->debut();i!=(*itPatient)->fin();++i) {
397 WriteEntry(*i,_fp, gdcmExplicitVR);
399 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
400 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) {
401 for(i=(*itStudy)->debut();i!=(*itStudy)->fin();++i) {
402 WriteEntry(*i,_fp, gdcmExplicitVR);
404 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
405 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) {
406 for(i=(*itSerie)->debut();i!=(*itSerie)->fin();++i) {
407 WriteEntry(*i,_fp, gdcmExplicitVR);
409 itImage = ((*itSerie)->GetDicomDirImages()).begin();
410 while (itImage != (*itSerie)->GetDicomDirImages().end() ) {
411 for(i=(*itImage)->debut();i!=(*itImage)->fin();++i) {
412 WriteEntry(*i,_fp, gdcmExplicitVR);
425 //-----------------------------------------------------------------------------
429 * \ingroup gdcmDicomDir
430 * \brief create a gdcmDocument-like chained list from a root Directory
431 * @param path entry point of the tree-like structure
433 void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path)
436 gdcmDirList fileList(path,1); // gets recursively the file list
437 unsigned int count = 0;
444 for( gdcmDirList::iterator it = fileList.begin();
445 it != fileList.end();
448 progress = (float)(count+1)/(float)fileList.size();
449 CallProgressMethod();
455 header = new gdcmHeader(it->c_str(),false,true);
457 std::cout << "failure in new Header " << it->c_str() << std::endl; // JPR
459 if(header->IsReadable()) {
460 list.push_back(header); // adds the file header to the chained list
461 std::cout << "readable : " <<it->c_str() << std::endl; // JPR
470 // sorts Patient/Study/Serie/
471 std::sort(list.begin(), list.end(), gdcmDicomDir::HeaderLessThan );
473 std::string tmp = fileList.GetDirName();
475 //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
476 SetElements(tmp, list);
482 * \ingroup gdcmDicomDir
483 * \brief adds *the* Meta to a partially created DICOMDIR
486 /// \todo FIXME : Heuuuuu ! Il prend les Entries du Document deja parse,
487 /// il ne fabrique rien !
489 gdcmDicomDirMeta * gdcmDicomDir::NewMeta()
491 gdcmDicomDirMeta *m = new gdcmDicomDirMeta( &TagHT );
492 for ( TagDocEntryHT::iterator cc = TagHT.begin();
493 cc != TagHT.end(); ++cc)
495 m->AddDocEntry( cc->second );
502 * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
504 gdcmDicomDirPatient * gdcmDicomDir::NewPatient()
506 std::list<gdcmElement>::iterator it;
507 uint16_t tmpGr,tmpEl;
508 gdcmDictEntry *dictEntry;
511 std::list<gdcmElement> elemList;
512 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
513 // Looks nice, but gdcmDicomDir IS NOT a gdcmObject ...
514 // gdcmDicomDirPatient *p = new gdcmDicomDirPatient(ptagHT);
515 // FillObject(elemList);
516 // patients.push_front( p );
518 /// \todo TODO : find a trick to use FillObject !!!
520 gdcmSQItem *s = new gdcmSQItem(0);
522 // for all the DicomDirPatient Elements
523 for( it = elemList.begin(); it != elemList.end(); ++it )
527 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
528 entry = new gdcmValEntry( dictEntry );
529 entry->SetOffset(0); // just to avoid further missprinting
530 entry->SetValue( it->value );
532 // dealing with value length ...
534 if( dictEntry->GetGroup() == 0xfffe)
536 entry->SetLength(entry->GetValue().length());
538 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
540 entry->SetLength( 4 );
542 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
546 else if( dictEntry->GetVR() == "SQ" )
548 entry->SetLength( 0xffffffff );
552 entry->SetLength( entry->GetValue().length() );
554 s->AddDocEntry( entry );
557 gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &TagHT);
558 patients.push_front( p );
564 * \brief adds to the HTable
565 * the gdcmEntries (Dicom Elements) corresponding to the given type
566 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
567 * @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT,
568 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
569 * @param header gdcmHeader of the current file
571 void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
572 gdcmDocument *header)
574 std::list<gdcmElement> elemList;
575 std::list<gdcmElement>::iterator it;
576 uint16_t tmpGr, tmpEl;
577 gdcmDictEntry *dictEntry;
583 case GDCM_DICOMDIR_IMAGE:
584 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
587 case GDCM_DICOMDIR_SERIE:
588 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements();
591 case GDCM_DICOMDIR_STUDY:
592 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
595 case GDCM_DICOMDIR_PATIENT:
596 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
599 case GDCM_DICOMDIR_META:
600 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
607 for( it = elemList.begin(); it != elemList.end(); ++it)
611 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
612 entry = new gdcmValEntry( dictEntry ); // Be sure it's never a BinEntry !
614 entry->SetOffset(0); // just to avoid further missprinting
616 if( header ) // NULL when we Build Up (ex nihilo) a DICOMDIR
617 // or when we add the META elems
619 val = header->GetEntryByNumber(tmpGr, tmpEl);
626 if( val == GDCM_UNFOUND)
628 if( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
630 // force to the *end* File Name
631 val = GetName( path );
633 else if( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
635 if( header->GetFileName().substr(0, path.length()) != path )
637 dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path"
638 " of file name is incorrect");
639 val = header->GetFileName();
643 val = &(header->GetFileName().c_str()[path.length()]);
653 if ( header->GetEntryLengthByNumber(tmpGr,tmpEl) == 0 )
659 entry->SetValue( val );
663 if( dictEntry->GetGroup() == 0xfffe )
665 entry->SetLength( entry->GetValue().length() ); // FIXME
667 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
671 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
675 else if( dictEntry->GetVR() == "SQ" )
677 entry->SetLength( 0xffffffff );
681 entry->SetLength( entry->GetValue().length() );
684 std::cout << " was TagHT[entry->GetKey()] = entry " << std::endl;
685 if ( type == GDCM_DICOMDIR_META ) {
686 std::cout << " special Treatment for GDCM_DICOMDIR_META" << std::endl;
689 //TagHT[entry->GetKey()] = entry; // FIXME : use a SEQUENCE !
694 * \brief CallStartMethod
696 void gdcmDicomDir::CallStartMethod()
702 startMethod( startArg );
707 * \ingroup gdcmDicomDir
708 * \brief CallProgressMethod
710 void gdcmDicomDir::CallProgressMethod()
714 progressMethod( progressArg );
719 * \ingroup gdcmDicomDir
720 * \brief CallEndMethod
722 void gdcmDicomDir::CallEndMethod()
731 //-----------------------------------------------------------------------------
734 * \ingroup gdcmDicomDir
735 * \brief create a 'gdcmDicomDir' from a DICOMDIR gdcmHeader
737 void gdcmDicomDir::CreateDicomDir()
739 // The list is parsed.
740 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
741 // 1 - we save the beginning iterator
742 // 2 - we continue to parse
743 // 3 - we find an other tag
744 // + we create the object for the precedent tag
747 // Directory record sequence
748 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
751 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
752 " sequence (0x0004,0x1220)");
753 /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?
757 gdcmSeqEntry* s = dynamic_cast<gdcmSeqEntry*>(e);
760 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: no SeqEntry present");
761 // useless : (0x0004,0x1220) IS a Sequence !
765 gdcmDicomDirType type = gdcmDicomDir::GDCM_DICOMDIR_META;
766 metaElems = NewMeta();
768 ListSQItem listItems = s->GetSQItems();
772 for( ListSQItem::iterator i = listItems.begin();
773 i !=listItems.end(); ++i )
775 d = (*i)->GetDocEntryByNumber(0x0004, 0x1430); // Directory Record Type
776 if ( gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(d) )
778 v = ValEntry->GetValue();
782 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: not a ValEntry.");
786 if( v == "PATIENT " )
788 AddDicomDirPatientToEnd( *i );
789 //AddObjectToEnd(type,*i);
790 type = gdcmDicomDir::GDCM_DICOMDIR_PATIENT;
792 else if( v == "STUDY " )
794 AddDicomDirStudyToEnd( *i );
795 // AddObjectToEnd(type,*i);
796 type = gdcmDicomDir::GDCM_DICOMDIR_STUDY;
798 else if( v == "SERIES" )
800 AddDicomDirSerieToEnd( *i );
801 // AddObjectToEnd(type,*i);
802 type = gdcmDicomDir::GDCM_DICOMDIR_SERIE;
804 else if( v == "IMAGE " )
806 AddDicomDirImageToEnd( *i );
807 // AddObjectToEnd(type,*i);
808 type = gdcmDicomDir::GDCM_DICOMDIR_IMAGE;
812 // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
813 // neither an 'IMAGE' SQItem. Skip to next item.
820 * \ingroup gdcmDicomDir
821 * \brief AddObjectToEnd
823 * @param begin iterator on the first DocEntry within the chained List
824 * @param end iterator on the last DocEntry within the chained List
829 /*void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,gdcmSQItem *s)
836 case gdcmDicomDir::GDCM_DICOMDIR_META:
839 case gdcmDicomDir::GDCM_DICOMDIR_PATIENT:
840 AddDicomDirPatientToEnd(s);
842 case gdcmDicomDir::GDCM_DICOMDIR_STUDY:
843 AddDicomDirStudyToEnd(s);
845 case gdcmDicomDir::GDCM_DICOMDIR_SERIE:
846 AddDicomDirSerieToEnd(s);
848 case gdcmDicomDir::GDCM_DICOMDIR_IMAGE:
849 AddDicomDirImageToEnd(s);
851 case gdcmDicomDir::GDCM_DICOMDIR_NONE:
852 AddDicomDirImageToEnd(s); //FIXME
860 * \ingroup gdcmDicomDir
861 * \brief Well ... there is only one occurence
863 void gdcmDicomDir::AddDicomDirMeta()
869 metaElems = new gdcmDicomDirMeta( &TagHT );
873 * \ingroup gdcmDicomDir
874 * \brief AddDicomDirPatientToEnd
875 * @param s SQ Item to enqueue to the DicomPatient chained List
877 void gdcmDicomDir::AddDicomDirPatientToEnd(gdcmSQItem *s)
879 patients.push_back(new gdcmDicomDirPatient(s, &TagHT));
883 * \ingroup gdcmDicomDir
884 * \brief AddDicomDirStudyToEnd
885 * @param s SQ Item to enqueue to the DicomDirStudy chained List
887 void gdcmDicomDir::AddDicomDirStudyToEnd(gdcmSQItem *s)
889 if( patients.size() > 0 )
891 ListDicomDirPatient::iterator itp = patients.end();
893 (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(s, &TagHT));
898 * \ingroup gdcmDicomDir
899 * \brief AddDicomDirSerieToEnd
900 * @param s SQ Item to enqueue to the DicomDirSerie chained List
902 void gdcmDicomDir::AddDicomDirSerieToEnd(gdcmSQItem *s)
904 if( patients.size() > 0 )
906 ListDicomDirPatient::iterator itp = patients.end();
909 if( (*itp)->GetDicomDirStudies().size() > 0 )
911 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
913 (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(s, &TagHT));
919 * \ingroup gdcmDicomDir
920 * \brief AddDicomDirImageToEnd
921 * @param s SQ Item to enqueue to the DicomDirImage chained List
923 void gdcmDicomDir::AddDicomDirImageToEnd(gdcmSQItem *s)
925 if( patients.size() > 0 )
927 ListDicomDirPatient::iterator itp = patients.end();
930 if( (*itp)->GetDicomDirStudies().size() > 0 )
932 ListDicomDirStudy::iterator itst = (*itp)->GetDicomDirStudies().end();
935 if( (*itst)->GetDicomDirSeries().size() > 0 )
937 ListDicomDirSerie::iterator its = (*itst)->GetDicomDirSeries().end();
939 (*its)->AddDicomDirImage(new gdcmDicomDirImage(s, &TagHT));
946 * \ingroup gdcmDicomDir
947 * \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info
948 * @param path path of the root directory
949 * @param list chained list of Headers
951 void gdcmDicomDir::SetElements(std::string &path, VectDocument &list)
953 std::string patPrevName = "", patPrevID = "";
954 std::string studPrevInstanceUID = "", studPrevID = "";
955 std::string serPrevInstanceUID = "", serPrevID = "";
957 std::string patCurName, patCurID;
958 std::string studCurInstanceUID, studCurID;
959 std::string serCurInstanceUID, serCurID;
961 SetElement( path, GDCM_DICOMDIR_META,NULL);
963 for( VectDocument::iterator it = list.begin();
964 it != list.end(); ++it )
966 // get the current file characteristics
967 patCurName = (*it)->GetEntryByNumber(0x0010,0x0010);
968 patCurID = (*it)->GetEntryByNumber(0x0010,0x0011);
969 studCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000d);
970 studCurID = (*it)->GetEntryByNumber(0x0020,0x0010);
971 serCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000e);
972 serCurID = (*it)->GetEntryByNumber(0x0020,0x0011);
974 if( patCurName != patPrevName || patCurID != patPrevID)
976 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
979 // if new Study Deal with 'STUDY' Elements
980 if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID )
982 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
985 // if new Serie Deal with 'SERIE' Elements
986 if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID )
988 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
991 // Always Deal with 'IMAGE' Elements
992 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
994 patPrevName = patCurName;
995 patPrevID = patCurID;
996 studPrevInstanceUID = studCurInstanceUID;
997 studPrevID = studCurID;
998 serPrevInstanceUID = serCurInstanceUID;
999 serPrevID = serCurID;
1004 * \ingroup gdcmDicomDir
1005 * \brief compares two dgcmHeaders
1007 bool gdcmDicomDir::HeaderLessThan(gdcmDocument *header1, gdcmDocument *header2)
1009 return *header1 < *header2;
1013 * \brief Sets the accurate value for the (0x0004,0x1220) element of a DICOMDIR
1015 void gdcmDicomDir::UpdateDirectoryRecordSequenceLength()
1018 /// \todo FIXME : to go on compiling
1020 /// to be re written !
1022 /// ListTag::iterator it;
1023 /// uint16_t gr, el;
1025 /// for(it=listEntries.begin();it!=listEntries.end();++it) {
1026 /// gr = (*it)->GetGroup();
1027 /// el = (*it)->GetElement();
1028 /// vr = (*it)->GetVR();
1029 /// if (gr !=0xfffe) {
1030 /// if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) {
1031 /// offset += 4; // explicit VR AND OB, OW, SQ : 4 more bytes
1033 /// offset += 2 + 2 + 4 + (*it)->GetLength();
1035 /// offset += 4; // delimiters don't have a value.
1038 /// //bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
1039 /// SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
1044 //-----------------------------------------------------------------------------