1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2004/06/28 09:30:58 $
7 Version: $Revision: 1.53 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
21 #include <sys/types.h>
30 #include "gdcmDicomDir.h"
31 #include "gdcmDicomDirStudy.h"
32 #include "gdcmDicomDirSerie.h"
33 #include "gdcmDicomDirImage.h"
34 #include "gdcmDirList.h"
36 #include "gdcmDebug.h"
37 #include "gdcmGlobal.h"
38 #include "gdcmHeader.h"
39 #include "gdcmSeqEntry.h"
40 #include "gdcmSQItem.h"
41 #include "gdcmValEntry.h"
43 //-----------------------------------------------------------------------------
44 // For full DICOMDIR description, see:
45 // PS 3.3-2003, pages 731-750
46 //-----------------------------------------------------------------------------
47 // Constructor / Destructor
49 void gdcmDicomDir::Initialize(void)
52 progressMethod = NULL;
54 startMethodArgDelete = NULL;
55 progressMethodArgDelete = NULL;
56 endMethodArgDelete = NULL;
64 metaElems = (gdcmDicomDirMeta *)0;
69 * \brief Constructor Parses recursively the directory and creates the DicomDir
70 * or uses an already built DICOMDIR, depending on 'parseDir' value.
71 * @param FileName name
72 * - of the root directory (parseDir = true)
73 * - of the DICOMDIR (parseDir = false)
74 * @param parseDir boolean
75 * - true if user passed an entry point
76 * and wants to explore recursively the directories
77 * - false if user passed an already built DICOMDIR file
79 * @param exception_on_error whether we want to throw an exception or not
81 gdcmDicomDir::gdcmDicomDir(const char *FileName, bool parseDir,
82 bool exception_on_error):
83 gdcmDocument(FileName,exception_on_error,true) // true : enable SeQuences
85 // que l'on ai passe un root directory ou un DICOMDIR
86 // et quelle que soit la valeur de parseDir,
87 // on a lance gdcmDocument
90 // gdcmDocument already executed
91 // if user passed a root directory, sure we didn't get anything
93 if( GetEntry().begin() == GetEntry().end() )
95 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry HT empty");
97 if(strlen(FileName)==1 && FileName[0]=='.') { // user passed '.' as Name
98 // we get current directory name
99 char* dummy= new char[1000];
100 getcwd(dummy, (size_t)1000);
101 SetFileName(dummy); // will be converted into a string
102 delete[] dummy; // no longer needed
107 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory"
108 " and create the DicomDir");
111 /// \todo if parseDir == false, it should be tagged as an error
116 // Directory record sequence
117 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
119 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
120 " sequence (0x0004,0x1220)");
121 /// \todo FIXME : what to do when the parsed file IS NOT a
129 * \ingroup gdcmDicomDir
130 * \brief Constructor : creates an empty gdcmDicomDir
131 * @param exception_on_error whether we want to throw an exception or not
133 gdcmDicomDir::gdcmDicomDir(bool exception_on_error):
134 gdcmDocument(exception_on_error)
139 std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...
140 SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements
145 * \brief Canonical destructor
147 gdcmDicomDir::~gdcmDicomDir()
149 SetStartMethod(NULL);
150 SetProgressMethod(NULL);
156 for(ListDicomDirPatient::iterator cc = patients.begin();
164 //-----------------------------------------------------------------------------
167 * \brief Canonical Printer
169 void gdcmDicomDir::Print(std::ostream &os)
173 metaElems->SetPrintLevel(printLevel);
174 metaElems->Print(os);
176 for(ListDicomDirPatient::iterator cc = patients.begin();
177 cc != patients.end();
180 (*cc)->SetPrintLevel(printLevel);
185 //-----------------------------------------------------------------------------
188 * \brief This predicate, based on hopefully reasonable heuristics,
189 * decides whether or not the current header was properly parsed
190 * and contains the mandatory information for being considered as
191 * a well formed and usable DicomDir.
192 * @return true when gdcmDocument is the one of a reasonable DicomDir,
195 bool gdcmDicomDir::IsReadable(void)
197 if(!gdcmDocument::IsReadable())
201 if(patients.size()<=0)
208 * \ingroup gdcmDicomDir
209 * \brief fills the whole structure, starting from a root Directory
211 void gdcmDicomDir::ParseDirectory(void)
213 CreateDicomDirChainedList(GetFileName());
218 * \ingroup gdcmDicomDir
219 * \brief Set the start method to call when the parsing of the directory starts
220 * @param method Method to call
221 * @param arg Argument to pass to the method
222 * @param argDelete Argument
223 * \warning In python : the arg parameter isn't considered
225 void gdcmDicomDir::SetStartMethod(gdcmMethod *method,void *arg,gdcmMethod *argDelete)
227 if((startArg)&&(startMethodArgDelete))
228 startMethodArgDelete(startArg);
232 startMethodArgDelete=argDelete;
236 * \ingroup gdcmDicomDir
237 * \brief Set the method to delete the argument
238 * The argument is destroyed when the method is changed or when the
240 * @param method Method to call to delete the argument
242 void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod *method)
244 startMethodArgDelete=method;
248 * \ingroup gdcmDicomDir
249 * \brief Set the progress method to call when the parsing of the directory progress
250 * @param method Method to call
251 * @param arg Argument to pass to the method
252 * @param argDelete Argument
253 * \warning In python : the arg parameter isn't considered
255 void gdcmDicomDir::SetProgressMethod(gdcmMethod *method,void *arg,gdcmMethod *argDelete)
257 if((progressArg)&&(progressMethodArgDelete))
258 progressMethodArgDelete(progressArg);
260 progressMethod=method;
262 progressMethodArgDelete=argDelete;
266 * \ingroup gdcmDicomDir
267 * \brief Set the method to delete the argument
268 * The argument is destroyed when the method is changed or when the
270 * @param method Method to call to delete the argument
272 void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod *method)
274 progressMethodArgDelete=method;
278 * \ingroup gdcmDicomDir
279 * \brief Set the end method to call when the parsing of the directory ends
280 * @param method Method to call
281 * @param arg Argument to pass to the method
282 * @param argDelete Argument
283 * \warning In python : the arg parameter isn't considered
285 void gdcmDicomDir::SetEndMethod(gdcmMethod *method, void *arg, gdcmMethod *argDelete)
287 if((endArg)&&(endMethodArgDelete))
288 endMethodArgDelete(endArg);
292 endMethodArgDelete=argDelete;
296 * \ingroup gdcmDicomDir
297 * \brief Set the method to delete the argument
298 * The argument is destroyed when the method is changed or when the class
300 * @param method Method to call to delete the argument
302 void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod *method)
304 endMethodArgDelete=method;
308 * \ingroup gdcmDicomDir
309 * \brief writes on disc a DICOMDIR
310 * \ warning does NOT add the missing elements in the header :
311 * it's up to the user doing it !
312 * \todo : to be re-written using the DICOMDIR tree-like structure
313 * *not* the chained list
314 * (does NOT exist if the DICOMDIR is user-forged !)
315 * @param fileName file to be written to
316 * @return false only when fail to open
319 bool gdcmDicomDir::Write(std::string fileName)
323 fp1=fopen(fileName.c_str(),"wb");
326 printf("Failed to open(write) File [%s] \n",fileName.c_str());
330 char * filePreamble = new char[128];
331 fwrite(filePreamble,128,1,fp1);
332 fwrite("DICM",4,1,fp1);
333 delete[] filePreamble;
334 UpdateDirectoryRecordSequenceLength();
342 * \brief Writes in a file using the tree-like structure.
343 * @param _fp already open file pointer
346 void gdcmDicomDir::WriteEntries(FILE *) //_fp
348 /// \todo (?) tester les echecs en ecriture
349 /// (apres chaque fwrite, dans le WriteEntry)
352 /* TODO : to go on compiling
354 gdcmDicomDirMeta *ptrMeta;
355 ListDicomDirPatient::iterator itPatient;
356 ListDicomDirStudy::iterator itStudy;
357 ListDicomDirSerie::iterator itSerie;
358 ListDicomDirImage::iterator itImage;
361 ptrMeta= GetDicomDirMeta();
362 for(i=ptrMeta->debut();i!=ptrMeta->fin();++i) {
363 WriteEntry(*i,_fp, gdcmExplicitVR);
366 itPatient = GetDicomDirPatients().begin();
367 while ( itPatient != GetDicomDirPatients().end() ) {
368 for(i=(*itPatient)->debut();i!=(*itPatient)->fin();++i) {
369 WriteEntry(*i,_fp, gdcmExplicitVR);
371 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
372 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) {
373 for(i=(*itStudy)->debut();i!=(*itStudy)->fin();++i) {
374 WriteEntry(*i,_fp, gdcmExplicitVR);
376 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
377 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) {
378 for(i=(*itSerie)->debut();i!=(*itSerie)->fin();++i) {
379 WriteEntry(*i,_fp, gdcmExplicitVR);
381 itImage = ((*itSerie)->GetDicomDirImages()).begin();
382 while (itImage != (*itSerie)->GetDicomDirImages().end() ) {
383 for(i=(*itImage)->debut();i!=(*itImage)->fin();++i) {
384 WriteEntry(*i,_fp, gdcmExplicitVR);
397 //-----------------------------------------------------------------------------
401 * \ingroup gdcmDicomDir
402 * \brief create a gdcmDocument-like chained list from a root Directory
403 * @param path entry point of the tree-like structure
405 void gdcmDicomDir::CreateDicomDirChainedList(std::string path)
408 gdcmDirList fileList(path,1); // gets recursively the file list
409 unsigned int count=0;
416 for(gdcmDirList::iterator it=fileList.begin();
420 std::cout << "nom fichier " << it->c_str() << std::endl; //JPR
422 progress=(float)(count+1)/(float)fileList.size();
423 CallProgressMethod();
427 header=new gdcmHeader(it->c_str());
429 std::cout << "echec new Header " << it->c_str() << std::endl; // JPR
431 if(header->IsReadable()) {
432 list.push_back(header); // adds the file header to the chained list
433 std::cout << "readable : " <<it->c_str() << std::endl;
441 // sorts Patient/Study/Serie/
442 std::sort(list.begin(),list.end(),gdcmDicomDir::HeaderLessThan);
444 std::string tmp=fileList.GetDirName();
446 //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
447 SetElements(tmp,list);
453 * \ingroup gdcmDicomDir
454 * \brief adds *the* Meta to a partially created DICOMDIR
457 // FIXME : Heuuuuu ! Il prend les Entries du Document deja parse,
458 // il ne fabrique rien !
460 gdcmDicomDirMeta * gdcmDicomDir::NewMeta(void) {
461 gdcmDicomDirMeta *m = new gdcmDicomDirMeta(&tagHT);
462 for (TagDocEntryHT::iterator cc = tagHT.begin();cc != tagHT.end();++cc) {
463 m->AddDocEntry(cc->second);
470 * \ingroup gdcmDicomDir
471 * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
473 gdcmDicomDirPatient * gdcmDicomDir::NewPatient(void) {
474 std::list<gdcmElement> elemList;
475 std::list<gdcmElement>::iterator it;
477 gdcmDictEntry *dictEntry;
480 gdcmSQItem *s = new gdcmSQItem(0);
482 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
484 // TODO : use FillObject !!!
486 // for all the DicomDirPatient Elements
488 for(it=elemList.begin();it!=elemList.end();++it)
492 dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
493 entry=new gdcmValEntry(dictEntry);
494 entry->SetOffset(0); // just to avoid further missprinting
495 entry->SetValue(it->value);
497 // dealing with value length ...
499 if(dictEntry->GetGroup()==0xfffe)
501 entry->SetLength(entry->GetValue().length());
503 else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") )
507 else if( (dictEntry->GetVR()=="US") || (dictEntry->GetVR()=="SS") )
511 else if(dictEntry->GetVR()=="SQ")
513 entry->SetLength(0xffffffff);
517 entry->SetLength(entry->GetValue().length());
519 s->AddDocEntry(entry);
522 gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &tagHT);
523 patients.push_front(p);
528 * \brief adds to the HTable
529 * the gdcmEntries (Dicom Elements) corresponding to the given type
530 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
531 * @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT,
532 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
533 * @param header gdcmHeader of the current file
535 void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
536 gdcmDocument *header)
538 std::list<gdcmElement> elemList;
539 std::list<gdcmElement>::iterator it;
540 guint16 tmpGr, tmpEl;
541 gdcmDictEntry *dictEntry;
546 case GDCM_DICOMDIR_PATIENT:
547 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
549 case GDCM_DICOMDIR_STUDY:
550 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
552 case GDCM_DICOMDIR_SERIE:
553 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements();
555 case GDCM_DICOMDIR_IMAGE:
556 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
558 case GDCM_DICOMDIR_META:
559 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
565 for(it=elemList.begin();it!=elemList.end();++it) {
568 dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
569 entry=new gdcmValEntry(dictEntry); // Be sure it's never a BinEntry !
571 entry->SetOffset(0); // just to avoid further missprinting
574 val=header->GetEntryByNumber(tmpGr,tmpEl);
578 if(val==GDCM_UNFOUND)
580 if((tmpGr==0x0004) &&(tmpEl==0x1130) ) // File-set ID
582 // force to the *end* File Name
585 else if( (tmpGr==0x0004) && (tmpEl==0x1500) ) // Only used for image
587 if(header->GetFileName().substr(0,path.length())!=path)
589 dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path"
590 " of file name is incorrect");
591 val=header->GetFileName();
595 val=&(header->GetFileName().c_str()[path.length()]);
605 if (header->GetEntryLengthByNumber(tmpGr,tmpEl)== 0)
609 entry->SetValue(val);
613 if(dictEntry->GetGroup()==0xfffe) {
614 entry->SetLength(entry->GetValue().length());
616 else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") )
620 else if( (dictEntry->GetVR()=="US") || (dictEntry->GetVR()=="SS") )
624 else if(dictEntry->GetVR()=="SQ")
626 entry->SetLength(0xffffffff);
630 entry->SetLength(entry->GetValue().length());
633 //AddDocEntry(entry); // both in H Table and in chained list
634 tagHT[entry->GetKey()] = entry; // FIXME : use a SEQUENCE !
639 * \brief CallStartMethod
641 void gdcmDicomDir::CallStartMethod(void)
646 startMethod(startArg);
649 * \ingroup gdcmDicomDir
650 * \brief CallProgressMethod
652 void gdcmDicomDir::CallProgressMethod(void)
655 progressMethod(progressArg);
658 * \ingroup gdcmDicomDir
659 * \brief CallEndMethod
661 void gdcmDicomDir::CallEndMethod(void)
668 //-----------------------------------------------------------------------------
671 * \ingroup gdcmDicomDir
672 * \brief create a 'gdcmDicomDir' from a DICOMDIR gdcmHeader
674 void gdcmDicomDir::CreateDicomDir()
676 // The list is parsed.
677 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
678 // 1 - we save the beginning iterator
679 // 2 - we continue to parse
680 // 3 - we find an other tag
681 // + we create the object for the precedent tag
684 gdcmDicomDirType type=gdcmDicomDir::GDCM_DICOMDIR_META;
686 // Directory record sequence
687 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
690 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
691 " sequence (0x0004,0x1220)");
692 /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?
696 gdcmSeqEntry* s = dynamic_cast<gdcmSeqEntry*>(e);
699 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: no SeqEntry present");
703 ListSQItem listItems = s->GetSQItems();
704 gdcmDicomDirMeta *m = new gdcmDicomDirMeta(&tagHT);
709 for(ListSQItem::iterator i=listItems.begin(); i !=listItems.end();++i)
711 d=(*i)->GetDocEntryByNumber(0x0004, 0x1430); // Directory Record Type
712 if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(d) )
714 v = ValEntry->GetValue();
718 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: not a ValEntry.");
724 AddDicomDirPatientToEnd(*i);
725 //AddObjectToEnd(type,*i);
726 type=gdcmDicomDir::GDCM_DICOMDIR_PATIENT;
731 AddDicomDirStudyToEnd(*i);
732 // AddObjectToEnd(type,*i);
733 type=gdcmDicomDir::GDCM_DICOMDIR_STUDY;
738 AddDicomDirSerieToEnd(*i);
739 // AddObjectToEnd(type,*i);
740 type=gdcmDicomDir::GDCM_DICOMDIR_SERIE;
745 AddDicomDirImageToEnd(*i);
746 // AddObjectToEnd(type,*i);
747 type=gdcmDicomDir::GDCM_DICOMDIR_IMAGE;
751 // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
752 // neither an 'IMAGE' SQItem. Skip to next item.
757 * \ingroup gdcmDicomDir
758 * \brief AddObjectToEnd
760 * @param begin iterator on the first DocEntry within the chained List
761 * @param end iterator on the last DocEntry within the chained List
766 /*void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,gdcmSQItem *s)
773 case gdcmDicomDir::GDCM_DICOMDIR_META:
776 case gdcmDicomDir::GDCM_DICOMDIR_PATIENT:
777 AddDicomDirPatientToEnd(s);
779 case gdcmDicomDir::GDCM_DICOMDIR_STUDY:
780 AddDicomDirStudyToEnd(s);
782 case gdcmDicomDir::GDCM_DICOMDIR_SERIE:
783 AddDicomDirSerieToEnd(s);
785 case gdcmDicomDir::GDCM_DICOMDIR_IMAGE:
786 AddDicomDirImageToEnd(s);
788 case gdcmDicomDir::GDCM_DICOMDIR_NONE:
789 AddDicomDirImageToEnd(s); //FIXME
797 * \ingroup gdcmDicomDir
798 * \brief Well ... there is only one occurence
800 void gdcmDicomDir::AddDicomDirMeta()
804 metaElems = new gdcmDicomDirMeta(&tagHT);
808 * \ingroup gdcmDicomDir
809 * \brief AddDicomDirPatientToEnd
810 * @param s SQ Item to enqueue to the DicomPatient chained List
812 void gdcmDicomDir::AddDicomDirPatientToEnd(gdcmSQItem *s)
814 patients.push_back(new gdcmDicomDirPatient(s, &tagHT));
818 * \ingroup gdcmDicomDir
819 * \brief AddDicomDirStudyToEnd
820 * @param s SQ Item to enqueue to the DicomDirStudy chained List
822 void gdcmDicomDir::AddDicomDirStudyToEnd(gdcmSQItem *s)
824 if(patients.size()>0)
826 ListDicomDirPatient::iterator itp=patients.end();
828 (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(s, &tagHT));
832 * \ingroup gdcmDicomDir
833 * \brief AddDicomDirSerieToEnd
834 * @param s SQ Item to enqueue to the DicomDirSerie chained List
836 void gdcmDicomDir::AddDicomDirSerieToEnd(gdcmSQItem *s)
838 if(patients.size()>0)
840 ListDicomDirPatient::iterator itp=patients.end();
843 if((*itp)->GetDicomDirStudies().size()>0)
845 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
847 (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(s, &tagHT));
853 * \ingroup gdcmDicomDir
854 * \brief AddDicomDirImageToEnd
855 * @param s SQ Item to enqueue to the DicomDirImage chained List
857 void gdcmDicomDir::AddDicomDirImageToEnd(gdcmSQItem *s)
859 if(patients.size()>0)
861 ListDicomDirPatient::iterator itp=patients.end();
864 if((*itp)->GetDicomDirStudies().size()>0)
866 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
869 if((*itst)->GetDicomDirSeries().size()>0)
871 ListDicomDirSerie::iterator its=(*itst)->GetDicomDirSeries().end();
873 (*its)->AddDicomDirImage(new gdcmDicomDirImage(s, &tagHT));
880 * \ingroup gdcmDicomDir
881 * \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info
882 * @param path path of the root directory
883 * @param list chained list of Headers
885 void gdcmDicomDir::SetElements(std::string &path, VectDocument &list)
887 std::string patPrevName="", patPrevID="";
888 std::string studPrevInstanceUID="", studPrevID="";
889 std::string serPrevInstanceUID="", serPrevID="";
891 std::string patCurName, patCurID;
892 std::string studCurInstanceUID, studCurID;
893 std::string serCurInstanceUID, serCurID;
895 SetElement(path,GDCM_DICOMDIR_META,NULL);
897 for(VectDocument::iterator it=list.begin();it!=list.end();++it)
899 // get the current file characteristics
900 patCurName= (*it)->GetEntryByNumber(0x0010,0x0010);
901 patCurID= (*it)->GetEntryByNumber(0x0010,0x0011);
902 studCurInstanceUID=(*it)->GetEntryByNumber(0x0020,0x000d);
903 studCurID= (*it)->GetEntryByNumber(0x0020,0x0010);
904 serCurInstanceUID= (*it)->GetEntryByNumber(0x0020,0x000e);
905 serCurID= (*it)->GetEntryByNumber(0x0020,0x0011);
907 if(patCurName!=patPrevName || patCurID!=patPrevID)
908 SetElement(path,GDCM_DICOMDIR_PATIENT,*it);
910 // if new Study Deal with 'STUDY' Elements
911 if(studCurInstanceUID!=studPrevInstanceUID || studCurID!=studPrevID)
912 SetElement(path,GDCM_DICOMDIR_STUDY,*it);
914 // if new Serie Deal with 'SERIE' Elements
915 if(serCurInstanceUID!=serPrevInstanceUID || serCurID!=serPrevID)
916 SetElement(path,GDCM_DICOMDIR_SERIE,*it);
918 // Always Deal with 'IMAGE' Elements
919 SetElement(path,GDCM_DICOMDIR_IMAGE,*it);
921 patPrevName= patCurName;
923 studPrevInstanceUID=studCurInstanceUID;
924 studPrevID= studCurID;
925 serPrevInstanceUID= serCurInstanceUID;
931 * \ingroup gdcmDicomDir
932 * \brief compares two dgcmHeaders
934 bool gdcmDicomDir::HeaderLessThan(gdcmDocument *header1,gdcmDocument *header2)
936 return(*header1<*header2);
940 * \ingroup gdcmDicomDir
941 * \brief Sets the accurate value for the (0x0004,0x1220) element of a DICOMDIR
944 void gdcmDicomDir::UpdateDirectoryRecordSequenceLength() {
946 // FIXME : to go on compiling
948 // to be re written !
951 ListTag::iterator it;
954 for(it=listEntries.begin();it!=listEntries.end();++it) {
955 gr = (*it)->GetGroup();
956 el = (*it)->GetElement();
959 if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) {
960 offset += 4; // explicit VR AND OB, OW, SQ : 4 more bytes
962 offset += 2 + 2 + 4 + (*it)->GetLength();
964 offset += 4; // delimiters don't have a value.
967 //bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
968 SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
973 //-----------------------------------------------------------------------------