+
+DicomDirMeta * DicomDir::NewMeta()
+{
+ DicomDirMeta *m = new DicomDirMeta( &TagHT );
+
+ if ( TagHT.begin() != TagHT.end() ) // after Document Parsing
+ {
+ TagDocEntryHT::iterator lastOneButSequence = TagHT.end();
+ lastOneButSequence --;
+ // ALL the 'out of Sequence' Tags belong to Meta Elems
+ // (we skip 0004|1220 [Directory record sequence] )
+ for ( TagDocEntryHT::iterator cc = TagHT.begin();
+ cc != lastOneButSequence;
+ ++cc)
+ {
+ m->AddDocEntry( cc->second );
+ }
+ }
+ else // after root directory parsing
+ {
+ std::list<Element> elemList;
+ elemList=Global::GetDicomDirElements()->GetDicomDirMetaElements();
+ m->FillObject(elemList);
+ }
+ m->SetSQItemNumber(0); // To avoid further missprinting
+ return m;
+}
+
+/**
+ * \brief adds a new Patient (with the basic elements) to a partially created DICOMDIR
+ */
+DicomDirPatient * DicomDir::NewPatient()
+{
+ std::list<Element>::iterator it;
+ uint16_t tmpGr,tmpEl;
+ DictEntry *dictEntry;
+ ValEntry *entry;
+
+ std::list<Element> elemList;
+ elemList=Global::GetDicomDirElements()->GetDicomDirPatientElements();
+ SQItem *s = new SQItem(0);
+
+ // for all the DicomDirPatient Elements
+ for( it = elemList.begin(); it != elemList.end(); ++it )
+ {
+ tmpGr = it->Group;
+ tmpEl = it->Elem;
+ dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
+ entry = new ValEntry( dictEntry );
+ entry->SetOffset(0); // just to avoid further missprinting
+ entry->SetValue( it->Value );
+
+ // dealing with value length ...
+
+ if( dictEntry->GetGroup() == 0xfffe)
+ {
+ entry->SetLength(entry->GetValue().length());
+ }
+ else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
+ {
+ entry->SetLength( 4 );
+ }
+ else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
+ {
+ entry->SetLength(2);
+ }
+ else if( dictEntry->GetVR() == "SQ" )
+ {
+ entry->SetLength( 0xffffffff );
+ }
+ else
+ {
+ entry->SetLength( entry->GetValue().length() );
+ }
+ s->AddDocEntry( entry );
+ }
+
+ DicomDirPatient *p = new DicomDirPatient(s, &TagHT);
+ Patients.push_front( p );
+
+ return p;
+}
+
+/**
+ * \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 &path,DicomDirType type,
+ Document *header)
+{
+ std::list<Element> elemList;
+ std::list<Element>::iterator it;
+ uint16_t tmpGr, tmpEl;
+ DictEntry *dictEntry;
+ ValEntry *entry;
+ std::string val;
+ SQItem *si = new SQItem(0); // all the items will be at level 1
+ switch( type )
+ {
+ case GDCM_DICOMDIR_IMAGE:
+ elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
+ break;
+
+ case GDCM_DICOMDIR_SERIE:
+ elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
+ break;
+
+ case GDCM_DICOMDIR_STUDY:
+ elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
+ break;
+
+ case GDCM_DICOMDIR_PATIENT:
+ elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
+ break;
+
+ case GDCM_DICOMDIR_META:
+ elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
+ break;
+
+ default:
+ return;
+ }
+ // removed all the seems-to-be-useless stuff about Referenced Image Sequence
+ // to avoid further troubles
+ // imageElem 0008 1140 "" // Referenced Image Sequence
+ // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
+ // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
+ // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
+ // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
+ // for all the relevant elements found in their own spot of the DicomDir.dic
+ // FIXME : troubles found when it's a SeqEntry
+
+ for( it = elemList.begin(); it != elemList.end(); ++it)