Mercurial > hg > orthanc
annotate OrthancServer/ServerContext.cpp @ 933:aab7e6cac543 mac
Close branch mac
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 24 Jun 2014 18:00:26 +0200 |
parents | 84513f2ee1f3 |
children | b3f6fb1130cd |
rev | line source |
---|---|
224 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
689 | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
224 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
33 #include "PrecompiledHeadersServer.h" |
224 | 34 #include "ServerContext.h" |
35 | |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
36 #include "../Core/HttpServer/FilesystemHttpSender.h" |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
37 #include "../Core/Lua/LuaFunctionCall.h" |
795 | 38 #include "FromDcmtkBridge.h" |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
39 #include "ServerToolbox.h" |
771 | 40 #include "OrthancInitialization.h" |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
41 |
224 | 42 #include <glog/logging.h> |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
376
diff
changeset
|
43 #include <EmbeddedResources.h> |
794 | 44 #include <dcmtk/dcmdata/dcfilefo.h> |
224 | 45 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
46 #define ENABLE_DICOM_CACHE 1 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
47 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
48 static const char* RECEIVED_INSTANCE_FILTER = "ReceivedInstanceFilter"; |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
49 |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
50 static const size_t DICOM_CACHE_SIZE = 2; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
51 |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
52 /** |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
53 * IMPORTANT: We make the assumption that the same instance of |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
54 * FileStorage can be accessed from multiple threads. This seems OK |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
55 * since the filesystem implements the required locking mechanisms, |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
56 * but maybe a read-writer lock on the "FileStorage" could be |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
57 * useful. Conversely, "ServerIndex" already implements mutex-based |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
58 * locking. |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
59 **/ |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
60 |
224 | 61 namespace Orthanc |
62 { | |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
320
diff
changeset
|
63 ServerContext::ServerContext(const boost::filesystem::path& storagePath, |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
320
diff
changeset
|
64 const boost::filesystem::path& indexPath) : |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
320
diff
changeset
|
65 storage_(storagePath.string()), |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
320
diff
changeset
|
66 index_(*this, indexPath.string()), |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
67 accessor_(storage_), |
656 | 68 compressionEnabled_(false), |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
69 provider_(*this), |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
70 dicomCache_(provider_, DICOM_CACHE_SIZE) |
224 | 71 { |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
72 scu_.SetLocalApplicationEntityTitle(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC")); |
774 | 73 //scu_.SetMillisecondsBeforeClose(1); // The connection is always released |
74 | |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
376
diff
changeset
|
75 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); |
224 | 76 } |
77 | |
236 | 78 void ServerContext::SetCompressionEnabled(bool enabled) |
79 { | |
80 if (enabled) | |
81 LOG(WARNING) << "Disk compression is enabled"; | |
82 else | |
83 LOG(WARNING) << "Disk compression is disabled"; | |
84 | |
85 compressionEnabled_ = enabled; | |
86 } | |
87 | |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
88 void ServerContext::RemoveFile(const std::string& fileUuid) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
89 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
90 storage_.Remove(fileUuid); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
91 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
92 |
304 | 93 StoreStatus ServerContext::Store(const char* dicomInstance, |
224 | 94 size_t dicomSize, |
95 const DicomMap& dicomSummary, | |
96 const Json::Value& dicomJson, | |
97 const std::string& remoteAet) | |
98 { | |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
99 // Test if the instance must be filtered out |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
100 if (lua_.IsExistingFunction(RECEIVED_INSTANCE_FILTER)) |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
101 { |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
102 Json::Value simplified; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
103 SimplifyTags(simplified, dicomJson); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
104 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
105 LuaFunctionCall call(lua_, RECEIVED_INSTANCE_FILTER); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
106 call.PushJSON(simplified); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
107 call.PushString(remoteAet); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
108 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
109 if (!call.ExecutePredicate()) |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
110 { |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
407
diff
changeset
|
111 LOG(INFO) << "An incoming instance has been discarded by the filter"; |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
112 return StoreStatus_FilteredOut; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
113 } |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
114 } |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
115 |
236 | 116 if (compressionEnabled_) |
117 { | |
118 accessor_.SetCompressionForNextOperations(CompressionType_Zlib); | |
119 } | |
120 else | |
121 { | |
122 accessor_.SetCompressionForNextOperations(CompressionType_None); | |
123 } | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
124 |
304 | 125 FileInfo dicomInfo = accessor_.Write(dicomInstance, dicomSize, FileContentType_Dicom); |
697
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
126 FileInfo jsonInfo = accessor_.Write(dicomJson.toStyledString(), FileContentType_DicomAsJson); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
127 |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
128 ServerIndex::Attachments attachments; |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
129 attachments.push_back(dicomInfo); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
130 attachments.push_back(jsonInfo); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
131 |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
132 StoreStatus status = index_.Store(dicomSummary, attachments, remoteAet); |
224 | 133 |
134 if (status != StoreStatus_Success) | |
135 { | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
136 storage_.Remove(dicomInfo.GetUuid()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
137 storage_.Remove(jsonInfo.GetUuid()); |
224 | 138 } |
139 | |
140 switch (status) | |
141 { | |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
142 case StoreStatus_Success: |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
143 LOG(INFO) << "New instance stored"; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
144 break; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
145 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
146 case StoreStatus_AlreadyStored: |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
147 LOG(INFO) << "Already stored"; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
148 break; |
224 | 149 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
150 case StoreStatus_Failure: |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
151 LOG(ERROR) << "Store failure"; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
152 break; |
224 | 153 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
154 default: |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
155 // This should never happen |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
156 break; |
224 | 157 } |
158 | |
159 return status; | |
160 } | |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
161 |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
162 |
697
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
163 void ServerContext::AnswerDicomFile(RestApiOutput& output, |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
164 const std::string& instancePublicId, |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
165 FileContentType content) |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
166 { |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
167 FileInfo attachment; |
236 | 168 if (!index_.LookupAttachment(attachment, instancePublicId, content)) |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
169 { |
236 | 170 throw OrthancException(ErrorCode_InternalError); |
171 } | |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
172 |
236 | 173 accessor_.SetCompressionForNextOperations(attachment.GetCompressionType()); |
320 | 174 |
236 | 175 std::auto_ptr<HttpFileSender> sender(accessor_.ConstructHttpFileSender(attachment.GetUuid())); |
320 | 176 sender->SetContentType("application/dicom"); |
177 sender->SetDownloadFilename(instancePublicId + ".dcm"); | |
236 | 178 output.AnswerFile(*sender); |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
179 } |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
180 |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
181 |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
182 void ServerContext::ReadJson(Json::Value& result, |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
183 const std::string& instancePublicId) |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
184 { |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
185 std::string s; |
697
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
186 ReadFile(s, instancePublicId, FileContentType_DicomAsJson); |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
187 |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
188 Json::Reader reader; |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
189 if (!reader.parse(s, result)) |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
190 { |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
191 throw OrthancException("Corrupted JSON file"); |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
192 } |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
193 } |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
194 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
195 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
196 void ServerContext::ReadFile(std::string& result, |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
197 const std::string& instancePublicId, |
697
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
198 FileContentType content, |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
199 bool uncompressIfNeeded) |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
200 { |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
201 FileInfo attachment; |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
202 if (!index_.LookupAttachment(attachment, instancePublicId, content)) |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
203 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
204 throw OrthancException(ErrorCode_InternalError); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
205 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
206 |
697
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
207 if (uncompressIfNeeded) |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
208 { |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
209 accessor_.SetCompressionForNextOperations(attachment.GetCompressionType()); |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
210 } |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
211 else |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
212 { |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
213 accessor_.SetCompressionForNextOperations(CompressionType_None); |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
214 } |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
696
diff
changeset
|
215 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
216 accessor_.Read(result, attachment.GetUuid()); |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
217 } |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
218 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
219 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
220 IDynamicObject* ServerContext::DicomCacheProvider::Provide(const std::string& instancePublicId) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
221 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
222 std::string content; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
223 context_.ReadFile(content, instancePublicId, FileContentType_Dicom); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
224 return new ParsedDicomFile(content); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
225 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
226 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
227 |
778
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
228 ServerContext::DicomCacheLocker::DicomCacheLocker(ServerContext& that, |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
229 const std::string& instancePublicId) : |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
230 that_(that) |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
231 { |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
232 #if ENABLE_DICOM_CACHE == 0 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
233 static std::auto_ptr<IDynamicObject> p; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
234 p.reset(provider_.Provide(instancePublicId)); |
778
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
235 dicom_ = dynamic_cast<ParsedDicomFile*>(p.get()); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
236 #else |
778
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
237 that_.dicomCacheMutex_.lock(); |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
238 dicom_ = &dynamic_cast<ParsedDicomFile&>(that_.dicomCache_.Access(instancePublicId)); |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
239 #endif |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
240 } |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
241 |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
242 |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
243 ServerContext::DicomCacheLocker::~DicomCacheLocker() |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
244 { |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
245 #if ENABLE_DICOM_CACHE == 0 |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
246 #else |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
774
diff
changeset
|
247 that_.dicomCacheMutex_.unlock(); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
248 #endif |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
249 } |
304 | 250 |
251 | |
792 | 252 static DcmFileFormat& GetDicom(ParsedDicomFile& file) |
253 { | |
254 return *reinterpret_cast<DcmFileFormat*>(file.GetDcmtkObject()); | |
255 } | |
256 | |
257 | |
304 | 258 StoreStatus ServerContext::Store(std::string& resultPublicId, |
791 | 259 ParsedDicomFile& dicomInstance, |
304 | 260 const char* dicomBuffer, |
261 size_t dicomSize) | |
262 { | |
263 DicomMap dicomSummary; | |
792 | 264 FromDcmtkBridge::Convert(dicomSummary, *GetDicom(dicomInstance).getDataset()); |
304 | 265 |
730
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
266 try |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
267 { |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
268 DicomInstanceHasher hasher(dicomSummary); |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
269 resultPublicId = hasher.HashInstance(); |
304 | 270 |
730
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
271 Json::Value dicomJson; |
792 | 272 FromDcmtkBridge::ToJson(dicomJson, *GetDicom(dicomInstance).getDataset()); |
304 | 273 |
730
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
274 StoreStatus status = StoreStatus_Failure; |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
275 if (dicomSize > 0) |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
276 { |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
277 status = Store(dicomBuffer, dicomSize, dicomSummary, dicomJson, ""); |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
278 } |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
279 |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
280 return status; |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
281 } |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
282 catch (OrthancException& e) |
304 | 283 { |
730
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
284 if (e.GetErrorCode() == ErrorCode_InexistentTag) |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
285 { |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
286 LogMissingRequiredTag(dicomSummary); |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
287 } |
304 | 288 |
730
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
289 throw e; |
309e686b41e7
better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
699
diff
changeset
|
290 } |
304 | 291 } |
292 | |
293 | |
294 StoreStatus ServerContext::Store(std::string& resultPublicId, | |
791 | 295 ParsedDicomFile& dicomInstance) |
304 | 296 { |
297 std::string buffer; | |
792 | 298 if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, GetDicom(dicomInstance).getDataset())) |
304 | 299 { |
300 throw OrthancException(ErrorCode_InternalError); | |
301 } | |
302 | |
303 if (buffer.size() == 0) | |
304 return Store(resultPublicId, dicomInstance, NULL, 0); | |
305 else | |
306 return Store(resultPublicId, dicomInstance, &buffer[0], buffer.size()); | |
307 } | |
308 | |
309 | |
310 StoreStatus ServerContext::Store(std::string& resultPublicId, | |
311 const char* dicomBuffer, | |
312 size_t dicomSize) | |
313 { | |
314 ParsedDicomFile dicom(dicomBuffer, dicomSize); | |
791 | 315 return Store(resultPublicId, dicom, dicomBuffer, dicomSize); |
304 | 316 } |
317 | |
791 | 318 |
319 StoreStatus ServerContext::Store(std::string& resultPublicId, | |
320 const std::string& dicomContent) | |
321 { | |
322 if (dicomContent.size() == 0) | |
323 { | |
324 return Store(resultPublicId, NULL, 0); | |
325 } | |
326 else | |
327 { | |
328 return Store(resultPublicId, &dicomContent[0], dicomContent.size()); | |
329 } | |
330 } | |
331 | |
332 | |
695
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
333 void ServerContext::SetStoreMD5ForAttachments(bool storeMD5) |
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
334 { |
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
335 LOG(INFO) << "Storing MD5 for attachments: " << (storeMD5 ? "yes" : "no"); |
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
336 accessor_.SetStoreMD5(storeMD5); |
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
337 } |
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
338 |
699
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
339 |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
340 bool ServerContext::AddAttachment(const std::string& resourceId, |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
341 FileContentType attachmentType, |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
342 const void* data, |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
343 size_t size) |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
344 { |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
345 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId; |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
346 |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
347 if (compressionEnabled_) |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
348 { |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
349 accessor_.SetCompressionForNextOperations(CompressionType_Zlib); |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
350 } |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
351 else |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
352 { |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
353 accessor_.SetCompressionForNextOperations(CompressionType_None); |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
354 } |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
355 |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
356 FileInfo info = accessor_.Write(data, size, attachmentType); |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
357 StoreStatus status = index_.AddAttachment(info, resourceId); |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
358 |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
359 if (status != StoreStatus_Success) |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
360 { |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
361 storage_.Remove(info.GetUuid()); |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
362 return false; |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
363 } |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
364 else |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
365 { |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
366 return true; |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
367 } |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
368 } |
224 | 369 } |