+ entry->SetLength( entry->GetValue().length() );
+ }
+ }
+
+ if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
+ {
+ std::cout << "GDCM_DICOMDIR_META ?!? should never print that"
+ << std::endl;
+ }
+ si->AddEntry(entry);
+ }
+ switch( type )
+ {
+ case GDCM_DICOMDIR_IMAGE:
+ AddDicomDirImageToEnd(si);
+ break;
+
+ case GDCM_DICOMDIR_SERIE:
+ AddDicomDirSerieToEnd(si);
+ break;
+
+ case GDCM_DICOMDIR_STUDY:
+ AddDicomDirStudyToEnd(si);
+ break;
+
+ case GDCM_DICOMDIR_PATIENT:
+ AddDicomDirPatientToEnd(si);
+ break;
+
+ default:
+ return;
+ }
+ //int count=1; // find a trick to increment
+ //s->AddEntry(si, count); // Seg Faults
+
+}
+
+//-----------------------------------------------------------------------------
+/**
+ * \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));