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 std::cout << s.str() << "SQItemNumber " << SQItemNumber << std::endl;
49 for (ListDocEntry::iterator i = docEntries.begin();
50 i != docEntries.end();
54 //(*i)->SetPrintLevel(printLevel); //self->GetPrintLevel() ?
55 (*i)->SetPrintLevel(2);
60 //-----------------------------------------------------------------------------
63 * \brief adds any Entry (Dicom Element) to the Sequence Item
65 bool gdcmSQItem::AddEntry(gdcmDocEntry *entry) {
66 docEntries.push_back(entry);
67 //TODO : check if it worked
73 * \brief Sets Entry (Dicom Element) value of an element,
74 * specified by it's tag (Group, Number)
75 * and the length, too ... inside a SQ Item
76 * If the Element is not found, it's just created !
77 * \warning we suppose, right now, the element belongs to a Public Group
79 * @param val string value to set
80 * @param group Group of the searched tag.
81 * @param element Element of the searched tag.
82 * @return true if element was found or created successfully
84 bool gdcmSQItem::SetEntryByNumber(std::string val,guint16 group,
87 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
88 if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0xe000 )
90 if ( group < (*i)->GetGroup() ||
91 (group == (*i)->GetGroup() && element < (*i)->GetElement()) ){
92 // instead of ReplaceOrCreateByNumber
93 // that is a method of gdcmDocument :-(
95 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
96 if ( ! ptagHT->count(key)) {
97 // we assume a Public Dictionnary *is* loaded
98 gdcmDict *PubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
99 // if the invoked (group,elem) doesn't exist inside the Dictionary
100 // we create a VirtualDictEntry
101 gdcmDictEntry *DictEntry = PubDict->GetDictEntryByNumber(group, element);
102 if (DictEntry == NULL) {
103 DictEntry=gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,"UN","??","??");
105 // we assume the constructor didn't fail
106 Entry = new gdcmDocEntry(DictEntry);
109 /// better we don't assume too much !
110 /// gdcmSQItem is now used to describe any DICOMDIR related object
113 Entry = ptagHT->find(key)->second;
115 ((gdcmValEntry*)Entry)->SetValue(val);
116 Entry->SetLength(val.length());
117 docEntries.insert(i,Entry);
120 if (group == (*i)->GetGroup() && element == (*i)->GetElement() ) {
121 ((gdcmValEntry*)(*i))->SetValue(val);
122 (*i)->SetLength(val.length());
127 //-----------------------------------------------------------------------------
130 //-----------------------------------------------------------------------------
133 // end-user intended : the guy *wants* to create his own SeQuence ?!?
135 /// \brief to be written if really usefull
136 gdcmDocEntry *gdcmSQItem::NewDocEntryByNumber(guint16 group,
140 std::cout << " gdcmSQItem::NewDocEntryByNumber : TODO" <<std::endl;
144 /// \brief to be written if really usefull
145 gdcmDocEntry *gdcmSQItem::NewDocEntryByName (std::string Name) {
148 std::cout << " gdcmSQItem::NewDocEntryByName : TODO" <<std::endl;
153 * \ingroup gdcmSQItem
154 * \brief Gets a Dicom Element inside a SQ Item Entry, by name
157 gdcmDocEntry *gdcmSQItem::GetDocEntryByName(std::string name) {
158 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
159 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
160 if( dictEntry == NULL)
162 return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
166 * \ingroup gdcmSQItem
167 * \brief Gets a Dicom Element inside a SQ Item Entry, by number
170 gdcmDocEntry *gdcmSQItem::GetDocEntryByNumber(guint16 group, guint16 element) {
171 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
172 if ( (*i)->GetGroup()==group && (*i)->GetElement()==element)
179 * \ingroup gdcmSQItem
180 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by number
184 std::string gdcmSQItem::GetEntryByNumber(guint16 group, guint16 element) {
185 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
186 if ( (*i)->GetGroup()==group && (*i)->GetElement()==element) {
187 return ((gdcmValEntry *)(*i))->GetValue();
194 * \ingroup gdcmSQItem
195 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by name
196 * @param name : name of the searched element.
200 std::string gdcmSQItem::GetEntryByName(TagName name) {
201 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
202 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
204 if( dictEntry == NULL)
206 return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
209 //-----------------------------------------------------------------------------