+/*
+ * \ingroup gdcmDicomDir
+ * \brief
+ * @param
+ */
+void gdcmDicomDir::SetElements(std::string &path,ListHeader &list)
+{
+ std::string patPrevName="", patPrevID="";
+ std::string studPrevInstanceUID="", studPrevID="";
+ std::string serPrevInstanceUID="", serPrevID="";
+
+ std::string patCurName, patCurID;
+ std::string studCurInstanceUID, studCurID;
+ std::string serCurInstanceUID, serCurID;
+
+ SetElement(path,GDCM_NONE,NULL);
+
+ ListTag::iterator debPat=listEntries.begin();
+ for(ListHeader::iterator it=list.begin();it!=list.end();++it)
+ {
+ // get the current file characteristics
+ patCurName=(*it)->GetEntryByNumber(0x0010,0x0010);
+ patCurID=(*it)->GetEntryByNumber(0x0010,0x0011);
+ studCurInstanceUID=(*it)->GetEntryByNumber(0x0020,0x000d);
+ studCurID=(*it)->GetEntryByNumber(0x0020,0x0010);
+ serCurInstanceUID=(*it)->GetEntryByNumber(0x0020,0x000e);
+ serCurID=(*it)->GetEntryByNumber(0x0020,0x0011);
+
+ if(patCurName!=patPrevName || patCurID!=patPrevID)
+ SetElement(path,GDCM_PATIENT,*it);
+
+ // if new Study Deal with 'STUDY' Elements
+ if(studCurInstanceUID!=studPrevInstanceUID || studCurID!=studPrevID)
+ SetElement(path,GDCM_STUDY,*it);
+
+ // if new Serie Deal with 'SERIE' Elements
+ if(serCurInstanceUID!=serPrevInstanceUID || serCurID!=serPrevID)
+ {
+ SetElement(path,GDCM_SERIE,*it);
+ }
+
+ // Always Deal with 'IMAGE' Elements
+ SetElement(path,GDCM_IMAGE,*it);
+
+ patPrevName=patCurName;
+ patPrevID=patCurID;
+ studPrevInstanceUID=studCurInstanceUID;
+ studPrevID=studCurID;
+ serPrevInstanceUID=serCurInstanceUID;
+ serPrevID=serCurID;
+ }
+}
+
+/*
+ * \ingroup gdcmDicomDir
+ * \brief
+ * @param
+ */
+void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader *header)
+{
+ std::list<gdcmElement> elemList;
+ std::list<gdcmElement>::iterator it;
+ guint16 tmpGr, tmpEl;
+ gdcmDictEntry *dictEntry;
+ gdcmHeaderEntry *entry;
+ std::string val;
+
+ switch(type)
+ {
+ case GDCM_PATIENT:
+ elemList=gdcmGlobal::GetDicomDirElements()->GetPatientElements();
+ break;
+ case GDCM_STUDY:
+ elemList=gdcmGlobal::GetDicomDirElements()->GetStudyElements();
+ break;
+ case GDCM_SERIE:
+ elemList=gdcmGlobal::GetDicomDirElements()->GetSerieElements();
+ break;
+ case GDCM_IMAGE:
+ elemList=gdcmGlobal::GetDicomDirElements()->GetImageElements();
+ break;
+ case GDCM_NONE:
+ elemList=gdcmGlobal::GetDicomDirElements()->GetMetaElements();
+ break;
+ default:
+ return;
+ }
+
+ for(it=elemList.begin();it!=elemList.end();++it)
+ {
+ tmpGr=it->group;
+ tmpEl=it->elem;
+
+ dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
+ entry=new gdcmHeaderEntry(dictEntry);
+ entry->SetOffset(0); // just to avoid missprinting
+
+ if(header)
+ val=header->GetEntryByNumber(tmpGr,tmpEl);
+ else
+ val=GDCM_UNFOUND;
+
+ if(val==GDCM_UNFOUND)
+ {
+ if((tmpGr==0x0004) &&(tmpEl==0x1130) )
+ {
+ // TODO force the *end* File Name(remove path)
+ val=path;
+ }
+ else if( (tmpGr==0x0004) && (tmpEl==0x1500) ) // Only used for image
+ {
+ if(header->GetFileName().substr(0,path.length())!=path)
+ {
+ dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path of file name is incorrect");
+ val=header->GetFileName();
+ }
+ else
+ val=&(header->GetFileName()[path.length()]);
+ }
+ else
+ {
+ val=it->value;
+ }
+ }
+ entry->SetValue(val);
+
+ if(dictEntry)
+ {
+ if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") )
+ {
+ entry->SetLength(4);
+ }
+ else if( (dictEntry->GetVR()=="US") || (dictEntry->GetVR()=="SS") )
+ {
+ entry->SetLength(2);
+ }
+ else if(dictEntry->GetVR()=="SQ")
+ {
+ entry->SetLength(0xffffffff);
+ }
+ else
+ {
+ entry->SetLength(entry->GetValue().length());
+ }
+ }
+
+ listEntries.push_back(entry);
+ }
+}
+
+bool gdcmDicomDir::HeaderLessThan(gdcmHeader *header1,gdcmHeader *header2)
+{
+ return(*header1<*header2);
+}
+