comparison OrthancServer/Sources/Database/FindResponse.cpp @ 5666:aa231c18b9d2 find-refactoring

adding computed tags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Jul 2024 18:31:54 +0200
parents 3f13db27b399
children 93dff1fccf36
comparison
equal deleted inserted replaced
5665:d8c86698110c 5666:aa231c18b9d2
140 } 140 }
141 } 141 }
142 } 142 }
143 143
144 144
145 void FindResponse::Resource::AddChildIdentifier(const std::string& identifier) 145 std::set<std::string>& FindResponse::Resource::GetChildrenIdentifiers(ResourceType level)
146 { 146 {
147 if (childrenIdentifiers_.find(identifier) == childrenIdentifiers_.end()) 147 switch (level)
148 { 148 {
149 childrenIdentifiers_.insert(identifier); 149 case ResourceType_Study:
150 if (level_ == ResourceType_Patient)
151 {
152 return childrenStudiesIdentifiers_;
153 }
154 else
155 {
156 throw OrthancException(ErrorCode_ParameterOutOfRange);
157 }
158
159 case ResourceType_Series:
160 if (level_ == ResourceType_Patient ||
161 level_ == ResourceType_Study)
162 {
163 return childrenSeriesIdentifiers_;
164 }
165 else
166 {
167 throw OrthancException(ErrorCode_ParameterOutOfRange);
168 }
169
170 case ResourceType_Instance:
171 if (level_ == ResourceType_Patient ||
172 level_ == ResourceType_Study ||
173 level_ == ResourceType_Series)
174 {
175 return childrenInstancesIdentifiers_;
176 }
177 else
178 {
179 throw OrthancException(ErrorCode_ParameterOutOfRange);
180 }
181
182 default:
183 throw OrthancException(ErrorCode_ParameterOutOfRange);
184 }
185 }
186
187
188 void FindResponse::Resource::AddChildIdentifier(ResourceType level,
189 const std::string& identifier)
190 {
191 std::set<std::string>& target = GetChildrenIdentifiers(level);
192
193 if (target.find(identifier) == target.end())
194 {
195 target.insert(identifier);
150 } 196 }
151 else 197 else
152 { 198 {
153 throw OrthancException(ErrorCode_BadSequenceOfCalls); 199 throw OrthancException(ErrorCode_BadSequenceOfCalls);
154 } 200 }
373 return true; 419 return true;
374 } 420 }
375 } 421 }
376 422
377 423
378 void FindResponse::Resource::SetOneInstanceIdentifier(const std::string& id)
379 {
380 if (level_ == ResourceType_Instance)
381 {
382 throw OrthancException(ErrorCode_BadParameterType);
383 }
384 else if (HasOneInstanceIdentifier())
385 {
386 throw OrthancException(ErrorCode_BadSequenceOfCalls);
387 }
388 else
389 {
390 oneInstanceIdentifier_.reset(new std::string(id));
391 }
392 }
393
394
395 const std::string& FindResponse::Resource::GetOneInstanceIdentifier() const 424 const std::string& FindResponse::Resource::GetOneInstanceIdentifier() const
396 { 425 {
397 if (level_ == ResourceType_Instance) 426 const std::set<std::string>& instances = GetChildrenIdentifiers(ResourceType_Instance);
398 { 427
399 throw OrthancException(ErrorCode_BadParameterType); 428 if (instances.size() == 0)
400 } 429 {
401 else if (HasOneInstanceIdentifier()) 430 throw OrthancException(ErrorCode_BadSequenceOfCalls); // HasOneInstanceIdentifier() should have been called
402 { 431 }
403 return *oneInstanceIdentifier_; 432 else
404 } 433 {
405 else 434 return *instances.begin();
406 {
407 throw OrthancException(ErrorCode_BadSequenceOfCalls);
408 }
409 }
410
411
412 bool FindResponse::Resource::HasOneInstanceIdentifier() const
413 {
414 if (level_ == ResourceType_Instance)
415 {
416 throw OrthancException(ErrorCode_BadParameterType);
417 }
418 else
419 {
420 return oneInstanceIdentifier_.get() != NULL;
421 } 435 }
422 } 436 }
423 437
424 438
425 static void DebugDicomMap(Json::Value& target, 439 static void DebugDicomMap(Json::Value& target,
521 { 535 {
522 throw OrthancException(ErrorCode_NotImplemented); // TODO-FIND 536 throw OrthancException(ErrorCode_NotImplemented); // TODO-FIND
523 } 537 }
524 else 538 else
525 { 539 {
540 const std::set<std::string>& ids = GetChildrenIdentifiers(levels[i]);
541
526 Json::Value v = Json::arrayValue; 542 Json::Value v = Json::arrayValue;
527 for (std::set<std::string>::const_iterator it = childrenIdentifiers_.begin(); 543 for (std::set<std::string>::const_iterator it = ids.begin(); it != ids.end(); ++it)
528 it != childrenIdentifiers_.end(); ++it)
529 { 544 {
530 v.append(*it); 545 v.append(*it);
531 } 546 }
532 target[level]["Identifiers"] = v; 547 target[level]["Identifiers"] = v;
533 } 548 }