1 #include <creaImageIOTreeAttributeDescriptor.h>
2 #include <creaImageIOSystem.h>
6 #include <gdcmGlobal.h>
7 #include <gdcmDictSet.h>
10 #if defined(USE_GDCM2)
11 #include <gdcmGlobal.h>
12 #include <gdcmDicts.h>
16 #include <boost/algorithm/string/replace.hpp>
24 //========================================================================
25 void AttributeDescriptor::CleanName(std::string& str) const
27 // quote must be doubled for SQL
28 // crea::Utils::Replace( str, "'", "''" );
29 boost::algorithm::replace_all(str,"'","''");
30 // Found strange strings which contained NULL char INSIDE string
31 int i,size=str.size();
36 str = str.substr(0,i);
41 //========================================================================
43 //=====================================================================
44 // Ctor with key, name and flags
45 AttributeDescriptor::AttributeDescriptor(const std::string& key,
46 const std::string& name,
48 : mKey(key), mName(name), mGroup(0), mElement(0), mFlags(flags)
52 GimmickDebugMessage(3,"AttributeDescriptor : '"<<key
53 <<"' ["<<flags<<"]"<<std::endl);
54 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
57 //=====================================================================
59 //=====================================================================
60 // Ctor with dicom group, elem and flags
61 // The key is built as 'Dgroup_elem'
62 // The user name is retreived from dicom dictionnary
63 AttributeDescriptor::AttributeDescriptor(unsigned short group,
64 unsigned short element,
66 : mGroup(group), mElement(element), mFlags(flags)
69 //GDCM_NAME_SPACE::TagKey tag(group,element);
71 sprintf(ctag,"D%04x_%04x",group,element);
74 GimmickDebugMessage(3,"AttributeDescriptor : '"<<mKey
75 <<"' ["<<flags<<"]"<<std::endl);
78 // Retrieve the name from gdcm dict
79 GDCM_NAME_SPACE::DictEntry* entry =
80 GDCM_NAME_SPACE::Global::GetDicts()
81 ->GetDefaultPubDict()->GetEntry(mGroup,mElement);
85 mName = entry->GetName();
87 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
91 GimmickMessage(1,"!! WARNING : tag '"<<mKey
92 <<"' is not in DICOM dictionnary ! "
93 <<"Considering it as a user attribute"
96 mGroup = mElement = 0;
103 #if defined(USE_GDCM2)
104 // Retrieve the name from gdcm dict
106 gdcm::DictEntry dictentry = dicts.GetDictEntry(gdcm::Tag(mGroup, mElement));
108 mName = dictentry.GetName();
112 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
116 GimmickMessage(1,"!! WARNING : tag '"<<mKey
117 <<"' is not in DICOM dictionnary ! "
118 <<"Considering it as a user attribute"
121 mGroup = mElement = 0;
126 //=====================================================================
129 //=====================================================================
130 /// Extracts group and element from a key of the form "Dgroup_elem"
131 void AttributeDescriptor::GetDicomGroupElementFromKey(const std::string& key,
132 unsigned short& group,
133 unsigned short& elem)
136 if ( (key.size()==10) &&
140 sscanf(key.c_str(),"D%04hx_%04hx ",&group,&elem);
141 GimmickDebugMessage(3,"GetDicomGroupElementFromKey '"<<key<<"' : " <<group<<"|"<<elem<<std::endl);
145 GimmickMessage(5,"GetDicomGroupElementFromKey '"<<key<<"' : "
146 <<" not a DICOM key format"<<std::endl);
151 //=====================================================================
152 /// test if the type is a date
153 bool AttributeDescriptor::isDateEntry() const
157 // Retrieve the name from gdcm dict
158 #if defined(USE_GDCM)
159 GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
162 if( entry->GetVR().str() == "DA" )
168 #if defined(USE_GDCM2)
169 const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
170 const gdcm::Dicts &dicts = g.GetDicts();
171 const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
173 if(mGroup != 0 && mElement != 0)
175 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(GetGroup(), GetElement()));
176 if( gdcm::VR::GetVRString(dictentry.GetVR()) == "DA")
185 //=====================================================================
186 /// test if the type is a time
187 bool AttributeDescriptor::isTimeEntry() const
191 #if defined(USE_GDCM)
192 // Retrieve the name from gdcm dict
193 GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
196 if( entry->GetVR().str() == "TM" )
203 #if defined(USE_GDCM2)
204 const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
205 const gdcm::Dicts &dicts = g.GetDicts();
206 const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
207 if(mGroup != 0 && mElement != 0)
209 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
210 if(gdcm::VR::GetVRString(dictentry.GetVR()) == "TM")
221 //=====================================================================
222 /// Decodes the type of the attribute
223 void AttributeDescriptor::DecodeType(unsigned int& typ) const
226 #if defined(USE_GDCM)
227 // Retrieve the name from gdcm dict
228 GDCM_NAME_SPACE::DictEntry* entry =
229 GDCM_NAME_SPACE::Global::GetDicts()
230 ->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
237 type = entry->GetVR().str();
239 #if defined(USE_GDCM2)
240 const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
241 const gdcm::Dicts &dicts = g.GetDicts();
242 const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
243 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
244 type = gdcm::VR::GetVRString(dictentry.GetVR());
247 GimmickDebugMessage(3,"VR Value is "<<type<<"!"<<std::endl);
269 //=====================================================================
271 } // EO namespace tree
273 } // EO namespace creaImageIO