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 * \brief adds any Entry (Dicom Element) to the Sequence Item
64 bool gdcmSQItem::AddEntry(gdcmDocEntry *entry) {
65 docEntries.push_back(entry);
66 //TODO : check if it worked
72 * \brief Sets Entry (Dicom Element) value of an element,
73 * specified by it's tag (Group, Number)
74 * and the length, too ... inside a SQ Item
75 * If the Element is not found, it's just created !
76 * \warning we suppose, right now, the element belongs to a Public Group
78 * @param val string value to set
79 * @param group Group of the searched tag.
80 * @param element Element of the searched tag.
81 * @return true if element was found or created successfully
83 bool gdcmSQItem::SetEntryByNumber(std::string val,guint16 group,
86 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
87 if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0xe000 )
89 if ( group < (*i)->GetGroup() ||
90 (group == (*i)->GetGroup() && element < (*i)->GetElement()) ){
91 // instead of ReplaceOrCreateByNumber
92 // that is a method of gdcmDocument :-(
94 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
95 if ( ! ptagHT->count(key)) {
96 // we assume a Public Dictionnary *is* loaded
97 gdcmDict *PubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
98 // if the invoked (group,elem) doesn't exist inside the Dictionary
99 // we create a VirtualDictEntry
100 gdcmDictEntry *DictEntry = PubDict->GetDictEntryByNumber(group, element);
101 if (DictEntry == NULL) {
102 DictEntry=gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,"UN","??","??");
104 // we assume the constructor didn't fail
105 Entry = new gdcmDocEntry(DictEntry);
108 /// better we don't assume too much !
109 /// gdcmSQItem is now used to describe any DICOMDIR related object
112 Entry = ptagHT->find(key)->second;
114 ((gdcmValEntry*)Entry)->SetValue(val);
115 Entry->SetLength(val.length());
116 docEntries.insert(i,Entry);
119 if (group == (*i)->GetGroup() && element == (*i)->GetElement() ) {
120 ((gdcmValEntry*)(*i))->SetValue(val);
121 (*i)->SetLength(val.length());
126 //-----------------------------------------------------------------------------
129 //-----------------------------------------------------------------------------
132 // end-user intended : the guy *wants* to create his own SeQuence ?!?
134 /// \brief to be written if really usefull
135 gdcmDocEntry *gdcmSQItem::NewDocEntryByNumber(guint16 group,
139 std::cout << " gdcmSQItem::NewDocEntryByNumber : TODO" <<std::endl;
143 /// \brief to be written if really usefull
144 gdcmDocEntry *gdcmSQItem::NewDocEntryByName (std::string Name) {
147 std::cout << " gdcmSQItem::NewDocEntryByName : TODO" <<std::endl;
152 * \ingroup gdcmSQItem
153 * \brief Gets a Dicom Element inside a SQ Item Entry, by name
156 gdcmDocEntry *gdcmSQItem::GetDocEntryByName(std::string name) {
157 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
158 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
159 if( dictEntry == NULL)
161 return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
165 * \ingroup gdcmSQItem
166 * \brief Gets a Dicom Element inside a SQ Item Entry, by number
169 gdcmDocEntry *gdcmSQItem::GetDocEntryByNumber(guint16 group, guint16 element) {
170 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
171 if ( (*i)->GetGroup()==group && (*i)->GetElement()==element)
178 * \ingroup gdcmSQItem
179 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by number
183 std::string gdcmSQItem::GetEntryByNumber(guint16 group, guint16 element) {
184 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
185 if ( (*i)->GetGroup()==group && (*i)->GetElement()==element) {
186 return ((gdcmValEntry *)(*i))->GetValue();
193 * \ingroup gdcmSQItem
194 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by name
195 * @param name : name of the searched element.
199 std::string gdcmSQItem::GetEntryByName(TagName name) {
200 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
201 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
203 if( dictEntry == NULL)
205 return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
208 //-----------------------------------------------------------------------------