2 //-----------------------------------------------------------------------------
4 #include "gdcmSQItem.h"
5 #include "gdcmGlobal.h"
7 #include "gdcmValEntry.h"
10 //-----------------------------------------------------------------------------
11 // Constructor / Destructor
14 * \brief Constructor from a given gdcmSQItem
16 gdcmSQItem::gdcmSQItem(int depthLevel )
17 : gdcmDocEntrySet(depthLevel) {
18 SQDepthLevel = depthLevel +1;
22 * \brief Canonical destructor.
24 gdcmSQItem::~gdcmSQItem()
26 for(ListDocEntry::iterator cc = docEntries.begin();
27 cc != docEntries.end();
35 //-----------------------------------------------------------------------------
39 * \brief canonical Printer
41 void gdcmSQItem::Print(std::ostream & os) {
45 for (int i=0;i<SQDepthLevel;i++)
48 for (ListDocEntry::iterator i = docEntries.begin();
49 i != docEntries.end();
53 //(*i)->SetPrintLevel(printLevel); //self->GetPrintLevel() ?
54 (*i)->SetPrintLevel(2);
59 //-----------------------------------------------------------------------------
62 bool gdcmSQItem::AddEntry(gdcmDocEntry *entry) {
63 docEntries.push_back(entry);
64 //TODO : check if it worked
70 * \brief Sets Entry (Dicom Element) value of an element,
71 * specified by it's tag (Group, Number)
72 * and the length, too ... inside a SQ Item
73 * If the Element is not found, it's just created !
74 * \warning we suppose, right now, the element belongs to a Public Group
76 * @param val string value to set
77 * @param group Group of the searched tag.
78 * @param element Element of the searched tag.
79 * @return true if element was found or created successfully
81 bool gdcmSQItem::SetEntryByNumber(std::string val,guint16 group,
84 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
85 if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0xe000 )
87 if ( group < (*i)->GetGroup() ||
88 (group == (*i)->GetGroup() && element < (*i)->GetElement()) ){
89 // instead of ReplaceOrCreateByNumber
90 // that is a method of gdcmDocument :-(
92 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
93 if ( ! ptagHT->count(key)) {
94 // we assume a Public Dictionnary *is* loaded
95 gdcmDict *PubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
96 // if the invoked (group,elem) doesn't exist inside the Dictionary
97 // we create a VirtualDictEntry
98 gdcmDictEntry *DictEntry = PubDict->GetDictEntryByNumber(group, element);
99 if (DictEntry == NULL) {
100 DictEntry=gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,"UN","??","??");
102 // we assume the constructor didn't fail
103 Entry = new gdcmDocEntry(DictEntry);
106 /// better we don't assume too much !
107 /// gdcmSQItem is now used to describe any DICOMDIR related object
110 Entry = ptagHT->find(key)->second;
112 ((gdcmValEntry*)Entry)->SetValue(val);
113 Entry->SetLength(val.length());
114 docEntries.insert(i,Entry);
117 if (group == (*i)->GetGroup() && element == (*i)->GetElement() ) {
118 ((gdcmValEntry*)(*i))->SetValue(val);
119 (*i)->SetLength(val.length());
124 //-----------------------------------------------------------------------------
127 //-----------------------------------------------------------------------------
130 // end-user intended : the guy *wants* to create his own SeQuence ?!?
131 gdcmDocEntry *gdcmSQItem::NewDocEntryByNumber(guint16 group,
135 std::cout << " gdcmSQItem::NewDocEntryByNumber : TODO" <<std::endl;
139 gdcmDocEntry *gdcmSQItem::NewDocEntryByName (std::string Name) {
142 std::cout << " gdcmSQItem::NewDocEntryByName : TODO" <<std::endl;
147 * \ingroup gdcmSQItem
148 * \brief Gets a Dicom Element inside a SQ Item Entry, by name
151 gdcmDocEntry *gdcmSQItem::GetDocEntryByName(std::string name) {
152 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
153 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
154 if( dictEntry == NULL)
156 return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
160 * \ingroup gdcmSQItem
161 * \brief Gets a Dicom Element inside a SQ Item Entry, by number
164 gdcmDocEntry *gdcmSQItem::GetDocEntryByNumber(guint16 group, guint16 element) {
165 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
166 if ( (*i)->GetGroup()==group && (*i)->GetElement()==element)
173 * \ingroup gdcmSQItem
174 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by number
178 std::string gdcmSQItem::GetEntryByNumber(guint16 group, guint16 element) {
179 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
180 if ( (*i)->GetGroup()==group && (*i)->GetElement()==element) {
181 return ((gdcmValEntry *)(*i))->GetValue();
188 * \ingroup gdcmSQItem
189 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by name
190 * @param name : name of the searched element.
194 std::string gdcmSQItem::GetEntryByName(TagName name) {
195 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
196 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
198 if( dictEntry == NULL)
200 return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
203 //-----------------------------------------------------------------------------