annotate OrthancServer/Sources/OrthancWebDav.cpp @ 4884:d7d5d63985c8

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