1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDir.cxx,v $
6 Date: $Date: 2004/06/19 23:51:03 $
7 Version: $Revision: 1.48 $
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)
137 std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...
138 SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements
143 * \brief Canonical destructor
145 gdcmDicomDir::~gdcmDicomDir()
147 SetStartMethod(NULL);
148 SetProgressMethod(NULL);
154 for(ListDicomDirPatient::iterator cc = patients.begin();
162 //-----------------------------------------------------------------------------
165 * \brief Canonical Printer
167 void gdcmDicomDir::Print(std::ostream &os)
171 metaElems->SetPrintLevel(printLevel);
172 metaElems->Print(os);
174 for(ListDicomDirPatient::iterator cc = patients.begin();
175 cc != patients.end();
178 (*cc)->SetPrintLevel(printLevel);
183 //-----------------------------------------------------------------------------
186 * \brief This predicate, based on hopefully reasonable heuristics,
187 * decides whether or not the current header was properly parsed
188 * and contains the mandatory information for being considered as
189 * a well formed and usable DicomDir.
190 * @return true when gdcmDocument is the one of a reasonable DicomDir,
193 bool gdcmDicomDir::IsReadable(void)
195 if(!gdcmDocument::IsReadable())
199 if(patients.size()<=0)
206 * \ingroup gdcmDicomDir
207 * \brief fills the whole structure, starting from a root Directory
209 void gdcmDicomDir::ParseDirectory(void)
211 CreateDicomDirChainedList(GetFileName());
216 * \ingroup gdcmDicomDir
217 * \brief Set the start method to call when the parsing of the directory starts
218 * @param method Method to call
219 * @param arg Argument to pass to the method
220 * @param argDelete Argument
221 * \warning In python : the arg parameter isn't considered
223 void gdcmDicomDir::SetStartMethod(gdcmMethod *method,void *arg,gdcmMethod *argDelete)
225 if((startArg)&&(startMethodArgDelete))
226 startMethodArgDelete(startArg);
230 startMethodArgDelete=argDelete;
234 * \ingroup gdcmDicomDir
235 * \brief Set the method to delete the argument
236 * The argument is destroyed when the method is changed or when the
238 * @param method Method to call to delete the argument
240 void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod *method)
242 startMethodArgDelete=method;
246 * \ingroup gdcmDicomDir
247 * \brief Set the progress method to call when the parsing of the directory progress
248 * @param method Method to call
249 * @param arg Argument to pass to the method
250 * @param argDelete Argument
251 * \warning In python : the arg parameter isn't considered
253 void gdcmDicomDir::SetProgressMethod(gdcmMethod *method,void *arg,gdcmMethod *argDelete)
255 if((progressArg)&&(progressMethodArgDelete))
256 progressMethodArgDelete(progressArg);
258 progressMethod=method;
260 progressMethodArgDelete=argDelete;
264 * \ingroup gdcmDicomDir
265 * \brief Set the method to delete the argument
266 * The argument is destroyed when the method is changed or when the
268 * @param method Method to call to delete the argument
270 void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod *method)
272 progressMethodArgDelete=method;
276 * \ingroup gdcmDicomDir
277 * \brief Set the end method to call when the parsing of the directory ends
278 * @param method Method to call
279 * @param arg Argument to pass to the method
280 * @param argDelete Argument
281 * \warning In python : the arg parameter isn't considered
283 void gdcmDicomDir::SetEndMethod(gdcmMethod *method, void *arg, gdcmMethod *argDelete)
285 if((endArg)&&(endMethodArgDelete))
286 endMethodArgDelete(endArg);
290 endMethodArgDelete=argDelete;
294 * \ingroup gdcmDicomDir
295 * \brief Set the method to delete the argument
296 * The argument is destroyed when the method is changed or when the class
298 * @param method Method to call to delete the argument
300 void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod *method)
302 endMethodArgDelete=method;
306 * \ingroup gdcmDicomDir
307 * \brief writes on disc a DICOMDIR
308 * \ warning does NOT add the missing elements in the header :
309 * it's up to the user doing it !
310 * \todo : to be re-written using the DICOMDIR tree-like structure
311 * *not* the chained list
312 * (does NOT exist if the DICOMDIR is user-forged !)
313 * @param fileName file to be written to
314 * @return false only when fail to open
317 bool gdcmDicomDir::Write(std::string fileName)
321 fp1=fopen(fileName.c_str(),"wb");
324 printf("Failed to open(write) File [%s] \n",fileName.c_str());
328 char * filePreamble = new char[128];
329 fwrite(filePreamble,128,1,fp1);
330 fwrite("DICM",4,1,fp1);
331 delete[] filePreamble;
332 UpdateDirectoryRecordSequenceLength();
340 * \brief Writes in a file using the tree-like structure.
341 * @param _fp already open file pointer
344 void gdcmDicomDir::WriteEntries(FILE *_fp)
346 /// \todo (?) tester les echecs en ecriture
347 /// (apres chaque fwrite, dans le WriteEntry)
350 /* TODO : to go on compiling
352 gdcmDicomDirMeta *ptrMeta;
353 ListDicomDirPatient::iterator itPatient;
354 ListDicomDirStudy::iterator itStudy;
355 ListDicomDirSerie::iterator itSerie;
356 ListDicomDirImage::iterator itImage;
359 ptrMeta= GetDicomDirMeta();
360 for(i=ptrMeta->debut();i!=ptrMeta->fin();++i) {
361 WriteEntry(*i,_fp, gdcmExplicitVR);
364 itPatient = GetDicomDirPatients().begin();
365 while ( itPatient != GetDicomDirPatients().end() ) {
366 for(i=(*itPatient)->debut();i!=(*itPatient)->fin();++i) {
367 WriteEntry(*i,_fp, gdcmExplicitVR);
369 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
370 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) {
371 for(i=(*itStudy)->debut();i!=(*itStudy)->fin();++i) {
372 WriteEntry(*i,_fp, gdcmExplicitVR);
374 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
375 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) {
376 for(i=(*itSerie)->debut();i!=(*itSerie)->fin();++i) {
377 WriteEntry(*i,_fp, gdcmExplicitVR);
379 itImage = ((*itSerie)->GetDicomDirImages()).begin();
380 while (itImage != (*itSerie)->GetDicomDirImages().end() ) {
381 for(i=(*itImage)->debut();i!=(*itImage)->fin();++i) {
382 WriteEntry(*i,_fp, gdcmExplicitVR);
395 //-----------------------------------------------------------------------------
399 * \ingroup gdcmDicomDir
400 * \brief create a gdcmDocument-like chained list from a root Directory
401 * @param path entry point of the tree-like structure
403 void gdcmDicomDir::CreateDicomDirChainedList(std::string path)
407 gdcmDirList fileList(path,1); // gets recursively the file list
408 unsigned int count=0;
415 for(gdcmDirList::iterator it=fileList.begin();
419 progress=(float)(count+1)/(float)fileList.size();
420 CallProgressMethod();
424 header=new gdcmHeader(it->c_str());
425 if(header->IsReadable())
426 list.push_back(header); // adds the file header to the chained list
432 // sorts Patient/Study/Serie/
433 std::sort(list.begin(),list.end(),gdcmDicomDir::HeaderLessThan);
435 std::string tmp=fileList.GetDirName();
437 //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
438 SetElements(tmp,list);
444 * \ingroup gdcmDicomDir
445 * \brief adds *the* Meta to a partially created DICOMDIR
448 // FIXME : Heuuuuu ! Il prend les Entries du Document deja parse,
449 // il ne fabrique rien !
451 gdcmDicomDirMeta * gdcmDicomDir::NewMeta(void) {
452 gdcmDicomDirMeta *m = new gdcmDicomDirMeta(&tagHT);
453 for (TagDocEntryHT::iterator cc = tagHT.begin();cc != tagHT.end();++cc) {
454 m->AddDocEntry(cc->second);
461 * \ingroup gdcmDicomDir
462 * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
464 gdcmDicomDirPatient * gdcmDicomDir::NewPatient(void) {
465 std::list<gdcmElement> elemList;
466 std::list<gdcmElement>::iterator it;
468 gdcmDictEntry *dictEntry;
471 gdcmSQItem *s = new gdcmSQItem(0);
473 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
475 // TODO : use FillObject !!!
477 // for all the DicomDirPatient Elements
479 for(it=elemList.begin();it!=elemList.end();++it)
483 dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
484 entry=new gdcmValEntry(dictEntry);
485 entry->SetOffset(0); // just to avoid further missprinting
486 entry->SetValue(it->value);
488 // dealing with value length ...
490 if(dictEntry->GetGroup()==0xfffe)
492 entry->SetLength(entry->GetValue().length());
494 else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") )
498 else if( (dictEntry->GetVR()=="US") || (dictEntry->GetVR()=="SS") )
502 else if(dictEntry->GetVR()=="SQ")
504 entry->SetLength(0xffffffff);
508 entry->SetLength(entry->GetValue().length());
510 s->AddDocEntry(entry);
513 gdcmDicomDirPatient *p = new gdcmDicomDirPatient(s, &tagHT);
514 patients.push_front(p);
519 * \brief adds to the HTable
520 * the gdcmEntries (Dicom Elements) corresponding to the given type
521 * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
522 * @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT,
523 * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
524 * @param header gdcmHeader of the current file
526 void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,
527 gdcmDocument *header)
529 std::list<gdcmElement> elemList;
530 std::list<gdcmElement>::iterator it;
531 guint16 tmpGr, tmpEl;
532 gdcmDictEntry *dictEntry;
538 case GDCM_DICOMDIR_PATIENT:
539 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
541 case GDCM_DICOMDIR_STUDY:
542 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements();
544 case GDCM_DICOMDIR_SERIE:
545 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements();
547 case GDCM_DICOMDIR_IMAGE:
548 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements();
550 case GDCM_DICOMDIR_META:
551 elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements();
557 for(it=elemList.begin();it!=elemList.end();++it)
561 dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
562 entry=new gdcmValEntry(dictEntry);
563 entry->SetOffset(0); // just to avoid further missprinting
566 val=header->GetEntryByNumber(tmpGr,tmpEl);
570 if(val==GDCM_UNFOUND)
572 if((tmpGr==0x0004) &&(tmpEl==0x1130) ) // File-set ID
574 // force to the *end* File Name
577 else if( (tmpGr==0x0004) && (tmpEl==0x1500) ) // Only used for image
579 if(header->GetFileName().substr(0,path.length())!=path)
581 dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path"
582 " of file name is incorrect");
583 val=header->GetFileName();
587 val=&(header->GetFileName().c_str()[path.length()]);
597 if (header->GetEntryLengthByNumber(tmpGr,tmpEl)== 0)
601 entry->SetValue(val);
605 if(dictEntry->GetGroup()==0xfffe)
607 entry->SetLength(entry->GetValue().length());
609 else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") )
613 else if( (dictEntry->GetVR()=="US") || (dictEntry->GetVR()=="SS") )
617 else if(dictEntry->GetVR()=="SQ")
619 entry->SetLength(0xffffffff);
623 entry->SetLength(entry->GetValue().length());
626 //AddDocEntry(entry); // both in H Table and in chained list
627 tagHT[entry->GetKey()] = entry; // FIXME : use a SEQUENCE !
632 * \brief CallStartMethod
634 void gdcmDicomDir::CallStartMethod(void)
639 startMethod(startArg);
642 * \ingroup gdcmDicomDir
643 * \brief CallProgressMethod
645 void gdcmDicomDir::CallProgressMethod(void)
648 progressMethod(progressArg);
651 * \ingroup gdcmDicomDir
652 * \brief CallEndMethod
654 void gdcmDicomDir::CallEndMethod(void)
661 //-----------------------------------------------------------------------------
664 * \ingroup gdcmDicomDir
665 * \brief create a 'gdcmDicomDir' from a DICOMDIR gdcmHeader
667 void gdcmDicomDir::CreateDicomDir()
669 // The list is parsed.
670 // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
671 // 1 - we save the beginning iterator
672 // 2 - we continue to parse
673 // 3 - we find an other tag
674 // + we create the object for the precedent tag
677 gdcmDicomDirType type=gdcmDicomDir::GDCM_DICOMDIR_META;
679 // Directory record sequence
680 gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
683 dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : NO Directory record"
684 " sequence (0x0004,0x1220)");
685 /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?
689 gdcmSeqEntry* s = dynamic_cast<gdcmSeqEntry*>(e);
692 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: no SeqEntry present");
696 ListSQItem listItems = s->GetSQItems();
697 gdcmDicomDirMeta *m = new gdcmDicomDirMeta(&tagHT);
701 for(ListSQItem::iterator i=listItems.begin(); i !=listItems.end();++i)
703 d=(*i)->GetDocEntryByNumber(0x0004, 0x1430); // Directory Record Type
704 if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(d) )
706 v = ValEntry->GetValue();
710 dbg.Verbose(0, "gdcmDicomDir::CreateDicomDir: not a ValEntry.");
716 AddDicomDirPatientToEnd(*i);
717 //AddObjectToEnd(type,*i);
718 type=gdcmDicomDir::GDCM_DICOMDIR_PATIENT;
723 AddDicomDirStudyToEnd(*i);
724 // AddObjectToEnd(type,*i);
725 type=gdcmDicomDir::GDCM_DICOMDIR_STUDY;
730 AddDicomDirSerieToEnd(*i);
731 // AddObjectToEnd(type,*i);
732 type=gdcmDicomDir::GDCM_DICOMDIR_SERIE;
737 AddDicomDirImageToEnd(*i);
738 // AddObjectToEnd(type,*i);
739 type=gdcmDicomDir::GDCM_DICOMDIR_IMAGE;
743 // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
744 // neither an 'IMAGE' SQItem. Skip to next item.
749 * \ingroup gdcmDicomDir
750 * \brief AddObjectToEnd
752 * @param begin iterator on the first DocEntry within the chained List
753 * @param end iterator on the last DocEntry within the chained List
758 /*void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,gdcmSQItem *s)
765 case gdcmDicomDir::GDCM_DICOMDIR_META:
768 case gdcmDicomDir::GDCM_DICOMDIR_PATIENT:
769 AddDicomDirPatientToEnd(s);
771 case gdcmDicomDir::GDCM_DICOMDIR_STUDY:
772 AddDicomDirStudyToEnd(s);
774 case gdcmDicomDir::GDCM_DICOMDIR_SERIE:
775 AddDicomDirSerieToEnd(s);
777 case gdcmDicomDir::GDCM_DICOMDIR_IMAGE:
778 AddDicomDirImageToEnd(s);
780 case gdcmDicomDir::GDCM_DICOMDIR_NONE:
781 AddDicomDirImageToEnd(s); //FIXME
789 * \ingroup gdcmDicomDir
790 * \brief Well ... there is only one occurence
792 void gdcmDicomDir::AddDicomDirMeta()
796 metaElems = new gdcmDicomDirMeta(&tagHT);
800 * \ingroup gdcmDicomDir
801 * \brief AddDicomDirPatientToEnd
802 * @param s SQ Item to enqueue to the DicomPatient chained List
804 void gdcmDicomDir::AddDicomDirPatientToEnd(gdcmSQItem *s)
806 patients.push_back(new gdcmDicomDirPatient(s, &tagHT));
810 * \ingroup gdcmDicomDir
811 * \brief AddDicomDirStudyToEnd
812 * @param s SQ Item to enqueue to the DicomDirStudy chained List
814 void gdcmDicomDir::AddDicomDirStudyToEnd(gdcmSQItem *s)
816 if(patients.size()>0)
818 ListDicomDirPatient::iterator itp=patients.end();
820 (*itp)->AddDicomDirStudy(new gdcmDicomDirStudy(s, &tagHT));
824 * \ingroup gdcmDicomDir
825 * \brief AddDicomDirSerieToEnd
826 * @param s SQ Item to enqueue to the DicomDirSerie chained List
828 void gdcmDicomDir::AddDicomDirSerieToEnd(gdcmSQItem *s)
830 if(patients.size()>0)
832 ListDicomDirPatient::iterator itp=patients.end();
835 if((*itp)->GetDicomDirStudies().size()>0)
837 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
839 (*itst)->AddDicomDirSerie(new gdcmDicomDirSerie(s, &tagHT));
845 * \ingroup gdcmDicomDir
846 * \brief AddDicomDirImageToEnd
847 * @param s SQ Item to enqueue to the DicomDirImage chained List
849 void gdcmDicomDir::AddDicomDirImageToEnd(gdcmSQItem *s)
851 if(patients.size()>0)
853 ListDicomDirPatient::iterator itp=patients.end();
856 if((*itp)->GetDicomDirStudies().size()>0)
858 ListDicomDirStudy::iterator itst=(*itp)->GetDicomDirStudies().end();
861 if((*itst)->GetDicomDirSeries().size()>0)
863 ListDicomDirSerie::iterator its=(*itst)->GetDicomDirSeries().end();
865 (*its)->AddDicomDirImage(new gdcmDicomDirImage(s, &tagHT));
872 * \ingroup gdcmDicomDir
873 * \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info
874 * @param path path of the root directory
875 * @param list chained list of Headers
877 void gdcmDicomDir::SetElements(std::string &path, VectDocument &list)
879 std::string patPrevName="", patPrevID="";
880 std::string studPrevInstanceUID="", studPrevID="";
881 std::string serPrevInstanceUID="", serPrevID="";
883 std::string patCurName, patCurID;
884 std::string studCurInstanceUID, studCurID;
885 std::string serCurInstanceUID, serCurID;
887 SetElement(path,GDCM_DICOMDIR_META,NULL);
889 for(VectDocument::iterator it=list.begin();it!=list.end();++it)
891 // get the current file characteristics
892 patCurName= (*it)->GetEntryByNumber(0x0010,0x0010);
893 patCurID= (*it)->GetEntryByNumber(0x0010,0x0011);
894 studCurInstanceUID=(*it)->GetEntryByNumber(0x0020,0x000d);
895 studCurID= (*it)->GetEntryByNumber(0x0020,0x0010);
896 serCurInstanceUID= (*it)->GetEntryByNumber(0x0020,0x000e);
897 serCurID= (*it)->GetEntryByNumber(0x0020,0x0011);
899 if(patCurName!=patPrevName || patCurID!=patPrevID)
900 SetElement(path,GDCM_DICOMDIR_PATIENT,*it);
902 // if new Study Deal with 'STUDY' Elements
903 if(studCurInstanceUID!=studPrevInstanceUID || studCurID!=studPrevID)
904 SetElement(path,GDCM_DICOMDIR_STUDY,*it);
906 // if new Serie Deal with 'SERIE' Elements
907 if(serCurInstanceUID!=serPrevInstanceUID || serCurID!=serPrevID)
908 SetElement(path,GDCM_DICOMDIR_SERIE,*it);
910 // Always Deal with 'IMAGE' Elements
911 SetElement(path,GDCM_DICOMDIR_IMAGE,*it);
913 patPrevName= patCurName;
915 studPrevInstanceUID=studCurInstanceUID;
916 studPrevID= studCurID;
917 serPrevInstanceUID= serCurInstanceUID;
923 * \ingroup gdcmDicomDir
924 * \brief compares two dgcmHeaders
926 bool gdcmDicomDir::HeaderLessThan(gdcmDocument *header1,gdcmDocument *header2)
928 return(*header1<*header2);
932 * \ingroup gdcmDicomDir
933 * \brief Sets the accurate value for the (0x0004,0x1220) element of a DICOMDIR
936 void gdcmDicomDir::UpdateDirectoryRecordSequenceLength() {
938 // FIXME : to go on compiling
940 // to be re written !
943 ListTag::iterator it;
946 for(it=listEntries.begin();it!=listEntries.end();++it) {
947 gr = (*it)->GetGroup();
948 el = (*it)->GetElement();
951 if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) {
952 offset += 4; // explicit VR AND OB, OW, SQ : 4 more bytes
954 offset += 2 + 2 + 4 + (*it)->GetLength();
956 offset += 4; // delimiters don't have a value.
959 //bool res=SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
960 SetEntryLengthByNumber(offset, 0x0004, 0x1220); // Hope there is no dupps.
965 //-----------------------------------------------------------------------------