Mercurial > hg > orthanc
annotate OrthancServer/Sources/OrthancWebDav.cpp @ 4860:3e9a76464e8a openssl-3.x
integration mainline->openssl-3.x
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 24 Dec 2021 16:52:51 +0100 |
parents | 2e71a08eea15 |
children | 6eff25f70121 |
rev | line source |
---|---|
4240 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4386
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
4831
7053502fbf97
added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4796
diff
changeset
|
6 * Copyright (C) 2021-2021 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
4240 | 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 "OrthancWebDav.h" | |
24 | |
4358
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
25 #include "../../OrthancFramework/Sources/Compression/ZipReader.h" |
4240 | 26 #include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h" |
27 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" | |
28 #include "../../OrthancFramework/Sources/HttpServer/WebDavStorage.h" | |
4304 | 29 #include "../../OrthancFramework/Sources/Logging.h" |
4240 | 30 #include "Search/DatabaseLookup.h" |
31 #include "ServerContext.h" | |
32 | |
33 #include <boost/regex.hpp> | |
34 #include <boost/algorithm/string/predicate.hpp> | |
35 | |
36 | |
37 static const char* const BY_PATIENTS = "by-patients"; | |
38 static const char* const BY_STUDIES = "by-studies"; | |
4241 | 39 static const char* const BY_DATES = "by-dates"; |
4240 | 40 static const char* const BY_UIDS = "by-uids"; |
41 static const char* const UPLOADS = "uploads"; | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
42 static const char* const STUDY_INFO = "study.json"; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
43 static const char* const SERIES_INFO = "series.json"; |
4240 | 44 |
45 | |
46 namespace Orthanc | |
47 { | |
48 static boost::posix_time::ptime GetNow() | |
49 { | |
50 return boost::posix_time::second_clock::universal_time(); | |
51 } | |
52 | |
53 | |
54 static void LookupTime(boost::posix_time::ptime& target, | |
55 ServerContext& context, | |
56 const std::string& publicId, | |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
57 ResourceType level, |
4240 | 58 MetadataType metadata) |
59 { | |
60 std::string value; | |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4588
diff
changeset
|
61 int64_t revision; // Ignored |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4588
diff
changeset
|
62 if (context.GetIndex().LookupMetadata(value, revision, publicId, level, metadata)) |
4240 | 63 { |
64 try | |
65 { | |
66 target = boost::posix_time::from_iso_string(value); | |
67 return; | |
68 } | |
69 catch (std::exception& e) | |
70 { | |
71 } | |
72 } | |
73 | |
74 target = GetNow(); | |
75 } | |
76 | |
77 | |
78 class OrthancWebDav::DicomIdentifiersVisitor : public ServerContext::ILookupVisitor | |
79 { | |
80 private: | |
81 ServerContext& context_; | |
82 bool isComplete_; | |
83 Collection& target_; | |
84 ResourceType level_; | |
85 | |
86 public: | |
87 DicomIdentifiersVisitor(ServerContext& context, | |
88 Collection& target, | |
89 ResourceType level) : | |
90 context_(context), | |
91 isComplete_(false), | |
92 target_(target), | |
93 level_(level) | |
94 { | |
95 } | |
96 | |
97 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE | |
98 { | |
99 return false; // (*) | |
100 } | |
101 | |
102 virtual void MarkAsComplete() ORTHANC_OVERRIDE | |
103 { | |
104 isComplete_ = true; // TODO | |
105 } | |
106 | |
107 virtual void Visit(const std::string& publicId, | |
108 const std::string& instanceId /* unused */, | |
109 const DicomMap& mainDicomTags, | |
110 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE | |
111 { | |
112 DicomTag tag(0, 0); | |
113 MetadataType timeMetadata; | |
114 | |
115 switch (level_) | |
116 { | |
117 case ResourceType_Study: | |
118 tag = DICOM_TAG_STUDY_INSTANCE_UID; | |
119 timeMetadata = MetadataType_LastUpdate; | |
120 break; | |
121 | |
122 case ResourceType_Series: | |
123 tag = DICOM_TAG_SERIES_INSTANCE_UID; | |
124 timeMetadata = MetadataType_LastUpdate; | |
125 break; | |
126 | |
127 case ResourceType_Instance: | |
128 tag = DICOM_TAG_SOP_INSTANCE_UID; | |
129 timeMetadata = MetadataType_Instance_ReceptionDate; | |
130 break; | |
131 | |
132 default: | |
133 throw OrthancException(ErrorCode_InternalError); | |
134 } | |
135 | |
136 std::string s; | |
137 if (mainDicomTags.LookupStringValue(s, tag, false) && | |
138 !s.empty()) | |
139 { | |
140 std::unique_ptr<Resource> resource; | |
141 | |
142 if (level_ == ResourceType_Instance) | |
143 { | |
144 FileInfo info; | |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
145 int64_t revision; // Ignored |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
146 if (context_.GetIndex().LookupAttachment(info, revision, publicId, FileContentType_Dicom)) |
4240 | 147 { |
148 std::unique_ptr<File> f(new File(s + ".dcm")); | |
149 f->SetMimeType(MimeType_Dicom); | |
150 f->SetContentLength(info.GetUncompressedSize()); | |
151 resource.reset(f.release()); | |
152 } | |
153 } | |
154 else | |
155 { | |
156 resource.reset(new Folder(s)); | |
157 } | |
158 | |
159 if (resource.get() != NULL) | |
160 { | |
161 boost::posix_time::ptime t; | |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
162 LookupTime(t, context_, publicId, level_, timeMetadata); |
4240 | 163 resource->SetCreationTime(t); |
164 target_.AddResource(resource.release()); | |
165 } | |
166 } | |
167 } | |
168 }; | |
169 | |
170 | |
171 class OrthancWebDav::DicomFileVisitor : public ServerContext::ILookupVisitor | |
172 { | |
173 private: | |
174 ServerContext& context_; | |
175 bool success_; | |
176 std::string& target_; | |
177 boost::posix_time::ptime& time_; | |
178 | |
179 public: | |
180 DicomFileVisitor(ServerContext& context, | |
181 std::string& target, | |
182 boost::posix_time::ptime& time) : | |
183 context_(context), | |
184 success_(false), | |
185 target_(target), | |
186 time_(time) | |
187 { | |
188 } | |
189 | |
190 bool IsSuccess() const | |
191 { | |
192 return success_; | |
193 } | |
194 | |
195 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE | |
196 { | |
197 return false; // (*) | |
198 } | |
199 | |
200 virtual void MarkAsComplete() ORTHANC_OVERRIDE | |
201 { | |
202 } | |
203 | |
204 virtual void Visit(const std::string& publicId, | |
205 const std::string& instanceId /* unused */, | |
206 const DicomMap& mainDicomTags, | |
207 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE | |
208 { | |
209 if (success_) | |
210 { | |
211 success_ = false; // Two matches => Error | |
212 } | |
213 else | |
214 { | |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
215 LookupTime(time_, context_, publicId, ResourceType_Instance, MetadataType_Instance_ReceptionDate); |
4240 | 216 context_.ReadDicom(target_, publicId); |
217 success_ = true; | |
218 } | |
219 } | |
220 }; | |
221 | |
222 | |
223 class OrthancWebDav::OrthancJsonVisitor : public ServerContext::ILookupVisitor | |
224 { | |
225 private: | |
226 ServerContext& context_; | |
227 bool success_; | |
228 std::string& target_; | |
229 ResourceType level_; | |
230 | |
231 public: | |
232 OrthancJsonVisitor(ServerContext& context, | |
233 std::string& target, | |
234 ResourceType level) : | |
235 context_(context), | |
236 success_(false), | |
237 target_(target), | |
238 level_(level) | |
239 { | |
240 } | |
241 | |
242 bool IsSuccess() const | |
243 { | |
244 return success_; | |
245 } | |
246 | |
247 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE | |
248 { | |
249 return false; // (*) | |
250 } | |
251 | |
252 virtual void MarkAsComplete() ORTHANC_OVERRIDE | |
253 { | |
254 } | |
255 | |
256 virtual void Visit(const std::string& publicId, | |
257 const std::string& instanceId /* unused */, | |
258 const DicomMap& mainDicomTags, | |
259 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE | |
260 { | |
4554 | 261 Json::Value resource; |
4697
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
262 if (context_.GetIndex().ExpandResource(resource, publicId, level_, DicomToJsonFormat_Human)) |
4240 | 263 { |
264 if (success_) | |
265 { | |
266 success_ = false; // Two matches => Error | |
267 } | |
268 else | |
269 { | |
4554 | 270 target_ = resource.toStyledString(); |
4240 | 271 |
272 // Replace UNIX newlines with DOS newlines | |
273 boost::replace_all(target_, "\n", "\r\n"); | |
274 | |
275 success_ = true; | |
276 } | |
277 } | |
278 } | |
279 }; | |
280 | |
281 | |
282 class OrthancWebDav::ResourcesIndex : public boost::noncopyable | |
283 { | |
284 public: | |
285 typedef std::map<std::string, std::string> Map; | |
286 | |
287 private: | |
288 ServerContext& context_; | |
289 ResourceType level_; | |
290 std::string template_; | |
291 Map pathToResource_; | |
292 Map resourceToPath_; | |
293 | |
294 void CheckInvariants() | |
295 { | |
296 #ifndef NDEBUG | |
297 assert(pathToResource_.size() == resourceToPath_.size()); | |
298 | |
299 for (Map::const_iterator it = pathToResource_.begin(); it != pathToResource_.end(); ++it) | |
300 { | |
301 assert(resourceToPath_[it->second] == it->first); | |
302 } | |
303 | |
304 for (Map::const_iterator it = resourceToPath_.begin(); it != resourceToPath_.end(); ++it) | |
305 { | |
306 assert(pathToResource_[it->second] == it->first); | |
307 } | |
308 #endif | |
309 } | |
310 | |
311 void AddTags(DicomMap& target, | |
312 const std::string& resourceId, | |
313 ResourceType tagsFromLevel) | |
314 { | |
315 DicomMap tags; | |
316 if (context_.GetIndex().GetMainDicomTags(tags, resourceId, level_, tagsFromLevel)) | |
317 { | |
318 target.Merge(tags); | |
319 } | |
320 } | |
321 | |
322 void Register(const std::string& resourceId) | |
323 { | |
324 // Don't register twice the same resource | |
325 if (resourceToPath_.find(resourceId) == resourceToPath_.end()) | |
326 { | |
327 std::string name = template_; | |
328 | |
329 DicomMap tags; | |
330 | |
331 AddTags(tags, resourceId, level_); | |
332 | |
333 if (level_ == ResourceType_Study) | |
334 { | |
335 AddTags(tags, resourceId, ResourceType_Patient); | |
336 } | |
337 | |
338 DicomArray arr(tags); | |
339 for (size_t i = 0; i < arr.GetSize(); i++) | |
340 { | |
341 const DicomElement& element = arr.GetElement(i); | |
342 if (!element.GetValue().IsNull() && | |
343 !element.GetValue().IsBinary()) | |
344 { | |
345 const std::string tag = FromDcmtkBridge::GetTagName(element.GetTag(), ""); | |
346 boost::replace_all(name, "{{" + tag + "}}", element.GetValue().GetContent()); | |
347 } | |
348 } | |
349 | |
350 // Blank the tags that were not matched | |
351 static const boost::regex REGEX_BLANK_TAGS("{{.*?}}"); // non-greedy match | |
352 name = boost::regex_replace(name, REGEX_BLANK_TAGS, ""); | |
353 | |
354 // UTF-8 characters cannot be used on Windows XP | |
355 name = Toolbox::ConvertToAscii(name); | |
356 boost::replace_all(name, "/", ""); | |
357 boost::replace_all(name, "\\", ""); | |
358 | |
359 // Trim sequences of spaces as one single space | |
360 static const boost::regex REGEX_TRIM_SPACES("{{.*?}}"); | |
361 name = boost::regex_replace(name, REGEX_TRIM_SPACES, " "); | |
362 name = Toolbox::StripSpaces(name); | |
363 | |
364 size_t count = 0; | |
365 for (;;) | |
366 { | |
367 std::string path = name; | |
368 if (count > 0) | |
369 { | |
370 path += " (" + boost::lexical_cast<std::string>(count) + ")"; | |
371 } | |
372 | |
373 if (pathToResource_.find(path) == pathToResource_.end()) | |
374 { | |
375 pathToResource_[path] = resourceId; | |
376 resourceToPath_[resourceId] = path; | |
377 return; | |
378 } | |
379 | |
380 count++; | |
381 } | |
382 | |
383 throw OrthancException(ErrorCode_InternalError); | |
384 } | |
385 } | |
386 | |
387 public: | |
388 ResourcesIndex(ServerContext& context, | |
389 ResourceType level, | |
390 const std::string& templateString) : | |
391 context_(context), | |
392 level_(level), | |
393 template_(templateString) | |
394 { | |
395 } | |
396 | |
397 ResourceType GetLevel() const | |
398 { | |
399 return level_; | |
400 } | |
401 | |
402 void Refresh(std::set<std::string>& removedPaths /* out */, | |
403 const std::set<std::string>& resources) | |
404 { | |
405 CheckInvariants(); | |
406 | |
407 // Detect the resources that have been removed since last refresh | |
408 removedPaths.clear(); | |
409 std::set<std::string> removedResources; | |
410 | |
411 for (Map::iterator it = resourceToPath_.begin(); it != resourceToPath_.end(); ++it) | |
412 { | |
413 if (resources.find(it->first) == resources.end()) | |
414 { | |
415 const std::string& path = it->second; | |
416 | |
417 assert(pathToResource_.find(path) != pathToResource_.end()); | |
418 pathToResource_.erase(path); | |
419 removedPaths.insert(path); | |
420 | |
421 removedResources.insert(it->first); // Delay the removal to avoid disturbing the iterator | |
422 } | |
423 } | |
424 | |
425 // Remove the missing resources | |
426 for (std::set<std::string>::const_iterator it = removedResources.begin(); it != removedResources.end(); ++it) | |
427 { | |
428 assert(resourceToPath_.find(*it) != resourceToPath_.end()); | |
429 resourceToPath_.erase(*it); | |
430 } | |
431 | |
432 CheckInvariants(); | |
433 | |
434 for (std::set<std::string>::const_iterator it = resources.begin(); it != resources.end(); ++it) | |
435 { | |
436 Register(*it); | |
437 } | |
438 | |
439 CheckInvariants(); | |
440 } | |
441 | |
442 const Map& GetPathToResource() const | |
443 { | |
444 return pathToResource_; | |
445 } | |
446 }; | |
447 | |
448 | |
449 class OrthancWebDav::InstancesOfSeries : public INode | |
450 { | |
451 private: | |
452 ServerContext& context_; | |
453 std::string parentSeries_; | |
454 | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
455 static bool LookupInstanceId(std::string& instanceId, |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
456 const UriComponents& path) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
457 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
458 if (path.size() == 1 && |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
459 boost::ends_with(path[0], ".dcm")) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
460 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
461 instanceId = path[0].substr(0, path[0].size() - 4); |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
462 return true; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
463 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
464 else |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
465 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
466 return false; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
467 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
468 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
469 |
4240 | 470 public: |
471 InstancesOfSeries(ServerContext& context, | |
472 const std::string& parentSeries) : | |
473 context_(context), | |
474 parentSeries_(parentSeries) | |
475 { | |
476 } | |
477 | |
478 virtual bool ListCollection(IWebDavBucket::Collection& target, | |
479 const UriComponents& path) ORTHANC_OVERRIDE | |
480 { | |
481 if (path.empty()) | |
482 { | |
483 std::list<std::string> resources; | |
484 try | |
485 { | |
486 context_.GetIndex().GetChildren(resources, parentSeries_); | |
487 } | |
488 catch (OrthancException&) | |
489 { | |
490 // Unknown (or deleted) parent series | |
491 return false; | |
492 } | |
493 | |
494 for (std::list<std::string>::const_iterator | |
495 it = resources.begin(); it != resources.end(); ++it) | |
496 { | |
497 boost::posix_time::ptime time; | |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
498 LookupTime(time, context_, *it, ResourceType_Instance, MetadataType_Instance_ReceptionDate); |
4240 | 499 |
500 FileInfo info; | |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
501 int64_t revision; // Ignored |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
502 if (context_.GetIndex().LookupAttachment(info, revision, *it, FileContentType_Dicom)) |
4240 | 503 { |
504 std::unique_ptr<File> resource(new File(*it + ".dcm")); | |
505 resource->SetMimeType(MimeType_Dicom); | |
506 resource->SetContentLength(info.GetUncompressedSize()); | |
507 resource->SetCreationTime(time); | |
508 target.AddResource(resource.release()); | |
509 } | |
510 } | |
511 | |
512 return true; | |
513 } | |
514 else | |
515 { | |
516 return false; | |
517 } | |
518 } | |
519 | |
520 virtual bool GetFileContent(MimeType& mime, | |
521 std::string& content, | |
522 boost::posix_time::ptime& time, | |
523 const UriComponents& path) ORTHANC_OVERRIDE | |
524 { | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
525 std::string instanceId; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
526 if (LookupInstanceId(instanceId, path)) |
4240 | 527 { |
528 try | |
529 { | |
530 mime = MimeType_Dicom; | |
531 context_.ReadDicom(content, instanceId); | |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
532 LookupTime(time, context_, instanceId, ResourceType_Instance, MetadataType_Instance_ReceptionDate); |
4240 | 533 return true; |
534 } | |
535 catch (OrthancException&) | |
536 { | |
537 // File was removed | |
538 return false; | |
539 } | |
540 } | |
541 else | |
542 { | |
543 return false; | |
544 } | |
545 } | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
546 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
547 virtual bool DeleteItem(const UriComponents& path) ORTHANC_OVERRIDE |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
548 { |
4252 | 549 if (path.empty()) |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
550 { |
4252 | 551 // Delete all |
552 std::list<std::string> resources; | |
553 try | |
554 { | |
555 context_.GetIndex().GetChildren(resources, parentSeries_); | |
556 } | |
557 catch (OrthancException&) | |
558 { | |
559 // Unknown (or deleted) parent series | |
560 return true; | |
561 } | |
562 | |
563 for (std::list<std::string>::const_iterator it = resources.begin(); | |
564 it != resources.end(); ++it) | |
565 { | |
566 Json::Value info; | |
567 context_.DeleteResource(info, *it, ResourceType_Instance); | |
568 } | |
569 | |
570 return true; | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
571 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
572 else |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
573 { |
4252 | 574 std::string instanceId; |
575 if (LookupInstanceId(instanceId, path)) | |
576 { | |
577 Json::Value info; | |
578 return context_.DeleteResource(info, instanceId, ResourceType_Instance); | |
579 } | |
580 else | |
581 { | |
582 return false; | |
583 } | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
584 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
585 } |
4240 | 586 }; |
587 | |
588 | |
589 | |
590 /** | |
591 * The "InternalNode" class corresponds to a non-leaf node in the | |
592 * WebDAV tree, that only contains subfolders (no file). | |
593 * | |
594 * TODO: Implement a LRU index to dynamically remove the oldest | |
595 * children on high RAM usage. | |
596 **/ | |
597 class OrthancWebDav::InternalNode : public INode | |
598 { | |
599 private: | |
600 typedef std::map<std::string, INode*> Children; | |
601 | |
602 Children children_; | |
603 | |
604 INode* GetChild(const std::string& path) // Don't delete the result pointer! | |
605 { | |
606 Children::const_iterator child = children_.find(path); | |
607 if (child == children_.end()) | |
608 { | |
4253 | 609 INode* node = CreateSubfolder(path); |
4240 | 610 |
4253 | 611 if (node == NULL) |
4240 | 612 { |
613 return NULL; | |
614 } | |
615 else | |
616 { | |
4253 | 617 children_[path] = node; |
618 return node; | |
4240 | 619 } |
620 } | |
621 else | |
622 { | |
623 assert(child->second != NULL); | |
624 return child->second; | |
625 } | |
626 } | |
627 | |
628 protected: | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
629 void InvalidateSubfolder(const std::string& path) |
4240 | 630 { |
631 Children::iterator child = children_.find(path); | |
632 if (child != children_.end()) | |
633 { | |
634 assert(child->second != NULL); | |
635 delete child->second; | |
636 children_.erase(child); | |
637 } | |
638 } | |
639 | |
640 virtual void Refresh() = 0; | |
641 | |
642 virtual bool ListSubfolders(IWebDavBucket::Collection& target) = 0; | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
643 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
644 virtual INode* CreateSubfolder(const std::string& path) = 0; |
4240 | 645 |
646 public: | |
647 virtual ~InternalNode() | |
648 { | |
649 for (Children::iterator it = children_.begin(); it != children_.end(); ++it) | |
650 { | |
651 assert(it->second != NULL); | |
652 delete it->second; | |
653 } | |
654 } | |
655 | |
656 virtual bool ListCollection(IWebDavBucket::Collection& target, | |
657 const UriComponents& path) | |
658 ORTHANC_OVERRIDE ORTHANC_FINAL | |
659 { | |
660 Refresh(); | |
661 | |
662 if (path.empty()) | |
663 { | |
664 return ListSubfolders(target); | |
665 } | |
666 else | |
667 { | |
668 // Recursivity | |
669 INode* child = GetChild(path[0]); | |
670 if (child == NULL) | |
671 { | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
672 // Must be "true" to allow DELETE on folders that are |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
673 // automatically removed through recursive deletion |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
674 return true; |
4240 | 675 } |
676 else | |
677 { | |
678 UriComponents subpath(path.begin() + 1, path.end()); | |
679 return child->ListCollection(target, subpath); | |
680 } | |
681 } | |
682 } | |
683 | |
684 virtual bool GetFileContent(MimeType& mime, | |
685 std::string& content, | |
686 boost::posix_time::ptime& time, | |
687 const UriComponents& path) | |
688 ORTHANC_OVERRIDE ORTHANC_FINAL | |
689 { | |
690 if (path.empty()) | |
691 { | |
692 return false; // An internal node doesn't correspond to a file | |
693 } | |
694 else | |
695 { | |
696 // Recursivity | |
697 Refresh(); | |
698 | |
699 INode* child = GetChild(path[0]); | |
700 if (child == NULL) | |
701 { | |
702 return false; | |
703 } | |
704 else | |
705 { | |
706 UriComponents subpath(path.begin() + 1, path.end()); | |
707 return child->GetFileContent(mime, content, time, subpath); | |
708 } | |
709 } | |
710 } | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
711 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
712 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
713 virtual bool DeleteItem(const UriComponents& path) ORTHANC_OVERRIDE ORTHANC_FINAL |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
714 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
715 Refresh(); |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
716 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
717 if (path.empty()) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
718 { |
4252 | 719 IWebDavBucket::Collection collection; |
720 if (ListSubfolders(collection)) | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
721 { |
4252 | 722 std::set<std::string> content; |
723 collection.ListDisplayNames(content); | |
724 | |
725 for (std::set<std::string>::const_iterator | |
726 it = content.begin(); it != content.end(); ++it) | |
727 { | |
728 INode* node = GetChild(*it); | |
729 if (node) | |
730 { | |
731 node->DeleteItem(path); | |
732 } | |
733 } | |
734 | |
735 return true; | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
736 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
737 else |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
738 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
739 return false; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
740 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
741 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
742 else |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
743 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
744 INode* child = GetChild(path[0]); |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
745 if (child == NULL) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
746 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
747 return true; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
748 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
749 else |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
750 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
751 // Recursivity |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
752 UriComponents subpath(path.begin() + 1, path.end()); |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
753 return child->DeleteItem(subpath); |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
754 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
755 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
756 } |
4240 | 757 }; |
758 | |
759 | |
760 class OrthancWebDav::ListOfResources : public InternalNode | |
761 { | |
762 private: | |
763 ServerContext& context_; | |
764 const Templates& templates_; | |
765 std::unique_ptr<ResourcesIndex> index_; | |
766 MetadataType timeMetadata_; | |
767 | |
768 protected: | |
769 virtual void Refresh() ORTHANC_OVERRIDE ORTHANC_FINAL | |
770 { | |
771 std::list<std::string> resources; | |
772 GetCurrentResources(resources); | |
773 | |
774 std::set<std::string> removedPaths; | |
775 index_->Refresh(removedPaths, std::set<std::string>(resources.begin(), resources.end())); | |
776 | |
777 // Remove the children whose associated resource doesn't exist anymore | |
778 for (std::set<std::string>::const_iterator | |
779 it = removedPaths.begin(); it != removedPaths.end(); ++it) | |
780 { | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
781 InvalidateSubfolder(*it); |
4240 | 782 } |
783 } | |
784 | |
785 virtual bool ListSubfolders(IWebDavBucket::Collection& target) ORTHANC_OVERRIDE ORTHANC_FINAL | |
786 { | |
787 if (index_->GetLevel() == ResourceType_Instance) | |
788 { | |
789 // Not a collection, no subfolders | |
790 return false; | |
791 } | |
792 else | |
793 { | |
794 const ResourcesIndex::Map& paths = index_->GetPathToResource(); | |
795 | |
796 for (ResourcesIndex::Map::const_iterator it = paths.begin(); it != paths.end(); ++it) | |
797 { | |
798 boost::posix_time::ptime time; | |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
799 LookupTime(time, context_, it->second, index_->GetLevel(), timeMetadata_); |
4240 | 800 |
801 std::unique_ptr<IWebDavBucket::Resource> resource(new IWebDavBucket::Folder(it->first)); | |
802 resource->SetCreationTime(time); | |
803 target.AddResource(resource.release()); | |
804 } | |
805 | |
806 return true; | |
807 } | |
808 } | |
809 | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
810 virtual INode* CreateSubfolder(const std::string& path) ORTHANC_OVERRIDE ORTHANC_FINAL |
4240 | 811 { |
812 ResourcesIndex::Map::const_iterator resource = index_->GetPathToResource().find(path); | |
813 if (resource == index_->GetPathToResource().end()) | |
814 { | |
815 return NULL; | |
816 } | |
817 else | |
818 { | |
819 return CreateResourceNode(resource->second); | |
820 } | |
821 } | |
822 | |
823 ServerContext& GetContext() const | |
824 { | |
825 return context_; | |
826 } | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
827 |
4240 | 828 virtual void GetCurrentResources(std::list<std::string>& resources) = 0; |
829 | |
830 virtual INode* CreateResourceNode(const std::string& resource) = 0; | |
831 | |
832 public: | |
833 ListOfResources(ServerContext& context, | |
834 ResourceType level, | |
835 const Templates& templates) : | |
836 context_(context), | |
837 templates_(templates) | |
838 { | |
839 Templates::const_iterator t = templates.find(level); | |
840 if (t == templates.end()) | |
841 { | |
842 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
843 } | |
844 | |
845 index_.reset(new ResourcesIndex(context, level, t->second)); | |
846 | |
847 if (level == ResourceType_Instance) | |
848 { | |
849 timeMetadata_ = MetadataType_Instance_ReceptionDate; | |
850 } | |
851 else | |
852 { | |
853 timeMetadata_ = MetadataType_LastUpdate; | |
854 } | |
855 } | |
856 | |
857 ResourceType GetLevel() const | |
858 { | |
859 return index_->GetLevel(); | |
860 } | |
861 | |
862 const Templates& GetTemplates() const | |
863 { | |
864 return templates_; | |
865 } | |
866 }; | |
867 | |
868 | |
869 | |
870 class OrthancWebDav::SingleDicomResource : public ListOfResources | |
871 { | |
872 private: | |
873 std::string parentId_; | |
874 | |
875 protected: | |
876 virtual void GetCurrentResources(std::list<std::string>& resources) ORTHANC_OVERRIDE | |
877 { | |
878 try | |
879 { | |
880 GetContext().GetIndex().GetChildren(resources, parentId_); | |
881 } | |
882 catch (OrthancException&) | |
883 { | |
884 // Unknown parent resource | |
885 resources.clear(); | |
886 } | |
887 } | |
888 | |
889 virtual INode* CreateResourceNode(const std::string& resource) ORTHANC_OVERRIDE | |
890 { | |
891 if (GetLevel() == ResourceType_Instance) | |
892 { | |
893 return NULL; | |
894 } | |
895 else if (GetLevel() == ResourceType_Series) | |
896 { | |
897 return new InstancesOfSeries(GetContext(), resource); | |
898 } | |
899 else | |
900 { | |
901 ResourceType l = GetChildResourceType(GetLevel()); | |
902 return new SingleDicomResource(GetContext(), l, resource, GetTemplates()); | |
903 } | |
904 } | |
905 | |
906 public: | |
907 SingleDicomResource(ServerContext& context, | |
908 ResourceType level, | |
909 const std::string& parentId, | |
910 const Templates& templates) : | |
911 ListOfResources(context, level, templates), | |
912 parentId_(parentId) | |
913 { | |
914 } | |
915 }; | |
916 | |
917 | |
918 class OrthancWebDav::RootNode : public ListOfResources | |
919 { | |
920 protected: | |
921 virtual void GetCurrentResources(std::list<std::string>& resources) ORTHANC_OVERRIDE | |
922 { | |
923 GetContext().GetIndex().GetAllUuids(resources, GetLevel()); | |
924 } | |
925 | |
926 virtual INode* CreateResourceNode(const std::string& resource) ORTHANC_OVERRIDE | |
927 { | |
928 if (GetLevel() == ResourceType_Series) | |
929 { | |
930 return new InstancesOfSeries(GetContext(), resource); | |
931 } | |
932 else | |
933 { | |
934 ResourceType l = GetChildResourceType(GetLevel()); | |
935 return new SingleDicomResource(GetContext(), l, resource, GetTemplates()); | |
936 } | |
937 } | |
938 | |
939 public: | |
940 RootNode(ServerContext& context, | |
941 ResourceType level, | |
942 const Templates& templates) : | |
943 ListOfResources(context, level, templates) | |
944 { | |
945 } | |
946 }; | |
947 | |
948 | |
949 class OrthancWebDav::ListOfStudiesByDate : public ListOfResources | |
950 { | |
951 private: | |
952 std::string year_; | |
953 std::string month_; | |
954 | |
955 class Visitor : public ServerContext::ILookupVisitor | |
956 { | |
957 private: | |
958 std::list<std::string>& resources_; | |
959 | |
960 public: | |
4253 | 961 explicit Visitor(std::list<std::string>& resources) : |
4240 | 962 resources_(resources) |
963 { | |
964 } | |
965 | |
966 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE | |
967 { | |
968 return false; // (*) | |
969 } | |
970 | |
971 virtual void MarkAsComplete() ORTHANC_OVERRIDE | |
972 { | |
973 } | |
974 | |
975 virtual void Visit(const std::string& publicId, | |
976 const std::string& instanceId /* unused */, | |
977 const DicomMap& mainDicomTags, | |
978 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE | |
979 { | |
980 resources_.push_back(publicId); | |
981 } | |
982 }; | |
983 | |
984 protected: | |
985 virtual void GetCurrentResources(std::list<std::string>& resources) ORTHANC_OVERRIDE | |
986 { | |
987 DatabaseLookup query; | |
988 query.AddRestConstraint(DICOM_TAG_STUDY_DATE, year_ + month_ + "01-" + year_ + month_ + "31", | |
989 true /* case sensitive */, true /* mandatory tag */); | |
990 | |
991 Visitor visitor(resources); | |
992 GetContext().Apply(visitor, query, ResourceType_Study, 0 /* since */, 0 /* no limit */); | |
993 } | |
994 | |
995 virtual INode* CreateResourceNode(const std::string& resource) ORTHANC_OVERRIDE | |
996 { | |
997 return new SingleDicomResource(GetContext(), ResourceType_Series, resource, GetTemplates()); | |
998 } | |
999 | |
1000 public: | |
1001 ListOfStudiesByDate(ServerContext& context, | |
1002 const std::string& year, | |
1003 const std::string& month, | |
1004 const Templates& templates) : | |
1005 ListOfResources(context, ResourceType_Study, templates), | |
1006 year_(year), | |
1007 month_(month) | |
1008 { | |
1009 if (year.size() != 4 || | |
1010 month.size() != 2) | |
1011 { | |
1012 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1013 } | |
1014 } | |
1015 }; | |
1016 | |
1017 | |
1018 class OrthancWebDav::ListOfStudiesByMonth : public InternalNode | |
1019 { | |
1020 private: | |
1021 ServerContext& context_; | |
1022 std::string year_; | |
1023 const Templates& templates_; | |
1024 | |
1025 class Visitor : public ServerContext::ILookupVisitor | |
1026 { | |
1027 private: | |
1028 std::set<std::string> months_; | |
1029 | |
1030 public: | |
1031 const std::set<std::string>& GetMonths() const | |
1032 { | |
1033 return months_; | |
1034 } | |
1035 | |
1036 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE | |
1037 { | |
1038 return false; // (*) | |
1039 } | |
1040 | |
1041 virtual void MarkAsComplete() ORTHANC_OVERRIDE | |
1042 { | |
1043 } | |
1044 | |
1045 virtual void Visit(const std::string& publicId, | |
1046 const std::string& instanceId /* unused */, | |
1047 const DicomMap& mainDicomTags, | |
1048 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE | |
1049 { | |
1050 std::string s; | |
1051 if (mainDicomTags.LookupStringValue(s, DICOM_TAG_STUDY_DATE, false) && | |
1052 s.size() == 8) | |
1053 { | |
1054 months_.insert(s.substr(4, 2)); // Get the month from "YYYYMMDD" | |
1055 } | |
1056 } | |
1057 }; | |
1058 | |
1059 protected: | |
1060 virtual void Refresh() ORTHANC_OVERRIDE | |
1061 { | |
1062 } | |
1063 | |
1064 virtual bool ListSubfolders(IWebDavBucket::Collection& target) ORTHANC_OVERRIDE | |
1065 { | |
1066 DatabaseLookup query; | |
1067 query.AddRestConstraint(DICOM_TAG_STUDY_DATE, year_ + "0101-" + year_ + "1231", | |
1068 true /* case sensitive */, true /* mandatory tag */); | |
1069 | |
1070 Visitor visitor; | |
1071 context_.Apply(visitor, query, ResourceType_Study, 0 /* since */, 0 /* no limit */); | |
1072 | |
1073 for (std::set<std::string>::const_iterator it = visitor.GetMonths().begin(); | |
1074 it != visitor.GetMonths().end(); ++it) | |
1075 { | |
1076 target.AddResource(new IWebDavBucket::Folder(year_ + "-" + *it)); | |
1077 } | |
1078 | |
1079 return true; | |
1080 } | |
1081 | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1082 virtual INode* CreateSubfolder(const std::string& path) ORTHANC_OVERRIDE |
4240 | 1083 { |
1084 if (path.size() != 7) // Format: "YYYY-MM" | |
1085 { | |
1086 throw OrthancException(ErrorCode_InternalError); | |
1087 } | |
1088 else | |
1089 { | |
1090 const std::string year = path.substr(0, 4); | |
1091 const std::string month = path.substr(5, 2); | |
1092 return new ListOfStudiesByDate(context_, year, month, templates_); | |
1093 } | |
1094 } | |
1095 | |
1096 public: | |
1097 ListOfStudiesByMonth(ServerContext& context, | |
1098 const std::string& year, | |
1099 const Templates& templates) : | |
1100 context_(context), | |
1101 year_(year), | |
1102 templates_(templates) | |
1103 { | |
1104 if (year_.size() != 4) | |
1105 { | |
1106 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1107 } | |
1108 } | |
1109 }; | |
1110 | |
1111 | |
1112 class OrthancWebDav::ListOfStudiesByYear : public InternalNode | |
1113 { | |
1114 private: | |
1115 ServerContext& context_; | |
1116 const Templates& templates_; | |
1117 | |
1118 protected: | |
1119 virtual void Refresh() ORTHANC_OVERRIDE | |
1120 { | |
1121 } | |
1122 | |
1123 virtual bool ListSubfolders(IWebDavBucket::Collection& target) ORTHANC_OVERRIDE | |
1124 { | |
1125 std::list<std::string> resources; | |
1126 context_.GetIndex().GetAllUuids(resources, ResourceType_Study); | |
1127 | |
1128 std::set<std::string> years; | |
1129 | |
1130 for (std::list<std::string>::const_iterator it = resources.begin(); it != resources.end(); ++it) | |
1131 { | |
1132 DicomMap tags; | |
1133 std::string studyDate; | |
1134 if (context_.GetIndex().GetMainDicomTags(tags, *it, ResourceType_Study, ResourceType_Study) && | |
1135 tags.LookupStringValue(studyDate, DICOM_TAG_STUDY_DATE, false) && | |
1136 studyDate.size() == 8) | |
1137 { | |
1138 years.insert(studyDate.substr(0, 4)); // Get the year from "YYYYMMDD" | |
1139 } | |
1140 } | |
1141 | |
1142 for (std::set<std::string>::const_iterator it = years.begin(); it != years.end(); ++it) | |
1143 { | |
1144 target.AddResource(new IWebDavBucket::Folder(*it)); | |
1145 } | |
1146 | |
1147 return true; | |
1148 } | |
1149 | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1150 virtual INode* CreateSubfolder(const std::string& path) ORTHANC_OVERRIDE |
4240 | 1151 { |
1152 return new ListOfStudiesByMonth(context_, path, templates_); | |
1153 } | |
1154 | |
1155 public: | |
1156 ListOfStudiesByYear(ServerContext& context, | |
1157 const Templates& templates) : | |
1158 context_(context), | |
1159 templates_(templates) | |
1160 { | |
1161 } | |
1162 }; | |
1163 | |
1164 | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1165 class OrthancWebDav::DicomDeleteVisitor : public ServerContext::ILookupVisitor |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1166 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1167 private: |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1168 ServerContext& context_; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1169 ResourceType level_; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1170 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1171 public: |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1172 DicomDeleteVisitor(ServerContext& context, |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1173 ResourceType level) : |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1174 context_(context), |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1175 level_(level) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1176 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1177 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1178 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1179 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1180 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1181 return false; // (*) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1182 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1183 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1184 virtual void MarkAsComplete() ORTHANC_OVERRIDE |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1185 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1186 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1187 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1188 virtual void Visit(const std::string& publicId, |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1189 const std::string& instanceId /* unused */, |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1190 const DicomMap& mainDicomTags /* unused */, |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1191 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1192 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1193 Json::Value info; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1194 context_.DeleteResource(info, publicId, level_); |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1195 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1196 }; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1197 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1198 |
4240 | 1199 void OrthancWebDav::AddVirtualFile(Collection& collection, |
1200 const UriComponents& path, | |
1201 const std::string& filename) | |
1202 { | |
1203 MimeType mime; | |
1204 std::string content; | |
4246 | 1205 boost::posix_time::ptime modification; // Unused, let the date be set to "GetNow()" |
4240 | 1206 |
1207 UriComponents p = path; | |
1208 p.push_back(filename); | |
1209 | |
1210 if (GetFileContent(mime, content, modification, p)) | |
1211 { | |
1212 std::unique_ptr<File> f(new File(filename)); | |
1213 f->SetMimeType(mime); | |
1214 f->SetContentLength(content.size()); | |
1215 collection.AddResource(f.release()); | |
1216 } | |
1217 } | |
1218 | |
1219 | |
1220 void OrthancWebDav::UploadWorker(OrthancWebDav* that) | |
1221 { | |
1222 assert(that != NULL); | |
1223 | |
1224 boost::posix_time::ptime lastModification = GetNow(); | |
1225 | |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1226 while (that->uploadRunning_) |
4240 | 1227 { |
1228 std::unique_ptr<IDynamicObject> obj(that->uploadQueue_.Dequeue(100)); | |
1229 if (obj.get() != NULL) | |
1230 { | |
1231 that->Upload(reinterpret_cast<const SingleValueObject<std::string>&>(*obj).GetValue()); | |
1232 lastModification = GetNow(); | |
1233 } | |
4245
c70df925151e
RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4244
diff
changeset
|
1234 else if (GetNow() - lastModification > boost::posix_time::seconds(30)) |
4240 | 1235 { |
4245
c70df925151e
RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4244
diff
changeset
|
1236 /** |
c70df925151e
RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4244
diff
changeset
|
1237 * After every 30 seconds of inactivity, remove the empty |
c70df925151e
RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4244
diff
changeset
|
1238 * folders. This delay is needed to avoid removing |
c70df925151e
RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4244
diff
changeset
|
1239 * just-created folders before the remote WebDAV has time to |
c70df925151e
RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4244
diff
changeset
|
1240 * write files into it. |
c70df925151e
RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4244
diff
changeset
|
1241 **/ |
4268
0ae2ca210077
new macro TLOG() to replace VLOG() for trace logs with a category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4264
diff
changeset
|
1242 LOG(TRACE) << "Cleaning up the empty WebDAV upload folders"; |
4240 | 1243 that->uploads_.RemoveEmptyFolders(); |
1244 lastModification = GetNow(); | |
1245 } | |
1246 } | |
1247 } | |
1248 | |
1249 | |
1250 void OrthancWebDav::Upload(const std::string& path) | |
1251 { | |
1252 UriComponents uri; | |
1253 Toolbox::SplitUriComponents(uri, path); | |
1254 | |
1255 LOG(INFO) << "Upload from WebDAV: " << path; | |
1256 | |
1257 MimeType mime; | |
1258 std::string content; | |
1259 boost::posix_time::ptime time; | |
1260 if (uploads_.GetFileContent(mime, content, time, uri)) | |
1261 { | |
4244
416c35da7d25
robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4243
diff
changeset
|
1262 bool success = false; |
416c35da7d25
robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4243
diff
changeset
|
1263 |
4358
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1264 if (ZipReader::IsZipMemoryBuffer(content)) |
4240 | 1265 { |
4374
79ef2b6d8e76
there will be a 1.8.2 release before 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4358
diff
changeset
|
1266 // New in Orthanc 1.8.2 |
4358
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1267 std::unique_ptr<ZipReader> reader(ZipReader::CreateFromMemory(content)); |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1268 |
4386 | 1269 std::string filename, uncompressedFile; |
1270 while (reader->ReadNextFile(filename, uncompressedFile)) | |
4244
416c35da7d25
robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4243
diff
changeset
|
1271 { |
4386 | 1272 if (!uncompressedFile.empty()) |
4358
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1273 { |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1274 LOG(INFO) << "Uploading DICOM file extracted from a ZIP archive in WebDAV: " << filename; |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1275 |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4460
diff
changeset
|
1276 std::unique_ptr<DicomInstanceToStore> instance(DicomInstanceToStore::CreateFromBuffer(uncompressedFile)); |
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4460
diff
changeset
|
1277 instance->SetOrigin(DicomInstanceOrigin::FromWebDav()); |
4358
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1278 |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1279 std::string publicId; |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1280 |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1281 try |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1282 { |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4460
diff
changeset
|
1283 context_.Store(publicId, *instance, StoreInstanceMode_Default); |
4358
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1284 } |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1285 catch (OrthancException& e) |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1286 { |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1287 if (e.GetErrorCode() == ErrorCode_BadFileFormat) |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1288 { |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1289 LOG(ERROR) << "Cannot import non-DICOM file from ZIP archive: " << filename; |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1290 } |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1291 } |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1292 } |
4244
416c35da7d25
robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4243
diff
changeset
|
1293 } |
4358
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1294 |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1295 success = true; |
4240 | 1296 } |
4358
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1297 else |
4240 | 1298 { |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4460
diff
changeset
|
1299 std::unique_ptr<DicomInstanceToStore> instance(DicomInstanceToStore::CreateFromBuffer(content)); |
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4460
diff
changeset
|
1300 instance->SetOrigin(DicomInstanceOrigin::FromWebDav()); |
4358
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1301 |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1302 try |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1303 { |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1304 std::string publicId; |
4796
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
1305 ServerContext::StoreResult result = context_.Store(publicId, *instance, StoreInstanceMode_Default); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
1306 if (result.GetStatus() == StoreStatus_Success || |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
1307 result.GetStatus() == StoreStatus_AlreadyStored) |
4358
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1308 { |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1309 LOG(INFO) << "Successfully imported DICOM instance from WebDAV: " |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1310 << path << " (Orthanc ID: " << publicId << ")"; |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1311 success = true; |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1312 } |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1313 } |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1314 catch (OrthancException& e) |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1315 { |
d6929f052ec4
ZIP archives containing DICOM files can be uploaded using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
1316 } |
4244
416c35da7d25
robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4243
diff
changeset
|
1317 } |
416c35da7d25
robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4243
diff
changeset
|
1318 |
416c35da7d25
robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4243
diff
changeset
|
1319 uploads_.DeleteItem(uri); |
416c35da7d25
robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4243
diff
changeset
|
1320 |
416c35da7d25
robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4243
diff
changeset
|
1321 if (!success) |
416c35da7d25
robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4243
diff
changeset
|
1322 { |
416c35da7d25
robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4243
diff
changeset
|
1323 LOG(WARNING) << "Cannot import DICOM instance from WebWAV (maybe not a DICOM file): " << path; |
4240 | 1324 } |
1325 } | |
1326 } | |
1327 | |
1328 | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1329 OrthancWebDav::INode& OrthancWebDav::GetRootNode(const std::string& rootPath) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1330 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1331 if (rootPath == BY_PATIENTS) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1332 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1333 return *patients_; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1334 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1335 else if (rootPath == BY_STUDIES) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1336 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1337 return *studies_; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1338 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1339 else if (rootPath == BY_DATES) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1340 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1341 return *dates_; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1342 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1343 else |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1344 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1345 throw OrthancException(ErrorCode_InternalError); |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1346 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1347 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1348 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1349 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1350 OrthancWebDav::OrthancWebDav(ServerContext& context, |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1351 bool allowDicomDelete, |
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1352 bool allowUpload) : |
4240 | 1353 context_(context), |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1354 allowDicomDelete_(allowDicomDelete), |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1355 allowUpload_(allowUpload), |
4240 | 1356 uploads_(false /* store uploads as temporary files */), |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1357 uploadRunning_(false) |
4240 | 1358 { |
1359 patientsTemplates_[ResourceType_Patient] = "{{PatientID}} - {{PatientName}}"; | |
1360 patientsTemplates_[ResourceType_Study] = "{{StudyDate}} - {{StudyDescription}}"; | |
1361 patientsTemplates_[ResourceType_Series] = "{{Modality}} - {{SeriesDescription}}"; | |
1362 | |
1363 studiesTemplates_[ResourceType_Study] = "{{PatientID}} - {{PatientName}} - {{StudyDescription}}"; | |
1364 studiesTemplates_[ResourceType_Series] = patientsTemplates_[ResourceType_Series]; | |
1365 | |
1366 patients_.reset(new RootNode(context, ResourceType_Patient, patientsTemplates_)); | |
1367 studies_.reset(new RootNode(context, ResourceType_Study, studiesTemplates_)); | |
1368 dates_.reset(new ListOfStudiesByYear(context, studiesTemplates_)); | |
1369 } | |
1370 | |
1371 | |
1372 bool OrthancWebDav::IsExistingFolder(const UriComponents& path) | |
1373 { | |
1374 if (path.empty()) | |
1375 { | |
1376 return true; | |
1377 } | |
1378 else if (path[0] == BY_UIDS) | |
1379 { | |
1380 return (path.size() <= 3 && | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1381 (path.size() != 3 || path[2] != STUDY_INFO)); |
4240 | 1382 } |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1383 else if (path[0] == BY_PATIENTS || |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1384 path[0] == BY_STUDIES || |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1385 path[0] == BY_DATES) |
4240 | 1386 { |
4252 | 1387 IWebDavBucket::Collection collection; |
1388 return GetRootNode(path[0]).ListCollection(collection, UriComponents(path.begin() + 1, path.end())); | |
4240 | 1389 } |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1390 else if (allowUpload_ && |
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1391 path[0] == UPLOADS) |
4240 | 1392 { |
1393 return uploads_.IsExistingFolder(UriComponents(path.begin() + 1, path.end())); | |
1394 } | |
1395 else | |
1396 { | |
1397 return false; | |
1398 } | |
1399 } | |
1400 | |
1401 | |
1402 bool OrthancWebDav::ListCollection(Collection& collection, | |
1403 const UriComponents& path) | |
1404 { | |
1405 if (path.empty()) | |
1406 { | |
4241 | 1407 collection.AddResource(new Folder(BY_DATES)); |
4240 | 1408 collection.AddResource(new Folder(BY_PATIENTS)); |
1409 collection.AddResource(new Folder(BY_STUDIES)); | |
1410 collection.AddResource(new Folder(BY_UIDS)); | |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1411 |
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1412 if (allowUpload_) |
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1413 { |
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1414 collection.AddResource(new Folder(UPLOADS)); |
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1415 } |
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1416 |
4240 | 1417 return true; |
1418 } | |
1419 else if (path[0] == BY_UIDS) | |
1420 { | |
1421 DatabaseLookup query; | |
1422 ResourceType level; | |
1423 size_t limit = 0; // By default, no limits | |
1424 | |
1425 if (path.size() == 1) | |
1426 { | |
1427 level = ResourceType_Study; | |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1428 limit = 0; // TODO - Should we limit here? |
4240 | 1429 } |
1430 else if (path.size() == 2) | |
1431 { | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1432 AddVirtualFile(collection, path, STUDY_INFO); |
4240 | 1433 |
1434 level = ResourceType_Series; | |
1435 query.AddRestConstraint(DICOM_TAG_STUDY_INSTANCE_UID, path[1], | |
1436 true /* case sensitive */, true /* mandatory tag */); | |
1437 } | |
1438 else if (path.size() == 3) | |
1439 { | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1440 AddVirtualFile(collection, path, SERIES_INFO); |
4240 | 1441 |
1442 level = ResourceType_Instance; | |
1443 query.AddRestConstraint(DICOM_TAG_STUDY_INSTANCE_UID, path[1], | |
1444 true /* case sensitive */, true /* mandatory tag */); | |
1445 query.AddRestConstraint(DICOM_TAG_SERIES_INSTANCE_UID, path[2], | |
1446 true /* case sensitive */, true /* mandatory tag */); | |
1447 } | |
1448 else | |
1449 { | |
1450 return false; | |
1451 } | |
1452 | |
1453 DicomIdentifiersVisitor visitor(context_, collection, level); | |
1454 context_.Apply(visitor, query, level, 0 /* since */, limit); | |
1455 | |
1456 return true; | |
1457 } | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1458 else if (path[0] == BY_PATIENTS || |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1459 path[0] == BY_STUDIES || |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1460 path[0] == BY_DATES) |
4240 | 1461 { |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1462 return GetRootNode(path[0]).ListCollection(collection, UriComponents(path.begin() + 1, path.end())); |
4240 | 1463 } |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1464 else if (allowUpload_ && |
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1465 path[0] == UPLOADS) |
4240 | 1466 { |
1467 return uploads_.ListCollection(collection, UriComponents(path.begin() + 1, path.end())); | |
1468 } | |
1469 else | |
1470 { | |
1471 return false; | |
1472 } | |
1473 } | |
1474 | |
1475 | |
1476 bool OrthancWebDav::GetFileContent(MimeType& mime, | |
1477 std::string& content, | |
1478 boost::posix_time::ptime& modificationTime, | |
1479 const UriComponents& path) | |
1480 { | |
1481 if (path.empty()) | |
1482 { | |
1483 return false; | |
1484 } | |
1485 else if (path[0] == BY_UIDS) | |
1486 { | |
1487 if (path.size() == 3 && | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1488 path[2] == STUDY_INFO) |
4240 | 1489 { |
1490 DatabaseLookup query; | |
1491 query.AddRestConstraint(DICOM_TAG_STUDY_INSTANCE_UID, path[1], | |
1492 true /* case sensitive */, true /* mandatory tag */); | |
1493 | |
1494 OrthancJsonVisitor visitor(context_, content, ResourceType_Study); | |
1495 context_.Apply(visitor, query, ResourceType_Study, 0 /* since */, 0 /* no limit */); | |
1496 | |
1497 mime = MimeType_Json; | |
1498 return visitor.IsSuccess(); | |
1499 } | |
1500 else if (path.size() == 4 && | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1501 path[3] == SERIES_INFO) |
4240 | 1502 { |
1503 DatabaseLookup query; | |
1504 query.AddRestConstraint(DICOM_TAG_STUDY_INSTANCE_UID, path[1], | |
1505 true /* case sensitive */, true /* mandatory tag */); | |
1506 query.AddRestConstraint(DICOM_TAG_SERIES_INSTANCE_UID, path[2], | |
1507 true /* case sensitive */, true /* mandatory tag */); | |
1508 | |
1509 OrthancJsonVisitor visitor(context_, content, ResourceType_Series); | |
1510 context_.Apply(visitor, query, ResourceType_Series, 0 /* since */, 0 /* no limit */); | |
1511 | |
1512 mime = MimeType_Json; | |
1513 return visitor.IsSuccess(); | |
1514 } | |
1515 else if (path.size() == 4 && | |
1516 boost::ends_with(path[3], ".dcm")) | |
1517 { | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1518 const std::string sopInstanceUid = path[3].substr(0, path[3].size() - 4); |
4240 | 1519 |
1520 DatabaseLookup query; | |
1521 query.AddRestConstraint(DICOM_TAG_STUDY_INSTANCE_UID, path[1], | |
1522 true /* case sensitive */, true /* mandatory tag */); | |
1523 query.AddRestConstraint(DICOM_TAG_SERIES_INSTANCE_UID, path[2], | |
1524 true /* case sensitive */, true /* mandatory tag */); | |
1525 query.AddRestConstraint(DICOM_TAG_SOP_INSTANCE_UID, sopInstanceUid, | |
1526 true /* case sensitive */, true /* mandatory tag */); | |
1527 | |
1528 DicomFileVisitor visitor(context_, content, modificationTime); | |
1529 context_.Apply(visitor, query, ResourceType_Instance, 0 /* since */, 0 /* no limit */); | |
1530 | |
1531 mime = MimeType_Dicom; | |
1532 return visitor.IsSuccess(); | |
1533 } | |
1534 else | |
1535 { | |
1536 return false; | |
1537 } | |
1538 } | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1539 else if (path[0] == BY_PATIENTS || |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1540 path[0] == BY_STUDIES || |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1541 path[0] == BY_DATES) |
4240 | 1542 { |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1543 return GetRootNode(path[0]).GetFileContent(mime, content, modificationTime, UriComponents(path.begin() + 1, path.end())); |
4241 | 1544 } |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1545 else if (allowUpload_ && |
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1546 path[0] == UPLOADS) |
4240 | 1547 { |
1548 return uploads_.GetFileContent(mime, content, modificationTime, UriComponents(path.begin() + 1, path.end())); | |
1549 } | |
1550 else | |
1551 { | |
1552 return false; | |
1553 } | |
1554 } | |
1555 | |
1556 | |
1557 bool OrthancWebDav::StoreFile(const std::string& content, | |
1558 const UriComponents& path) | |
1559 { | |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1560 if (allowUpload_ && |
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1561 path.size() >= 1 && |
4240 | 1562 path[0] == UPLOADS) |
1563 { | |
1564 UriComponents subpath(UriComponents(path.begin() + 1, path.end())); | |
1565 | |
1566 if (uploads_.StoreFile(content, subpath)) | |
1567 { | |
1568 if (!content.empty()) | |
1569 { | |
1570 uploadQueue_.Enqueue(new SingleValueObject<std::string>(Toolbox::FlattenUri(subpath))); | |
1571 } | |
1572 return true; | |
1573 } | |
1574 else | |
1575 { | |
1576 return false; | |
1577 } | |
1578 } | |
1579 else | |
1580 { | |
1581 return false; | |
1582 } | |
1583 } | |
1584 | |
1585 | |
1586 bool OrthancWebDav::CreateFolder(const UriComponents& path) | |
1587 { | |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1588 if (allowUpload_ && |
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1589 path.size() >= 1 && |
4240 | 1590 path[0] == UPLOADS) |
1591 { | |
1592 return uploads_.CreateFolder(UriComponents(path.begin() + 1, path.end())); | |
1593 } | |
1594 else | |
1595 { | |
1596 return false; | |
1597 } | |
1598 } | |
1599 | |
1600 | |
1601 bool OrthancWebDav::DeleteItem(const std::vector<std::string>& path) | |
1602 { | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1603 if (path.empty()) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1604 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1605 return false; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1606 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1607 else if (path[0] == BY_UIDS && |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1608 path.size() >= 2 && |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1609 path.size() <= 4) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1610 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1611 if (allowDicomDelete_) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1612 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1613 ResourceType level; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1614 DatabaseLookup query; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1615 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1616 query.AddRestConstraint(DICOM_TAG_STUDY_INSTANCE_UID, path[1], |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1617 true /* case sensitive */, true /* mandatory tag */); |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1618 level = ResourceType_Study; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1619 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1620 if (path.size() >= 3) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1621 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1622 if (path[2] == STUDY_INFO) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1623 { |
4252 | 1624 return true; // Allow deletion of virtual files (to avoid blocking recursive DELETE) |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1625 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1626 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1627 query.AddRestConstraint(DICOM_TAG_SERIES_INSTANCE_UID, path[2], |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1628 true /* case sensitive */, true /* mandatory tag */); |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1629 level = ResourceType_Series; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1630 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1631 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1632 if (path.size() == 4) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1633 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1634 if (path[3] == SERIES_INFO) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1635 { |
4252 | 1636 return true; // Allow deletion of virtual files (to avoid blocking recursive DELETE) |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1637 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1638 else if (boost::ends_with(path[3], ".dcm")) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1639 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1640 const std::string sopInstanceUid = path[3].substr(0, path[3].size() - 4); |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1641 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1642 query.AddRestConstraint(DICOM_TAG_SOP_INSTANCE_UID, sopInstanceUid, |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1643 true /* case sensitive */, true /* mandatory tag */); |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1644 level = ResourceType_Instance; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1645 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1646 else |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1647 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1648 return false; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1649 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1650 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1651 |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1652 DicomDeleteVisitor visitor(context_, level); |
4252 | 1653 context_.Apply(visitor, query, level, 0 /* since */, 0 /* no limit */); |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1654 return true; |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1655 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1656 else |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1657 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1658 return false; // read-only |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1659 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1660 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1661 else if (path[0] == BY_PATIENTS || |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1662 path[0] == BY_STUDIES || |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1663 path[0] == BY_DATES) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1664 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1665 if (allowDicomDelete_) |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1666 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1667 return GetRootNode(path[0]).DeleteItem(UriComponents(path.begin() + 1, path.end())); |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1668 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1669 else |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1670 { |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1671 return false; // read-only |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1672 } |
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1673 } |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1674 else if (allowUpload_ && |
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1675 path[0] == UPLOADS) |
4240 | 1676 { |
1677 return uploads_.DeleteItem(UriComponents(path.begin() + 1, path.end())); | |
1678 } | |
1679 else | |
1680 { | |
4242
5cfa6ba75dfc
deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4241
diff
changeset
|
1681 return false; |
4240 | 1682 } |
1683 } | |
1684 | |
1685 | |
1686 void OrthancWebDav::Start() | |
1687 { | |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1688 if (uploadRunning_) |
4240 | 1689 { |
1690 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1691 } | |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1692 else if (allowUpload_) |
4240 | 1693 { |
1694 LOG(INFO) << "Starting the WebDAV upload thread"; | |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1695 uploadRunning_ = true; |
4240 | 1696 uploadThread_ = boost::thread(UploadWorker, this); |
1697 } | |
1698 } | |
1699 | |
1700 | |
1701 void OrthancWebDav::Stop() | |
1702 { | |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1703 if (uploadRunning_) |
4240 | 1704 { |
1705 LOG(INFO) << "Stopping the WebDAV upload thread"; | |
4243
64f57c9d5f79
configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4242
diff
changeset
|
1706 uploadRunning_ = false; |
4240 | 1707 if (uploadThread_.joinable()) |
1708 { | |
1709 uploadThread_.join(); | |
1710 } | |
1711 } | |
1712 } | |
1713 } |