1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2004/08/01 02:39:09 $
7 Version: $Revision: 1.62 $
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;
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)
348 FILE * fp1 = fopen(fileName.c_str(), "wb");
351 printf("Failed to open(write) File [%s] \n", fileName.c_str());
355 char * filePreamble = new char[128];
356 fwrite(filePreamble,128,1,fp1);
357 fwrite("DICM",4,1,fp1);
358 delete[] filePreamble;
359 UpdateDirectoryRecordSequenceLength();
367 * \brief Writes in a file using the tree-like structure.
368 * @param _fp already open file pointer
371 void gdcmDicomDir::WriteEntries(FILE *) //_fp
373 /// \todo (?) tester les echecs en ecriture
374 /// (apres chaque fwrite, dans le WriteEntry)
377 /* TODO : to go on compiling
379 gdcmDicomDirMeta *ptrMeta;
380 ListDicomDirPatient::iterator itPatient;
381 ListDicomDirStudy::iterator itStudy;
382 ListDicomDirSerie::iterator itSerie;
383 ListDicomDirImage::iterator itImage;
386 ptrMeta= GetDicomDirMeta();
387 for(i=ptrMeta->debut();i!=ptrMeta->fin();++i) {
388 WriteEntry(*i,_fp, gdcmExplicitVR);
391 itPatient = GetDicomDirPatients().begin();
392 while ( itPatient != GetDicomDirPatients().end() ) {
393 for(i=(*itPatient)->debut();i!=(*itPatient)->fin();++i) {
394 WriteEntry(*i,_fp, gdcmExplicitVR);
396 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
397 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) {
398 for(i=(*itStudy)->debut();i!=(*itStudy)->fin();++i) {
399 WriteEntry(*i,_fp, gdcmExplicitVR);
401 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
402 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) {
403 for(i=(*itSerie)->debut();i!=(*itSerie)->fin();++i) {
404 WriteEntry(*i,_fp, gdcmExplicitVR);
406 itImage = ((*itSerie)->GetDicomDirImages()).begin();
407 while (itImage != (*itSerie)->GetDicomDirImages().end() ) {
408 for(i=(*itImage)->debut();i!=(*itImage)->fin();++i) {
409 WriteEntry(*i,_fp, gdcmExplicitVR);
422 //-----------------------------------------------------------------------------
426 * \ingroup gdcmDicomDir
427 * \brief create a gdcmDocument-like chained list from a root Directory
428 * @param path entry point of the tree-like structure
430 void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path)
433 gdcmDirList fileList(path,1); // gets recursively the file list
434 unsigned int count = 0;
441 for( gdcmDirList::iterator it = fileList.begin();
442 it != fileList.end();
445 progress = (float)(count+1)/(float)fileList.size();
446 CallProgressMethod();
452 header = new gdcmHeader( it->c_str(),false );
456 "gdcmDicomDir::CreateDicomDirChainedList: "
457 "failure in new Header ",
460 if( header->IsReadable() )
462 // Add the file header to the chained list:
463 list.push_back(header);
465 "gdcmDicomDir::CreateDicomDirChainedList: readable ",
475 // sorts Patient/Study/Serie/
476 std::sort(list.begin(), list.end(), gdcmDicomDir::HeaderLessThan );
478 std::string tmp = fileList.GetDirName();
480 //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
481 SetElements(tmp, list);
487 * \ingroup gdcmDicomDir
488 * \brief adds *the* Meta to a partially created DICOMDIR
491 /// \todo FIXME : Heuuuuu ! Il prend les Entries du Document deja parse,
492 /// il ne fabrique rien !
494 gdcmDicomDirMeta * gdcmDicomDir::NewMeta()
496 gdcmDicomDirMeta *m = new gdcmDicomDirMeta( &TagHT );
497 for ( TagDocEntryHT::iterator cc = TagHT.begin();
498 cc != TagHT.end(); ++cc)
500 m->AddDocEntry( cc->second );
507 * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
509 gdcmDicomDirPatient * gdcmDicomDir::NewPatient()
511 std::list<gdcmElement>::iterator it;
512 uint16_t tmpGr,tmpEl;
513 gdcmDictEntry *dictEntry;
516 std::list<gdcmElement> elemList;
517 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
518 // Looks nice, but gdcmDicomDir IS NOT a gdcmObject ...
519 // gdcmDicomDirPatient *p = new gdcmDicomDirPatient(ptagHT);
520 // FillObject(elemList);
521 // patients.push_front( p );
523 /// \todo TODO : find a trick to use FillObject !!!
525 gdcmSQItem *s = new gdcmSQItem(0);
527 // for all the DicomDirPatient Elements
528 for( it = elemList.begin(); it != elemList.end(); ++it )
532 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
533 entry = new gdcmValEntry( dictEntry );
534 entry->SetOffset(0); // just to avoid further missprinting
535 entry->SetValue( it->value );
537 // dealing with value length ...
539 if( dictEntry->GetGroup() == 0xfffe)
541 entry->SetLength(entry->GetValue().length());
543 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
545 entry->SetLength( 4 );
547 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
551 else if( dictEntry->GetVR() == "SQ" )
553 entry->SetLength( 0xffffffff );
557 entry->SetLength( entry->GetValue().length() );
559 s->AddDocEntry( entry );
562 gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &TagHT);
563 patients.push_front( p );
569 * \brief adds to the HTable
570 * the gdcmEntries (Dicom Elements) corresponding to the given type
571 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
572 * @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT,
573 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
574 * @param header gdcmHeader of the current file
576 void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
577 gdcmDocument *header)
579 std::list<gdcmElement> elemList;
580 std::list<gdcmElement>::iterator it;
581 uint16_t tmpGr, tmpEl;
582 gdcmDictEntry *dictEntry;
588 case GDCM_DICOMDIR_IMAGE:
589 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
592 case GDCM_DICOMDIR_SERIE:
593 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements();
596 case GDCM_DICOMDIR_STUDY:
597 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
600 case GDCM_DICOMDIR_PATIENT:
601 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
604 case GDCM_DICOMDIR_META:
605 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
612 for( it = elemList.begin(); it != elemList.end(); ++it)
616 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
617 entry = new gdcmValEntry( dictEntry ); // Be sure it's never a BinEntry !
619 entry->SetOffset(0); // just to avoid further missprinting
621 if( header ) // NULL when we Build Up (ex nihilo) a DICOMDIR
622 // or when we add the META elems
624 val = header->GetEntryByNumber(tmpGr, tmpEl);
631 if( val == GDCM_UNFOUND)
633 if( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
635 // force to the *end* File Name
636 val = GetName( path );
638 else if( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
640 if( header->GetFileName().substr(0, path.length()) != path )
642 dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path"
643 " of file name is incorrect");
644 val = header->GetFileName();
648 val = &(header->GetFileName().c_str()[path.length()]);
658 if ( header->GetEntryLengthByNumber(tmpGr,tmpEl) == 0 )
664 entry->SetValue( val );
668 if( dictEntry->GetGroup() == 0xfffe )
670 entry->SetLength( entry->GetValue().length() ); // FIXME
672 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
676 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
680 else if( dictEntry->GetVR() == "SQ" )
682 entry->SetLength( 0xffffffff );
686 entry->SetLength( entry->GetValue().length() );
689 std::cout << " was TagHT[entry->GetKey()] = entry " << std::endl;
690 if ( type == GDCM_DICOMDIR_META ) {
691 std::cout << " special Treatment for GDCM_DICOMDIR_META" << std::endl;
694 //TagHT[entry->GetKey()] = entry; // FIXME : use a SEQUENCE !
699 * \brief CallStartMethod
701 void gdcmDicomDir::CallStartMethod()
707 startMethod( startArg );
712 * \ingroup gdcmDicomDir
713 * \brief CallProgressMethod
715 void gdcmDicomDir::CallProgressMethod()
719 progressMethod( progressArg );
724 * \ingroup gdcmDicomDir
725 * \brief CallEndMethod
727 void gdcmDicomDir::CallEndMethod()
736 //-----------------------------------------------------------------------------
739 * \ingroup gdcmDicomDir
740 * \brief create a 'gdcmDicomDir' from a DICOMDIR gdcmHeader
742 void gdcmDicomDir::CreateDicomDir()
744 // The list is parsed.
745 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
746 // 1 - we save the beginning iterator
747 // 2 - we continue to parse
748 // 3 - we find an other tag
749 // + we create the object for the precedent tag
752 // Directory record sequence
753 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
756 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
757 " sequence (0x0004,0x1220)");
758 /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?
762 gdcmSeqEntry* s = dynamic_cast<gdcmSeqEntry*>(e);
765 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: no SeqEntry present");
766 // useless : (0x0004,0x1220) IS a Sequence !
770 gdcmDicomDirType type = gdcmDicomDir::GDCM_DICOMDIR_META;
771 metaElems = NewMeta();
773 ListSQItem listItems = s->GetSQItems();
777 for( ListSQItem::iterator i = listItems.begin();
778 i !=listItems.end(); ++i )
780 d = (*i)->GetDocEntryByNumber(0x0004, 0x1430); // Directory Record Type
781 if ( gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(d) )
783 v = ValEntry->GetValue();
787 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: not a ValEntry.");
791 if( v == "PATIENT " )
793 AddDicomDirPatientToEnd( *i );
794 //AddObjectToEnd(type,*i);
795 type = gdcmDicomDir::GDCM_DICOMDIR_PATIENT;
797 else if( v == "STUDY " )
799 AddDicomDirStudyToEnd( *i );
800 // AddObjectToEnd(type,*i);
801 type = gdcmDicomDir::GDCM_DICOMDIR_STUDY;
803 else if( v == "SERIES" )
805 AddDicomDirSerieToEnd( *i );
806 // AddObjectToEnd(type,*i);
807 type = gdcmDicomDir::GDCM_DICOMDIR_SERIE;
809 else if( v == "IMAGE " )
811 AddDicomDirImageToEnd( *i );
812 // AddObjectToEnd(type,*i);
813 type = gdcmDicomDir::GDCM_DICOMDIR_IMAGE;
817 // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
818 // neither an 'IMAGE' SQItem. Skip to next item.
825 * \ingroup gdcmDicomDir
826 * \brief AddObjectToEnd
828 * @param begin iterator on the first DocEntry within the chained List
829 * @param end iterator on the last DocEntry within the chained List
834 /*void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,gdcmSQItem *s)
841 case gdcmDicomDir::GDCM_DICOMDIR_META:
844 case gdcmDicomDir::GDCM_DICOMDIR_PATIENT:
845 AddDicomDirPatientToEnd(s);
847 case gdcmDicomDir::GDCM_DICOMDIR_STUDY:
848 AddDicomDirStudyToEnd(s);
850 case gdcmDicomDir::GDCM_DICOMDIR_SERIE:
851 AddDicomDirSerieToEnd(s);
853 case gdcmDicomDir::GDCM_DICOMDIR_IMAGE:
854 AddDicomDirImageToEnd(s);
856 case gdcmDicomDir::GDCM_DICOMDIR_NONE:
857 AddDicomDirImageToEnd(s); //FIXME
865 * \ingroup gdcmDicomDir
866 * \brief Well ... there is only one occurence
868 void gdcmDicomDir::AddDicomDirMeta()
874 metaElems = new gdcmDicomDirMeta( &TagHT );
878 * \ingroup gdcmDicomDir
879 * \brief AddDicomDirPatientToEnd
880 * @param s SQ Item to enqueue to the DicomPatient chained List
882 void gdcmDicomDir::AddDicomDirPatientToEnd(gdcmSQItem *s)
884 patients.push_back(new gdcmDicomDirPatient(s, &TagHT));
888 * \ingroup gdcmDicomDir
889 * \brief AddDicomDirStudyToEnd
890 * @param s SQ Item to enqueue to the DicomDirStudy chained List
892 void gdcmDicomDir::AddDicomDirStudyToEnd(gdcmSQItem *s)
894 if( patients.size() > 0 )
896 ListDicomDirPatient::iterator itp = patients.end();
898 (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(s, &TagHT));
903 * \ingroup gdcmDicomDir
904 * \brief AddDicomDirSerieToEnd
905 * @param s SQ Item to enqueue to the DicomDirSerie chained List
907 void gdcmDicomDir::AddDicomDirSerieToEnd(gdcmSQItem *s)
909 if( patients.size() > 0 )
911 ListDicomDirPatient::iterator itp = patients.end();
914 if( (*itp)->GetDicomDirStudies().size() > 0 )
916 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
918 (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(s, &TagHT));
924 * \ingroup gdcmDicomDir
925 * \brief AddDicomDirImageToEnd
926 * @param s SQ Item to enqueue to the DicomDirImage chained List
928 void gdcmDicomDir::AddDicomDirImageToEnd(gdcmSQItem *s)
930 if( patients.size() > 0 )
932 ListDicomDirPatient::iterator itp = patients.end();
935 if( (*itp)->GetDicomDirStudies().size() > 0 )
937 ListDicomDirStudy::iterator itst = (*itp)->GetDicomDirStudies().end();
940 if( (*itst)->GetDicomDirSeries().size() > 0 )
942 ListDicomDirSerie::iterator its = (*itst)->GetDicomDirSeries().end();
944 (*its)->AddDicomDirImage(new gdcmDicomDirImage(s, &TagHT));
951 * \ingroup gdcmDicomDir
952 * \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info
953 * @param path path of the root directory
954 * @param list chained list of Headers
956 void gdcmDicomDir::SetElements(std::string &path, VectDocument &list)
958 std::string patPrevName = "", patPrevID = "";
959 std::string studPrevInstanceUID = "", studPrevID = "";
960 std::string serPrevInstanceUID = "", serPrevID = "";
962 std::string patCurName, patCurID;
963 std::string studCurInstanceUID, studCurID;
964 std::string serCurInstanceUID, serCurID;
966 SetElement( path, GDCM_DICOMDIR_META,NULL);
968 for( VectDocument::iterator it = list.begin();
969 it != list.end(); ++it )
971 // get the current file characteristics
972 patCurName = (*it)->GetEntryByNumber(0x0010,0x0010);
973 patCurID = (*it)->GetEntryByNumber(0x0010,0x0011);
974 studCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000d);
975 studCurID = (*it)->GetEntryByNumber(0x0020,0x0010);
976 serCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000e);
977 serCurID = (*it)->GetEntryByNumber(0x0020,0x0011);
979 if( patCurName != patPrevName || patCurID != patPrevID)
981 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
984 // if new Study Deal with 'STUDY' Elements
985 if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID )
987 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
990 // if new Serie Deal with 'SERIE' Elements
991 if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID )
993 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
996 // Always Deal with 'IMAGE' Elements
997 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
999 patPrevName = patCurName;
1000 patPrevID = patCurID;
1001 studPrevInstanceUID = studCurInstanceUID;
1002 studPrevID = studCurID;
1003 serPrevInstanceUID = serCurInstanceUID;
1004 serPrevID = serCurID;
1009 * \ingroup gdcmDicomDir
1010 * \brief compares two dgcmHeaders
1012 bool gdcmDicomDir::HeaderLessThan(gdcmDocument *header1, gdcmDocument *header2)
1014 return *header1 < *header2;
1018 * \brief Sets the accurate value for the (0x0004,0x1220) element of a DICOMDIR
1020 void gdcmDicomDir::UpdateDirectoryRecordSequenceLength()
1023 /// \todo FIXME : to go on compiling
1025 /// to be re written !
1027 /// ListTag::iterator it;
1028 /// uint16_t gr, el;
1030 /// for(it=listEntries.begin();it!=listEntries.end();++it) {
1031 /// gr = (*it)->GetGroup();
1032 /// el = (*it)->GetElement();
1033 /// vr = (*it)->GetVR();
1034 /// if (gr !=0xfffe) {
1035 /// if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) {
1036 /// offset += 4; // explicit VR AND OB, OW, SQ : 4 more bytes
1038 /// offset += 2 + 2 + 4 + (*it)->GetLength();
1040 /// offset += 4; // delimiters don't have a value.
1043 /// //bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
1044 /// SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
1049 //-----------------------------------------------------------------------------