+ gdcmVerboseMacro( "Element (0004,1220) is not a Sequence ?!?");
+ return;
+ }
+
+ NewMeta();
+
+ DocEntry *d;
+ std::string v;
+ SQItem *si;
+
+ SQItem *tmpSI=s->GetFirstSQItem();
+ while(tmpSI)
+ {
+ d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
+ if ( ValEntry* valEntry = dynamic_cast<ValEntry *>(d) )
+ {
+ v = valEntry->GetValue();
+ }
+ else
+ {
+ gdcmVerboseMacro( "Not a ValEntry.");
+ continue;
+ }
+
+ if( v == "PATIENT " )
+ {
+ si = new DicomDirPatient(true);
+ if( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
+ {
+ delete si;
+ si = NULL;
+ gdcmErrorMacro( "Add PatientToEnd failed");
+ }
+ }
+ else if( v == "STUDY " )
+ {
+ si = new DicomDirStudy(true);
+ if( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
+ {
+ delete si;
+ si = NULL;
+ gdcmErrorMacro( "Add AddStudyToEnd failed");
+ }
+ }
+ else if( v == "SERIES" )
+ {
+ si = new DicomDirSerie(true);
+ if( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
+ {
+ delete si;
+ si = NULL;
+ gdcmErrorMacro( "Add AddSerieToEnd failed");
+ }
+ }
+ else if( v == "IMAGE " )
+ {
+ si = new DicomDirImage(true);
+ if( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
+ {
+ delete si;
+ si = NULL;
+ gdcmErrorMacro( "Add AddImageToEnd failed");
+ }
+ }
+ else
+ {
+ // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
+ // neither an 'IMAGE' SQItem. Skip to next item.
+ continue;
+ }
+ if( si )
+ MoveSQItem(si,tmpSI);
+
+ tmpSI=s->GetNextSQItem();
+ }
+ ClearEntry();
+}
+
+/**
+ * \brief AddPatientToEnd
+ * @param dd SQ Item to enqueue to the DicomPatient chained List
+ */
+bool DicomDir::AddPatientToEnd(DicomDirPatient *dd)
+{
+ Patients.push_back(dd);
+ return true;
+}
+
+/**
+ * \brief AddStudyToEnd
+ * @param dd SQ Item to enqueue to the DicomDirStudy chained List
+ */
+bool DicomDir::AddStudyToEnd(DicomDirStudy *dd)
+{
+ if( Patients.size() > 0 )
+ {
+ ListDicomDirPatient::iterator itp = Patients.end();