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