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
105 const gdcm::Global& g = gdcm::Global::GetInstance();
106 const gdcm::Dicts &dicts = g.GetDicts();
107 const gdcm::Dict &dict = dicts.GetPublicDict();
108 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
110 mName = dictentry.GetName();
114 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
118 GimmickMessage(1,"!! WARNING : tag '"<<mKey
119 <<"' is not in DICOM dictionnary ! "
120 <<"Considering it as a user attribute"
123 mGroup = mElement = 0;
128 //=====================================================================
131 //=====================================================================
132 /// Extracts group and element from a key of the form "Dgroup_elem"
133 void AttributeDescriptor::GetDicomGroupElementFromKey(const std::string& key,
134 unsigned short& group,
135 unsigned short& elem)
138 if ( (key.size()==10) &&
142 sscanf(key.c_str(),"D%04hx_%04hx ",&group,&elem);
143 GimmickDebugMessage(3,"GetDicomGroupElementFromKey '"<<key<<"' : " <<group<<"|"<<elem<<std::endl);
147 GimmickMessage(5,"GetDicomGroupElementFromKey '"<<key<<"' : "
148 <<" not a DICOM key format"<<std::endl);
153 //=====================================================================
154 /// test if the type is a date
155 bool AttributeDescriptor::isDateEntry() const
159 // Retrieve the name from gdcm dict
160 #if defined(USE_GDCM)
161 GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
164 if( entry->GetVR().str() == "DA" )
170 #if defined(USE_GDCM2)
171 const gdcm::Global& g = gdcm::Global::GetInstance();
172 const gdcm::Dicts &dicts = g.GetDicts();
173 const gdcm::Dict &dict = dicts.GetPublicDict();
174 if(mGroup != 0 && mElement != 0)
176 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(GetGroup(), GetElement()));
177 if( gdcm::VR::GetVRString(dictentry.GetVR()) == "DA")
186 //=====================================================================
187 /// test if the type is a time
188 bool AttributeDescriptor::isTimeEntry() const
192 #if defined(USE_GDCM)
193 // Retrieve the name from gdcm dict
194 GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
197 if( entry->GetVR().str() == "TM" )
204 #if defined(USE_GDCM2)
205 const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
206 const gdcm::Dicts &dicts = g.GetDicts();
207 const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
208 if(mGroup != 0 && mElement != 0)
210 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
211 if(gdcm::VR::GetVRString(dictentry.GetVR()) == "TM")
222 //=====================================================================
223 /// Decodes the type of the attribute
224 void AttributeDescriptor::DecodeType(unsigned int& typ) const
227 #if defined(USE_GDCM)
228 // Retrieve the name from gdcm dict
229 GDCM_NAME_SPACE::DictEntry* entry =
230 GDCM_NAME_SPACE::Global::GetDicts()
231 ->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
238 type = entry->GetVR().str();
240 #if defined(USE_GDCM2)
241 const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
242 const gdcm::Dicts &dicts = g.GetDicts();
243 const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
244 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
245 type = gdcm::VR::GetVRString(dictentry.GetVR());
248 GimmickDebugMessage(3,"VR Value is "<<type<<"!"<<std::endl);
270 //=====================================================================
272 } // EO namespace tree
274 } // EO namespace creaImageIO