2 //-----------------------------------------------------------------------------
4 #include "gdcmSQItem.h"
5 #include "gdcmSeqEntry.h"
6 #include "gdcmGlobal.h"
8 #include "gdcmValEntry.h"
11 //-----------------------------------------------------------------------------
12 // Constructor / Destructor
15 * \brief Constructor from a given gdcmSQItem
17 gdcmSQItem::gdcmSQItem(int depthLevel )
18 : gdcmDocEntrySet(depthLevel) {
19 SQDepthLevel = depthLevel +1;
23 * \brief Canonical destructor.
25 gdcmSQItem::~gdcmSQItem()
27 for(ListDocEntry::iterator cc = docEntries.begin();
28 cc != docEntries.end();
31 gdcmDocEntry* DocEntry = *cc;
32 if ( gdcmSeqEntry* SeqEntry = dynamic_cast<gdcmSeqEntry*>(DocEntry) )
45 //-----------------------------------------------------------------------------
49 * \brief canonical Printer
51 void gdcmSQItem::Print(std::ostream & os) {
55 for (int i=0;i<SQDepthLevel;i++)
58 std::cout << s.str() << "SQItemNumber " << SQItemNumber << std::endl;
59 for (ListDocEntry::iterator i = docEntries.begin();
60 i != docEntries.end();
64 //(*i)->SetPrintLevel(printLevel); //self->GetPrintLevel() ?
65 (*i)->SetPrintLevel(2);
70 //-----------------------------------------------------------------------------
73 * \brief adds any Entry (Dicom Element) to the Sequence Item
75 bool gdcmSQItem::AddEntry(gdcmDocEntry *entry) {
76 docEntries.push_back(entry);
77 //TODO : check if it worked
83 * \brief Sets Entry (Dicom Element) value of an element,
84 * specified by it's tag (Group, Number)
85 * and the length, too ... inside a SQ Item
86 * If the Element is not found, it's just created !
87 * \warning we suppose, right now, the element belongs to a Public Group
89 * @param val string value to set
90 * @param group Group of the searched tag.
91 * @param element Element of the searched tag.
92 * @return true if element was found or created successfully
94 bool gdcmSQItem::SetEntryByNumber(std::string val,guint16 group,
97 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
98 if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0xe000 )
100 if ( group < (*i)->GetGroup() ||
101 (group == (*i)->GetGroup() && element < (*i)->GetElement()) ){
102 // instead of ReplaceOrCreateByNumber
103 // that is a method of gdcmDocument :-(
105 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
106 if ( ! ptagHT->count(key)) {
107 // we assume a Public Dictionnary *is* loaded
108 gdcmDict *PubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
109 // if the invoked (group,elem) doesn't exist inside the Dictionary
110 // we create a VirtualDictEntry
111 gdcmDictEntry *DictEntry = PubDict->GetDictEntryByNumber(group, element);
112 if (DictEntry == NULL) {
113 DictEntry=gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,"UN","??","??");
115 // we assume the constructor didn't fail
116 Entry = new gdcmDocEntry(DictEntry);
119 /// better we don't assume too much !
120 /// gdcmSQItem is now used to describe any DICOMDIR related object
123 Entry = ptagHT->find(key)->second;
125 ((gdcmValEntry*)Entry)->SetValue(val);
126 Entry->SetLength(val.length());
127 docEntries.insert(i,Entry);
130 if (group == (*i)->GetGroup() && element == (*i)->GetElement() ) {
131 ((gdcmValEntry*)(*i))->SetValue(val);
132 (*i)->SetLength(val.length());
137 //-----------------------------------------------------------------------------
140 //-----------------------------------------------------------------------------
143 // end-user intended : the guy *wants* to create his own SeQuence ?!?
145 /// \brief to be written if really usefull
146 gdcmDocEntry *gdcmSQItem::NewDocEntryByNumber(guint16 group,
150 std::cout << " gdcmSQItem::NewDocEntryByNumber : TODO" <<std::endl;
154 /// \brief to be written if really usefull
155 gdcmDocEntry *gdcmSQItem::NewDocEntryByName (std::string Name) {
158 std::cout << " gdcmSQItem::NewDocEntryByName : TODO" <<std::endl;
163 * \ingroup gdcmSQItem
164 * \brief Gets a Dicom Element inside a SQ Item Entry, by name
167 gdcmDocEntry *gdcmSQItem::GetDocEntryByName(std::string name) {
168 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
169 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
170 if( dictEntry == NULL)
172 return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
176 * \ingroup gdcmSQItem
177 * \brief Gets a Dicom Element inside a SQ Item Entry, by number
180 gdcmDocEntry *gdcmSQItem::GetDocEntryByNumber(guint16 group, guint16 element) {
181 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
182 if ( (*i)->GetGroup()==group && (*i)->GetElement()==element)
189 * \ingroup gdcmSQItem
190 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by number
194 std::string gdcmSQItem::GetEntryByNumber(guint16 group, guint16 element) {
195 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
196 if ( (*i)->GetGroup()==group && (*i)->GetElement()==element) {
197 return ((gdcmValEntry *)(*i))->GetValue();
204 * \ingroup gdcmSQItem
205 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by name
206 * @param name : name of the searched element.
210 std::string gdcmSQItem::GetEntryByName(TagName name) {
211 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
212 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
214 if( dictEntry == NULL)
216 return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
219 //-----------------------------------------------------------------------------