+ if ( Patients.size() > 0 )
+ {
+ ListDicomDirPatient::iterator itp = Patients.end();
+ itp--;
+ (*itp)->AddStudy(dd);
+ return true;
+ }
+ return false;
+}
+
+/**
+ * \brief AddSerieToEnd
+ * @param dd SQ Item to enqueue to the DicomDirSerie chained List
+ */
+bool DicomDir::AddSerieToEnd(DicomDirSerie *dd)
+{
+ if ( Patients.size() > 0 )
+ {
+ ListDicomDirPatient::iterator itp = Patients.end();
+ itp--;
+
+ DicomDirStudy *study = (*itp)->GetLastStudy();
+ if ( study )
+ {
+ study->AddSerie(dd);
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * \brief AddVisitToEnd
+ * @param dd SQ Item to enqueue to the DicomDirVisit chained List
+ */
+bool DicomDir::AddVisitToEnd(DicomDirVisit *dd)
+{
+ if ( Patients.size() > 0 )
+ {
+ ListDicomDirPatient::iterator itp = Patients.end();
+ itp--;
+
+ DicomDirStudy *study = (*itp)->GetLastStudy();
+ if ( study )
+ {
+ study->AddVisit(dd);
+ return true;
+ }
+ }
+ return false;
+}
+/**
+ * \brief AddImageToEnd
+ * @param dd SQ Item to enqueue to the DicomDirImage chained List
+ */
+bool DicomDir::AddImageToEnd(DicomDirImage *dd)
+{
+ if ( Patients.size() > 0 )
+ {
+ ListDicomDirPatient::iterator itp = Patients.end();
+ itp--;
+
+ DicomDirStudy *study = (*itp)->GetLastStudy();
+ if ( study )
+ {
+ DicomDirSerie *serie = study->GetLastSerie();
+ if ( serie )
+ {
+ serie->AddImage(dd);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+/**
+ * \brief for each Header of the chained list,
+ * add/update the Patient/Study/Serie/Image info
+ * @param path path of the root directory
+ * @param list chained list of Headers
+ */
+void DicomDir::SetElements(std::string const &path, VectDocument const &list)
+{
+ ClearEntry();
+ ClearPatient();
+
+ std::string patPrevName = "", patPrevID = "";
+ std::string studPrevInstanceUID = "", studPrevID = "";
+ std::string serPrevInstanceUID = "", serPrevID = "";
+
+ std::string patCurName, patCurID;
+ std::string studCurInstanceUID, studCurID;
+ std::string serCurInstanceUID, serCurID;
+
+ bool first = true;
+ for( VectDocument::const_iterator it = list.begin();
+ it != list.end();
+ ++it )
+ {
+ // get the current file characteristics
+ patCurName = (*it)->GetEntryString(0x0010,0x0010);
+ patCurID = (*it)->GetEntryString(0x0010,0x0011);
+ studCurInstanceUID = (*it)->GetEntryString(0x0020,0x000d);
+ studCurID = (*it)->GetEntryString(0x0020,0x0010);
+ serCurInstanceUID = (*it)->GetEntryString(0x0020,0x000e);
+ serCurID = (*it)->GetEntryString(0x0020,0x0011);
+
+ if ( patCurName != patPrevName || patCurID != patPrevID || first )
+ {
+ SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
+ first = true;
+ }
+
+ // if new Study, deal with 'STUDY' Elements
+ if ( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID
+ || first )
+ {
+ SetElement(path, GDCM_DICOMDIR_STUDY, *it);
+ first = true;
+ }
+
+ // if new Serie, deal with 'SERIE' Elements
+ if ( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
+ || first )
+ {
+ SetElement(path, GDCM_DICOMDIR_SERIE, *it);
+ }
+
+ // Always Deal with 'IMAGE' Elements
+ SetElement(path, GDCM_DICOMDIR_IMAGE, *it);
+
+ patPrevName = patCurName;
+ patPrevID = patCurID;
+ studPrevInstanceUID = studCurInstanceUID;
+ studPrevID = studCurID;
+ serPrevInstanceUID = serCurInstanceUID;
+ serPrevID = serCurID;
+ first = false;
+ }
+}
+
+/**
+ * \brief adds to the HTable
+ * the Entries (Dicom Elements) corresponding to the given type
+ * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
+ * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
+ * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
+ * @param header Header of the current file
+ */
+void DicomDir::SetElement(std::string const &path, DicomDirType type,
+ Document *header)
+{
+ ListDicomDirElem elemList;
+ ListDicomDirElem::const_iterator it;