comparison OrthancServer/FromDcmtkBridge.cpp @ 304:4eea080e6e7a

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Dec 2012 14:57:18 +0100
parents c76a35a85c69
children 86bb79522f19
comparison
equal deleted inserted replaced
303:c76a35a85c69 304:4eea080e6e7a
80 #include <glog/logging.h> 80 #include <glog/logging.h>
81 #include <dcmtk/dcmdata/dcostrmb.h> 81 #include <dcmtk/dcmdata/dcostrmb.h>
82 82
83 namespace Orthanc 83 namespace Orthanc
84 { 84 {
85 ParsedDicomFile::ParsedDicomFile(const std::string& content) 85 void ParsedDicomFile::Setup(const char* buffer, size_t size)
86 { 86 {
87 DcmInputBufferStream is; 87 DcmInputBufferStream is;
88 if (content.size() > 0) 88 if (size > 0)
89 { 89 {
90 is.setBuffer(&content[0], content.size()); 90 is.setBuffer(buffer, size);
91 } 91 }
92 is.setEos(); 92 is.setEos();
93 93
94 file_.reset(new DcmFileFormat); 94 file_.reset(new DcmFileFormat);
95 file_->transferInit(); 95 file_->transferInit();
139 (GetCharValue(c[1]) << 8) + 139 (GetCharValue(c[1]) << 8) +
140 (GetCharValue(c[2]) << 4) + 140 (GetCharValue(c[2]) << 4) +
141 GetCharValue(c[3])); 141 GetCharValue(c[3]));
142 } 142 }
143 143
144 static bool ParseTagAndGroup(DcmTagKey& key, 144 static void ParseTagAndGroup(DcmTagKey& key,
145 const std::string& tag) 145 const std::string& tag)
146 { 146 {
147 if (tag.size() != 9 || 147 DicomTag t = FromDcmtkBridge::ParseTag(tag);
148 !isxdigit(tag[0]) || 148 key = DcmTagKey(t.GetGroup(), t.GetElement());
149 !isxdigit(tag[1]) ||
150 !isxdigit(tag[2]) ||
151 !isxdigit(tag[3]) ||
152 tag[4] != '-' ||
153 !isxdigit(tag[5]) ||
154 !isxdigit(tag[6]) ||
155 !isxdigit(tag[7]) ||
156 !isxdigit(tag[8]))
157 {
158 return false;
159 }
160
161 uint16_t group = GetTagValue(tag.c_str());
162 uint16_t element = GetTagValue(tag.c_str() + 5);
163
164 key = DcmTagKey(group, element);
165
166 return true;
167 } 149 }
168 150
169 151
170 static void SendSequence(RestApiOutput& output, 152 static void SendSequence(RestApiOutput& output,
171 DcmSequenceOfItems& sequence) 153 DcmSequenceOfItems& sequence)
222 static void SendPathValueForLeaf(RestApiOutput& output, 204 static void SendPathValueForLeaf(RestApiOutput& output,
223 const std::string& tag, 205 const std::string& tag,
224 DcmItem& dicom) 206 DcmItem& dicom)
225 { 207 {
226 DcmTagKey k; 208 DcmTagKey k;
227 if (!ParseTagAndGroup(k, tag)) 209 ParseTagAndGroup(k, tag);
228 {
229 return;
230 }
231 210
232 DcmSequenceOfItems* sequence = NULL; 211 DcmSequenceOfItems* sequence = NULL;
233 if (dicom.findAndGetSequence(k, sequence).good() && 212 if (dicom.findAndGetSequence(k, sequence).good() &&
234 sequence != NULL && 213 sequence != NULL &&
235 sequence->getVR() == EVR_SQ) 214 sequence->getVR() == EVR_SQ)
266 return; 245 return;
267 } 246 }
268 247
269 DcmTagKey k; 248 DcmTagKey k;
270 DcmItem *child = NULL; 249 DcmItem *child = NULL;
271 if (!ParseTagAndGroup(k, uri[2 * pos]) || 250 ParseTagAndGroup(k, uri[2 * pos]);
272 !dicom->findAndGetSequenceItem(k, child, index).good() || 251 if (!dicom->findAndGetSequenceItem(k, child, index).good() ||
273 child == NULL) 252 child == NULL)
274 { 253 {
275 return; 254 return;
276 } 255 }
277 256
1156 dcmDataDict.unlock(); 1135 dcmDataDict.unlock();
1157 return s; 1136 return s;
1158 } 1137 }
1159 1138
1160 1139
1161 DicomTag FromDcmtkBridge::FindTag(const char* name) 1140 DicomTag FromDcmtkBridge::ParseTag(const char* name)
1162 { 1141 {
1142 if (strlen(name) == 9 &&
1143 isxdigit(name[0]) &&
1144 isxdigit(name[1]) &&
1145 isxdigit(name[2]) &&
1146 isxdigit(name[3]) &&
1147 name[4] == '-' &&
1148 isxdigit(name[5]) &&
1149 isxdigit(name[6]) &&
1150 isxdigit(name[7]) &&
1151 isxdigit(name[8]))
1152 {
1153 uint16_t group = GetTagValue(name);
1154 uint16_t element = GetTagValue(name + 5);
1155 return DicomTag(group, element);
1156 }
1157
1163 const DcmDataDictionary& dict = dcmDataDict.rdlock(); 1158 const DcmDataDictionary& dict = dcmDataDict.rdlock();
1164 const DcmDictEntry* entry = dict.findEntry(name); 1159 const DcmDictEntry* entry = dict.findEntry(name);
1165 1160
1166 if (entry == NULL) 1161 if (entry == NULL)
1167 { 1162 {