-gdcmDicomDirPatient * gdcmDicomDir::NewPatient(void) {
- std::list<gdcmElement> elemList;
- std::list<gdcmElement>::iterator it;
- guint16 tmpGr,tmpEl;
- gdcmDictEntry *dictEntry;
- gdcmHeaderEntry *entry;
-
- elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
- std::list<gdcmHeaderEntry *>::iterator debInsertion, finInsertion, i,j;
-
- debInsertion = metaElems->fin();
- ++debInsertion;
- finInsertion=debInsertion;
-
- // 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 gdcmHeaderEntry(dictEntry);
- entry->SetOffset(0); // just to avoid missprinting
- entry->SetValue(it->value);
-
- if(dictEntry->GetGroup()==0xfffe)
- {
- entry->SetLength(entry->GetValue().length());
- }
- else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") )
+void DicomDir::SetElement(std::string const & path, DicomDirType type,
+ Document *header)
+{
+ ListDicomDirElem elemList; //FIXME this is going to be a by copy operation
+ ListDicomDirElem::const_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)
+ {
+ tmpGr = it->Group;
+ tmpEl = it->Elem;
+ dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl);
+
+ entry = new ValEntry( dictEntry ); // Be sure it's never a BinEntry !
+
+ entry->SetOffset(0); // just to avoid further missprinting
+ entry->SetLength(0); // just to avoid further missprinting
+
+ if( header )
+ {
+ // NULL when we Build Up (ex nihilo) a DICOMDIR
+ // or when we add the META elems
+ val = header->GetEntryByNumber(tmpGr, tmpEl);
+ }
+ else
+ {
+ val = GDCM_UNFOUND;
+ }
+
+ if( val == GDCM_UNFOUND)
+ {
+ if( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
+ {
+ // force to the *end* File Name
+ val = Util::GetName( path );
+ }
+ else if( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
+ {
+ if( header->GetFileName().substr(0, path.length()) != path )
+ {
+ dbg.Verbose(0, "DicomDir::SetElement : the base path"
+ " of file name is incorrect");
+ val = header->GetFileName();
+ }
+ else
+ {
+ val = &(header->GetFileName().c_str()[path.length()]);
+ }
+ }
+ else
+ {
+ val = it->Value;
+ }
+ }
+ else
+ {
+ if ( header->GetEntryLengthByNumber(tmpGr,tmpEl) == 0 )
+ val = it->Value;
+ }
+
+ // GDCM_UNFOUND or not !
+
+ entry->SetValue( val ); // troubles expected when vr=SQ ...
+
+ if( dictEntry )
+ {
+ if( dictEntry->GetGroup() == 0xfffe )
+ {
+ entry->SetLength( entry->GetValue().length() ); // FIXME
+ }
+ else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )