1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2004/08/26 15:29:52 $
7 Version: $Revision: 1.64 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
21 #include <sys/types.h>
29 #include "gdcmDicomDir.h"
30 #include "gdcmDicomDirStudy.h"
31 #include "gdcmDicomDirSerie.h"
32 #include "gdcmDicomDirImage.h"
33 #include "gdcmDirList.h"
35 #include "gdcmDebug.h"
36 #include "gdcmGlobal.h"
37 #include "gdcmHeader.h"
38 #include "gdcmSeqEntry.h"
39 #include "gdcmSQItem.h"
40 #include "gdcmValEntry.h"
42 //-----------------------------------------------------------------------------
43 // For full DICOMDIR description, see:
44 // PS 3.3-2003, pages 731-750
45 //-----------------------------------------------------------------------------
46 // Constructor / Destructor
49 * \ingroup gdcmDicomDir
50 * \brief Constructor : creates an empty gdcmDicomDir
52 gdcmDicomDir::gdcmDicomDir()
55 Initialize(); // sets all private fields to NULL
57 std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...
58 SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements
63 * \brief Constructor Parses recursively the directory and creates the DicomDir
64 * or uses an already built DICOMDIR, depending on 'parseDir' value.
65 * @param FileName name
66 * - of the root directory (parseDir = true)
67 * - of the DICOMDIR (parseDir = false)
68 * @param parseDir boolean
69 * - true if user passed an entry point
70 * and wants to explore recursively the directories
71 * - false if user passed an already built DICOMDIR file
74 gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir ):
75 gdcmDocument( fileName )
77 // que l'on ai passe un root directory ou un DICOMDIR
78 // et quelle que soit la valeur de parseDir,
79 // on a deja lance gdcmDocument
80 Initialize(); // sets all private fields to NULL
82 // gdcmDocument already executed
83 // if user passed a root directory, sure we didn't get anything
85 if ( TagHT.begin() == TagHT.end() ) // when user passed a Directory to parse
87 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry HT empty");
89 if ( fileName.size() == 1 && fileName[0] == '.' )
91 // user passed '.' as Name
92 // we get current directory name
93 char* dummy = new char[1000];
94 getcwd(dummy, (size_t)1000);
95 SetFileName( dummy ); // will be converted into a string
96 delete[] dummy; // no longer needed
99 if ( parseDir ) // user asked for a recursive parsing of a root directory
101 metaElems = NewMeta();
103 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory"
104 " and create the DicomDir");
109 /// \todo if parseDir == false, it should be tagged as an error
110 // NON ! il suffit d'appeler ParseDirectory()
111 // apres le constructeur
114 else // Only if user passed a DICOMDIR
116 // Directory record sequence
117 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
120 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
121 " sequence (0x0004,0x1220)");
122 /// \todo FIXME : what do we do when the parsed file IS NOT a
130 * \brief Canonical destructor
132 gdcmDicomDir::~gdcmDicomDir()
134 SetStartMethod(NULL);
135 SetProgressMethod(NULL);
137 for(ListDicomDirPatient::iterator cc = patients.begin();
149 //-----------------------------------------------------------------------------
152 * \brief Canonical Printer
154 void gdcmDicomDir::Print(std::ostream &os)
158 metaElems->SetPrintLevel(PrintLevel);
159 metaElems->Print(os);
161 for(ListDicomDirPatient::iterator cc = patients.begin();
162 cc != patients.end();
165 (*cc)->SetPrintLevel( PrintLevel );
170 //-----------------------------------------------------------------------------
173 * \brief This predicate, based on hopefully reasonable heuristics,
174 * decides whether or not the current header was properly parsed
175 * and contains the mandatory information for being considered as
176 * a well formed and usable DicomDir.
177 * @return true when gdcmDocument is the one of a reasonable DicomDir,
180 bool gdcmDicomDir::IsReadable()
182 if( !gdcmDocument::IsReadable() )
190 if( patients.size() <= 0 )
199 * \brief Sets all fields to NULL
202 void gdcmDicomDir::Initialize()
205 progressMethod = NULL;
207 startMethodArgDelete = NULL;
208 progressMethodArgDelete = NULL;
209 endMethodArgDelete = NULL;
222 * \ingroup gdcmDicomDir
223 * \brief fills the whole structure, starting from a root Directory
225 void gdcmDicomDir::ParseDirectory()
227 CreateDicomDirChainedList( GetFileName() );
232 * \ingroup gdcmDicomDir
233 * \brief Set the start method to call when the parsing of the directory starts
234 * @param method Method to call
235 * @param arg Argument to pass to the method
236 * @param argDelete Argument
237 * \warning In python : the arg parameter isn't considered
239 void gdcmDicomDir::SetStartMethod(gdcmMethod *method, void *arg,
240 gdcmMethod *argDelete )
242 if( startArg && startMethodArgDelete )
244 startMethodArgDelete( startArg );
247 startMethod = method;
249 startMethodArgDelete = argDelete;
253 * \ingroup gdcmDicomDir
254 * \brief Set the method to delete the argument
255 * The argument is destroyed when the method is changed or when the
257 * @param method Method to call to delete the argument
259 void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod *method)
261 startMethodArgDelete = method;
265 * \ingroup gdcmDicomDir
266 * \brief Set the progress method to call when the parsing of the directory progress
267 * @param method Method to call
268 * @param arg Argument to pass to the method
269 * @param argDelete Argument
270 * \warning In python : the arg parameter isn't considered
272 void gdcmDicomDir::SetProgressMethod(gdcmMethod *method, void *arg,
273 gdcmMethod *argDelete )
275 if( progressArg && progressMethodArgDelete )
277 progressMethodArgDelete( progressArg );
280 progressMethod = method;
282 progressMethodArgDelete = argDelete;
286 * \ingroup gdcmDicomDir
287 * \brief Set the method to delete the argument
288 * The argument is destroyed when the method is changed or when the
290 * @param method Method to call to delete the argument
292 void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod *method)
294 progressMethodArgDelete = method;
298 * \ingroup gdcmDicomDir
299 * \brief Set the end method to call when the parsing of the directory ends
300 * @param method Method to call
301 * @param arg Argument to pass to the method
302 * @param argDelete Argument
303 * \warning In python : the arg parameter isn't considered
305 void gdcmDicomDir::SetEndMethod(gdcmMethod *method, void *arg,
306 gdcmMethod *argDelete )
308 if( endArg && endMethodArgDelete )
310 endMethodArgDelete( endArg );
315 endMethodArgDelete = argDelete;
319 * \ingroup gdcmDicomDir
320 * \brief Set the method to delete the argument
321 * The argument is destroyed when the method is changed or when the class
323 * @param method Method to call to delete the argument
325 void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod *method)
327 endMethodArgDelete = method;
331 * \ingroup gdcmDicomDir
332 * \brief writes on disc a DICOMDIR
333 * \ warning does NOT add the missing elements in the header :
334 * it's up to the user doing it !
335 * \todo : to be re-written using the DICOMDIR tree-like structure
336 * *not* the chained list
337 * (does NOT exist if the DICOMDIR is user-forged !)
338 * @param fileName file to be written to
339 * @return false only when fail to open
342 bool gdcmDicomDir::Write(std::string const & fileName)
344 uint16_t sq[5] = { 0x0004, 0x1220, 0x0000, 0xffff, 0xffff };
345 uint16_t sqt[3]= { 0xfffe, 0xe0dd, 0x0000 };
347 FILE * fp = fopen(fileName.c_str(), "wb");
350 printf("Failed to open(write) File [%s] \n", fileName.c_str());
354 uint8_t* filePreamble = new uint8_t[128];
355 memset(filePreamble, 0, 128);
356 fwrite(filePreamble,128,1,fp);
357 fwrite("DICM",4,1,fp);
358 delete[] filePreamble;
359 // UpdateDirectoryRecordSequenceLength(); // TODO (if *really* usefull)
360 gdcmDicomDirMeta *ptrMeta = GetDicomDirMeta();
361 ptrMeta->Write(fp, gdcmExplicitVR);
363 // force writing 0004|1220 [SQ ], that CANNOT exist within gdcmDicomDirMeta
364 fwrite(&sq[0],4,1,fp); // 0004 1220
365 fwrite("SQ" ,2,1,fp); // SQ
366 fwrite(&sq[2],6,1,fp); // 00 ffffffff
368 for(ListDicomDirPatient::iterator cc = patients.begin();cc!=patients.end();++cc)
370 (*cc)->Write( fp, gdcmExplicitVR );
372 // force writing Sequence Delimitation Item
373 fwrite(&sqt[0],4,1,fp); // fffe e0dd
374 fwrite("UL" ,2,1,fp); // UL
375 fwrite(&sqt[2],1,1,fp); // 00
380 //-----------------------------------------------------------------------------
384 * \ingroup gdcmDicomDir
385 * \brief create a gdcmDocument-like chained list from a root Directory
386 * @param path entry point of the tree-like structure
388 void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path)
391 gdcmDirList fileList(path,1); // gets recursively the file list
392 unsigned int count = 0;
399 for( gdcmDirList::iterator it = fileList.begin();
400 it != fileList.end();
403 progress = (float)(count+1)/(float)fileList.size();
404 CallProgressMethod();
410 header = new gdcmHeader( it->c_str() );
414 "gdcmDicomDir::CreateDicomDirChainedList: "
415 "failure in new Header ",
418 if( header->IsReadable() )
420 // Add the file header to the chained list:
421 list.push_back(header);
423 "gdcmDicomDir::CreateDicomDirChainedList: readable ",
433 // sorts Patient/Study/Serie/
434 std::sort(list.begin(), list.end(), gdcmDicomDir::HeaderLessThan );
436 std::string tmp = fileList.GetDirName();
438 //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
439 SetElements(tmp, list);
444 * \ingroup gdcmDicomDir
445 * \brief adds *the* Meta to a partially created DICOMDIR
448 gdcmDicomDirMeta * gdcmDicomDir::NewMeta()
450 gdcmDicomDirMeta *m = new gdcmDicomDirMeta( &TagHT );
452 if ( TagHT.begin() != TagHT.end() ) // after Document Parsing
454 TagDocEntryHT::iterator lastOneButSequence = TagHT.end();
455 lastOneButSequence --;
456 // This works because ALL the 'out of Sequence' Tags belong to Meta Elems
457 // (we skip 0004|1220 [Directory record sequence] )
458 for ( TagDocEntryHT::iterator cc = TagHT.begin();
459 cc != lastOneButSequence;
462 m->AddDocEntry( cc->second );
465 else // after root directory parsing
467 //cout << "gdcmDicomDir::NewMeta avec FillObject" << endl;
468 std::list<gdcmElement> elemList;
469 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
470 m->FillObject(elemList);
471 // we create the Sequence manually
472 //gdcmSeqEntry *se =NewSeqEntryByNumber(0x0004, 0x1220); // NOT YET!
475 m->SetSQItemNumber(0); // To avoid further missprinting
481 * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
483 gdcmDicomDirPatient * gdcmDicomDir::NewPatient()
485 std::list<gdcmElement>::iterator it;
486 uint16_t tmpGr,tmpEl;
487 gdcmDictEntry *dictEntry;
490 std::list<gdcmElement> elemList;
491 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
492 // Looks nice, but gdcmDicomDir IS NOT a gdcmObject ...
493 // gdcmDicomDirPatient *p = new gdcmDicomDirPatient(ptagHT);
494 // FillObject(elemList);
495 // patients.push_front( p );
497 /// \todo TODO : find a trick to use FillObject !!!
499 gdcmSQItem *s = new gdcmSQItem(0);
501 // for all the DicomDirPatient Elements
502 for( it = elemList.begin(); it != elemList.end(); ++it )
506 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
507 entry = new gdcmValEntry( dictEntry );
508 entry->SetOffset(0); // just to avoid further missprinting
509 entry->SetValue( it->value );
511 // dealing with value length ...
513 if( dictEntry->GetGroup() == 0xfffe)
515 entry->SetLength(entry->GetValue().length());
517 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
519 entry->SetLength( 4 );
521 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
525 else if( dictEntry->GetVR() == "SQ" )
527 entry->SetLength( 0xffffffff );
531 entry->SetLength( entry->GetValue().length() );
533 s->AddDocEntry( entry );
536 gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &TagHT);
537 patients.push_front( p );
543 * \brief adds to the HTable
544 * the gdcmEntries (Dicom Elements) corresponding to the given type
545 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
546 * @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT,
547 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
548 * @param header gdcmHeader of the current file
550 void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
551 gdcmDocument *header)
553 std::list<gdcmElement> elemList;
554 std::list<gdcmElement>::iterator it;
555 uint16_t tmpGr, tmpEl;
556 gdcmDictEntry *dictEntry;
559 gdcmSQItem *si = new gdcmSQItem(0); // all the items will be at level 1
562 case GDCM_DICOMDIR_IMAGE:
563 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
566 case GDCM_DICOMDIR_SERIE:
567 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements();
570 case GDCM_DICOMDIR_STUDY:
571 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
574 case GDCM_DICOMDIR_PATIENT:
575 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
578 case GDCM_DICOMDIR_META:
579 elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
580 // add already done ?
586 // removed all the seems-to-be-useless stuff about Referenced Image Sequence
587 // to avoid further troubles
588 // imageElem 0008 1140 "" // Referenced Image Sequence
589 // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
590 // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
591 // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
592 // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
593 // for all the relevant elements found in their own spot of the DicomDir.dic
594 // FIXME : troubles found when it's a SeqEntry
596 for( it = elemList.begin(); it != elemList.end(); ++it)
600 dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
602 entry = new gdcmValEntry( dictEntry ); // Be sure it's never a BinEntry !
604 entry->SetOffset(0); // just to avoid further missprinting
605 entry->SetLength(0); // just to avoid further missprinting
607 if( header ) // NULL when we Build Up (ex nihilo) a DICOMDIR
608 // or when we add the META elems
609 val = header->GetEntryByNumber(tmpGr, tmpEl);
613 if( val == GDCM_UNFOUND)
615 if( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
617 // force to the *end* File Name
618 val = GetName( path );
620 else if( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
622 if( header->GetFileName().substr(0, path.length()) != path )
624 dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path"
625 " of file name is incorrect");
626 val = header->GetFileName();
629 val = &(header->GetFileName().c_str()[path.length()]);
636 if ( header->GetEntryLengthByNumber(tmpGr,tmpEl) == 0 )
640 // GDCM_UNFOUND or not !
642 entry->SetValue( val ); // troubles expected when vr=SQ ...
646 if( dictEntry->GetGroup() == 0xfffe )
648 entry->SetLength( entry->GetValue().length() ); // FIXME
650 else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
654 else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
658 else if( dictEntry->GetVR() == "SQ" )
660 entry->SetLength( 0xffffffff );
664 entry->SetLength( entry->GetValue().length() );
668 if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
669 std::cout << " special Treatment for GDCM_DICOMDIR_META" << std::endl;
674 case GDCM_DICOMDIR_IMAGE:
675 AddDicomDirImageToEnd(si);
678 case GDCM_DICOMDIR_SERIE:
679 AddDicomDirSerieToEnd(si);
682 case GDCM_DICOMDIR_STUDY:
683 AddDicomDirStudyToEnd(si);
686 case GDCM_DICOMDIR_PATIENT:
687 AddDicomDirPatientToEnd(si);
693 //int count=1; // find a trick to increment
694 //s->AddEntry(si, count); // Seg Faults
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 type = gdcmDicomDir::GDCM_DICOMDIR_PATIENT;
796 else if( v == "STUDY " )
798 AddDicomDirStudyToEnd( *i );
799 type = gdcmDicomDir::GDCM_DICOMDIR_STUDY;
801 else if( v == "SERIES" )
803 AddDicomDirSerieToEnd( *i );
804 type = gdcmDicomDir::GDCM_DICOMDIR_SERIE;
806 else if( v == "IMAGE " )
808 AddDicomDirImageToEnd( *i );
809 type = gdcmDicomDir::GDCM_DICOMDIR_IMAGE;
813 // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
814 // neither an 'IMAGE' SQItem. Skip to next item.
821 * \ingroup gdcmDicomDir
822 * \brief Well ... there is only one occurence
824 void gdcmDicomDir::AddDicomDirMeta()
830 metaElems = new gdcmDicomDirMeta( &TagHT );
834 * \ingroup gdcmDicomDir
835 * \brief AddDicomDirPatientToEnd
836 * @param s SQ Item to enqueue to the DicomPatient chained List
838 void gdcmDicomDir::AddDicomDirPatientToEnd(gdcmSQItem *s)
840 patients.push_back(new gdcmDicomDirPatient(s, &TagHT));
844 * \ingroup gdcmDicomDir
845 * \brief AddDicomDirStudyToEnd
846 * @param s SQ Item to enqueue to the DicomDirStudy chained List
848 void gdcmDicomDir::AddDicomDirStudyToEnd(gdcmSQItem *s)
850 if( patients.size() > 0 )
852 ListDicomDirPatient::iterator itp = patients.end();
854 (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(s, &TagHT));
859 * \ingroup gdcmDicomDir
860 * \brief AddDicomDirSerieToEnd
861 * @param s SQ Item to enqueue to the DicomDirSerie chained List
863 void gdcmDicomDir::AddDicomDirSerieToEnd(gdcmSQItem *s)
865 if( patients.size() > 0 )
867 ListDicomDirPatient::iterator itp = patients.end();
870 if( (*itp)->GetDicomDirStudies().size() > 0 )
872 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
874 (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(s, &TagHT));
880 * \ingroup gdcmDicomDir
881 * \brief AddDicomDirImageToEnd
882 * @param s SQ Item to enqueue to the DicomDirImage chained List
884 void gdcmDicomDir::AddDicomDirImageToEnd(gdcmSQItem *s)
886 if( patients.size() > 0 )
888 ListDicomDirPatient::iterator itp = patients.end();
891 if( (*itp)->GetDicomDirStudies().size() > 0 )
893 ListDicomDirStudy::iterator itst = (*itp)->GetDicomDirStudies().end();
896 if( (*itst)->GetDicomDirSeries().size() > 0 )
898 ListDicomDirSerie::iterator its = (*itst)->GetDicomDirSeries().end();
900 (*its)->AddDicomDirImage(new gdcmDicomDirImage(s, &TagHT));
907 * \ingroup gdcmDicomDir
908 * \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info
909 * @param path path of the root directory
910 * @param list chained list of Headers
912 void gdcmDicomDir::SetElements(std::string &path, VectDocument &list)
914 std::string patPrevName = "", patPrevID = "";
915 std::string studPrevInstanceUID = "", studPrevID = "";
916 std::string serPrevInstanceUID = "", serPrevID = "";
918 std::string patCurName, patCurID;
919 std::string studCurInstanceUID, studCurID;
920 std::string serCurInstanceUID, serCurID;
922 //SetElement( path, GDCM_DICOMDIR_META,NULL); // already done (NewMeta)
924 for( VectDocument::iterator it = list.begin();
925 it != list.end(); ++it )
927 // get the current file characteristics
928 patCurName = (*it)->GetEntryByNumber(0x0010,0x0010);
929 patCurID = (*it)->GetEntryByNumber(0x0010,0x0011);
930 studCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000d);
931 studCurID = (*it)->GetEntryByNumber(0x0020,0x0010);
932 serCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000e);
933 serCurID = (*it)->GetEntryByNumber(0x0020,0x0011);
935 if( patCurName != patPrevName || patCurID != patPrevID)
937 SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
940 // if new Study Deal with 'STUDY' Elements
941 if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID )
943 SetElement(path, GDCM_DICOMDIR_STUDY, *it);
946 // if new Serie Deal with 'SERIE' Elements
947 if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID )
949 SetElement(path, GDCM_DICOMDIR_SERIE, *it);
952 // Always Deal with 'IMAGE' Elements
953 SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
955 patPrevName = patCurName;
956 patPrevID = patCurID;
957 studPrevInstanceUID = studCurInstanceUID;
958 studPrevID = studCurID;
959 serPrevInstanceUID = serCurInstanceUID;
960 serPrevID = serCurID;
965 * \ingroup gdcmDicomDir
966 * \brief compares two dgcmHeaders
968 bool gdcmDicomDir::HeaderLessThan(gdcmDocument *header1, gdcmDocument *header2)
970 return *header1 < *header2;
974 * \brief Sets the accurate value for the (0x0004,0x1220) element of a DICOMDIR
976 void gdcmDicomDir::UpdateDirectoryRecordSequenceLength()
979 /// \todo FIXME : to go on compiling
981 /// to be re written !
983 /// ListTag::iterator it;
986 /// for(it=listEntries.begin();it!=listEntries.end();++it) {
987 /// gr = (*it)->GetGroup();
988 /// el = (*it)->GetElement();
989 /// vr = (*it)->GetVR();
990 /// if (gr !=0xfffe) {
991 /// if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) {
992 /// offset += 4; // explicit VR AND OB, OW, SQ : 4 more bytes
994 /// offset += 2 + 2 + 4 + (*it)->GetLength();
996 /// offset += 4; // delimiters don't have a value.
999 /// //bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
1000 /// SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
1005 //-----------------------------------------------------------------------------