1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2004/07/30 16:09:27 $
7 Version: $Revision: 1.61 $
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
51 * @param exception_on_error whether we want to throw an exception or not
53 gdcmDicomDir::gdcmDicomDir(bool exception_on_error):
54 gdcmDocument( exception_on_error )
58 std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...
59 SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements
64 * \brief Constructor Parses recursively the directory and creates the DicomDir
65 * or uses an already built DICOMDIR, depending on 'parseDir' value.
66 * @param FileName name
67 * - of the root directory (parseDir = true)
68 * - of the DICOMDIR (parseDir = false)
69 * @param parseDir boolean
70 * - true if user passed an entry point
71 * and wants to explore recursively the directories
72 * - false if user passed an already built DICOMDIR file
74 * @param exception_on_error whether we want to throw an exception or not
76 gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir,
77 bool exception_on_error):
78 gdcmDocument( fileName, exception_on_error)
80 // que l'on ai passe un root directory ou un DICOMDIR
81 // et quelle que soit la valeur de parseDir,
82 // on a deja lance gdcmDocument
85 // gdcmDocument already executed
86 // if user passed a root directory, sure we didn't get anything
88 if ( TagHT.begin() == TagHT.end() )
90 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry HT empty");
92 if ( fileName.size() == 1 && fileName[0] == '.' )
94 // user passed '.' as Name
95 // we get current directory name
96 char* dummy = new char[1000];
97 getcwd(dummy, (size_t)1000);
98 std::cout << "Directory to parse : [" << dummy << "]" << std::endl;
99 SetFileName( dummy ); // will be converted into a string
100 delete[] dummy; // no longer needed
105 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory"
106 " and create the DicomDir");
111 /// \todo if parseDir == false, it should be tagged as an error
112 // NON ! il suffit d'appeler ParseDirectory()
113 // apres le constructeur
118 // Directory record sequence
119 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
122 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
123 " sequence (0x0004,0x1220)");
124 /// \todo FIXME : what do we do when the parsed file IS NOT a
132 * \brief Canonical destructor
134 gdcmDicomDir::~gdcmDicomDir()
136 SetStartMethod(NULL);
137 SetProgressMethod(NULL);
145 for(ListDicomDirPatient::iterator cc = patients.begin();
153 //-----------------------------------------------------------------------------
156 * \brief Canonical Printer
158 void gdcmDicomDir::Print(std::ostream &os)
162 metaElems->SetPrintLevel(PrintLevel);
163 metaElems->Print(os);
165 for(ListDicomDirPatient::iterator cc = patients.begin();
166 cc != patients.end();
169 (*cc)->SetPrintLevel( PrintLevel );
174 //-----------------------------------------------------------------------------
177 * \brief This predicate, based on hopefully reasonable heuristics,
178 * decides whether or not the current header was properly parsed
179 * and contains the mandatory information for being considered as
180 * a well formed and usable DicomDir.
181 * @return true when gdcmDocument is the one of a reasonable DicomDir,
184 bool gdcmDicomDir::IsReadable()
186 if( !gdcmDocument::IsReadable() )
194 if( patients.size() <= 0 )
203 * \brief Sets all fields to NULL
206 void gdcmDicomDir::Initialize()
209 progressMethod = NULL;
211 startMethodArgDelete = NULL;
212 progressMethodArgDelete = NULL;
213 endMethodArgDelete = NULL;
221 metaElems = (gdcmDicomDirMeta *)0;
226 * \ingroup gdcmDicomDir
227 * \brief fills the whole structure, starting from a root Directory
229 void gdcmDicomDir::ParseDirectory()
231 CreateDicomDirChainedList( GetFileName() );
236 * \ingroup gdcmDicomDir
237 * \brief Set the start method to call when the parsing of the directory starts
238 * @param method Method to call
239 * @param arg Argument to pass to the method
240 * @param argDelete Argument
241 * \warning In python : the arg parameter isn't considered
243 void gdcmDicomDir::SetStartMethod(gdcmMethod *method, void *arg,
244 gdcmMethod *argDelete )
246 if( startArg && startMethodArgDelete )
248 startMethodArgDelete( startArg );
251 startMethod = method;
253 startMethodArgDelete = argDelete;
257 * \ingroup gdcmDicomDir
258 * \brief Set the method to delete the argument
259 * The argument is destroyed when the method is changed or when the
261 * @param method Method to call to delete the argument
263 void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod *method)
265 startMethodArgDelete = method;
269 * \ingroup gdcmDicomDir
270 * \brief Set the progress method to call when the parsing of the directory progress
271 * @param method Method to call
272 * @param arg Argument to pass to the method
273 * @param argDelete Argument
274 * \warning In python : the arg parameter isn't considered
276 void gdcmDicomDir::SetProgressMethod(gdcmMethod *method, void *arg,
277 gdcmMethod *argDelete )
279 if( progressArg && progressMethodArgDelete )
281 progressMethodArgDelete( progressArg );
284 progressMethod = method;
286 progressMethodArgDelete = argDelete;
290 * \ingroup gdcmDicomDir
291 * \brief Set the method to delete the argument
292 * The argument is destroyed when the method is changed or when the
294 * @param method Method to call to delete the argument
296 void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod *method)
298 progressMethodArgDelete = method;
302 * \ingroup gdcmDicomDir
303 * \brief Set the end method to call when the parsing of the directory ends
304 * @param method Method to call
305 * @param arg Argument to pass to the method
306 * @param argDelete Argument
307 * \warning In python : the arg parameter isn't considered
309 void gdcmDicomDir::SetEndMethod(gdcmMethod *method, void *arg,
310 gdcmMethod *argDelete )
312 if( endArg && endMethodArgDelete )
314 endMethodArgDelete( endArg );
319 endMethodArgDelete = argDelete;
323 * \ingroup gdcmDicomDir
324 * \brief Set the method to delete the argument
325 * The argument is destroyed when the method is changed or when the class
327 * @param method Method to call to delete the argument
329 void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod *method)
331 endMethodArgDelete = method;
335 * \ingroup gdcmDicomDir
336 * \brief writes on disc a DICOMDIR
337 * \ warning does NOT add the missing elements in the header :
338 * it's up to the user doing it !
339 * \todo : to be re-written using the DICOMDIR tree-like structure
340 * *not* the chained list
341 * (does NOT exist if the DICOMDIR is user-forged !)
342 * @param fileName file to be written to
343 * @return false only when fail to open
346 bool gdcmDicomDir::Write(std::string const & fileName)
350 fp1 = fopen(fileName.c_str(), "wb");
353 printf("Failed to open(write) File [%s] \n", fileName.c_str());
357 char * filePreamble = new char[128];
358 fwrite(filePreamble,128,1,fp1);
359 fwrite("DICM",4,1,fp1);
360 delete[] filePreamble;
361 UpdateDirectoryRecordSequenceLength();
369 * \brief Writes in a file using the tree-like structure.
370 * @param _fp already open file pointer
373 void gdcmDicomDir::WriteEntries(FILE *) //_fp
375 /// \todo (?) tester les echecs en ecriture
376 /// (apres chaque fwrite, dans le WriteEntry)
379 /* TODO : to go on compiling
381 gdcmDicomDirMeta *ptrMeta;
382 ListDicomDirPatient::iterator itPatient;
383 ListDicomDirStudy::iterator itStudy;
384 ListDicomDirSerie::iterator itSerie;
385 ListDicomDirImage::iterator itImage;
388 ptrMeta= GetDicomDirMeta();
389 for(i=ptrMeta->debut();i!=ptrMeta->fin();++i) {
390 WriteEntry(*i,_fp, gdcmExplicitVR);
393 itPatient = GetDicomDirPatients().begin();
394 while ( itPatient != GetDicomDirPatients().end() ) {
395 for(i=(*itPatient)->debut();i!=(*itPatient)->fin();++i) {
396 WriteEntry(*i,_fp, gdcmExplicitVR);
398 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
399 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) {
400 for(i=(*itStudy)->debut();i!=(*itStudy)->fin();++i) {
401 WriteEntry(*i,_fp, gdcmExplicitVR);
403 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
404 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) {
405 for(i=(*itSerie)->debut();i!=(*itSerie)->fin();++i) {
406 WriteEntry(*i,_fp, gdcmExplicitVR);
408 itImage = ((*itSerie)->GetDicomDirImages()).begin();
409 while (itImage != (*itSerie)->GetDicomDirImages().end() ) {
410 for(i=(*itImage)->debut();i!=(*itImage)->fin();++i) {
411 WriteEntry(*i,_fp, gdcmExplicitVR);
424 //-----------------------------------------------------------------------------
428 * \ingroup gdcmDicomDir
429 * \brief create a gdcmDocument-like chained list from a root Directory
430 * @param path entry point of the tree-like structure
432 void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path)
435 gdcmDirList fileList(path,1); // gets recursively the file list
436 unsigned int count = 0;
443 for( gdcmDirList::iterator it = fileList.begin();
444 it != fileList.end();
447 progress = (float)(count+1)/(float)fileList.size();
448 CallProgressMethod();
454 header = new gdcmHeader( it->c_str(),false );
458 "gdcmDicomDir::CreateDicomDirChainedList: "
459 "failure in new Header ",
462 if( header->IsReadable() )
464 // Add the file header to the chained list:
465 list.push_back(header);
467 "gdcmDicomDir::CreateDicomDirChainedList: readable ",
477 // sorts Patient/Study/Serie/
478 std::sort(list.begin(), list.end(), gdcmDicomDir::HeaderLessThan );
480 std::string tmp = fileList.GetDirName();
482 //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
483 SetElements(tmp, list);
489 * \ingroup gdcmDicomDir
490 * \brief adds *the* Meta to a partially created DICOMDIR
493 /// \todo FIXME : Heuuuuu ! Il prend les Entries du Document deja parse,
494 /// il ne fabrique rien !
496 gdcmDicomDirMeta * gdcmDicomDir::NewMeta()
498 gdcmDicomDirMeta *m = new gdcmDicomDirMeta( &TagHT );
499 for ( TagDocEntryHT::iterator cc = TagHT.begin();
500 cc != TagHT.end(); ++cc)
502 m->AddDocEntry( cc->second );
509 * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
511 gdcmDicomDirPatient * gdcmDicomDir::NewPatient()
513 std::list<gdcmElement>::iterator it;
514 uint16_t tmpGr,tmpEl;
515 gdcmDictEntry *dictEntry;
518 std::list<gdcmElement> elemList;
519 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
520 // Looks nice, but gdcmDicomDir IS NOT a gdcmObject ...
521 // gdcmDicomDirPatient *p = new gdcmDicomDirPatient(ptagHT);
522 // FillObject(elemList);
523 // patients.push_front( p );
525 /// \todo TODO : find a trick to use FillObject !!!
527 gdcmSQItem *s = new gdcmSQItem(0);
529 // for all the DicomDirPatient Elements
530 for( it = elemList.begin(); it != elemList.end(); ++it )
534 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
535 entry = new gdcmValEntry( dictEntry );
536 entry->SetOffset(0); // just to avoid further missprinting
537 entry->SetValue( it->value );
539 // dealing with value length ...
541 if( dictEntry->GetGroup() == 0xfffe)
543 entry->SetLength(entry->GetValue().length());
545 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
547 entry->SetLength( 4 );
549 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
553 else if( dictEntry->GetVR() == "SQ" )
555 entry->SetLength( 0xffffffff );
559 entry->SetLength( entry->GetValue().length() );
561 s->AddDocEntry( entry );
564 gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &TagHT);
565 patients.push_front( p );
571 * \brief adds to the HTable
572 * the gdcmEntries (Dicom Elements) corresponding to the given type
573 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
574 * @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT,
575 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
576 * @param header gdcmHeader of the current file
578 void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
579 gdcmDocument *header)
581 std::list<gdcmElement> elemList;
582 std::list<gdcmElement>::iterator it;
583 uint16_t tmpGr, tmpEl;
584 gdcmDictEntry *dictEntry;
590 case GDCM_DICOMDIR_IMAGE:
591 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
594 case GDCM_DICOMDIR_SERIE:
595 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements();
598 case GDCM_DICOMDIR_STUDY:
599 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
602 case GDCM_DICOMDIR_PATIENT:
603 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
606 case GDCM_DICOMDIR_META:
607 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
614 for( it = elemList.begin(); it != elemList.end(); ++it)
618 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
619 entry = new gdcmValEntry( dictEntry ); // Be sure it's never a BinEntry !
621 entry->SetOffset(0); // just to avoid further missprinting
623 if( header ) // NULL when we Build Up (ex nihilo) a DICOMDIR
624 // or when we add the META elems
626 val = header->GetEntryByNumber(tmpGr, tmpEl);
633 if( val == GDCM_UNFOUND)
635 if( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
637 // force to the *end* File Name
638 val = GetName( path );
640 else if( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
642 if( header->GetFileName().substr(0, path.length()) != path )
644 dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path"
645 " of file name is incorrect");
646 val = header->GetFileName();
650 val = &(header->GetFileName().c_str()[path.length()]);
660 if ( header->GetEntryLengthByNumber(tmpGr,tmpEl) == 0 )
666 entry->SetValue( val );
670 if( dictEntry->GetGroup() == 0xfffe )
672 entry->SetLength( entry->GetValue().length() ); // FIXME
674 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
678 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
682 else if( dictEntry->GetVR() == "SQ" )
684 entry->SetLength( 0xffffffff );
688 entry->SetLength( entry->GetValue().length() );
691 std::cout << " was TagHT[entry->GetKey()] = entry " << std::endl;
692 if ( type == GDCM_DICOMDIR_META ) {
693 std::cout << " special Treatment for GDCM_DICOMDIR_META" << std::endl;
696 //TagHT[entry->GetKey()] = entry; // FIXME : use a SEQUENCE !
701 * \brief CallStartMethod
703 void gdcmDicomDir::CallStartMethod()
709 startMethod( startArg );
714 * \ingroup gdcmDicomDir
715 * \brief CallProgressMethod
717 void gdcmDicomDir::CallProgressMethod()
721 progressMethod( progressArg );
726 * \ingroup gdcmDicomDir
727 * \brief CallEndMethod
729 void gdcmDicomDir::CallEndMethod()
738 //-----------------------------------------------------------------------------
741 * \ingroup gdcmDicomDir
742 * \brief create a 'gdcmDicomDir' from a DICOMDIR gdcmHeader
744 void gdcmDicomDir::CreateDicomDir()
746 // The list is parsed.
747 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
748 // 1 - we save the beginning iterator
749 // 2 - we continue to parse
750 // 3 - we find an other tag
751 // + we create the object for the precedent tag
754 // Directory record sequence
755 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
758 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
759 " sequence (0x0004,0x1220)");
760 /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?
764 gdcmSeqEntry* s = dynamic_cast<gdcmSeqEntry*>(e);
767 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: no SeqEntry present");
768 // useless : (0x0004,0x1220) IS a Sequence !
772 gdcmDicomDirType type = gdcmDicomDir::GDCM_DICOMDIR_META;
773 metaElems = NewMeta();
775 ListSQItem listItems = s->GetSQItems();
779 for( ListSQItem::iterator i = listItems.begin();
780 i !=listItems.end(); ++i )
782 d = (*i)->GetDocEntryByNumber(0x0004, 0x1430); // Directory Record Type
783 if ( gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(d) )
785 v = ValEntry->GetValue();
789 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: not a ValEntry.");
793 if( v == "PATIENT " )
795 AddDicomDirPatientToEnd( *i );
796 //AddObjectToEnd(type,*i);
797 type = gdcmDicomDir::GDCM_DICOMDIR_PATIENT;
799 else if( v == "STUDY " )
801 AddDicomDirStudyToEnd( *i );
802 // AddObjectToEnd(type,*i);
803 type = gdcmDicomDir::GDCM_DICOMDIR_STUDY;
805 else if( v == "SERIES" )
807 AddDicomDirSerieToEnd( *i );
808 // AddObjectToEnd(type,*i);
809 type = gdcmDicomDir::GDCM_DICOMDIR_SERIE;
811 else if( v == "IMAGE " )
813 AddDicomDirImageToEnd( *i );
814 // AddObjectToEnd(type,*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 AddObjectToEnd
830 * @param begin iterator on the first DocEntry within the chained List
831 * @param end iterator on the last DocEntry within the chained List
836 /*void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,gdcmSQItem *s)
843 case gdcmDicomDir::GDCM_DICOMDIR_META:
846 case gdcmDicomDir::GDCM_DICOMDIR_PATIENT:
847 AddDicomDirPatientToEnd(s);
849 case gdcmDicomDir::GDCM_DICOMDIR_STUDY:
850 AddDicomDirStudyToEnd(s);
852 case gdcmDicomDir::GDCM_DICOMDIR_SERIE:
853 AddDicomDirSerieToEnd(s);
855 case gdcmDicomDir::GDCM_DICOMDIR_IMAGE:
856 AddDicomDirImageToEnd(s);
858 case gdcmDicomDir::GDCM_DICOMDIR_NONE:
859 AddDicomDirImageToEnd(s); //FIXME
867 * \ingroup gdcmDicomDir
868 * \brief Well ... there is only one occurence
870 void gdcmDicomDir::AddDicomDirMeta()
876 metaElems = new gdcmDicomDirMeta( &TagHT );
880 * \ingroup gdcmDicomDir
881 * \brief AddDicomDirPatientToEnd
882 * @param s SQ Item to enqueue to the DicomPatient chained List
884 void gdcmDicomDir::AddDicomDirPatientToEnd(gdcmSQItem *s)
886 patients.push_back(new gdcmDicomDirPatient(s, &TagHT));
890 * \ingroup gdcmDicomDir
891 * \brief AddDicomDirStudyToEnd
892 * @param s SQ Item to enqueue to the DicomDirStudy chained List
894 void gdcmDicomDir::AddDicomDirStudyToEnd(gdcmSQItem *s)
896 if( patients.size() > 0 )
898 ListDicomDirPatient::iterator itp = patients.end();
900 (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(s, &TagHT));
905 * \ingroup gdcmDicomDir
906 * \brief AddDicomDirSerieToEnd
907 * @param s SQ Item to enqueue to the DicomDirSerie chained List
909 void gdcmDicomDir::AddDicomDirSerieToEnd(gdcmSQItem *s)
911 if( patients.size() > 0 )
913 ListDicomDirPatient::iterator itp = patients.end();
916 if( (*itp)->GetDicomDirStudies().size() > 0 )
918 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
920 (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(s, &TagHT));
926 * \ingroup gdcmDicomDir
927 * \brief AddDicomDirImageToEnd
928 * @param s SQ Item to enqueue to the DicomDirImage chained List
930 void gdcmDicomDir::AddDicomDirImageToEnd(gdcmSQItem *s)
932 if( patients.size() > 0 )
934 ListDicomDirPatient::iterator itp = patients.end();
937 if( (*itp)->GetDicomDirStudies().size() > 0 )
939 ListDicomDirStudy::iterator itst = (*itp)->GetDicomDirStudies().end();
942 if( (*itst)->GetDicomDirSeries().size() > 0 )
944 ListDicomDirSerie::iterator its = (*itst)->GetDicomDirSeries().end();
946 (*its)->AddDicomDirImage(new gdcmDicomDirImage(s, &TagHT));
953 * \ingroup gdcmDicomDir
954 * \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info
955 * @param path path of the root directory
956 * @param list chained list of Headers
958 void gdcmDicomDir::SetElements(std::string &path, VectDocument &list)
960 std::string patPrevName = "", patPrevID = "";
961 std::string studPrevInstanceUID = "", studPrevID = "";
962 std::string serPrevInstanceUID = "", serPrevID = "";
964 std::string patCurName, patCurID;
965 std::string studCurInstanceUID, studCurID;
966 std::string serCurInstanceUID, serCurID;
968 SetElement( path, GDCM_DICOMDIR_META,NULL);
970 for( VectDocument::iterator it = list.begin();
971 it != list.end(); ++it )
973 // get the current file characteristics
974 patCurName = (*it)->GetEntryByNumber(0x0010,0x0010);
975 patCurID = (*it)->GetEntryByNumber(0x0010,0x0011);
976 studCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000d);
977 studCurID = (*it)->GetEntryByNumber(0x0020,0x0010);
978 serCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000e);
979 serCurID = (*it)->GetEntryByNumber(0x0020,0x0011);
981 if( patCurName != patPrevName || patCurID != patPrevID)
983 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
986 // if new Study Deal with 'STUDY' Elements
987 if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID )
989 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
992 // if new Serie Deal with 'SERIE' Elements
993 if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID )
995 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
998 // Always Deal with 'IMAGE' Elements
999 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
1001 patPrevName = patCurName;
1002 patPrevID = patCurID;
1003 studPrevInstanceUID = studCurInstanceUID;
1004 studPrevID = studCurID;
1005 serPrevInstanceUID = serCurInstanceUID;
1006 serPrevID = serCurID;
1011 * \ingroup gdcmDicomDir
1012 * \brief compares two dgcmHeaders
1014 bool gdcmDicomDir::HeaderLessThan(gdcmDocument *header1, gdcmDocument *header2)
1016 return *header1 < *header2;
1020 * \brief Sets the accurate value for the (0x0004,0x1220) element of a DICOMDIR
1022 void gdcmDicomDir::UpdateDirectoryRecordSequenceLength()
1025 /// \todo FIXME : to go on compiling
1027 /// to be re written !
1029 /// ListTag::iterator it;
1030 /// uint16_t gr, el;
1032 /// for(it=listEntries.begin();it!=listEntries.end();++it) {
1033 /// gr = (*it)->GetGroup();
1034 /// el = (*it)->GetElement();
1035 /// vr = (*it)->GetVR();
1036 /// if (gr !=0xfffe) {
1037 /// if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) {
1038 /// offset += 4; // explicit VR AND OB, OW, SQ : 4 more bytes
1040 /// offset += 2 + 2 + 4 + (*it)->GetLength();
1042 /// offset += 4; // delimiters don't have a value.
1045 /// //bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
1046 /// SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
1051 //-----------------------------------------------------------------------------