+ // The SeqEntries of "Directory Record Sequence" are 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 = GetDocEntry(0x0004, 0x1220);
+ if ( !e )
+ {
+ gdcmWarningMacro( "No Directory Record Sequence (0004,1220) found");
+ return;
+ }
+
+ SeqEntry *s = dynamic_cast<SeqEntry *>(e);
+ if ( !s )
+ {
+ gdcmWarningMacro( "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
+ {
+ gdcmWarningMacro( "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;