comparison OrthancServer/Sources/Database/FindRequest.cpp @ 5567:f3562c1a150d find-refactoring

FindRequest: group metadata and tag constrains in a single class, allow ordering against metadata
author Alain Mazy <am@orthanc.team>
date Tue, 23 Apr 2024 16:49:44 +0200
parents def06a42e5ef
children b0b5546f1b9f
comparison
equal deleted inserted replaced
5566:8b507b1514eb 5567:f3562c1a150d
57 } 57 }
58 58
59 59
60 FindRequest::FindRequest(ResourceType level) : 60 FindRequest::FindRequest(ResourceType level) :
61 level_(level), 61 level_(level),
62 responseContent_(ResponseContent_IdentifiersOnly),
63 hasLimits_(false), 62 hasLimits_(false),
64 limitsSince_(0), 63 limitsSince_(0),
65 limitsCount_(0), 64 limitsCount_(0),
65 responseContent_(ResponseContent_IdentifiersOnly),
66 retrievePatientTags_(false), 66 retrievePatientTags_(false),
67 retrieveStudyTags_(false), 67 retrieveStudyTags_(false),
68 retrieveSeriesTags_(false), 68 retrieveSeriesTags_(false),
69 retrieveInstanceTags_(false) 69 retrieveInstanceTags_(false)
70 { 70 {
71 } 71 }
72 72
73 73
74 FindRequest::~FindRequest() 74 FindRequest::~FindRequest()
75 { 75 {
76 for (std::deque<TagConstraint*>::iterator it = tagConstraints_.begin(); it != tagConstraints_.end(); ++it) 76 for (std::deque<FilterConstraint*>::iterator it = filterConstraints_.begin(); it != filterConstraints_.end(); ++it)
77 { 77 {
78 assert(*it != NULL); 78 assert(*it != NULL);
79 delete *it; 79 delete *it;
80 } 80 }
81 } 81
82 82 for (std::deque<Ordering*>::iterator it = ordering_.begin(); it != ordering_.end(); ++it)
83 83 {
84 void FindRequest::AddTagConstraint(TagConstraint* constraint /* takes ownership */) 84 assert(*it != NULL);
85 delete *it;
86 }
87 }
88
89
90 void FindRequest::AddFilterConstraint(FilterConstraint* constraint /* takes ownership */)
85 { 91 {
86 if (constraint == NULL) 92 if (constraint == NULL)
87 { 93 {
88 throw OrthancException(ErrorCode_NullPointer); 94 throw OrthancException(ErrorCode_NullPointer);
89 } 95 }
90 else 96 else
91 { 97 {
92 tagConstraints_.push_back(constraint); 98 filterConstraints_.push_back(constraint);
93 } 99 }
94 } 100 }
95 101
96 102
97 const FindRequest::TagConstraint& FindRequest::GetTagConstraint(size_t index) const 103 const FindRequest::FilterConstraint& FindRequest::GetFilterConstraint(size_t index) const
98 { 104 {
99 if (index >= tagConstraints_.size()) 105 if (index >= filterConstraints_.size())
100 { 106 {
101 throw OrthancException(ErrorCode_ParameterOutOfRange); 107 throw OrthancException(ErrorCode_ParameterOutOfRange);
102 } 108 }
103 else 109 else
104 { 110 {
105 assert(tagConstraints_[index] != NULL); 111 assert(filterConstraints_[index] != NULL);
106 return *tagConstraints_[index]; 112 return *filterConstraints_[index];
107 } 113 }
108 } 114 }
109 115
110 116
111 void FindRequest::SetLimits(uint64_t since, 117 void FindRequest::SetLimits(uint64_t since,
202 throw OrthancException(ErrorCode_ParameterOutOfRange); 208 throw OrthancException(ErrorCode_ParameterOutOfRange);
203 } 209 }
204 } 210 }
205 211
206 212
207 void FindRequest::SetTagOrdering(DicomTag tag, 213 void FindRequest::AddOrdering(const DicomTag& tag,
208 Ordering ordering) 214 OrderingDirection direction)
209 { 215 {
210 switch (ordering) 216 ordering_.push_back(new Ordering(Key(tag), direction));
211 { 217 }
212 case Ordering_None: 218
213 tagOrdering_.erase(tag); 219 void FindRequest::AddOrdering(MetadataType metadataType,
214 break; 220 OrderingDirection direction)
215 221 {
216 case Ordering_Ascending: 222 ordering_.push_back(new Ordering(Key(metadataType), direction));
217 tagOrdering_[tag] = Ordering_Ascending; 223 }
218 break; 224
219
220 case Ordering_Descending:
221 tagOrdering_[tag] = Ordering_Descending;
222 break;
223
224 default:
225 throw OrthancException(ErrorCode_ParameterOutOfRange);
226 }
227 }
228
229
230 void FindRequest::AddMetadataConstraint(MetadataType metadata,
231 const std::string& value)
232 {
233 if (metadataConstraints_.find(metadata) == metadataConstraints_.end())
234 {
235 metadataConstraints_[metadata] = value;
236 }
237 else
238 {
239 throw OrthancException(ErrorCode_BadSequenceOfCalls);
240 }
241 }
242 } 225 }