+
+//-----------------------------------------------------------------------------
+/**
+ * \brief CallStartMethod
+ */
+void DicomDir::CallStartMethod()
+{
+ Progress = 0.0f;
+ Abort = false;
+ if( StartMethod )
+ {
+ StartMethod( StartArg );
+ }
+}
+
+//-----------------------------------------------------------------------------
+/**
+ * \ingroup DicomDir
+ * \brief CallProgressMethod
+ */
+void DicomDir::CallProgressMethod()
+{
+ if( ProgressMethod )
+ {
+ ProgressMethod( ProgressArg );
+ }
+}
+
+//-----------------------------------------------------------------------------
+/**
+ * \ingroup DicomDir
+ * \brief CallEndMethod
+ */
+void DicomDir::CallEndMethod()
+{
+ Progress = 1.0f;
+ if( EndMethod )
+ {
+ EndMethod( EndArg );
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Private
+/**
+ * \ingroup DicomDir
+ * \brief create a 'DicomDir' from a DICOMDIR Header
+ */
+void DicomDir::CreateDicomDir()
+{
+ // The list is parsed.
+ // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
+ // 1 - we save the beginning iterator
+ // 2 - we continue to parse
+ // 3 - we find an other tag
+ // + we create the object for the precedent tag
+ // + loop to 1 -
+
+ // Directory record sequence
+ DocEntry *e = GetDocEntryByNumber(0x0004, 0x1220);
+ if ( !e )
+ {
+ dbg.Verbose(0, "DicomDir::DicomDir : NO Directory record"
+ " sequence (0x0004,0x1220)");
+ /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?
+ return;
+ }
+
+ SeqEntry* s = dynamic_cast<SeqEntry*>(e);
+ if ( !s )
+ {
+ dbg.Verbose(0, "DicomDir::CreateDicomDir: no SeqEntry present");
+ // useless : (0x0004,0x1220) IS a Sequence !
+ return;
+ }
+
+ DicomDirType type = DicomDir::GDCM_DICOMDIR_META;
+ MetaElems = NewMeta();
+
+ ListSQItem listItems = s->GetSQItems();
+
+ DocEntry * d;
+ std::string v;
+ for( ListSQItem::iterator i = listItems.begin();
+ i !=listItems.end(); ++i )
+ {
+ d = (*i)->GetDocEntryByNumber(0x0004, 0x1430); // Directory Record Type
+ if ( ValEntry* valEntry = dynamic_cast< ValEntry* >(d) )
+ {
+ v = valEntry->GetValue();
+ }
+ else
+ {
+ dbg.Verbose(0, "DicomDir::CreateDicomDir: not a ValEntry.");
+ continue;
+ }
+
+ if( v == "PATIENT " )
+ {
+ AddDicomDirPatientToEnd( *i );
+ type = DicomDir::GDCM_DICOMDIR_PATIENT;
+ }
+ else if( v == "STUDY " )
+ {
+ AddDicomDirStudyToEnd( *i );
+ type = DicomDir::GDCM_DICOMDIR_STUDY;
+ }
+ else if( v == "SERIES" )
+ {
+ AddDicomDirSerieToEnd( *i );
+ type = DicomDir::GDCM_DICOMDIR_SERIE;
+ }
+ else if( v == "IMAGE " )
+ {
+ AddDicomDirImageToEnd( *i );
+ type = DicomDir::GDCM_DICOMDIR_IMAGE;
+ }
+ else
+ {
+ // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
+ // neither an 'IMAGE' SQItem. Skip to next item.
+ continue;
+ }
+ }
+}
+
+/**
+ * \ingroup DicomDir
+ * \brief Well ... there is only one occurence
+ */
+void DicomDir::AddDicomDirMeta()
+{
+ if( MetaElems )
+ {
+ delete MetaElems;
+ }
+ MetaElems = new DicomDirMeta( &TagHT );
+}
+
+/**
+ * \ingroup DicomDir
+ * \brief AddDicomDirPatientToEnd
+ * @param s SQ Item to enqueue to the DicomPatient chained List
+ */
+void DicomDir::AddDicomDirPatientToEnd(SQItem *s)
+{
+ Patients.push_back(new DicomDirPatient(s, &TagHT));
+}
+
+/**
+ * \ingroup DicomDir
+ * \brief AddDicomDirStudyToEnd
+ * @param s SQ Item to enqueue to the DicomDirStudy chained List
+ */
+ void DicomDir::AddDicomDirStudyToEnd(SQItem *s)
+{
+ if( Patients.size() > 0 )
+ {
+ ListDicomDirPatient::iterator itp = Patients.end();
+ itp--;
+ (*itp)->AddDicomDirStudy(new DicomDirStudy(s, &TagHT));
+ }
+}
+
+/**
+ * \ingroup DicomDir
+ * \brief AddDicomDirSerieToEnd
+ * @param s SQ Item to enqueue to the DicomDirSerie chained List
+ */
+void DicomDir::AddDicomDirSerieToEnd(SQItem *s)
+{
+ if( Patients.size() > 0 )
+ {
+ ListDicomDirPatient::iterator itp = Patients.end();
+ itp--;
+
+ if( (*itp)->GetDicomDirStudies().size() > 0 )
+ {
+ ListDicomDirStudy::const_iterator itst =
+ (*itp)->GetDicomDirStudies().end();
+ itst--;
+ (*itst)->AddDicomDirSerie(new DicomDirSerie(s, &TagHT));
+ }
+ }
+}
+
+/**
+ * \ingroup DicomDir
+ * \brief AddDicomDirImageToEnd
+ * @param s SQ Item to enqueue to the DicomDirImage chained List
+ */
+ void DicomDir::AddDicomDirImageToEnd(SQItem *s)
+{
+ if( Patients.size() > 0 )
+ {
+ ListDicomDirPatient::iterator itp = Patients.end();
+ itp--;
+
+ if( (*itp)->GetDicomDirStudies().size() > 0 )
+ {
+ ListDicomDirStudy::const_iterator itst =
+ (*itp)->GetDicomDirStudies().end();
+ itst--;
+
+ if( (*itst)->GetDicomDirSeries().size() > 0 )
+ {
+ ListDicomDirSerie::const_iterator its = (*itst)->GetDicomDirSeries().end();
+ its--;
+ (*its)->AddDicomDirImage(new DicomDirImage(s, &TagHT));
+ }
+ }
+ }
+}
+
+/**
+ * \ingroup DicomDir
+ * \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)
+{
+ std::string patPrevName = "", patPrevID = "";
+ std::string studPrevInstanceUID = "", studPrevID = "";
+ std::string serPrevInstanceUID = "", serPrevID = "";
+
+ std::string patCurName, patCurID;
+ std::string studCurInstanceUID, studCurID;
+ std::string serCurInstanceUID, serCurID;
+
+ for( VectDocument::const_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_DICOMDIR_PATIENT, *it);
+ }
+
+ // if new Study Deal with 'STUDY' Elements
+ if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID )
+ {
+ SetElement(path, GDCM_DICOMDIR_STUDY, *it);
+ }
+
+ // if new Serie Deal with 'SERIE' Elements
+ if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID )
+ {
+ 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;
+ }
+}
+
+/**
+ * \ingroup DicomDir
+ * \brief compares two dgcmHeaders
+ */
+bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
+{
+ return *header1 < *header2;
+}
+} // end namespace gdcm
+
+//-----------------------------------------------------------------------------