Mercurial > hg > orthanc
annotate OrthancServer/Sources/ResourceFinder.cpp @ 5620:4bfd885fb45f find-refactoring
optimization as patient-level tags are copied at study level
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 11 May 2024 15:11:22 +0200 |
parents | 1864b16bc7b1 |
children | 732ec9feeea8 |
rev | line source |
---|---|
5608 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium | |
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
7 * | |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include "PrecompiledHeadersServer.h" | |
24 #include "ResourceFinder.h" | |
25 | |
26 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" | |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
27 #include "../../OrthancFramework/Sources/Logging.h" |
5608 | 28 #include "../../OrthancFramework/Sources/OrthancException.h" |
29 #include "../../OrthancFramework/Sources/SerializationToolbox.h" | |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
30 #include "OrthancConfiguration.h" |
5608 | 31 #include "ServerContext.h" |
32 #include "ServerIndex.h" | |
33 | |
34 | |
35 namespace Orthanc | |
36 { | |
37 SeriesStatus ResourceFinder::GetSeriesStatus(uint32_t& expectedNumberOfInstances, | |
38 const FindResponse::Resource& resource) const | |
39 { | |
40 if (request_.GetLevel() != ResourceType_Series) | |
41 { | |
42 throw OrthancException(ErrorCode_BadParameterType); | |
43 } | |
44 | |
45 std::string s; | |
46 if (!resource.LookupMetadata(s, ResourceType_Series, MetadataType_Series_ExpectedNumberOfInstances) || | |
47 !SerializationToolbox::ParseUnsignedInteger32(expectedNumberOfInstances, s)) | |
48 { | |
49 return SeriesStatus_Unknown; | |
50 } | |
51 | |
52 std::list<std::string> values; | |
53 if (!resource.LookupChildrenMetadata(values, MetadataType_Instance_IndexInSeries)) | |
54 { | |
55 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
56 } | |
57 | |
58 std::set<int64_t> instances; | |
59 | |
60 for (std::list<std::string>::const_iterator | |
61 it = values.begin(); it != values.end(); ++it) | |
62 { | |
63 int64_t index; | |
64 | |
65 if (!SerializationToolbox::ParseInteger64(index, *it)) | |
66 { | |
67 return SeriesStatus_Unknown; | |
68 } | |
69 | |
70 if (index <= 0 || | |
71 index > static_cast<int64_t>(expectedNumberOfInstances)) | |
72 { | |
73 // Out-of-range instance index | |
74 return SeriesStatus_Inconsistent; | |
75 } | |
76 | |
77 if (instances.find(index) != instances.end()) | |
78 { | |
79 // Twice the same instance index | |
80 return SeriesStatus_Inconsistent; | |
81 } | |
82 | |
83 instances.insert(index); | |
84 } | |
85 | |
86 if (instances.size() == static_cast<size_t>(expectedNumberOfInstances)) | |
87 { | |
88 return SeriesStatus_Complete; | |
89 } | |
90 else | |
91 { | |
92 return SeriesStatus_Missing; | |
93 } | |
94 } | |
95 | |
96 | |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
97 static void InjectRequestedTags(DicomMap& requestedTags, |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
98 std::set<DicomTag>& missingTags /* out */, |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
99 const FindResponse::Resource& resource, |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
100 ResourceType level, |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
101 const std::set<DicomTag>& tags) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
102 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
103 if (!tags.empty()) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
104 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
105 DicomMap m; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
106 resource.GetMainDicomTags(m, level); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
107 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
108 for (std::set<DicomTag>::const_iterator it = tags.begin(); it != tags.end(); ++it) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
109 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
110 std::string value; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
111 if (m.LookupStringValue(value, *it, false /* not binary */)) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
112 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
113 requestedTags.SetValue(*it, value, false /* not binary */); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
114 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
115 else |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
116 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
117 // This is the case where the Housekeeper should be run |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
118 missingTags.insert(*it); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
119 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
120 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
121 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
122 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
123 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
124 |
5608 | 125 void ResourceFinder::Expand(Json::Value& target, |
126 const FindResponse::Resource& resource, | |
127 ServerIndex& index) const | |
128 { | |
129 /** | |
130 * This method closely follows "SerializeExpandedResource()" in | |
131 * "ServerContext.cpp" from Orthanc 1.12.3. | |
132 **/ | |
133 | |
134 if (resource.GetLevel() != request_.GetLevel()) | |
135 { | |
136 throw OrthancException(ErrorCode_InternalError); | |
137 } | |
138 | |
139 target = Json::objectValue; | |
140 | |
141 target["Type"] = GetResourceTypeText(resource.GetLevel(), false, true); | |
142 target["ID"] = resource.GetIdentifier(); | |
143 | |
144 switch (resource.GetLevel()) | |
145 { | |
146 case ResourceType_Patient: | |
147 break; | |
148 | |
149 case ResourceType_Study: | |
150 target["ParentPatient"] = resource.GetParentIdentifier(); | |
151 break; | |
152 | |
153 case ResourceType_Series: | |
154 target["ParentStudy"] = resource.GetParentIdentifier(); | |
155 break; | |
156 | |
157 case ResourceType_Instance: | |
158 target["ParentSeries"] = resource.GetParentIdentifier(); | |
159 break; | |
160 | |
161 default: | |
162 throw OrthancException(ErrorCode_InternalError); | |
163 } | |
164 | |
165 if (resource.GetLevel() != ResourceType_Instance) | |
166 { | |
167 const std::set<std::string>& children = resource.GetChildrenIdentifiers(); | |
168 | |
169 Json::Value c = Json::arrayValue; | |
170 for (std::set<std::string>::const_iterator | |
171 it = children.begin(); it != children.end(); ++it) | |
172 { | |
173 c.append(*it); | |
174 } | |
175 | |
176 switch (resource.GetLevel()) | |
177 { | |
178 case ResourceType_Patient: | |
179 target["Studies"] = c; | |
180 break; | |
181 | |
182 case ResourceType_Study: | |
183 target["Series"] = c; | |
184 break; | |
185 | |
186 case ResourceType_Series: | |
187 target["Instances"] = c; | |
188 break; | |
189 | |
190 default: | |
191 throw OrthancException(ErrorCode_InternalError); | |
192 } | |
193 } | |
194 | |
195 switch (resource.GetLevel()) | |
196 { | |
197 case ResourceType_Patient: | |
198 case ResourceType_Study: | |
199 break; | |
200 | |
201 case ResourceType_Series: | |
202 { | |
203 uint32_t expectedNumberOfInstances; | |
204 SeriesStatus status = GetSeriesStatus(expectedNumberOfInstances, resource); | |
205 | |
206 target["Status"] = EnumerationToString(status); | |
207 | |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
208 static const char* const EXPECTED_NUMBER_OF_INSTANCES = "ExpectedNumberOfInstances"; |
5608 | 209 |
210 if (status == SeriesStatus_Unknown) | |
211 { | |
212 target[EXPECTED_NUMBER_OF_INSTANCES] = Json::nullValue; | |
213 } | |
214 else | |
215 { | |
216 target[EXPECTED_NUMBER_OF_INSTANCES] = expectedNumberOfInstances; | |
217 } | |
218 | |
219 break; | |
220 } | |
221 | |
222 case ResourceType_Instance: | |
223 { | |
224 FileInfo info; | |
225 if (resource.LookupAttachment(info, FileContentType_Dicom)) | |
226 { | |
227 target["FileSize"] = static_cast<Json::UInt64>(info.GetUncompressedSize()); | |
228 target["FileUuid"] = info.GetUuid(); | |
229 } | |
230 else | |
231 { | |
232 throw OrthancException(ErrorCode_InternalError); | |
233 } | |
234 | |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
235 static const char* const INDEX_IN_SERIES = "IndexInSeries"; |
5608 | 236 |
237 std::string s; | |
238 uint32_t index; | |
239 if (resource.LookupMetadata(s, ResourceType_Instance, MetadataType_Instance_IndexInSeries) && | |
240 SerializationToolbox::ParseUnsignedInteger32(index, s)) | |
241 { | |
242 target[INDEX_IN_SERIES] = index; | |
243 } | |
244 else | |
245 { | |
246 target[INDEX_IN_SERIES] = Json::nullValue; | |
247 } | |
248 | |
249 break; | |
250 } | |
251 | |
252 default: | |
253 throw OrthancException(ErrorCode_InternalError); | |
254 } | |
255 | |
256 std::string s; | |
257 if (resource.LookupMetadata(s, resource.GetLevel(), MetadataType_AnonymizedFrom)) | |
258 { | |
259 target["AnonymizedFrom"] = s; | |
260 } | |
261 | |
262 if (resource.LookupMetadata(s, resource.GetLevel(), MetadataType_ModifiedFrom)) | |
263 { | |
264 target["ModifiedFrom"] = s; | |
265 } | |
266 | |
267 if (resource.GetLevel() == ResourceType_Patient || | |
268 resource.GetLevel() == ResourceType_Study || | |
269 resource.GetLevel() == ResourceType_Series) | |
270 { | |
271 target["IsStable"] = !index.IsUnstableResource(resource.GetLevel(), resource.GetInternalId()); | |
272 | |
273 if (resource.LookupMetadata(s, resource.GetLevel(), MetadataType_LastUpdate)) | |
274 { | |
275 target["LastUpdate"] = s; | |
276 } | |
277 } | |
278 | |
279 { | |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
280 DicomMap allMainDicomTags; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
281 resource.GetMainDicomTags(allMainDicomTags, resource.GetLevel()); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
282 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
283 /** |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
284 * This section was part of "StatelessDatabaseOperations::ExpandResource()" |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
285 * in Orthanc <= 1.12.3 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
286 **/ |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
287 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
288 // read all main sequences from DB |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
289 std::string serializedSequences; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
290 if (resource.LookupMetadata(serializedSequences, resource.GetLevel(), MetadataType_MainDicomSequences)) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
291 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
292 Json::Value jsonMetadata; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
293 Toolbox::ReadJson(jsonMetadata, serializedSequences); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
294 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
295 if (jsonMetadata["Version"].asInt() == 1) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
296 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
297 allMainDicomTags.FromDicomAsJson(jsonMetadata["Sequences"], true /* append */, true /* parseSequences */); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
298 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
299 else |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
300 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
301 throw OrthancException(ErrorCode_NotImplemented); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
302 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
303 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
304 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
305 /** |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
306 * End of section from StatelessDatabaseOperations |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
307 **/ |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
308 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
309 |
5608 | 310 static const char* const MAIN_DICOM_TAGS = "MainDicomTags"; |
311 static const char* const PATIENT_MAIN_DICOM_TAGS = "PatientMainDicomTags"; | |
312 | |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
313 // TODO-FIND : Ignore "null" values |
5608 | 314 |
315 DicomMap levelMainDicomTags; | |
316 allMainDicomTags.ExtractResourceInformation(levelMainDicomTags, resource.GetLevel()); | |
317 | |
318 target[MAIN_DICOM_TAGS] = Json::objectValue; | |
319 FromDcmtkBridge::ToJson(target[MAIN_DICOM_TAGS], levelMainDicomTags, format_); | |
320 | |
321 if (resource.GetLevel() == ResourceType_Study) | |
322 { | |
323 DicomMap patientMainDicomTags; | |
324 allMainDicomTags.ExtractPatientInformation(patientMainDicomTags); | |
325 | |
326 target[PATIENT_MAIN_DICOM_TAGS] = Json::objectValue; | |
327 FromDcmtkBridge::ToJson(target[PATIENT_MAIN_DICOM_TAGS], patientMainDicomTags, format_); | |
328 } | |
329 } | |
330 | |
331 { | |
332 Json::Value labels = Json::arrayValue; | |
333 | |
334 for (std::set<std::string>::const_iterator | |
335 it = resource.GetLabels().begin(); it != resource.GetLabels().end(); ++it) | |
336 { | |
337 labels.append(*it); | |
338 } | |
339 | |
340 target["Labels"] = labels; | |
341 } | |
342 | |
343 if (includeAllMetadata_) // new in Orthanc 1.12.4 | |
344 { | |
345 const std::map<MetadataType, std::string>& m = resource.GetMetadata(resource.GetLevel()); | |
346 | |
347 Json::Value metadata = Json::objectValue; | |
348 | |
349 for (std::map<MetadataType, std::string>::const_iterator it = m.begin(); it != m.end(); ++it) | |
350 { | |
351 metadata[EnumerationToString(it->first)] = it->second; | |
352 } | |
353 | |
354 target["Metadata"] = metadata; | |
355 } | |
356 } | |
357 | |
358 | |
359 ResourceFinder::ResourceFinder(ResourceType level, | |
360 bool expand) : | |
361 request_(level), | |
362 expand_(expand), | |
363 format_(DicomToJsonFormat_Human), | |
5617
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5616
diff
changeset
|
364 allowStorageAccess_(true), |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
365 hasRequestedTags_(false), |
5608 | 366 includeAllMetadata_(false) |
367 { | |
368 if (expand) | |
369 { | |
5619
1864b16bc7b1
added FindRequest::ParentRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5617
diff
changeset
|
370 request_.SetRetrieveMainDicomTags(true); |
1864b16bc7b1
added FindRequest::ParentRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5617
diff
changeset
|
371 request_.SetRetrieveMetadata(true); |
5608 | 372 request_.SetRetrieveLabels(true); |
373 | |
374 if (level == ResourceType_Series) | |
375 { | |
376 request_.AddRetrieveChildrenMetadata(MetadataType_Instance_IndexInSeries); // required for the SeriesStatus | |
377 } | |
378 | |
379 if (level == ResourceType_Instance) | |
380 { | |
381 request_.SetRetrieveAttachments(true); // for FileSize & FileUuid | |
382 } | |
383 else | |
384 { | |
385 request_.SetRetrieveChildrenIdentifiers(true); | |
386 } | |
387 | |
388 if (level != ResourceType_Patient) | |
389 { | |
390 request_.SetRetrieveParentIdentifier(true); | |
391 } | |
392 } | |
393 } | |
394 | |
395 | |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
396 void ResourceFinder::AddRequestedTags(const DicomTag& tag) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
397 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
398 if (DicomMap::IsMainDicomTag(tag, ResourceType_Patient)) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
399 { |
5620
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
400 if (request_.GetLevel() == ResourceType_Patient) |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
401 { |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
402 request_.GetParentRetrieveSpecification(ResourceType_Patient).SetRetrieveMainDicomTags(true); |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
403 request_.GetParentRetrieveSpecification(ResourceType_Patient).SetRetrieveMetadata(true); |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
404 requestedPatientTags_.insert(tag); |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
405 } |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
406 else |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
407 { |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
408 /** |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
409 * This comes from the fact that patient-level tags are copied |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
410 * at the study level, as implemented by "ResourcesContent::AddResource()". |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
411 **/ |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
412 request_.GetParentRetrieveSpecification(ResourceType_Study).SetRetrieveMainDicomTags(true); |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
413 request_.GetParentRetrieveSpecification(ResourceType_Study).SetRetrieveMetadata(true); |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
414 requestedStudyTags_.insert(tag); |
4bfd885fb45f
optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5619
diff
changeset
|
415 } |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
416 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
417 else if (DicomMap::IsMainDicomTag(tag, ResourceType_Study)) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
418 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
419 if (request_.GetLevel() == ResourceType_Patient) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
420 { |
5612
599ce5ed126c
added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5610
diff
changeset
|
421 LOG(WARNING) << "Requested tag " << tag.Format() |
599ce5ed126c
added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5610
diff
changeset
|
422 << " should only be read at the study, series, or instance level"; |
599ce5ed126c
added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5610
diff
changeset
|
423 requestedTagsFromFileStorage_.insert(tag); |
599ce5ed126c
added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5610
diff
changeset
|
424 request_.SetRetrieveOneInstanceIdentifier(true); |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
425 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
426 else |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
427 { |
5619
1864b16bc7b1
added FindRequest::ParentRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5617
diff
changeset
|
428 request_.GetParentRetrieveSpecification(ResourceType_Study).SetRetrieveMainDicomTags(true); |
1864b16bc7b1
added FindRequest::ParentRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5617
diff
changeset
|
429 request_.GetParentRetrieveSpecification(ResourceType_Study).SetRetrieveMetadata(true); |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
430 requestedStudyTags_.insert(tag); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
431 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
432 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
433 else if (DicomMap::IsMainDicomTag(tag, ResourceType_Series)) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
434 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
435 if (request_.GetLevel() == ResourceType_Patient || |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
436 request_.GetLevel() == ResourceType_Study) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
437 { |
5612
599ce5ed126c
added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5610
diff
changeset
|
438 LOG(WARNING) << "Requested tag " << tag.Format() |
599ce5ed126c
added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5610
diff
changeset
|
439 << " should only be read at the series or instance level"; |
599ce5ed126c
added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5610
diff
changeset
|
440 requestedTagsFromFileStorage_.insert(tag); |
599ce5ed126c
added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5610
diff
changeset
|
441 request_.SetRetrieveOneInstanceIdentifier(true); |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
442 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
443 else |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
444 { |
5619
1864b16bc7b1
added FindRequest::ParentRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5617
diff
changeset
|
445 request_.GetParentRetrieveSpecification(ResourceType_Series).SetRetrieveMainDicomTags(true); |
1864b16bc7b1
added FindRequest::ParentRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5617
diff
changeset
|
446 request_.GetParentRetrieveSpecification(ResourceType_Series).SetRetrieveMetadata(true); |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
447 requestedSeriesTags_.insert(tag); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
448 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
449 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
450 else if (DicomMap::IsMainDicomTag(tag, ResourceType_Instance)) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
451 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
452 if (request_.GetLevel() == ResourceType_Patient || |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
453 request_.GetLevel() == ResourceType_Study || |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
454 request_.GetLevel() == ResourceType_Series) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
455 { |
5612
599ce5ed126c
added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5610
diff
changeset
|
456 LOG(WARNING) << "Requested tag " << tag.Format() |
599ce5ed126c
added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5610
diff
changeset
|
457 << " should only be read at the instance level"; |
599ce5ed126c
added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5610
diff
changeset
|
458 requestedTagsFromFileStorage_.insert(tag); |
599ce5ed126c
added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5610
diff
changeset
|
459 request_.SetRetrieveOneInstanceIdentifier(true); |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
460 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
461 else |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
462 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
463 // Main DICOM tags from the instance level will be retrieved anyway |
5619
1864b16bc7b1
added FindRequest::ParentRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5617
diff
changeset
|
464 assert(request_.IsRetrieveMainDicomTags()); |
1864b16bc7b1
added FindRequest::ParentRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5617
diff
changeset
|
465 assert(request_.IsRetrieveMetadata()); |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
466 requestedInstanceTags_.insert(tag); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
467 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
468 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
469 else |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
470 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
471 // This is not a main DICOM tag: We will be forced to access the DICOM file anyway |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
472 requestedTagsFromFileStorage_.insert(tag); |
5610
d4b570834d3a
adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
473 |
d4b570834d3a
adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
474 if (request_.GetLevel() != ResourceType_Instance) |
d4b570834d3a
adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
475 { |
d4b570834d3a
adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
476 request_.SetRetrieveOneInstanceIdentifier(true); |
d4b570834d3a
adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
477 } |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
478 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
479 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
480 hasRequestedTags_ = true; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
481 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
482 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
483 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
484 void ResourceFinder::AddRequestedTags(const std::set<DicomTag>& tags) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
485 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
486 for (std::set<DicomTag>::const_iterator it = tags.begin(); it != tags.end(); ++it) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
487 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
488 AddRequestedTags(*it); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
489 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
490 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
491 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
492 |
5608 | 493 void ResourceFinder::Execute(Json::Value& target, |
494 ServerContext& context) | |
495 { | |
496 FindResponse response; | |
497 context.GetIndex().ExecuteFind(response, request_); | |
498 | |
499 target = Json::arrayValue; | |
500 | |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
501 for (size_t i = 0; i < response.GetSize(); i++) |
5608 | 502 { |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
503 const FindResponse::Resource& resource = response.GetResourceByIndex(i); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
504 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
505 if (expand_) |
5608 | 506 { |
507 Json::Value item; | |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
508 Expand(item, resource, context.GetIndex()); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
509 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
510 std::set<DicomTag> missingTags = requestedTagsFromFileStorage_; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
511 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
512 DicomMap requestedTags; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
513 InjectRequestedTags(requestedTags, missingTags, resource, ResourceType_Patient, requestedPatientTags_); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
514 InjectRequestedTags(requestedTags, missingTags, resource, ResourceType_Study, requestedStudyTags_); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
515 InjectRequestedTags(requestedTags, missingTags, resource, ResourceType_Series, requestedSeriesTags_); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
516 InjectRequestedTags(requestedTags, missingTags, resource, ResourceType_Instance, requestedInstanceTags_); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
517 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
518 if (!missingTags.empty()) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
519 { |
5617
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5616
diff
changeset
|
520 if (!allowStorageAccess_) |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5616
diff
changeset
|
521 { |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5616
diff
changeset
|
522 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5616
diff
changeset
|
523 "Cannot add missing requested tags, as access to file storage is disallowed"); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5616
diff
changeset
|
524 } |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5616
diff
changeset
|
525 |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
526 OrthancConfiguration::ReaderLock lock; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
527 if (lock.GetConfiguration().IsWarningEnabled(Warnings_001_TagsBeingReadFromStorage)) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
528 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
529 std::string missings; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
530 FromDcmtkBridge::FormatListOfTags(missings, missingTags); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
531 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
532 LOG(WARNING) << "W001: Accessing Dicom tags from storage when accessing " |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
533 << Orthanc::GetResourceTypeText(resource.GetLevel(), false, false) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
534 << ": " << missings; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
535 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
536 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
537 std::string instancePublicId; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
538 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
539 if (request_.IsRetrieveOneInstanceIdentifier()) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
540 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
541 instancePublicId = resource.GetOneInstanceIdentifier(); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
542 } |
5610
d4b570834d3a
adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
543 else if (request_.GetLevel() == ResourceType_Instance) |
d4b570834d3a
adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
544 { |
d4b570834d3a
adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
545 instancePublicId = resource.GetIdentifier(); |
d4b570834d3a
adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
546 } |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
547 else |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
548 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
549 FindRequest requestDicomAttachment(request_.GetLevel()); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
550 requestDicomAttachment.SetOrthancId(request_.GetLevel(), resource.GetIdentifier()); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
551 requestDicomAttachment.SetRetrieveOneInstanceIdentifier(true); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
552 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
553 FindResponse responseDicomAttachment; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
554 context.GetIndex().ExecuteFind(responseDicomAttachment, requestDicomAttachment); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
555 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
556 if (responseDicomAttachment.GetSize() != 1 || |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
557 !responseDicomAttachment.GetResourceByIndex(0).HasOneInstanceIdentifier()) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
558 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
559 throw OrthancException(ErrorCode_InexistentFile); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
560 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
561 else |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
562 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
563 instancePublicId = responseDicomAttachment.GetResourceByIndex(0).GetOneInstanceIdentifier(); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
564 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
565 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
566 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
567 LOG(INFO) << "Will retrieve missing DICOM tags from instance: " << instancePublicId; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
568 |
5616 | 569 // TODO-FIND: What do we do if the DICOM has been removed since the request? |
570 // Do we fail, or do we skip the resource? | |
571 | |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
572 Json::Value tmpDicomAsJson; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
573 context.ReadDicomAsJson(tmpDicomAsJson, instancePublicId, missingTags /* ignoreTagLength */); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
574 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
575 DicomMap tmpDicomMap; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
576 tmpDicomMap.FromDicomAsJson(tmpDicomAsJson, false /* append */, true /* parseSequences*/); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
577 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
578 for (std::set<DicomTag>::const_iterator it = missingTags.begin(); it != missingTags.end(); ++it) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
579 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
580 assert(!requestedTags.HasTag(*it)); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
581 if (tmpDicomMap.HasTag(*it)) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
582 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
583 requestedTags.SetValue(*it, tmpDicomMap.GetValue(*it)); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
584 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
585 else |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
586 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
587 requestedTags.SetNullValue(*it); // TODO-FIND: Is this compatible with Orthanc <= 1.12.3? |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
588 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
589 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
590 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
591 |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
592 if (hasRequestedTags_) |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
593 { |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
594 static const char* const REQUESTED_TAGS = "RequestedTags"; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
595 item[REQUESTED_TAGS] = Json::objectValue; |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
596 FromDcmtkBridge::ToJson(item[REQUESTED_TAGS], requestedTags, format_); |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
597 } |
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
598 |
5608 | 599 target.append(item); |
600 } | |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
601 else |
5608 | 602 { |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
603 target.append(resource.GetIdentifier()); |
5608 | 604 } |
605 } | |
606 } | |
5615
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
607 |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
608 |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
609 bool ResourceFinder::ExecuteOneResource(Json::Value& target, |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
610 ServerContext& context) |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
611 { |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
612 Json::Value answer; |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
613 Execute(answer, context); |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
614 |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
615 if (answer.type() != Json::arrayValue) |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
616 { |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
617 throw OrthancException(ErrorCode_InternalError); |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
618 } |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
619 else if (answer.size() > 1) |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
620 { |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
621 throw OrthancException(ErrorCode_DatabasePlugin); |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
622 } |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
623 else if (answer.empty()) |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
624 { |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
625 // Inexistent resource (or was deleted between the first and second phases) |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
626 return false; |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
627 } |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
628 else |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
629 { |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
630 target = answer[0]; |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
631 return true; |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
632 } |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5612
diff
changeset
|
633 } |
5608 | 634 } |