1 #include <creaImageIOTreeAttributeDescriptor.h>
2 #include <creaImageIOSystem.h>
4 #include <gdcmGlobal.h>
5 #include <gdcmDictSet.h>
7 #include <boost/algorithm/string/replace.hpp>
15 //========================================================================
16 void AttributeDescriptor::CleanName(std::string& str) const
18 // quote must be doubled for SQL
19 // crea::Utils::Replace( str, "'", "''" );
20 boost::algorithm::replace_all(str,"'","''");
21 // Found strange strings which contained NULL char INSIDE string
22 int i,size=str.size();
27 str = str.substr(0,i);
32 //========================================================================
34 //=====================================================================
35 // Ctor with key, name and flags
36 AttributeDescriptor::AttributeDescriptor(const std::string& key,
37 const std::string& name,
39 : mKey(key), mName(name), mGroup(0), mElement(0), mFlags(flags)
43 GimmickDebugMessage(3,"AttributeDescriptor : '"<<key
44 <<"' ["<<flags<<"]"<<std::endl);
45 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
48 //=====================================================================
50 //=====================================================================
51 // Ctor with dicom group, elem and flags
52 // The key is built as 'Dgroup_elem'
53 // The user name is retreived from dicom dictionnary
54 AttributeDescriptor::AttributeDescriptor(unsigned short group,
55 unsigned short element,
57 : mGroup(group), mElement(element), mFlags(flags)
60 //GDCM_NAME_SPACE::TagKey tag(group,element);
62 sprintf(ctag,"D%04x_%04x",group,element);
65 GimmickDebugMessage(3,"AttributeDescriptor : '"<<mKey
66 <<"' ["<<flags<<"]"<<std::endl);
68 // Retrieve the name from gdcm dict
69 GDCM_NAME_SPACE::DictEntry* entry =
70 GDCM_NAME_SPACE::Global::GetDicts()
71 ->GetDefaultPubDict()->GetEntry(mGroup,mElement);
75 mName = entry->GetName();
77 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
81 GimmickMessage(1,"!! WARNING : tag '"<<mKey
82 <<"' is not in DICOM dictionnary ! "
83 <<"Considering it as a user attribute"
86 mGroup = mElement = 0;
90 //=====================================================================
93 //=====================================================================
94 /// Extracts group and element from a key of the form "Dgroup_elem"
95 void AttributeDescriptor::GetDicomGroupElementFromKey(const std::string& key,
96 unsigned short& group,
100 if ( (key.size()==10) &&
104 std::string g = key.substr(1,4);
105 std::string e = key.substr(6,4);
106 std::stringstream val;
107 val << std::dec << g.c_str() ;
108 val >> std::hex >> group;
110 val << std::dec << e.c_str();
111 val >> std::hex >> elem;
112 //sscanf_s(key.c_str(),"D%04x_%04x ",&group,&elem);
113 GimmickDebugMessage(3,"GetDicomGroupElementFromKey '"<<key<<"' : " <<group<<"|"<<elem<<std::endl);
117 GimmickMessage(5,"GetDicomGroupElementFromKey '"<<key<<"' : "
118 <<" not a DICOM key format"<<std::endl);
123 //=====================================================================
124 /// test if the type is a date
125 bool AttributeDescriptor::isDateEntry() const
129 // Retrieve the name from gdcm dict
130 GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
133 if( entry->GetVR().str() == "DA" )
141 //=====================================================================
142 /// test if the type is a time
143 bool AttributeDescriptor::isTimeEntry() const
147 // Retrieve the name from gdcm dict
148 GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
151 if( entry->GetVR().str() == "TM" )
160 //=====================================================================
161 /// Decodes the type of the attribute
162 void AttributeDescriptor::DecodeType(unsigned int& typ) const
166 // Retrieve the name from gdcm dict
167 GDCM_NAME_SPACE::DictEntry* entry =
168 GDCM_NAME_SPACE::Global::GetDicts()
169 ->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
176 std::string type = entry->GetVR().str();
177 GimmickDebugMessage(3,"VR Value is "<<type<<"!"<<std::endl);
199 //=====================================================================
201 } // EO namespace tree
203 } // EO namespace creaImageIO